From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jason Thorpe <thorpej@me.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, qemu-devel@nongnu.org
Subject: Re: Please help me understand VIRTIO_F_IOMMU_PLATFORM
Date: Wed, 6 Oct 2021 04:26:47 -0400 [thread overview]
Message-ID: <20211006042222-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <4DB2A4EE-5628-4505-A173-6098F4CFCDBD@me.com>
On Wed, Aug 18, 2021 at 05:35:24AM -0700, Jason Thorpe wrote:
>
> > On Aug 18, 2021, at 12:58 AM, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> wrote:
> >
> > On 31/07/2021 16:41, Jason Thorpe wrote:
> >
> > (added Michael on CC)
> >
> > Hi Jason,
> >
> > Thanks for looking at this! I've had previous discussions with Martin trying to figure out why virtio-blk-pci doesn't work with Netbsd/sparc64 so glad that you've been able to find the underlying cause.
> >
> > My read on VIRTIO_F_IOMMU_PLATFORM is that this is declaring host IOMMU support so the implementation on the guest should not be relevant here.
The name is confusing. The spec renamed it to VIRTIO_F_ACCESS_PLATFORM
now, with this explanation:
\item[VIRTIO_F_ACCESS_PLATFORM(33)] This feature indicates that
the device can be used on a platform where device access to data
in memory is limited and/or translated. E.g. this is the case if the device can be located
behind an IOMMU that translates bus addresses from the device into physical
addresses in memory, if the device can be limited to only access
certain memory addresses or if special commands such as
a cache flush can be needed to synchronise data in memory with
the device. Whether accesses are actually limited or translated
is described by platform-specific means.
If this feature bit is set to 0, then the device
has same access to memory addresses supplied to it as the
driver has.
In particular, the device will always use physical addresses
matching addresses used by the driver (typically meaning
physical addresses used by the CPU)
and not translated further, and can access any address supplied to it by
the driver. When clear, this overrides any platform-specific description of
whether device access is limited or translated in any way, e.g.
whether an IOMMU may be present.
> That’s basically the conclusion I came to, as well, but I still wasn’t quite sure how the host IOMMU was relevant so I wasn’t quite willing to stick my neck out :-)
>
> > Testing Linux/sparc64 boot from a virtio-blk-pci device on current git master shows I can boot from a virtio-blk-pci device without any problem, even though the existing code fails the has_iommu check and vdev->dma_as gets set to address_space_memory which is why I haven't spotted this before.
> >
> > Stepping through the code shows that klass->get_dma_as() is pointing to virtio_pci_get_dma_as() which in turn returns pci_get_address_space(dev) which looks correct to me. I think that the logic to set vdev->dma_as is incorrect here since qemu-system-sparc64 has an emulated IOMMU with its own address space independent of whether the host has an IOMMU.
>
> Right, this more-or-less the same situation as qemu-system-alpha. I’m curious why the Linux/sparc64 guest is able to use VirtIO without the patch, though. I guess that VirtIO client implementation is skipping the normal platform DMA mapping step and is just poking physical addresses in directly? The NetBSD VirtIO client code behaves like all other NetBSD PCI drivers and does NOT skip the platform DMA mapping step.
How did it work then?
If the driver wants to use DMA addresses normally it has to negotiate VIRTIO_F_ACCESS_PLATFORM.
Without it the assumption is that it uses physical addresses.
> > I modified your patch slightly as below and confirmed that I can still boot Linux/sparc64 here:
> >
> > diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
> > index 859978d248..ee178b8223 100644
> > --- a/hw/virtio/virtio-bus.c
> > +++ b/hw/virtio/virtio-bus.c
> > @@ -82,9 +82,11 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
> > return;
> > }
> >
> > - if (klass->get_dma_as != NULL && has_iommu) {
> > - virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
> > + if (klass->get_dma_as != NULL) {
> > vdev->dma_as = klass->get_dma_as(qbus->parent);
> > + if (has_iommu) {
> > + virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
> > + }
> > } else {
> > vdev->dma_as = &address_space_memory;
> > }
> >
> > Michael: can you comment further on whether the analysis and patch above are correct?
> >
> >
> > ATB,
> >
> > Mark.
>
> -- thorpej
Maybe this platform simply has to mandate VIRTIO_F_ACCESS_PLATFORM then.
I would be very reluctant to add to the pile of hacks around legacy
devices.
--
MST
prev parent reply other threads:[~2021-10-06 8:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-31 15:41 Please help me understand VIRTIO_F_IOMMU_PLATFORM Jason Thorpe
2021-08-18 7:58 ` Mark Cave-Ayland
2021-08-18 12:35 ` Jason Thorpe
2021-10-06 8:26 ` Michael S. Tsirkin [this message]
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=20211006042222-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
--cc=thorpej@me.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;
as well as URLs for NNTP newsgroup(s).