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

Re: Disable swiotlb for Dom0


  • To: Julien Grall <julien@xxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>
  • From: Roman Skakun <Roman_Skakun@xxxxxxxx>
  • Date: Wed, 11 Aug 2021 08:49:42 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zl02WHcFpCS0M/lwtXzNyuIo2a8mvAEFAKPZQlY0B94=; b=CvBNKK8qlFuGYmelo6Bo0jBdMHYiTRA9K8zNVwIl+fdYRgo1F3k8w3li5sxS8h2Eahst7/Hj4M7nOjXxkuOSNF7FT8bsb5CtDrlJRyA6cEsqt4W0bbJZ/vYOm+yjTMG9FKVRRe9fL81geryW5/IWkNWq5YTtjhW/+QshW0OHbh6rLPcEhrwLQyZefE7Ic9THgcBIh4aw+z4WYZQe+3yGRTHBr3nOB6jhpaEQWdj8nkbeQ3jUjt+fNWfAaqw8mtKzXZn6e1HHl/ia1sEnHq21DIzTlUMUhsNmusdgQG09Z76H4PbGrDOVAvEC7en7IhXNWaLvw6dT6/NCDhlEIhxXYw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S1M9m8UGwnAhFU66zKTWk3//tfmKIvvuc0XZDUPTUmlqsorLz4Y1y9qlwiLr/8m/KHnR1kaU480iRZeRoOEfBbE1T+pBHtFqNVwnGvrt3LCEza76gU26doABJTaXNcAr1ntamkOuPbiSeCJ+0moVe1cr5JGvUcS8zAHQBLsTTuOeNPokWia1lmhcEOMES1ydj0CQbY/quj6EbC9QkFglTtX/K0rYbb5VOb3jYloeaZW5ba61gBiFsjznMZpKLNyoqoAhMAx/ZWXKhHjRT3DDcyzGSzCuHi8yDSCPAphWn/txUppK6xWvzDS7XzUrc68CtSV5stnmHffOgNEUTlZBfw==
  • Authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=epam.com;
  • Cc: Bertrand Marquis <bertrand.marquis@xxxxxxx>, Andrii Anisov <Andrii_Anisov@xxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roman Skakun <rm.skakun@xxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roman Skakun <Roman_Skakun@xxxxxxxx>
  • Delivery-date: Wed, 11 Aug 2021 08:50:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXjfwJK3kYIT7XAUWdmOu1AWm+tKts6kUAgAD/Ofo=
  • Thread-topic: Disable swiotlb for Dom0

Hi, Julien!

Thanks for the answer!

>> I have observed your patch here:
>> https://urldefense.com/v3/__https://patchwork.kernel.org/project/xen-devel/patch/alpine.DEB.2.21.2102161333090.3234@sstabellini-ThinkPad->>T480s/__;!!GF_29dbcQIUBPA!kH5gzG1mxcIgDqMu2cVjTD3ggN9LiPN4OVinOnqrhLQrNr-mRb72udp2B5XBqZlW$ [patchwork[.]kernel[.]org]
>>
>> And I collided with the same issue, when Dom0 device trying to use
>> swiotlb fops for devices which are controlled by IOMMU.
>
>The issue Stefano reported was when the dom0 is not direct mapped.
>However...

I applied these 
patches:
https://github.com/torvalds/linux/commit/f5079a9a2a31607a2343e544e9182ce35b030578
to check this more pragmatically.

Also, I added the log in xen_swiotlb_detect() and can see that swiotlb still used (other devices within dom0 used too), when dom0 is direct mapped:

[    1.870363] xen_swiotlb_detect() dev: rcar-fcp, XENFEAT_direct_mapped, use swiotlb
[    1.878352] xen_swiotlb_detect() dev: rcar-fcp, XENFEAT_direct_mapped, use swiotlb
[    1.886309] xen_swiotlb_detect() dev: rcar-fcp, XENFEAT_direct_mapped, use swiotlb

This means, that all devices are using swiotlb-xen DMA fops.
By the way, before applying this patches, dom0 always used swiotlb-xen fops for initial domain by design.


> Any reason to not use the stable branch for 5.10? I don't know whether
> your issue will be fixed there, but the stable branch usually contains a
> lot of bug fixes (including security one). So it is a good idea to use
> it over the first release of a kernel version.

Yes, sure, current BSP release based on 5.10 kernel:
BTW, I specified the wrong kernel URL in the previous massage, sorry.

>> Issue caused in xen_swiotlb_map_page():
>> ```
>>   dev: rcar-fcp, cap: 0, dma_mask: ffffffff, page: fffffe00180c7400, page_to_phys: 64b1d0000,
>> xen_phys_to_dma(phys): 64b1d0000
>> ```
>
>I can't seem to find this printk in Linux 5.10. Did you add it yourself?

Yes, it's my own log.


> This line suggests that the SWIOTLB tried to bounce the DMA buffer. In
> general, the use of the bounce buffer should be rare. So I would suggest
> to find out why this is used.
> 
> Looking at the code, this suggests that one of the following check is false:
> 
>         /*
>          * If the address happens to be in the device's DMA window,
>           * we can safely return the device addr and not worry about bounce
>           * buffering it.
>           */
>         if (dma_capable(dev, dev_addr, size, true) &&
>             !range_straddles_page_boundary(phys, size) &&
>                 !xen_arch_need_swiotlb(dev, phys, dev_addr) &&
>                 swiotlb_force != SWIOTLB_FORCE)
>                 goto done;

