From patchwork Wed May 24 15:33:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76736C77B73 for ; Wed, 24 May 2023 15:33:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A479900012; Wed, 24 May 2023 11:33:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15626900007; Wed, 24 May 2023 11:33:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01D31900012; Wed, 24 May 2023 11:33:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E64CC900007 for ; Wed, 24 May 2023 11:33:45 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BCDC31A0A2D for ; Wed, 24 May 2023 15:33:45 +0000 (UTC) X-FDA: 80825543610.24.9A7122B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id A7116C0023 for ; Wed, 24 May 2023 15:33:43 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=goBkd0Oo; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684942423; a=rsa-sha256; cv=none; b=G2I8gi8Ujst7+vJvv8YZCOAasCbSx03bgqXyt+ugLRnEcP9Rtx4n+bj3p7dZQ1sr/letYt m1vMCOHP/Dw5S+QKF0kTgb2f3ovz/cql7PRpjvAXLbrkV6GeEwnG25h23XQ418mZsrCTuY 0vDqnHe2OvnFW+f3yE5vubp0vIEl/tY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=goBkd0Oo; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684942423; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uekJL1E5Uz+9JLqowhoPzZVYALfVqMM/z7Y13jfCLzU=; b=UTi69orBQnJhbKbmg6i231yUQPY/rocqlXrQNsKoiDU12LlVB1dbHg9zsYzq3LDdGMYZS/ CBP22J9lgHNhwvtu/JbM87FclOotJ9OTv23tofumz7WRdg5v/B0C/TI4x9CCUEJKixCmI9 Cv4hvsEdh4jzQ8EaIYwGx9EcEvUadPI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684942422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uekJL1E5Uz+9JLqowhoPzZVYALfVqMM/z7Y13jfCLzU=; b=goBkd0OowYWyH3QUPeS3qWxBlGoHkHgSDnWtPPThmZjoQLf+Dx8VCmbgEpcr17+WibYYzg tnhem5GYfUXEOCXSMvqq7tI9kqo9RdMGEnkwxJAFzOP9WG9rWgquHsBKCDZtCLNII3j6F3 vcWQqo+xo3DMCX3bzqxinsHrBh9dC4U= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-168-UtOOYHJNMQqeOwkvKYu_rw-1; Wed, 24 May 2023 11:33:38 -0400 X-MC-Unique: UtOOYHJNMQqeOwkvKYu_rw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F027280BCA2; Wed, 24 May 2023 15:33:36 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A068492B0A; Wed, 24 May 2023 15:33:32 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jeroen de Borst , Catherine Sullivan , Shailend Chand , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-nvme@lists.infradead.org Subject: [PATCH net-next 05/12] mm: Make the page_frag_cache allocator handle __GFP_ZERO itself Date: Wed, 24 May 2023 16:33:04 +0100 Message-Id: <20230524153311.3625329-6-dhowells@redhat.com> In-Reply-To: <20230524153311.3625329-1-dhowells@redhat.com> References: <20230524153311.3625329-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A7116C0023 X-Stat-Signature: ymwdbaoqape9fjqgszkyi6i9mtwri41y X-Rspam-User: X-HE-Tag: 1684942423-294632 X-HE-Meta: U2FsdGVkX18CaKKB56Rh4SFXKI6TkbycwHvQShABpT0Xu5E32eQjpkMQK6AXq8d805D60Pj4b8JzItCfj2sfsztwPBT/uza9p/tG4gV/5fNS9/lIpoMRAAsYooYh5ou0sZsCnD4aDrm6aS0kBmLnkmCWKg0dQ+0ayJthppyMZfYrzQzZZoPm8vxIgSN92H0G7I7xYvuzJYOoGEdjsA12nwQwWABz38RiS+mdWesowACbyD3Q3BrTcb5QxXTVJotBCi8U/tUqIAkg355ij7mR8uWrFz89N6bOeAljEjMX9YBKbWTxbMoccLfunls07QHjMh6W98+/sfc5YAa0gxx5nf3d2em4KizADJdpcLqeT+tvOUNqqkOnDcnjdxU+ycoBk+iAoQOzoEflK7ngGBdvQS2jYFzEo5EI8vS/QnGXezdKO0KftrHSpj/9u931pigbXuPcmoXPTagQYBeqBCeaPWIKOUjYshgzGmJ8rgVZYpAQke3vBPepLguYaMw1qzA6RxBh1+Bi8Y6bZjXLltZWfxUmwDYXIL/VCMdoq2YyY72zfH5EVz1wnR2QIXaoyQhXFTXx/UEMt6T40arnn5lTLVC1jRcEqctVBADCdQAedsmxrHvxsZF/Na5E4jh47KGiYpNxidbbprMglhl2TZu3L6QI5B7QdUzV9Ufem+TcorZwiZa/aEL5UY9m/5OdCQNrqDT5WQ2q94CP5g0t876w8nIf3beofQhi57ZqNTInwfLBXCXrFh0SXer4f74ShTs9CgAcFY7CWPa17YR+0lcLf6gSG0ZF8OWm+gV/3zJORyRcxmCyWZuX2DawHHqaN+reJp+BmPDIONoo9POdsQuDRl512TbeAnJXDhBsZHnasCtCgNaFXLbV6ID2usRQFu9j6rBzQ6j9qurMplcxM8vGslXDHJub3gwet40ASyImj047cdiDCYJlN/gC2lOxoE5uhM6Tx83T4iuZpFa1rSv NJDJQe3K 3gRWQkpNgDTLIViUeRLndfld23Ybcp8btbctF43mncjrNprk5a1OUqt4g22tjQjMEj8kIszWpl0sSx5WgVPZsqbGCYQafG8Mqt9bXjE5WqV4muDmWfRhhAwN2GgkTKEDFaTptFBtjOAgfeXnbG89i3fCJakfVHNJAeQ/PMbjAey6wudO+Lkhdl2HftkH+JZ4QynrVdpTbUyt9d3J117WM+xaEQB75BNWFtql45hm5Tq6N+1A+Ge58ltl93HxWYuEgJ6n17qW7JNuQ3SgxUoQfyhx66ijhWw+2vfpkqWSaxa26Ckx9Ka2kBl5LJiYGk1QSkTjgaWMLIxGjUTXMRSHbhypxV+uA6mrqp4YCZZ06GxCJhMd909VqZXUiYVpghf9+xTMwqAV/wRtVwFPgxATDSJvh3bCe+JJGJgRV7nv8Vu1zW539EdFayHKiYkMzFyL769iTQzwrIGdD8KsE/NMLiyBt60uhEMnmORMZmD6KJ8UC204dRd7zLU6jV8k2mF3ik9iWf2qKRlzX9++IVg6ARj0mJh52DboDsIVOOQhraHL6MuJ512OfRmnSatYn6okL4HkRp4Kb9e9KC4wUNpZ1goVqulLoiB1jWCjidUOtToOfj1ML0e17sHa78jPTI2HqrkUy594ahgXRv72usAvdihdudnyrTOrWnzn/wmAtZpInVq4QnmD31Q7omT8tk3ynhNm2tlVuTEwZh7NP7dBZSf5QDLCF/idhPHmoIsmkaEDd+w6R2Acx1CMUQVwwejs2gBdMnvvQR6/LD1MXoErPX5w5GXtVXjZRARKaRtYKnvP0dzo7h+J97xju/kQ/JnEbMs2bqApk0R/lqkmbG2zyyqxjWBLgsvj1uxZ6ymagB+asp5NGCMchWNUmwgAqltcs962yNh+pUHXjGzc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make the page_frag_cache allocator handle __GFP_ZERO itself rather than passing it off to the page allocator. There may be a mix of callers, some specifying __GFP_ZERO and some not - and even if all specify __GFP_ZERO, we might refurbish the page, in which case the returned memory doesn't get cleared. This is a potential bug in the nvme over TCP driver. Signed-off-by: David Howells cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Jeroen de Borst cc: Catherine Sullivan cc: Shailend Chand cc: Felix Fietkau cc: John Crispin cc: Sean Wang cc: Mark Lee cc: Lorenzo Bianconi cc: Matthias Brugger cc: AngeloGioacchino Del Regno cc: Keith Busch cc: Jens Axboe cc: Christoph Hellwig cc: Sagi Grimberg cc: Chaitanya Kulkarni cc: Andrew Morton cc: Matthew Wilcox cc: netdev@vger.kernel.org cc: linux-arm-kernel@lists.infradead.org cc: linux-mediatek@lists.infradead.org cc: linux-nvme@lists.infradead.org cc: linux-mm@kvack.org --- mm/page_frag_alloc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/page_frag_alloc.c b/mm/page_frag_alloc.c index ffd68bfb677d..2b73c7f5d9a9 100644 --- a/mm/page_frag_alloc.c +++ b/mm/page_frag_alloc.c @@ -23,7 +23,10 @@ static struct folio *page_frag_cache_refill(struct page_frag_cache *nc, gfp_t gfp_mask) { struct folio *folio = NULL; - gfp_t gfp = gfp_mask; + gfp_t gfp; + + gfp_mask &= ~__GFP_ZERO; + gfp = gfp_mask; #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) gfp_mask |= __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; @@ -71,6 +74,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, { struct folio *folio = nc->folio; size_t offset; + void *p; WARN_ON_ONCE(!is_power_of_2(align)); @@ -133,7 +137,10 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, offset &= ~(align - 1); nc->offset = offset; - return folio_address(folio) + offset; + p = folio_address(folio) + offset; + if (gfp_mask & __GFP_ZERO) + return memset(p, 0, fragsz); + return p; } EXPORT_SYMBOL(page_frag_alloc_align);