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

Re: [PATCH RFC] xen/swiotlb: avoid arch_sync_dma_* on per-device DMA memory


  • To: Jason Gunthorpe <jgg@xxxxxxxx>
  • From: Peng Fan <peng.fan@xxxxxxxxxxx>
  • Date: Fri, 24 Apr 2026 14:57:19 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bKmrSqn3mEOETaFW5rN2OEA5bGxOIbczvq85Q03itfg=; b=xIRzdjflIxKIM3fWpoMfb8rv0+8zgtSwnWJu4zOBZ9i73kFGqP1ayKdc9FgCBDKR0gRCbrP3pSytHBmLSIKBmpW2ZsMWC1hiHYTSrVDuXrEB0hl4SWRX+RB8VZ1k+LJt1hhl78EcuDlOCAmgU7Urgmn3Not8TCYdlo4QQq9OfwraWf0ZX7AAsgvymDABPUFQfG9bbuRyFS1xgN6fxSAR8w44YjBVJkRWG1PCHg777yc9gULwNYH1QNVKAsKf8dH48E98XW43wB73nleJTwgiPmkgICazi0x24STNl+/79nBn/cB9akG0p5O0PfsIhohW3tX9OwsDostyc5yqM1nxDQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ONOknKi0dEDjJvvYA1TAf+FZgt2l8vGH78ytJXjQuhLsGFiWKk1+QCJawWOsI7fP9eDtHhG6k0uCgIXk1B2I8IZtkwRwVja2POipYUGu4yyesJgmumOdhWTFHfxCFu/tYZquMQO6XxGyJ7lwL2NdqpKKNaCgLmrVXqJg/4/se4ljp9szE5h5x2y7ZxBbLMin5Xk6jL2yLKferpo+MseE1yHkWHPJV2mOaVZRFQYFqXdyfThwi0yoFA+Uv9NH1ZLQo2Ljch6tjsMYmle+bOH+7b5uIh4tnjDjNlK4C/FZwyN1w500Aq55TZrD2OiZrrLt6a01m9SRkiuMYXUz2n6D1A==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1-NXP1-onmicrosoft-com header.d=NXP1.onmicrosoft.com header.i="@NXP1.onmicrosoft.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com;
  • Cc: Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, iommu@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Peng Fan <peng.fan@xxxxxxx>
  • Delivery-date: Fri, 24 Apr 2026 06:55:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Jason,

On Mon, Apr 20, 2026 at 08:01:37PM -0300, Jason Gunthorpe wrote:
>On Wed, Apr 15, 2026 at 11:08:36PM +0800, Peng Fan (OSS) wrote:
>> From: Peng Fan <peng.fan@xxxxxxx>
>> 
>> On ARM64, arch_sync_dma_for_{cpu,device}() assumes that the
>> physical address passed in refers to normal RAM that is part of the
>> kernel linear(direct) mapping, as it unconditionally derives a CPU
>> virtual address via phys_to_virt().
>> 
>> With Xen swiotlb, devices may use per-device coherent DMA memory,
>> such as reserved-memory regions described by 'shared-dma-pool',
>> which are assigned to dev->dma_mem. These regions may be marked
>> no-map in DT and therefore are not part of the kernel linear map.
>> In such cases, pfn_valid() still returns true, but phys_to_virt()
>> is not valid and cache maintenance via arch_sync_dma_* will fault.
>> 
>> Prevent this by excluding devices with a private DMA memory pool
>> (dev->dma_mem) from the arch_sync_dma_* fast path, and always
>> fall back to xen_dma_sync_* for those devices to avoid invalid
>> phys_to_virt() conversions for no-map DMA memory while preserving the
>> existing fast path for normal, linear-mapped RAM.
>
>I think this is the same sort of weirdness the other two CC threads are
>dealing with.. We already have two different flags indicating the
>cache flush should be skipped, it would make more sense to have the
>swiotlb mangle the flags, just like for cc.
>
>https://lore.kernel.org/r/20260420061415.3650870-1-aneesh.kumar@xxxxxxxxxx
>
>Then you know that the swiotlb was used and it should flow down to
>here.

Xen fully implements dev->dma_ops and does not leak hypervisor-specific
semantics outside of it.

The issue is that the existing DMA attribute model only distinguishes
between "CPU sync required" and "no sync required at all". Xen needs
a third case: CPU cache sync must be skipped, but platform-level DMA
synchronization remains mandatory.

This is not a generic DMA extension but a constraint of Xen's DMA
model when mapping private or foreign memory that is not CPU-mapped.

>
>>   * physical address to use is returned.
>> @@ -262,7 +267,8 @@ static dma_addr_t xen_swiotlb_map_phys(struct device 
>> *dev, phys_addr_t phys,
>>  
>>  done:
>>      if (!dev_is_dma_coherent(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) {
>> -            if (pfn_valid(PFN_DOWN(dma_to_phys(dev, dev_addr)))) {
>> +            if (pfn_valid(PFN_DOWN(dma_to_phys(dev, dev_addr))) &&
>> +                !dev_has_private_dma_pool(dev)) {
>
>Also this pfn_valid() is totally bogus. Unless DMA_ATTR_MMIO the phys
>must have a struct page, be pfn_valid, etc.
>
>This is why you are getting into trouble here, beacuse swiotlb created
>a non-struct page address and passed it to lower layers without
>setting something like DMA_ATTR_MMIO..

See above.
xen swiotlb maybe a bit misleading, it is not kind of linux swiotlb.

Juergen, Stefano,

Please help correct if I am wrong or I may miss something.

Thanks,
Peng

>
>Jason
>



 


Rackspace

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