Page MenuHomeFreeBSD

linux_dma: Ensure proper flags pass to allocators.
ClosedPublic

Authored by bdrewery on Dec 8 2020, 5:44 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 18, 12:52 PM
Unknown Object (File)
Mon, Nov 18, 1:50 AM
Unknown Object (File)
Oct 13 2024, 1:16 AM
Unknown Object (File)
Oct 1 2024, 2:35 PM
Unknown Object (File)
Sep 25 2024, 9:20 AM
Unknown Object (File)
Sep 23 2024, 1:00 AM
Unknown Object (File)
Sep 22 2024, 4:52 PM
Unknown Object (File)
Sep 21 2024, 10:44 PM

Details

Summary

No functional change intended.

Sponsored by: Dell EMC

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Hi,

Can you explain this change a bit more?

gfp_t may contain bits which are not supported by the M_XXX flags and should be filtered away?

If you need to pass additional flags you need to update GFP_NATIVE_MASK .

--HPS

Hi,

Can you explain this change a bit more?

gfp_t may contain bits which are not supported by the M_XXX flags and should be filtered away?

If you need to pass additional flags you need to update GFP_NATIVE_MASK .

--HPS

% git grep GFP_NATIVE_MASK sys
sys/compat/linuxkpi/common/include/linux/gfp.h:#define  GFP_NATIVE_MASK (M_NOWAIT | M_WAITOK | M_USE_RESERVE | M_ZERO)
sys/compat/linuxkpi/common/include/linux/gfp.h:CTASSERT((__GFP_DMA32 & GFP_NATIVE_MASK) == 0);
sys/compat/linuxkpi/common/include/linux/gfp.h:CTASSERT((__GFP_BITS_MASK & GFP_NATIVE_MASK) == GFP_NATIVE_MASK);
sys/compat/linuxkpi/common/include/linux/slab.h:        return (flags & GFP_NATIVE_MASK);
sys/compat/linuxkpi/common/src/linux_page.c:            addr = kmem_malloc(size, flags & GFP_NATIVE_MASK);
sys/compat/linuxkpi/common/src/linux_page.c:            addr = kmem_alloc_contig(size, flags & GFP_NATIVE_MASK, 0,

While reviewing the code here, I noticed the kmem_malloc and kmem_alloc_contig in linux_page.c were masking but not the calls in linux_pci.c. Yes this masks to only pass the acceptable M_ flags.

	if (priv->dma_mask)
		high = priv->dma_mask;
	else if (flag & GFP_DMA32)                                 //////////////////////////// here
		high = BUS_SPACE_MAXADDR_32BIT;
	else
		high = BUS_SPACE_MAXADDR;
	align = PAGE_SIZE << get_order(size);
	mem = (void *)kmem_alloc_contig(size, flag, 0, high, align, 0,
	    VM_MEMATTR_DEFAULT);

It looks like GFP_DMA32 may be set in flag, 1 << 24 which isn't a normal flag kmem_alloc_contig should be seeing. It appears harmless currently.

Then there is a possible bug in linux_pci.c

Mixed right and left side. Thought you were removing the GFP_NATIVE_MASK.

This revision is now accepted and ready to land.Dec 9 2020, 8:40 PM