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)
Dec 20 2023, 5:52 AM
Unknown Object (File)
Dec 12 2023, 12:20 PM
Unknown Object (File)
Dec 10 2023, 12:37 PM
Unknown Object (File)
Nov 2 2023, 12:08 PM
Unknown Object (File)
Sep 4 2023, 8:11 AM
Unknown Object (File)
Sep 4 2023, 8:11 AM
Unknown Object (File)
Sep 4 2023, 8:10 AM
Unknown Object (File)
Aug 29 2023, 1:36 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