Skip to contentSkip to conversation

xen/arm: traps: Correctly interpret the content of the register HPFAR_EL2

PATCH Superseded Julien Grall 7 participants 21 messages Apr 13, 2016 – Apr 22, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover xen/arm: traps: Correctly interpret the content of the register HPFAR_EL2

Hello,

This small patch series is a bug fix for Xen 4.7 and should also be backported to Xen 4.6.

Without it, the faulting IPA reported to memaccess may be wrong.

Regards,

Julien Grall (2):
xen/bitops: Introduce macros to generate mask xen/arm: traps: Correctly interpret the content of the register
HPFAR_EL2

 xen/arch/arm/traps.c            | 11 +++++++++--
 xen/include/asm-arm/processor.h |  7 +++++++
 xen/include/xen/bitops.h        | 11 +++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/2 xen/bitops: Introduce macros to generate mask

The code has been imported from the header include/linux/bitops.h in Linux v4.6-rc3.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

---
 xen/include/xen/bitops.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
xen/include/xen/bitops.h +11 -0
index cb56f24..e1a4d93 100644
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+	(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+
+/*
  * ffs: find first bit set. This is defined the same way as
  * the libc and compiler builtin ffs routines, therefore
  * differs in spirit from the above ffz (man ffs).
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 1/2
#2 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Quoted 4 lines · Julien Grall

The code has been imported from the header include/linux/bitops.h in Linux v4.6-rc3.

Quoted 33 lines

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

 xen/include/xen/bitops.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
xen/include/xen/bitops.h +11 -0
index cb56f24..e1a4d93 100644
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+	(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+
+/*
  * ffs: find first bit set. This is defined the same way as
  * the libc and compiler builtin ffs routines, therefore
  * differs in spirit from the above ffz (man ffs).
Signature · 1 line
1.9.1

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

#3 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

In reply to Julien Grall
Quoted 21 lines · Julien Grall

The code has been imported from the header include/linux/bitops.h in Linux v4.6-rc3.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

---
 xen/include/xen/bitops.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
xen/include/xen/bitops.h +0 -0
index cb56f24..e1a4d93 100644
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+	(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

You should have just a single GENMASK() which works in terms of LL.

Masks must be signed to work correctly when implicitly extended.

~Andrew

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

#4 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Hi Andrew,

Quoted 35 lines · Andrew Cooper
Quoted 21 lines · Julien Grall

The code has been imported from the header include/linux/bitops.h in Linux v4.6-rc3.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

---
  xen/include/xen/bitops.h | 11 +++++++++++
  1 file changed, 11 insertions(+)
xen/include/xen/bitops.h +0 -0
index cb56f24..e1a4d93 100644
@@ -3,6 +3,17 @@
  #include <asm/types.h>
 

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
  /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+	(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

You should have just a single GENMASK() which works in terms of LL.

Quoted 1 line

Masks must be signed to work correctly when implicitly extended.

May I ask you why? AFAICT, if the mask is signed, it will result to duplicate the sign bit to the new bits. This is not the expected behavior of this macro.

For instance, the following patch is using this macro to mask RES0 bits in the HPFAR_EL2 register. For ARM, RES0 means the bit is currently read as zero but the software should not rely on it to preserve forward compatibility.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#5 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

In reply to Julien Grall
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/13/16 6:01 PM >>>

xen/include/xen/bitops.h +0 -0
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+    (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Irrespective of Linux perhaps considering them useful, I'm not sure they are (and ISTR these macros having got proposed before). Plus - I don't think we even have BITS_PER_LONG_LONG anywhere.

Jan

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

#6 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Hi Jan,

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/13/16 6:01 PM >>>

xen/include/xen/bitops.h +0 -0
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
Quoted 13 lines

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+    (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Irrespective of Linux perhaps considering them useful, I'm not sure they are (and ISTR these macros having got proposed before).

This is useful on ARM to generate mask for register. For instance, the following patch introduces mask for the register HPFAR_EL2. Only the bits [4:39] are usable, the rest are RES0.

For ARM, RES0 means the bit is currently read as zero but the software should not rely on it to preserve forward compatibility. So we want to mask those bits to avoid breakage with new version of the architecture.

Quoted 2 lines

Plus - I don't
think we even have BITS_PER_LONG_LONG anywhere.

Hmmm right, we don't have it. I can drop GENMASK_ULL as I only need GENMASK for the moment.

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#7 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Quoted 22 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/14/16 10:55 AM >>>

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/13/16 6:01 PM >>>

xen/include/xen/bitops.h +0 -0
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
Quoted 13 lines

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+    (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Irrespective of Linux perhaps considering them useful, I'm not sure they are (and ISTR these macros having got proposed before).

Quoted 7 lines

This is useful on ARM to generate mask for register. For instance, the following patch introduces mask for the register HPFAR_EL2. Only the bits [4:39] are usable, the rest are RES0.

For ARM, RES0 means the bit is currently read as zero but the software should not rely on it to preserve forward compatibility. So we want to mask those bits to avoid breakage with new version of the architecture.

All understood and needed on every kind of architecture. Yet what's wrong
with expressing this is as 0xfffffffff0, as is being done most everywhere else?

Jan

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

#8 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Hi Jan,

Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/14/16 10:55 AM >>>

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/13/16 6:01 PM >>>

xen/include/xen/bitops.h +0 -0
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
Quoted 13 lines

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+    (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Irrespective of Linux perhaps considering them useful, I'm not sure they are (and ISTR these macros having got proposed before).

This is useful on ARM to generate mask for register. For instance, the following patch introduces mask for the register HPFAR_EL2. Only the bits [4:39] are usable, the rest are RES0.

Quoted 6 lines
Quoted 3 lines

For ARM, RES0 means the bit is currently read as zero but the software should not rely on it to preserve forward compatibility. So we want to mask those bits to avoid breakage with new version of the architecture.

All understood and needed on every kind of architecture. Yet what's wrong
with expressing this is as 0xfffffffff0, as is being done most everywhere else?

It is less intuitive to read and it is easier to make a mistake in the mask.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#9 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Quoted 28 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/14/16 5:08 PM >>>

Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/14/16 10:55 AM >>>

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/13/16 6:01 PM >>>

xen/include/xen/bitops.h +0 -0
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
Quoted 13 lines

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+    (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Irrespective of Linux perhaps considering them useful, I'm not sure they are (and ISTR these macros having got proposed before).

This is useful on ARM to generate mask for register. For instance, the following patch introduces mask for the register HPFAR_EL2. Only the bits [4:39] are usable, the rest are RES0.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

For ARM, RES0 means the bit is currently read as zero but the software should not rely on it to preserve forward compatibility. So we want to mask those bits to avoid breakage with new version of the architecture.

All understood and needed on every kind of architecture. Yet what's wrong
with expressing this is as 0xfffffffff0, as is being done most everywhere else?

It is less intuitive to read and it is easier to make a mistake in the mask.

Well, I guess that depends on the person reading/writing the respective piece of code. To me the macroized form would at least require getting used to.

Jan

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

#10 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Hi Jan,

Quoted 32 lines · Jan Beulich
Quoted 32 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/14/16 5:08 PM >>>

Quoted 30 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/14/16 10:55 AM >>>

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/13/16 6:01 PM >>>

xen/include/xen/bitops.h +0 -0
@@ -3,6 +3,17 @@
 #include <asm/types.h>
 
Quoted 13 lines

xen/include/xen/bitops.h line 14

Quoted 10 lines
xen/include/xen/bitops.h +9 -0
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+    (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

Irrespective of Linux perhaps considering them useful, I'm not sure they are (and ISTR these macros having got proposed before).

This is useful on ARM to generate mask for register. For instance, the following patch introduces mask for the register HPFAR_EL2. Only the bits [4:39] are usable, the rest are RES0.

For ARM, RES0 means the bit is currently read as zero but the software should not rely on it to preserve forward compatibility. So we want to mask those bits to avoid breakage with new version of the architecture.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

All understood and needed on every kind of architecture. Yet what's wrong
with expressing this is as 0xfffffffff0, as is being done most everywhere else?

It is less intuitive to read and it is easier to make a mistake in the mask.

Well, I guess that depends on the person reading/writing the respective piece of code. To me the macroized form would at least require getting used to.

It is a matter of taste. Is there any reason to not allow different way to create a mask?

In the case of ARM, the macro version helps to find quickly if a mask matches the ARM specification. It is also less error-prone with 64-bit mask.

If you are concerned to have this macro in the common, I would be fine to carry it in asm-arm/.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#11 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Quoted 2 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/20/16 2:35 PM >>>

It is a matter of taste.

Indeed.

Quoted 1 line

Is there any reason to not allow different way to create a mask?

I dislike it, but not so much to stand in the way to get it in. I.e. I'm not going to NAK it, but I'm also not currently planning to ACK it.

Jan

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

#12 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Hi Jan,

Quoted 9 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/20/16 2:35 PM >>>

It is a matter of taste.

Indeed.

Quoted 1 line

Is there any reason to not allow different way to create a mask?

I dislike it, but not so much to stand in the way to get it in. I.e. I'm not going to NAK it, but I'm also not currently planning to ACK it.

Stefano, who is now "REST maintainers", acked this patch few days. I guess this could be considered as valid ack.

As this series has been release-acked by Wei and acked by Stefano, can a committer apply this series to master?

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#13 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Quoted 14 lines · Julien Grall

Hi Jan,

Quoted 10 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/20/16 2:35 PM >>>

It is a matter of taste.

Indeed.

Quoted 1 line

Is there any reason to not allow different way to create a mask?

I dislike it, but not so much to stand in the way to get it in. I.e. I'm not going
to NAK it, but I'm also not currently planning to ACK it.

Quoted 5 lines

Stefano, who is now "REST maintainers", acked this patch few days. I guess this could be considered as valid ack.

As this series has been release-acked by Wei and acked by Stefano, can a committer apply this series to master?

Please resubmit, dropping or fixing GENMASK_ULL

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

#14 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Hi Stefano,

Quoted 15 lines · Stefano Stabellini
Quoted 14 lines · Julien Grall

Hi Jan,

Quoted 10 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/20/16 2:35 PM >>>

It is a matter of taste.

Indeed.

Quoted 1 line

Is there any reason to not allow different way to create a mask?

I dislike it, but not so much to stand in the way to get it in. I.e. I'm not going
to NAK it, but I'm also not currently planning to ACK it.

Quoted 7 lines
Quoted 5 lines

Stefano, who is now "REST maintainers", acked this patch few days. I guess this could be considered as valid ack.

As this series has been release-acked by Wei and acked by Stefano, can a committer apply this series to master?

Please resubmit, dropping or fixing GENMASK_ULL

Oh right, I forgot about this macro. Can I keep your ack here?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#15 lore raw

Re: [for-4.7 1/2] xen/bitops: Introduce macros to generate mask

Quoted 22 lines · Julien Grall

Hi Stefano,

Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Julien Grall

Hi Jan,

Quoted 11 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Julien Grall <[email protected]> 04/20/16 2:35 PM >>>

It is a matter of taste.

Indeed.

Quoted 1 line

Is there any reason to not allow different way to create a mask?

I dislike it, but not so much to stand in the way to get it in. I.e. I'm not
going
to NAK it, but I'm also not currently planning to ACK it.

Stefano, who is now "REST maintainers", acked this patch few days. I guess this could be considered as valid ack.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

As this series has been release-acked by Wei and acked by Stefano, can a committer apply this series to master?

Please resubmit, dropping or fixing GENMASK_ULL

Oh right, I forgot about this macro. Can I keep your ack here?

Sure

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

#16 lore raw

PATCH 2/2 xen/arm: traps: Correctly interpret the content of the register HPFAR_EL2

In reply to Julien Grall

The register HPFAR_EL2 (resp. HPFAR on arm32) contains the bits [47:12] (resp. [39:12]) of the faulting IPA. Unlike other registers that represent an address, the upper bits of the IPA are stored in the register bits [4:39] (resp. [4:21]).

However, Xen assumes that the register contains the faulting IPA correctly offsetted. This will result to get a wrong IPA when the fault is happening during a translation table walk. Note this is only affecting memaccess.

Introduce a new helper to get the faulting IPA from HPFAR_EL2 and replace direct read from the register by the helper.

---
Cc: [email protected]

This is a bug fix for Xen 4.7 and should also be backported to Xen 4.6. Without this patch, the faulting IPA reported to memaccess may be wrong.

---
 xen/arch/arm/traps.c            | 11 +++++++++--
 xen/include/asm-arm/processor.h |  7 +++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
xen/arch/arm/traps.c +9 -2
index 1516abd..5e865cf 100644
@@ -2363,6 +2363,13 @@ done:
     if (first) unmap_domain_page(first);
 }
 
+static inline paddr_t get_faulting_ipa(void)
+{
+    register_t hpfar = READ_SYSREG(HPFAR_EL2);
+
+    return ((paddr_t)(hpfar & HPFAR_MASK) << (12 - 4));
+}
+
 static void do_trap_instr_abort_guest(struct cpu_user_regs *regs,
                                       const union hsr hsr)
 {
@@ -2381,7 +2388,7 @@ static void do_trap_instr_abort_guest(struct cpu_user_regs *regs,
         };
 
         if ( hsr.iabt.s1ptw )
-            gpa = READ_SYSREG(HPFAR_EL2);
+            gpa = get_faulting_ipa();
         else
         {
             /*
@@ -2431,7 +2438,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
 #endif
 
     if ( dabt.s1ptw )
-        info.gpa = READ_SYSREG(HPFAR_EL2);
+        info.gpa = get_faulting_ipa();
     else
     {
         rc = gva_to_ipa(info.gva, &info.gpa, GV2M_READ);
xen/include/asm-arm/processor.h +7 -0
index 7e6eb66..6789cd0 100644
@@ -565,6 +565,13 @@ union hsr {
 
 #define FSC_LL_MASK    (_AC(0x03,U)<<0)
 
+/* HPFAR_EL2: Hypervisor IPA Fault Address Register */
+#ifdef CONFIG_ARM_64
+#define HPFAR_MASK	GENMASK(39, 4)
+#else
+#define HPFAR_MASK	GENMASK(31, 4)
+#endif
+
 /* Time counter hypervisor control register */
 #define CNTHCTL_EL2_EL1PCTEN (1u<<0) /* Kernel/user access to physical counter */
 #define CNTHCTL_EL2_EL1PCEN  (1u<<1) /* Kernel/user access to CNTP timer regs */
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v1 2/2
#17 lore raw
Quoted 5 lines · Julien Grall

The register HPFAR_EL2 (resp. HPFAR on arm32) contains the bits [47:12] (resp. [39:12]) of the faulting IPA. Unlike other registers that represent an address, the upper bits of the IPA are stored in the register bits [4:39] (resp. [4:21]).

Quoted 8 lines

However, Xen assumes that the register contains the faulting IPA correctly offsetted. This will result to get a wrong IPA when the fault is happening during a translation table walk. Note this is only affecting memaccess.

Introduce a new helper to get the faulting IPA from HPFAR_EL2 and replace direct read from the register by the helper.

Quoted 68 lines

---
Cc: [email protected]

This is a bug fix for Xen 4.7 and should also be backported to Xen 4.6. Without this patch, the faulting IPA reported to memaccess may be wrong.

---
 xen/arch/arm/traps.c            | 11 +++++++++--
 xen/include/asm-arm/processor.h |  7 +++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
xen/arch/arm/traps.c +9 -2
index 1516abd..5e865cf 100644
@@ -2363,6 +2363,13 @@ done:
     if (first) unmap_domain_page(first);
 }
 
