xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] xen/privcmd: allow fetching resource sizes
@ 2021-01-12 11:53 Roger Pau Monne
  2021-01-12 12:17 ` Jürgen Groß
  2021-01-13 11:32 ` Jürgen Groß
  0 siblings, 2 replies; 4+ messages in thread
From: Roger Pau Monne @ 2021-01-12 11:53 UTC (permalink / raw)
  To: linux-kernel
  Cc: Roger Pau Monne, stable, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Paul Durrant, amc96, andrew.cooper3,
	xen-devel

Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and
addr = 0 in order to fetch the size of a specific resource.

Add a shortcut to the default map resource path, since fetching the
size requires no address to be passed in, and thus no VMA to setup.

This is missing from the initial implementation, and causes issues
when mapping resources that don't have fixed or known sizes.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: stable@vger.kernel.org # >= 4.18
---
NB: fetching the size of a resource shouldn't trigger an hypercall
preemption, and hence I've dropped the preempt indications.
---
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Paul Durrant <paul.durrant@citrix.com>
Cc: amc96@cam.ac.uk
Cc: andrew.cooper3@citrix.com
Cc: xen-devel@lists.xenproject.org
---
Changes since v1:
 - Remove Fixes tag, add backport.
 - Make sure both addr and num are set or unset.
---
 drivers/xen/privcmd.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index b0c73c58f987..720a7b7abd46 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -717,14 +717,15 @@ static long privcmd_ioctl_restrict(struct file *file, void __user *udata)
 	return 0;
 }
 
-static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata)
+static long privcmd_ioctl_mmap_resource(struct file *file,
+				struct privcmd_mmap_resource __user *udata)
 {
 	struct privcmd_data *data = file->private_data;
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
 	struct privcmd_mmap_resource kdata;
 	xen_pfn_t *pfns = NULL;
-	struct xen_mem_acquire_resource xdata;
+	struct xen_mem_acquire_resource xdata = { };
 	int rc;
 
 	if (copy_from_user(&kdata, udata, sizeof(kdata)))
@@ -734,6 +735,22 @@ static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata)
 	if (data->domid != DOMID_INVALID && data->domid != kdata.dom)
 		return -EPERM;
 
+	/* Both fields must be set or unset */
+	if (!!kdata.addr != !!kdata.num)
+		return -EINVAL;
+
+	xdata.domid = kdata.dom;
+	xdata.type = kdata.type;
+	xdata.id = kdata.id;
+
+	if (!kdata.addr && !kdata.num) {
+		/* Query the size of the resource. */
+		rc = HYPERVISOR_memory_op(XENMEM_acquire_resource, &xdata);
+		if (rc)
+			return rc;
+		return __put_user(xdata.nr_frames, &udata->num);
+	}
+
 	mmap_write_lock(mm);
 
 	vma = find_vma(mm, kdata.addr);
@@ -768,10 +785,6 @@ static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata)
 	} else
 		vma->vm_private_data = PRIV_VMA_LOCKED;
 
-	memset(&xdata, 0, sizeof(xdata));
-	xdata.domid = kdata.dom;
-	xdata.type = kdata.type;
-	xdata.id = kdata.id;
 	xdata.frame = kdata.idx;
 	xdata.nr_frames = kdata.num;
 	set_xen_guest_handle(xdata.frame_list, pfns);
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] xen/privcmd: allow fetching resource sizes
  2021-01-12 11:53 [PATCH v2] xen/privcmd: allow fetching resource sizes Roger Pau Monne
@ 2021-01-12 12:17 ` Jürgen Groß
  2021-01-12 20:09   ` Andrew Cooper
  2021-01-13 11:32 ` Jürgen Groß
  1 sibling, 1 reply; 4+ messages in thread
From: Jürgen Groß @ 2021-01-12 12:17 UTC (permalink / raw)
  To: Roger Pau Monne, linux-kernel
  Cc: stable, Boris Ostrovsky, Stefano Stabellini, Paul Durrant, amc96,
	andrew.cooper3, xen-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 624 bytes --]

On 12.01.21 12:53, Roger Pau Monne wrote:
> Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and
> addr = 0 in order to fetch the size of a specific resource.
> 
> Add a shortcut to the default map resource path, since fetching the
> size requires no address to be passed in, and thus no VMA to setup.
> 
> This is missing from the initial implementation, and causes issues
> when mapping resources that don't have fixed or known sizes.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Cc: stable@vger.kernel.org # >= 4.18

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] xen/privcmd: allow fetching resource sizes
  2021-01-12 12:17 ` Jürgen Groß
@ 2021-01-12 20:09   ` Andrew Cooper
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Cooper @ 2021-01-12 20:09 UTC (permalink / raw)
  To: Jürgen Groß, Roger Pau Monne, linux-kernel
  Cc: stable, Boris Ostrovsky, Stefano Stabellini, Paul Durrant,
	andrew.cooper3, xen-devel

On 12/01/2021 12:17, Jürgen Groß wrote:
> On 12.01.21 12:53, Roger Pau Monne wrote:
>> Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and
>> addr = 0 in order to fetch the size of a specific resource.
>>
>> Add a shortcut to the default map resource path, since fetching the
>> size requires no address to be passed in, and thus no VMA to setup.
>>
>> This is missing from the initial implementation, and causes issues
>> when mapping resources that don't have fixed or known sizes.
>>
>> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>> Cc: stable@vger.kernel.org # >= 4.18
>
> Reviewed-by: Juergen Gross <jgross@suse.com>

Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] xen/privcmd: allow fetching resource sizes
  2021-01-12 11:53 [PATCH v2] xen/privcmd: allow fetching resource sizes Roger Pau Monne
  2021-01-12 12:17 ` Jürgen Groß
@ 2021-01-13 11:32 ` Jürgen Groß
  1 sibling, 0 replies; 4+ messages in thread
From: Jürgen Groß @ 2021-01-13 11:32 UTC (permalink / raw)
  To: Roger Pau Monne, linux-kernel
  Cc: stable, Boris Ostrovsky, Stefano Stabellini, Paul Durrant, amc96,
	andrew.cooper3, xen-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 616 bytes --]

On 12.01.21 12:53, Roger Pau Monne wrote:
> Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and
> addr = 0 in order to fetch the size of a specific resource.
> 
> Add a shortcut to the default map resource path, since fetching the
> size requires no address to be passed in, and thus no VMA to setup.
> 
> This is missing from the initial implementation, and causes issues
> when mapping resources that don't have fixed or known sizes.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Cc: stable@vger.kernel.org # >= 4.18

Pushed to xen/tip.git for-linus-5.11


Juergen

[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-13 11:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 11:53 [PATCH v2] xen/privcmd: allow fetching resource sizes Roger Pau Monne
2021-01-12 12:17 ` Jürgen Groß
2021-01-12 20:09   ` Andrew Cooper
2021-01-13 11:32 ` Jürgen Groß

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).