Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1142086rdb; Wed, 20 Sep 2023 00:13:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7fqlmhr4qafCAKKUpAF/UKmJVVX+RirN5sIW1tAXQrL5S6iGtu7h5tv6jR3D0XEBy1A4i X-Received: by 2002:a05:6a20:8420:b0:157:e4c6:766a with SMTP id c32-20020a056a20842000b00157e4c6766amr2167521pzd.41.1695193980974; Wed, 20 Sep 2023 00:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695193980; cv=none; d=google.com; s=arc-20160816; b=YwuKLrgQeC4biXe7+SEyPB5CUwgzmirSdKEo6vJT6URbWQYnUPoGISA5E7JBQnMZiX YW6V0ITZGb7J6O8Mx62OXY5fcGsxkIzCE3TfzR5SUEXs9VeQAXYU/ikNRe+m+gciWS97 1lBMSNYys7skNrOL2H6eWQZQmhxk0YDDP8d8cnH0tKnNwHvCK1ZrZ9a0ZKIo2CjNKiYy s3jstwTK3ZkkhUg54/1zB3FqpOHtQ1soannnSRpB1fY/d6dxH+9RbMFIhZjxPSQxwyhQ PIL6IDdSlp1IsZTkkWQL3CIywRARJtTihxs1YyMClyLFhYoZ9oCmFYjDUgfjcpS4A5I0 JJow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rYSL2OliA8I9jFK5tlBwpRh/J6O5TRCGMrfD6pOu/aU=; fh=nyUiyAsrvrmzhT78twm/HjZK3HoXiwGs/QcgTn/TSA0=; b=Krv7PM7cFqsDftDAbQXKs2oD6o9Wfu4ndU07wlX7wvofubdWg+VPDV326hKeNpevhG 2MfNDCoitntBKu018f5hPIH1coktB/fT5tm8RQWczHzu66uDGjqXkZnIljrt5TBtGoFh Pe58vFoAYLqMU5PZLTQk6yM4gRSUP51Xoejdl+966NVG6lHRqbrK4mXYMuT4ZW5lcEnu /pzF+z/lczIymD5Sj/TU50tNjTAjkRSttV5p/Fe2NmPudaFuqjmzDk1gq3DiBiij9itb IUJXKUDTA5KR76kUJx3BY2UZvmEE2WT/XXQcTB0JnJMo9SI6hXdGXcfcNRfGs1sABmck P/wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=iD1jgcRc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h3-20020a170902680300b001c448d89b6asi7565586plk.104.2023.09.20.00.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 00:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=iD1jgcRc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 17F5F807792D; Wed, 20 Sep 2023 00:10:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233595AbjITHKe (ORCPT + 99 others); Wed, 20 Sep 2023 03:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbjITHKd (ORCPT ); Wed, 20 Sep 2023 03:10:33 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5FB799 for ; Wed, 20 Sep 2023 00:10:27 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31ff2ce9d4cso4907021f8f.0 for ; Wed, 20 Sep 2023 00:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695193826; x=1695798626; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rYSL2OliA8I9jFK5tlBwpRh/J6O5TRCGMrfD6pOu/aU=; b=iD1jgcRc8xCdA7s+NsBn5xmXKATx6nOYpYpdeAAJs6MczuyjPfD7Lly3Och/0lXudu WYlZW5eiCvag2EQ1YmHEFEB/oQ6kmWugKX8qggvb7gbJcp/++N+gstzzVPaTiJp5bXUl V0aUovDNxlZY+DkWm6jYuMrVAL0qeKS0yxcln9VhzH1DrJX9XRM3KN+0s21UVQF29yxh c7Ozw55cMrOaJl4z9a0FbAUkUfgYmt+YY/bbUoYSG1nrfBFKL7DAMGGWUwDHZIx4MQV3 ursECcvO/Ia9ovGCznmQytfmJ740XzJiCut9i3IAaIJVKr2nFIofztHfegmbzjOeisxN sAGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695193826; x=1695798626; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rYSL2OliA8I9jFK5tlBwpRh/J6O5TRCGMrfD6pOu/aU=; b=g2GkTCgP1xZmw41jVf0nwJduchVg4+mB7kydyeOOUCRQLLmMvJZrB29uA/l2goa4qC P/VCbIRepzcgbGqp5sxD45uhIEtY6xmywwkgXsB8IWixVRyQjxjYgs9Ag+gXSP6pZlJ/ EDdC+wYNSQUlB62rZDMqENGnoyVMX6kxDk1CihicBu2esleuI6BndEsyc0lGanSJwM9X HUDMqXYpwGlfkIKQXG3P4rYjl09m14gJE6+9XeAteTVlko3yMBkS6cPvwrLH5z38nrp5 hpRxTVhcLFJRFyp//QGTGujda4CzdJ+I7nzSMv6/wURkTwK84NEdje17Oz6YFDT9g38j jYBA== X-Gm-Message-State: AOJu0YyLi2zIAuSg9RKqpv7LC+PkCpqSaeG0FavdBvkaUpGhwNTarHgw jJcs/hn5ABkOb8Fh71GvofpehA== X-Received: by 2002:adf:e990:0:b0:317:5f04:bc00 with SMTP id h16-20020adfe990000000b003175f04bc00mr1683384wrm.27.1695193826024; Wed, 20 Sep 2023 00:10:26 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id e17-20020adffc51000000b0031435731dfasm17486584wrs.35.2023.09.20.00.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 00:10:25 -0700 (PDT) Date: Wed, 20 Sep 2023 09:10:19 +0200 From: Andrew Jones To: Anup Patel Cc: Paolo Bonzini , Atish Patra , Shuah Khan , Palmer Dabbelt , Paul Walmsley , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 4/4] KVM: riscv: selftests: Selectively filter-out AIA registers Message-ID: <20230920-c1362aebecf7ef8e36489efa@orel> References: <20230918180646.1398384-1-apatel@ventanamicro.com> <20230918180646.1398384-5-apatel@ventanamicro.com> <20230920-d524c40b616536d0ad8213c3@orel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230920-d524c40b616536d0ad8213c3@orel> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 20 Sep 2023 00:10:41 -0700 (PDT) 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 > > --- > > .../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 Thanks, drew