From patchwork Fri Jul 26 23:51:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743435 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 48676C3DA4A for ; Fri, 26 Jul 2024 23:57: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:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OCfqpOOOZn7LpwpHWWHUZjndC9uE6mObDYxnDRBBpAY=; b=nABC2qR7vsbrUfS0dW1wMhdyUW /YgS5slVxfT5cp8KLAPgO3q2wIrwufGTakz+/OQkdiot07in7IStDxXdB8DCIxgRJ/SZCgRIYrUUl SB8rvIZ4g0ThiufesMrP6aHgKHjUHuNrRC/+5TJH1s0UzPo17FJwE/TPpsNc+58T2LReG8VolUFDP 0Tft/DK0z7zyJKI+uMH/5xNSN/F4eGfkLgSf6SeAKA87XLS0NXy4d+79QcfRCqEI+3437dViVQmBk Z0fbM51cd09zOv1+cbk1OxFAVmtiyZSOb8RQnWgCGp6IwyUXjYbFb6wElsDK+jmMu0QPZ0gg9EmaT CHiRcIYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUoh-00000005SgO-2i7O; Fri, 26 Jul 2024 23:57:43 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUk9-00000005PNf-0aLT for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:53:05 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1fd6d695662so11959945ad.0 for ; Fri, 26 Jul 2024 16:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722037980; x=1722642780; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=OCfqpOOOZn7LpwpHWWHUZjndC9uE6mObDYxnDRBBpAY=; b=zeQVfyBDSt5ZHvwYebEP0uro5oBdHpEzHPdBkpvI/I4x17yijVY2J2UxY2jxcAcFMt bCieqLC0T5S+zNfqauINpfVaWWl5WcaMm2+FOcGrF4DrJj9QujYpALc7ptADkxRgnvwH Bf6ok3gPx94pJ0AFJOgWsxa3/Ko1J8NSrE0PNCh178TKkV7OlCWzGp1OPQKCvA9pR1rv OlVTlZovgjBAs3eZD1epXdokQKo2A6l5w46qdopqUkHJ191TzSV7VKah51UPiqjprS5K o1El7+rwwUtPhozESv9J4pxs81utV5X6rvNSajjD5Nu/U1Mjr0NUCnS1qUsLnIrRmCnR r6Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722037980; x=1722642780; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OCfqpOOOZn7LpwpHWWHUZjndC9uE6mObDYxnDRBBpAY=; b=B+1w+422h6ptmfbdzHbEHVzMuZWpdwxaa2dUAAyY19tJT+0n2p3nqpnER+GKuG8x3X 98tAFFPSTSuLzZvNuDd9LcoOGMBrkvu+weTwYesDOmvkZS+CZsXDVJQ7LdC/7zKWlWxR 4lR32IF3kExtw7QfRM9Mo+YEFpbhMfK5Pfbj422x5f8g8JFjAdnVV/UQhNYQYvh7qmUS PZ/zNifqwnA1IS53tx2et0ivsLcip/PmXrbUR0izBhVQTZhhkxVuBFmiTTWytABb5kfw 7kbQS8lvpIvTIYWXPzWNCiSGExFEjzpf1kGf26aH/T2bG0zbu6Y+3crmYsNhSrHL15i0 B3cA== X-Forwarded-Encrypted: i=1; AJvYcCVkf3o05A/CvtKvL8aR1qTNQAB7z7bLoq4mbFVV+X89i35XW8JsConsUXkJCyYYnhJp4FstchDqzo89K+gGyH6jecrlNaguOXL2HnUhoZh+OqiGkZQ= X-Gm-Message-State: AOJu0YzdZ0+VLEWrMwQDAFe9iqxFcI/jefSatKfjIs4khgud53aw3U+v juu1LOaLvF8P0A6nh9E34AJuTIItWG4UEGOjsTI342HQRaYKCC+hiMFdolPiygZUODbMnELN/KT zVA== X-Google-Smtp-Source: AGHT+IGEij7x5iOOrUuL0BYhT5Dm9YFKfO4AZ5nK1acS0T3wJ2KiuANG5aiKSF+tpPt4GoCINPA3jjFDrnM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:2341:b0:1fd:d740:b1e5 with SMTP id d9443c01a7336-1ff04850898mr447825ad.6.1722037979718; Fri, 26 Jul 2024 16:52:59 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:20 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-12-seanjc@google.com> Subject: [PATCH v12 11/84] KVM: Rename gfn_to_page_many_atomic() to kvm_prefetch_pages() From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165301_253215_93CCEAED X-CRM114-Status: GOOD ( 13.61 ) 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: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rename gfn_to_page_many_atomic() to kvm_prefetch_pages() to try and communicate its true purpose, as the "atomic" aspect is essentially a side effect of the fact that x86 uses the API while holding mmu_lock. E.g. even if mmu_lock weren't held, KVM wouldn't want to fault-in pages, as the goal is to opportunistically grab surrounding pages that have already been accessed and/or dirtied by the host, and to do so quickly. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 2 +- include/linux/kvm_host.h | 4 ++-- virt/kvm/kvm_main.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b7642f1f993f..c1914f02c5e1 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2912,7 +2912,7 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu, if (!slot) return -1; - ret = gfn_to_page_many_atomic(slot, gfn, pages, end - start); + ret = kvm_prefetch_pages(slot, gfn, pages, end - start); if (ret <= 0) return -1; diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 6b215a932158..bc801d454f41 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -549,7 +549,7 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, if (!slot) return false; - if (gfn_to_page_many_atomic(slot, gfn, &page, 1) != 1) + if (kvm_prefetch_pages(slot, gfn, &page, 1) != 1) return false; mmu_set_spte(vcpu, slot, spte, pte_access, gfn, page_to_pfn(page), NULL); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c5d39a337aa3..79fed9fea638 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1192,8 +1192,8 @@ void kvm_arch_flush_shadow_all(struct kvm *kvm); void kvm_arch_flush_shadow_memslot(struct kvm *kvm, struct kvm_memory_slot *slot); -int gfn_to_page_many_atomic(struct kvm_memory_slot *slot, gfn_t gfn, - struct page **pages, int nr_pages); +int kvm_prefetch_pages(struct kvm_memory_slot *slot, gfn_t gfn, + struct page **pages, int nr_pages); struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn); unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 656e931ac39e..803299778cf8 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3060,8 +3060,8 @@ kvm_pfn_t kvm_vcpu_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn) } EXPORT_SYMBOL_GPL(kvm_vcpu_gfn_to_pfn); -int gfn_to_page_many_atomic(struct kvm_memory_slot *slot, gfn_t gfn, - struct page **pages, int nr_pages) +int kvm_prefetch_pages(struct kvm_memory_slot *slot, gfn_t gfn, + struct page **pages, int nr_pages) { unsigned long addr; gfn_t entry = 0; @@ -3075,7 +3075,7 @@ int gfn_to_page_many_atomic(struct kvm_memory_slot *slot, gfn_t gfn, return get_user_pages_fast_only(addr, nr_pages, FOLL_WRITE, pages); } -EXPORT_SYMBOL_GPL(gfn_to_page_many_atomic); +EXPORT_SYMBOL_GPL(kvm_prefetch_pages); /* * Do not use this helper unless you are absolutely certain the gfn _must_ be