From patchwork Fri Jul 26 23:51:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743434 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 75DDEC3DA4A for ; Fri, 26 Jul 2024 23:57:24 +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=e1uaEfwlbucR9PkkwcUB/hlZrD43F2tYkTCYXf9cR5U=; b=kI1M2GZHzM+i5ursuQ11fiR1mG +Dy3XLzhxJEgp7Ie9JTbiwmfaU6Afi87iuqjXvsNR6pr6u4IbGWA8iiSELZ73JaoSj478qlKnu7x7 DVHo6RUReYPFXH2aSrthrVzeD7PGP/EIe/IrPFr2M5FvQ4MMd84WVPLlVU0WNIZoDNKZ2uI3kqnaE 85jU0MbLl+AeArkwdMpK9ewndsNSIcm18m7kf49NQTy/HIJ0zGcQR7z3I4NYDDnIA3mBKQFnaJ4EH FioIdlTGhagAKdyu1hQDOehZLtDb54lYWLkQTPzSqVgOrsTHO5q4KDy7Y9aTI7fXj2sk4+VAimE/8 37nc2QSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUoC-00000005SNX-0JCd; Fri, 26 Jul 2024 23:57:12 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUk7-00000005PLe-0vm4 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:53:02 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e08723e9d7cso412265276.0 for ; Fri, 26 Jul 2024 16:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722037978; x=1722642778; 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=e1uaEfwlbucR9PkkwcUB/hlZrD43F2tYkTCYXf9cR5U=; b=eA52MVxC4pkGUKu9bK7pA+8ay9aAT0XMfj2BsQEg9d5EV3eGJwrmRVsHZ+teqvd8GB BD61VVKs07SQs9UBfP06zBwMwmJrOezttpVjaoEpcjRMV+9FLRUscmPpRiWj5Fkfyb50 k637X3VzHGBXnfFHcsH2sBnZYopLGLxjAhbX+PXfbzW4gJVYqSmVZ3J01OwoTiiSOYCy K0SOcalE7K8+jKQVAbVbIim7LBtuJXmNb9p9IOGTVAqZCKhmWasYPq/HxAi7GGbEAeNi t5/8M1j5tknh3iSYMX0rfclBfyOmnQTwO1QhqzwkVb2jLsWNZHCZIYKerRyJoZ5ox2v7 lGGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722037978; x=1722642778; 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=e1uaEfwlbucR9PkkwcUB/hlZrD43F2tYkTCYXf9cR5U=; b=dVLohdf+5H3GuJSzqGfTVviwj4FMg+TpC5HqJU24DachSuvrzVkI15ye/tT6Rt/Hgr c5DQ133y6SoTghfl+1GjVpktC02+x1Bqz8fDo6w91LYmArn08Yj24ymy+yJiYqmlYg0i PKNU7BY5AdJ3UuED0EasV8fYMhkB5qFqF7Oos4QSeDYXY1Wlu172uKaFL9hmSWtc/P4o mR2Cz1wWEVDFFCbLcmA+tLNS9CUac2ze6hkR9dlRRZJznWZil73BpK8c1Qf769Qyc/YR QbJOmPkP/+po1XACLAN+hocHGyw0ezVFhR34QsBrZ2p+KrC+ErpiHH+5k03Q53HKjR9l I/BA== X-Forwarded-Encrypted: i=1; AJvYcCXglih+QRt9fW2ROVwfHt2NGE0/MH4Z+DxITl5NyVgNbegMdfwzyig8OuZM8tkXK3iaq2wDY/93B86/TFQonuPRIzBwUPiT+iAupqcRduJHcUuM1ys= X-Gm-Message-State: AOJu0YwOYoaf6PIRrN57kMSChB8VfZBa+YlZYy/GaInVb9yvZ2+Op3tp NZ+4oTL18iTD7PCBCrAXpTQTx+Q+yxIY6XP63Iqa77nulv3WDokN06nqPrmefE3FJ5GUFvI30ti WfA== X-Google-Smtp-Source: AGHT+IG4XdyN3FgjZWItv/Lgg5QEKJKUQifoplgps87wy/mf6q3lv4u9rcIn8zN490p0nZ8TWmWhP2C2xyU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1081:b0:e0b:1407:e357 with SMTP id 3f1490d57ef6-e0b543f0dc9mr70203276.3.1722037977844; Fri, 26 Jul 2024 16:52:57 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:19 -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-11-seanjc@google.com> Subject: [PATCH v12 10/84] KVM: x86/mmu: Use gfn_to_page_many_atomic() when prefetching indirect PTEs 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_165259_319224_1F01839E X-CRM114-Status: GOOD ( 11.21 ) 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 Use gfn_to_page_many_atomic() instead of gfn_to_pfn_memslot_atomic() when prefetching indirect PTEs (direct_pte_prefetch_many() already uses the "to page" APIS). Functionally, the two are subtly equivalent, as the "to pfn" API short-circuits hva_to_pfn() if hva_to_pfn_fast() fails, i.e. is just a wrapper for get_user_page_fast_only()/get_user_pages_fast_only(). Switching to the "to page" API will allow dropping the @atomic parameter from the entire hva_to_pfn() callchain. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/paging_tmpl.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index ef0b3b213e5b..6b215a932158 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -535,8 +535,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, { struct kvm_memory_slot *slot; unsigned pte_access; + struct page *page; gfn_t gfn; - kvm_pfn_t pfn; if (FNAME(prefetch_invalid_gpte)(vcpu, sp, spte, gpte)) return false; @@ -549,12 +549,11 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, if (!slot) return false; - pfn = gfn_to_pfn_memslot_atomic(slot, gfn); - if (is_error_pfn(pfn)) + if (gfn_to_page_many_atomic(slot, gfn, &page, 1) != 1) return false; - mmu_set_spte(vcpu, slot, spte, pte_access, gfn, pfn, NULL); - kvm_release_pfn_clean(pfn); + mmu_set_spte(vcpu, slot, spte, pte_access, gfn, page_to_pfn(page), NULL); + kvm_release_page_clean(page); return true; }