[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN][PATCH] x86/hvm: vlapic: fix RO bits emulation in LVTx regs


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Fri, 26 Sep 2025 14:34:08 +0300
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lDveB0z0IWUTiwfsPqeUVIxWy6C0/DR8E2pKH/EZrCw=; b=mUkSBOoHcdCeuG4mYEBNGXs2C8Mb62b8ytRUG+azaSXk9cY0jeVAD4pH6zle7RHIIIFXEbxYhAgQcuDebHIHsY1mdIyMoVaWpgvxxmptXoVfoNifdfRYClQVaFn35K75dhNGpG9RkIITDa/E0eaGym/kvYlRF56SJd2MQe+C5aaiz8Ubfl07S21op3UJEguCj1FcpZ+jSNgjAE32terf5FT8EJBeHQXjKI8HJsuj8CLHiogmXl5CHo+oJaj57KNMn/0tsgqTqVfA8V51z9Sos2elWv1vbd/4fmui/ylxb1JK2Ttiw1sqMDiJGuJSxGFPyBioaL3hK2RxcTMBexZeqA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eWIpIr+PQdgOuyjL6JXg+wg40RNnQRe9GGLkXc6HalqCsmF6XqDiozbwIuw71DEj4i0La3Ijv8UIdEEbuv2ME+QXmJsPpQIYHWgCojE0ACmPgcBggcigqopfxLEajgxt8CiQKCm5qArfxCN+EYXoahFyisYKh2vnZrSIPXEJzrH0l/Jb7L/7Jcj4WNgENWmhnRWz8ypBrlQeplOBg3KIciA/VbCWd5mDu46EUbBN0ypUi6RfJTKaYg1ReodcFYmjxnzvZv15TnUFPRj6JXWK8XCZ9YZqDElHMFEe0L5fVZvUr4AMUo84wEWl2kzpuI2GEJRDzGzGk15G6Ko4dePfqA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 26 Sep 2025 11:34:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 26.09.25 13:52, Jan Beulich wrote:
On 26.09.2025 12:38, Grygorii Strashko wrote:
On 26.09.25 11:17, Jan Beulich wrote:
On 25.09.2025 21:55, Grygorii Strashko wrote:
From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

The LAPIC LVTx registers have two RO bits:
- all: Delivery Status (DS) bit 12
- LINT0/LINT1: Remote IRR Flag (RIR) bit 14.
    This bit is reserved for other LVTx regs with RAZ/WI access type (MMIO), 
while
    WRMSR (guest_wrmsr_x2apic()) has appropiate checks for reserved bits
    (MBZ access type).

Question is what the behavior is for writing the r/o (but not reserved) bits.
I wasn't able to find any statement in the SDM.

Me too. Usually RO/WI on most HW.
For example, LAPIC MMIO "Write" will be ignored (WRMSR will trigger exception).

Sorry, ignore ^ sentence.


My remark was specifically about WRMSR, and what you say here contradicts ...


--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -880,6 +880,7 @@ void vlapic_reg_write(struct vcpu *v, unsigned int reg, 
uint32_t val)
           if ( vlapic_sw_disabled(vlapic) )
               val |= APIC_LVT_MASKED;
           val &= array_access_nospec(vlapic_lvt_mask, (reg - APIC_LVTT) >> 4);
+        val &= ~(APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING);

There shouldn't be a 2nd &= here; what needs adding should imo be added to
(really: removed from) vlapic_lvt_mask[].

I'll try it.

   (Orthogonal to this I wonder whether
guest_wrmsr_x2apic() wouldn't better use that array, too.)

WRMSR checks for MBZ. RO bits are not MBZ, so masks are different.

... what you say here.

Above reflects current code - guest_wrmsr_x2apic() allows valid RO bits,
then vlapic_reg_write() ignores (W/I) them.
That's why masks are different between guest_wrmsr_x2apic and vlapic_reg_write.


While looking at this, don't we have an issue with CMCI as well?

I see no APIC_CMCI write emulation. only read.

guest_wrmsr_x2apic() has

     case APIC_CMCI:

it will end up calling vlapic_reg_write() which doesn't have case statement for
APIC_CMCI - write ignored.


guest_{rd,wr}msr_x2apic() handle it, but vlapic_reg_write() doesn't. I.e. on
AMD we would fail to deliver #GP when the guest accesses it, while on Intel
we would lose the value written. And we also don't set its mask bit in
vlapic_do_init(). I guess I need to make a patch ...

Is'n it depends on CMCI capability exposing to guest?

Yes, that's part of what I was (effectively) saying.

(have no idea what's CMCI :)

Corrected Machine Check Interrupt.

Looking at:

 #define VLAPIC_VERSION                  0x00050014

which means "Max LVT Entries" = 6 (5+1)

Looking at linux kernel apic.c:
#ifdef CONFIG_X86_MCE_INTEL
        if (maxlvt >= 6) {
                v = apic_read(APIC_LVTCMCI);
                if (!(v & APIC_LVT_MASKED))
                        apic_write(APIC_LVTCMCI, v | APIC_LVT_MASKED);
        }
#endif

Which means Xen never really emulated APIC_CMCI, so wouldn't it be correct to 
just drop APIC_CMCI?
Also, taking into account that it's Intel specific.

--
Best regards,
-grygorii




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.