Skip to content

Commit 68bf65e

Browse files
committed
executor: arm64: Init PMUs if enabling the feature
KVM requires initializing PMUs (via KVM_SET_DEVICE_ATTR) if the PMU feature is enabled in a VCPU (via KVM_ARM_VCPU_INIT). This fix ensures that whenever we enable the PMU feature, we also initialize PMUs.
1 parent 9ac0fdc commit 68bf65e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

executor/common_kvm_arm64.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ static void install_user_code(int cpufd, void* user_text_slot, int cpu_id, const
177177
static void setup_cpu_with_opts(int vmfd, int cpufd, const struct kvm_opt* opt, int opt_count)
178178
{
179179
uint32 features = 0;
180+
const uint32 pmu_bit = (1 << KVM_ARM_VCPU_PMU_V3);
180181
if (opt_count > 1)
181182
opt_count = 1;
182183
for (int i = 0; i < opt_count; i++) {
@@ -195,6 +196,14 @@ static void setup_cpu_with_opts(int vmfd, int cpufd, const struct kvm_opt* opt,
195196
init.features[0] = features;
196197
// Use the modified struct kvm_vcpu_init to initialize the virtual CPU.
197198
ioctl(cpufd, KVM_ARM_VCPU_INIT, &init);
199+
// Make sure that PMUs are initialized if enabled
200+
if (opt_count == 1 && (features & pmu_bit)) {
201+
struct kvm_device_attr attrs = {
202+
.group = KVM_ARM_VCPU_PMU_V3_CTRL,
203+
.attr = KVM_ARM_VCPU_PMU_V3_INIT
204+
};
205+
ioctl(cpufd, KVM_SET_DEVICE_ATTR, &attrs);
206+
}
198207
}
199208

200209
#endif

0 commit comments

Comments
 (0)