From patchwork Thu Sep 26 01:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13812676 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7820BCCFA12 for ; Thu, 26 Sep 2024 01:35:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 996DA6B00AD; Wed, 25 Sep 2024 21:35:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 944B66B00AE; Wed, 25 Sep 2024 21:35:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E4D86B00B4; Wed, 25 Sep 2024 21:35:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 61DE86B00AD for ; Wed, 25 Sep 2024 21:35:19 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E6EF81A1211 for ; Thu, 26 Sep 2024 01:35:18 +0000 (UTC) X-FDA: 82605171516.13.F28C275 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf09.hostedemail.com (Postfix) with ESMTP id 2C83B14000A for ; Thu, 26 Sep 2024 01:35:17 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bvlj7Ksl; spf=pass (imf09.hostedemail.com: domain of 3VLr0ZgoKCNkEOCJPBCOJIBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3VLr0ZgoKCNkEOCJPBCOJIBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727314357; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xCPXKlvg3fvHTzjtwRf5eteIHvTFuMld4Zvbq5X/Dxs=; b=jVaxCZZ2Bmd/s3SH+bF/GNa8orQ5SAo8E4BLs0DPY4KodD1kMr2Z8Jd4VhmGz+Pd9eOKgX cwGK9SlroZY76MlYgVjpvYg47Bk116BHMakAUe0YapsY+WBisIgI1Z22MhYjK4Ont+l/vi 4LnToq/LvOF0Sot7CvXGJcKAak7uOac= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bvlj7Ksl; spf=pass (imf09.hostedemail.com: domain of 3VLr0ZgoKCNkEOCJPBCOJIBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3VLr0ZgoKCNkEOCJPBCOJIBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727314357; a=rsa-sha256; cv=none; b=t5MOQROMYdB/BqxgLeayAk1Djdta63ioSBoc/t+m17+kMkCWfWY3UMZyk+jziEMHUnKy+V 8bRQ5mFopRr6V0B788Uczbl08py1gH6o1lmzjHjC9cwaCGYoLddfYkUcOqzYCCbmXykCBL jEeqyrTMmP/9wxmOYbZEeJDxfQXzqls= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e25cfee6581so84922276.2 for ; Wed, 25 Sep 2024 18:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727314516; x=1727919316; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xCPXKlvg3fvHTzjtwRf5eteIHvTFuMld4Zvbq5X/Dxs=; b=bvlj7Ksl6cxdh56fj9d6mO4ikFd5vSmjoS+UhwuW5l0iUAziBjiRU1X8Sw6SshFocr RnrD5ykx0pgv+POaKdBpV4lN9XNDhKAA+G6G+0lY/G5jBTmeyjjrYwXyonCtAauJRkXB 8/zqJ0z/hUTl1QY7ojCeVJWH6BIC3hTlujMYB70gc938iz6b1DSosUePQQQ1Bstq1qi9 lTyzDF8s+g/6zAZYcqP5BNPjjtVenHv8o1oxgg3+mLxQEvvaQD7NlLY2abZapgwEyMVp YrPdVlIEliFWnJW6VzeB9N7y7xFZG3xkiHB3Xfv1L5e4P+fv87IRH6pf6E3hKrWwrkbh JBwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727314516; x=1727919316; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xCPXKlvg3fvHTzjtwRf5eteIHvTFuMld4Zvbq5X/Dxs=; b=KjefD42k9gC+OI1WfXgjimWs7h34LmobxfowVBG/3tC4uwWlb47D6VuZJ2phymuAh1 WeLZAYa3g8ov+g3fncBc8tlndkvzGbrh8Pk4GhfvH2Pd61RgVrY+mOkwgSYNR5Ef1yXx b9nsrTwm6X0yiMDiKd2XvNA7Dc6OLrbzPkq3eqaOMzFt7elZdeygRH9Ewjs9yMZgC95u 86D76exVHp3gJrESoXWoE/9YXRrKCcYdImphwCG9IgXmNra/D1aK5DBk9/eO9PM7gax5 j2rhyRwEslQt6eEq/SLUc0llqFbuhZpclAsHgtVFgpuz/ayjgNHUdp5jiisDxsFxHo2j l3Fw== X-Forwarded-Encrypted: i=1; AJvYcCUSQ5WeltfPJyAWDJHrv17DFDuXURjkerGu8jqDq1sui2K6zKTTo88g1Z3RW9T9DLlehxWDC6shbw==@kvack.org X-Gm-Message-State: AOJu0YxWE/MzgyO0IdjIIr8S/4femVXgQd4NWA6AHDIifqyHbZ25hmKE 16SIxTJRa7cnLi0SNo3SlYlpdr2I1BDjUGiZG5P1viJuUuCgpKollfjizIPHtL3WpmquoGgt6xE LJDi8yJF409Q2gXDL8g== X-Google-Smtp-Source: AGHT+IHCtBDgdi+XBFMofkXIkzVJkl+teLSBao9sOlv55Q8B7jZN9hLVgp83Pu834/Q28A3MUQoEEh6YXmiO2wqz X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:13d:fb22:ac12:a84b]) (user=jthoughton job=sendgmr) by 2002:a25:97c7:0:b0:e25:c8fc:b78c with SMTP id 3f1490d57ef6-e25c8fcbb92mr1586276.9.1727314516206; Wed, 25 Sep 2024 18:35:16 -0700 (PDT) Date: Thu, 26 Sep 2024 01:34:49 +0000 In-Reply-To: <20240926013506.860253-1-jthoughton@google.com> Mime-Version: 1.0 References: <20240926013506.860253-1-jthoughton@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926013506.860253-2-jthoughton@google.com> Subject: [PATCH v7 01/18] KVM: Remove kvm_handle_hva_range helper functions From: James Houghton To: Sean Christopherson , Paolo Bonzini Cc: Andrew Morton , David Matlack , David Rientjes , James Houghton , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Oliver Upton , Wei Xu , Yu Zhao , Axel Rasmussen , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2C83B14000A X-Stat-Signature: hcpkdp7deqdnauxxh6iyhfnjsdweu8x4 X-Rspam-User: X-HE-Tag: 1727314517-165223 X-HE-Meta: U2FsdGVkX1+L5vjuIaETZU7gtCoZX2/YiEldwGU4o+6Ka8I1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iJqAGXKgv1s1h5z/fRg/Vzi3UEFR1C7+VbHP6Aa1mYX/uM1SBbuAhQZjAqdOzq9ghpU5wN9ZF0ULQ2UWxVgZmBkQVBpjhar5bXqmJJLr5cDfA843JTMO435CjbWV7n5sDxt4xT8svgCMoMCbbCy2GKGXPBH6kA91AcXuMjhGXJGyS1FigMxtSSrYYR4ObOQGRkI9ReE6teWUOptiT0pwLzXa5xyQb5AUpN826zWPVJm8srW4ReiaHrr0oUkV0tl1dsY6u32oNZ5irkHWZqbG5sniFJl22sPwdk6SC6CUQTfy5GuWQ3ZGJvVpT0N1jKCV7E9sQlJtgvoVgQwLXt91yDPavC374kKUkLhIWBKcWdTiOO10rrzG+piHyb5GREn/m8fqkWN+fn2NSAn2etVpHPmEmy/lDJTHgDO06TJmbk4uGR0GixqZJAf0YyLgS49d7pBdIv8NZhJtKvgf8EjAmimQ1s2WgRsg923y1+UxGmQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: kvm_handle_hva_range is only used by the young notifiers. In a later patch, it will be even further tied to the young notifiers. Instead of renaming kvm_handle_hva_range to something like kvm_handle_hva_range_young, simply remove kvm_handle_hva_range. This seems slightly more readable, though there is slightly more code duplication. Finally, rename __kvm_handle_hva_range to kvm_handle_hva_range, now that the name is available. Suggested-by: David Matlack Signed-off-by: James Houghton --- virt/kvm/kvm_main.c | 81 +++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d51357fd28d7..090e79e4304f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -589,8 +589,8 @@ static void kvm_null_fn(void) node; \ node = interval_tree_iter_next(node, start, last)) \ -static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, - const struct kvm_mmu_notifier_range *range) +static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm, + const struct kvm_mmu_notifier_range *range) { struct kvm_mmu_notifier_return r = { .ret = false, @@ -666,42 +666,6 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, return r; } -static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn, - unsigned long start, - unsigned long end, - gfn_handler_t handler) -{ - struct kvm *kvm = mmu_notifier_to_kvm(mn); - const struct kvm_mmu_notifier_range range = { - .start = start, - .end = end, - .handler = handler, - .on_lock = (void *)kvm_null_fn, - .flush_on_ret = true, - .may_block = false, - }; - - return __kvm_handle_hva_range(kvm, &range).ret; -} - -static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn, - unsigned long start, - unsigned long end, - gfn_handler_t handler) -{ - struct kvm *kvm = mmu_notifier_to_kvm(mn); - const struct kvm_mmu_notifier_range range = { - .start = start, - .end = end, - .handler = handler, - .on_lock = (void *)kvm_null_fn, - .flush_on_ret = false, - .may_block = false, - }; - - return __kvm_handle_hva_range(kvm, &range).ret; -} - void kvm_mmu_invalidate_begin(struct kvm *kvm) { lockdep_assert_held_write(&kvm->mmu_lock); @@ -794,7 +758,7 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, * that guest memory has been reclaimed. This needs to be done *after* * dropping mmu_lock, as x86's reclaim path is slooooow. */ - if (__kvm_handle_hva_range(kvm, &hva_range).found_memslot) + if (kvm_handle_hva_range(kvm, &hva_range).found_memslot) kvm_arch_guest_memory_reclaimed(kvm); return 0; @@ -840,7 +804,7 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, }; bool wake; - __kvm_handle_hva_range(kvm, &hva_range); + kvm_handle_hva_range(kvm, &hva_range); /* Pairs with the increment in range_start(). */ spin_lock(&kvm->mn_invalidate_lock); @@ -862,9 +826,19 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn, unsigned long start, unsigned long end) { + struct kvm *kvm = mmu_notifier_to_kvm(mn); + const struct kvm_mmu_notifier_range range = { + .start = start, + .end = end, + .handler = kvm_age_gfn, + .on_lock = (void *)kvm_null_fn, + .flush_on_ret = true, + .may_block = false, + }; + trace_kvm_age_hva(start, end); - return kvm_handle_hva_range(mn, start, end, kvm_age_gfn); + return kvm_handle_hva_range(kvm, &range).ret; } static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, @@ -872,6 +846,16 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, unsigned long start, unsigned long end) { + struct kvm *kvm = mmu_notifier_to_kvm(mn); + const struct kvm_mmu_notifier_range range = { + .start = start, + .end = end, + .handler = kvm_age_gfn, + .on_lock = (void *)kvm_null_fn, + .flush_on_ret = false, + .may_block = false, + }; + trace_kvm_age_hva(start, end); /* @@ -887,17 +871,26 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, * cadence. If we find this inaccurate, we might come up with a * more sophisticated heuristic later. */ - return kvm_handle_hva_range_no_flush(mn, start, end, kvm_age_gfn); + return kvm_handle_hva_range(kvm, &range).ret; } static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn, struct mm_struct *mm, unsigned long address) { + struct kvm *kvm = mmu_notifier_to_kvm(mn); + const struct kvm_mmu_notifier_range range = { + .start = address, + .end = address + 1, + .handler = kvm_test_age_gfn, + .on_lock = (void *)kvm_null_fn, + .flush_on_ret = false, + .may_block = false, + }; + trace_kvm_test_age_hva(address); - return kvm_handle_hva_range_no_flush(mn, address, address + 1, - kvm_test_age_gfn); + return kvm_handle_hva_range(kvm, &range).ret; } static void kvm_mmu_notifier_release(struct mmu_notifier *mn,