All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guanghui Feng" <guanghuifeng@linux.alibaba.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 2/2] vfio/pci: Align BAR mappings for huge page support
Date: Tue, 24 Nov 2026 12:59:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-231185@kernel.org> (raw)
In-Reply-To: <20261124124004.457441-3-guanghuifeng@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vfio/pci: missing PMD_SIZE fallback in
  vfio_pci_core_get_unmapped_area()
--

commit 3832a7d37e0d4c0624cff5984fcc1260c28a37ab
Author: Guanghui Feng <guanghuifeng@linux.alibaba.com>

vfio/pci: Align BAR mappings for huge page support

This commit implements vfio_pci_core_get_unmapped_area() to align BAR VMA
addresses to PMD_SIZE or PUD_SIZE and sets VM_HUGEPAGE on BAR mappings so
vfio_pci_mmap_huge_fault() can install huge pfnmaps.

> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index f2d5b6857925f..a1ccdd5f4657f 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
[ ... ]
> @@ -1878,12 +1879,106 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
[ ... ]
> +unsigned long vfio_pci_core_get_unmapped_area(struct vfio_device *core_vdev,
> +					      struct file *filp,
> +					      unsigned long addr,
> +					      unsigned long len,
> +					      unsigned long pgoff,
> +					      unsigned long flags)
> +{
[ ... ]
> +	/*
> +	 * Select the largest huge page size that the BAR physical alignment,
> +	 * mapping length, and arch support can all satisfy.  Only PMD and PUD
> +	 * orders are supported by vfio_pci_vmf_insert_pfn().
> +	 */
> +	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PUD_PFNMAP) &&
> +	    bar_len >= PUD_SIZE && len >= PUD_SIZE)
> +		align = PUD_SIZE;
> +	else if (bar_len >= PMD_SIZE && len >= PMD_SIZE)
> +		align = PMD_SIZE;
> +	else
> +		goto out;
> +
> +	off = pgoff << PAGE_SHIFT;
> +	off_end = off + len;
> +	if (off_end < off)
> +		goto out;
> +	off_align = round_up(off, align);
> +
> +	/* The mapping has to span at least one fully aligned huge page */
> +	if (off_end <= off_align || off_end - off_align < align)
> +		goto out;
> +
> +	len_align = len + align;
> +	if (len_align < len)
> +		goto out;
> +
> +	/*
> +	 * Find an area that can hold the mapping plus the slack needed to
> +	 * shift it up to the next aligned address, then apply that shift.
> +	 * The shift preserves the relative alignment of the file offset,
> +	 * which is what makes the pfn alignment work out.
> +	 */
> +	addr_align = mm_get_unmapped_area(filp, addr, len_align, pgoff, flags);
> +	if (!IS_ERR_VALUE(addr_align)) {
> +		addr_align += (off - addr_align) & (align - 1);
> +		return addr_align;
> +	}
> +
> +out:
> +	return mm_get_unmapped_area(filp, addr, len, pgoff, flags);
> +}

[Severity: Medium]
Should vfio_pci_core_get_unmapped_area() fall back to PMD_SIZE when
PUD_SIZE alignment cannot be satisfied?

When CONFIG_ARCH_SUPPORTS_PUD_PFNMAP is enabled and both bar_len and len
are at least PUD_SIZE, align is set to PUD_SIZE before checking whether
[off, off_end) spans a PUD_SIZE-aligned boundary or whether
mm_get_unmapped_area() can find a len + PUD_SIZE range.  If a mapping on a
2 GiB BAR starts at a non-1GiB-aligned offset (for example to skip an
MSI-X table at the start of the BAR) and does not enclose a full 1 GiB
PUD page, or if virtual address space is too fragmented for len + PUD_SIZE,
this jumps straight to out and returns a PAGE_SIZE-aligned VMA.
is_aligned_for_order() in vfio_pci_mmap_huge_fault() then fails for
PMD_ORDER as well, degrading the entire mapping to PAGE_SIZE faults instead
of using PMD huge pfnmaps.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124124004.457441-1-guanghuifeng@linux.alibaba.com?part=2

  reply	other threads:[~2026-11-24 12:59 UTC|newest]

Thread overview: 12+ 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
2026-11-24 12:40   ` [PATCH v2 2/2] vfio/pci: Align BAR mappings for huge page support Guanghui Feng
2026-11-24 12:59     ` sashiko-bot [this message]
2026-11-24 13:52     ` Jason Gunthorpe
2026-11-24 17:25       ` Lorenzo Stoakes (ARM)

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-231185@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.