Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2930339imw; Sun, 17 Jul 2022 21:12:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tE3X4Wp1AagXo+B8GXD+T8xzOSqfcIEdjOeT4l1M5CJVpYNmIyjF/Zj3DbeePe4t3vmmQQ X-Received: by 2002:a63:d94a:0:b0:412:6e04:dc26 with SMTP id e10-20020a63d94a000000b004126e04dc26mr23248222pgj.539.1658117536142; Sun, 17 Jul 2022 21:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658117536; cv=none; d=google.com; s=arc-20160816; b=hy6yPVHP2o87gnDwngzkBoS+xc+gfzqNwlO6a6ILGKglSFkyQzZc3DJd+8E8h+o/jC O/Jj7EXlLOjSWnz3HZYdc8RGoefxwNGjsn4QvdSJuocS8udnQx23bP28A7Q0h4Yay590 TzCvfbE4gSNMvVB3rNz2ucsl+ASLH/JlitLN5kMdxhI9nD+SzpPYk/htEgCdrJVJjmLr EIAGLRgaZJ0g0Ad9hCpdEcT+HGaRs2Dqz/tDfGSJ+TBNOzuzVTdEQzvkXGOVn1FDxzuw qMJ3QtD6jtP19Nhgzr/R2JnhNxqsMBNqWXJjcqeNSBMYA/fsh2I9ain/firR24pedlab cv1A== 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=HHoY7kVryiChr5cJFDSaFpXhijBDuPWIwQr/N0jnjFo=; b=We/dv0ISE/6T0kcKpJZjYrY8bID4IQj5e0xFv49Sx0trua6OY1tVGMn/PXYIQzR4er ndiuR2T/KZD5mE+tdFJqrg0YLGRLA/LNfh/NZ28yzGTuzHq1y2it9ajOEZIKRDBLsIZ5 MGGDsZh+svHWqVNX/sg7bzO1RBhEJogZXkHnZvt1dCK6uZUUL0MvjcvlqGIo7gyCHgQ8 fvdeSVYwLRprUjJycQ++0Gy8Sx8ohC2yO75Up443w1r1eYBWTPSebXjjj/2PL25BDMh8 timEccH2D5E7DSSRUard+XiXF3OxXPQD11sHnQiQRhbU9Pv0rynKu1xLoP6YWk4ijEbb YpIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=qtaN6WcM; 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 q18-20020a63e952000000b00415ea6aca03si14297295pgj.547.2022.07.17.21.12.01; Sun, 17 Jul 2022 21:12:16 -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=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=qtaN6WcM; 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 S232667AbiGREHl (ORCPT + 99 others); Mon, 18 Jul 2022 00:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbiGREHj (ORCPT ); Mon, 18 Jul 2022 00:07:39 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88A812D0F for ; Sun, 17 Jul 2022 21:07:38 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id b26so15276408wrc.2 for ; Sun, 17 Jul 2022 21:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HHoY7kVryiChr5cJFDSaFpXhijBDuPWIwQr/N0jnjFo=; b=qtaN6WcM7juIy+n1eFrV7mazTFqzvLWTIBqtGrqh9fUUTz89/1F1Ps6gSAq0qbntIl HR0NdANXG7QVJ15000c4yJwY4aEOJeWWaZgTdi7QwfejvWE2/OiZrzlgGWtRU4txCSZ5 +cIb1kW9R3JWRvtBRbbJhuIZ5+jcRx60qDrmXwZBVGXOmDt64JGJjoLIrFKkLQhaufuf yvxDoJ12zqmZU6WLqy9mPWj+A4sgGfGfJAbBux6jeGNlG3nHThIq1F+U/DOddBa2ufZN iuV4eWst2h0BrJ4Q0p2YTubNC1EItG7sXU00T78E0eCWCON1qEUL3PqoegYJH+IVy4Ek y3EA== 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=HHoY7kVryiChr5cJFDSaFpXhijBDuPWIwQr/N0jnjFo=; b=jhvC2c1qBpI2D856SiAEqKgdq0DG23HDfc5o3m/8zG7rM6kvcD603gKNwVHMuKY/AP ExsXjik/BYXMNHuRcAfRld1CGW3iUr0+3jqjPe1D51BoLCfVKBQ6NFee1rcw8J8zjM5V C1NASUO/4i0KI+vgMdDEbHLSECN0wZCMlGd2oCoIezc8jN7lzUodUgK5TcOPadtaPpFz wMSFkJH2mne8XmR+iMH2EvB9O78oGPge9gQ429yihsTjv4F/vjBihyY68MnN0Cj4UOQA W7WtVTytPQa9XaR6gj2JvkDju5SN8q930U7Tp+6yQp9kJgihxVkYFcJhrMWX1R5nUMGb t9rA== X-Gm-Message-State: AJIora+Mk2s8ySD9adC6xZpe9FOehE2cgAu9YPRKowH7UK6ABvuEXxEc aD7PpkOkaYNzloWdA0ceWp9sQXaXKSduiSrDCXXui4oqXwPFIA== X-Received: by 2002:a5d:64ac:0:b0:21d:7832:ecf9 with SMTP id m12-20020a5d64ac000000b0021d7832ecf9mr20978506wrp.86.1658117257348; Sun, 17 Jul 2022 21:07:37 -0700 (PDT) MIME-Version: 1.0 References: <20220707145248.458771-1-apatel@ventanamicro.com> <20220707145248.458771-6-apatel@ventanamicro.com> In-Reply-To: From: Anup Patel Date: Mon, 18 Jul 2022 09:37:25 +0530 Message-ID: Subject: Re: [PATCH 5/5] RISC-V: KVM: Add support for Svpbmt inside Guest/VM To: Atish Patra Cc: Anup Patel , Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Alistair Francis , 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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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, Jul 13, 2022 at 6:54 AM Atish Patra wrote: > > 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 > Queued this patch for 5.20. Thanks, Anup