Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp976187lqb; Wed, 29 May 2024 17:17:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKPVgTOfWhDlBYQ6a5gfVq8luxqc+pkUFYELsiPSwADYCco/l73CmEexJa44i6fwaOwFvmpP9MxjFa70d+UngHhK+qELXPX/viWI++iQ== X-Google-Smtp-Source: AGHT+IHUqHBOlK4ng4C1+brxCIL48p+j+nVkvdIsR05G5XMsCoSDSy8cah3iqm6k/EZdmVbINhmi X-Received: by 2002:a17:90a:f58e:b0:2c1:a9e3:9fd1 with SMTP id 98e67ed59e1d1-2c1abc226edmr655532a91.19.1717028270305; Wed, 29 May 2024 17:17:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717028270; cv=pass; d=google.com; s=arc-20160816; b=RAIcqLvXsA1zukogjFz4HG6AQMaWSrVFdbi5C/mEX8ecgzXRyP2vIk1QA0Oo55KVUd 4xqMr6eOjTwEjBuiRbLAZglFO5+3yqSc22slRQDHOTul6CQouMw15AyT9xCuljT9yE67 K1nYAnF+c9M6kNQoRieSry4Ffdi+JtO6nhdfTCS+77+Xbhp/go9KGPr8FYRAqgLa3EAi 7mjxNWpu+LWNcAFIT3xRe7t07U+K1ze8sW6nkcagAE5n9hpvjik/ZhEzlDB+6C/BGZJn h3fMJeQ2dRxdCTKuNi62LHpqp47rxt3IXg8LPVyfUA/8ALIDkBFa3e58Wj+7EvT+FiFk /6AQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iGEn7Dcpmrkm/qCwkDxBmXXDS+7v8jGlOPv5lWfc4rI=; fh=gNUYiv73h6u5ZmRlF2RuFX9gm9dJ5pn6p0K0pPeVQbM=; b=Ea3RXYVm/HLpx8w5BdeSL7UpkGt5XpbZKbdmfnqfU1nLi4nDlyqxBdp1UmPIM8uCHu vXK1xqkdkv6lNmvEK7ISYBNmnTv8Uf2p78eH84a8GLJ0YHhpbtG0O99+7FXiFxAKBHu8 vSMie8NJv+SjVJMVE4en6FGDZPLCotU94uBeD6jKPUuX/+p9wN8/0jawjPx3++XVLmkB 0DvP52Ajk5ZaJ0LSKSkJdDUdMjIENu6ORoI7f1lKDwdGo3PCkkF4qhXmqItQXZ9akQXg hPou4wD0VTY1aaTkTixa8FTbhq8e5EX30dNc3fCyPf5DpwwCDKXHsjS4kwt9IH8Ts1EA Gv0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=IoyQ5TPv; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-194797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c1a776d3efsi547853a91.23.2024.05.29.17.17.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 17:17:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=IoyQ5TPv; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-194797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A33ED285A4E for ; Thu, 30 May 2024 00:17:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 631A18BEF; Thu, 30 May 2024 00:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="IoyQ5TPv" Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20B1F20EB for ; Thu, 30 May 2024 00:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717028258; cv=none; b=EwL6l22nmnVIx1JGPCjwxi2tyLbhThLA9QQW6pwCqMAIFNF/CCUciqYOIbRR/ccpqFo/tb1rBFOIQJoWw2Y1VlrpfL/+4QGzks/Y0LVfIOU+Egtqg1KKx5lOijkaaiy3zlQeNi7W8La6kFne9yph6vHtuH6VY2Z5YDCEKfD28uk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717028258; c=relaxed/simple; bh=5Kwe/U7PxVluGsCYFpMPZL03B/JZXYv8/BfkMbqTtoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WbVi4ekjaIMcx9zUCSTQMQzo4b8iRNiARNOctAmQdEG5tHowHotHj4kG7BZNJXzycUCUlRW47ez6Yt3JdSr6AxY11ptSPpEmWjHZwtpaNxWvKc8L2wzF6dFmrr+pPC2AY7oLwN5KnlEMCFKetjuNA8TRCxNrWY4nEOJojAm5ydA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=IoyQ5TPv; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6f8e9878514so283188b3a.1 for ; Wed, 29 May 2024 17:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1717028256; x=1717633056; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iGEn7Dcpmrkm/qCwkDxBmXXDS+7v8jGlOPv5lWfc4rI=; b=IoyQ5TPvCb2/+BRu/01JNWfp9xi1CPdxlLw11h1BkrDhdDcPXptoxr81kvyBNrr+bV yCSFVdQWkml8f2/QBjgz5CSiZl6jwJWOvDfUzTnJKyNEgwZUEiJBfJ6iYijEFiSCvCQA A7merkOUVk4MEN14gjdXuxf9xORlT/rgzHVzo09AtOky6n/R2wx1hb198pHqxj4/mBA2 w0Iu54ahOnvnUlSIp8Un9vecUEn9fOdflf8xrMwZV9LtSrBvt8/AL3rNE/mheaCtDeps RLKC2A0dTxpGMWoqMGtaqQpgKl7gXGVEQeiKSL4JiYn6S2OLyy9lUnXl3LLfKQTp4QPv Hedg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717028256; x=1717633056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iGEn7Dcpmrkm/qCwkDxBmXXDS+7v8jGlOPv5lWfc4rI=; b=fH1HfG4TdThKVCjnmZvq2aQ1YSy3w4CWYUBnVA+S+XQ3bX6nd4W+/pJwFEC2MtJwvL u3ZvtBKtA/GkQC/JXuTwxdobzvc55hixYe4BLadVugaDssF97lvY6CfwZCf1XxPJE+Z/ GNnVe0mRhSotQ7asoG7/YkjJaZKiqtR4y1oYW69m7lqxyly48JekVX7aPac3vHlWnmld jYurK7yLMLC1LuM41XABVGdO5OEYglXJGTQxLq4D69SyHz0vlWRLLAL24PxjDu6jfFt7 Q+7Wubg3hc5eLgMPzAYkcUVW2UU7bBJmOUU3awajumBTXF6/80Esgy2y2hXh5dJIH+So ZI9A== X-Gm-Message-State: AOJu0YwWglj72WcIPQm+TTQ5NIdTBGuqJ5W6ti5Ibdrk6qbmrK6y3yEP rgtKGqdIWZ3qBcS8z8UeuDlhU5VFx5Y3tIHEHOis1+kHZdGrqvhL7BiX5F5jQY8= X-Received: by 2002:a05:6a20:158f:b0:1af:cd4a:1e1d with SMTP id adf61e73a8af0-1b26470f21bmr645349637.40.1717028256348; Wed, 29 May 2024 17:17:36 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c1a776e206sm432171a91.20.2024.05.29.17.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 17:17:35 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: linux-kernel@vger.kernel.org, Andy Chiu , linux-riscv@lists.infradead.org, Matthew Bystrin , Sami Tolvanen , Samuel Holland Subject: [PATCH 1/4] riscv: Fix 32-bit call_on_irq_stack() frame pointer ABI Date: Wed, 29 May 2024 17:15:56 -0700 Message-ID: <20240530001733.1407654-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240530001733.1407654-1-samuel.holland@sifive.com> References: <20240530001733.1407654-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit call_on_irq_stack() uses struct member offsets to set up its link in the frame record list. On riscv32, `struct stackframe` is the wrong size to maintain stack pointer alignment, so STACKFRAME_SIZE_ON_STACK includes padding. However, the ABI requires the frame record to be placed immediately below the address stored in s0, so the padding must come before the struct members. Fix the layout by making STACKFRAME_FP and STACKFRAME_RA the negative offsets from s0, instead of the positive offsets from sp. Fixes: 82982fdd5133 ("riscv: Deduplicate IRQ stack switching") Signed-off-by: Samuel Holland --- arch/riscv/kernel/asm-offsets.c | 4 ++-- arch/riscv/kernel/entry.S | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c index b09ca5f944f7..84c056f5ee09 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -487,8 +487,8 @@ void asm_offsets(void) OFFSET(SBI_HART_BOOT_STACK_PTR_OFFSET, sbi_hart_boot_data, stack_ptr); DEFINE(STACKFRAME_SIZE_ON_STACK, ALIGN(sizeof(struct stackframe), STACK_ALIGN)); - OFFSET(STACKFRAME_FP, stackframe, fp); - OFFSET(STACKFRAME_RA, stackframe, ra); + DEFINE(STACKFRAME_FP, offsetof(struct stackframe, fp) - sizeof(struct stackframe)); + DEFINE(STACKFRAME_RA, offsetof(struct stackframe, ra) - sizeof(struct stackframe)); #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS DEFINE(FREGS_SIZE_ON_STACK, ALIGN(sizeof(struct ftrace_regs), STACK_ALIGN)); diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 68a24cf9481a..4c5b22cb7381 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -246,8 +246,8 @@ SYM_CODE_END(ret_from_fork) SYM_FUNC_START(call_on_irq_stack) /* Create a frame record to save ra and s0 (fp) */ addi sp, sp, -STACKFRAME_SIZE_ON_STACK - REG_S ra, STACKFRAME_RA(sp) - REG_S s0, STACKFRAME_FP(sp) + REG_S ra, (STACKFRAME_SIZE_ON_STACK + STACKFRAME_RA)(sp) + REG_S s0, (STACKFRAME_SIZE_ON_STACK + STACKFRAME_FP)(sp) addi s0, sp, STACKFRAME_SIZE_ON_STACK /* Switch to the per-CPU shadow call stack */ @@ -265,8 +265,8 @@ SYM_FUNC_START(call_on_irq_stack) /* Switch back to the thread stack and restore ra and s0 */ addi sp, s0, -STACKFRAME_SIZE_ON_STACK - REG_L ra, STACKFRAME_RA(sp) - REG_L s0, STACKFRAME_FP(sp) + REG_L ra, (STACKFRAME_SIZE_ON_STACK + STACKFRAME_RA)(sp) + REG_L s0, (STACKFRAME_SIZE_ON_STACK + STACKFRAME_FP)(sp) addi sp, sp, STACKFRAME_SIZE_ON_STACK ret -- 2.44.1