Message ID | 20230918180646.1398384-5-apatel@ventanamicro.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3153289vqi; Mon, 18 Sep 2023 22:49:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzrMDbhMXx1HHoGzu8afl/DcxMUYfp5FeFp/vYWOQOQwn9KQeuHS92tO3rhbzVcBH/aXbY X-Received: by 2002:a17:902:6949:b0:1bb:9b29:20d9 with SMTP id k9-20020a170902694900b001bb9b2920d9mr9974248plt.20.1695102582928; Mon, 18 Sep 2023 22:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695102582; cv=none; d=google.com; s=arc-20160816; b=PZ+BsMPsLWNaQ8NFyOZh6wDSIG+3jPqfv5O7CEOoBoPl8LqMAZWppfaTfHDceOl3Oz xGb0XnqhR7iMEfzLXsUmchA6mZ0sxxIZhjwTlebNlgYGFoTHRBEPK+F5ul2F8wHXaM7n S1fzICzCIA9+5z9UPtpX1SIcGpvlVEZUeYc+TtsKpza53Dc4ej8q4GGNgV2iAfxyTemJ 9PCENtZ2+t0suPKUWTbo703BozqrAtylJ4LZLRP1S+PpdHXBiQP2cfbAgZkf7bk/a+JN pXeLD93tB8CDQ3W9u7evaMapWJWEogbJ38Ndaik6M2pWHYpm2zEFzTGG4SpE11o14YIW VzIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bpLoyMijHBoqQ//iQuuQg2kQqMONVlRrgQK7tTPKQvg=; fh=2S+54NKBCousR9yNCeiEbYlRCvnfU9LmKXxbaD6jKe8=; b=sGXWfTHFeHW4QckBx6HMhaUMfqmNitExXcUGL+82KNqYEsBHZqWrGwqAD0bqgRfkWW fOrcVk2dL6op5xduPYxVMMwaomLyz0G1rKBqFI4aF/k3cZaq3YkjiwpBbeFh8PGVCeOx SiKZ2X0p9wSUIEm9Ml98EukvXpOnuKYZ8qeiz3VnNfry09LjMcW9yap9cDpirMv+O/R3 Weyt777fC+TkkXw3zu5h762RSt5uZ8cCl/xn6Cm7DAU4lI9NKjc07yW7Y4NklPxheQHO lzraMTz8nJJYdf5Vp7N9HlhavmMzY/Z8SrnhNlqhvoWmt8SnKRqQBvSu0rgfazgI5VQZ Nxmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=mhaPApHP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f18-20020a170902ce9200b001bbd0358ef7si9482091plg.518.2023.09.18.22.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 22:49:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=mhaPApHP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9AEC381A1E9C; Mon, 18 Sep 2023 11:07:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjIRSHi (ORCPT <rfc822;kernel.ruili@gmail.com> + 25 others); Mon, 18 Sep 2023 14:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229776AbjIRSH0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 18 Sep 2023 14:07:26 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A89B8126 for <linux-kernel@vger.kernel.org>; Mon, 18 Sep 2023 11:07:16 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c4707b1031so14903585ad.2 for <linux-kernel@vger.kernel.org>; Mon, 18 Sep 2023 11:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695060436; x=1695665236; darn=vger.kernel.org; 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=bpLoyMijHBoqQ//iQuuQg2kQqMONVlRrgQK7tTPKQvg=; b=mhaPApHPeu6Ramd6n9ddV0AZ872+Rnt6Mz9YNzMaEbyJnre9Y0ROlOAG39xjKofO9t b5/omxnvKmE6q4xNcupPKPKNCI+SvyxcyZ+Fl7unkwCbGB7NPDJ88VMGY03Xwhszl+el 5Sk8VFU7er7EHryhjCpjZXS0rAOwnf/UrUoPe7z8KQA6BNG+JLe5ygXQcrthkxpzUcSl Y3u9H/a1G69tb2O/UMLu5nw6tfYvtzkpmi2BK2HJ1FHOh+qIJMMnWPf1qzWYWzKpjhuc pB6Iq/thu3ptdvZQHFPx/YZBOqaL1VRNVNGJS5P9//oyO41Xm1rH+RLcbI1aCE2/yH+w NSLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695060436; x=1695665236; 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=bpLoyMijHBoqQ//iQuuQg2kQqMONVlRrgQK7tTPKQvg=; b=CpBtc6SbpCHPKQ+TNVZQ7Y+ky+UpScynEVcBY0dHq5fI17cM0RASOO7nOryFAJxfAl j/d6iGSuDioJlW36Awb2AIB+ZLRifyoQkTKZPEb3SRlL+3YYPCYZdJ5QFJ7ee+3tgP7Z F16c74NPIpXCOPOg8PBwNjKPUqMBZ1XP4dIozOR2T5dE9ueA3VB0s5jJbzJQKnnGDAtg vQpeRBmE4AoCwUBe8nWvGpxqx3gZ2l4DlKErtQ4pC3cRaxjMtu6PnEHlniQI/+Fma7L0 hsnfIRFa4dIYOnKSFabkDQbDW0agQzglCpE7CIxm4VG+SHGk8FUKVwqyYhgANOPrahZn JoYw== X-Gm-Message-State: AOJu0YygQNcWLLvITJznb+E6xvt2QdCfETQyGlpH3FxX6HoYTZ1vGRAQ Wzj+8hqdpkKa5yMRg2nMP3tYsA== X-Received: by 2002:a17:902:728a:b0:1bb:d048:3173 with SMTP id d10-20020a170902728a00b001bbd0483173mr10004616pll.61.1695060435836; Mon, 18 Sep 2023 11:07:15 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id h7-20020a170902704700b001aaf2e8b1eesm8556720plt.248.2023.09.18.11.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:07:15 -0700 (PDT) From: Anup Patel <apatel@ventanamicro.com> To: Paolo Bonzini <pbonzini@redhat.com>, Atish Patra <atishp@atishpatra.org>, Shuah Khan <shuah@kernel.org> Cc: Palmer Dabbelt <palmer@dabbelt.com>, Paul Walmsley <paul.walmsley@sifive.com>, Andrew Jones <ajones@ventanamicro.com>, 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 <apatel@ventanamicro.com> Subject: [PATCH 4/4] KVM: riscv: selftests: Selectively filter-out AIA registers Date: Mon, 18 Sep 2023 23:36:46 +0530 Message-Id: <20230918180646.1398384-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918180646.1398384-1-apatel@ventanamicro.com> References: <20230918180646.1398384-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:07:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777443886328077258 X-GMAIL-MSGID: 1777443886328077258 |
Series |
KVM RISC-V fixes for ONE_REG interface
|
|
Commit Message
Anup Patel
Sept. 18, 2023, 6:06 p.m. UTC
Currently the AIA ONE_REG registers are reported by get-reg-list
as new registers for various vcpu_reg_list configs whenever Ssaia
is available on the host because Ssaia extension can only be
disabled by Smstateen extension which is not always available.
To tackle this, we should filter-out AIA ONE_REG registers only
when Ssaia can't be disabled for a VCPU.
Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test")
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
.../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
Comments
On Mon, Sep 18, 2023 at 11:07 AM Anup Patel <apatel@ventanamicro.com> wrote: > > Currently the AIA ONE_REG registers are reported by get-reg-list > as new registers for various vcpu_reg_list configs whenever Ssaia > is available on the host because Ssaia extension can only be > disabled by Smstateen extension which is not always available. > > To tackle this, we should filter-out AIA ONE_REG registers only > when Ssaia can't be disabled for a VCPU. > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > --- > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > 1 file changed, 21 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > index 76c0ad11e423..85907c86b835 100644 > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > @@ -12,6 +12,8 @@ > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > + > bool filter_reg(__u64 reg) > { > switch (reg & ~REG_MASK) { > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > return true; > + /* AIA registers are always available when Ssaia can't be disabled */ > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; Ahh I guess. you do need the switch case for AIA CSRs but for ISA extensions can be avoided as it is contiguous. > default: > break; > } > @@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > { > + int rc; > struct vcpu_reg_sublist *s; > + unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; > + > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); > > /* > * Disable all extensions which were enabled by default > * if they were available in the risc-v host. > */ > - for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > - __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { > + rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > + if (rc && isa_ext_state[i]) > + isa_ext_cant_disable[i] = true; > + } > > for_each_sublist(c, s) { > if (!s->feature) > -- > 2.34.1 > Otherwise, LGTM. Reviewed-by: Atish Patra <atishp@rivosinc.com>
On Tue, Sep 19, 2023 at 01:12:47PM -0700, Atish Patra wrote: > On Mon, Sep 18, 2023 at 11:07 AM Anup Patel <apatel@ventanamicro.com> wrote: > > > > Currently the AIA ONE_REG registers are reported by get-reg-list > > as new registers for various vcpu_reg_list configs whenever Ssaia > > is available on the host because Ssaia extension can only be > > disabled by Smstateen extension which is not always available. > > > > To tackle this, we should filter-out AIA ONE_REG registers only > > when Ssaia can't be disabled for a VCPU. > > > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > --- > > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > > 1 file changed, 21 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > index 76c0ad11e423..85907c86b835 100644 > > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > @@ -12,6 +12,8 @@ > > > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > > + > > bool filter_reg(__u64 reg) > > { > > switch (reg & ~REG_MASK) { > > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > > return true; > > + /* AIA registers are always available when Ssaia can't be disabled */ > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; > > Ahh I guess. you do need the switch case for AIA CSRs but for ISA > extensions can be avoided as it is contiguous. I guess we could so something like case KVM_REG_RISCV_ISA_EXT ... KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_MAX: for the ISA extensions. Thanks, drew
On Mon, Sep 18, 2023 at 11:36:46PM +0530, Anup Patel wrote: > Currently the AIA ONE_REG registers are reported by get-reg-list > as new registers for various vcpu_reg_list configs whenever Ssaia > is available on the host because Ssaia extension can only be > disabled by Smstateen extension which is not always available. > > To tackle this, we should filter-out AIA ONE_REG registers only > when Ssaia can't be disabled for a VCPU. > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > --- > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > 1 file changed, 21 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > index 76c0ad11e423..85907c86b835 100644 > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > @@ -12,6 +12,8 @@ > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > + > bool filter_reg(__u64 reg) > { > switch (reg & ~REG_MASK) { > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > return true; > + /* AIA registers are always available when Ssaia can't be disabled */ > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; No need for the '? true : false' > default: > break; > } > @@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > { > + int rc; > struct vcpu_reg_sublist *s; > + unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; nit: I think we prefer reverse xmas tree in kselftests, but whatever. > + > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); > > /* > * Disable all extensions which were enabled by default > * if they were available in the risc-v host. > */ > - for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > - __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { > + rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > + if (rc && isa_ext_state[i]) How helpful is it to check that isa_ext_state[i] isn't zero? The value of the register could be zero, right? Shouldn't we instead capture the return values from __vcpu_get_reg and if the return value is zero for a get, but nonzero for a set, then we know we have it, but can't disable it. > + isa_ext_cant_disable[i] = true; > + } > > for_each_sublist(c, s) { > if (!s->feature) > -- > 2.34.1 > Thanks, drew
On Wed, Sep 20, 2023 at 06:48:11AM +0200, Andrew Jones wrote: > On Tue, Sep 19, 2023 at 01:12:47PM -0700, Atish Patra wrote: > > On Mon, Sep 18, 2023 at 11:07 AM Anup Patel <apatel@ventanamicro.com> wrote: > > > > > > Currently the AIA ONE_REG registers are reported by get-reg-list > > > as new registers for various vcpu_reg_list configs whenever Ssaia > > > is available on the host because Ssaia extension can only be > > > disabled by Smstateen extension which is not always available. > > > > > > To tackle this, we should filter-out AIA ONE_REG registers only > > > when Ssaia can't be disabled for a VCPU. > > > > > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > > --- > > > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > > > 1 file changed, 21 insertions(+), 2 deletions(-) > > > > > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > > index 76c0ad11e423..85907c86b835 100644 > > > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > > > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > > @@ -12,6 +12,8 @@ > > > > > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > > > > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > > > + > > > bool filter_reg(__u64 reg) > > > { > > > switch (reg & ~REG_MASK) { > > > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > > > return true; > > > + /* AIA registers are always available when Ssaia can't be disabled */ > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > > > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; > > > > Ahh I guess. you do need the switch case for AIA CSRs but for ISA > > extensions can be avoided as it is contiguous. > > I guess we could so something like > > case KVM_REG_RISCV_ISA_EXT ... KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_MAX: > > for the ISA extensions. > On second thought, I think I like them each listed explicitly. When we add a new extension it will show up in the new register list, which will not only remind us that it needs to be filtered, but also that we should probably also create a specific config for it. Thanks, drew
On Wed, Sep 20, 2023 at 07:24:16AM +0200, Andrew Jones wrote: > On Mon, Sep 18, 2023 at 11:36:46PM +0530, Anup Patel wrote: > > Currently the AIA ONE_REG registers are reported by get-reg-list > > as new registers for various vcpu_reg_list configs whenever Ssaia > > is available on the host because Ssaia extension can only be > > disabled by Smstateen extension which is not always available. > > > > To tackle this, we should filter-out AIA ONE_REG registers only > > when Ssaia can't be disabled for a VCPU. > > > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > --- > > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > > 1 file changed, 21 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > index 76c0ad11e423..85907c86b835 100644 > > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > @@ -12,6 +12,8 @@ > > > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > > + > > bool filter_reg(__u64 reg) > > { > > switch (reg & ~REG_MASK) { > > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > > return true; > > + /* AIA registers are always available when Ssaia can't be disabled */ > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; > > No need for the '? true : false' > > > default: > > break; > > } > > @@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > > > void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > > { > > + int rc; > > struct vcpu_reg_sublist *s; > > + unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; > > nit: I think we prefer reverse xmas tree in kselftests, but whatever. > > > + > > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > > + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); > > > > /* > > * Disable all extensions which were enabled by default > > * if they were available in the risc-v host. > > */ > > - for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > > - __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { > > + rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > > + if (rc && isa_ext_state[i]) > > How helpful is it to check that isa_ext_state[i] isn't zero? The value of > the register could be zero, right? Shouldn't we instead capture the return > values from __vcpu_get_reg and if the return value is zero for a get, > but nonzero for a set, then we know we have it, but can't disable it. Eh, never mind. After sending this, I felt like there was something fishy about my interpretation of how this works, so I took a second look. The patch is correct as is, since we're checking for when the ISA extension is present, but we can't disable it (just like it says it's doing :-) I was thinking too much about AIA registers and not ISA extension registers. > > > + isa_ext_cant_disable[i] = true; > > + } > > > > for_each_sublist(c, s) { > > if (!s->feature) > > -- > > 2.34.1 > > > Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Thanks, drew
On Wed, Sep 20, 2023 at 10:54 AM Andrew Jones <ajones@ventanamicro.com> wrote: > > On Mon, Sep 18, 2023 at 11:36:46PM +0530, Anup Patel wrote: > > Currently the AIA ONE_REG registers are reported by get-reg-list > > as new registers for various vcpu_reg_list configs whenever Ssaia > > is available on the host because Ssaia extension can only be > > disabled by Smstateen extension which is not always available. > > > > To tackle this, we should filter-out AIA ONE_REG registers only > > when Ssaia can't be disabled for a VCPU. > > > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > --- > > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > > 1 file changed, 21 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > index 76c0ad11e423..85907c86b835 100644 > > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > @@ -12,6 +12,8 @@ > > > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > > + > > bool filter_reg(__u64 reg) > > { > > switch (reg & ~REG_MASK) { > > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > > return true; > > + /* AIA registers are always available when Ssaia can't be disabled */ > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; > > No need for the '? true : false' Okay, I will update. > > > default: > > break; > > } > > @@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > > > void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > > { > > + int rc; > > struct vcpu_reg_sublist *s; > > + unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; > > nit: I think we prefer reverse xmas tree in kselftests, but whatever. Okay, I will update. > > > + > > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > > + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); > > > > /* > > * Disable all extensions which were enabled by default > > * if they were available in the risc-v host. > > */ > > - for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > > - __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { > > + rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > > + if (rc && isa_ext_state[i]) > > How helpful is it to check that isa_ext_state[i] isn't zero? The value of > the register could be zero, right? Shouldn't we instead capture the return > values from __vcpu_get_reg and if the return value is zero for a get, > but nonzero for a set, then we know we have it, but can't disable it. The intent is to find-out the ISA_EXT registers which are enabled but we are not able to disable it. > > > + isa_ext_cant_disable[i] = true; > > + } > > > > for_each_sublist(c, s) { > > if (!s->feature) > > -- > > 2.34.1 > > > > Thanks, > drew Regards, Anup
On Wed, Sep 20, 2023 at 1:43 AM Atish Patra <atishp@atishpatra.org> wrote: > > On Mon, Sep 18, 2023 at 11:07 AM Anup Patel <apatel@ventanamicro.com> wrote: > > > > Currently the AIA ONE_REG registers are reported by get-reg-list > > as new registers for various vcpu_reg_list configs whenever Ssaia > > is available on the host because Ssaia extension can only be > > disabled by Smstateen extension which is not always available. > > > > To tackle this, we should filter-out AIA ONE_REG registers only > > when Ssaia can't be disabled for a VCPU. > > > > Fixes: 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test") > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > --- > > .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- > > 1 file changed, 21 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > index 76c0ad11e423..85907c86b835 100644 > > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > @@ -12,6 +12,8 @@ > > > > #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) > > > > +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; > > + > > bool filter_reg(__u64 reg) > > { > > switch (reg & ~REG_MASK) { > > @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: > > case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: > > return true; > > + /* AIA registers are always available when Ssaia can't be disabled */ > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): > > + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): > > + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; > > Ahh I guess. you do need the switch case for AIA CSRs but for ISA > extensions can be avoided as it is contiguous. Fow now, let's leave it as-is because this way get-reg-list will complain if some new ONE_REG register is missed out. > > > default: > > break; > > } > > @@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > > > void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > > { > > + int rc; > > struct vcpu_reg_sublist *s; > > + unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; > > + > > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > > + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); > > > > /* > > * Disable all extensions which were enabled by default > > * if they were available in the risc-v host. > > */ > > - for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) > > - __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { > > + rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > > + if (rc && isa_ext_state[i]) > > + isa_ext_cant_disable[i] = true; > > + } > > > > for_each_sublist(c, s) { > > if (!s->feature) > > -- > > 2.34.1 > > > > Otherwise, LGTM. > > Reviewed-by: Atish Patra <atishp@rivosinc.com> > > -- > Regards, > Atish Regards, Anup
diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c index 76c0ad11e423..85907c86b835 100644 --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c @@ -12,6 +12,8 @@ #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; + bool filter_reg(__u64 reg) { switch (reg & ~REG_MASK) { @@ -48,6 +50,15 @@ bool filter_reg(__u64 reg) case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI: case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM: return true; + /* AIA registers are always available when Ssaia can't be disabled */ + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect): + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1): + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2): + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh): + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph): + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h): + case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h): + return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA] ? true : false; default: break; } @@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) { + int rc; struct vcpu_reg_sublist *s; + unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; + + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); /* * Disable all extensions which were enabled by default * if they were available in the risc-v host. */ - for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) - __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { + rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); + if (rc && isa_ext_state[i]) + isa_ext_cant_disable[i] = true; + } for_each_sublist(c, s) { if (!s->feature)