Skip to contentSkip to conversation

Implement errata 766422

PATCH Superseded Julien Grall 2 participants 9 messages Aug 6, 2013 – Aug 8, 2013

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Implement errata 766422

Hi,

This is fourth version of this patch series. It allows a guest kernel to use THUMB set instructions on the processor affected by the errata 766422 (for instance the Arndale board).

This patch series is divided in two patch:
- The first patch implements a basic decoder to fill the ISS field of the hsr_dabt struct
- The second patch implements the errata

Since the last version, only the patch #1 has been modified. See the changes in the patch.

Julien Grall (2):
xen/arm: Start to implement an ARM decoder instruction xen/arm: errata 766422: decode thumb store during data abort

 xen/arch/arm/Makefile                 |    1 +
 xen/arch/arm/decode.c                 |  168 +++++++++++++++++++++++++++++++++
 xen/arch/arm/decode.h                 |   49 ++++++++++
 xen/arch/arm/traps.c                  |   12 +++
 xen/include/asm-arm/arm32/processor.h |    4 +
 xen/include/asm-arm/arm64/processor.h |    2 +
 6 files changed, 236 insertions(+)
 create mode 100644 xen/arch/arm/decode.c
 create mode 100644 xen/arch/arm/decode.h
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v4 1/2 xen/arm: Start to implement an ARM decoder instruction

Some erratas on ARM processor requires to decode the instruction. The decoder will, obviously, decode and fill the ISS fields of the hsr_dabt.

For the moment, the decoder only supports:
- THUMB2 store instruction
- THUMB single load/store instruction

---
Changes in v4:
- Add warning about the purpose of this function
- Add helper to update ISS (register, sign, size) field of DABT
- Improve decoding for THUMB 2 store instruction
- Only decode thumb instruction if it's a 32-bit guest

---
 xen/arch/arm/Makefile |    1 +
 xen/arch/arm/decode.c |  168 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/decode.h |   49 +++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 xen/arch/arm/decode.c
 create mode 100644 xen/arch/arm/decode.h
xen/arch/arm/Makefile +1 -0
index 5ae5831..5c13a65 100644
@@ -30,6 +30,7 @@ obj-y += vtimer.o
 obj-y += vpl011.o
 obj-y += hvm.o
 obj-y += device.o
+obj-y += decode.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/decode.c new file +168 -0

168 lines not on this page · raw message

xen/arch/arm/decode.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH v4 1/2] xen/arm: Start to implement an ARM decoder instruction

Quoted 1 line · Julien Grall

Some erratas on ARM processor requires to decode the instruction.

Errata is already the plural of Erratum, I think.

Quoted 66 lines

The decoder will, obviously, decode and fill the ISS fields of the hsr_dabt.

For the moment, the decoder only supports:
- THUMB2 store instruction
- THUMB single load/store instruction

---
Changes in v4:
- Add warning about the purpose of this function
- Add helper to update ISS (register, sign, size) field of DABT
- Improve decoding for THUMB 2 store instruction
- Only decode thumb instruction if it's a 32-bit guest

---
 xen/arch/arm/Makefile |    1 +
 xen/arch/arm/decode.c |  168 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/decode.h |   49 +++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 xen/arch/arm/decode.c
 create mode 100644 xen/arch/arm/decode.h
xen/arch/arm/Makefile +1 -0
index 5ae5831..5c13a65 100644
@@ -30,6 +30,7 @@ obj-y += vtimer.o
 obj-y += vpl011.o
 obj-y += hvm.o
 obj-y += device.o
+obj-y += decode.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/decode.c new file +26 -0
new file mode 100644
index 0000000..0e7d8ba
@@ -0,0 +1,168 @@
+/*
+ * xen/arch/arm/decode.c
+ *
+ * Instruction decoder
+ *
+ * Julien Grall <[email protected]>
+ * Copyright (C) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/types.h>
+#include <xen/sched.h>
+#include <asm/current.h>
+#include <asm/guest_access.h>
+#include <xen/lib.h>
+
+#include "decode.h"

xen/arch/arm/decode.c line 36

Quoted 10 lines
xen/arch/arm/decode.c new file +10 -0
+
+static void update_dabt(struct hsr_dabt *dabt, int reg,
+                        uint8_t size, bool_t sign)
+{
+    dabt->reg = reg;
+    dabt->size = size;
+    dabt->sign = sign;
+}
+
+/* TODO: Handle all THUMB2 instruction other than simple store */

