Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4416444ioa; Wed, 27 Apr 2022 03:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx6g4qRiIP98yX8j/VR+K62qrgWJ9S+vgUNJIpk/MSnVBPtnunmub0zwutWItHjC/GxBH/ X-Received: by 2002:a17:902:f605:b0:154:aa89:bd13 with SMTP id n5-20020a170902f60500b00154aa89bd13mr28131789plg.112.1651055289372; Wed, 27 Apr 2022 03:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651055289; cv=none; d=google.com; s=arc-20160816; b=jeXQB6K58p58MG31L7/+RQEPDlrCiRwZI2v4FWnltpiCHJjuAVUKtxtd5o+zgWqlXP TxeLAgFw1UC8Nix5b4gKaPRluIqIkaEqDLZqipPPHxBHhFqO6CS3brRac6unKw2KwS6R Dnjrj/4E9ZOjXWbblg7wGQLkYRGJzjc+ySdXN8FS0aoqJ4gE4PKGpiBjgATL19BZxP2l T8bOpQah90sDDg/nMtqb8AtiYun4o96/ey9O+AHgfBgrVVXk6+B/wfg83f1gLHwJDDrZ 16gtUlVLrQDnwTJtfRDUz0syEryuIFVz9BqxNT4UgK4BjALRt7mca+5bVPzxWQ010ytd QXVg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lkORTyE4+2S4eSHBhvp14/h/F0xRr3P2TIZmyQV++C0=; b=NXA8OCmIPnzHVrbSl1BFZ3xsVXZ8Fq+Etr2+Rr9e1eVxIvpweUIKGtGV/bd71UbYWE Ox2CD/fWEEI/VjZxm9PHvHTGiSHmz/fnm1w02FKCbLrY3LSpmiZdVtDDa4CNc3ksAyKQ Ewt0zPoAQuesUMtVULr2+33VoCsYIqSCKbNfvZQ60GHTUPGzWaxt57RhbRgzgirgqpe0 uvywjTpIStoIUt8rKp3m0qPf2tcZT/BJJvdTiFdaU99Af4IVOHmLgRuOXwtRjQkQlZPa bYaGE5u44/l6LNIyPe+lTrk3Wmal/XQ2OuH4IJmbmFbBupmGm//C7cBg8UnD659gOMa8 3/hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fp440xzH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p31-20020a056a000a1f00b0050832077ba7si1083562pfh.273.2022.04.27.03.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fp440xzH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0135D395205; Wed, 27 Apr 2022 02:44:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347519AbiDZJ2D (ORCPT + 99 others); Tue, 26 Apr 2022 05:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347321AbiDZJF1 (ORCPT ); Tue, 26 Apr 2022 05:05:27 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86A5410FF35; Tue, 26 Apr 2022 01:44:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 90520CE1BC9; Tue, 26 Apr 2022 08:44:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B240C385A4; Tue, 26 Apr 2022 08:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962662; bh=DmMGXqK7DS2Xf58XdTr8GbA0QdOIbiW13DwxnpGq0S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fp440xzHA8bW9i4PISZ6DpncbW2z0sUhjMPWYisnRIoh3mhTL1pg6J6a8swrkWV5q 3ZOHfbw7kn5R+BoRny3dsRR9sHewN9z95mkY4CFurg4oEYHN4c4ihwg3yU7DWXtOvo zYOw+V+j0mpx4rsnq8lMwX7GP0TGo8mGk3LRZkSw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Atish Patra , Anup Patel , Sasha Levin Subject: [PATCH 5.17 046/146] RISC-V: KVM: Restrict the extensions that can be disabled Date: Tue, 26 Apr 2022 10:20:41 +0200 Message-Id: <20220426081751.364424754@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081750.051179617@linuxfoundation.org> References: <20220426081750.051179617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Atish Patra [ Upstream commit 38d9a4ac65f204f264b33b966f0af4366f5518a8 ] Currently, the config isa register allows us to disable all allowed single letter ISA extensions. It shouldn't be the case as vmm shouldn't be able to disable base extensions (imac). These extensions should always be enabled as long as they are enabled in the host ISA. Signed-off-by: Atish Patra Signed-off-by: Anup Patel Fixes: 92ad82002c39 ("RISC-V: KVM: Implement KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls") Signed-off-by: Sasha Levin --- arch/riscv/kvm/vcpu.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 2e25a7b83a1b..aad430668bb4 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -38,12 +38,16 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { sizeof(kvm_vcpu_stats_desc), }; -#define KVM_RISCV_ISA_ALLOWED (riscv_isa_extension_mask(a) | \ - riscv_isa_extension_mask(c) | \ - riscv_isa_extension_mask(d) | \ - riscv_isa_extension_mask(f) | \ - riscv_isa_extension_mask(i) | \ - riscv_isa_extension_mask(m)) +#define KVM_RISCV_ISA_DISABLE_ALLOWED (riscv_isa_extension_mask(d) | \ + riscv_isa_extension_mask(f)) + +#define KVM_RISCV_ISA_DISABLE_NOT_ALLOWED (riscv_isa_extension_mask(a) | \ + riscv_isa_extension_mask(c) | \ + riscv_isa_extension_mask(i) | \ + riscv_isa_extension_mask(m)) + +#define KVM_RISCV_ISA_ALLOWED (KVM_RISCV_ISA_DISABLE_ALLOWED | \ + KVM_RISCV_ISA_DISABLE_NOT_ALLOWED) static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) { @@ -217,7 +221,8 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu, switch (reg_num) { case KVM_REG_RISCV_CONFIG_REG(isa): if (!vcpu->arch.ran_atleast_once) { - vcpu->arch.isa = reg_val; + /* Ignore the disable request for these extensions */ + vcpu->arch.isa = reg_val | KVM_RISCV_ISA_DISABLE_NOT_ALLOWED; vcpu->arch.isa &= riscv_isa_extension_base(NULL); vcpu->arch.isa &= KVM_RISCV_ISA_ALLOWED; kvm_riscv_vcpu_fp_reset(vcpu); -- 2.35.1