From patchwork Fri Jul 26 23:51:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743468 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 B2CDAC3DA4A for ; Sat, 27 Jul 2024 00:04:29 +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=o1vHCUb6CZ680r+o/spGyfXDOmfamym0Nonz9UARGME=; b=GbQSA72jLZkj/OdSRubBCKOXQF BsNS68nCusyjMuTGeYL8oZU8NlafKix8Tk2aFa8E3/iBzyJfq9wpSfEoSW4euPE+QfbqULkcxO2R6 E63DRLWhvCpxAe41lfoMrkcPw6j5IE6Z+M/YcF5vxkMWA+eXXVRhjAgUr+wdxHp1qAlm807ZAz21V 6QFfUybxSqcRB7dsCIPOe0cZOo6+3sR4GXRaB63hbo6br2p9qB8q/X7oIXB2UX0NMzja3bFoInBrS m49GDpyEtTrMTvndsEleQG7M7RPHGzZXRnMsswbHjFqeGruLCh8NNwXIV6VzblU2nfB09RZmAYlDI CXiDiSIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUv6-00000005W5C-1PJN; Sat, 27 Jul 2024 00:04:20 +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 1sXUkh-00000005Pr3-0IM4 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:53:38 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1fc5b60f416so10713505ad.3 for ; Fri, 26 Jul 2024 16:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038014; x=1722642814; 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=o1vHCUb6CZ680r+o/spGyfXDOmfamym0Nonz9UARGME=; b=ASID56uOqS7A7nICzxxM8Jr7+MVvEX/51hN7vQA6Xhg61XIKknC+txjvtbHaUfFW61 3c/JJq/vhCzAKRyuAfS5HHbfawnj9weOWtch1m4zSDYnkhSKmCf93+3wjsEOfg9oSPKl SjspJrJEzeQXeVoFdNQjt/fzq1KbdU6sidEMuLSqXnK+lUlZWUj2a7pge5JnwSBFz/ry Z77BNMmk1U0mpl22cojlcERTTOKyezdMFiWgxqYTtdDYT5gLWvVUjKx5yWW8Z62bGxDp BQzRnot6gZHOc0GqOkiUhIpBQ5QledMXprzeidPIplFLGd4aOGpwXNCtn9XwN2pGtWLU bs0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038014; x=1722642814; 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=o1vHCUb6CZ680r+o/spGyfXDOmfamym0Nonz9UARGME=; b=Qyopz6RV4ZiktkvPQUvbJ20X7WdFBmocE34I+PDOfwQ2xlsT5nDb42+brhuctsL6z/ r2iaetHRuW4Zu1ViUWoWtWvuvAweCC8ri4+4f1PiFAej4ingh5bN7ma9aKD1yj7F/OyT XytvPZTk6peB01xpelAHxlU67ZocFDJOICLZZI+2TAfR3xZlDNuUhwwTDw+NcdF21EeL +u2EJhNZrR34pgD38zx4Y52s8PXmF+v7bhpZIs0uUEynfQYtE2rbKqGVsxsspFzSIEaw SXHjb3wXXwlQhyFtDV8wAc5fZffFE9jJC2j7q996kkzY1rQWU9hFQsgii4tfn2VsEiic ukLQ== X-Forwarded-Encrypted: i=1; AJvYcCWp4Ky0CsK4yBf+msY9iztDQA+f6dgXnxnX7OeAQRcZV+AlPGvsdIZpe7JW3FHXtdphMk7dGeHME5VdtB5TZ32xHekwoSKJogxLCbzPw9Qx66YLQaU= X-Gm-Message-State: AOJu0YwODA07KZFToXuOtJmBp2w2/NDhHBDTdE7UoDlsCZcTVWr6e3rJ 6Fp30J/iDd0LdugkOrWddcBz+/47eVdsS/SUQbzegK30LPOvjOnlOzZgRDQ8AB9dQtKLBj+hxHV b3g== X-Google-Smtp-Source: AGHT+IEBaNygerYKF4xG2tivsYC4I+4KiNqX7pDiMNbM1xexlfLGsv92ykpFMstIuclC7BO9j6NqEQXsK1A= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d2c5:b0:1f9:b35f:a2b6 with SMTP id d9443c01a7336-1ff047dce33mr22915ad.1.1722038013079; Fri, 26 Jul 2024 16:53:33 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:36 -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-28-seanjc@google.com> Subject: [PATCH v12 27/84] KVM: pfncache: Precisely track refcounted 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_165335_179298_A84A40BE X-CRM114-Status: GOOD ( 12.89 ) 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 Track refcounted struct page memory using kvm_follow_pfn.refcounted_page instead of relying on kvm_release_pfn_clean() to correctly detect that the pfn is associated with a struct page. Signed-off-by: Sean Christopherson --- virt/kvm/pfncache.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 067daf9ad6ef..728d2c1b488a 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -159,11 +159,14 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) kvm_pfn_t new_pfn = KVM_PFN_ERR_FAULT; void *new_khva = NULL; unsigned long mmu_seq; + struct page *page; + struct kvm_follow_pfn kfp = { .slot = gpc->memslot, .gfn = gpa_to_gfn(gpc->gpa), .flags = FOLL_WRITE, .hva = gpc->uhva, + .refcounted_page = &page, }; lockdep_assert_held(&gpc->refresh_lock); @@ -198,7 +201,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) if (new_khva != old_khva) gpc_unmap(new_pfn, new_khva); - kvm_release_pfn_clean(new_pfn); + kvm_release_page_unused(page); cond_resched(); } @@ -218,7 +221,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) new_khva = gpc_map(new_pfn); if (!new_khva) { - kvm_release_pfn_clean(new_pfn); + kvm_release_page_unused(page); goto out_error; } @@ -236,11 +239,11 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) gpc->khva = new_khva + offset_in_page(gpc->uhva); /* - * Put the reference to the _new_ pfn. The pfn is now tracked by the + * Put the reference to the _new_ page. The page is now tracked by the * cache and can be safely migrated, swapped, etc... as the cache will * invalidate any mappings in response to relevant mmu_notifier events. */ - kvm_release_pfn_clean(new_pfn); + kvm_release_page_clean(page); return 0;