From: Gavin Shan <gshan@redhat.com>
To: Mathieu Poirier <mathieu.poirier@linaro.org>,
berrange@redhat.com, kchamart@redhat.com,
pierrick.bouvier@oss.qualcomm.com, peter.maydell@linaro.org,
mst@redhat.com, cohuck@redhat.com, pbonzini@redhat.com,
eblake@redhat.com, armbru@redhat.com,
lorenzo.pieralisi@linaro.org, enju.kohei@fujitsu.com
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, kvm@vger.kernel.org
Subject: Re: [RFC v4 12/24] target/arm/cpu: Set number of breakpoints and watchpoints in KVM
Date: Fri, 2 Oct 2026 14:06:24 +1000 [thread overview]
Message-ID: <eda8ee8f-5f17-4144-b21e-b1d990ee3270@redhat.com> (raw)
In-Reply-To: <20260903193611.1058589-13-mathieu.poirier@linaro.org>
On 9/4/26 5:35 AM, Mathieu Poirier wrote:
> From: Jean-Philippe Brucker <jean-philippe@linaro.org>
>
> Add "num-breakpoints" and "num-watchpoints" CPU parameters to configure
> the debug features that KVM presents to the guest. The KVM vCPU
> configuration is modified by calling SET_ONE_REG on the ID register.
>
> This is needed for Realm VMs, whose parameters include breakpoints and
> watchpoints, and influence the Realm Initial Measurement.
>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> ---
> target/arm/arm-qmp-cmds.c | 1 +
> target/arm/cpu.h | 4 ++
> target/arm/cpu64.c | 81 +++++++++++++++++++++++++++++++++++++++
> target/arm/kvm.c | 56 +++++++++++++++++++++++++++
> 4 files changed, 142 insertions(+)
>
> diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c
> index 83ec95c290f6..9ed65eb090d7 100644
> --- a/target/arm/arm-qmp-cmds.c
> +++ b/target/arm/arm-qmp-cmds.c
> @@ -76,6 +76,7 @@ static const char *cpu_model_advertised_features[] = {
> "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048",
> "kvm-no-adjvtime", "kvm-steal-time",
> "pauth", "pauth-impdef", "pauth-qarma3", "pauth-qarma5",
> + "num-breakpoints", "num-watchpoints",
> NULL
> };
>
> diff --git a/target/arm/cpu.h b/target/arm/cpu.h
> index 6bbc942f9a59..d256d66a3e1b 100644
> --- a/target/arm/cpu.h
> +++ b/target/arm/cpu.h
> @@ -1173,6 +1173,10 @@ struct ArchCPU {
>
> /* Generic timer counter frequency, in Hz */
> uint64_t gt_cntfrq_hz;
> +
> + /* Allows to override the default configuration */
> + uint8_t num_bps;
> + uint8_t num_wps;
> };
>
May improve the comments to indicate: these two fields are only needed
by RME-vCPUs.
/* Override the default configuration, only for RME vCPUs */
> typedef struct ARMCPUInfo {
> diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
> index 4e8c47253086..18adb06d78ad 100644
> --- a/target/arm/cpu64.c
> +++ b/target/arm/cpu64.c
> @@ -666,6 +666,86 @@ void aarch64_add_pauth_properties(Object *obj)
> }
> }
>
> +#if defined(CONFIG_KVM)
> +static void arm_cpu_get_num_wps(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint8_t val;
> + ARMCPU *cpu = ARM_CPU(obj);
> +
> + val = cpu->num_wps;
> + if (val == 0) {
> + val = FIELD_EX64(cpu->isar.idregs[ID_AA64DFR0_EL1_IDX],
> + ID_AA64DFR0, WRPS) + 1;
> + }
> +
> + visit_type_uint8(v, name, &val, errp);
> +}
> +
> +static void arm_cpu_set_num_wps(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint8_t val;
> + ARMCPU *cpu = ARM_CPU(obj);
> + uint8_t max_wps = FIELD_EX64(cpu->isar.idregs[ID_AA64DFR0_EL1_IDX],
> + ID_AA64DFR0, WRPS) + 1;
> +
> + if (!visit_type_uint8(v, name, &val, errp)) {
> + return;
> + }
> +
> + if (val < 2 || val > max_wps) {
> + error_setg(errp, "invalid number of watchpoints");
> + return;
> + }
> +
> + cpu->num_wps = val;
> +}
> +
> +static void arm_cpu_get_num_bps(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint8_t val;
> + ARMCPU *cpu = ARM_CPU(obj);
> +
> + val = cpu->num_bps;
> + if (val == 0) {
> + val = FIELD_EX64(cpu->isar.idregs[ID_AA64DFR0_EL1_IDX],
> + ID_AA64DFR0, BRPS) + 1;
> + }
> +
> + visit_type_uint8(v, name, &val, errp);
> +}
> +
> +static void arm_cpu_set_num_bps(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint8_t val;
> + ARMCPU *cpu = ARM_CPU(obj);
> + uint8_t max_bps = FIELD_EX64(cpu->isar.idregs[ID_AA64DFR0_EL1_IDX],
> + ID_AA64DFR0, BRPS) + 1;
> +
> + if (!visit_type_uint8(v, name, &val, errp)) {
> + return;
> + }
> +
> + if (val < 2 || val > max_bps) {
> + error_setg(errp, "invalid number of breakpoints");
^^^^^
Code alignment issue here.
> + return;
> + }
> +
> + cpu->num_bps = val;
> +}
> +
> +static void aarch64_add_kvm_writable_properties(Object *obj)
> +{
> + object_property_add(obj, "num-breakpoints", "uint8", arm_cpu_get_num_bps,
> + arm_cpu_set_num_bps, NULL, NULL);
> + object_property_add(obj, "num-watchpoints", "uint8", arm_cpu_get_num_wps,
> + arm_cpu_set_num_wps, NULL, NULL);
> +}
> +#endif /* CONFIG_KVM */
> +
> void aarch64_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp)
> {
> uint64_t t;
> @@ -807,6 +887,7 @@ void aarch64_host_initfn(Object *obj)
> kvm_arm_set_cpreg_mig_tolerances(cpu);
> kvm_arm_set_cpu_features_from_host(cpu);
> aarch64_add_sve_properties(obj);
> + aarch64_add_kvm_writable_properties(obj);
> #elif defined(CONFIG_HVF)
> hvf_arm_set_cpu_features_from_host(cpu);
> #elif defined(CONFIG_WHPX)
> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
> index ca25b707a0a8..93686b038263 100644
> --- a/target/arm/kvm.c
> +++ b/target/arm/kvm.c
> @@ -912,6 +912,56 @@ out:
> return ret;
> }
>
> +#define KVM_REG_ARM_ID_AA64DFR0_EL1 ARM64_SYS_REG(3, 0, 0, 5, 0)
> +
> +static void kvm_arm_configure_aa64dfr0(ARMCPU *cpu)
> +{
> + int ret;
> + uint64_t val, newval;
> + CPUState *cs = CPU(cpu);
> +
> + if (!cpu->num_bps && !cpu->num_wps) {
> + return;
> + }
> +
> + newval = cpu->isar.idregs[ID_AA64DFR0_EL1_IDX];
> + if (cpu->num_bps) {
> + uint64_t ctx_cmps = FIELD_EX64(newval, ID_AA64DFR0, CTX_CMPS);
> +
> + /* CTX_CMPs is never greater than BRPs */
> + ctx_cmps = MIN(ctx_cmps, cpu->num_bps - 1);
> + newval = FIELD_DP64(newval, ID_AA64DFR0, BRPS, cpu->num_bps - 1);
> + newval = FIELD_DP64(newval, ID_AA64DFR0, CTX_CMPS, ctx_cmps);
> + }
> + if (cpu->num_wps) {
> + newval = FIELD_DP64(newval, ID_AA64DFR0, WRPS, cpu->num_wps - 1);
> + }
> + ret = kvm_set_one_reg(cs, KVM_REG_ARM_ID_AA64DFR0_EL1, &newval);
> + if (ret) {
> + error_report("Failed to set KVM_REG_ARM_ID_AA64DFR0_EL1");
> + return;
> + }
> +
> + /*
> + * Check if the write succeeded. KVM does offer the writable mask for this
> + * register, but this way we also check if the value we wrote was sane.
> + */
> + ret = kvm_get_one_reg(cs, KVM_REG_ARM_ID_AA64DFR0_EL1, &val);
> + if (ret) {
> + error_report("Failed to get KVM_REG_ARM_ID_AA64DFR0_EL1");
> + return;
> + }
> +
> + if (val != newval) {
> + error_report("Failed to update KVM_REG_ARM_ID_AA64DFR0_EL1");
> + }
These two checks could be combined since we needn't to know how the write has
been failing.
if (ret || val != newval) {
error_report("Failed to update KVM_REG_ARM_ID_AA64DFR0_EL1");
}
> +}
> +
> +static void kvm_arm_configure_vcpu_regs(ARMCPU *cpu)
> +{
> + kvm_arm_configure_aa64dfr0(cpu);
> +}
> +
> /**
> * kvm_arm_cpreg_level:
> * @regidx: KVM register index
> @@ -1128,6 +1178,12 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu)
> fprintf(stderr, "kvm_arm_vcpu_init failed: %s\n", strerror(-ret));
> abort();
> }
> +
> + /*
> + * Before loading the KVM values into CPUState, update the KVM configuration
> + */
Can be squeezed into one line:
/* Update KVM state before it's loaded to CPUState */
> + kvm_arm_configure_vcpu_regs(cpu);
> +
The newly added properties ("num-breakpoints", "num-watchpoints") are only needed by
RME-vCPUs, but they're also visible to the normal vCPUs. So do we need to bail without
adding the properties if RME isn't supported by the vCPUs in kvm_arm_configure_vcpu_regs() ?
> if (!write_kvmstate_to_list(cpu)) {
> fprintf(stderr, "write_kvmstate_to_list failed\n");
> abort();
Thanks,
Gavin
next prev parent reply other threads:[~2026-10-02 4:06 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 19:35 [RFC v4 00/24] Add Realm support to QEMU-VMM Mathieu Poirier
2026-09-03 19:35 ` [RFC v4 01/24] linux-headers: Add RME related definitions Mathieu Poirier
2026-09-04 6:07 ` Gavin Shan
2026-09-04 16:24 ` Mathieu Poirier
2026-09-03 19:35 ` [RFC v4 02/24] target/arm/kvm: Return immediately on error in kvm_arch_init() Mathieu Poirier
2026-09-15 21:01 ` Michael Roth
2026-09-30 21:24 ` Mathieu Poirier
2026-09-03 19:35 ` [RFC v4 03/24] target/arm: Add confidential guest support Mathieu Poirier
2026-09-07 8:49 ` Markus Armbruster
2026-09-15 21:27 ` Michael Roth
2026-09-22 8:01 ` Lorenzo Pieralisi
2026-09-24 3:12 ` Kohei Enju
2026-09-30 21:28 ` Mathieu Poirier
2026-09-03 19:35 ` [RFC v4 04/24] target/arm/kvm-rme: Add mechanic to initialize realms Mathieu Poirier
2026-10-01 23:42 ` Gavin Shan
2026-09-03 19:35 ` [RFC v4 05/24] target/arm/kvm: Split kvm_arch_get/put_registers Mathieu Poirier
2026-09-03 19:35 ` [RFC v4 06/24] target/arm/kvm-rme: Initialize vCPU Mathieu Poirier
2026-10-02 0:53 ` Gavin Shan
2026-09-03 19:35 ` [RFC v4 07/24] target/arm/kvm: Create scratch Realm VM when requested Mathieu Poirier
2026-09-04 3:09 ` Kohei Enju
2026-09-04 16:25 ` Mathieu Poirier
2026-10-02 1:05 ` Gavin Shan
2026-09-03 19:35 ` [RFC v4 08/24] target/arm/kvm: Use kvm_vm_check_extension() where necessary Mathieu Poirier
2026-09-03 19:35 ` [RFC v4 09/24] hw/core/loader: Add a ROM loader notifier Mathieu Poirier
2026-09-15 22:36 ` Michael Roth
2026-10-02 1:15 ` Gavin Shan
2026-09-03 19:35 ` [RFC v4 10/24] target/arm/kvm-rme: Keep track of images loaded in Realm memory Mathieu Poirier
2026-09-15 22:50 ` Michael Roth
2026-09-16 21:40 ` Mathieu Poirier
2026-10-02 1:23 ` Gavin Shan
2026-09-03 19:35 ` [RFC v4 11/24] target/arm/kvm-rme: Populate Realm with runtime images Mathieu Poirier
2026-10-02 3:45 ` Gavin Shan
2026-10-02 9:27 ` Lorenzo Pieralisi
2026-09-03 19:35 ` [RFC v4 12/24] target/arm/cpu: Set number of breakpoints and watchpoints in KVM Mathieu Poirier
2026-10-02 4:06 ` Gavin Shan [this message]
2026-09-03 19:36 ` [RFC v4 13/24] target/arm/cpu: Set number of PMU counters " Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 14/24] target/arm/cpu: Don't read Realm registers Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 15/24] hw/arm/virt: Set proper conduit method for Realms Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 16/24] hw/arm/virt: Embed Realm VM type with IPA address space Mathieu Poirier
2026-10-02 4:16 ` Gavin Shan
2026-09-03 19:36 ` [RFC v4 17/24] hw/arm/virt: Reserve one bit of guest physical address for RME Mathieu Poirier
2026-10-02 4:19 ` Gavin Shan
2026-09-03 19:36 ` [RFC v4 18/24] hw/arm/virt: Disable DTB randomness for confidential VMs Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 19/24] hw/arm/virt: Move virt_flash_create() to machvirt_init() Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 20/24] hw/arm/virt: Use RAM instead of flash for confidential guest firmware Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 21/24] target/arm/kvm-rme: Add DMA remapping for the shared memory region Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 22/24] docs/interop/firmware.json: Add arm-rme firmware feature Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 23/24] hw/arm/boot: Load DTB as is for confidential VMs Mathieu Poirier
2026-09-03 19:36 ` [RFC v4 24/24] hw/arm/boot: Skip bootloader for confidential guests Mathieu Poirier
2026-09-21 4:05 ` [RFC v4 00/24] Add Realm support to QEMU-VMM Gavin Shan
2026-10-02 20:31 ` Mathieu Poirier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eda8ee8f-5f17-4144-b21e-b1d990ee3270@redhat.com \
--to=gshan@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=cohuck@redhat.com \
--cc=eblake@redhat.com \
--cc=enju.kohei@fujitsu.com \
--cc=kchamart@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=lorenzo.pieralisi@linaro.org \
--cc=mathieu.poirier@linaro.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox