diff mbox

[v2,2/2] vring: Force use of DMA API for ARM-based systems

Message ID 4833e705fb6841fbfdbee3b1a21a7bc917292410.1484070340.git.robin.murphy@arm.com
State New
Headers show

Commit Message

Robin Murphy Jan. 10, 2017, 5:51 p.m. UTC
From: Will Deacon <will.deacon@arm.com>


Booting Linux on an ARM fastmodel containing an SMMU emulation results
in an unexpected I/O page fault from the legacy virtio-blk PCI device:

[    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:
[    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010
[    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000
[    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002
[    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000
[    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:
[    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010
[    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000
[    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000
[    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

<system hangs failing to read partition table>

This is because the virtio-blk is behind an SMMU, so we have consequently
swizzled its DMA ops and configured the SMMU to translate accesses. This
then requires the vring code to use the DMA API to establish translations,
otherwise all transactions will result in fatal faults and termination.

Given that ARM-based systems only see an SMMU if one is really present
(the topology is all described by firmware tables such as device-tree or
IORT), then we can safely use the DMA API for all virtio devices.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>

---
 drivers/virtio/virtio_ring.c | 4 ++++
 1 file changed, 4 insertions(+)

-- 
2.10.2.dirty


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Comments

Michael S. Tsirkin Jan. 10, 2017, 11:33 p.m. UTC | #1
On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:
> From: Will Deacon <will.deacon@arm.com>

> 

> Booting Linux on an ARM fastmodel containing an SMMU emulation results

> in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> 

> [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> 

> <system hangs failing to read partition table>

> 

> This is because the virtio-blk is behind an SMMU, so we have consequently

> swizzled its DMA ops and configured the SMMU to translate accesses. This

> then requires the vring code to use the DMA API to establish translations,

> otherwise all transactions will result in fatal faults and termination.

> 

> Given that ARM-based systems only see an SMMU if one is really present

> (the topology is all described by firmware tables such as device-tree or

> IORT), then we can safely use the DMA API for all virtio devices.

> 

> Cc: Andy Lutomirski <luto@kernel.org>

> Cc: Michael S. Tsirkin <mst@redhat.com>

> Signed-off-by: Will Deacon <will.deacon@arm.com>


I'd like to better understand then need for this one.
Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

I'd rather we avoided need for more hacks and just
have everyone switch to that.


> ---

>  drivers/virtio/virtio_ring.c | 4 ++++

>  1 file changed, 4 insertions(+)

> 

> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c

> index 409aeaa49246..447245f2c813 100644

> --- a/drivers/virtio/virtio_ring.c

> +++ b/drivers/virtio/virtio_ring.c

> @@ -159,6 +159,10 @@ static bool vring_use_dma_api(struct virtio_device *vdev)

>  	if (xen_domain())

>  		return true;

>  

> +	/* On ARM-based machines, the DMA ops will do the right thing */

> +	if (IS_ENABLED(CONFIG_ARM) || IS_ENABLED(CONFIG_ARM64))

> +		return true;

> +

>  	return false;

>  }

>  

> -- 

> 2.10.2.dirty


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 11, 2017, 10:01 a.m. UTC | #2
On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:
> On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> > From: Will Deacon <will.deacon@arm.com>

> > 

> > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > 

> > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > 

> > <system hangs failing to read partition table>

> > 

> > This is because the virtio-blk is behind an SMMU, so we have consequently

> > swizzled its DMA ops and configured the SMMU to translate accesses. This

> > then requires the vring code to use the DMA API to establish translations,

> > otherwise all transactions will result in fatal faults and termination.

> > 

> > Given that ARM-based systems only see an SMMU if one is really present

> > (the topology is all described by firmware tables such as device-tree or

> > IORT), then we can safely use the DMA API for all virtio devices.

> > 

> > Cc: Andy Lutomirski <luto@kernel.org>

> > Cc: Michael S. Tsirkin <mst@redhat.com>

> > Signed-off-by: Will Deacon <will.deacon@arm.com>

> 

> I'd like to better understand then need for this one.

> Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> 

> I'd rather we avoided need for more hacks and just

> have everyone switch to that.


There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

1. It doesn't exist for legacy devices, which are all we have on the
   platform in question.

2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied
   my patch ;). Thanks.

In which case, for non-legacy devices we should definitely be using
VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the
world of flying cars, could we unconditionally set the DMA ops on ARM
for legacy devices? The alternative is disabling the SMMU altogether,
but that's less than ideal because there are non-virtio devices on the
same PCI bus.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Andy Lutomirski Jan. 11, 2017, 6:12 p.m. UTC | #3
On Wed, Jan 11, 2017 at 2:01 AM, Will Deacon <will.deacon@arm.com> wrote:
> On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

>> On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

>> > From: Will Deacon <will.deacon@arm.com>

>> >

>> > Booting Linux on an ARM fastmodel containing an SMMU emulation results

>> > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

>> >

>> > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

>> > [    1.211800] arm-smmu-v3 2b400000.smmu:   0x00000000fffff010

>> > [    1.211880] arm-smmu-v3 2b400000.smmu:   0x0000020800000000

>> > [    1.211959] arm-smmu-v3 2b400000.smmu:   0x00000008fa081002

>> > [    1.212075] arm-smmu-v3 2b400000.smmu:   0x0000000000000000

>> > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

>> > [    1.212234] arm-smmu-v3 2b400000.smmu:   0x00000000fffff010

>> > [    1.212314] arm-smmu-v3 2b400000.smmu:   0x0000020800000000

>> > [    1.212394] arm-smmu-v3 2b400000.smmu:   0x00000008fa081000

>> > [    1.212471] arm-smmu-v3 2b400000.smmu:   0x0000000000000000

>> >

>> > <system hangs failing to read partition table>

>> >

>> > This is because the virtio-blk is behind an SMMU, so we have consequently

>> > swizzled its DMA ops and configured the SMMU to translate accesses. This

>> > then requires the vring code to use the DMA API to establish translations,

>> > otherwise all transactions will result in fatal faults and termination.

>> >

>> > Given that ARM-based systems only see an SMMU if one is really present

>> > (the topology is all described by firmware tables such as device-tree or

>> > IORT), then we can safely use the DMA API for all virtio devices.

>> >

>> > Cc: Andy Lutomirski <luto@kernel.org>

>> > Cc: Michael S. Tsirkin <mst@redhat.com>

>> > Signed-off-by: Will Deacon <will.deacon@arm.com>

>>

>> I'd like to better understand then need for this one.

>> Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

>>

>> I'd rather we avoided need for more hacks and just

>> have everyone switch to that.

>

> There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

>

> 1. It doesn't exist for legacy devices, which are all we have on the

>    platform in question.

>

> 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

>    my patch ;). Thanks.

>

> In which case, for non-legacy devices we should definitely be using

> VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> world of flying cars, could we unconditionally set the DMA ops on ARM

> for legacy devices? The alternative is disabling the SMMU altogether,

> but that's less than ideal because there are non-virtio devices on the

> same PCI bus.


Also, on ARM, using the DMA API appears to *always* be the correct
approach.  Why not do it all the time, then?  The non-DMA-API path is
a legacy thing that is needed because a few platforms incorrectly
enumerate their IOMMUs.  ARM gets it right, so I don't see why ARM
should be subject to the legacy mess.

Even on x86, it should be possible to get the code into a state where
using DMA ops is always correct.

--Andy

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 12, 2017, 10:12 p.m. UTC | #4
On Wed, Jan 11, 2017 at 10:01:39AM +0000, Will Deacon wrote:
> On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> > On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> > > From: Will Deacon <will.deacon@arm.com>

> > > 

> > > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > > 

> > > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > 

> > > <system hangs failing to read partition table>

> > > 

> > > This is because the virtio-blk is behind an SMMU, so we have consequently

> > > swizzled its DMA ops and configured the SMMU to translate accesses. This

> > > then requires the vring code to use the DMA API to establish translations,

> > > otherwise all transactions will result in fatal faults and termination.

> > > 

> > > Given that ARM-based systems only see an SMMU if one is really present

> > > (the topology is all described by firmware tables such as device-tree or

> > > IORT), then we can safely use the DMA API for all virtio devices.

> > > 

> > > Cc: Andy Lutomirski <luto@kernel.org>

> > > Cc: Michael S. Tsirkin <mst@redhat.com>

> > > Signed-off-by: Will Deacon <will.deacon@arm.com>

> > 

> > I'd like to better understand then need for this one.

> > Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> > 

> > I'd rather we avoided need for more hacks and just

> > have everyone switch to that.

> 

> There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> 

> 1. It doesn't exist for legacy devices, which are all we have on the

>    platform in question.

> 

> 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

>    my patch ;). Thanks.

> 

> In which case, for non-legacy devices we should definitely be using

> VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> world of flying cars, could we unconditionally set the DMA ops on ARM

> for legacy devices? The alternative is disabling the SMMU altogether,

> but that's less than ideal because there are non-virtio devices on the

> same PCI bus.

> 

> Will


I'd rather people didn't use SMMU with legacy devices.
Can't you guys just code up the virtio 1 layout in QEMU?
I took a look and it's not a big deal now that two other
transports converted, except mmio code in QEMU doesn't
use linux header to it's a bit messy.
I'll send a patch to clean that up.

-- 
MST

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 13, 2017, 9:25 a.m. UTC | #5
On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:
> On Wed, Jan 11, 2017 at 10:01:39AM +0000, Will Deacon wrote:

> > On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> > > On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> > > > From: Will Deacon <will.deacon@arm.com>

> > > > 

> > > > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > > > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > > > 

> > > > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > > > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > > > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > 

> > > > <system hangs failing to read partition table>

> > > > 

> > > > This is because the virtio-blk is behind an SMMU, so we have consequently

> > > > swizzled its DMA ops and configured the SMMU to translate accesses. This

> > > > then requires the vring code to use the DMA API to establish translations,

> > > > otherwise all transactions will result in fatal faults and termination.

> > > > 

> > > > Given that ARM-based systems only see an SMMU if one is really present

> > > > (the topology is all described by firmware tables such as device-tree or

> > > > IORT), then we can safely use the DMA API for all virtio devices.

> > > > 

> > > > Cc: Andy Lutomirski <luto@kernel.org>

> > > > Cc: Michael S. Tsirkin <mst@redhat.com>

> > > > Signed-off-by: Will Deacon <will.deacon@arm.com>

> > > 

> > > I'd like to better understand then need for this one.

> > > Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> > > 

> > > I'd rather we avoided need for more hacks and just

> > > have everyone switch to that.

> > 

> > There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> > 

> > 1. It doesn't exist for legacy devices, which are all we have on the

> >    platform in question.

> > 

> > 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

> >    my patch ;). Thanks.

> > 

> > In which case, for non-legacy devices we should definitely be using

> > VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> > world of flying cars, could we unconditionally set the DMA ops on ARM

> > for legacy devices? The alternative is disabling the SMMU altogether,

> > but that's less than ideal because there are non-virtio devices on the

> > same PCI bus.

> > 

> 

> I'd rather people didn't use SMMU with legacy devices.


I'm afraid we've been doing that for two years and the model already
exists in a mature state, being actively used for development and
validation by ARM and our partners. One of the big things its used for
is to develop SMMU and GIC (our interrupt controller) code with PCI, so
dropping the SMMU from the picture isn't an option.

> Can't you guys just code up the virtio 1 layout in QEMU?

> I took a look and it's not a big deal now that two other

> transports converted, except mmio code in QEMU doesn't

> use linux header to it's a bit messy.

> I'll send a patch to clean that up.


If the model ever changes in this area (which isn't planned atm), the
right thing to do would be to move to modern virtio. However, we're stuck
with what we have for the forseeable future and it works just fine if we
use the DMA API. If we don't use it, Linux no longer boots because it
installs the SMMU-backed DMA ops for the virtio devices and everything
faults.

I really don't understand why this is controversial.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 13, 2017, 9:40 a.m. UTC | #6
On Wed, Jan 11, 2017 at 10:12:36AM -0800, Andy Lutomirski wrote:
> On Wed, Jan 11, 2017 at 2:01 AM, Will Deacon <will.deacon@arm.com> wrote:

> > On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> >> On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> >> > From: Will Deacon <will.deacon@arm.com>

> >> >

> >> > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> >> > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> >> >

> >> > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> >> > [    1.211800] arm-smmu-v3 2b400000.smmu:   0x00000000fffff010

> >> > [    1.211880] arm-smmu-v3 2b400000.smmu:   0x0000020800000000

> >> > [    1.211959] arm-smmu-v3 2b400000.smmu:   0x00000008fa081002

> >> > [    1.212075] arm-smmu-v3 2b400000.smmu:   0x0000000000000000

> >> > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> >> > [    1.212234] arm-smmu-v3 2b400000.smmu:   0x00000000fffff010

> >> > [    1.212314] arm-smmu-v3 2b400000.smmu:   0x0000020800000000

> >> > [    1.212394] arm-smmu-v3 2b400000.smmu:   0x00000008fa081000

> >> > [    1.212471] arm-smmu-v3 2b400000.smmu:   0x0000000000000000

> >> >

> >> > <system hangs failing to read partition table>

> >> >

> >> > This is because the virtio-blk is behind an SMMU, so we have consequently

> >> > swizzled its DMA ops and configured the SMMU to translate accesses. This

> >> > then requires the vring code to use the DMA API to establish translations,

> >> > otherwise all transactions will result in fatal faults and termination.

> >> >

> >> > Given that ARM-based systems only see an SMMU if one is really present

> >> > (the topology is all described by firmware tables such as device-tree or

> >> > IORT), then we can safely use the DMA API for all virtio devices.

> >> >

> >> > Cc: Andy Lutomirski <luto@kernel.org>

> >> > Cc: Michael S. Tsirkin <mst@redhat.com>

> >> > Signed-off-by: Will Deacon <will.deacon@arm.com>

> >>

> >> I'd like to better understand then need for this one.

> >> Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> >>

> >> I'd rather we avoided need for more hacks and just

> >> have everyone switch to that.

> >

> > There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> >

> > 1. It doesn't exist for legacy devices, which are all we have on the

> >    platform in question.

> >

> > 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

> >    my patch ;). Thanks.

> >

> > In which case, for non-legacy devices we should definitely be using

> > VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> > world of flying cars, could we unconditionally set the DMA ops on ARM

> > for legacy devices? The alternative is disabling the SMMU altogether,

> > but that's less than ideal because there are non-virtio devices on the

> > same PCI bus.

> 

> Also, on ARM, using the DMA API appears to *always* be the correct

> approach.  Why not do it all the time, then?  The non-DMA-API path is

> a legacy thing that is needed because a few platforms incorrectly

> enumerate their IOMMUs.  ARM gets it right, so I don't see why ARM

> should be subject to the legacy mess.


That's what my patch does, but since modern virtio has the
VIRTIO_F_IOMMU_PLATFORM flag (and the spec says if it's not present then
the driver must pass physical addresses), it feels to me like we should
just honour that so that different architectures all have the same
behaviour. For legacy devices, the horse has bolted and we need
arch-specific behaviours to keep things working.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 13, 2017, 4:46 p.m. UTC | #7
On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:
> On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > On Wed, Jan 11, 2017 at 10:01:39AM +0000, Will Deacon wrote:

> > > On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> > > > On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> > > > > From: Will Deacon <will.deacon@arm.com>

> > > > > 

> > > > > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > > > > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > > > > 

> > > > > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > > > > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > > > > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > > 

> > > > > <system hangs failing to read partition table>

> > > > > 

> > > > > This is because the virtio-blk is behind an SMMU, so we have consequently

> > > > > swizzled its DMA ops and configured the SMMU to translate accesses. This

> > > > > then requires the vring code to use the DMA API to establish translations,

> > > > > otherwise all transactions will result in fatal faults and termination.

> > > > > 

> > > > > Given that ARM-based systems only see an SMMU if one is really present

> > > > > (the topology is all described by firmware tables such as device-tree or

> > > > > IORT), then we can safely use the DMA API for all virtio devices.

> > > > > 

> > > > > Cc: Andy Lutomirski <luto@kernel.org>

> > > > > Cc: Michael S. Tsirkin <mst@redhat.com>

> > > > > Signed-off-by: Will Deacon <will.deacon@arm.com>

> > > > 

> > > > I'd like to better understand then need for this one.

> > > > Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> > > > 

> > > > I'd rather we avoided need for more hacks and just

> > > > have everyone switch to that.

> > > 

> > > There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> > > 

> > > 1. It doesn't exist for legacy devices, which are all we have on the

> > >    platform in question.

> > > 

> > > 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

> > >    my patch ;). Thanks.

> > > 

> > > In which case, for non-legacy devices we should definitely be using

> > > VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> > > world of flying cars, could we unconditionally set the DMA ops on ARM

> > > for legacy devices? The alternative is disabling the SMMU altogether,

> > > but that's less than ideal because there are non-virtio devices on the

> > > same PCI bus.

> > > 

> > 

> > I'd rather people didn't use SMMU with legacy devices.

> 

> I'm afraid we've been doing that for two years and the model already

> exists in a mature state, being actively used for development and

> validation by ARM and our partners. One of the big things its used for

> is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> dropping the SMMU from the picture isn't an option.


Oh so this fixes a regression?  This is something I didn't realize.
A "Fixes:" tag can't hurt here.  I then wonder
might DMA ops ever use a DMA address which isn't a physical address
from QEMU point of view? If that happens, this hack breaks
because in legacy mode QEMU still uses the GPA.

> > Can't you guys just code up the virtio 1 layout in QEMU?

> > I took a look and it's not a big deal now that two other

> > transports converted, except mmio code in QEMU doesn't

> > use linux header to it's a bit messy.

> > I'll send a patch to clean that up.

> 

> If the model ever changes in this area (which isn't planned atm), the

> right thing to do would be to move to modern virtio. However, we're stuck

> with what we have for the forseeable future and it works just fine if we

> use the DMA API. If we don't use it, Linux no longer boots because it

> installs the SMMU-backed DMA ops for the virtio devices and everything

> faults.

> 

> I really don't understand why this is controversial.

> 

> Will


I agree we need to keep working things working. I just don't yet
understand what change broke things and how did it happen - legacy
devices used to just poke at guest PA from QEMU, what does it matter
that there are changes in DMA ops if neither host nor guest use them for
legacy setups?

I guess that's just me now knowing about how DMA ops work on SMMU
or missing some other basic point about SMMU.

I take your word that it's the right thing to do, but I'd like to figure
it out before merging this.  I'll read up in the coming days to make
sure I understand what the patch does, any pointers welcome.

-- 
MST

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 13, 2017, 4:59 p.m. UTC | #8
On Wed, Jan 11, 2017 at 10:12:36AM -0800, Andy Lutomirski wrote:
> On Wed, Jan 11, 2017 at 2:01 AM, Will Deacon <will.deacon@arm.com> wrote:

> > On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> >> On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> >> > From: Will Deacon <will.deacon@arm.com>

> >> >

> >> > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> >> > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> >> >

> >> > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> >> > [    1.211800] arm-smmu-v3 2b400000.smmu:   0x00000000fffff010

> >> > [    1.211880] arm-smmu-v3 2b400000.smmu:   0x0000020800000000

> >> > [    1.211959] arm-smmu-v3 2b400000.smmu:   0x00000008fa081002

> >> > [    1.212075] arm-smmu-v3 2b400000.smmu:   0x0000000000000000

> >> > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> >> > [    1.212234] arm-smmu-v3 2b400000.smmu:   0x00000000fffff010

> >> > [    1.212314] arm-smmu-v3 2b400000.smmu:   0x0000020800000000

> >> > [    1.212394] arm-smmu-v3 2b400000.smmu:   0x00000008fa081000

> >> > [    1.212471] arm-smmu-v3 2b400000.smmu:   0x0000000000000000

> >> >

> >> > <system hangs failing to read partition table>

> >> >

> >> > This is because the virtio-blk is behind an SMMU, so we have consequently

> >> > swizzled its DMA ops and configured the SMMU to translate accesses. This

> >> > then requires the vring code to use the DMA API to establish translations,

> >> > otherwise all transactions will result in fatal faults and termination.

> >> >

> >> > Given that ARM-based systems only see an SMMU if one is really present

> >> > (the topology is all described by firmware tables such as device-tree or

> >> > IORT), then we can safely use the DMA API for all virtio devices.

> >> >

> >> > Cc: Andy Lutomirski <luto@kernel.org>

> >> > Cc: Michael S. Tsirkin <mst@redhat.com>

> >> > Signed-off-by: Will Deacon <will.deacon@arm.com>

> >>

> >> I'd like to better understand then need for this one.

> >> Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> >>

> >> I'd rather we avoided need for more hacks and just

> >> have everyone switch to that.

> >

> > There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> >

> > 1. It doesn't exist for legacy devices, which are all we have on the

> >    platform in question.

> >

> > 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

> >    my patch ;). Thanks.

> >

> > In which case, for non-legacy devices we should definitely be using

> > VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> > world of flying cars, could we unconditionally set the DMA ops on ARM

> > for legacy devices? The alternative is disabling the SMMU altogether,

> > but that's less than ideal because there are non-virtio devices on the

> > same PCI bus.

> 

> Also, on ARM, using the DMA API appears to *always* be the correct

> approach.  Why not do it all the time, then?  The non-DMA-API path is

> a legacy thing that is needed because a few platforms incorrectly

> enumerate their IOMMUs.  ARM gets it right, so I don't see why ARM

> should be subject to the legacy mess.


I didn't realize ARM gets this right. QEMU still pokes at
physical addresses directly in legacy mode so I wonder how could
that be the case. I'll try to find out.

> Even on x86, it should be possible to get the code into a state where

> using DMA ops is always correct.

> 

> --Andy


This I could totally get behind. A driver would install some per device
flag to make it figure out IOMMU does not apply, and in a portable way
since at least x86 and PPC need this, maybe more. This would/should
also handle the bug that admin can bind vfio to legacy virtio
devices even without the noiommu mode.

-- 
MST

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 13, 2017, 5:21 p.m. UTC | #9
On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:
> On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > On Wed, Jan 11, 2017 at 10:01:39AM +0000, Will Deacon wrote:

> > > > On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> > > > > On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> > > > > > From: Will Deacon <will.deacon@arm.com>

> > > > > > 

> > > > > > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > > > > > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > > > > > 

> > > > > > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > > > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > > > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > > > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > > > > > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > > > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > > > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > > > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > > > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > > > > > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > > > 

> > > > > > <system hangs failing to read partition table>

> > > > > > 

> > > > > > This is because the virtio-blk is behind an SMMU, so we have consequently

> > > > > > swizzled its DMA ops and configured the SMMU to translate accesses. This

> > > > > > then requires the vring code to use the DMA API to establish translations,

> > > > > > otherwise all transactions will result in fatal faults and termination.

> > > > > > 

> > > > > > Given that ARM-based systems only see an SMMU if one is really present

> > > > > > (the topology is all described by firmware tables such as device-tree or

> > > > > > IORT), then we can safely use the DMA API for all virtio devices.

> > > > > > 

> > > > > > Cc: Andy Lutomirski <luto@kernel.org>

> > > > > > Cc: Michael S. Tsirkin <mst@redhat.com>

> > > > > > Signed-off-by: Will Deacon <will.deacon@arm.com>

> > > > > 

> > > > > I'd like to better understand then need for this one.

> > > > > Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> > > > > 

> > > > > I'd rather we avoided need for more hacks and just

> > > > > have everyone switch to that.

> > > > 

> > > > There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> > > > 

> > > > 1. It doesn't exist for legacy devices, which are all we have on the

> > > >    platform in question.

> > > > 

> > > > 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

> > > >    my patch ;). Thanks.

> > > > 

> > > > In which case, for non-legacy devices we should definitely be using

> > > > VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> > > > world of flying cars, could we unconditionally set the DMA ops on ARM

> > > > for legacy devices? The alternative is disabling the SMMU altogether,

> > > > but that's less than ideal because there are non-virtio devices on the

> > > > same PCI bus.

> > > > 

> > > 

> > > I'd rather people didn't use SMMU with legacy devices.

> > 

> > I'm afraid we've been doing that for two years and the model already

> > exists in a mature state, being actively used for development and

> > validation by ARM and our partners. One of the big things its used for

> > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > dropping the SMMU from the picture isn't an option.

> 

> Oh so this fixes a regression?  This is something I didn't realize.


Yes, thanks. The regression came about because we implemented SMMU-backed
DMA ops and only then was it apparent that the virtio stuff was bypassing
even with translation enabled (because it wasn't using the DMA API).

> A "Fixes:" tag can't hurt here.  I then wonder

> might DMA ops ever use a DMA address which isn't a physical address

> from QEMU point of view? If that happens, this hack breaks

> because in legacy mode QEMU still uses the GPA.


If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,
because we won't swizzle the DMA ops for the master device. If QEMU does
advertise an SMMU, then we'll allocate DMA addresses to fit within the
the intersection of the SMMU aperture and device's DMA mask.

> > > Can't you guys just code up the virtio 1 layout in QEMU?

> > > I took a look and it's not a big deal now that two other

> > > transports converted, except mmio code in QEMU doesn't

> > > use linux header to it's a bit messy.

> > > I'll send a patch to clean that up.

> > 

> > If the model ever changes in this area (which isn't planned atm), the

> > right thing to do would be to move to modern virtio. However, we're stuck

> > with what we have for the forseeable future and it works just fine if we

> > use the DMA API. If we don't use it, Linux no longer boots because it

> > installs the SMMU-backed DMA ops for the virtio devices and everything

> > faults.

> > 

> > I really don't understand why this is controversial.

> > 

> I agree we need to keep working things working. I just don't yet

> understand what change broke things and how did it happen - legacy

> devices used to just poke at guest PA from QEMU, what does it matter

> that there are changes in DMA ops if neither host nor guest use them for

> legacy setups?


The problem is that platforms which advertise an SMMU downstream of the
(virtual) PCI-RC now automatically have their PCI devices attached to the
SMMU, so if they don't use the DMA ops then they will fault.

> I guess that's just me now knowing about how DMA ops work on SMMU

> or missing some other basic point about SMMU.

> 

> I take your word that it's the right thing to do, but I'd like to figure

> it out before merging this.  I'll read up in the coming days to make

> sure I understand what the patch does, any pointers welcome.


Ok, thanks. Just shout if you have more questions. I'm also happy with
only doing this for legacy devices, given that modern virtio has the
IOMMU flag.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 13, 2017, 6:23 p.m. UTC | #10
On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:
> On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > On Wed, Jan 11, 2017 at 10:01:39AM +0000, Will Deacon wrote:

> > > > > On Wed, Jan 11, 2017 at 01:33:31AM +0200, Michael S. Tsirkin wrote:

> > > > > > On Tue, Jan 10, 2017 at 05:51:18PM +0000, Robin Murphy wrote:

> > > > > > > From: Will Deacon <will.deacon@arm.com>

> > > > > > > 

> > > > > > > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > > > > > > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > > > > > > 

> > > > > > > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > > > > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > > > > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > > > > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > > > > > > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > > > > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > > > > > > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > > > > > > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > > > > > > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > > > > > > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > > > > > > 

> > > > > > > <system hangs failing to read partition table>

> > > > > > > 

> > > > > > > This is because the virtio-blk is behind an SMMU, so we have consequently

> > > > > > > swizzled its DMA ops and configured the SMMU to translate accesses. This

> > > > > > > then requires the vring code to use the DMA API to establish translations,

> > > > > > > otherwise all transactions will result in fatal faults and termination.

> > > > > > > 

> > > > > > > Given that ARM-based systems only see an SMMU if one is really present

> > > > > > > (the topology is all described by firmware tables such as device-tree or

> > > > > > > IORT), then we can safely use the DMA API for all virtio devices.

> > > > > > > 

> > > > > > > Cc: Andy Lutomirski <luto@kernel.org>

> > > > > > > Cc: Michael S. Tsirkin <mst@redhat.com>

> > > > > > > Signed-off-by: Will Deacon <will.deacon@arm.com>

> > > > > > 

> > > > > > I'd like to better understand then need for this one.

> > > > > > Can't the device in question just set VIRTIO_F_IOMMU_PLATFORM ?

> > > > > > 

> > > > > > I'd rather we avoided need for more hacks and just

> > > > > > have everyone switch to that.

> > > > > 

> > > > > There are a couple of problems with VIRTIO_F_IOMMU_PLATFORM:

> > > > > 

> > > > > 1. It doesn't exist for legacy devices, which are all we have on the

> > > > >    platform in question.

> > > > > 

> > > > > 2. It's not documented in the virtio sp^H^HSTOP PRESS. I see you applied

> > > > >    my patch ;). Thanks.

> > > > > 

> > > > > In which case, for non-legacy devices we should definitely be using

> > > > > VIRTIO_F_IOMMU_PLATFORM, but since this platform hasn't yet moved to the

> > > > > world of flying cars, could we unconditionally set the DMA ops on ARM

> > > > > for legacy devices? The alternative is disabling the SMMU altogether,

> > > > > but that's less than ideal because there are non-virtio devices on the

> > > > > same PCI bus.

> > > > > 

> > > > 

> > > > I'd rather people didn't use SMMU with legacy devices.

> > > 

> > > I'm afraid we've been doing that for two years and the model already

> > > exists in a mature state, being actively used for development and

> > > validation by ARM and our partners. One of the big things its used for

> > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > dropping the SMMU from the picture isn't an option.

> > 

> > Oh so this fixes a regression?  This is something I didn't realize.

> 

> Yes, thanks. The regression came about because we implemented SMMU-backed

> DMA ops and only then was it apparent that the virtio stuff was bypassing

> even with translation enabled (because it wasn't using the DMA API).


Could you point out a commit ID?


> > A "Fixes:" tag can't hurt here.  I then wonder

> > might DMA ops ever use a DMA address which isn't a physical address

> > from QEMU point of view? If that happens, this hack breaks

> > because in legacy mode QEMU still uses the GPA.

> 

> If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> because we won't swizzle the DMA ops for the master device. If QEMU does

> advertise an SMMU, then we'll allocate DMA addresses to fit within the

> the intersection of the SMMU aperture and device's DMA mask.



Right but doesn't just poking from qemu into phys addresses work
anymore? It used to ...

> > > > Can't you guys just code up the virtio 1 layout in QEMU?

> > > > I took a look and it's not a big deal now that two other

> > > > transports converted, except mmio code in QEMU doesn't

> > > > use linux header to it's a bit messy.

> > > > I'll send a patch to clean that up.

> > > 

> > > If the model ever changes in this area (which isn't planned atm), the

> > > right thing to do would be to move to modern virtio. However, we're stuck

> > > with what we have for the forseeable future and it works just fine if we

> > > use the DMA API. If we don't use it, Linux no longer boots because it

> > > installs the SMMU-backed DMA ops for the virtio devices and everything

> > > faults.

> > > 

> > > I really don't understand why this is controversial.

> > > 

> > I agree we need to keep working things working. I just don't yet

> > understand what change broke things and how did it happen - legacy

> > devices used to just poke at guest PA from QEMU, what does it matter

> > that there are changes in DMA ops if neither host nor guest use them for

> > legacy setups?

> 

> The problem is that platforms which advertise an SMMU downstream of the

> (virtual) PCI-RC now automatically have their PCI devices attached to the

> SMMU, so if they don't use the DMA ops then they will fault.

> 

> > I guess that's just me now knowing about how DMA ops work on SMMU

> > or missing some other basic point about SMMU.

> > 

> > I take your word that it's the right thing to do, but I'd like to figure

> > it out before merging this.  I'll read up in the coming days to make

> > sure I understand what the patch does, any pointers welcome.

> 

> Ok, thanks. Just shout if you have more questions. I'm also happy with

> only doing this for legacy devices, given that modern virtio has the

> IOMMU flag.

> 

> Will


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 16, 2017, 10:40 a.m. UTC | #11
On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:
> On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > 

> > > > I'm afraid we've been doing that for two years and the model already

> > > > exists in a mature state, being actively used for development and

> > > > validation by ARM and our partners. One of the big things its used for

> > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > dropping the SMMU from the picture isn't an option.

> > > 

> > > Oh so this fixes a regression?  This is something I didn't realize.

> > 

> > Yes, thanks. The regression came about because we implemented SMMU-backed

> > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > even with translation enabled (because it wasn't using the DMA API).

> 

> Could you point out a commit ID?


There has been a fair amount of work in this area recently, but you're
probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")
as the culprit, which is the point at which we started to swizzle DMA
ops for devices upstream of an SMMU automatically.

> > > A "Fixes:" tag can't hurt here.  I then wonder

> > > might DMA ops ever use a DMA address which isn't a physical address

> > > from QEMU point of view? If that happens, this hack breaks

> > > because in legacy mode QEMU still uses the GPA.

> > 

> > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > because we won't swizzle the DMA ops for the master device. If QEMU does

> > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > the intersection of the SMMU aperture and device's DMA mask.

> 

> 

> Right but doesn't just poking from qemu into phys addresses work

> anymore? It used to ...


Provided that there's no SMMU, then it will continue to work. and my
understanding (from talking to Peter Maydell) is that qemu doesn't model
an SMMU for ARM-based machines.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 16, 2017, 2:18 p.m. UTC | #12
On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:
> On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> > On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > > 

> > > > > I'm afraid we've been doing that for two years and the model already

> > > > > exists in a mature state, being actively used for development and

> > > > > validation by ARM and our partners. One of the big things its used for

> > > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > > dropping the SMMU from the picture isn't an option.

> > > > 

> > > > Oh so this fixes a regression?  This is something I didn't realize.

> > > 

> > > Yes, thanks. The regression came about because we implemented SMMU-backed

> > > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > > even with translation enabled (because it wasn't using the DMA API).

> > 

> > Could you point out a commit ID?

> 

> There has been a fair amount of work in this area recently, but you're

> probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> as the culprit, which is the point at which we started to swizzle DMA

> ops for devices upstream of an SMMU automatically.

> 

> > > > A "Fixes:" tag can't hurt here.  I then wonder

> > > > might DMA ops ever use a DMA address which isn't a physical address

> > > > from QEMU point of view? If that happens, this hack breaks

> > > > because in legacy mode QEMU still uses the GPA.

> > > 

> > > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > > because we won't swizzle the DMA ops for the master device. If QEMU does

> > > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > > the intersection of the SMMU aperture and device's DMA mask.

> > 

> > 

> > Right but doesn't just poking from qemu into phys addresses work

> > anymore? It used to ...

> 

> Provided that there's no SMMU, then it will continue to work. and my

> understanding (from talking to Peter Maydell) is that qemu doesn't model

> an SMMU for ARM-based machines.

> 

> Will


So how come people report failures due to presence of SMMU?
Using some other hypervisor?

-- 
MST

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 16, 2017, 2:21 p.m. UTC | #13
On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:
> On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

> > On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> > > On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > > > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > > > 

> > > > > > I'm afraid we've been doing that for two years and the model already

> > > > > > exists in a mature state, being actively used for development and

> > > > > > validation by ARM and our partners. One of the big things its used for

> > > > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > > > dropping the SMMU from the picture isn't an option.

> > > > > 

> > > > > Oh so this fixes a regression?  This is something I didn't realize.

> > > > 

> > > > Yes, thanks. The regression came about because we implemented SMMU-backed

> > > > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > > > even with translation enabled (because it wasn't using the DMA API).

> > > 

> > > Could you point out a commit ID?

> > 

> > There has been a fair amount of work in this area recently, but you're

> > probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> > as the culprit, which is the point at which we started to swizzle DMA

> > ops for devices upstream of an SMMU automatically.

> > 

> > > > > A "Fixes:" tag can't hurt here.  I then wonder

> > > > > might DMA ops ever use a DMA address which isn't a physical address

> > > > > from QEMU point of view? If that happens, this hack breaks

> > > > > because in legacy mode QEMU still uses the GPA.

> > > > 

> > > > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > > > because we won't swizzle the DMA ops for the master device. If QEMU does

> > > > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > > > the intersection of the SMMU aperture and device's DMA mask.

> > > 

> > > 

> > > Right but doesn't just poking from qemu into phys addresses work

> > > anymore? It used to ...

> > 

> > Provided that there's no SMMU, then it will continue to work. and my

> > understanding (from talking to Peter Maydell) is that qemu doesn't model

> > an SMMU for ARM-based machines.

> > 

> 

> So how come people report failures due to presence of SMMU?

> Using some other hypervisor?


The failures are reported on the ARM fastmodel (a complete system
emulation that runs on an x86 box), where an SMMU *is* present
downstream of the virtio-pci masters. There's no qemu involved there.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 16, 2017, 2:27 p.m. UTC | #14
On Mon, Jan 16, 2017 at 02:21:03PM +0000, Will Deacon wrote:
> On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:

> > On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

> > > On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> > > > On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > > > > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > > > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > > > > 

> > > > > > > I'm afraid we've been doing that for two years and the model already

> > > > > > > exists in a mature state, being actively used for development and

> > > > > > > validation by ARM and our partners. One of the big things its used for

> > > > > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > > > > dropping the SMMU from the picture isn't an option.

> > > > > > 

> > > > > > Oh so this fixes a regression?  This is something I didn't realize.

> > > > > 

> > > > > Yes, thanks. The regression came about because we implemented SMMU-backed

> > > > > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > > > > even with translation enabled (because it wasn't using the DMA API).

> > > > 

> > > > Could you point out a commit ID?

> > > 

> > > There has been a fair amount of work in this area recently, but you're

> > > probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> > > as the culprit, which is the point at which we started to swizzle DMA

> > > ops for devices upstream of an SMMU automatically.

> > > 

> > > > > > A "Fixes:" tag can't hurt here.  I then wonder

> > > > > > might DMA ops ever use a DMA address which isn't a physical address

> > > > > > from QEMU point of view? If that happens, this hack breaks

> > > > > > because in legacy mode QEMU still uses the GPA.

> > > > > 

> > > > > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > > > > because we won't swizzle the DMA ops for the master device. If QEMU does

> > > > > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > > > > the intersection of the SMMU aperture and device's DMA mask.

> > > > 

> > > > 

> > > > Right but doesn't just poking from qemu into phys addresses work

> > > > anymore? It used to ...

> > > 

> > > Provided that there's no SMMU, then it will continue to work. and my

> > > understanding (from talking to Peter Maydell) is that qemu doesn't model

> > > an SMMU for ARM-based machines.

> > > 

> > 

> > So how come people report failures due to presence of SMMU?

> > Using some other hypervisor?

> 

> The failures are reported on the ARM fastmodel (a complete system

> emulation that runs on an x86 box), where an SMMU *is* present

> downstream of the virtio-pci masters. There's no qemu involved there.

> 

> Will


I see. And this hypervisor actually coded up looking up
translations in the SMMU unconditionally for legacy devices,
and this worked as long as guest didn't touch the SMMU?

-- 
MST

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 16, 2017, 2:34 p.m. UTC | #15
On Mon, Jan 16, 2017 at 04:27:28PM +0200, Michael S. Tsirkin wrote:
> On Mon, Jan 16, 2017 at 02:21:03PM +0000, Will Deacon wrote:

> > On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:

> > > On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

> > > > On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> > > > > On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > > > > > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > > > > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > > > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > > > > > 

> > > > > > > > I'm afraid we've been doing that for two years and the model already

> > > > > > > > exists in a mature state, being actively used for development and

> > > > > > > > validation by ARM and our partners. One of the big things its used for

> > > > > > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > > > > > dropping the SMMU from the picture isn't an option.

> > > > > > > 

> > > > > > > Oh so this fixes a regression?  This is something I didn't realize.

> > > > > > 

> > > > > > Yes, thanks. The regression came about because we implemented SMMU-backed

> > > > > > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > > > > > even with translation enabled (because it wasn't using the DMA API).

> > > > > 

> > > > > Could you point out a commit ID?

> > > > 

> > > > There has been a fair amount of work in this area recently, but you're

> > > > probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> > > > as the culprit, which is the point at which we started to swizzle DMA

> > > > ops for devices upstream of an SMMU automatically.

> > > > 

> > > > > > > A "Fixes:" tag can't hurt here.  I then wonder

> > > > > > > might DMA ops ever use a DMA address which isn't a physical address

> > > > > > > from QEMU point of view? If that happens, this hack breaks

> > > > > > > because in legacy mode QEMU still uses the GPA.

> > > > > > 

> > > > > > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > > > > > because we won't swizzle the DMA ops for the master device. If QEMU does

> > > > > > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > > > > > the intersection of the SMMU aperture and device's DMA mask.

> > > > > 

> > > > > 

> > > > > Right but doesn't just poking from qemu into phys addresses work

> > > > > anymore? It used to ...

> > > > 

> > > > Provided that there's no SMMU, then it will continue to work. and my

> > > > understanding (from talking to Peter Maydell) is that qemu doesn't model

> > > > an SMMU for ARM-based machines.

> > > > 

> > > 

> > > So how come people report failures due to presence of SMMU?

> > > Using some other hypervisor?

> > 

> > The failures are reported on the ARM fastmodel (a complete system

> > emulation that runs on an x86 box), where an SMMU *is* present

> > downstream of the virtio-pci masters. There's no qemu involved there.

> > 

> I see. And this hypervisor actually coded up looking up

> translations in the SMMU unconditionally for legacy devices,

> and this worked as long as guest didn't touch the SMMU?


Well, the fastmodel isn't a hypervisor really. It's a full system emulation,
so it's better to think of it like a piece of hardware. For example, you
could run KVM on the fastmodel. But yes, when Linux didn't swizzle the
DMA ops to point at the SMMU, then everything defaults to bypass (because
that's the default behaviour of the SMMU driver -- this is configurable
on the command line) which is why things used to work.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 19, 2017, 9:51 p.m. UTC | #16
On Mon, Jan 16, 2017 at 02:34:08PM +0000, Will Deacon wrote:
> On Mon, Jan 16, 2017 at 04:27:28PM +0200, Michael S. Tsirkin wrote:

> > On Mon, Jan 16, 2017 at 02:21:03PM +0000, Will Deacon wrote:

> > > On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:

> > > > On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

> > > > > On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> > > > > > On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > > > > > > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > > > > > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > > > > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > > > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > > > > > > 

> > > > > > > > > I'm afraid we've been doing that for two years and the model already

> > > > > > > > > exists in a mature state, being actively used for development and

> > > > > > > > > validation by ARM and our partners. One of the big things its used for

> > > > > > > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > > > > > > dropping the SMMU from the picture isn't an option.

> > > > > > > > 

> > > > > > > > Oh so this fixes a regression?  This is something I didn't realize.

> > > > > > > 

> > > > > > > Yes, thanks. The regression came about because we implemented SMMU-backed

> > > > > > > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > > > > > > even with translation enabled (because it wasn't using the DMA API).

> > > > > > 

> > > > > > Could you point out a commit ID?

> > > > > 

> > > > > There has been a fair amount of work in this area recently, but you're

> > > > > probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> > > > > as the culprit, which is the point at which we started to swizzle DMA

> > > > > ops for devices upstream of an SMMU automatically.

> > > > > 

> > > > > > > > A "Fixes:" tag can't hurt here.  I then wonder

> > > > > > > > might DMA ops ever use a DMA address which isn't a physical address

> > > > > > > > from QEMU point of view? If that happens, this hack breaks

> > > > > > > > because in legacy mode QEMU still uses the GPA.

> > > > > > > 

> > > > > > > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > > > > > > because we won't swizzle the DMA ops for the master device. If QEMU does

> > > > > > > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > > > > > > the intersection of the SMMU aperture and device's DMA mask.

> > > > > > 

> > > > > > 

> > > > > > Right but doesn't just poking from qemu into phys addresses work

> > > > > > anymore? It used to ...

> > > > > 

> > > > > Provided that there's no SMMU, then it will continue to work. and my

> > > > > understanding (from talking to Peter Maydell) is that qemu doesn't model

> > > > > an SMMU for ARM-based machines.

> > > > > 

> > > > 

> > > > So how come people report failures due to presence of SMMU?

> > > > Using some other hypervisor?

> > > 

> > > The failures are reported on the ARM fastmodel (a complete system

> > > emulation that runs on an x86 box), where an SMMU *is* present

> > > downstream of the virtio-pci masters. There's no qemu involved there.

> > > 

> > I see. And this hypervisor actually coded up looking up

> > translations in the SMMU unconditionally for legacy devices,

> > and this worked as long as guest didn't touch the SMMU?

> 

> Well, the fastmodel isn't a hypervisor really. It's a full system emulation,

> so it's better to think of it like a piece of hardware. For example, you

> could run KVM on the fastmodel. But yes, when Linux didn't swizzle the

> DMA ops to point at the SMMU, then everything defaults to bypass (because

> that's the default behaviour of the SMMU driver -- this is configurable

> on the command line) which is why things used to work.

> 

> Will


I would be a bit happier if Linux checked virtio iommu quirk and skipped
the DMA ops thing then. It's a bit ugly but at least it's consistently
ugly.  To get clean emulation you would then use a modern device.

-- 
MST

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 20, 2017, 10:33 a.m. UTC | #17
On Thu, Jan 19, 2017 at 11:51:06PM +0200, Michael S. Tsirkin wrote:
> On Mon, Jan 16, 2017 at 02:34:08PM +0000, Will Deacon wrote:

> > On Mon, Jan 16, 2017 at 04:27:28PM +0200, Michael S. Tsirkin wrote:

> > > On Mon, Jan 16, 2017 at 02:21:03PM +0000, Will Deacon wrote:

> > > > On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:

> > > > > On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

> > > > > > On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> > > > > > > On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> > > > > > > > On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> > > > > > > > > On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> > > > > > > > > > On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> > > > > > > > > > > I'd rather people didn't use SMMU with legacy devices.

> > > > > > > > > > 

> > > > > > > > > > I'm afraid we've been doing that for two years and the model already

> > > > > > > > > > exists in a mature state, being actively used for development and

> > > > > > > > > > validation by ARM and our partners. One of the big things its used for

> > > > > > > > > > is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> > > > > > > > > > dropping the SMMU from the picture isn't an option.

> > > > > > > > > 

> > > > > > > > > Oh so this fixes a regression?  This is something I didn't realize.

> > > > > > > > 

> > > > > > > > Yes, thanks. The regression came about because we implemented SMMU-backed

> > > > > > > > DMA ops and only then was it apparent that the virtio stuff was bypassing

> > > > > > > > even with translation enabled (because it wasn't using the DMA API).

> > > > > > > 

> > > > > > > Could you point out a commit ID?

> > > > > > 

> > > > > > There has been a fair amount of work in this area recently, but you're

> > > > > > probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> > > > > > as the culprit, which is the point at which we started to swizzle DMA

> > > > > > ops for devices upstream of an SMMU automatically.

> > > > > > 

> > > > > > > > > A "Fixes:" tag can't hurt here.  I then wonder

> > > > > > > > > might DMA ops ever use a DMA address which isn't a physical address

> > > > > > > > > from QEMU point of view? If that happens, this hack breaks

> > > > > > > > > because in legacy mode QEMU still uses the GPA.

> > > > > > > > 

> > > > > > > > If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> > > > > > > > because we won't swizzle the DMA ops for the master device. If QEMU does

> > > > > > > > advertise an SMMU, then we'll allocate DMA addresses to fit within the

> > > > > > > > the intersection of the SMMU aperture and device's DMA mask.

> > > > > > > 

> > > > > > > 

> > > > > > > Right but doesn't just poking from qemu into phys addresses work

> > > > > > > anymore? It used to ...

> > > > > > 

> > > > > > Provided that there's no SMMU, then it will continue to work. and my

> > > > > > understanding (from talking to Peter Maydell) is that qemu doesn't model

> > > > > > an SMMU for ARM-based machines.

> > > > > > 

> > > > > 

> > > > > So how come people report failures due to presence of SMMU?

> > > > > Using some other hypervisor?

> > > > 

> > > > The failures are reported on the ARM fastmodel (a complete system

> > > > emulation that runs on an x86 box), where an SMMU *is* present

> > > > downstream of the virtio-pci masters. There's no qemu involved there.

> > > > 

> > > I see. And this hypervisor actually coded up looking up

> > > translations in the SMMU unconditionally for legacy devices,

> > > and this worked as long as guest didn't touch the SMMU?

> > 

> > Well, the fastmodel isn't a hypervisor really. It's a full system emulation,

> > so it's better to think of it like a piece of hardware. For example, you

> > could run KVM on the fastmodel. But yes, when Linux didn't swizzle the

> > DMA ops to point at the SMMU, then everything defaults to bypass (because

> > that's the default behaviour of the SMMU driver -- this is configurable

> > on the command line) which is why things used to work.

> > 

> I would be a bit happier if Linux checked virtio iommu quirk and skipped

> the DMA ops thing then. It's a bit ugly but at least it's consistently

> ugly.  To get clean emulation you would then use a modern device.


Sorry, but I'm not sure I follow your suggestion here. If you're talking
about the DMA ops themselves, they are assigned in arch_setup_dma_ops long
before the virtio layer gets involved, so we really can't figure out
whether the device has a virtio iommu quirk at that point.

I've reworked the patch (see below) so that we unconditionally set the
DMA ops for arm-based legacy devices, but I can't really tell what you're
after here.

Will

--->8

From 213bad7fdb8e4f45a7724be169cda292bbb50d2b Mon Sep 17 00:00:00 2001
From: Will Deacon <will.deacon@arm.com>

Date: Tue, 20 Dec 2016 12:12:49 +0000
Subject: [PATCH] vring: Force use of DMA API for ARM-based systems with legacy
 devices

Booting Linux on an ARM fastmodel containing an SMMU emulation results
in an unexpected I/O page fault from the legacy virtio-blk PCI device:

[    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:
[    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010
[    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000
[    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002
[    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000
[    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:
[    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010
[    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000
[    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000
[    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

<system hangs failing to read partition table>

This is because the legacy virtio-blk device is behind an SMMU, so we
have consequently swizzled its DMA ops and configured the SMMU to
translate accesses. This then requires the vring code to use the DMA API
to establish translations, otherwise all transactions will result in
fatal faults and termination.

Given that ARM-based systems only see an SMMU if one is really present
(the topology is all described by firmware tables such as device-tree or
IORT), then we can safely use the DMA API for all legacy virtio devices.
Modern devices can advertise the prescense of an IOMMU using the
VIRTIO_F_IOMMU_PLATFORM feature flag.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: <stable@vger.kernel.org>
Fixes: 876945dbf649 ("arm64: Hook up IOMMU dma_ops")
Signed-off-by: Will Deacon <will.deacon@arm.com>

---
 drivers/virtio/virtio_ring.c | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
2.1.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kerneldiff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 409aeaa49246..7e38ed79c3fc 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -159,6 +159,13 @@ static bool vring_use_dma_api(struct virtio_device *vdev)
 	if (xen_domain())
 		return true;
 
+	/*
+	 * On ARM-based machines, the DMA ops will do the right thing,
+	 * so always use them with legacy devices.
+	 */
+	if (IS_ENABLED(CONFIG_ARM) || IS_ENABLED(CONFIG_ARM64))
+		return !virtio_has_feature(vdev, VIRTIO_F_VERSION_1);
+
 	return false;
 }
 

Marc Zyngier Jan. 24, 2017, 4:04 p.m. UTC | #18
On 20/01/17 10:33, Will Deacon wrote:
> On Thu, Jan 19, 2017 at 11:51:06PM +0200, Michael S. Tsirkin wrote:

>> On Mon, Jan 16, 2017 at 02:34:08PM +0000, Will Deacon wrote:

>>> On Mon, Jan 16, 2017 at 04:27:28PM +0200, Michael S. Tsirkin wrote:

>>>> On Mon, Jan 16, 2017 at 02:21:03PM +0000, Will Deacon wrote:

>>>>> On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:

>>>>>> On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

>>>>>>> On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

>>>>>>>> On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

>>>>>>>>> On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

>>>>>>>>>> On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

>>>>>>>>>>> On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

>>>>>>>>>>>> I'd rather people didn't use SMMU with legacy devices.

>>>>>>>>>>>

>>>>>>>>>>> I'm afraid we've been doing that for two years and the model already

>>>>>>>>>>> exists in a mature state, being actively used for development and

>>>>>>>>>>> validation by ARM and our partners. One of the big things its used for

>>>>>>>>>>> is to develop SMMU and GIC (our interrupt controller) code with PCI, so

>>>>>>>>>>> dropping the SMMU from the picture isn't an option.

>>>>>>>>>>

>>>>>>>>>> Oh so this fixes a regression?  This is something I didn't realize.

>>>>>>>>>

>>>>>>>>> Yes, thanks. The regression came about because we implemented SMMU-backed

>>>>>>>>> DMA ops and only then was it apparent that the virtio stuff was bypassing

>>>>>>>>> even with translation enabled (because it wasn't using the DMA API).

>>>>>>>>

>>>>>>>> Could you point out a commit ID?

>>>>>>>

>>>>>>> There has been a fair amount of work in this area recently, but you're

>>>>>>> probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

>>>>>>> as the culprit, which is the point at which we started to swizzle DMA

>>>>>>> ops for devices upstream of an SMMU automatically.

>>>>>>>

>>>>>>>>>> A "Fixes:" tag can't hurt here.  I then wonder

>>>>>>>>>> might DMA ops ever use a DMA address which isn't a physical address

>>>>>>>>>> from QEMU point of view? If that happens, this hack breaks

>>>>>>>>>> because in legacy mode QEMU still uses the GPA.

>>>>>>>>>

>>>>>>>>> If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

>>>>>>>>> because we won't swizzle the DMA ops for the master device. If QEMU does

>>>>>>>>> advertise an SMMU, then we'll allocate DMA addresses to fit within the

>>>>>>>>> the intersection of the SMMU aperture and device's DMA mask.

>>>>>>>>

>>>>>>>>

>>>>>>>> Right but doesn't just poking from qemu into phys addresses work

>>>>>>>> anymore? It used to ...

>>>>>>>

>>>>>>> Provided that there's no SMMU, then it will continue to work. and my

>>>>>>> understanding (from talking to Peter Maydell) is that qemu doesn't model

>>>>>>> an SMMU for ARM-based machines.

>>>>>>>

>>>>>>

>>>>>> So how come people report failures due to presence of SMMU?

>>>>>> Using some other hypervisor?

>>>>>

>>>>> The failures are reported on the ARM fastmodel (a complete system

>>>>> emulation that runs on an x86 box), where an SMMU *is* present

>>>>> downstream of the virtio-pci masters. There's no qemu involved there.

>>>>>

>>>> I see. And this hypervisor actually coded up looking up

>>>> translations in the SMMU unconditionally for legacy devices,

>>>> and this worked as long as guest didn't touch the SMMU?

>>>

>>> Well, the fastmodel isn't a hypervisor really. It's a full system emulation,

>>> so it's better to think of it like a piece of hardware. For example, you

>>> could run KVM on the fastmodel. But yes, when Linux didn't swizzle the

>>> DMA ops to point at the SMMU, then everything defaults to bypass (because

>>> that's the default behaviour of the SMMU driver -- this is configurable

>>> on the command line) which is why things used to work.

>>>

>> I would be a bit happier if Linux checked virtio iommu quirk and skipped

>> the DMA ops thing then. It's a bit ugly but at least it's consistently

>> ugly.  To get clean emulation you would then use a modern device.

> 

> Sorry, but I'm not sure I follow your suggestion here. If you're talking

> about the DMA ops themselves, they are assigned in arch_setup_dma_ops long

> before the virtio layer gets involved, so we really can't figure out

> whether the device has a virtio iommu quirk at that point.

> 

> I've reworked the patch (see below) so that we unconditionally set the

> DMA ops for arm-based legacy devices, but I can't really tell what you're

> after here.

> 

> Will

> 

> --->8

> 

> From 213bad7fdb8e4f45a7724be169cda292bbb50d2b Mon Sep 17 00:00:00 2001

> From: Will Deacon <will.deacon@arm.com>

> Date: Tue, 20 Dec 2016 12:12:49 +0000

> Subject: [PATCH] vring: Force use of DMA API for ARM-based systems with legacy

>  devices

> 

> Booting Linux on an ARM fastmodel containing an SMMU emulation results

> in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> 

> [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> 

> <system hangs failing to read partition table>

> 

> This is because the legacy virtio-blk device is behind an SMMU, so we

> have consequently swizzled its DMA ops and configured the SMMU to

> translate accesses. This then requires the vring code to use the DMA API

> to establish translations, otherwise all transactions will result in

> fatal faults and termination.

> 

> Given that ARM-based systems only see an SMMU if one is really present

> (the topology is all described by firmware tables such as device-tree or

> IORT), then we can safely use the DMA API for all legacy virtio devices.

> Modern devices can advertise the prescense of an IOMMU using the

> VIRTIO_F_IOMMU_PLATFORM feature flag.

> 

> Cc: Andy Lutomirski <luto@kernel.org>

> Cc: Michael S. Tsirkin <mst@redhat.com>

> Cc: <stable@vger.kernel.org>

> Fixes: 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> Signed-off-by: Will Deacon <will.deacon@arm.com>

> ---

>  drivers/virtio/virtio_ring.c | 7 +++++++

>  1 file changed, 7 insertions(+)

> 

> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c

> index 409aeaa49246..7e38ed79c3fc 100644

> --- a/drivers/virtio/virtio_ring.c

> +++ b/drivers/virtio/virtio_ring.c

> @@ -159,6 +159,13 @@ static bool vring_use_dma_api(struct virtio_device *vdev)

>  	if (xen_domain())

>  		return true;

>  

> +	/*

> +	 * On ARM-based machines, the DMA ops will do the right thing,

> +	 * so always use them with legacy devices.

> +	 */

> +	if (IS_ENABLED(CONFIG_ARM) || IS_ENABLED(CONFIG_ARM64))

> +		return !virtio_has_feature(vdev, VIRTIO_F_VERSION_1);

> +

>  	return false;

>  }

>  

> 


Acked-by: Marc Zyngier <marc.zyngier@arm.com>


Any chance this fix (or anything with similar effects) gets applied
sometime soon? I cannot use the model without using a similar workaround:

http://git.kernel.org/cgit/linux/kernel/git/maz/arm-platforms.git/commit/?h=kvm-arm64/gicv4-wip&id=622ff1190890c0ae60d57e76a7c2f3e6fb27e25d

and I suspect that other users of the same system are carrying their own
version of the fix. Something in mainline would be infinitely better.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Michael S. Tsirkin Jan. 24, 2017, 4:06 p.m. UTC | #19
On Tue, Jan 24, 2017 at 04:04:11PM +0000, Marc Zyngier wrote:
> On 20/01/17 10:33, Will Deacon wrote:

> > On Thu, Jan 19, 2017 at 11:51:06PM +0200, Michael S. Tsirkin wrote:

> >> On Mon, Jan 16, 2017 at 02:34:08PM +0000, Will Deacon wrote:

> >>> On Mon, Jan 16, 2017 at 04:27:28PM +0200, Michael S. Tsirkin wrote:

> >>>> On Mon, Jan 16, 2017 at 02:21:03PM +0000, Will Deacon wrote:

> >>>>> On Mon, Jan 16, 2017 at 04:18:03PM +0200, Michael S. Tsirkin wrote:

> >>>>>> On Mon, Jan 16, 2017 at 10:40:28AM +0000, Will Deacon wrote:

> >>>>>>> On Fri, Jan 13, 2017 at 08:23:35PM +0200, Michael S. Tsirkin wrote:

> >>>>>>>> On Fri, Jan 13, 2017 at 05:21:54PM +0000, Will Deacon wrote:

> >>>>>>>>> On Fri, Jan 13, 2017 at 06:46:32PM +0200, Michael S. Tsirkin wrote:

> >>>>>>>>>> On Fri, Jan 13, 2017 at 09:25:22AM +0000, Will Deacon wrote:

> >>>>>>>>>>> On Fri, Jan 13, 2017 at 12:12:56AM +0200, Michael S. Tsirkin wrote:

> >>>>>>>>>>>> I'd rather people didn't use SMMU with legacy devices.

> >>>>>>>>>>>

> >>>>>>>>>>> I'm afraid we've been doing that for two years and the model already

> >>>>>>>>>>> exists in a mature state, being actively used for development and

> >>>>>>>>>>> validation by ARM and our partners. One of the big things its used for

> >>>>>>>>>>> is to develop SMMU and GIC (our interrupt controller) code with PCI, so

> >>>>>>>>>>> dropping the SMMU from the picture isn't an option.

> >>>>>>>>>>

> >>>>>>>>>> Oh so this fixes a regression?  This is something I didn't realize.

> >>>>>>>>>

> >>>>>>>>> Yes, thanks. The regression came about because we implemented SMMU-backed

> >>>>>>>>> DMA ops and only then was it apparent that the virtio stuff was bypassing

> >>>>>>>>> even with translation enabled (because it wasn't using the DMA API).

> >>>>>>>>

> >>>>>>>> Could you point out a commit ID?

> >>>>>>>

> >>>>>>> There has been a fair amount of work in this area recently, but you're

> >>>>>>> probably after something like 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> >>>>>>> as the culprit, which is the point at which we started to swizzle DMA

> >>>>>>> ops for devices upstream of an SMMU automatically.

> >>>>>>>

> >>>>>>>>>> A "Fixes:" tag can't hurt here.  I then wonder

> >>>>>>>>>> might DMA ops ever use a DMA address which isn't a physical address

> >>>>>>>>>> from QEMU point of view? If that happens, this hack breaks

> >>>>>>>>>> because in legacy mode QEMU still uses the GPA.

> >>>>>>>>>

> >>>>>>>>> If QEMU doesn't advertise an SMMU, then it will work fine with the GPA,

> >>>>>>>>> because we won't swizzle the DMA ops for the master device. If QEMU does

> >>>>>>>>> advertise an SMMU, then we'll allocate DMA addresses to fit within the

> >>>>>>>>> the intersection of the SMMU aperture and device's DMA mask.

> >>>>>>>>

> >>>>>>>>

> >>>>>>>> Right but doesn't just poking from qemu into phys addresses work

> >>>>>>>> anymore? It used to ...

> >>>>>>>

> >>>>>>> Provided that there's no SMMU, then it will continue to work. and my

> >>>>>>> understanding (from talking to Peter Maydell) is that qemu doesn't model

> >>>>>>> an SMMU for ARM-based machines.

> >>>>>>>

> >>>>>>

> >>>>>> So how come people report failures due to presence of SMMU?

> >>>>>> Using some other hypervisor?

> >>>>>

> >>>>> The failures are reported on the ARM fastmodel (a complete system

> >>>>> emulation that runs on an x86 box), where an SMMU *is* present

> >>>>> downstream of the virtio-pci masters. There's no qemu involved there.

> >>>>>

> >>>> I see. And this hypervisor actually coded up looking up

> >>>> translations in the SMMU unconditionally for legacy devices,

> >>>> and this worked as long as guest didn't touch the SMMU?

> >>>

> >>> Well, the fastmodel isn't a hypervisor really. It's a full system emulation,

> >>> so it's better to think of it like a piece of hardware. For example, you

> >>> could run KVM on the fastmodel. But yes, when Linux didn't swizzle the

> >>> DMA ops to point at the SMMU, then everything defaults to bypass (because

> >>> that's the default behaviour of the SMMU driver -- this is configurable

> >>> on the command line) which is why things used to work.

> >>>

> >> I would be a bit happier if Linux checked virtio iommu quirk and skipped

> >> the DMA ops thing then. It's a bit ugly but at least it's consistently

> >> ugly.  To get clean emulation you would then use a modern device.

> > 

> > Sorry, but I'm not sure I follow your suggestion here. If you're talking

> > about the DMA ops themselves, they are assigned in arch_setup_dma_ops long

> > before the virtio layer gets involved, so we really can't figure out

> > whether the device has a virtio iommu quirk at that point.

> > 

> > I've reworked the patch (see below) so that we unconditionally set the

> > DMA ops for arm-based legacy devices, but I can't really tell what you're

> > after here.

> > 

> > Will

> > 

> > --->8

> > 

> > From 213bad7fdb8e4f45a7724be169cda292bbb50d2b Mon Sep 17 00:00:00 2001

> > From: Will Deacon <will.deacon@arm.com>

> > Date: Tue, 20 Dec 2016 12:12:49 +0000

> > Subject: [PATCH] vring: Force use of DMA API for ARM-based systems with legacy

> >  devices

> > 

> > Booting Linux on an ARM fastmodel containing an SMMU emulation results

> > in an unexpected I/O page fault from the legacy virtio-blk PCI device:

> > 

> > [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

> > [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

> > [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

> > [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

> > [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

> > [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

> > 

> > <system hangs failing to read partition table>

> > 

> > This is because the legacy virtio-blk device is behind an SMMU, so we

> > have consequently swizzled its DMA ops and configured the SMMU to

> > translate accesses. This then requires the vring code to use the DMA API

> > to establish translations, otherwise all transactions will result in

> > fatal faults and termination.

> > 

> > Given that ARM-based systems only see an SMMU if one is really present

> > (the topology is all described by firmware tables such as device-tree or

> > IORT), then we can safely use the DMA API for all legacy virtio devices.

> > Modern devices can advertise the prescense of an IOMMU using the

> > VIRTIO_F_IOMMU_PLATFORM feature flag.

> > 

> > Cc: Andy Lutomirski <luto@kernel.org>

> > Cc: Michael S. Tsirkin <mst@redhat.com>

> > Cc: <stable@vger.kernel.org>

> > Fixes: 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

> > Signed-off-by: Will Deacon <will.deacon@arm.com>

> > ---

> >  drivers/virtio/virtio_ring.c | 7 +++++++

> >  1 file changed, 7 insertions(+)

> > 

> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c

> > index 409aeaa49246..7e38ed79c3fc 100644

> > --- a/drivers/virtio/virtio_ring.c

> > +++ b/drivers/virtio/virtio_ring.c

> > @@ -159,6 +159,13 @@ static bool vring_use_dma_api(struct virtio_device *vdev)

> >  	if (xen_domain())

> >  		return true;

> >  

> > +	/*

> > +	 * On ARM-based machines, the DMA ops will do the right thing,

> > +	 * so always use them with legacy devices.

> > +	 */

> > +	if (IS_ENABLED(CONFIG_ARM) || IS_ENABLED(CONFIG_ARM64))

> > +		return !virtio_has_feature(vdev, VIRTIO_F_VERSION_1);

> > +

> >  	return false;

> >  }

> >  

> > 

> 

> Acked-by: Marc Zyngier <marc.zyngier@arm.com>

> 

> Any chance this fix (or anything with similar effects) gets applied

> sometime soon? I cannot use the model without using a similar

> workaround:

> 

> http://git.kernel.org/cgit/linux/kernel/git/maz/arm-platforms.git/commit/?h=kvm-arm64/gicv4-wip&id=622ff1190890c0ae60d57e76a7c2f3e6fb27e25d

> 

> and I suspect that other users of the same system are carrying their own

> version of the fix. Something in mainline would be infinitely better.

> 

> Thanks,

> 

> 	M.


I'll merge this in the next pull.

> -- 

> Jazz is not dead. It just smells funny...


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Marc Zyngier Jan. 24, 2017, 4:10 p.m. UTC | #20
On 24/01/17 16:06, Michael S. Tsirkin wrote:
> On Tue, Jan 24, 2017 at 04:04:11PM +0000, Marc Zyngier wrote:

>> On 20/01/17 10:33, Will Deacon wrote:

>>> From 213bad7fdb8e4f45a7724be169cda292bbb50d2b Mon Sep 17 00:00:00 2001

>>> From: Will Deacon <will.deacon@arm.com>

>>> Date: Tue, 20 Dec 2016 12:12:49 +0000

>>> Subject: [PATCH] vring: Force use of DMA API for ARM-based systems with legacy

>>>  devices

>>>

>>> Booting Linux on an ARM fastmodel containing an SMMU emulation results

>>> in an unexpected I/O page fault from the legacy virtio-blk PCI device:

>>>

>>> [    1.211721] arm-smmu-v3 2b400000.smmu: event 0x10 received:

>>> [    1.211800] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

>>> [    1.211880] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

>>> [    1.211959] arm-smmu-v3 2b400000.smmu:	0x00000008fa081002

>>> [    1.212075] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

>>> [    1.212155] arm-smmu-v3 2b400000.smmu: event 0x10 received:

>>> [    1.212234] arm-smmu-v3 2b400000.smmu:	0x00000000fffff010

>>> [    1.212314] arm-smmu-v3 2b400000.smmu:	0x0000020800000000

>>> [    1.212394] arm-smmu-v3 2b400000.smmu:	0x00000008fa081000

>>> [    1.212471] arm-smmu-v3 2b400000.smmu:	0x0000000000000000

>>>

>>> <system hangs failing to read partition table>

>>>

>>> This is because the legacy virtio-blk device is behind an SMMU, so we

>>> have consequently swizzled its DMA ops and configured the SMMU to

>>> translate accesses. This then requires the vring code to use the DMA API

>>> to establish translations, otherwise all transactions will result in

>>> fatal faults and termination.

>>>

>>> Given that ARM-based systems only see an SMMU if one is really present

>>> (the topology is all described by firmware tables such as device-tree or

>>> IORT), then we can safely use the DMA API for all legacy virtio devices.

>>> Modern devices can advertise the prescense of an IOMMU using the

>>> VIRTIO_F_IOMMU_PLATFORM feature flag.

>>>

>>> Cc: Andy Lutomirski <luto@kernel.org>

>>> Cc: Michael S. Tsirkin <mst@redhat.com>

>>> Cc: <stable@vger.kernel.org>

>>> Fixes: 876945dbf649 ("arm64: Hook up IOMMU dma_ops")

>>> Signed-off-by: Will Deacon <will.deacon@arm.com>

>>> ---

>>>  drivers/virtio/virtio_ring.c | 7 +++++++

>>>  1 file changed, 7 insertions(+)

>>>

>>> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c

>>> index 409aeaa49246..7e38ed79c3fc 100644

>>> --- a/drivers/virtio/virtio_ring.c

>>> +++ b/drivers/virtio/virtio_ring.c

>>> @@ -159,6 +159,13 @@ static bool vring_use_dma_api(struct virtio_device *vdev)

>>>  	if (xen_domain())

>>>  		return true;

>>>  

>>> +	/*

>>> +	 * On ARM-based machines, the DMA ops will do the right thing,

>>> +	 * so always use them with legacy devices.

>>> +	 */

>>> +	if (IS_ENABLED(CONFIG_ARM) || IS_ENABLED(CONFIG_ARM64))

>>> +		return !virtio_has_feature(vdev, VIRTIO_F_VERSION_1);

>>> +

>>>  	return false;

>>>  }

>>>  

>>>

>>

>> Acked-by: Marc Zyngier <marc.zyngier@arm.com>

>>

>> Any chance this fix (or anything with similar effects) gets applied

>> sometime soon? I cannot use the model without using a similar

>> workaround:

>>

>> http://git.kernel.org/cgit/linux/kernel/git/maz/arm-platforms.git/commit/?h=kvm-arm64/gicv4-wip&id=622ff1190890c0ae60d57e76a7c2f3e6fb27e25d

>>

>> and I suspect that other users of the same system are carrying their own

>> version of the fix. Something in mainline would be infinitely better.

>>

>> Thanks,

>>

>> 	M.

> 

> I'll merge this in the next pull.


Awesome, thanks a lot.

	M.
-- 
Jazz is not dead. It just smells funny...

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox

Patch

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 409aeaa49246..447245f2c813 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -159,6 +159,10 @@  static bool vring_use_dma_api(struct virtio_device *vdev)
 	if (xen_domain())
 		return true;
 
+	/* On ARM-based machines, the DMA ops will do the right thing */
+	if (IS_ENABLED(CONFIG_ARM) || IS_ENABLED(CONFIG_ARM64))
+		return true;
+
 	return false;
 }