From patchwork Tue Oct 19 12:12:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12569723 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 DD1CEC433F5 for ; Tue, 19 Oct 2021 12:15:02 +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 AB84C6115B for ; Tue, 19 Oct 2021 12:15:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AB84C6115B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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: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=moXD0sJnnraOARpXWhIbj2T98jftAxxp4rqXGLG+PlA=; b=rwd4fbaeFeiw8DFaA+YXOAc+cV IxWnoStfJnETWwwoulxMyGGeaP+4MUqGY4mspywL/+W2cZB9LuPON78B5xM7+q4aTmrqEiZolLpEL CGjQjgkARJiJUGgXLZ/LP751kRXZMH0Jts9xNl9J/LOHiYEpxMpRwm6S/EGOmUnc53zydDEa5KkcB 5Y5pbLcp/+ENd4pgIfzgvR74VaGDu8J2tZItwEg1Xv46JBeGf9n5676I7yA1TXe+UbXtYLH/EbXHU rz09gggrSMEH7Nxgxv9zFg3ZcsrlEH1ge7cz4wWJVH+elIa6hiqZ9j0y6YD4m0qxv3+rwjH1kNdNE si8aOKNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcnzj-0015H3-FE; Tue, 19 Oct 2021 12:13:27 +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 1mcnzU-00159B-Hz for linux-arm-kernel@lists.infradead.org; Tue, 19 Oct 2021 12:13:13 +0000 Received: by mail-wr1-x44a.google.com with SMTP id l8-20020a5d6d88000000b001611b5de796so10085720wrs.10 for ; Tue, 19 Oct 2021 05:13:10 -0700 (PDT) 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=tdsCErEUABqyyQ1mbx3uMSi/aufrxWWc3XxvUpZyi6c=; b=agqompm2B2MZmrGmB/gxpWpG6vgaVYlKU4CIg03TGpGC+4aalw5NfoiD3nd16AtPKC +DDl3VZfg72c4W3xGXNnVhohTo/s1mh5Cyu5/QSadO0RvwtMUqZBiqtMAx328Fh9wqjq O0Nnn+TUupK1jSkoQ6zAv3/qn9uizgYDbldXMVCRDlXhC3lCi4AOj3ogrxk1mN+ucv3t cBTjLmdxquTpk/VsYC9VrDb0/yJLDYC7h9Lyd93revkEa0NK2jXBGNPbXzqtFp+2iCfn x3H7XuI7FYVAgUe1wh0Gh6d7Wleobtrh8ZGRAvmytblQRuG07xpaCyWW6Wf03jkJTJVX x5Zw== 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=tdsCErEUABqyyQ1mbx3uMSi/aufrxWWc3XxvUpZyi6c=; b=FOLJZW1Sb5Nt7ucqZYTxIaesKnAoHap80zr5MRZyMdL2mgneRiv0LOW/WiPnb+qM55 YsYmSCmvdKNQzsiY7FFvRH21jtrMCoIKC1o/Uq6E+k1LDOEGpLRx+65HkVT7HHINjelc ZtcpxrQbvKEpUjPSYPs7bb+Jamq10RDlvj23IRQKBeLBQpwoaWlrD90guswU8GFSpx6t ChNH8vKFqiIubDGq995pDT6mvyOy86EsjS/iEaiBkUrkBsSJcc1D/Qi4QamMvfMeHQcn 9zYiQgpBT1PNsyfp4Mq7IErdQuuKaGL81cmJrRlRMb++CSl2tP4tTy+SypMmAqWCgBJg yprw== X-Gm-Message-State: AOAM533nvGV3N+jmXV3tN/Ad1UyAGCCD8I4F03s83zoMa0SxNKfP7pFL B18yKC9JhqEkvhC1okzA2MfW8n1tleSD X-Google-Smtp-Source: ABdhPJwSSTIWtOO8ktVy4rHrNPU+CIvJsJy3oLDvfo1jOaII6PMNjG5KAfWEfB/Wt+zdj/T+fCLv/8OQmHxo X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:59ca:401f:83a8:de6d]) (user=qperret job=sendgmr) by 2002:a1c:5417:: with SMTP id i23mr5564552wmb.17.1634645589172; Tue, 19 Oct 2021 05:13:09 -0700 (PDT) Date: Tue, 19 Oct 2021 13:12:50 +0100 In-Reply-To: <20211019121304.2732332-1-qperret@google.com> Message-Id: <20211019121304.2732332-2-qperret@google.com> Mime-Version: 1.0 References: <20211019121304.2732332-1-qperret@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v2 01/15] KVM: arm64: Check if running in VHE from kvm_host_owns_hyp_mappings() From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Fuad Tabba , David Brazdil , Andrew Walbran 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-20211019_051312_628478_F3AEF33B X-CRM114-Status: GOOD ( 12.52 ) 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 --- 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 da10996dcdf1..0019b2309f70 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;