Skip to contentSkip to conversation

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

PATCH In review Julien Grall 4 participants 6 messages Apr 22, 2016

lore
Share & tools
lore
#0 lore raw

v2 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.

For all the changes see in each patch.

Regards,

Julien Grall (2):
xen/bitops: Introduce GENMASK 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        |  8 ++++++++
 3 files changed, 24 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 v2 1/2 xen/bitops: Introduce GENMASK to generate mask

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

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

Changes in v2:
- Remove GENMASK_ULL
- Add Stefano's acked-by

---
 xen/include/xen/bitops.h | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/include/xen/bitops.h +8 -0
index cb56f24..bd0883a 100644
@@ -3,6 +3,14 @@
 #include <asm/types.h>
 
 /*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK(30, 21) gives us the 32bit vector 0x01fe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_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
#2 lore raw

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

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.04.16 at 17:58, <[email protected]> wrote:

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

And just to double check - Stefano, this ack was meant also as a REST maintainer, not just an ARM one (as the latter was the context it was originally given in)?

Jan

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

#3 lore raw

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

Quoted 10 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.04.16 at 17:58, <[email protected]> wrote:

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

And just to double check - Stefano, this ack was meant also as a REST maintainer, not just an ARM one (as the latter was the context it was originally given in)?

Yeah, the macro is OK for me.

It is just a macro - we don't have to introduce it if you dislike it, we could simply explode it in xen/include/asm-arm/processor.h. On the other hand, if you don't have an opinion about it, I would go ahead with this patch. I am happy either way.

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

#4 lore raw

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

In reply to Jan Beulich

Jan Beulich writes ("Re: [for-4.7 v2 1/2] xen/bitops: Introduce GENMASK to generate mask"):

Quoted 10 lines · On 22.04.16 at 17:58, <[email protected]> wrote:
Quoted 5 lines

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

And just to double check - Stefano, this ack was meant also as a REST maintainer, not just an ARM one (as the latter was the context it was originally given in)?

For what it's worth, on the matter of taste I agree with Julien. Having read the occasional ARM manual, the proposed macro will make it much easier to check that the code matches the book.

Ian.

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

#5 lore raw

PATCH v2 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.

Changes in v2:
- Add Andre's and Stefano's reviewed-by

---
 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