On 9/4/25 10:26, Zhao Liu wrote:
KVM_SET_PMU_EVENT_FILTER of x86 KVM allows user to configure x86 fixed
function counters by a bitmap.
Add the support of x86-fixed-counter in kvm-pmu-filter object and handle
this in i386 kvm codes.
Signed-off-by: Zhao Liu <zhao1....@intel.com>
Tested-by: Yi Lai <yi1....@intel.com>
---
Changes since RFC v2:
* Drop KVMPMUX86FixedCounter structure and use uint32_t to represent
bitmap in QAPI directly.
* Add Tested-by from Yi.
* Add documentation in qemu-options.hx.
* Bump up the supported QAPI version to v10.1.
Changes since RFC v1:
* Make "action" as a global (per filter object) item, not a per-counter
parameter. (Dapeng)
* Bump up the supported QAPI version to v10.0.
---
accel/kvm/kvm-pmu.c | 31 +++++++++++++++++++++++++++++++
include/system/kvm-pmu.h | 5 ++++-
qapi/kvm.json | 6 +++++-
qemu-options.hx | 6 +++++-
target/i386/kvm/kvm.c | 39 ++++++++++++++++++++++++---------------
5 files changed, 69 insertions(+), 18 deletions(-)
diff --git a/accel/kvm/kvm-pmu.c b/accel/kvm/kvm-pmu.c
index 9205907d1779..509d69d9c515 100644
--- a/accel/kvm/kvm-pmu.c
+++ b/accel/kvm/kvm-pmu.c
@@ -101,6 +101,29 @@ fail:
qapi_free_KvmPmuFilterEventList(head);
}
+static void kvm_pmu_filter_get_fixed_counter(Object *obj, Visitor *v,
+ const char *name, void *opaque,
+ Error **errp)
+{
+ KVMPMUFilter *filter = KVM_PMU_FILTER(obj);
+
+ visit_type_uint32(v, name, &filter->x86_fixed_counter, errp);
+}
+
+static void kvm_pmu_filter_set_fixed_counter(Object *obj, Visitor *v,
+ const char *name, void *opaque,
+ Error **errp)
+{
+ KVMPMUFilter *filter = KVM_PMU_FILTER(obj);
+ uint32_t counter;
+
+ if (!visit_type_uint32(v, name, &counter, errp)) {
+ return;
+ }
+
+ filter->x86_fixed_counter = counter;
+}
+
static void kvm_pmu_filter_class_init(ObjectClass *oc, void *data)
{
object_class_property_add_enum(oc, "action", "KvmPmuFilterAction",
@@ -116,6 +139,14 @@ static void kvm_pmu_filter_class_init(ObjectClass *oc,
void *data)
NULL, NULL);
object_class_property_set_description(oc, "events",
"KVM PMU event list");
+
+ object_class_property_add(oc, "x86-fixed-counter", "uint32_t",
+ kvm_pmu_filter_get_fixed_counter,
+ kvm_pmu_filter_set_fixed_counter,
+ NULL, NULL);
+ object_class_property_set_description(oc, "x86-fixed-counter",
+ "Enablement bitmap of "
+ "x86 PMU fixed counter");
Adding that x86-specific field to all architectures is a bit dubious.
}
static void kvm_pmu_filter_instance_init(Object *obj)
diff --git a/include/system/kvm-pmu.h b/include/system/kvm-pmu.h
index 6abc0d037aee..5238b2b4dcc7 100644
--- a/include/system/kvm-pmu.h
+++ b/include/system/kvm-pmu.h
@@ -19,10 +19,12 @@ OBJECT_DECLARE_SIMPLE_TYPE(KVMPMUFilter, KVM_PMU_FILTER)
/**
* KVMPMUFilter:
- * @action: action that KVM PMU filter will take for selected PMU events.
+ * @action: action that KVM PMU filter will take for selected PMU events
+ * and counters.
* @nevents: number of PMU event entries listed in @events
* @events: list of PMU event entries. A PMU event entry may represent one
* event or multiple events due to its format.
+ * @x86_fixed_counter: bitmap of x86 fixed counter.
*/
struct KVMPMUFilter {
Object parent_obj;
@@ -30,6 +32,7 @@ struct KVMPMUFilter {
KvmPmuFilterAction action;
uint32_t nevents;
KvmPmuFilterEventList *events;
+ uint32_t x86_fixed_counter;
};