From patchwork Wed Jul 26 08:43:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327628 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C69B8C0015E for ; Wed, 26 Jul 2023 08:44:16 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=yZAL5gbZtGWOw8M3EDeLV6ITIF6+6Ormd2nxAR8uO0Y=; b=EldZbP834NvcEu 9KJYtEDD/SmPJ9BvFFRMnbVtXDDd5C+Ko+0b7cwKbe/9/EqTcrR8NHL+g5SsIi+ad0U7oTbxONXHD aUp5wK/9BRurE/19CBAXyb3iu7eKb0lPTEh+sSbr1ALlXtBb/5I4hMutZdOm0A756YXBqtJk/BBOz UF+8I4js0llx/TAGFUu7epN8n5ItBz+jpN2PjonB0LTykOePNyNUxeBqQhVZXrxUOm8aeHLtBxxBA WqfW7/LvttteE1EsTX9rabQJ+8nIpTFmlWhHWcJSv59g1fIQ6X51wbwgJQyUJ51KeZf+oQMfXi/me voQk+sn19vO1T/px5zSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa7x-009c4z-2P; Wed, 26 Jul 2023 08:44:13 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa7u-009c3K-2B for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:12 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b9ecf0cb4cso37312315ad.2 for ; Wed, 26 Jul 2023 01:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361048; x=1690965848; 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=O32qj0iS0CQ128y9LZa/4+ORdT9w9cMnSwkHBE7Wcdc=; b=BwAoUmgm2wTc+HtECOxsDTZZecU8XqE5Lj/ftd1WiZN8KOacImkkRn02sHX4nPT/Ir RdjUoPGoKdrTcNDuH/rqbWWiv5kTtrj27XMsX0YZyVX+E8S6RSqZOiZMA9G6ute6LzYu A6PUN/hKGe55DGYlhVMW18W2Gs4+FlAMn1CVU+y2cjGF7ecCMW7X76EQnJaFOjqyuuQz X1GR7owALu1erNetnr8Qc4ErP1J+0EJc8V8z2c9lykKRxjIaEoPQ2h2tczCR90E5M4++ F/gYOKhV3Lx7YeGNCwX9FLOkQlU4Hn2F1QuWCHOgdb0c1wmP+cLPXOxbu7Xh6zvLLkOn 8ghg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361048; x=1690965848; 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=O32qj0iS0CQ128y9LZa/4+ORdT9w9cMnSwkHBE7Wcdc=; b=H8FsnxLOdhbnd3ZHPpWZ/505MsDpVJt1JHIIsP8q4aExXF3nJAkPPt4hFeiNXUFkLe z+qKt/UlUolo+q+2ut/YryTB+Bx2S5ZIm82NcTZkPeboVN3O3hf9LiU92bfvmRePiKXd 1D7Ik+ePHKWk838iyje4Aa5qhg6HLGebqtf318MauOkr442mM3N4vJMg+ndy9SqPKT00 BDqda3bWmlkRv5c1vU1xZJYDNutC5DJgfgH3dou9g3YyoD87yrmti2jwvLjlaNtu6uYd qJHrDh7VrE0/gNcibJltla0vZvJ4zZ77D+Dnlxh1MvyCYHVBZpBtsEvatHhwEF4W7ec4 MKoA== X-Gm-Message-State: ABy/qLaa09zsOda3VJqBraFG1XIVxU6xmLZ4wHdIdub0F2gwhtDaw9+m UYBVBKi7ZJ2P7ag9d9ORvcjhSg== X-Google-Smtp-Source: APBJJlF1UcZfD4GtZQbExiDlryyarP7U0RVaiWEcRPCc9PBWbKK440mq/9FDPD6l/cW9TbDZY/oxaw== X-Received: by 2002:a17:902:a40f:b0:1b8:28f6:20e6 with SMTP id p15-20020a170902a40f00b001b828f620e6mr1074573plq.34.1690361047695; Wed, 26 Jul 2023 01:44:07 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:07 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 1/7] RISC-V: Detect Smstateen extension Date: Wed, 26 Jul 2023 14:13:46 +0530 Message-Id: <20230726084352.2136377-2-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014410_733896_521288D5 X-CRM114-Status: GOOD ( 10.98 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Extend the ISA string parsing to detect the Smstateen extension. If the extension is enabled then access to certain 'state' such as AIA CSRs in VS mode is controlled by *stateen0 registers. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones --- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index f041bfa7f6a0..fad1fd1fcd05 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -53,6 +53,7 @@ #define RISCV_ISA_EXT_ZICSR 40 #define RISCV_ISA_EXT_ZIFENCEI 41 #define RISCV_ISA_EXT_ZIHPM 42 +#define RISCV_ISA_EXT_SMSTATEEN 43 #define RISCV_ISA_EXT_MAX 64 #define RISCV_ISA_EXT_NAME_LEN_MAX 32 diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index a2fc952318e9..fb0df651bc48 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -217,6 +217,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = { __RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB), __RISCV_ISA_EXT_DATA(zbs, RISCV_ISA_EXT_ZBS), __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), + __RISCV_ISA_EXT_DATA(smstateen, RISCV_ISA_EXT_SMSTATEEN), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index a8f66c015229..c3742a765f8b 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -301,6 +301,7 @@ void __init riscv_fill_hwcap(void) } else { /* sorted alphabetically */ SET_ISA_EXT_MAP("smaia", RISCV_ISA_EXT_SMAIA); + SET_ISA_EXT_MAP("smstateen", RISCV_ISA_EXT_SMSTATEEN); SET_ISA_EXT_MAP("ssaia", RISCV_ISA_EXT_SSAIA); SET_ISA_EXT_MAP("sscofpmf", RISCV_ISA_EXT_SSCOFPMF); SET_ISA_EXT_MAP("sstc", RISCV_ISA_EXT_SSTC); From patchwork Wed Jul 26 08:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327629 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A0E58C0015E for ; Wed, 26 Jul 2023 08:44:20 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=X4Ogg+dImdSIaKIDo/kTrGDRYItzKteggITm6gfp+3Q=; b=fi16U3nQJa7wVc NFFXxGrS0TgEyOzZRmhOpbCXyoVei64FhJVe8WbnWTXjFzZ3dcEOWUz9Y4lW/Dk8osj0Sz8G0a2LQ Bz39mQ6riJdI7l31yNt5oY+02qn70iTeMFTAr20aK75BBjxI4if7WLPYQicQC9bLqn02xnmI0LWLL 0/ozV8gChwLEN7PWx/H5Ff2EzE2jNrLv9NtThTTJXMR1qLQFFMPjwhd9OR6DM1PCMwXV/iTMvkPk3 mj2OQMSf8yAlY0/0L1nrOIGcvCoaF0TpEOjQjtPe4gXCoStFhb7xANDiPCXIodBLB8Kkr5PvPCOgy B2Fm6NXlf9J97ATNVPgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa81-009c6W-1N; Wed, 26 Jul 2023 08:44:17 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa7z-009c50-1P for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:16 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-54290603887so3465443a12.1 for ; Wed, 26 Jul 2023 01:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361053; x=1690965853; 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=JqR2RDc36TENwkhRWI02ORvUk5zlxgidXHuawQH9lCY=; b=nlUK5rRbwoL2VhzRVg0zVv8tMWmh5i6cSI3ycOIOo5D46+1/Oj3Z1PlX+i62+rFJ5w lbo89W1s+ZWo1FuJQEcNvr01bFZ5E+iXwjepPMN6v4Df0TAlOoGJNV68dsR33hS3Kish qLMghPo23+FOC44Q9Tm5RT13r+bs+VRfnR5Py8kmU5qVaZSCvrwROf3PwgRHDDxtlOBu TtipXnH0Q74TOj6r5Tpwci1B3Qw2RU2dSabea+XRJ1sPUNCXn2tUy2i//yYT/tJgRBXO VLyoHjAl4VXV8UEUbEgyGK4VihZ/+uTJc6xfRzUsO9cQFEGUM8J1cHuFskek9czV+9no OPdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361053; x=1690965853; 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=JqR2RDc36TENwkhRWI02ORvUk5zlxgidXHuawQH9lCY=; b=QJZyAxlswJlK+0glC7FfOUbwiRk1ZLOwNaVnIUQ4si1asbZMSLHOBMK05vnCppsqn2 Y3ReY9Nmk4AP3/o5dF73ogVZLW9PnsWLopN2NNVYFrOOSZqXZ2EYsABDkjknFKw+gOIE Oj3H2sUSLd0YDZImd5oyX/A2xQjMQeNJ/fhUiXMWplb3Dt37A+D7ijPvdQfqaGg9IwAV JYPEfsvJJkOeTFrXYZwrkqpl5hsrgsKZMtnKoj+X7Y2+e2vYWpYr9jqFc662g6vYF6PN RFzlR3B46s9U7MT3GyfqEgqw6VIRrMjuZQxofLHxO79VgvK5LvxRgmvJDq+BWVV1RrK5 6JSw== X-Gm-Message-State: ABy/qLZOueMcg5me9pFdRfxecHSLVy7DrhD8JMUFmSSquD+lzGrxen4R FaAF1bd3gZg+dYgYFB7FOJDAPg== X-Google-Smtp-Source: APBJJlH592K84ltOhRh3gR6yAOgGgfgy0lypixvCAnYvAI+Q7Scr3ODImmwLsYXSc+lgNqrvJcEdSg== X-Received: by 2002:a05:6a21:6da2:b0:130:46ea:29cb with SMTP id wl34-20020a056a216da200b0013046ea29cbmr1341794pzb.25.1690361053298; Wed, 26 Jul 2023 01:44:13 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:13 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org, Conor Dooley Subject: [PATCH v4 2/7] dt-bindings: riscv: Add smstateen entry Date: Wed, 26 Jul 2023 14:13:47 +0530 Message-Id: <20230726084352.2136377-3-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014415_471269_82B2A0F6 X-CRM114-Status: UNSURE ( 8.67 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add an entry for the Smstateen extension to the riscv,isa-extensions property. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones Reviewed-by: Conor Dooley --- Documentation/devicetree/bindings/riscv/extensions.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Documentation/devicetree/bindings/riscv/extensions.yaml index cc1f546fdbdc..36ff6749fbba 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -128,6 +128,12 @@ properties: changes to interrupts as frozen at commit ccbddab ("Merge pull request #42 from riscv/jhauser-2023-RC4") of riscv-aia. + - const: smstateen + description: | + The standard Smstateen extension for controlling access to CSRs + added by other RISC-V extensions in H/S/VS/U/VU modes and as + ratified at commit a28bfae (Ratified (#7)) of riscv-state-enable. + - const: ssaia description: | The standard Ssaia supervisor-level extension for the advanced From patchwork Wed Jul 26 08:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327630 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 DD130C0015E for ; Wed, 26 Jul 2023 08:44:28 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=GKKmLZnmRxQUDQJO5UHF/0+D++1c7gLM/jmUqrPKW18=; b=FEmOAq3j8gLc6y fHvk3ypNFGnHXhrAsOAS8IcO4mzbTC4B8ltrjDA/IdL2vu9WzWombKGfD/wKgaM8JnSsILIDLG2nv kDToc+/Dspe9FQ9c1jJjaM9ge2ceS3u5LnvUV5nnvrclPpy4ikJnHqUBN3rNetHUKL4BxujpTlSwq /rhxrdXlzcDr3BNlQm1/M4331PFlTPPd1AB8pxAQmKzbhmOnI1pFo980GbLmGwf62uab3oPpwH07M eL26NrYiKniAGln2/Z52c8gNuvVtnptwgHd/LhfP4jqh+zIs23zcAXd9eAb7J2EyKLOut69M+WcvK Hgibig0saDPdUqzCen2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa88-009c9Z-1D; Wed, 26 Jul 2023 08:44:24 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa85-009c71-1C for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:23 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b8ad907ba4so34312915ad.0 for ; Wed, 26 Jul 2023 01:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361058; x=1690965858; 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=bSl78JKjr1Ozi5FVfVkKZdxT71ozQmSZWCuKqW85yyQ=; b=AqEQZOAF8/hH3MUoAOP+XSxHAk++rZYA0dqm8HRoAQkIO7MoM2fbaeAjoZuGALh+QL +7SLmLuYen/TMdB5lKolShu2TN8tD0H44Os8gvqPNZSTZ8mD6TtzEk5VSzOpVBIIrc+1 5Jh9SCPpbuCNttNwWm1zqAli2IbOllrmUIOKP/VBMUXKIyzWv4/gAlmGiENgvB5zOlEr htNU3JFuqPa6Np6nIrtR1gQacTe94rJOk+kNZOfW74ryGJeFyed7fGkrbv+H8Haz5z69 RNZuc9RGhJGKDzg66HwmXT4cFAg/OiOFXLBKIt+5hjVgrOZfL+X6ZRiOwmQiPa/OJ59C GozA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361058; x=1690965858; 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=bSl78JKjr1Ozi5FVfVkKZdxT71ozQmSZWCuKqW85yyQ=; b=By3IOATtusdeOr4FbV3zxjkXZfq68AOrLPwE9fddrvjRks675+bxWOn0XssDoK06BS NPeRkKYkymAbgPEuHwDCRZO4IvSVabPnabhbVdUU23EtRPKyzWrEQzhjSdYYTQei7p20 nPBG4BhBo14+uzTxcZ+NH8SgbZ2i64gKnNS/CAyIE/y/TnKpo7neXB2bw2x219+MVgl0 UFX/DCZ1kDIqunE55ihKPfiUMb4i95fCBVauLuot90M7WVbpHuARAjfE8c3jXxZ9bXX1 itbtbVbu70/me+Yensqlr4iiGO5OgNjr5Up3YhlBQcAJ9xmVkCqlCz4HVwmcGC5TjhHK U6FQ== X-Gm-Message-State: ABy/qLayvVLpIuItyC42Lv4M2i8Oja2R5RF9Rv97kvPSYL5KTUdxGcUv 4jnnrjCtXPJbS4zktvrxiqs2jw== X-Google-Smtp-Source: APBJJlFsfjAuUtDTwjbGLMPtbitCif0Sa9s+E7FgVEnnWkxQxV371oOJKzePeoRwrOEXAKyOueKiuA== X-Received: by 2002:a17:902:f815:b0:1b5:49fc:e336 with SMTP id ix21-20020a170902f81500b001b549fce336mr990692plb.42.1690361058349; Wed, 26 Jul 2023 01:44:18 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:18 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 3/7] RISC-V: KVM: Add kvm_vcpu_config Date: Wed, 26 Jul 2023 14:13:48 +0530 Message-Id: <20230726084352.2136377-4-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014421_410724_A153A7AA X-CRM114-Status: GOOD ( 13.73 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add a placeholder for all registers such as henvcfg, hstateen etc which have 'static' configurations depending on extensions supported by the guest. The values are derived once and are then subsequently written to the corresponding CSRs while switching to the vcpu. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones --- arch/riscv/include/asm/kvm_host.h | 7 +++++++ arch/riscv/kvm/vcpu.c | 27 ++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 55bc7bdbff48..c0fb54d164c7 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -164,6 +164,10 @@ struct kvm_vcpu_csr { unsigned long scounteren; }; +struct kvm_vcpu_config { + u64 henvcfg; +}; + struct kvm_vcpu_arch { /* VCPU ran at least once */ bool ran_atleast_once; @@ -244,6 +248,9 @@ struct kvm_vcpu_arch { /* Performance monitoring context */ struct kvm_pmu pmu_context; + + /* 'static' configurations which are set only once */ + struct kvm_vcpu_config cfg; }; static inline void kvm_arch_sync_events(struct kvm *kvm) {} diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 452d6548e951..43d955eca286 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -453,31 +453,28 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, return -EINVAL; } -static void kvm_riscv_vcpu_update_config(const unsigned long *isa) +static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) { - u64 henvcfg = 0; + const unsigned long *isa = vcpu->arch.isa; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; if (riscv_isa_extension_available(isa, SVPBMT)) - henvcfg |= ENVCFG_PBMTE; + cfg->henvcfg |= ENVCFG_PBMTE; if (riscv_isa_extension_available(isa, SSTC)) - henvcfg |= ENVCFG_STCE; + cfg->henvcfg |= ENVCFG_STCE; if (riscv_isa_extension_available(isa, ZICBOM)) - henvcfg |= (ENVCFG_CBIE | ENVCFG_CBCFE); + cfg->henvcfg |= (ENVCFG_CBIE | ENVCFG_CBCFE); if (riscv_isa_extension_available(isa, ZICBOZ)) - henvcfg |= ENVCFG_CBZE; - - csr_write(CSR_HENVCFG, henvcfg); -#ifdef CONFIG_32BIT - csr_write(CSR_HENVCFGH, henvcfg >> 32); -#endif + cfg->henvcfg |= ENVCFG_CBZE; } void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; csr_write(CSR_VSSTATUS, csr->vsstatus); csr_write(CSR_VSIE, csr->vsie); @@ -488,8 +485,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) csr_write(CSR_VSTVAL, csr->vstval); csr_write(CSR_HVIP, csr->hvip); csr_write(CSR_VSATP, csr->vsatp); - - kvm_riscv_vcpu_update_config(vcpu->arch.isa); + csr_write(CSR_HENVCFG, cfg->henvcfg); + if (IS_ENABLED(CONFIG_32BIT)) + csr_write(CSR_HENVCFGH, cfg->henvcfg >> 32); kvm_riscv_gstage_update_hgatp(vcpu); @@ -609,6 +607,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) struct kvm_cpu_trap trap; struct kvm_run *run = vcpu->run; + if (!vcpu->arch.ran_atleast_once) + kvm_riscv_vcpu_setup_config(vcpu); + /* Mark this VCPU ran at least once */ vcpu->arch.ran_atleast_once = true; From patchwork Wed Jul 26 08:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327631 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2823BC001E0 for ; Wed, 26 Jul 2023 08:44:31 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=q+BXQMyi7YW41Vk8f+DaUBZjfQ52KXyYP8nz3gPXIz0=; b=XrB2Ryfw0/lu6u 4uQZZtCC/egCV/SmAk3qF11y3vUFzRP80TYOTVkbPGYDUtKgCs6LDXxA/dUC4JnbsIrTovesx9lg6 6tYJho9w1mZJXhsRKNhYczP8Fa59ofMCZtzdq6C6Em7N9tfTnAcEVh+z22HI6KbFT06Vrfu27yDQZ whqULucIIr2C/o8en4rKMK8Pvmt4SYB85ggWuxBoeXVnfN35FG3NXJNVR8lLYwp/dyX4seYviemx7 EdaiWFmtmDIHJmWgGvttABvxGFyJ1qtT/1mxVZ50JBZ4wOowAOwOZvm51783ayU9LORUQhlB/XA6A Z140UIi1ttcZIJ50iwXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8B-009cBJ-15; Wed, 26 Jul 2023 08:44:27 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa88-009c98-01 for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:25 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bba54f7eefso4760915ad.1 for ; Wed, 26 Jul 2023 01:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361063; x=1690965863; 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=qAcARu5ZxkxhhYJPR5lGRGBeKU4C8+q0CB3P21eo9N8=; b=h6hKidnpgoyRETT2Q9vc6177CPzk/5C4u8luo1sZ0zBBUL3KfdQpXp/gzLdSPX0i30 Q3Fd+D+tQKNhrwlFdsZ9cW4pGhVzcKfCwOC+lPRvRQIrqrDKKUuy0RtgNsU/1BORaaqA TfHXGUd2l8jSqy31lXaARQuQCLnnf58u5R2XjQdxBfkqZhNr2e8yP6NhoQHd5GglA2Oc Pd5eLbTDqiRGRLf/1pgSg+5U3YXRI79WPkZBf0ri5PVowfyvDc15j0fXzjJzemFPTdro 3+Jxi22JFE3yTmgD/G8STggugsDEgxa6LZmITOtH/OlTbOJfJF74jivniwDyNibN/ic5 LoTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361063; x=1690965863; 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=qAcARu5ZxkxhhYJPR5lGRGBeKU4C8+q0CB3P21eo9N8=; b=J0kClUW+L6Ws3miGHbxWWURPxNtUF++0/cDaeaGfBnycVbSAM/0dnOv2PUcVMgDIr0 EZ3qbddxVGf0Xj6gnePtratcB1fq42ethCYFrYx+LeK68z6OStPpM/6dBDWrWi/tQF/t WRRRuq+r9WHqF+sxQgHQEI8QyCGdQR3J/h6MbogycX277p/F47z9oSjd91SX5efK01MG T8nP9prn3LUqxm6BKWPPN2fEIATIhGCzGiOjRj9foGM1qB15DGE6kFziKLLSQ53vSx5D 3XU2HcGoi8iRsTdtlPdznQfyyxLOodukbJdFBJ957mojNFkuhoCT6bODrpP1tA0uRRSx h9Gg== X-Gm-Message-State: ABy/qLbfuATRKtTOeDAal+CfNrK+IgN89i2KjsZz48BMjJ8sqnxyCfXJ j6vE0hBQRxia9KW6p8yTxedqmg== X-Google-Smtp-Source: APBJJlH8xEYPZjQkD6d1UqCJhsvl91pSiac5LQdtMZXzva2mUldIcZ24xpJLXh+FPkqq95yNXnIiFA== X-Received: by 2002:a17:902:c950:b0:1ae:6947:e63b with SMTP id i16-20020a170902c95000b001ae6947e63bmr1988736pla.16.1690361063331; Wed, 26 Jul 2023 01:44:23 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:23 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 4/7] RISC-V: KVM: Enable Smstateen accesses Date: Wed, 26 Jul 2023 14:13:49 +0530 Message-Id: <20230726084352.2136377-5-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014424_047745_2D815438 X-CRM114-Status: GOOD ( 12.58 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Configure hstateen0 register so that the AIA state and envcfg are accessible to the vcpus. This includes registers such as siselect, sireg, siph, sieh and all the IMISC registers. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones --- arch/riscv/include/asm/csr.h | 16 ++++++++++++++++ arch/riscv/include/asm/kvm_host.h | 1 + arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 7bac43a3176e..38730677dcd5 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -201,6 +201,18 @@ #define ENVCFG_CBIE_INV _AC(0x3, UL) #define ENVCFG_FIOM _AC(0x1, UL) +/* Smstateen bits */ +#define SMSTATEEN0_AIA_IMSIC_SHIFT 58 +#define SMSTATEEN0_AIA_IMSIC (_ULL(1) << SMSTATEEN0_AIA_IMSIC_SHIFT) +#define SMSTATEEN0_AIA_SHIFT 59 +#define SMSTATEEN0_AIA (_ULL(1) << SMSTATEEN0_AIA_SHIFT) +#define SMSTATEEN0_AIA_ISEL_SHIFT 60 +#define SMSTATEEN0_AIA_ISEL (_ULL(1) << SMSTATEEN0_AIA_ISEL_SHIFT) +#define SMSTATEEN0_HSENVCFG_SHIFT 62 +#define SMSTATEEN0_HSENVCFG (_ULL(1) << SMSTATEEN0_HSENVCFG_SHIFT) +#define SMSTATEEN0_SSTATEEN0_SHIFT 63 +#define SMSTATEEN0_SSTATEEN0 (_ULL(1) << SMSTATEEN0_SSTATEEN0_SHIFT) + /* symbolic CSR names: */ #define CSR_CYCLE 0xc00 #define CSR_TIME 0xc01 @@ -347,6 +359,10 @@ #define CSR_VSIEH 0x214 #define CSR_VSIPH 0x254 +/* Hypervisor stateen CSRs */ +#define CSR_HSTATEEN0 0x60c +#define CSR_HSTATEEN0H 0x61c + #define CSR_MSTATUS 0x300 #define CSR_MISA 0x301 #define CSR_MIDELEG 0x303 diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index c0fb54d164c7..d00b61620f54 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -166,6 +166,7 @@ struct kvm_vcpu_csr { struct kvm_vcpu_config { u64 henvcfg; + u64 hstateen0; }; struct kvm_vcpu_arch { diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 9c35e1427f73..dc185e7875ce 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -130,6 +130,7 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_ZICSR, KVM_RISCV_ISA_EXT_ZIFENCEI, KVM_RISCV_ISA_EXT_ZIHPM, + KVM_RISCV_ISA_EXT_SMSTATEEN, KVM_RISCV_ISA_EXT_MAX, }; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 43d955eca286..7ce250087aed 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -469,6 +469,16 @@ static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) if (riscv_isa_extension_available(isa, ZICBOZ)) cfg->henvcfg |= ENVCFG_CBZE; + + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) { + cfg->hstateen0 |= SMSTATEEN0_HSENVCFG; + if (riscv_isa_extension_available(isa, SSAIA)) + cfg->hstateen0 |= SMSTATEEN0_AIA_IMSIC | + SMSTATEEN0_AIA | + SMSTATEEN0_AIA_ISEL; + if (riscv_isa_extension_available(isa, SMSTATEEN)) + cfg->hstateen0 |= SMSTATEEN0_SSTATEEN0; + } } void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) @@ -488,6 +498,11 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) csr_write(CSR_HENVCFG, cfg->henvcfg); if (IS_ENABLED(CONFIG_32BIT)) csr_write(CSR_HENVCFGH, cfg->henvcfg >> 32); + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) { + csr_write(CSR_HSTATEEN0, cfg->hstateen0); + if (IS_ENABLED(CONFIG_32BIT)) + csr_write(CSR_HSTATEEN0H, cfg->hstateen0 >> 32); + } kvm_riscv_gstage_update_hgatp(vcpu); From patchwork Wed Jul 26 08:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327632 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 0A26BC0015E for ; Wed, 26 Jul 2023 08:44:37 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=OeilCiCnwXox9a/imztxggwB4eE7CkghtZGgyxzXCRI=; b=rdFyQ/+IbcMYco 76dVPM/27Q2a4PdtaMB67dBmjhF7MlvL+R1Fch8E+8Oab02bX/fQXkwR7nOGBpdWVXY3TSvDzF62x MtZ1wlP5vjbQwcarf/ppecxlLcsd6XG8/OwHyDOlq7ArFPN/zDVbIgcQt6hKPyxlVp88nD/B/gTDg v0MSe5MMQ37lqbqhx3sClMdcvAGpADL65IsDS28D7UtBIU+BE9pOu3F4pacpXeYkCTkgtJp4M4OMJ tmPspx26mkCKzYEKZjsP2TsrLuuvCJ5zEUKb4GW5k50TZTqTCCPeqf0cPt7BR9d8LdN5y/3ikB0Hd f1bwSS5hh7QXHwvBIajg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8H-009cEr-1T; Wed, 26 Jul 2023 08:44:33 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8D-009cCh-1H for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:31 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b9e9765f2cso34265085ad.3 for ; Wed, 26 Jul 2023 01:44:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361069; x=1690965869; 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=Xkwt55ASzalurZDhelB085cYknOoaxiIqUh90s6et6s=; b=eG630qlQB7KXIlEHP1M7zhLY6CuIH2iNku217voDlUNi4pBNWZwHDFYX3sq2PtfjGW GrZ8BIeEsbR7+gZdEwo6KiBr2w64+E1sr+f400qWzSiRL75idQbOMMYQeGrUqwa9TLAo ZEsL1FP43CCXvd1cB8txpwcibQabdlBKIeIkOFXAXa4mJQDnvYCso4xQpb/ZphCYcx8R x2LeDRSMb8Yf44ZfvmWKqlhPY3ugrDLp2Bu/WaEkM6Lo4BfuOplbgXMjuzKwBlFbscYn 5jL2+8466PpVe9n7u12pa571CH+zGwpiek1m/cdzK4L0wXdVz3yqRE+VZeDzXAErTxsX +i+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361069; x=1690965869; 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=Xkwt55ASzalurZDhelB085cYknOoaxiIqUh90s6et6s=; b=FYuCQfuvCobsxXDdgDzS76De2TN0LwAeI++qKodHDM+mzZfr3WHcsk4aM+VYTcdgeQ 9vfu7y7shTXa5lT4Zszy+Uzrud5xJHbFp5BDaXeRXza03sA3lRu7g/druTV0MHal0kAu b3GL65IhkYfA5Ho3dqZgghXB4rHb3B2IGPVE3UWRA62h9vE1qiWSq8cNt0LKgQMsBmd1 +pEUqHgNK5iSpsqjVPFNhkeP+ooPMVZ2KtJ7ax080+x4U1KFaIKyJW1r+dnE7lnUxIRE fqTQQCDLO9ij9TBxHlA6OjlzhYSI8izrF+TboEhcfxAYoGXnSkEqJFXmA+3sPq87kwiQ V1tw== X-Gm-Message-State: ABy/qLbwMi6VFn3Crg6kCha7DQQk/htTeLC83zgubQDINY20zOMGbgZ9 liI4zzx6PdVWATGTldgvkCZtUA== X-Google-Smtp-Source: APBJJlE3K7rG2ZbmVz2XlDZyVkQYtuoWgWvqT+MC5/m/wIva7uAAwsTNT0Zp52al8a0wgpSLotCZPA== X-Received: by 2002:a17:903:50e:b0:1b8:50ae:557 with SMTP id jn14-20020a170903050e00b001b850ae0557mr977806plb.36.1690361068391; Wed, 26 Jul 2023 01:44:28 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:28 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 5/7] RISCV: KVM: Add senvcfg context save/restore Date: Wed, 26 Jul 2023 14:13:50 +0530 Message-Id: <20230726084352.2136377-6-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014429_826089_293D1EF9 X-CRM114-Status: GOOD ( 12.49 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add senvcfg context save/restore for guest VCPUs and also add it to the ONE_REG interface to allow its access from user space. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/kvm_host.h | 2 ++ arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 16 ++++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 38730677dcd5..b52270278733 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -285,6 +285,7 @@ #define CSR_SIE 0x104 #define CSR_STVEC 0x105 #define CSR_SCOUNTEREN 0x106 +#define CSR_SENVCFG 0x10a #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142 diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index d00b61620f54..53d1c7e1eea4 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -162,6 +162,7 @@ struct kvm_vcpu_csr { unsigned long hvip; unsigned long vsatp; unsigned long scounteren; + unsigned long senvcfg; }; struct kvm_vcpu_config { @@ -188,6 +189,7 @@ struct kvm_vcpu_arch { unsigned long host_sscratch; unsigned long host_stvec; unsigned long host_scounteren; + unsigned long host_senvcfg; /* CPU context of Host */ struct kvm_cpu_context host_context; diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index dc185e7875ce..7a43d08c3eed 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -79,6 +79,7 @@ struct kvm_riscv_csr { unsigned long sip; unsigned long satp; unsigned long scounteren; + unsigned long senvcfg; }; /* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 7ce250087aed..0f4f0d6032cc 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -601,6 +601,20 @@ static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu) kvm_riscv_vcpu_aia_update_hvip(vcpu); } +static __always_inline void kvm_riscv_vcpu_swap_in_guest_state(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + + vcpu->arch.host_senvcfg = csr_swap(CSR_SENVCFG, csr->senvcfg); +} + +static __always_inline void kvm_riscv_vcpu_swap_in_host_state(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + + csr->senvcfg = csr_swap(CSR_SENVCFG, vcpu->arch.host_senvcfg); +} + /* * Actually run the vCPU, entering an RCU extended quiescent state (EQS) while * the vCPU is running. @@ -610,10 +624,12 @@ static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu) */ static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu) { + kvm_riscv_vcpu_swap_in_guest_state(vcpu); guest_state_enter_irqoff(); __kvm_riscv_switch_to(&vcpu->arch); vcpu->arch.last_exit_cpu = vcpu->cpu; guest_state_exit_irqoff(); + kvm_riscv_vcpu_swap_in_host_state(vcpu); } int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) From patchwork Wed Jul 26 08:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327633 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 EC1ABC001DC for ; Wed, 26 Jul 2023 08:44:42 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=hwqBolMThaqGn5bGlqMNQGoMrLspiVIRq3JvoHlRCtw=; b=jntk+Hs+KSP+fm qPkUV5AlQztM3AgnUHJNchfrW8knBsgxQEHqzZuwxXmdoSGQkmOG7KjDUXMadDzVktME8jRwThNzy UBvaKb5LPERMIlJ5onf12QhO1cmkpgI1UJoiMDFcsTh73R72i4yhfWIzEY+CVz3xvfYjJYuawDN1G Ri5II02dZMz0HkSkTM25146mvbyufE1VyojAMV7MGPt6W/zWnDQyMTU3576pcOechqi8WrF8/pRtC o9e0lM99KF76qsVnfHuKxu1vQJjr2/VZuMR1K8ebPBFAJQ6vQw1ASuKOMDytoWfGEXBn0yqQ6LzrQ TK8O1YT+YWKjiRZ73V+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8M-009cK8-37; Wed, 26 Jul 2023 08:44:38 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8K-009cFW-0p for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:37 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bb7b8390e8so21056885ad.2 for ; Wed, 26 Jul 2023 01:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361074; x=1690965874; 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=S83lKR12v2b2CNGJrryAuoUc3tc0JGwPpbCg6Cfe0sw=; b=l2nOi3hjUjFYAo6UFU2jZf5p8Gl38Itq2YMWjZ7bvNI/X/4dFCvWvAAlE82lz9yoXA dL2dwlNoAg9jlrI/9cgJJAiwIO4XTwJnaX2mObAPSRDfZRhojD1wMi5WO4e8od/UC/mS PuZUeJqr/yc2wiryM5ymzvv6HzsSqmWQ/qwRwatuAjQcazaxdp7XiXwy3IiYZgrZx4EF HaUXM4Ly2TuAd1FuhcC5ZrmTCbEKlNucs5nik9N/rvOMtMomqgO6gVZovtQW/QKnAXaU 6UE7YPwM2WSX7htDvElxOBO6VAsibhSp3CwXluVDCofEQ4AZKOhonc0tRKA4dpNmVlhM 7JxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361074; x=1690965874; 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=S83lKR12v2b2CNGJrryAuoUc3tc0JGwPpbCg6Cfe0sw=; b=W5k/H9yLejLCy5QHAynqqrj88j0zw59nS+gSFhaaDgVVslI8T10/uX2lAfV49AK3SX DHxs27lupHISkGExcAgVx+8lG3q65yqmbeTWCIlX1nJgGd4d+1POTaC3Xs65jWBzxQWf JPt6Q6kITUKcgKQmaGhx8/fvTVZ9kMrkTPvQAeYclR1ncn/cDqEtLW6xAGg3mgrfHmVS pSGCgODoJTo7S6VX49ehWbwU2guQw/T9tgmTCr02bv/2nJaME8QcmwlT4GvpQrQD5WCu bvyJLt5VuG5TjXB7nxXC5N+8w/rfwYHGTXp0y65mEL337Dg/AkPAPiJTRo5TwpW0RFXf j7AQ== X-Gm-Message-State: ABy/qLYfPvjYJMChdIn6sg6HjvsSB1u7yjo/ROWqdpOBFL4DXxQWk1jp 1jo/oJBGtGLLQX8OrpMyxLTk0g== X-Google-Smtp-Source: APBJJlFV12aMDrfin7w7RiKN4BpdcTNkkbIpQhNmJ8MHeh9fkEHIdAwkqwkq5bxoypKSwltyMqTZ+Q== X-Received: by 2002:a17:902:e80f:b0:1bb:3406:a612 with SMTP id u15-20020a170902e80f00b001bb3406a612mr1358952plg.57.1690361073815; Wed, 26 Jul 2023 01:44:33 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:33 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 6/7] RISCV: KVM: Add sstateen0 context save/restore Date: Wed, 26 Jul 2023 14:13:51 +0530 Message-Id: <20230726084352.2136377-7-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014436_321255_F415CA20 X-CRM114-Status: GOOD ( 13.16 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Define sstateen0 and add sstateen0 save/restore for guest VCPUs. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/kvm_host.h | 8 ++++++++ arch/riscv/kvm/vcpu.c | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index b52270278733..5168f37d8e75 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -286,6 +286,7 @@ #define CSR_STVEC 0x105 #define CSR_SCOUNTEREN 0x106 #define CSR_SENVCFG 0x10a +#define CSR_SSTATEEN0 0x10c #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142 diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 53d1c7e1eea4..6d614022bf3e 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -170,6 +170,10 @@ struct kvm_vcpu_config { u64 hstateen0; }; +struct kvm_vcpu_smstateen_csr { + unsigned long sstateen0; +}; + struct kvm_vcpu_arch { /* VCPU ran at least once */ bool ran_atleast_once; @@ -190,6 +194,7 @@ struct kvm_vcpu_arch { unsigned long host_stvec; unsigned long host_scounteren; unsigned long host_senvcfg; + unsigned long host_sstateen0; /* CPU context of Host */ struct kvm_cpu_context host_context; @@ -200,6 +205,9 @@ struct kvm_vcpu_arch { /* CPU CSR context of Guest VCPU */ struct kvm_vcpu_csr guest_csr; + /* CPU Smstateen CSR context of Guest VCPU */ + struct kvm_vcpu_smstateen_csr smstateen_csr; + /* CPU context upon Guest VCPU reset */ struct kvm_cpu_context guest_reset_context; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 0f4f0d6032cc..30dd9e3261dd 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -603,16 +603,28 @@ static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu) static __always_inline void kvm_riscv_vcpu_swap_in_guest_state(struct kvm_vcpu *vcpu) { + struct kvm_vcpu_smstateen_csr *smcsr = &vcpu->arch.smstateen_csr; struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; vcpu->arch.host_senvcfg = csr_swap(CSR_SENVCFG, csr->senvcfg); + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN) && + (cfg->hstateen0 & SMSTATEEN0_SSTATEEN0)) + vcpu->arch.host_sstateen0 = csr_swap(CSR_SSTATEEN0, + smcsr->sstateen0); } static __always_inline void kvm_riscv_vcpu_swap_in_host_state(struct kvm_vcpu *vcpu) { + struct kvm_vcpu_smstateen_csr *smcsr = &vcpu->arch.smstateen_csr; struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; csr->senvcfg = csr_swap(CSR_SENVCFG, vcpu->arch.host_senvcfg); + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN) && + (cfg->hstateen0 & SMSTATEEN0_SSTATEEN0)) + smcsr->sstateen0 = csr_swap(CSR_SSTATEEN0, + vcpu->arch.host_sstateen0); } /* From patchwork Wed Jul 26 08:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327634 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5E56CC0015E for ; Wed, 26 Jul 2023 08:44:47 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=/1f74u6/NfAnIiAT8p6dySwNbsbqdbCh77uhEcXOumQ=; b=OTi2ba2b6KUHTI vjEB4a1ydu7uW29BJ0mx0YgCJ0L/DvGNmKCS96PxV0tBZXu9hyNJBMZFVryGjM3B9JX7Do3R0f1RK 5KDGtEYi8Vo20IigxiFpBz4hD/qcYIqJWCQe650fqVD/Mx1Th++sOT53T4qbvSqNpdY1X9WzYj8IA MSywu4RRT5GEnUO8s7ctTU9cadLu02aZfegNS9cnXeTwKb5z72by0ggmmhV2R/in1y+4UDnlVR+03 4qYynoM2LzE870DWkUirsW6oeULsjmtRExWV6lqrfiT7QB71zTe3sxMv9M3uoHz+cymrWQt1AZ4B7 758TOeTfQQdWdX0SIaVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8S-009cNm-14; Wed, 26 Jul 2023 08:44:44 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa8O-009cKO-2i for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:42 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1b8ad8383faso49193375ad.0 for ; Wed, 26 Jul 2023 01:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361079; x=1690965879; 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=jq7CatpLvEuamo8s3Q0+Xj2eL2B+J8eMtzZwBU9xifI=; b=CDJ5Frer1O2G8FhQCsxljDvfHgI9sNZeIBtVCrG0/I8KI2DfKVMIXtK1f3WPBe183c 6AWp5YaRzM0WQWqzJJXfxFTgPjw2/MANBEfvTz4hK9cLmcVp7hHJte3tHgUJHxz1AdAV liQ8mMsLBq6Q0KDHYaJP8C11hC4n5dZSXmoQI067n6TCkGfz0Ov7ulE2XYnXUZqmSxLK 9kCaMGfRFBxEOrtoh9h+xc2yTnKxUKU22XkHPpZP9zgWYirxod2BPBz4Elk5UuUfPhX+ v9ss9A1s/iTgE8O8UPD+XVNuPHlSSVCCUuwfhw62KxbdbabnvNwuXQokX3rdxvD5h5Of xAHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361079; x=1690965879; 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=jq7CatpLvEuamo8s3Q0+Xj2eL2B+J8eMtzZwBU9xifI=; b=cZBV1V9GxBtV1nCkjxH4FxQ0dyQ3MSRVXxqnw5b3TWcdpaijGx8wS5cp35zMyCzaAw 46AC0Y1/a8sFpLd+aJUkUBnZJ/Pncer4vj2KJsF0ZBvCkCgK1lwo8ASTbzRrtBM38DeP Y7BdTU50jnEILQL+2Vzo2o1+PhGMuGG5xRX33gEeH1/W/NlA7cNO9NLyIH+5gf0G5S/r U00jqDPTmLuGX/42L+PBya8wqZbR/JCBVFDmcs2EpEE9acw1t4XeQA1R/1szgdbEpFoe 6g4rblDRJjSc7rh9JPmGMYnsY1gHRyX08nGSEcqAbEG4oohcqLrh45u7OJiQ4p9kyWcI zUSg== X-Gm-Message-State: ABy/qLZMDGttv7tuD/F3MuH93BL9ccr0HbUrrKL7X+QZYBysDqRrjaOU kdygsoJMP9hMj6rzbnhstCDhZA== X-Google-Smtp-Source: APBJJlHz6r3/3jHGuEGLyXcyY2FTESfSup8IkUNWJtj0Ni8hH5kEK3u0sqlFMldEiX74b/dZ7oFlFg== X-Received: by 2002:a17:902:e88a:b0:1bb:1e69:28c0 with SMTP id w10-20020a170902e88a00b001bb1e6928c0mr1885397plg.30.1690361078782; Wed, 26 Jul 2023 01:44:38 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:38 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 7/7] RISCV: KVM: Add sstateen0 to ONE_REG Date: Wed, 26 Jul 2023 14:13:52 +0530 Message-Id: <20230726084352.2136377-8-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726084352.2136377-1-mchitale@ventanamicro.com> References: <20230726084352.2136377-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014440_897732_7D6BD967 X-CRM114-Status: GOOD ( 13.22 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add support for sstateen0 CSR to the ONE_REG interface to allow its access from user space. Signed-off-by: Mayuresh Chitale Reviewed-by: Andrew Jones --- arch/riscv/include/uapi/asm/kvm.h | 9 +++++++ arch/riscv/kvm/vcpu_onereg.c | 41 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 7a43d08c3eed..fd3866cc08a2 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -93,6 +93,11 @@ struct kvm_riscv_aia_csr { unsigned long iprio2h; }; +/* Smstateen CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +struct kvm_riscv_smstateen_csr { + unsigned long sstateen0; +}; + /* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_timer { __u64 frequency; @@ -179,10 +184,14 @@ enum KVM_RISCV_SBI_EXT_ID { #define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT) #define KVM_REG_RISCV_CSR_GENERAL (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) #define KVM_REG_RISCV_CSR_AIA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_CSR_SMSTATEEN (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT) + #define KVM_REG_RISCV_CSR_REG(name) \ (offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long)) #define KVM_REG_RISCV_CSR_AIA_REG(name) \ (offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long)) +#define KVM_REG_RISCV_CSR_SMSTATEEN_REG(name) \ + (offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long)) /* Timer registers are mapped as type 4 */ #define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT) diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index 0dc2c2cecb45..2d1ea5bb2a1d 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -49,6 +49,7 @@ static const unsigned long kvm_isa_ext_arr[] = { KVM_ISA_EXT_ARR(ZIFENCEI), KVM_ISA_EXT_ARR(ZIHINTPAUSE), KVM_ISA_EXT_ARR(ZIHPM), + KVM_ISA_EXT_ARR(SMSTATEEN), }; static unsigned long kvm_riscv_vcpu_base2isa_ext(unsigned long base_ext) @@ -350,6 +351,34 @@ static int kvm_riscv_vcpu_general_set_csr(struct kvm_vcpu *vcpu, return 0; } +static inline int kvm_riscv_vcpu_smstateen_set_csr(struct kvm_vcpu *vcpu, + unsigned long reg_num, + unsigned long reg_val) +{ + struct kvm_vcpu_smstateen_csr *csr = &vcpu->arch.smstateen_csr; + + if (reg_num >= sizeof(struct kvm_riscv_smstateen_csr) / + sizeof(unsigned long)) + return -EINVAL; + + ((unsigned long *)csr)[reg_num] = reg_val; + return 0; +} + +static int kvm_riscv_vcpu_smstateen_get_csr(struct kvm_vcpu *vcpu, + unsigned long reg_num, + unsigned long *out_val) +{ + struct kvm_vcpu_smstateen_csr *csr = &vcpu->arch.smstateen_csr; + + if (reg_num >= sizeof(struct kvm_riscv_smstateen_csr) / + sizeof(unsigned long)) + return -EINVAL; + + *out_val = ((unsigned long *)csr)[reg_num]; + return 0; +} + static int kvm_riscv_vcpu_get_reg_csr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { @@ -373,6 +402,12 @@ static int kvm_riscv_vcpu_get_reg_csr(struct kvm_vcpu *vcpu, case KVM_REG_RISCV_CSR_AIA: rc = kvm_riscv_vcpu_aia_get_csr(vcpu, reg_num, ®_val); break; + case KVM_REG_RISCV_CSR_SMSTATEEN: + rc = -EINVAL; + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) + rc = kvm_riscv_vcpu_smstateen_get_csr(vcpu, reg_num, + ®_val); + break; default: rc = -EINVAL; break; @@ -412,6 +447,12 @@ static int kvm_riscv_vcpu_set_reg_csr(struct kvm_vcpu *vcpu, case KVM_REG_RISCV_CSR_AIA: rc = kvm_riscv_vcpu_aia_set_csr(vcpu, reg_num, reg_val); break; + case KVM_REG_RISCV_CSR_SMSTATEEN: + rc = -EINVAL; + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) + rc = kvm_riscv_vcpu_smstateen_set_csr(vcpu, reg_num, + reg_val); + break; default: rc = -EINVAL; break;