From patchwork Thu Sep 23 11:22:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12512433 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=ham 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 6C96CC433EF for ; Thu, 23 Sep 2021 11:26:17 +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 2CCBC60EC0 for ; Thu, 23 Sep 2021 11:26:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2CCBC60EC0 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=0KNNBZr5+4dI1IlbCgkd84qRKWPoZKu/a2rBJLpYzbA=; b=fGnoqvoTJbcpEi BgWyg7OPY7ywmTKV6tNQy4lIoVQEYb7A6OeF2NvJqjEjlEB8HpqbspTHyNUPbHkgPJ1ftdHQ9EjnM 1LbjCjwF3+vNLEeTQjIqaKmD4PmWpHMn1M86LbYwyNTFoWAaNoDBDRfxDv7sdkVQ2OB8hse38AFjM IOOqq66eKZQP8KG5peZbz7iW2itb+PUA79lVvvv2uSEqmqhRbjFzcgF2x7JDM/eo6cvlEqIMl3fUF nr4TsukXZoF3sVL8o19CRTm61OL01uzmOfJhlVZ7F56fe5BTYs6ErYfdEf0TG4UcpWS5WL4bNLO4h pAt9qcXmZL7IShC2m7SA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTMpS-00B4yK-Sx; Thu, 23 Sep 2021 11:23:51 +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 1mTMoo-00B4oC-6H for linux-arm-kernel@lists.infradead.org; Thu, 23 Sep 2021 11:23:11 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75BEF6121F; Thu, 23 Sep 2021 11:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632396189; bh=9XTol94Ae+OoVJE6oULI43J/aM3k1N+7z3owBAICrso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RXMy8DYZ5qgn6LaLVqLH062rIFiZAAAwxgsAQJg2dkYGFmW+c9v1zKYJNJEL8Ncl6 /O7Pls6/YD7T2VtlghGoupJg3Vx6DXNs0TTtJ4cYKdvL7SCYHnDliF7m8sDXKIyIKz cfrqah6slI/Ob10r5teEu3UdmaEf97SwgYO0U0+r9qn0OsC/Xe4zZZL45/l2/toZim mbNN+6Tm3zVI6qPrdZUmtUysR76X9+j1RrZXRZ73BdjjJSEv64raFc8syVCHiytAwW hxjA0/AzL29OtgeAXGFmg5yNThvwhDSxpdlmangTe8fuVsf5zcFu5OxTGh6H7sfryn zc82FT5+misCQ== 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 4/5] KVM: arm64: Prevent re-finalisation of pKVM for a given CPU Date: Thu, 23 Sep 2021 12:22:55 +0100 Message-Id: <20210923112256.15767-5-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_042310_292819_A4ADA203 X-CRM114-Status: GOOD ( 10.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 __pkvm_prot_finalize() completes the deprivilege of the host when pKVM is in use by installing a stage-2 translation table for the calling CPU. Issuing the hypercall multiple times for a given CPU makes little sense, but in such a case just return early with -EPERM rather than go through the whole page-table dance again. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon Reviewed-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index bacd493a4eac..cafe17e5fa8f 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -123,6 +123,9 @@ int __pkvm_prot_finalize(void) struct kvm_s2_mmu *mmu = &host_kvm.arch.mmu; struct kvm_nvhe_init_params *params = this_cpu_ptr(&kvm_init_params); + if (params->hcr_el2 & HCR_VM) + return -EPERM; + params->vttbr = kvm_get_vttbr(mmu); params->vtcr = host_kvm.arch.vtcr; params->hcr_el2 |= HCR_VM;