From: Mahmoud Adam <mngyadam@amazon.de>
To: <kvm@vger.kernel.org>
Cc: <alex.williamson@redhat.com>, <jgg@ziepe.ca>, <kbusch@kernel.org>,
<benh@kernel.crashing.org>, David Woodhouse <dwmw@amazon.co.uk>,
<pravkmr@amazon.de>, <nagy@khwaternagy.com>,
<linux-kernel@vger.kernel.org>
Subject: [RFC PATCH 6/7] vfio-pci: add alias_region mmap ops
Date: Wed, 24 Sep 2025 16:09:57 +0200 [thread overview]
Message-ID: <20250924141018.80202-7-mngyadam@amazon.de> (raw)
In-Reply-To: <20250924141018.80202-1-mngyadam@amazon.de>
Implement struct vfio_pci_regops for alias regions. Where it
implements the mmap ops. When mmap is called on these regions it
translates the vm_pgoff to match the aliased region. Then it calls the
required mmap for the target region. It updates the vm_page_prot
afterwards with the requested flags.
The call path would be:
vfio_pci_core_mmap (index >= VFIO_PCI_NUM_REGIONS)
vfio_pci_alias_region_mmap (update vm_pgoff)
vfio_pci_core_mmap
For now no more information is needed more than the aliased index. So
we use region->data to save the aliased index number.
Note: Alias regions can't alias another alias.
Signed-off-by: Mahmoud Adam <mngyadam@amazon.de>
---
drivers/vfio/pci/vfio_pci_core.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 04b93bd55a5c2..962d3eda1ea9f 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1528,6 +1528,33 @@ static int vfio_pci_core_feature_token(struct vfio_device *device, u32 flags,
return 0;
}
+static int vfio_pci_alias_region_mmap(struct vfio_pci_core_device *vdev,
+ struct vfio_pci_region *region,
+ struct vm_area_struct *vma)
+{
+ unsigned int alias_index = (uintptr_t) region->data;
+ unsigned long vm_pgoff;
+ int ret;
+
+ /* change the pgoff to the corresponding alias */
+ vm_pgoff = alias_index << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
+ vm_pgoff |= vma->vm_pgoff &
+ ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
+ vma->vm_pgoff = vm_pgoff;
+
+ ret = vdev->vdev.ops->mmap(&vdev->vdev, vma);
+
+ /* overwrite prot with the alias flags */
+ if (region->flags & VFIO_REGION_INFO_FLAG_WC)
+ vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+
+ return ret;
+}
+
+struct vfio_pci_regops vfio_pci_alias_region_ops = {
+ .mmap = vfio_pci_alias_region_mmap,
+};
+
int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
void __user *arg, size_t argsz)
{
--
2.47.3
Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christian Schlaeger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
next prev parent reply other threads:[~2025-09-24 14:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 14:09 [RFC PATCH 0/7] vfio: Add alias region uapi for device feature Mahmoud Adam
2025-09-24 14:09 ` [RFC PATCH 1/7] vfio/pci: refactor region dereferences for RCU Mahmoud Adam
2025-09-24 14:09 ` [RFC PATCH 2/7] vfio_pci_core: split krealloc to allow use RCU & return index Mahmoud Adam
2025-09-24 14:09 ` [RFC PATCH 3/7] vfio/pci: add RCU locking for regions access Mahmoud Adam
2025-09-24 16:15 ` Mahmoud Nagy Adam
2025-09-24 14:09 ` [RFC PATCH 4/7] vfio: add FEATURE_ALIAS_REGION uapi Mahmoud Adam
2025-09-24 14:09 ` [RFC PATCH 5/7] vfio_pci_core: allow regions with no release op Mahmoud Adam
2025-09-24 14:09 ` Mahmoud Adam [this message]
2025-09-24 14:09 ` [RFC PATCH 7/7] vfio-pci-core: implement FEATURE_ALIAS_REGION uapi Mahmoud Adam
2025-10-03 21:58 ` [RFC PATCH 0/7] vfio: Add alias region uapi for device feature David Matlack
2025-10-05 10:16 ` Mahmoud Nagy Adam
2025-10-15 19:36 ` Alex Williamson
2025-10-27 16:32 ` David Matlack
2025-10-27 18:19 ` Mahmoud Nagy Adam
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=20250924141018.80202-7-mngyadam@amazon.de \
--to=mngyadam@amazon.de \
--cc=alex.williamson@redhat.com \
--cc=benh@kernel.crashing.org \
--cc=dwmw@amazon.co.uk \
--cc=jgg@ziepe.ca \
--cc=kbusch@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nagy@khwaternagy.com \
--cc=pravkmr@amazon.de \
/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