From patchwork Thu Sep 23 11:22:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12512429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3BE9C433EF for ; Thu, 23 Sep 2021 11:25:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B909760EC0 for ; Thu, 23 Sep 2021 11:25:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B909760EC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=jkf/vywvb4X4ksV0cu0OluTOT+Hww6CGqZI7U0n+rqU=; b=GTNaaT1nrU02dF cSNh3uscAAGhVV4PU2l63h4TVnNNzGZTxvPVDjbAFmcymwxcgInh1cJYfEC01WuyPQlKwAdKHIFyf mGSthegovd8xuvK9Y38X9KW/OSz6c8u4tmP/t5vQJxt6JDnNISAbqbW/XkntZyE6Q3+EFVaIRjte/ zH0TwM/yT5PaqRr3P5SkJp1J9xofSCKWA7AGyncBTScPBN6i2wBr70GJV41gw00eVGRHW6S0EmzWy 8y8im4U9M7Oy9J4gdtf/dyNoQle2Qv+uZ15X6m0oB6u4TKkgg2rcKQmhoYW6sbYA1gIFFG+2QoNZh Cmg93bf31vQRJSkyJYbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTMpH-00B4u2-EJ; Thu, 23 Sep 2021 11:23:39 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTMom-00B4nl-Bl for linux-arm-kernel@lists.infradead.org; Thu, 23 Sep 2021 11:23:09 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id A39B560EC0; Thu, 23 Sep 2021 11:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632396188; bh=zTSEoixQnsN3jbLczk6zfspLIXgI2IJ8ZyDChfPcm6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fFSg2eCfq7DlcK2X8lz+o8qpNPlQZb3vzjvDAK+6e4fjl+ZAgtnud90Mb5L+VKdU2 ffXHb/OEgiKumuztfDLE8gILHTcBs/Dq1pLEF2JB8ARcrg3pH80oyIbHDCzv42lfIB DZ+7C7MGSrgy6BGo8wrhXY+fvBfy7USZgHc6rDSVzxIb3cAk5k0RZJDBTUmw3WzJpy VxKVMMz38G/WBcy+6GBmcK0asTZoojzV90e92cWk9q2iqQzBG/kqtSEBzqYEKbEAuu wSX7TXUtDrRVLRhCesU3nGN+XEJ2i64KpmUyxp403TqmGFtv7NF+ITAdesmWU6tBN9 TcvWAT1j/2n6Q== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Marc Zyngier , Quentin Perret , Catalin Marinas , Alexandru Elisei , Suzuki K Poulose , kvmarm@lists.cs.columbia.edu Subject: [PATCH 3/5] KVM: arm64: Propagate errors from __pkvm_prot_finalize hypercall Date: Thu, 23 Sep 2021 12:22:54 +0100 Message-Id: <20210923112256.15767-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210923112256.15767-1-will@kernel.org> References: <20210923112256.15767-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210923_042308_460992_6372B80C X-CRM114-Status: GOOD ( 13.58 ) 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 the __pkvm_prot_finalize hypercall returns an error, we WARN but fail to propagate the failure code back to kvm_arch_init(). Pass a pointer to a zero-initialised return variable so that failure to finalise the pKVM protections on a host CPU can be reported back to KVM. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/arm.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 9506cf88fa0e..13bbf35896cd 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1986,9 +1986,25 @@ static int init_hyp_mode(void) return err; } -static void _kvm_host_prot_finalize(void *discard) +static void _kvm_host_prot_finalize(void *arg) { - WARN_ON(kvm_call_hyp_nvhe(__pkvm_prot_finalize)); + int *err = arg; + + if (WARN_ON(kvm_call_hyp_nvhe(__pkvm_prot_finalize))) + WRITE_ONCE(*err, -EINVAL); +} + +static int pkvm_drop_host_privileges(void) +{ + int ret = 0; + + /* + * Flip the static key upfront as that may no longer be possible + * once the host stage 2 is installed. + */ + static_branch_enable(&kvm_protected_mode_initialized); + on_each_cpu(_kvm_host_prot_finalize, &ret, 1); + return ret; } static int finalize_hyp_mode(void) @@ -2002,15 +2018,7 @@ static int finalize_hyp_mode(void) * None of other sections should ever be introspected. */ kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start); - - /* - * Flip the static key upfront as that may no longer be possible - * once the host stage 2 is installed. - */ - static_branch_enable(&kvm_protected_mode_initialized); - on_each_cpu(_kvm_host_prot_finalize, NULL, 1); - - return 0; + return pkvm_drop_host_privileges(); } struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)