linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/5] arm64: Define Falkor v1 CPU
@ 2016-12-29 22:43 Christopher Covington
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Christopher Covington @ 2016-12-29 22:43 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur
  Cc: Christopher Covington

From: Shanker Donthineni <shankerd@codeaurora.org>

Define the MIDR implementer and part number field values for the Qualcomm
Datacenter Technologies Falkor processor version 1 in the usual manner.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Signed-off-by: Christopher Covington <cov@codeaurora.org>
---
 arch/arm64/include/asm/cputype.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
index 26a68dd..ee60561 100644
--- a/arch/arm64/include/asm/cputype.h
+++ b/arch/arm64/include/asm/cputype.h
@@ -71,6 +71,7 @@
 #define ARM_CPU_IMP_APM			0x50
 #define ARM_CPU_IMP_CAVIUM		0x43
 #define ARM_CPU_IMP_BRCM		0x42
+#define ARM_CPU_IMP_QCOM		0x51
 
 #define ARM_CPU_PART_AEM_V8		0xD0F
 #define ARM_CPU_PART_FOUNDATION		0xD00
@@ -84,10 +85,13 @@
 
 #define BRCM_CPU_PART_VULCAN		0x516
 
+#define QCOM_CPU_PART_FALKOR_V1		0x800
+
 #define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
 #define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
 #define MIDR_THUNDERX	MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)
 #define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)
+#define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1)
 
 #ifndef __ASSEMBLY__
 
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora
Forum, a Linux Foundation Collaborative Project.

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

