linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Shivank Garg <shivankg@amd.com>,
	mhiramat@kernel.org, oleg@redhat.com, peterz@infradead.org,
	mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
	kan.liang@linux.intel.com, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-perf-users@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC] mm: use folio_expected_ref_count() helper for reference counting
Date: Tue, 10 Jun 2025 09:08:44 +0200	[thread overview]
Message-ID: <398d49f6-00c8-4bd8-ba30-62cbf0efee46@redhat.com> (raw)
In-Reply-To: <20250609170806.447302-2-shivankg@amd.com>

On 09.06.25 19:08, Shivank Garg wrote:
> Replace open-coded folio reference count calculations with the
> folio_expected_ref_count() helper to improve code maintainability
> and reduce duplication.
> 
> No functional changes intended.
> 
> Signed-off-by: Shivank Garg <shivankg@amd.com>
> ---
>   kernel/events/uprobes.c | 5 +++--
>   mm/memfd.c              | 4 ++--
>   2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 4c965ba77f9f..c978c8c27340 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -434,10 +434,11 @@ static int __uprobe_write_opcode(struct vm_area_struct *vma,
>   	/*
>   	 * When unregistering, we may only zap a PTE if uffd is disabled and
>   	 * there are no unexpected folio references ...
> +	 * Expected refs: mappings + swapcache.
> +	 * We hold one additional reference (+1).
>   	 */
>   	if (is_register || userfaultfd_missing(vma) ||
> -	    (folio_ref_count(folio) != folio_mapcount(folio) + 1 +
> -	     folio_test_swapcache(folio) * folio_nr_pages(folio)))
> +	    (folio_ref_count(folio) != folio_expected_ref_count(folio) + 1))
>   		goto remap;
>   

With the comment removed (the caller holds a reference from GUP) or 
simplified ("Caller holds an additional folio reference.")

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



  parent reply	other threads:[~2025-06-10  7:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09 17:08 Shivank Garg
2025-06-09 19:21 ` Matthew Wilcox
2025-06-09 19:31   ` Steven Rostedt
2025-06-09 19:51     ` Matthew Wilcox
2025-06-09 20:14       ` Steven Rostedt
2025-06-10  8:59         ` Shivank Garg
2025-06-10  7:05       ` David Hildenbrand
2025-06-10  2:26 ` Alistair Popple
2025-06-10  5:50   ` Shivank Garg
2025-06-10  7:08 ` David Hildenbrand [this message]
2025-06-10  9:00   ` Shivank Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=398d49f6-00c8-4bd8-ba30-62cbf0efee46@redhat.com \
    --to=david@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shivankg@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox