From patchwork Fri Oct 8 13:58:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12545479 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 926E2C433F5 for ; Fri, 8 Oct 2021 14:01:20 +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 5CC226101E for ; Fri, 8 Oct 2021 14:01:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5CC226101E 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=xUlkqYlwBUFNOVGs+V6l3Rj8BIFHv+BsUearK7OzaTU=; b=D6rsSVeCcP3qdu ZOMAud6A5nLgTaAdSLFNfXPQvTDB4VyoIJDuwKU5I9P48zR8el7C5DXpEcf/8dHVj35MPc2+fAJbW exQ1rlvfuRlDW44W6zAYojBmaVind3izpjMQW46/SVE5OZGI9ZqgbtUb6nYq9w4BzGr4VjkYLjMvE 44Ontmm6SYJF/6x+UnkDGmv5qx4GFEp6vBDdKVZZoTqN+mNexH8K38+kzeQ0qBw50UkdwInD7UwD3 cS6rHX6Z4WXjoNBvdXBvs63K/J0C2SSFsVjQEYy0WMsnqCvG11xwJErFHbLSJ7qnwr7vmfu3S2rDS 6B0/tIpb9S67ydJCkZtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYqPO-002yq3-Td; Fri, 08 Oct 2021 13:59:35 +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 1mYqOn-002yhW-SB for linux-arm-kernel@lists.infradead.org; Fri, 08 Oct 2021 13:58:59 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1166C60FD8; Fri, 8 Oct 2021 13:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633701537; bh=d3wFH/yIetGiq5uriHxlgYqLTUnj/21bzxMY8KFLvuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gSvmFTxBs3Yv3TsWi3tqX1+3UZfMC5nAidDqLeOMgNhiZwKO3rcX0xDtnTVSqPls8 1WKd7E2cNsrWEuJUcNOegtncGN3biwCWV9+kWuY+DF//z2s+v/+z4t1ZMsq5P5Coey SEG96mqW3SKMHFVwCLFTaWJ7OrBHJqMhfdwIhehq9bA9zvPrcHNM7YbuLTTS4SH9qv uW3OC9bISzBwlAwH5griMOPP3/kdXkWfKVHe8Xga07syTnDPDf9bgxMHUFnzHIDPlU HI1lJZ9b5xg3SDUVuU/nnIT1yCZGYK3XGDbZXXrEyaFTtKBI7T2FJbsxxSWjN4I2MC ZMDtaCgbISNZQ== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Marc Zyngier , Quentin Perret , Catalin Marinas , Alexandru Elisei , Suzuki K Poulose , Mark Rutland , kvmarm@lists.cs.columbia.edu Subject: [PATCH v3 4/6] KVM: arm64: Propagate errors from __pkvm_prot_finalize hypercall Date: Fri, 8 Oct 2021 14:58:37 +0100 Message-Id: <20211008135839.1193-5-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211008135839.1193-1-will@kernel.org> References: <20211008135839.1193-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211008_065857_950784_D15844AE X-CRM114-Status: GOOD ( 13.96 ) 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)