I think we decided to remove this (and the other one).

Quoted 8 lines
xen/arch/arm/decode.c new file +8 -0
+static int decode_thumb2(register_t pc, struct hsr_dabt *dabt, uint16_t hw1)
+{
+    uint16_t hw2;
+    int rc;
+    uint16_t rt;
+
+    rc = raw_copy_from_guest(&hw2, (void *__user)(pc + 2), sizeof (hw2));
+    if ( rc )

xen/arch/arm/decode.c line 54

Quoted 10 lines
xen/arch/arm/decode.c new file +10 -0
+        return rc;
+
+    rt = (hw2 >> 12) & 0x7;
+
+    switch ( (hw1 >> 9) & 0xf )
+    {
+    case 12:
+    {
+        bool_t sign = !!(hw1 & (1 << 8));
+        bool_t load = !!(hw1 & (1 << 4));

!! is unneeded with the bool type I think.

xen/arch/arm/decode.c line 66

Quoted 12 lines
xen/arch/arm/decode.c new file +12 -0
+
+        if ( (hw1 & 0x0110) == 0x0100 )
+            /* NEON instruction */
+            goto bad_thumb2;
+
+        if ( (hw1 & 0x0070) == 0x0070 )
+            /* Undefined opcodes */
+            goto bad_thumb2;
+
+        /* Store/Load single data item */
+        if ( rt == 15 )
+            /* XXX: Rt == 15 is only invalid for store instruction */

So the check should be "rt == 15 && load" ?

Quoted 9 lines
xen/arch/arm/decode.c new file +9 -0
+            goto bad_thumb2;
+
+        if ( !load && sign )
+            /* Store instruction doesn't support sign extension */
+            goto bad_thumb2;
+
+        update_dabt(dabt, rt, (hw1 >> 5) & 3, sign);
+
+        break;

xen/arch/arm/decode.c line 85

Quoted 10 lines
xen/arch/arm/decode.c new file +10 -0
+    }
+    default:
+        goto bad_thumb2;
+    }
+
+    return 0;
+
+bad_thumb2:
+    printk("DOM%u: unhandled THUMB2 instruction 0x%x%x\n",
+           current->domain->domain_id, hw1, hw2);

Should this be gdprintk or gprintk?

Quoted 61 lines
xen/arch/arm/decode.c new file +61 -0
+
+    return 1;
+}
+
+/* TODO: Handle all THUMB instructions other than store */
+static int decode_thumb(register_t pc, struct hsr_dabt *dabt)
+{
+    uint16_t instr;
+    int rc;
+
+    rc = raw_copy_from_guest(&instr, (void * __user)pc, sizeof (instr));
+    if ( rc )
+        return rc;
+
+    switch ( instr >> 12 )
+    {
+    case 5:
+    {
+        /* Load/Store register */
+        uint16_t opB = (instr >> 9) & 0x7;
+        int reg = instr & 7;
+
+        switch ( opB & 0x3 )
+        {
+        case 0: /* Non-signed word */
+            update_dabt(dabt, reg, 2, 0);
+            break;
+        case 1: /* Non-signed halfword */
+            update_dabt(dabt, reg, 1, 0);
+            break;
+        case 2: /* Non-signed byte */
+            update_dabt(dabt, reg, 0, 0);
+            break;
+        case 3: /* Signed byte */
+            update_dabt(dabt, reg, 0, 1);
+            break;
+        }
+
+        break;
+    }
+    case 6:
+        /* Load/Store word immediate offset */
+        update_dabt(dabt, instr & 7, 2, 0);
+        break;
+    case 7:
+        /* Load/Store byte immediate offset */
+        update_dabt(dabt, instr & 7, 0, 0);
+        break;
+    case 8:
+        /* Load/Store halfword immediate offset */
+        update_dabt(dabt, instr & 7, 1, 0);
+        break;
+    case 9:
+        /* Load/Store word sp offset */
+        update_dabt(dabt, (instr >> 8) & 7, 2, 0);
+        break;
+    case 14:
+        if ( instr & (1 << 11) )
+            return decode_thumb2(pc, dabt, instr);
+        goto bad_thumb;
+    case 15:

xen/arch/arm/decode.c line 156

Quoted 10 lines
xen/arch/arm/decode.c new file +10 -0
+        return decode_thumb2(pc, dabt, instr);
+    default:
+        goto bad_thumb;
+    }
+
+    return 0;
+
+bad_thumb:
+    printk("DOM%u: unhandled THUMB instruction 0x%x\n",
+           current->domain->domain_id, instr);

gdprint etc?

xen/arch/arm/decode.c line 165

Quoted 9 lines
xen/arch/arm/decode.c new file +9 -0
+    return 1;
+}
+
+int decode_instruction(const struct cpu_user_regs *regs, struct hsr_dabt *dabt)
+{
+    if ( is_pv32_domain(current->domain) && regs->cpsr & PSR_THUMB )
+        return decode_thumb(regs->pc, dabt);
+
+    /* TODO: Handle ARM instruction */

You log unhandled thumb instructions but not ARM one, I think you should log here too.

Quoted 58 lines
xen/arch/arm/decode.c new file +3 -0
+
+    return 1;
+}
xen/arch/arm/decode.h new file +49 -0
new file mode 100644
index 0000000..4613763
@@ -0,0 +1,49 @@
+/*
+ * xen/arch/arm/decode.h
+ *
+ * Instruction decoder
+ *
+ * Julien Grall <[email protected]>
+ * Copyright (C) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __ARCH_ARM_DECODE_H_
+#define __ARCH_ARM_DECODE_H_
+
+#include <asm/regs.h>
+#include <asm/processor.h>
+
+/**
+ * Decode an instruction from pc
+ * /!\ This function is not intended to fully decode an instruction. It
+ * considers that the instruction is valid.
+ *
+ * This function will get:
+ *  - The transfer register
+ *  - Sign bit
+ *  - Size
+ */
+
+int decode_instruction(const struct cpu_user_regs *regs,
+                       struct hsr_dabt *dabt);
+
+#endif /* __ARCH_ARM_DECODE_H_ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
#3 lore raw

