From patchwork Wed Apr 10 02:05:20 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: 1921650 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=Up/Yzc+L; 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=QAInZnRU; 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 4VDmQL5SH9z1yYM for ; Wed, 10 Apr 2024 12:06:00 +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=5ynlGpr8YOD8Gt7wg4M+JPHiunJHfDKfvDJW23CHH5I=; b=Up/Yzc+LlR8rrs vMPyP+PCCp0h8oy2rElVAGpYcHq/tOvo7nPiqeVu/wq1LRla3XSvlokCzu54sEKeFzj60bHZgTueR vbNItSscBKZFvTEOyyv8u5uJlHs6gpHeRrXjAR/HkmDWSzVVYO3tLxBIqraGdtq3FGt0UWutMynBb TO4BwYAc2mhAjNcNPyR6JyPE5mFqwODlMmflXDp+E/O7tGfrUZcIO/1iERZ06NxAu2+BtJCgpvhmn gFd0lNXNvvm7cqx07H/XGScGIP7B3nEs5GDKD11B2omvhPEnLiKWqMaJVoVNlNZhnh0rBa9BKXYx1 Pk64/bXDM+8bkyssMGwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruNLO-00000004gfA-2qFV; Wed, 10 Apr 2024 02:05:46 +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 1ruNLM-00000004gdX-2jzv for opensbi@lists.infradead.org; Wed, 10 Apr 2024 02:05:46 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1e4bf0b3e06so9470425ad.1 for ; Tue, 09 Apr 2024 19:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712714739; x=1713319539; 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=BBUcBQ8azLjvy7wdikV51z4yulDcHoHiBJ06sLFqsLg=; b=QAInZnRU5H4awBLkOpIcEil4HDLiZPZEdE877UAcXJlKCFyh9WuCOcVp0vV2uSH7oe xYjuYXeNa3nK845UrAEBwBWs9V7shR15+e/fdFPhJM1VySgJpPlrBpO8AJ69cetozYWO /fKT327BQSz7d1X+IkkWDuginKP0SWRm6C4hQka5p5x0uOZ3QugWPLcXI0Vh0duV1tky 4CvbVk/GAuAqMXcQycQ6+f64CTsxMSCIFBbJQmwVK+vwFQxQde8MNn96HVGkL7d1L1eR G9RZ7lxJYRfEeoFTf77md4EoFq+o5rc/JBqjQcxSx469Nyy44vCd0gTGkTfKVhO8zZA+ hjEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712714739; x=1713319539; 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=BBUcBQ8azLjvy7wdikV51z4yulDcHoHiBJ06sLFqsLg=; b=CWTOK9j5jkSAcm5Xmq3eKzmHQ2hm02sQGl6AqQ93Ky+rjWGN5ZcGZ5JkHD8OHGaOZ/ SotUtslddusFLSp4e7SZFxwkQDnnAW4U8HdRWAk8jUMt1JgDUIarjetkhDVR892OviXX YCz7GsYAID06TFFxWipt//Ou8Ak1wikYS0B7KG9eXBOoQ0rtkQ/LwBRatz7XduHb3ChF G1UR5MMwTVvB+D9BFbHFlhNdOsdTLwp40FcPMEZuZSTPNrBR2gwpK9vQsr+A2Rw7sJAl C/RGnsWHWERXaZQfpViIbEdIwnBGtBzFHoI1GtxMys7q4Ufw/hQQt5KmS07z4K596G4H RTXA== X-Gm-Message-State: AOJu0Yx6u+NYgpGocNtjx+daFmzszGBR2D5G5H+MkXVMrT51UkGk2g8N v/zaHylWnmySsq5/Kf0mGSirinSCVxA8ZkYUYdKwXWr1F2Lx5kAQY4YP16CUe2g= X-Google-Smtp-Source: AGHT+IEEfF4IukL/eVnU5Jrx2ZDwQzhOxqyMjWpCCNn1qNCAoY9nIqIxiWEszeeLqDFJct1rj7TyDQ== X-Received: by 2002:a17:903:249:b0:1e4:24bc:426f with SMTP id j9-20020a170903024900b001e424bc426fmr1716311plh.24.1712714739203; Tue, 09 Apr 2024 19:05:39 -0700 (PDT) Received: from smtp.qq.com ([118.112.98.89]) by smtp.gmail.com with ESMTPSA id im23-20020a170902bb1700b001e0b5eee802sm3224612plb.123.2024.04.09.19.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 19:05:38 -0700 (PDT) From: "Pope B.Lei" To: opensbi@lists.infradead.org Cc: "Pope B.Lei" Subject: [PATCH v3] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode. Date: Wed, 10 Apr 2024 10:05:20 +0800 Message-Id: <20240410020521.1898-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_190544_790133_B7CECF49 X-CRM114-Status: UNSURE ( 9.06 ) 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 V2 -> V3: Format indentation to tabs. 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 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.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_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: Anup Patel --- V1 -> V2: Simplify the if condition V2 -> V3: Format indentation to tabs. 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..ea75e74 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);