From: sashiko-bot@kernel.org
To: "Guanghui Feng" <guanghuifeng@linux.alibaba.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] vfio: Add get_unmapped_area callback to vfio_device_ops
Date: Tue, 24 Nov 2026 07:48:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-230674@kernel.org> (raw)
In-Reply-To: <20261124073048.268988-2-guanghuifeng@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vfio: MAP_FIXED mappings reach
device->ops->get_unmapped_area()
--
commit c2dec2a94cdf65407cd97caccc3240752b010cec
Author: Guanghui Feng <guanghuifeng@linux.alibaba.com>
vfio: Add get_unmapped_area callback to vfio_device_ops
This commit adds an optional get_unmapped_area callback to vfio_device_ops
and dispatches to it from vfio_device_fops so bus drivers can align VMA
virtual addresses for huge pfnmaps.
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 4e5d738ccf4be..edf9eb4cd4778 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
[ ... ]
> @@ -1431,6 +1432,36 @@ static int vfio_device_fops_mmap(struct file *filep, struct vm_area_struct *vma)
> return device->ops->mmap(device, vma);
> }
>
> +#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP
> +/*
> + * Give the bus driver a chance to request a virtual address that allows the
> + * mapping to be backed by huge pages, fex. a PCI BAR mapping that could be
> + * faulted in with PMD or PUD sized pfnmaps. Anything the driver cannot
> + * handle, including devices without huge mapping support, falls back to the
> + * generic address selection, which is also what happens without this
> + * callback.
> + */
> +static unsigned long vfio_device_fops_get_unmapped_area(struct file *filep,
> + unsigned long addr,
> + unsigned long len,
> + unsigned long pgoff,
> + unsigned long flags)
> +{
> + struct vfio_device_file *df = filep->private_data;
> + struct vfio_device *device = df->device;
> +
> + /* Paired with smp_store_release() following vfio_df_open() */
> + if (!smp_load_acquire(&df->access_granted))
> + goto out;
> +
> + if (device->ops->get_unmapped_area)
> + return device->ops->get_unmapped_area(device, filep, addr, len,
> + pgoff, flags);
> +out:
> + return mm_get_unmapped_area(filep, addr, len, pgoff, flags);
> +}
> +#endif
[Severity: Medium]
Should vfio_device_fops_get_unmapped_area() bail out to out when
flags & MAP_FIXED is set?
The commit message states that a MAP_FIXED mapping never reaches the hook,
however do_mmap() and __get_unmapped_area() invoke
file->f_op->get_unmapped_area() unconditionally even when MAP_FIXED or
MAP_FIXED_NOREPLACE is set (the MAP_FIXED check only happens inside
generic_get_unmapped_area() / generic_get_unmapped_area_topdown() via
mm_get_unmapped_area()). If a bus driver implements get_unmapped_area()
by only checking whether addr is non-zero (like dax_get_unmapped_area()),
a MAP_FIXED request at addr == 0 with an unaligned file offset can have its
fixed address shifted to a non-zero aligned offset, violating MAP_FIXED
semantics and overwriting mappings at the shifted address.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124073048.268988-1-guanghuifeng@linux.alibaba.com?part=1
next prev parent reply other threads:[~2026-11-24 7:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 7:30 [PATCH 0/2] vfio/pci: Provide kernel-side BAR alignment for huge page mapping Guanghui Feng
2026-11-24 7:30 ` [PATCH 1/2] vfio: Add get_unmapped_area callback to vfio_device_ops Guanghui Feng
2026-11-24 7:48 ` sashiko-bot [this message]
2026-11-24 7:30 ` [PATCH 2/2] vfio/pci: Align BAR mappings for huge page support Guanghui Feng
2026-11-24 7:52 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-230674@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=guanghuifeng@linux.alibaba.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox