
# perf_event_open被限制导致的"No access to perf events"报错问题
#### 问题现象
CPU Profiler依赖perf_event_open的系统调用，但因为Linux kernel的Syscall安全策略（[seccomp](https://man7.org/linux/man-pages/man2/seccomp.2.html)）控制，可能会禁止进程调用特定Syscall。
错误提示如下：
```
[ERROR] xxxx Failed to execute 'start,jfr=7,jstackdepth=100,threads=true,event=cpu,interval=50ms,alloc=512k,wall=50ms,file=xxxx.jfr'
[ERROR] xxxx Failed to start Continuous Profile Collector
[ERROR] xxxx No access to perf events. Try --fdtransfer or --all-user option or 'sysctl kernel.perf_event_paranoid=1'
```
#### 解决方案
- Docker环境：执行以下命令运行容器。如需配置更精细化的系统调用控制，请参见[官方文档](https://docs.docker.com/engine/security/seccomp/)。开启特权容器存在容器逃逸风险，请评估后使用。
  ```
  docker run --security-opt seccomp=unconfined  XXX
  ```
  
- Kubernetes环境：配置特权容器参数privileged: true，特权容器始终保持为**Unconfined** 。如果无法配置特权容器参数privileged: true，可以通过修改k8s的yaml文件中的securityContext配置，使用默认的系统调用控制，请参见[官方文档](https://kubernetes.io/docs/tutorials/security/seccomp/)。开启特权容器存在容器逃逸风险，请评估后使用。
  ```
  apiVersion: v1
  kind: Pod
  metadata:
    name: default-pod
    labels:
      app: default-pod
  spec:
    containers:
      - name: test-container
        image: hashicorp/http-echo:1.0
        args:
          - "-text=just made some more syscalls!"
        securityContext:
          seccompProfile:
            type: RuntimeDefault
          capabilities:
            add: [ "SYS_ADMIN" ]
          privileged: false
  ```
  
 
