From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B36603955DD for ; Mon, 8 Jun 2026 08:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907766; cv=none; b=oXat9MWCkURctNuYDtBRicBr6yeeYQjYL/nhhisqPAbFRL7MWtZY2vzhjZXNCdpUgvw0GqNBhws3j/5dSbp08Wr4oykE0ZiYkSA2+Piq2SeQNuNzw3ih39ZaQSxxF/6oeAhaWvsgDEx7/QhrRlhMuIW5YG91I2wfTjXgGSDng/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907766; c=relaxed/simple; bh=VvYEZY8DbRfnOqU9SNzEdKKP+Kx+uDwCJkKNzhWK0fc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZORDV1n9uCVqzD53jwYiUDvVVHstQQUBKBvIDZw0CNSl4TUmmjJrKri08RGh09RcWojqAGmZPKSfLypxGGuw2RbbOJV69hn6RkRJyIuAXuki/i9HoF/BHZWLQXQVHHlxGRhRFcsLBzk/sLZTtvKiD2yN2XCxKCTk/OunF34/Ne4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c3wqB9hY; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Bg6HP6do; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c3wqB9hY"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bg6HP6do" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OcVo+/Lds4YxddLi3UfNSteOvi0JEMISiAqD3/N1YSI=; b=c3wqB9hY472bXHN0m28ksX9jAWkzuEfRf4FObbAfwBuF/lm99nlWprXZtAOhoxLm0Ktzj/ eXMCC+UXHWMh1dlWmSAq8uRLdRWYLpXyU/WW3FQCDEzVfa0UWiFboNNrHs1RBiIgMEitRE VJ8/VnzLk3Y0ulzbSz8m80t+K95AvT8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-4H4DAZNFMOSWLuqIJhOdUQ-1; Mon, 08 Jun 2026 04:35:47 -0400 X-MC-Unique: 4H4DAZNFMOSWLuqIJhOdUQ-1 X-Mimecast-MFC-AGG-ID: 4H4DAZNFMOSWLuqIJhOdUQ_1780907746 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4601c9b630fso1627511f8f.0 for ; Mon, 08 Jun 2026 01:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907746; x=1781512546; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OcVo+/Lds4YxddLi3UfNSteOvi0JEMISiAqD3/N1YSI=; b=Bg6HP6doMddpIcDcHk/v5luheQ/8ry7EpxqVQT6mxwLvipVeLeEKW126LlF/jIK0zT vDTGEgQdrHDntqBs0gessKzNWHwUJO83rnqX/MLvn4YaGafid0RIITMrVSNa3SC+DNKI htHWMQRnRZNPhGwjB89Ed6hD0lQzAu8Q35DjIhckbEpcS5p5xK4aH8GAwjthNpGhvcsF 9CGsHkOOyiaEPpY5xvlwuVbfUoWuRJikYfW9pFKulwkz8yj8hxhpvA6gq5iARtRfVZVZ P5fdMkCfmW1hNf7mWSgb+Vl12nSZ1LVQmhyccibnSCbxVG54zTpUuRJ8XbifdmeArx9v q2Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907746; x=1781512546; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OcVo+/Lds4YxddLi3UfNSteOvi0JEMISiAqD3/N1YSI=; b=saO7gwy7S5w6am5bq+VdIvJei9F62uTjRSNamxKmUj761Fjlddy5fyI6GhxEyAkryI M+tSLhTmHJFUjXkup7CBsRGwvvBoaRKeBVYsLF9d+CMS8SNOtqRUPUNZybd6dE2Z851f EqW3laxvD1giiQtd8f/mbfQOPN1CkO79SVpyo3PtgVkrwg7M4HJD2EZ/YhBmi1FatdXd UW+dEYaU4ALaRKIkrUMKxOdPVrzeqx2KQSz7ZMazbLYf2VAbxjmiqaJgBjkf18g1Snn4 Ej/6aIDZBETfIJEf3faVNvLThfmEQ22slMl9OdYd3THtuEkjyTRlH+NHd0G+9FEDp7Pt X+bA== X-Gm-Message-State: AOJu0Yx0Iyj3m3rdqNmxpKhlW7aqDB13rmbaer8Bat7XeCa5ISNtAvM0 jyZiSmrkvAaFpwkIUDYCusztU7qVR59MPz7cgm2auYZ2dZK4ecEW0CST/VBEqs+l/wXqIMC6CZe UfEQCHVCKVL5H+7zRheJ84GlT32KPBX7eN5ElEyjLfIle49jsXZKUnbw5RTI+ZPFMivqVBw/NJ1 sOIZcnyXRL1HKFjLgH9oZ46QYO+8NUCdQMGJYAONTJmTM= X-Gm-Gg: Acq92OEaDhhWyaKsI3cfm1PX1WWzpATUbWlhtcYucUqt6jYcw2gZKkf008NhQ+k6wHL TU0O5yveVAvWXahdxLfih2UYbW+tTeur0eWED0ftb6wkR7K1IiLU4Oit042SfX3osQ/HQIvJof5 +TOBcYz2hxmeik7hLLhi7koS0z308Rlz/uW0poIl1TmRqpkJxjNaDTi1JXmvz+7H4Fs5Yj/LPPi w6y9PbqiXhq00iFsmSVjcGkDJtU6Y0mVjh5ChrwFd6ZiqkRiW95pc56B+udzxnrvHDOsStSx9gq 2XrNwb1hkPz9QjXWWP73oNEMFrn/n/e0IkCJm23Sx/amny0d1Ghc5KqHsTmnylExGryDv60bN2U PC6XG0ZeSrjam+oNae1dxp1U= X-Received: by 2002:a05:600c:e548:10b0:490:cf76:dea4 with SMTP id 5b1f17b1804b1-490cf76dec2mr27271375e9.2.1780907744827; Mon, 08 Jun 2026 01:35:44 -0700 (PDT) X-Received: by 2002:a05:600c:e548:10b0:490:cf76:dea4 with SMTP id 5b1f17b1804b1-490cf76dec2mr27270255e9.2.1780907744100; Mon, 08 Jun 2026 01:35:44 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2dc577sm50742305f8f.3.2026.06.08.01.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:35:43 -0700 (PDT) Date: Mon, 8 Jun 2026 04:35:29 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: [PATCH v10 08/37] mm: add alloc_contig_frozen_pages_user for cache-friendly zeroing Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.51.2.2891.g4157995a80.dirty X-Mutt-Fcc: =sent Add a _user variant of alloc_contig_frozen_pages that accepts a user_addr parameter for cache-friendly zeroing of contiguous allocations. No functional change; all existing callers continue to pass USER_ADDR_NONE. Note for reviewers: non-compound contiguous allocations are zeroed via kernel_init_pages, same as before this patch. There is no fault address because these allocations are not from the page fault path. For compound allocations, user_addr reaches post_alloc_hook() which calls folio_zero_user() with the dcache flush on cache-aliasing architectures. Note about Sashiko (sashiko.dev) false positives: sashiko flags two issues here: (1) user_addr silently ignored for non-compound allocations, and (2) post_alloc_hook ignores user_addr. Both are false positives: (1) non-compound contiguous allocations have no fault address to pass, and (2) post_alloc_hook does use user_addr when it is not USER_ADDR_NONE. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/gfp.h | 6 ++++++ mm/page_alloc.c | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ee35c5367abc..73109d4e31a4 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -453,6 +453,12 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, #define alloc_contig_frozen_pages(...) \ alloc_hooks(alloc_contig_frozen_pages_noprof(__VA_ARGS__)) +struct page *alloc_contig_frozen_pages_user_noprof(unsigned long nr_pages, + gfp_t gfp_mask, int nid, nodemask_t *nodemask, + unsigned long user_addr); +#define alloc_contig_frozen_pages_user(...) \ + alloc_hooks(alloc_contig_frozen_pages_user_noprof(__VA_ARGS__)) + struct page *alloc_contig_pages_noprof(unsigned long nr_pages, gfp_t gfp_mask, int nid, nodemask_t *nodemask); #define alloc_contig_pages(...) \ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 21b52c879751..6d3f284c607d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6975,13 +6975,15 @@ static void __free_contig_frozen_range(unsigned long pfn, unsigned long nr_pages } /** - * alloc_contig_frozen_range() -- tries to allocate given range of frozen pages + * __alloc_contig_frozen_range() -- tries to allocate given range of frozen pages * @start: start PFN to allocate * @end: one-past-the-last PFN to allocate * @alloc_flags: allocation information * @gfp_mask: GFP mask. Node/zone/placement hints are ignored; only some * action and reclaim modifiers are supported. Reclaim modifiers * control allocation behavior during compaction/migration/reclaim. + * @user_addr: user virtual address for cache-friendly zeroing, or + * USER_ADDR_NONE for kernel allocations. * * The PFN range does not have to be pageblock aligned. The PFN range must * belong to a single zone. @@ -6997,8 +6999,9 @@ static void __free_contig_frozen_range(unsigned long pfn, unsigned long nr_pages * * Return: zero on success or negative error code. */ -int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, - acr_flags_t alloc_flags, gfp_t gfp_mask) +static int __alloc_contig_frozen_range(unsigned long start, unsigned long end, + acr_flags_t alloc_flags, gfp_t gfp_mask, + unsigned long user_addr) { const unsigned int order = ilog2(end - start); unsigned long outer_start, outer_end; @@ -7125,7 +7128,7 @@ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, struct page *head = pfn_to_page(start); check_new_pages(head, order); - prep_new_page(head, order, gfp_mask, 0, USER_ADDR_NONE); + prep_new_page(head, order, gfp_mask, 0, user_addr); } else { ret = -EINVAL; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n", @@ -7135,6 +7138,13 @@ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, undo_isolate_page_range(start, end); return ret; } + +int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, + acr_flags_t alloc_flags, gfp_t gfp_mask) +{ + return __alloc_contig_frozen_range(start, end, alloc_flags, gfp_mask, + USER_ADDR_NONE); +} EXPORT_SYMBOL(alloc_contig_frozen_range_noprof); /** @@ -7227,14 +7237,16 @@ static bool zone_spans_last_pfn(const struct zone *zone, return zone_spans_pfn(zone, last_pfn); } -/** - * alloc_contig_frozen_pages() -- tries to find and allocate contiguous range of frozen pages +/* + * alloc_contig_frozen_pages_user_noprof() -- allocate contiguous frozen pages with user address * @nr_pages: Number of contiguous pages to allocate * @gfp_mask: GFP mask. Node/zone/placement hints limit the search; only some * action and reclaim modifiers are supported. Reclaim modifiers * control allocation behavior during compaction/migration/reclaim. * @nid: Target node * @nodemask: Mask for other possible nodes + * @user_addr: user virtual address for cache-friendly zeroing, or + * USER_ADDR_NONE for kernel allocations. * * This routine is a wrapper around alloc_contig_frozen_range(). It scans over * zones on an applicable zonelist to find a contiguous pfn range which can then @@ -7253,8 +7265,9 @@ static bool zone_spans_last_pfn(const struct zone *zone, * * Return: pointer to contiguous frozen pages on success, or NULL if not successful. */ -struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, - gfp_t gfp_mask, int nid, nodemask_t *nodemask) +struct page *alloc_contig_frozen_pages_user_noprof(unsigned long nr_pages, + gfp_t gfp_mask, int nid, nodemask_t *nodemask, + unsigned long user_addr) { unsigned long ret, pfn, flags; struct zonelist *zonelist; @@ -7282,10 +7295,11 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, * win the race and cause allocation to fail. */ spin_unlock_irqrestore(&zone->lock, flags); - ret = alloc_contig_frozen_range_noprof(pfn, + ret = __alloc_contig_frozen_range(pfn, pfn + nr_pages, ACR_FLAGS_NONE, - gfp_mask); + gfp_mask, + user_addr); if (!ret) return pfn_to_page(pfn); spin_lock_irqsave(&zone->lock, flags); @@ -7307,6 +7321,14 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, } return NULL; } +EXPORT_SYMBOL(alloc_contig_frozen_pages_user_noprof); + +struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, + gfp_t gfp_mask, int nid, nodemask_t *nodemask) +{ + return alloc_contig_frozen_pages_user_noprof(nr_pages, gfp_mask, nid, + nodemask, USER_ADDR_NONE); +} EXPORT_SYMBOL(alloc_contig_frozen_pages_noprof); /** -- MST