Re: [PATCH v4 1/2] xen/arm: Start to implement an ARM decoder instruction

Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall

Some erratas on ARM processor requires to decode the instruction.

Errata is already the plural of Erratum, I think.

Right, I will fix it.

Quoted 71 lines
Quoted 71 lines

The decoder will, obviously, decode and fill the ISS fields of the hsr_dabt.

For the moment, the decoder only supports:
- THUMB2 store instruction
- THUMB single load/store instruction

---
Changes in v4:
- Add warning about the purpose of this function
- Add helper to update ISS (register, sign, size) field of DABT
- Improve decoding for THUMB 2 store instruction
- Only decode thumb instruction if it's a 32-bit guest

---
 xen/arch/arm/Makefile |    1 +
 xen/arch/arm/decode.c |  168 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/decode.h |   49 +++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 xen/arch/arm/decode.c
 create mode 100644 xen/arch/arm/decode.h
xen/arch/arm/Makefile +1 -0
index 5ae5831..5c13a65 100644
@@ -30,6 +30,7 @@ obj-y += vtimer.o
 obj-y += vpl011.o
 obj-y += hvm.o
 obj-y += device.o
+obj-y += decode.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/decode.c new file +30 -0
new file mode 100644
index 0000000..0e7d8ba
@@ -0,0 +1,168 @@
+/*
+ * xen/arch/arm/decode.c
+ *
+ * Instruction decoder
+ *
+ * Julien Grall <[email protected]>
+ * Copyright (C) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/types.h>
+#include <xen/sched.h>
+#include <asm/current.h>
+#include <asm/guest_access.h>
+#include <xen/lib.h>
+
+#include "decode.h"
+
+static void update_dabt(struct hsr_dabt *dabt, int reg,
+                        uint8_t size, bool_t sign)
+{
Quoted 8 lines

xen/arch/arm/decode.c line 36

Quoted 6 lines
xen/arch/arm/decode.c new file +6 -0
+    dabt->reg = reg;
+    dabt->size = size;
+    dabt->sign = sign;
+}
+
+/* TODO: Handle all THUMB2 instruction other than simple store */

