From: Thomas Huth <thuth@redhat.com>
To: "Clément MATHIEU--DRIF" <clement.mathieu--drif@bull.com>,
"Peter Xu" <peterx@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
Yi Liu <yi.l.liu@intel.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: intel_iommu unit test is also failing
Date: Tue, 5 May 2026 12:15:02 +0200 [thread overview]
Message-ID: <b860aea4-849e-4d0d-83ea-931de4cfc545@redhat.com> (raw)
In-Reply-To: <0e67d95e01efb0823fe07cd556461ad3d9a0709a.camel@bull.com>
On 05/05/2026 11.53, Clément MATHIEU--DRIF wrote:
>
>
> On Tue, 2026-05-05 at 11:45 +0200, Thomas Huth wrote:
>> Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
>>
>>
>> On 05/05/2026 11.27, Clément MATHIEU--DRIF wrote:
>>
>>> I had a bit more time to hook into qemu to check the root cause.
>>>
>>> It seems that testb issues a single byte read (out of the valid size range), as we can see on the following breakpoint:
>>>
>>> ```
>>> Thread 6 "CPU 0/TCG" hit Breakpoint 2, memory_region_dispatch_read (mr=0x55d72883cb30, addr=152, pval=0x7f62d25f4590, op=MO_BSWAP, attrs=...) at ../system/memory.c:1473
>>> 1473 unsigned size = memop_size(op);
>>> (gdb) n
>>> 1474 MemTxResult r;
>>> (gdb) p size
>>> $1 = 1
>>> (gdb)
>>> ```
>>
>>
>> Ouch! That's an excellent finding, Clément ... so GCC 16 is "smart" enough
>> to see that we only want to test the lowest bit here, so it optimizes the
>> code to access only one byte of memory instead of 4 bytes... which would be
>> ok for normal memory, but not for an MMIO register :-/
>>
>> Ugly work-around, to force GCC to read 32 bits:
>>
>> diff --git a/lib/asm-generic/io.h b/lib/asm-generic/io.h
>> --- a/lib/asm-generic/io.h
>> +++ b/lib/asm-generic/io.h
>> @@ -38,7 +38,9 @@ static inline u16 __raw_readw(const volatile void *addr)
>> #ifndef __raw_readl
>> static inline u32 __raw_readl(const volatile void *addr)
>> {
>> - return *(const volatile u32 *)addr;
>> + u32 val = *(const volatile u32 *)addr;
>> + asm volatile ("\n" : : "r"(addr));
>> + return val;
>> }
>> #endif
>>
>> ... but I wonder whether this should rather be treated as a bug in GCC
>> instead, since it should IMHO really not change the access size for a
>> volatile memory access?
>
> Volatile is expected to make sure that the read side effect is visible.
> I don't know if the size of the access is in the scope of this constraint or not o.O
Maybe we should simply adjust the read/write functions in the pci-edu.h
code, WDYT:
diff --git a/lib/pci-edu.h b/lib/pci-edu.h
--- a/lib/pci-edu.h
+++ b/lib/pci-edu.h
@@ -59,24 +59,24 @@ struct pci_edu_dev {
static inline uint64_t edu_reg_readq(struct pci_edu_dev *dev, int reg)
{
- return __raw_readq(edu_reg(dev, reg));
+ return readq(edu_reg(dev, reg));
}
static inline uint32_t edu_reg_readl(struct pci_edu_dev *dev, int reg)
{
- return __raw_readl(edu_reg(dev, reg));
+ return readl(edu_reg(dev, reg));
}
static inline void edu_reg_writeq(struct pci_edu_dev *dev, int reg,
uint64_t val)
{
- __raw_writeq(val, edu_reg(dev, reg));
+ writeq(val, edu_reg(dev, reg));
}
static inline void edu_reg_writel(struct pci_edu_dev *dev, int reg,
uint32_t val)
{
- __raw_writel(val, edu_reg(dev, reg));
+ writel(val, edu_reg(dev, reg));
}
bool edu_init(struct pci_edu_dev *dev);
... it might be good to use the non-raw functions here for ordered access
anyway...
Thomas
next prev parent reply other threads:[~2026-05-05 10:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240604143507.1041901-1-pbonzini@redhat.com>
2026-05-04 7:58 ` [PATCH kvm-unit-tests] realmode: load above stack Thomas Huth
2026-05-04 8:07 ` intel_iommu unit test is also failing (was: Re: [PATCH kvm-unit-tests] realmode: load above stack) Thomas Huth
2026-05-04 15:45 ` Peter Xu
2026-05-05 5:49 ` Clément MATHIEU--DRIF
2026-05-05 6:37 ` Clément MATHIEU--DRIF
2026-05-05 7:36 ` Clément MATHIEU--DRIF
2026-05-05 9:27 ` Clément MATHIEU--DRIF
2026-05-05 9:45 ` intel_iommu unit test is also failing Thomas Huth
2026-05-05 9:53 ` Clément MATHIEU--DRIF
2026-05-05 10:15 ` Thomas Huth [this message]
2026-05-05 10:23 ` Michael S. Tsirkin
2026-05-05 10:34 ` Thomas Huth
2026-05-05 10:53 ` Michael S. Tsirkin
2026-05-05 11:38 ` Thomas Huth
2026-05-05 12:33 ` Michael S. Tsirkin
2026-05-05 17:08 ` Thomas Huth
2026-05-05 11:39 ` Clément MATHIEU--DRIF
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=b860aea4-849e-4d0d-83ea-931de4cfc545@redhat.com \
--to=thuth@redhat.com \
--cc=clement.mathieu--drif@bull.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=yi.l.liu@intel.com \
/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