From patchwork Thu Jun 9 12:12:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12875480 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 08E25C43334 for ; Thu, 9 Jun 2022 12:20:01 +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=NM8bttOLkfCcJmzHNbT0fzAmZYEPOdkOBb7bJ1KtGbA=; b=jS46L9j0GZoBYv KM81Af35bNrGmMtpcBrrGBU79YQjrRaXUyWbQIuQdD/uPDIbPI5YutgAuahoLl6k1htKkfd3P+K45 7tdl1RxUGlirPr9DQbnRvj7r8bAfptPF41WEMsvSFtXU5klNkNBtGt6GLnajp80y9shed0v+GwZKa 14XNQ6ZFy3eGZcdrwg+1bO7Q1fJCr7EvIrz9pWjUNGpGJdOa6CNqJI3A6gpylWabbOnEaYRRDbgUA QwoJLgHDuwtz1zEL6k5KDfVLp/wCgzpSAaSTYan+/i5+zW0QR/Or9MDO1s91nZkM263nD49EiO1Vt cGihYtVZLJb2KSfs40Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH7g-001fkJ-PA; Thu, 09 Jun 2022 12:18:49 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH1f-001cmP-JO for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 12:12:37 +0000 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 dfw.source.kernel.org (Postfix) with ESMTPS id ED65460C34; Thu, 9 Jun 2022 12:12:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 203F1C3411B; Thu, 9 Jun 2022 12:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654776751; bh=ZP2LKc+PqJhpwgOwUSWwHxASOb1EzEUlXbWANnogBiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gbKa9PIgEEgAia+jihKaV+0Wfz476xjKqSwKu10ioqCXh4033dEaMFOO9Udwv9U1K XBDmdpj7g0S07SzgOLdxpWNRcLUlwrdLeKnXJnAT1c0SpYIvvHWPFvrBLOhSMzyhJU SsbVcwZ4KA5Dm2h4wi9m3ZFlBIWYRsNWVSwT05dJIM8epRXEz4gPgWLsdRZoIJn7km cEUvLaGIChB6yQTePYU1fLcmUZ6+qCLCdFh+sYTW2/C7WoZovmoveC+tRr8v4amwXH miKHD3YqwpPATxVi0DxURYMTWjDmAk0rQI6wYCPtT+rD62fdx716VidMFDC9lCR8/b 1a61Fasj9wXug== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Marc Zyngier , Alexandru Elisei , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/6] KVM: arm64: Return error from kvm_arch_init_vm() on allocation failure Date: Thu, 9 Jun 2022 13:12:18 +0100 Message-Id: <20220609121223.2551-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220609121223.2551-1-will@kernel.org> References: <20220609121223.2551-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_051235_716670_A57104AE X-CRM114-Status: GOOD ( 12.65 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If we fail to allocate the 'supported_cpus' cpumask in kvm_arch_init_vm() then be sure to return -ENOMEM instead of success (0) on the failure path. Reviewed-by: Alexandru Elisei Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 400bb0fe2745..0da0f06037db 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -150,8 +150,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) if (ret) goto out_free_stage2_pgd; - if (!zalloc_cpumask_var(&kvm->arch.supported_cpus, GFP_KERNEL)) + if (!zalloc_cpumask_var(&kvm->arch.supported_cpus, GFP_KERNEL)) { + ret = -ENOMEM; goto out_free_stage2_pgd; + } cpumask_copy(kvm->arch.supported_cpus, cpu_possible_mask); kvm_vgic_early_init(kvm); From patchwork Thu Jun 9 12:12:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12875481 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 49E0CC43334 for ; Thu, 9 Jun 2022 12:20:45 +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=s+zrRXPofjQUhtGV+azw2RSWMF60KTZef+VXTlcdY24=; b=n5gzlOrYe7Qh+w SOKe7rxjnTwOmMsMUngLBhAC6hW2GrCGmFNbXjVga8/TXaLHrBW+oBrR/qkay8/l5SdTrP6k2gsWm YVhmX3YP8CuTKcTU+g+RZYAV+/h/uABRm8UBy7M2tqK8O4eC15uxCM5C9Lml9LCCV3an+KParmQ4/ oNk1mn8n3q3BirUgrWHOyHlYv3RkVBeVtYpK0Ge454eHezrsu+zrD7JyJGPqkDlDokPZVVo6KYESx +fsXFBcb72BWSbhAKTcalqwSFQxSFVXm83vvgGwy/IfNDEE1Tza4tyaVvhJ1BGB0j/tPZ4klWyMRz FSSFZNqoGg0DKGUlJntA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH8U-001g6x-6a; Thu, 09 Jun 2022 12:19:38 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH1f-001coJ-P8 for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 12:12:38 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 57CC1B82D50; Thu, 9 Jun 2022 12:12:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFE36C34114; Thu, 9 Jun 2022 12:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654776753; bh=C0btZ9R2wYnDdcYBRBHXCX9ZxoBZ12YtxECxE3n++BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T3mT0t2TMQUekhNLaEmuAHsMuJ4u5kdZwfkTXTgWvYR3R4ZLGaXFun7lEdgRPm+Vn FVdy/pjuCe+Ce/J5StBAlAkwpCuydNWUu2pWME4NkMklX9SOfi8KhY3bW3UhZ+piCe z6li3FEXz483a892552FODAv7vA06c3lCvf5CIumJKnmtY9dYsRVOI5roP4Va4lItH niF4sUbleOTI/LEWzKu/T0AavzMc0B6jdokbOsUvVYxkWgzwYSeiNjamSR/jhweIfs 5iVF2jyhR3ZJhNBiimFbFdpUix8t5uglZYpuYG3FH5M1GhPiLpgRbU34AJ0F+4k7Js grdhoaeniK9dw== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Marc Zyngier , Alexandru Elisei , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/6] KVM: arm64: Handle all ID registers trapped for a protected VM Date: Thu, 9 Jun 2022 13:12:19 +0100 Message-Id: <20220609121223.2551-3-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220609121223.2551-1-will@kernel.org> References: <20220609121223.2551-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_051236_142233_F9F71839 X-CRM114-Status: GOOD ( 14.37 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Marc Zyngier A protected VM accessing ID_AA64ISAR2_EL1 gets punished with an UNDEF, while it really should only get a zero back if the register is not handled by the hypervisor emulation (as mandated by the architecture). Introduce all the missing ID registers (including the unallocated ones), and have them to return 0. Reported-by: Will Deacon Signed-off-by: Marc Zyngier Reviewed-by: Reiji Watanabe --- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 42 ++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c index b6d86e423319..35a4331ba5f3 100644 --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c @@ -243,15 +243,9 @@ u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id) case SYS_ID_AA64MMFR2_EL1: return get_pvm_id_aa64mmfr2(vcpu); default: - /* - * Should never happen because all cases are covered in - * pvm_sys_reg_descs[]. - */ - WARN_ON(1); - break; + /* Unhandled ID register, RAZ */ + return 0; } - - return 0; } static u64 read_id_reg(const struct kvm_vcpu *vcpu, @@ -332,6 +326,16 @@ static bool pvm_gic_read_sre(struct kvm_vcpu *vcpu, /* Mark the specified system register as an AArch64 feature id register. */ #define AARCH64(REG) { SYS_DESC(REG), .access = pvm_access_id_aarch64 } +/* + * sys_reg_desc initialiser for architecturally unallocated cpufeature ID + * register with encoding Op0=3, Op1=0, CRn=0, CRm=crm, Op2=op2 + * (1 <= crm < 8, 0 <= Op2 < 8). + */ +#define ID_UNALLOCATED(crm, op2) { \ + Op0(3), Op1(0), CRn(0), CRm(crm), Op2(op2), \ + .access = pvm_access_id_aarch64, \ +} + /* Mark the specified system register as Read-As-Zero/Write-Ignored */ #define RAZ_WI(REG) { SYS_DESC(REG), .access = pvm_access_raz_wi } @@ -375,24 +379,46 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = { AARCH32(SYS_MVFR0_EL1), AARCH32(SYS_MVFR1_EL1), AARCH32(SYS_MVFR2_EL1), + ID_UNALLOCATED(3,3), AARCH32(SYS_ID_PFR2_EL1), AARCH32(SYS_ID_DFR1_EL1), AARCH32(SYS_ID_MMFR5_EL1), + ID_UNALLOCATED(3,7), /* AArch64 ID registers */ /* CRm=4 */ AARCH64(SYS_ID_AA64PFR0_EL1), AARCH64(SYS_ID_AA64PFR1_EL1), + ID_UNALLOCATED(4,2), + ID_UNALLOCATED(4,3), AARCH64(SYS_ID_AA64ZFR0_EL1), + ID_UNALLOCATED(4,5), + ID_UNALLOCATED(4,6), + ID_UNALLOCATED(4,7), AARCH64(SYS_ID_AA64DFR0_EL1), AARCH64(SYS_ID_AA64DFR1_EL1), + ID_UNALLOCATED(5,2), + ID_UNALLOCATED(5,3), AARCH64(SYS_ID_AA64AFR0_EL1), AARCH64(SYS_ID_AA64AFR1_EL1), + ID_UNALLOCATED(5,6), + ID_UNALLOCATED(5,7), AARCH64(SYS_ID_AA64ISAR0_EL1), AARCH64(SYS_ID_AA64ISAR1_EL1), + AARCH64(SYS_ID_AA64ISAR2_EL1), + ID_UNALLOCATED(6,3), + ID_UNALLOCATED(6,4), + ID_UNALLOCATED(6,5), + ID_UNALLOCATED(6,6), + ID_UNALLOCATED(6,7), AARCH64(SYS_ID_AA64MMFR0_EL1), AARCH64(SYS_ID_AA64MMFR1_EL1), AARCH64(SYS_ID_AA64MMFR2_EL1), + ID_UNALLOCATED(7,3), + ID_UNALLOCATED(7,4), + ID_UNALLOCATED(7,5), + ID_UNALLOCATED(7,6), + ID_UNALLOCATED(7,7), /* Scalable Vector Registers are restricted. */ From patchwork Thu Jun 9 12:12:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12875483 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 71C3BC43334 for ; Thu, 9 Jun 2022 12:22:05 +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=EPO4E116VejiN8O3PhfKGgF89GZYtSHJhMBHr62QE9I=; b=R4Fl3+bGM+wyMP QthoB7BbVtEQf3/W0liRLbWRRSpGXLtcDBYr4UcAJH4zpLl0suonCS2aV8UlUnkCSsOpZqEA68Of+ /w5OOuaBCRY5TUDKnPceJkkZr+INgtwyGcIwZarWz8nPufEciThMUlbNNSdwO4N7P5EIP6gBIZ2uu UWDSYb5HzODsUerzD+Tnv/2Ohv343lwKa/RDUMu8maoGEMypu6CnYhnCjGLhQ6y5+S19510YCj4mt G8P9DXrn7QV8Mq76hzaBW2pxbinRpwyOkF8y5gd/3vsJWNVR47ngdIF0cKWExsVVvRq3FYmSEY1Xy jQehfCpBasvixmdtpB2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH9i-001gdj-66; Thu, 09 Jun 2022 12:20:54 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH1h-001cq1-Oc for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 12:12:39 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 6980FB82D52; Thu, 9 Jun 2022 12:12:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BD85C341C0; Thu, 9 Jun 2022 12:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654776755; bh=Mbdzwq+/LSDhpTjAr+4Im28oBh5q/AlLTEBka/3LM4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8YFNZU5ljPunq4/7iQewiGaxXNSBDeb41QAi5HBCpirWUELTNHwjvbXczz4649DS eHoJ1HkGSm3LdzAGw3Tp0pi9pOQZvI/0PJ22ad7svKf5mj3ExNiZPdBFvWyUKpkn1J ZuqRZRputXWqDysLVTxjUEX32xIetduM61YV0dWFRtYtc6I1Sh3kF232U10BtE8ekc dKh22ImSklI7NekFN5ob/O1bb04RszCwPbGbhZoyWqCiGoA3VuKh6ZjBeeGyT9S7EJ DPnbaN5rC5Oc7P/fkgVKrz3L9quoeNcgBg4jdsq7XbXcXgvR9zIcWJP8lZFR56hGsg am0Zh8ff5aczw== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Marc Zyngier , Alexandru Elisei , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, David Brazdil , Mark Rutland Subject: [PATCH 3/6] KVM: arm64: Ignore 'kvm-arm.mode=protected' when using VHE Date: Thu, 9 Jun 2022 13:12:20 +0100 Message-Id: <20220609121223.2551-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220609121223.2551-1-will@kernel.org> References: <20220609121223.2551-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_051238_003016_402FBE10 X-CRM114-Status: GOOD ( 15.23 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Ignore 'kvm-arm.mode=protected' when using VHE so that kvm_get_mode() only returns KVM_MODE_PROTECTED on systems where the feature is available. Cc: David Brazdil Acked-by: Mark Rutland Signed-off-by: Will Deacon --- Documentation/admin-guide/kernel-parameters.txt | 1 - arch/arm64/kernel/cpufeature.c | 10 +--------- arch/arm64/kvm/arm.c | 6 +++++- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 8090130b544b..97c16aa2f53f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2469,7 +2469,6 @@ protected: nVHE-based mode with support for guests whose state is kept private from the host. - Not valid if the kernel is running in EL2. Defaults to VHE/nVHE based on hardware support. Setting mode to "protected" will disable kexec and hibernation diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 42ea2bd856c6..79fac13ab2ef 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1974,15 +1974,7 @@ static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) #ifdef CONFIG_KVM static bool is_kvm_protected_mode(const struct arm64_cpu_capabilities *entry, int __unused) { - if (kvm_get_mode() != KVM_MODE_PROTECTED) - return false; - - if (is_kernel_in_hyp_mode()) { - pr_warn("Protected KVM not available with VHE\n"); - return false; - } - - return true; + return kvm_get_mode() == KVM_MODE_PROTECTED; } #endif /* CONFIG_KVM */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 0da0f06037db..a0188144a122 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -2273,7 +2273,11 @@ static int __init early_kvm_mode_cfg(char *arg) return -EINVAL; if (strcmp(arg, "protected") == 0) { - kvm_mode = KVM_MODE_PROTECTED; + if (!is_kernel_in_hyp_mode()) + kvm_mode = KVM_MODE_PROTECTED; + else + pr_warn_once("Protected KVM not available with VHE\n"); + return 0; } From patchwork Thu Jun 9 12:12:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12875482 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 62EE3C433EF for ; Thu, 9 Jun 2022 12:21:25 +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=5uRPaxF6+ipJ/JdN3gJF4mOCWU0QYm1zfSsNizTxYYI=; b=MSXdmCB961Sy9e 6xpOAP7Yo4GL5yD2U5F5pmRjwDVgKNHjAZ/4/FVhSMS/vmGl79Xrf6Dp4AKAItWRbVzECffkpAsRZ 9enKTMn6kLU7TlDYH9jLvmyu7OnLMjEwzxyJPn7gffnCw1bk/9hZY9CbQHeQnU3M4WW/SBQyJdXZx 6XpSQKINSOixkxj2UFtM/fJS04/TQ/7cU5rBl01GbFuiUPxO9GCc+lWTw2b6iF53bdCxM2jptpBZH rIxUQpCuCgooCIBCVwr8ZdYCYrb2UCSL8flLOTsLXEGUxFzI+bxbV38myk1YM2HJX0Co5ThXrAwmZ BYiBUZ3S8BA+7qxBJzdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH97-001gOB-N7; Thu, 09 Jun 2022 12:20:18 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH1j-001cqw-Rc for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 12:12:41 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 78A3EB82D5B; Thu, 9 Jun 2022 12:12:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97545C3411F; Thu, 9 Jun 2022 12:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654776757; bh=Vt2h95kPG0rNKVQQsdXAODtHYoMLCkyG3rzEO6q/eug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gv+GUgGppkKB03l7lJQ/wVVkga0Gm3t6nEI6UygxyNzTAosWDy19fFtQ1vAsgUQW8 5P2cTvEZ+hphy9wKSHolD29YcxdZd88j3Em7BFHYm0y0tBH8LEL2Z5zwxOzPotPN7j a3fnIqGHZ08KcwDaUgeglRRhLSMCZCIjacv6rKxeSLW/CHt5SmTzZPXVHjj2uWXBy/ KZsjPAZXxFgJ5z4cw0zpNalwO8yFM4Lto7MVcZOlvO9pZMTsXaEinNU28ZPjM/v1ku NdiYIgyZhC9jfSB+UEBVheB9vYaqE6xj6LFrTkRnkMSynhu+LHvudPlk1zLVqCk7DK 2CRjBeTMt29+A== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Marc Zyngier , Alexandru Elisei , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, David Brazdil , Mark Rutland Subject: [PATCH 4/6] KVM: arm64: Extend comment in has_vhe() Date: Thu, 9 Jun 2022 13:12:21 +0100 Message-Id: <20220609121223.2551-5-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220609121223.2551-1-will@kernel.org> References: <20220609121223.2551-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_051240_243853_425D6528 X-CRM114-Status: GOOD ( 12.84 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org has_vhe() expands to a compile-time constant when evaluated from the VHE or nVHE code, alternatively checking a static key when called from elsewhere in the kernel. On face value, this looks like a case of premature optimization, but in fact this allows symbol references on VHE-specific code paths to be dropped from the nVHE object. Expand the comment in has_vhe() to make this clearer, hopefully discouraging anybody from simplifying the code. Cc: David Brazdil Acked-by: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/include/asm/virt.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 3c8af033a997..0e80db4327b6 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -113,6 +113,9 @@ static __always_inline bool has_vhe(void) /* * Code only run in VHE/NVHE hyp context can assume VHE is present or * absent. Otherwise fall back to caps. + * This allows the compiler to discard VHE-specific code from the + * nVHE object, reducing the number of external symbol references + * needed to link. */ if (is_vhe_hyp_code()) return true; From patchwork Thu Jun 9 12:12:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12875485 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 2BB01C43334 for ; Thu, 9 Jun 2022 12:23:28 +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=dC+u8vulyftdXMtso/6LEXdKGa0GTs/p2Ac2SGR79U0=; b=h690oHWRQuvvH7 B//6Zx6FrEBPi368l33DQqD1YV8RiPmg1yu2F76ZmuvitTfTU9/7xMNbxKoCnBmDTgVqPaT2Nf6ac xraEeUsMCSjuxXUU7l03ZIjkQd7kawYLEwE8nvLVxehQrpqvOFhaGe3o8EJSCArJVIY137PGp/gin jb/7sMscwWvQZdQ+4l0khA6IFhZcvhSnglfkhPu1eRigVAiKmoF08jRrqsSeI44FAerECLBzZndba afAxbXqdY2bHCrbWvLQ1kGK16/hLJs2kUwygSTgnj8FRmPGMLEK9iS+rjrJkqskiQOJjtp4FCknHM JNsJvHL6+RqmxWpw/J6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzHB2-001hG9-QD; Thu, 09 Jun 2022 12:22:17 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH1l-001cs6-M7 for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 12:12:43 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 3C932B82D50; Thu, 9 Jun 2022 12:12:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FBF6C341C5; Thu, 9 Jun 2022 12:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654776758; bh=LxU7fuaFrS1upsAZVNVrFcaeQoyaqGRLJQVCKcd3y+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U5n1sSbwe0oLqa3cOclRUTXArFmRJtXkXrJmqo/VgrWVoAMWqYjuyUgtLp/n5xvLj LrC58s2W2bHB2/ppdYJAcK3JNUUrbvZEsQ02hWlguWN1DJs38289D5YYT7F6hT1rgd oOKSkRfF1QyafkJIS+kha+HDXAEJr7peKooKzkgAqgHrdR/34KO6lzf94bHJeRpTZB N1Shkhh3LxvspdO3qHrTPeWeyH7/k8Qo46Sth/sXo3Ps3fS6WfGyb36HAohVTaangO TP6P3M9DPVUWFBAeCTQJCi//j/S6N8Nw66z0sErntOXFsYKdLFkctcbuTRXW04OQe7 8S5TDjqcf5bzQ== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Marc Zyngier , Alexandru Elisei , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/6] KVM: arm64: Remove redundant hyp_assert_lock_held() assertions Date: Thu, 9 Jun 2022 13:12:22 +0100 Message-Id: <20220609121223.2551-6-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220609121223.2551-1-will@kernel.org> References: <20220609121223.2551-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_051241_914508_F6370567 X-CRM114-Status: GOOD ( 10.53 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org host_stage2_try() asserts that the KVM host lock is held, so there's no need to duplicate the assertion in its wrappers. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 78edf077fa3b..1e78acf9662e 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -314,15 +314,11 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range) int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot) { - hyp_assert_lock_held(&host_kvm.lock); - return host_stage2_try(__host_stage2_idmap, addr, addr + size, prot); } int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) { - hyp_assert_lock_held(&host_kvm.lock); - return host_stage2_try(kvm_pgtable_stage2_set_owner, &host_kvm.pgt, addr, size, &host_s2_pool, owner_id); } From patchwork Thu Jun 9 12:12:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12875484 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 1E69DC433EF for ; Thu, 9 Jun 2022 12:22:32 +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=PCxsx2Uqwbze4b30KyxucedNdOUTRcKbA0LjH1tzppw=; b=owl5YqPEU/GNLs 2YRPKgKnhDUDGuIjlpjKGT1uOLb29TocO9eJbtqRgZNrwZ72DtnQOiZBmorxnLcxd8LSxpZzIVCOd E+lw4EG834fdCE6Ze2i7f637jH8Jqy+QCAJSI76Oq4NSXqhkhdaMmaVPoul+M0IeL+sFbeSzdd5kR JT/v8ytFHVDBqNkmFFag1CzhMsHWPfpxAHEIG1YLf+nz8kgd3SGU55XMb/FPkmVaGlZS6Y58znuVG aOrUrnLRLoefTrCdFKkA7qmqycj0K1OKEJvHs1hPaGw9AitE3jfHJ9nHRNL5wqrz3y9npWTzZKzVI u6Jy9Q5wm5y3GxUiUD9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzHAG-001gur-7q; Thu, 09 Jun 2022 12:21:28 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzH1m-001cqw-BS for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 12:12:43 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id E3F56B82D32; Thu, 9 Jun 2022 12:12:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 593E9C3411F; Thu, 9 Jun 2022 12:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654776760; bh=mF0MZDnz8qQHCl3wYfr445Mxu4221ivldNZ8SHrMvCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FaDVmvOcm/v9Q+F0wG3RtCAL1CvVQyYMFIU19KlSoFOfFIt77LbWOj1rhr6P1BiPT 0P9xesgFm12thHY/tmMAPX2E8CXaDc0ieSLDpv1+/2gpK4QTWL/7SCIHsj9AD6gIv8 24EcOaFP4wBtA+Ee4o3gme2vh1K+f2Zv5mGPR27+rvrla4fDAPYXdGxHT4D+9AzATu h6vSR/VFRSrtbDf/QsKk8oNQRZaFNUitG5CZjmVyI/k2ktQPRmRBhJi6Lf3UUM8hqr uAcvXuqzphgiAa80eZSKvv3Kcu7Jc1bjUTAq8AoNCrQlHKZdR5uGlejjx7AIAjTNge JDBV3dA/DkQow== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Marc Zyngier , Alexandru Elisei , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH 6/6] KVM: arm64: Drop stale comment Date: Thu, 9 Jun 2022 13:12:23 +0100 Message-Id: <20220609121223.2551-7-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220609121223.2551-1-will@kernel.org> References: <20220609121223.2551-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_051242_577022_0306C4B0 X-CRM114-Status: GOOD ( 12.17 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Marc Zyngier The layout of 'struct kvm_vcpu_arch' has evolved significantly since the initial port of KVM/arm64, so remove the stale comment suggesting that a prefix of the structure is used exclusively from assembly code. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 47a1e25e25bb..de32152cea04 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -362,11 +362,6 @@ struct kvm_vcpu_arch { struct arch_timer_cpu timer_cpu; struct kvm_pmu pmu; - /* - * Anything that is not used directly from assembly code goes - * here. - */ - /* * Guest registers we preserve during guest debugging. *