+static inline paddr_t get_faulting_ipa(void)
+{
+    register_t hpfar = READ_SYSREG(HPFAR_EL2);
+
+    return ((paddr_t)(hpfar & HPFAR_MASK) << (12 - 4));
+}
+
 static void do_trap_instr_abort_guest(struct cpu_user_regs *regs,
                                       const union hsr hsr)
 {
@@ -2381,7 +2388,7 @@ static void do_trap_instr_abort_guest(struct cpu_user_regs *regs,
         };
 
         if ( hsr.iabt.s1ptw )
-            gpa = READ_SYSREG(HPFAR_EL2);
+            gpa = get_faulting_ipa();
         else
         {
             /*
@@ -2431,7 +2438,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
 #endif
 
     if ( dabt.s1ptw )
-        info.gpa = READ_SYSREG(HPFAR_EL2);
+        info.gpa = get_faulting_ipa();
     else
     {
         rc = gva_to_ipa(info.gva, &info.gpa, GV2M_READ);
xen/include/asm-arm/processor.h +7 -0
index 7e6eb66..6789cd0 100644
@@ -565,6 +565,13 @@ union hsr {
 
 #define FSC_LL_MASK    (_AC(0x03,U)<<0)
 
+/* HPFAR_EL2: Hypervisor IPA Fault Address Register */
+#ifdef CONFIG_ARM_64
+#define HPFAR_MASK	GENMASK(39, 4)
+#else
+#define HPFAR_MASK	GENMASK(31, 4)
+#endif
+
 /* Time counter hypervisor control register */
 #define CNTHCTL_EL2_EL1PCTEN (1u<<0) /* Kernel/user access to physical counter */
 #define CNTHCTL_EL2_EL1PCEN  (1u<<1) /* Kernel/user access to CNTP timer regs */
Signature · 1 line
1.9.1

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

#18 lore raw
In reply to Julien Grall
Quoted 5 lines · Julien Grall

The register HPFAR_EL2 (resp. HPFAR on arm32) contains the bits [47:12] (resp. [39:12]) of the faulting IPA. Unlike other registers that represent an address, the upper bits of the IPA are stored in the register bits [4:39] (resp. [4:21]).

Quoted 9 lines

However, Xen assumes that the register contains the faulting IPA correctly offsetted. This will result to get a wrong IPA when the fault is happening during a translation table walk. Note this is only affecting memaccess.

Introduce a new helper to get the faulting IPA from HPFAR_EL2 and replace direct read from the register by the helper.

Thanks for the fix, I totally missed that. I did notice not getting any events for translation table-walks so at least now I know why.

Tamas

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

Reviewed-by on v1 2/2
#19 lore raw
In reply to Julien Grall
Quoted 5 lines · Julien Grall

The register HPFAR_EL2 (resp. HPFAR on arm32) contains the bits [47:12] (resp. [39:12]) of the faulting IPA. Unlike other registers that represent an address, the upper bits of the IPA are stored in the register bits [4:39] (resp. [4:21]).

Quoted 8 lines

However, Xen assumes that the register contains the faulting IPA correctly offsetted. This will result to get a wrong IPA when the fault is happening during a translation table walk. Note this is only affecting memaccess.

Introduce a new helper to get the faulting IPA from HPFAR_EL2 and replace direct read from the register by the helper.

Thanks for the catch!

Cheers,
Andre.

Quoted 57 lines

---
Cc: [email protected]

This is a bug fix for Xen 4.7 and should also be backported to Xen 4.6. Without this patch, the faulting IPA reported to memaccess may be wrong.

---
 xen/arch/arm/traps.c            | 11 +++++++++--
 xen/include/asm-arm/processor.h |  7 +++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
xen/arch/arm/traps.c +9 -2
index 1516abd..5e865cf 100644
@@ -2363,6 +2363,13 @@ done:
     if (first) unmap_domain_page(first);
 }
 
+static inline paddr_t get_faulting_ipa(void)
+{
+    register_t hpfar = READ_SYSREG(HPFAR_EL2);
+
+    return ((paddr_t)(hpfar & HPFAR_MASK) << (12 - 4));
+}
+
 static void do_trap_instr_abort_guest(struct cpu_user_regs *regs,
                                       const union hsr hsr)
 {
@@ -2381,7 +2388,7 @@ static void do_trap_instr_abort_guest(struct cpu_user_regs *regs,
         };
 
         if ( hsr.iabt.s1ptw )
-            gpa = READ_SYSREG(HPFAR_EL2);
+            gpa = get_faulting_ipa();
         else
         {
             /*
@@ -2431,7 +2438,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
 #endif
 
     if ( dabt.s1ptw )
-        info.gpa = READ_SYSREG(HPFAR_EL2);
+        info.gpa = get_faulting_ipa();
     else
     {
         rc = gva_to_ipa(info.gva, &info.gpa, GV2M_READ);
xen/include/asm-arm/processor.h +0 -0
index 7e6eb66..6789cd0 100644
@@ -565,6 +565,13 @@ union hsr {
 
 #define FSC_LL_MASK    (_AC(0x03,U)<<0)
 

xen/include/asm-arm/processor.h union hsr { · line 577

Quoted 10 lines
xen/include/asm-arm/processor.h +7 -0
+/* HPFAR_EL2: Hypervisor IPA Fault Address Register */
+#ifdef CONFIG_ARM_64
+#define HPFAR_MASK	GENMASK(39, 4)
+#else
+#define HPFAR_MASK	GENMASK(31, 4)
+#endif
+
 /* Time counter hypervisor control register */
 #define CNTHCTL_EL2_EL1PCTEN (1u<<0) /* Kernel/user access to physical counter */
 #define CNTHCTL_EL2_EL1PCEN  (1u<<1) /* Kernel/user access to CNTP timer regs */

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

#20 lore raw
In reply to Julien Grall
Quoted 7 lines · Julien Grall

Hello,

This small patch series is a bug fix for Xen 4.7 and should also be backported to Xen 4.6.

Without it, the faulting IPA reported to memaccess may be wrong.

Quoted 8 lines

Regards,

Julien Grall (2):
xen/bitops: Introduce macros to generate mask xen/arm: traps: Correctly interpret the content of the register
HPFAR_EL2

The second patch is a genuine bug fix, so

Quoted 14 lines
 xen/arch/arm/traps.c            | 11 +++++++++--
 xen/include/asm-arm/processor.h |  7 +++++++
 xen/include/xen/bitops.h        | 11 +++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
Signature · 7 lines
1.9.1


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

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