From patchwork Wed Sep 14 08:34:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12975821 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 7D725ECAAD8 for ; Wed, 14 Sep 2022 08:47:08 +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=CcZl+xx/OkuTPLlPSJNDO+f3MhqLEDJswYTBdq3JIWw=; b=xR7a+oWkw799F4 k7ASR/Q4jUUNSGORltUgY2vLsIjfu611YFUuUipT//YNpLhq48SkXEKZFfGAnrrU8YH3/wvc2vwbk ynEUa2tnPfBOW7OUrS+K3k3T3dFY6aNR1m7YxcWLjqxBvtfrIKGo2tdQM14AZPdieAIySKt1Bw1pB jyLXEePjUf2kQxEqxUuW3qEUtoYKA+ZFruYAWxBq7K950r62V6d2z9xCPn98vE5SKh4SdvXGclomq biALyoNIA/jGPd3DXHYNmxTLSu+WYSS2SmuBwpNG1QWrbjTsyXorEs2rtamRZz4qQSxcleT1tW+wb C3jpkv3XbxTMuJGOFcew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oYO1x-00DgQ2-NO; Wed, 14 Sep 2022 08:46:01 +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 1oYNsL-00DcHt-AR for linux-arm-kernel@lists.infradead.org; Wed, 14 Sep 2022 08:36:07 +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 E3679B81687; Wed, 14 Sep 2022 08:36:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CE1FC433B5; Wed, 14 Sep 2022 08:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663144562; bh=V3BSJgwq3VpYDMiwgqOd1SlJQcprRikDJcmaYNL/r3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J5dxWEWx0UkemCb+XvVi3gq5e8hCE10u9bJ6FycygphT4VEzX7eGqnIV/8VL1If3o 3j4PcepPuQ1HskYYkO96X6hs7WZeEWvWmPqx3/EPh/ZqtxpW0H7Bjg7SMMHTUD8imS 3BvdY2RaYEU7Xci6rGYZQ/1Ai53UXWPcVP+S0sd4vffqGFjOdhUdiHGTZUjLRQGIWj N0QreTgcVMwJnEp5+QS5tN7ci95JvnICN337OWkYcQsrslX41IPUz9DqaRYxzrUQxI BmTjiXfBebgGh1mP8DA7RovMVELPy8FxHLzs0kxpXPfJ+VA4N/vE9bttqClbqSf0LK B4nW0Om/SGXhQ== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: Will Deacon , Sean Christopherson , Vincent Donnefort , Alexandru Elisei , Catalin Marinas , James Morse , Chao Peng , Quentin Perret , Suzuki K Poulose , Mark Rutland , Fuad Tabba , Oliver Upton , Marc Zyngier , kernel-team@android.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 15/25] KVM: arm64: Initialise hypervisor copies of host symbols unconditionally Date: Wed, 14 Sep 2022 09:34:50 +0100 Message-Id: <20220914083500.5118-16-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220914083500.5118-1-will@kernel.org> References: <20220914083500.5118-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220914_013605_737628_2840F840 X-CRM114-Status: GOOD ( 14.66 ) 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 The nVHE object at EL2 maintains its own copies of some host variables so that, when pKVM is enabled, the host cannot directly modify the hypervisor state. When running in normal nVHE mode, however, these variables are still mirrored at EL2 but are not initialised. Initialise the hypervisor symbols from the host copies regardless of pKVM, ensuring that any reference to this data at EL2 with normal nVHE will return a sensibly initialised value. Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 0befe2313604..83fcb5099647 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1886,11 +1886,8 @@ static int do_pkvm_init(u32 hyp_va_bits) return ret; } -static int kvm_hyp_init_protection(u32 hyp_va_bits) +static void kvm_hyp_init_symbols(void) { - void *addr = phys_to_virt(hyp_mem_base); - int ret; - kvm_nvhe_sym(id_aa64pfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); kvm_nvhe_sym(id_aa64pfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1); kvm_nvhe_sym(id_aa64isar0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR0_EL1); @@ -1899,6 +1896,12 @@ static int kvm_hyp_init_protection(u32 hyp_va_bits) kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1); +} + +static int kvm_hyp_init_protection(u32 hyp_va_bits) +{ + void *addr = phys_to_virt(hyp_mem_base); + int ret; ret = create_hyp_mappings(addr, addr + hyp_mem_size, PAGE_HYP); if (ret) @@ -2073,6 +2076,8 @@ static int init_hyp_mode(void) cpu_prepare_hyp_mode(cpu); } + kvm_hyp_init_symbols(); + if (is_protected_kvm_enabled()) { init_cpu_logical_map(); @@ -2080,9 +2085,7 @@ static int init_hyp_mode(void) err = -ENODEV; goto out_err; } - } - if (is_protected_kvm_enabled()) { err = kvm_hyp_init_protection(hyp_va_bits); if (err) { kvm_err("Failed to init hyp memory protection\n");