From patchwork Thu Feb 27 21:34:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11410353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 327E917E0 for ; Thu, 27 Feb 2020 21:35:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 03E89246A1 for ; Thu, 27 Feb 2020 21:35:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UZNedvtb"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="BxCCNCvy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03E89246A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:To:From: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2nKrAkc7nEDUcUx0/lfg7h3wWZF++DSMjw3PSOPi658=; b=UZNedvtbpXckxU8cFCT/Lbb1A Mdjsg8FIaLMcvzJOxD7MoeGRom53gqvBdhePwswTYXQMXKinZAFTg7Np05WpHpcyuT7GzsDisLV3y qmW3UWdcEOwIhdMxVLrdgm6OAKK9YcEv/xqQtCYSYYgivZcXSwIFLwr0sU+BLVdJy3ltkuIO/vzvZ DiNzVSs0hc6sr6Jt8hQrXunrehzR3UKuVsIQ5UfqGFxGUJeefwKw0CaIQ89DSOOp0f/P91mFsNMbN IdoDkb2lu0Eq2y85wUFXJ76rllT5jKMdgMfXvE7voI2SFFEj9qM7E2nEOWiS/F5SLwU0ayp+pkTjG FyeejgL7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Qou-0007gY-AT; Thu, 27 Feb 2020 21:35:48 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Qor-0007f1-AQ for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 21:35:46 +0000 Received: by mail-pl1-x644.google.com with SMTP id q4so335921pls.4 for ; Thu, 27 Feb 2020 13:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=2nKrAkc7nEDUcUx0/lfg7h3wWZF++DSMjw3PSOPi658=; b=BxCCNCvypzdE0nGtBwI/KrvijMeblsePC3Bh9Gz462Jo73Aj/puwZGXXCWYim/SlkU /A2ftlvWPQgnnICG+1T+yv67RBKkeAT2D40XZ8UkZTrYsjfKKUHur1uCFlRkvoY69kGn jq5fDkpJbEbl49QT9mUN4r6P2oIHM4jkN5cKZGQ+lqdBTWDxGAAo48yMcokij1WvadyY gxuwZIxgq9H9sqcEIeWT/0IrTpW9WJ+IsJm504iiEN9hjLpPjGfIy9tscKMnoF4oHIBk 8y3/tgktht9G1pi9J0rN4RbX9/Go7zZ8gLLD0ruYJ0jS3qCVu7JInV4PGklYF/DmwtGL e7Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=2nKrAkc7nEDUcUx0/lfg7h3wWZF++DSMjw3PSOPi658=; b=g7EYiVErZ+qhzNJjSI8qKZLLlf+4JiQVn+L9Ck5V2rZMRKD9fLtKN6o8fFZ4I4ZTmw 3iFX1vWqrfaQ3AHJSFD6DAAn5HtOyKt35tFquIVJkTkeYZAoNQ7pP7lSs0KXeJr5XRDS FMN9zOWDfDIUVoHLfR2KCn5XuJ71qNjCzhLouYPFmzDflhvxpRyx3/Z+PtTttOd1rtKq +oh1TgaPOkBJu+ioQ+JRtTB7kMJocwqQkhXswnF59IY+D1hefyPWJVbaN/l/KzmJ/Bol 9oBuclKsYlLRuUaXDvCD9Cwa1BFtz9jbq99CebC/IWAkWNMzeVRGp4w/ODELbEDMBX2h baQg== X-Gm-Message-State: APjAAAWgyK7KOddMlxd+X5P0eXBIYR/Rh+ubeAnOcbXsWrsKMtP8mt4z +xYKcsfkpC57cnNDwuiQqOg3ew== X-Google-Smtp-Source: APXvYqyxiJo7NJKOBkuKQfAk3KytzrONlSNU2e8xVGzWvqeuHJLVgi3ADlmJBCS1BOgWHs1G8rMkIg== X-Received: by 2002:a17:902:9b8a:: with SMTP id y10mr772783plp.114.1582839343678; Thu, 27 Feb 2020 13:35:43 -0800 (PST) Received: from localhost ([2620:0:1000:2514:23a5:d584:6a92:3e3c]) by smtp.gmail.com with ESMTPSA id a22sm8187624pfk.108.2020.02.27.13.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 13:35:43 -0800 (PST) Subject: [PATCH 1/3] RISC-V: Stop relying on GCC's register allocator's hueristics Date: Thu, 27 Feb 2020 13:34:48 -0800 Message-Id: <20200227213450.87194-2-palmer@dabbelt.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200227213450.87194-1-palmer@dabbelt.com> References: <20200227213450.87194-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_133545_357586_7E225CAF X-CRM114-Status: GOOD ( 16.24 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:644 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: clang-built-linux@googlegroups.com, Palmer Dabbelt , kernel-team@android.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt GCC allows users to hint to the register allocation that a variable should be placed in a register by using a syntax along the lines of function(...) { register long in_REG __asm__("REG"); } We've abused this a bit throughout the RISC-V port to access fixed registers directly as C variables. In practice it's never going to blow up because GCC isn't going to allocate these registers, but it's not a well defined syntax so we really shouldn't be relying upon this. Luckily there is a very similar but well defined syntax that allows us to still access these registers directly as C variables, which is to simply declare the register variables globally. For fixed variables this doesn't change the ABI. LLVM disallows this ambiguous syntax, so this isn't just strictly a formatting change. Signed-off-by: Palmer Dabbelt --- arch/riscv/include/asm/current.h | 5 +++-- arch/riscv/kernel/process.c | 5 +++-- arch/riscv/kernel/stacktrace.c | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/current.h b/arch/riscv/include/asm/current.h index dd973efe5d7c..1de233d8e8de 100644 --- a/arch/riscv/include/asm/current.h +++ b/arch/riscv/include/asm/current.h @@ -17,6 +17,8 @@ struct task_struct; +register struct task_struct *riscv_current_is_tp __asm__("tp"); + /* * This only works because "struct thread_info" is at offset 0 from "struct * task_struct". This constraint seems to be necessary on other architectures @@ -26,8 +28,7 @@ struct task_struct; */ static __always_inline struct task_struct *get_current(void) { - register struct task_struct *tp __asm__("tp"); - return tp; + return riscv_current_is_tp; } #define current get_current() diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 817cf7b0974c..610c11e91606 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -22,6 +22,8 @@ #include #include +unsigned long gp_in_global __asm__("gp"); + extern asmlinkage void ret_from_fork(void); extern asmlinkage void ret_from_kernel_thread(void); @@ -107,9 +109,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp, /* p->thread holds context to be restored by __switch_to() */ if (unlikely(p->flags & PF_KTHREAD)) { /* Kernel thread */ - const register unsigned long gp __asm__ ("gp"); memset(childregs, 0, sizeof(struct pt_regs)); - childregs->gp = gp; + childregs->gp = gp_in_global; /* Supervisor/Machine, irqs on: */ childregs->status = SR_PP | SR_PIE; diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 0940681d2f68..02087fe539c6 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -19,6 +19,8 @@ struct stackframe { unsigned long ra; }; +register unsigned long sp_in_global __asm__("sp"); + void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg) { @@ -29,7 +31,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, sp = user_stack_pointer(regs); pc = instruction_pointer(regs); } else if (task == NULL || task == current) { - const register unsigned long current_sp __asm__ ("sp"); + const register unsigned long current_sp = sp_in_global; fp = (unsigned long)__builtin_frame_address(0); sp = current_sp; pc = (unsigned long)walk_stackframe; @@ -73,8 +75,7 @@ static void notrace walk_stackframe(struct task_struct *task, sp = user_stack_pointer(regs); pc = instruction_pointer(regs); } else if (task == NULL || task == current) { - const register unsigned long current_sp __asm__ ("sp"); - sp = current_sp; + sp = sp_in_global; pc = (unsigned long)walk_stackframe; } else { /* task blocked in __switch_to */ From patchwork Thu Feb 27 21:34:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11410355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E31E92A for ; Thu, 27 Feb 2020 21:35:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C09524677 for ; Thu, 27 Feb 2020 21:35:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ktwEAIT1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="02iHtvHC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C09524677 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:To:From: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AcocSUGKmr1hGuXmIYHI/PJN7pt2xJxuohE1KdhBYJU=; b=ktwEAIT1fqkl0pg1qwNY4YNes H9A7X0PwZqtj8F+DKpFdKBrfOPQ9fCi+W6ykzXbScbxDzqiZBsVmWhD1WUSBMpiZp0cOpkmNniW1Z f7zD5j0wHknRVWJDveJHKa82bXNifc2/MNpowCcpaZRir1M5siwv5FflQ2I24sjV78rYSeX1QmzLo A9BHfv12Gsp8FRZU6FKa9m7AHVlj8mGRriQaONY9kvzfOHHCT4HHk84gTMpu2RcFjobWHwvtRsG6H Dm/LFAIwwQqnQpNjAReu/VbN8dDUkWjDMsWtQ9L8nJ/U0X34rPCGFO7Jo0oGNJJMdw/Q8rnEYNtKc DUq+Z2EfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Qow-0007i8-37; Thu, 27 Feb 2020 21:35:50 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Qos-0007fT-3V for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 21:35:48 +0000 Received: by mail-pj1-x1044.google.com with SMTP id r67so347566pjb.0 for ; Thu, 27 Feb 2020 13:35:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=AcocSUGKmr1hGuXmIYHI/PJN7pt2xJxuohE1KdhBYJU=; b=02iHtvHC/YXKtORtJx0po9jlRvhSKPjJItwMvsClrrrEtPAQtNhZXnEO3BM9iGkOq+ IC/sLV5zmSl9X8af5/YbMvtz6iDCBcVP0vAw3ZgcwTe/Wz5szQxxF2lPVZwMGROtGR18 1f0q3a5sgvzgneII3BP7vjLzo0z1jOUpyD90F8icIb58n+vNGUB0RHfXdm3DmqkM4aP8 XpAadSZ1qt/vdnoWv5eWOujwuW/S+KlyKXZRtxqSuRgamdwRkaIhLCRTvNLcW1MPrGeX KvYkngqxlnspCbt09zwf6oFTquOx9AglO/pp1uAkAj4Z73tn5/IRpYjon0GOUMkn9596 YjjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=AcocSUGKmr1hGuXmIYHI/PJN7pt2xJxuohE1KdhBYJU=; b=B2OQaST/RfjRVZeUJxZE42U3yyvyro7kq4wD0ExFlu+vuSXojhSOdt8IOkLi4zMy06 59gHM002awGLeOJbkhWMc9o7EyLbOPHj/RpUCmMNYnxS/MQiEemq3+X99aHtZb11aFZT Ox3damZptaNnma6KdsSxRm6L5OndStnpSf6uPwGBYQzGxz710qD4aG53i7E9aJkxTe+T 6yfEtyl6kjFIw37Krfl9Ora0st+754tQeI1EbLtax7wUtzYrI5F+oAqfrPPH5BdSd1DF 5XXhdMsmCaqEO5NASIbZWQKTK/1/Jxd4VeanSDpIYQfgBMtg/ebckaVx25yyqrbebafb fg7g== X-Gm-Message-State: APjAAAVcQaOipw/3TYewuVQ1DcrYAVdyMgVRMQfJWEv4lQvFdXmaC2HX sXijzpqZevoymKi5zezmw7UxVQ== X-Google-Smtp-Source: APXvYqzgsQV2UfdPsP4ccDri4Rwx1yutDxP11+BF7+wtZwGOEOBnQ4QOq2PwSH4DbO4CjVTitVaO3g== X-Received: by 2002:a17:90a:c691:: with SMTP id n17mr1019733pjt.41.1582839344878; Thu, 27 Feb 2020 13:35:44 -0800 (PST) Received: from localhost ([2620:0:1000:2514:23a5:d584:6a92:3e3c]) by smtp.gmail.com with ESMTPSA id u6sm7709711pgj.7.2020.02.27.13.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 13:35:44 -0800 (PST) Subject: [PATCH 2/3] RISC-V: Inline the assembly register save/restore macros Date: Thu, 27 Feb 2020 13:34:49 -0800 Message-Id: <20200227213450.87194-3-palmer@dabbelt.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200227213450.87194-1-palmer@dabbelt.com> References: <20200227213450.87194-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_133546_155620_016F1085 X-CRM114-Status: GOOD ( 14.63 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: clang-built-linux@googlegroups.com, Palmer Dabbelt , kernel-team@android.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt These are only used once, and when reading the code I've always found them to be more of a headache than a benefit. While they were never worth removing before, LLVM's integrated assembler doesn't support LOCAL so rather that trying to figure out how to refactor the macros it seems saner to just inline them. Signed-off-by: Palmer Dabbelt Reviewed-by: Nick Desaulniers --- arch/riscv/kernel/entry.S | 143 ++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 82 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index bad4d85b5e91..f2e8e7c8089d 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -13,17 +13,11 @@ #include #include - .text - .altmacro - -/* - * Prepares to enter a system call or exception by saving all registers to the - * stack. - */ - .macro SAVE_ALL - LOCAL _restore_kernel_tpsp - LOCAL _save_context +#if !IS_ENABLED(CONFIG_PREEMPTION) +.set resume_kernel, restore_all +#endif +ENTRY(handle_exception) /* * If coming from userspace, preserve the user thread pointer and load * the kernel thread pointer. If we came from the kernel, the scratch @@ -90,77 +84,6 @@ _save_context: REG_S s3, PT_BADADDR(sp) REG_S s4, PT_CAUSE(sp) REG_S s5, PT_TP(sp) - .endm - -/* - * Prepares to return from a system call or exception by restoring all - * registers from the stack. - */ - .macro RESTORE_ALL - REG_L a0, PT_STATUS(sp) - /* - * The current load reservation is effectively part of the processor's - * state, in the sense that load reservations cannot be shared between - * different hart contexts. We can't actually save and restore a load - * reservation, so instead here we clear any existing reservation -- - * it's always legal for implementations to clear load reservations at - * any point (as long as the forward progress guarantee is kept, but - * we'll ignore that here). - * - * Dangling load reservations can be the result of taking a trap in the - * middle of an LR/SC sequence, but can also be the result of a taken - * forward branch around an SC -- which is how we implement CAS. As a - * result we need to clear reservations between the last CAS and the - * jump back to the new context. While it is unlikely the store - * completes, implementations are allowed to expand reservations to be - * arbitrarily large. - */ - REG_L a2, PT_EPC(sp) - REG_SC x0, a2, PT_EPC(sp) - - csrw CSR_STATUS, a0 - csrw CSR_EPC, a2 - - REG_L x1, PT_RA(sp) - REG_L x3, PT_GP(sp) - REG_L x4, PT_TP(sp) - REG_L x5, PT_T0(sp) - REG_L x6, PT_T1(sp) - REG_L x7, PT_T2(sp) - REG_L x8, PT_S0(sp) - REG_L x9, PT_S1(sp) - REG_L x10, PT_A0(sp) - REG_L x11, PT_A1(sp) - REG_L x12, PT_A2(sp) - REG_L x13, PT_A3(sp) - REG_L x14, PT_A4(sp) - REG_L x15, PT_A5(sp) - REG_L x16, PT_A6(sp) - REG_L x17, PT_A7(sp) - REG_L x18, PT_S2(sp) - REG_L x19, PT_S3(sp) - REG_L x20, PT_S4(sp) - REG_L x21, PT_S5(sp) - REG_L x22, PT_S6(sp) - REG_L x23, PT_S7(sp) - REG_L x24, PT_S8(sp) - REG_L x25, PT_S9(sp) - REG_L x26, PT_S10(sp) - REG_L x27, PT_S11(sp) - REG_L x28, PT_T3(sp) - REG_L x29, PT_T4(sp) - REG_L x30, PT_T5(sp) - REG_L x31, PT_T6(sp) - - REG_L x2, PT_SP(sp) - .endm - -#if !IS_ENABLED(CONFIG_PREEMPTION) -.set resume_kernel, restore_all -#endif - -ENTRY(handle_exception) - SAVE_ALL /* * Set the scratch register to 0, so that if a recursive exception @@ -298,7 +221,63 @@ resume_userspace: csrw CSR_SCRATCH, tp restore_all: - RESTORE_ALL + REG_L a0, PT_STATUS(sp) + /* + * The current load reservation is effectively part of the processor's + * state, in the sense that load reservations cannot be shared between + * different hart contexts. We can't actually save and restore a load + * reservation, so instead here we clear any existing reservation -- + * it's always legal for implementations to clear load reservations at + * any point (as long as the forward progress guarantee is kept, but + * we'll ignore that here). + * + * Dangling load reservations can be the result of taking a trap in the + * middle of an LR/SC sequence, but can also be the result of a taken + * forward branch around an SC -- which is how we implement CAS. As a + * result we need to clear reservations between the last CAS and the + * jump back to the new context. While it is unlikely the store + * completes, implementations are allowed to expand reservations to be + * arbitrarily large. + */ + REG_L a2, PT_EPC(sp) + REG_SC x0, a2, PT_EPC(sp) + + csrw CSR_STATUS, a0 + csrw CSR_EPC, a2 + + REG_L x1, PT_RA(sp) + REG_L x3, PT_GP(sp) + REG_L x4, PT_TP(sp) + REG_L x5, PT_T0(sp) + REG_L x6, PT_T1(sp) + REG_L x7, PT_T2(sp) + REG_L x8, PT_S0(sp) + REG_L x9, PT_S1(sp) + REG_L x10, PT_A0(sp) + REG_L x11, PT_A1(sp) + REG_L x12, PT_A2(sp) + REG_L x13, PT_A3(sp) + REG_L x14, PT_A4(sp) + REG_L x15, PT_A5(sp) + REG_L x16, PT_A6(sp) + REG_L x17, PT_A7(sp) + REG_L x18, PT_S2(sp) + REG_L x19, PT_S3(sp) + REG_L x20, PT_S4(sp) + REG_L x21, PT_S5(sp) + REG_L x22, PT_S6(sp) + REG_L x23, PT_S7(sp) + REG_L x24, PT_S8(sp) + REG_L x25, PT_S9(sp) + REG_L x26, PT_S10(sp) + REG_L x27, PT_S11(sp) + REG_L x28, PT_T3(sp) + REG_L x29, PT_T4(sp) + REG_L x30, PT_T5(sp) + REG_L x31, PT_T6(sp) + + REG_L x2, PT_SP(sp) + #ifdef CONFIG_RISCV_M_MODE mret #else From patchwork Thu Feb 27 21:34:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11410359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B600992A for ; Thu, 27 Feb 2020 21:36:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 93D2A24677 for ; Thu, 27 Feb 2020 21:36:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AUwTnjtT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="uXZzIxo8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93D2A24677 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:To:From: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3j2hvJMpq/q8KaX+62obi9xX+88RkfLzjLfHwZgX5Y4=; b=AUwTnjtTc6V3UrbxL3S3TDrf0 jkMmU26ZzzhDIh7xRjVohqrGBoqtM3ajFnKXyHCDLp8GUOLxOvHvOaL7ugw8A5U51thQ3lm32HyXH vMFDaNT+htQwoIEj3ApLagtzcvS0PqAkxAjn6zPHmtMXe+qy5XVHIVKuTfj42Eb09T6TnkBNsJVn4 6Q4iUgcNOKo41YoL/o7P6FM+cn8jZmp0vLxSj+h7ve7HDCZDtvevs9RAwONunwBxgOxTnnD2CfmIG NAYe7S3igrN/mteErQm8N7pZxeuQ0Vr8eda+7n+fKKVdjBFK+yWZm+601jccFnQwEDBg3n4NhAdsc zEcDh1gbA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Qoy-0007lZ-EC; Thu, 27 Feb 2020 21:35:52 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Qow-0007hS-E5 for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 21:35:51 +0000 Received: by mail-pl1-x641.google.com with SMTP id u3so324771plr.9 for ; Thu, 27 Feb 2020 13:35:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=3j2hvJMpq/q8KaX+62obi9xX+88RkfLzjLfHwZgX5Y4=; b=uXZzIxo89Z4LxTDa6mxgsSUY1VE3WEALGEbe6IW2oRxdnpOM5JB2tvy2SP9CnMMUL3 L39qPT+dFrfWx4Q1a/A4M3+5ImvJVTf0eQJpVkrG2NQ9lxUgp456wM3JJq22FPbv1jfL lu2jOnckNAVd6oInp4DW6NhzKhkbk9VpswMcMBXa6JVawd7QdddHzwCgQmR6VVQ2TVFu ++h6qKA35rg2IYcw0MA2bXgdP5O6qiOCqnbl1nD1NWdyCC7gonRCQ7OpuoBXxZwr5UWM MLOccK5Mh+C6S8SJiPa3HoUZ6Jvdisx15xTzm7ekYyj9YOsFF8EM4p6H+yEkIojmPcVm d6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=3j2hvJMpq/q8KaX+62obi9xX+88RkfLzjLfHwZgX5Y4=; b=OV5iJkberaNYBBGMx5eMxKiqXHTm9Rj5e/2GIpRcAugCfSx5kGpBaqw7Wno/YUTdJt OwkuzR92MTWnArxxEAXorytlqMLr05KSZJKcoMWV2EstrrCxbvxfw/jTaaST7/qZ+hTs /lX2RWi7sbD5P72F+4Rv0vQ1HQYjPWfO2rakEM0rEoxg5X6328cwjDtY4XB2bDgxQCTp J7feCJgbXpoYhV+U395WfOpYd2im+F/qlXzoopYQZY6/NiFrFVhnarL8fL6Z45doN/3z IsliEnywfWRPvkY+8wrXmA8yXJQ1REqiJG3jQD0up+km+W9NB8P2vcpoS6o7ZInlJDHz VtHw== X-Gm-Message-State: APjAAAVrlK+VCwmT8rgfHiqWg/mB1lv78wD+kanGLGuvfNlEXETh5QyS uP0Nr6sMMufo7PKMBLKD3HnFPw== X-Google-Smtp-Source: APXvYqwFdyfYW/BOsbTXa99Ah8PH7ILIGEXzCbznhwADcIu4uLZidf2EfB1n6jarymqXJi839ZaLdQ== X-Received: by 2002:a17:902:8b89:: with SMTP id ay9mr740609plb.309.1582839346217; Thu, 27 Feb 2020 13:35:46 -0800 (PST) Received: from localhost ([2620:0:1000:2514:23a5:d584:6a92:3e3c]) by smtp.gmail.com with ESMTPSA id p21sm8047800pfn.103.2020.02.27.13.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 13:35:45 -0800 (PST) Subject: [PATCH 3/3] RISC-V: Stop using LOCAL for the uaccess fixups Date: Thu, 27 Feb 2020 13:34:50 -0800 Message-Id: <20200227213450.87194-4-palmer@dabbelt.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200227213450.87194-1-palmer@dabbelt.com> References: <20200227213450.87194-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_133550_487690_DDE9FF70 X-CRM114-Status: UNSURE ( 9.77 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:641 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: clang-built-linux@googlegroups.com, Palmer Dabbelt , kernel-team@android.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt LLVM's integrated assembler doesn't support the LOCAL directive, which we're using when generating our uaccess fixup tables. Luckily the table fragment is small enough that there's only one internal symbol, so using a relative symbol reference doesn't really complicate anything. Signed-off-by: Palmer Dabbelt --- arch/riscv/lib/uaccess.S | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/riscv/lib/uaccess.S b/arch/riscv/lib/uaccess.S index f29d2ba2c0a6..40bf130073e8 100644 --- a/arch/riscv/lib/uaccess.S +++ b/arch/riscv/lib/uaccess.S @@ -5,12 +5,11 @@ .altmacro .macro fixup op reg addr lbl - LOCAL _epc -_epc: +100: \op \reg, \addr .section __ex_table,"a" .balign RISCV_SZPTR - RISCV_PTR _epc, \lbl + RISCV_PTR 100b, \lbl .previous .endm