From patchwork Fri Jun 25 07:36:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Stevens X-Patchwork-Id: 12343859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5D79C49EB7 for ; Fri, 25 Jun 2021 07:37:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 752AF6141B for ; Fri, 25 Jun 2021 07:37:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 752AF6141B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69BB96ECDF; Fri, 25 Jun 2021 07:37:19 +0000 (UTC) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by gabe.freedesktop.org (Postfix) with ESMTPS id 149DB6ECDA for ; Fri, 25 Jun 2021 07:37:18 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id y21so4294482plb.4 for ; Fri, 25 Jun 2021 00:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=arS0mKVzVlqtqVfiVwhtHqUqhLwMsArq/fcDdatjRgU=; b=dHO26QDY5LUMI+Tc2XZzsgpXZDpORNAX7YyZkCQ5xy7oSytr1O3oUF01CG9gH6yL5q Y3La01kqEVPP9WWTMrMPMSLK8aydIT/ocZATNuL06J51ec4Okfq4Nv5ekqNB14ZWBhjL tL88LfPKWlydh9eprQr48AASmItpc0PiVGEJE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=arS0mKVzVlqtqVfiVwhtHqUqhLwMsArq/fcDdatjRgU=; b=Mutr1Jzq0S4AFQCbiDmPHhf99I+xEM4IRJQyzXj771a0C2tOVYg5Bg7prOpSKk5eS4 EhW5FdBoPBH2Scvzua+Il38rz/ea+Sf3vKKn6+kRx6f8Bd+e18tTaeYNnMLnaZNw8qlM BMa+1PxKOoBAFB3XLp/dDl9KSNEx+eKTmGUpmmIel8DW93nse6SBRiZOZSBvrJAAvC6e ZG1XSluE4wra+fYFYRL/9/x94M2SmKae20jZ/MZjFP5Aq5qeDL3bmOc/TI7EyA+YyJLW 8+idCcZco0MxPXdRTmehKg51PbmsENNsW2QAgSR0oXJQCXNp71difKAQIyPcJkUgB7OX q0Fg== X-Gm-Message-State: AOAM5326V4tmrgUqIySFnJG/IWViogFG3X43/8NPI/Ga/GWTOYkkNnB0 PFe/M6OLqvzuJG0vw30KSgkEBA== X-Google-Smtp-Source: ABdhPJzJyYhoE1B9Fk5Wy7zlre5sRlAATH1Tds+i1SalCyUSMMBey0lep4anSoEg3on5gb5KkCMm2Q== X-Received: by 2002:a17:902:c947:b029:125:34d4:249d with SMTP id i7-20020a170902c947b029012534d4249dmr7925026pla.3.1624606637340; Fri, 25 Jun 2021 00:37:17 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:1492:9d4f:19fa:df61]) by smtp.gmail.com with UTF8SMTPSA id a9sm9986991pjm.51.2021.06.25.00.37.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jun 2021 00:37:16 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Paolo Bonzini , Nick Piggin Subject: [PATCH v2 0/5] Remove uses of struct page from x86 and arm64 MMU Date: Fri, 25 Jun 2021 16:36:11 +0900 Message-Id: <20210625073616.2184426-1-stevensd@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wanpeng Li , kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mips@vger.kernel.org, Will Deacon , kvmarm@lists.cs.columbia.edu, Alexandru Elisei , Joerg Roedel , David Stevens , Zhi Wang , Suzuki K Poulose , intel-gfx@lists.freedesktop.org, kvm-ppc@vger.kernel.org, intel-gvt-dev@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, Jim Mattson , Sean Christopherson , linux-kernel@vger.kernel.org, James Morse , Vitaly Kuznetsov , linuxppc-dev@lists.ozlabs.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" KVM supports mapping VM_IO and VM_PFNMAP memory into the guest by using follow_pte in gfn_to_pfn. However, the resolved pfns may not have assoicated struct pages, so they should not be passed to pfn_to_page. This series removes such calls from the x86 and arm64 secondary MMU. To do this, this series introduces gfn_to_pfn_page functions that parallel the gfn_to_pfn functions. These functions take an extra out parameter which contains the page if the hva was resovled by gup. This allows the caller to call put_page only when necessated by gup. The gfn_to_pfn functions are depreciated. For now the functions remain with identical behavior to before, but callers should be migrated to the new gfn_to_pfn_page functions. I added new functions instead of simply adding another parameter to the existing functions to make it easier to track down users of the deprecated functions. I have migrated the x86 and arm64 secondary MMUs to the new gfn_to_pfn_page functions. This addresses CVE-2021-22543 on x86 and arm64. v1 -> v2: - Introduce new gfn_to_pfn_page functions instead of modifying the behavior of existing gfn_to_pfn functions, to make the change less invasive. - Drop changes to mmu_audit.c - Include Nicholas Piggin's patch to avoid corrupting refcount in the follow_pte case, and use it in depreciated gfn_to_pfn functions. - Rebase on kvm/next David Stevens (4): KVM: mmu: introduce new gfn_to_pfn_page functions KVM: x86/mmu: use gfn_to_pfn_page KVM: arm64/mmu: use gfn_to_pfn_page KVM: mmu: remove over-aggressive warnings Nicholas Piggin (1): KVM: do not allow mapping valid but non-refcounted pages arch/arm64/kvm/mmu.c | 26 +++-- arch/x86/kvm/mmu/mmu.c | 50 ++++----- arch/x86/kvm/mmu/mmu_internal.h | 3 +- arch/x86/kvm/mmu/paging_tmpl.h | 23 +++-- arch/x86/kvm/mmu/tdp_mmu.c | 6 +- arch/x86/kvm/mmu/tdp_mmu.h | 4 +- arch/x86/kvm/x86.c | 6 +- include/linux/kvm_host.h | 17 +++ virt/kvm/kvm_main.c | 177 +++++++++++++++++++++++++------- 9 files changed, 222 insertions(+), 90 deletions(-)