From patchwork Wed Apr 26 17:13:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13224792 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E0C1C77B7C for ; Wed, 26 Apr 2023 17:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QYD2oJu0KVL8IWJn8DzGrXMGpqqi3zj7T4imzT/CMEw=; b=WE10suihHLd+Kl ISzKi2OoJ7GwZjVqncNe44QfPD2oF3E3Y10skHA8qti37t/qr29fQlHlU3q082kuic7EG1SBpU8Ie FBbjVOO7X/51LRkj9ddQ04krzXkbMLXhTwoIlmYoBi4zTgiNJyaY7We15rqY1v7B2tyYJ22z/Gzv0 NJObC4s0vB2oarkV0AhACvC9Wopq5TtKLiyaKHC2KRAQj7SRCTvOZ9Ancpkvm3gxawGJQOKHqXbwN fS3ZVBToi0zNMqc/KURh6TupgXAetlPH0+oTP+ctg/s2MPp60rrk6jt9n/n3S8NEK6MmWYHwtI9kn PuWhqL0u4Ln1j5o2v5Mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1prii2-004UIW-02; Wed, 26 Apr 2023 17:13:38 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1prihz-004UFd-0J for linux-riscv@lists.infradead.org; Wed, 26 Apr 2023 17:13:36 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-94f3df30043so1190099966b.2 for ; Wed, 26 Apr 2023 10:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682529211; x=1685121211; 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=Q7yo9bVha72+sBsBMxWgYP9QvranjKNqfZXNxICaThQ=; b=MPmqSKrXYajpwKmF09ub/E/fmIyqOKAtEIEHMcQgftfTlzz3dE7egtDNQsu4MkvJgY 0Uu3jm4F/c8CNO/JhbUSqMNL0gyq7J2JEzhPzhZPbCWhXeQPyYH42YzzLfEfZiRU8XsJ 7bkJeEFvcz9j/+PSO3+DZWZvLoclCkOB8x1TR8YwgAup6mgYAbeElr2yUPIQSxzjiPWW becQkDSMBmfoB6PJbBD7SQnjIWyBV89EvNAq7YdLW9VJf+2PzZxxjcYm4JKR/IED0iCD 1VNBwtWqOWjArFKnsgYwmAu6lPt2SmJO6i30ZgTC4UYV35Oy3rjCa5a/tEtYPNFNdGzr wY2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682529211; x=1685121211; 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=Q7yo9bVha72+sBsBMxWgYP9QvranjKNqfZXNxICaThQ=; b=UX7sd01JnGaje2lG8wvqyE3Bem1Ps9YYUndhDbi4Rr8mUlMgFNfra9RC4lJMoKs7N+ t27Qif8tZk90n0YetwlVUBUz6YKjS0QmE5BP3bxGEEZB1eu+lInJYG5u9McipmV5s2Js goHVWK/oBWxeQMIMrZ0ihkpHfC7IR2E+j8qsYrFyq+qId2vMAznVrPyyODg6dpmDZUXf jxtUEXym2wXI5MEMwNY07XKOnTscboKacdSvTvXfuh1WX2zL1To/Z7VqherI8WDw7odC L62oGYUihJneax7LJ1Paeg0LzGmf+01f5vfM83wmUIlNUecAm40OOwKmekOGmH0QDN1O ipHQ== X-Gm-Message-State: AAQBX9ewzsBjUyh2PjNPhuL07TnGyLKnccdyD3Ad9ZeGjaRFYewkpYt/ jjOO0Jrw5oyAxDx8nAeVTqiCIg== X-Google-Smtp-Source: AKy350aaKoi8HMKrWXAUe1fHTi6e79Y8RGbYHQx5TQvvIGBDEf4tI9h2sruZT0i8Y3uFTnjKQ600bg== X-Received: by 2002:a17:906:280d:b0:94e:fe9a:f617 with SMTP id r13-20020a170906280d00b0094efe9af617mr15897714ejc.20.1682529211348; Wed, 26 Apr 2023 10:13:31 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id vf1-20020a170907238100b0094f71c73d35sm8641759ejb.145.2023.04.26.10.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 10:13:31 -0700 (PDT) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Cc: 'Palmer Dabbelt ' , 'Anup Patel ' , 'Atish Patra ' , 'Albert Ou ' , 'Paul Walmsley ' Subject: [PATCH 1/3] RISC-V: KVM: Disable SBI extension when its probe fails Date: Wed, 26 Apr 2023 19:13:26 +0200 Message-Id: <20230426171328.69663-2-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230426171328.69663-1-ajones@ventanamicro.com> References: <20230426171328.69663-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230426_101335_133201_7296EA06 X-CRM114-Status: GOOD ( 12.32 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When an SBI extension specific probe function exists and fails, then use the extension_disabled context to disable the extension. This ensures the extension's functions cannot be invoked. Doing the disabling in kvm_vcpu_sbi_find_ext() allows it to be done lazily on its first use. Checking extension_disabled prior to probing ensures the probe is only executed once for disabled extensions. Later patches ensure we only execute probe once for enabled extensions as well. Signed-off-by: Andrew Jones --- arch/riscv/kvm/vcpu_sbi.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index e52fde504433..aa3c126d2e3c 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -307,18 +307,25 @@ int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( struct kvm_vcpu *vcpu, unsigned long extid) { - int i; - const struct kvm_riscv_sbi_extension_entry *sext; struct kvm_vcpu_sbi_context *scontext = &vcpu->arch.sbi_context; + const struct kvm_riscv_sbi_extension_entry *entry; + const struct kvm_vcpu_sbi_extension *ext; + int i; for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { - sext = &sbi_ext[i]; - if (sext->ext_ptr->extid_start <= extid && - sext->ext_ptr->extid_end >= extid) { - if (sext->dis_idx < KVM_RISCV_SBI_EXT_MAX && - scontext->extension_disabled[sext->dis_idx]) + entry = &sbi_ext[i]; + ext = entry->ext_ptr; + + if (ext->extid_start <= extid && ext->extid_end >= extid) { + if (entry->dis_idx >= KVM_RISCV_SBI_EXT_MAX) + return ext; + if (scontext->extension_disabled[entry->dis_idx]) + return NULL; + if (ext->probe && !ext->probe(vcpu)) { + scontext->extension_disabled[entry->dis_idx] = true; return NULL; - return sbi_ext[i].ext_ptr; + } + return ext; } } From patchwork Wed Apr 26 17:13:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13224793 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D446C7618E for ; Wed, 26 Apr 2023 17:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pk9I7kUt/YPn1vA+Wr9D1wMV6kzTubXS/4ejfX/Dbp4=; b=2fUI+9/O9A4Mai 5i6q+hk53+MH/TIfeTgDAxiKUIguIaAGoknFFhLsRImq+4JwaBVMlhXH82hAEmXWKpW6X1CHE04sx ProQ+htyiNUQ+GaayaeCvJCj+g9Sv3l3napteHWMFgoOVgE8qpoZEwTZKaa8qlcD+nrBEBqmpHaQp XVJRku6Ag4gMAyiZMYl3dPdR2RALlsW5NwAWY31b4czwZAgGfcFBmUG+dIy4UExlqPR7IRyy/Ymy8 DCqS222wPEU++u63XPKUq58oQva5yB/c5SDd0j/ibcK1MdJyl/cN9limkN/uhxVhJHhmOmXRDbnzS xkBYKbDoEAcODsd+jsKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1prii5-004UKg-0B; Wed, 26 Apr 2023 17:13:41 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1prihz-004UFj-2e for linux-riscv@lists.infradead.org; Wed, 26 Apr 2023 17:13:38 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-94f3df30043so1190106766b.2 for ; Wed, 26 Apr 2023 10:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682529213; x=1685121213; 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=DLvoZhq+rB4GKS9Jeshc9hm/LbfOD54WKU572zKZVKY=; b=OBBPINo2kNtRNJSI8ktm7BJfq5Zk0JiU0bS+6AwYo5IcWqTLd/MNnhBQfLuzkhbHff JijGxXkN8Ysv8GfbW7AIoTVTn8UWuksw6VZxXMUNMtkPCLhTn3x1k9XRncZt4chYhQkl izuuxNs1U0PNOR8aJYZC5aWQNNyX8oEiKgjsS8BeD0I7oob8Z/n5/A9JhA2OraB1ukDe 8guTseXh3X0I5hvxfijRHiJjzeNWoFkMINU8hmPcls2GtM2kKsAfTKGeElzJPntgwCyC jA1gEnsPoBOcJKB4X+2m1IoRLQLUaA5Ofq3ejIihLNKlHGJtPTcsoj8EmMbowxXdR06k fmjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682529213; x=1685121213; 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=DLvoZhq+rB4GKS9Jeshc9hm/LbfOD54WKU572zKZVKY=; b=T7KtxXxDSwHboJ4XyXHoJZZhSypbtBdMxElupEqDv2hOC5ul8K0gyWDC4Rd77j+40J nQu7o/KcKLbqB3vFnQhx0t43LJbfWvgdZXgC7pJgXxTkzjG+BkVOcwajp8s0rGPmZvpc x8lxtSsESg/b33JsquFP0KfsHC8stb5x0uXZ8JDFtFcT2iyAathbotgU0INjlA/vy3iT 4qNf6cU8kopaSQLLDbelt/oDSoHHFnkYmpyfsE2BevF9eHpuC9gCXx1VmLbf79SpoRjQ DHJO+c3FR4QcRo0KYk517tghJSGFDUz9XK6KGBCJZBSYfnUKEMUifgGlyOGRMmVLm1xy aMVg== X-Gm-Message-State: AC+VfDyHS01g7h5ms8J/QFAZAYvzVNgmrizvIOwNNDvJpmcI1KXAqSJZ WUOoejT8PzfRk1jxSkBAS5afXA== X-Google-Smtp-Source: ACHHUZ7I35k4hyJXmFuZZC27P65C1wwJC8CBdqvTGrj5UGwV8XGPcbigbLRRGlp9HmITAJrveGNCPA== X-Received: by 2002:a17:907:7da6:b0:95f:1359:84ae with SMTP id oz38-20020a1709077da600b0095f135984aemr2738820ejc.55.1682529212771; Wed, 26 Apr 2023 10:13:32 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id lh11-20020a170906f8cb00b0094a789256dcsm8525937ejb.111.2023.04.26.10.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 10:13:32 -0700 (PDT) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Cc: 'Palmer Dabbelt ' , 'Anup Patel ' , 'Atish Patra ' , 'Albert Ou ' , 'Paul Walmsley ' Subject: [PATCH 2/3] RISC-V: KVM: Rename dis_idx to ext_idx Date: Wed, 26 Apr 2023 19:13:27 +0200 Message-Id: <20230426171328.69663-3-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230426171328.69663-1-ajones@ventanamicro.com> References: <20230426171328.69663-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230426_101335_861011_B7A2D30B X-CRM114-Status: GOOD ( 13.01 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Make the name of the extension_disabled[] index more general in order to expand its application. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- arch/riscv/kvm/vcpu_sbi.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index aa3c126d2e3c..a1a82f0fbad2 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -31,49 +31,49 @@ static const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_pmu = { #endif struct kvm_riscv_sbi_extension_entry { - enum KVM_RISCV_SBI_EXT_ID dis_idx; + enum KVM_RISCV_SBI_EXT_ID ext_idx; const struct kvm_vcpu_sbi_extension *ext_ptr; }; static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = { { - .dis_idx = KVM_RISCV_SBI_EXT_V01, + .ext_idx = KVM_RISCV_SBI_EXT_V01, .ext_ptr = &vcpu_sbi_ext_v01, }, { - .dis_idx = KVM_RISCV_SBI_EXT_MAX, /* Can't be disabled */ + .ext_idx = KVM_RISCV_SBI_EXT_MAX, /* Can't be disabled */ .ext_ptr = &vcpu_sbi_ext_base, }, { - .dis_idx = KVM_RISCV_SBI_EXT_TIME, + .ext_idx = KVM_RISCV_SBI_EXT_TIME, .ext_ptr = &vcpu_sbi_ext_time, }, { - .dis_idx = KVM_RISCV_SBI_EXT_IPI, + .ext_idx = KVM_RISCV_SBI_EXT_IPI, .ext_ptr = &vcpu_sbi_ext_ipi, }, { - .dis_idx = KVM_RISCV_SBI_EXT_RFENCE, + .ext_idx = KVM_RISCV_SBI_EXT_RFENCE, .ext_ptr = &vcpu_sbi_ext_rfence, }, { - .dis_idx = KVM_RISCV_SBI_EXT_SRST, + .ext_idx = KVM_RISCV_SBI_EXT_SRST, .ext_ptr = &vcpu_sbi_ext_srst, }, { - .dis_idx = KVM_RISCV_SBI_EXT_HSM, + .ext_idx = KVM_RISCV_SBI_EXT_HSM, .ext_ptr = &vcpu_sbi_ext_hsm, }, { - .dis_idx = KVM_RISCV_SBI_EXT_PMU, + .ext_idx = KVM_RISCV_SBI_EXT_PMU, .ext_ptr = &vcpu_sbi_ext_pmu, }, { - .dis_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, + .ext_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, .ext_ptr = &vcpu_sbi_ext_experimental, }, { - .dis_idx = KVM_RISCV_SBI_EXT_VENDOR, + .ext_idx = KVM_RISCV_SBI_EXT_VENDOR, .ext_ptr = &vcpu_sbi_ext_vendor, }, }; @@ -147,7 +147,7 @@ static int riscv_vcpu_set_sbi_ext_single(struct kvm_vcpu *vcpu, return -EINVAL; for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { - if (sbi_ext[i].dis_idx == reg_num) { + if (sbi_ext[i].ext_idx == reg_num) { sext = &sbi_ext[i]; break; } @@ -155,7 +155,7 @@ static int riscv_vcpu_set_sbi_ext_single(struct kvm_vcpu *vcpu, if (!sext) return -ENOENT; - scontext->extension_disabled[sext->dis_idx] = !reg_val; + scontext->extension_disabled[sext->ext_idx] = !reg_val; return 0; } @@ -172,7 +172,7 @@ static int riscv_vcpu_get_sbi_ext_single(struct kvm_vcpu *vcpu, return -EINVAL; for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { - if (sbi_ext[i].dis_idx == reg_num) { + if (sbi_ext[i].ext_idx == reg_num) { sext = &sbi_ext[i]; break; } @@ -180,7 +180,7 @@ static int riscv_vcpu_get_sbi_ext_single(struct kvm_vcpu *vcpu, if (!sext) return -ENOENT; - *reg_val = !scontext->extension_disabled[sext->dis_idx]; + *reg_val = !scontext->extension_disabled[sext->ext_idx]; return 0; } @@ -317,12 +317,12 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( ext = entry->ext_ptr; if (ext->extid_start <= extid && ext->extid_end >= extid) { - if (entry->dis_idx >= KVM_RISCV_SBI_EXT_MAX) + if (entry->ext_idx >= KVM_RISCV_SBI_EXT_MAX) return ext; - if (scontext->extension_disabled[entry->dis_idx]) + if (scontext->extension_disabled[entry->ext_idx]) return NULL; if (ext->probe && !ext->probe(vcpu)) { - scontext->extension_disabled[entry->dis_idx] = true; + scontext->extension_disabled[entry->ext_idx] = true; return NULL; } return ext; From patchwork Wed Apr 26 17:13:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13224794 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4FC5C77B78 for ; Wed, 26 Apr 2023 17:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lrynfbVcz/8nmdBwXoBzSQEArqfwiC0RTkWcnGBwGGU=; b=MSibNn5in/hl1h zDUZjpp0UH8nMtbJ4jgE9oliuHtEHBZgqIRRYytyO1LZBPR4VlNAs9aPm9E/OAsfhRSZavm4pzY4U blW5bsv/hre68O9YJoNTF16OxDf0KfFVL5hAsqByF5sShDXTv627xUxZWJF3ilLktR4KC+qK0ntsE Jn0yVnZ/IipHebvKQIP1DAvszvx7W9iu8r8U8QMNsYUDRppI/edTa+nSOBAgEhniFt4jBmFWilXE/ Wr1x0O1zAPQedIF5gdsXSvqnCZfkRMOEzXkL+2RLr04CfoeOxiBfjp3RWKN97W4bsdPmyjiXS0dFh KgYqjYeF+FNRSd55OD1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1prii4-004UKN-1u; Wed, 26 Apr 2023 17:13:40 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1prii0-004UGE-0C for linux-riscv@lists.infradead.org; Wed, 26 Apr 2023 17:13:38 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-94f109b1808so1406232466b.1 for ; Wed, 26 Apr 2023 10:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682529214; x=1685121214; 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=I2t91pIf4+2i19zzmmslCDmFjK0SYDa4k9dLFYZoUjk=; b=miOdfxuqHzMzoOSkqNvGdojuPUWOIKH2Kxse5V14s3UAUXAdYi2L/5m3AVhmZ+wgE7 krJTdYYcc0aTAkzHTDkp7ZG+pVj3uhkUMgLfnlveUITXiEwPMFY0T7ZAqqV//nVHCjFe yiF16sZUCDfIkJ1XQWckQfmu4QgvKWd8vtKf5lwwO2U8h29+s7bcbT6ZmP4SZ/vME6D2 VfVfUATDCkZ7F4GLfHNRKGN5v9q1dMJU2T6EUA1XwjcrVf+W5lqWxY7FCF7hm5ei/s7y XCIBAQQ04c0Rdw9MqqZQ1UX27dMpsYDZvkXP/KV4YhmIlq/mswPhG24RBQHzw9jmFbUa Mt1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682529214; x=1685121214; 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=I2t91pIf4+2i19zzmmslCDmFjK0SYDa4k9dLFYZoUjk=; b=SHhyINg3hVIPGMC+FxTX9InebtmQLEff3ZRo3uS4N4dvopnaFivOS7sl0af/gzm497 KCI1bo6u00zk+mV48DeCuJrX7VdcvI6wxtmhUR6mR8V5u8ZC/ygrf2BhqLT4z2z9cL7r XDZm7fCxMEfElyhqCvhHsuJ5IsXw4Eqr1wSOsg1ZBpaqYzqZAgDigHepbf4zWwdg9k8p 3/YxGtraG8z2cpN1hUCmlUjzLxCo15C5dZyUsVah4xdDbLogZKr5k4LkcL977GQouKif Zfm1byplq6+rCWw4MVXPOHILYbKJP46ghJxfFpO/Szk7kpZR4mLPOrqSxHLu9tkfDNCc XxNw== X-Gm-Message-State: AAQBX9cno0rFgjgW9SZUn1JbrPkrhAXdrqDaSc/sTQ4J5dba+hAjAKs9 /EBqkLmJ/zDKE4cRBi1nKzP+/g== X-Google-Smtp-Source: AKy350YfsT9n1WhH3XV2GYO9+nTVvkYji/9HQ59CGhxf7J6PypkpJr3BYCSgpe5A/uZnwCr2KLk4jw== X-Received: by 2002:a17:907:8195:b0:94f:62a2:d1ab with SMTP id iy21-20020a170907819500b0094f62a2d1abmr13881545ejc.63.1682529214056; Wed, 26 Apr 2023 10:13:34 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id z11-20020a170906074b00b0094f3c281b34sm8370863ejb.196.2023.04.26.10.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 10:13:33 -0700 (PDT) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Cc: 'Palmer Dabbelt ' , 'Anup Patel ' , 'Atish Patra ' , 'Albert Ou ' , 'Paul Walmsley ' Subject: [PATCH 3/3] RISC-V: KVM: Introduce extension_enabled Date: Wed, 26 Apr 2023 19:13:28 +0200 Message-Id: <20230426171328.69663-4-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230426171328.69663-1-ajones@ventanamicro.com> References: <20230426171328.69663-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230426_101336_103052_8EBBA1A3 X-CRM114-Status: GOOD ( 14.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We need three SBI extension status values (uninitialized, enabled, and disabled). Pairing another boolean array, extension_enabled[], with the boolean array extension_disabled[] provides four states. Using a pair of boolean arrays, which may eventually be changed to a pair of bitmaps, is more space efficient than using one enum status field. Apply the new (enabled=1,disabled=0) state, which means either the extension doesn't have a probe function or that its probe was successful, to avoid more than one probe of the extension. Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 9 +++++++++ arch/riscv/kvm/vcpu_sbi.c | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 4278125a38a5..e3c5e1d15e93 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -16,6 +16,15 @@ struct kvm_vcpu_sbi_context { int return_handled; + /* + * extension_enabled[] and extension_disabled[] provide SBI + * extensions four status values, of which we need three: + * (0,0) uninitialized, (1,0) enabled, (0,1) disabled. Using + * a pair of boolean arrays, which may eventually be changed + * to a pair of bitmaps, is more space efficient than using + * one enum status field. + */ + bool extension_enabled[KVM_RISCV_SBI_EXT_MAX]; bool extension_disabled[KVM_RISCV_SBI_EXT_MAX]; }; diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index a1a82f0fbad2..344d38bbe06a 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -155,6 +155,12 @@ static int riscv_vcpu_set_sbi_ext_single(struct kvm_vcpu *vcpu, if (!sext) return -ENOENT; + /* + * We can't set scontext->extension_enabled[] to reg_val since the + * extension may have a probe() function which needs to confirm + * enablement first. Only set extension_disabled[] here and leave + * the extension_enabled[] setting to kvm_vcpu_sbi_find_ext(). + */ scontext->extension_disabled[sext->ext_idx] = !reg_val; return 0; @@ -317,7 +323,8 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( ext = entry->ext_ptr; if (ext->extid_start <= extid && ext->extid_end >= extid) { - if (entry->ext_idx >= KVM_RISCV_SBI_EXT_MAX) + if (entry->ext_idx >= KVM_RISCV_SBI_EXT_MAX || + scontext->extension_enabled[entry->ext_idx]) return ext; if (scontext->extension_disabled[entry->ext_idx]) return NULL; @@ -325,6 +332,8 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( scontext->extension_disabled[entry->ext_idx] = true; return NULL; } + + scontext->extension_enabled[entry->ext_idx] = true; return ext; } }