From patchwork Tue Sep 3 06:17:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fea.Wang" X-Patchwork-Id: 13788074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30E0ECD342F for ; Tue, 3 Sep 2024 06:15:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slMo9-0004lV-Gz; Tue, 03 Sep 2024 02:14:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slMo7-0004gG-At for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:27 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slMo5-0002ER-Ca for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:26 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-7cd9e4f550dso1330840a12.0 for ; Mon, 02 Sep 2024 23:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725344064; x=1725948864; darn=nongnu.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=Ocor0J69gEkcnw3K93XNkT/Ls3GmiKCW3UrbQY2G9R0=; b=bvS8jn1nA+gB+M/2FITlCLBJ+2tNLa+z3j0AtbMGvhbpbw6plkVxhKumURG8od+BPW nd4WNv5jOe+7z7xS+UkMW4CZPSFNUS+aXJdn8STTkyHiwP9agVOFQJ8clihwOPaqTeQt FTEOuBzsrPGzh13HghbrLaZ8BJ3IB7av0aZ9ienVTj8gO1MXiZjcEekoZ7EfhDBXtsvZ /aSOE8xs84Yk9xlawsiX/Q5plcNyfFnwTdVXkuJOZ7ZLlDblr/qiJhz8tj6d7E+/tplj i/z6pZGdUaEa9aUNLkXnL0Gi4uwmoGqYKDSbLEEC5lYNohRE6qXmLwGYVI74i9y/u3eR RvBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725344064; x=1725948864; 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=Ocor0J69gEkcnw3K93XNkT/Ls3GmiKCW3UrbQY2G9R0=; b=OnZ3qTrXHwsH5paVY4YaUI5Kkp/oWxJviGHXhqop20bAq1a56B4RtCjPag+imzM51Q swUZ70gkyIIkF1vVDTEnrH+YztqsgbwSc8MX2irCWYYhQiniIsvSGWDIms91v0zNUQyt Ed5dVK3g8Bl2NQvfO0XclXBqwzQobl/MBvRYsmN9hmzQDFLUnH7s4/++RxDHy3Oo47tn AG0p9VE7x12KSeYC3RSydufUEwLhoywJS8HtQsnciXKNr0sYRkg6Ua3OaD/VaOzjoiv5 o80Tuq8YeMYGfoyilHpRcIz8jSYrCuPZKWNMPnkXC+b4xxDvbehkwn8FEKRSHvs0QPdv E4cg== X-Gm-Message-State: AOJu0Yz9yVAKv/udXdk7hZcT5MXthYR2p72ACFEbNxOz4Tm/XzeN3eFC MlvP3fV6hKj+mQxxtSHFMVVlysE2iz/v9r7n6iW79zCvSkeFaUgkpRkSHjt0t6f86LoOTQ969Jn /IQzDp9Dqz6lp3+jZgeCoQp3fMb+oYsJkxXuLjM/CS4J1n54JENHCy99E/ey5vCku+8zuFBKcjE WSNxD7Kz9nNSTpAtfRLbyJafZHFXbbp9fcBy0= X-Google-Smtp-Source: AGHT+IGlW3H0k9zO3KUAuUhCu3brrjl8Zmq8jrT/neqsuWTj7tdazdx9Nl4f8aM6bKD/6QA3jg6+Hg== X-Received: by 2002:a05:6a21:60c4:b0:1c3:ba3d:3ec3 with SMTP id adf61e73a8af0-1cce109796cmr14688854637.36.1725344063316; Mon, 02 Sep 2024 23:14:23 -0700 (PDT) Received: from hsinchu36-syssw02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20524c16145sm60467145ad.98.2024.09.02.23.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 23:14:22 -0700 (PDT) From: "Fea.Wang" To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , "Fea.Wang" , Frank Chang , Jim Shu Subject: [PATCH 1/5] target/riscv: Add svukte extension capability variable Date: Tue, 3 Sep 2024 14:17:53 +0800 Message-Id: <20240903061757.1114957-2-fea.wang@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903061757.1114957-1-fea.wang@sifive.com> References: <20240903061757.1114957-1-fea.wang@sifive.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=fea.wang@sifive.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Refer to the draft of svukte extension from: https://github.com/riscv/riscv-isa-manual/pull/1564 Svukte provides a means to make user-mode accesses to supervisor memory raise page faults in constant time, mitigating attacks that attempt to discover the supervisor software's address-space layout. Signed-off-by: Fea.Wang Reviewed-by: Frank Chang Reviewed-by: Jim Shu --- target/riscv/cpu_cfg.h | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 96fe26d4ea..636b12e1c2 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -81,6 +81,7 @@ struct RISCVCPUConfig { bool ext_svinval; bool ext_svnapot; bool ext_svpbmt; + bool ext_svukte; bool ext_zdinx; bool ext_zaamo; bool ext_zacas; From patchwork Tue Sep 3 06:17:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fea.Wang" X-Patchwork-Id: 13788073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 347B8CD3432 for ; Tue, 3 Sep 2024 06:15:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slMoC-0004vS-8q; Tue, 03 Sep 2024 02:14:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slMoA-0004pF-GO for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:30 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slMo8-0002Ep-Rk for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:30 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2057917c493so12149395ad.0 for ; Mon, 02 Sep 2024 23:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725344067; x=1725948867; darn=nongnu.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=9nfh143S9vnLrU32qZoavXZ9QOvGGiPS+biYpynrjdo=; b=AnlEHjeUszuv4xWsGBD9MVTC7CFKTK7Zf920qgeCEUr2/qoA1J4S1a5ILzodZUnwaX orHHCtoHi8VK2fISUPVqrHkjHmFLyhtGQCHp57XcegoJPc/PkY66/3dXh2ZT0X3kD1RK zhz1IAnGlfoqfQvlGZupe2KY49z9T1PuTmiNX8NwlRfDINFFVVAReHY1vYRCyXA0HemI CW3DJUz7RRiyyeTQaDW1b1RVHB8YaN1fGZhy2EI5SFeS9BpmgdqYKuELsMZWAspzSeTN oLI5ApRZeycGhu7KxyRx/tHVUuNBXWuQH0sk+63iZTYtLuesdbK492laMx+Z5QPzQ+/P iHEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725344067; x=1725948867; 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=9nfh143S9vnLrU32qZoavXZ9QOvGGiPS+biYpynrjdo=; b=fwe78bJs1QmVge1wfhXCQsoSsxw19iqcomG7gRFQYwuBHjGCH4aSfg5iqvO9ruS24V dTANJ9gUw2w3PHzyTkx9FqDZy547npbeFemBee+T39D/nWWWzk6CTMvY9WwyrysdbUmR A9z8ESvhreP1lEKExTgF7uU13jJ3NMJPGgty4vLLIPHihZFxz++jtm1zilMKad6zP039 pX2p1exd7keG9+GgbA7ARMFnVIlN3R0Ypy3FNDJY1GRbOc3MuW0B8x7V3D48bgLdlXPG Ku9U2EvR2QdX2xm4B3nZfKPvIzLL4Up+3k3p6GgPoGlTFiC8q4GxL+liE5mMC6glfV/7 aQyw== X-Gm-Message-State: AOJu0YzOj9CHUJpyK8vNqW3KrkWev6w0ggPgeTkRnMGp/KsWXrFgzWie m31/iYSBwzTNzXMIFJj2qOQpQ1ejZYZuroQf/NtNPyQGkZRJIMPXUU2LAIvoNh6WUY+jepPg7Uc F1mBzKGyDPoYZsvck6/pJJ1rqVicXA4fzbUcq6yC59wwrURrMIuu8RMGaas4QE8EgHXtQpzX1cX fLx4/CSJ3qIYiTxgZElEuvHfEuEcvZhu1I1jE= X-Google-Smtp-Source: AGHT+IFLcdnT0UzJqAGKytX7UjtV4QgMIHxdRp9ElrguCXNQprAFEEE9fEAis1x8YulhWh4sSNBhUw== X-Received: by 2002:a17:903:228f:b0:205:6a64:3144 with SMTP id d9443c01a7336-2056a6432e3mr99595125ad.27.1725344066530; Mon, 02 Sep 2024 23:14:26 -0700 (PDT) Received: from hsinchu36-syssw02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20524c16145sm60467145ad.98.2024.09.02.23.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 23:14:26 -0700 (PDT) From: "Fea.Wang" To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , "Fea.Wang" , Frank Chang , Jim Shu Subject: [PATCH 2/5] target/riscv: Support senvcfg[UKTE] bit when svukte extension is enabled Date: Tue, 3 Sep 2024 14:17:54 +0800 Message-Id: <20240903061757.1114957-3-fea.wang@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903061757.1114957-1-fea.wang@sifive.com> References: <20240903061757.1114957-1-fea.wang@sifive.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=fea.wang@sifive.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Svukte extension add UKTE bit, bit[8] in senvcfg CSR. The bit will be supported when the svukte extension is enabled. When senvcfg[UKTE] bit is set, the memory access from U-mode should do the svukte check only except HLV/HLVX/HSV H-mode instructions which depend on hstatus[HUKTE]. Signed-off-by: Fea.Wang Reviewed-by: Frank Chang Reviewed-by: Jim Shu --- target/riscv/cpu_bits.h | 1 + target/riscv/csr.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 7e3f629356..54c3ae0a4e 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -770,6 +770,7 @@ typedef enum RISCVException { #define SENVCFG_CBIE MENVCFG_CBIE #define SENVCFG_CBCFE MENVCFG_CBCFE #define SENVCFG_CBZE MENVCFG_CBZE +#define SENVCFG_UKTE BIT(8) #define HENVCFG_FIOM MENVCFG_FIOM #define HENVCFG_CBIE MENVCFG_CBIE diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ea3560342c..6ee6d1a9cd 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2396,6 +2396,10 @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno, return ret; } + if (env_archcpu(env)->cfg.ext_svukte) { + mask |= SENVCFG_UKTE; + } + env->senvcfg = (env->senvcfg & ~mask) | (val & mask); return RISCV_EXCP_NONE; } From patchwork Tue Sep 3 06:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fea.Wang" X-Patchwork-Id: 13788075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B3C9CA101E for ; Tue, 3 Sep 2024 06:15:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slMoE-00055E-S0; Tue, 03 Sep 2024 02:14:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slMoD-00050i-L7 for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:33 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slMoB-0002FC-Ub for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:33 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-205722ba00cso11754975ad.0 for ; Mon, 02 Sep 2024 23:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725344070; x=1725948870; darn=nongnu.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=HGrHAUtc6Oe0+s4X91g1WKyiAEgqhFplpZjvQxzqUvM=; b=AwPPysbhvdeuwWA6xfuWeygjVTApWuQcQLHG9rW6lBPwbvRdD7qoQnYz3/cU+9fAp+ XVF7oMLmBzPGkgQMLblzagGFCo/yPO6zs4+2/PJqrEZ7VsC7yhY+5Pfogv8UYXr/Nn9X dG22/86SBN+EQAk0hypKSv1U0Auop7rrLrmFTnR0cdOI+gvD/GvTz4Z5XmKgutopWfyi YBREda8KSCvbM1Ma9EKbvz1qmkFWXqSePXaVTU+EW1xP8bN9b+znXnMfWfVRVeBLI/cj ph7o/xaadQYfhPbBs6qplYF2MEW2eGoMM065rlYOGCQV9D4oDusTd43+/LlglbfyHeWK SPbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725344070; x=1725948870; 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=HGrHAUtc6Oe0+s4X91g1WKyiAEgqhFplpZjvQxzqUvM=; b=CSZbYsiQF/3LSY+l6UkdGlhjBCddEqEZwr7WZwMS+rY8wmH3yEP4Pa973h2KukV9xD l/COyZk6IExByx5vScsd5b3EgIAtEViMkS/gjN7Iud2rrHGPwXlKkop4iDELmZdyHXnO 5zMzsDVneweK6p0Ze0z4ThD5/RKAGoGO17Rjet1LsMvfQ4f2ZfvgPLqhcL8739nzTiTS IT6sicT184MI2Q7W0LFT6bLMuAY7ynuY80srquQq18dROSVS2YBldbq+Pxk8sdu1Cg26 yfwtLvyWjAT1gOJgyHAyVeF42iZRlrxhZEUS/tPIfBR05hmkVv13jEDatAaqcEfkqZ3v wcZQ== X-Gm-Message-State: AOJu0YwattjWMYUGcnN66dhIA4pVy0u8W6CQyRSvTAj3IYT85rIXXPZh KqElfEPbIDd7WG3+v1HWZ4C8lZB7XCW96v4MfPCAKY/j6WGDTCRp9oxGtEqRFnJUnznyYTgaFMI 9OzXWZZ/mG1XSfvl8paGZz7XL1w+rOra3JAFeQwx5j0QFNAjzOJlNp/qQMG7Ftqq4pn01kI8Fnh y0jBMfg0X6Cy9L9Pe/KetxD86JMNkR5x2p5UQ= X-Google-Smtp-Source: AGHT+IGgDblYLu4YoqREVmIigSlZWUIjjn25hLwT5Wc+rpeN3wTIzOPNa5Sk8ZXp00UM0tgK9T10Yw== X-Received: by 2002:a17:902:d2c2:b0:202:38d8:16c with SMTP id d9443c01a7336-2054733519dmr75286795ad.37.1725344069759; Mon, 02 Sep 2024 23:14:29 -0700 (PDT) Received: from hsinchu36-syssw02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20524c16145sm60467145ad.98.2024.09.02.23.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 23:14:29 -0700 (PDT) From: "Fea.Wang" To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , "Fea.Wang" , Frank Chang , Jim Shu Subject: [PATCH 3/5] target/riscv: Support hstatus[HUKTE] bit when svukte extension is enabled Date: Tue, 3 Sep 2024 14:17:55 +0800 Message-Id: <20240903061757.1114957-4-fea.wang@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903061757.1114957-1-fea.wang@sifive.com> References: <20240903061757.1114957-1-fea.wang@sifive.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=fea.wang@sifive.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Svukte extension add HUKTE bit, bit[24] in hstatus CSR. The written value will be masked when the svukte extension is not enabled. When hstatus[HUKTE] bit is set, HLV/HLVX/HSV work in the U-mode should do svukte check. Signed-off-by: Fea.Wang Reviewed-by: Frank Chang Reviewed-by: Jim Shu --- target/riscv/cpu_bits.h | 1 + target/riscv/csr.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 54c3ae0a4e..8cfc24428e 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -598,6 +598,7 @@ typedef enum { #define HSTATUS_VTVM 0x00100000 #define HSTATUS_VTW 0x00200000 #define HSTATUS_VTSR 0x00400000 +#define HSTATUS_HUKTE 0x01000000 #define HSTATUS_VSXL 0x300000000 #define HSTATUS32_WPRI 0xFF8FF87E diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 6ee6d1a9cd..2b28057e57 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3459,6 +3459,9 @@ static RISCVException read_hstatus(CPURISCVState *env, int csrno, static RISCVException write_hstatus(CPURISCVState *env, int csrno, target_ulong val) { + if (!env_archcpu(env)->cfg.ext_svukte) { + val = val & (~HSTATUS_HUKTE); + } env->hstatus = val; if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) { qemu_log_mask(LOG_UNIMP, From patchwork Tue Sep 3 06:17:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fea.Wang" X-Patchwork-Id: 13788072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6998CD342D for ; Tue, 3 Sep 2024 06:15:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slMoJ-0005Np-Hi; Tue, 03 Sep 2024 02:14:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slMoH-0005Fy-JW for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:37 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slMoF-0002Fd-PJ for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:37 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-7c6aee8e8daso3486618a12.0 for ; Mon, 02 Sep 2024 23:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725344074; x=1725948874; darn=nongnu.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=folyLjZC+gAsCGvjBm1lXgO8dCUSFEawIl5b8lF+iF0=; b=L+cAzWebSa6ky2pLasS1h8A2ykF0ftPqYZxqJC1wSKiw3V2L3h12sFV6FCh1HHphSS ub4lE/gqYua/wl3P7dfC47QuDE3THXPZrdpi86Ror58bwvJ48lz9OIB0DhXqfl8E/aC0 4S8qFd0vutxesAQT9V+fkZyABHdBFQrUBMLDMCyUs9d+krkKWRnEpQzqJk6cscH9PIid 20CY4y2ON2VfOgGGw3Jao65ekD18mHcRgWu+n3kz4ndbmDo15ANLOzhQU6LZ5BKLui6R dwBt0yldcOKrmKmGPzg4lsc/3fyWKKAHszdFv1UZZZG9X+1RenB4RytmkkPPTvlprvKj YCAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725344074; x=1725948874; 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=folyLjZC+gAsCGvjBm1lXgO8dCUSFEawIl5b8lF+iF0=; b=kENaVYlqZpbjiPQb8amiEfFG0ijeKvDeHXjcRBvwf04JKSeNceLiOxXhkKBAle0ZXY AM0MyVPWqoKFyBd4FlnuF+gRTyVo7qloiphdp1ol920CZDJ+VSgvBAoE3/BsLyKhHkaq vvHaDp5SVPtyyIA9kYy8aff5I6gQPm7HEFjcyC7ID7U+gG7kMKkezcjjW0hkFUpXrpbz oXDAJvlfUK/9Ek0jBrdvC9z3FdA4G959fr0ph5K9PM+Ywq1EPfKdAC088Pq8RTa+QYx5 yfih6XERBRCVz6cV4YjwBALQG+4hRn83iGr0UaWMMs6IeWceNu7ZKuO09E0QZgfKSN1Y s/Hg== X-Gm-Message-State: AOJu0YzkpvRA0Nue3rQBrMLD/b4uUkikC2w4GU8ECtpKmBwznUtul9qO RtWDAbv/MIRb1Sfs2TxdMe115N5KfV91CKdUeczacwRFaYxCF2FU+qpdz0nEuh0j6D5UJhPIwhN FCjHvQNEdUpDMoq9Z2IZc016v+kbbqYRFBeA9OtsVhLj/HfDBZzJomvARyBh7zumyncrq+otczt CmfgpmtOVqJ13mNygakL2weC3K56knOe6SETg= X-Google-Smtp-Source: AGHT+IEyN2rUfbGr134wm+tqxlU2vIVN3oo6zzz+Zv6lMjPNdnPHz/LRLxMnKc9te3n3Yelt2JN9hQ== X-Received: by 2002:a05:6a20:c88b:b0:1c4:ba7c:741c with SMTP id adf61e73a8af0-1cecdf0fb58mr11741360637.21.1725344073713; Mon, 02 Sep 2024 23:14:33 -0700 (PDT) Received: from hsinchu36-syssw02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20524c16145sm60467145ad.98.2024.09.02.23.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 23:14:33 -0700 (PDT) From: "Fea.Wang" To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , "Fea.Wang" , Frank Chang , Jim Shu Subject: [PATCH 4/5] target/riscv: Check memory access to meet svuket rule Date: Tue, 3 Sep 2024 14:17:56 +0800 Message-Id: <20240903061757.1114957-5-fea.wang@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903061757.1114957-1-fea.wang@sifive.com> References: <20240903061757.1114957-1-fea.wang@sifive.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=fea.wang@sifive.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Follow the Svukte spec, do the memory access address checking 1. Include instruction fetches or explicit memory accesses 2. System run in effective privilege U or VU 3. Check senvcfg[UKTE] being set, or hstatus[HUKTE] being set if instruction is HLV, HLVX, HSV and excute from U mode to VU mode 4. Depend on Sv39 and check virtual addresses bit[SXLEN-1] 5. Raises a page-fault exception corresponding to the original access type. Ref: https://github.com/riscv/riscv-isa-manual/pull/1564/files Signed-off-by: Frank Chang Signed-off-by: Fea.Wang Reviewed-by: Jim Shu --- target/riscv/cpu_helper.c | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 395a1d9140..db65ed14b9 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -777,6 +777,54 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot, hwaddr addr, return TRANSLATE_SUCCESS; } +/* + * Return 'true' means no need to do svukte check, or need to do svukte and the + * address is valid. Return 'false' means need to do svukte check but address + * is invalid. + */ +static bool check_svukte_valid(CPURISCVState *env, vaddr addr, + int mode, bool virt) +{ + if (VM_1_10_SV39 != get_field(env->satp, SATP64_MODE)) { + /* Svukte extension depends on Sv39. */ + return true; + } + + /* + * Svukte extension is qualified only in U or VU-mode. + * + * Effective mode can be switched to U or VU-mode by: + * - M-mode + mstatus.MPRV=1 + mstatus.MPP=U-mode. + * - Execute HLV/HLVX/HSV from HS-mode + hstatus.SPVP=0. + * - U-mode. + * - VU-mode. + * - Execute HLV/HLVX/HSV from U-mode + hstatus.HU=1. + */ + if (mode != PRV_U) { + return true; + } + + /* + * Check hstatus.HUKTE if the effective mode is switched to VU-mode by + * executing HLV/HLVX/HSV in U-mode. + * For other cases, check senvcfg.UKTE. + */ + bool ukte = (env->priv == PRV_U && !env->virt_enabled && virt) ? + !!(env->hstatus & HSTATUS_HUKTE) : + !!(env->senvcfg & SENVCFG_UKTE); + + if (!ukte) { + return true; + } + + uint32_t sxl = riscv_cpu_sxl(env); + sxl = (sxl == 0) ? MXL_RV32 : sxl; + uint32_t sxlen = 32 * sxl; + uint64_t high_bit = addr & (1UL << (sxlen - 1)); + + return !high_bit; +} + /* * get_physical_address - get the physical address for this virtual address * @@ -814,11 +862,18 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, MemTxResult res; MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; int mode = mmuidx_priv(mmu_idx); + bool virt = mmuidx_2stage(mmu_idx); bool use_background = false; hwaddr ppn; int napot_bits = 0; target_ulong napot_mask; + if (first_stage) { + if (!check_svukte_valid(env, addr, mode, virt)) { + return TRANSLATE_FAIL; + } + } + /* * Check if we should use the background registers for the two * stage translation. We don't need to check if we actually need From patchwork Tue Sep 3 06:17:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fea.Wang" X-Patchwork-Id: 13788076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9A17CA101E for ; Tue, 3 Sep 2024 06:15:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slMoa-0005pZ-QD; Tue, 03 Sep 2024 02:14:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slMoR-0005mv-QX for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:47 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slMoQ-0002GJ-Ax for qemu-devel@nongnu.org; Tue, 03 Sep 2024 02:14:47 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7142a30e3bdso4271244b3a.0 for ; Mon, 02 Sep 2024 23:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725344085; x=1725948885; darn=nongnu.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=wR1GACgrZzM7YYzeZtxjDqa8lje9TmssIu2+ZZwLLUw=; b=WB6HxnHTIqMvpSEwd18xTkuvzGbBYCHALt9NV5uUrxMoX0XUj+GjY07ESuRXBNe0D5 oC/nKN/CHBf2a89Xf4U0PoTMaUOVJMmFPwdCJ5cz38M5wZ9/FgN6N1XsG9R1VQ3YAWKn hQGUHZ7qMPQYaLTSACjCXr8jKfI9ZNXuk2vl8SWW27SzvcqL3l2EGcI2VHzOZc9HzsKr jiUBWyVjAYieEoLYfCAtoB3fEA2XlZJvtZU+Ld+aQoj+jztWrEQ5rZvaLEb5Uo+5nikq p4gCtehLuJLTQZApGtViP87GGXyP2PNFDfN74pS+bPPceCugNSDSDet8t/vqHzBio3qT NwJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725344085; x=1725948885; 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=wR1GACgrZzM7YYzeZtxjDqa8lje9TmssIu2+ZZwLLUw=; b=SSH0btEA1DFTnvNBjIDkrE2QRJOzdtkKx3zTUmk2UsWSrbXz3qCmqydbtGrfRGkw9Q BpQGY8e1w6UiBbLy5/nrgbNUo58SmO2Z5ER29KmfjAAEd9XP370nJ0BG/tWJSsG6qGL/ 9S6VmAUoz7PS4QrssC1iMBW59II9RGveNSuDZL2XH7Qy4Ux1bwn0l4KtvLZzkGH5BUox rZcUOtl42f7LMBMwCsh08hEWX4VR+USFfWtCXz6hh1uD90O3l7h0yoTRwN1U6lukNSgC TD/GFIrCz0Zi2JSvkL+L1Zxkz2hs3g8Xdcg1gssvw5xBi9Hx7jYVYBHrQGLT/lMBcRfJ rpBg== X-Gm-Message-State: AOJu0YxS1N/3W3TPkW6qwqiP17COH4dLg86Ws5Rm8Mda1KysCSVMe8s+ d60IBlMTczkior8KVG1Y6dvk1Snp+ejvAjJxOgRA2GkgNnCM8heC5B7GXVyoidWDIxMSorXcJcn X4A+HT0D5s8ab4Zj86Ac1xTdcnzCvXYg4Q3/bVL0zjM7Wl6azoCFd3Gsf1IEBJpswnGOVVeTbEX NCWlMFV0KmubRPG0ydC0D32n1wS/4VneCELeY= X-Google-Smtp-Source: AGHT+IHnrqov/tdCdxu/H9D4C2PmIbQlFgcZjWjC/5cJOCXrVSACI+28gYp7QCRK+CCzgoZlqmfGtg== X-Received: by 2002:a17:902:e551:b0:205:753e:e2e6 with SMTP id d9443c01a7336-205753ee47emr102309515ad.16.1725344084629; Mon, 02 Sep 2024 23:14:44 -0700 (PDT) Received: from hsinchu36-syssw02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20524c16145sm60467145ad.98.2024.09.02.23.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 23:14:44 -0700 (PDT) From: "Fea.Wang" To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , "Fea.Wang" , Frank Chang , Jim Shu Subject: [PATCH 5/5] target/riscv: Expose svukte ISA extension Date: Tue, 3 Sep 2024 14:17:57 +0800 Message-Id: <20240903061757.1114957-6-fea.wang@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903061757.1114957-1-fea.wang@sifive.com> References: <20240903061757.1114957-1-fea.wang@sifive.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=fea.wang@sifive.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add "svukte" in the ISA string when svukte extension is enabled. Signed-off-by: Fea.Wang Reviewed-by: Frank Chang Reviewed-by: Jim Shu --- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index fc3f75e826..a568194317 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -197,6 +197,7 @@ const RISCVIsaExtData isa_edata_arr[] = { ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), ISA_EXT_DATA_ENTRY(svpbmt, PRIV_VERSION_1_12_0, ext_svpbmt), + ISA_EXT_DATA_ENTRY(svukte, PRIV_VERSION_1_13_0, ext_svukte), ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba), ISA_EXT_DATA_ENTRY(xtheadbb, PRIV_VERSION_1_11_0, ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs), @@ -1597,6 +1598,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { /* These are experimental so mark with 'x-' */ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { + MULTI_EXT_CFG_BOOL("x-svukte", ext_svukte, false), DEFINE_PROP_END_OF_LIST(), };