From patchwork Fri Dec 24 07:36:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12698904 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 03BDCC433EF for ; Fri, 24 Dec 2021 07:36: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=NSsqoQpWZlSWNlhKoDy+VcgtFEFdfvG+JgPoGN7ozBI=; b=HThSdTFSA8sLyU cPfqwN0bXV3dRt75AytTXteE7jI+R7GA/2kCHEnjYIP0zDb1LhDzo7Y6qERUsk+s5L1w/TyMrpkE/ 7Yoyw7b6/r5BAnJfo8L4VljMACOfQUNjQiW/dx48y7Ys2ldkx61lA7MPq4OzSpDAHE05gD8rybrss YdAEO4iGetRJ/VaLLr/cUkvNwuIWDfvr++O+j6BPbUKFQ0JPeVGsU0A44Dya60HdCR+nltJzfsnwt d12tFZJ+Isz+0hIEigkgydYS4pvF6a8qHB2rbQo8p2w6+37hLRsDGuuKr8jPBnoBh7KSQdpNH1HM4 7WMtAlsT3pR3G+YPgWyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0f8C-00DrGH-O4; Fri, 24 Dec 2021 07:36:48 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0f89-00DrF6-SN; Fri, 24 Dec 2021 07:36:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1640331405; x=1671867405; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=6IVuN8fMfTgKUxJ+G6/ulPX5w+2v0oz2A8DPleTJ8E0=; b=pbZtbTOEmlUcPlGWua0FFiV3fZAZHdKmSYMHRjPMpjNpoiFezHsLAZZf GsHYZ/FRgO10IRNgzXmmRImkd0FkyckNcux18N0+z/+T7P/NNDD60TUCq lQIteKLnoyv5MVS2IHhcX57RjzOPZxaizVDwQ91TGifVrrVTR2KXI6E6h lIig/emunYjCrOk+0gaPPMdFapAsw1ZvnQWC3XHq8C9e7KaCb0IYlYppq Wj7/WCTqwZkrMB0tnuHrjez/Wi9YJX3U8AICV0kKZK5sm1l5b2pA+cR7h zLYm34aZcQXEmlebk/ybCE/JBw0oKCfIWSBKlEjbMNnOSkkHA/VGROi3r A==; X-IronPort-AV: E=Sophos;i="5.88,231,1635177600"; d="scan'208";a="293035153" Received: from mail-co1nam11lp2177.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.177]) by ob1.hgst.iphmx.com with ESMTP; 24 Dec 2021 15:36:44 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lqUItnxjoVOLQJDmxB3YYvjIZoOMTR/owmZ9g/aHAD/3eg15ypfdrFXTSzBZGa68boewp+xLrMm8yo2HWbn52GMRMbY+1T0V83G6We9IkIpvjsIfgPaylSztQCRuERjbuvGMDu30UnaWpvN5aTP1wZExharevrMhdy0pIN5q/QF936zWhUFj8D/gk5/xdDZppz1MALa97BiD1StZwK31oxanj7y16XGf1yYqzvohG6eEYFSCCDkTDh5tLqVX2j4IlWXlbEh2NnT8aW5/2LqKmh31Aev42/Ig1FMMp1msJlzf6EzsV6hsyIh8H/BJEo1e70u4NkfL+oEdHkcy+Rq/Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N4jzQudXJSjPM/lzJNkVj24n3Uo3rbWmg9VgQIQeQFI=; b=N4kDUnDGwuJhqJCGXi4KYNpGT9u+w+RcA+rMTtxY6xQVfzX4LHEOqdhg+JUWKkGnsxauvyPO7KctDvkqXzN+p6Rn203FTOv4lydziRi4weuH6OxkabSvLHWPh9RGj5n8VCOiN3PHzfHdrv4Wnxssjaj5+7WAT7UDKIXO0ACOF8GYCdCX7Tc0tG8GprMmF/fAA+3nvoi2HCLqD/v+YlfC77Epygctuhtg00W4ffBw44aUeF7jcjVORkZssgpiGslhAO439cxYddDsC6Bya/An3ZR/rB/Wm9yy4HysniASq8SW9eD2OnZiv2+cNGwCr8+wctGZsLbRBtZFh5pttT0a3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N4jzQudXJSjPM/lzJNkVj24n3Uo3rbWmg9VgQIQeQFI=; b=Hk89JzrIKSg9Ednx3XyLwoZa2TU3JXFOs2/C5xBT6Ouz7Wtx4RacW6R7Q8RGSeUZDulaWtps/pgjDyzP/IKnXOedQkhm/fCMbHgQ96a1EttCgVp9eExL0CU9XYEBIXhKX0eH1MNrxFnRk7pYHpRi/emp2FyJySV7Bn1eo/j+hho= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7859.namprd04.prod.outlook.com (2603:10b6:5:35e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.17; Fri, 24 Dec 2021 07:36:44 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4823.021; Fri, 24 Dec 2021 07:36:44 +0000 From: Anup Patel To: Paolo Bonzini , Shuah Khan , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anup Patel , Atish Patra Subject: [PATCH v4 2/4] RISC-V: KVM: Add VM capability to allow userspace get GPA bits Date: Fri, 24 Dec 2021 13:06:02 +0530 Message-Id: <20211224073604.1085464-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211224073604.1085464-1-anup.patel@wdc.com> References: <20211224073604.1085464-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR01CA0117.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::35) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83781c94-bd30-4eae-ffac-08d9c6b021ea X-MS-TrafficTypeDiagnostic: CO6PR04MB7859:EE_ X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hUxJREFNIfVRt+HckuoX1Ap11EkGkxAqlJvBC9cEHVZ/TekmkOfrk+/iiCOZWCE7RbzyQDHdhmQCs6KupqPT5SxVh4nw8/ilBDy/NFqJI/QO02xD2SGAcrbKU/htaDcNXIVMJreqHVtf2Js3lSqLZh/naN+CEnePvjBOTlxq6FT3KDBMk5znq1VjwBemy86uLY9EPIk2Dz1Wx7AxiIKZYtpiAwwpt7TWwDDI2wWQyB4tD1Tp8mDdkP0c/2JiCbdQPQLvODaDMNwAe+dQTPpTQkpUqba7wkMnSfLrlmyRk+dUSaeR2WI/HM9CmJ8HUWkloJtGHLBMTkPqvHwxcHXAE27s1zTrButJ8P/6fUhwO+7MM+7bAg6dPjXGBM51e47lK5x9DXfx4v6+fmUWJaYgfcFjJW5buIviOa+x1A1SmrbiY84Abgj8xfOY4mHbTXBYKKNiQ7p5lNBBBmhTTlVxaYR8zAA7V7hyyBsZbDjUllxGjHJdRFwkGT1VwblU7WkDdD90+KF2p2a36g6UOUbdH8h2ZW1iENcBy1HO0CUyGnqERzGhm7obR6HfVyDtC7+E9F9/ZY3BEb/qQxatsuO03aDcKVStG+tG8n789GtSXhenJ4/nTTcLMLyELKPSE9YvUb3+GkbK2EKDDe9tz9b4LF1vqkhtgSY3Nay0ptB4PSEMH5cqjPgXKhwOujnzPlK7In8wycF00m6KNIZRC5DyOQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(52116002)(6512007)(7416002)(86362001)(186003)(5660300002)(2616005)(4326008)(82960400001)(8676002)(26005)(44832011)(2906002)(8936002)(6506007)(508600001)(316002)(83380400001)(38100700002)(110136005)(38350700002)(54906003)(6666004)(66946007)(6486002)(66476007)(1076003)(66556008)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5Rwa2vbuv+9zJbex3njGwgRDpXuHYbJee/12zW5vF2dQ6BQPHGSCB67CFm6q6m9gPToXc/uYrx2VJmdm5sZWssxIrh1uPe45Gus8xF/2csc7xw/e08J3aymlIyxB+wYV4R7er1gIeWV9rGtLz2IiJCfx6m/WvXL8lJZSsTBotTnQE2LnE3R6WYdw/RlDIXH7RLqdAw9/sSakcq4ltDbkIcdG6KXqLVB/razTdYJ9HFlq7IfUGdcW6sBGSktgersLQEJxDtlo+X1xtLZ8xLkR8bmYWee4TW48KmiELiWbbbasVsnep+5YQb9nlibG4446mnY+6ty1QAHEeoq50iOaCW5a7B7OBZhFMkfJe8vIaLYrB84CpeuE1dJoauK7COnwfrSpDqxxRtLjOinPLxUr/ZwjoyVXEFRknE8Tlcj7HZVKEIB0LytZBu+8hN/AF91AKtskoApPcJBUAuLfmvxXFlIdqv+pF+PpjqO75DIej/E6TNhPCh+gJ08f8Hi8qw8nPFqo29jZJRLvJJLsT3LAv3BH8wCV+MHXThBCaYnvUh7tsT61e2DDAm9heYQkYdWSHUpNzzQYaXlC6mj1ugRslPPLw+G9K09S94R2jeoJ48fxny1A7awsHOEzVcel12vmqHs3TAfRs7M/VEAtFfdEH57Qb0wuBjKhD+9E0mf6qBJ156zEvXr3sg/oIuaU4G2HnTWso/d8P+0TRYDTzPbPTfjmF36gNfg0h38U4cXQz7jdxeh0X1UzlbZSjInonXnqF4LYlszIUrrYFDx9wdX95mMMnVl/gfIRSFKAVZWISzknrmScUo3HAZwG7wdB/asrBaLSWP3livVrgZ8DO0kJR2d5HfUljdsBchD48i1Z/yiu4M9QxnVtFDoyWe8zk5N1xyOcLSjR7Y+R2yX8GqQ79oCw+nVih7NoAXz/FDREQ2TG8fTd1YBFdnYSd2Udisj7kXlvDaszLqO5Ty3wJCJiyQToRX8G9Tr6+ynTnZF6sfsbpHHiFZNflb4FuNvKRSF1gA5uFLpw3xlZNcQHYRc7XRqfYVgR41s1voVdZH7caagmbCiUtW4X5Fbuq3S8Go74g8O1uGzBoa+N3AIDlye+wNcw2j++IeIeHq+VQueC7k2P8MwAoZGCW+/H2EAmac40OekbrfaZvV4cnpZbRCDvvsvFVvbo4eIJcMX+3tj2hZ9UaVYEkekXdsOqcyCHzqxby2dPT/QwF0ZDP91htYSlb1ltToqRurG0+QhM4Fgh6vvZIJOdegTCy/1EaBwIbzrdjTddCChpr66/buvtLQDRraiH9pD21ScmF1B9B8LHNNyRI4HC2sv4Hv9J4kyF4waXVZPtFJBhdENWn471aqmFfNBuCy59od4QY9m99eQUL+KDKWrCst0JgrlIB/oze/Hz2mPZSQjhcu4KjUgTwhfncmI8cb/MGeGoM9vQGfJsJVgJYs/yQFcQDJqxPB3SK3V4Rn72OhG/DX/zmBJu+a/A+9y4YF1/8fHrwJ9ExC5WePWIABeTr4aH4Wmthph1zeeB8F2UEaUgVfSNuAuKRb9Tfe2Xc3xkuM2n7IO43OE4ooCRQEv4oH3Hrk7FC2POAM/F+pwIEeAh9PnN9R/F+JVjQrup1NVz2Sz/34rhvvia7nY= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83781c94-bd30-4eae-ffac-08d9c6b021ea X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Dec 2021 07:36:43.9446 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: n7j6rLaWr2cQXjyLyRQreberIIudGVXtSFvyaoMp/c5R1TRdNsDTpKmVz9WVw/RVNPKyg8APfIdIPL2s64KpVg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7859 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211223_233646_005309_90279223 X-CRM114-Status: GOOD ( 13.85 ) 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 The number of GPA bits supported for a RISC-V Guest/VM is based on the MMU mode used by the G-stage translation. The KVM RISC-V will detect and use the best possible MMU mode for the G-stage in kvm_arch_init(). We add a generic VM capability KVM_CAP_VM_GPA_BITS which can be used by the KVM userspace to get the number of GPA (guest physical address) bits supported for a Guest/VM. Signed-off-by: Anup Patel Reviewed-and-tested-by: Atish Patra --- arch/riscv/include/asm/kvm_host.h | 1 + arch/riscv/kvm/mmu.c | 5 +++++ arch/riscv/kvm/vm.c | 3 +++ include/uapi/linux/kvm.h | 1 + 4 files changed, 10 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 247b761c72fd..ac38696abedf 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -219,6 +219,7 @@ void kvm_riscv_stage2_free_pgd(struct kvm *kvm); void kvm_riscv_stage2_update_hgatp(struct kvm_vcpu *vcpu); void kvm_riscv_stage2_mode_detect(void); unsigned long kvm_riscv_stage2_mode(void); +int kvm_riscv_stage2_gpa_bits(void); void kvm_riscv_stage2_vmid_detect(void); unsigned long kvm_riscv_stage2_vmid_bits(void); diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index d0efdc2259dc..58a47c93e5f9 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -766,3 +766,8 @@ unsigned long kvm_riscv_stage2_mode(void) { return stage2_mode >> HGATP_MODE_SHIFT; } + +int kvm_riscv_stage2_gpa_bits(void) +{ + return stage2_gpa_bits; +} diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index fb18af34a4b5..1e12c19a7c6a 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -82,6 +82,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_NR_MEMSLOTS: r = KVM_USER_MEM_SLOTS; break; + case KVM_CAP_VM_GPA_BITS: + r = kvm_riscv_stage2_gpa_bits(); + break; default: r = 0; break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 1daa45268de2..469f05d69c8d 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1131,6 +1131,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_EXIT_ON_EMULATION_FAILURE 204 #define KVM_CAP_ARM_MTE 205 #define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 206 +#define KVM_CAP_VM_GPA_BITS 207 #ifdef KVM_CAP_IRQ_ROUTING