Skip to content

Commit

Permalink
Revert "linuxkpi: GFP_KERNEL equals M_NOWAIT now"
Browse files Browse the repository at this point in the history
This change seems to break some drivers such as the mlx5*(4) drivers.

As kib@ says:
> According to the 'official' Linux kernel documentation, the GFP_KERNEL
> flag implies sleepable context.

It was introduced while working on the new vt(4)/DRM integration [1].
During this work, doing sleepable allocations broke vt(4) and the DRM
drivers. However, I made further improvements and some locking-related
fixed to the new integration without revisiting the need for it.

After more testing, the improvements to the integration mentionned above
seems to make the change to `GFP_KERNEL` unneeded now. I can thus
revert it to restore expectations of other drivers.

This reverts commit 14dcd40.

[1] freebsd/drm-kmod#243

Reviewed by:	kib
Approved by:	kib
Differential Revision:	https://reviews.freebsd.org/D42962
  • Loading branch information
dumbbell authored and bsdjhb committed Mar 5, 2024
2 parents e4bf2cc + 8a8e86b commit 4555ef3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sys/compat/linuxkpi/common/include/linux/gfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

#define GFP_NOWAIT M_NOWAIT
#define GFP_ATOMIC (M_NOWAIT | M_USE_RESERVE)
#define GFP_KERNEL M_NOWAIT
#define GFP_KERNEL M_WAITOK
#define GFP_USER M_WAITOK
#define GFP_HIGHUSER M_WAITOK
#define GFP_HIGHUSER_MOVABLE M_WAITOK
Expand Down
8 changes: 4 additions & 4 deletions sys/compat/linuxkpi/common/include/linux/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ MALLOC_DECLARE(M_KMALLOC);
#define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO)
#define kzalloc_node(size, flags, node) kmalloc_node(size, (flags) | __GFP_ZERO, node)
#define kfree_const(ptr) kfree(ptr)
#define vzalloc(size) __vmalloc(size, M_WAITOK | __GFP_NOWARN | __GFP_ZERO, 0)
#define vzalloc(size) __vmalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 0)
#define vfree(arg) kfree(arg)
#define kvfree(arg) kfree(arg)
#define vmalloc_node(size, node) __vmalloc_node(size, M_WAITOK, node)
#define vmalloc_user(size) __vmalloc(size, M_WAITOK | __GFP_ZERO, 0)
#define vmalloc(size) __vmalloc(size, M_WAITOK, 0)
#define vmalloc_node(size, node) __vmalloc_node(size, GFP_KERNEL, node)
#define vmalloc_user(size) __vmalloc(size, GFP_KERNEL | __GFP_ZERO, 0)
#define vmalloc(size) __vmalloc(size, GFP_KERNEL, 0)
#define __kmalloc(...) kmalloc(__VA_ARGS__)

/*
Expand Down
7 changes: 2 additions & 5 deletions sys/compat/linuxkpi/common/src/linux_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ linux_file_alloc(void)
{
struct linux_file *filp;

filp = kzalloc(sizeof(*filp), M_WAITOK);
filp = kzalloc(sizeof(*filp), GFP_KERNEL);

/* set initial refcount */
filp->f_count = 1;
Expand Down Expand Up @@ -1410,9 +1410,6 @@ linux_file_mmap_single(struct file *fp, const struct file_operations *fop,
return (EINVAL);

vmap = kzalloc(sizeof(*vmap), GFP_KERNEL);
if (vmap == NULL)
return (ENOMEM);

vmap->vm_start = 0;
vmap->vm_end = size;
vmap->vm_pgoff = *offset / PAGE_SIZE;
Expand Down Expand Up @@ -1940,7 +1937,7 @@ vmmap_add(void *addr, unsigned long size)
{
struct vmmap *vmmap;

vmmap = kmalloc(sizeof(*vmmap), M_WAITOK);
vmmap = kmalloc(sizeof(*vmmap), GFP_KERNEL);
mtx_lock(&vmmaplock);
vmmap->vm_size = size;
vmmap->vm_addr = addr;
Expand Down
3 changes: 0 additions & 3 deletions sys/compat/linuxkpi/common/src/linux_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ lkpi_request_irq(struct device *xdev, unsigned int irq,
GFP_KERNEL | __GFP_ZERO);
else
irqe = kzalloc(sizeof(*irqe), GFP_KERNEL);
if (irqe == NULL)
return (-ENOMEM);

irqe->dev = dev;
irqe->res = res;
irqe->arg = arg;
Expand Down
4 changes: 2 additions & 2 deletions sys/compat/linuxkpi/common/src/linux_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ lkpifill_pci_dev(device_t dev, struct pci_dev *pdev)
pdev->subsystem_device = pci_get_subdevice(dev);
pdev->class = pci_get_class(dev);
pdev->revision = pci_get_revid(dev);
pdev->path_name = kasprintf(M_WAITOK, "%04d:%02d:%02d.%d",
pdev->path_name = kasprintf(GFP_KERNEL, "%04d:%02d:%02d.%d",
pci_get_domain(dev), pci_get_bus(dev), pci_get_slot(dev),
pci_get_function(dev));
pdev->bus = malloc(sizeof(*pdev->bus), M_DEVBUF, M_WAITOK | M_ZERO);
Expand Down Expand Up @@ -1468,7 +1468,7 @@ linux_dma_pool_create(char *name, struct device *dev, size_t size,

priv = dev->dma_priv;

pool = kzalloc(sizeof(*pool), M_WAITOK);
pool = kzalloc(sizeof(*pool), GFP_KERNEL);
pool->pool_device = dev;
pool->pool_entry_size = size;

Expand Down
11 changes: 2 additions & 9 deletions sys/compat/linuxkpi/common/src/linux_shmemfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,8 @@ linux_shmem_read_mapping_page_gfp(vm_object_t obj, int pindex, gfp_t gfp)
struct page *page;
int rv;

/*
* Historically, GFP_KERNEL was the equivalent of M_WAITOK. But it was
* changed to a synonym of M_NOWAIT to allow allocations in
* non-sleepable code.
*
* However, there was an assertion here to make sure that `gfp` was
* never set to GFP_NOWAIT/M_NOWAIT. Do we need a specific handling of
* M_NOWAIT here?
*/
if ((gfp & GFP_NOWAIT) != 0)
panic("GFP_NOWAIT is unimplemented");

VM_OBJECT_WLOCK(obj);
rv = vm_page_grab_valid(&page, obj, pindex, VM_ALLOC_NORMAL |
Expand Down

0 comments on commit 4555ef3

Please sign in to comment.