From patchwork Wed Apr 20 01:32:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12819562 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8F3EC433F5 for ; Wed, 20 Apr 2022 01:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358746AbiDTBfx (ORCPT ); Tue, 19 Apr 2022 21:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352841AbiDTBfw (ORCPT ); Tue, 19 Apr 2022 21:35:52 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A39C2C138 for ; Tue, 19 Apr 2022 18:33:08 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id r83so166939pgr.2 for ; Tue, 19 Apr 2022 18:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FoHTOogFtEFyi2gNo6Vrdy4zpvF5IOVfK5C2C7jCsAQ=; b=MZELzdB6m/N+Tx2B2ifqHAoQt0o7GPvWBNxirhKoqDbWPYy3pyvqNwH5vc4KKtHimo tIJgCsRmVYwVmJq8AqCt1MbKzPF50nYZVIZKSgpuF0Uc3lsa5Mpl1BjvcEmtVfBzjcLT MJZfUrZY80AGXx+8axdjdEPU3FXBT6/aQosj0HVepLz6DaJjqhD24X6n5EahYw0oXaD1 y/ryXYBtJjPVSADimqPZXceX6fXJOeNoQRUGdZzzBeIU+iqkZbypTBw7BHWUiyQoSZf2 r9g4wdgg3jG0s2CtfZ3aHi7Ismv8AcqI/lZpZ7Nke/lZ0o1owmZOKKOgpniMEVM1yiaM 3oRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FoHTOogFtEFyi2gNo6Vrdy4zpvF5IOVfK5C2C7jCsAQ=; b=p3A1U9SlwccoEvZ3RJE/5r4EaL7sZBSZOVes65YFIxnzf8NqciDt0Sj05lpwBNn1z6 EQT3Y4W3d5+sseH4kjXQeXILAitAuOFvcsgHwP0uUWplsAY4iFQkf/sX7yPUmFVcmXji 0OQjJLZlgxIKrCUVDhuZDI1mFNmTMusxxb1tlVri0+cn9noEvUYyI7LRQi8btchwqvjV uXp+NzkhN6EST/sdwdS6W+PVkqAoOeqsvWuhLiiSqk+AVA06NrhccxRTpZSEE+ZOZMyd odpknPiHD5Ygx/ipJHELzgCfiCv2blkFVq1vOuk3u6+iMEztuU30L5Bt8cybmGsZqm3H Uzbw== X-Gm-Message-State: AOAM532M+kwQ0R4qZhLKuJCLVypi2RJ2l0+fs67i8vgJphANXO+vk8Q5 oiHX5aNgxa8iM4ZCRlkynVzNCdYn5KPRbg== X-Google-Smtp-Source: ABdhPJxubNniBJ0qcUnSZUXfvxlKrtRZAvi6X+saBuEJcQjBtqfiHGpD3lEIBbsx8g8XamIAwcIrLQ== X-Received: by 2002:a63:e912:0:b0:39d:f8f:ca7 with SMTP id i18-20020a63e912000000b0039d0f8f0ca7mr16851234pgh.121.1650418387455; Tue, 19 Apr 2022 18:33:07 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id r13-20020a635d0d000000b003aa482388dbsm2484863pgb.9.2022.04.19.18.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 18:33:07 -0700 (PDT) From: Atish Patra To: kvm@vger.kernel.org Cc: Atish Patra , Atish Patra , Anup Patel , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring , kvm-riscv@lists.infradead.org Subject: [PATCH 1/2] RISC-V: KVM: Remove 's' & 'u' as valid ISA extension Date: Tue, 19 Apr 2022 18:32:57 -0700 Message-Id: <20220420013258.3639264-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220420013258.3639264-1-atishp@rivosinc.com> References: <20220420013258.3639264-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There are no ISA extension defined as 's' & 'u' in RISC-V specifications. The misa register defines 's' & 'u' bit as Supervisor/User privilege mode enabled. But it should not appear in the ISA extension in the device tree. Remove those from the allowed ISA extension for kvm. Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 6785aef4cbd4..2e25a7b83a1b 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -43,9 +43,7 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { riscv_isa_extension_mask(d) | \ riscv_isa_extension_mask(f) | \ riscv_isa_extension_mask(i) | \ - riscv_isa_extension_mask(m) | \ - riscv_isa_extension_mask(s) | \ - riscv_isa_extension_mask(u)) + riscv_isa_extension_mask(m)) static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) { From patchwork Wed Apr 20 01:32:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12819563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B93FC433F5 for ; Wed, 20 Apr 2022 01:33:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358759AbiDTBf6 (ORCPT ); Tue, 19 Apr 2022 21:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358747AbiDTBfx (ORCPT ); Tue, 19 Apr 2022 21:35:53 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD5262BB0B for ; Tue, 19 Apr 2022 18:33:09 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id k14so191180pga.0 for ; Tue, 19 Apr 2022 18:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bQGz28Ui4S/iukqjTafR3gtWfXZeyNKknhgIBizer1w=; b=Ml9jMffdoy/2q7KFGepfvYHABxn+GEgv6sFYcp7cRyRu9aeoki9WAtEKAWMRAnc04b yEJH2yveccXmJIT0A2KILfR4/dg8uWdcp7hvfDh/vJlBov71W0uNrMeCwwIVI9EjpxK1 fvrh9xZIKnqtiJrAaoHbfYx2E1eFlL3KCfwHzfYTZ9YR7LzBBs09DE1U5SWdV9IpfHqR PnJpmAllJD3NC0fYdqwcemLqg28r6Z4dErbLY2yrH5Ejcpj51TwdGju+84Up0oB0+2ak eF2hLnIWyphii/a1xhm8Nvs77zvRqi8ax9kGVCkMdeBRFw2H8/xHKsFa6g5UfjI0U/ST fR2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bQGz28Ui4S/iukqjTafR3gtWfXZeyNKknhgIBizer1w=; b=7uulHSQqBTcereKKsrMr3o1Gij6zy0rlCwVe6PA2rdjSeRGiJdOTmji6xT/N+HXLh6 EE+4gI2IuxOARlad2BoWL2J4cyKGAgWo+ob5Ns5vt9m0LRmX0O/XoeVBOqvRblyOO17W arq2RkOPBFb+bLA8t5L5NXzdtILQSLh3Rrg/D+ovopxsoP2pMPx31siWU4RchxY0TIUm cDXpxZuEuwgmLcMtWZi9ILGouutqlSPYKgdp0SGTGQk2lxT2zWUcNW0yqjq8SiALlDf/ ulI26gG9kZBZySpQrSzoK0b8jM7IxtT1OVpUT5+u8WLPqaww/uJmr2I6eOF0/MUiAnSO 5oww== X-Gm-Message-State: AOAM530ifn/hLx4kG0sJjC771cBbhbLL7YUPyZLVGo4DNs9GaIGc7NWs oG8wloEHsYCNgxORlPGA9a4k66NtgtSn3Q== X-Google-Smtp-Source: ABdhPJzxTpZ+2xwx1gMkeidRVI2UERYeMHLYI3TWIyQPEGUnycJdzAomsob4aGhDIn3i1GIkK78eYA== X-Received: by 2002:a65:5286:0:b0:398:dad:c3d8 with SMTP id y6-20020a655286000000b003980dadc3d8mr17233342pgp.228.1650418388951; Tue, 19 Apr 2022 18:33:08 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id r13-20020a635d0d000000b003aa482388dbsm2484863pgb.9.2022.04.19.18.33.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 18:33:08 -0700 (PDT) From: Atish Patra To: kvm@vger.kernel.org Cc: Atish Patra , Atish Patra , Anup Patel , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring , kvm-riscv@lists.infradead.org Subject: [PATCH 2/2] RISC-V: KVM: Restrict the extensions that can be disabled Date: Tue, 19 Apr 2022 18:32:58 -0700 Message-Id: <20220420013258.3639264-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220420013258.3639264-1-atishp@rivosinc.com> References: <20220420013258.3639264-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently, the config reg register allows to disable all allowed single letter ISA extensions. It shouldn't be the case as vmm shouldn't be able 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 --- arch/riscv/kvm/vcpu.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 2e25a7b83a1b..14dd801651e5 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,9 +221,10 @@ 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; + vcpu->arch.isa &= KVM_RISCV_ISA_DISABLE_ALLOWED; kvm_riscv_vcpu_fp_reset(vcpu); } else { return -EOPNOTSUPP;