From: sashiko-bot@kernel.org
To: "Guanghui Feng" <guanghuifeng@linux.alibaba.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 1/2] vfio: Add get_unmapped_area callback to vfio_device_ops
Date: Tue, 24 Nov 2026 12:51:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-231182@kernel.org> (raw)
In-Reply-To: <20261124124004.457441-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 0477ef7e38ed92136abaf6feac25d75050278697
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 a corresponding vfio_device_fops dispatcher so bus drivers can align
mmap 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() skip
device->ops->get_unmapped_area() and fall back to mm_get_unmapped_area()
when flags & MAP_FIXED is set?
The commit message states that a MAP_FIXED mapping never reaches the hook,
which matches dax_get_unmapped_area() only checking whether addr is
non-zero. However, do_mmap() folds MAP_FIXED_NOREPLACE into MAP_FIXED,
skips round_hint_to_min(addr) when MAP_FIXED is set, and still invokes
__get_unmapped_area() -> file->f_op->get_unmapped_area(). If a driver
implements this callback assuming MAP_FIXED cannot reach it (or checks only
!addr), calling mmap() with addr == 0 and MAP_FIXED will run the driver's
alignment logic and shift the requested fixed address instead of mapping at
0.
The follow-up commit "vfio/pci: Align BAR mappings for huge page support"
checks flags & (MAP_FIXED | MAP_FIXED_NOREPLACE) in
vfio_pci_core_get_unmapped_area(), but checking flags & MAP_FIXED here in
vfio_device_fops_get_unmapped_area() would enforce the documented contract
for all VFIO bus drivers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124124004.457441-1-guanghuifeng@linux.alibaba.com?part=1
next prev parent reply other threads:[~2026-11-24 12:51 UTC|newest]
Thread overview: 9+ 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
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
2026-11-24 12:40 ` [PATCH v2 0/2] vfio/pci: Provide kernel-side BAR alignment for huge page mapping Guanghui Feng
2026-11-24 12:40 ` [PATCH v2 1/2] vfio: Add get_unmapped_area callback to vfio_device_ops Guanghui Feng
2026-11-24 12:51 ` sashiko-bot [this message]
2026-11-24 12:40 ` [PATCH v2 2/2] vfio/pci: Align BAR mappings for huge page support Guanghui Feng
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-231182@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