Skip to contentSkip to conversation

ARM64 MM Random Cleanups

PATCH New Anshuman Khandual 2 participants 7 messages Sep 22, 2018 – Oct 1, 2018 arm64

lore
Share & tools
lore
#0 lore raw

cover ARM64 MM Random Cleanups

This just contains some unrelated cleanup patches on memory.

Anshuman Khandual (5):
arm64/mm: Use ESR_ELx_FSC macro while decoding fault exception arm64/mm: Reorganize arguments for is_el1_permission_fault() arm64/mm: Define esr_to_debug_fault_info() arm64/numa: Report correct memblock range for the dummy node arm64/numa: Unify common error path in numa_init()

 arch/arm64/mm/fault.c | 19 ++++++++++++-------
 arch/arm64/mm/numa.c  | 13 ++++++++-----
 2 files changed, 20 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 arm64/mm: Use ESR_ELx_FSC macro while decoding fault exception

Just replace hard code value of 63 (0x111111) with an existing macro ESR_ELx_FSC when parsing for the status code during fault exception.

---
 arch/arm64/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/fault.c +1 -1
index 50b30ff..75b8794 100644
@@ -59,7 +59,7 @@ static const struct fault_info fault_info[];
 
 static inline const struct fault_info *esr_to_fault_info(unsigned int esr)
 {
-	return fault_info + (esr & 63);
+	return fault_info + (esr & ESR_ELx_FSC);
 }
 
 #ifdef CONFIG_KPROBES
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 arm64/mm: Reorganize arguments for is_el1_permission_fault()

In reply to Anshuman Khandual

Most memory abort exception handling related functions have the arguments in the order (addr, esr, regs) except is_el1_permission_fault(). This changes the argument order in this function as (addr, esr, regs) like others.

---
 arch/arm64/mm/fault.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/arm64/mm/fault.c +4 -5
index 75b8794..30e040c 100644
@@ -235,9 +235,8 @@ static bool is_el1_instruction_abort(unsigned int esr)
 	return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR;
 }
 
-static inline bool is_el1_permission_fault(unsigned int esr,
-					   struct pt_regs *regs,
-					   unsigned long addr)
+static inline bool is_el1_permission_fault(unsigned long addr, unsigned int esr,
+					   struct pt_regs *regs)
 {
 	unsigned int ec       = ESR_ELx_EC(esr);
 	unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE;
@@ -283,7 +282,7 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr,
 	if (!is_el1_instruction_abort(esr) && fixup_exception(regs))
 		return;
 
-	if (is_el1_permission_fault(esr, regs, addr)) {
+	if (is_el1_permission_fault(addr, esr, regs)) {
 		if (esr & ESR_ELx_WNR)
 			msg = "write to read-only memory";
 		else
@@ -454,7 +453,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
 		mm_flags |= FAULT_FLAG_WRITE;
 	}
 
-	if (addr < TASK_SIZE && is_el1_permission_fault(esr, regs, addr)) {
+	if (addr < TASK_SIZE && is_el1_permission_fault(addr, esr, regs)) {
 		/* regs->orig_addr_limit may be 0 if we entered from EL0 */
 		if (regs->orig_addr_limit == KERNEL_DS)
 			die_kernel_fault("access to user memory with fs=KERNEL_DS",
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 arm64/mm: Define esr_to_debug_fault_info()

In reply to Anshuman Khandual

fault_info[] and debug_fault_info[] are static arrays defining memory abort exception handling functions looking into ESR fault status code encodings. As esr_to_fault_info() is already available providing fault_info[] array lookup, it really makes sense to have a corresponding debug_fault_info[] array lookup function as well. This just adds an equivalent helper function esr_to_debug_fault_info().

---
 arch/arm64/mm/fault.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm64/mm/fault.c +7 -1
index 30e040c..9c64f93 100644
@@ -56,12 +56,18 @@ struct fault_info {
 };
 
 static const struct fault_info fault_info[];
+static struct fault_info debug_fault_info[];
 
 static inline const struct fault_info *esr_to_fault_info(unsigned int esr)
 {
 	return fault_info + (esr & ESR_ELx_FSC);
 }
 
+static inline const struct fault_info *esr_to_debug_fault_info(unsigned int esr)
+{
+	return debug_fault_info + DBG_ESR_EVT(esr);
+}
+
 #ifdef CONFIG_KPROBES
 static inline int notify_page_fault(struct pt_regs *regs, unsigned int esr)
 {
@@ -830,7 +836,7 @@ asmlinkage int __exception do_debug_exception(unsigned long addr,
 					      unsigned int esr,
 					      struct pt_regs *regs)
 {
-	const struct fault_info *inf = debug_fault_info + DBG_ESR_EVT(esr);
+	const struct fault_info *inf = esr_to_debug_fault_info(esr);
 	int rv;
 
 	/*
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/5 arm64/numa: Report correct memblock range for the dummy node

In reply to Anshuman Khandual

The dummy node ID is marked into all memory ranges on the system. So the dummy node really extends the entire memblock.memory. Hence report correct extent information for the dummy node using memblock range helper functions instead of the range [0LLU, PFN_PHYS(max_pfn) - 1)].

Fixes 1a2db30034 ("arm64, numa: Add NUMA support for arm64 platforms")
---
 arch/arm64/mm/numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/numa.c +1 -1
index 146c04c..54529b4 100644
@@ -432,7 +432,7 @@ static int __init dummy_numa_init(void)
 	if (numa_off)
 		pr_info("NUMA disabled\n"); /* Forced off on command line. */
 	pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n",
-		0LLU, PFN_PHYS(max_pfn) - 1);
+		memblock_start_of_DRAM(), memblock_end_of_DRAM() - 1);
 
 	for_each_memblock(memory, mblk) {
 		ret = numa_add_memblk(0, mblk->base, mblk->base + mblk->size);
Signature · 1 line
2.7.4
#5 lore raw

PATCH 5/5 arm64/numa: Unify common error path in numa_init()

In reply to Anshuman Khandual

At present numa_free_distance() is being called before numa_distance is even initialized with numa_alloc_distance() which is really pointless. Instead lets call numa_free_distance() on the common error path inside numa_init() after numa_alloc_distance() has been successful.

Fixes 1a2db30034 ("arm64, numa: Add NUMA support for arm64 platforms")
---
 arch/arm64/mm/numa.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/arm64/mm/numa.c +7 -4
index 54529b4..d7b66fc 100644
@@ -391,7 +391,6 @@ static int __init numa_init(int (*init_func)(void))
 	nodes_clear(numa_nodes_parsed);
 	nodes_clear(node_possible_map);
 	nodes_clear(node_online_map);
-	numa_free_distance();
 
 	ret = numa_alloc_distance();
 	if (ret < 0)
@@ -399,20 +398,24 @@ static int __init numa_init(int (*init_func)(void))
 
 	ret = init_func();
 	if (ret < 0)
-		return ret;
+		goto out_free_distance;
 
 	if (nodes_empty(numa_nodes_parsed)) {
 		pr_info("No NUMA configuration found\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out_free_distance;
 	}
 
 	ret = numa_register_nodes();
 	if (ret < 0)
-		return ret;
+		goto out_free_distance;
 
 	setup_node_to_cpumask_map();
 
 	return 0;
+out_free_distance:
+	numa_free_distance();
+	return ret;
 }
 
 /**
Signature · 1 line
2.7.4
maintainer Applied
#6 lore raw

cover ARM64 MM Random Cleanups

In reply to Anshuman Khandual
Quoted 8 lines · Anshuman Khandual

This just contains some unrelated cleanup patches on memory.

Anshuman Khandual (5):
arm64/mm: Use ESR_ELx_FSC macro while decoding fault exception arm64/mm: Reorganize arguments for is_el1_permission_fault() arm64/mm: Define esr_to_debug_fault_info() arm64/numa: Report correct memblock range for the dummy node arm64/numa: Unify common error path in numa_init()

Queued for 4.20. Thanks.

Signature · 1 line
Catalin