I think we decided to remove this (and the other one).

Oh right, I forgot to remove it.

Quoted 12 lines
Quoted 12 lines
xen/arch/arm/decode.c new file +12 -0
+static int decode_thumb2(register_t pc, struct hsr_dabt *dabt, uint16_t hw1)
+{
+    uint16_t hw2;
+    int rc;
+    uint16_t rt;
+
+    rc = raw_copy_from_guest(&hw2, (void *__user)(pc + 2), sizeof (hw2));
+    if ( rc )
+        return rc;
+
+    rt = (hw2 >> 12) & 0x7;
+
Quoted 8 lines

xen/arch/arm/decode.c line 54

Quoted 6 lines
xen/arch/arm/decode.c new file +6 -0
+    switch ( (hw1 >> 9) & 0xf )
+    {
+    case 12:
+    {
+        bool_t sign = !!(hw1 & (1 << 8));
+        bool_t load = !!(hw1 & (1 << 4));

!! is unneeded with the bool type I think.

I was not sure, I will remove the '!!'.

Quoted 6 lines
Quoted 6 lines
xen/arch/arm/decode.c new file +6 -0
+
+        if ( (hw1 & 0x0110) == 0x0100 )
+            /* NEON instruction */
+            goto bad_thumb2;
+
+        if ( (hw1 & 0x0070) == 0x0070 )
Quoted 8 lines

xen/arch/arm/decode.c line 66

Quoted 6 lines
xen/arch/arm/decode.c new file +6 -0
+            /* Undefined opcodes */
+            goto bad_thumb2;
+
+        /* Store/Load single data item */
+        if ( rt == 15 )
+            /* XXX: Rt == 15 is only invalid for store instruction */

So the check should be "rt == 15 && load" ?

No, when rt == 15 the instructions are memory hints (pld, pldw,..) and the layout is different.

Quoted 13 lines
Quoted 13 lines
xen/arch/arm/decode.c new file +13 -0
+            goto bad_thumb2;
+
+        if ( !load && sign )
+            /* Store instruction doesn't support sign extension */
+            goto bad_thumb2;
+
+        update_dabt(dabt, rt, (hw1 >> 5) & 3, sign);
+
+        break;
+    }
+    default:
+        goto bad_thumb2;
+    }
Quoted 8 lines

xen/arch/arm/decode.c line 85

Quoted 6 lines
xen/arch/arm/decode.c new file +6 -0
+
+    return 0;
+
+bad_thumb2:
+    printk("DOM%u: unhandled THUMB2 instruction 0x%x%x\n",
+           current->domain->domain_id, hw1, hw2);

Should this be gdprintk or gprintk?

I will use gdprintk.

Quoted 75 lines
Quoted 62 lines
xen/arch/arm/decode.c new file +61 -0
+
+    return 1;
+}
+
+/* TODO: Handle all THUMB instructions other than store */
+static int decode_thumb(register_t pc, struct hsr_dabt *dabt)
+{
+    uint16_t instr;
+    int rc;
+
+    rc = raw_copy_from_guest(&instr, (void * __user)pc, sizeof (instr));
+    if ( rc )
+        return rc;
+
+    switch ( instr >> 12 )
+    {
+    case 5:
+    {
+        /* Load/Store register */
+        uint16_t opB = (instr >> 9) & 0x7;
+        int reg = instr & 7;
+
+        switch ( opB & 0x3 )
+        {
+        case 0: /* Non-signed word */
+            update_dabt(dabt, reg, 2, 0);
+            break;
+        case 1: /* Non-signed halfword */
+            update_dabt(dabt, reg, 1, 0);
+            break;
+        case 2: /* Non-signed byte */
+            update_dabt(dabt, reg, 0, 0);
+            break;
+        case 3: /* Signed byte */
+            update_dabt(dabt, reg, 0, 1);
+            break;
+        }
+
+        break;
+    }
+    case 6:
+        /* Load/Store word immediate offset */
+        update_dabt(dabt, instr & 7, 2, 0);
+        break;
+    case 7:
+        /* Load/Store byte immediate offset */
+        update_dabt(dabt, instr & 7, 0, 0);
+        break;
+    case 8:
+        /* Load/Store halfword immediate offset */
+        update_dabt(dabt, instr & 7, 1, 0);
+        break;
+    case 9:
+        /* Load/Store word sp offset */
+        update_dabt(dabt, (instr >> 8) & 7, 2, 0);
+        break;
+    case 14:
+        if ( instr & (1 << 11) )
+            return decode_thumb2(pc, dabt, instr);
+        goto bad_thumb;
+    case 15:

xen/arch/arm/decode.c line 156

Quoted 10 lines
xen/arch/arm/decode.c new file +10 -0
+        return decode_thumb2(pc, dabt, instr);
+    default:
+        goto bad_thumb;
+    }
+
+    return 0;
+
+bad_thumb:
+    printk("DOM%u: unhandled THUMB instruction 0x%x\n",
+           current->domain->domain_id, instr);

gdprint etc?

Quoted 12 lines

xen/arch/arm/decode.c line 165

Quoted 9 lines
xen/arch/arm/decode.c new file +9 -0
+    return 1;
+}
+
+int decode_instruction(const struct cpu_user_regs *regs, struct hsr_dabt *dabt)
+{
+    if ( is_pv32_domain(current->domain) && regs->cpsr & PSR_THUMB )
+        return decode_thumb(regs->pc, dabt);
+
+    /* TODO: Handle ARM instruction */

You log unhandled thumb instructions but not ARM one, I think you should log here too.

I'll add a warning.

Quoted 60 lines
Quoted 58 lines
xen/arch/arm/decode.c new file +3 -0
+
+    return 1;
+}
xen/arch/arm/decode.h new file +49 -0
new file mode 100644
index 0000000..4613763
@@ -0,0 +1,49 @@
+/*
+ * xen/arch/arm/decode.h
+ *
+ * Instruction decoder
+ *
+ * Julien Grall <[email protected]>
+ * Copyright (C) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __ARCH_ARM_DECODE_H_
+#define __ARCH_ARM_DECODE_H_
+
+#include <asm/regs.h>
+#include <asm/processor.h>
+
+/**
+ * Decode an instruction from pc
+ * /!\ This function is not intended to fully decode an instruction. It
+ * considers that the instruction is valid.
+ *
+ * This function will get:
+ *  - The transfer register
+ *  - Sign bit
+ *  - Size
+ */
+
+int decode_instruction(const struct cpu_user_regs *regs,
+                       struct hsr_dabt *dabt);
+
+#endif /* __ARCH_ARM_DECODE_H_ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v4 1/2] xen/arm: Start to implement an ARM decoder instruction

