mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

When pointer masking is enabled for userspace, the kernel can accept tagged pointers as arguments to some system calls. Allow this by untagging the pointers in access_ok() and the uaccess routines. The uaccess routines must peform untagging in software because U-mode and S-mode have entirely separate pointer masking configurations. In fact, hardware may not even implement pointer masking for S-mode. Since the number of tag bits is variable, untagged_addr_remote() needs to know what PMLEN to use for the remote mm. Therefore, the pointer masking mode must be the same for all threads sharing an mm. Enforce this with a lock flag in the mm context, as x86 does for LAM. The flag gets reset in init_new_context() during fork(), as the new mm is no longer multithreaded. Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Charlie Jenkins <charlie@rivosinc.com> Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Link: https://lore.kernel.org/r/20241016202814.4061541-6-samuel.holland@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
* Copyright (C) 2017 SiFive
|
|
*/
|
|
|
|
#ifndef _ASM_RISCV_MMU_CONTEXT_H
|
|
#define _ASM_RISCV_MMU_CONTEXT_H
|
|
|
|
#include <linux/mm_types.h>
|
|
#include <asm-generic/mm_hooks.h>
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/sched.h>
|
|
|
|
void switch_mm(struct mm_struct *prev, struct mm_struct *next,
|
|
struct task_struct *task);
|
|
|
|
#define activate_mm activate_mm
|
|
static inline void activate_mm(struct mm_struct *prev,
|
|
struct mm_struct *next)
|
|
{
|
|
#ifdef CONFIG_RISCV_ISA_SUPM
|
|
next->context.pmlen = 0;
|
|
#endif
|
|
switch_mm(prev, next, NULL);
|
|
}
|
|
|
|
#define init_new_context init_new_context
|
|
static inline int init_new_context(struct task_struct *tsk,
|
|
struct mm_struct *mm)
|
|
{
|
|
#ifdef CONFIG_MMU
|
|
atomic_long_set(&mm->context.id, 0);
|
|
#endif
|
|
if (IS_ENABLED(CONFIG_RISCV_ISA_SUPM))
|
|
clear_bit(MM_CONTEXT_LOCK_PMLEN, &mm->context.flags);
|
|
return 0;
|
|
}
|
|
|
|
DECLARE_STATIC_KEY_FALSE(use_asid_allocator);
|
|
|
|
#ifdef CONFIG_RISCV_ISA_SUPM
|
|
#define mm_untag_mask mm_untag_mask
|
|
static inline unsigned long mm_untag_mask(struct mm_struct *mm)
|
|
{
|
|
return -1UL >> mm->context.pmlen;
|
|
}
|
|
#endif
|
|
|
|
#include <asm-generic/mmu_context.h>
|
|
|
|
#endif /* _ASM_RISCV_MMU_CONTEXT_H */
|