From patchwork Mon Jul 24 14:20:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324855 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 8F42DC001B0 for ; Mon, 24 Jul 2023 14:20:57 +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=WfvSeAJZvCyh59vmrHSXLHQb5JQswY4CDaKVZ7jfUGw=; b=bbzvblJwSc/sYO /+krRcaUELjb9uJMrcQmhQFCrhSWAMbruq6pm+kXKhCLkxjIc/CFrGUCWtG2hVvo0+cP5b7/cI5G/ a9DDbgid8C3/hEGfm12qR+wCOomAaRKbhZ4Iev64F1gFr8ICntk2MmDV4zqx97YNIbVFjZ8vnRpHn PEbNFc/jOs7yXXKya/2AZ5+MQeGHigHiirzq922I7evTvQGI7La1mTy9l97Kq5mVTKMvxH6/Zof4Y VBWkdPo99E4jPoZrj+wrHYUq1Hr5/qy6H9lSlol/xzvtpaVRNmR2u+MfofvN4fRx+tp4ayWAfzYht 6DutAPztU9JQIJckB7gQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwQf-004aYJ-1w; Mon, 24 Jul 2023 14:20:53 +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 1qNwQc-004aWm-1P for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:20:51 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b9d80e33fbso24441295ad.0 for ; Mon, 24 Jul 2023 07:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208449; x=1690813249; 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=xA2xKVDlTfhJaNwFbFuXOx8UsiAOIvWBIr+xpGIDHbw=; b=Ti7MinIAsiXaxrUK9+vbFPfIJZw9yh5briqdt2G4FzLvgLbKNtQvj8lRk6Jxu8he00 tBoBQxUgLAyqEDIIrJLWnZOrtgM+Cl+g75CdtJU+eGsUbrQukAb/sk86a7uTl1kF0MEO G2HjLVvjJ4e0SC2jgNBt9XREGqtnKUcLW6yaGJqIxJexYb1v1pfQNl57wB5uF+CeSbMu ggknQQnG+qS3mLj6ilvvNs8bG+aPFNZlSAYC9srmqEzyd0hCSNFj0GNmAOXxUSBR4jxj AfR2fXBRUdRaD/8etMel8v/f/MqsTCt+jEe9YfbN7mNPXPX8sW+pKpAtKAYQo00io3fj QWYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208449; x=1690813249; 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=xA2xKVDlTfhJaNwFbFuXOx8UsiAOIvWBIr+xpGIDHbw=; b=P2HvPGtx3S3k7dUVdxk4J7zPRjw/DYkYHrbIpKDXYtytNvCsXYjVc2pbJePrXVEfRD kEr1j+xEa4skVSM2mJLpuNMzKkJdQXUKkMg6tFU/xuYfq0W2noQ7MtpZplZRvN9dJeNb KESy0c91PabyXb1+4tyD68I9JgWGGs92vZPGfz1FZPp+OB+gWPKIBEm4YP7hvwxsE88/ t5/fLNeD9e+UragfwcMKNqEYLMczzePxgP5oxyahtjGV1wIS2ktQB2RKhYzoEWuR0KjB Ygynr9FV5eAk7krfHbnCj0Binu/mFKEOwNHhSRALWtrcH2JhQlXVejUC7IE5iNAxcpxg Z8Tw== X-Gm-Message-State: ABy/qLZnUEKTWEwyJasowZQ7l6q1XnNT5k9m/jy/mzvXVOZe0jXDAknr Wq0dismRLHSG+Hp2f11/+FJqcw== X-Google-Smtp-Source: APBJJlHPt6y/N05egGPuqcnG8ZCXhgJ+77H629QsBZHfvLDHAUCNTQjZG9Jyiv3v1HjRVo5UAXElsQ== X-Received: by 2002:a17:902:ea0a:b0:1b3:c7c1:8ded with SMTP id s10-20020a170902ea0a00b001b3c7c18dedmr9467459plg.27.1690208449126; Mon, 24 Jul 2023 07:20:49 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:20:48 -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 v3 1/7] RISC-V: Detect Smstateen extension Date: Mon, 24 Jul 2023 19:50:27 +0530 Message-Id: <20230724142033.306538-2-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072050_477843_16192926 X-CRM114-Status: GOOD ( 10.28 ) 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 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 Mon Jul 24 14:20:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324856 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 30912C001DF for ; Mon, 24 Jul 2023 14:21:02 +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=augNdg5Kwn732LebLjI7SAvUGSSQ0Ye9mfU0FskQfv0=; b=tiPu48ehc8o5V/ zYpebcSeAMFp+NNZsk57BTIaMcHckmXdoU5hhyChfgmHsRk6+AqAERFUncJ+c8honOIQK5QxY04bs aXqgNpm/9Swwritavr/+bvi8BZnD5bBbJpLxlRFAQDIUlEt9YqQAT2bOl5APSP2fU6uhA9M3fWCbm o7P3pg3iVCjTgKErGxw4AkLhbmJcXIJe3yHEWdFwpePZxoElSEIiOaH03B5iz08bEdtnv+CH805ej jTrzWKlyvXNCkdIB9P3pqJGFymTB58LRPw84KYtaDk7LVHcI26pPhLiqUwctnnbTdK8OJOzCh/CfI DPbnLSSQsPIKpyQooedQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwQk-004aac-1u; Mon, 24 Jul 2023 14:20:58 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qNwQh-004aYu-1l for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:20:56 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-66872d4a141so2407119b3a.1 for ; Mon, 24 Jul 2023 07:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208454; x=1690813254; 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=xufKQxJZ1yMufxzMxtt76Rklm7qyQEzWEW8M8cPFlHM=; b=bC6GYsoh/H3PR+/JPzzVT2fMBcYc6uYovUuNhtlxPoNWVAqKq5UNsJdieKixeX/tod 1ZV0pTnpatWWYx/p4XgSry+qNGMAhi/bVja3zNa7LNY3iSUD4lnztOR3OLeSfZDAwa1I kAH2qozVJb9imAZApR20rY2plXzKZiouGGgVFMSoc1nDfSEw3L5YSdSNKaGlFQ81p2mh eQfjF/8iLqwDZ6b5cPQi6fkvoWA7NODznBZOrjcoqIPxQlU3XkE8Gr+dFMQVzEqnvtT1 2TItRA+Hz4FVq1Pnur4ItSXg9nPw+ABSUYuEmrVAw2vJ8oDPfoWGlE/W3iN/JRCCaVCb Cuew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208454; x=1690813254; 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=xufKQxJZ1yMufxzMxtt76Rklm7qyQEzWEW8M8cPFlHM=; b=bboDQg1vmaSkdyWxzv7Yn2PBzRLaBEXGSuZJKULYNDJViT/SvlMNFlisy6jKu4T3VE co6emnhzDM0gzgQHclKN5cLGsKOAEiTRfuE9G6jltS8y1OcitvbXa/gQWy3+HCn4M9+T JOWiP8xEsQrWQH1K4IgKgyBd3+mNQYUQ/Yf5UP3peKAOPlaQVsdNaJ88D3RoZ9DewQds X7JJ/Scs+L2+jjODfivdTjThhdGMe/2bIv1W7uSyE6MSb9jdEti9B/oyseaeS9nthRsL tpT1YoR6vCoG44IV/y+b3UHcceSZUQPLyQRj7K8BbC/7pzYm1VP1m+ePaJQ5h+mV7gHW j21Q== X-Gm-Message-State: ABy/qLa2ZrwgZ4VYzgni8iJ7OrCwODgiZMyXjtYbb3og0A5o1xX9g+Al MM6WJmD2mbUcpNdA3tEVmLNEKQ== X-Google-Smtp-Source: APBJJlEo3gtTsxiR0fYDOZcP5/iHY2QuQDqA3+tze14PsUJjDAVDEFqk1Zsr4maai1yipTLksmB6mw== X-Received: by 2002:a05:6a21:32a9:b0:137:514a:984f with SMTP id yt41-20020a056a2132a900b00137514a984fmr9109819pzb.35.1690208454453; Mon, 24 Jul 2023 07:20:54 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:20:54 -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 v3 2/7] dt-bindings: riscv: Add smstateen entry Date: Mon, 24 Jul 2023 19:50:28 +0530 Message-Id: <20230724142033.306538-3-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072055_581192_64663B0E X-CRM114-Status: UNSURE ( 8.38 ) 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 Mon Jul 24 14:20:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324857 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 53CB4C001B0 for ; Mon, 24 Jul 2023 14:21:07 +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=osZxPmoC3j/L8tROuBhhkgJH+JS/3nidhXO4brVsdMI=; b=BO9yLI8htacyXp 502xs3wkRHDQ42wANbjUjKY+fsu/0zba0wJNQqlEjL1c+dUDfaf+mucrVGmJ28PGnptmGcuGxOIDc jRqqv39Fu38D+fi1vrzUOEPJd04huRvrICLhirmcM5irkBnXU+VE5KZ4hxtNY9EjxW+ZM5cINHRR/ oisSe1tptpW3QfuebhOTpXa5ipxfPchuqrWqdsjLh72mni55bEeJE7BTo6hDNAK/10iybcQ1xXQRL ng8gQGWCuguMLFcDqh1vOEf6r4Y3DWAZaOyNIPYTDjhzLIVbPtDCvSI/rjD6KRQnqJxJzeNJebBjn niG/AG6dLphl02EFtawA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwQp-004add-30; Mon, 24 Jul 2023 14:21:03 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qNwQn-004abj-1L for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:21:03 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bb7b8390e8so8423715ad.2 for ; Mon, 24 Jul 2023 07:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208460; x=1690813260; 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=3/Xdg8XbbVT22KHgRAU3cUFwRbEnJ1pB0f6Hw3GSNwE=; b=cFC6P1d99IQ3kPlBukdOvwlmm747gDcxwx4/NNdg8egywEvP50l5bYdxGqDfcoBcG3 4vzs6S675+i3g0a3+zZdXizye0oWtLY0WSsIg03tw2PKQ+k3LRu+/v7LKEcHZfI01OMk TZxZ5AdAlYc4UCFA2XDhdlObnzF9idf5OdGoC6JEOQwdi4EpN7NT2zM6jSO1OriRQ272 oOxKeFFyOQSuutCQfduOZv6YvtLv3YV+Vq37ESXE6MV9klNXges3FrR8JJAvM3vpNtKS g1X5UKLipEqxetUE/RhFtw+4zarAhl/oWimDKvNgukvs9x8hlrVguNS1xCfhoy7xlCDZ L8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208460; x=1690813260; 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=3/Xdg8XbbVT22KHgRAU3cUFwRbEnJ1pB0f6Hw3GSNwE=; b=KFR16rmbirQt3uRycGqb5Wl813qhVnGc1mk2srqghQ/uVj4HxaGUxnvk40hyZbs54W gvrzr0Bn59tsPexoW7Ew8wNc/iQBTnZKsp7ddnSzHyYV07MCCHTiB42k6KjYfI3czVB4 nZERi58dPjPqiwF0EF9pQvL7bskinaP4EQjYaPe10i2nNOIFmeatbfWuZOolRjUeTGwY di0uUNnHAGfcWnOiwkVifhggwdm+ZbnhgsT16C8XVx0VrDtZRxrMQyuny5af/bz+/lNW SeRm/PUPsOH4Xi0+/HMxcLz71XN+XD+BT6bH3qHEv7roslluvWErvJCWRrn7NdCnpP2B NINA== X-Gm-Message-State: ABy/qLaBivq3/dm5HISeTOzDPIwrQmqYfQqbE0s2aC7NeVy6WaHVnp5B EAOQmucUG/aqbfWiqQDwYCD3qg== X-Google-Smtp-Source: APBJJlGtuSUXWx8QiCNhM0KKMAFADs7SoqRSqjxQ03zVOl9UAeikqFuj7I16Fv2eRG+VZ39xprJCiQ== X-Received: by 2002:a17:902:8547:b0:1bb:7b6c:9837 with SMTP id d7-20020a170902854700b001bb7b6c9837mr4455102plo.49.1690208459919; Mon, 24 Jul 2023 07:20:59 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:20:59 -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 v3 3/7] RISC-V: KVM: Add kvm_vcpu_config Date: Mon, 24 Jul 2023 19:50:29 +0530 Message-Id: <20230724142033.306538-4-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072101_457015_640C9290 X-CRM114-Status: GOOD ( 13.62 ) 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 2d8ee53b66c7..c0c50b4b3394 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 d12ef99901fc..e01f47bb636f 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -980,31 +980,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); @@ -1015,8 +1012,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); @@ -1136,6 +1134,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 Mon Jul 24 14:20:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324858 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 1DAAFC001DF for ; Mon, 24 Jul 2023 14:21: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=SAwuJotNvoZucF4fJsGijdW2WdDGAmhz0x1twCfYWQI=; b=nOyhPDCzRAfG2U HUUhtMwfKgEYvBUWfVRS14SLF3Lo1L0910lzoi7gx5SMgUZVXwX7AXXX32YwaQldC+iv01+X7GJsY 4ADC4US3sS5rO2w6DzngPDy4yytU3gBiPRGeK0Wutwbo71Glorti7sXYMaRDSHxRn4zg7lt+yMJD/ Ad5zI8RSCadkncA7tVIahWiF5iz5Cw2Ev61lYQWQctheNlQ8IGccz3rG9KBscggexCK1MBitJdfob pVxcGo/XUkoLicYCPKtFUPQv5IczbQZBNZcwbdKE0BX8o+l2HPet3WotEpyeNO5GlY89IPFn+Mgek vGqhSkllD5CsPAFkFXhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwQu-004agN-2s; Mon, 24 Jul 2023 14:21:08 +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 1qNwQs-004aes-0U for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:21:07 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b9e93a538dso22240305ad.3 for ; Mon, 24 Jul 2023 07:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208465; x=1690813265; 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=55wynEDcDz+Q3KKi4FYGJKBhw76WCDMX7ZEgaQ6AiPs=; b=XvpHNBgW2Zs9pL5s/H0k4VA6f2+AGdg2vISe6ZgjLfek83l8Pa3WDXuvftHJp0e7Ne ea51gqBBQ1USBDoYsARJDuL5o7S9qoghY+FIw94gteCa5Ioru5b/lgdL9jg0hYE7TA7p zhZ7bfE4TW2Zb7CQBMTjVnJza9ikE9ejTPlZlN1Jr8P12lUS98YYSNux+8aYw5+Zv9TD c33/n9jVvQVnucjdBVRM1xekKifGLnBspZpGfsfmp0ojCqCqwB9YksPZQp1LZpH6RIBB pgy4wmw7duNh+vJul5I4eDtwxDyARmEaxOzn+00v/9XqIKxEYkLjsAX1HFrxAKN+mcxx FpXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208465; x=1690813265; 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=55wynEDcDz+Q3KKi4FYGJKBhw76WCDMX7ZEgaQ6AiPs=; b=WXo+vY8v6fZ3bURnRmuL1DCu44yHaB5aogP+Rdyq8Ma8A98aYv2E/qcwq4I8zopazp jJM9iZ5HOBCLAGr4o44Aghuiq4z5GvQO0hsjI0PIHbJyk5sp4yiMrlFbTvHz2QevYy5c 8AMm963nIuPnnAZG6+Tsjn6JSPZns4Ju4aINV/ZMAIrV/qNw2j9bY8U8gxbmj9Si0MjZ StbazyTQ95Gl544V5zFs3heu0sYWqqBorJb9kP0RV18weHCKBiW/SiVc3cVGIfkcUBfQ 4MDXw1wJbXbQ9ua1k0QR3m0940FJSebm1fH4L1ztsYDo2QJU6VRZ0iezLOCjbpZ6e9MW C4DQ== X-Gm-Message-State: ABy/qLZ7EZyiHODSaQhkp6Ne1GOOZ2oar6jMXeve3tp0BQM2O9JMuuGO oPxUy4owAkXmvMx8g2a2W+7hvw== X-Google-Smtp-Source: APBJJlFqvDZTiOhDlggPQO6QOwhXESMUL3VCGb/cGLcVQWNN18LtUwSKaqWeEKq6ae20r/XbUeYkgQ== X-Received: by 2002:a17:902:d4d2:b0:1b8:b4d5:4c3d with SMTP id o18-20020a170902d4d200b001b8b4d54c3dmr8515161plg.51.1690208465490; Mon, 24 Jul 2023 07:21:05 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:21:05 -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 v3 4/7] RISC-V: KVM: Enable Smstateen accesses Date: Mon, 24 Jul 2023 19:50:30 +0530 Message-Id: <20230724142033.306538-5-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072106_188807_052907B7 X-CRM114-Status: GOOD ( 13.07 ) 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 | 16 ++++++++++++++++ 4 files changed, 34 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 c0c50b4b3394..ee55e5fc8b84 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 930fdc4101cd..7bc1634b0a89 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -124,6 +124,7 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_SSAIA, KVM_RISCV_ISA_EXT_V, KVM_RISCV_ISA_EXT_SVNAPOT, + 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 e01f47bb636f..d3166b676430 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -70,6 +70,7 @@ static const unsigned long kvm_isa_ext_arr[] = { KVM_ISA_EXT_ARR(ZIHINTPAUSE), KVM_ISA_EXT_ARR(ZICBOM), KVM_ISA_EXT_ARR(ZICBOZ), + KVM_ISA_EXT_ARR(SMSTATEEN), }; static unsigned long kvm_riscv_vcpu_base2isa_ext(unsigned long base_ext) @@ -996,6 +997,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) @@ -1015,6 +1026,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 Mon Jul 24 14:20:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324859 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 9E87CC001B0 for ; Mon, 24 Jul 2023 14:21:18 +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=o8BDoAcYcFl9yINZaVzLEMNFSiMcER9nGVh/Ty0ZxrI=; b=MG67yW+bLpeS8f 4rjLMU6wWikoxifvlF2QVj+S4bUfKymI8LBrfxrzAl576f1eVa5W8TLf/Zcf6AkXKriUGwWRHENQ5 8Bot/OuoZZJaIunkR5XUEUxA58WEKGD3bKFQ1VUdJtg4pS9lxQu7sDSS05m8/fVUl6UVakVJKBT4Y SZBQTinmU/C5OBivYiOtlWUpe6etxtyfJH5xk6xQfKuLHqnVb7ai0PcMzidF9P9zcmyAWgEeWUb8K XquQCJHolZ9dMSUWPmUIAfw3qvIr3dqcBjwA+B9Jck+r9xHL+Esj69IJ3tHhyoszfcsIVuVfFjldR zYGFGLL/lLCCvEO9OZeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwR0-004ajX-0m; Mon, 24 Jul 2023 14:21:14 +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 1qNwQx-004ahn-26 for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:21:13 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bb81809ca8so17845515ad.3 for ; Mon, 24 Jul 2023 07:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208471; x=1690813271; 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=XWBcboB8FAg6vBr25GMQxT+1AebhzKVOh/ZnCapT0AM=; b=GwCKeAuwMXS6oAjq/vrTYy+q9hMY7Sgf2HRFtNraIw3ybHmiZoXVC3nrk8MRWIsNLP O5eGN0u7oz+g/RQo5WgHKu0YspuojUGe+BoRVaT7bSw3f+ro/pbpfHUywDfmo1ZSpH8z 0iAU1z9LfUepTFzWPjiZrIR+mA6t9pIliSHVwx5E6nfXGp9vkSZAGaU2Bv8+5wUVScew an4P4XHBQQxrIWkcgup6J1a7MbYLW2WnsYOKqC0y2QxvBXY1gsIJRj8ZxdpM2GnrGe++ DGvHEOPIF0b2cewgGo8hoPmgQ72Kp5KqyncqT2WhLtU/a/nm3DAclGrOPJzuAhdSw4pj 0otQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208471; x=1690813271; 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=XWBcboB8FAg6vBr25GMQxT+1AebhzKVOh/ZnCapT0AM=; b=Pc4AbAaV0OOZ15bn29ltQR10n238MVqt27DqDcafMwvLJDQQhVcOnrafuqXDmk7AgK hzpZSjw3x8cTLKHou08Ktej5vaDCeYdPGV1u+xQ9vGxgkMk56Q+gGat7kU5VRAWpOqay eZd+doCyO5Ztu/qcSgU6Da2usQuIFOzSILprfFb6Hx97l0DpGgdwiy2TNge60oGWtXiT VyMLwuUSJKGjfDpHRyGLEDvbqVKstWlVtwVlyAJYG7GfDMaxdc4k+1oZYQY3M93f7NM+ A8uBKmQsPiCMh/xRQLT6Q6WjX52CVtqxXSuiApCfSNBJYxPyCIGec5dPMiKI/SA/XlCX O4sw== X-Gm-Message-State: ABy/qLbsCumNnq3kq9yEWQGzccYYahPsYpC2IRrfD8LqY9tidEUSE655 gT8yDg2gEzmrdoZPq/0Jmz3LwQ== X-Google-Smtp-Source: APBJJlF5Wc1/nlIL2etddXdNd4kj854cm697DfDflaN4tDLhlkCN8ioug7vmn37Pl6VoNQ2tctbFNQ== X-Received: by 2002:a17:902:c945:b0:1b8:88c5:2d2f with SMTP id i5-20020a170902c94500b001b888c52d2fmr13294720pla.64.1690208471129; Mon, 24 Jul 2023 07:21:11 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:21:10 -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 v3 5/7] RISCV: KVM: Add senvcfg context save/restore Date: Mon, 24 Jul 2023 19:50:31 +0530 Message-Id: <20230724142033.306538-6-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072111_691360_AFA7930F X-CRM114-Status: GOOD ( 12.28 ) 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 ee55e5fc8b84..c3cc0cb39cf8 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 7bc1634b0a89..74c7f42de29d 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 d3166b676430..5764d22efa29 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -1129,6 +1129,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. @@ -1138,10 +1152,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 Mon Jul 24 14:20:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324860 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 74275C001B0 for ; Mon, 24 Jul 2023 14:21:24 +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=kHsqS2lJ3cxR5Z5Rf4GoKNaKfbBvzu8D3KgnOb4u0TA=; b=suXDH+nQ69O/S7 D18MIKm7cInXczT000jbQphL9fpBtXWQlzSXDpS+SpaK936F38U6Cy2QnaX3n57vj589vMCzmeZMD fUDRqG87Tv+EXOUxajyMlQU7DLxZH3STNewRcbqEszHWVIFBWeSU4tEbWqOMpUQvMtUcJ5e3xZuth /bbIjbqkYFTRltkd9FP7h9Qse6q6GTQWjPtJC1nmu25zF467H9VCmoHz2Yx0/rOaqq/9axVONEM6g gaHHEsTJGSI5f7ey287rkO8yGMR5MLKA1hqtnenKiQH1pbfMjzt6Kyt5Ui1K7Ka84SobTDTDErRHZ DX2BAM+1MOfLkYhNyyCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwR7-004anv-0B; Mon, 24 Jul 2023 14:21:21 +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 1qNwR3-004alB-1P for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:21:18 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bb8e45185bso6558345ad.1 for ; Mon, 24 Jul 2023 07:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208477; x=1690813277; 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=jeBit2HNTThkMI6F9leen3WIW5NeA5jHqdoTdMy2SDk=; b=INcMG8ZHx0b8yfXTa2Nj1yn9yJzBsKD7W25MzHKKGgHItU7yakStopz7HNm1MSMcTJ AtsmHaKRlKVr8GCryip+h5f6EYkGEqmZVziwvppe324DWYDe67Q8sxaWt9fqAVuaI5mc k4q07y4+Fqe+pk3oi25OcyYeNOp2AqMZmsmKRA8VA5NZ3QoLZNeqmM07GY7B5+d+ybR0 ez/vhIhy8dvyUPUasZpRb9ih8g7BTuCvNzVMzqSOn+z7Qyh0OHubG6bcV5K8zPdFZEcv lNZQe0+2tB9lShpnD+DZJ1r8dKIqhjmmD6NJaHS7YzUEonqwJwT+ECR7sla0J4k2fIvc WldA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208477; x=1690813277; 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=jeBit2HNTThkMI6F9leen3WIW5NeA5jHqdoTdMy2SDk=; b=HRuZ3TWLA9cdbvQQ08+9I+INczoqnflLwd5NAPo051/Lqlpl1SvfiYwnSTvmgOuyeo doWDdkVAp1AFSo7hMNT4ZPFqpbjmd5fLeaiQLnp50/leQEU5bP1slXBwWLPMG81t5dN8 fJGR+keI/u4vgxc2GL8e7DpEmKjJZaqwadyZMTf9F2cwBlFc1cYcZHC4ek9SBf686S7U RxFDsYVALljVNo4vLO1WbV4yMlqxdWhp6afy35u+azdFK4ZGMnNMO4MlBrKdu5J3KC/z A6+gJfShBQzqZtfMFjiQKMAkJMF6+4WaBolJSQd4dy3V/Wq+HWH86Ksy9Pb1I/ixCbJS swFA== X-Gm-Message-State: ABy/qLZ95QImAIx78MoMXtvDVpMg9XALO02Kjnd2DyC8qkOBKKn8xtIn IL73l2EdYx24K9JFd/XDQBboHA== X-Google-Smtp-Source: APBJJlHyb3xgYcT32yxcD6LZM8/JX0OSj9UH9wSW6Xf5zDVZwj+PE3K8EqFFsMz45s2HtuqN8R5IZg== X-Received: by 2002:a17:902:8693:b0:1b1:753a:49ce with SMTP id g19-20020a170902869300b001b1753a49cemr689867plo.53.1690208476936; Mon, 24 Jul 2023 07:21:16 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:21:16 -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 v3 6/7] RISCV: KVM: Add sstateen0 context save/restore Date: Mon, 24 Jul 2023 19:50:32 +0530 Message-Id: <20230724142033.306538-7-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072117_477641_181ADEC3 X-CRM114-Status: GOOD ( 12.95 ) 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 c3cc0cb39cf8..c9837772b109 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 5764d22efa29..1f8e8b5f659b 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -1131,16 +1131,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 Mon Jul 24 14:20:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13324861 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 E8090C001DF for ; Mon, 24 Jul 2023 14:21:29 +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=0ucYmdW/+nenvRn7+nmkyS0ajCKpnbIsEG/TVYomNIY=; b=1GWWFi9lZ2/5om Ys4yGHTCsV8EaoLLSQDw8DMJqxKTkY/4m2O+xNi9+3BWn7vCywRmOWsTOWmEcJt5vcWtlIQAMG7rb AgC/dRIzcGPDq3xB9VryBfqYwa8PJwDLmKXKzCAp7Ga0LO3X5wLQANhj/LnNlup5hMLqGxA4iX3LQ aHbuHpVniG10TsAsC5+hv+XZAYWICxQS7ING5IQVkc1SVvZNUUBRMfRACyUcXw6Xy3MfvcuGdW9xf IxPuGt9HyS9f+jaMyx3XxqORtCdq15iU8II0FUy/9RXHCf6+j9U+jBPGAoMogE5ewzt8t8nwGsvK7 DuxBO17+j81xA+uuRBxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNwRC-004arV-0e; Mon, 24 Jul 2023 14:21:26 +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 1qNwR9-004apM-1m for linux-riscv@lists.infradead.org; Mon, 24 Jul 2023 14:21:25 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b9ecf0cb4cso24315985ad.2 for ; Mon, 24 Jul 2023 07:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690208482; x=1690813282; 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=rDnREYRMUsFKwotu4+OZbUuiYKT956lIR1m4uTAXghk=; b=BpMmpgZLigGNyFchrxOPOLlJlgmjs0MiG9pCQaVC5n/bE9lBJToYkJY/T81TALk0ln 48mdZU0OiESH7WEdkYAV5JUYdP5OsKBtYJtvK0+YK0qrV4rjmtFNnp+JYhO4m8vgUH3e Lrcll9X8RLTuVsd2Sw4w1cRoDy9hleJmzkJMdyOt5PxkzvSPSWmSrBi1dKP1ncuPtfJ8 meOsSZn3jdDqpPM/mV937BTSlbfHElrnLzF0zPxLvGyL/N7AjvDsGGZ08LM4xLf6EF56 GofdbaIR79gbpbSSY7iHLkCxB2uH3tcOTwJK9hHaHx/EZrM900sLMp+lD779OXM8kIjY 8HZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690208482; x=1690813282; 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=rDnREYRMUsFKwotu4+OZbUuiYKT956lIR1m4uTAXghk=; b=QfLwJXnQ8tvWFSykFbzXH+0cf5T7FhOuxBja8csExydha7y0/Tz/Bcvj5PUhRIFfCl Xi1D3S/dKsGXlJ6knT7Al+/xzc8jF6Q8kA8EFQvPFMKZso4uVNCt9uhpv/ov+PhzM+Hn oAHD3HXJ2HkxhbirzVuX4Q2QGDAHOKxsZyAEq+Dxr0ELiYJhRHger3dqt58XJtCda+m6 Y8NAd2+7/YtrYPd/8RzDx0HIR2zzKsgBfGIgyxalP9bTyqzMOmBk5SJ8eP2t+p5FqLjv K7yac1RAiX2qPG+Fea5VaXFfvKVjtSRfLHx0+s188SY6INSUAg4CX54E2in2HsSNhHOz kWwg== X-Gm-Message-State: ABy/qLaepM8Zif+ERdHvHGYZUoz8kpHEqI/aWD029Qdn/BOuGB7xxkrG dAvQg7WrNq/O/T/VNdRYTmqyCKKWYKKbOPrAmTirfw== X-Google-Smtp-Source: APBJJlFVpOfpewEUKvNfOOSKkZ45Iflti55y5wOh08p3XPPqcFtt1L3xleW+okCDUdPZ11RRLSxMDQ== X-Received: by 2002:a17:902:d489:b0:1b8:8069:d432 with SMTP id c9-20020a170902d48900b001b88069d432mr9288355plg.16.1690208482323; Mon, 24 Jul 2023 07:21:22 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id s10-20020a170902a50a00b001b8307c81c8sm9009821plq.121.2023.07.24.07.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:21:22 -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 v3 7/7] RISCV: KVM: Add sstateen0 to ONE_REG Date: Mon, 24 Jul 2023 19:50:33 +0530 Message-Id: <20230724142033.306538-8-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724142033.306538-1-mchitale@ventanamicro.com> References: <20230724142033.306538-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_072123_591876_C25BA0A5 X-CRM114-Status: GOOD ( 12.21 ) 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.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 74c7f42de29d..bdddfb20299a 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; @@ -173,10 +178,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.c b/arch/riscv/kvm/vcpu.c index 1f8e8b5f659b..630669513bd7 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -507,6 +507,34 @@ static int kvm_riscv_vcpu_general_get_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 inline int kvm_riscv_vcpu_general_set_csr(struct kvm_vcpu *vcpu, unsigned long reg_num, unsigned long reg_val) @@ -552,6 +580,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; @@ -591,6 +625,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;