lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250924141018.80202-7-mngyadam@amazon.de>
Date: Wed, 24 Sep 2025 16:09:57 +0200
From: Mahmoud Adam <mngyadam@...zon.de>
To: <kvm@...r.kernel.org>
CC: <alex.williamson@...hat.com>, <jgg@...pe.ca>, <kbusch@...nel.org>,
	<benh@...nel.crashing.org>, David Woodhouse <dwmw@...zon.co.uk>,
	<pravkmr@...zon.de>, <nagy@...aternagy.com>, <linux-kernel@...r.kernel.org>
Subject: [RFC PATCH 6/7] vfio-pci: add alias_region mmap ops

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@...zon.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