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

Re: [RFC PATCH] xen: privcmd: fix ioeventfd/ioreq crashing PV domain


  • To: Val Packett <val@xxxxxxxxxxxxxxxxxxxxxx>, Jürgen Groß <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
  • From: Demi Marie Obenour <demiobenour@xxxxxxxxx>
  • Date: Wed, 5 Nov 2025 15:42:14 -0500
  • Autocrypt: addr=demiobenour@xxxxxxxxx; keydata= xsFNBFp+A0oBEADffj6anl9/BHhUSxGTICeVl2tob7hPDdhHNgPR4C8xlYt5q49yB+l2nipd aq+4Gk6FZfqC825TKl7eRpUjMriwle4r3R0ydSIGcy4M6eb0IcxmuPYfbWpr/si88QKgyGSV Z7GeNW1UnzTdhYHuFlk8dBSmB1fzhEYEk0RcJqg4AKoq6/3/UorR+FaSuVwT7rqzGrTlscnT DlPWgRzrQ3jssesI7sZLm82E3pJSgaUoCdCOlL7MMPCJwI8JpPlBedRpe9tfVyfu3euTPLPx wcV3L/cfWPGSL4PofBtB8NUU6QwYiQ9Hzx4xOyn67zW73/G0Q2vPPRst8LBDqlxLjbtx/WLR 6h3nBc3eyuZ+q62HS1pJ5EvUT1vjyJ1ySrqtUXWQ4XlZyoEFUfpJxJoN0A9HCxmHGVckzTRl 5FMWo8TCniHynNXsBtDQbabt7aNEOaAJdE7to0AH3T/Bvwzcp0ZJtBk0EM6YeMLtotUut7h2 Bkg1b//r6bTBswMBXVJ5H44Qf0+eKeUg7whSC9qpYOzzrm7+0r9F5u3qF8ZTx55TJc2g656C 9a1P1MYVysLvkLvS4H+crmxA/i08Tc1h+x9RRvqba4lSzZ6/Tmt60DPM5Sc4R0nSm9BBff0N m0bSNRS8InXdO1Aq3362QKX2NOwcL5YaStwODNyZUqF7izjK4QARAQABzTxEZW1pIE1hcmll IE9iZW5vdXIgKGxvdmVyIG9mIGNvZGluZykgPGRl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wu2DrrwUi6ChRVTUBcj6+/9IJ81H2P2gJk3Ls3AVIxIffLoY34E +MYSfkEjBz0E8CLOcAw7JIwAaeBT
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
  • Delivery-date: Wed, 05 Nov 2025 20:42:34 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 11/4/25 20:16, Val Packett wrote:
> 
> On 11/4/25 9:15 AM, Jürgen Groß wrote:
>> On 15.10.25 21:57, Val Packett wrote:
>>> Starting a virtio backend in a PV domain would panic the kernel in
>>> alloc_ioreq, trying to dereference vma->vm_private_data as a pages
>>> pointer when in reality it stayed as PRIV_VMA_LOCKED.
>>>
>>> Fix by allocating a pages array in mmap_resource in the PV case,
>>> filling it with page info converted from the pfn array. This allows
>>> ioreq to function successfully with a backend provided by a PV dom0.
>>>
>>> Signed-off-by: Val Packett <val@xxxxxxxxxxxxxxxxxxxxxx>
>>> ---
>>> I've been porting the xen-vhost-frontend[1] to Qubes, which runs on 
>>> amd64
>>> and we (still) use PV for dom0. The x86 part didn't give me much 
>>> trouble,
>>> but the first thing I found was this crash due to using a PV domain 
>>> to host
>>> the backend. alloc_ioreq was dereferencing the '1' constant and 
>>> panicking
>>> the dom0 kernel.
>>>
>>> I figured out that I can make a pages array in the expected format 
>>> from the
>>> pfn array where the actual memory mapping happens for the PV case, 
>>> and with
>>> the fix, the ioreq part works: the vhost frontend replies to the probing
>>> sequence and the guest recognizes which virtio device is being provided.
>>>
>>> I still have another thing to debug: the MMIO accesses from the inner 
>>> driver
>>> (e.g. virtio_rng) don't get through to the vhost provider (ioeventfd 
>>> does
>>> not get notified), and manually kicking the eventfd from the frontend
>>> seems to crash... Xen itself?? (no Linux panic on console, just a 
>>> freeze and
>>> quick reboot - will try to set up a serial console now)
>>
>> IMHO for making the MMIO accesses work you'd need to implement 
>> ioreq-server
>> support for PV-domains in the hypervisor. This will be a major 
>> endeavor, so
>> before taking your Linux kernel patch I'd like to see this covered.
> 
> Sorry, I wasn't clear enough.. it's *not* that MMIO accesses don't work.
> 
> I debugged this a bit more, and it turns out:
> 
> 1. the reason why "ioeventfd does not get notified" is because accessing 
> the virtio page (allocated with this privcmd interface) from the kernel 
> was failing. The exchange between the guest driver and the userspace 
> ioreq server has been working perfectly, but the *kernel* access (which 
> is what needs this `struct page` allocation with the current code) was 
> returning nonsense and the check for the virtqueue readiness flag was 
> failing.
> 
> I have noticed and fixed (locally) a bug in this patch: reusing the 
> `pfns` allocation for `errs` in `xen_remap_domain_mfn_array` meant that 
> the actual pfn value was overwritten with a zero ("success" error code), 
> and that's the `pfn` I was using.
> 
> Still, the memory visible in the dom0 kernel at that pfn is not the same 
> allocation that's mapped into the process. Instead, it's some random 
> other memory. I've added a hexdump for it in the ioeventfd notifier and 
> it was returning random stuff from other userspace programs such as "// 
> SPDX-License-Identifier" from a text editor (haha). Actually, *once* it 
> did just work and I've managed to attach a virtio-rng driver and have it 
> fully work.
> 
> Clearly I'm just struggling with the way memory mappings work under PV. 
> Do I need to specifically create a second mapping for the kernel using 
> the same `xen_remap_domain_mfn_array` call?
> 
> 2. the reason why "manually kicking the eventfd from the frontend seems 
> to crash... Xen itself" was actually because that triggered the guest 
> interrupt and I was using the ISA interrupts that required the virtual 
> (IO)APIC to exist, and it doesn't in PVH domains. For now I switched my 
> test setup to HVM to get around that, but I'd need to.. figure out a 
> virq/pirq type setup to route XEN_DMOP_set_isa_irq_level calls over 
> event channels for PV(H) guests.

Still, this should return an error rather than crashing the hypervisor.
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

Attachment: OpenPGP_0xB288B55FFF9C22C1.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


 


Rackspace

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