Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp273377imw; Tue, 12 Jul 2022 19:48:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vw5T+AzXO1720FS7KkCh6Vt+Eih9CCi0YfTjxAxJ8Vs1gaYCGqnWmTrxabi2AtQlnu0tXg X-Received: by 2002:a63:c056:0:b0:411:b3d3:ae4c with SMTP id z22-20020a63c056000000b00411b3d3ae4cmr1152600pgi.102.1657680526842; Tue, 12 Jul 2022 19:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657680526; cv=none; d=google.com; s=arc-20160816; b=VAqAJnPQYEmpBylVqkiiyKoHP/XoW05voJ1PxJSOORQJGKHVUyoc5qQnkW4et/thxk ZoQY3XUjrwo7gGgN5VuXgI83yftPuLNxKPwIg3yNmsUx4FrYc4CrMncsfO7CkgSBYWRr z8zrH43M1st7qpgbL2FnOXFMicmfzbAlPbs9RXzsrSMaIkXMTD8JZah6x9J8KWIOCIno Ou/CsOMCSR2COJ/p2Elq4DS3UyCskYAHqYB31vyIBDi8q22+K0XMhCxsHova5j/OoMrM JNc93hAsoeRBBLmnepj/ISA0GEOi+r8h4iDc7WvZUJ3Dku0oSjMn8+eTREopPUgwyVkt gzkg== 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=YxOh0nLFFVmYSRH0bGoSLFMwaYMfiAsAxktFavty9+E=; b=Y645NTe9nhf+EF4nqAcYJXHP770XjI6F7PwaiP4n1V/EoratxNDS1lahXMY26y/k/4 1cct0m3ekE9y9ITz+VaEveuA+FWuNedwE0gR4BVMzoavFYEU4DptRHJZ5g0gYo32Fa6o 10fo8MV5BUmYC4MQC+tae00Zvq3zq/xuJGF6Od0K85lgrApCnxdj8UNqfoNk/Kk3c2PK wVwpkvgeFCIdJxbMRzXC8C5LUCIuvd6JZGvz3djTYUh6C32bdHTc9Ct/MIzYH8UIrFbE RGZMee1lQQ0I4Tct9Tfa/AJ1y+b1uT73M2Gi86QLZQ4Ma7lQf0nGrXGEIIxNr84BCdyn 9F7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b="A/l4Vpcz"; 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 a3-20020a170902ecc300b0016bebb59879si5065987plh.185.2022.07.12.19.48.34; Tue, 12 Jul 2022 19:48:46 -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="A/l4Vpcz"; 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 S232944AbiGMBYD (ORCPT + 99 others); Tue, 12 Jul 2022 21:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbiGMBYC (ORCPT ); Tue, 12 Jul 2022 21:24:02 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FBB2FD37 for ; Tue, 12 Jul 2022 18:24:01 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id 136so16931177ybl.5 for ; Tue, 12 Jul 2022 18:24:01 -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=YxOh0nLFFVmYSRH0bGoSLFMwaYMfiAsAxktFavty9+E=; b=A/l4VpczNL+qIPVoPAmdw5rmr3hZET1GfjqWyIQyU6QVbLdHkupXiiGeAivJMI5Y2q UUED2SFUDX7v6cJBHpLH6mTaw26pLid3XLm4YpAleqf6ybOVqlITCQo0zJoErF59t++V Vhf/vlRY1AvKBd7Pkv54IVx2HwmVDaQvyyVLc= 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=YxOh0nLFFVmYSRH0bGoSLFMwaYMfiAsAxktFavty9+E=; b=EXDTjVVVkwyxsNsE7BtgZsLrchkmN1dIxc6fAMt4/dlRqIOwqUOy8Aba7xUXaPA7IG cPWQRJ8/ssPEL3qG9PEC4UGxYg3facd0aVeiP/wiN5csFs08F1q99yLhEItqK1O9kKIN Dl2duTlroIibzjmTHxZGTPih7eS7pD6K+73CWqK4G5nxXssqy8CdXq1cnxWg/EZxCC+w W63HtraCnofdctf+r7xhy1mQepIYJCdzZ5EKtMTS6jsZEvO9IfoDBBfIMUDrm4zrPDE9 jBfs731LVEui45QRbWpkyw0hE7ZS8C+rff6OQU9VlcLModOuRN2P5t6Ju3kecDsE0lyI 0TZA== X-Gm-Message-State: AJIora/NphptJbHizFSJZK9zEon7elkTprem9hKDLCmgr4CV1cY9kw81 +kHsBQxaGJpnvO14Fem0i7ssi0oDf6I5ELWveh0y X-Received: by 2002:a05:6902:154e:b0:66e:6718:f6f2 with SMTP id r14-20020a056902154e00b0066e6718f6f2mr1293389ybu.228.1657675440625; Tue, 12 Jul 2022 18:24:00 -0700 (PDT) MIME-Version: 1.0 References: <20220707145248.458771-1-apatel@ventanamicro.com> <20220707145248.458771-6-apatel@ventanamicro.com> In-Reply-To: <20220707145248.458771-6-apatel@ventanamicro.com> From: Atish Patra Date: Tue, 12 Jul 2022 18:23:50 -0700 Message-ID: Subject: Re: [PATCH 5/5] RISC-V: KVM: Add support for Svpbmt inside Guest/VM To: Anup Patel Cc: Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Alistair Francis , Anup Patel , KVM General , "open list:KERNEL VIRTUAL MACHINE FOR RISC-V (KVM/riscv)" , 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 Thu, Jul 7, 2022 at 7:53 AM Anup Patel wrote: > > The Guest/VM can use Svpbmt in VS-stage page tables when allowed by the > Hypervisor using the henvcfg.PBMTE bit. > > We add Svpbmt support for the KVM Guest/VM which can be enabled/disabled > by the KVM user-space (QEMU/KVMTOOL) using the ISA extension ONE_REG > interface. > > Signed-off-by: Anup Patel > --- > arch/riscv/include/asm/csr.h | 16 ++++++++++++++++ > arch/riscv/include/uapi/asm/kvm.h | 1 + > arch/riscv/kvm/vcpu.c | 16 ++++++++++++++++ > 3 files changed, 33 insertions(+) > > diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h > index 6d85655e7edf..17516afc389a 100644 > --- a/arch/riscv/include/asm/csr.h > +++ b/arch/riscv/include/asm/csr.h > @@ -156,6 +156,18 @@ > (_AC(1, UL) << IRQ_S_TIMER) | \ > (_AC(1, UL) << IRQ_S_EXT)) > > +/* xENVCFG flags */ > +#define ENVCFG_STCE (_AC(1, ULL) << 63) > +#define ENVCFG_PBMTE (_AC(1, ULL) << 62) > +#define ENVCFG_CBZE (_AC(1, UL) << 7) > +#define ENVCFG_CBCFE (_AC(1, UL) << 6) > +#define ENVCFG_CBIE_SHIFT 4 > +#define ENVCFG_CBIE (_AC(0x3, UL) << ENVCFG_CBIE_SHIFT) > +#define ENVCFG_CBIE_ILL _AC(0x0, UL) > +#define ENVCFG_CBIE_FLUSH _AC(0x1, UL) > +#define ENVCFG_CBIE_INV _AC(0x3, UL) > +#define ENVCFG_FIOM _AC(0x1, UL) > + > /* symbolic CSR names: */ > #define CSR_CYCLE 0xc00 > #define CSR_TIME 0xc01 > @@ -252,7 +264,9 @@ > #define CSR_HTIMEDELTA 0x605 > #define CSR_HCOUNTEREN 0x606 > #define CSR_HGEIE 0x607 > +#define CSR_HENVCFG 0x60a > #define CSR_HTIMEDELTAH 0x615 > +#define CSR_HENVCFGH 0x61a > #define CSR_HTVAL 0x643 > #define CSR_HIP 0x644 > #define CSR_HVIP 0x645 > @@ -264,6 +278,8 @@ > #define CSR_MISA 0x301 > #define CSR_MIE 0x304 > #define CSR_MTVEC 0x305 > +#define CSR_MENVCFG 0x30a > +#define CSR_MENVCFGH 0x31a > #define CSR_MSCRATCH 0x340 > #define CSR_MEPC 0x341 > #define CSR_MCAUSE 0x342 > diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h > index 6119368ba6d5..24b2a6e27698 100644 > --- a/arch/riscv/include/uapi/asm/kvm.h > +++ b/arch/riscv/include/uapi/asm/kvm.h > @@ -96,6 +96,7 @@ enum KVM_RISCV_ISA_EXT_ID { > KVM_RISCV_ISA_EXT_H, > KVM_RISCV_ISA_EXT_I, > KVM_RISCV_ISA_EXT_M, > + KVM_RISCV_ISA_EXT_SVPBMT, > KVM_RISCV_ISA_EXT_MAX, > }; > > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c > index 6dd9cf729614..b7a433c54d0f 100644 > --- a/arch/riscv/kvm/vcpu.c > +++ b/arch/riscv/kvm/vcpu.c > @@ -51,6 +51,7 @@ static const unsigned long kvm_isa_ext_arr[] = { > RISCV_ISA_EXT_h, > RISCV_ISA_EXT_i, > RISCV_ISA_EXT_m, > + RISCV_ISA_EXT_SVPBMT, > }; > > static unsigned long kvm_riscv_vcpu_base2isa_ext(unsigned long base_ext) > @@ -777,6 +778,19 @@ 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) > +{ > + u64 henvcfg = 0; > + > + if (__riscv_isa_extension_available(isa, RISCV_ISA_EXT_SVPBMT)) > + henvcfg |= ENVCFG_PBMTE; > + > + csr_write(CSR_HENVCFG, henvcfg); > +#ifdef CONFIG_32BIT > + csr_write(CSR_HENVCFGH, henvcfg >> 32); > +#endif > +} > + > void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > { > struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; > @@ -791,6 +805,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > csr_write(CSR_HVIP, csr->hvip); > csr_write(CSR_VSATP, csr->vsatp); > > + kvm_riscv_vcpu_update_config(vcpu->arch.isa); > + > kvm_riscv_gstage_update_hgatp(vcpu); > > kvm_riscv_vcpu_timer_restore(vcpu); > -- > 2.34.1 > LGTM. Reviewed-by: Atish Patra -- Regards, Atish