From patchwork Wed Dec 8 15:22:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12695376 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 9FFC5C433F5 for ; Wed, 8 Dec 2021 15:32:15 +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=uK1B7dZE49rTXBoLmlZuWiEi0nSJTHrzlnI2Zf0M5/w=; b=cLzUV+pcDcL6G8UXNGrLYEL227 gij/KOU2qV33AZTpedroTpVNyiIenY3h0XXP7dQ8NkL5mzdddW6yw0DPk7UQt9P9qIycdOAkCFfSJ uJhVQUOC/egG1BYey+shWxrgPJkEDu3+ubp8HbjrSB1oci6aKSKEXUjr4SVMcz8Vn1VtuFDzHDjJL BUmh5Us0XwfMNZWoFjU6jm5J3bgYvggRK0tmZMdr9CVW5852KAdcI+sN9ahe+UL5JeueSTLGKO5GH K05CkV8IcPCUTLVBn5WxF2lUWo23hrsQy7YJYlJ95Jh09VNHs9YCQKrfIzeeORZmm1uvdjtIX34X3 mcAD9DcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muytm-00DGCC-6H; Wed, 08 Dec 2021 15:30:26 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1muymi-00DCfn-GH for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 15:23:09 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 69-20020a1c0148000000b0033214e5b021so1460966wmb.3 for ; Wed, 08 Dec 2021 07:23:06 -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=r27uQnQQtVbS3yI0XEL7/R9cqNgVk61W5XrAJ0Nw0Ww=; b=naFD9LicXyODJErTfR403GKq7ei5lGkVN74aV1AhQuJdG7N+BLYc8N+bJ37PaGYh39 SdctqEgFuCTMuF5FWpGFNJe/hL1KT7NEPGKmw8HIn2GMoXMiktzuHvhDjfo+P9wZLdDt 5mw45WlmYwCXT+ULUp/dRM12JoD6391Z4YYbBoWBD6E9W4TdWHwOmw+tuxk8VfsoPUFq FlUeaULBj+v/FzA7O1ubmKEHblv0W4KcYDQGhFM7mk6rf2k4sbm5nlj1FelFQx4kRRdl NCC26n15GXzmRdPue/vf6hJbdDqylJoqp5mGGTGvvUXzyNqZvoRj2euYDhHpZumkY6tV 0qIg== 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=r27uQnQQtVbS3yI0XEL7/R9cqNgVk61W5XrAJ0Nw0Ww=; b=EWrrzyO8FSv+xTuaOkMO5SVBA8aSV3hzYypMK6FwmKf4lgUxk1YWJxNM5aQ8t7hlnQ Eld1XdRTootvw4NSj2o2MF+hnuunN9TW+8+tcXQOki2Hj2RCMeD2ikVNFzDfO3/WFLDQ MYVHmcfOnO8dOJfXsgVhsTWxxyWl/WAlhIJrp2rZO3ZqSX+0WFhdSHEMVQSgKkV964kA eGb0obg86btzdgeNl36Sjg+UvMZFN4nTMAV7veMlv9k6peW1E9CwhAZcWXy5RYhfMy1z Y3u4RXPfSxn6rSugAFL+XXGqbLQjBJYFufI+/Kldq6slDXRWmO2VWAWtTeGfb+wCgLRx Xb6Q== X-Gm-Message-State: AOAM532pX1k56mW6FiPMb6ojtv/Qk4Bx80Ak4g80xvVC6vqpVn/BNSjs +Pc+DoXV9arh6z0u5Kwl8dBqV1OTa7jF X-Google-Smtp-Source: ABdhPJyVBhdRR4oxaKYKZEdM1jxQ1KGBiBeRjA9M0nAxRA3k7kRNUlf5UDHP+FOncXY+IqD/xhb12Q9Uy29Q X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c718:14b8:982a:57d5]) (user=qperret job=sendgmr) by 2002:a5d:4d8b:: with SMTP id b11mr58840186wru.393.1638976985582; Wed, 08 Dec 2021 07:23:05 -0800 (PST) Date: Wed, 8 Dec 2021 15:22:54 +0000 In-Reply-To: <20211208152300.2478542-1-qperret@google.com> Message-Id: <20211208152300.2478542-2-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 1/6] KVM: arm64: pkvm: Fix hyp_pool max order 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_072308_581075_54A23931 X-CRM114-Status: GOOD ( 12.42 ) 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 EL2 page allocator in protected mode maintains a per-pool max order value to optimize allocations when the memory region it covers is small. However, the max order value is currently under-estimated whenever the number of pages in the region is a power of two. Fix the estimation. Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index 0bd7701ad1df..543cad6c376a 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -241,7 +241,7 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, int i; hyp_spin_lock_init(&pool->lock); - pool->max_order = min(MAX_ORDER, get_order(nr_pages << PAGE_SHIFT)); + pool->max_order = min(MAX_ORDER, get_order((nr_pages + 1) << PAGE_SHIFT)); for (i = 0; i < pool->max_order; i++) INIT_LIST_HEAD(&pool->free_area[i]); pool->range_start = phys; From patchwork Wed Dec 8 15:22: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: 12695377 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 61DDDC433F5 for ; Wed, 8 Dec 2021 15:33:11 +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=NPQS8Qx5lDSu+CVUtyQTfmflU7cMcOu2I//PdIRwzmM=; b=P4qHaMZ1Soa3MFVmvi3aHHYAlS mlG7t+tOezwfPVBRydVhUfCNcXkmjgtzQK9mokopqu8EsokcUNWM9a+9pBXQmTaKX9TEQya/WzAQn K+07Se7ylDuT1l/pqZ4hgQ91/cJ0T5w0SG5wjzu5Y+PguPluDcB66xHXL49gcGt7V7GUeP5oWcpd/ bYUhoZDOojpwcp/egjEFe0IDpDo2d29houiwz9ou1vNLISJlAk+wck8GoGdDp7/+eBfsKkQRaOVZE vNUT9444jxIavH980nr8LgKypSVMiGp/tGymflQ1OhFr+27OvSSe//iAu3DqWi3DWNtq3Y5Tm5F08 mvBMx3ig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muyui-00DGa5-J9; Wed, 08 Dec 2021 15:31:26 +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 1muymm-00DChQ-Lf for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 15:23:14 +0000 Received: by mail-wm1-x349.google.com with SMTP id g81-20020a1c9d54000000b003330e488323so1294417wme.0 for ; Wed, 08 Dec 2021 07:23:10 -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=WFv2lXz9eCHT3yd+CF6ElCbrsux6py5SHwDqlqAaTn4=; b=ZDiX6clEZwsCO576ptI4p+U8abQdk4d/G9Oef955pfW4K0FAUmdqldx2WNOMkcw9ak 5qSvscHuqPi9DAOEf9QVnnWjJ0eeoJurD1kc1Ea5jfSWXTNnLJWLVDBU6AJOV7sIIG8/ Pj1j4AYMPQGGlZR/X4DymKwUQpNV1Upw0xVjLfOPKCa+hA/UhqGSyjcFm2+Act+iJqI5 GSAuAGgG5gFc8GwslklSGNlNKa08cXanws+vPcdHC51+MWHmwmFsAbRHed6kq+FwtS8Q SRgV/L9TyhcBHOZLXurecAnFAJEuOgoccyWzRd6O1ChhBQV/YHcSQeEYlhC+TfRaL5Je kYtw== 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=WFv2lXz9eCHT3yd+CF6ElCbrsux6py5SHwDqlqAaTn4=; b=h2YUMWoUWT5asdRa10VIKEb2T/XwVwromynwPI4mQsjGXOFURjlimGvbJncDW1cBFv ckVEmt1fuvXLDsvGSHU03dSwjvA/YoQ16CQBmCAU0hfSvELLUkrpmcdbBXvfj2ia4+wd IGghkEtXv0jEZK46aLlOAd+tIcX4B4BC/WUUO3QgFLkXyd4aNWR985wGJqXI8jTLQb+9 QiNik5/CME3jYi5DzUlTMERKTwpJWbFXgr6qTAmIrj9VAT8Vg5L4HSPF2qoGdZqhp8rl X/s592YRawYVvJo9r1OAFilzkrTKg3rtDYekiIDGrbLXKXVc/XKO3MC3b9ArZGbMWmb6 466w== X-Gm-Message-State: AOAM531duPg9gxCsDsIncJQhOlIh7lfuvqBprrTvC73uwAeQgcnnwyFX JUEwLHk7673Wpx0RGvC6o38EtJ99kZJf X-Google-Smtp-Source: ABdhPJxSs8eDEFE+1XbumupLfjxLtoH5gK9ACn6/1cAzmR58bQj+dtBX/daKqvo9wufYXRpz+sc7M4xxqTKl X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c718:14b8:982a:57d5]) (user=qperret job=sendgmr) by 2002:a05:600c:1c1a:: with SMTP id j26mr17342732wms.28.1638976988812; Wed, 08 Dec 2021 07:23:08 -0800 (PST) Date: Wed, 8 Dec 2021 15:22:55 +0000 In-Reply-To: <20211208152300.2478542-1-qperret@google.com> Message-Id: <20211208152300.2478542-3-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 2/6] KVM: arm64: pkvm: Disable GICv2 support 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_072312_765383_DFA637D4 X-CRM114-Status: GOOD ( 13.58 ) 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 GICv2 requires having device mappings in guests and the hypervisor, which is incompatible with the current pKVM EL2 page ownership model which only covers memory. While it would be desirable to support pKVM with GICv2, this will require a lot more work, so let's make the current assumption clear until then. Co-developed-by: Marc Zyngier Signed-off-by: Marc Zyngier Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/vgic/vgic-v2.c | 5 +++++ arch/arm64/kvm/vgic/vgic-v3.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/vgic/vgic-v2.c b/arch/arm64/kvm/vgic/vgic-v2.c index 95a18cec14a3..8e337a0d7817 100644 --- a/arch/arm64/kvm/vgic/vgic-v2.c +++ b/arch/arm64/kvm/vgic/vgic-v2.c @@ -345,6 +345,11 @@ int vgic_v2_probe(const struct gic_kvm_info *info) int ret; u32 vtr; + if (is_protected_kvm_enabled()) { + kvm_err("GICv2 not supported in protected mode\n"); + return -ENXIO; + } + if (!info->vctrl.start) { kvm_err("GICH not present in the firmware table\n"); return -ENXIO; diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c index 04f62c4b07fb..debad4e6e6c9 100644 --- a/arch/arm64/kvm/vgic/vgic-v3.c +++ b/arch/arm64/kvm/vgic/vgic-v3.c @@ -651,7 +651,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info) } else if (!PAGE_ALIGNED(info->vcpu.start)) { pr_warn("GICV physical address 0x%llx not page aligned\n", (unsigned long long)info->vcpu.start); - } else { + } else if (kvm_get_mode() != KVM_MODE_PROTECTED) { kvm_vgic_global_state.vcpu_base = info->vcpu.start; kvm_vgic_global_state.can_emulate_gicv2 = true; ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V2); From patchwork Wed Dec 8 15:22:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12695378 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 C41D8C433F5 for ; Wed, 8 Dec 2021 15:33:54 +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=9ZMKSjr98GazVPGUbqvre/dKBZNtL9IpXVUHzAGvTR0=; b=OYEViSf72iG8+j1wcJf4pHvit0 zannQUqwqiXLbgdJVaBZ8IJvEhwcfRdn76IIC0o7YrVnYFHzYiSf6QT9CoQn4Wp4b/+wIieiBAgPq VReycZPTKkgWV1SmbKoCOQtTPDW9rU69aErsi5SP9WmE2X7zoL2rn1MNT3udNU9ZRRahi0Ctw+Mcm I/qfA+/VZrJMQQRhn7BnBkFIMDlUy93tkvfNwFb4ORhz7xJSXsBlv9d6plgHgxwWecG42i7p2grJr Wz2iZUsJQFpYGpJKByTciBVamt0ENGl88gpm2STOljN9t1HH+vizKbHeRA8HUM7tbY9veVyZrpebP e+TqpdFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muyvL-00DGqs-RH; Wed, 08 Dec 2021 15:32:04 +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 1muymn-00DCil-US for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 15:23:15 +0000 Received: by mail-wm1-x349.google.com with SMTP id r129-20020a1c4487000000b00333629ed22dso3167055wma.6 for ; Wed, 08 Dec 2021 07:23:12 -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=yo/eXM0M5vLhun4zn7QEhUouednn+qQj5dLApDQTa4k=; b=YQiiyTtUq3FaM4VAJoRYtem6jDT89osDA2RviQd2g7IHWgQJ2hB10vOD4CnqbX80AH Q03Kv0t3cWaNVFH1q6wRsylJ5jUi0wqfgyba5j8cMwuubV0aq//6Yx3rXFD3A7vFd+5a QaJSdPOTGPYL7v2/LTUouYfSPXGBXWEV6dqjmyQm6v5eRnmQFCNoPjtn5tvVgXgzaOXf UvQqBvOuCgat8swSkzUAV+FtJRHigg7wX2okKam46SRWE5L0r64Ce2BYha5fYY273J7A ULh+k1+ojzQY3CDqEKIVR7qDEtjRXHo6xmgkTRZFN2V1FPXKiL26iAIlSpweK5BIkit2 QJrw== 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=yo/eXM0M5vLhun4zn7QEhUouednn+qQj5dLApDQTa4k=; b=FjwR55nI0rdC/b9W3y+3OEHv6YNGCpm33cNJlsVO0gy4KKoYwisCKvjyQD47PT3Hxb eC8TR6zplvOShdeL8fw8ysSonyDFYaGp8JfUv/JKrQvMFeiYtffW1ogHNfFSfIT+3g19 yn3X7QpPRKsY5DSw78d86plmgdJHR3TVDJuxhaFU/18ROIBmZwj9y6saBodJrMUKxsLz 1AclZ+I1ze17rWmnAm1tRmBeve9/UBmEe6O8fUGBphtz6BukzTOoGqIMFERgXvIy0iIn ypsWhzy6FC5jrbzldPqovZHDkOLLyB4ppuCc/1c6f7w3ics4Sqisum3XcfeASAXSn3xx 5Ycg== X-Gm-Message-State: AOAM532k5MX7FNrZObLy944qN17HEFoYgVcx1lZEEar5jim400bu4pw1 uiEPtkwjE5N8S+YjHywktzxvNeJdLlzy X-Google-Smtp-Source: ABdhPJwOfjubqI7meWxcl9D37/U/vlVJzBvp2U2d2RIIBKuRn/8kPhrJIutIwFz0Y5iAUysi8gbYXfV0y2wu X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c718:14b8:982a:57d5]) (user=qperret job=sendgmr) by 2002:a05:6000:252:: with SMTP id m18mr59432350wrz.117.1638976991841; Wed, 08 Dec 2021 07:23:11 -0800 (PST) Date: Wed, 8 Dec 2021 15:22:56 +0000 In-Reply-To: <20211208152300.2478542-1-qperret@google.com> Message-Id: <20211208152300.2478542-4-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 3/6] KVM: arm64: Make the hyp memory pool static 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_072314_041174_5DE24189 X-CRM114-Status: GOOD ( 13.44 ) 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 hyp memory pool struct is sized to fit exactly the needs of the hypervisor stage-1 page-table allocator, so it is important it is not used for anything else. As it is currently used only from setup.c, reduce its visibility by marking it static. Signed-off-by: Quentin Perret Reviewed-by: Andrew Walbran --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 1 - arch/arm64/kvm/hyp/nvhe/setup.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h index ef6a58a04235..3f60d6cc5368 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h @@ -12,7 +12,6 @@ extern struct kvm_pgtable pkvm_pgtable; extern hyp_spinlock_t pkvm_pgd_lock; -extern struct hyp_pool hpool; extern u64 __io_map_base; int hyp_create_idmap(u32 hyp_va_bits); diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 51e68a040d8a..e31149965204 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -18,7 +18,6 @@ #include #include -struct hyp_pool hpool; unsigned long hyp_nr_cpus; #define hyp_percpu_size ((unsigned long)__per_cpu_end - \ @@ -28,6 +27,7 @@ static void *vmemmap_base; static void *hyp_pgt_base; static void *host_s2_pgt_base; static struct kvm_pgtable_mm_ops pkvm_pgtable_mm_ops; +static struct hyp_pool hpool; static int divide_memory_pool(void *virt, unsigned long size) { From patchwork Wed Dec 8 15:22:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12695379 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 9E1A7C433F5 for ; Wed, 8 Dec 2021 15:34:36 +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=EA9djU0KllCl0MeK1VIzW1sLFefoYtcgrsXQTQzGyr4=; b=rQNha+8J/wxQbHlSXKqXy0a36j PIcz1uqi2bzzoHnQ8HGirD3t3xrDriM7KTuJIG1dY7G2ruMxAEpfypMEVqGk19H/5VfPAMU6zMy2f C7RUYOti08C6DL2I8qD+4X4cEAm4bUFMxMXUawmu+8GG2bvq9y2yfUtjz6QeTTonRNID+xFJnjSNy pc9wAHoL6L62IEMUez9H5rEsfWbTUhchZ5Y9FKTY3KT2UB0ML6xUU8xyvPkx+gA9f4Ejfbz5P2mHW TCh/b4ZqQCi4mWl2LcRn6waotxO3APagrNPvivMEaZBpq0TFPq116A8nrBjOcHEe1zBPtJcmuezud jGgXNJ9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muyw1-00DHAB-NP; Wed, 08 Dec 2021 15:32:46 +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 1muymr-00DCkg-Oh for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 15:23:19 +0000 Received: by mail-wr1-x44a.google.com with SMTP id q17-20020adff791000000b00183e734ba48so480911wrp.8 for ; Wed, 08 Dec 2021 07:23:16 -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=dgTcer4H5x2V6vg1108kd2kvmSCOK/fdrPt0IEA/yAc=; b=OO++pgN0LQkRixb3Sq7Hd5w4QXWKTHU22mu8fVnumx/eTq9CxL7X2F8nL4x04jkISf kipUAI4bu44wE9v5DHK56LMB2no0ObvfG7M8kGv5bzcym0vpdnDAJ8Lk4yq+49UtdWo3 bZ8yP9xdUCTiHdkctcvrwAgccOD0TBjeYFZucZKb836bHeZhaqsMS2NSKTW1g1P7/re0 9AgPiRniaapcw/g+FhGxeT0goa83px619Dqwd1v+txQWUZTOE5sF8onQT6zmISmitbWL 81NrTCgrmHgZ5NfFOREPevSqkUNFg6S1AEJOfg+NXVGsl4K9TjJThlPj455oD1dIYaT3 +3JQ== 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=dgTcer4H5x2V6vg1108kd2kvmSCOK/fdrPt0IEA/yAc=; b=cAQXzkiBYaLqOJXaU/aqoc81mX6Nc6nTpyCq9SBkBZdirR5qK7l5gJXzjF5ftcT6OU swYX5Wa1gklTdP4dhO9XUo9ea1/ZVzLS4Mbts74mK19hMyAcijMlcNwButByMw5hVmW7 +AZU3QX1rD2v/v4ol8ph3+aqTl3mSAM4gP59G5RUtk9RMaUNGB8ltt//fDoctsWFlRzU 6aPxjr+27rWdS8v/FiVb/2LxTVW3FIw4a9vs1UWXWesXEmQqR2r4kFnpCf3HF59F0W1q up68Ogjvalc333RsHDHR2J6+g1c3xmm9ksXqV9ZC+5iR/mtFkumVfjVNo09uvvF6sFM6 1GLw== X-Gm-Message-State: AOAM530TZPhJas0hOHiSTe1mZ/DLcgBi+rPYEaMcbJMeA7RHN5XkoXxe wqAvDvS+boA1HWLR9esrnboowwJEzptk X-Google-Smtp-Source: ABdhPJzw57yyhlFRsGBdsMP0b1MuPYqG3wH3zEnWZDUhTXBl2eHsIR7+DocFx3KMxHXiRp33Wa8qily/O8bz X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c718:14b8:982a:57d5]) (user=qperret job=sendgmr) by 2002:a7b:c407:: with SMTP id k7mr16929430wmi.35.1638976994756; Wed, 08 Dec 2021 07:23:14 -0800 (PST) Date: Wed, 8 Dec 2021 15:22:57 +0000 In-Reply-To: <20211208152300.2478542-1-qperret@google.com> Message-Id: <20211208152300.2478542-5-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 4/6] KVM: arm64: Make __io_map_base static 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_072317_873636_68400C50 X-CRM114-Status: GOOD ( 12.40 ) 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 __io_map_base variable is used at EL2 to track the end of the hypervisor's "private" VA range in nVHE protected mode. However it doesn't need to be used outside of mm.c, so let's make it static to keep all the hyp VA allocation logic in one place. Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 1 - arch/arm64/kvm/hyp/nvhe/mm.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h index 3f60d6cc5368..2d08510c6cc1 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h @@ -12,7 +12,6 @@ extern struct kvm_pgtable pkvm_pgtable; extern hyp_spinlock_t pkvm_pgd_lock; -extern u64 __io_map_base; int hyp_create_idmap(u32 hyp_va_bits); int hyp_map_vectors(void); diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c index 9e0ff5a700dd..526a7d6fa86f 100644 --- a/arch/arm64/kvm/hyp/nvhe/mm.c +++ b/arch/arm64/kvm/hyp/nvhe/mm.c @@ -19,11 +19,12 @@ struct kvm_pgtable pkvm_pgtable; hyp_spinlock_t pkvm_pgd_lock; -u64 __io_map_base; struct memblock_region hyp_memory[HYP_MEMBLOCK_REGIONS]; unsigned int hyp_memblock_nr; +static u64 __io_map_base; + static int __pkvm_create_mappings(unsigned long start, unsigned long size, unsigned long phys, enum kvm_pgtable_prot prot) { From patchwork Wed Dec 8 15:22:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12695380 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 2BFABC433EF for ; Wed, 8 Dec 2021 15:35:31 +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=jv3EyJR0R/A3xyvFFx7rhjQ0ti35gEcd3FXoYA2NBEA=; b=iEMx9jIi7F+nCahpTSglXP+XQj 9tOOWhEs/71gqDK+09NNiFL9NN4ErQVtXIu/mqfn3NgyFqI5TTMzC3S02KOlWSfTh+j2jHZDq3xrX KLGnZLFx2KufaygZyY+J7CfCEFxiPvxEer0RjIsI0ydA++eM7VDtXmX4OIX6Y5QPc6IrCuy9gGZAt a6XBWwT1f9qTkvh1UHPYE9PUcz5reB4dlpxxDzk2oWI99caXi6RkQ16m+NiBisR5/DJb1K6MCJoTs ByBrxSREe7C8n1hCCfXmueaxfI3aQUqBF0etLZJpvOmCMlq5bbWRrLnjjbPAF9ECsVFochPOimbby cXOyboDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muyws-00DHXc-Ma; Wed, 08 Dec 2021 15:33:40 +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 1muymu-00DCmc-Dt for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 15:23:21 +0000 Received: by mail-wm1-x349.google.com with SMTP id 138-20020a1c0090000000b00338bb803204so1465601wma.1 for ; Wed, 08 Dec 2021 07:23:19 -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=cuQE0YW8UdMGW3rLCo6CNfwjy36MSIxkvZOeV47gVAQ=; b=KUpsl8OdrXa2TfNhJOIs3W3KwuQrGlRyqmoXmUyaJ/yuu4HpfU1Kh6qBx0/DO5VGCW 30J/V6mtYiRAmcRHM+mRVJum30AGeDLlvKOpqxYp+Jet7qFJJ1RdoNIVvktcVDiLDpqZ ehHF9n08W/1YSh/QKI1PIfTOx8lNeNdWFZqFuHY4IbZYhDWrHvWxvuQ+m8SLOOOKopWV Uch7He8l5dVKPrpUzYaPboYyMT/+vk2ZeR+zmJn7QZvuOWKOuoJdoYS5ptXP4LyB1l/u sS5qgHeFSbCTheo3xIpypUgjz9uCkJAgxoYl5uOx5eSw/hZ/dtcTXVGboSUwYK26WUuE AqJg== 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=cuQE0YW8UdMGW3rLCo6CNfwjy36MSIxkvZOeV47gVAQ=; b=0fHSsZ74VW8zU6fqQnwi8t++YociMMgjjXCkSyaGEf6IxjGa8HscluqtV9MGghp5AO SMHOzYY82JmnLpxLnVH5uqNnfrATu9TMtwux1yUtgyNqxkMwFFvVVaa/353EWcC4hJSy t+HKk4fd4A2eMQVHFzcIiIpyE5EatlDwLVLZagZAaqtIquAXKQIQ4Vk0S9gFLwaiF/OE EA78/wiYnEFOp+tmPMfNAjt8rfOKI3FufSXyyb8cXgsFBaUr7Obi1gs+t5s+qnljLiL4 ikmQ0D6KCKjhD5Zsy0JzBFTWkAVSVWz0vudC2ilzEe6hTiDKlXluGvR1b/X0Gq/+jBd5 Z1Wg== X-Gm-Message-State: AOAM5334cMJFr9uUfSz7CqX9+TJPuVXitzl64S8WjrXeaifCILk5MW2X M8CZOJGocDm/gbwZkxNKljfuecLydOUR X-Google-Smtp-Source: ABdhPJxGsSBocOeLXiSRK4wTT3nM6evq9+M4+nial4TaliEuNBrySS5ScIR8zMauErKeWzLKuaryRYic2Qfw X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c718:14b8:982a:57d5]) (user=qperret job=sendgmr) by 2002:a05:600c:3506:: with SMTP id h6mr16840889wmq.122.1638976997976; Wed, 08 Dec 2021 07:23:17 -0800 (PST) Date: Wed, 8 Dec 2021 15:22:58 +0000 In-Reply-To: <20211208152300.2478542-1-qperret@google.com> Message-Id: <20211208152300.2478542-6-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 5/6] KVM: arm64: pkvm: Stub io map functions 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_072320_515438_2BAA9678 X-CRM114-Status: UNSURE ( 8.84 ) X-CRM114-Notice: Please train this message. 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 Now that GICv2 is disabled in nVHE protected mode there should be no other reason for the host to use create_hyp_io_mappings() or kvm_phys_addr_ioremap(). Add sanity checks to make sure that assumption remains true looking forward. Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/mmu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 326cdfec74a1..605c104eb030 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -407,6 +407,9 @@ int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size, unsigned long addr; int ret; + if (is_protected_kvm_enabled()) + return -EPERM; + *kaddr = ioremap(phys_addr, size); if (!*kaddr) return -ENOMEM; @@ -650,6 +653,9 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, KVM_PGTABLE_PROT_R | (writable ? KVM_PGTABLE_PROT_W : 0); + if (is_protected_kvm_enabled()) + return -EPERM; + size += offset_in_page(guest_ipa); guest_ipa &= PAGE_MASK; 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;