All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mahmoud Adam <mngyadam@amazon.de>
To: <kvm@vger.kernel.org>
Cc: <alex.williamson@redhat.com>, <jgg@ziepe.ca>,
	<benh@kernel.crashing.org>, David Woodhouse <dwmw@amazon.co.uk>,
	<pravkmr@amazon.de>, <nagy@khwaternagy.com>
Subject: [RFC PATCH 9/9] vfio_pci_core: support mmap attrs uapi & WC
Date: Mon, 4 Aug 2025 12:40:02 +0200	[thread overview]
Message-ID: <20250804104012.87915-10-mngyadam@amazon.de> (raw)
In-Reply-To: <20250804104012.87915-1-mngyadam@amazon.de>

Now we established the required dependencies to support WC through the
new vmmap in vfio_pci, this implements the new uapi & checks if the WC
attr is set while mmaping, then calls pgprot_writecombine.

Signed-off-by: Mahmoud Adam <mngyadam@amazon.de>
---
 drivers/vfio/pci/vfio_pci_core.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 8418d98ac66ce..461440700af75 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1198,6 +1198,30 @@ static int vfio_pci_ioctl_get_region_info2(struct vfio_pci_core_device *vdev,
 	return _vfio_pci_ioctl_get_region_info(vdev, mmap_mt, arg);
 }
 
+static int vfio_pci_ioctl_set_mmap_attrs(struct vfio_pci_core_device *vdev,
+					 struct maple_tree *mmap_mt,
+					 struct vfio_irq_info __user *arg)
+{
+	struct vfio_mmap_attrs vmmap_attrs;
+	struct vfio_pci_mmap *vmmap;
+
+	if (copy_from_user(&vmmap_attrs, arg, sizeof(vmmap_attrs)))
+		return -EFAULT;
+
+	if (vmmap_attrs.attrs & ~VFIO_MMAP_ATTR_WRITE_COMBINE)
+		return -EINVAL;
+
+	vmmap = mtree_load(mmap_mt, vmmap_attrs.offset);
+	if (!vmmap)
+		return -EINVAL;
+
+	if (!(vmmap->core.region_flags & VFIO_REGION_INFO_FLAG_MMAP))
+		return -EINVAL;
+
+	vmmap->core.attrs = vmmap_attrs.attrs;
+	return 0;
+}
+
 static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
 				       struct vfio_irq_info __user *arg)
 {
@@ -1549,6 +1573,8 @@ long vfio_pci_core_ioctl2(struct vfio_device *core_vdev, unsigned int cmd,
 	switch (cmd) {
 	case VFIO_DEVICE_GET_REGION_INFO:
 		return vfio_pci_ioctl_get_region_info2(vdev, mmap_mt, uarg);
+	case VFIO_DEVICE_SET_MMAP_ATTRS:
+		return vfio_pci_ioctl_set_mmap_attrs(vdev, mmap_mt, uarg);
 	default:
 		return vfio_pci_core_ioctl(core_vdev, cmd, arg);
 	}
@@ -1855,7 +1881,10 @@ static int _vfio_pci_core_mmap(struct vfio_device *core_vdev,
 	}
 
 	vma->vm_private_data = vdev;
-	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+	if (vmmap && vmmap->core.attrs & VFIO_MMAP_ATTR_WRITE_COMBINE)
+		vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+	else
+		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 	vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
 
 	/*
-- 
2.47.3




Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597


  parent reply	other threads:[~2025-08-04 10:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 10:39 [RFC PATCH 0/9] vfio: Introduce mmap maple tree Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 1/9] vfio: add mmap maple tree to vfio Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 2/9] vfio: add transient ops to support vfio mmap mt Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 3/9] vfio-pci-core: rename vm operations Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 4/9] vfio-pci-core: remove redundant offset calculations Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 5/9] vfio-pci-core: add vfio_pci_mmap & helpers Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 6/9] vfio-pci-core: support the new vfio ops Mahmoud Adam
2025-08-04 10:40 ` [RFC PATCH 7/9] vfio-pci: use " Mahmoud Adam
2025-08-04 10:40 ` [RFC PATCH 8/9] vfio: UAPI for setting mmap attributes Mahmoud Adam
2025-08-04 10:40 ` Mahmoud Adam [this message]
2025-08-04 18:49 ` [RFC PATCH 0/9] vfio: Introduce mmap maple tree Alex Williamson
2025-08-04 20:09   ` Mahmoud Nagy Adam
2025-08-05 14:31     ` Jason Gunthorpe
2025-08-05 15:48       ` Mahmoud Nagy Adam
2025-08-05 18:50         ` [RFC " Jason Gunthorpe
2025-08-05 19:00         ` Alex Williamson
     [not found]           ` <80dc87730f694b2d6e6aabbd29df49cf3c7c44fb.camel@amazon.com>
     [not found]             ` <20250806115224.GB377696@ziepe.ca>
2025-08-07  8:12               ` Herrenschmidt, Benjamin
2025-08-07 19:06                 ` Alex Williamson
2025-08-11 15:55                   ` Jason Gunthorpe
2025-08-11 22:07                     ` Alex Williamson
2025-08-12  0:30                       ` Jason Gunthorpe
2025-08-12 19:26                         ` Alex Williamson
2025-08-13  0:17                           ` Jason Gunthorpe
2025-08-14  8:39                       ` Mahmoud Nagy Adam
2025-08-14  9:52                       ` Mahmoud Nagy Adam
2025-08-14 17:52                         ` Alex Williamson
2025-08-28  8:53                           ` Mahmoud Nagy Adam
2025-08-28 19:17                             ` Alex Williamson
2025-08-07  8:13               ` Benjamin Herrenschmidt

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=20250804104012.87915-10-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=kvm@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 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.