Skip to contentSkip to conversation

x86/xen: support priv-mapping in an HVM tools domain

PATCH Superseded Paul Durrant 2 participants 8 messages Oct 19, 2017 – Oct 20, 2017

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/xen: support priv-mapping in an HVM tools domain

If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +12 -2
index 3e15345abfe7..d33e7dbe3129 100644
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
+						 prot, domid, pages);
+
 	/* We BUG_ON because it's a programmer error to pass a NULL err_ptr,
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@ EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 25 lines · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains, there is a check in privcmd_ioctl_mmap() for that.

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 11 lines
arch/x86/xen/mmu.c +4 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

-boris

Quoted 8 lines
arch/x86/xen/mmu.c +0 -1
 	/* We BUG_ON because it's a programmer error to pass a NULL err_ptr,
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@ EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)

arch/x86/xen/mmu.c EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); · line 211

Quoted 10 lines
arch/x86/xen/mmu.c +5 -1
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
In reply to Paul Durrant
Quoted 25 lines · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains, there is a check in privcmd_ioctl_mmap() for that.

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 11 lines
arch/x86/xen/mmu.c +4 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages);
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

-boris

Quoted 18 lines
arch/x86/xen/mmu.c +5 -2
 	/* We BUG_ON because it's a programmer error to pass a NULL err_ptr,
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@ EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
 
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;
#3 lore raw
Quoted 39 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 19 October 2017 18:45
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an HVM tools domain

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct

Quoted 25 lines · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct

vm_area_struct *vma,

Quoted 9 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains, there is a check in privcmd_ioctl_mmap() for that.

Yes, that's true but it seems like the wrong place for such a check. I could remove that one it you'd prefer.

Quoted 13 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct · line 178

Quoted 2 lines
arch/x86/xen/mmu.c +0 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid,

pages);

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct

vm_area_struct *vma,

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma,

Quoted 5 lines
arch/x86/xen/mmu.c +2 -0
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr,

err_ptr,

Quoted 5 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

I assume mean 'array' for the map since there is no xen_xlate_remap_gfn_range() function. I'm not quite sure what you're asking? Without this patch the mmu code in an x86 domain simply assumes the domain is PV... the xlate code is currently only used via the arm mmu code (where it clearly knows it's not PV). AFAICS this Is just a straightforward buggy assumption in the x86 code.

Paul

Quoted 30 lines

-boris

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct · line 192

Quoted 1 line
arch/x86/xen/mmu.c +0 -0
 	/* We BUG_ON because it's a programmer error to pass a NULL

err_ptr,

arch/x86/xen/mmu.c

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@

EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);

Quoted 4 lines
arch/x86/xen/mmu.c +0 -1
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)

arch/x86/xen/mmu.c EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); · line 211

Quoted 10 lines
arch/x86/xen/mmu.c +5 -1
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 47 lines · Paul Durrant
Quoted 39 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 19 October 2017 18:45
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an HVM tools domain

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct

Quoted 25 lines · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct

vm_area_struct *vma,

Quoted 8 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains, there is a check in privcmd_ioctl_mmap() for that.

Quoted 1 line

Yes, that's true but it seems like the wrong place for such a check. I could remove that one it you'd prefer.

I actually think that perhaps we could wrap privcmd_ioctl_mmap() with "#ifdef CONFIG_XEN_PV" (#else return -ENOSYS) and move xen_remap_domain_gfn_range() to mmu_pv.c. We can then remove it from ARM code too.

Quoted 13 lines
Quoted 13 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct · line 178

Quoted 2 lines
arch/x86/xen/mmu.c +0 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid,

pages);

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct

vm_area_struct *vma,

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma,

Quoted 5 lines
arch/x86/xen/mmu.c +2 -0
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr,

err_ptr,

Quoted 5 lines
Quoted 4 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

I assume mean 'array' for the map since there is no xen_xlate_remap_gfn_range() function. I'm not quite sure what you're asking? Without this patch the mmu code in an x86 domain simply assumes the domain is PV... the xlate code is currently only used via the arm mmu code (where it clearly knows it's not PV). AFAICS this Is just a straightforward buggy assumption in the x86 code.

Looks like this was originally intended for dom0 PVH and was removed by 063334f. So it should indeed be restored.

-boris

Quoted 30 lines

Paul

Quoted 27 lines

-boris

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct · line 192

Quoted 1 line
arch/x86/xen/mmu.c +0 -0
 	/* We BUG_ON because it's a programmer error to pass a NULL

err_ptr,

arch/x86/xen/mmu.c

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@

EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);

arch/x86/xen/mmu.c EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); · line 211

Quoted 13 lines
arch/x86/xen/mmu.c +5 -2
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 90 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 20 October 2017 16:09
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an HVM tools domain

Quoted 10 lines · Paul Durrant
Quoted 10 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 19 October 2017 18:45
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an

HVM

Quoted 4 lines
Quoted 4 lines

tools domain

Quoted 1 line · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the

PV-

Quoted 25 lines
Quoted 25 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct

Quoted 24 lines

specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct

vm_area_struct *vma,

Quoted 7 lines
Quoted 7 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains,

there

Quoted 2 lines
Quoted 1 line

is a check in privcmd_ioctl_mmap() for that.

Yes, that's true but it seems like the wrong place for such a check. I could

remove that one it you'd prefer.

I actually think that perhaps we could wrap privcmd_ioctl_mmap() with "#ifdef CONFIG_XEN_PV" (#else return -ENOSYS) and move xen_remap_domain_gfn_range() to mmu_pv.c. We can then remove it from ARM
code too.

Quoted 13 lines
Quoted 13 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct · line 178

Quoted 2 lines
arch/x86/xen/mmu.c +0 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid,

pages);

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct

vm_area_struct *vma,

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma,

Quoted 5 lines
arch/x86/xen/mmu.c +2 -0
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr,

err_ptr,

Quoted 5 lines
Quoted 4 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

I assume mean 'array' for the map since there is no

Quoted 9 lines

xen_xlate_remap_gfn_range() function. I'm not quite sure what you're asking? Without this patch the mmu code in an x86 domain simply assumes the domain is PV... the xlate code is currently only used via the arm mmu code (where it clearly knows it's not PV). AFAICS this Is just a straightforward buggy assumption in the x86 code.

Looks like this was originally intended for dom0 PVH and was removed by 063334f. So it should indeed be restored.

Ok, I'll re-work the patch with your suggestion re xen_remap_domain_gfn_range() and send a v2.

Thanks,

Paul

Quoted 39 lines

-boris

Quoted 30 lines

Paul

Quoted 27 lines

-boris

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct · line 192

Quoted 1 line
arch/x86/xen/mmu.c +0 -0
 	/* We BUG_ON because it's a programmer error to pass a NULL

err_ptr,

arch/x86/xen/mmu.c

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@

EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);

arch/x86/xen/mmu.c EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); · line 211

Quoted 13 lines
arch/x86/xen/mmu.c +5 -2
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
In reply to Boris Ostrovsky
Quoted 90 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 20 October 2017 16:09
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an HVM tools domain

Quoted 10 lines · Paul Durrant
Quoted 10 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 19 October 2017 18:45
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an

HVM

Quoted 4 lines
Quoted 4 lines

tools domain

Quoted 1 line · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the

PV-

Quoted 25 lines
Quoted 25 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct

Quoted 24 lines

specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct

vm_area_struct *vma,

Quoted 7 lines
Quoted 7 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains,

there

Quoted 2 lines
Quoted 1 line

is a check in privcmd_ioctl_mmap() for that.

Yes, that's true but it seems like the wrong place for such a check. I could

remove that one it you'd prefer.

I actually think that perhaps we could wrap privcmd_ioctl_mmap() with "#ifdef CONFIG_XEN_PV" (#else return -ENOSYS) and move xen_remap_domain_gfn_range() to mmu_pv.c. We can then remove it from ARM
code too.

Quoted 13 lines
Quoted 13 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct · line 178

Quoted 2 lines
arch/x86/xen/mmu.c +0 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid,

pages);

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct

vm_area_struct *vma,

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma,

Quoted 5 lines
arch/x86/xen/mmu.c +2 -0
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr,

err_ptr,

Quoted 5 lines
Quoted 4 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

I assume mean 'array' for the map since there is no

Quoted 9 lines

xen_xlate_remap_gfn_range() function. I'm not quite sure what you're asking? Without this patch the mmu code in an x86 domain simply assumes the domain is PV... the xlate code is currently only used via the arm mmu code (where it clearly knows it's not PV). AFAICS this Is just a straightforward buggy assumption in the x86 code.

Looks like this was originally intended for dom0 PVH and was removed by 063334f. So it should indeed be restored.

Ok, I'll re-work the patch with your suggestion re xen_remap_domain_gfn_range() and send a v2.

Thanks,

Paul

Quoted 35 lines

-boris

Quoted 30 lines

Paul

Quoted 27 lines

-boris

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct · line 192

Quoted 1 line
arch/x86/xen/mmu.c +0 -0
 	/* We BUG_ON because it's a programmer error to pass a NULL

err_ptr,

arch/x86/xen/mmu.c

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@

EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);

arch/x86/xen/mmu.c EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); · line 211

Quoted 13 lines
arch/x86/xen/mmu.c +5 -2
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
 	return -EINVAL;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
In reply to Boris Ostrovsky
Quoted 39 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Boris Ostrovsky
Sent: 19 October 2017 18:45
To: Paul Durrant <[email protected]>; [email protected]; xen- [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>
Subject: Re: [Xen-devel] [PATCH] x86/xen: support priv-mapping in an HVM tools domain

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct

Quoted 25 lines · Paul Durrant

If the domain has XENFEAT_auto_translated_physmap then use of the PV- specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and xen_unmap_domain_gfn_array() which call through to the approprate xlate_mmu function if the feature is present. A check is also added to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this should not be used in an HVM tools domain.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>

---
 arch/x86/xen/mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/xen/mmu.c +0 -0
index 3e15345abfe7..d33e7dbe3129 100644
@@ -172,6 +172,9 @@ int xen_remap_domain_gfn_range(struct

vm_area_struct *vma,

Quoted 9 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct vm_area_struct *vma, · line 177

Quoted 6 lines
arch/x86/xen/mmu.c +3 -0
 			       pgprot_t prot, unsigned domid,
 			       struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return -EOPNOTSUPP;
+

This is never called on XENFEAT_auto_translated_physmap domains, there is a check in privcmd_ioctl_mmap() for that.

Yes, that's true but it seems like the wrong place for such a check. I could remove that one it you'd prefer.

Quoted 13 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_range(struct · line 178

Quoted 2 lines
arch/x86/xen/mmu.c +0 -0
 	return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid,

pages);

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 }
 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
@@ -182,6 +185,10 @@ int xen_remap_domain_gfn_array(struct

vm_area_struct *vma,

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma,

Quoted 5 lines
arch/x86/xen/mmu.c +2 -0
 			       int *err_ptr, pgprot_t prot,
 			       unsigned domid, struct page **pages)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr,

err_ptr,

Quoted 5 lines

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct vm_area_struct *vma, · line 191

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+						 prot, domid, pages);
+

So how did this work before? In fact, I don't see any callers of xen_xlate_{re|un}map_gfn_range().

I assume mean 'array' for the map since there is no xen_xlate_remap_gfn_range() function. I'm not quite sure what you're asking? Without this patch the mmu code in an x86 domain simply assumes the domain is PV... the xlate code is currently only used via the arm mmu code (where it clearly knows it's not PV). AFAICS this Is just a straightforward buggy assumption in the x86 code.

Paul

Quoted 23 lines

-boris

arch/x86/xen/mmu.c int xen_remap_domain_gfn_array(struct · line 192

Quoted 1 line
arch/x86/xen/mmu.c +0 -0
 	/* We BUG_ON because it's a programmer error to pass a NULL

err_ptr,

arch/x86/xen/mmu.c

Quoted 3 lines
arch/x86/xen/mmu.c +0 -0
 	 * and the consequences later is quite hard to detect what the actual
 	 * cause of "wrong memory was mapped in".
@@ -193,9 +200,12 @@

EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);

Quoted 13 lines
arch/x86/xen/mmu.c +5 -2
 /* Returns: 0 success */
 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
-			       int numpgs, struct page **pages)
+			       int nr, struct page **pages)
 {
-	if (!pages || !xen_feature(XENFEAT_auto_translated_physmap))
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return xen_xlate_unmap_gfn_range(vma, nr, pages);
+
+	if (!pages)
 		return 0;
 
Quoted 7 lines

arch/x86/xen/mmu.c EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array); · line 211

Quoted 1 line
arch/x86/xen/mmu.c +0 -0
 	return -EINVAL;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel