Skip to contentSkip to conversation

um: Minor pgtable fixes

PATCH New Tiwei Bie 1 participant 3 messages Mar 2

Subsystems (3)
lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

cover um: Minor pgtable fixes

Tiwei Bie (2):
um: Fix potential race condition in TLB sync
um: Fix pte_read() and pte_exec() for kernel mappings

 arch/um/include/asm/pgtable.h | 9 ++++-----
 arch/um/kernel/tlb.c          | 4 ++--
 mm/Kconfig                    | 1 +
 3 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 um: Fix potential race condition in TLB sync

During the TLB sync, we need to traverse and modify the page table, so we should hold the page table lock. Since full SMP support for threads within the same process is still missing, let's disable the split page table lock for simplicity.

Fixes 1e4ee5135d81 ("um: Add initial SMP support")
---
 arch/um/kernel/tlb.c | 1 +
 mm/Kconfig           | 1 +
 2 files changed, 2 insertions(+)
arch/um/kernel/tlb.c +1 -0
index 39608cccf2c6..5386ab2d0da5 100644
@@ -165,6 +165,7 @@ int um_tlb_sync(struct mm_struct *mm)
 	unsigned long addr, next;
 	int ret = 0;
 
+	guard(spinlock_irqsave)(&mm->page_table_lock);
 	guard(spinlock_irqsave)(&mm->context.sync_tlb_lock);
 
 	if (mm->context.sync_tlb_range_to == 0)
mm/Kconfig +1 -0
index ebd8ea353687..befa8909ae29 100644
@@ -572,6 +572,7 @@ config SPLIT_PTE_PTLOCKS
 	depends on !ARM || CPU_CACHE_VIPT
 	depends on !PARISC || PA20
 	depends on !SPARC32
+	depends on !UML
 
 config ARCH_ENABLE_SPLIT_PMD_PTLOCK
 	bool
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 um: Fix pte_read() and pte_exec() for kernel mappings

In reply to Tiwei Bie

The pte_read() and pte_exec() helpers are only used during the TLB sync to determine the read/exec permissions for mmap. However, for kernel mappings, they will always return 0. This leads to kern_map() having to unconditionally set the exec flag to 1 and the read flag unexpectedly always being 0. Remove the unnecessary check for the _PAGE_USER bit in these helpers to ensure that the kernel mapping permissions can be correctly determined.

---
 arch/um/include/asm/pgtable.h | 9 ++++-----
 arch/um/kernel/tlb.c          | 3 +--
 2 files changed, 5 insertions(+), 7 deletions(-)
arch/um/include/asm/pgtable.h +4 -5
index 3b42b0f45bf6..e156ef6f4fdb 100644
@@ -121,13 +121,12 @@ static inline int pte_none(pte_t pte)
  */
 static inline int pte_read(pte_t pte)
 {
-	return((pte_get_bits(pte, _PAGE_USER)) &&
-	       !(pte_get_bits(pte, _PAGE_PROTNONE)));
+	return !pte_get_bits(pte, _PAGE_PROTNONE);
 }
 
-static inline int pte_exec(pte_t pte){
-	return((pte_get_bits(pte, _PAGE_USER)) &&
-	       !(pte_get_bits(pte, _PAGE_PROTNONE)));
+static inline int pte_exec(pte_t pte)
+{
+	return !pte_get_bits(pte, _PAGE_PROTNONE);
 }
 
 static inline int pte_write(pte_t pte)
arch/um/kernel/tlb.c +1 -2
index 5386ab2d0da5..1f175716b474 100644
@@ -29,10 +29,9 @@ static int kern_map(struct mm_id *mm_idp,
 		    unsigned long virt, unsigned long len, int prot,
 		    int phys_fd, unsigned long long offset)
 {
-	/* TODO: Why is executable needed to be always set in the kernel? */
 	return os_map_memory((void *)virt, phys_fd, offset, len,
 			     prot & UM_PROT_READ, prot & UM_PROT_WRITE,
-			     1);
+			     prot & UM_PROT_EXEC);
 }
 
 static int kern_unmap(struct mm_id *mm_idp,
Signature · 1 line
2.34.1