* [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 22:43 [PATCH v2 1/5] arm64: Define Falkor v1 CPU Christopher Covington
@ 2016-12-29 22:43 ` Christopher Covington
  2016-12-29 23:02   ` Timur Tabi
                     ` (4 more replies)
  2016-12-29 22:43 ` [PATCH v2 3/5] arm64: Create and use __tlbi_dsb() macros Christopher Covington
                   ` (2 subsequent siblings)
  3 siblings, 5 replies; 19+ messages in thread
From: Christopher Covington @ 2016-12-29 22:43 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc
  Cc: Christopher Covington

From: Shanker Donthineni <shankerd@codeaurora.org>

On the Qualcomm Datacenter Technologies Falkor v1 CPU, memory accesses may
allocate TLB entries using an incorrect ASID when TTBRx_EL1 is being
updated. Changing the TTBRx_EL1[ASID] and TTBRx_EL1[BADDR] fields
separately using a reserved ASID will ensure that there are no TLB entries
with incorrect ASID after changing the the ASID.

Pseudo code:
  write TTBRx_EL1[ASID] to a reserved value
  ISB
  write TTBRx_EL1[BADDR] to a desired value
  ISB
  write TTBRx_EL1[ASID] to a desired value
  ISB

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Signed-off-by: Christopher Covington <cov@codeaurora.org>
---
 Documentation/arm64/silicon-errata.txt | 43 +++++++++++++++++-----------------
 arch/arm64/Kconfig                     | 16 +++++++++++++
 arch/arm64/include/asm/cpucaps.h       |  3 ++-
 arch/arm64/kernel/cpu_errata.c         |  7 ++++++
 arch/arm64/mm/context.c                | 10 ++++++++
 arch/arm64/mm/proc.S                   | 12 ++++++++++
 6 files changed, 69 insertions(+), 22 deletions(-)

diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt
index 405da11..7151aed 100644
--- a/Documentation/arm64/silicon-errata.txt
+++ b/Documentation/arm64/silicon-errata.txt
@@ -42,24 +42,25 @@ file acts as a registry of software workarounds in the Linux Kernel and
 will be updated when new workarounds are committed and backported to
 stable kernels.
 
-| Implementor    | Component       | Erratum ID      | Kconfig                 |
-+----------------+-----------------+-----------------+-------------------------+
-| ARM            | Cortex-A53      | #826319         | ARM64_ERRATUM_826319    |
-| ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
-| ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
-| ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
-| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
-| ARM            | Cortex-A53      | #843419         | ARM64_ERRATUM_843419    |
-| ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
-| ARM            | Cortex-A57      | #852523         | N/A                     |
-| ARM            | Cortex-A57      | #834220         | ARM64_ERRATUM_834220    |
-| ARM            | Cortex-A72      | #853709         | N/A                     |
-| ARM            | MMU-500         | #841119,#826419 | N/A                     |
-|                |                 |                 |                         |
-| Cavium         | ThunderX ITS    | #22375, #24313  | CAVIUM_ERRATUM_22375    |
-| Cavium         | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144    |
-| Cavium         | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154    |
-| Cavium         | ThunderX Core   | #27456          | CAVIUM_ERRATUM_27456    |
-| Cavium         | ThunderX SMMUv2 | #27704          | N/A		       |
-|                |                 |                 |                         |
-| Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585     |
+| Implementor   | Component       | Erratum ID      | Kconfig                  |
++---------------+-----------------+-----------------+--------------------------+
+| ARM           | Cortex-A53      | #826319         | ARM64_ERRATUM_826319     |
+| ARM           | Cortex-A53      | #827319         | ARM64_ERRATUM_827319     |
+| ARM           | Cortex-A53      | #824069         | ARM64_ERRATUM_824069     |
+| ARM           | Cortex-A53      | #819472         | ARM64_ERRATUM_819472     |
+| ARM           | Cortex-A53      | #845719         | ARM64_ERRATUM_845719     |
+| ARM           | Cortex-A53      | #843419         | ARM64_ERRATUM_843419     |
+| ARM           | Cortex-A57      | #832075         | ARM64_ERRATUM_832075     |
+| ARM           | Cortex-A57      | #852523         | N/A                      |
+| ARM           | Cortex-A57      | #834220         | ARM64_ERRATUM_834220     |
+| ARM           | Cortex-A72      | #853709         | N/A                      |
+| ARM           | MMU-500         | #841119,#826419 | N/A                      |
+|               |                 |                 |                          |
+| Cavium        | ThunderX ITS    | #22375, #24313  | CAVIUM_ERRATUM_22375     |
+| Cavium        | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144     |
+| Cavium        | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154     |
+| Cavium        | ThunderX Core   | #27456          | CAVIUM_ERRATUM_27456     |
+| Cavium        | ThunderX SMMUv2 | #27704          | N/A                      |
+|               |                 |                 |                          |
+| Freescale/NXP | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585      |
+| Qualcomm      | Falkor v1       | E1003           | QCOM_FALKOR_ERRATUM_1003 |
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1117421..7ce4a4b 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -479,6 +479,22 @@ config CAVIUM_ERRATUM_27456
 
 	  If unsure, say Y.
 
+config QCOM_FALKOR_ERRATUM_1003
+	bool "Falkor E1003: Incorrect translation due to ASID change"
+	default y
+	help
+	  An incorrect translation TLBI entry may be created while
+	  changing the ASID & translation table address together for
+	  TTBR0_EL1. The workaround for this issue is use a reserved
+	  ASID in cpu_do_switch_mm() before switching to target ASID.
+
+	  If unsure, say Y.
+
+config QCOM_FALKOR_E1003_RESERVED_ASID
+	int
+	default 1
+	depends on QCOM_FALKOR_ERRATUM_1003
+
 endmenu
 
 
diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index 4174f09..5aaf7ee 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -35,7 +35,8 @@
 #define ARM64_HYP_OFFSET_LOW			14
 #define ARM64_MISMATCHED_CACHE_LINE_SIZE	15
 #define ARM64_HAS_NO_FPSIMD			16
+#define ARM64_WORKAROUND_QCOM_FALKOR_E1003	17
 
-#define ARM64_NCAPS				17
+#define ARM64_NCAPS				18
 
 #endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index b75e917..787b542 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -130,6 +130,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
 		.def_scope = SCOPE_LOCAL_CPU,
 		.enable = cpu_enable_trap_ctr_access,
 	},
+#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
+	{
+		.desc = "Qualcomm Falkor erratum 1003",
+		.capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
+		MIDR_RANGE(MIDR_QCOM_FALKOR_V1, 0x00, 0x00),
+	},
+#endif
 	{
 	}
 };
diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
index 4c63cb1..9514a89 100644
--- a/arch/arm64/mm/context.c
+++ b/arch/arm64/mm/context.c
@@ -87,6 +87,11 @@ static void flush_context(unsigned int cpu)
 	/* Update the list of reserved ASIDs and the ASID bitmap. */
 	bitmap_clear(asid_map, 0, NUM_USER_ASIDS);
 
+	/* Reserve ASID for Falkor erratum 1003 */
+	if (IS_ENABLED(CONFIG_QCOM_FALKOR_ERRATUM_1003) &&
+	    cpus_have_cap(ARM64_WORKAROUND_QCOM_FALKOR_E1003))
+		__set_bit(CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID, asid_map);
+
 	/*
 	 * Ensure the generation bump is observed before we xchg the
 	 * active_asids.
@@ -244,6 +249,11 @@ static int asids_init(void)
 		panic("Failed to allocate bitmap for %lu ASIDs\n",
 		      NUM_USER_ASIDS);
 
+	/* Reserve ASID for Falkor erratum 1003 */
+	if (IS_ENABLED(CONFIG_QCOM_FALKOR_ERRATUM_1003) &&
+	    cpus_have_cap(ARM64_WORKAROUND_QCOM_FALKOR_E1003))
+		__set_bit(CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID, asid_map);
+
 	pr_info("ASID allocator initialised with %lu entries\n", NUM_USER_ASIDS);
 	return 0;
 }
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 32682be..0c6d173 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -140,6 +140,18 @@ ENDPROC(cpu_do_resume)
 ENTRY(cpu_do_switch_mm)
 	mmid	x1, x1				// get mm->context.id
 	bfi	x0, x1, #48, #16		// set the ASID
+#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
+alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003
+	mrs     x2, ttbr0_el1                   // get cuurent TTBR0_EL1
+	mov     x3, #CONFIG_QCOM_FALKOR_ERRATUM_1003	// reserved ASID
+	bfi     x2, x3, #48, #16                // set the reserved ASID + old BADDR
+	msr     ttbr0_el1, x2                   // update TTBR0_EL1
+	isb
+	bfi     x2, x0, #0, #48                 // set the desired BADDR + reserved ASID
+	msr     ttbr0_el1, x2                   // update TTBR0_EL1
+	isb
+alternative_else_nop_endif
+#endif
 	msr	ttbr0_el1, x0			// set TTBR0
 	isb
 	post_ttbr0_update_workaround
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora
Forum, a Linux Foundation Collaborative Project.

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

* [PATCH v2 3/5] arm64: Create and use __tlbi_dsb() macros
  2016-12-29 22:43 [PATCH v2 1/5] arm64: Define Falkor v1 CPU Christopher Covington
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
@ 2016-12-29 22:43 ` Christopher Covington
  2016-12-29 22:43 ` [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code Christopher Covington
  2016-12-29 22:43 ` [PATCH v2 5/5] arm64: Work around Falkor erratum 1009 Christopher Covington
  3 siblings, 0 replies; 19+ messages in thread
From: Christopher Covington @ 2016-12-29 22:43 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur
  Cc: Christopher Covington

This refactoring will allow an errata workaround that repeats tlbi dsb
sequences to only change one location. This is not intended to change the
generated assembly and comparing before and after preprocessor output of
arch/arm64/mm/mmu.c and vmlinux objdump show no functional changes.

Signed-off-by: Christopher Covington <cov@codeaurora.org>
---
 arch/arm64/include/asm/tlbflush.h | 104 +++++++++++++++++++++++++-------------
 1 file changed, 69 insertions(+), 35 deletions(-)

diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
index deab523..f28813c 100644
--- a/arch/arm64/include/asm/tlbflush.h
+++ b/arch/arm64/include/asm/tlbflush.h
@@ -25,22 +25,69 @@
 #include <asm/cputype.h>
 
 /*
- * Raw TLBI operations.
+ * Raw TLBI, DSB operations
  *
- * Where necessary, use the __tlbi() macro to avoid asm()
- * boilerplate. Drivers and most kernel code should use the TLB
- * management routines in preference to the macro below.
+ * Where necessary, use __tlbi_*dsb() macros to avoid asm() boilerplate.
+ * Drivers and most kernel code should use the TLB management routines in
+ * preference to the macros below.
  *
- * The macro can be used as __tlbi(op) or __tlbi(op, arg), depending
- * on whether a particular TLBI operation takes an argument or
- * not. The macros handles invoking the asm with or without the
- * register argument as appropriate.
+ * The __tlbi_dsb() macro handles invoking the asm without any register
+ * argument, with a single register argument, and with start (included)
+ * and end (excluded) range of register arguments. For example:
+ *
+ * __tlbi_dsb(op, attr)
+ *
+ * 	tlbi op
+ *	dsb attr
+ *
+ * __tlbi_dsb(op, attr, addr)
+ *
+ *	mov %[addr], =addr
+ *	tlbi op, %[addr]
+ *	dsb attr
+ *
+ * __tlbi_range_dsb(op, attr, start, end)
+ *
+ * 	mov %[arg], =start
+ *	mov %[end], =end
+ * for:
+ * 	tlbi op, %[addr]
+ * 	add %[addr], %[addr], #(1 << (PAGE_SHIFT - 12))
+ * 	cmp %[addr], %[end]
+ * 	b.ne for
+ * 	dsb attr
  */
-#define __TLBI_0(op, arg)		asm ("tlbi " #op)
-#define __TLBI_1(op, arg)		asm ("tlbi " #op ", %0" : : "r" (arg))
-#define __TLBI_N(op, arg, n, ...)	__TLBI_##n(op, arg)
 
-#define __tlbi(op, ...)		__TLBI_N(op, ##__VA_ARGS__, 1, 0)
+#define __TLBI_FOR_0(ig0, ig1, ig2)
+#define __TLBI_INSTR_0(op, ig1, ig2)	"tlbi " #op
+#define __TLBI_IO_0(ig0, ig1, ig2)	: :
+
+#define __TLBI_FOR_1(ig0, ig1, ig2)
+#define __TLBI_INSTR_1(op, ig0, ig1)	"tlbi " #op ", %0"
+#define __TLBI_IO_1(ig0, arg, ig1)	: : "r" (arg)
+
+#define __TLBI_FOR_2(ig0, start, ig1)	unsigned long addr;		       \
+					for (addr = start; addr < end;	       \
+						addr += 1 << (PAGE_SHIFT - 12))
+#define __TLBI_INSTR_2(op, ig0, ig1)	"tlbi " #op ", %0"
+#define __TLBI_IO_2(ig0, ig1, ig2)	: : "r" (addr)
+
+#define __TLBI_FOR_N(op, a1, a2, n, ...)	__TLBI_FOR_##n(op, a1, a2)
+#define __TLBI_INSTR_N(op, a1, a2, n, ...)	__TLBI_INSTR_##n(op, a1, a2)
+#define __TLBI_IO_N(op, a1, a2, n, ...)	__TLBI_IO_##n(op, a1, a2)
+
+#define __TLBI_FOR(op, ...)		__TLBI_FOR_N(op, ##__VA_ARGS__, 2, 1, 0)
+#define __TLBI_INSTR(op, ...)		__TLBI_INSTR_N(op, ##__VA_ARGS__, 2, 1, 0)
+#define __TLBI_IO(op, ...)		__TLBI_IO_N(op, ##__VA_ARGS__, 2, 1, 0)
+
+#define __tlbi_asm_dsb(as, op, attr, ...) do {				       \
+		__TLBI_FOR(op, ##__VA_ARGS__)				       \
+			asm (__TLBI_INSTR(op, ##__VA_ARGS__)		       \
+			__TLBI_IO(op, ##__VA_ARGS__));			       \
+		asm volatile (	     as			"\ndsb " #attr "\n"    \
+		: : : "memory"); } while (0)
+
+#define __tlbi_dsb(...)	__tlbi_asm_dsb("", ##__VA_ARGS__)
 
 /*
  *	TLB Management
@@ -84,16 +131,14 @@
 static inline void local_flush_tlb_all(void)
 {
 	dsb(nshst);
-	__tlbi(vmalle1);
-	dsb(nsh);
+	__tlbi_dsb(vmalle1, nsh);
 	isb();
 }
 
 static inline void flush_tlb_all(void)
 {
 	dsb(ishst);
-	__tlbi(vmalle1is);
-	dsb(ish);
+	__tlbi_dsb(vmalle1is, ish);
 	isb();
 }
 
@@ -102,8 +147,7 @@ static inline void flush_tlb_mm(struct mm_struct *mm)
 	unsigned long asid = ASID(mm) << 48;
 
 	dsb(ishst);
-	__tlbi(aside1is, asid);
-	dsb(ish);
+	__tlbi_dsb(aside1is, ish, asid);
 }
 
 static inline void flush_tlb_page(struct vm_area_struct *vma,
@@ -112,8 +156,7 @@ static inline void flush_tlb_page(struct vm_area_struct *vma,
 	unsigned long addr = uaddr >> 12 | (ASID(vma->vm_mm) << 48);
 
 	dsb(ishst);
-	__tlbi(vale1is, addr);
-	dsb(ish);
+	__tlbi_dsb(vale1is, ish, addr);
 }
 
 /*
@@ -127,7 +170,6 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma,
 				     bool last_level)
 {
 	unsigned long asid = ASID(vma->vm_mm) << 48;
-	unsigned long addr;
 
 	if ((end - start) > MAX_TLB_RANGE) {
 		flush_tlb_mm(vma->vm_mm);
@@ -138,13 +180,10 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma,
 	end = asid | (end >> 12);
 
 	dsb(ishst);
-	for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) {
-		if (last_level)
-			__tlbi(vale1is, addr);
-		else
-			__tlbi(vae1is, addr);
-	}
-	dsb(ish);
+	if (last_level)
+		__tlbi_dsb(vale1is, ish, start, end);
+	else
+		__tlbi_dsb(vae1is, ish, start, end);
 }
 
 static inline void flush_tlb_range(struct vm_area_struct *vma,
@@ -155,8 +194,6 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
 
 static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
 {
-	unsigned long addr;
-
 	if ((end - start) > MAX_TLB_RANGE) {
 		flush_tlb_all();
 		return;
@@ -166,9 +203,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end
 	end >>= 12;
 
 	dsb(ishst);
-	for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
-		__tlbi(vaae1is, addr);
-	dsb(ish);
+	__tlbi_dsb(vaae1is, ish, start, end);
 	isb();
 }
 
@@ -181,8 +216,7 @@ static inline void __flush_tlb_pgtable(struct mm_struct *mm,
 {
 	unsigned long addr = uaddr >> 12 | (ASID(mm) << 48);
 
-	__tlbi(vae1is, addr);
-	dsb(ish);
+	__tlbi_dsb(vae1is, ish, addr);
 }
 
 #endif
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora
Forum, a Linux Foundation Collaborative Project.

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

* [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code
  2016-12-29 22:43 [PATCH v2 1/5] arm64: Define Falkor v1 CPU Christopher Covington
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
  2016-12-29 22:43 ` [PATCH v2 3/5] arm64: Create and use __tlbi_dsb() macros Christopher Covington
@ 2016-12-29 22:43 ` Christopher Covington
  2017-01-03 15:57   ` Mark Rutland
  2016-12-29 22:43 ` [PATCH v2 5/5] arm64: Work around Falkor erratum 1009 Christopher Covington
  3 siblings, 1 reply; 19+ messages in thread
From: Christopher Covington @ 2016-12-29 22:43 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur
  Cc: Christopher Covington

Refactor the KVM code to use the newly introduced __tlbi_dsb macros, which
will allow an errata workaround that repeats tlbi dsb sequences to only
change one location. This is not intended to change the generated assembly
and comparing before and after vmlinux objdump shows no functional changes.

Signed-off-by: Christopher Covington <cov@codeaurora.org>
---
 arch/arm64/kvm/hyp/tlb.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c
index 88e2f2b..66e3f72 100644
--- a/arch/arm64/kvm/hyp/tlb.c
+++ b/arch/arm64/kvm/hyp/tlb.c
@@ -16,6 +16,7 @@
  */
 
 #include <asm/kvm_hyp.h>
+#include <asm/tlbflush.h>
 
 void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
 {
@@ -32,7 +33,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
 	 * whole of Stage-1. Weep...
 	 */
 	ipa >>= 12;
-	asm volatile("tlbi ipas2e1is, %0" : : "r" (ipa));
+	__tlbi_dsb(ipas2e1is, ish, ipa);
 
 	/*
 	 * We have to ensure completion of the invalidation at Stage-2,
@@ -40,9 +41,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
 	 * complete (S1 + S2) walk based on the old Stage-2 mapping if
 	 * the Stage-1 invalidation happened first.
 	 */
-	dsb(ish);
-	asm volatile("tlbi vmalle1is" : : );
-	dsb(ish);
+	__tlbi_dsb(vmalle1is, ish);
 	isb();
 
 	write_sysreg(0, vttbr_el2);
@@ -57,8 +56,7 @@ void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
 	write_sysreg(kvm->arch.vttbr, vttbr_el2);
 	isb();
 
-	asm volatile("tlbi vmalls12e1is" : : );
-	dsb(ish);
+	__tlbi_dsb(vmalls12e1is, ish);
 	isb();
 
 	write_sysreg(0, vttbr_el2);
@@ -72,8 +70,7 @@ void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
 	write_sysreg(kvm->arch.vttbr, vttbr_el2);
 	isb();
 
-	asm volatile("tlbi vmalle1" : : );
-	dsb(nsh);
+	__tlbi_dsb(vmalle1, nsh);
 	isb();
 
 	write_sysreg(0, vttbr_el2);
@@ -82,7 +79,5 @@ void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
 void __hyp_text __kvm_flush_vm_context(void)
 {
 	dsb(ishst);
-	asm volatile("tlbi alle1is	\n"
-		     "ic ialluis	  ": : );
-	dsb(ish);
+	__tlbi_asm_dsb("ic ialluis", alle1is, ish);
 }
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora
Forum, a Linux Foundation Collaborative Project.

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

* [PATCH v2 5/5] arm64: Work around Falkor erratum 1009
  2016-12-29 22:43 [PATCH v2 1/5] arm64: Define Falkor v1 CPU Christopher Covington
                   ` (2 preceding siblings ...)
  2016-12-29 22:43 ` [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code Christopher Covington
@ 2016-12-29 22:43 ` Christopher Covington
  3 siblings, 0 replies; 19+ messages in thread
From: Christopher Covington @ 2016-12-29 22:43 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc
  Cc: Christopher Covington

During a TLB invalidate sequence targeting the inner shareable
domain, Falkor may prematurely complete the DSB before all loads
and stores using the old translation are observed; instruction
fetches are not subject to the conditions of this erratum.

Signed-off-by: Christopher Covington <cov@codeaurora.org>

Change-Id: I25e86b068addd68cdfba5a11142b9fc37312b1ee
---
 Documentation/arm64/silicon-errata.txt |  1 +
 arch/arm64/Kconfig                     | 10 ++++++++++
 arch/arm64/include/asm/cpucaps.h       |  3 ++-
 arch/arm64/include/asm/tlbflush.h      |  5 ++++-
 arch/arm64/kernel/cpu_errata.c         |  7 +++++++
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt
index 7151aed..98bef2a 100644
--- a/Documentation/arm64/silicon-errata.txt
+++ b/Documentation/arm64/silicon-errata.txt
@@ -64,3 +64,4 @@ stable kernels.
 |               |                 |                 |                          |
 | Freescale/NXP | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585      |
 | Qualcomm      | Falkor v1       | E1003           | QCOM_FALKOR_ERRATUM_1003 |
+| Qualcomm      | Falkor v1       | E1009           | QCOM_FALKOR_ERRATUM_1009 |
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 7ce4a4b..567651b 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -495,6 +495,16 @@ config QCOM_FALKOR_E1003_RESERVED_ASID
 	default 1
 	depends on QCOM_FALKOR_ERRATUM_1003
 
+config QCOM_FALKOR_ERRATUM_1009
+	bool "Falkor E1009: Prematurely complete a DSB after a TLBI"
+	default y
+	help
+	  Falkor CPU may prematurely complete a DSB following a TLBI xxIS
+	  invalidate maintenance operations. Repeat the TLBI operation one
+	  more time to fix the issue.
+
+	  If unsure, say Y.
+
 endmenu
 
 
diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index 5aaf7ee..55bcd02 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -36,7 +36,8 @@
 #define ARM64_MISMATCHED_CACHE_LINE_SIZE	15
 #define ARM64_HAS_NO_FPSIMD			16
 #define ARM64_WORKAROUND_QCOM_FALKOR_E1003	17
+#define ARM64_WORKAROUND_REPEAT_TLBI		18
 
-#define ARM64_NCAPS				18
+#define ARM64_NCAPS				19
 
 #endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
index f28813c..7313cd3 100644
--- a/arch/arm64/include/asm/tlbflush.h
+++ b/arch/arm64/include/asm/tlbflush.h
@@ -85,7 +85,10 @@
 			asm (__TLBI_INSTR(op, ##__VA_ARGS__)		       \
 			__TLBI_IO(op, ##__VA_ARGS__));			       \
 		asm volatile (	     as			"\ndsb " #attr "\n"    \
-		: : : "memory"); } while (0)
+			ALTERNATIVE("nop"		"\nnop"	       "\n",   \
+			__TLBI_INSTR(op, ##__VA_ARGS__)	"\ndsb " #attr "\n",   \
+			ARM64_WORKAROUND_REPEAT_TLBI)			       \
+		__TLBI_IO(op, ##__VA_ARGS__) : "memory"); } while (0)
 
 #define __tlbi_dsb(...)	__tlbi_asm_dsb("", ##__VA_ARGS__)
 
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index 787b542..e644364 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -137,6 +137,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
 		MIDR_RANGE(MIDR_QCOM_FALKOR_V1, 0x00, 0x00),
 	},
 #endif
+#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
+	{
+		.desc = "Qualcomm Falkor erratum 1009",
+		.capability = ARM64_WORKAROUND_REPEAT_TLBI,
+		MIDR_RANGE(MIDR_QCOM_FALKOR_V1, 0x00, 0x00),
+	},
+#endif
 	{
 	}
 };
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora
Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
@ 2016-12-29 23:02   ` Timur Tabi
  2017-01-06 15:39     ` Christopher Covington
  2016-12-29 23:08   ` Timur Tabi
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Timur Tabi @ 2016-12-29 23:02 UTC (permalink / raw)
  To: Christopher Covington, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd,
	Jonathan Corbet, linux-doc

On 12/29/2016 04:43 PM, Christopher Covington wrote:
> -| Implementor    | Component       | Erratum ID      | Kconfig                 |
> -+----------------+-----------------+-----------------+-------------------------+
> -| ARM            | Cortex-A53      | #826319         | ARM64_ERRATUM_826319    |
> -| ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
> -| ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
> -| ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
> -| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
> -| ARM            | Cortex-A53      | #843419         | ARM64_ERRATUM_843419    |
> -| ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
> -| ARM            | Cortex-A57      | #852523         | N/A                     |
> -| ARM            | Cortex-A57      | #834220         | ARM64_ERRATUM_834220    |
> -| ARM            | Cortex-A72      | #853709         | N/A                     |
> -| ARM            | MMU-500         | #841119,#826419 | N/A                     |
> -|                |                 |                 |                         |
> -| Cavium         | ThunderX ITS    | #22375, #24313  | CAVIUM_ERRATUM_22375    |
> -| Cavium         | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144    |
> -| Cavium         | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154    |
> -| Cavium         | ThunderX Core   | #27456          | CAVIUM_ERRATUM_27456    |
> -| Cavium         | ThunderX SMMUv2 | #27704          | N/A		       |
> -|                |                 |                 |                         |
> -| Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585     |
> +| Implementor   | Component       | Erratum ID      | Kconfig                  |
> ++---------------+-----------------+-----------------+--------------------------+
> +| ARM           | Cortex-A53      | #826319         | ARM64_ERRATUM_826319     |
> +| ARM           | Cortex-A53      | #827319         | ARM64_ERRATUM_827319     |
> +| ARM           | Cortex-A53      | #824069         | ARM64_ERRATUM_824069     |
> +| ARM           | Cortex-A53      | #819472         | ARM64_ERRATUM_819472     |
> +| ARM           | Cortex-A53      | #845719         | ARM64_ERRATUM_845719     |
> +| ARM           | Cortex-A53      | #843419         | ARM64_ERRATUM_843419     |
> +| ARM           | Cortex-A57      | #832075         | ARM64_ERRATUM_832075     |
> +| ARM           | Cortex-A57      | #852523         | N/A                      |
> +| ARM           | Cortex-A57      | #834220         | ARM64_ERRATUM_834220     |
> +| ARM           | Cortex-A72      | #853709         | N/A                      |
> +| ARM           | MMU-500         | #841119,#826419 | N/A                      |
> +|               |                 |                 |                          |
> +| Cavium        | ThunderX ITS    | #22375, #24313  | CAVIUM_ERRATUM_22375     |
> +| Cavium        | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144     |
> +| Cavium        | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154     |
> +| Cavium        | ThunderX Core   | #27456          | CAVIUM_ERRATUM_27456     |
> +| Cavium        | ThunderX SMMUv2 | #27704          | N/A                      |
> +|               |                 |                 |                          |
> +| Freescale/NXP | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585      |
> +| Qualcomm      | Falkor v1       | E1003           | QCOM_FALKOR_ERRATUM_1003 |

Looks like you've made an unrelated whitespace change that affected the entire table,
not just the line you're adding.

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
  2016-12-29 23:02   ` Timur Tabi
@ 2016-12-29 23:08   ` Timur Tabi
  2017-01-06 15:44     ` Christopher Covington
  2016-12-30  2:44   ` kbuild test robot
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Timur Tabi @ 2016-12-29 23:08 UTC (permalink / raw)
  To: Christopher Covington, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd,
	Jonathan Corbet, linux-doc

On 12/29/2016 04:43 PM, Christopher Covington wrote:
> +config QCOM_FALKOR_E1003_RESERVED_ASID
> +	int
> +	default 1
> +	depends on QCOM_FALKOR_ERRATUM_1003

Also, since this can't be changed via the menu, why bother putting it in?

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
  2016-12-29 23:02   ` Timur Tabi
  2016-12-29 23:08   ` Timur Tabi
@ 2016-12-30  2:44   ` kbuild test robot
  2017-01-03 15:55   ` Mark Rutland
  2017-01-04 10:33   ` Christoffer Dall
  4 siblings, 0 replies; 19+ messages in thread
From: kbuild test robot @ 2016-12-30  2:44 UTC (permalink / raw)
  To: Christopher Covington
  Cc: kbuild-all, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc, Christopher Covington

[-- Attachment #1: Type: text/plain, Size: 2188 bytes --]

Hi Shanker,

[auto build test ERROR on next-20161224]
[also build test ERROR on v4.10-rc1]
[cannot apply to arm64/for-next/core v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Christopher-Covington/arm64-Define-Falkor-v1-CPU/20161230-081412
config: arm64-allnoconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm64 

All errors (new ones prefixed by >>):

   arch/arm64/mm/context.c: In function 'flush_context':
>> arch/arm64/mm/context.c:93:13: error: 'CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID' undeclared (first use in this function)
      __set_bit(CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID, asid_map);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/mm/context.c:93:13: note: each undeclared identifier is reported only once for each function it appears in
   arch/arm64/mm/context.c: In function 'asids_init':
   arch/arm64/mm/context.c:255:13: error: 'CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID' undeclared (first use in this function)
      __set_bit(CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID, asid_map);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID +93 arch/arm64/mm/context.c

    87		/* Update the list of reserved ASIDs and the ASID bitmap. */
    88		bitmap_clear(asid_map, 0, NUM_USER_ASIDS);
    89	
    90		/* Reserve ASID for Falkor erratum 1003 */
    91		if (IS_ENABLED(CONFIG_QCOM_FALKOR_ERRATUM_1003) &&
    92		    cpus_have_cap(ARM64_WORKAROUND_QCOM_FALKOR_E1003))
  > 93			__set_bit(CONFIG_QCOM_FALKOR_E1003_RESERVED_ASID, asid_map);
    94	
    95		/*
    96		 * Ensure the generation bump is observed before we xchg the

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6340 bytes --]

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
                     ` (2 preceding siblings ...)
  2016-12-30  2:44   ` kbuild test robot
@ 2017-01-03 15:55   ` Mark Rutland
  2017-01-06 15:49     ` Christopher Covington
  2017-01-04 10:33   ` Christoffer Dall
  4 siblings, 1 reply; 19+ messages in thread
From: Mark Rutland @ 2017-01-03 15:55 UTC (permalink / raw)
  To: Christopher Covington
  Cc: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc

Hi,

On Thu, Dec 29, 2016 at 05:43:32PM -0500, Christopher Covington wrote:
> +config QCOM_FALKOR_E1003_RESERVED_ASID
> +	int
> +	default 1
> +	depends on QCOM_FALKOR_ERRATUM_1003
> +

I don't think this needs to be configurable, so let's drop this into a
header, e.g. drop:

#define FALKOR_RESERVED_ASID	1

... in <asm/mmu_context.h>, protecting the rest with an ifndef
__ASSEMBLY__ guard.

[...]

> +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
> +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003
> +	mrs     x2, ttbr0_el1                   // get cuurent TTBR0_EL1
> +	mov     x3, #CONFIG_QCOM_FALKOR_ERRATUM_1003	// reserved ASID

Wrong macro? That's not the ASID.

Thanks,
Mark.

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

* Re: [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code
  2016-12-29 22:43 ` [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code Christopher Covington
@ 2017-01-03 15:57   ` Mark Rutland
  2017-01-06 15:51     ` Christopher Covington
  0 siblings, 1 reply; 19+ messages in thread
From: Mark Rutland @ 2017-01-03 15:57 UTC (permalink / raw)
  To: Christopher Covington
  Cc: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur

On Thu, Dec 29, 2016 at 05:43:34PM -0500, Christopher Covington wrote:
> Refactor the KVM code to use the newly introduced __tlbi_dsb macros, which
> will allow an errata workaround that repeats tlbi dsb sequences to only
> change one location. This is not intended to change the generated assembly
> and comparing before and after vmlinux objdump shows no functional changes.

> @@ -40,9 +41,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
>  	 * complete (S1 + S2) walk based on the old Stage-2 mapping if
>  	 * the Stage-1 invalidation happened first.
>  	 */
> -	dsb(ish);

Looks like this got accidentally removed. AFAICT it is still necessary.

> -	asm volatile("tlbi vmalle1is" : : );
> -	dsb(ish);
> +	__tlbi_dsb(vmalle1is, ish);
>  	isb();

Thanks,
Mark.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
                     ` (3 preceding siblings ...)
  2017-01-03 15:55   ` Mark Rutland
@ 2017-01-04 10:33   ` Christoffer Dall
  2017-01-11 13:11     ` Christopher Covington
  4 siblings, 1 reply; 19+ messages in thread
From: Christoffer Dall @ 2017-01-04 10:33 UTC (permalink / raw)
  To: Christopher Covington
  Cc: Paolo Bonzini, Radim Krčmář,
	Marc Zyngier, Catalin Marinas, Will Deacon, kvm,
	linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc

On Thu, Dec 29, 2016 at 05:43:32PM -0500, Christopher Covington wrote:
> From: Shanker Donthineni <shankerd@codeaurora.org>
> 
> On the Qualcomm Datacenter Technologies Falkor v1 CPU, memory accesses may
> allocate TLB entries using an incorrect ASID when TTBRx_EL1 is being
> updated. Changing the TTBRx_EL1[ASID] and TTBRx_EL1[BADDR] fields
> separately using a reserved ASID will ensure that there are no TLB entries
> with incorrect ASID after changing the the ASID.

When we restore guest state in KVM, we completely save and restore
TTBRx_EL1 from EL2. Would that be affected by this erratum?

Thanks,
-Christoffer

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 23:02   ` Timur Tabi
@ 2017-01-06 15:39     ` Christopher Covington
  2017-01-06 15:51       ` Timur Tabi
  0 siblings, 1 reply; 19+ messages in thread
From: Christopher Covington @ 2017-01-06 15:39 UTC (permalink / raw)
  To: Timur Tabi, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd,
	Jonathan Corbet, linux-doc

On 12/29/2016 06:02 PM, Timur Tabi wrote:
> On 12/29/2016 04:43 PM, Christopher Covington wrote:
>> -| Implementor    | Component       | Erratum ID      | Kconfig                 |
>> -+----------------+-----------------+-----------------+-------------------------+
>> -| ARM            | Cortex-A53      | #826319         | ARM64_ERRATUM_826319    |
>> -| ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
>> -| ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
>> -| ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
>> -| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
>> -| ARM            | Cortex-A53      | #843419         | ARM64_ERRATUM_843419    |
>> -| ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
>> -| ARM            | Cortex-A57      | #852523         | N/A                     |
>> -| ARM            | Cortex-A57      | #834220         | ARM64_ERRATUM_834220    |
>> -| ARM            | Cortex-A72      | #853709         | N/A                     |
>> -| ARM            | MMU-500         | #841119,#826419 | N/A                     |
>> -|                |                 |                 |                         |
>> -| Cavium         | ThunderX ITS    | #22375, #24313  | CAVIUM_ERRATUM_22375    |
>> -| Cavium         | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144    |
>> -| Cavium         | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154    |
>> -| Cavium         | ThunderX Core   | #27456          | CAVIUM_ERRATUM_27456    |
>> -| Cavium         | ThunderX SMMUv2 | #27704          | N/A               |
>> -|                |                 |                 |                         |
>> -| Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585     |
>> +| Implementor   | Component       | Erratum ID      | Kconfig                  |
>> ++---------------+-----------------+-----------------+--------------------------+
>> +| ARM           | Cortex-A53      | #826319         | ARM64_ERRATUM_826319     |
>> +| ARM           | Cortex-A53      | #827319         | ARM64_ERRATUM_827319     |
>> +| ARM           | Cortex-A53      | #824069         | ARM64_ERRATUM_824069     |
>> +| ARM           | Cortex-A53      | #819472         | ARM64_ERRATUM_819472     |
>> +| ARM           | Cortex-A53      | #845719         | ARM64_ERRATUM_845719     |
>> +| ARM           | Cortex-A53      | #843419         | ARM64_ERRATUM_843419     |
>> +| ARM           | Cortex-A57      | #832075         | ARM64_ERRATUM_832075     |
>> +| ARM           | Cortex-A57      | #852523         | N/A                      |
>> +| ARM           | Cortex-A57      | #834220         | ARM64_ERRATUM_834220     |
>> +| ARM           | Cortex-A72      | #853709         | N/A                      |
>> +| ARM           | MMU-500         | #841119,#826419 | N/A                      |
>> +|               |                 |                 |                          |
>> +| Cavium        | ThunderX ITS    | #22375, #24313  | CAVIUM_ERRATUM_22375     |
>> +| Cavium        | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144     |
>> +| Cavium        | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154     |
>> +| Cavium        | ThunderX Core   | #27456          | CAVIUM_ERRATUM_27456     |
>> +| Cavium        | ThunderX SMMUv2 | #27704          | N/A                      |
>> +|               |                 |                 |                          |
>> +| Freescale/NXP | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585      |
>> +| Qualcomm      | Falkor v1       | E1003           | QCOM_FALKOR_ERRATUM_1003 |
> 
> Looks like you've made an unrelated whitespace change that affected the entire table,
> not just the line you're adding.

I'm making space for "QCOM_FALKOR_ERRATUM_1003".

Cov

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code
Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2016-12-29 23:08   ` Timur Tabi
@ 2017-01-06 15:44     ` Christopher Covington
  2017-01-06 15:49       ` Timur Tabi
  0 siblings, 1 reply; 19+ messages in thread
From: Christopher Covington @ 2017-01-06 15:44 UTC (permalink / raw)
  To: Timur Tabi, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd,
	Jonathan Corbet, linux-doc

On 12/29/2016 06:08 PM, Timur Tabi wrote:
> On 12/29/2016 04:43 PM, Christopher Covington wrote:
>> +config QCOM_FALKOR_E1003_RESERVED_ASID
>> +    int
>> +    default 1
>> +    depends on QCOM_FALKOR_ERRATUM_1003
> 
> Also, since this can't be changed via the menu, why bother putting it in?

I put it in in response to review comments asking for the magic number to
be clarified by a #define or variable. I could not find a suitably shared
header between the files in question, so I used the Kconfig machinery to
generate the #define.

Cov

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code
Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2017-01-06 15:44     ` Christopher Covington
@ 2017-01-06 15:49       ` Timur Tabi
  0 siblings, 0 replies; 19+ messages in thread
From: Timur Tabi @ 2017-01-06 15:49 UTC (permalink / raw)
  To: Christopher Covington, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd,
	Jonathan Corbet, linux-doc

Christopher Covington wrote:
>> > Also, since this can't be changed via the menu, why bother putting it in?
> I put it in in response to review comments asking for the magic number to
> be clarified by a #define or variable. I could not find a suitably shared
> header between the files in question, so I used the Kconfig machinery to
> generate the #define.

I don't think that's the right approach.  Kconfigs are not an 
alternative to header files.  Is the ASID configurable?  If you just put 
some text after the "int" then it because a menu option that the user 
can select and change.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2017-01-03 15:55   ` Mark Rutland
@ 2017-01-06 15:49     ` Christopher Covington
  0 siblings, 0 replies; 19+ messages in thread
From: Christopher Covington @ 2017-01-06 15:49 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc

On 01/03/2017 10:55 AM, Mark Rutland wrote:
> Hi,
> 
> On Thu, Dec 29, 2016 at 05:43:32PM -0500, Christopher Covington wrote:
>> +config QCOM_FALKOR_E1003_RESERVED_ASID
>> +	int
>> +	default 1
>> +	depends on QCOM_FALKOR_ERRATUM_1003
>> +
> 
> I don't think this needs to be configurable, so let's drop this into a
> header, e.g. drop:
> 
> #define FALKOR_RESERVED_ASID	1
> 
> ... in <asm/mmu_context.h>, protecting the rest with an ifndef
> __ASSEMBLY__ guard.

Will do, thanks for the concrete suggestion.

> [...]
> 
>> +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
>> +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003
>> +	mrs     x2, ttbr0_el1                   // get cuurent TTBR0_EL1
>> +	mov     x3, #CONFIG_QCOM_FALKOR_ERRATUM_1003	// reserved ASID
> 
> Wrong macro? That's not the ASID.

Oops, thanks for spotting.

Cov

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code
Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2017-01-06 15:39     ` Christopher Covington
@ 2017-01-06 15:51       ` Timur Tabi
  0 siblings, 0 replies; 19+ messages in thread
From: Timur Tabi @ 2017-01-06 15:51 UTC (permalink / raw)
  To: Christopher Covington, Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd,
	Jonathan Corbet, linux-doc

Christopher Covington wrote:
>> > Looks like you've made an unrelated whitespace change that affected the entire table,
>> > not just the line you're adding.
> I'm making space for "QCOM_FALKOR_ERRATUM_1003".

Ok, but you're also shrinking the other columns.  I think a better 
solution is to make the macro shorter. QCOM_ERRATUM_FLK1003?

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* Re: [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code
  2017-01-03 15:57   ` Mark Rutland
@ 2017-01-06 15:51     ` Christopher Covington
  2017-01-06 16:05       ` Mark Rutland
  0 siblings, 1 reply; 19+ messages in thread
From: Christopher Covington @ 2017-01-06 15:51 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur

On 01/03/2017 10:57 AM, Mark Rutland wrote:
> On Thu, Dec 29, 2016 at 05:43:34PM -0500, Christopher Covington wrote:
>> Refactor the KVM code to use the newly introduced __tlbi_dsb macros, which
>> will allow an errata workaround that repeats tlbi dsb sequences to only
>> change one location. This is not intended to change the generated assembly
>> and comparing before and after vmlinux objdump shows no functional changes.

@@ -32,7 +33,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
 	 * whole of Stage-1. Weep...
 	 */
 	ipa >>= 12;
-	asm volatile("tlbi ipas2e1is, %0" : : "r" (ipa));
+	__tlbi_dsb(ipas2e1is, ish, ipa);
 
 	/*
 	 * We have to ensure completion of the invalidation at Stage-2,

>> @@ -40,9 +41,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
>>  	 * complete (S1 + S2) walk based on the old Stage-2 mapping if
>>  	 * the Stage-1 invalidation happened first.
>>  	 */
>> -	dsb(ish);
> 
> Looks like this got accidentally removed. AFAICT it is still necessary.

Not removed, just hoisted above the comment block to the previous patch hunk.

>> -	asm volatile("tlbi vmalle1is" : : );
>> -	dsb(ish);
>> +	__tlbi_dsb(vmalle1is, ish);
>>  	isb();

Thanks,
Cov

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code
Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code
  2017-01-06 15:51     ` Christopher Covington
@ 2017-01-06 16:05       ` Mark Rutland
  0 siblings, 0 replies; 19+ messages in thread
From: Mark Rutland @ 2017-01-06 16:05 UTC (permalink / raw)
  To: Christopher Covington
  Cc: Paolo Bonzini, Radim Krčmář,
	Christoffer Dall, Marc Zyngier, Catalin Marinas, Will Deacon,
	kvm, linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur

On Fri, Jan 06, 2017 at 10:51:53AM -0500, Christopher Covington wrote:
> On 01/03/2017 10:57 AM, Mark Rutland wrote:
> > On Thu, Dec 29, 2016 at 05:43:34PM -0500, Christopher Covington wrote:
> >> Refactor the KVM code to use the newly introduced __tlbi_dsb macros, which
> >> will allow an errata workaround that repeats tlbi dsb sequences to only
> >> change one location. This is not intended to change the generated assembly
> >> and comparing before and after vmlinux objdump shows no functional changes.
> 
> @@ -32,7 +33,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
>  	 * whole of Stage-1. Weep...
>  	 */
>  	ipa >>= 12;
> -	asm volatile("tlbi ipas2e1is, %0" : : "r" (ipa));
> +	__tlbi_dsb(ipas2e1is, ish, ipa);
>  
>  	/*
>  	 * We have to ensure completion of the invalidation at Stage-2,
> 
> >> @@ -40,9 +41,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
> >>  	 * complete (S1 + S2) walk based on the old Stage-2 mapping if
> >>  	 * the Stage-1 invalidation happened first.
> >>  	 */
> >> -	dsb(ish);
> > 
> > Looks like this got accidentally removed. AFAICT it is still necessary.
> 
> Not removed, just hoisted above the comment block to the previous patch hunk.

Ah, sorry. I hadn't spotted that it got folded into the __tlbi_dsb()
above.

Given the comment was previously attached to the DSB, it might make more
sense to fold it into the prior comment block, so that it remains
attached to the __tlbi_dsb(), which guarantees the completion that the
comment describes.

Thanks,
Mark.

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

* Re: [PATCH v2 2/5] arm64: Work around Falkor erratum 1003
  2017-01-04 10:33   ` Christoffer Dall
@ 2017-01-11 13:11     ` Christopher Covington
  0 siblings, 0 replies; 19+ messages in thread
From: Christopher Covington @ 2017-01-11 13:11 UTC (permalink / raw)
  To: Christoffer Dall
  Cc: Paolo Bonzini, Radim Krčmář,
	Marc Zyngier, Catalin Marinas, Will Deacon, kvm,
	linux-arm-kernel, kvmarm, linux-kernel, shankerd, timur,
	Jonathan Corbet, linux-doc

Hi Christoffer,

On 01/04/2017 05:33 AM, Christoffer Dall wrote:
> On Thu, Dec 29, 2016 at 05:43:32PM -0500, Christopher Covington wrote:
>> From: Shanker Donthineni <shankerd@codeaurora.org>
>>
>> On the Qualcomm Datacenter Technologies Falkor v1 CPU, memory accesses may
>> allocate TLB entries using an incorrect ASID when TTBRx_EL1 is being
>> updated. Changing the TTBRx_EL1[ASID] and TTBRx_EL1[BADDR] fields
>> separately using a reserved ASID will ensure that there are no TLB entries
>> with incorrect ASID after changing the the ASID.
> 
> When we restore guest state in KVM, we completely save and restore
> TTBRx_EL1 from EL2. Would that be affected by this erratum?

Good question, but apparently not. I'll add the following explanation to the
v3 commit message.

"EL2 and EL3 code changing the EL1&0 ASID is not subject to this erratum
because hardware is prohibited from performing translations from an
out-of-context translation regime."

Thanks,
Cov

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code
Aurora Forum, a Linux Foundation Collaborative Project.

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

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

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-29 22:43 [PATCH v2 1/5] arm64: Define Falkor v1 CPU Christopher Covington
2016-12-29 22:43 ` [PATCH v2 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
2016-12-29 23:02   ` Timur Tabi
2017-01-06 15:39     ` Christopher Covington
2017-01-06 15:51       ` Timur Tabi
2016-12-29 23:08   ` Timur Tabi
2017-01-06 15:44     ` Christopher Covington
2017-01-06 15:49       ` Timur Tabi
2016-12-30  2:44   ` kbuild test robot
2017-01-03 15:55   ` Mark Rutland
2017-01-06 15:49     ` Christopher Covington
2017-01-04 10:33   ` Christoffer Dall
2017-01-11 13:11     ` Christopher Covington
2016-12-29 22:43 ` [PATCH v2 3/5] arm64: Create and use __tlbi_dsb() macros Christopher Covington
2016-12-29 22:43 ` [PATCH v2 4/5] arm64: Use __tlbi_dsb() macros in KVM code Christopher Covington
2017-01-03 15:57   ` Mark Rutland
2017-01-06 15:51     ` Christopher Covington
2017-01-06 16:05       ` Mark Rutland
2016-12-29 22:43 ` [PATCH v2 5/5] arm64: Work around Falkor erratum 1009 Christopher Covington

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