From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8697401A31 for ; Mon, 11 May 2026 15:37:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778513864; cv=none; b=J842RtUw28o8VZhGKqiKm1kRzsvbEAUTRcNRaFh5X2IAIYeC1mBwTx+KbwAl3I0XlL062caNWRzft6TVsIojDdDLijHHqwLx6NnR/Q4vVdpL/l8jRP7BpqWvVGvjeJjS4fAhXEykav5DRiu0T/fxmFtaocp/FHXmdeL0NXjyJ60= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778513864; c=relaxed/simple; bh=Yj3LjSZQo7HQJbCpCUOtAzwclCCix2BLoMMa9VEHBsI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f8H8jA60nuBTGK5iypxsKHGx56T/nE8QCbxycFYSCxaAc6s0bOg/meT2ad1lHIaPRinmVYWMoedR5ibe+FbNUEMuSn2nI1kqh8tAOf/aFD1Pf88cuYT2irpEXH2aDnPlQmwMlwuzMR5Dfq73BPL8eT2XCczBRvbJvQgAV9MJ/zM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=MAjyBDLB; arc=none smtp.client-ip=209.85.217.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="MAjyBDLB" Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-628086439b6so3370765137.2 for ; Mon, 11 May 2026 08:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1778513861; x=1779118661; 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=4o7InZBqCk+7loPCj3VNzWtQgfmKxcMnRJsXC1AWBtY=; b=MAjyBDLBqbmMtV5ldlx2GYh+05iHzG1lVbajnX/0waRmTC0DIgHKqbvaU2bB2tBzt+ cRrWc7+nvf8qI5vuOQIIspBodGlDpQZjtu+p6FezaKOgoV2AD//BpYqECDaNjvyjF0nN n5C3NOxv7oSANOtP/hOiRSwlSQLI++jFO37o66t4y0UI4jwpdXkS9rS+9dvcCYC2LueS p0+HNYOkxCOPwHbiV+n+fQez6WKUb86PyciReUDY3J7L6AZ3YTdcvOovyLYXas7qFv0t +fBPCEVz66Fo4cjMs57F+NAdBkwd5m9Ni3ItS4pPZ4DWaJx2PFQAuYyy/QhCbtVdWWfF rErA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778513861; x=1779118661; 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=4o7InZBqCk+7loPCj3VNzWtQgfmKxcMnRJsXC1AWBtY=; b=B1Y8smVdg5zbYnfJJn97nPDYao+SDA9pF6a2zcQ8pnWW8yzCyXTxaKk50UJPC0jRtJ dRzXk/4FLUE4aEHuTQt3qsPNiLPWm0cFVrNy8N4vuO+gJFqyNjH9eKteiYKCEH1K1+AH eURbKCUOOAeI2ahfR906dpOoHkotw1yIN2ICycURT3C4VVZDvzBUl+itRbY84XPEWGZl Br+APUxnNpISWquuBSTelb7pwt7bZ6Odh9kWBFIDcMHTWQlSTlP7z4wlLisNI8SQ1UK/ j7q1GDjTIn6uXdm9hTzPXz3CMgoL2ur9HnsvITNkeJEUAaffXn5B4WnH8DZpQAa9GXI6 zPzA== X-Gm-Message-State: AOJu0YwEN7G8HF7bYtfjCL7lQad+i2T3AfzN9OicP9k72k7mO0RgBCkU jDLOQnPjCjALC3cvS/hGrjRedUURmRK7WTQDvynKPAcDlWoFL3zhhOwrgiV/7kXwAaM= X-Gm-Gg: Acq92OGizwPQrGelf0bGzvCN/LexXyx1hn2/4CGAfLoeR8e30kt3UxklI8dsXqgHckz s+uF+QEzpLZ5bqKwL5X3IitVnHY2xeLogFtnaaDrSbwm2p2zTVdrjq1F8Z/A025BeMcsxuAp5XS weAx083iOFfAeII8rzGpgS7nQqbDpNiwlEXlfQhlhixCmvjtMijXZgYYKAzBwkCflpugjH7eTW9 AP7CHN67wuUY/HUdpMp6ate9g61wzVbnV/X9d3n0dyFovd5p2e7Ej1clvTThNI5XECPkyIKGyZ4 fhIj+LlhVOIcgTdMreW8Rs2Qj1u7yQ2UV+k0B0v+y6SQk+rSVUeqxFO7HFB3DBj+1F7isrCJgAe VQ0RPZSvDUNJEkSml+KBcf2c7SqDE7Hy6RQmm/9lp5DkFGX6AA1joO+eHzSiuMbGsyMKRwcenKR I8lPr5wHh8p0ZFT/PR2/utQZ1hoNmOCp6imK57gdO5kkZ+O3tndVgaNJD87RJ1S3jXdLtHctMXQ QpXx42izUjEfNDa/ZQEXCw= X-Received: by 2002:a05:6102:5a85:b0:633:4d1a:65e4 with SMTP id ada2fe7eead31-6334d29b73amr3014460137.12.1778513860817; Mon, 11 May 2026 08:37:40 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F (pool-100-36-248-188.washdc.fios.verizon.net. [100.36.248.188]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8bf39c81b1csm97160166d6.28.2026.05.11.08.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 08:37:40 -0700 (PDT) Date: Mon, 11 May 2026 11:37:37 -0400 From: Gregory Price To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , 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 , 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 , "Liam R. Howlett" , Harry Yoo , Hao Li Subject: Re: [PATCH resend v6 03/30] mm: thread user_addr through page allocator for cache-friendly zeroing Message-ID: References: <9b53972f4854c1064b92cefc464f51949afeb83f.1778489843.git.mst@redhat.com> 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: <9b53972f4854c1064b92cefc464f51949afeb83f.1778489843.git.mst@redhat.com> On Mon, May 11, 2026 at 05:01:55AM -0400, Michael S. Tsirkin wrote: > Thread a user virtual address from vma_alloc_folio() down through > the page allocator to post_alloc_hook(). This is plumbing > preparation for a subsequent patch that will use user_addr to > call folio_zero_user() for cache-friendly zeroing of user pages. > > The user_addr is stored in struct alloc_context and flows through: > vma_alloc_folio -> folio_alloc_mpol -> __alloc_pages_mpol -> > __alloc_frozen_pages -> get_page_from_freelist -> prep_new_page -> > post_alloc_hook This is the nitty-est of all nits, but when doing this can we please prefer stack style? vma_alloc_folio folio_alloc_mpol __alloc_pages_mpol __alloc_frozen_pages get_page_from_freelist prep_new_page post_alloc_hook Claude has a bad habit of writing changelog changes this way, and it's painful for a human to try to read. > > USER_ADDR_NONE ((unsigned long)-1) is used for non-user > allocations, since address 0 is a valid userspace mapping. > > +/* > + * Sentinel for user_addr: indicates a non-user allocation. > + * Cannot use 0 because address 0 is a valid userspace mapping. > + */ > +#define USER_ADDR_NONE ((unsigned long)-1) Ehm, hm. Does -1 hold as a non-user address across all architectures? What about in linear addressing / no VM mode? > diff --git a/include/linux/gfp.h b/include/linux/gfp.h > index 7ccbda35b9ad..ee35c5367abc 100644 > --- a/include/linux/gfp.h > +++ b/include/linux/gfp.h > @@ -337,7 +337,7 @@ static inline struct folio *folio_alloc_noprof(gfp_t gfp, unsigned int order) > static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, > struct mempolicy *mpol, pgoff_t ilx, int nid) > { > - return folio_alloc_noprof(gfp, order); > + return __folio_alloc_noprof(gfp, order, numa_node_id(), NULL); > } > #endif > This change seems out of place unless i'm missing something. > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index f24bf49be047..a999f3ead852 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1806,7 +1806,8 @@ struct address_space *hugetlb_folio_mapping_lock_write(struct folio *folio) > } > > static struct folio *alloc_buddy_frozen_folio(int order, gfp_t gfp_mask, > - int nid, nodemask_t *nmask, nodemask_t *node_alloc_noretry) > + int nid, nodemask_t *nmask, nodemask_t *node_alloc_noretry, > + unsigned long addr) user_addr? uaddr? > @@ -1823,7 +1824,7 @@ static struct folio *alloc_buddy_frozen_folio(int order, gfp_t gfp_mask, > if (alloc_try_hard) > gfp_mask |= __GFP_RETRY_MAYFAIL; > > - folio = (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmask); > + folio = (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmask, addr); Not on you, but the changes in hugetlb.c as a whole are :[ We do all of this to pass USER_ADDR_NONE all over the place, but the alternative is having a separate function specifically for user-land bound allocations. So the trade off is: a) churn the current interface for everyone b) add a user_ variant and know people will just get it wrong IIRC you said the consequence of getting wrong here is subtle corruption if a caller got it wrong, and this was related to cache flushing for the provided user address? Stupid question: Does this not apply to kernel allocations as well? Or is it simply a matter of the cache having stale data that could leak, and therefore it's not a concern in-kernel? ~Gregory