[PATCH RFC] x86/hvm: Disallow modifying the APIC_ID register

Andrew Cooper posted 1 patch 2 weeks, 3 days ago
xen/arch/x86/hvm/vlapic.c | 4 ----
1 file changed, 4 deletions(-)
[PATCH RFC] x86/hvm: Disallow modifying the APIC_ID register
Posted by Andrew Cooper 2 weeks, 3 days ago
The APIC_ID register is strictly read-only in x2APIC mode.  In xAPIC mode,
both Intel and AMD document the read-only-ness as being implementation
dependent.

In practice, for Intel it's read-only on any x2APIC-capable hardware (Nehalem
and later, so almost two decades now).  For AMD, the register is writeable but
doing so trucates the 32bit x2APIC ID, so in practice nothing (not even the
firmware) does modify it.

Just as we disallow changing the LAPIC base for ease of supporting APIC
virtualisation extentions, ignore guest writes to the APIC_ID in xAPIC mode.

Note, this still allows the toolstack to configure APIC IDs, for migration and
topology reasons.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <jbeulich@suse.com>
CC: Roger Pau Monné <roger@xenproject.org>
CC: Teddy Astie <teddy.astie@vates.tech>
CC: Jason Andryuk <jason.andryuk@amd.com>
CC: Denis Mukhin <dmukhin@ford.com>
CC: Ross Lagerwall <ross.lagerwall@citrix.com>

This patch is from 2019.  I apparently never got as far as sending it...

This is even lower risk than disallowing changing the xAPIC MMIO window.
There's been no comment or issue with that restriction, which has been in
place since 2018.

It is however RFC.

 * Without this APIC_ID restriction, we need to modify the logical id table in
   response to changes, including disabling AVIC domain-wide if the guest sets
   a layout which can't be expressed.  Intel have gained a similar table with
   their IPI Virt capability on SPR and later.

 * Both Intel and AMD allow writes to the APIC_ID to be accelerated, and give
   a trap VMExit after the backing page has been updated.  So if we're going
   to enforce this restriction then we need the VMExit to undo the
   modification.
---
 xen/arch/x86/hvm/vlapic.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c
index 6698779e227c..358fdd4baf92 100644
--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -795,10 +795,6 @@ void vlapic_reg_write(struct vcpu *v, unsigned int reg, uint32_t val)
 
     switch ( reg )
     {
-    case APIC_ID:
-        vlapic_set_reg(vlapic, APIC_ID, val);
-        break;
-
     case APIC_ESR:
         val = xchg(&vlapic->hw.pending_esr, 0);
         vlapic_set_reg(vlapic, APIC_ESR, val);

base-commit: c4a09c112c391ffc1aea33afff49ffb28156fbdb
-- 
2.39.5


Re: [PATCH RFC] x86/hvm: Disallow modifying the APIC_ID register
Posted by Jan Beulich 2 weeks ago
On 06.11.2026 21:14, Andrew Cooper wrote:
> The APIC_ID register is strictly read-only in x2APIC mode.  In xAPIC mode,
> both Intel and AMD document the read-only-ness as being implementation
> dependent.
> 
> In practice, for Intel it's read-only on any x2APIC-capable hardware (Nehalem
> and later, so almost two decades now).  For AMD, the register is writeable but
> doing so trucates the 32bit x2APIC ID, so in practice nothing (not even the
> firmware) does modify it.
> 
> Just as we disallow changing the LAPIC base for ease of supporting APIC
> virtualisation extentions, ignore guest writes to the APIC_ID in xAPIC mode.
> 
> Note, this still allows the toolstack to configure APIC IDs, for migration and
> topology reasons.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <jbeulich@suse.com>
> CC: Roger Pau Monné <roger@xenproject.org>
> CC: Teddy Astie <teddy.astie@vates.tech>
> CC: Jason Andryuk <jason.andryuk@amd.com>
> CC: Denis Mukhin <dmukhin@ford.com>
> CC: Ross Lagerwall <ross.lagerwall@citrix.com>
> 
> This patch is from 2019.  I apparently never got as far as sending it...
> 
> This is even lower risk than disallowing changing the xAPIC MMIO window.
> There's been no comment or issue with that restriction, which has been in
> place since 2018.
> 
> It is however RFC.
> 
>  * Without this APIC_ID restriction, we need to modify the logical id table in
>    response to changes, including disabling AVIC domain-wide if the guest sets
>    a layout which can't be expressed.  Intel have gained a similar table with
>    their IPI Virt capability on SPR and later.
> 
>  * Both Intel and AMD allow writes to the APIC_ID to be accelerated, and give
>    a trap VMExit after the backing page has been updated.  So if we're going
>    to enforce this restriction then we need the VMExit to undo the
>    modification.

IOW the patch as sent is incomplete?

If we're to undo the prior change, that would include undoing the truncation
you describe earlier on?

Jan