Message ID | 168244294889.1741095.16231421250476473539.stgit@firesoul (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 A00D3C77B61 for <linux-mm@archiver.kernel.org>; Tue, 25 Apr 2023 17:15:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4865B6B0096; Tue, 25 Apr 2023 13:15:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4368B6B0098; Tue, 25 Apr 2023 13:15:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FE9E6B0099; Tue, 25 Apr 2023 13:15:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 21D406B0096 for <linux-mm@kvack.org>; Tue, 25 Apr 2023 13:15:57 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B2D9F402EB for <linux-mm@kvack.org>; Tue, 25 Apr 2023 17:15:56 +0000 (UTC) X-FDA: 80720565912.16.FCAD641 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id BFE97A000F for <linux-mm@kvack.org>; Tue, 25 Apr 2023 17:15:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ug72baL6; spf=pass (imf15.hostedemail.com: domain of brouer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=brouer@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=1682442954; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wynb7GdU79YYV9ENu+xz5worQ7/3FbOaM+jXoCkc6Vg=; b=thudqcRM9rLv5msQO3C3MkgbjZRxYWWuxI1TB/VeEhqsDiRvA49OMZFj98uYnB+mInULy9 SB/EN+//wpcHBGYvNfdnhpTar7/RRNiQlrVt6AAMDnvCZMhjscQIuYjYAWpqDhxoUPmCDg 4cXxGVIEk+OWrWaXfa2anI+zk0bgs9s= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ug72baL6; spf=pass (imf15.hostedemail.com: domain of brouer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=brouer@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682442954; a=rsa-sha256; cv=none; b=Jsn7p+wj217xlIxDpAv8d+P0MIKlDRyw0uVe5A9evw0avXCu/PKz4tMTbf/H+SUr/qip/C C9Y1RwvylhNf1u66NJbELSMoTU5d5IHpVDGjeBcoxdH2D705JQ5JJyrJjI8Z7t2A6/dgRp xywz8IhXL/EzOjR+dMxulYRclhfh7Ko= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682442954; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wynb7GdU79YYV9ENu+xz5worQ7/3FbOaM+jXoCkc6Vg=; b=Ug72baL6x5sZpAdOz/W5wB74qLCEkrlJbAOTMlL1442qVwBdS4N2KBczy4mbnpvwN+2lrQ vxwU5AO4ciiyLzZxnti7EVEGCYJGX2Vc4AMKQKY5mGvaSPFWxUOrsW3sdfGj4oLRa/1uQ4 bVF8gA4FAPrrImj/f7yKe7HhSylqC74= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-493-wrDmbxbYOgmM7gRaWquA5g-1; Tue, 25 Apr 2023 13:15:50 -0400 X-MC-Unique: wrDmbxbYOgmM7gRaWquA5g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE36E101A552; Tue, 25 Apr 2023 17:15:49 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 806322166B3A; Tue, 25 Apr 2023 17:15:49 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id E6032307372E8; Tue, 25 Apr 2023 19:15:48 +0200 (CEST) Subject: [PATCH RFC net-next/mm V1 3/3] mm/page_pool: catch page_pool memory leaks From: Jesper Dangaard Brouer <brouer@redhat.com> To: Ilias Apalodimas <ilias.apalodimas@linaro.org>, netdev@vger.kernel.org, Eric Dumazet <eric.dumazet@gmail.com>, linux-mm@kvack.org, Mel Gorman <mgorman@techsingularity.net> Cc: Jesper Dangaard Brouer <brouer@redhat.com>, lorenzo@kernel.org, =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= <toke@redhat.com>, linyunsheng@huawei.com, bpf@vger.kernel.org, "David S. Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Andrew Morton <akpm@linux-foundation.org>, willy@infradead.org Date: Tue, 25 Apr 2023 19:15:48 +0200 Message-ID: <168244294889.1741095.16231421250476473539.stgit@firesoul> In-Reply-To: <168244288038.1741095.1092368365531131826.stgit@firesoul> References: <168244288038.1741095.1092368365531131826.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Stat-Signature: e47gdyjnrog6ybeatbmmskbcz1t899r5 X-Rspam-User: X-Rspamd-Queue-Id: BFE97A000F X-Rspamd-Server: rspam06 X-HE-Tag: 1682442954-284774 X-HE-Meta: U2FsdGVkX1+62TlKNuXN2tq5iZ3969PUwd9MuRVRac+iDTo6TfG1sArIz9t9E5nPFcuS+Vq4slurn6sgZ9bEuIFF5aXTAN9r6TrAjvd7gnv5O9nL6g4xh7iwku4A4I1LMfVS4Y4SBeNE7jbSDh5yr4TEQo3c6+pPkJ2b8HZBf8nptYZtNPK7xz4w4PRfZpEeBl1VKH1X1azFXTIWoyDBoHV0IRa2y7JtccHONwFGzTtK+IqPUCjtUPLNWDB5/d1Zfp3IDYc8so8heEZ3WGzQ8ea0kMbF0L3V3/zcQ+M296hjejt6dwoVCImHs7vIqdfAuLgxpKOttUqLZclIk9kIJiDyDNSqx0eqSVyf7wa9JJq9lIhhevHqqLkIPmbADFvMlgH6nIbzogz2NaC/UTJtd6QoMhpG6A3Juhza2mcYPWlrEYs8rEgo/mUntOKT+W3xmwmGbIjJJxf5ttvy4qcR6psP5EANF7JH00h7aexFkVne7cGt/A1vdQMmzpNj6RjTsili/CJqJn3UlqGATwdv0WLumxko/uzElBY3eswv8DVFyQWjA/e9Z5CPDEmJGekasP4nUBTuDFKteVMD2tHlDH4RjxIfZ+fIUXCHln+k0P6pEfQC2sAn0q+SQAtfkA0KBMjWu9IsG6aMWc/3pa4mMUFAXK7YtiiImNl8e0SSEjCYMHJLPRO3OpgT+M7X1xy/k8EpRsREJJA88kGYu4fGX+OFvv2VoDwFS4zPb70AgeOWrSme2AYi7DreLbOxF4rYMZ4mtPpEvK9ovS8ek8SZ3JcSu/gY+8dk0O30klwg9yxuqk5Ioo+LWbuBh8l0HGsQRe75IeBKWQUjHviYBXCJsES5pjgJkiV1TgvrQbyX2KO4ZgP4dBDf1tVuHQxfR4AMUn8wN40X6HiwQW44QWPKc0hDAvOzjG3EumLxvok58xwOVHzD9lzVk/zfsvHg8ctTnI+rIG0fb+oIg7mJ4oR aZPUwysY LY5lcXOYwkeFDGRTQHCLmqhzGvEVC5x9RFKissbo6L7EsagC1pYdRzJTm0cW/sDGgJ8iaHAvkMf06sAR9lTix8HzpMlylOEdqUaYUu3lT82hL9tNdAvbCGFqzt0uDdozv/NPPHQflZCQWfY5RSsKaSihU7KE3dcD7+vHescmDZA4rR6H++eLEcKtELkzRx+qSFh3OD1BVyGDt5qVoyNImX54kNmXkwiY0Igdft9HtBg8/L1ytsvE5VV++t/BqtKdRGYNVxmicoh43OSgOUk23dPt7m1TofBCr8I16MegMm8O6NMt8avVHB4BHSTnt0NcmUZDL 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: <linux-mm.kvack.org> |
Series |
page_pool: new approach for leak detection and shutdown phase
|
expand
|
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8e39705c7bdc..137b72f8ab8b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1247,6 +1247,9 @@ static inline bool page_expected_state(struct page *page, page_ref_count(page) | #ifdef CONFIG_MEMCG page->memcg_data | +#endif +#ifdef CONFIG_PAGE_POOL + ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) | #endif (page->flags & check_flags))) return false; @@ -1273,6 +1276,10 @@ static const char *page_bad_reason(struct page *page, unsigned long flags) #ifdef CONFIG_MEMCG if (unlikely(page->memcg_data)) bad_reason = "page still charged to cgroup"; +#endif +#ifdef CONFIG_PAGE_POOL + if (unlikely((page->pp_magic & ~0x3UL) == PP_SIGNATURE)) + bad_reason = "page_pool leak"; #endif return bad_reason; }
Pages belonging to a page_pool (PP) instance must be freed through the PP APIs in-order to correctly release any DMA mappings and release refcnt on the DMA device when freeing PP instance. When PP release a page (page_pool_release_page) the page->pp_magic value is cleared. This patch detect a leaked PP page in free_page_is_bad() via unexpected state of page->pp_magic value being PP_SIGNATURE. We choose to report and treat it as a bad page. It would be possible to release the page via returning it to the PP instance as the page->pp pointer is likely still valid. Notice this code is only activated when either compiled with CONFIG_DEBUG_VM or boot cmdline debug_pagealloc=on, and CONFIG_PAGE_POOL. Reduced example output of leak with PP_SIGNATURE = dead000000000040: BUG: Bad page state in process swapper/0 pfn:110bbf page:000000005bc8cfb8 refcount:0 mapcount:0 mapping:0000000000000000 index:0x110bbf000 pfn:0x110bbf flags: 0x2fffff80000000(node=0|zone=2|lastcpupid=0x1fffff) raw: 002fffff80000000 dead000000000040 ffff888117255000 0000000000000000 raw: 0000000110bbf000 000000000000003e 00000000ffffffff 0000000000000000 page dumped because: page_pool leak [...] Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> --- mm/page_alloc.c | 7 +++++++ 1 file changed, 7 insertions(+)