From patchwork Thu Oct 10 18:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13831155 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 60625D24455 for ; Thu, 10 Oct 2024 21:16:40 +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-Transfer-Encoding:Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=k3/xcOX0JmpZSdxUAeDWhRU0v4mqVA9cM67JfDYoNsA=; b=A/MLAD2DUuatCr /YevtBfVj966HugWDzylmzm/fnPgJFA0/AJ6UfBztHvfbaxQqd1uU99mC4ysmkOvyt7EcogS80J1z hojgceIljejrDNXd62weVlqfVdlX8bWQb9zBB4u02DtZZTHuq7b5Mh39EaIeT6NOhFeoNJL0LMejp FAPgdTMfLfxQDlQQxku0UWAVDnI3lNzuVRlIDp0UySf1snlbzsWFpP8Wcd/cVULbcgJwdbaL7XTgM 1HjVdhlPoWmd2nJ7K+Qp4HYhemW+lTk2z3yrM/ud257T69jIF8hy8qCH+/kzVo2dV41hgXtBqABp4 aVn1QtSZyXMXrzIcF6tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sz0WJ-0000000ENWX-0gSC; Thu, 10 Oct 2024 21:16:27 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxqm-0000000Dpyw-04W6 for linux-arm-kernel@bombadil.infradead.org; Thu, 10 Oct 2024 18:25:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :Cc:To:From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Reply-To:Sender:Content-ID:Content-Description; bh=k3/xcOX0JmpZSdxUAeDWhRU0v4mqVA9cM67JfDYoNsA=; b=e4kC1GsnMc3fVWx150TWZkk4mJ W9GNOR/3K/bSrB94o8PL5T2UF2z018oVq2U9wburO+xK0rj9KecRNrOr51jKS8cees/SQmWs2coEj 7crRYNlk34ft5lpW5zYx/MnM6XBac6uKJh18ThElAGKnMITSu8ZIa8Gh5cMsRsIIIxblVx3UigMYs iAbVZTmnMYnL2Y6fMigROyCInmASG71VBBNm6gAAO0cFKJesKDIXnoCFyxTAJdHYyD0qCpj+8oei8 LTGP04cXknc8RAep1genntbr4rvg1hxzEVqdvHjwnBgnVDFVjDNe1fqQbPBXfZyaH0xArGfw0QFIR I4LJ7ATQ==; Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxqh-00000005UVL-1Ga9 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 18:25:22 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2e2a9577037so1354367a91.1 for ; Thu, 10 Oct 2024 11:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584713; x=1729189513; darn=lists.infradead.org; h=content-transfer-encoding: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=k3/xcOX0JmpZSdxUAeDWhRU0v4mqVA9cM67JfDYoNsA=; b=25I4FmM9q8/zakq/tajBcDwOrvaX/2yJF+noHaaqm7+nhtCEEA/vHiU69MABElw42H B0+z7J4m0eAxHcEysEV5vjKCvS07QkxRcPK+VkmZpmuUDp6NfwO3Hvjtsgw809Xkf7cK xEWsOB6J1lk8cjv54hI8ebnqvdiE0V8pyzSHiEy5o33n4d83JNM2vXUxpVVLfIIBy2Gk vnelAIZWHr1D4pc4Ntp/6Ckp76P4LiMNNaMPcqx8leW2ZC1NVk0dvQPNTg2yv+KCnTwe kjkpA8Kzuy4XL/IX5EnjFjgQ3ax4KyRzS75vIqG1SBagCjy18+WtNgYR9ZX90VOYzF7L 2vtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584713; x=1729189513; h=content-transfer-encoding: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=k3/xcOX0JmpZSdxUAeDWhRU0v4mqVA9cM67JfDYoNsA=; b=Bc+cdr+qY4bSow+iUI3FP2sDafjySebZzEnhYeS5rMtKnWyMuyZxRkkn5FHtvCUBsY KV1FTeX+EkAh0LGbQSlzzyqzZHYmvtHQGlwmDIOwrn7dpIl7/HO43sQWgbtV5RY+987w FO9osKujVlbvX7jPbEK2OeOWc3TBJxjC/BxR/si94tx92nuaFiwNAc6GtLoQVaYdU5NH l5aGdAPlT0t76DYRXv5X/HcmCITNxQk254EsoFcz0zPULZxFYxMO5AeStCXVfqQT+1+b BNtKH3CCaK5DtQFzOV+c5M3iYcAo4ypwk+D2mDyITpUbyYiaiwd/CdPqVKu2djl5/ryk MiZg== X-Forwarded-Encrypted: i=1; AJvYcCXt+dtIwA2keRsiqO+EKarBm0SzuWRy7a72rG2LiSzVnfs2gc7QzAaKVxa537wMEsanMT3gGmqKDCqP1DVk7evb@lists.infradead.org X-Gm-Message-State: AOJu0YyL+83AsAoHTjoykJ4ivsj7BvLJavZpj9Jl0Sw0obtYVwRIcMgj K8eAas73I9jikjFFoCRZW7njpzn2uFefTAiqqZ5IPUc+OZqNEE1gwva37KL8aJxTJMqeD1ap0o5 ajQ== X-Google-Smtp-Source: AGHT+IEzZdX7U43FtBqfYwOSCvhQrFRs7MoNj08p1am6l1FbD4QaVhgMc/3KfB78OlyTOzXtpjGPG3KIosU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:90a:ea0e:b0:2e2:d843:4880 with SMTP id 98e67ed59e1d1-2e2f0c82a2fmr30a91.5.1728584713017; Thu, 10 Oct 2024 11:25:13 -0700 (PDT) Date: Thu, 10 Oct 2024 11:23:12 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-11-seanjc@google.com> Subject: [PATCH v13 10/85] 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, " =?utf-8?q?Alex_Benn=C3=A9e?= " , Yan Zhao , David Matlack , David Stevens , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_192519_452165_3C5259FA X-CRM114-Status: GOOD ( 10.39 ) 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. Tested-by: Alex Bennée 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 fbaae040218b..36b2607280f0 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; }