Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp976255lqb; Wed, 29 May 2024 17:18:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUatW87kGNSC7u7qibwWjx4NO7LrsRLFY6mCMOSdsoPbQ0R+gR51QqS7lobZfYMsLmVXU9WhjqwInRIIHjkQq3X5NnbL1IZnMJgb7pbJQ== X-Google-Smtp-Source: AGHT+IEBuKtRSXOQ6veDa1FyG0uqG7wFuZ3jLwQowCyh0+HZsP4gLZ2fX2zhJnvG2TR8vRmI6WeH X-Received: by 2002:a19:ac08:0:b0:529:593f:3f3c with SMTP id 2adb3069b0e04-52b7d47ac02mr350252e87.53.1717028281138; Wed, 29 May 2024 17:18:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717028281; cv=pass; d=google.com; s=arc-20160816; b=Y2VW37Rjf4AArFAvNWlIzIEzeiZKFgq88fPhVfA+PK30cQPA8rS8f2ZdFO/RnsZ+bm oQvZZuZopCOJACbN3/EZE8lMjOJXe0Ht+AiaF9qr0bOiNbAH5si2QWb2ZlnvAyyWi9Vh skVuw3ygOwLSDkZTAvYejHBCDfm510pLJgZpKTPx/hFGPeJgnDOOycJXu5pdpYT+0smE Ab5mM2/TdpjJbvawpOje0tBjRaTurIuhHaAmN3IWFHcgZDjXsGUgksaZMkZAlZm4ZAu8 bgVQGAOz5NGSMOx2ph8kyrA8qCe1LFxV+PnmYd4iyX1SBCO0GzrgmQB6rj0dHaWtVIxH L4xQ== 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=EQ03pSwu03IPlBKbH+1bfFOAbPC/t45t8cr4rrzecao=; fh=gNUYiv73h6u5ZmRlF2RuFX9gm9dJ5pn6p0K0pPeVQbM=; b=oWBr6GmqdaD6/2CBV7VUhG2ma0xGYDY8RjonmCF60lIchQ6DPmO4ZtK+V6xChiPrJq 4veLG3IVMiCKbMFqgNpQpTtmatCrPS0/AqMJH9ZctC1X9JpC0AwET+oGP4rA7d6RHCQB 02gL+si4WOc6gZdd4WjHkYzLR3rObtpWBWHfdKc/I2539ErnFvHS1cs8w6NmzsWe+90O ZwOXcsLA46gOdH/7/IoneG6BFIxsVZIBU7rWZKR4wZoagHVV+J/1I5xNRLG0fqHw5HOM jAjvlgboWigIQvMVFK5yfCIgjMjodWHURqBBZwHh/Qr7LGQ5SZeZPtrrOOsvkmZzUO3K BAHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DJe4Rq7+; 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-194798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194798-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc69a26si706707166b.691.2024.05.29.17.18.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 17:18:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DJe4Rq7+; 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-194798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194798-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D4B9E1F2284A for ; Thu, 30 May 2024 00:18:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 738D0CA40; Thu, 30 May 2024 00:17:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="DJe4Rq7+" Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 4D3654C66 for ; Thu, 30 May 2024 00:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717028259; cv=none; b=IODPyaTpXFkRFeF1GLY4Xa5y7dIF4Z206LcPGIVaIDJSyEgOOmsXjDVcHEXBDnf87gX0X6p1v2Hl3iiasH4ehnGOIRD1T+AJRUXObL8E/qr+PWgsk2k073cMSnBbWAWr8KhVPlI+fKBsWEXwwxKWCscqm3BcwKwZJ+q3Kwxujyk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717028259; c=relaxed/simple; bh=yY/gxEyGxhRFbtdU3MNkfHK5yFxHXxkQvyGAhpiHdzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AMwCxN8UAEx0kZJAn3tOhLnmOF6FSFoxXWgCnVmRr93wc2yK/JozO5FgMVNBPxzCahJGUJen90frF7FsX0nkn12aOb5p+Qov7ODrJ5/2bbjyRwz46v6h1OEtL02rJMnMmZQpDx9/LEr3MEkulsfYP9E0Abc1W9M+9FSdAU8JmWw= 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=DJe4Rq7+; arc=none smtp.client-ip=209.85.216.48 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-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2c19e6dc3dcso267100a91.3 for ; Wed, 29 May 2024 17:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1717028257; x=1717633057; 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=EQ03pSwu03IPlBKbH+1bfFOAbPC/t45t8cr4rrzecao=; b=DJe4Rq7+hwc9hzaYfMS23pYFxhadXaNFB9kLzPwww6CA/3FBbWdlX7Ss7kclN+13rD H/5b1Bld6MrNOa2VRxoNY8S4CozsNAJSdzLIXJk5BZ4NpecCPXJm4lj6XuXIlwyisuIk 7TQ7HK3u6uTPWccQ0DyHYNsGwXqi19kwLzxjxMkF5QZ2TKjIygGKWWacSVP7LA0DNj0V MGMQDBGmuse5IAmBe3jH8P2tP3NZsoM9srPIkQC7JWUnCiBRna+P9MATkuMa0XljuGKJ bRCqhDpP7NJg16+MvacbKtpVstMAUV7J1RZWxwHrXXMo3qvexNaGMbYbGKVlgVMuXuOr gCJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717028257; x=1717633057; 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=EQ03pSwu03IPlBKbH+1bfFOAbPC/t45t8cr4rrzecao=; b=OAeY4MpBnknrJPAxGmBKnB1BJ9u2wMUxLpTZCn/8zbcNK4jYk+QtPOcaDeGzG4WN7b G/pmM8sHpFXmoTJjCHk8MBRV3AmW9eokBjWsDsei1gaciWfsHCz7+e00zH9fmohs004c ZmoFYMYaA9DssXpmbj4apNWEqhuBy4dX4LNQwnpTNIYyg9hDPi0g5yh2EIIhjil3Iczn C/OXpF7DVqX1BK8pqYcqBNbNtgc6Hjb1aclCsFS0cdbTu86k5NUo6XQIzhdbucaNnKHa 6tFovR7/y88p4qNe4LK0thwToSgPBLNEftW3V1Ny5vurzbsb8WBNSnPzZwBHO8WZigNQ 65GQ== X-Gm-Message-State: AOJu0YzCz4YQ5gee3QrbLGCh8l4Y/eaRmNDMunFmf+yxQZ4LMHvnf7AK U6tMLfeP2eqdZz5V/JSxxClIRRfjfXpsI2JRECC+9xnMs1M2RZmCGv77bU2FfVSPvQPheh4WQgO v X-Received: by 2002:a17:90b:3905:b0:2bd:f968:da46 with SMTP id 98e67ed59e1d1-2c1abb02cf4mr633039a91.27.1717028257563; Wed, 29 May 2024 17:17:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 17:17:37 -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 2/4] riscv: entry: Balance vector context nesting Date: Wed, 29 May 2024 17:15:57 -0700 Message-ID: <20240530001733.1407654-3-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 Vector context management is the last thing done before jumping to C code, so it should be the first thing done after returning from C code. This also improves efficiency: riscv_v_context_nesting_end() clobbers the saved value of the status CSR, so currently ret_from_exception() must reload it. This is not necessary if riscv_v_context_nesting_end() is called first. Signed-off-by: Samuel Holland --- arch/riscv/kernel/entry.S | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 4c5b22cb7381..d13d1aad7649 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -120,6 +120,11 @@ ASM_NOKPROBE(handle_exception) * - ret_from_fork */ SYM_CODE_START_NOALIGN(ret_from_exception) +#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE + move a0, sp + call riscv_v_context_nesting_end +#endif + REG_L s0, PT_STATUS(sp) #ifdef CONFIG_RISCV_M_MODE /* the MPP value is too large to be used as an immediate arg for addi */ @@ -143,10 +148,6 @@ SYM_CODE_START_NOALIGN(ret_from_exception) */ csrw CSR_SCRATCH, tp 1: -#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE - move a0, sp - call riscv_v_context_nesting_end -#endif REG_L a0, PT_STATUS(sp) /* * The current load reservation is effectively part of the processor's -- 2.44.1