commit d98ecdaca296 ("arm64: perf: Count EL2 events if the kernel is running in HYP") returns -EINVAL when perf system call perf_event_open is called with exclude_hv != exclude_kernel. This change breaks applications on VHE enabled ARMv8.1 platforms. The issue was observed with HHVM application, which calls perf_event_open with exclude_hv = 1 and exclude_kernel = 0. There is no separate hypervisor privilege level when VHE is enabled, the host kernel runs at EL2. So when VHE is enabled, we should ignore exclude_hv from the application. This behaviour is consistent with PowerPC where the exclude_hv is ignored when the hypervisor is not present and with x86 where this flag is ignored.
Unified · Split
| @@ -877,15 +877,24 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event, · 876 unmodified lines | ||
| 877 | 877 | |
| 878 | 878 | if (attr->exclude_idle) |
| 879 | 879 | return -EPERM; |
| 880 | − if (is_kernel_in_hyp_mode() && | |
| 881 | − attr->exclude_kernel != attr->exclude_hv) | |
| 882 | − return -EINVAL; | |
| 880 | + | |
| 881 | + /* | |
| 882 | + * If we're running in hyp mode, then we *are* the hypervisor. | |
| 883 | + * Therefore we ignore exclude_hv in this configuration, since | |
| 884 | + * there's no hypervisor to sample anyway. This is consistent | |
| 885 | + * with other architectures (x86 and Power). | |
| 886 | + */ | |
| 887 | + if (is_kernel_in_hyp_mode()) { | |
| 888 | + if (!attr->exclude_kernel) | |
| 889 | + config_base |= ARMV8_PMU_INCLUDE_EL2; | |
| 890 | + } else { | |
| 891 | + if (attr->exclude_kernel) | |
| 892 | + config_base |= ARMV8_PMU_EXCLUDE_EL1; | |
| 893 | + if (!attr->exclude_hv) | |
| 894 | + config_base |= ARMV8_PMU_INCLUDE_EL2; | |
| 895 | + } | |
| 883 | 896 | if (attr->exclude_user) |
| 884 | 897 | config_base |= ARMV8_PMU_EXCLUDE_EL0; |
| 885 | − if (!is_kernel_in_hyp_mode() && attr->exclude_kernel) | |
| 886 | − config_base |= ARMV8_PMU_EXCLUDE_EL1; | |
| 887 | − if (!attr->exclude_hv) | |
| 888 | − config_base |= ARMV8_PMU_INCLUDE_EL2; | |
| 889 | 898 | |
| 890 | 899 | /* |
| 891 | 900 | * Install the filter into config_base as this is used to |