From patchwork Wed Dec 1 17:03:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12694348 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 06114C433EF for ; Wed, 1 Dec 2021 17:06:08 +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=O2Tbht+T7nnXOsfHT2s1JPNm7N68XYtfeWDsbiiIqUM=; b=d+SWBM6Vv0K2wlp5adexP1IS9I 3ON4bujCIY/FPH5TviwL1wSCt2PejZDQy6nusTrps4FBUxaQZ4kFjxT/Xv++d3vB+PcbQCghCRPh6 QP8ayHw9kullZfgS0tnO9WGwdjaoCdXTXB05IM/WVbahn/YOip/h61KcsRkHHWgiuyKTQRyoIYONQ tieXEyaBGgMbT420O9zA5GemTYFLd1BwRKsSHLge6buFtwVD1Tbktu5KtPvNp0YaM3+w+Dw2fodVz dicGQYMWlClSlnIaQ6SJhLwdv7CH9ZBxQHthqU1+gxBtYn2nAWl5eFTfy1M0hMmEfwK8PWCWpo2XJ WDYfX+NQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msT1z-009Rrg-Kp; Wed, 01 Dec 2021 17:04:31 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1msT1o-009RoP-Nf for linux-arm-kernel@lists.infradead.org; Wed, 01 Dec 2021 17:04:21 +0000 Received: by mail-wm1-x349.google.com with SMTP id m18-20020a05600c3b1200b0033283ea5facso610941wms.1 for ; Wed, 01 Dec 2021 09:04:18 -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=To0SNnHVfI+H6lAX6lBPI0gbbL9kvAmYwmWxoThbEmQ=; b=c3N+Hsz63lDc/AuLe7OwcJn+QlFGAiiPAK/v+uveeQj4J/xIMFLUVreGUkLB/OhWe7 xxQExo5sN2tjJX/K0t22Pyedrge8bHw8PQX9ioa+ZyPcJXTNVTqwnzaN4wJmEAY0G3WF qePOIM36BNZrzbzHLF499Ie9giwIeOEhK0DjLg4A4aO0pyneUPX9V3J3QAgZhnAalmGq GgU2j5rGVQ+/ywMfsyzLjUCf/yIn9JUsfAZrM4tEXfekoTu7F7CPl0GECKg5acnJo0gD ldlS2SRcWRjiOuZ7JvgkDuWdek0FI/pSl01nLYU8GyAhvbnuRN8Ufpu4D57DZce5aeNr wU9Q== 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=To0SNnHVfI+H6lAX6lBPI0gbbL9kvAmYwmWxoThbEmQ=; b=LlJ4seYuuPCz9kHUJ/rGt51Wa9sgxXFY1mFF7JGg/igEkDL63lTOA3Yrn5hqfEDsLl etU06YsjPiuBottqu7fQ7QF7wBlAXpfDeYUxWKBVA9OLBDUSIqhu8EVYimsG/oecNle+ TEi7S9VxmgvtdeTfRlOWiq/eXIO0aMrByqJnAmQVTlZLxUC9aqUsDOgl5ExkyoMJ7gF4 Ie8ztdo9d9wj54VSQRXmNz7OD+zxrMRHZfyISRY+xxzYWO+aX+KPpwfzt1Y/M/k89Te0 yDB1A8nYi8msnQqkbWtQeBTrTei+G+CSs6YjNxNbBYA/0TeJo9cOGQuLOBDq8tF8UfWB iDqw== X-Gm-Message-State: AOAM530wvLu06WConAleWEz3Y4gOJRsRUR/gTbBkzDBDM6sYq56vXT7D 71IwAEGYhqskQO/eY6unNL0sDHu5acEI X-Google-Smtp-Source: ABdhPJyFcaB2RvMSztkS941w8QnL4bS9fgV6ZFzqQ3PoBgP+qzxkDtb1aqs2DI+obM4eDv5SPs/p5zCTtLuI X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:1cab:1a20:2ef1:ddde]) (user=qperret job=sendgmr) by 2002:a05:600c:198f:: with SMTP id t15mr8655534wmq.94.1638378257676; Wed, 01 Dec 2021 09:04:17 -0800 (PST) Date: Wed, 1 Dec 2021 17:03:55 +0000 In-Reply-To: <20211201170411.1561936-1-qperret@google.com> Message-Id: <20211201170411.1561936-2-qperret@google.com> Mime-Version: 1.0 References: <20211201170411.1561936-1-qperret@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v3 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 Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211201_090420_793289_9C61517D X-CRM114-Status: GOOD ( 12.30 ) 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 326cdfec74a1..f8f1096a297f 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;