In reply to Ian Campbell
Quoted 95 lines · Ian Campbell
Quoted 1 line · Julien Grall

Some erratas on ARM processor requires to decode the instruction.

Errata is already the plural of Erratum, I think.

Quoted 66 lines

The decoder will, obviously, decode and fill the ISS fields of the hsr_dabt.

For the moment, the decoder only supports:
- THUMB2 store instruction
- THUMB single load/store instruction

---
Changes in v4:
- Add warning about the purpose of this function
- Add helper to update ISS (register, sign, size) field of DABT
- Improve decoding for THUMB 2 store instruction
- Only decode thumb instruction if it's a 32-bit guest

---
 xen/arch/arm/Makefile |    1 +
 xen/arch/arm/decode.c |  168 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/decode.h |   49 +++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 xen/arch/arm/decode.c
 create mode 100644 xen/arch/arm/decode.h
xen/arch/arm/Makefile +1 -0
index 5ae5831..5c13a65 100644
@@ -30,6 +30,7 @@ obj-y += vtimer.o
 obj-y += vpl011.o
 obj-y += hvm.o
 obj-y += device.o
+obj-y += decode.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/decode.c new file +26 -0
new file mode 100644
index 0000000..0e7d8ba
@@ -0,0 +1,168 @@
+/*
+ * xen/arch/arm/decode.c
+ *
+ * Instruction decoder
+ *
+ * Julien Grall <[email protected]>
+ * Copyright (C) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/types.h>
+#include <xen/sched.h>
+#include <asm/current.h>
+#include <asm/guest_access.h>
+#include <xen/lib.h>
+
+#include "decode.h"

xen/arch/arm/decode.c line 36

Quoted 10 lines
xen/arch/arm/decode.c new file +10 -0
+
+static void update_dabt(struct hsr_dabt *dabt, int reg,
+                        uint8_t size, bool_t sign)
+{
+    dabt->reg = reg;
+    dabt->size = size;
+    dabt->sign = sign;
+}
+
+/* TODO: Handle all THUMB2 instruction other than simple store */

