From mboxrd@z Thu Jan 1 00:00:00 1970 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 E01E4C7113B for ; Thu, 24 Aug 2023 08:05:28 +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:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=vFl9LRJaceq+yUWEL9wHGYsf626LsA1dAsBPq1vebmk=; b=3t7H5MybXb4m86 ZL9nT1HgiMVRgBTKL1bEL5YftziHldPervi9kvniznWFxt2C0rrDcPCAq1G2gDqNetwbDPNgPtXQx HtOQCUXTITxi4AAh7A78YWhaDW2+op7Q3OZgEzSVoe+bKs3zaAkLGNPWwQis4iAuO0DFws4pD1s0P NnGtFhMMGq0CNoNk/w/hydjRHkKH/Gwq2VdEwqhAWCicfADHs6Tv4QqLfGgQRclTbeN6ho/N/60Tr P8j0scgxNqM5ukjrechK0ftkGPtC3iUz55V+j2lPxPvojhcKhwkJ4ssQa01XEFizu6QI7+tBd/gGQ qWtdan692vsEZB0KAb7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZ5Kn-002UxX-1m; Thu, 24 Aug 2023 08:04:53 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZ5Kk-002Uwh-1x for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 08:04:52 +0000 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3a8036d805eso4747576b6e.3 for ; Thu, 24 Aug 2023 01:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692864289; x=1693469089; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5EE+UzoRngnjehf25g1txAUD7jFYvBFO8xVG5NUnepk=; b=PiabMMQhe9y2vUBAt7h+ntRdrItXl5XEmXNUAkQzHdz/5Usah2vUewJPe1DxJjyMoj MPwJ8vBC0PRuHBzkM99uP/8pDt3bKa4MMVAyZvrVMT5+kHkXevDD6Xbkw9rXNNage966 g+94vbQfs3rPzxqPbviDDzoC4v8GyCo9zgfVo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692864289; x=1693469089; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5EE+UzoRngnjehf25g1txAUD7jFYvBFO8xVG5NUnepk=; b=kLSSR4lmmmYHqzBSy7mNOVLKEtIOpr4voMSBDEWl4g5qNqz6Ip/s/s09YjAzX1BVHO 0oiYPpa730IZ0PRH9SHw1trMmK0wUwaMcd3MaShC1RR4/gSR3lRiBxRU2GZZv4Rhqibd auYRdXZx5cYs2y+UYoxMzyuBGSy8kugLGMXBdvDr8wPea3GF7BIyY/he9UhlrjjyzKqL fbaT1zqNijW9Fyo/a4H0Wg0i88JxP60NiYduMS4JauR2uzfZpi3m6w75rO1ksyjTVsyU HPb7oHEwYVZ3xmjtsfs8zhZhIQfbn8GH6AAwlisDJKLJpx/gmrxXoiHAgY6FMFXgulI3 cLaQ== X-Gm-Message-State: AOJu0Yz+nKQf53nR3Yvm2NwMaBRXFxFVKSM/jyeyzryGx/F41iMGXomC wXDQdFssK3i9jj1YOIl/DS/J8A== X-Google-Smtp-Source: AGHT+IHkBcWKFj3+pW5fuuiWfLnbD3ta+ABypKF47WzCDkfdw67HWPAGK/Ns2WRoKXuxgQGkt6DXAw== X-Received: by 2002:a05:6358:720c:b0:13c:c84b:88bb with SMTP id h12-20020a056358720c00b0013cc84b88bbmr2497118rwa.27.1692864289233; Thu, 24 Aug 2023 01:04:49 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:515:8b2a:90c3:b79e]) by smtp.gmail.com with UTF8SMTPSA id a18-20020aa78652000000b00666e649ca46sm7014327pfo.101.2023.08.24.01.04.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Aug 2023 01:04:48 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Sean Christopherson Cc: Yu Zhang , Isaku Yamahata , Marc Zyngier , Michael Ellerman , Peter Xu , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, David Stevens Subject: [PATCH v8 0/8] KVM: allow mapping non-refcounted pages Date: Thu, 24 Aug 2023 17:04:00 +0900 Message-ID: <20230824080408.2933205-1-stevensd@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_010450_643171_7F0CDDFA X-CRM114-Status: GOOD ( 18.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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: David Stevens This patch series adds support for mapping VM_IO and VM_PFNMAP memory that is backed by struct pages that aren't currently being refcounted (e.g. tail pages of non-compound higher order allocations) into the guest. Our use case is virtio-gpu blob resources [1], which directly map host graphics buffers into the guest as "vram" for the virtio-gpu device. This feature currently does not work on systems using the amdgpu driver, as that driver allocates non-compound higher order pages via ttm_pool_alloc_page. First, this series replaces the __gfn_to_pfn_memslot API with a more extensible __kvm_faultin_pfn API. The updated API rearranges __gfn_to_pfn_memslot's args into a struct and where possible packs the bool arguments into a FOLL_ flags argument. The refactoring changes do not change any behavior, except as noted in the PPC change. When introduced in the refactoring, __kvm_faultin_pfn implies FOLL_GET to preserve existing behavior. From there, the API is made to support mapping non-refcounted pages by respecting the FOLL_GET flag. This series only adds support for non-refcounted pages to the x86 MMU. Other MMUs can likely be updated without too much difficulty, but it is not needed at this point. Updating other parts of KVM (e.g. pfncache) is not straightforward [2]. [1] https://patchwork.kernel.org/project/dri-devel/cover/20200814024000.2485-1-gurchetansingh@chromium.org/ [2] https://lore.kernel.org/all/ZBEEQtmtNPaEqU1i@google.com/ v7 -> v8: - Set access bits before releasing mmu_lock. - Pass FOLL_GET on 32-bit x86 or !tdp_enabled. - Refactor FOLL_GET handling, add kvm_follow_refcounted_pfn helper. - Set refcounted bit on >4k pages. - Add comments and apply formatting suggestions. - rebase on kvm next branch. v6 -> v7: - Replace __gfn_to_pfn_memslot with a more flexible __kvm_faultin_pfn, and extend that API to support non-refcounted pages. v5 -> v6: - rebase on kvm next branch - rename gfn_to_pfn_page to gfn_to_pfn_noref - fix uninitialized outparam in error case of __kvm_faultin_pfn - add kvm_release_pfn_noref_clean for releasing pfn/page pair v4 -> v5: - rebase on kvm next branch again v3 -> v4: - rebase on kvm next branch again - Add some more context to a comment in ensure_pfn_ref v2 -> v3: - rebase on kvm next branch 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 (7): KVM: mmu: Introduce __kvm_follow_pfn function KVM: mmu: Make __kvm_follow_pfn not imply FOLL_GET KVM: x86/mmu: Migrate to __kvm_follow_pfn KVM: x86/mmu: Don't pass FOLL_GET to __kvm_follow_pfn KVM: arm64: Migrate to __kvm_follow_pfn KVM: PPC: Migrate to __kvm_follow_pfn KVM: mmu: remove __gfn_to_pfn_memslot Sean Christopherson (1): KVM: Assert that a page's refcount is elevated when marking accessed/dirty arch/arm64/kvm/mmu.c | 25 +-- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 38 ++-- arch/powerpc/kvm/book3s_64_mmu_radix.c | 50 +++--- arch/powerpc/kvm/book3s_hv_nested.c | 4 +- arch/x86/kvm/mmu/mmu.c | 94 +++++++--- arch/x86/kvm/mmu/mmu_internal.h | 1 + arch/x86/kvm/mmu/paging_tmpl.h | 8 +- arch/x86/kvm/mmu/spte.c | 4 +- arch/x86/kvm/mmu/spte.h | 12 +- arch/x86/kvm/mmu/tdp_mmu.c | 22 ++- include/linux/kvm_host.h | 26 +++ virt/kvm/kvm_main.c | 231 ++++++++++++++----------- virt/kvm/kvm_mm.h | 3 +- virt/kvm/pfncache.c | 10 +- 15 files changed, 316 insertions(+), 214 deletions(-) -- 2.42.0.rc1.204.g551eb34607-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel