Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp890697iob; Wed, 4 May 2022 10:02:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqkEXR0wFc3I3WA4dyaKHbj59ScT/zk2THY1cLA7i1t+9AA9Ju/G7m3XAJVApmkOx50KT9 X-Received: by 2002:a05:6602:194:b0:64f:caa4:f9e0 with SMTP id m20-20020a056602019400b0064fcaa4f9e0mr8676582ioo.1.1651683760915; Wed, 04 May 2022 10:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651683760; cv=none; d=google.com; s=arc-20160816; b=Yy9aLLrVclcAv7iKja0gCRYhqLf5HYHSYLlpLwqE7ykt7AKF/pOVKq6Cr02Tat5O2A KZNzrgYQvapZRFPeCQCZh2YWzSWkaUc0pnAfpuvczt0KikDP4VRWL5JfV2Hgg+l9u4en Jv6MfuzJNwpRyIsVMF6dAk1y3awsPc1b1MuDBF5m6T3qYKvU6uzrBBuTtN5C2yRxjith nJZUwSj8gSzfaLLpvEhnRMOaw1VBCKdLK0tqAAh9m2TJKpPX1ecwBQfXVvS6epqab+qw NcEF6ZVBwKy9maNbHkBUGfx4q/rqyDfyVrBeD9NdE7gj/7EnEoVKOWlxvvg1Fuw31hn3 kAJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VHVfBZ+ZbG4jO46Y3xTAJPGI1FCH2/0sdEc6UgyZ1v8=; b=i00kfC8WRgcWWzE3hXgIjl4MRy0JpFKKPFMq6y+/IwlKkreA6rSoVJ9Ce4drH/f2Rk MhpaiRtnXmu0ccpVy8dTHdO/Ca4nMief93W3mQ7A+pRAR9jdSC9LAsIkT1VheWbvCar6 vFGwGUdh6Xs85Uz6Ewtm3NaDIiWthLYKut2tm0exYAKFDrAfPL1d9fVAAgopj/+a221D pHyLtlZ6icbWkS9HpWFgTW3r5zte4UiWY4l65wYmCsWjGSDwQMuhg/3K5DfgZ9QByegM mfWwxOPeXsd6cvCJO/fJ6O3XUXV+HAl/sjtIzLv3BETDAq95/Vhvz50qye5g/No9jmWq L11g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=FAjHBA3D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a92dd0a000000b002ca43f2e01bsi7962254ilm.41.2022.05.04.10.02.23; Wed, 04 May 2022 10:02:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=FAjHBA3D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343936AbiEDCR6 (ORCPT + 99 others); Tue, 3 May 2022 22:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343873AbiEDCRy (ORCPT ); Tue, 3 May 2022 22:17:54 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85A9E29CA8 for ; Tue, 3 May 2022 19:14:18 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-2f16645872fso1872377b3.4 for ; Tue, 03 May 2022 19:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VHVfBZ+ZbG4jO46Y3xTAJPGI1FCH2/0sdEc6UgyZ1v8=; b=FAjHBA3DYZrjCcFJ6SRJYEfqXCfuaP++2tcA5MdxVcnYV4gcDkdMhPq+5V+nwRn/LB BPMK6R1GX5gCsG+Nlz2u1xpC+BwbzLmN1BsOC3quRE/uMcT3rOlEdtmyarUKmSP4Xf5U CNGi2Y+hFXf66WgcBSOmRixHtd49iCwN7waBQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VHVfBZ+ZbG4jO46Y3xTAJPGI1FCH2/0sdEc6UgyZ1v8=; b=0eN3unMMZO0xlY2hsUC/q/1TCl+/kMy605+mPcaNni3MyMz4A17/GcPZnsnCzr5SeO V3ejwCch7fXKZsuFpablIfAG4RSRNZwBJgviRf0DmVVTjlYinYPfm3dmqHRjf2wJoy/D +ErjW1WF0F/hEu8C1904r3dTRA2sF9nv0we1dGqp8QEKXGyoW4/GwJOgggG3YvVW6s0d jhzvFRFyOTKUF+BEmprpTbTQWcj6D9gOE14WZipwQF81B1aOPeBoo8wWaaITsAohG0su 2AddDRNVlY1dE2Ou5Op2AnI2b32/Xvo/Fwk6lcsePtUnt2Od3zFAotxetPDZJAZuuokV Eonw== X-Gm-Message-State: AOAM53133Z+Db+Yh+7vvvEe1HgomKK4d6BWQXa0OwL2CAcsmpeUus3+X pSmZXgkzfu9k6sCuWDgGbG6b3nsAPJqDFcUK95rT X-Received: by 2002:a81:20c1:0:b0:2f8:5dcd:91d4 with SMTP id g184-20020a8120c1000000b002f85dcd91d4mr17984573ywg.443.1651630457801; Tue, 03 May 2022 19:14:17 -0700 (PDT) MIME-Version: 1.0 References: <20220420112450.155624-1-apatel@ventanamicro.com> <20220420112450.155624-3-apatel@ventanamicro.com> In-Reply-To: <20220420112450.155624-3-apatel@ventanamicro.com> From: Atish Patra Date: Tue, 3 May 2022 19:14:07 -0700 Message-ID: Subject: Re: [PATCH v2 2/7] RISC-V: KVM: Add Sv57x4 mode support for G-stage To: Anup Patel Cc: Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Alistair Francis , Anup Patel , KVM General , kvm-riscv@lists.infradead.org, linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 20, 2022 at 4:25 AM Anup Patel wrote: > > Latest QEMU supports G-stage Sv57x4 mode so this patch extends KVM > RISC-V G-stage handling to detect and use Sv57x4 mode when available. > > Signed-off-by: Anup Patel > --- > arch/riscv/include/asm/csr.h | 1 + > arch/riscv/kvm/main.c | 3 +++ > arch/riscv/kvm/mmu.c | 11 ++++++++++- > 3 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h > index e935f27b10fd..cc40521e438b 100644 > --- a/arch/riscv/include/asm/csr.h > +++ b/arch/riscv/include/asm/csr.h > @@ -117,6 +117,7 @@ > #define HGATP_MODE_SV32X4 _AC(1, UL) > #define HGATP_MODE_SV39X4 _AC(8, UL) > #define HGATP_MODE_SV48X4 _AC(9, UL) > +#define HGATP_MODE_SV57X4 _AC(10, UL) > > #define HGATP32_MODE_SHIFT 31 > #define HGATP32_VMID_SHIFT 22 > diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c > index c374dad82eee..1549205fe5fe 100644 > --- a/arch/riscv/kvm/main.c > +++ b/arch/riscv/kvm/main.c > @@ -105,6 +105,9 @@ int kvm_arch_init(void *opaque) > case HGATP_MODE_SV48X4: > str = "Sv48x4"; > break; > + case HGATP_MODE_SV57X4: > + str = "Sv57x4"; > + break; > default: > return -ENODEV; > } > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c > index dc0520792e31..8823eb32dcde 100644 > --- a/arch/riscv/kvm/mmu.c > +++ b/arch/riscv/kvm/mmu.c > @@ -751,14 +751,23 @@ void kvm_riscv_gstage_update_hgatp(struct kvm_vcpu *vcpu) > void kvm_riscv_gstage_mode_detect(void) > { > #ifdef CONFIG_64BIT > + /* Try Sv57x4 G-stage mode */ > + csr_write(CSR_HGATP, HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT); > + if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV57X4) { > + gstage_mode = (HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT); > + gstage_pgd_levels = 5; > + goto skip_sv48x4_test; > + } > + > /* Try Sv48x4 G-stage mode */ > csr_write(CSR_HGATP, HGATP_MODE_SV48X4 << HGATP_MODE_SHIFT); > if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV48X4) { > gstage_mode = (HGATP_MODE_SV48X4 << HGATP_MODE_SHIFT); > gstage_pgd_levels = 4; > } > - csr_write(CSR_HGATP, 0); > +skip_sv48x4_test: > > + csr_write(CSR_HGATP, 0); > __kvm_riscv_hfence_gvma_all(); > #endif > } > -- > 2.25.1 > Reviewed-by: Atish Patra -- Regards, Atish