From nobody Sat Jun 13 03:27:12 2026 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 2200D3BD654 for ; Mon, 11 May 2026 09:01:54 +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=1778490116; cv=none; b=kWN3YSMOFl8dnryBta1AYl9PQeq4Enroa7w/tc3gWjQHtnfBnCrXncNVQ6KS0P3Gf08AYhprdZbCGh9wheRu++2Ei3uo/GKeL3y5Dgopxr110mBvXsZUeKdBPaJXi8O4fZxkIAvNNa99jY9j1VnAYyGafAGpEAM11L4wZsiOK/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490116; c=relaxed/simple; bh=9w/BOdxv/UPl05k6lc7Ua9O+VaMhaIMHRfLJTh0Clsg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jcyumh5/AzdwnEv/LU19SXjQTwceNMSCZlUpN/0rhSbLMridBIeBdh1lGBIO/bFQbfzixa4hcBntfklyfPEijJSxLQySxpikn0veAMrWwsts7Z0LxukSrYDW1BUPgz0lMd5XMVaBZYLRRZy1fFbmxlVtU0dqNgVMyMMErVotmmg= 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=M4Z8ILe+; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Nz7Ddn6N; 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="M4Z8ILe+"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Nz7Ddn6N" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490114; 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=hsz4Yb9WaP0J2d/ovLyM+GlU9a8IJXiQXaVWXPUNWME=; b=M4Z8ILe+2JehaQMrKLRJkERLRIaVSFWmZTC3wPZhe22StUzxrJY3IVqLYA3gdk3aPUwgx1 ThHgoaV+NKDh8nLTm7XJk7aH2I0KBDmYcVj3zC/inVVwfqcP0zng7ZLf1x7VlfHPJ69w8k kvu1OFWcOg4R1vSEFCXAEJX9axu5zUQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-mF06cxbJPbSUlO0m3ogUmA-1; Mon, 11 May 2026 05:01:52 -0400 X-MC-Unique: mF06cxbJPbSUlO0m3ogUmA-1 X-Mimecast-MFC-AGG-ID: mF06cxbJPbSUlO0m3ogUmA_1778490111 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48a5952c635so46889385e9.2 for ; Mon, 11 May 2026 02:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490111; x=1779094911; 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=hsz4Yb9WaP0J2d/ovLyM+GlU9a8IJXiQXaVWXPUNWME=; b=Nz7Ddn6NIgZVYSGFV3o3lcVsoZRvUFNB0np6hNhOiy0hXXooRF5WGKgzDf+rk5MkiJ Mwc3vjrGtyVFrXvvLFrBjSPQxI1lQLv8wyuvW6uLd6seknXfG6k74mDOijdJqUc2BtX8 +opbaWR2C8OwZSIZC1CV8HwnLNDcgWDOtP5qAh3Z8wU5qgodMTKEKgEI8OjWuS0Rt40A DCVMkH4gyim6+RyU9cVH0B/zUqd9v6b3QL5ZaVYMqkNr3HagExKweGyYqxNm1CPrD0RQ tIKGdweIY/zA7lsiMhRqAbKlPf1i5pkQFUb0HYwaU8yztzuHiqqbU8OSnO/jzXNkmmTK /X3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490111; x=1779094911; 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=hsz4Yb9WaP0J2d/ovLyM+GlU9a8IJXiQXaVWXPUNWME=; b=iQf8RYmDScnmMpSXMei0eCdLELTwRaV59lcOyZkt2Tp1tsGgR2nMlPzlBkuGrItA6W l8Wv+BzZem4VsgW+JNvW5Ur9GKoIRVYPqGnAo/CtikHW9qQsqIvT2OTkmr2F14nIV/YM 4Dz4j329Oj/oWpxxAV7T2m5BsgtmN1LLKkWUucscthuDPSL6/FOiTpegXsBd1NjPhAT1 BbvoQhKshWzfoc2WUnnfbeWqa0p8bC0B5tMwA9NqC0FqZBU66z/6at4bXCn1OgCSID3X wzaHU3+d34t2EAE+uYV7/p5lX99EPFKY/HK4AnFI1i3EFAlfnejuWxMeybMVzezrKP8u Ptcg== X-Gm-Message-State: AOJu0Yzmo3NXHmmLEq7pYy6l9sEDIV5sGDlcm8q5ld+HxwTH8BS2p5nM VKS94ysuemxiFZ2V9eI1iyTrhlWR509qcYwrdDjmVK9ArcipOKvEF8ajuqe/4DY2auqXpqUdWEY mzmogNx9cnJHj2+e87yYjMM5Aoc2XhMs0YyMY0G0hA+FXNYwo+x7cuD8MRPftnYE+oOS+qzbl5l uVz0GCfbxjBoV30ptmJjkAw0OfIONk/pSdu3+m8QW8ITI= X-Gm-Gg: Acq92OFsO9bSunAz4pHjKmhVOH7YnPQnCPs7IBByaDlQMdmBU8Zyzg8LUAf/W8TCDkn fj/pfG7yZq0g2YEce89enJVZwsp7m11zRLs2ZNyiz6JZNcpg+/qojdzclwfw/1O2VyihQm+MiGW vmN7xSYLvRjU7Nbwt+RdniRvuk8h8L8iZ18rMCsieA/zTfP0FpmUc6LA7Exrbz7KXxLWT1qTIEj JhSMBsI0kpatznrio8bqOHfchYsbGUpzNkrlpuqBnYqU+381zOG+IPFHVZEwW38ZBiYWgMvSU3J 59pwhwgX7gUF8hOmc3ItGtHjrq2QAQ5/m3DfWGRijFWin3anO4r5KE/VJVTA/k6pgkG1RK613+d 4bjS+6eTkPwuoa4RRBaF3dkDNSdI3STVRa4m77v8FKmmJMRzW6Cc= X-Received: by 2002:a05:600c:46d2:b0:485:364e:9328 with SMTP id 5b1f17b1804b1-48e51f32aebmr335187425e9.16.1778490110263; Mon, 11 May 2026 02:01:50 -0700 (PDT) X-Received: by 2002:a05:600c:46d2:b0:485:364e:9328 with SMTP id 5b1f17b1804b1-48e51f32aebmr335186515e9.16.1778490109502; Mon, 11 May 2026 02:01:49 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e80ca2666sm91504845e9.10.2026.05.11.02.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:01:49 -0700 (PDT) Date: Mon, 11 May 2026 05:01:44 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 01/30] mm: move vma_alloc_folio_noprof to page_alloc.c Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move vma_alloc_folio_noprof() from an inline in gfp.h (for !NUMA) and mempolicy.c (for NUMA) to page_alloc.c. This prepares for a subsequent patch that will thread user_addr through the allocator: having vma_alloc_folio_noprof in page_alloc.c means user_addr can be passed to the internal allocation path without changing public API signatures or duplicating plumbing in both gfp.h and mempolicy.c. The !NUMA path gains the VM_DROPPABLE -> __GFP_NOWARN check that the NUMA path already had. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/gfp.h | 9 ++------- mm/mempolicy.c | 32 -------------------------------- mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 51ef13ed756e..7ccbda35b9ad 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -318,13 +318,13 @@ static inline struct page *alloc_pages_node_noprof(in= t nid, gfp_t gfp_mask, =20 #define alloc_pages_node(...) alloc_hooks(alloc_pages_node_noprof(__VA_= ARGS__)) =20 +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr); #ifdef CONFIG_NUMA struct page *alloc_pages_noprof(gfp_t gfp, unsigned int order); struct folio *folio_alloc_noprof(gfp_t gfp, unsigned int order); struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, struct mempolicy *mpol, pgoff_t ilx, int nid); -struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_= struct *vma, - unsigned long addr); #else static inline struct page *alloc_pages_noprof(gfp_t gfp_mask, unsigned int= order) { @@ -339,11 +339,6 @@ static inline struct folio *folio_alloc_mpol_noprof(gf= p_t gfp, unsigned int orde { return folio_alloc_noprof(gfp, order); } -static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, - struct vm_area_struct *vma, unsigned long addr) -{ - return folio_alloc_noprof(gfp, order); -} #endif =20 #define alloc_pages(...) alloc_hooks(alloc_pages_noprof(__VA_ARGS__)) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4e4421b22b59..6832cc68120f 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2515,38 +2515,6 @@ struct folio *folio_alloc_mpol_noprof(gfp_t gfp, uns= igned int order, return page_rmappable_folio(page); } =20 -/** - * vma_alloc_folio - Allocate a folio for a VMA. - * @gfp: GFP flags. - * @order: Order of the folio. - * @vma: Pointer to VMA. - * @addr: Virtual address of the allocation. Must be inside @vma. - * - * Allocate a folio for a specific address in @vma, using the appropriate - * NUMA policy. The caller must hold the mmap_lock of the mm_struct of the - * VMA to prevent it from going away. Should be used for all allocations - * for folios that will be mapped into user space, excepting hugetlbfs, and - * excepting where direct use of folio_alloc_mpol() is more appropriate. - * - * Return: The folio on success or NULL if allocation fails. - */ -struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_= struct *vma, - unsigned long addr) -{ - struct mempolicy *pol; - pgoff_t ilx; - struct folio *folio; - - if (vma->vm_flags & VM_DROPPABLE) - gfp |=3D __GFP_NOWARN; - - pol =3D get_vma_policy(vma, addr, order, &ilx); - folio =3D folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); - mpol_cond_put(pol); - return folio; -} -EXPORT_SYMBOL(vma_alloc_folio_noprof); - struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned order) { struct mempolicy *pol =3D &default_policy; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 227d58dc3de6..fc7327ebdf6c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5273,6 +5273,49 @@ struct folio *__folio_alloc_noprof(gfp_t gfp, unsign= ed int order, int preferred_ } EXPORT_SYMBOL(__folio_alloc_noprof); =20 +#ifdef CONFIG_NUMA +/** + * vma_alloc_folio - Allocate a folio for a VMA. + * @gfp: GFP flags. + * @order: Order of the folio. + * @vma: Pointer to VMA. + * @addr: Virtual address of the allocation. Must be inside @vma. + * + * Allocate a folio for a specific address in @vma, using the appropriate + * NUMA policy. The caller must hold the mmap_lock of the mm_struct of the + * VMA to prevent it from going away. Should be used for all allocations + * for folios that will be mapped into user space, excepting hugetlbfs, and + * excepting where direct use of folio_alloc_mpol() is more appropriate. + * + * Return: The folio on success or NULL if allocation fails. + */ +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr) +{ + struct mempolicy *pol; + pgoff_t ilx; + struct folio *folio; + + if (vma->vm_flags & VM_DROPPABLE) + gfp |=3D __GFP_NOWARN; + + pol =3D get_vma_policy(vma, addr, order, &ilx); + folio =3D folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); + mpol_cond_put(pol); + return folio; +} +#else +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr) +{ + if (vma->vm_flags & VM_DROPPABLE) + gfp |=3D __GFP_NOWARN; + + return folio_alloc_noprof(gfp, order); +} +#endif +EXPORT_SYMBOL(vma_alloc_folio_noprof); + /* * Common helper functions. Never use with __GFP_HIGHMEM because the retur= ned * address cannot represent highmem pages. Use alloc_pages and then kmap if --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 DD7EF3BE651 for ; Mon, 11 May 2026 09:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490122; cv=none; b=m4kTDgpcIgIefCW5HM2DMGh/NR4vHG9Ji+4k4HZ+xTGlzJi8kbh2dzIjzDRyeyeqO54u64Rb7tfW/OxZmCXq/mB64MqhFXQmGdyTYdtBNdWD/SF/a37PDPs9YdifI1w+nGuY7Sn9SjBIGzA/ryYYzUkU40sTYgYGudMH8qYl2kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490122; c=relaxed/simple; bh=1Vb7u84GjOzr+CW7azCqmocyWDL053FJeunJoBfC3h8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZAys4Ha/gBAe4ZtOMqKbDx7pi+Jnp5gZSQawfVo1KZLUc2MezneHTMtuEvN+YPxyJAjUi9Wf1Gok6U86+2ibuSYH9DVV7n5mbIFY6m/98YFqqAOV/q9l6luhO1KPos8DoUiSWvCulpUC5p715UiEUOLupYGNKIW5mtdhsLr2HJ8= 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=h3gf+3j3; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tkGxKBRr; arc=none smtp.client-ip=170.10.129.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="h3gf+3j3"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tkGxKBRr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490120; 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=9tuOG0LtkLDTSKD1+Re+ayATul75v5uc/Qit0qQeEcQ=; b=h3gf+3j3t9iTeH8CiVQCyFWMcdYU6hXBJTVR1ldaq8EkEaQacuLPGkcVpjj2WWITc0oPIm vNUh4/xzznH8fdzhJS3MoZyWpYIvsUSqP8BuOPpP55FAsXzY2f6tvY1v5XljWhlxp39cHL LxUee7PAlhFpDzpFIRGaf76Eojg7hAE= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-8zl6S4CNPkmHs0n1mW3A4Q-1; Mon, 11 May 2026 05:01:57 -0400 X-MC-Unique: 8zl6S4CNPkmHs0n1mW3A4Q-1 X-Mimecast-MFC-AGG-ID: 8zl6S4CNPkmHs0n1mW3A4Q_1778490116 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488dcaf2f2fso31830035e9.0 for ; Mon, 11 May 2026 02:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490116; x=1779094916; 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=9tuOG0LtkLDTSKD1+Re+ayATul75v5uc/Qit0qQeEcQ=; b=tkGxKBRrldkVD8L4KbXo0Ysu9HkKxeKVcOFfR5Gc73XSJZRu2dERisN/23fCEYXUAs Oit1IfON4VMyQZMYrJlt/lM6yMWICtrpruam529k8kBsfzVaYJ7c7WZgHqBSnGSNV9RZ ZYbfde6staPltKQfdkxgaYy7B9hRHaLovosha4JG83Wd6v3t4ZfPcQ87SBgutjSvd0Yu Pa91kQ1Nyt7L1rma4TUDnOeY0xu6IwZcj4L5GImiCjE6rJtNqeU31ZFGpuuyA4giNNgw urN0y7HuNv4rElImtyvp/lDf9nr3w48itf12HzKoYDC98jA2r90qTa6JFD1Jm7Wx0XFx DxhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490116; x=1779094916; 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=9tuOG0LtkLDTSKD1+Re+ayATul75v5uc/Qit0qQeEcQ=; b=NnK92aOVT4PR6iCXwoEBvfTUR6rLtmgum0LXx9o3eY1Q/h/SADP9QUVe0y6Hu2Lok/ G/ZtGjkK8JTbm/zOP1GeZDd9hGYdm0noxc53M0OFbiaP5+n8B4/EoDoYvH9evtM2dYkz heLa2mwyDwrZDwO7U5LW+p3yaDkDsRt/qgECJJYlpRRIaYaGYY1329buXguRoulsdT+j X4FT8P8oTHiDNS9Pei5l8VsJ+ulHsPpVYeQ5bzerxlvBl8rIkYyGz5j44Trpd6ntuS1X i+EVaxLWJ8wL0JerwnC8yk4T+UAW91IywgQKVeEaT0n+zhM6K9tLY/yQ3ZD1B3QcueOl wAdg== X-Gm-Message-State: AOJu0YwjYcB6e6lzO6VcBhk2Z3FMlR6+G26S3u2aSyXriJC+QySUh2nD oCxe3VDqgXwaxvFGBROJJf5ol0y5VPQKiJ5joiY8/fB0R6adXcLRPC8HtVAhaOLeu6/wZf0B8fp tIGrH/qpfKzW3tXeLRqdLH04eYhBQCLbdrPKKXpjVxCalrI3HuXmbHI9QMGE03Jj5mftaeSuDtb 5o+l0ljhZndianyMwKFsJDp5PX/Nwlzw5BHTjbWdR45LM= X-Gm-Gg: Acq92OE5AhFih4IZMbuPi/JCDqN3hvTteaeQjumni9g9+WbT4fMlrxCdSXHcatm3+Jw 3eXWIBLh0FVbF8/bLnljO7kdJZnGLZP2smF23jiXcnVINhu7T5htKQkxwcceiYL9fB3ACzskuIS ofemc5awXFXHL9S26FU9nwds466ay4faTQ3TNuau9MSVwL5+2l7iedi4DSpcTKOnfeIle8DjtHV ckVySfyalwRRkxNkpGjXaHI2xMGOnIDlQwTnOeB6HRALI0O6fqAFQSp3IC49scj6rEBl7DFCT0C +Pk+yN3zUSRIAvfqpbCBRePA3UtubwAlHTGSie5DETr4OxVZ0Ck21NqLKag8zH9OGfeiLjZH0au 0qtxPGonABoCjBRNoV+TLyqUq+W6Ov+YJHTVx9MzE X-Received: by 2002:a05:600c:c096:b0:48a:f18:ece4 with SMTP id 5b1f17b1804b1-48e51f50982mr286077255e9.24.1778490115933; Mon, 11 May 2026 02:01:55 -0700 (PDT) X-Received: by 2002:a05:600c:c096:b0:48a:f18:ece4 with SMTP id 5b1f17b1804b1-48e51f50982mr286076135e9.24.1778490114930; Mon, 11 May 2026 02:01:54 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6d895781sm104480065e9.0.2026.05.11.02.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:01:54 -0700 (PDT) Date: Mon, 11 May 2026 05:01:49 -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 resend v6 02/30] mm: mempolicy: fix interleave index for unaligned VMA start Message-ID: <41bd50fdaae943e1a79215ea4000322e74a823be.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The NUMA interleave index formula (addr - vm_start) >> shift gives wrong results when vm_start is not aligned to the folio size: the subtraction before the shift allows low bits to affect the result via borrows. Use (addr >> shift) - (vm_start >> shift) instead, which independently aligns both values before computing the difference. No functional change for current callers: the fix only affects NUMA interleave and weighted-interleave policies. Current large-order callers either pre-align the address (vma_alloc_anon_folio_pmd) or do not use NUMA interleave (drm_pagemap). All other callers use order 0 where the old and new formulas are equivalent. However subsequent patches in this series add large-order callers that pass unaligned fault addresses, making this fix necessary. Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price --- mm/mempolicy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 6832cc68120f..39e556e3d263 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2049,7 +2049,8 @@ struct mempolicy *get_vma_policy(struct vm_area_struc= t *vma, if (pol->mode =3D=3D MPOL_INTERLEAVE || pol->mode =3D=3D MPOL_WEIGHTED_INTERLEAVE) { *ilx +=3D vma->vm_pgoff >> order; - *ilx +=3D (addr - vma->vm_start) >> (PAGE_SHIFT + order); + *ilx +=3D (addr >> (PAGE_SHIFT + order)) - + (vma->vm_start >> (PAGE_SHIFT + order)); } return pol; } --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 CCAA93BED79 for ; Mon, 11 May 2026 09:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490129; cv=none; b=RcEuMFTLJJd8VIJGnjoc+VHPfJ4eCbuBbbWQK2mOJcn1n+L2Nl0uW3xaOQaiqoyk5LFZb3KL3fwFT0q03a7pBCcWM9RTT4IkEOWaBmOCN9IVgCMjIE4KnrzcT8if3ErKqO1DmK8RC6PK9b7cZ5qwE0OPeKWsN0zUi5muzBWVle4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490129; c=relaxed/simple; bh=Jkr7UMBO7bIZsD5XCAT0VxRRbICq9gXj/SQ971DUFx0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bi2NerhK4H13vUUBGRRjPnLk2z2JnfltJxW3VU4Axvda4Lo9DvA4pAWxip9gJoO6fr27dxpV11hENgIYoB6sMQxe7QkOXvGTA6LfjxNIWDBj1Rtikdts5WZe9zsBiafCu4tTfozLkftw3C8Bc+16N9FSuE0w7TW+hi6eKm4kr2A= 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=I4bUcIXY; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=pM+LELcb; arc=none smtp.client-ip=170.10.129.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="I4bUcIXY"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="pM+LELcb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490126; 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=dWkU+3Xsu4f368D1B49V88gxG3ITHAQNLuQBUMIkCCw=; b=I4bUcIXYC2a03I8mDXE3QBYFWs0aF2Vvhbp+gCtYXfFyvoXHOolWSyuJLDKJxRId65hi/W Vhs/hPllQQYjR5GNb3680zs+L4wAVcAYQepkJIRxNkSQZz9d/nCyfNG6yNWAX6nXOVVc0G 2Sde8qu2Ne6lch9O253IXcvk48WG15Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-197-wXydnkX8OCSWCW17Q_eFYQ-1; Mon, 11 May 2026 05:02:05 -0400 X-MC-Unique: wXydnkX8OCSWCW17Q_eFYQ-1 X-Mimecast-MFC-AGG-ID: wXydnkX8OCSWCW17Q_eFYQ_1778490124 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48e6af7a9cdso16463315e9.3 for ; Mon, 11 May 2026 02:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490124; x=1779094924; 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=dWkU+3Xsu4f368D1B49V88gxG3ITHAQNLuQBUMIkCCw=; b=pM+LELcb0q+BqqfEy7BzE3OwQpn+Fdm9MJZHKfDPyyNM33Ef5YDrUtY/RENnmRp7YZ rIDqDAFaDwRdlsM+YdsxnJjmaIZX6Idb1APhuEDwNZRCUTCQmbAKjgUaRPdG6Luyh8Zb YYWCCrcQKT82exz2/9kJjJnZtlV3NPEuTSl1mJtI3Jeeijbnvv7jKp/gJ76wAm/fV0ec QgN3gE1I7qCAAKsf6+BUxhrFpRu20B9s2SeRofO2Z5W9M+X9lcYrqxMLDKbUf6C4+N+L TMWl/pwGqh38a2472TjAvYRNiG4g8VDC5LPVq0+yKruN+KAvbcAZaa4ovHazcZbPB4XW fYWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490124; x=1779094924; 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=dWkU+3Xsu4f368D1B49V88gxG3ITHAQNLuQBUMIkCCw=; b=KiFFLcWXPtkeHB/PuaTYboszrlWSMeX1Tu3DenRcuiVN2WnXEDIaqmJ5O/bu7VKUNU 5HXaZf2ioJx3u9lXnoFAkchpgtQku1q7GAeNJneibO1ejaHt8JV8duZIUmA6uUZtvUu8 MhxzUAC91dB1RfEB5EdBouywZ77QlG3Zu+CCskz0dlMGs6zl5AsQW8KrD7SHg+m6S3mw BZiExzuIe7EjkwG6dKdnx1MXFKU6TNlxefwuB3OzMeTWRdd+/rfTJC8UHmkEiO7xbbGW J1+x18V+3OVvTCWXb4/8q4JjbUo2RzcKBrK6evYkBZieJxxPXdLmIsupO3pLyaotCyRx bG3Q== X-Gm-Message-State: AOJu0Yx1iqgyXadoF1n62dS1mOQ+l7BdHa8+5E2P5asMWMKnG2D405VF dJBlGIYxlNVDy2udEi9a1LZhBGo9i+h1pWXfNk1tBQIW3s+kW94WtHdxo5PP1MrHA0x3RtTfhSn +RswJlCqIyj69qj8oRJrlf+5ZHmbeI+A3DEzIXSrXdC86lqWzE1yYq94FQB5FIuH9VVeN24RB9D Bj6Icc1tYZOUiHul00KAFfj0wHm48fGqICaOPlIgo5DfXBjw== X-Gm-Gg: Acq92OEpigUk95Wp8JyhwO8xghqIP2Ti1qbE5vDTWvXFZhmEsBRbV1eIq2tYQp1RtsU TlwCtCnSQW+BbtCBndmRluY4vDnQuQ8mgbrGzDv7TNh5dt5vn3TGkqr7OUMJnRuwSx+PnFqx9ME bXD3cGVnS2TUhYkmnuSS5263cpRVw1SjgyIUkJbR7gdaYVyF/hjtslNmA/HnG6xb6uvTWjtVf9f f8cdIR7ccwVoWnngt7zhIOP3dKWkMFNlf6PCrOKlOrolbAR+i0jTSyfaLDn+0dOWWqt83eLaegp N0pZavM+g9zmIlZn6osMTX2zfOpsOleYkKtaS3f8dvxhmjp1DoxlxR+4r8bk8wVJa+KinfEfqb1 hbrN+omIIb1eAqc1YF8lP5SNHrXUlwGsa5ntVv88/ X-Received: by 2002:a05:600c:2d15:b0:485:9a50:3370 with SMTP id 5b1f17b1804b1-48e51e16d0bmr221514115e9.8.1778490122154; Mon, 11 May 2026 02:02:02 -0700 (PDT) X-Received: by 2002:a05:600c:2d15:b0:485:9a50:3370 with SMTP id 5b1f17b1804b1-48e51e16d0bmr221513045e9.8.1778490120929; Mon, 11 May 2026 02:02:00 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6daf039esm83608395e9.3.2026.05.11.02.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:00 -0700 (PDT) Date: Mon, 11 May 2026 05:01:55 -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 , "Liam R. Howlett" , Harry Yoo , Hao Li Subject: [PATCH resend v6 03/30] mm: thread user_addr through page allocator for cache-friendly zeroing Message-ID: <9b53972f4854c1064b92cefc464f51949afeb83f.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 USER_ADDR_NONE ((unsigned long)-1) is used for non-user allocations, since address 0 is a valid userspace mapping. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/gfp.h | 2 +- mm/compaction.c | 5 ++--- mm/hugetlb.c | 36 ++++++++++++++++++++---------------- mm/internal.h | 18 +++++++++++++++--- mm/mempolicy.c | 44 ++++++++++++++++++++++++++++++++------------ mm/page_alloc.c | 44 +++++++++++++++++++++++++++++--------------- mm/slub.c | 4 ++-- 7 files changed, 101 insertions(+), 52 deletions(-) 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 gf= p, unsigned int order) static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned in= t 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 =20 diff --git a/mm/compaction.c b/mm/compaction.c index 3648ce22c807..72684fe81e83 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -82,7 +82,7 @@ static inline bool is_via_compact_memory(int order) { ret= urn false; } =20 static struct page *mark_allocated_noprof(struct page *page, unsigned int = order, gfp_t gfp_flags) { - post_alloc_hook(page, order, __GFP_MOVABLE); + post_alloc_hook(page, order, __GFP_MOVABLE, USER_ADDR_NONE); set_page_refcounted(page); return page; } @@ -1849,8 +1849,7 @@ static struct folio *compaction_alloc_noprof(struct f= olio *src, unsigned long da set_page_private(&freepage[size], start_order); } dst =3D (struct folio *)freepage; - - post_alloc_hook(&dst->page, order, __GFP_MOVABLE); + post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); set_page_refcounted(&dst->page); if (order) prep_compound_page(&dst->page, order); 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_writ= e(struct folio *folio) } =20 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) { struct folio *folio; bool alloc_try_hard =3D true; @@ -1823,7 +1824,7 @@ static struct folio *alloc_buddy_frozen_folio(int ord= er, gfp_t gfp_mask, if (alloc_try_hard) gfp_mask |=3D __GFP_RETRY_MAYFAIL; =20 - folio =3D (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmas= k); + folio =3D (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmas= k, addr); =20 /* * If we did not specify __GFP_RETRY_MAYFAIL, but still got a @@ -1852,7 +1853,7 @@ static struct folio *alloc_buddy_frozen_folio(int ord= er, gfp_t gfp_mask, =20 static struct folio *only_alloc_fresh_hugetlb_folio(struct hstate *h, gfp_t gfp_mask, int nid, nodemask_t *nmask, - nodemask_t *node_alloc_noretry) + nodemask_t *node_alloc_noretry, unsigned long addr) { struct folio *folio; int order =3D huge_page_order(h); @@ -1864,7 +1865,7 @@ static struct folio *only_alloc_fresh_hugetlb_folio(s= truct hstate *h, folio =3D alloc_gigantic_frozen_folio(order, gfp_mask, nid, nmask); else folio =3D alloc_buddy_frozen_folio(order, gfp_mask, nid, nmask, - node_alloc_noretry); + node_alloc_noretry, addr); if (folio) init_new_hugetlb_folio(folio); return folio; @@ -1878,11 +1879,12 @@ static struct folio *only_alloc_fresh_hugetlb_folio= (struct hstate *h, * pages is zero, and the accounting must be done in the caller. */ static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, - gfp_t gfp_mask, int nid, nodemask_t *nmask) + gfp_t gfp_mask, int nid, nodemask_t *nmask, + unsigned long addr) { struct folio *folio; =20 - folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL); + folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL, a= ddr); if (folio) hugetlb_vmemmap_optimize_folio(h, folio); return folio; @@ -1922,7 +1924,7 @@ static struct folio *alloc_pool_huge_folio(struct hst= ate *h, struct folio *folio; =20 folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, node, - nodes_allowed, node_alloc_noretry); + nodes_allowed, node_alloc_noretry, USER_ADDR_NONE); if (folio) return folio; } @@ -2091,7 +2093,8 @@ int dissolve_free_hugetlb_folios(unsigned long start_= pfn, unsigned long end_pfn) * Allocates a fresh surplus page from the page allocator. */ static struct folio *alloc_surplus_hugetlb_folio(struct hstate *h, - gfp_t gfp_mask, int nid, nodemask_t *nmask) + gfp_t gfp_mask, int nid, nodemask_t *nmask, + unsigned long addr) { struct folio *folio =3D NULL; =20 @@ -2103,7 +2106,7 @@ static struct folio *alloc_surplus_hugetlb_folio(stru= ct hstate *h, goto out_unlock; spin_unlock_irq(&hugetlb_lock); =20 - folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask); + folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, addr); if (!folio) return NULL; =20 @@ -2146,7 +2149,7 @@ static struct folio *alloc_migrate_hugetlb_folio(stru= ct hstate *h, gfp_t gfp_mas if (hstate_is_gigantic(h)) return NULL; =20 - folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask); + folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, USER_ADDR_NO= NE); if (!folio) return NULL; =20 @@ -2182,14 +2185,14 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(s= truct hstate *h, if (mpol_is_preferred_many(mpol)) { gfp_t gfp =3D gfp_mask & ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); =20 - folio =3D alloc_surplus_hugetlb_folio(h, gfp, nid, nodemask); + folio =3D alloc_surplus_hugetlb_folio(h, gfp, nid, nodemask, addr); =20 /* Fallback to all nodes if page=3D=3DNULL */ nodemask =3D NULL; } =20 if (!folio) - folio =3D alloc_surplus_hugetlb_folio(h, gfp_mask, nid, nodemask); + folio =3D alloc_surplus_hugetlb_folio(h, gfp_mask, nid, nodemask, addr); mpol_cond_put(mpol); return folio; } @@ -2296,7 +2299,8 @@ static int gather_surplus_pages(struct hstate *h, lon= g delta) * down the road to pick the current node if that is the case. */ folio =3D alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h), - NUMA_NO_NODE, &alloc_nodemask); + NUMA_NO_NODE, &alloc_nodemask, + USER_ADDR_NONE); if (!folio) { alloc_ok =3D false; break; @@ -2702,7 +2706,7 @@ static int alloc_and_dissolve_hugetlb_folio(struct fo= lio *old_folio, spin_unlock_irq(&hugetlb_lock); gfp_mask =3D htlb_alloc_mask(h) | __GFP_THISNODE; new_folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, - nid, NULL); + nid, NULL, USER_ADDR_NONE); if (!new_folio) return -ENOMEM; goto retry; @@ -3400,13 +3404,13 @@ static void __init hugetlb_hstate_alloc_pages_oneno= de(struct hstate *h, int nid) gfp_t gfp_mask =3D htlb_alloc_mask(h) | __GFP_THISNODE; =20 folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, - &node_states[N_MEMORY], NULL); + &node_states[N_MEMORY], NULL, USER_ADDR_NONE); if (!folio && !list_empty(&folio_list) && hugetlb_vmemmap_optimizable_size(h)) { prep_and_add_allocated_folios(h, &folio_list); INIT_LIST_HEAD(&folio_list); folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, - &node_states[N_MEMORY], NULL); + &node_states[N_MEMORY], NULL, USER_ADDR_NONE); } if (!folio) break; diff --git a/mm/internal.h b/mm/internal.h index 5a2ddcf68e0b..751ae8911607 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -662,6 +662,12 @@ void calculate_min_free_kbytes(void); int __meminit init_per_zone_wmark_min(void); void page_alloc_sysctl_init(void); =20 +/* + * 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) + /* * Structure for holding the mostly immutable allocation parameters passed * between functions involved in allocations, including the alloc_pages* @@ -693,6 +699,7 @@ struct alloc_context { */ enum zone_type highest_zoneidx; bool spread_dirty_pages; + unsigned long user_addr; }; =20 /* @@ -916,24 +923,29 @@ static inline void init_compound_tail(struct page *ta= il, prep_compound_tail(tail, head, order); } =20 -void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flag= s); +void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flag= s, + unsigned long user_addr); extern bool free_pages_prepare(struct page *page, unsigned int order); =20 extern int user_min_free_kbytes; =20 struct page *__alloc_frozen_pages_noprof(gfp_t, unsigned int order, int ni= d, - nodemask_t *); + nodemask_t *, unsigned long user_addr); #define __alloc_frozen_pages(...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__)) void free_frozen_pages(struct page *page, unsigned int order); +void free_frozen_pages_zeroed(struct page *page, unsigned int order); void free_unref_folios(struct folio_batch *fbatch); =20 #ifdef CONFIG_NUMA struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order); +struct folio *folio_alloc_mpol_user_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid, + unsigned long user_addr); #else static inline struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned i= nt order) { - return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL); + return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL, USER= _ADDR_NONE); } #endif =20 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 39e556e3d263..ea3043e0075b 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2413,7 +2413,8 @@ bool mempolicy_in_oom_domain(struct task_struct *tsk, } =20 static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int ord= er, - int nid, nodemask_t *nodemask) + int nid, nodemask_t *nodemask, + unsigned long user_addr) { struct page *page; gfp_t preferred_gfp; @@ -2426,25 +2427,29 @@ static struct page *alloc_pages_preferred_many(gfp_= t gfp, unsigned int order, */ preferred_gfp =3D gfp | __GFP_NOWARN; preferred_gfp &=3D ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); - page =3D __alloc_frozen_pages_noprof(preferred_gfp, order, nid, nodemask); + page =3D __alloc_frozen_pages_noprof(preferred_gfp, order, nid, + nodemask, user_addr); if (!page) - page =3D __alloc_frozen_pages_noprof(gfp, order, nid, NULL); + page =3D __alloc_frozen_pages_noprof(gfp, order, nid, NULL, + user_addr); =20 return page; } =20 /** - * alloc_pages_mpol - Allocate pages according to NUMA mempolicy. + * __alloc_pages_mpol - Allocate pages according to NUMA mempolicy. * @gfp: GFP flags. * @order: Order of the page allocation. * @pol: Pointer to the NUMA mempolicy. * @ilx: Index for interleave mempolicy (also distinguishes alloc_pages()). * @nid: Preferred node (usually numa_node_id() but @mpol may override it). + * @user_addr: User fault address for cache-friendly zeroing, or USER_ADDR= _NONE. * * Return: The page on success or NULL if allocation fails. */ -static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order, - struct mempolicy *pol, pgoff_t ilx, int nid) +static struct page *__alloc_pages_mpol(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid, + unsigned long user_addr) { nodemask_t *nodemask; struct page *page; @@ -2452,7 +2457,8 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, nodemask =3D policy_nodemask(gfp, pol, ilx, &nid); =20 if (pol->mode =3D=3D MPOL_PREFERRED_MANY) - return alloc_pages_preferred_many(gfp, order, nid, nodemask); + return alloc_pages_preferred_many(gfp, order, nid, nodemask, + user_addr); =20 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && /* filter "hugepage" allocation, unless from alloc_pages() */ @@ -2476,7 +2482,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, */ page =3D __alloc_frozen_pages_noprof( gfp | __GFP_THISNODE | __GFP_NORETRY, order, - nid, NULL); + nid, NULL, user_addr); if (page || !(gfp & __GFP_DIRECT_RECLAIM)) return page; /* @@ -2488,7 +2494,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, } } =20 - page =3D __alloc_frozen_pages_noprof(gfp, order, nid, nodemask); + page =3D __alloc_frozen_pages_noprof(gfp, order, nid, nodemask, user_addr= ); =20 if (unlikely(pol->mode =3D=3D MPOL_INTERLEAVE || pol->mode =3D=3D MPOL_WEIGHTED_INTERLEAVE) && page) { @@ -2504,11 +2510,18 @@ static struct page *alloc_pages_mpol(gfp_t gfp, uns= igned int order, return page; } =20 -struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, +static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order, struct mempolicy *pol, pgoff_t ilx, int nid) { - struct page *page =3D alloc_pages_mpol(gfp | __GFP_COMP, order, pol, - ilx, nid); + return __alloc_pages_mpol(gfp, order, pol, ilx, nid, USER_ADDR_NONE); +} + +struct folio *folio_alloc_mpol_user_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid, + unsigned long user_addr) +{ + struct page *page =3D __alloc_pages_mpol(gfp | __GFP_COMP, order, pol, + ilx, nid, user_addr); if (!page) return NULL; =20 @@ -2516,6 +2529,13 @@ struct folio *folio_alloc_mpol_noprof(gfp_t gfp, uns= igned int order, return page_rmappable_folio(page); } =20 +struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid) +{ + return folio_alloc_mpol_user_noprof(gfp, order, pol, ilx, nid, + USER_ADDR_NONE); +} + struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned order) { struct mempolicy *pol =3D &default_policy; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fc7327ebdf6c..c3c0f4e2baa7 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1806,7 +1806,7 @@ static inline bool should_skip_init(gfp_t flags) } =20 inline void post_alloc_hook(struct page *page, unsigned int order, - gfp_t gfp_flags) + gfp_t gfp_flags, unsigned long user_addr) { bool init =3D !want_init_on_free() && want_init_on_alloc(gfp_flags) && !should_skip_init(gfp_flags); @@ -1861,9 +1861,10 @@ inline void post_alloc_hook(struct page *page, unsig= ned int order, } =20 static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp= _flags, - unsigned int alloc_flags) + unsigned int alloc_flags, + unsigned long user_addr) { - post_alloc_hook(page, order, gfp_flags); + post_alloc_hook(page, order, gfp_flags, user_addr); =20 if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); @@ -3943,7 +3944,8 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int o= rder, int alloc_flags, page =3D rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, gfp_mask, alloc_flags, ac->migratetype); if (page) { - prep_new_page(page, order, gfp_mask, alloc_flags); + prep_new_page(page, order, gfp_mask, alloc_flags, + ac->user_addr); =20 return page; } else { @@ -4171,7 +4173,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned= int order, =20 /* Prep a captured page if available */ if (page) - prep_new_page(page, order, gfp_mask, alloc_flags); + prep_new_page(page, order, gfp_mask, alloc_flags, + ac->user_addr); =20 /* Try get a page from the freelist if available */ if (!page) @@ -5048,7 +5051,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, struct zoneref *z; struct per_cpu_pages *pcp; struct list_head *pcp_list; - struct alloc_context ac; + struct alloc_context ac =3D { .user_addr =3D USER_ADDR_NONE }; gfp_t alloc_gfp; unsigned int alloc_flags =3D ALLOC_WMARK_LOW; int nr_populated =3D 0, nr_account =3D 0; @@ -5163,7 +5166,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, } nr_account++; =20 - prep_new_page(page, 0, gfp, 0); + prep_new_page(page, 0, gfp, 0, USER_ADDR_NONE); set_page_refcounted(page); page_array[nr_populated++] =3D page; } @@ -5188,12 +5191,13 @@ EXPORT_SYMBOL_GPL(alloc_pages_bulk_noprof); * This is the 'heart' of the zoned buddy allocator. */ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, - int preferred_nid, nodemask_t *nodemask) + int preferred_nid, nodemask_t *nodemask, + unsigned long user_addr) { struct page *page; unsigned int alloc_flags =3D ALLOC_WMARK_LOW; gfp_t alloc_gfp; /* The gfp_t that was actually used for allocation */ - struct alloc_context ac =3D { }; + struct alloc_context ac =3D { .user_addr =3D user_addr }; =20 /* * There are several places where we assume that the order value is sane @@ -5254,10 +5258,12 @@ EXPORT_SYMBOL(__alloc_frozen_pages_noprof); =20 struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, int preferred_nid, nodemask_t *nodemask) + { struct page *page; =20 - page =3D __alloc_frozen_pages_noprof(gfp, order, preferred_nid, nodemask); + page =3D __alloc_frozen_pages_noprof(gfp, order, preferred_nid, + nodemask, USER_ADDR_NONE); if (page) set_page_refcounted(page); return page; @@ -5300,7 +5306,8 @@ struct folio *vma_alloc_folio_noprof(gfp_t gfp, int o= rder, gfp |=3D __GFP_NOWARN; =20 pol =3D get_vma_policy(vma, addr, order, &ilx); - folio =3D folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); + folio =3D folio_alloc_mpol_user_noprof(gfp, order, pol, ilx, + numa_node_id(), addr); mpol_cond_put(pol); return folio; } @@ -5308,10 +5315,17 @@ struct folio *vma_alloc_folio_noprof(gfp_t gfp, int= order, struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_struct *vma, unsigned long addr) { + struct page *page; + if (vma->vm_flags & VM_DROPPABLE) gfp |=3D __GFP_NOWARN; =20 - return folio_alloc_noprof(gfp, order); + page =3D __alloc_frozen_pages_noprof(gfp | __GFP_COMP, order, + numa_node_id(), NULL, addr); + if (!page) + return NULL; + set_page_refcounted(page); + return page_rmappable_folio(page); } #endif EXPORT_SYMBOL(vma_alloc_folio_noprof); @@ -6892,7 +6906,7 @@ static void split_free_frozen_pages(struct list_head = *list, gfp_t gfp_mask) list_for_each_entry_safe(page, next, &list[order], lru) { int i; =20 - post_alloc_hook(page, order, gfp_mask); + post_alloc_hook(page, order, gfp_mask, USER_ADDR_NONE); if (!order) continue; =20 @@ -7098,7 +7112,7 @@ int alloc_contig_frozen_range_noprof(unsigned long st= art, unsigned long end, struct page *head =3D pfn_to_page(start); =20 check_new_pages(head, order); - prep_new_page(head, order, gfp_mask, 0); + prep_new_page(head, order, gfp_mask, 0, USER_ADDR_NONE); } else { ret =3D -EINVAL; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n", @@ -7763,7 +7777,7 @@ struct page *alloc_frozen_pages_nolock_noprof(gfp_t g= fp_flags, int nid, unsigned gfp_t alloc_gfp =3D __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_= COMP | gfp_flags; unsigned int alloc_flags =3D ALLOC_TRYLOCK; - struct alloc_context ac =3D { }; + struct alloc_context ac =3D { .user_addr =3D USER_ADDR_NONE }; struct page *page; =20 VM_WARN_ON_ONCE(gfp_flags & ~__GFP_ACCOUNT); diff --git a/mm/slub.c b/mm/slub.c index 0baa906f39ab..74dd2d96941b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3275,7 +3275,7 @@ static inline struct slab *alloc_slab_page(gfp_t flag= s, int node, else if (node =3D=3D NUMA_NO_NODE) page =3D alloc_frozen_pages(flags, order); else - page =3D __alloc_frozen_pages(flags, order, node, NULL); + page =3D __alloc_frozen_pages(flags, order, node, NULL, USER_ADDR_NONE); =20 if (!page) return NULL; @@ -5235,7 +5235,7 @@ static void *___kmalloc_large_node(size_t size, gfp_t= flags, int node) if (node =3D=3D NUMA_NO_NODE) page =3D alloc_frozen_pages_noprof(flags, order); else - page =3D __alloc_frozen_pages_noprof(flags, order, node, NULL); + page =3D __alloc_frozen_pages_noprof(flags, order, node, NULL, USER_ADDR= _NONE); =20 if (page) { ptr =3D page_address(page); --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 3933A3C060C for ; Mon, 11 May 2026 09:02:16 +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=1778490138; cv=none; b=XpUmx0eo0F7pIeip7xnB8Mah8Hajb3jE1vqGEoHygcsQeTxPRCMW2OzphLiOGQzpVocEoNWA6UxVFt6O3wVlRo5a9BUoSVsXuGWusuENoLyIiSywlmlcM8q/LdSNXM71sTI57g45Plu6wGiSBh/j5h7J+RU1SbqsWOA54yCqWko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490138; c=relaxed/simple; bh=69QG+5KxbknuqowgRzIPAH0Udu09EBE3lvMvWnTXBmg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zv7ZNrt0Nz7q1pV4vUHdRm7Zd1Lc/HuReegV6D+ijj7Brz59La2yF1pONeoZGWq9WyeY3L+7DxaPe0Ho9X/c9UwrV89cy3dh8R52UI+/6IgmeVqp+GKKHAfB0TB4s9pUjS5qJMbdK/Njndt6h1rqhXd+MMdixY81WqCoYTBKJfU= 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=GudVkmr3; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=c4QnHudU; 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="GudVkmr3"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="c4QnHudU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490136; 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=6dawd7eS61o9/4A+PK33L87yl5/YoiTuIytB/tOyfis=; b=GudVkmr3UiTWoHuvwI2HONOJeA9VY6yxysofyJ/Xek7tSS9Q533ZG9D3BnOqtAuyNR7MAz lYCN+p0Uq2CeLxCuEjWu2U2/sTUtWCrWe7NcWc6Y+la8Dpb8W0I1ugZRTcp2Pr8n59vT3a bxIigbI7GDQ798Q8YKAJ+9z6TpNr7ds= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-546-UyP8Jy3wN1Cy6zPrDzDS9Q-1; Mon, 11 May 2026 05:02:13 -0400 X-MC-Unique: UyP8Jy3wN1Cy6zPrDzDS9Q-1 X-Mimecast-MFC-AGG-ID: UyP8Jy3wN1Cy6zPrDzDS9Q_1778490132 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-449dcfe8005so3841473f8f.3 for ; Mon, 11 May 2026 02:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490132; x=1779094932; 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=6dawd7eS61o9/4A+PK33L87yl5/YoiTuIytB/tOyfis=; b=c4QnHudUFURplqk9s7DuxSRIS/TjmPk8uKeR8dYvDCPYJ7I+N2gPU0SQXo4hpV/+FM CuSHyM7ZHpCKMVAY0PYCIsoUz6cKgM9ocr5u8Ezjl0HeUlAW5gqBRTqu+W/2s0wicsqL +ME9X+L6vqK029/WyXLil9p3tjn6xqn8KwJfEtxAlQ/NeLbJr0jtjp4vAvRsofhmecJp X3RpGdEwY3GJRfdSQguJRi8Kn9313jnncszyuQ6blrAY7r8eovfDX8rab7MJxYYm+G49 WIeLCHqF5snsjnWAh56AX7kVrYEfgLvSwqa7w870rtquhnYhnFohxwSX30v0GXvFML/W AADw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490132; x=1779094932; 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=6dawd7eS61o9/4A+PK33L87yl5/YoiTuIytB/tOyfis=; b=SeIw9uwH9ijrReBUvJbJM/+KnsygNKrUFOhb3mlEynaBpQPeCLLNskcpjH/ZUHgymK XNvSk3SHCf2oDIWrQqNaG6BTXbyUz6R8ASZD0ol8mHya4WPAL14nvL3BU5K9zNUvOKhK iQNITOBSpPAs+KlI6GhivXEnv4hDVF0gAJ79bzfSXFqp7b6KFI/nNc63xb85erGUUrAg LlFwqUszJr9zzXLBgqBbFO12sRzXw8ojt12xpLa5A2rKlVb3dYoOYgdG3+/vWTWhZ0hL EzkhfWEdFBJDl4zmShHCl0hSz45dr82xF333PqNxIDLTudbjcuGNmCuYPml1H45O0pN1 xLlA== X-Gm-Message-State: AOJu0Yz95z/wIJfrFLj2SPO1evWLXtmrGwz5Vqdm1BFXRSg1IBLL+qx8 aa8GCcdegOgkQ1LxrVq+YsA/UKdAe//7IVPZtz8JJEX76d/QovNzDO1lcMoZFotxlMkeuUrhWXy n5ZftXHRxJoXeTjjnwERfHVi7IwJbANeKBMLBv1eMpZ9uXTn9kvugp4IMvPpwfNRb8/JDxTdCJN e1FMZEwBPDOYzcPX5JrY3Ya5UHEpYdhO43JNljd2NUPA8= X-Gm-Gg: Acq92OGrli+G3CGqAzlD4c0eXIBKrVLgwQnpaAKm1z07fjHN7GJkP+4vrN84feg1FxW 9DSUDMz4f1w8o/B76kLNvGExV3XASq/VB4skJbjlWZICxJ3u42+SB56+rvs8fsJbANWhwoyORui SGNKXG4Z4Y70qheGne2x3S8hBT9IV+JkiqNl286rlXOwJDHWRrwAOYcgtMDa5GWeNOpbn6Gbmk3 4fAlfoH+yFTFcuGlKy+/dAUCY8u7d2VJVJObIZGYIZ5vVbI0XwXKJNHaWHUG6aZIDcOhlFq/GdD EpLrYKwMhGyL6Ga2cKM+8BP5VwFhn4LUkicSDsVSiCP7j6rSviYQoB8N0iOiRsJP1i1FCzgIRD1 ADMG1Fd6w3siFPNcMkdLQFH4v1O8ev+n03iXEayg2 X-Received: by 2002:a05:600c:4f51:b0:48d:1a94:56c with SMTP id 5b1f17b1804b1-48e51f3054cmr404025475e9.18.1778490131611; Mon, 11 May 2026 02:02:11 -0700 (PDT) X-Received: by 2002:a05:600c:4f51:b0:48d:1a94:56c with SMTP id 5b1f17b1804b1-48e51f3054cmr404019825e9.18.1778490126688; Mon, 11 May 2026 02:02:06 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6db1742asm59834415e9.31.2026.05.11.02.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:06 -0700 (PDT) Date: Mon, 11 May 2026 05:02:01 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 04/30] mm: add folio_zero_user stub for configs without THP/HUGETLBFS Message-ID: <1aaf861301e26121bcbbf549060cb6b3b04e0c06.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" folio_zero_user() is defined in mm/memory.c under CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS. A subsequent patch will call it from post_alloc_hook() for all user page zeroing, so configs without THP or HUGETLBFS will need a stub. Add a macro in the #else branch that falls back to clear_user_highpages(), which handles cache aliasing correctly on VIPT architectures and is always available via highmem.h. Without THP/HUGETLBFS, only order-0 user pages are allocated, so the locality optimization in the real folio_zero_user() (zero near the faulting address last) is not needed. This also matches what vma_alloc_zeroed_movable_folio currently does. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/mm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index af23453e9dbd..3b1ca90fd435 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5070,6 +5070,9 @@ long copy_folio_from_user(struct folio *dst_folio, const void __user *usr_src, bool allow_pagefault); =20 +#else /* !CONFIG_TRANSPARENT_HUGEPAGE && !CONFIG_HUGETLBFS */ +#define folio_zero_user(folio, addr_hint) \ + clear_user_highpages(&(folio)->page, (addr_hint), folio_nr_pages(folio)) #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ =20 #if MAX_NUMNODES > 1 --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 3942B3C060F for ; Mon, 11 May 2026 09:02:17 +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=1778490138; cv=none; b=FOIAM1VeP9whOy4gmqq8vqXYvZ/TKMYo/eVG181mWaZySIEtRtXktnjCUeK0F+p4B+T+Ebi05rFKe18WTNm3NFxQq9QFbDTNJ2aXAAg4DL0v0tSK233PvJueRmwfWDtvszVNK0Hvdc2VbMSzncWMm0BRLlgeKRMP/Da1cVgxfpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490138; c=relaxed/simple; bh=XgkToM0l5fC6A+WA27EumzbdOVH3Y/tvtIPE5N6fvlI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qSXLaOvO5NIoWm+bw0cRnN7YyIgprjWoxUptMIr8HNSdSnQIu9pOWdsg9GPBZp390wqfB7RECQgCVeAAqK6AbPdEk7YArqe9imZgVehHRFv8FkOBN41PNnPXHCAG5ah/p/DtoE3+jDdSg5o1xl4/ppI0WIArjAZGNk4igUN2fk4= 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=ggzYbS77; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=On01t3NH; 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="ggzYbS77"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="On01t3NH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490136; 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=Mz2Z32/qoGa6ei05M/PHSG1PfYksVkCsfkbIzcH2BdQ=; b=ggzYbS77R7NMdRsdBQcTxVQZ5nG0Sxdz1bOjiAfjM7jh9K3YALZA53i6gUcwSlk7XAOG57 LY9TKJ55RMhSh4zRBqMEBMb9RBfrKfUOsmG6BDWzqOpaxalEIPOf+082VQzi395dmuwKD0 Vjv/7stxV1qe09r70FSphdudrqVmewM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-Px4nlpIUNnqhfp4-eqIw5g-1; Mon, 11 May 2026 05:02:15 -0400 X-MC-Unique: Px4nlpIUNnqhfp4-eqIw5g-1 X-Mimecast-MFC-AGG-ID: Px4nlpIUNnqhfp4-eqIw5g_1778490134 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43ff19e54beso2869338f8f.2 for ; Mon, 11 May 2026 02:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490134; x=1779094934; 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=Mz2Z32/qoGa6ei05M/PHSG1PfYksVkCsfkbIzcH2BdQ=; b=On01t3NHEdwNkT+rv5qtZY/QYXZhTk9hqMDoYa79V9TAES/qCtZ0lWu+y1SaJjH4e1 gZBnGUVBYa5Zla1vj/hPFTR4Iiz05y2DlZHHM6ZvRIqPJpvmS7+2i+Vi2wAIXQJjYi3m Hy8LSDD26oBWyT2nOA4ZH5MtFSdXGyj5X3IdOAVvJ1EfXejXT3cN9oBqadW7TPITwbGP h7OQcASwM/5iC2awI1JZpHGpIq3mwLBW59Z/ynqI1QA7CzwNUK1el99UlAf6wxca1ZA4 N1ScfwOPFG0hprd7nm6228KRy0M2WyL/EHGdaNqGDDe8+uFtAPONfmO16FbvTEc3VpXk 69Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490134; x=1779094934; 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=Mz2Z32/qoGa6ei05M/PHSG1PfYksVkCsfkbIzcH2BdQ=; b=UPSKwdLlAQWJv/9022T9IQ3XgOPtT6AugN5GmFQ6HmggkQI+TrOFt1MM7Cs6DwOSPY 2fLQi8zkHOypP1FbqhTRLRrHr5ohvSpfCMZ4dT4OCXzQSfFwRfxXJmJqE+g8z6HgVa7E pw0EdmAzx8ZcLQzTLbOziKiEyzsasdJlaz6J8Hu7OkySjCNuTg7AC8sREb0QR2cG/I6q d694zfV7h1aAXeXlx++v4YGt22sTEc4UaD8G6mUtzaNAeXma+1hk4q1oFaXuvJqE5vfg h000iIEtCsGu5RcquvLQxHtQGOskcOnuB9CGd8g92kQAjO5CZY4RlYj97S4hIlGdombD A/NA== X-Gm-Message-State: AOJu0YySH6ekBQEETGm14PrahxKP2NazP+gttLhqYBpMOX4OmK1cgp4q Ko1BvW81YsQfCbWGQNcpj7YD9SIykRg16IbhKhQuZ8tR7AE87k/FNkxbVLcsiXLn8Xi3fLVz9W6 KGQ1jHBzvn4HEiqoM4owTATb9wMcWqqHXZnqTaG6wSDVFo+CXeMSeLgyqOPSFRpWsPJqUyGWdL0 1xLXgHRgdEOD+5HAPlu/1PTHoUf0QacDQU6BrW9H72TQ/nig== X-Gm-Gg: Acq92OFlwL6yXs/zs83yMN13LoCmB0rikHIxnSZAcvD/4YhGwqm8hSKIFPsmKFEV/N8 bLimOWQcNEqdpKavY9uL/ioaHiL0M2odzr76bn9eEigqYTkc5DE27ylu+NcLr/SYLZDKk+mA5bP NYv9zRmYuC40h6996pwGMVVLjTmjFB7Kq2ENtw9Hvf+sKz4GK1B1p/yFLBsXySX5c4mtpViU60j 2L9EKkCcjMbnd3h1WU1K96CpzsSMxy/bVUpZ6YJZquJGPdnfTXtTbY4enfNGBvy52HLPFE+Nb9f 3iXvO4ImaP4E0XYl9Dcca/1iRpP+F1C+pZflxF82wtXbYWABa70XF3ZOFFSSTjEw4nipxtAdXVp wdylH1/q/kxad+jH/2YHvZvGK3s2pT+VDMb/zO4ED X-Received: by 2002:a05:6000:2502:b0:43f:dd40:bbc8 with SMTP id ffacd0b85a97d-45462c341d9mr21397121f8f.24.1778490133582; Mon, 11 May 2026 02:02:13 -0700 (PDT) X-Received: by 2002:a05:6000:2502:b0:43f:dd40:bbc8 with SMTP id ffacd0b85a97d-45462c341d9mr21396993f8f.24.1778490132555; Mon, 11 May 2026 02:02:12 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a6a64sm25368230f8f.6.2026.05.11.02.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:12 -0700 (PDT) Date: Mon, 11 May 2026 05:02:06 -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 resend v6 05/30] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: <6345727fdfa76157ba0518e2148d1848e0bdbc16.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move prep_compound_page() before post_alloc_hook() in prep_new_page(). The next patch adds a folio_zero_user() call to post_alloc_hook(), which uses folio_nr_pages() to determine how many pages to zero. Without compound metadata set up first, folio_nr_pages() returns 1 for higher-order allocations, so only the first page would be zeroed. All other operations in post_alloc_hook() (arch_alloc_page, KASAN, debug, page owner, etc.) use raw page pointers with explicit order counts and are unaffected by this reordering. Note: compaction_alloc_noprof() has the opposite ordering (post_alloc_hook before prep_compound_page). This is fine because compaction always passes USER_ADDR_NONE, so folio_zero_user() is never called there and folio_nr_pages() is never reached inside post_alloc_hook(). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- mm/page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c3c0f4e2baa7..f76d5271b5c6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1864,11 +1864,11 @@ static void prep_new_page(struct page *page, unsign= ed int order, gfp_t gfp_flags unsigned int alloc_flags, unsigned long user_addr) { - post_alloc_hook(page, order, gfp_flags, user_addr); - if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); =20 + post_alloc_hook(page, order, gfp_flags, user_addr); + /* * page is set pfmemalloc when ALLOC_NO_WATERMARKS was necessary to * allocate the page. The expectation is that the caller is taking --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 73F143C3443 for ; Mon, 11 May 2026 09:02:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490146; cv=none; b=AAw3FJtUARHrtfc4TwHrPDVOIgbXctmunb6C7smHOZUlyAEwwquadXTb73tslB4rkBRTJsNqRz6MFcjLIfK1RRmnK4vJhKRTWgAQk88ea8mVoNdxNEOI4gvfOQhunNtt4MDNzHvtWkEAanI011hh0NMdbUuNwW/6I7honP2KjzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490146; c=relaxed/simple; bh=B3Elvsk2QbFB4j/MM54kU4HNtRj52gz2EfVB/ero4mc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GkYxz4P1Raxkf6LdvCezb5ckZoYRXWbhayDG7lQXUWEoHjxtQ6070oNJD5KIi4DTIO6XeaqXWWdG2WB0fENTyHBnxjAQKj8lPMgFLC0S1ecP/BImHDwbA+e0UunzCpaPnpA+f5DB7ljaDU/eNUOSa2EFxqDIL79CPfVbz4vRZtM= 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=gLMAdN1R; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=OoZW9QZu; arc=none smtp.client-ip=170.10.129.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="gLMAdN1R"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="OoZW9QZu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490144; 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=zuBj5G8Fe8DfsQghniXtZy4OYrf8Ud9rSYDvYLkW/0M=; b=gLMAdN1R/F4XKfMncfrbYvcUcowApFYWp60XFZWEtuol5vZ9+OR1bC1G9XXe3mktAW027d NXbSZJ88YE8hY3Ps5ySGsphb2iImEdKlBwzt9yYVC7LR46Srv65+IZjdQABPX+fnmTPBxj yrLhxPJk/2yAL/wd87oSlQvPlibaNV8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-YwPMQrk3MT2ifgtpB7D8fw-1; Mon, 11 May 2026 05:02:22 -0400 X-MC-Unique: YwPMQrk3MT2ifgtpB7D8fw-1 X-Mimecast-MFC-AGG-ID: YwPMQrk3MT2ifgtpB7D8fw_1778490141 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-b8704795d25so326907966b.2 for ; Mon, 11 May 2026 02:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490141; x=1779094941; 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=zuBj5G8Fe8DfsQghniXtZy4OYrf8Ud9rSYDvYLkW/0M=; b=OoZW9QZu5TXmsWTfDYUbK4LvCRplUDXjit5ms3Dttqo/jLKb7EQudNd1NdZatrKPHR 9jL09BZwnEPg+mayHVSBRESXHBW+shsC0OhrDQmvR6OWfKdES6u16MBcY9EGYezuzC6q XuX3ZyihVgzvJg/c6svWsEw0l0nqKAkJdNecfYdW4QDi2Wq3/mTL4e4sStyCDKc97VD3 Yl01n0vjfaFAH5uNvoordE7oZTZTcNOELZF7uCzpRT5RM9b/4zvvxJv0ENWP78JXK2EP 4D0pupHo04oA4J1oSdYqc/yTyy31CiC1rDwXbnkzVfyPdzR9LniJpJ3+ek7X2LDpWwJS 6gIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490141; x=1779094941; 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=zuBj5G8Fe8DfsQghniXtZy4OYrf8Ud9rSYDvYLkW/0M=; b=TTm2RtRtvyLm+d/Ie3NwC9Za3cK0vYO/gdPX2KimXWrpQWXh5fqnNEmuMkCzTupgu/ LlLrpDMiTKk700LYlLeQUZ76qlb7WM9Ri3/RZnMuK6ZaDl1cFAJkmkt/C5sihCSG3jcu SYBj1LTCom5DhFvFcmy87hCgBLgL4gqGm4PCU7ZaSpQr/sbcArhbDB66uSK7TxcDBtEH s8iCpHEs49wBh84yz2TajsoUHbRI376FKVIgpvqoRwHZpPtAUrWnL8pjt0pW3LOl25QZ jbgBzA/yD/XMTfK7LDsIBQC7qMixsKRvDxUWXGDqw4pEGr9apTzyXAVv1v7GkUjDQMDr VaVw== X-Gm-Message-State: AOJu0YwVZ0wh8RsS8KE1+ochgamxH0PCjU2yinF+2VlAnrAqShe1tzY9 QinUpin+YL74mtshDuJ1uAIuGpUzyNKrvSsvq1otySmPn/kutRWonzZYKGFEsBabiMNH8uxTT/m DwlXO5cqaTTbrr15gUlcF0yJlFPgOIYXb/nwzayroEBWPicj/RINMDbmKfiss+hIfZl+s4lOkP6 gHmuTA2Bdx1HHAByHkYKJStv6oUii8SCaQavUjAaBjZn8= X-Gm-Gg: Acq92OH3A5B/wa1kiNINgxj8hFTsbB3Hw2SQT4ZDiAfKVfqKOrnfIqPYcWOakp0IJto 4PGuUlqdwGfhxCbFbxWIe/vxxilxEGJtQvYRhy5ZClMlSMzhIuxomHGtR9AQ8W1O9Bu8TrT4q5a +I7dA8BANHVFbzFUiGfWt1cwRPo7jimrLofQ8IwW+Inxe7au5cimHUFKEAGSnwE9S3yEOaIVPOX HjdXbu3rsdQqwgVRDrWcj93FSA3lZ+PK62TOVKSn9KT+AIcjMmM+R/SSpbo3fhmxe7w5ClwpuLv jymUz5qUc0cGLRMqhhbGfNw2ODamPuz23HesWky0c3Avfco0rMnf3sP3+B9OXjuD/52+aMTAytc y/vPLjDe2geiPXsfCRk41kPmEXk3HLyUTxHMeJSBKQlRFmgI76uo= X-Received: by 2002:a17:907:1ca8:b0:bc3:783f:1da9 with SMTP id a640c23a62f3a-bc56d13123amr1190835566b.33.1778490140347; Mon, 11 May 2026 02:02:20 -0700 (PDT) X-Received: by 2002:a17:907:1ca8:b0:bc3:783f:1da9 with SMTP id a640c23a62f3a-bc56d13123amr1190817666b.33.1778490138948; Mon, 11 May 2026 02:02:18 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e4bb87bsm23408179f8f.2.2026.05.11.02.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:18 -0700 (PDT) Date: Mon, 11 May 2026 05:02:12 -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 resend v6 06/30] mm: use folio_zero_user for user pages in post_alloc_hook Message-ID: <87e7ec6a9722ebe27a837a29781547d0d210147f.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When post_alloc_hook() needs to zero a page for an explicit __GFP_ZERO allocation for a user page (user_addr is set), use folio_zero_us= er() instead of kernel_init_pages(). This zeros near the faulting address last, keeping those cachelines hot for the impending user access. folio_zero_user() is only used for explicit __GFP_ZERO, not for init_on_alloc. On architectures with virtually-indexed caches (e.g., ARM), clear_user_highpage() performs per-line cache operations; using it for init_on_alloc would add overhead that kernel_init_pages() avoids (the page fault path flushes the cache at PTE installation time regardless). No functional change yet: current callers do not pass __GFP_ZERO for user pages (they zero at the callsite instead). Subsequent patches will convert them. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f76d5271b5c6..842f5080d728 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1851,9 +1851,20 @@ inline void post_alloc_hook(struct page *page, unsig= ned int order, for (i =3D 0; i !=3D 1 << order; ++i) page_kasan_tag_reset(page + i); } - /* If memory is still not initialized, initialize it now. */ - if (init) - kernel_init_pages(page, 1 << order); + /* + * If memory is still not initialized, initialize it now. + * When __GFP_ZERO was explicitly requested and user_addr is set, + * use folio_zero_user() which zeros near the faulting address + * last, keeping those cachelines hot. For init_on_alloc, use + * kernel_init_pages() to avoid unnecessary cache flush overhead + * on architectures with virtually-indexed caches. + */ + if (init) { + if ((gfp_flags & __GFP_ZERO) && user_addr !=3D USER_ADDR_NONE) + folio_zero_user(page_folio(page), user_addr); + else + kernel_init_pages(page, 1 << order); + } =20 set_page_owner(page, order, gfp_flags); page_table_check_alloc(page, order); --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 43BCF3C4576 for ; Mon, 11 May 2026 09:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490151; cv=none; b=g35BIGmoXZIkDE9a+9jZ1QtCLfBCnQZuwMRCbu34Ntk1F4sw0OWJXUwUTqjXzOfR38Dosp2JWarprm7WUyirZRh6uSjMAivgmzy8UlmwXIHgkjUVQ9UnCGKmn9J1NNw2aIXZd9D+xVv1//I6WAAtctzSfrxde3Z4iITANfSJcy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490151; c=relaxed/simple; bh=B4v7SD6SJ84KapLgBy+iXreANiiaF75HE81bu1RBt3E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fl9wDlCAVSmdEa8cIAoF0FxxtRW4GsVhbLDd5Zf0XnEXtugFQtcnlX0vZnIHggpi9KAiP0MDhZBV8FjVp9LayxEmn3DOmOoj7otADbFWXMta6QI4hibwPPpikWm3jygp8EvPvncjLXNXIRF7pplQE0mguvTHcA/tHVEhfA6UrRo= 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=ijurj5ur; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=sUN3J9Ca; arc=none smtp.client-ip=170.10.129.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="ijurj5ur"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="sUN3J9Ca" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490149; 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=jpAQ9O1oMgUNlo5ukg9OEno1SM1k+70VK2/jH7/8vVM=; b=ijurj5ursZI6LBsVPyLvZ/NdcoLvuz8kk/10D4qNen8VhJ71YBtcAyNK5OXQI3CHRKqYrx ymuzOR4621H6C3uX/dwUjLOoGqYmq4FBAn0cWKaKwnm2CqfvNiBZgEXNiARpKRkZYnCsLp 23EYC/7TYFzxu6Xvk/WMZEA+oqJcIAU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-393-3mXe8thHOPSt3-E1uEY-DQ-1; Mon, 11 May 2026 05:02:28 -0400 X-MC-Unique: 3mXe8thHOPSt3-E1uEY-DQ-1 X-Mimecast-MFC-AGG-ID: 3mXe8thHOPSt3-E1uEY-DQ_1778490147 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-44a122a5128so3130656f8f.0 for ; Mon, 11 May 2026 02:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490147; x=1779094947; 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=jpAQ9O1oMgUNlo5ukg9OEno1SM1k+70VK2/jH7/8vVM=; b=sUN3J9CaOlET7tDF2yVz/JRbTsUFIZ6qiN+0No8QMltzNKKOnTTb09ZoLUuGt3CKMa LyRRIq0KLe6UYad+MfhzJEC1aQnJEhakFQLN4K12/SsG142jk5ihFH3gDCXMwIIcBY+J 5+eSw9xdbJnlxOB6HsespfG/YNQyTDuFIBOm9MHDR6O2dhnd6EM8UU/92TZug9PSf2kR pb4ORM7zzvIQvfEiH0CsoR8IuGwpIKnTmdVvvQKmckpLCqSgzCkJHJz4MBjJB9VvCyCS G5zqaO7lPyhHnTcenOT1m3CTbn3QmJ1iPwKgy4j/y5nibJ91UOKakyckuUOyKHnqu0ad KmBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490147; x=1779094947; 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=jpAQ9O1oMgUNlo5ukg9OEno1SM1k+70VK2/jH7/8vVM=; b=ZHBvwwTLn54Yc12TWuPLbW/Qhfx/p/6fhcGCvhKrigCHNSc72b617zxy0DZ9qPTeJQ HK3VETgmOnZUOIR5PgboK91hRK/ESfLRDbG1fOwaXJDi9f70mud6+UT9oMvgcZdp/1AO c/fJFEHiZQ6GTk6u2Iz1un86KFNb5MeZzLsPiPxf6HCOf4TIWJ1va2iwtbMe9ShVjQrn CEy77gmad3/ycW4boFzTbSDofGf50jOU9w5AEpPFn5dcpUdNF9/hEFOCATF9uMLOE1g1 +tloRKvtqkUk8h+VqvUGuslzsYOM8eQcI3MOL+lj0SdrdtyoAz8XA/WNioPuIqEnJ17l OYOw== X-Gm-Message-State: AOJu0YynmZU1CollEV/9lsQSNzUmnNN7yZRr84na+M8yOWWvKFfqT0tT aKhldVj8WO5BH/GrlXbIev+uaW30JitJ7KdeToTjs2I+tDmDq/TeCBKmncsB6kjINFNjh+SepBM 4U1IQgMyHyIPXnpBP2SVviAAIVCJM+Yrym9Ms/P4DBMqC2hv559Tf/XrZWARItjuZXjbGDtyWXo wRbyeGrK/7ltmwKSCAWw+adU/xchEQiUPKPLEO4NjU183X/Q== X-Gm-Gg: Acq92OE9Al1r1wxHAQ4JDwutYI12f+2dLaJEW4N9AzVmDwvLf2u9AjsGSVJS6gHOLxD 7mNdSJ/y5e5H4E98gUexcVAWopnb1tb0LtHMs6fnMxulLMwXzpMiD5iIe+3poanU4XDJ7nzbTTK RNzIXKG6M+yT79PehCY2kQodww6eRnNmVljTJUz/BqOHimGz0CD7rT/dBnRFHUL19+dsKslZyYK vAR5Q+/gSO/DnEMKauyNLlaFUIK+7JI3acfjW03Ua4182Mvw6pkhV8I5Zq3mh/epS1qkbAXgO4g InMlIfkkBOSWL5+l0mrS6EnRFkvKk4k+N+DiBuf7IY4QltyapV+Oe6uWoBBYxWCDA7GdzbSk0oO J65R6CA20sAEItCWwx4m7wnt+KM1UTRmMhKiYQDKJ X-Received: by 2002:a05:6000:310a:b0:446:96b1:f51 with SMTP id ffacd0b85a97d-45462c34296mr20229283f8f.22.1778490146511; Mon, 11 May 2026 02:02:26 -0700 (PDT) X-Received: by 2002:a05:6000:310a:b0:446:96b1:f51 with SMTP id ffacd0b85a97d-45462c34296mr20229157f8f.22.1778490145663; Mon, 11 May 2026 02:02:25 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4549120ec0asm23630828f8f.17.2026.05.11.02.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:25 -0700 (PDT) Date: Mon, 11 May 2026 05:02:19 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 07/30] mm: use __GFP_ZERO in vma_alloc_zeroed_movable_folio Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that post_alloc_hook() handles cache-friendly user page zeroing via folio_zero_user(), convert vma_alloc_zeroed_movable_folio() to pass __GFP_ZERO instead of zeroing at the callsite. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/highmem.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index af03db851a1d..ffa683f64f1d 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -320,13 +320,8 @@ static inline struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma, unsigned long vaddr) { - struct folio *folio; - - folio =3D vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr); - if (folio && user_alloc_needs_zeroing()) - clear_user_highpage(&folio->page, vaddr); - - return folio; + return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, + 0, vma, vaddr); } #endif =20 --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 585653C8716 for ; Mon, 11 May 2026 09:02:37 +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=1778490158; cv=none; b=EVJywpX46Ojdykq6R6c4AAtCEiTH4X+ABwX2lSAaBQ7ZFq7t9aS4X6o53Qob/TKn8e6JfUbpJWFhJjBeOqd/bxYLLbGgaXrjcScDrEHxkbvoklAzGunhh8Xu+eITp//JxVeVvUIy4qdz/6DVfh609r4UbpLoAveVPBs8qxP+g5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490158; c=relaxed/simple; bh=xVZpENOTPSkcCw9H72WToBvwV1ZsJAWZkigdtcUbLLU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Tnr8FQeOkuZVFue1R7yCMI9VghnaUL+DUf8qvEl00l/QkH+bWfRWvnyDTIluD3FnFv3hLFzQWEWn6LZsA46u7qQI1YuA82VKM1J8rfdB1ugl3tE5rY2xArvdIEPYmDnN+ANP0p3RogyfdizsfiCMyuSyIj0GR4Z2pKjMmwbTbhM= 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=LhUUdbXU; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=pxS20Td/; 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="LhUUdbXU"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="pxS20Td/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490156; 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=+4kzhpMcne9QL/iUfytpcOnuwyhDfw3DKjMmXnNjefM=; b=LhUUdbXU5rLV8LcGjKMJ7r6KcdK7v0VpU8kl2gujOLfEBw1QcpFZdU6JKHVXp4MytvGz30 +y5eg9IbWLKL9LXyBi6mjJwCJ6W1WtJLqPjv/iGnJ12xGqKZgn2ppJxahTHKMc6w/iweU7 iGCkJvSUZhFRT6AySbmuZVbnoaDdzwE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-WY2NU2j7NN6IHmHhhEpFXg-1; Mon, 11 May 2026 05:02:35 -0400 X-MC-Unique: WY2NU2j7NN6IHmHhhEpFXg-1 X-Mimecast-MFC-AGG-ID: WY2NU2j7NN6IHmHhhEpFXg_1778490154 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48e60b55de2so35340005e9.3 for ; Mon, 11 May 2026 02:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490154; x=1779094954; 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=+4kzhpMcne9QL/iUfytpcOnuwyhDfw3DKjMmXnNjefM=; b=pxS20Td/tXuBCp+2WwfKjxOzm/PvmO82GEQX/QjIjoVxg+zwFN/WR4VJz8P9zmQqaG 4+Lh6Vz9hgego5Qz8YxqD1lECpXeFnTh7av3NccEbkMiVg4+NuqWYFjHFQSqDyLUg05z pqNLJFmnDWkYEpDgh9E6/g2UcKynHnuVYXjk6aNXzk/rS+/61pJRkL8ZN9kBsG/EBnFf eqI1Y9Fp8bBiu5y8bS0CXW6S2axX1FB5qotl8PMjc1wLhbok+ewdJDqRPYWmV0rFnJit jicXPVzO2Az32Al/rLp7unQ4V3P/kkzt7xaEqyV9adgaFj5JuihEdKSF7ylgR9o5s/c3 6LMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490154; x=1779094954; 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=+4kzhpMcne9QL/iUfytpcOnuwyhDfw3DKjMmXnNjefM=; b=C3I1qSitcTyrFPTzJ7ld38s6mV28S5lBkFNObNMkLuCVQdP2bhYB6aydmrECscJIFV PAf62C/CLn5bd6fy3G0AtqVlST+JWOreP7/oGWvyLazE6S+O6/ovF45YdhNEWns1CiAk QlGDcZv3YnCIbdoIsXz8Pcq4aCAerxc64afwyRmG70ay3eOPnOpw65wTjVaX/OxSarWk 7+i7ZWH8lRJA5nUbyPSDEMYeKrPF8WLmNT2k47hhrACP7b9Fe01Sbu2BzE4eCTZ8quiG hBqgd6773VFiGPRh61zqGIf771knVVIYV3CaGA3H4fqGBVW5ZAm4+QNsXvylF48676sD hvIA== X-Gm-Message-State: AOJu0YwLZt/jaViPLQuHZJ0z1XSNoqYPFhYmZ6tv2OaIhM2hrteK9Vwm d4sx0f9xKhuGz0MOz6EE5Q5zrVD+9bAcNDQmbHVrcmawsWcNWREdVG49jb9GxuCQ1sN0UDFsdJd KW7398Gkn91EU6FJH93lXocPVMokplCx3LC6yih54yxjf5+HPc603YSF7IqZUY8Ld3X4sC8ASfr J+PF/kLcTARp8Vr6pmeLwFJklVXBozJnAHFGQ0Ar3b3Go= X-Gm-Gg: Acq92OGEKH1cFFexQ6j/ye5aGZn4E1Iu0hwA6aRC6Vlfm8wR7jYEpb5J0108n+vGsFJ pkKqnP9NpTAiu7iV+ApQ0YfsX6yiEeWPEW42zJzBJCSkDJN/maQFcOmlDpYwoBR1YwvMxocjGhm Tt7NWB69aBsG/fkNxGgrgADwX7YNEtq0kntLfGwKodlS86swWNMIsL0Gv1ijuNHxC4OhPC5e6e+ i4TCDy4liVVSofEn4E5vkBNh0UMfTlU2slSSavZzUVpueVErl6JDpcrc6QqkShD4U1XrAa8F+I9 hqy+CwwcBzlAkvZnJq66xkXqW0WQxmymMxialdLpdrXh51S2eHMfLH4XdbJz78L1EjY7tzBPpCz YMR3jl43yiMT1AV00Dbqe1EyxwlZCtSo0azAiTgVS X-Received: by 2002:a05:600c:1d18:b0:48a:906b:14ca with SMTP id 5b1f17b1804b1-48e51f46e46mr365112915e9.20.1778490153491; Mon, 11 May 2026 02:02:33 -0700 (PDT) X-Received: by 2002:a05:600c:1d18:b0:48a:906b:14ca with SMTP id 5b1f17b1804b1-48e51f46e46mr365111235e9.20.1778490152468; Mon, 11 May 2026 02:02:32 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e7040a9a9sm297049045e9.9.2026.05.11.02.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:32 -0700 (PDT) Date: Mon, 11 May 2026 05:02:25 -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 , Magnus Lindholm , Greg Ungerer , Geert Uytterhoeven , Richard Henderson , Matt Turner , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-alpha@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-s390@vger.kernel.org Subject: [PATCH resend v6 08/30] mm: remove arch vma_alloc_zeroed_movable_folio overrides Message-ID: <24a1b25f4f1cf31fc5bc053e475958ed5e1bf8bd.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the generic vma_alloc_zeroed_movable_folio() uses __GFP_ZERO, the arch-specific macros on alpha, m68k, s390, and x86 that did the same thing are redundant. Remove them. arm64 is not affected: it has a real function override that handles MTE tag zeroing, not just __GFP_ZERO. Suggested-by: David Hildenbrand Acked-by: Magnus Lindholm Acked-by: Greg Ungerer Acked-by: Geert Uytterhoeven # m68k Signed-off-by: Michael S. Tsirkin --- arch/alpha/include/asm/page.h | 3 --- arch/m68k/include/asm/page_no.h | 3 --- arch/s390/include/asm/page.h | 3 --- arch/x86/include/asm/page.h | 3 --- 4 files changed, 12 deletions(-) diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h index 59d01f9b77f6..4327029cd660 100644 --- a/arch/alpha/include/asm/page.h +++ b/arch/alpha/include/asm/page.h @@ -12,9 +12,6 @@ =20 extern void clear_page(void *page); =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - extern void copy_page(void * _to, void * _from); #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) =20 diff --git a/arch/m68k/include/asm/page_no.h b/arch/m68k/include/asm/page_n= o.h index d2532bc407ef..f511b763a235 100644 --- a/arch/m68k/include/asm/page_no.h +++ b/arch/m68k/include/asm/page_no.h @@ -12,9 +12,6 @@ extern unsigned long memory_end; =20 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - #define __pa(vaddr) ((unsigned long)(vaddr)) #define __va(paddr) ((void *)((unsigned long)(paddr))) =20 diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 56da819a79e6..e995d2a413f9 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -67,9 +67,6 @@ static inline void copy_page(void *to, void *from) =20 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - #ifdef CONFIG_STRICT_MM_TYPECHECKS #define STRICT_MM_TYPECHECKS #endif diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 416dc88e35c1..92fa975b46f3 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -28,9 +28,6 @@ static inline void copy_user_page(void *to, void *from, u= nsigned long vaddr, copy_page(to, from); } =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - #ifndef __pa #define __pa(x) __phys_addr((unsigned long)(x)) #endif --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 1753C3CA491 for ; Mon, 11 May 2026 09:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490165; cv=none; b=H6w7fg0MlWJAlV650N4hmac6/LG+69JNrvBPW4fk5X5T1bsPlnilSIDTq1UPHJKlc9jzcecI4rl0HxfIADfVRx7lKgWMhZD4+5QpvL6G0KVMGckmfRfc4OosPzrQHctOeZwUs0Jb2FuuZIR6nXGcZBJodMBF0+kOdZBSaGYhfD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490165; c=relaxed/simple; bh=MamMMWXXtV18pX2Nm4tlwaTMDaamkDfpCh9w7kBXTEw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AWlInh+TYacZUnEkoa3tux3nuS3vRHG6MoFPX4stBjMqYCSmTecXUIHw5yX5qY+ghmwo4H+eQz3iWpIskmWfhvxUwYVY9Tw8SC9nRA1zXbPkKceT2x/Yc9MUqzuprkZpp7YqLZhG/q7Ubn2e9HuK9cemCO6mlHTtP7LJMIUB3Ug= 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=SGJ4CaB+; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=UGs64M3M; arc=none smtp.client-ip=170.10.129.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="SGJ4CaB+"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="UGs64M3M" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490163; 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=PyhJPD76XSlXOLIxrgX26vlRXB2m99TPkgzm+4tnrhY=; b=SGJ4CaB+Iq8XxVixOV1kCOvGAAJSd667Sru8U6ED6bEoGcl+PQM2uD7QkQaZB8fb7/85zt TizuSqDJR0beOomwMFDVAP7LTAnTcChL7tbb27CoTgePY1Q92iR+6UtMzeKAqV1Q6c36Fs Av9Yl7yswLLTMiWV+k9q1mipQVxXEpk= 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-683-YA2SPTygMaaSjcJ3KoDz4g-1; Mon, 11 May 2026 05:02:42 -0400 X-MC-Unique: YA2SPTygMaaSjcJ3KoDz4g-1 X-Mimecast-MFC-AGG-ID: YA2SPTygMaaSjcJ3KoDz4g_1778490161 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-441243ba35fso3393933f8f.0 for ; Mon, 11 May 2026 02:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490160; x=1779094960; 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=PyhJPD76XSlXOLIxrgX26vlRXB2m99TPkgzm+4tnrhY=; b=UGs64M3MRTw6DBlEAhP5HqlKS9sJAstsjGhsufZZJk0TBZx+NAy5DuFeUyx2tafCEr L4D0LiQFexYlMpOXGUNZpmcxcGgcSdvvZj+QAv8b3C4/Vckbk07lMvlFwxQv7a1frTic fxoavPDMWNWwZ+CehFSh2QpbqxGcvv3aFU15WglF/K3BIs2ZZwwzki4Afq0LWSGEO8Tb JFjOSG1G0JGEfdN1Ju8IimDHXFaj7VaRgihC9yA/lf5mj6+ixiyStku9CQ00GJSC3UEa 7OuLhnCUtq1etAELQOAcBDnRj0jDsJ4nFYt7FNG1zvgqdCgc7l0rrys6Vr8xAxIUdwKX lihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490160; x=1779094960; 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=PyhJPD76XSlXOLIxrgX26vlRXB2m99TPkgzm+4tnrhY=; b=mxra7+zMMM4+TD5dTotvNk6xHnVhJSO5CD8g6SJiAN4X42m/+xFu6JaqeHfXssxGb1 bcxfF17oMVFIdGHPJ1fv8+xS10caFH+4gKf5W2ZVLWKJCKQeKOhYVFlMBhl2KxgNrE7K 0i2NMmaiT/HbpfG7ULY5OZNnouthU6lAtLphDpCTO+Q6nSqCh/0JUs4Q34NO0jYK2kyl AlsAiEsrCNc3Yor59SGJaLQZU0CPCfnlkmZgM2xv9ilo3i17bGAsw3WEMwtWJqTn7jTZ iO6MIXNQgjPun5kAWSgJoG88biWf2MI17pU0ZKIauJxVQM5hgzqvgKXLzZY/L6KBAtUS xxgg== X-Gm-Message-State: AOJu0YzgfWQ20zrSArzrCM1nKIOl3XGhkt1TDc5XDgvNWS3+/SCUHEFO 0v5YR5YRJ+MzjJ9iwDFjS8Gp291ZLTV7PQsrtcgYb9Fw2fp432qynqMoKgPRjQJT2+mixjxPZPM OAwBfyzqf2XLecbR8ZX2Ejc6Cv+peV7d29r5BKcu0s5hGBymjTSLJJINjcg53ezZwgqUIIP3TGW Gn+7FSju9ToHF2XaIvtTXQc7i0dnrvHJQUv3skB7RetVY= X-Gm-Gg: Acq92OEsZWtfW45m7jF1cj9z1E4N9G+cEdJfaZSmjx/zgPkfvYSZUZAstSECCqZUOyL PXbVLulAYsA2nl9dLiF2Hcp/e2VXMBH+jxI5BiZ9U/BlWVc8R+z7qXsbIrdX/TDWFcMyEBIhP7B 7v7xQtqFjijzcvEzoF89CakzquAxlkqKbrE47dH71zIKL7H0ZbYm4xrKKzU0iZGiOB9YpgVyugA 4nHoOTJRl1lDbiUhts4qcB1jqIqGdsOlnc0mC/uUI895xkWV9YaitmkmxBCpeCA2DnxZkojqPLX ldThvKhM/h/pKdRuaN5+HKeibZcLEw3745ZdQjCCfvl9E5fBrLqacZ7XR1B1n642sP94hoKHsyC Z4NqalclFh+Ig4fUuTijLWQItPIh1XuqvyGkkxnQQ X-Received: by 2002:a05:600c:628b:b0:48a:557e:6b4f with SMTP id 5b1f17b1804b1-48e706cd77dmr153153685e9.23.1778490160004; Mon, 11 May 2026 02:02:40 -0700 (PDT) X-Received: by 2002:a05:600c:628b:b0:48a:557e:6b4f with SMTP id 5b1f17b1804b1-48e706cd77dmr153152205e9.23.1778490159368; Mon, 11 May 2026 02:02:39 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e702e5516sm264424385e9.7.2026.05.11.02.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:37 -0700 (PDT) Date: Mon, 11 May 2026 05:02:32 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 09/30] mm: alloc_anon_folio: pass raw fault address to vma_alloc_folio Message-ID: <96bbd5dcc37aed93a9b7733780bdcba4fdacfa3d.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass vmf->address directly instead of ALIGN_DOWN(vmf->address, ...). vma_alloc_folio_noprof now aligns internally for NUMA interleave, and post_alloc_hook will use the raw address for cache-friendly zeroing via folio_zero_user(). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index ea6568571131..0824441a6ba1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5252,8 +5252,7 @@ static struct folio *alloc_anon_folio(struct vm_fault= *vmf) /* Try allocating the highest of the remaining orders. */ gfp =3D vma_thp_gfp_mask(vma); while (orders) { - addr =3D ALIGN_DOWN(vmf->address, PAGE_SIZE << order); - folio =3D vma_alloc_folio(gfp, order, vma, addr); + folio =3D vma_alloc_folio(gfp, order, vma, vmf->address); if (folio) { if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 EE1723CBE8F for ; Mon, 11 May 2026 09:02:49 +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=1778490171; cv=none; b=u9mrlnc6+ff1Sw3iDpxVPQsyve23p9AXtwF7PTgzjzvKi+A5glOjFi7RxV5b81QJcSoXlDy+kphsd9urmNVTlIb485ESAkGCr2pFnWy5BzPMt6tRfA/rEmGxuG3+isZ93xL9bbYMYyioZU/oaWNxvc1U+UdKYzttiXGJMmjlRWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490171; c=relaxed/simple; bh=WO4MHxi65GFX0xUNciL8bEMuUsPiR9dGIohoqGtzw3w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gj3VEdufmagDsJdfly6gArpzCxEggp/E3OV5lu50+BOko8S5mDG+NeG+dZQwqgH+D4kJguGJe0qsR7YF2qKgEuNr/L7qMp+5cLvHVgzfVMdxD/AmFyjIHq+BW2IeUeY7k6lXhMfdrMjfoaHMNG4O1pSm4FFYBBE3vcsCnOruc5k= 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=OX6OaYHV; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=GN3u7/4s; 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="OX6OaYHV"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="GN3u7/4s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490169; 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=XL/pBrxkXlfOOto9pZb2YfWp+jJTrqFtHfQ0Ihv6FSM=; b=OX6OaYHVbcgpmV7F4zWmdkcBToq2UjmdhrX2uUuaFlpHXkA7bf6/p3wtil9DZrEWtpGfL/ 7waRFd4F5ZsTniBlzytxuOpXFTSDPEuhPt9qUZ+j68eVJnrXQRVLf/xq95+VBeLrsxxeIT WJnnXBqBGSR9DGlk2TU2nddrL94KJbk= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-YmmyOzZ6PU2Lxgy4INsb3A-1; Mon, 11 May 2026 05:02:47 -0400 X-MC-Unique: YmmyOzZ6PU2Lxgy4INsb3A-1 X-Mimecast-MFC-AGG-ID: YmmyOzZ6PU2Lxgy4INsb3A_1778490166 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-44a52d5e572so2552454f8f.3 for ; Mon, 11 May 2026 02:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490166; x=1779094966; 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=XL/pBrxkXlfOOto9pZb2YfWp+jJTrqFtHfQ0Ihv6FSM=; b=GN3u7/4smyB4wXqX6//v4oj6aV7BC96t+cQ9u1IFznr7kaMcwz2nCbXazig2sSim3l Hc7eUklQLHTBsuFosQbZJfFTGhaultnY4PzSXvOnXLHcWv/w2xUWop1J/VdmXCa6jWzu 0T4pxqFr9SUMYx8RZyH/Dso0eNjmBfj9UzmXzZdS9nOYNkF2ZpQ5iv/0OK3m3+HuPH7M xOMIGRc6rxTXqQjk8uQZKiThYVTSC7AHKghkLAb7ydQ5aazGG+Aw3O2lzPE9CsKGezRH ootUkb/XTvpvlWjcuOpB4sr1aa69DKmWphmjdAqgAWzbbG7Qm/kqtXp4EPsGdSlnExgu rHGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490166; x=1779094966; 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=XL/pBrxkXlfOOto9pZb2YfWp+jJTrqFtHfQ0Ihv6FSM=; b=k/io3tO+2h4m4DsCWHBs+j/j6UHTxfGAsg/qROOOZEYkG1DuUEW5U80SBNBHEN86W4 RKMrsaM71vVd/WG47/DaFG5dArf62VgYkmrsL4/6fqv9P6VYbqgV1av0CxlTLggFGT6k sshYmLU5+8MKZf600Xi6G/21WBuMkLBy4YGfChpF5cr95OCNauVg6pelhI81i3TzZ/6w sMGbEI8/quz1jkraUqT8ihwsqvXSr16kdGAYoMSJTmwxINuja9alN6ogM9/mLULBh8I7 9QXqpHBggwc7L42FSduw19jfh1EXtG0NknVESjdxJjFvlsEPvU/KckLZq5HtJ50ZIb5U w5XA== X-Gm-Message-State: AOJu0YwJgWD0hYGUq2lZgqP9DV9onfWy8EWd3nTuw4nb06GAveGmLEq2 7/PwZKIKLRVkvqedPMQk01o3L6dK+C4nc8DLix90PpIB7MEsxQQQEVj3H8WHm8vDOPogN+MKtwh I5bm7F1S9u7B6okrzyminsqhABPAoESPSD50L6a2Yk9FPMtZK99tky0qHhvvl3gtncjYICkEYGs YJ2b5vOU3N1tdJtRxF9IJ5txLkApJ/KmgRXLhvLUrsY1M= X-Gm-Gg: Acq92OGwONiIi7v9J0Ycu2brvM4S9YfmoFWyR8fnTDKEDmWDk3WCbPFhH3p0xaQ5fTE mTT4Ggnu1e76s5aYr60oHnP0ufdOGorLA7aOudVxzRkdrg9RV8cvpH5iQGLiX/o71aR+885lawS UjkU1S3lA1li/htAx2ZzXIOV/2On6U4Px2RuStaJeLlDJUr5UrrghyrDALUWpMv9spqogE4od8Q xFbiFA7Kj6lMo+HEjqvFrJnODysv0uQqg+ifrqPdRQfiJJa9Loe/kVM7yLdDbp65og5A3x9ujFA sqGAlmvMy1r1XFPWE/bn24+GGZeWhZvAKgcS8NYngDqZCHDFh5mDBCfVKPdt0rIw4ccm96c/IAI r0oyZMNRfktqLecEpJ43yer32QF4a3nJunmhufzIVYxITFkqQqZE= X-Received: by 2002:a05:600c:190e:b0:48e:82af:d9 with SMTP id 5b1f17b1804b1-48e82af0239mr50309005e9.29.1778490165948; Mon, 11 May 2026 02:02:45 -0700 (PDT) X-Received: by 2002:a05:600c:190e:b0:48e:82af:d9 with SMTP id 5b1f17b1804b1-48e82af0239mr50307675e9.29.1778490165221; Mon, 11 May 2026 02:02:45 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-458b3664e3esm8472285f8f.3.2026.05.11.02.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:44 -0700 (PDT) Date: Mon, 11 May 2026 05:02:39 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 10/30] mm: alloc_swap_folio: pass raw fault address to vma_alloc_folio Message-ID: <369a08b86f51572b2715a9ec577de27ea98000d3.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Same change as the previous patch but for alloc_swap_folio: pass vmf->address directly instead of ALIGN_DOWN(vmf->address, ...). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0824441a6ba1..74523bc00d8a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4734,8 +4734,7 @@ static struct folio *alloc_swap_folio(struct vm_fault= *vmf) /* Try allocating the highest of the remaining orders. */ gfp =3D vma_thp_gfp_mask(vma); while (orders) { - addr =3D ALIGN_DOWN(vmf->address, PAGE_SIZE << order); - folio =3D vma_alloc_folio(gfp, order, vma, addr); + folio =3D vma_alloc_folio(gfp, order, vma, vmf->address); if (folio) { if (!mem_cgroup_swapin_charge_folio(folio, vma->vm_mm, gfp, entry)) --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 648BE3C8713 for ; Mon, 11 May 2026 09:02:57 +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=1778490178; cv=none; b=OYdXryrKS1JmBKadRzzz7NmLUG08fxvCp///yR47Xui8KHViBJTE+u86mnYG1zbSnnHujDs+l1KoXAu/jrYVC1GexaB6kklnZQJHm4z5TQOdRuaJOUmRBsnYYM8k+UqZmylrcOG/LP18hqU1Nj4Dumu6P7nc9X6iCvbpO8IwrTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490178; c=relaxed/simple; bh=oLC9kYur6b/H/9DjaJgYZkAV9obgkYCnPswl1inVcjU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n4/qzqZSxKk9h2z1fK8fkJ1XHAmJunzVWYVzG5VUv3TrHmGCyjwyAWtIFj0WTTRF3iIHehhZho5HadwJ67SwI5ktjXrti5yCQitHxjQ2MbOotU7CMWd9RlDPejOPf5DLffUsGYE6UlmNOosdqbwnA9dRPT+A7vKMsZ/TZKy8mt4= 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=ai861k8g; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=IkSnMGxj; 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="ai861k8g"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="IkSnMGxj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490176; 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=2eYp/q7ILAhscET8EXyPBKCW0KNcPEmiVquSYEOS+Yg=; b=ai861k8gh6mP+7C/9RVQfIea5RTMamZ1JsSraNRSXnV4DtuJCON7spoC+MEWOIS+5E9HE6 IvPFbQO0pgBCFElIg8BnPWxmrU8mnTW1kWKwIDqEkY8F11ZfkcaUqCsJnL6lVIvws+GSwH W6DAqGV1INLPwhuvng4x80sjBNrTxc0= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-x-kCMEsWOcK_DkQMP7rJ-Q-1; Mon, 11 May 2026 05:02:54 -0400 X-MC-Unique: x-kCMEsWOcK_DkQMP7rJ-Q-1 X-Mimecast-MFC-AGG-ID: x-kCMEsWOcK_DkQMP7rJ-Q_1778490173 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-bceb2b8bc2bso69425566b.1 for ; Mon, 11 May 2026 02:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490173; x=1779094973; 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=2eYp/q7ILAhscET8EXyPBKCW0KNcPEmiVquSYEOS+Yg=; b=IkSnMGxjf2iJ08BgSgHVvTXISPGRx72fF7rWDax6tzCacAYrY5m11dkn9C/VdrqkKD QIUeV4j7UFkCtaRxgveNwqtAKXGAmxRsLcWxLg5vtkYImRlhFmqABUQ8HU5+HbrQ8zSO WGwrLzCciA5KboOIpZy68EJ0ZrvkhghizSkZz+W6S750Bw/FCLCb3qHMM3obkz2oTmJu Rcm6ILXz9xRVbSo/BUytZelicrKoE3U/c6TY5iIjhu+QRBDYtfSxyrcx6fs7hEgEdTTF 1IzdoZRJnkR0edIv9SobGOqy02XtJ4ooqbSeAD8P75StjGDemZDXE1iLleesDVuUvHnC i7BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490173; x=1779094973; 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=2eYp/q7ILAhscET8EXyPBKCW0KNcPEmiVquSYEOS+Yg=; b=QVAvZlTDOkLYfWwCslrvAwYdGCCxlziu5Nws9sdpRE38WV5t75ZMBovGr7cVnhne0i koYajB2LhQT+X46ZQDqdPM3upOf4RmfN/J957PM4qa92tSOIlR3Mmx58vJXGmRBwne1d YOlEAk3TJ51uNbuJQA5+T708isLhOjELBzzYVjRFNM40K04KnGJ7MS0UJYCGIUksnOfG E47L5I0V+PHZEq0yH/k+6tEqzls4i4qG2MTbbIgtX9RDSRPRy0sTe91DBzHUkWLMCM2d ZVyvF+/iaBLzUu3hmZC3z9yDgLFDMlUtAt011h+PUaxyeOr2qHlJqeSYmOvKgL5kpL6v P00Q== X-Gm-Message-State: AOJu0Yx9AMe2N7/gugJkC4YkeIYXomDyAgIkwNVgnHD+k14petyMHMn2 MWxnw4nV8ykIJsTvxbktWKVMolpii2RqENQ1a4+UxOWf51eCHxX7Add5OZFBrE9exHzbZRs+ouL mMKO12adxn+WmPvi7k8Y3gZK/Dnf6q2SBnbhGokR8AJ2BecDS19hjwXLNr3QvuHWFJOEYDf69nn l/yCZmHn/nYI2YsQVcB7TQnTY+8TP4at7ADwgMtzRhIKizZw== X-Gm-Gg: Acq92OGVd/p4vLHyi9giLvdFwXthjE0dQ2s8OmXNZzvD6uWZ+IYBdWq6VPn7/C1NEUB YZo1bBkAU1ZTh0Jy1RFAALoiuJ5ckeDMlkifXRQ0MSc+0VmKyvAmCSzr9blx6bkbH2PV1LS/kOR wPaovjMKfsgfpuQRZV6J8sUKD3NY97aiyHYP5B0ygVxx8mgZMDdGMhxkNHfRva/aWIU0QIk4VkR 6fEcJ4hu2favHmRYOEZBRrctxV6QOl5MdtcTg0dxu/b8RGxppupnF2cnk0aLPgULY7sj4D/ZuKC qK7UU+pIJkDvGlkE/OIJFR8WhtelNpLyuJKX3pHNID/d6gGBJnj0RkSPbZElNnWOwo88ETMhyz6 JVBr8Y+tw2i/+d2jmBo1IzQpnZoZp9CqqUTd5cyaXvDu85KIbzMc= X-Received: by 2002:a17:907:98c:b0:bad:255d:b5bc with SMTP id a640c23a62f3a-bc56df1b69emr1313616466b.39.1778490172718; Mon, 11 May 2026 02:02:52 -0700 (PDT) X-Received: by 2002:a17:907:98c:b0:bad:255d:b5bc with SMTP id a640c23a62f3a-bc56df1b69emr1313602366b.39.1778490171589; Mon, 11 May 2026 02:02:51 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45491ca2fd6sm25007169f8f.30.2026.05.11.02.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:51 -0700 (PDT) Date: Mon, 11 May 2026 05:02:45 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 11/30] mm: use __GFP_ZERO in alloc_anon_folio Message-ID: <99c79224ca94e63dfcbe8523cedb2a8d658bdce1.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert alloc_anon_folio() to pass __GFP_ZERO instead of zeroing at the callsite. post_alloc_hook uses the fault address passed through vma_alloc_folio for cache-friendly zeroing. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Reviewed-by: Gregory Price --- mm/memory.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 74523bc00d8a..f3f1bc66366d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5249,7 +5249,7 @@ static struct folio *alloc_anon_folio(struct vm_fault= *vmf) goto fallback; =20 /* Try allocating the highest of the remaining orders. */ - gfp =3D vma_thp_gfp_mask(vma); + gfp =3D vma_thp_gfp_mask(vma) | __GFP_ZERO; while (orders) { folio =3D vma_alloc_folio(gfp, order, vma, vmf->address); if (folio) { @@ -5259,15 +5259,6 @@ static struct folio *alloc_anon_folio(struct vm_faul= t *vmf) goto next; } folio_throttle_swaprate(folio, gfp); - /* - * When a folio is not zeroed during allocation - * (__GFP_ZERO not used) or user folios require special - * handling, folio_zero_user() is used to make sure - * that the page corresponding to the faulting address - * will be hot in the cache after zeroing. - */ - if (user_alloc_needs_zeroing()) - folio_zero_user(folio, vmf->address); return folio; } next: --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 C8F243D1CA5 for ; Mon, 11 May 2026 09:03:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490183; cv=none; b=q/j/Gh3HsBh899ia5WDhjklRsM4Cpbxo03/YzxV7y+sgG4Y1ExcuByQqykq0opAB1lGQFhz/mosFilRT8PQdqLNzhrJWmLgkYmwcpCW//WT+XwRYc2IdszHjMqF4iJWW6J05nNYmkgBxd+3zXmOND76GXWnPegYPGxXPk6h35x4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490183; c=relaxed/simple; bh=m8forpKa92wSEANoV2LwX8iYn506Fg/3SPdqojZoxqY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Sc5prl6lPPdkwBkMdmpXiyP9p8iCDdEvFyiEeJGSZLJv4G3y3I3dj6F8UwIfYgnIqdXga7o3U0Z3cv9pY8edz2F9BV31md2SnmeJFbvL/QoVOrCPH4LWQ36bf+CBLiMFFjFKCd70YjtuxrpIvaSnnQO/yCsHVwScZ2ozskSHYjo= 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=C3pC9KZc; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=k8abUbjY; arc=none smtp.client-ip=170.10.129.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="C3pC9KZc"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="k8abUbjY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490180; 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=awVRqRC+b/AmjARdxVJbu/50IYPO1xelbVaktsnFd6g=; b=C3pC9KZcjiLvACYdbpfEDhgV5zbtSl1aht1uFTTuJRGHVcnGGDNToo1yswuoiiIEoiECy5 4OCo8ct3pEntwe6PUfFNyl56QpUvBNurxQ8c6sRJOuN021a4gpC2rt3kGD9NsBUz0Lea8a N5CTLOEiGh3ibHwqnFq/VLdBxtch0T0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-XIDzvqPaP16xJPX78V8mRA-1; Mon, 11 May 2026 05:02:59 -0400 X-MC-Unique: XIDzvqPaP16xJPX78V8mRA-1 X-Mimecast-MFC-AGG-ID: XIDzvqPaP16xJPX78V8mRA_1778490178 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48a548b585cso27014955e9.2 for ; Mon, 11 May 2026 02:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490178; x=1779094978; 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=awVRqRC+b/AmjARdxVJbu/50IYPO1xelbVaktsnFd6g=; b=k8abUbjY4LEmgijcXPqupvUJ1+aPocHGYNA9ymNr5bwR0foX1nFhhU0v/20miY+esA Sql9Fs9QD6ZcuLj9VL0KVuonobYz32ffS+odgEUevKLs1pqDLLbTaonnBlIESAyrk3L5 2YknEpGkEaKunZqR6UpK0yLVNqbwQFWlPQngCBG4+ogezeGqpdkNXTzaR9GTljli6F3Q ODNjj9alNDJNfwnV5jeB0gz5vxv6ycIOLpHN8UqxkZu55ePqbCKoJZNt+y+0GtYX4e0k 0B4/khgWhrQfGywEgm/2lyobwTfM99RTnkgMXjKSKIrtsGleNVtVM2jLKjBdRR2B12bm w3QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490178; x=1779094978; 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=awVRqRC+b/AmjARdxVJbu/50IYPO1xelbVaktsnFd6g=; b=pCgQkRnTyXZlW8X9XRpNc8XP0m55BsG/OaDKsQ02PYTIZ/j9YnYMlXWXWsXHk0rwlp f0G4LFpoUlreeTTXDOcXW9Qf0/zlRY2BH5qxCW312pw6gaB+B11p199W5YEkX1BKC066 amShtoIGgWy0/8O2WdoUCqMnWCUVtxpsvFfzGe9L+hEWki6q9rfsyczg16zQLqrjyCT5 OJRRqLVutxhXIFD4Sfo2ChNSOtXau8G5lUkOVMncWNyWqIr+Kgroj7YZCfuO9OJXhF9m sDh+hrRfIWKoDzCDOI6FiQhCAXzoYL6ieFca17ouR1uEFgcB2G1Gexf8GX9w8dk9+8wz gxBA== X-Gm-Message-State: AOJu0Yy1fGgGuXszDeggqpWkMyzxztOfgGnHqied1Duzm5mWQAC5dkRR mWBr0bjqqNPaRaCL/JVNRAkKupQ6Jb6v+h/LWiImgfXF8RGo1VQ9JOcMF8lpOgWlT7xwfqJCaHP CAZmlCcAnyqAFKPNnR6JE5haWtjwG+Vx1O7My5skks2qOrX4ScIvDyV9yfb+cjUsMYi3GBueXGd 7h8P3yzxV3QNKtKMs9Hjh5MCJCszTLS/Cn94xHEbBnj8g= X-Gm-Gg: Acq92OHNmTWGYkywoIfQaBAHOhrRbH0mhsi3UEWPPvJklD/dsS5Q0DSkGuCvsHjdN+T CmA+z9wG0a1rtqwcJsIBlzORBM5Z9GLMT9DyR+EYSd/UDo2T6ISYFim8AkQ1WXEmz3QqALN/q/B KkthAjzaHirRYvPRSP/9CtlYMxWJpdX3Wokr/MXfFG25JdvWI5Jj0mMx/DcrwTxTTJpSgBO+sPA +IwICS5TFg9LqMakmwF1mD7skcrv8wJCTOSF0JBlYqafCrHm4XJeBHjYvh4ZCu/Ow1pAraEd16Y unVcvPi6Hq5sPh6kcVAjdvTJe5C5q4eEbZ4BrZqwnALKhJeFM0MkEZGoJD0oRZIc/o3QVxYtsCP 36uSjkMkFcgOBQkQwJBAsn6UQZcKumMgIFmLDyvsb X-Received: by 2002:a05:600c:8115:b0:48a:9540:1a3a with SMTP id 5b1f17b1804b1-48e51e196f9mr374461595e9.8.1778490177963; Mon, 11 May 2026 02:02:57 -0700 (PDT) X-Received: by 2002:a05:600c:8115:b0:48a:9540:1a3a with SMTP id 5b1f17b1804b1-48e51e196f9mr374460235e9.8.1778490177155; Mon, 11 May 2026 02:02:57 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6db10684sm60460435e9.26.2026.05.11.02.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:56 -0700 (PDT) Date: Mon, 11 May 2026 05:02:51 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 12/30] mm: vma_alloc_anon_folio_pmd: pass raw fault address to vma_alloc_folio Message-ID: <20ce2bd8227c0149fb205d293b47348c3ef49974.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that vma_alloc_folio aligns the address internally, drop the redundant HPAGE_PMD_MASK alignment at the callsite. Signed-off-by: Michael S. Tsirkin --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 970e077019b7..d689e6491ddb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1337,7 +1337,7 @@ static struct folio *vma_alloc_anon_folio_pmd(struct = vm_area_struct *vma, const int order =3D HPAGE_PMD_ORDER; struct folio *folio; =20 - folio =3D vma_alloc_folio(gfp, order, vma, addr & HPAGE_PMD_MASK); + folio =3D vma_alloc_folio(gfp, order, vma, addr); =20 if (unlikely(!folio)) { count_vm_event(THP_FAULT_FALLBACK); --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 A2F813CF05B for ; Mon, 11 May 2026 09:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490188; cv=none; b=KdJMHVzjqF6tbXkJf6H5CZxezXX5tbR5ET4HLfeTR6UY6e6QUsIeo7U7sHqO8PxUetTbuvsVNl3gtKlabyVj5Fb0Mf93CIUSGWECC7pR+yi/ygPouiGzAUDMyXUew83PXamtrhMnIebT0LPMWXRiC1JvhQSjDQuSJQA/U4XqlyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490188; c=relaxed/simple; bh=tkchtNB3GzzFWMQ1E0X1DKUjhQK/O579SYT7H3vP5sk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nlID6VBFEm7kTQ25IfNUwscF7TU41IEHuhDpJEN+RPUjVoSRJNyRNLslqlnvy4iOA+Lq5D2rqeZoyHuS+msqHRvN3w9DRV8RQIOXPC86C05bx8VqTWaXafcvImred2O7I3gKe6QuEui8Q1gaGBbD4uk8bz/QS/ZSzDu1BGcw5T0= 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=H4MNVfI+; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=QH4V1HAq; arc=none smtp.client-ip=170.10.129.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="H4MNVfI+"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="QH4V1HAq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490186; 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=43zcPeyEBahcbXzXBePbjbHiq0vh8NFM/GDJyyFYelY=; b=H4MNVfI+nANAbOxjiQag0VH+A4xKmgWI+w2KEds9QNrKA6Upb3RCl3H2Wrk7xECNCWiLGx 5jReJmuw/ZqVKEIIKtD6ikMK7zok51M2wTB9Su28BftPb0HfmNgeKYeB9cL36ahxbPLblQ h7sc+eQlcsIan/0VCkrgbcB9MLyyGWg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-nbmIVI2sNOuPhNHtOEohGw-1; Mon, 11 May 2026 05:03:05 -0400 X-MC-Unique: nbmIVI2sNOuPhNHtOEohGw-1 X-Mimecast-MFC-AGG-ID: nbmIVI2sNOuPhNHtOEohGw_1778490184 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-441243ba35fso3394181f8f.0 for ; Mon, 11 May 2026 02:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490184; x=1779094984; 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=43zcPeyEBahcbXzXBePbjbHiq0vh8NFM/GDJyyFYelY=; b=QH4V1HAqm4ltEnXp1aPp4goX9YPM3gvUfiC9x/bqdN7aXSD1B/lvWs+esOnvP6azki i5UmhnGYRsEsZjb3WJuNlZSU4T/hLRrFLW7rTV08ZE5HDfPsq6G8XxqauhtR8nf9XsUx BMoM8jkEwVYl8J8qyt7A8lxOHpeUkHu4e2ZxUSEofpZQLWAR13uuvAdfYYtIfUZlM/y7 JFEDB6e+esPbDqCagJddshQPBsSZGYFuBSjStGUVotqRM9rvpoD010w+LDDMA5k6JZoW 4EqlD2MyI7GSEmew+Hi09kYsw6fwWFpKcc7u9f6R8rnBlYDqciGFgwdPlwGlBRv4lseY RdLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490184; x=1779094984; 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=43zcPeyEBahcbXzXBePbjbHiq0vh8NFM/GDJyyFYelY=; b=hnHsf4BE/bwK3cYZf0Y0g8o7I1JkM7AmvHaynp1fZ/AscwGG8EJlmrVwNQczq8CiML N/jSf0W4Fu69/DmcI5Ufj5RMRF58IDEQjDk5jgg+8BGjKwEFWtXEk4IrSbbxGghkJlbQ u5DXiX7C1M6j4FMRspBqvlosNdUrwOkYbAYBLRO+3VIXowvuJl8RRd93QwXiCpcJNCpc xkHCEKbmKh1yBb9PvKWsPg9I6+pmW80AFJa8ZhkGQ0xXNup/OJWX22oxZR8D4TQj5Lmk p3WRYYR5LMfg5AXqxIe91VmF5XsudProBacWrE4raXpSb8P7J9qXVdUCph82Z5kkV8/C gi7A== X-Gm-Message-State: AOJu0Yw03BT8j5P8bSNQlP0mkL55FhEINS1uFHJz4yWCCzxvaYmVT3iI gRD97JNNOvKAVelV7XvmzCe8nsbwE5H+Gh8D4V+X4afOplPy91FHemB9io5vZrmwtJ0VV36kb4l 0kEPC056iXqZ+L8wJYQVBoo9PZ9lc3VAxu0HfSsYHOAAyjNJDdIpGgLK6kPE5bDWZdK11DLxgn2 OgRx5uy7e9lS2u1aS37EU+LWrxpSedBbYgaMKuWayjCtEBEg== X-Gm-Gg: Acq92OHs1YIKkBe0rL+t46KA2S2mRB6jdVB9v3OBM2tb2KMC2wrz5p9jc00BN4O0kRb uHcBU0ZXs+3cbCbJUBvI/aOpYNVC20qFD9tk3pOxsosXhQWPvt8DA+tNT96R5jbMzGFaEbZQCCm a8nf8XlDWpfyV5Zsa+7UH3w3YiaAbMY3xNkhTYWHvCI6C/XyLmAFzG+kjsgmkVI+wgkGwGOrFqJ s5cuA6jDsA+j0A0DWrMdyafPvLpRS1ZCR3qCw4pA6hEFf7g4WrogmJMc6oFu7bOjf6gj1sVGOdo HQ1uqoxWAAos5Vf29/ESttqwgGCEQVtg7l8qPltzYxchEnvO2wUZ0VR8+LRnJWyNDb5SQaG3eOx x/PPrAsXWyV2jOV7PWbpRESvgNT9gCZYLyS2H/x3kjTnELTwxxmE= X-Received: by 2002:a05:600c:8010:b0:48a:5339:ef0e with SMTP id 5b1f17b1804b1-48e70687eabmr138059905e9.3.1778490183511; Mon, 11 May 2026 02:03:03 -0700 (PDT) X-Received: by 2002:a05:600c:8010:b0:48a:5339:ef0e with SMTP id 5b1f17b1804b1-48e70687eabmr138058895e9.3.1778490182719; Mon, 11 May 2026 02:03:02 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a6470sm20880966f8f.7.2026.05.11.02.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:02 -0700 (PDT) Date: Mon, 11 May 2026 05:02:57 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 13/30] mm: use __GFP_ZERO in vma_alloc_anon_folio_pmd Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert vma_alloc_anon_folio_pmd() to pass __GFP_ZERO instead of zeroing at the callsite. post_alloc_hook uses the fault address passed through vma_alloc_folio for cache-friendly zeroing. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Reviewed-by: Gregory Price --- mm/huge_memory.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d689e6491ddb..9845c920c29c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1333,7 +1333,7 @@ EXPORT_SYMBOL_GPL(thp_get_unmapped_area); static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma, unsigned long addr) { - gfp_t gfp =3D vma_thp_gfp_mask(vma); + gfp_t gfp =3D vma_thp_gfp_mask(vma) | __GFP_ZERO; const int order =3D HPAGE_PMD_ORDER; struct folio *folio; =20 @@ -1356,14 +1356,6 @@ static struct folio *vma_alloc_anon_folio_pmd(struct= vm_area_struct *vma, } folio_throttle_swaprate(folio, gfp); =20 - /* - * When a folio is not zeroed during allocation (__GFP_ZERO not used) - * or user folios require special handling, folio_zero_user() is used to - * make sure that the page corresponding to the faulting address will be - * hot in the cache after zeroing. - */ - if (user_alloc_needs_zeroing()) - folio_zero_user(folio, addr); /* * The memory barrier inside __folio_mark_uptodate makes sure that * folio_zero_user writes become visible before the set_pmd_at() --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 D9FDA3CF680 for ; Mon, 11 May 2026 09:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490195; cv=none; b=TmccWS3doiRhvkK0v1+aao00MrUNP3m76DoQ79mr5rbTPCEm+KCD9FjyXXwSKVhhw25f+/yU66CpOReg+3BhzETiZ3L4bkH3acax6ttSDNjRTuCntNXvLJa2XFcpYIPWn1ah7oN6l6aCOEhBw8o8vkrqUU44BzNlAcCZsUFAkSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490195; c=relaxed/simple; bh=nhIdqHx7RVXN0ISM6az/8nnv+4RiBG53oCOcvaW262c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BwF6Kd2QolRW0sHn8GzYgZHC2eKH1hqKoCK7BMlwZVOW1HHxuIdIALwTc4M4ZPt+pZbl1wGeiknxGf1UstEQ0LoBuqIHBO6YgvumDjWg4O8mLzD0Fd3KC7flxb0RScEMWbkLg2sFqTyk0e05TaYMYZ0PWLSyJrq91YQ7SWy+J10= 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=Ykh8fDox; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=PBcS8Rzy; arc=none smtp.client-ip=170.10.129.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="Ykh8fDox"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="PBcS8Rzy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490193; 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=HSkauV/IjsYyN3rKw556EWRQycHO+B2Bstj+Uf0KUNg=; b=Ykh8fDoxnf4+ZNlLnmAkl2num2+of8/76x+M1g349ljRI0F/bbNZ79Ty4pMYfd928BDjSZ FQ3Kl/2Vv1BeeUWQzrGFRiMOruh06tubOy+lAM2/mJqGRfWQhejYk9JXWwDYqWVp9mBR3+ LompUEDZwKknGWQBjjr+ZmpcLWcJiEk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-Ax4VEu98Mi-16_FVexr6HQ-1; Mon, 11 May 2026 05:03:10 -0400 X-MC-Unique: Ax4VEu98Mi-16_FVexr6HQ-1 X-Mimecast-MFC-AGG-ID: Ax4VEu98Mi-16_FVexr6HQ_1778490190 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48d05e7b117so32857495e9.0 for ; Mon, 11 May 2026 02:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490189; x=1779094989; 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=HSkauV/IjsYyN3rKw556EWRQycHO+B2Bstj+Uf0KUNg=; b=PBcS8RzysKw7k3rjHLH8cUzIldmdNA4hRB7dD34Cida9BWh933lvTK2ryz1fvXvzgR R+q4LdC0t3SnmIaUucP6RwlOrA/5QaJGZ2rL7r+QBQP/N5nJvKjE6GTZF4Z/vqFztG9i M/0Atg63rSopZ1k8bRLmJulXzZj6zpTjZJyf64VdtaI3+lAOFPF1HqEBoFGk62PUmGir 5yZth48xzdqv1iXEs+fW03HTExtp05hyMaWHJR6DQwU0ZZWwyWq+VMyO+GtASMk7NpbV WNRFop3lZrLo7B8yMjyVGG4s/hoO8bQTX+ohBue/eF0BIgkjmSnaeBFo2dTPoXmXC2o/ XcOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490189; x=1779094989; 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=HSkauV/IjsYyN3rKw556EWRQycHO+B2Bstj+Uf0KUNg=; b=igsvlWsTuVHDRT21at0qgHv8nNcEFMwuLZgcF0Zc1+H7L0YpMvAalXg6pHm+hhEG+N qBGxzhzndq8tZncquTcHhoKbX2PSfgXtIl0naC7ogCwuBVseeUifNUWZYUAWfXzsL7u4 M8tBG8of3egiXt7gSWXY/R8CzwWf79xybYwFRXyn36ZXKiklZ+YN6M7DZ0jeXJl8hMkl YOiWhp2XR6B91fsb3uYQKS8VIUhASg47m11JGmQRbt6OwHkTyhDTBfiRt6LpizSKTVLF a795S0H85xqCHEghA9dwidOy2iap/bLXv6vfVfGwNQFFRjvKbHVlJIzYs6M0tG0mIqN4 iPIA== X-Gm-Message-State: AOJu0YzrHfJzCzNvrTpVfQzfqK5ryTABurcs4QdOVgrS77b6OfnjcSID k3vW1IY5zZo0AZLOIZ17LjDTsp8sd0kUNfHH4kMhlwDK3A1o23NPWhxAhNTXhAoPV6kVu+STVMF B/Bsi6xc84gK4fKRxvHSlWagpRvlNlHgH9YyzXSBf3FjoGISMVu2cRg1fCUpvHaffzo34EweVxq 3Lcs9wPPbAGFcC7LlFG1jxsV5yzKorfhXgf2uJN1XgUNc= X-Gm-Gg: Acq92OEiwGlYB0MH0bJSEwaQmOz+y5TOHsht1snc7aHH9DFZ3GE3ixy1hp0ntU2Z/d3 TO3XHlldO4WP/L6PoQO1DP5Tl7LQDuGJgEmxOfKJbkIqHb4MQThTVbZsVLYrMqvbobgP1P7ms9C hVn0Wdm9gpieVy7AiNgv+FfIdPSTbRbM/aUEnWo2yV7P7TdzxPrPBKv+fGli2Q7vGxRx7RauPIO /1iTvHtb7zRc307LSAyCZr4MQd1Vxn7IPalmdSbctYRQ9aDTeSjoW/vQVIPAuexR2QrT55PJ+AU K+xw87aOUWezDUlOujX/iPtQkBc+oWajUHslVynPrMbp0FJNjbIfKL66W8Hf4GMsv4VvKU3fIbE VJ/SKR/ySN9i8kOTsA6Njq4B4qvrejgBosdsCg64J X-Received: by 2002:a05:600c:a110:b0:488:ae6c:42c6 with SMTP id 5b1f17b1804b1-48e51f2e8a3mr329714795e9.14.1778490189023; Mon, 11 May 2026 02:03:09 -0700 (PDT) X-Received: by 2002:a05:600c:a110:b0:488:ae6c:42c6 with SMTP id 5b1f17b1804b1-48e51f2e8a3mr329713385e9.14.1778490188196; Mon, 11 May 2026 02:03:08 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6d895781sm104533135e9.0.2026.05.11.02.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:07 -0700 (PDT) Date: Mon, 11 May 2026 05:03:02 -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 resend v6 14/30] mm: hugetlb: use __GFP_ZERO and skip zeroing for zeroed pages Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert the hugetlb fault and fallocate paths to use __GFP_ZERO. For pages allocated from the buddy allocator, post_alloc_hook() handles zeroing. Hugetlb surplus pages need special handling because they can be pre-allocated into the pool during mmap (by hugetlb_acct_memory) before any page fault. Pool pages are kept around and may need zeroing long after buddy allocation, so a buddy-level zeroed hint (consumed at allocation time) cannot track their state. Add a bool *zeroed output parameter to alloc_hugetlb_folio() so callers know whether the page needs zeroing. Buddy-allocated pages are always zeroed (zeroed by post_alloc_hook). Pool pages use a new HPG_zeroed flag to track whether the page is known-zero (freshly buddy-allocated, never mapped to userspace). The flag is set in alloc_surplus_hugetlb_folio() after buddy allocation and cleared in free_huge_folio() when a user-mapped page returns to the pool. Callers that do not need zeroing (CoW, migration) pass NULL for zeroed and 0 for gfp. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- fs/hugetlbfs/inode.c | 10 ++++++-- include/linux/hugetlb.h | 8 +++++-- mm/hugetlb.c | 52 ++++++++++++++++++++++++++++++----------- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 8b05bec08e04..24e42cb10ade 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -810,14 +810,20 @@ static long hugetlbfs_fallocate(struct file *file, in= t mode, loff_t offset, * folios in these areas, we need to consume the reserves * to keep reservation accounting consistent. */ - folio =3D alloc_hugetlb_folio(&pseudo_vma, addr, false); + { + bool zeroed; + + folio =3D alloc_hugetlb_folio(&pseudo_vma, addr, false, + __GFP_ZERO, &zeroed); if (IS_ERR(folio)) { mutex_unlock(&hugetlb_fault_mutex_table[hash]); error =3D PTR_ERR(folio); goto out; } - folio_zero_user(folio, addr); + if (!zeroed) + folio_zero_user(folio, addr); __folio_mark_uptodate(folio); + } error =3D hugetlb_add_to_page_cache(folio, mapping, index); if (unlikely(error)) { restore_reserve_on_error(h, &pseudo_vma, addr, folio); diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 93418625d3c5..950e1702fbd8 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -599,6 +599,7 @@ enum hugetlb_page_flags { HPG_vmemmap_optimized, HPG_raw_hwp_unreliable, HPG_cma, + HPG_zeroed, __NR_HPAGEFLAGS, }; =20 @@ -659,6 +660,7 @@ HPAGEFLAG(Freed, freed) HPAGEFLAG(VmemmapOptimized, vmemmap_optimized) HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) HPAGEFLAG(Cma, cma) +HPAGEFLAG(Zeroed, zeroed) =20 #ifdef CONFIG_HUGETLB_PAGE =20 @@ -706,7 +708,8 @@ int isolate_or_dissolve_huge_folio(struct folio *folio,= struct list_head *list); int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long en= d_pfn); void wait_for_freed_hugetlb_folios(void); struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, bool cow_from_owner); + unsigned long addr, bool cow_from_owner, + gfp_t gfp, bool *zeroed); struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred= _nid, nodemask_t *nmask, gfp_t gfp_mask, bool allow_alloc_fallback); @@ -1131,7 +1134,8 @@ static inline void wait_for_freed_hugetlb_folios(void) =20 static inline struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, unsigned long addr, - bool cow_from_owner) + bool cow_from_owner, + gfp_t gfp, bool *zeroed) { return NULL; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a999f3ead852..8710366d14b7 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1708,6 +1708,9 @@ void free_huge_folio(struct folio *folio) int nid =3D folio_nid(folio); struct hugepage_subpool *spool =3D hugetlb_folio_subpool(folio); bool restore_reserve; + + /* Page was mapped to userspace; no longer known-zero */ + folio_clear_hugetlb_zeroed(folio); unsigned long flags; =20 VM_BUG_ON_FOLIO(folio_ref_count(folio), folio); @@ -2110,6 +2113,10 @@ static struct folio *alloc_surplus_hugetlb_folio(str= uct hstate *h, if (!folio) return NULL; =20 + /* Mark as known-zero only if __GFP_ZERO was requested */ + if (gfp_mask & __GFP_ZERO) + folio_set_hugetlb_zeroed(folio); + spin_lock_irq(&hugetlb_lock); /* * nr_huge_pages needs to be adjusted within the same lock cycle @@ -2173,11 +2180,11 @@ static struct folio *alloc_migrate_hugetlb_folio(st= ruct hstate *h, gfp_t gfp_mas */ static struct folio *alloc_buddy_hugetlb_folio_with_mpol(struct hstate *h, - struct vm_area_struct *vma, unsigned long addr) + struct vm_area_struct *vma, unsigned long addr, gfp_t gfp) { struct folio *folio =3D NULL; struct mempolicy *mpol; - gfp_t gfp_mask =3D htlb_alloc_mask(h); + gfp_t gfp_mask =3D htlb_alloc_mask(h) | gfp; int nid; nodemask_t *nodemask; =20 @@ -2874,7 +2881,8 @@ typedef enum { * When it's set, the allocation will bypass all vma level reservations. */ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, bool cow_from_owner) + unsigned long addr, bool cow_from_owner, + gfp_t gfp, bool *zeroed) { struct hugepage_subpool *spool =3D subpool_vma(vma); struct hstate *h =3D hstate_vma(vma); @@ -2883,7 +2891,9 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, map_chg_state map_chg; int ret, idx; struct hugetlb_cgroup *h_cg =3D NULL; - gfp_t gfp =3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; + bool from_pool; + + gfp |=3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; =20 idx =3D hstate_index(h); =20 @@ -2951,13 +2961,15 @@ struct folio *alloc_hugetlb_folio(struct vm_area_st= ruct *vma, folio =3D dequeue_hugetlb_folio_vma(h, vma, addr, gbl_chg); if (!folio) { spin_unlock_irq(&hugetlb_lock); - folio =3D alloc_buddy_hugetlb_folio_with_mpol(h, vma, addr); + folio =3D alloc_buddy_hugetlb_folio_with_mpol(h, vma, addr, gfp); if (!folio) goto out_uncharge_cgroup; spin_lock_irq(&hugetlb_lock); list_add(&folio->lru, &h->hugepage_activelist); folio_ref_unfreeze(folio, 1); - /* Fall through */ + from_pool =3D false; + } else { + from_pool =3D true; } =20 /* @@ -2980,6 +2992,14 @@ struct folio *alloc_hugetlb_folio(struct vm_area_str= uct *vma, =20 spin_unlock_irq(&hugetlb_lock); =20 + if (zeroed) { + if (from_pool) + *zeroed =3D folio_test_hugetlb_zeroed(folio); + else + *zeroed =3D true; /* buddy-allocated, zeroed by post_alloc_hook */ + folio_clear_hugetlb_zeroed(folio); + } + hugetlb_set_folio_subpool(folio, spool); =20 if (map_chg !=3D MAP_CHG_ENFORCED) { @@ -4988,7 +5008,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, st= ruct mm_struct *src, spin_unlock(src_ptl); spin_unlock(dst_ptl); /* Do not use reserve as it's private owned */ - new_folio =3D alloc_hugetlb_folio(dst_vma, addr, false); + new_folio =3D alloc_hugetlb_folio(dst_vma, addr, false, 0, NULL); if (IS_ERR(new_folio)) { folio_put(pte_folio); ret =3D PTR_ERR(new_folio); @@ -5517,7 +5537,7 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf) * be acquired again before returning to the caller, as expected. */ spin_unlock(vmf->ptl); - new_folio =3D alloc_hugetlb_folio(vma, vmf->address, cow_from_owner); + new_folio =3D alloc_hugetlb_folio(vma, vmf->address, cow_from_owner, 0, N= ULL); =20 if (IS_ERR(new_folio)) { /* @@ -5711,7 +5731,7 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, struct vm_fault *vmf) { u32 hash =3D hugetlb_fault_mutex_hash(mapping, vmf->pgoff); - bool new_folio, new_anon_folio =3D false; + bool new_folio, new_anon_folio =3D false, zeroed; struct vm_area_struct *vma =3D vmf->vma; struct mm_struct *mm =3D vma->vm_mm; struct hstate *h =3D hstate_vma(vma); @@ -5777,7 +5797,8 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, goto out; } =20 - folio =3D alloc_hugetlb_folio(vma, vmf->address, false); + folio =3D alloc_hugetlb_folio(vma, vmf->address, false, + __GFP_ZERO, &zeroed); if (IS_ERR(folio)) { /* * Returning error will result in faulting task being @@ -5797,7 +5818,12 @@ static vm_fault_t hugetlb_no_page(struct address_spa= ce *mapping, ret =3D 0; goto out; } - folio_zero_user(folio, vmf->real_address); + /* + * Buddy-allocated pages are zeroed in post_alloc_hook(). + * Pool pages bypass the allocator, zero them here. + */ + if (!zeroed) + folio_zero_user(folio, vmf->real_address); __folio_mark_uptodate(folio); new_folio =3D true; =20 @@ -6236,7 +6262,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } =20 - folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false); + folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false, 0, NULL); if (IS_ERR(folio)) { pte_t *actual_pte =3D hugetlb_walk(dst_vma, dst_addr, PMD_SIZE); if (actual_pte) { @@ -6283,7 +6309,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } =20 - folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false); + folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false, 0, NULL); if (IS_ERR(folio)) { folio_put(*foliop); ret =3D -ENOMEM; --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B847A3D093F for ; Mon, 11 May 2026 09:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490200; cv=none; b=j3UUnnqkctb9U9VH94iaDngXB0wQ4iXEla7oCexQ5y6n+g4glzYelCjT2nT/zlLd7ibqI7LJ5cFcow9XRvhcK0pbIIZWmt4/w3/lD6xp6233R7Q9KpVzqE/e/FV6FzApqp7Q2RIXGMGc9ryULK/Evz6oxCzy2X+RPKX9/GZDKkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490200; c=relaxed/simple; bh=uae5V1T54mMZVBXPfWqdPxGd95+bgq8V6VITT9f8SnY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X86lupHYpjWd5rKYhGPzrpM70bAies1VJIM84ztbVhT3MA08QY500h1vHA8QIeUhoR/fPrp8CcT9e5BtmVuJYU9CmYM38BH3cj22gt43k6Ib1wD/SFbzWV2AbVZ1eoU6HFSCbxiwNdUXBcdXewuN3dS96a0oSJfVb6KWX6vxfEY= 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=XJYOY5dg; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=PAHmF6Go; arc=none smtp.client-ip=170.10.129.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="XJYOY5dg"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="PAHmF6Go" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490198; 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=q0Jd/7EvCnA8N9ANiNsWM9FOCa/+r1oqSAVkRa3NTmw=; b=XJYOY5dgS3VuSUmkVHyLr1hWvTIYMlltXarvz0c+xBmHG03emWLYEDkIcqHTqpngpNYsKN WD4TOzun9VrGnt6ycPe3DbBqOh83M06Y+qKjeufux0MMwhUrLLBlZ3lzl0pXwwFtMWGfoH hp7evnhPGRdx8YyWmiP2hD9QhQ0vMwc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-29-gis7nvr5Pb2TQCLQMl4r5g-1; Mon, 11 May 2026 05:03:16 -0400 X-MC-Unique: gis7nvr5Pb2TQCLQMl4r5g-1 X-Mimecast-MFC-AGG-ID: gis7nvr5Pb2TQCLQMl4r5g_1778490196 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48d127eb013so22819255e9.1 for ; Mon, 11 May 2026 02:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490195; x=1779094995; 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=q0Jd/7EvCnA8N9ANiNsWM9FOCa/+r1oqSAVkRa3NTmw=; b=PAHmF6GouH7mjwbgv/R/KBpVhZWAtw5MP95qpCq0bjXnfLxCJst0MZrLA17ljSevbY 9yQluwn08UKb9ObD9/WDuGp3Xk2YakY8AqENDt9r+f/S6ZrZ5xRsvMmoYlFCI3+uQt2M dGBCFebrbGf98EJSgpAVSix0+1VBKupa2IJlFrjjCBHJ7RVFuNmx0BJEH94srB9cwst7 wXAYVDCo/aABnRrYXyUh44xjC/AGCdn1kghGcH5g1PB2mXTt2c6mvBekBBwV8F0AAS6t AqQml4wFHmGXy89sPvgjZFl1r1zm32PR9p8DOkYWjWw4A6LQKcJX4KQxFDJN5Sr7zLQs XEvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490195; x=1779094995; 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=q0Jd/7EvCnA8N9ANiNsWM9FOCa/+r1oqSAVkRa3NTmw=; b=GSU/G4jgZWQtukVMXGtz1zYwOY4B9h8VXuCuku6siukP/W+X3sBwGZB2OzeVjncGbK y6jpF8yFDzYbERJg8e8bkWSTvq4KmaIu5A1sIZ3T1bfQUq6r5A+rFNEp1jK8vJZibG9l tjjn82IB3pUt2WXfB/7VZw/5vz1/btKWpPzulFw/VCbcQjVreAr2BxglgS5ZxMZGoSoH Xp2DBF3zEp1BFYiMxpjJJpuw0tp8GdSgnNzS7FYS+XCmOXhL38icbtOmbmuePbu1Qxqv 9W3rrjRDgJ2kfrVNRyO20EzNA616/La8aQUBsM6UpvHn4nK+uTr5PmUqhmfbnZcw+H+I qFiw== X-Gm-Message-State: AOJu0YxIqETP/6zpFH02NUoqPFTcNX7k/FEH7n7mskgLizgAU4aRdB7A 3skq1VaK34tKxjYaJA34VP0qe7KvishLfgth1uB8fHcmOl1tu7KSQn6UXO2J9BdNBeZutU4arhO fE3vGQbjFTLaBrr79QzksBDJ6DfWHWfqCssE/nuEFfO3SdzPL4Z3Q0BvSbX5n0pUcq2DaVaUpig pIQ54jDq4KfBHjj+Pjdlr3ltyqgLl1nkdGXB/pRlCsW1M= X-Gm-Gg: Acq92OGkLI2LhHgkGeNGTEX/p+VavxPrdVHCUJmjASQ2SCkJf7lW8WKYghnj/MjIqOW uiH8ZLBEZHKe0WZfgXHCCBqXQgpz8LGqQlSLLRIr5hA8321RbQ1sHGHxjkjfM81cYRu3Q08V7hk pNuxDOVFkrf4XnQ0uxzhA6yDCe2F+ht9s58ZbyvEhrTDPZvDnNam6TWlDBmfEuwAM6fIvog5Awv gYeaReuP7w3vImQVfpv6HJPPLgRUoJZuzpQcTMUST6gRoRU86NJH/gbzzUE7+bJEONsalb00S5/ uAqsgh1kc43K3zLTiBKm8EjNAjTFim8eO3AWqAWAt39DibQgHcmvLUJ28xWpy5c7/tl+qwTVH5Q rhDhUl18lYGYNLE6RoBJTPmSa+HkoyRD3jLUtKKZA X-Received: by 2002:a05:600c:4355:b0:48e:85b4:ac7b with SMTP id 5b1f17b1804b1-48e85b4ad2dmr11170465e9.18.1778490194131; Mon, 11 May 2026 02:03:14 -0700 (PDT) X-Received: by 2002:a05:600c:4355:b0:48e:85b4:ac7b with SMTP id 5b1f17b1804b1-48e85b4ad2dmr11169355e9.18.1778490193392; Mon, 11 May 2026 02:03:13 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6d8946a5sm98618955e9.0.2026.05.11.02.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:12 -0700 (PDT) Date: Mon, 11 May 2026 05:03:08 -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 resend v6 15/30] mm: memfd: skip zeroing for zeroed hugetlb pool pages Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gather_surplus_pages() pre-allocates hugetlb pages into the pool during mmap. Pass __GFP_ZERO so these pages are zeroed by the buddy allocator, and HPG_zeroed is set by alloc_surplus_hugetlb_folio. Add bool *zeroed output to alloc_hugetlb_folio_reserve() so callers can check whether the pool page is known-zero. memfd's memfd_alloc_folio() uses this to skip the explicit folio_zero_user() when the page is already zero. This avoids redundant zeroing for memfd hugetlb pages that were pre-allocated into the pool and never mapped to userspace. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/hugetlb.h | 6 ++++-- mm/hugetlb.c | 11 +++++++++-- mm/memfd.c | 14 ++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 950e1702fbd8..c4e66a371fce 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -714,7 +714,8 @@ struct folio *alloc_hugetlb_folio_nodemask(struct hstat= e *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask, bool allow_alloc_fallback); struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_= nid, - nodemask_t *nmask, gfp_t gfp_mask); + nodemask_t *nmask, gfp_t gfp_mask, + bool *zeroed); =20 int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *m= apping, pgoff_t idx); @@ -1142,7 +1143,8 @@ static inline struct folio *alloc_hugetlb_folio(struc= t vm_area_struct *vma, =20 static inline struct folio * alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask, gfp_t gfp_mask, + bool *zeroed) { return NULL; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8710366d14b7..03ad5c1e0655 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2205,7 +2205,7 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(str= uct hstate *h, } =20 struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_= nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask, gfp_t gfp_mask, bool *zeroed) { struct folio *folio; =20 @@ -2221,6 +2221,12 @@ struct folio *alloc_hugetlb_folio_reserve(struct hst= ate *h, int preferred_nid, h->resv_huge_pages--; =20 spin_unlock_irq(&hugetlb_lock); + + if (zeroed && folio) { + *zeroed =3D folio_test_hugetlb_zeroed(folio); + folio_clear_hugetlb_zeroed(folio); + } + return folio; } =20 @@ -2305,7 +2311,8 @@ static int gather_surplus_pages(struct hstate *h, lon= g delta) * It is okay to use NUMA_NO_NODE because we use numa_mem_id() * down the road to pick the current node if that is the case. */ - folio =3D alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h), + folio =3D alloc_surplus_hugetlb_folio(h, + htlb_alloc_mask(h) | __GFP_ZERO, NUMA_NO_NODE, &alloc_nodemask, USER_ADDR_NONE); if (!folio) { diff --git a/mm/memfd.c b/mm/memfd.c index fb425f4e315f..5518f7d2d91f 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -69,6 +69,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff= _t idx) #ifdef CONFIG_HUGETLB_PAGE struct folio *folio; gfp_t gfp_mask; + bool zeroed; =20 if (is_file_hugepages(memfd)) { /* @@ -93,17 +94,18 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t idx) folio =3D alloc_hugetlb_folio_reserve(h, numa_node_id(), NULL, - gfp_mask); + gfp_mask, + &zeroed); if (folio) { u32 hash; =20 /* - * Zero the folio to prevent information leaks to userspace. - * Use folio_zero_user() which is optimized for huge/gigantic - * pages. Pass 0 as addr_hint since this is not a faulting path - * and we don't have a user virtual address yet. + * Zero the folio to prevent information leaks to + * userspace. Skip if the pool page is known-zero + * (HPG_zeroed set during pool pre-allocation). */ - folio_zero_user(folio, 0); + if (!zeroed) + folio_zero_user(folio, 0); =20 /* * Mark the folio uptodate before adding to page cache, --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 756773CF680 for ; Mon, 11 May 2026 09:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490205; cv=none; b=bltA6piNGigGYeih53o+CE4fUxTKcaQvypwq9ZiT1+I4stAo/d+JpTgr/V6uiz98TlpsrX5vSxHRj6lpqEkMz8e2lFKa70p5bR9n2jbZO/F05Dw66tp37QzD0un+6Smjy+0eOXfCQDehc8ylWlvo2DqmYPBQK6lHl+55DOg0C4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490205; c=relaxed/simple; bh=jAEaO4JfYvTZh0h5rRrKJYMGQ45gKsBKH3AVbKj8c00=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VZBLxbmxN9J/tQpz2JlOm3ZdCYaEsTxKjBvtemybfaPaIxUoY73ya0Hy2xhlxrk2Z2i2ko1oOsQ/xoN1iwXY9m4WKdHNbrMiIM6BWAkQBsMLapaz2RYMl9VhnaGnADAiDJxra1pKOjvYxoYJPZRQ4QxGL59HPeiET9Pi0DwUBEE= 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=TkM3RQMS; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=P7Hy8+yZ; arc=none smtp.client-ip=170.10.129.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="TkM3RQMS"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="P7Hy8+yZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490203; 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=dLzVjPl4JuXWdYl/OMkyXvKlFkDQF6qpB2cxYBp2hXA=; b=TkM3RQMS4xvOuRv3OIo8ziR+afLwc14Ivt/Ed7btIO4qAVbVrfCQoisqZ2QognSDOSs29a kJB/osaM4Y78dyClWqS6eG02yNsZanRoUGrN87KLOIAgDYkHPPoMF8DNtxd7YAWXWAc+Cv DG/lalMq4tTnj8fhG+JOdZyrPSkiHoU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-BkwuNcNtMMGLOodL98jZgQ-1; Mon, 11 May 2026 05:03:22 -0400 X-MC-Unique: BkwuNcNtMMGLOodL98jZgQ-1 X-Mimecast-MFC-AGG-ID: BkwuNcNtMMGLOodL98jZgQ_1778490201 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48e79219704so7729075e9.1 for ; Mon, 11 May 2026 02:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490201; x=1779095001; 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=dLzVjPl4JuXWdYl/OMkyXvKlFkDQF6qpB2cxYBp2hXA=; b=P7Hy8+yZYQdGgAV0dBHSK+Xzt6PIK2Wg5HO/iKLPASEKfUR7UCTZtAkd8HDsOn8AwN N/eYqgbA0zPxb5uq4Ww72hhBh/zPhSPlgXJMHbNtb8bVfkGc53nuR1SmKL5kHRxFn5uR ksYgQDLAqbsYiRUk923xeh7ow4jVlPtWF6Nah/nE4aufhzEAFj10dkbSei8DlcZgKOni DuLhpoVmJ8Zii0Wo9sIii1/XNJ7i0raHQ7WbWv5QKRL16tHOb0GxDjTHiRLrqOKkx25b T74BZ9p/aknptbFAqMYTb1SeOqPGUkUK+lfQeRlMEy3fN5eRLgMJO/+2R/pm1ZGbFRa4 16zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490201; x=1779095001; 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=dLzVjPl4JuXWdYl/OMkyXvKlFkDQF6qpB2cxYBp2hXA=; b=DEOVtbsQRc35X2rXIWry1sWVG3FWGD+ysDbso0t9dKDS6VJcY4hac4bYP1N76JBVIG LGu8i9ZJxzIUEPz6F7YR3Oi9aQOhwyGvhTyHZJnYdHfBQsuQgJKXeWxKeXXD3CbRDuHY 0hSvuCgJIm5LnTREYBjHPNe75PJSwa+aVoSujkI5lWSsWXLqObWbgTjL4Vexvan/KDCG GYDzCUaez9Scu1ZV30TC6dOfkqZ2DR9T/KfXcUrEM0AdvcHkbFSYqekdE/USHvOyOEqa 3shed2z44D2ZZuAowDNXvkdgWBpyVudh9VMNc+tj9nyJGXKkxdKT8irhEY0LrPtxo4LU jMBA== X-Gm-Message-State: AOJu0Yz6y99e8D09fX0UFv8EUUaUd9A/mwgePJzRN75KXCJsbwiJnrQB wOaqSLpZLdl+R8j4fODP+ZGaI+lanYiMnpOrx6FLTgRPh9CXbkiqShChrkjCLPE/lf+lIGoopsU omzUTRDMfxMVbV+PCWtcaeU9vb85aFplfjRBop5vAieltCyT3Lwu7nID1Z1jIx0iidS30RAAz5P +4vidwfLfn6cGs421VhYFrrmBa1qHtyMjZ0LFGbq849ro= X-Gm-Gg: Acq92OEaN9IDcfcyMhT+m0RSpYPzyPiC6+aLK6pNWJUcbPwbRoX7RQEXTe+G9ySYZcJ CwUENlaquI3J9LPDP2qYVaCeEPDbyAHfxUzEaieMwqfzQE68ZdYyNQxk7vDlzBmaN9M3pVMZfnC u06+lTblJYL0HGBVy04i8aCHD/wFOX8eg6nwI4//CNN0TUJPNb2+Tyk7jcqlhoFURF2Cij8pA/y IcKiljT09anMZTK2INcOfXRQI7FlyjlPBHbjgDYsTTS3JIPJ69cyDo5cY8GoPdRqv0sw5BF2vNH 95NlzHJTffdq70be04awuQUq6mSwxBAPlJNEgPrEJAV7Fy/WisgG+N0pZ6NFMJq2hY9NxuJDbQe fYd6Tg3ti2A44VTC8g+Z1+ZlHLtMFdxmE4XEEvfAm X-Received: by 2002:a05:600d:6:b0:488:b749:8482 with SMTP id 5b1f17b1804b1-48e51f21e2amr304831835e9.4.1778490200536; Mon, 11 May 2026 02:03:20 -0700 (PDT) X-Received: by 2002:a05:600d:6:b0:488:b749:8482 with SMTP id 5b1f17b1804b1-48e51f21e2amr304830375e9.4.1778490199227; Mon, 11 May 2026 02:03:19 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6d8d4462sm80127935e9.1.2026.05.11.02.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:18 -0700 (PDT) Date: Mon, 11 May 2026 05:03:13 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 16/30] mm: page_reporting: allow driver to set batch capacity Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a capacity field to page_reporting_dev_info so drivers can control the maximum number of pages per report batch. This is useful when the driver needs to reserve virtqueue descriptors for metadata (e.g., a bitmap buffer) alongside the page buffers. The value is capped at PAGE_REPORTING_CAPACITY and rounded down to a power of 2. If unset (0), defaults to PAGE_REPORTING_CAPACITY. The virtio_balloon driver sets capacity to the reporting virtqueue size, letting page_reporting adapt to whatever the device provides. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- drivers/virtio/virtio_balloon.c | 5 +---- include/linux/page_reporting.h | 3 +++ mm/page_reporting.c | 26 +++++++++++++++----------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index f6c2dff33f8a..6a1a610c2cb1 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -1017,10 +1017,6 @@ static int virtballoon_probe(struct virtio_device *v= dev) unsigned int capacity; =20 capacity =3D virtqueue_get_vring_size(vb->reporting_vq); - if (capacity < PAGE_REPORTING_CAPACITY) { - err =3D -ENOSPC; - goto out_unregister_oom; - } =20 vb->pr_dev_info.order =3D PAGE_REPORTING_ORDER_UNSPECIFIED; =20 @@ -1041,6 +1037,7 @@ static int virtballoon_probe(struct virtio_device *vd= ev) vb->pr_dev_info.order =3D 5; #endif =20 + vb->pr_dev_info.capacity =3D capacity; err =3D page_reporting_register(&vb->pr_dev_info); if (err) goto out_unregister_oom; diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h index 9d4ca5c218a0..5ab5be02fa15 100644 --- a/include/linux/page_reporting.h +++ b/include/linux/page_reporting.h @@ -22,6 +22,9 @@ struct page_reporting_dev_info { =20 /* Minimal order of page reporting */ unsigned int order; + + /* Max pages per report batch (default PAGE_REPORTING_CAPACITY) */ + unsigned int capacity; }; =20 /* Tear-down and bring-up for page reporting devices */ diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 7418f2e500bb..006f7cdddc18 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -174,10 +174,10 @@ page_reporting_cycle(struct page_reporting_dev_info *= prdev, struct zone *zone, * list processed. This should result in us reporting all pages on * an idle system in about 30 seconds. * - * The division here should be cheap since PAGE_REPORTING_CAPACITY - * should always be a power of 2. + * The division here should be cheap since capacity should + * always be a power of 2. */ - budget =3D DIV_ROUND_UP(area->nr_free, PAGE_REPORTING_CAPACITY * 16); + budget =3D DIV_ROUND_UP(area->nr_free, prdev->capacity * 16); =20 /* loop through free list adding unreported pages to sg list */ list_for_each_entry_safe(page, next, list, lru) { @@ -222,10 +222,10 @@ page_reporting_cycle(struct page_reporting_dev_info *= prdev, struct zone *zone, spin_unlock_irq(&zone->lock); =20 /* begin processing pages in local list */ - err =3D prdev->report(prdev, sgl, PAGE_REPORTING_CAPACITY); + err =3D prdev->report(prdev, sgl, prdev->capacity); =20 /* reset offset since the full list was reported */ - *offset =3D PAGE_REPORTING_CAPACITY; + *offset =3D prdev->capacity; =20 /* update budget to reflect call to report function */ budget--; @@ -234,7 +234,7 @@ page_reporting_cycle(struct page_reporting_dev_info *pr= dev, struct zone *zone, spin_lock_irq(&zone->lock); =20 /* flush reported pages from the sg list */ - page_reporting_drain(prdev, sgl, PAGE_REPORTING_CAPACITY, !err); + page_reporting_drain(prdev, sgl, prdev->capacity, !err); =20 /* * Reset next to first entry, the old next isn't valid @@ -260,13 +260,13 @@ static int page_reporting_process_zone(struct page_reporting_dev_info *prdev, struct scatterlist *sgl, struct zone *zone) { - unsigned int order, mt, leftover, offset =3D PAGE_REPORTING_CAPACITY; + unsigned int order, mt, leftover, offset =3D prdev->capacity; unsigned long watermark; int err =3D 0; =20 /* Generate minimum watermark to be able to guarantee progress */ watermark =3D low_wmark_pages(zone) + - (PAGE_REPORTING_CAPACITY << page_reporting_order); + (prdev->capacity << page_reporting_order); =20 /* * Cancel request if insufficient free memory or if we failed @@ -290,7 +290,7 @@ page_reporting_process_zone(struct page_reporting_dev_i= nfo *prdev, } =20 /* report the leftover pages before going idle */ - leftover =3D PAGE_REPORTING_CAPACITY - offset; + leftover =3D prdev->capacity - offset; if (leftover) { sgl =3D &sgl[offset]; err =3D prdev->report(prdev, sgl, leftover); @@ -322,11 +322,11 @@ static void page_reporting_process(struct work_struct= *work) atomic_set(&prdev->state, state); =20 /* allocate scatterlist to store pages being reported on */ - sgl =3D kmalloc_objs(*sgl, PAGE_REPORTING_CAPACITY); + sgl =3D kmalloc_objs(*sgl, prdev->capacity); if (!sgl) goto err_out; =20 - sg_init_table(sgl, PAGE_REPORTING_CAPACITY); + sg_init_table(sgl, prdev->capacity); =20 for_each_zone(zone) { err =3D page_reporting_process_zone(prdev, sgl, zone); @@ -377,6 +377,10 @@ int page_reporting_register(struct page_reporting_dev_= info *prdev) page_reporting_order =3D pageblock_order; } =20 + if (!prdev->capacity || prdev->capacity > PAGE_REPORTING_CAPACITY) + prdev->capacity =3D PAGE_REPORTING_CAPACITY; + prdev->capacity =3D rounddown_pow_of_two(prdev->capacity); + /* initialize state and work structures */ atomic_set(&prdev->state, PAGE_REPORTING_IDLE); INIT_DELAYED_WORK(&prdev->work, &page_reporting_process); --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 3B2AC3BA237 for ; Mon, 11 May 2026 09:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490210; cv=none; b=O+4mzYC3YlWLy/DLYMulqpQIzPkvh0Orbq2iCKZdQajjKAEeQecw8Khm84/FJX7keZvUnaPAU/hxPlx/fu9ErapNTL65GYoxWmk6KiFFww/sZpe2J9DNBB4UzpTVesI/fUakhgNyHGBHcl1og9+3L6xH27gJYU2/JwhtdN0PuyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490210; c=relaxed/simple; bh=jg72mm9srvK1uE2wmvtubyBWSeDnP4AXuR+h0vGBnIo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tSrGcEOjNEb4fvBVvKOPaDLEhb9IFn5ZoS48iGHj034g5rRXgTslWDFQ8HKKxOAqn002ILAXG/wzhsZJYybx+1+qx+ZfF+xBchDBcKHQMeKm/NezepLVv8X8ZIx1DdxN5XtCVfiv6St1ICF1Yw1M+J7mT2YmlwchyKQznhUOCy8= 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=IRGV2+sg; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=dIQysuj2; arc=none smtp.client-ip=170.10.129.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="IRGV2+sg"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="dIQysuj2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490208; 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=huIB05uLC0/aRI1yhZqtcpv3ok57gc+RgGl8EPTE8A0=; b=IRGV2+sgKipJEKXMKzzGCfcdgPfaH2G/rCagRDwtlJJ1rTLtJijBOFhoBj1b7nnacccVMT BcfbEcBLC9K2KwKsFoA6wP9hgs3SepWBXuhQO9k3iKizGYYZil7/3i/VDIw0wMNGjjT+bC vN3S7uilytvjklxOZF93w2vc8X4oNpo= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-8miqW0LTOKS-uD-cXkQbeA-1; Mon, 11 May 2026 05:03:27 -0400 X-MC-Unique: 8miqW0LTOKS-uD-cXkQbeA-1 X-Mimecast-MFC-AGG-ID: 8miqW0LTOKS-uD-cXkQbeA_1778490206 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-44b186b715aso2588132f8f.0 for ; Mon, 11 May 2026 02:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490205; x=1779095005; 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=huIB05uLC0/aRI1yhZqtcpv3ok57gc+RgGl8EPTE8A0=; b=dIQysuj23UoxWmU37rDE57sUaeySgwd2P+X8t5r3qS7AQicF9NtOeFKx+XjAmm4rVy knDB5VfxjqD0costK+WzhoSzniyUk7Dl5HkRRaYstm6xNwUePzFDmFwWqoznDUQZqXnM /VZQC7gvW6nJQNBt3rcbcI9X8CyG7R11Iv5MSLWjB3SY5u6EOvDYLQelbtk4HjUSmW2I JmnonoZTAT91i2cf9Vm24TD7r0KG9OonO8mu5qTE8OXlBLWEr3/6mu8Ds066BdsBA+aO PupAsjuk5ELj1xoJt1jxIkTUVDwI9cmERUtOmtBm+2fE3YoRzebJTTk9wC8OYh9+AV/C uu2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490205; x=1779095005; 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=huIB05uLC0/aRI1yhZqtcpv3ok57gc+RgGl8EPTE8A0=; b=oR4OKBBHsYqGDgLL+eAHg0pfJpk0GGPlwKSPQX7R2/nSMty8qIPfsmTRT9v57YxjBx u6xTeK4Pa3oddltCVTDgzIo2Rg+lVQWd5cFkptdA+IPLuffUjY440z5bPwuqXrylQFbH noB22vE0b4SBce5xO+RRIyZueJU9/xIvfujNo/cm1MQ1efm6trBAUelfvYjux7wnLlcf nVqFVdgPECB/obKBoUmYkCUt3n85jQ7MhqVNM1kuNGEmRbSJkjQ4pBgNTWDcxFwo4/tv vVAIU7Wbl/1i2kCtMO1ytTtuSbBQOrpWQ/HMX3vlnJwBrLyEWR4KBGQUpycl15/iAnmJ OUAA== X-Gm-Message-State: AOJu0YwUUNSWiOPza1fJiOFTWHAG9rPETCncQkUExNXx98UOFZTUQUwH W0OXWhUDDGqTe80wWHUuou5WOmgPJYY5331gZyzaRxyzvx8Dr/0i2bIMfhX2yfpF7uca//i1pRU s4T3eCSYNfS+FlhnFuSa0ahXfqhWaSYewA8G2+K4LBvXz9yGwBAgduIYktoTXqVXt8RlyTi8Epo 2bdX4fLhuyr8KUr8RwaHUuSGp5Ztuvh884lKYvb+VrMjU= X-Gm-Gg: Acq92OEwrbh8q6A7vjhhUR/U7gb2c9kSb4ZpbtvrTiudhHD+0TrDQiZkRMJ2N82wzn0 ZMrx7Jee7aksfI2df1t1MUnpmi7rYE4SFjB35ERnHzq+VeXpAY0MQcQiKbf/XPIECU7rIWGqkIE 1NxgJ5oE75ghZcHrDEMXoijZOvqGER10xsQF6yTv8C6ut27q0J2WMQKFZ3BlKtz+7jj+VjAAUzd mq8rutjNwRU7b9JCg5vw1dPdxiXIOfTIu7nnDcc+BY3ZlABMR3XvfKSLJK/UT7j8yd0FUb1YD93 CjM5oREznEBCTcp6pOldtH4aK/t4y8GYrH1opEBvtEk9rRrOG99oixUPVzEMJ/4hmll4OHpqOBA pXXqwMrLGgq0+VVdVku9EMzGv2wdYNAdTMEIZ901z9JduO4qMHag= X-Received: by 2002:a05:6000:26c2:b0:43d:70de:1c71 with SMTP id ffacd0b85a97d-4515b61a7a5mr36392558f8f.11.1778490205407; Mon, 11 May 2026 02:03:25 -0700 (PDT) X-Received: by 2002:a05:6000:26c2:b0:43d:70de:1c71 with SMTP id ffacd0b85a97d-4515b61a7a5mr36392444f8f.11.1778490204503; Mon, 11 May 2026 02:03:24 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-458b3664e3esm8476641f8f.3.2026.05.11.02.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:24 -0700 (PDT) Date: Mon, 11 May 2026 05:03:19 -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 resend v6 17/30] mm: page_alloc: propagate PageReported flag across buddy splits Message-ID: <6d98a35c94fa44b550afa66923c620511e2826f0.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a reported free page is split via expand() to satisfy a smaller allocation, the sub-pages placed back on the free lists lose the PageReported flag. This means they will be unnecessarily re-reported to the hypervisor in the next reporting cycle, wasting work. Propagate the PageReported flag to sub-pages during expand(), both in page_del_and_expand() and try_to_claim_block(), so that they are recognized as already-reported. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 842f5080d728..76f39dd026ff 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1699,7 +1699,7 @@ struct page *__pageblock_pfn_to_page(unsigned long st= art_pfn, * -- nyc */ static inline unsigned int expand(struct zone *zone, struct page *page, in= t low, - int high, int migratetype) + int high, int migratetype, bool reported) { unsigned int size =3D 1 << high; unsigned int nr_added =3D 0; @@ -1721,6 +1721,15 @@ static inline unsigned int expand(struct zone *zone,= struct page *page, int low, __add_to_free_list(&page[size], zone, high, migratetype, false); set_buddy_order(&page[size], high); nr_added +=3D size; + + /* + * The parent page has been reported to the host. The + * sub-pages are part of the same reported block, so mark + * them reported too. This avoids re-reporting pages that + * the host already knows about. + */ + if (reported) + __SetPageReported(&page[size]); } =20 return nr_added; @@ -1731,9 +1740,10 @@ static __always_inline void page_del_and_expand(stru= ct zone *zone, int high, int migratetype) { int nr_pages =3D 1 << high; + bool was_reported =3D page_reported(page); =20 __del_page_from_free_list(page, zone, high, migratetype); - nr_pages -=3D expand(zone, page, low, high, migratetype); + nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported); account_freepages(zone, -nr_pages, migratetype); } =20 @@ -2300,10 +2310,12 @@ try_to_claim_block(struct zone *zone, struct page *= page, /* Take ownership for orders >=3D pageblock_order */ if (current_order >=3D pageblock_order) { unsigned int nr_added; + bool was_reported =3D page_reported(page); =20 del_page_from_free_list(page, zone, current_order, block_type); change_pageblock_range(page, current_order, start_type); - nr_added =3D expand(zone, page, order, current_order, start_type); + nr_added =3D expand(zone, page, order, current_order, start_type, + was_reported); account_freepages(zone, nr_added, start_type); return page; } --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 2BDE43BBA09 for ; Mon, 11 May 2026 09:03:34 +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=1778490217; cv=none; b=b2CkiOwiCfwOrirM3+tyLWeKzy9XWrlD5ArAkao2RkJYXwxiqvyFvFUtGd3eNnVuaxw3wnA6k3Y4LF3HFUkGG95TSUYE+5BbgPCAYwZfsk8ZJvzI+cIPgs+10FBF1nwzNh2OJVOmj+SRKgL6ONeL5/CaLK+EQJLdBpuai5mIbu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490217; c=relaxed/simple; bh=2ddnfhFFRPTce9J7vQ0Jy0dRt3hpxsOUcfeczlfSXes=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N/Udl4Qp2lnCSFWzTQAVDVt8pf4hcYpytDiQzJg5v+996JnZTfKXy7OZZumtiwBY9C4k3f/EQisyBibTbgH7adn2q0/v3Ld+jlxsoDYLhaEhH450efjEinVlVsHUDYKdSCGXDwbkDjS6KOAwodIv34cVqSsRO+0AyiRa/QKamYY= 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=UwrNIo3H; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=bc9StOMn; 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="UwrNIo3H"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="bc9StOMn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490214; 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=+7pKWc4JWD9TR0gt2XZNvXhAZcErXVmSBtqXvun1gtY=; b=UwrNIo3HqoUT+4+xJDfwAZ8vrjG7MmKe1pTdIBt9FXFvWK+CnklYjuon34go1oy3xsiymj YxEHa8KPPPaV6jkhxzsZZbVtaY1++SHvv8yZ1oAfWjARrlrVIoncj6GjlKHQHvsuSHZj9G +z+9DZ2Mpd5tQMO9Caun2AJsQQp6BtI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-510-J27GxnRRNEC3DSfj-xR9qQ-1; Mon, 11 May 2026 05:03:32 -0400 X-MC-Unique: J27GxnRRNEC3DSfj-xR9qQ-1 X-Mimecast-MFC-AGG-ID: J27GxnRRNEC3DSfj-xR9qQ_1778490212 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48d035e8593so27919875e9.0 for ; Mon, 11 May 2026 02:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490211; x=1779095011; 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=+7pKWc4JWD9TR0gt2XZNvXhAZcErXVmSBtqXvun1gtY=; b=bc9StOMnrtjnCIyi04yZrZ2VuTsr+vbJY/KXip0XrqBhPgPiTyhN94zflGmhJVZqUy tWMMOMsZG1d8NXg6p0opCiImck7D6d7NcaOF55OAgFXSY9duWvxWV3jgiwyJFrZ71nYX 0rtFuHJnCsmb1mX5ry1Xov9636norH8SjzfPR4bD7LTk+A7Ss+8uOTqrtg4R2KSq9oz2 ubEZm3/y9ncGkz3n+7Ch+oqYLWSa+tcwjMK0ad2udEEtVizZU8SF5XczcNp/uvW1pao4 U3NaZIBG4RyWrv/5AKZ14WvKNeZVsskV40MbLWsphQRfsIobpxocJ0MG53Si/HlZ/uJv tjnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490211; x=1779095011; 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=+7pKWc4JWD9TR0gt2XZNvXhAZcErXVmSBtqXvun1gtY=; b=ex1VfpqnkcFhNoFhvHWcetyqcG+vwXKftxQkDib54I1nH077pqNzTHmeBe6O+kb9Un plh3gdW9jVFZ9c+5xt2MDJAbm1P9FtkqJi87shwlsOtHXaNQWAyGQVAwhPsrGTgCmF9Y i32m55WFz5n9s8DRoyuM2g5KnEDF0Q3GA8MPTs1eR5O7qOLNpBlToY0YNYG8ATsy1eS3 eb1KBzFXx/Ar6K7bWDKfXwIfY9p1Fb2OgbpZBisXD3NFDRnOmv2iqaw0NNYVmbKtc+A/ DC3zAcCybeKKK00jXT/MUmV7x0NywQhpotUo93L2XPtjN5YfW2MMh+64fAzt0gtKLhfA vd0Q== X-Gm-Message-State: AOJu0Ywhqh2pk9KmdSWuCRMd7YisBvR4B08RXyBYoJgBbjskQnavPEaU 7ocyrtUVFbwNDkXHSxOTq2Fzz4v8KsZAzTX604xtEYVRnBuOnQQxOCOniOPHmPMGSq04w0CKMpG YvKsVAB2eLUUGzrca1QFoHz4N5h9iQ0VerJ/cABDcNvOZcBgRw5r4prPefsPd9FyB4/epEqFf19 FzXmOfVFOj+dujhVWnIUOgB9hLh406W+qcCULuRhUNOUM= X-Gm-Gg: Acq92OE1lotT9ave8OvLrVZ8ZI0plL7hHYtWfZPDGPD209nWEDKVOps6JWFARDFOJW2 wvoWYjOg0Umu4Q6cAcwBNYwLsjSYqZXAg4C3g/vN4fCDxrIL+1PFvVjGsZDEQTF6Lx42qlPhFh/ SxsS7R/09n8gcN1Iz5dW2lNnpEjMTTV3l+EFWCb4X0V3F3aDmqoGT+cT+avuwOfiyw0dbEehHpi IMVhJ14Av7hcU6e/CNZ8jjqF7jPFLPzxd4SGC6VlFp/322dabyPPTkEhOf53yTSIWezwnui0X73 hzNE3luY6xHaIFzbxgtrwT+lZewxLJxbxynJpZOlvc+F1+M3c27tI43yvc+hvJrLNgOJwfKFwx+ EWb4F2Iobt+G30fuF/fUPWilEfRMZK7UiwvVfMMWm X-Received: by 2002:a05:600d:8496:20b0:48e:86e6:c2f1 with SMTP id 5b1f17b1804b1-48e86e6c38fmr9654715e9.2.1778490211068; Mon, 11 May 2026 02:03:31 -0700 (PDT) X-Received: by 2002:a05:600d:8496:20b0:48e:86e6:c2f1 with SMTP id 5b1f17b1804b1-48e86e6c38fmr9653555e9.2.1778490210030; Mon, 11 May 2026 02:03:30 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6f9fc89asm182328085e9.0.2026.05.11.02.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:29 -0700 (PDT) Date: Mon, 11 May 2026 05:03:24 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 18/30] mm: page_reporting: skip redundant zeroing of host-zeroed reported pages Message-ID: <696f60c35b95b65fcb5872ae3f6ab6ffa194b555.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a guest reports free pages to the hypervisor via the page reporting framework (used by virtio-balloon and hv_balloon), the host typically zeros those pages when reclaiming their backing memory. However, when those pages are later allocated in the guest, post_alloc_hook() unconditionally zeros them again if __GFP_ZERO is set. This double-zeroing is wasteful, especially for large pages. Avoid redundant zeroing: - Add a host_zeroes_pages flag to page_reporting_dev_info, allowing drivers to declare that their host zeros reported pages on reclaim. A static key (page_reporting_host_zeroes) gates the fast path. - Add PG_zeroed page flag (sharing PG_private bit) to mark pages that have been zeroed by the host. Set it in page_reporting_drain() after the host reports them. - Thread the zeroed bool through rmqueue -> prep_new_page -> post_alloc_hook, where it skips redundant zeroing for __GFP_ZERO allocations. No driver sets host_zeroes_pages yet; a follow-up patch to virtio_balloon is needed to opt in. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/page-flags.h | 9 +++++ include/linux/page_reporting.h | 3 ++ mm/compaction.c | 6 ++-- mm/internal.h | 2 +- mm/page_alloc.c | 66 +++++++++++++++++++++++----------- mm/page_reporting.c | 14 +++++++- mm/page_reporting.h | 12 +++++++ 7 files changed, 87 insertions(+), 25 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 0e03d816e8b9..4ee64134acc3 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -135,6 +135,8 @@ enum pageflags { PG_swapcache =3D PG_owner_priv_1, /* Swap page: swp_entry_t in private */ /* Some filesystems */ PG_checked =3D PG_owner_priv_1, + /* Page contents are known to be zero */ + PG_zeroed =3D PG_private, =20 /* * Depending on the way an anonymous folio can be mapped into a page @@ -673,6 +675,13 @@ FOLIO_TEST_CLEAR_FLAG_FALSE(young) FOLIO_FLAG_FALSE(idle) #endif =20 +/* + * PageZeroed() tracks pages known to be zero. The allocator + * uses this to skip redundant zeroing in post_alloc_hook(). + */ +__PAGEFLAG(Zeroed, zeroed, PF_NO_COMPOUND) +#define __PG_ZEROED (1UL << PG_zeroed) + /* * PageReported() is used to track reported free pages within the Buddy * allocator. We can use the non-atomic version of the test and set diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h index 5ab5be02fa15..c331c6b36687 100644 --- a/include/linux/page_reporting.h +++ b/include/linux/page_reporting.h @@ -14,6 +14,9 @@ struct page_reporting_dev_info { int (*report)(struct page_reporting_dev_info *prdev, struct scatterlist *sg, unsigned int nents); =20 + /* If true, host zeros reported pages on reclaim */ + bool host_zeroes_pages; + /* work struct for processing reports */ struct delayed_work work; =20 diff --git a/mm/compaction.c b/mm/compaction.c index 72684fe81e83..0471c5326ec0 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -82,7 +82,8 @@ static inline bool is_via_compact_memory(int order) { ret= urn false; } =20 static struct page *mark_allocated_noprof(struct page *page, unsigned int = order, gfp_t gfp_flags) { - post_alloc_hook(page, order, __GFP_MOVABLE, USER_ADDR_NONE); + __ClearPageZeroed(page); + post_alloc_hook(page, order, __GFP_MOVABLE, false, USER_ADDR_NONE); set_page_refcounted(page); return page; } @@ -1849,7 +1850,8 @@ static struct folio *compaction_alloc_noprof(struct f= olio *src, unsigned long da set_page_private(&freepage[size], start_order); } dst =3D (struct folio *)freepage; - post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); + __ClearPageZeroed(&dst->page); + post_alloc_hook(&dst->page, order, __GFP_MOVABLE, false, USER_ADDR_NONE); set_page_refcounted(&dst->page); if (order) prep_compound_page(&dst->page, order); diff --git a/mm/internal.h b/mm/internal.h index 751ae8911607..fa7ffea4d492 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -924,7 +924,7 @@ static inline void init_compound_tail(struct page *tail, } =20 void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flag= s, - unsigned long user_addr); + bool zeroed, unsigned long user_addr); extern bool free_pages_prepare(struct page *page, unsigned int order); =20 extern int user_min_free_kbytes; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 76f39dd026ff..bd3b909cacdf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1743,6 +1743,7 @@ static __always_inline void page_del_and_expand(struc= t zone *zone, bool was_reported =3D page_reported(page); =20 __del_page_from_free_list(page, zone, high, migratetype); + nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported); account_freepages(zone, -nr_pages, migratetype); } @@ -1815,8 +1816,10 @@ static inline bool should_skip_init(gfp_t flags) return (flags & __GFP_SKIP_ZERO); } =20 + inline void post_alloc_hook(struct page *page, unsigned int order, - gfp_t gfp_flags, unsigned long user_addr) + gfp_t gfp_flags, bool zeroed, + unsigned long user_addr) { bool init =3D !want_init_on_free() && want_init_on_alloc(gfp_flags) && !should_skip_init(gfp_flags); @@ -1825,6 +1828,14 @@ inline void post_alloc_hook(struct page *page, unsig= ned int order, =20 set_page_private(page, 0); =20 + /* + * If the page is zeroed, skip memory initialization. + * We still need to handle tag zeroing separately since the host + * does not know about memory tags. + */ + if (zeroed && init && !zero_tags) + init =3D false; + arch_alloc_page(page, order); debug_pagealloc_map_pages(page, 1 << order); =20 @@ -1882,13 +1893,13 @@ inline void post_alloc_hook(struct page *page, unsi= gned int order, } =20 static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp= _flags, - unsigned int alloc_flags, - unsigned long user_addr) + unsigned int alloc_flags, bool zeroed, + unsigned long user_addr) { if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); =20 - post_alloc_hook(page, order, gfp_flags, user_addr); + post_alloc_hook(page, order, gfp_flags, zeroed, user_addr); =20 /* * page is set pfmemalloc when ALLOC_NO_WATERMARKS was necessary to @@ -3154,6 +3165,7 @@ int __isolate_free_page(struct page *page, unsigned i= nt order) } =20 del_page_from_free_list(page, zone, order, mt); + __ClearPageZeroed(page); =20 /* * Set the pageblock if the isolated page is at least half of a @@ -3226,7 +3238,7 @@ static inline void zone_statistics(struct zone *prefe= rred_zone, struct zone *z, static __always_inline struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, unsigned int order, unsigned int alloc_flags, - int migratetype) + int migratetype, bool *zeroed) { struct page *page; unsigned long flags; @@ -3261,6 +3273,8 @@ struct page *rmqueue_buddy(struct zone *preferred_zon= e, struct zone *zone, } } spin_unlock_irqrestore(&zone->lock, flags); + *zeroed =3D PageZeroed(page); + __ClearPageZeroed(page); } while (check_new_pages(page, order)); =20 /* @@ -3329,10 +3343,9 @@ static int nr_pcp_alloc(struct per_cpu_pages *pcp, s= truct zone *zone, int order) /* Remove page from the per-cpu list, caller must protect the list */ static inline struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, - int migratetype, - unsigned int alloc_flags, + int migratetype, unsigned int alloc_flags, struct per_cpu_pages *pcp, - struct list_head *list) + struct list_head *list, bool *zeroed) { struct page *page; =20 @@ -3367,6 +3380,8 @@ struct page *__rmqueue_pcplist(struct zone *zone, uns= igned int order, page =3D list_first_entry(list, struct page, pcp_list); list_del(&page->pcp_list); pcp->count -=3D 1 << order; + *zeroed =3D PageZeroed(page); + __ClearPageZeroed(page); } while (check_new_pages(page, order)); =20 return page; @@ -3375,7 +3390,8 @@ struct page *__rmqueue_pcplist(struct zone *zone, uns= igned int order, /* Lock and remove page from the per-cpu list */ static struct page *rmqueue_pcplist(struct zone *preferred_zone, struct zone *zone, unsigned int order, - int migratetype, unsigned int alloc_flags) + int migratetype, unsigned int alloc_flags, + bool *zeroed) { struct per_cpu_pages *pcp; struct list_head *list; @@ -3393,7 +3409,8 @@ static struct page *rmqueue_pcplist(struct zone *pref= erred_zone, */ pcp->free_count >>=3D 1; list =3D &pcp->lists[order_to_pindex(migratetype, order)]; - page =3D __rmqueue_pcplist(zone, order, migratetype, alloc_flags, pcp, li= st); + page =3D __rmqueue_pcplist(zone, order, migratetype, alloc_flags, + pcp, list, zeroed); pcp_spin_unlock(pcp); if (page) { __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); @@ -3418,19 +3435,19 @@ static inline struct page *rmqueue(struct zone *preferred_zone, struct zone *zone, unsigned int order, gfp_t gfp_flags, unsigned int alloc_flags, - int migratetype) + int migratetype, bool *zeroed) { struct page *page; =20 if (likely(pcp_allowed_order(order))) { page =3D rmqueue_pcplist(preferred_zone, zone, order, - migratetype, alloc_flags); + migratetype, alloc_flags, zeroed); if (likely(page)) goto out; } =20 page =3D rmqueue_buddy(preferred_zone, zone, order, alloc_flags, - migratetype); + migratetype, zeroed); =20 out: /* Separate test+clear to avoid unnecessary atomics */ @@ -3821,6 +3838,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int o= rder, int alloc_flags, struct pglist_data *last_pgdat =3D NULL; bool last_pgdat_dirty_ok =3D false; bool no_fallback; + bool zeroed; bool skip_kswapd_nodes =3D nr_online_nodes > 1; bool skipped_kswapd_nodes =3D false; =20 @@ -3965,10 +3983,11 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int= order, int alloc_flags, =20 try_this_zone: page =3D rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, - gfp_mask, alloc_flags, ac->migratetype); + gfp_mask, alloc_flags, ac->migratetype, + &zeroed); if (page) { prep_new_page(page, order, gfp_mask, alloc_flags, - ac->user_addr); + zeroed, ac->user_addr); =20 return page; } else { @@ -4195,9 +4214,11 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigne= d int order, count_vm_event(COMPACTSTALL); =20 /* Prep a captured page if available */ - if (page) - prep_new_page(page, order, gfp_mask, alloc_flags, + if (page) { + __ClearPageZeroed(page); + prep_new_page(page, order, gfp_mask, alloc_flags, false, ac->user_addr); + } =20 /* Try get a page from the freelist if available */ if (!page) @@ -5170,6 +5191,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, /* Attempt the batch allocation */ pcp_list =3D &pcp->lists[order_to_pindex(ac.migratetype, 0)]; while (nr_populated < nr_pages) { + bool zeroed =3D false; =20 /* Skip existing pages */ if (page_array[nr_populated]) { @@ -5178,7 +5200,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, } =20 page =3D __rmqueue_pcplist(zone, 0, ac.migratetype, alloc_flags, - pcp, pcp_list); + pcp, pcp_list, &zeroed); if (unlikely(!page)) { /* Try and allocate at least one page */ if (!nr_account) { @@ -5189,7 +5211,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, } nr_account++; =20 - prep_new_page(page, 0, gfp, 0, USER_ADDR_NONE); + prep_new_page(page, 0, gfp, 0, zeroed, USER_ADDR_NONE); set_page_refcounted(page); page_array[nr_populated++] =3D page; } @@ -6929,7 +6951,8 @@ static void split_free_frozen_pages(struct list_head = *list, gfp_t gfp_mask) list_for_each_entry_safe(page, next, &list[order], lru) { int i; =20 - post_alloc_hook(page, order, gfp_mask, USER_ADDR_NONE); + __ClearPageZeroed(page); + post_alloc_hook(page, order, gfp_mask, false, USER_ADDR_NONE); if (!order) continue; =20 @@ -7134,8 +7157,9 @@ int alloc_contig_frozen_range_noprof(unsigned long st= art, unsigned long end, } else if (start =3D=3D outer_start && end =3D=3D outer_end && is_power_o= f_2(end - start)) { struct page *head =3D pfn_to_page(start); =20 + __ClearPageZeroed(head); check_new_pages(head, order); - prep_new_page(head, order, gfp_mask, 0, USER_ADDR_NONE); + prep_new_page(head, order, gfp_mask, 0, false, USER_ADDR_NONE); } else { ret =3D -EINVAL; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n", diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 006f7cdddc18..37e4fce9eb38 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -50,6 +50,8 @@ EXPORT_SYMBOL_GPL(page_reporting_order); #define PAGE_REPORTING_DELAY (2 * HZ) static struct page_reporting_dev_info __rcu *pr_dev_info __read_mostly; =20 +DEFINE_STATIC_KEY_FALSE(page_reporting_host_zeroes); + enum { PAGE_REPORTING_IDLE =3D 0, PAGE_REPORTING_REQUESTED, @@ -129,8 +131,11 @@ page_reporting_drain(struct page_reporting_dev_info *p= rdev, * report on the new larger page when we make our way * up to that higher order. */ - if (PageBuddy(page) && buddy_order(page) =3D=3D order) + if (PageBuddy(page) && buddy_order(page) =3D=3D order) { __SetPageReported(page); + if (page_reporting_host_zeroes_pages()) + __SetPageZeroed(page); + } } while ((sg =3D sg_next(sg))); =20 /* reinitialize scatterlist now that it is empty */ @@ -391,6 +396,10 @@ int page_reporting_register(struct page_reporting_dev_= info *prdev) /* Assign device to allow notifications */ rcu_assign_pointer(pr_dev_info, prdev); =20 + /* enable zeroed page optimization if host zeroes reported pages */ + if (prdev->host_zeroes_pages) + static_branch_enable(&page_reporting_host_zeroes); + /* enable page reporting notification */ if (!static_key_enabled(&page_reporting_enabled)) { static_branch_enable(&page_reporting_enabled); @@ -415,6 +424,9 @@ void page_reporting_unregister(struct page_reporting_de= v_info *prdev) =20 /* Flush any existing work, and lock it out */ cancel_delayed_work_sync(&prdev->work); + + if (prdev->host_zeroes_pages) + static_branch_disable(&page_reporting_host_zeroes); } =20 mutex_unlock(&page_reporting_mutex); diff --git a/mm/page_reporting.h b/mm/page_reporting.h index c51dbc228b94..736ea7b37e9e 100644 --- a/mm/page_reporting.h +++ b/mm/page_reporting.h @@ -15,6 +15,13 @@ DECLARE_STATIC_KEY_FALSE(page_reporting_enabled); extern unsigned int page_reporting_order; void __page_reporting_notify(void); =20 +DECLARE_STATIC_KEY_FALSE(page_reporting_host_zeroes); + +static inline bool page_reporting_host_zeroes_pages(void) +{ + return static_branch_unlikely(&page_reporting_host_zeroes); +} + static inline bool page_reported(struct page *page) { return static_branch_unlikely(&page_reporting_enabled) && @@ -46,6 +53,11 @@ static inline void page_reporting_notify_free(unsigned i= nt order) #else /* CONFIG_PAGE_REPORTING */ #define page_reported(_page) false =20 +static inline bool page_reporting_host_zeroes_pages(void) +{ + return false; +} + static inline void page_reporting_notify_free(unsigned int order) { } --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 191C73C7E16 for ; Mon, 11 May 2026 09:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490235; cv=none; b=PvjMKk4EeIwIazeSDOvHikiQKYzT1ClXh8HP9CsoIweTP/e7kQ62PP6PA9PjdEHVJw8QRppTnNPl3TFfAQ+vjEx59U9cye+7dv7Wq4Vlm0qbxXI+Rx/4dbA2294SAzCLdwIlbk5bzvQIgxuikpik+oem2sPhO2H8FFl1LWFdQyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490235; c=relaxed/simple; bh=S3lspdseAiA9VDFP1z5oU53ONzTmuB9EAtNlvAmS1xQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NnKR1DbJnu5tdtQWuu2mLItwhp0/xPfoSn+tk5pLlNtnph/AADLvKQPxo72Mll+iDc1D521K1S5h3PGzx6Xktl5Ubi+/0FcPhRfZdYNlKYFtHwRzNjVVScaItA8qr+u3sHoKN06Ge7SmNvLhO4zUeNorAY+ftYreGMtJHfu3vek= 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=T7iI+hGR; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=QZeJ6Luc; arc=none smtp.client-ip=170.10.129.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="T7iI+hGR"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="QZeJ6Luc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490229; 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=MrvzrHYJp3qtzaZog5kuCX8qehdfFd6F9etMXff3gHQ=; b=T7iI+hGR65dA8n7CbMAwn778PfOhLjK7Vxr0X643TlxdZrjjgOFDoOvv1TCsxqlMFHOaI+ kgueLHuQ/IwC2VyJi8iTNEy//cU6Gig2Y54m7BAmiW8iRuqfpa9TVZZSwqnh/fLJn0aohn fgmRFs/ktTDNYLtSV1DTdweob+d8x0k= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-eLTaaN1gPQq96dUz5HtkPA-1; Mon, 11 May 2026 05:03:41 -0400 X-MC-Unique: eLTaaN1gPQq96dUz5HtkPA-1 X-Mimecast-MFC-AGG-ID: eLTaaN1gPQq96dUz5HtkPA_1778490217 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4470d6d2a4fso4376266f8f.1 for ; Mon, 11 May 2026 02:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490217; x=1779095017; 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=MrvzrHYJp3qtzaZog5kuCX8qehdfFd6F9etMXff3gHQ=; b=QZeJ6LucmlepDlPK9ydQT4SfmAeZ9zXPMTAvCfCmIbrKqpHtyVqbZlfULhBmTy9j/V 6Pft3Zv3P1fXU4mTW3QSBZDJVikvzmwEM1dWk/55OkjBTOEIIH/cJHbBd5ySSyf8nYr3 XVShpWwYMGT5wydh22aMcnHHkBoVmPXnbRxfn3vLEc6hWJikkwQCO5f573PdcMZ3YKLy pJYo6HoZIJQscYimI7J1qNi0NQ4+j0bE6FzgjyVvodviWq+k4Bd52HhYFNt+9SB/y4or /nPS53FQattU+5NmEAieBP6uqDbABxdvJRoMC9aDciusK16wEgw/o5d6qk4vkgySGst6 48RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490217; x=1779095017; 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=MrvzrHYJp3qtzaZog5kuCX8qehdfFd6F9etMXff3gHQ=; b=GZdqAbJ/HLLCl8EQbrJvUH/++PK4lrWwUt6sbe7OxVrn9f3U3TUN895T0OsO89kU2Y XEX2ezmSVyk3L6A+pDiNi2holYyShYIukZhk7J3h5lPuAcMskTTGxi6MchJSbhCyQlFV 0Il8+WlJ6tARwB0Q7RHccnyRbvvZvOYkVxNxtb++X0oj3MlxP66q1y6ltAmvO338FBBE GBj+BDPkrzQJulTqHG5c/AbTb7mqOs9PWxDK8KdYLxDehBi9bcdEk/sNCGs6xMUYrLUA LtrG0SImtv9m/1Ln6USsCxOSCyu9tgQ8rwo1PWl8XZYIDJNCnF3X5CjZ1nBzE1vBSdi/ 4tOw== X-Gm-Message-State: AOJu0Yz5Pmu5jxy8ot6n2apKaPnV3JRZXe515I015cOUNHN3VoyxWVi1 zF4lTp0MGP6ow+lRV64ESGZjOW/KANKkXDf30r6J2RzCNBI738aWamPmT+2TJgWGhf5MjsxseKB Ian9m0CPqAlIV4GLmRLBm/CEdfhjZTeKvfBCCR4tXsQslzP0Rij5d6PGjeowa4l0sFbqllwCRQp UYkvr7Ql/vT5xdPzLKNJoTzMV9AaJvX/29afg7XR2lBZg= X-Gm-Gg: Acq92OG9Q4QgNzvEeUX55bD8mG/hu/HTcc7D/i9U8E0Kq0jtxzI0JTBgyVdSj0k+O08 6YFw4QrRYkbqqEIZIwzOwwAejB4+mmNSKlZKsfvnTD6ztgAgtuJaZQbETy1QNKxCUNodSzqy1js 5rpMR4sNiiLMHduJEOPLGEt480UBHL1YtyfB49W1Jnk4ZRO4uM/0Sh/Z+1asRf1aHkSj3ld+PxN 9N0xoAYG66D1cBEZwXiyajg9eG90+DZHqwIwWNqeJ4qNaw9Qj97wbjmiCt2N0JN57y644pU5QDQ qfOYNwwrPbw3wXKfPXXNNW5AW22m1sL/IFfaoLV9UAD89JfxFV0OTJJLb4+KgiWshwnQ7DLm7ei odY35OWoRTofpnVX4AmJziyJ2U+l/2DJWs5dEVcOg X-Received: by 2002:a05:600c:4ba6:b0:488:a882:c7 with SMTP id 5b1f17b1804b1-48e51f4bab4mr214596045e9.25.1778490216205; Mon, 11 May 2026 02:03:36 -0700 (PDT) X-Received: by 2002:a05:600c:4ba6:b0:488:a882:c7 with SMTP id 5b1f17b1804b1-48e51f4bab4mr214595015e9.25.1778490215419; Mon, 11 May 2026 02:03:35 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548ec6b071sm23711514f8f.14.2026.05.11.02.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:35 -0700 (PDT) Date: Mon, 11 May 2026 05:03:30 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 19/30] mm: page_reporting: add per-page zeroed bitmap for host feedback Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The host may skip zeroing some reported pages (e.g., due to alignment constraints or bounce buffer fallback in QEMU). Currently, when host_zeroes_pages is set, all reported pages are unconditionally marked PG_zeroed - even ones the host did not actually zero. Add a zeroed_bitmap to page_reporting_dev_info that the report() callback can use to indicate which pages were actually zeroed. The driver's report() callback is responsible for managing the bitmap: zeroing it before sending pages to the host, then setting bits for pages the host actually zeroed. page_reporting_drain() checks the bitmap per-page in addition to the global host_zeroes_pages flag. No driver sets host_zeroes_pages yet, so the static key is off and the bitmap is never read. Behavior is unchanged. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/page_reporting.h | 7 +++++++ mm/page_reporting.c | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h index c331c6b36687..e2e6a487ddab 100644 --- a/include/linux/page_reporting.h +++ b/include/linux/page_reporting.h @@ -17,6 +17,13 @@ struct page_reporting_dev_info { /* If true, host zeros reported pages on reclaim */ bool host_zeroes_pages; =20 + /* + * Per-page zeroed status, indexed by scatterlist position. + * The driver's report() callback must clear the bitmap, + * then set bits for pages that were actually zeroed. + */ + DECLARE_BITMAP(zeroed_bitmap, PAGE_REPORTING_CAPACITY); + /* work struct for processing reports */ struct delayed_work work; =20 diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 37e4fce9eb38..6c957a9daeef 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -108,6 +108,7 @@ page_reporting_drain(struct page_reporting_dev_info *pr= dev, struct scatterlist *sgl, unsigned int nents, bool reported) { struct scatterlist *sg =3D sgl; + unsigned int i =3D 0; =20 /* * Drain the now reported pages back into their respective @@ -122,7 +123,7 @@ page_reporting_drain(struct page_reporting_dev_info *pr= dev, =20 /* If the pages were not reported due to error skip flagging */ if (!reported) - continue; + goto next; =20 /* * If page was not commingled with another page we can @@ -133,9 +134,12 @@ page_reporting_drain(struct page_reporting_dev_info *p= rdev, */ if (PageBuddy(page) && buddy_order(page) =3D=3D order) { __SetPageReported(page); - if (page_reporting_host_zeroes_pages()) + if (page_reporting_host_zeroes_pages() && + test_bit(i, prdev->zeroed_bitmap)) __SetPageZeroed(page); } +next: + i++; } while ((sg =3D sg_next(sg))); =20 /* reinitialize scatterlist now that it is empty */ --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 2BAA33BE17C for ; Mon, 11 May 2026 09:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490227; cv=none; b=rz4GWj3twGH83qHKUgu9zZ+VjYNJVwaC8m54hQ/p3B/edM9zSXfJgLqhcXWOF/Y+C3caBDpAi58FtzHu8bp6sfj9117qBBJjnekN7EiEZGt/ZNyXP0pq0hXKarYI7+IM0zlCUkVgBZyLx6woUbEzr4b//VHTyix0mmb4HCShqCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490227; c=relaxed/simple; bh=2qwfIvYMP4MobFXYMZ9IfggvCGLyS5KNS+zvJpAn5WA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D235O4oSehMV9RSxJ+redeKpiPC3pgKMV1V3HmylFL9iDTLr25/oPvCm8q/PQa5SizjbJ7o52Q2OlFixzKDkOfSUKWP34i/YimguHs/b2q+kAp1Byq0g3SqZBYbTWinglaks4isXAzV2w5gsqi4xGBaeuLNyxKikpv66hSFfD4E= 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=HZqg5Eg4; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tVWtFTKW; arc=none smtp.client-ip=170.10.129.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="HZqg5Eg4"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tVWtFTKW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490225; 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=aIsDJpt3h7ld/REGYicPHvXqVXWObeKhcjO9DGpcUJs=; b=HZqg5Eg4/tLEHdNhhGBl05uNKVD3mTL4npZUAfvTmpv8y03M0XcNpz+WLMhSI5sSH41miN 2vYJ+q/tsIOhHEgafXk1OqKFuOayiQDgcagyErD5uj0dY/5k6jwkOsFOoy40V4Vxne6W6u PrW98LjErz+uK+/ksBibvXSU91aKdl0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-f3VToZjxMfaa_lTBTEswZw-1; Mon, 11 May 2026 05:03:43 -0400 X-MC-Unique: f3VToZjxMfaa_lTBTEswZw-1 X-Mimecast-MFC-AGG-ID: f3VToZjxMfaa_lTBTEswZw_1778490222 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48d1b294dfeso38016335e9.0 for ; Mon, 11 May 2026 02:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490222; x=1779095022; 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=aIsDJpt3h7ld/REGYicPHvXqVXWObeKhcjO9DGpcUJs=; b=tVWtFTKWwvnmHxSvw/TMTtyz5v60CaxNsZzpjz3wS74RnmHrL+5mSRbahW9/5USd/s TtUq/1PytkP0gOTvMhEdTIe9JJDVWsb8l7MBenBe74lRfkgzN7kjnySAuFFbVB2QVjT/ 2q58EWCuIVoVSJldStj6XCsSJgrVVva5gvRxsrmTGWm2EiB/01T1tFS5Njo46njpLLjm 8vc3PBbHdYspPVBGR+3URqd+u4VX7tfciSWA1c4lGvu9iPHwxpTNhISLCZnPYXVa/lIe qdX/RxlyErGobqwdOrt3GIswahgfnx/+jxPi1rYig2lc7ZJrL5WsIVVaKW6V25HEMjoV AoRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490222; x=1779095022; 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=aIsDJpt3h7ld/REGYicPHvXqVXWObeKhcjO9DGpcUJs=; b=j2F30EkYhI9DfjO/nzxMab2gk/5JLf62eC0y8q02uggIte4dS8wA3eLzQZQYwT4EzZ a+DZBpFUncsn9kB0LLMhF4hmekrqxSoYleCAf4D1gsJVKwiXeiozKoaYTS6C5rrVjYdj BAHDHTeEtAWABrYOwKqYAfX/Jsx+klS4u0icf4Rj7SvSSiHaH8Qgt613eVOztW1OwVzM dVqKAkei2CUVnDQt4rB8eXa3pLjFzt10pvVi26lQzAQAZyWbTO/ajgHTlrY2TX9h8yQk VJ/qWhchCBWm+/S3b0V+aH//7GVteMnUxXlw2DfvfO/UPJrAW1Z6Fs7gfhFi0GRYJD/k 7Ocg== X-Gm-Message-State: AOJu0YwFc9neqld5YcIxqGUC1IwvWQ0zfmBxIIntJr54Hwz9JXRO+mZg Gog5c+5D/hqVzjOACC/ZT70tPKz7fgJ4yX1IXYQoiQzJz8NGYy644WZbIX7DfTOjbGnC0l8zllp Q9NRJ/Esr0rR8nLYhEh1FzAiEZjTrG4Q3/ZWlWGUcWfcGwLqpOKtEF1ihn28sA6OeOqx+DM5WBS CG9AMt2jxS+At0/HvEh9txQ34ritSwZDd0XzkG7sbos0E= X-Gm-Gg: Acq92OHrMeCka7jgDJ0wHZhA/xY0ttLX0v19L+sMfxlMm0Snm0m46OS9HhQSOfEgCSt mCQPjdQgHkCv6KwbFIaCcJfsD5h2MBc3lbWHMMdunGCyEJuUOkckxBo+q4uwVz0RjzozJFkQMjk rNsXzOl03w3Hsw+vY47FnGNKUAfT0dGGDXgUSbkfeHWBvb1RdVM1jO8YG4/K1d6DV57FtFyxSiD KRibN5E9YM68lhHkDp3PvFc4vfVwb1IAxe3H8n2GCSvWWofcCKYf/D8pbMf79B06n8o4Ed++F1u 9nuI3kHwOthHzrkC/3PVSFQhUWvQ8lZOzwT7w9SQ9f917Zn9k6UhVJjXDJtLP801veWAWzWCxUf py9dZdldWBX2vtoGdVqpZ8BZ5b4b/rAPE3vSOsra1 X-Received: by 2002:a05:600c:6299:b0:489:1c32:210d with SMTP id 5b1f17b1804b1-48e706f120fmr146717885e9.15.1778490221636; Mon, 11 May 2026 02:03:41 -0700 (PDT) X-Received: by 2002:a05:600c:6299:b0:489:1c32:210d with SMTP id 5b1f17b1804b1-48e706f120fmr146716725e9.15.1778490220928; Mon, 11 May 2026 02:03:40 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6fffb9bdsm160295555e9.1.2026.05.11.02.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:40 -0700 (PDT) Date: Mon, 11 May 2026 05:03:35 -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 resend v6 20/30] mm: page_alloc: clear PG_zeroed on buddy merge if not both zero Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When two buddy pages merge in __free_one_page(), preserve PG_zeroed on the merged page only if both buddies have the flag set. Otherwise clear it. The merged page would inherit PG_zeroed, and a later __GFP_ZERO allocation would skip zeroing stale data in the non-zero half. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- mm/page_alloc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index bd3b909cacdf..d70c9ba6b329 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -940,10 +940,14 @@ static inline void __free_one_page(struct page *page, unsigned long buddy_pfn =3D 0; unsigned long combined_pfn; struct page *buddy; + bool buddy_zeroed; + bool page_zeroed; bool to_tail; =20 VM_BUG_ON(!zone_is_initialized(zone)); - VM_BUG_ON_PAGE(page->flags.f & PAGE_FLAGS_CHECK_AT_PREP, page); + /* PG_zeroed (aliased to PG_private) is valid on free-list pages */ + VM_BUG_ON_PAGE(page->flags.f & + (PAGE_FLAGS_CHECK_AT_PREP & ~__PG_ZEROED), page); =20 VM_BUG_ON(migratetype =3D=3D -1); VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page); @@ -978,6 +982,8 @@ static inline void __free_one_page(struct page *page, goto done_merging; } =20 + buddy_zeroed =3D PageZeroed(buddy); + /* * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, * merge with it and move up one order. @@ -996,10 +1002,17 @@ static inline void __free_one_page(struct page *page, change_pageblock_range(buddy, order, migratetype); } =20 + page_zeroed =3D PageZeroed(page); + __ClearPageZeroed(page); + __ClearPageZeroed(buddy); + combined_pfn =3D buddy_pfn & pfn; page =3D page + (combined_pfn - pfn); pfn =3D combined_pfn; order++; + + if (page_zeroed && buddy_zeroed) + __SetPageZeroed(page); } =20 done_merging: --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 D0CEC3BED78 for ; Mon, 11 May 2026 09:03:51 +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=1778490233; cv=none; b=OLfFFm7ClOBu+HMu36s3ZFAuAlsK+AWs7buqfoubc5DEeiqes4WFNiKARlk13wrA6U7X5frdjRJTzkSSSbx3A+8vnHuE67ftxq1fw5ag9ycs5Kr5PiyfxKALmpnUAUy8SCRrj2HkYfPJ3otNVBzOQJYsffA7ZH7zwhnuHA4z9nM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490233; c=relaxed/simple; bh=NGAOCZ1WWFki8ZjzkCn4xgO9pK8NqvqtlCATI7T+TGs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sr3U+XsR7cl/6jFj2M/yrWPlFJqIv1yAj3FWiZwTBOls8rfRV1KTGBNg5i7G4p22d4cjITU7wWSs2MQDkjvh5jHfpf1KBhDZQq/72iyZAh/hS1W7fwG1j8LiDsR9mWrkLP2cyO+J+rd5uag2S3xfv/RHjYcJIz7gSdmgfC5NSZg= 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=WK+CRUrs; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=F5jpqNzq; 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="WK+CRUrs"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="F5jpqNzq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490231; 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=ahWBOyIHSf1xwmLBF3en/Ugor1Y2nztY4A6z0DPh0SQ=; b=WK+CRUrseA99QuFnBgWmKTwyobarp63BCqrKVfiOMA6XApdqzTDQLbGebV+2w7p8SjLqPv ideDgPh09G9D5CElzK/tZNQJBpps47bpRmGehgLZmTgL3lYfLMblM8bUbSFAIP6MlW6lai r5iMqg+nDwClIfXBVj8f2HMeR2cVecE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-yaZphVDiPLGbdwSIP95b3g-1; Mon, 11 May 2026 05:03:49 -0400 X-MC-Unique: yaZphVDiPLGbdwSIP95b3g-1 X-Mimecast-MFC-AGG-ID: yaZphVDiPLGbdwSIP95b3g_1778490228 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-44d68ed8f95so3208679f8f.1 for ; Mon, 11 May 2026 02:03:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490228; x=1779095028; 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=ahWBOyIHSf1xwmLBF3en/Ugor1Y2nztY4A6z0DPh0SQ=; b=F5jpqNzqP+uwXv2N4F12X9KbimgK1F97WdhdP3tlhcHDrZwPQ3VblAntG7nTUCbhc/ qEJyHSb4VAwogBHgxv2FBMHlW/6oIiA3f1jJkxfpCk2Jk8GVpnk/qQ7291J7nUl0Hs41 BsjeeifDmADsnSTgciV0II+y0sXOPKYrsyiptrMb60cgf5/WaS09l3zif/Z/e3iMkyWz rGpq9picAQwBJ8lUyHnxm/F6CwdT61BfBVr0Rs1Y565YKFmYi3eyDvrRc3qfNCRI/MrR qAkF9+mvVIR/sqbxAxZ2uLnA7xjNKhCZrWSEb+XwAqLdx+iq61EPnWMjUbK5ZMMUDy0C C6oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490228; x=1779095028; 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=ahWBOyIHSf1xwmLBF3en/Ugor1Y2nztY4A6z0DPh0SQ=; b=M2cu+fxnLz9DcpDdlESxK2qoQYvUykbb+3CcthRskyHcZbYng+cT3Yj582YqZnGX5I ANTVGcWENKU/4AW2Vzvi9XoS2zerQe+6e3d1hbvYdU7uA3Zi40KK7eS3W6bMTjimAQ2H dWBSUImjycb3iblI/k45eC6GTI6jHP7pRrMGdcUdDIWnoQKhyDLS0r/Ruiz690B46MsA exwIP6U6y/0Ru5oR0zxyNjB1ksLgbhlUKiYQmbBAPdrGYWq+GQZ5d1Ml0uLiYtbhOnZx 0TFtktMQ2qGnIkpcDupaFIj0HLjCN0CpA56XUcsSIJr9+acvHwCSeG4HdWp43suTApz7 0XWg== X-Gm-Message-State: AOJu0YyjLciBIJAdF/Puds7/7drCpteolp+uoqfcck1l+U+f3RhN/2Hv pPq4aPH1Jfk3vzUTs2T4uzLGOiFIh2R+g81etLPEfPLGBj0sU9x48HPSzqfcPoT9svajB+4obD/ w9uValbYyi+CBM1gsRFUcOS9XGKU0rixyTLnA7WdIUehqtcqg5957WYT2Wi1hGAqUoO5GgV6m0m /FExiFLu/FzXysRU6p52q7DdT+YIzbtWXrQ5SBaGgF/cg= X-Gm-Gg: Acq92OHQm9AHLzQmgjtRtnovPduT/+rbIXKJOh0JUmk4VtoZQCEKh1Oes9EpPC6F+1C 6B11B/TDY8b6Rfbij2nr1OCxXChx0Q0irWzMn/+6RqScc5BHTAf1c9jiPHGL8N7/ARtwjlzqI+s gk3Eq/7B9DPQBUDVBnsU73jFJnDD9snr5IiSo40PowXwSJ0xrhDg3KxjCw2xTDe4VjpEO7qK5Zj ZRbGoY+JAp3YFy2oVCkIAtcA/rXNKNTAgEXXorLdj++GHHO7RL/DRj3XHjZ5NTLGtyUeaKACqyd 5GIOwtcwqqea8f7bM8ds0gbYByNoKQAQNKnxPpEjwaLuYP2xMbWydm0RwLkPXP2MdY5mMFVdRrr fNMAJawnDvaztbfA4/4njWqxiQmsQ296Jj+meytWF X-Received: by 2002:a05:6000:270f:b0:453:9897:76aa with SMTP id ffacd0b85a97d-45398977768mr16819475f8f.21.1778490227524; Mon, 11 May 2026 02:03:47 -0700 (PDT) X-Received: by 2002:a05:6000:270f:b0:453:9897:76aa with SMTP id ffacd0b85a97d-45398977768mr16819377f8f.21.1778490226554; Mon, 11 May 2026 02:03:46 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a5b65sm25226099f8f.8.2026.05.11.02.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:46 -0700 (PDT) Date: Mon, 11 May 2026 05:03:41 -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 resend v6 21/30] mm: page_alloc: preserve PG_zeroed in page_del_and_expand Message-ID: <57d30ce615c23d3f3737e38d300f4613b3ebadbc.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Propagate PG_zeroed through buddy splits in page_del_and_expand() and try_to_claim_block(). When a zeroed high-order page is split to satisfy a smaller allocation, the sub-pages placed back on the free lists keep PG_zeroed. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- mm/page_alloc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d70c9ba6b329..468e8bde7d34 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1712,7 +1712,8 @@ struct page *__pageblock_pfn_to_page(unsigned long st= art_pfn, * -- nyc */ static inline unsigned int expand(struct zone *zone, struct page *page, in= t low, - int high, int migratetype, bool reported) + int high, int migratetype, bool reported, + bool zeroed) { unsigned int size =3D 1 << high; unsigned int nr_added =3D 0; @@ -1743,6 +1744,8 @@ static inline unsigned int expand(struct zone *zone, = struct page *page, int low, */ if (reported) __SetPageReported(&page[size]); + if (zeroed) + __SetPageZeroed(&page[size]); } =20 return nr_added; @@ -1754,10 +1757,12 @@ static __always_inline void page_del_and_expand(str= uct zone *zone, { int nr_pages =3D 1 << high; bool was_reported =3D page_reported(page); + bool was_zeroed =3D PageZeroed(page); =20 __del_page_from_free_list(page, zone, high, migratetype); =20 - nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported); + nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported, + was_zeroed); account_freepages(zone, -nr_pages, migratetype); } =20 @@ -2335,11 +2340,12 @@ try_to_claim_block(struct zone *zone, struct page *= page, if (current_order >=3D pageblock_order) { unsigned int nr_added; bool was_reported =3D page_reported(page); + bool was_zeroed =3D PageZeroed(page); =20 del_page_from_free_list(page, zone, current_order, block_type); change_pageblock_range(page, current_order, start_type); nr_added =3D expand(zone, page, order, current_order, start_type, - was_reported); + was_reported, was_zeroed); account_freepages(zone, nr_added, start_type); return page; } --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 C4A983D34A6 for ; Mon, 11 May 2026 09:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490238; cv=none; b=UDhEyxqBy/7WJKalzF7eSEP3RYfXSBYn6h0nWVUd0U+YTUCVOAnKO/CcanvMKf1Nr2C+v0DQxPCxMJWe8JljZKeCgQLb2eEZZTMbjUU818lk1UuNseZdR88MuDiZBsVEof3rv7qheXLTyKGc23k5u/2yfM+2mQFubo7KglO+nzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490238; c=relaxed/simple; bh=oYf8Ac6ioZ/fyq4O92mQTh5p7Zvk+J/G+lE9Pf1TUvg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ucENbClFZPceE4a6h9gshjp1lcCrSd6zgdyl1n4HGAFqw1Rrfz23auAxPFdNmfCPsxGPuujcvrrv9sS4qKNyQT/NU6zEQH8j7v+jpGxQurJKdyAra8rSW52A3GnPj240si7IFKK+bEoSYSAiOF/IKvZdarYr3W2bJzcLmMP6uws= 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=UiDsfoAP; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=M2XhiRpE; arc=none smtp.client-ip=170.10.129.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="UiDsfoAP"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="M2XhiRpE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490236; 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=kJvki5d0ND9UiDEat7+4BM/+FuHUbmXzqDz6vRDL3g0=; b=UiDsfoAPyh8DvlsmbwlwZkFoMwSXBRWCKPbpkGlR7MaTVfgJFhYHtASf2KppEH0FqljApE cZC/5YU5LJloStxPsySLWnLOQS7Qixrc+KrtR7Tgyd2tLp5tkjNrE7YvlAA98TZr1ZUSQp cMvRmpEj5vq8DSbL+SbkruoXigPy+7U= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-A8DbqIKENGO7Hh4MTiI79A-1; Mon, 11 May 2026 05:03:54 -0400 X-MC-Unique: A8DbqIKENGO7Hh4MTiI79A-1 X-Mimecast-MFC-AGG-ID: A8DbqIKENGO7Hh4MTiI79A_1778490234 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43fe791a398so3726920f8f.0 for ; Mon, 11 May 2026 02:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490233; x=1779095033; 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=kJvki5d0ND9UiDEat7+4BM/+FuHUbmXzqDz6vRDL3g0=; b=M2XhiRpEUXE8491wCsbLdTmkIH37fEp1bj3ucw3+L01XO9aniDNi9VahR9EMQN0iBF F5l2wWRDLe1Ugx6ekObqcVkNyIi2G0kQ91ToyS5Rc13gVpJHlAfjznCoGIy2ev/ZIn+Y DqK7xymuSlTIqxdcAO+PSrsliEYlqLdL7PFVGFSke6gXL2Rx6N0wSWzD/mAtgIRDte0S MA6eiNBw4Hqx6EKzj8nDUyhcxM/dEGZkgxOrkKwLE9/1xy4eYHU+ugNajaNtVqQr4cTo dDFqnzvkONU8UtoZk/yzAyDdo53+b0jYAkKZ/Du9KxIkxBqF1Om6hwMwAKbUTr4PYhCG dBVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490233; x=1779095033; 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=kJvki5d0ND9UiDEat7+4BM/+FuHUbmXzqDz6vRDL3g0=; b=Ms/WziiZc074S9Egw2eow1zLY9XVVyT9sK+Njly5+C5oNvd2/ddTwyz7iZNb7ORyK/ x/hsSJPLpy9OVqzxsqHDiUIZC8xlWt8PTqS5dSG5Qxr9FLgg6a+y+APZKcfTs9M4jGDV +LFphCmPy4Gyc6PvFwLT0RktTpfFHam3pp6c2FCDK+WcenTklStDw6ejbXDG94GiTQ0l 796YWki0DDcedVMHK0BfCRdkXJ8cgn19xNmas2tIMtCkvKTjkXo2WtJu4O3T/Mwd13XZ HUvVH4hVMGNxsxX84xtFVHhumA5iZyLIsLqu9YtIxGD/G1gvgg7Ya9stwyQoBcH1+Qug 8kvw== X-Gm-Message-State: AOJu0YxK3dDii1TNiFXIBB3Nm8xxlTQwRLdeYY5tAcu8kGy6CBvE39hs HqurkDSeqd0oAeCUxg41FX1EpWwhgFN/MOFl9DnmpTvCp1ky2GJDd/YNTKADqL9qK4BCSY41BZv odPF1/np52VrsEkyPZeRbpWanI7Bd237wB2Z7VmSOcRPrMEXDQHvxQ7AbvR5w+5e6l9sAnhr2p0 1CKkjmoCdFFkL6ELhv3z5cZ86MMwWl/UGX15nKbmRRHhc= X-Gm-Gg: Acq92OHAmING6kHOMXhqQp1+v3rSXDqsXwGdvn4bnbNfcMIPuHPtD/sgkEjyypwW9at 4GL5cHRiGv1EC4C3FBmXHkEXXjVyWSwsbOSldVeqdwYi5p8G8GdtHXnQH3NC+S2gJ7PgJXdk1Ey RQ4yIpZvsN6noObxmo1KBk+cz0SvB538U1sxNbzXKv5RxytSz8MD5OeHOIL/bZRk/tf90bKUR8+ uqNX0w+8Y+LO9BgWjiOW9DWfz45cKyVGFTt57XVDhtEiaeqmLYn2UcwktbgzcGhgYHY4HM4Zp9o QHpX8si7+B2Ua8+1ju84V4x+U/iOwSP3VD2g8ErYXG8OdC+uG576Q8ssDZFWgtMTiNYXJrwm2KR vYkaGaYZNieBowS9BUdZ/sY2R04F14D3MgBZD4mw1 X-Received: by 2002:a05:6000:2909:b0:44b:e349:e6bc with SMTP id ffacd0b85a97d-4515b056ac1mr37167889f8f.3.1778490232971; Mon, 11 May 2026 02:03:52 -0700 (PDT) X-Received: by 2002:a05:6000:2909:b0:44b:e349:e6bc with SMTP id ffacd0b85a97d-4515b056ac1mr37167751f8f.3.1778490232034; Mon, 11 May 2026 02:03:52 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45491304387sm23431955f8f.21.2026.05.11.02.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:51 -0700 (PDT) Date: Mon, 11 May 2026 05:03:46 -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 resend v6 22/30] virtio_balloon: submit reported pages as individual buffers Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Submit each reported page as a separate virtqueue buffer instead of one buffer with an sg list of all pages. This avoids indirect descriptor allocation (kmalloc in the reporting path) and gives per-page used length feedback from the device. On error, the already-queued pages are kicked and drained before the error is returned. The caller (page_reporting_drain) then marks the batch as unreported, which is conservative but correct. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- drivers/virtio/virtio_balloon.c | 36 +++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index 6a1a610c2cb1..fdfd828657dd 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -202,25 +202,35 @@ static int virtballoon_free_page_report(struct page_r= eporting_dev_info *pr_dev_i struct virtio_balloon *vb =3D container_of(pr_dev_info, struct virtio_balloon, pr_dev_info); struct virtqueue *vq =3D vb->reporting_vq; - unsigned int unused, err; + unsigned int i, err; =20 /* We should always be able to add these buffers to an empty queue. */ - err =3D virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT); + for (i =3D 0; i < nents; i++) { + struct scatterlist one; =20 - /* - * In the extremely unlikely case that something has occurred and we - * are able to trigger an error we will simply display a warning - * and exit without actually processing the pages. - */ - if (WARN_ON_ONCE(err)) - return err; + sg_init_table(&one, 1); + sg_set_page(&one, sg_page(&sg[i]), sg[i].length, + sg[i].offset); + err =3D virtqueue_add_inbuf(vq, &one, 1, &sg[i], GFP_NOWAIT); + if (WARN_ON_ONCE(err)) { + nents =3D i; + break; + } + } =20 - virtqueue_kick(vq); + if (nents) { + virtqueue_kick(vq); =20 - /* When host has read buffer, this completes via balloon_ack */ - wait_event(vb->acked, virtqueue_get_buf(vq, &unused)); + /* When host has read buffer, this completes via balloon_ack */ + for (i =3D 0; i < nents; i++) { + unsigned int unused; =20 - return 0; + wait_event(vb->acked, + virtqueue_get_buf(vq, &unused)); + } + } + + return err; } =20 static void set_page_pfns(struct virtio_balloon *vb, --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 496733D3CEE for ; Mon, 11 May 2026 09:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490243; cv=none; b=I6yY93eeHXOU2pPc71gEHuh1Xc1kENDmO9nEXOMD0jzWOit+jrObN8GgRd/bJ4j0mvHZ3yNw2PuvGhPc5qPe5Mr5SUmCuNor+ezHIbgsVCL0EsDmJcDgXtI39erTUXMfGx2tcSTx/6NLTfJt4O3NxBi8ZkbmdcFE3nftnB+huVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490243; c=relaxed/simple; bh=gA+GhqYvwNlglcAAc+7safd3uN5pLfpD+OD4nI/Ceeg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FXVnG+U/NuC8HMko+npoSj58dUC8wdtlEuuTZi5Rmp7BTYulPaB5Phojf7AgF8SxtxXsTCI0GdvMwTuv+B4YrpYcMHg0jYb0IXekXsWw9V3tUG82LQAZCs1ps5/Fxi+v/FIAA6EGGVZGn/xwxydWZ/t1oAilLJnahvdsUpiOvxM= 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=Zh8DoXtC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=MRDVjWmi; arc=none smtp.client-ip=170.10.129.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="Zh8DoXtC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="MRDVjWmi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490241; 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=RuTcBXOBEgIcnIT/SeHSDJKAZ2vX9yg2mawsRplntmg=; b=Zh8DoXtC/jRvrfbtlKO13LO014yMiZEayKUUBEP0Ng3ZIqaUiMyrU92WFfc/e1WUFEV+9o QCY3UPzsY16Xt+1NfBFdOViuKCcph7hx8I024TWr3EuzWro2me0NYfDj55QQkmBH+FYyn5 X8NGMWBnH1kSvVRxAhq4OG5W+u0u3EI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-399-ZGiGW7ygPUOK7IMnLOjP3Q-1; Mon, 11 May 2026 05:04:00 -0400 X-MC-Unique: ZGiGW7ygPUOK7IMnLOjP3Q-1 X-Mimecast-MFC-AGG-ID: ZGiGW7ygPUOK7IMnLOjP3Q_1778490239 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-44a52d5e572so2553247f8f.3 for ; Mon, 11 May 2026 02:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490239; x=1779095039; 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=RuTcBXOBEgIcnIT/SeHSDJKAZ2vX9yg2mawsRplntmg=; b=MRDVjWmi27FV1gDxO/UDx/MGp9+8JpkiPgt2i3WzY0jX4ECuqsQ3NldD+UmDqKPCCN CuA5qMZtUpGnRPcSSs+Dt0nmxbJLWvXZccQ9hry8bKmgALfFUb14pgdHr83Zhkq18xDY /W5i/Bq06HguvWS/He2b4eX5793X8kzTdgDz6CHFAdPRheRYvL5VHHCPB53sYABkcWCH LcTe3zPQTtgU8x5YBlL6b42AYeAwONkjb+kx79olsO1bgiI9XFC2HnskG5AQIgj1rft9 19PpSoab/ocmBGXwjt4qv2mNitzp7TPjfBEE3V6MWp6ypJI6oneEDcsIRJmF944bmII2 kPig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490239; x=1779095039; 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=RuTcBXOBEgIcnIT/SeHSDJKAZ2vX9yg2mawsRplntmg=; b=XgJ/vSBtVgrIUXPNR8ZSRYZqmya4/kCmjLje0+2XimQH6/69Z9JEzNStgvfN7GKF6l HvrSuGCxWX1AEyknuH/9EsxleQo5DOR1qVYZuEBI4At/PeIyKZAZq4phEjvCab2CTpzs 3FtZeOc6eOYiJNoum8Z4tx6ClQ76zj7qFuFXJOVjlWOuSCbsTVBcyxKIPNE81XxsTiHu wIlC1gkXSZAbZmWwbWcSGEYLhoBAHGu/4800dA4u8xBAEOBH9D6uPTflxgQlPd5pfsWX DYuEpc6n7B4HQ1ZIxu/2Lk6/RWog224zL9WMJFyC5PogG9nEF/jK0zSajp7sc7h365q2 zK0w== X-Gm-Message-State: AOJu0YzcBSiqO3TU+SzhHBjyJhplpvmlm4AYHs20LzWdQN2vNEgR5Alv RaLW9HQgjwZLjCTOPT8KMbaQfP9WGTj7JK+An9hobpuHSOvMe+kKodYgV22NKLAYBkO5bpOMqZ+ bi2I5lxrGt7jfLxWAsdBo31XPDF+V/1RJc9vZQvHxqFvu++T8yXadd0m6D+k8XZSdphwISuyyIO 9DzfTx7hmCjT6hM2UBgYOy075BoTZSVZlRbZeaUMj0oO4= X-Gm-Gg: Acq92OGX+ESfIQn0/XKEvb+KUrLrwYNUHgoPeMAV9n+N7DUHXa7gQBtyS2QlUhl6WvK rcg9EBpfrPihLuQ4B2kQUzdWRmCTmqeRJSFwGUtlBpE32YVi7aFFlumiARmnxTpp8ZOHKk+Wo9I ZtZRPwXqiyGd+kWjMpvffwQNAzVrOBBqrqvmyCO7wr3Irr5DudekWaXbngbaSyQuuRoR1nZ4fGj PJqiK99bB+OABC+VvdI57Bg/H1snsIGvMkGEft2GKugFYxSajYpLB7MeTK+zyG1+EXfg5faoXhX RmKWnYBbvT9KPTna/gksaIpUsoVrwjb7J8I9e+GDQCu+l3TBkjllkmfGgpiBO5lA4hqgVTIQmTH GmdoWhRuWkZhIaVbp7pHSliNsaHYRoi9M+hSTdmSunrP5Rc3H+3A= X-Received: by 2002:a05:6000:4006:b0:454:1e65:32f0 with SMTP id ffacd0b85a97d-4541e65332dmr22769423f8f.10.1778490238506; Mon, 11 May 2026 02:03:58 -0700 (PDT) X-Received: by 2002:a05:6000:4006:b0:454:1e65:32f0 with SMTP id ffacd0b85a97d-4541e65332dmr22769308f8f.10.1778490237654; Mon, 11 May 2026 02:03:57 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a5b65sm25227071f8f.8.2026.05.11.02.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:57 -0700 (PDT) Date: Mon, 11 May 2026 05:03:52 -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 resend v6 23/30] mm: page_reporting: add flush parameter with page budget Message-ID: <4e2e1015d22d5aeb3a60d74cc08b56e49363d3d8.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a write-only module parameter 'flush' that triggers immediate page reporting. The value specifies a page budget: at least this many pages (at page_reporting_order) will be reported, or all unreported pages if fewer remain. The actual number reported may exceed the budget since each reporting pass processes a full cycle across all zones. This is helpful when there is a lot of memory freed quickly, and a single cycle may not process all free pages due to internal budget limits. echo 512 > /sys/module/page_reporting/parameters/flush Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/page_reporting.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 6c957a9daeef..f4a0e27ac7fb 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -358,6 +358,48 @@ static void page_reporting_process(struct work_struct = *work) static DEFINE_MUTEX(page_reporting_mutex); DEFINE_STATIC_KEY_FALSE(page_reporting_enabled); =20 +static int page_reporting_flush_set(const char *val, + const struct kernel_param *kp) +{ + struct page_reporting_dev_info *prdev; + unsigned int budget; + int err; + + err =3D kstrtouint(val, 0, &budget); + if (err) + return err; + if (!budget) + return 0; + + mutex_lock(&page_reporting_mutex); + prdev =3D rcu_dereference_protected(pr_dev_info, + lockdep_is_held(&page_reporting_mutex)); + if (prdev) { + unsigned int reported; + + for (reported =3D 0; reported < budget; + reported +=3D prdev->capacity) { + flush_delayed_work(&prdev->work); + __page_reporting_request(prdev); + flush_delayed_work(&prdev->work); + if (atomic_read(&prdev->state) =3D=3D PAGE_REPORTING_IDLE) + break; + if (signal_pending(current)) + break; + } + } + mutex_unlock(&page_reporting_mutex); + return 0; +} + +static const struct kernel_param_ops flush_ops =3D { + .set =3D page_reporting_flush_set, + .get =3D param_get_uint, +}; +static unsigned int page_reporting_flush; +module_param_cb(flush, &flush_ops, &page_reporting_flush, 0200); +MODULE_PARM_DESC(flush, "Report at least N pages at page_reporting_order, = or until all reported"); + int page_reporting_register(struct page_reporting_dev_info *prdev) { int err =3D 0; --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 887843BED79 for ; Mon, 11 May 2026 09:04:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490248; cv=none; b=D8nQtW1DtOI2pQdS0Yl+b4lsICj0MiXFkvgxs0Sd/k8r+sCYNuIBEIdzUBPDjbdSRsV5r1+n5+kaorSgaaacv3wtPnFLp/8qxS/MN+cwk6ism0CI0qn6V6hElrjIcTC2zQy3uIyd4oPxdLOKtZfaPvELK2USjdFV2qaf3HCL/eY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490248; c=relaxed/simple; bh=UthrZxmdWcO06HJ9ALdgvYEd0atl77MZdyNsS+qUmSA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ei4UDY90os6mTWQwBjp+kaA1AC663nlloyz42NIwf45F2yT2xB2nbWzEbBxhGSauTJ/ntPHclz4Ycg3A7GtcYg9zvoVKoxaBNhpogOqVr9wsZXmLbkcZlxRcDayruh1ib77FZ66a3fMPMLyXuqta6i4zg9gAjOC9Caiej/W7zqY= 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=G82cq8U8; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=XUVsh+Ic; arc=none smtp.client-ip=170.10.129.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="G82cq8U8"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="XUVsh+Ic" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490246; 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=91FyDo4lvxPgkiSt2vN5y4yAYQZnqJbtxElmqdOrkw4=; b=G82cq8U8itgozYGxboQFtoycyu2vBOs5j3ri9cnUQkhaKYNvizpMoOgNWySnvJVh0PD+nq ivtAkWUrofmSfnqdFNiaHeypsjkXrkT0X1E+Q9v1aIUBi8x3dfPUKV3shrYc7rZXQ0hmvJ q+aLUUmtxc9Dicl35t0EYKeOGc8tt28= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-1-IQ67-jM5Kx0I6fCVOLvQ-1; Mon, 11 May 2026 05:04:05 -0400 X-MC-Unique: 1-IQ67-jM5Kx0I6fCVOLvQ-1 X-Mimecast-MFC-AGG-ID: 1-IQ67-jM5Kx0I6fCVOLvQ_1778490244 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-486fa07f2bbso24357545e9.2 for ; Mon, 11 May 2026 02:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490244; x=1779095044; 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=91FyDo4lvxPgkiSt2vN5y4yAYQZnqJbtxElmqdOrkw4=; b=XUVsh+IcxcX2nyY6bcxhAbBHXZc3gg4ZxGnSWNaIAoP6pYNi8b24qppi1CdqdbVm0k eWxv56RE7dPa4x9jKPkdSBtSXtSM/lSb6S7NIWo6ZYDnWufh7q9a0H91sGS02maFXcu9 /ODCQJOjbxKxV5ZQlMtnhZqOC9DaFAuqNd2CW36isFNt/Xi70oKQXwmXOgHCRclTpz2E n4N9ZFEBFPjP1XqDOLqPi1N4mxJR/2SEGsEC3oL5BMbGH7YtELmjOoJYfHERiygbucF3 m7dAHIXiiYpLanMlqagxBLz6Y1Soof1inVgR0AyDtPnw2ljVOmDp+q9dML9slWE+5MuW xTjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490244; x=1779095044; 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=91FyDo4lvxPgkiSt2vN5y4yAYQZnqJbtxElmqdOrkw4=; b=hdg6AImgGcqWdd1oDM0B/U3fy3piQI+dlQ4E1LnS65sjLZc1Gv6ipykqA4sas5RC8q mjTCAWGo6mHJoHl1F8FfTaB80jtLLVlEk91forXdNRKrZjiWm4e97DNYsmLaDYisYklp Z6JUj9yXXoLkQElhr19obpXFEjmiykxgoN+4wV9icrFnZFrcR+cBK82uDZWDyMTHMFVU aKC7O2B5sR2oENPbbGpI+8w+SaUZ+Ob+p2DCL/DCIYgjHHF6M7Z0RnySYpnmztn53MDW 3soZ8zv7CvFHphD9a5smjDfn8NKQW8QPKEvh8vvRRpfrr5aYu4ON152CeGiEkTsM8u10 4Rrw== X-Gm-Message-State: AOJu0YzQcPSZZ0L1/lpp+i9zxr5UmJMFdoprtXG6F0/brqHZzA+AU00w FoxvpMUDUGdMoyIZCJqm5RYVyxrsI+PETCFRd8zhDpFKrH3w/PGgi3CbRNhUeUwmAsJ2TIDLCV6 941XqzWVZZJ4pIQ66eoA7eotmDXp8a1HwQk8eHUXmDKxKeh9++Y5RGQa5bbARqqpzVh0GsWWcDO dh/VXcTgaLKHicY5ej1G7GQLlJgdWio0w0PN62j436bkQ= X-Gm-Gg: Acq92OEidBoOFeGCbFHhVGfVV1efsC4s1uCSkmp3o3esNp7Hhm0vRRmGJYX2903vYAh XoiFjtnks5iAdfsZieuAX0nsBfSSs7/JJI5J7fgGtzOLWOGdOyh0VXTHibBcwqVTObiWQKY/jcZ 8t8Tf5uQqOKQDY711xYBWT8UoBxR6kLFVNmk0c5tdYEGrQun2jcWm/ZMkZROkRkysb/629fF1+A Uq+nSCsQYaB99ak5NRpbcgMecJwsxE/5zHGqKq71FajDBHsDnj7nEWk31ctYQP8ziMhIT5Vh2Ez qNkaAWvXA5NEPAGBF6Nu8c/S8VFdLExcQuC8O3UHLIDcQjMNSuU1vcmxRtmn7tEynB/Eo5Ac2CP J+r54MeofYXsaPIm9UkrQEi8oi5TWh2YR1PY1z0EM X-Received: by 2002:a05:600c:4e87:b0:48e:706b:53e8 with SMTP id 5b1f17b1804b1-48e706b54famr152707235e9.11.1778490243850; Mon, 11 May 2026 02:04:03 -0700 (PDT) X-Received: by 2002:a05:600c:4e87:b0:48e:706b:53e8 with SMTP id 5b1f17b1804b1-48e706b54famr152705715e9.11.1778490242995; Mon, 11 May 2026 02:04:02 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e702f4042sm180354375e9.14.2026.05.11.02.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:02 -0700 (PDT) Date: Mon, 11 May 2026 05:03:57 -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 resend v6 24/30] mm: page_alloc: propagate PG_zeroed in split_large_buddy Message-ID: <53c45baf0b66b9ddb042377a2e060f7f88b9ad64.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When splitting a large buddy page, propagate the PG_zeroed flag to each sub-page before freeing it. __free_pages_prepare clears all flags (including PG_zeroed), so the flag must be re-set on each fragment after the split. This ensures that the buddy merge logic can see PG_zeroed on pages that were part of a larger zeroed block. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 468e8bde7d34..ce43f5a3dbaa 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1523,6 +1523,7 @@ static void split_large_buddy(struct zone *zone, stru= ct page *page, unsigned long pfn, int order, fpi_t fpi) { unsigned long end =3D pfn + (1 << order); + bool zeroed =3D PageZeroed(page); =20 VM_WARN_ON_ONCE(!IS_ALIGNED(pfn, 1 << order)); /* Caller removed page from freelist, buddy info cleared! */ @@ -1534,6 +1535,8 @@ static void split_large_buddy(struct zone *zone, stru= ct page *page, do { int mt =3D get_pfnblock_migratetype(page, pfn); =20 + if (zeroed) + __SetPageZeroed(page); __free_one_page(page, pfn, zone, order, mt, fpi); pfn +=3D 1 << order; if (pfn =3D=3D end) --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 0B62E3B9D93 for ; Mon, 11 May 2026 09:04:13 +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=1778490255; cv=none; b=JjcwnKD+PgSKmCEINpf/E1nteJk6LiQ/4JlIfuXOUya2Metk0DHOc7i4k6l8EvU4EkwkVY1p8IoihXdPmrTtgmBzipmzfQ/62CiRPLZpipvl4gBtl5yPj2NsnhVg8D3QkyozXqQIR8ZpDbd28/iGW5WbL5vE2zlyOLoMCOOEiQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490255; c=relaxed/simple; bh=kbeC8rzPmxUpVwR5cb8LtaGHCXNFNmNT7voh9QmR/3I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bJmoW25QyWpxBMU5cDV92AJ3ZbCGqQ31SVBfq1wZdGtQpTrkKQGJDx0lpYi7x7Ir2SNEEioTg8An/O1Mh7baTndJdrdeOAp0my3Cf1s+F/mfmyqT5ySEmsda6rgKoq/k56YG/f/QhNex9VyNEI5zxl4XhgBlODwH/IwTuO6L2BM= 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=dU75EKnF; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rbYaI6Ny; 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="dU75EKnF"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rbYaI6Ny" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490252; 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=R9MIHVZ1NMFTjGw8qWZvRYjcRPTh67thc0mkpGrxtNM=; b=dU75EKnFGxK+5HRacB4B1k1D+nZp2T2ai/Bajx2ObM3GZA2sQcwZOaEIBCGwuniz6Cbprn 7lRQknRAIJlJz8jyaJp/hsqG2zT80Qq9JT29VlI3hVM4pDMkFUzg/qg3dgUz5QkYDUbkYW twSJno/VLtIB3IZWLpQswU/13hBXVPA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-xim8ZSwHODWTnf_IiyfYEQ-1; Mon, 11 May 2026 05:04:11 -0400 X-MC-Unique: xim8ZSwHODWTnf_IiyfYEQ-1 X-Mimecast-MFC-AGG-ID: xim8ZSwHODWTnf_IiyfYEQ_1778490250 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48a9592f666so26641695e9.1 for ; Mon, 11 May 2026 02:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490250; x=1779095050; 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=R9MIHVZ1NMFTjGw8qWZvRYjcRPTh67thc0mkpGrxtNM=; b=rbYaI6NyeyyILU1XZkY5uHECtlONP59SgSE+jLQyadEJzS81tjz4hD64ifrv959tdh Scc58zQbOa57YOZXxRCe9v+IFP+LpElV5Hl40f5b1RvZSQct4eRHSHxPWEH2qTD1lkjm l6I7sR4aahkRghGTAZwBic0/ZR18AwY80+7EbEQrToNRAaygGKL1TJBqLJ6fd0vI7GzQ BGdMOptoD6fA5NWN4u8PdFbiRoTWzendGaqXbsfIO0UagF2VSqiTlFoGIShMrTvAnCM/ e9KnVhQInKq3lKwPxBk/4WyqkDY4nVsG/CZQQmtbPT1va5Au/lBfvuVIRvqtuwDMd+Mw 6+AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490250; x=1779095050; 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=R9MIHVZ1NMFTjGw8qWZvRYjcRPTh67thc0mkpGrxtNM=; b=MYPFtNFKBk1rWizqNp09g/ErrcjCRgH34M5TCLTNDh7zQ30QdsBNoYhqtAgXfZMNtV xeqQojWl0mDV4Xv2gqKwFJtLyHtbybKkdU1xABiqI1D1ieUG17PGAJ5+BGc8iY6t4U2H Cnz/FRUR3x1nY4U5wYatbpM66OMLUUvGtptqFUsNUYeL29k4UQi7Rygg3rqY+UAATTIw 2fkzF5N4cOPIrqPTX2NXr+OIOpyvzNuJ6hMbYEhzxpCDDy/EVfxOhevp4Ydn2GDHxmRO iJUQ74a22LGwch2zCGpb+3K/zDqwBkUcAm07K72vlBelNMJVIm/neTUn13VB3Us/IJ2F U2rg== X-Gm-Message-State: AOJu0YxOTUBuvXSh320pA7MHfByat6I7hwhyZ9PaevctXlvn9CmOymCc a13lvRmFL4NSZdwvpqPmkYQKpg2J+CWvbDljF8e3iJNDYm7uJ7ne4QX5h5jN5UT46I+riWfwGH+ yTj6audYUzz0ETLZRa5DEYPMiBv4TME+4ZhOzzKOInVKPKeqW0wfCXsShrU9Chu4HjnVxmzecU6 wSZLnMUfaeVS1Ec+8UN34x5q+3lc7OYisp0R1NndTJcf8= X-Gm-Gg: Acq92OFi1P75ALCskYhynnWkGyVV+4qTjQuXFyXGBWk49NSuHy4OpBCdjNBaSKx7/96 mENkYdz3pULGPFyMD89HrAKBUesL36+axWHVIy0n/dwn7Zj5QkWTjEwAiwItdV1y2pRRZkMsIel MowgyF9CgT9YaydEfwS/VmfiwnHbJf0zNCqvLk1MrvSGDsmuYKnH4Ig7crlq5ERqRc5jj1JyCeO R8bFoWEpEdj1PaaR6ErrfI8Ys8gv8EOZ8wEHPQhFKz1WdSjUJDek1ckJvLfT7lT1bahXzn4JwOG X+STYQ+B+BG3vQlA7SgYZlRf5PGiXGyUYayehlt4lo8gz02iH1H5hXEDV2glmb+tIQWQRee1ZRf VrhLsDCmxkqCbOxky81uW2fmA+Lo0ZzWfNRySOI9W X-Received: by 2002:a05:600c:6299:b0:489:1f97:6b1d with SMTP id 5b1f17b1804b1-48e706edd0dmr143939285e9.28.1778490249190; Mon, 11 May 2026 02:04:09 -0700 (PDT) X-Received: by 2002:a05:600c:6299:b0:489:1f97:6b1d with SMTP id 5b1f17b1804b1-48e706edd0dmr143938055e9.28.1778490248435; Mon, 11 May 2026 02:04:08 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e702e6d41sm220651835e9.7.2026.05.11.02.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:07 -0700 (PDT) Date: Mon, 11 May 2026 05:04:03 -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 resend v6 25/30] virtio_balloon: skip zeroing for host-zeroed reported pages Message-ID: <4a0f26ece4b662e928606a638959389bcff66b53.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED (per virtio spec proposal): when negotiated, the device initializes reported pages (zeros, or poison_val if PAGE_POISON). Check per-page used length returned by the device to determine which reported pages were zeroed. If used_len matches the page size, the device successfully initialized the page (e.g. via MADV_DONTNEED), and we set the corresponding zeroed_bitmap bit. Gate host_zeroes_pages on the feature bit and page content: when PAGE_POISON is negotiated with non-zero poison_val, the device fills with poison not zeros, so pages are not zeroed. Clear the feature in validate() if REPORTING is not present or if PAGE_POISON is active with non-zero poison_val. See the virtio spec change: https://github.com/oasis-tcs/virtio-spec/issues/244 Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 22 ++++++++++++++++++++-- include/uapi/linux/virtio_balloon.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index fdfd828657dd..e5d11782ce41 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -204,6 +204,8 @@ static int virtballoon_free_page_report(struct page_rep= orting_dev_info *pr_dev_i struct virtqueue *vq =3D vb->reporting_vq; unsigned int i, err; =20 + bitmap_zero(pr_dev_info->zeroed_bitmap, nents); + /* We should always be able to add these buffers to an empty queue. */ for (i =3D 0; i < nents; i++) { struct scatterlist one; @@ -223,10 +225,14 @@ static int virtballoon_free_page_report(struct page_r= eporting_dev_info *pr_dev_i =20 /* When host has read buffer, this completes via balloon_ack */ for (i =3D 0; i < nents; i++) { - unsigned int unused; + struct scatterlist *entry; + unsigned int used_len; =20 wait_event(vb->acked, - virtqueue_get_buf(vq, &unused)); + (entry =3D virtqueue_get_buf(vq, &used_len))); + if (used_len =3D=3D entry->length) + set_bit(entry - sg, + pr_dev_info->zeroed_bitmap); } } =20 @@ -1048,6 +1054,9 @@ static int virtballoon_probe(struct virtio_device *vd= ev) #endif =20 vb->pr_dev_info.capacity =3D capacity; + vb->pr_dev_info.host_zeroes_pages =3D + virtio_has_feature(vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); err =3D page_reporting_register(&vb->pr_dev_info); if (err) goto out_unregister_oom; @@ -1173,6 +1182,14 @@ static int virtballoon_validate(struct virtio_device= *vdev) else if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_REPORTING); =20 + if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_REPORTING)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + + /* Device fills with poison_val, not zeros; disable zeroed hint */ + if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON) && + !want_init_on_free()) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } @@ -1184,6 +1201,7 @@ static unsigned int features[] =3D { VIRTIO_BALLOON_F_FREE_PAGE_HINT, VIRTIO_BALLOON_F_PAGE_POISON, VIRTIO_BALLOON_F_REPORTING, + VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED, }; =20 static struct virtio_driver virtio_balloon_driver =3D { diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virti= o_balloon.h index ee35a372805d..13074631f300 100644 --- a/include/uapi/linux/virtio_balloon.h +++ b/include/uapi/linux/virtio_balloon.h @@ -37,6 +37,7 @@ #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */ #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ +#define VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED 6 /* Device initializes repo= rted pages */ =20 /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 CB59F3C3BE8 for ; Mon, 11 May 2026 09:04:18 +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=1778490260; cv=none; b=UWHOabkjgFcKNzrE3eicRZyoaZLiYggzn03UrUW/RDK22HmioKhu4Uu5bdGGHZjPUDKNG8DT1bbCxVRE52Abj1uQQoWTvtnLKke+FVv0400ePv9nWVqt7oG3OcCwWKPW7c3vewXwoGcbAuXpEmxrF4qdvS91qpTlZTrVbF7SNr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490260; c=relaxed/simple; bh=hR2o2io1GAVOsJv3zXjIRMgKCnEd5FQaTzCnowpFuV8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bdp0NHu/LSPKdsIOGad/+p9Jp3xhZ5ng+pb4//mdbQ2iwcW0Jqyc6h+iKab+Lto2bwRe2Lw2iSljK0xTLBdH/W0U+Sm5F9PeOLPHs8wbsEWu1PKJT2hR7b2zCEfoLmF4ZsWNg0WRd7APAWdlF+WBu4l1o7Ep3HGTCQBrQr2bExE= 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=CVvPNRvn; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=dpyxhX4/; 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="CVvPNRvn"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="dpyxhX4/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490258; 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=t2QKjWRUGZavYM1HdL6nJ1yLQpyzjFP+uSIPdSalIxY=; b=CVvPNRvnHR6mIgpHrBsHoT6CItRwAQO2jmrXxEZdaRyHYyQ2NSYo8lfdd01OdCw13+hbb5 LNcR4xbaoYa+aSkQRs4r/6ewwNclM5mf2MEZPHvkRvlpzpG5r/iAB/d6T4iu34e8OBKYH5 IOBMck+qjG1lwFadotrFEFGE+HkvG/M= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-QPDfNx0dMp2kJvgGfhSJVw-1; Mon, 11 May 2026 05:04:16 -0400 X-MC-Unique: QPDfNx0dMp2kJvgGfhSJVw-1 X-Mimecast-MFC-AGG-ID: QPDfNx0dMp2kJvgGfhSJVw_1778490255 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-488ba2f4094so31584135e9.1 for ; Mon, 11 May 2026 02:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490254; x=1779095054; 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=t2QKjWRUGZavYM1HdL6nJ1yLQpyzjFP+uSIPdSalIxY=; b=dpyxhX4/DrGeggCgzI1Kjp+vD69GikRFPPRQkcR77JnzHDwkMPJ3VYYDB4RN/a659A izAotbyYojjTWYCGPCHifN0TmEioBV2g+T+HJnKLobk0sYqQyi+T7P+2GgcU1EkGgrFa FhWuNyGSe1ZcD0WXQCbSDUEX39XBLSnYF1M6WPiOPopXyHSj+NuDxvB5nxl2LV4y/4WV lDshXdOG+O+2yjJ4eNegOq7/iEz+tRhWqms32dYG1fcTghu8z4KYgv1EPaeK8PKc1BV5 spHo/STX2Yp/QUKW+AUVixIYZ5hLeYHiw1FSv2JwDKWOton8ufO+gEAXXas63JZNpnEC kuSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490254; x=1779095054; 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=t2QKjWRUGZavYM1HdL6nJ1yLQpyzjFP+uSIPdSalIxY=; b=ilPzb2cS6N18toLuYTv33J+aah6yc5LiTAh2xd9uo02LXmL3AoCQxa/l7zX/hFV27s QecbOJrZLWql9doIgEwn2AZLVytWfI67FUSuWtkfhxmc85Rv7tn8hYiXGb2Rt/UThVBM Xa2vSqxkkYHl62qG9Mqnw2hpc44ewi8kKxOVPTsccxr+Hg/Wjc52WQaq0jzaioKeFpQf jCnTSn5IyGCnSQ4kZlaqiZZZhi0sLKPxLJXg+UPoz8sA4TilgHLb7LhMQ7WWmNsdhvNZ nUYTogIGpH9dIZflKGnd09TzqIl+jMZ/mjvd7v8dr+PYG9kyUS26Xapi8ReTN3moBvgm o/aw== X-Gm-Message-State: AOJu0Yy7hrtboAVFRiK7lGfDeYXcSbGCuEUYcAk0RgeXCvc1zs4Q9UXX 3/QPtC9+Ax9ACGWUKpOZLg2QnCo3gMrc7FESo3Ebt6FKd3Wm8X2gWfVn/rqgTqmHgzjbM55QGwL 1uqZa2sP81k25MzwYViOQ3zaS3XcRtO2XIyQQgAaXY/byQgMbgmf3P0COrMC7Jx2t915pvmBtvz ibhLLqWXxWzIVGwDEVzcnC+PkH+unS2XUnDIENoHFfTC8= X-Gm-Gg: Acq92OHuEAdtPa8M70qcVlUvEY7/5UJB0LlCMH6b6jVH8yJ1JW+bzfSjzm+z3sxS0zE D2S4iiYxqPF0Wy/765r8nRUW3gXPf3/s5pygfXr0B0Wt+ZddJxjEqVVSlI1T8EbnAemCh9ApKjA OBZX0Apgq/Bc/Glsy5n1zqDkebB5vZGTLUIHHQPYtqzJnFt7ij7p4X/tPRSp64Ro3FyBWHUPmoD OCdIOkaot0hP+/pPMP2XtZSJzLS9WYtUEIJnFIsn479Sy0SukVNTTyJVq2c2KIzRNyvqXq9/wMP +8F7hJzBYjlzGzAftSzl8jxuDWa79zXAD2+udXRMvV2icWYpbZ9uhBJSiq2k4eLD9EXsgq2I3Rs aPHD4RGma7zkXb3N9z4ImhjCAA40G0f4xcR9kEec7 X-Received: by 2002:a05:600d:1:b0:48e:7f1c:8760 with SMTP id 5b1f17b1804b1-48e7f1c87bdmr67342715e9.27.1778490254418; Mon, 11 May 2026 02:04:14 -0700 (PDT) X-Received: by 2002:a05:600d:1:b0:48e:7f1c:8760 with SMTP id 5b1f17b1804b1-48e7f1c87bdmr67341395e9.27.1778490253720; Mon, 11 May 2026 02:04:13 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6db0b08asm78949215e9.8.2026.05.11.02.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:13 -0700 (PDT) Date: Mon, 11 May 2026 05:04:08 -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 resend v6 26/30] virtio_balloon: disable reporting zeroed optimization for confidential guests Message-ID: <77585f29352cb5fa235898db07e7a3fa04d4d04e.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In confidential computing environments (TDX, SEV-SNP), the host is untrusted and may lie about zeroing reported pages. Clear DEVICE_INIT_REPORTED in validate() so the guest does not skip re-zeroing based on hints from an untrusted device. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index e5d11782ce41..d1cdb904d60b 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 /* * Balloon device works in 4K page units. So each page is pointed to by @@ -1190,6 +1191,8 @@ static int virtballoon_validate(struct virtio_device = *vdev) !want_init_on_free()) __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); =20 + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 D34B73C456D for ; Mon, 11 May 2026 09:04:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490265; cv=none; b=K5Fx2udPcVGPFPy+GxLas644yZolfD51x/dgZ6dXTLh5oT3V20p6YKXI+OsX4Lm1A+h0jIsF93IaZrZGjpRQApnFNVum33mN34Hu6oksA+3E7txAgxYMAWVv3cr+wft2aGmHX13tJBuuRmsqWn+kn9X9BkncOs5mJgRwWPcedFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490265; c=relaxed/simple; bh=+KuiJeJuJLSkbIBerUOZ9dDZIAZp2qPNKBgWnFOfNwU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QOweKPHFnu1amBS/xQSlKHCfSFp6Y8igRDv9l66oh6g33mIShr/JUrffeygUYyvYCFRCUJO3zovf7PPgQoQwjvrhaxj5EI2D+JiDiiYa1WnxlRyeURPg6wThynE7gITQxW4lxecktk5boiO/Zfm4gikDAC2syYe82t4a8L004Qo= 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=NSxSf7bC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=iXjGGcyZ; arc=none smtp.client-ip=170.10.129.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="NSxSf7bC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="iXjGGcyZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490263; 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=tewXfhJCZs85isDfaCarY9OYs1rdE/frw9lqrB10rtM=; b=NSxSf7bCx04m5JVxo1nwtaiaV2vjdXf2WwPlBqWg+eRBUCl5nSdhKFl8Son6Hgh6Duhzo/ /VxwwXLR7w36nk1z9unq9+gM7TWgSLEn4Iv4ZwZ4/hN49Gv4uylQiuEYnwv7kgyxaaAi5A nY9EOTa17clAMwovFe20MbFHMeJyA1I= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-1a-HNYBROd6GpS5Wy2EOhg-1; Mon, 11 May 2026 05:04:21 -0400 X-MC-Unique: 1a-HNYBROd6GpS5Wy2EOhg-1 X-Mimecast-MFC-AGG-ID: 1a-HNYBROd6GpS5Wy2EOhg_1778490261 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-43fe791a398so3727481f8f.0 for ; Mon, 11 May 2026 02:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490260; x=1779095060; 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=tewXfhJCZs85isDfaCarY9OYs1rdE/frw9lqrB10rtM=; b=iXjGGcyZNk5hVxB9lEWpVrlTX7pDHw4acpiKIrLoHYxoCblOvTRfc6/Cbdooyj2IYF Ya/gxF7bFte7o8mc3O1Z247KWzO464DGASJRelmZ2f7P4uYOwAW8vt347JssuQuozuJL yCVLwNWiTxOSMfZMy4v/jGvVaVNvgxxRz4dE8PCK0nCtDvd5glP7PVnGjWYzWSy3Bsit rqoI+shvsfhOMmHWTFe2zP5kTf+xDQ47hEmVmYmeijjSrc5BQqP9y9nUqCQhcSFFAwAC /K69XX5S1g3R74yNGc/9OLfCPhlGwe/uoNqwYl+AvlfDmTTvKVfZNuvKsb2swflYuaQq sRYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490260; x=1779095060; 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=tewXfhJCZs85isDfaCarY9OYs1rdE/frw9lqrB10rtM=; b=gMDI/EVG8oXDlAULOHqltJVkDfxGl2uX8IhAffdQJcE1btwj8hmaiFhffqqASDsAEW gPCBOS8X5uhDj1yRrXGewvfTpOu3geND/ebbI0HpkejH+epaTkayVwfoIchj3rOgxd/w zk3QKFTIxUc3d6KOIF9rtrhPIDTXrF2DmOGh5xkCeL2kpJvj7BgAz7FYVaEcS1u4MgTv DuosJ1rsPbsxOPm/J8oX+ECkkOpZ+WsgoP96SeXZ0oDxO+DDC1HIBdblhvGDNdgpHsHl jEs5kjbr+qMSAAsGiyKuis5aCOx+5r700CFGjzkJgNBbRLoEVRCwc/jj+lqetisO/tVI tM4A== X-Gm-Message-State: AOJu0YyRf7uawo8/31kBkTVHuLTT330uUV0dP4bjQmb3PfpNODs9Fu3o kYn6e1hgIwy4ITE/mRL6Sa8q96HOf2VCGqTW0GnFGHSSan4N4ENDK4adxhTTGjNEirzHfNsjkQP tbASRrMfi2cRdHfgIKxKbyzO/lD8YwFYt2Y7th+wegPO4krog87t66R/8/5HGe7NvqoFOEbFrsQ CIFwpq/Q5iS2ug8C1OcxvV7gHcboYPQZEr4SltmFO6AAs= X-Gm-Gg: Acq92OFLwTU8dDKgowEkAOBE061ccSUTzpg2VvInNqhKIzvFYJKnY+g6WsNRyRTeDx8 TVbuShN6x3u5ZHFLnqI8HfDWYFsRMMnV43C/+7LM0I037BcAf8sDMshHneXBnD6Dl+mu5YZcdL/ hJsQvbauWYadZQO7wwLYrURuOtGIc4Qxa8hjq1WyszooKwBh/L42nei5UeWV+JQKOFpHkxAYTPa Qd8Y3wzmgOZWTMyg3StFDc616dFBUsd2Qc29iOnVxIP3kDr3WIEB900A1m8mrSiACgjiEY0iXrG NTrnOkOkVKMCNMaIAYRzqT9ynq8nGQ4wkMlJI2/9xhB2aBlRUKCq65FWV+gQfy9pTr8c55OWGS2 wlpKVQtzxywv4ypAaS2LtQ4wg0BbQBg9sZZT2RSUT3yeyR8BEw1k= X-Received: by 2002:a5d:64e8:0:b0:43b:5672:efe with SMTP id ffacd0b85a97d-4515b056cf3mr37638833f8f.9.1778490259966; Mon, 11 May 2026 02:04:19 -0700 (PDT) X-Received: by 2002:a5d:64e8:0:b0:43b:5672:efe with SMTP id ffacd0b85a97d-4515b056cf3mr37638683f8f.9.1778490259026; Mon, 11 May 2026 02:04:19 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e4bb87bsm23423788f8f.2.2026.05.11.02.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:18 -0700 (PDT) Date: Mon, 11 May 2026 05:04:13 -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 , "Liam R. Howlett" Subject: [PATCH resend v6 27/30] mm: add free_frozen_pages_zeroed Message-ID: <94ea0046b290ffd74a1db6c5e89962366dbc1a1a.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add free_frozen_pages_zeroed(page, order) to free a frozen page while marking it as zeroed, so the next allocation can skip redundant zeroing. An FPI_ZEROED internal flag carries the hint through the free path. PageZeroed is set after __free_pages_prepare() clears all flags, so the hint survives on the free list. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/gfp.h | 1 + mm/internal.h | 1 - mm/page_alloc.c | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ee35c5367abc..e0d5743de68d 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -384,6 +384,7 @@ __meminit void *alloc_pages_exact_nid_noprof(int nid, s= ize_t size, gfp_t gfp_mas extern void __free_pages(struct page *page, unsigned int order); extern void free_pages_nolock(struct page *page, unsigned int order); extern void free_pages(unsigned long addr, unsigned int order); +void free_frozen_pages_zeroed(struct page *page, unsigned int order); =20 #define __free_page(page) __free_pages((page), 0) #define free_page(addr) free_pages((addr), 0) diff --git a/mm/internal.h b/mm/internal.h index fa7ffea4d492..0ef6f8221e5c 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -934,7 +934,6 @@ struct page *__alloc_frozen_pages_noprof(gfp_t, unsigne= d int order, int nid, #define __alloc_frozen_pages(...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__)) void free_frozen_pages(struct page *page, unsigned int order); -void free_frozen_pages_zeroed(struct page *page, unsigned int order); void free_unref_folios(struct folio_batch *fbatch); =20 #ifdef CONFIG_NUMA diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ce43f5a3dbaa..8eebe01cda80 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -90,6 +90,13 @@ typedef int __bitwise fpi_t; /* Free the page without taking locks. Rely on trylock only. */ #define FPI_TRYLOCK ((__force fpi_t)BIT(2)) =20 +/* + * The page contents are known to be zero (e.g., the host zeroed them + * during balloon deflate). Set PageZeroed after free so the next + * allocation can skip redundant zeroing. + */ +#define FPI_ZEROED ((__force fpi_t)BIT(3)) + /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */ static DEFINE_MUTEX(pcp_batch_high_lock); #define MIN_PERCPU_PAGELIST_HIGH_FRACTION (8) @@ -1596,8 +1603,11 @@ static void __free_pages_ok(struct page *page, unsig= ned int order, unsigned long pfn =3D page_to_pfn(page); struct zone *zone =3D page_zone(page); =20 - if (__free_pages_prepare(page, order, fpi_flags)) + if (__free_pages_prepare(page, order, fpi_flags)) { + if (fpi_flags & FPI_ZEROED) + __SetPageZeroed(page); free_one_page(zone, page, pfn, order, fpi_flags); + } } =20 void __meminit __free_pages_core(struct page *page, unsigned int order, @@ -3000,6 +3010,9 @@ static void __free_frozen_pages(struct page *page, un= signed int order, if (!__free_pages_prepare(page, order, fpi_flags)) return; =20 + if (fpi_flags & FPI_ZEROED) + __SetPageZeroed(page); + /* * We only track unmovable, reclaimable and movable on pcp lists. * Place ISOLATE pages on the isolated list because they are being @@ -3038,6 +3051,12 @@ void free_frozen_pages(struct page *page, unsigned i= nt order) __free_frozen_pages(page, order, FPI_NONE); } =20 +void free_frozen_pages_zeroed(struct page *page, unsigned int order) +{ + __free_frozen_pages(page, order, FPI_ZEROED); +} +EXPORT_SYMBOL(free_frozen_pages_zeroed); + void free_frozen_pages_nolock(struct page *page, unsigned int order) { __free_frozen_pages(page, order, FPI_TRYLOCK); --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 F255A3D5228 for ; Mon, 11 May 2026 09:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490271; cv=none; b=RGwVovEb6traoU6//WpU8AwbkI8nOEx2NjGKYFgHl9sWLOk9e9MBnC/ywJX8eSz89/90JwIJqDfww/WzTlQ0oJcUFaEPT6rxvJtns5kkzBelrkpTCn8j/r0GDPN/dUNuFg4CY1CGacaStVHlvtr87A4I9UlEL6M11hH3oaNF+vY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490271; c=relaxed/simple; bh=FzG8+92oH2mwvb1TgGky3Bd7ojioTSewgWR4luIpYTY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xg+SjBZbDFs7SSijSRx9P8c9PbuCeyL0FAFcTB0NzeeKIR6VyAhQUz6AFHZdBBVDHGSgBucnc0Rs4YivSu/v4F2taypR93WsNEfPtBfbDnLaq5A6M8JbUmARTPyNqN/aZXOO72G8oMO7+QcTX33LtAi+HU3Lt8M71+xVVj329A0= 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=HMUvj9Hv; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y1yd0xDR; arc=none smtp.client-ip=170.10.129.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="HMUvj9Hv"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y1yd0xDR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490269; 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=gBKqj2O9gjX/tz0GTabH1SzaDOD5jZb/zvIFduhmeuI=; b=HMUvj9Hv8umZRJ1eBTeyhrw+zJv6QQz8hnOP5o5eDUKL5Jm+QKnFX8yL4lmD8FF4pJqepv ucgb5sMy7CYa81o4xsxtucqFDl0LvZmf0YH/1W0l7q9vLzbGk9d6CDGSehrGRSgv0HNy0c /a87K+baXTLoSSB57hASVKd7UXRrOuk= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-jMwJgwBROSGkuR50L5ekgw-1; Mon, 11 May 2026 05:04:27 -0400 X-MC-Unique: jMwJgwBROSGkuR50L5ekgw-1 X-Mimecast-MFC-AGG-ID: jMwJgwBROSGkuR50L5ekgw_1778490266 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48906aa28cbso37470815e9.0 for ; Mon, 11 May 2026 02:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490266; x=1779095066; 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=gBKqj2O9gjX/tz0GTabH1SzaDOD5jZb/zvIFduhmeuI=; b=Y1yd0xDRtR1HlMSAhVzDkVfr9OYQpDekkgSBe33ytzLPJtIkH0AbbWKChV/Uw96PlS viyO8P/kTOTCg3cE8XOWFQnnTOOxV2w4qCgd4YTI2yzOLpVDwK5GEoja1klcukIvjiIo 7ZoSQCzY8LAdxTc+rf3uXmg6kGQARZfDwQkx7GmiiilpYvJZJ1bcxy95LV7oZgSOXM9u ajDWj7Bn+xXshE97yAOYQat2vBwoPS1w3kby3+BkIyymXG5O/3Vyb5IVfrNGkkGaa3Is T8iWjWXdW4TpHag3QVTT1+iph5wySsQTiuhOG1XJQjsdLvRzgC8vy1OD92nQDxugg1xi kpNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490266; x=1779095066; 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=gBKqj2O9gjX/tz0GTabH1SzaDOD5jZb/zvIFduhmeuI=; b=dklBVjwBEIOB7TpSxxYo21Jaxu54VqNW+oWollPljQxuhvFtfc7DV0+KBX3XiIMPYi EWIlwNZyrX5hp4eljrBOhQWT+5Ex7iAGXOUFeMuvql2LWG/AWz3kr5DIVYgRKfKQnBvl wV6Xy7KSN+L9qmrsqLjOipR9tQ9PdGP0TwVz0N/7FSWGzbkxMhXSujdmwXps3bcsDs7U VFdkgMCR/wMU7WKQGETgQXVcHS3h5fnC2i2mEgJWWBLopMgiJmzvIup40szSGakDWRPc OKJR7RGmrULCFZswu19ZnbglMu6T5ezJvnBfNZiUDdTbe4bM8+VNt3j3E3Wa3bTYE0rW uaTw== X-Gm-Message-State: AOJu0YyHT8akbIp2SlZdfTWnmvDTAv3bn6ZOxpg+ktfTNiRg9H0RGGRH jQaA9p63ZSZsc3UzcT5XNHaUkGxxgw9g2zPMnV5+eU0B8nAWGJlrExAvI0cqZ6DWcsJzr/+3oF+ EucqfaLwa6Oamn1PfXXiYBJbkuCrrvmz1dGh2PsPWCi9T4ovN5E45vGQL+xydISbqBJPE8ItZW+ Yk4fZox+4Oz6Z4lAYDC7JpOLItcnGIxhr+a+38s+vD9hU= X-Gm-Gg: Acq92OHSTuq0hH3qru03KqtWfDYzrl14tWeny+zaOUbHdhcTRmq1TWrVm+9jjWCi1MU 0O4wkBR57mv0TNfNIbuiKkRBSSBvQXFO4mYog52AoJPkViw7hoRhwZbqvpq7jvj4OFKEjUGgTxg +INjrB3fHUJxuAT3kztjJAq7UoJFiB7DAx1vU7HtpOsldUy1zwK7+a/32TwfGzaTwqspYeQqPAn 8GMfJqCWed5LUZtK4UUv+PFlQxLGFSIjAJv+uYHnAByoNbyT69/ri89VSDdxHzrJQOBEFZW68p5 9/Mbmq5sZTECHqie969e8xUKRK2D8jIA/LOgHz9xbYy8uaElAmjEGWZ6LDDMFkjxiINxikWjs99 14z01xuQHWmHUnDKIdsRoBMDPQ2XxM1nTxLpLOnIt X-Received: by 2002:a05:600c:3b8f:b0:48a:79d8:a8d6 with SMTP id 5b1f17b1804b1-48e642deefamr226935565e9.7.1778490265703; Mon, 11 May 2026 02:04:25 -0700 (PDT) X-Received: by 2002:a05:600c:3b8f:b0:48a:79d8:a8d6 with SMTP id 5b1f17b1804b1-48e642deefamr226934275e9.7.1778490264756; Mon, 11 May 2026 02:04:24 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e80ca2666sm91672175e9.10.2026.05.11.02.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:24 -0700 (PDT) Date: Mon, 11 May 2026 05:04:19 -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 , "Liam R. Howlett" , Youngjun Park , Qi Zheng , Shakeel Butt Subject: [PATCH resend v6 28/30] mm: add put_page_zeroed and folio_put_zeroed Message-ID: <450465e4a03e63381a4bb8a1799a25859d7fdd83.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add put_page_zeroed() / folio_put_zeroed() for callers that hold a reference to a page known to be zeroed. If this drops the last reference, the page goes through __folio_put_zeroed() which calls free_frozen_pages_zeroed() so the zeroed hint is preserved. If someone else still holds a reference, the hint is simply lost - this is best-effort. This is useful for balloon drivers during deflation: the host has already zeroed the pages, and the balloon is typically the sole owner. But if the page happens to be shared, silently dropping the hint is safe and avoids the need for callers to check the refcount. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/mm.h | 12 ++++++++++++ mm/swap.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3b1ca90fd435..4c51b7bd7576 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1913,6 +1913,7 @@ static inline struct folio *virt_to_folio(const void = *x) } =20 void __folio_put(struct folio *folio); +void __folio_put_zeroed(struct folio *folio); =20 void split_page(struct page *page, unsigned int order); void folio_copy(struct folio *dst, struct folio *src); @@ -2090,6 +2091,17 @@ static inline void folio_put(struct folio *folio) __folio_put(folio); } =20 +static inline void folio_put_zeroed(struct folio *folio) +{ + if (folio_put_testzero(folio)) + __folio_put_zeroed(folio); +} + +static inline void put_page_zeroed(struct page *page) +{ + folio_put_zeroed(page_folio(page)); +} + /** * folio_put_refs - Reduce the reference count on a folio. * @folio: The folio. diff --git a/mm/swap.c b/mm/swap.c index 5cc44f0de987..8d57223dfe34 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -94,7 +94,7 @@ static void page_cache_release(struct folio *folio) lruvec_unlock_irqrestore(lruvec, flags); } =20 -void __folio_put(struct folio *folio) +static void ___folio_put(struct folio *folio, bool zeroed) { if (unlikely(folio_is_zone_device(folio))) { free_zone_device_folio(folio); @@ -109,10 +109,24 @@ void __folio_put(struct folio *folio) page_cache_release(folio); folio_unqueue_deferred_split(folio); mem_cgroup_uncharge(folio); - free_frozen_pages(&folio->page, folio_order(folio)); + if (zeroed) + free_frozen_pages_zeroed(&folio->page, folio_order(folio)); + else + free_frozen_pages(&folio->page, folio_order(folio)); +} + +void __folio_put(struct folio *folio) +{ + ___folio_put(folio, false); } EXPORT_SYMBOL(__folio_put); =20 +void __folio_put_zeroed(struct folio *folio) +{ + ___folio_put(folio, true); +} +EXPORT_SYMBOL(__folio_put_zeroed); + typedef void (*move_fn_t)(struct lruvec *lruvec, struct folio *folio); =20 static void lru_add(struct lruvec *lruvec, struct folio *folio) --=20 MST From nobody Sat Jun 13 03:27:12 2026 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 4D33D37D101 for ; Mon, 11 May 2026 09:04:34 +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=1778490275; cv=none; b=aS5I/IJTdAxq8Xmes6fKwTYF2Ow+nn6Y1PlDLPHl+kBdo6vIUME/ax0XuokDj14uGe5w7lz7OsmRJtKgjrI68zE57dtXJlrckKgQObOJdPaGdByNU5gELSXWhnk+Ups8msqGJ1Asc3UdHFJNrc/VZ/mu7/50aEAOcAvlF1iqEpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490275; c=relaxed/simple; bh=tLMVAI8k8Vqd8nAD7gq4ERpr7r8SPw2I/CQ337Am1rA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l5Opv5vKwQpRXXOkE9bCxpnHq9GRioildKggv4DNFCIPk+guSpbYJ+bBYDLiOJTU7wyuqAnK25Vsr6y8c8COwKFw5w/A/Samxh1n54/sBcrrMD7rzd1riI/ChMymW68dqPpqIHLLdi2zedYF2Sm1z65a2HnsseRKRJpBojxxdWE= 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=JyBai0l8; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=SBciGVsP; 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="JyBai0l8"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="SBciGVsP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490273; 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=/f7bc8XiOUNOfql0TOUlaX7QjBdLhxcvl3clNO9GGlQ=; b=JyBai0l8w+zToh9lZFMdgmfr84a7T83epzYz58//TbtTUbI6mSOYG+t2XziLjsni4m4ET3 6PBTzepwB9ClSUOG5pFrrjk+lF4CrYQKbm++lWK6VdQ20pzIjJhilNWXCIJUJvNw7HKdDG zGl2o6lk3sAxSjnrP7PjyrYVWIcwGLY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-330-5JifjJGsNpO2MBW2SfpZqA-1; Mon, 11 May 2026 05:04:32 -0400 X-MC-Unique: 5JifjJGsNpO2MBW2SfpZqA-1 X-Mimecast-MFC-AGG-ID: 5JifjJGsNpO2MBW2SfpZqA_1778490271 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48906aa28cbso37471495e9.0 for ; Mon, 11 May 2026 02:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490271; x=1779095071; 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=/f7bc8XiOUNOfql0TOUlaX7QjBdLhxcvl3clNO9GGlQ=; b=SBciGVsPPBk55hTjU8Xln49EjWicCVxd1ghoVeorVcyYT9ynXZjiHFlxBfFwrF4//+ iAZiuzQFjLXflkAlCcafkZxJy9RBnzj6nJmljJdAFzsmGjpftoDoAJypxVKWyJ5ULCOy sp51/WpqkOlr+casBrD/1m8cFn9f6ExIlhyMYl1cN5kCRsDr2QdQwmxefvS4JsI8YPro tO0TmezOzu+wzAySus+coUZJl4YNPRc0ohXtwByBEFjrXlTj/a+/KUtjUirqwpKapMdL /SO96YClD3sGCThu5t2yv2hhlPXXWF1koYbp8uIqUiEcS05/cZ5LZhCx4jSRsY3b0R+K lJmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490271; x=1779095071; 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=/f7bc8XiOUNOfql0TOUlaX7QjBdLhxcvl3clNO9GGlQ=; b=TaDbvsq+Ppw0unhPKxGGO36LJJS8li7gvnuOpLqMCuvCMnNTyf0GgPV7kU9sgiV0n4 n4oaOHGUN9K7yRYkL9H9wOPwFHO3Cn8Kzr5/v4cqVvxKW4PrUv/QjpoxaJGUUzygU+Dm 5eqy7pp+iQetBY6IzNIoPwarwoyWHnFBjgOaS+ZVMblIqBsC4fQlsQXWW/7he73Ra8CV W3GghoTlo8+vrvPY6Lf/4C1H157N7TrK+0T2+2BCRrLSavsi7bMH/O1B7ITVe/7mawzz AkJ6nJWHJ+g1h/wAsDxgB1iby3PSMaMnPAHq6orTaNlAZwuY9hOY32hz+FQRDI778TFe Oa5g== X-Gm-Message-State: AOJu0YxAc9QmPae3gjnZslXAlRzOB5mE/KnTrP1K5dnyX3GX8lRZc85t 3D3sApYNJV9cM1xoSAmpM+f/NHBeVKUM/k27PNhadBcRSn0PAX0hYydOTAedCgwYTfptk66/vgq GxPtZvQs4VIJJ4R51tOrSgvu3zmJWaT87rhKk79irWBhkubCS+wQjEhDO48uj1xV+x8ICXg47pO 8B3ling1cQKv5JulUMNuhhm4+/al8tCsEj2ujPTSBwJRw= X-Gm-Gg: Acq92OEWaOtxO38DSDTcnPS6VLeFQqtkaopyMUectfcg0qg8gDYnuON/SdbaOgvEIRe Xr+4kMAbSKYkUlOEOrZ5+NJjgJYvU/G1qVV1hhxMY5IKcwlB0c/LIU4B8/sXZGc2SNKJqaD7GLl uGlz8p3JPizc06h9BTZbO7hwgBtgen59rL3Do3BubQZf27OVqrmjvMZ1tY3jC4lZygxne+p1IFx zbiQ/DQUbPHuVZmLRSl8NTC7FEcqHeHqQHuwc/KL+aiL42fbjm7kaARS1/buT8NmuCcO9oKeo3Q SFA8LJ0mn2CzxAXaBQtin7RB50RAbV15c9fkCoo33Ye7f3k4YMxiRmxxzPHtBRRBgiGam/+MeQa ambaGYtefqdUtbbHM8ciDU0RYInvv0n4z/Beh90jl X-Received: by 2002:a05:600c:3e86:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48e5dffabcamr278836735e9.9.1778490270606; Mon, 11 May 2026 02:04:30 -0700 (PDT) X-Received: by 2002:a05:600c:3e86:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48e5dffabcamr278835635e9.9.1778490269887; Mon, 11 May 2026 02:04:29 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6f9fbf12sm186458005e9.0.2026.05.11.02.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:29 -0700 (PDT) Date: Mon, 11 May 2026 05:04:25 -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 resend v6 29/30] virtio_balloon: implement VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE Message-ID: <50c8ac1a006cf4167529b0951498c76b8928874f.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the device offers DEVICE_INIT_ON_INFLATE (bit 7), the device initializes inflated pages and returns a per-page bitmap indicating which pages were successfully initialized. The driver appends a device-writable bitmap buffer to each inflate descriptor chain via virtqueue_add_sgs. After the host acknowledges, the driver checks bitmap bits (bounded by used_len) and marks pages with SetPageZeroed. tell_host() returns used_len from virtqueue_get_buf(). Bitmap reads are bounded: fill_balloon() and virtballoon_migratepage() only trust bits within the used_len range. On deflate, release_pages_balloon checks PageZeroed per page and uses put_page_zeroed for pages the host initialized, propagating the zeroed hint to the buddy allocator. If inflate_vq has fewer than 2 descriptors, probe fails with -ENOSPC. If PAGE_POISON is negotiated with non-zero poison_val, the feature is cleared in validate(). See the virtio spec change: https://lore.kernel.org/all/9c69b992c3dd83dfef3db92cd86b2fd8a0730d48.177773= 1396.git.mst@redhat.com Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 102 ++++++++++++++++++++++++---- include/uapi/linux/virtio_balloon.h | 1 + 2 files changed, 90 insertions(+), 13 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index d1cdb904d60b..284108dbcff1 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -121,6 +121,9 @@ struct virtio_balloon { struct virtqueue *reporting_vq; struct page_reporting_dev_info pr_dev_info; =20 + /* Bitmap returned by host for DEVICE_INIT_ON_INFLATE */ + DECLARE_BITMAP(inflate_bitmap, VIRTIO_BALLOON_ARRAY_PFNS_MAX); + /* State for keeping the wakeup_source active while adjusting the balloon= */ spinlock_t wakeup_lock; bool processing_wakeup_event; @@ -181,20 +184,30 @@ static void balloon_ack(struct virtqueue *vq) wake_up(&vb->acked); } =20 -static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) +static unsigned int tell_host(struct virtio_balloon *vb, struct virtqueue = *vq) { - struct scatterlist sg; + struct scatterlist sg_out, sg_in; + struct scatterlist *sgs[] =3D { &sg_out, &sg_in }; unsigned int len; =20 - sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); + sg_init_one(&sg_out, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); =20 - /* We should always be able to add one buffer to an empty queue. */ - virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); + if (vq =3D=3D vb->inflate_vq && + virtio_has_feature(vb->vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE)) { + unsigned int bitmap_bytes; + + bitmap_bytes =3D DIV_ROUND_UP(vb->num_pfns, 8); + bitmap_zero(vb->inflate_bitmap, vb->num_pfns); + sg_init_one(&sg_in, vb->inflate_bitmap, bitmap_bytes); + virtqueue_add_sgs(vq, sgs, 1, 1, vb, GFP_KERNEL); + } else { + virtqueue_add_outbuf(vq, &sg_out, 1, vb, GFP_KERNEL); + } virtqueue_kick(vq); =20 - /* When host has read buffer, this completes via balloon_ack */ wait_event(vb->acked, virtqueue_get_buf(vq, &len)); - + return len; } =20 static int virtballoon_free_page_report(struct page_reporting_dev_info *pr= _dev_info, @@ -297,8 +310,37 @@ static unsigned int fill_balloon(struct virtio_balloon= *vb, size_t num) =20 num_allocated_pages =3D vb->num_pfns; /* Did we get any? */ - if (vb->num_pfns !=3D 0) - tell_host(vb, vb->inflate_vq); + if (vb->num_pfns !=3D 0) { + unsigned int used_len =3D tell_host(vb, vb->inflate_vq); + + if (virtio_has_feature(vb->vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE)) { + unsigned int i; + unsigned int valid_bits =3D used_len * 8; + + for (i =3D 0; i < vb->num_pfns; + i +=3D VIRTIO_BALLOON_PAGES_PER_PAGE) { + unsigned int pfn, j; + bool zeroed =3D true; + + if (i + VIRTIO_BALLOON_PAGES_PER_PAGE > valid_bits) + break; + for (j =3D 0; j < VIRTIO_BALLOON_PAGES_PER_PAGE; j++) { + if (!test_bit(i + j, vb->inflate_bitmap)) { + zeroed =3D false; + break; + } + } + if (zeroed) { + pfn =3D virtio32_to_cpu(vb->vdev, + vb->pfns[i]); + __SetPageZeroed(pfn_to_page(pfn >> + (PAGE_SHIFT - + VIRTIO_BALLOON_PFN_SHIFT))); + } + } + } + } mutex_unlock(&vb->balloon_lock); =20 return num_allocated_pages; @@ -311,7 +353,12 @@ static void release_pages_balloon(struct virtio_balloo= n *vb, =20 list_for_each_entry_safe(page, next, pages, lru) { list_del(&page->lru); - put_page(page); /* balloon reference */ + if (PageZeroed(page)) { + __ClearPageZeroed(page); + put_page_zeroed(page); + } else { + put_page(page); + } } } =20 @@ -858,7 +905,25 @@ static int virtballoon_migratepage(struct balloon_dev_= info *vb_dev_info, /* balloon's page migration 1st step -- inflate "newpage" */ vb->num_pfns =3D VIRTIO_BALLOON_PAGES_PER_PAGE; set_page_pfns(vb, vb->pfns, newpage); - tell_host(vb, vb->inflate_vq); + { + unsigned int used_len =3D tell_host(vb, vb->inflate_vq); + + if (virtio_has_feature(vb->vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE) && + used_len >=3D DIV_ROUND_UP(VIRTIO_BALLOON_PAGES_PER_PAGE, 8)) { + unsigned int j; + bool zeroed =3D true; + + for (j =3D 0; j < VIRTIO_BALLOON_PAGES_PER_PAGE; j++) { + if (!test_bit(j, vb->inflate_bitmap)) { + zeroed =3D false; + break; + } + } + if (zeroed) + __SetPageZeroed(newpage); + } + } =20 /* balloon's page migration 2nd step -- deflate "page" */ vb->num_pfns =3D VIRTIO_BALLOON_PAGES_PER_PAGE; @@ -963,6 +1028,12 @@ static int virtballoon_probe(struct virtio_device *vd= ev) if (err) goto out_free_vb; =20 + if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE) && + virtqueue_get_vring_size(vb->inflate_vq) < 2) { + err =3D -ENOSPC; + goto out_del_vqs; + } + if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) vb->vb_dev_info.adjust_managed_page_count =3D true; #ifdef CONFIG_BALLOON_MIGRATION @@ -1188,11 +1259,15 @@ static int virtballoon_validate(struct virtio_devic= e *vdev) =20 /* Device fills with poison_val, not zeros; disable zeroed hint */ if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON) && - !want_init_on_free()) + !want_init_on_free()) { __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE); + } =20 - if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE); + } __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } @@ -1205,6 +1280,7 @@ static unsigned int features[] =3D { VIRTIO_BALLOON_F_PAGE_POISON, VIRTIO_BALLOON_F_REPORTING, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE, }; =20 static struct virtio_driver virtio_balloon_driver =3D { diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virti= o_balloon.h index 13074631f300..cbaf18e0b17c 100644 --- a/include/uapi/linux/virtio_balloon.h +++ b/include/uapi/linux/virtio_balloon.h @@ -38,6 +38,7 @@ #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ #define VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED 6 /* Device initializes repo= rted pages */ +#define VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE 7 /* Device initializes pa= ges on inflate */ =20 /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 --=20 MST From nobody Sat Jun 13 03:27:12 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 65E423C9EF8 for ; Mon, 11 May 2026 09:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490281; cv=none; b=oKs4ulYelgIXUFo0kErjfgpTPkMFh5rZ3TxgbDv5+vuBlMN3sJCqHMx/SiNedIsWxSK3Xjz/OxUY9CK97H/Jbbk8UQ8RmlttXindlxHlO9j9hckypDpzgU55ehaxws00HBIM0zsT1+vw5s5Q0giLp+8xP9GZk4XkVdZF5/5GeqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490281; c=relaxed/simple; bh=mQqx6N7f4HKujpbDEae/MRGG23U+Ado82zzAxmBrUmI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d7RfvOIDEmyl5WZBl03xeRm57zI0dxqysQ1VNf3lnseMpBkkjh4tShEocLIRrUmYwN4d+v/xw85+iRSo1K6Le6UklvYoI89K/poOFwsoZcciyBPUXbSRJTdAgwd/3/YBHr7r5c6I4OMEZkFeZMI0XfUOu6Dkr2LiceOMmXs9QfA= 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=C/7HrUoE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=orB/4NMg; arc=none smtp.client-ip=170.10.129.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="C/7HrUoE"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="orB/4NMg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490279; 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=MpBn8Jg+yemSfT/rKcYB8AJ8VmedmgkSc9fIviOsi3s=; b=C/7HrUoEsUsvXsEA8CTUaZHfPDqZP6G+6nBQaocJgdIGsvJSYvTxl8G9lme+5Np82t8pbi 7WVq5lQNVYWvFWYfEJSoG5t7rbiZdO0Wwv8w40gQBGkmfW7ppxs87E6g66UxxyAWtHqAQi TFuDAGZ8hTL5iHh6IoSe9seqaGJzCZM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-c6stDNT7PDmJI1yWf2feZQ-1; Mon, 11 May 2026 05:04:37 -0400 X-MC-Unique: c6stDNT7PDmJI1yWf2feZQ-1 X-Mimecast-MFC-AGG-ID: c6stDNT7PDmJI1yWf2feZQ_1778490276 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48e79219704so7736495e9.1 for ; Mon, 11 May 2026 02:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490276; x=1779095076; 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=MpBn8Jg+yemSfT/rKcYB8AJ8VmedmgkSc9fIviOsi3s=; b=orB/4NMgkSAGtM8JxvYl7tme0V9Lrv0OY5nPuBV3mjVj0WqpdI9xrk9198/pyPU3Li haCNUgs/VmYqjn7BhzL/Kts8c3QYl/lqQQqvjCvronlw8hkqdTrYp6cWEhkwMiLeMyOe cW3FHWwfDZ3Q7+UTUx5bN2Ri++Be0RnTiLOkJdeVr0U9wqBInjrasROphomGQOnzH5if VD62ddnrhL/nE/ObuZyBu/8ZGweUULQr5tFfsd5keyeuVWWT1sSKvvjpKwQGLyBjJQRM I82PN2rp6mnTrxUhDMSAwXpqUF7gJORpXj/GMcTRylSMY490Z1T5PVq43OHp1oVaBy5N PxzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490276; x=1779095076; 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=MpBn8Jg+yemSfT/rKcYB8AJ8VmedmgkSc9fIviOsi3s=; b=hdtdUUlZGoGl5qphBqzYnbuEjxwpUDImllnBQtkXto1MaUUNzp5OescUlFa3BnO9XQ +8viC0pB7I/ngeJCB9XzqDzKvpAiyaFoq6T4Vvskq9xpotK4C3z4gqVyh2emtqEmwKTh jTUnwnHj4xgrLa9/QL4UsTpHqPcWLeupj+IL3q4LqCHDNjhm85HtdhexscnNCDP/1x0m ru0v7Iufmc7uoORo6xjkJw3PoLbnlgzPI1qqgVyvQSy/6JHMTYMhio44pJ65XpkP10Kk eGCDuFvt7T0zJ6VrQLBI38BizOVXBONarjZOsKGnHZGq4CtnR169whwD7G4kpluEUQKV a2qg== X-Gm-Message-State: AOJu0YydaBJwq64pyWx9K7FztHC7KzIBqzlFz3S/IRM76kyp3RjlV3sI oBjBAzhDA9r5Pha9pwIJUPYwk5/4X/B7ZyKCT40zt42HVWVIsPDdhCeG+cyQyGBITrt5VRPx6WL yygfjuoanfQzCVOBceIBGnbaF7KU3Z6TWyMxmlrCxf3epVUQmVncBai+09xtdGPuPmFUYR9x30m Iw4yFBJUkNPzQVgJqs+wwRj1s65ZjmjFvArbzhQnOSTSc= X-Gm-Gg: Acq92OGzDwYnlIRHmy+Zk6ClAjqqRe7fAe+LwDadJijXF/QcKjluZ2vkAm6bPXMJwAw 2XkUtIuroPt/VwFwt+7sj5Noo5Vk3sEu8kcyZwDVkh5ypUe+Ey5xb/RzSqdGbfwNpDoI1/Kwa1w MubBDm1tkoInDfRZKgV49ysrPclZFi81idAs7p+TiAS6FypfB1srKGtO1WEcHVx2gfgtbTxiEBy smc/RE9N07r5Xlc544IHMxJOZ0P6BDeMdNepzEMqFKJXmMW55yJu1RwIITPCEMiUe/BnfZWFqCP 5hzYjimKwsRRH9Hrh7dFfsoBzVUb3kVGj8qxKMGSpQSsrwjBjpjyRKGZH0TA4QNOFjFDoJv1GuM dS19003SUhZ7g6Wpi4zRCyKqgqU8xAsfNhbb+yX6t X-Received: by 2002:a05:600c:3b0f:b0:487:1fb4:7e1 with SMTP id 5b1f17b1804b1-48e51f4cdd8mr372761035e9.22.1778490275793; Mon, 11 May 2026 02:04:35 -0700 (PDT) X-Received: by 2002:a05:600c:3b0f:b0:487:1fb4:7e1 with SMTP id 5b1f17b1804b1-48e51f4cdd8mr372759815e9.22.1778490275037; Mon, 11 May 2026 02:04:35 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e80ca2666sm91683315e9.10.2026.05.11.02.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:34 -0700 (PDT) Date: Mon, 11 May 2026 05:04:30 -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 resend v6 30/30] mm: balloon: use put_page_zeroed for zeroed balloon pages Message-ID: <446baed638f945982fc205a5354611bd24b2672f.1778489843.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a balloon page marked PageZeroed is freed during migration, use put_page_zeroed() to propagate the zeroed hint to the buddy allocator. Previously the hint was silently lost via plain put_page(). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/balloon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/balloon.c b/mm/balloon.c index 96a8f1e20bc6..1bf7eb2642a9 100644 --- a/mm/balloon.c +++ b/mm/balloon.c @@ -324,7 +324,12 @@ static int balloon_page_migrate(struct page *newpage, = struct page *page, balloon_page_finalize(page); spin_unlock_irqrestore(&balloon_pages_lock, flags); =20 - put_page(page); + if (PageZeroed(page)) { + __ClearPageZeroed(page); + put_page_zeroed(page); + } else { + put_page(page); + } =20 return 0; } --=20 MST