I checked this earlier and saw that dma_capable(dev, dev_addr, size, true)  returns false as expected because
we got dev_addr equals 64b1d0000 and according to this _expression_ under dma_capable():

```
dma_addr_t end = dev_addr + size - 1;
return end <= min_not_zero(*dev->dma_mask, dev->bus_dma_limit);
```
As result, DMA mask more than 32bit.

Let me start with that I agree we should disable swiotlb when we know
the device is protected. However, from what you describe, it sounds like
the same issue would appear if the IOMMU was disabled.

Yes, it looks like a potential issue. This means that swiotlb should be worked correctly, when it's needed, agreed.
But this is also potential improvement, and I presented this idea to discuss and create some patches.

Therefore, I think we should first find out why Linux wants to bounce
the DMA buffer.

We retrieved dev_addr(64b1d0000) + size > 32bit mask, but fcp driver wants to use only 32 bit boundary address, but that's consequence.
I think, the main reason of using bounce buffer is MFN address, not DMA phys address.

Cheers!

From: Julien Grall <julien@xxxxxxx>
Sent: Tuesday, August 10, 2021 7:16 PM
To: Roman Skakun <Roman_Skakun@xxxxxxxx>; sstabellini@xxxxxxxxxx <sstabellini@xxxxxxxxxx>
Cc: Bertrand Marquis <bertrand.marquis@xxxxxxx>; Andrii Anisov <Andrii_Anisov@xxxxxxxx>; Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>; Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>; Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx <xen-devel@xxxxxxxxxxxxxxxxxxxx>; Roman Skakun <rm.skakun@xxxxxxxxx>; Jan Beulich <jbeulich@xxxxxxxx>
Subject: Re: Disable swiotlb for Dom0
 


On 10/08/2021 16:38, Roman Skakun wrote:
> Hi, Stefano!

Hi,

> I have observed your patch here:
> https://urldefense.com/v3/__https://patchwork.kernel.org/project/xen-devel/patch/alpine.DEB.2.21.2102161333090.3234@sstabellini-ThinkPad-T480s/__;!!GF_29dbcQIUBPA!kH5gzG1mxcIgDqMu2cVjTD3ggN9LiPN4OVinOnqrhLQrNr-mRb72udp2B5XBqZlW$ [patchwork[.]kernel[.]org]
>
> And I collided with the same issue, when Dom0 device trying to use
> swiotlb fops for devices which are controlled by IOMMU.

The issue Stefano reported was when the dom0 is not direct mapped.
However...

>
> Prerequisites:
> https://urldefense.com/v3/__https://github.com/xen-project/xen/tree/stable-4.15__;!!GF_29dbcQIUBPA!kH5gzG1mxcIgDqMu2cVjTD3ggN9LiPN4OVinOnqrhLQrNr-mRb72udp2B6EVrRb_$ [github[.]com]

... if you are really using 4.15, then the domain will always be direct
mapped. So I think this is a different one.

> https://urldefense.com/v3/__https://github.com/torvalds/linux/tree/v5.10__;!!GF_29dbcQIUBPA!kH5gzG1mxcIgDqMu2cVjTD3ggN9LiPN4OVinOnqrhLQrNr-mRb72udp2B1n8el4F$ [github[.]com]

Any reason to not use the stable branch for 5.10? I don't know whether
your issue will be fixed there, but the stable branch usually contains a
lot of bug fixes (including security one). So it is a good idea to use
it over the first release of a kernel version.

> Issue caused in xen_swiotlb_map_page():
> ```
>   dev: rcar-fcp, cap: 0, dma_mask: ffffffff, page: fffffe00180c7400, page_to_phys: 64b1d0000,
> xen_phys_to_dma(phys): 64b1d0000
> ```

I can't seem to find this printk in Linux 5.10. Did you add it yourself?

>
> There is retrieved MFN(0x64b1d0000), which belongs to DomU. Dom0
> swiotlb couldn't proceed to this address and throws the log:
>
> ```
> [   99.504990] rcar-fcp fea2f000.fcp: swiotlb buffer is full (sz: 3686400 bytes), total 32768 (slots), used 64 (slots)
> ```

This line suggests that the SWIOTLB tried to bounce the DMA buffer. In
general, the use of the bounce buffer should be rare. So I would suggest
to find out why this is used.

Looking at the code, this suggests that one of the following check is false:

         /*
          * If the address happens to be in the device's DMA window,
          * we can safely return the device addr and not worry about bounce
          * buffering it.
          */
         if (dma_capable(dev, dev_addr, size, true) &&
             !range_straddles_page_boundary(phys, size) &&
                 !xen_arch_need_swiotlb(dev, phys, dev_addr) &&
                 swiotlb_force != SWIOTLB_FORCE)
                 goto done;

>
> Temporary, I resolved this issue by disabling swiotlb for dom0 at all
> because sure that all devices goes through IOMMU, but this mention can
> be true only for me.
>
> But, I think of a more reliable way is to declare a special IOMMU
> property in xen dts for each device. If the device controlled by IOMMU
> not need to set swiotlb fops in arch_setup_dma_ops.
> What do you think about it?

Let me start with that I agree we should disable swiotlb when we know
the device is protected. However, from what you describe, it sounds like
the same issue would appear if the IOMMU was disabled.

Therefore, I think we should first find out why Linux wants to bounce
the DMA buffer. Does your device have any DMA restriction?

Cheers,

--
Julien Grall

 


Rackspace

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