From patchwork Wed Dec 8 15:22:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12695381 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 78213C433EF for ; Wed, 8 Dec 2021 15:36:25 +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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pyRo2Co5LokakpWJIjopRnNaG6lYEbQ/ogRSKFbjCsY=; b=2HAgUySMb5cGtKSPEY4hH/ancf dALuEMnFyAV8lA753TrPkNQX1iSATnAobE+4x/WPBKU+CAoE91x3C2vTk98/tAcoim4j959prpGbX wke77lXyGSHq8pFC+DmikqMBjMlKwzH/ws+Ty00WaNQcLcQWuFUaqr7ZNxDxpxKpuyb+CYUlNfV6+ vShyRW3zNcxWFghOcUYdS8QD+J5y0NXGVyMHzlRTCFI8ZnQsX6nq/fvenSntkpvEUhB3o/pF57nvC IHrLMpxNRx6y053D6Y78Ze/xeUpP1V2BDjJbG6fG0v3NJsq88B4XLlYeMZYMKR17FOuM42UcS4pC0 jcQBSFZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muyxl-00DHzT-Cz; Wed, 08 Dec 2021 15:34:33 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1muymx-00DCnz-0T for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 15:23:24 +0000 Received: by mail-wr1-x44a.google.com with SMTP id v18-20020a5d5912000000b001815910d2c0so483244wrd.1 for ; Wed, 08 Dec 2021 07:23:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=uoeb8ZSnDE4o8Pfzcz/JRgpjIAPknsa+43VWqkDL6SE=; b=FLyX6GFGnWQE7qMZM26O1O1AIl75kaww4jWCqv4JML5oIxJznYt9gmaqoKEtOluEIA KivNJtKKcK5gQqfUIvhnbeRCcIGE4cfZuQ3Z1B5J5RHBhJLgW41frhBZiL+74d5zvtjQ YTXVsaTlKCICiUB8KMyDO8wp/JClMuGlKFewIBt3+94HtCTajeFbEV0YelIu3Iuj277W 86JPh53Fj2k/kN6UXiqUCcD5vyQdWQhbDDtxGqMl6se8ENYkODZ7oT+K2FS4TsPAAsCZ Dcqr8eXGeTQyX4059KSQKZm1fFeKlvhLHrQgxl0ZG1j46Mv7NoPJjwwGbd0clsKGfsfc ufJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uoeb8ZSnDE4o8Pfzcz/JRgpjIAPknsa+43VWqkDL6SE=; b=7TEaNonk2ZgueC1MFWTnDK9J0RKIuBpqtDfNq4lwgJJE2cEtnD7ox5bGPGmqVOHXpL +6TOLAjYQIDeNUrEyqQkDTeHmY8uRwkWfqicE81GI9doiizGKwGp35nh4HErl0MOnWrv 5xUXTmC8zrsgtJ+3Izf2DVV5oKv5dMRVbLm6SnUqGAr0ch39BhPDCKJl8qKlLG13+mVi SWHagR4BLjOdZxN9AZ/NI31LRiF4FghmV98eF/pSkVZVVwfHkctzjXk+VuUDuL4TcMjn BCHSAYdByxVt44DO//iLP9zclzfxbhRrPZIlFS19Z+t+fTPw+3IzsmAYIkG6Gmau+0oD QlxA== X-Gm-Message-State: AOAM530M9qsMlnejaiPVXUsAjHfgkCDrZ8sEc0dks3+koD3ePuAvgDhq aJFRdRcENt4sF7+1SOSanTWbf8UyqWs0 X-Google-Smtp-Source: ABdhPJzw6DIyY3LwITNb68nDRIYXL5b0dyrc0mUWTC50VbADX2UnqIrRkM3tCHlIcHHhMLL5CQqyW4AukkHv X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c718:14b8:982a:57d5]) (user=qperret job=sendgmr) by 2002:a7b:cc94:: with SMTP id p20mr16347652wma.162.1638977000902; Wed, 08 Dec 2021 07:23:20 -0800 (PST) Date: Wed, 8 Dec 2021 15:22:59 +0000 In-Reply-To: <20211208152300.2478542-1-qperret@google.com> Message-Id: <20211208152300.2478542-7-qperret@google.com> Mime-Version: 1.0 References: <20211208152300.2478542-1-qperret@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH 6/6] KVM: arm64: pkvm: Make kvm_host_owns_hyp_mappings() robust to VHE From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211208_072323_098023_66157E09 X-CRM114-Status: GOOD ( 11.93 ) 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 kvm_host_owns_hyp_mappings() function should return true if and only if the host kernel is responsible for creating the hypervisor stage-1 mappings. That is only possible in standard non-VHE mode, or during boot in protected nVHE mode. But either way, non of this makes sense in VHE, so make sure to catch this case as well, hence making the function return sensible values in any context (VHE or not). Suggested-by: Marc Zyngier Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/mmu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 605c104eb030..ea840fa223b5 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -239,6 +239,9 @@ void free_hyp_pgds(void) static bool kvm_host_owns_hyp_mappings(void) { + if (is_kernel_in_hyp_mode()) + return false; + if (static_branch_likely(&kvm_protected_mode_initialized)) return false;