From patchwork Tue Oct 5 11:37:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12536439 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 160D3C433EF for ; Tue, 5 Oct 2021 11:40:59 +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 DC266613AC for ; Tue, 5 Oct 2021 11:40:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DC266613AC 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=I2sBisAVjVPfPjLRhZXNeazhJYocsKU+4c5tIh1mD2U=; b=31JBOktfNYUKLr lnw1LHMMAHOWMfv5TsNh+LLFauHYQGTBzZy6l80DBCNmlP4UmBR+KutfMF0t1lmbsnRyOgKAfDfaP QB78nEffZBsf/gBCXsW7tm5nrTRJmyURKEPhjX7kkxTz8gQPpL8VE5B5BoYNBhhVnXdlevXzAtDFA mqT9v7BbcJxUxu3alywpmvjCBTWanuFheMx6WS57JMecke9qc9UR9UvHry83TBzl6uenrgD3oQ3gR 2x31BzlQI2HpZAirj5RYon2THNuKgfJbKmEeymtxnTRxpImWi5Rue6sNRDlxgSUozzW4aEL8pfMlc L8nBXoultPBzCFoM/MQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXimO-00AALW-OP; Tue, 05 Oct 2021 11:38:40 +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 1mXilU-00A9sL-4L for linux-arm-kernel@lists.infradead.org; Tue, 05 Oct 2021 11:37:45 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 49FBF6137D; Tue, 5 Oct 2021 11:37:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633433863; bh=kry0yCEkM1rOAPqgCZmnkCzktstFgLIzaFToUOzNxzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bCUAxH+im0T4w4QUPnOC3P6r8YG9nK6SmIOp8N6/nBuXL9ZzwSkA5J/Yie1abJeRJ ZJecFSr+JJxcStJw0gGY+QaB3vNI6W/7xnNwgfof8rdVDEHe0OqmsUBzawqv68asNZ H+f+xGMfYwJDm1ja9q8p8ePUJI5nskB5cQjICEJbgaqF0ZtyFfv1bugEr6zZHIpRxA 7wl1SAga+E6O7MNsoAIMZvkfADcu0ioOgxEQgpzx9cKxHJetoidp+SCqht2edYDtrE NOAVjB3K8lC/z5Ql4p+I+edu2r4OnhbKlKsRgO8Uhf+G31m2UCBzkzp1SQMqqyUv/U adhrHYpYQdilg== 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 v2 4/5] KVM: arm64: Prevent re-finalisation of pKVM for a given CPU Date: Tue, 5 Oct 2021 12:37:20 +0100 Message-Id: <20211005113721.29441-5-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211005113721.29441-1-will@kernel.org> References: <20211005113721.29441-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211005_043744_225119_D6C7ECBA X-CRM114-Status: GOOD ( 11.12 ) 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 Reviewed-by: Quentin Perret Signed-off-by: Will Deacon --- 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;