vfio/fsl-mc: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations
authorYishai Hadas <yishaih@nvidia.com>
Sun, 8 Jan 2023 15:44:26 +0000 (17:44 +0200)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 23 Jan 2023 18:26:30 +0000 (11:26 -0700)
Use GFP_KERNEL_ACCOUNT for userspace persistent allocations.

The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this
is untrusted allocation triggered from userspace and should be a subject
of kmem accounting, and as such it is controlled by the cgroup
mechanism.

Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20230108154427.32609-6-yishaih@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/fsl-mc/vfio_fsl_mc.c
drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c

index defeb8510ace52dd64921193cef5ef6aeca49866..c89a047a4cd815cbcb827a8ad3a86457a303c039 100644 (file)
@@ -28,7 +28,7 @@ static int vfio_fsl_mc_open_device(struct vfio_device *core_vdev)
        int i;
 
        vdev->regions = kcalloc(count, sizeof(struct vfio_fsl_mc_region),
-                               GFP_KERNEL);
+                               GFP_KERNEL_ACCOUNT);
        if (!vdev->regions)
                return -ENOMEM;
 
index 64d01f3fb13d1208299bc55fda130f9fa87f1acb..c51229fccbd6a8f24600ac95a9f93ab6da5b4aee 100644 (file)
@@ -29,7 +29,7 @@ static int vfio_fsl_mc_irqs_allocate(struct vfio_fsl_mc_device *vdev)
 
        irq_count = mc_dev->obj_desc.irq_count;
 
-       mc_irq = kcalloc(irq_count, sizeof(*mc_irq), GFP_KERNEL);
+       mc_irq = kcalloc(irq_count, sizeof(*mc_irq), GFP_KERNEL_ACCOUNT);
        if (!mc_irq)
                return -ENOMEM;
 
@@ -77,7 +77,7 @@ static int vfio_set_trigger(struct vfio_fsl_mc_device *vdev,
        if (fd < 0) /* Disable only */
                return 0;
 
-       irq->name = kasprintf(GFP_KERNEL, "vfio-irq[%d](%s)",
+       irq->name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-irq[%d](%s)",
                            hwirq, dev_name(&vdev->mc_dev->dev));
        if (!irq->name)
                return -ENOMEM;