From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796378978; b=GOZ5bkqaHrSbQRMRqNRjrFsAh7LYmPeE0hEzeDVzpVWDjNlwsIATtof6Vh5siRUyp+pU QcGiMMXNQ/xCGnKYncykW09c+rOEJUITR7HKOp2O/fh+QIDk8TXs9kO/Q+ivV6AEnQyjx hXQsWFD4FUDLt5ZsV35x6zkDrP7OA3DTqXBEql0fXntd2kTZwLLzeueIUsSEdjkY7qzyI 5fNYwu8/FSTdPUA3yqWLudJtyUOXZMN6q81qNBl5S1LYnngrbCDjZgklFfHH4pmRFtq9X vxuYixOcnYNatzFMLhPuM4LVuMxQoILxCD8SX+XMdc4KwJjtlQ6SZMnbk8iaNmPlyiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796378978; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=arFeq5olFKG1QZueVG4cBqwNVKf2XvXGu366c1xBUgs=; b=M8/+vRcEriRan/c1i2Vpwx4FBnaq+To5KOvPV9V4oUQXeKb5tyS6HYeq0cH19YwSg+o8 U5QgGKypJTES+iYi/wEQQ9np+WqiuFzUIReFKNgunzz9KBMrEk1Pn7NBxSheroDsn//eB PmVh6UT3XhvCVwEabWsCIxMQVERhn5D62nKuxIs7MLRDzoDnx9xLzhJEcNWOJtC3D8OnA YsgBwxSt2xBNfXCFSAvgnQUKIh8QY0Y8o3008T9Ril+91+2KhDCyDnJG1VfTr0VRJ/QKp 54e9xkPeb9y3+AcX7Uo46phAeaHPqfAnVd5yZ99y6GOKnqS9hSD5D7gdTs6AoGefEUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=StFGlGH3; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56327606A684 for ; Fri, 4 Dec 2026 10:09:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 56327606A684 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=StFGlGH3 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so7065005e9.2 for ; Fri, 04 Dec 2026 02:09:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796378977; x=1796983777; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=arFeq5olFKG1QZueVG4cBqwNVKf2XvXGu366c1xBUgs=; b=StFGlGH3JQf/CXoq8uhecDF/ayiA0Of9wxqnz0n4IimDaP05YKPpuN7SCCX2a8h88A RTVs8eU+pFif7t/XO/r4wdv5t8CVvtyUta8Yy0zFUphCvheZe1EYy+D+TCtZcC2/HV9l VXZAGa7Fj9MG3vSnmjE286nwMYl/0xAoJfGkp5JlsdBrLzQK73bKmLSqjzChXMHcmZAg fbneTrOivuRU2L5opRrvFZdj82ZTdS9dBZMnSjcBDNstQzSV+1UIfjz3jO47IXm4yAzP N2CFlx0nPgEmH1pGcq9Nelr1jEJwpuJOoS8LVkDCodXIpE6c9irQFqs5ht/tsLc9mlFF 4yTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796378977; x=1796983777; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=arFeq5olFKG1QZueVG4cBqwNVKf2XvXGu366c1xBUgs=; b=BNw205fkvc6ztJgx/+NeSGWIYFpyDp2gQh/TSecok6SxbOb6SHlTCXhn2/VtkoKilX AASWvPluUzIdditCiYjb/f5SS54TUHv6LCopJJuuvCVOYExwG2cMyylm+6L8wzBlVCdR WlhSuqwfBQ60+DtIxv4klPPnIZ5yaRYQvk8O4OKctSlMgFuk3amSOn5wf18r6G3vWY58 saWUo8OBEYo1PNWJYoZ5N0WjcBL2H+xTP0xRBc6TnRjlh0exwkSnv9pIDbB6w7gr6aI7 P+I7i4PSZjHR8vwVFJjJbY9ernj0Sl6tddXE/z12WgI3HiTBYO9FB/FcrV0eeht5qB3r qtHQ== X-Forwarded-Encrypted: i=1; AL+hErEtzTVcehkt/Zb+XLhTBVWf5R6vNMze+XVyXQgfKof+3bJ8CxIooc3rCMJ4+dsKckbFJsZFJtkfZmB149Y=@vger.kernel.org X-Gm-Message-State: APuU4Z9ie2axsnpWSevTGZIi8/4yl2fhYaimyQoOsPPRi3j4XdnXgouZ aIQZpNQYCSs7Ldjinu+JfIQ974EpRQreWGTt1db/VvrORICC2Vt/rUdI X-Gm-Gg: AZFdTZevg1ZxbznSt/dKYQbz/B8ZIEw8+9EiF8a8su2hCtPOu9K4jYaLsh9bE27GC2+ OwA/M5yk6CQJRd/HQUQVLL2VGskagpQRfspluZ9shbh0o0kQMeJg/iK5WcUHeX+G0OVsVtuMpLC 5WygDIu8uzNgAV8EDUq5yYq3d6kt+1GC0AQ/Zxlqb9VkjXvq2Df1ZoyQNL4uSD0m81lNnmwMV8S nNTQEHgamY9wB280TEkBUalCwFjIvnH4ue0ktvJZw5F3tr5ogUl/5VoFLmAef6HYehVtpBNKcNL y0YW3LwIO36VJy0lmMse20kctefIWVJE3umkFKg05vKKnaZrS585fHTpET9VcUCdJDGguaTO3CT b9Vx+CFp1yx6RrcsSPbsuTpsLLXe3GOxJHWcv7s4NxOF/6go2mlklGuBmv1tqx3QgLcKWAOfhLz bc2RREp8Z22MR1gISqbyd7iVrgiGmTO0rAj3OLfxh0UtZQ5tXwcEonhCO2Cwrq12eanHg08xy4g Ai2evQZ6dEMa4dTXgsYmDuv0lHKpHOBgcpC//nSpZXjAiYi2wo9iotpQzDmKvVzviRAsgEufrqi B00SPdKB3VR3MbqtNlcyTiX1fs+tf66jDX895NVreX1Tw8pQ6M6JE2lAy/z7tW8a X-Received: by 2002:a05:600c:8b34:b0:4bb:8143:e182 with SMTP id 5b1f17b1804b1-4bbeb8512c9mr26276195e9.5.1796378976571; Fri, 04 Dec 2026 02:09:36 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea285a26sm40630425e9.7.2026.12.04.02.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 02:09:36 -0800 (PST) Date: Fri, 4 Dec 2026 10:09:34 +0000 From: David Laight To: Yunhui Cui Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, dennis@kernel.org, tj@kernel.org, cl@gentwo.org, oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, bjorn@kernel.org, pulehui@huawei.com, puranjay@kernel.org, broonie@kernel.org, dave@stgolabs.net, jszhang@kernel.org, tglx@kernel.org, conor.dooley@microchip.com, thuth@redhat.com, ajones@ventanamicro.com, ben.dooks@codethink.co.uk, rkrcmar@ventanamicro.com, samuel.holland@sifive.com, zong.li@sifive.com, debug@rivosinc.com, seanwascoding@gmail.com, andybnac@gmail.com, menglong8.dong@gmail.com, cyrilbur@tenstorrent.com, wangruikang@iscas.ac.cn, atishp@rivosinc.com, apatel@ventanamicro.com, arnd@arndb.de, nathan@kernel.org, nick.desaulniers+lkml@gmail.com, morbo@google.com, justinstitt@google.com, qingfang.deng@siflower.com.cn, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v12 02/10] riscv: add infrastructure for preemptible this_cpu operations Message-ID: <20261204100934.41d214ff@pumpkin> In-Reply-To: <20261204085859.42277-3-cuiyunhui@bytedance.com> References: <20261204085859.42277-1-cuiyunhui@bytedance.com> <20261204085859.42277-3-cuiyunhui@bytedance.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 4 Dec 2026 16:58:50 +0800 Yunhui Cui wrote: > Generic this_cpu operations disable preemption or local interrupts to > keep per-CPU accesses on the current CPU. Provide infrastructure for > RISC-V operations to remain preemptible. > > Track the registers used for per-CPU address generation so exception > return can repair an interrupted operation after CPU migration. > > Preserve this state across exception handlers so handlers can use > per-CPU operations independently. Make the entry/exit protocol available > to NMI-like paths, including SBI Supervisor Software Events. > > Suggested-by: David Laight > Link: https://lore.kernel.org/r/20261108213254.67805ef0@pumpkin > Suggested-by: Jisheng Zhang > Link: https://lore.kernel.org/r/avG07pmpcLGkq5i-@xhacker > Signed-off-by: Yunhui Cui > --- > arch/riscv/include/asm/asm.h | 21 ++++++++++++ > arch/riscv/include/asm/percpu.h | 50 +++++++++++++++++++++++++++- > arch/riscv/include/asm/ptrace.h | 26 +++++++++++++++ > arch/riscv/include/asm/thread_info.h | 3 ++ > arch/riscv/kernel/Makefile | 6 ++++ > arch/riscv/kernel/asm-offsets.c | 4 +++ > arch/riscv/kernel/entry-common.c | 30 +++++++++++++++++ > arch/riscv/kernel/entry.S | 17 ++++++++++ > arch/riscv/mm/extable.c | 18 ---------- > 9 files changed, 156 insertions(+), 19 deletions(-) > create mode 100644 arch/riscv/kernel/entry-common.c > > diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h > index 06ac38f733b0a..6515adb29dc60 100644 > --- a/arch/riscv/include/asm/asm.h > +++ b/arch/riscv/include/asm/asm.h > @@ -81,6 +81,27 @@ > > /* Common assembly source macros */ > > +#ifdef CONFIG_SMP > +/* > + * Save and clear the active per-CPU GPR state on exception entry. Entry > + * paths which bypass handle_exception, such as SBI Supervisor Software > + * Events (SSE), must pair this with pcpu_gprs_exit around their handlers. > + */ > +.macro pcpu_gprs_entry tsk regs tmp > + lhu \tmp, TASK_TI_PCPU_GPRS(\tsk) > + REG_S \tmp, PT_PCPU_GPRS(\regs) > + sh zero, TASK_TI_PCPU_GPRS(\tsk) > +.endm > + > +/* > + * Restore the saved state before resuming the interrupted context. tmp must > + * contain PT_PCPU_GPRS from the interrupted frame. > + */ > +.macro pcpu_gprs_exit tsk tmp > + sh \tmp, TASK_TI_PCPU_GPRS(\tsk) > +.endm > +#endif > + > /* > * NOP sequence > */ > diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percpu.h > index bbb88a42b48f8..4d88c6830a7e5 100644 > --- a/arch/riscv/include/asm/percpu.h > +++ b/arch/riscv/include/asm/percpu.h > @@ -3,13 +3,61 @@ > #ifndef __ASM_PERCPU_H > #define __ASM_PERCPU_H > > +#include > +#include > #include > > +#include > #include > +#include > > #ifdef CONFIG_SMP > #define __my_cpu_offset (((struct thread_info *)current)->pcpu_offset) > -#endif > + > +#define PCPU_GPR_PCP_SHIFT 0 > +#define PCPU_GPR_PCP GENMASK(4, 0) > +#define PCPU_GPR_OFF_SHIFT 5 > +#define PCPU_GPR_OFF GENMASK(9, 5) > +#define PCPU_GPR_ADDR_SHIFT 10 > +#define PCPU_GPR_ADDR GENMASK(14, 10) > + > +#define __PCPU_GPR_NUM(gpr) ".L__gpr_num_%[" __stringify(gpr) "]" > + > +#define __PCPU_GPRS_VALUE \ > + "(" \ > + "(.L__pcpu_gpr_pcp << " __stringify(PCPU_GPR_PCP_SHIFT) ") | " \ > + "(.L__pcpu_gpr_off << " __stringify(PCPU_GPR_OFF_SHIFT) ") | " \ > + "(.L__pcpu_gpr_addr << " __stringify(PCPU_GPR_ADDR_SHIFT) ")" \ > + ")" > + > +#define __PCPU_GPRS_ASSERT_DISTINCT(pcp, off, addr) \ > + ".set .L__pcpu_gpr_pcp, " __PCPU_GPR_NUM(pcp) "\n" \ > + ".set .L__pcpu_gpr_off, " __PCPU_GPR_NUM(off) "\n" \ > + ".set .L__pcpu_gpr_addr, " __PCPU_GPR_NUM(addr) "\n" \ > + ".if ((.L__pcpu_gpr_pcp == .L__pcpu_gpr_off) || " \ > + "(.L__pcpu_gpr_pcp == .L__pcpu_gpr_addr) || " \ > + "(.L__pcpu_gpr_off == .L__pcpu_gpr_addr))\n" \ > + ".error \"PCPU GPRs overlap\"\n" \ > + ".endif\n" > + > +/* > + * Mark a region where the per-CPU offset and address registers may need to > + * be rewritten by exception return after migration. The three registers > + * must remain distinct for the whole region. > + */ > +#define __PCPU_GPRS_BEGIN(gprs, pcp, off, addr, pcpu_offset) \ > + __DEFINE_ASM_GPR_NUMS \ > + __PCPU_GPRS_ASSERT_DISTINCT(pcp, off, addr) \ > + "li %[" __stringify(off) "], " __PCPU_GPRS_VALUE "\n" \ > + "sh %[" __stringify(off) "], %[" __stringify(gprs) "]\n" \ > + REG_L " %[" __stringify(off) "], %[" __stringify(pcpu_offset) "]\n" \ > + "add %[" __stringify(addr) "], %[" __stringify(pcp) "], " \ > + "%[" __stringify(off) "]\n" > + > +#define __PCPU_GPRS_END(gprs) \ > + "sh zero, %[" __stringify(gprs) "]\n" > + > +#endif /* CONFIG_SMP */ > > #include > > diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h > index addc8188152f7..338612cb5d28d 100644 > --- a/arch/riscv/include/asm/ptrace.h > +++ b/arch/riscv/include/asm/ptrace.h > @@ -53,6 +53,10 @@ struct pt_regs { > unsigned long cause; > /* a0 value before the syscall */ > unsigned long orig_a0; > +#ifdef CONFIG_SMP > + /* Active preemptible per-CPU operation, if any. */ > + unsigned long pcpu_gprs; > +#endif > }; > > #define PTRACE_SYSEMU 0x1f > @@ -145,6 +149,28 @@ static inline unsigned long regs_get_register(struct pt_regs *regs, > return *(unsigned long *)((unsigned long)regs + offset); > } > > +static __always_inline unsigned long > +regs_get_gpr(struct pt_regs *regs, unsigned int offset) > +{ > + if (unlikely_notrace(!offset || offset > MAX_REG_OFFSET)) > + return 0; > + > + return *(unsigned long *)((unsigned long)regs + offset); > +} > + > +static __always_inline void regs_set_gpr(struct pt_regs *regs, > + unsigned int offset, unsigned long val) > +{ > + if (unlikely_notrace(!offset || offset > MAX_REG_OFFSET)) > + return; > + > + *(unsigned long *)((unsigned long)regs + offset) = val; > +} > + > +#ifdef CONFIG_SMP > +void noinstr riscv_pcpu_regs_fixup(struct pt_regs *regs); > +#endif > + > /** > * regs_get_kernel_argument() - get Nth function argument in kernel > * @regs: pt_regs of that context > diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h > index 523e95c1eedb8..4a123d40fbf4d 100644 > --- a/arch/riscv/include/asm/thread_info.h > +++ b/arch/riscv/include/asm/thread_info.h > @@ -79,6 +79,9 @@ struct thread_info { > #ifdef CONFIG_RISCV_USER_CFI > struct cfi_state user_cfi_state; > #endif > +#ifdef CONFIG_SMP > + unsigned short pcpu_gprs; > +#endif While the value is only 16 bits, making this 'short' starts looking like a 'recipe for disaster', especially since the field name is the same as 64bit fields in other structures and the local variables are 'long' not even 'int'. It isn't as though you've dropped into some padding. David > }; > > #ifdef CONFIG_SHADOW_CALL_STACK > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index f54c336bf547c..1f0639d807f1a 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -3,6 +3,11 @@ > # Makefile for the RISC-V Linux kernel > # > > +KASAN_SANITIZE_entry-common.o := n > +UBSAN_SANITIZE_entry-common.o := n > +KCOV_INSTRUMENT_entry-common.o := n > +CFLAGS_entry-common.o += -DDISABLE_BRANCH_PROFILING > + > CFLAGS_syscall_table.o += $(call cc-disable-warning, override-init) > CFLAGS_compat_syscall_table.o += $(call cc-disable-warning, override-init) > > @@ -52,6 +57,7 @@ obj-y += alternative.o > obj-y += cpu.o > obj-y += cpufeature.o > obj-y += entry.o > +obj-$(CONFIG_SMP) += entry-common.o > obj-y += irq.o > obj-y += process.o > obj-y += ptrace.o > diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c > index 50fdfe75eaf78..9cfd0ee8e6316 100644 > --- a/arch/riscv/kernel/asm-offsets.c > +++ b/arch/riscv/kernel/asm-offsets.c > @@ -40,6 +40,7 @@ void asm_offsets(void) > OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu); > #ifdef CONFIG_SMP > OFFSET(TASK_TI_PCPU_OFFSET, task_struct, thread_info.pcpu_offset); > + OFFSET(TASK_TI_PCPU_GPRS, task_struct, thread_info.pcpu_gprs); > #endif > OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count); > OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp); > @@ -132,6 +133,9 @@ void asm_offsets(void) > OFFSET(PT_STATUS, pt_regs, status); > OFFSET(PT_BADADDR, pt_regs, badaddr); > OFFSET(PT_CAUSE, pt_regs, cause); > +#ifdef CONFIG_SMP > + OFFSET(PT_PCPU_GPRS, pt_regs, pcpu_gprs); > +#endif > > OFFSET(SUSPEND_CONTEXT_REGS, suspend_context, regs); > > diff --git a/arch/riscv/kernel/entry-common.c b/arch/riscv/kernel/entry-common.c > new file mode 100644 > index 0000000000000..164505962d131 > --- /dev/null > +++ b/arch/riscv/kernel/entry-common.c > @@ -0,0 +1,30 @@ > +// SPDX-License-Identifier: GPL-2.0-only > + > +#include > +#include > +#include > + > +#include > +#include > + > +/* > + * If the interrupted context had an active per-CPU operation, rewrite its > + * saved offset and address registers for the CPU on which it will resume. > + */ > +void noinstr riscv_pcpu_regs_fixup(struct pt_regs *regs) > +{ > + unsigned long pcpu_offset = __my_cpu_offset; > + unsigned long gprs = regs->pcpu_gprs; > + unsigned long pcp; > + unsigned int reg_pcp; > + unsigned int reg_off; > + unsigned int reg_addr; > + > + reg_pcp = FIELD_GET(PCPU_GPR_PCP, gprs); > + reg_off = FIELD_GET(PCPU_GPR_OFF, gprs); > + reg_addr = FIELD_GET(PCPU_GPR_ADDR, gprs); > + > + pcp = regs_get_gpr(regs, reg_pcp * sizeof(unsigned long)); > + regs_set_gpr(regs, reg_off * sizeof(unsigned long), pcpu_offset); > + regs_set_gpr(regs, reg_addr * sizeof(unsigned long), pcp + pcpu_offset); > +} > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > index 628b85e3915a7..bb50317deecc5 100644 > --- a/arch/riscv/kernel/entry.S > +++ b/arch/riscv/kernel/entry.S > @@ -198,6 +198,10 @@ SYM_CODE_START(handle_exception) > REG_S s4, PT_CAUSE(sp) > REG_S s5, PT_TP(sp) > > +#ifdef CONFIG_SMP > + pcpu_gprs_entry tp sp s0 > +#endif > + > /* > * Set the scratch register to 0, so that if a recursive exception > * occurs, the exception vector knows it came from the kernel > @@ -281,6 +285,16 @@ SYM_CODE_START_NOALIGN(ret_from_exception) > move a0, sp > call riscv_v_context_nesting_end > #endif > +#ifdef CONFIG_SMP > + REG_L t0, PT_PCPU_GPRS(sp) > + beqz t0, .Lpcpu_regs_restored > + move a0, sp > + call riscv_pcpu_regs_fixup > + REG_L t0, PT_PCPU_GPRS(sp) > + pcpu_gprs_exit tp t0 > +.Lpcpu_regs_restored: > +#endif > + > REG_L a0, PT_STATUS(sp) > restore_userssp s3, a0 > /* > @@ -341,6 +355,9 @@ SYM_CODE_START_LOCAL(handle_kernel_stack_overflow) > REG_S x3, PT_GP(sp) > REG_S x5, PT_T0(sp) > save_from_x6_to_x31 > +#ifdef CONFIG_SMP > + pcpu_gprs_entry tp sp s0 > +#endif > > REG_L s0, TASK_TI_KERNEL_SP(tp) > csrr s1, CSR_STATUS > diff --git a/arch/riscv/mm/extable.c b/arch/riscv/mm/extable.c > index e252eba55edec..cb64c58148a83 100644 > --- a/arch/riscv/mm/extable.c > +++ b/arch/riscv/mm/extable.c > @@ -27,24 +27,6 @@ static bool ex_handler_fixup(const struct exception_table_entry *ex, > return true; > } > > -static inline unsigned long regs_get_gpr(struct pt_regs *regs, unsigned int offset) > -{ > - if (unlikely(!offset || offset > MAX_REG_OFFSET)) > - return 0; > - > - return *(unsigned long *)((unsigned long)regs + offset); > -} > - > -static inline void regs_set_gpr(struct pt_regs *regs, unsigned int offset, > - unsigned long val) > -{ > - if (unlikely(offset > MAX_REG_OFFSET)) > - return; > - > - if (offset) > - *(unsigned long *)((unsigned long)regs + offset) = val; > -} > - > static bool ex_handler_uaccess_err_zero(const struct exception_table_entry *ex, > struct pt_regs *regs) > {