From patchwork Tue Apr 9 09:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pope B.Lei" X-Patchwork-Id: 1921295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Wb4+qG8i; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LNEu2cwt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VDL9p4tg2z1yZ6 for ; Tue, 9 Apr 2024 19:23:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=xEd7XR8Gf9GuxBG2zPUTxk/xT4sqF5hI2c3eI/AhRHQ=; b=Wb4+qG8i8yMhzi CFL3sMNi+lrxSD7MDp5a492NHSYFnP936PEuvO71cLN53NyquwmT5IeQ+V46wtnDhMSMHYydAK3O3 tLfYaOu0+sSGz+Gk2MGs0F58Y8uA8Rg1XKvEY80NN4eRrNnbOxBJjdeh90znV5FGHWhwRDOnu3ILi bbU3vU+wlsaLtRbymjvzF4sNbFA0Ds7v7CYksQu24n6xf/OUDH9jm7mfVY5KTQmDrWS0ajSWCTeOE /R4m90FlDquIw/TNuypI7Ovl16P3kmTnJ0J7hgmh1r4bOwobN5jnnCk0rUa6QVdViy155JbB0+uMR RmGYCCMvfVxGbVRODeEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ru7hS-00000001BSI-0rsS; Tue, 09 Apr 2024 09:23:30 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ru7hN-00000001BPP-3RWz for opensbi@lists.infradead.org; Tue, 09 Apr 2024 09:23:28 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1e2bbc2048eso44262225ad.3 for ; Tue, 09 Apr 2024 02:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712654602; x=1713259402; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VJnJWE2Xt1oL2AEwGrGmFO6zvZMW6eOuRnuiYMdFmjo=; b=LNEu2cwt+1iU/FNlhLrQ6xhmGlP9yj9oQTCPfdB9q5k9Ak+6Vxxd/o7N7HDdVZwIhM uUsntvz4AjwElAxFgyCVWlreGRD5Bf4E+lVVUxH6VFgHK2PnGeLGJ3sf9mOvjFVfhz6P Xoyz3S4cxP5bRDxbwAkfjjDHi7Mp26EcFbS4ZHBzyp3Wc97BBuSkNnw8KOEtdcQupxyw npUghatoTjukenBYkf7/hJsdRUTSqz4o69xpUvkR/Q1N2WjhiNwtDQMJUMROINyK3axf 7TGlLw2PXBpIJQg/EHJItEiUf9W0KD8HHl3J2xsW8NCvNXb5/GObtvbm3waL8tSu+wTE e/ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712654602; x=1713259402; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VJnJWE2Xt1oL2AEwGrGmFO6zvZMW6eOuRnuiYMdFmjo=; b=h5kHjvaUI/INthYIqXVaCy5FF4STJkxzlBUNebYo4GWB3E7zZym5HfzxZvVYZ8SSGl kfesQF50sDd1l2OpvBdGjRX1hkuixNJVQql+l1vnl09joPethLtI3jS9/vkqM2EurXwG 8VbR/xCjAh7eZJxMtfwrKwNx2VItbw24C5wysCoIUZ5S4OwGYZTNKOvgUN3PvyHFbYXU NMuDz5JvXwKXiLKBu2M8tU9xUYZPSmuvvex1PtoWlvS+E66wPz2Tlrx5P5RdcZRpntw7 HRhQ5qdln1nId3AiR+ONUoB/KtKVu8WctISqK4xkaGcnn0FkzqdEau2gKs2R3vubM325 zoNA== X-Gm-Message-State: AOJu0YwTz6uXqHJhO2kd3jxjNfC8H8Pf80fApuunZMBn3U0W+Ghjaf/e qZ/WE57e4iiw9g6xrr0TJaTO5MJDNZCqRJNtIAeqtg6kdWODmBlx6hnqG/n57wc= X-Google-Smtp-Source: AGHT+IHESyyX9mFd/Ar6mfC9YYZ6fr/TwSRtQ+6i0Rv3/ZAXqpO02Abt0JNyAhA1E3Wbsh29sA47AQ== X-Received: by 2002:a17:902:d486:b0:1e3:e87b:423f with SMTP id c6-20020a170902d48600b001e3e87b423fmr7925163plg.65.1712654602146; Tue, 09 Apr 2024 02:23:22 -0700 (PDT) Received: from smtp.qq.com ([118.112.98.89]) by smtp.gmail.com with ESMTPSA id b7-20020a170902d50700b001e27c404922sm653288plg.130.2024.04.09.02.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 02:23:21 -0700 (PDT) From: "Pope B.Lei" To: opensbi@lists.infradead.org Cc: "Pope B.Lei" Subject: [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode. Date: Tue, 9 Apr 2024 17:23:04 +0800 Message-Id: <20240409092304.569-1-popeblei@gmail.com> X-Mailer: git-send-email 2.35.2.windows.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240409_022326_649700_57BE7480 X-CRM114-Status: UNSURE ( 9.02 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Although Mstatus.MPV is set, before executing mret, access to VS mode registers should use the actual register addresses, not the pseudonyms of S registers. Signed-off-by: Pope B.Lei --- V1 -> V2: Simplify the if condition - lib/sbi/sbi_hart.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) Content analysis details: (-0.2 points, 5.0 required) 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.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62a listed in] [list.dnswl.org] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [popeblei(at)gmail.com] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Although Mstatus.MPV is set, before executing mret, access to VS mode registers should use the actual register addresses, not the pseudonyms of S registers. Signed-off-by: Pope B.Lei Reviewed-by: Xiang W --- V1 -> V2: Simplify the if condition - lib/sbi/sbi_hart.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 3d13694..ccdd12f 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1, csr_write(CSR_MEPC, next_addr); if (next_mode == PRV_S) { - csr_write(CSR_STVEC, next_addr); - csr_write(CSR_SSCRATCH, 0); - csr_write(CSR_SIE, 0); - csr_write(CSR_SATP, 0); + if (next_virt) { + csr_write(CSR_VSTVEC, next_addr); + csr_write(CSR_VSSCRATCH, 0); + csr_write(CSR_VSIE, 0); + csr_write(CSR_VSATP, 0); + } else { + csr_write(CSR_STVEC, next_addr); + csr_write(CSR_SSCRATCH, 0); + csr_write(CSR_SIE, 0); + csr_write(CSR_SATP, 0); + } } else if (next_mode == PRV_U) { if (misa_extension('N')) { csr_write(CSR_UTVEC, next_addr);