I think we decided to remove this (and the other one).

Quoted 12 lines
xen/arch/arm/decode.c new file +12 -0
+static int decode_thumb2(register_t pc, struct hsr_dabt *dabt, uint16_t hw1)
+{
+    uint16_t hw2;
+    int rc;
+    uint16_t rt;
+
+    rc = raw_copy_from_guest(&hw2, (void *__user)(pc + 2), sizeof (hw2));
+    if ( rc )
+        return rc;
+
+    rt = (hw2 >> 12) & 0x7;
+
Quoted 8 lines

xen/arch/arm/decode.c line 54

Quoted 6 lines
xen/arch/arm/decode.c new file +6 -0
+    switch ( (hw1 >> 9) & 0xf )
+    {
+    case 12:
+    {
+        bool_t sign = !!(hw1 & (1 << 8));
+        bool_t load = !!(hw1 & (1 << 4));

!! is unneeded with the bool type I think.

I have tried to remove the !! and gcc complained:
decode.c:52:28: error: overflow in implicit constant conversion [-Werror=overflow]

         bool_t sign = (hw1 & (1 << 8));
                            ^

This is because bool_t is defined as char so the value will overflow.

Signature · 1 line
Julien Grall
#5 lore raw

PATCH v4 2/2 xen/arm: errata 766422: decode thumb store during data abort

In reply to Julien Grall

From the errata document:

When a non-secure non-hypervisor memory operation instruction generates a stage2 page table translation fault, a trap to the hypervisor will be triggered. For an architecturally defined subset of instructions, the Hypervisor Syndrome Register (HSR) will have the Instruction Syndrome Valid (ISV) bit set to 1’b1, and the Rt field should reflect the source register (for stores) or destination register for loads.
On Cortex-A15, for Thumb and ThumbEE stores, the Rt value may be incorrect and should not be used, even if the ISV bit is set. All loads, and all ARM instruction set loads and stores, will have the correct Rt value if the ISV bit is set.

To avoid this issue, Xen needs to decode thumb store instruction and update the transfer register.

---
Changes in v3:
- Use unlikely to check if the processor is affected by the errata
- Move the decoder in another patch and use it
Changes in v2:
- Only decode the instruction on affected processor
- Handle ARM 32-bit instruction in read_instruction

---
 xen/arch/arm/traps.c                  |   12 ++++++++++++
 xen/include/asm-arm/arm32/processor.h |    4 ++++
 xen/include/asm-arm/arm64/processor.h |    2 ++
 3 files changed, 18 insertions(+)
xen/arch/arm/traps.c +12 -0
index 6b5fa51..47e9ba4 100644
@@ -36,6 +36,7 @@
 #include <asm/cpregs.h>
 #include <asm/psci.h>
 
+#include "decode.h"
 #include "io.h"
 #include "vtimer.h"
 #include <asm/gic.h>
@@ -1336,6 +1337,17 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     if ( !dabt.valid )
         goto bad_data_abort;
 
+    /*
+     * Errata 766422: Thumb store translation fault to Hypervisor may
+     * not have correct HSR Rt value.
+     */
+    if ( cpu_has_errata_766422() && (regs->cpsr & PSR_THUMB) && dabt.write )
+    {
+        rc = decode_instruction(regs, &info.dabt);
+        if ( rc )
+            goto bad_data_abort;
+    }
+
     if (handle_mmio(&info))
     {
         advance_pc(regs, hsr);
xen/include/asm-arm/arm32/processor.h +4 -0
index b266252..a21d104 100644
@@ -111,6 +111,10 @@ struct cpu_user_regs
 #define READ_SYSREG(R...)       READ_SYSREG32(R)
 #define WRITE_SYSREG(V, R...)   WRITE_SYSREG32(V, R)
 
+/* Errata 766422: only Cortex A15 r0p4 is affected */
+#define cpu_has_errata_766422()                             \
+    (unlikely(current_cpu_data.midr.bits == 0x410fc0f4))
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_ARM_ARM32_PROCESSOR_H */
xen/include/asm-arm/arm64/processor.h +2 -0
index c8d4609..5d9b952 100644
@@ -104,6 +104,8 @@ struct cpu_user_regs
 #define READ_SYSREG(name)     READ_SYSREG64(name)
 #define WRITE_SYSREG(v, name) WRITE_SYSREG64(v, name)
 
+#define cpu_has_errata_766422() 0
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_ARM_ARM64_PROCESSOR_H */
Signature · 7 lines
1.7.10.4


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

Re: [PATCH v4 2/2] xen/arm: errata 766422: decode thumb store during data abort

xen/arch/arm/traps.c static void do_trap_data_abort_guest(struct cpu_user_regs *regs, · line 1348

Quoted 9 lines · Julien Grall
xen/arch/arm/traps.c +9 -0
+    /*
+     * Errata 766422: Thumb store translation fault to Hypervisor may
+     * not have correct HSR Rt value.
+     */
+    if ( cpu_has_errata_766422() && (regs->cpsr & PSR_THUMB) && dabt.write )
+    {
+        rc = decode_instruction(regs, &info.dabt);
+        if ( rc )
+            goto bad_data_abort;

Consider logging here so we know which caller of decode_instruction failed?

Either way:

Ian.

#7 lore raw

Re: [PATCH v4 2/2] xen/arm: errata 766422: decode thumb store during data abort

Quoted 11 lines · Ian Campbell

xen/arch/arm/traps.c static void do_trap_data_abort_guest(struct cpu_user_regs *regs, · line 1348

Quoted 9 lines · Julien Grall
xen/arch/arm/traps.c +9 -0
+    /*
+     * Errata 766422: Thumb store translation fault to Hypervisor may
+     * not have correct HSR Rt value.
+     */
+    if ( cpu_has_errata_766422() && (regs->cpsr & PSR_THUMB) && dabt.write )
+    {
+        rc = decode_instruction(regs, &info.dabt);
+        if ( rc )
+            goto bad_data_abort;
Quoted 2 lines

Consider logging here so we know which caller of decode_instruction failed?

I will add a printk.

Quoted 6 lines

Either way:

Ian.

Signature · 1 line
Julien Grall
#8 lore raw

Re: [PATCH v4 2/2] xen/arm: errata 766422: decode thumb store during data abort

Quoted 12 lines · Julien Grall
Quoted 11 lines · Ian Campbell
Quoted 9 lines · Julien Grall
xen/arch/arm/traps.c +9 -0
+    /*
+     * Errata 766422: Thumb store translation fault to Hypervisor may
+     * not have correct HSR Rt value.
+     */
+    if ( cpu_has_errata_766422() && (regs->cpsr & PSR_THUMB) && dabt.write )
+    {
+        rc = decode_instruction(regs, &info.dabt);
+        if ( rc )
+            goto bad_data_abort;
Quoted 4 lines
Quoted 2 lines

Consider logging here so we know which caller of decode_instruction failed?

I will add a printk.

gdprintk ;-)

Quoted 9 lines
Quoted 7 lines

Either way:

Ian.