lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <yq5awm1ck3zw.fsf@kernel.org>
Date: Tue, 20 Jan 2026 15:19:55 +0530
From: Aneesh Kumar K.V <aneesh.kumar@...nel.org>
To: Marek Szyprowski <m.szyprowski@...sung.com>,
	Robin Murphy <robin.murphy@....com>, iommu@...ts.linux.dev,
	linux-kernel@...r.kernel.org
Cc: Arnd Bergmann <arnd@...nel.org>, Linus Walleij <linusw@...nel.org>,
	Matthew Wilcox <willy@...radead.org>,
	Suzuki K Poulose <suzuki.poulose@....com>
Subject: Re: [PATCH] dma-direct: Skip cache prep for HighMem coherent
 allocations

Marek Szyprowski <m.szyprowski@...sung.com> writes:

> On 19.01.2026 05:13, Aneesh Kumar K.V wrote:
>> Marek Szyprowski <m.szyprowski@...sung.com> writes:
>>> On 12.01.2026 13:22, Aneesh Kumar K.V wrote:
>>>> Marek Szyprowski <m.szyprowski@...sung.com> writes:
>>>>> On 09.01.2026 04:15, Aneesh Kumar K.V wrote:
>>>>>> Robin Murphy <robin.murphy@....com> writes:
>>>>>>> On 2026-01-08 12:41 pm, Marek Szyprowski wrote:
>>>>>>>> On 08.01.2026 11:50, Robin Murphy wrote:
>>>>>>>>> On 2026-01-02 3:51 pm, Aneesh Kumar K.V (Arm) wrote:
>>>>>>>>>> dma_direct_alloc() calls arch_dma_prep_coherent() to clean any dirty
>>>>>>>>>> cache lines from the kernel linear alias before creating a coherent
>>>>>>>>>> remapping.
>>>>>>>>>>
>>>>>>>>>> HighMem pages have no kernel alias mapping, so there are no alias cache
>>>>>>>>>> lines to clean. Skip arch_dma_prep_coherent() for HighMem allocations.
>>>>>>>>> This is assuming that caches are always cleaned when unmapping
>>>>>>>>> highmem, and no still-mapped highmem pages are dirty - how is that
>>>>>>>>> guaranteed? The fact that they're not in the linear map doesn't mean
>>>>>>>>> they don't necessarily have kernel aliases in either vmalloc
>>>>>>>>> pagetables or caches.
>>>>>>>> Right, so it is better to keep this unconditional
>>>>>>>> arch_dma_prep_coherent() call. I will drop it from dma-mapping-fixes then.
>>>>>>> Yeah, I think the confusing thing here is that there are architectures
>>>>>>> with CONFIG_HIGHMEM that don't actually check for and handle it in their
>>>>>>> arch_dma_prep_coherent() as they seemingly should, however I'm not sure
>>>>>>> off-hand whether they also support/use highmem CMA in the manner that
>>>>>>> could end up being an issue in practice (the lack of any reports of
>>>>>>> crashes or DMA corruption over the last however many years suggests not...)
>>>>>>>
>>>>>> Should we then remove the PageHighMem() check with DMA_ATTR_NO_KERNEL_MAPPING?
>>>>> Right, this has to be unified.
>>>> I had a related question, how do we handle cache flushes required for
>>>> architectures that don't implement CONFIG_ARCH_HAS_DMA_PREP_COHERENT (arch/arm)?
>>> ARM 32bit architecture provides arch_dma_alloc(), which handles cache
>>> management internally.
>>>
>> But dma_direct_alloc does the below
>>
>> 	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
>> 	    !force_dma_unencrypted(dev) && !is_swiotlb_for_alloc(dev))
>> 		return dma_direct_alloc_no_mapping(dev, size, dma_handle, gfp);
>>
>> 	if (!dev_is_dma_coherent(dev)) {
>> 		if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_ALLOC) &&
>> 		    !is_swiotlb_for_alloc(dev))
>> 			return arch_dma_alloc(dev, size, dma_handle, gfp,
>> 					      attrs);
>>
>> IIUC, this implies we won't call arch_dma_alloc for
>> DMA_ATTR_NO_KERNEL_MAPPING ?
>
> It looks that commit 849facea92fa ("dma-direct: simplify the 
> DMA_ATTR_NO_KERNEL_MAPPING handling") changed this. Before that 
> arch_dma_alloc() was called regardless of the provided DMA attrs. 
> Indeed, this should be fixed. Frankly speaking this probably means that 
> there are no active users of this combination (arch/arm, 
> DMA_ATTR_NO_KERNEL_MAPPING and dma-direct) or nobody cares.
>

Before that commit we did

	if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
	    !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
	    dma_alloc_need_uncached(dev, attrs))
		return arch_dma_alloc(dev, size, dma_handle, gfp, attrs);

dma_alloc_need_uncached() returned false for DMA_ATTR_NO_KERNEL_MAPPING

static __always_inline bool dma_alloc_need_uncached(struct device *dev,
		unsigned long attrs)
{
	if (dev_is_dma_coherent(dev))
		return false;
	if (attrs & DMA_ATTR_NO_KERNEL_MAPPING)
		return false;
	return true;
}

It looks like for DMA_ATTR_NO_KERNEL_MAPPING, we never called into arch_dma_alloc()?

>
> The DMA_ATTR_NO_KERNEL_MAPPING attribute was initially introduced for 
> the DMA-IOMMU based implementation, where it saves significant amount of 
> resources.
>


-aneesh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