From patchwork Wed Mar 6 18:24:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13584444 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 7DAEBC5475B for ; Wed, 6 Mar 2024 18:26:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B005D6B00C4; Wed, 6 Mar 2024 13:26:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB21F6B00C5; Wed, 6 Mar 2024 13:26:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83EF66B00C6; Wed, 6 Mar 2024 13:26:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 71B066B00C4 for ; Wed, 6 Mar 2024 13:26:00 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4B773A0499 for ; Wed, 6 Mar 2024 18:26:00 +0000 (UTC) X-FDA: 81867443280.29.BB0F478 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf30.hostedemail.com (Postfix) with ESMTP id A6EEA80010 for ; Wed, 6 Mar 2024 18:25:58 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JjO907E9; spf=pass (imf30.hostedemail.com: domain of 3NbXoZQYKCHgoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3NbXoZQYKCHgoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709749558; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/rQHM1U0nLVwxoqb6VDJGJRpri0atHFBD/ukIXSlku4=; b=Hdeb2RW4p013s/weigOTvM/VYLy4KNoC9RdgdevcotWFZS2aQKAkNkVhZ55Ji0adEnpKg/ pMsykMUoem5DEngQ78J6gna86PwJj25fBIgew262TBOKOqQLwrjTunIA8B6RaAAI2NrzZv etYOhR52S5neukeA4hXydh4J8clubd8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709749558; a=rsa-sha256; cv=none; b=wg6Y2lF4dfl143ahYbNoncL6uB/DQYx3jRT+J+qvbLyn3VAT9ks101XqMv9O+MtX919EOG 7IXhIF91ajTjxqNzKFJF8lP0mRgTHr7jEvXG/KLYqB7eZO3GWU95LXRAxg1REttqFW09XO 8odx6BFd64HwMV7yWshU9u6WhfQT2rk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JjO907E9; spf=pass (imf30.hostedemail.com: domain of 3NbXoZQYKCHgoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3NbXoZQYKCHgoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609a8fc232bso692297b3.0 for ; Wed, 06 Mar 2024 10:25:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709749558; x=1710354358; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/rQHM1U0nLVwxoqb6VDJGJRpri0atHFBD/ukIXSlku4=; b=JjO907E9gCKQqk0dFWT6AzKXPHrtCYmYLJCjwznx0G5k5jgLySEVYfnMXyLQXDxW8+ 1lX/eHerccPDNU192DUKcqMVLMkxL8lVriVDJmUDv7SsWvfs7svQd7z4Jh8/WeZ7jcLh MtGxC07WVmYCJm+wDJJLa9CkvfJHdjc6I2OPt5bx9nqCV2A9c5VXdZ9eQYQzfyF0pbIp XZu78BR2pNXNZOTcCna6tA/sdQD3Pr4YlE8x/LcwjYRIldrGNoo++FueVaO6koUVTqJa O7XZWCP20FXRD4Y2uSeA5G+27D9ys9dH6XZ9M5XZoFcAQNYJbDyvfsCJs39qJ5HbsDlH rsqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709749558; x=1710354358; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/rQHM1U0nLVwxoqb6VDJGJRpri0atHFBD/ukIXSlku4=; b=Z58imHpSERhjI3uQ925F4lbu0WVfZsw5lA53Ai1z9OI4A93ioKvxniCJZfKlL5sxw7 sCToVe+xfWVN+6gHF6MFhSHoKcS7r1iueDWbSKOB+LQRCMW9jfr8rNInLQBWigtSMXXj ooa/36Jd9BpRVXKIa2cwekH+NFzuDLVq4shpl6lMhONS97ASlrtkU+TJSA68S/jetNEF zYNK9jAddPpUDRFNpHqOugCGm62aFESeDnsslVSoxPXhNgdrkOEjaye+wK1AUD0aX5zB G1WABgilH4gUUcA0w01pN6kuwDOnUgyU4vB7WEnWKrJLcxakVfJpKVcbw3/ObM4Dqv2I Fiiw== X-Forwarded-Encrypted: i=1; AJvYcCXLbBrVAnTMYT521oIlsJjFUX3c5wiNJkHzqy8pcBIOArkdPgpXCqocnx+UMDrg6KdykyqyFqrrVGBK9Iwwx+c2NiQ= X-Gm-Message-State: AOJu0YwFODlmOKEpgXghYKLTGvT+JjRmXIg5G3XYRprkVwT1mghgwz8m tYmyFizKPo4IXsftMCthzmaF/aY59HOVHPsE/UfuPzTH30W1Fzrx9vNTudOnyFGfuXGVk4F1La8 Iww== X-Google-Smtp-Source: AGHT+IGylq2hXmjkk0zshnCen8YUvCWPBEs19UcrOnAI3PcEdGgYWrVUEFQJWagWIw3puXNNod8UwtNgR7M= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:85f0:e3db:db05:85e2]) (user=surenb job=sendgmr) by 2002:a81:9b97:0:b0:609:3c53:d489 with SMTP id s145-20020a819b97000000b006093c53d489mr3279719ywg.3.1709749557600; Wed, 06 Mar 2024 10:25:57 -0800 (PST) Date: Wed, 6 Mar 2024 10:24:32 -0800 In-Reply-To: <20240306182440.2003814-1-surenb@google.com> Mime-Version: 1.0 References: <20240306182440.2003814-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240306182440.2003814-35-surenb@google.com> Subject: [PATCH v5 34/37] codetag: debug: mark codetags for reserved pages as empty From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, jhubbard@nvidia.com, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org X-Rspamd-Queue-Id: A6EEA80010 X-Rspam-User: X-Stat-Signature: mdjpctgbiquwn8xz53qnkrnznunxw19r X-Rspamd-Server: rspam03 X-HE-Tag: 1709749558-989022 X-HE-Meta: U2FsdGVkX181HrQqKeC52Vzdud2Fl6KEcl2w8+nlyuRmOHUyDvKNxUXOR6c+WCdhJkGpqL2rtNUamOldOKTC1ZSC5q+JgR7KdSBJRgAA4vWyWpmyhm6kNZfF7Jgq35B9vIStDbtk7nVX7RShuqCQxrR7lq7VUWmGawJhVEPs/kRysqSQrIhinhLKLkAu5+CTNWD1ShUDaBIhJgNv/vIxeOh6mQtthfhmb5Nh0nnVYScaIFacrkJqaXUvdRaq6VbDDy+tbe/upzfw0uCh8eJqo7nUZ0+g372HlgsckmSl3FbdIKMez1m+sCEilIW8JzXn2c3dn2d+sNUT157UWseDB+APuUojzzPsbQoyU45cAwrq2CXfBG2T7dK8vJOqNxYnwZK2QX6my0FmlMO7oxtn6OC+O8UkDa/HaajmeLip+Pe2YBPb+AIW2t3nQC86C5lM4xqG+4mVoaoUPqtcvAnPW58D1XnRNFCFsIF0eqE4G2c8k+BGFPm55uVnV20dNk4Fke7+lIFtcX9SviX0fzzCQai+V5Aw6Xw1qrIMLh/CpYAGP94k5pvwujf64/2J4Mlc6iQDKc+Q7cEgkHtziavA7g5aJWjNLr2GWjBaPtHRhm1mBooxKLZUlBuw8jgIs0fkH1hHaV0AX48fbEfb6sOjcMwPlgQhgSIA9Z0/UPIdoMor5Y0qU1spE6Jnb7GntIX1B5QZVs4RdY5P1KyqQW07kkqEK3/LACKtEGaidYdpPMiGQBXlDvzRqFXpyTdPLskpcI31IsP3eEl+QKfy4HBQzZE6azlf/bv21bO9GJcEhKVC6HQK47l8mGhdnB5HgLe5GQd2dB7F3+ybroeMv0A6MR1w0ubTVBEV90/97lvXv0wfCiofyGl/6GIFaVXBCV+Q1I4Iyft+glO87srUJ0DOLom7V90ewgd/GF6t5zdgP1hH+HhlzBn0oPS7amVlnKZ3Al6zl1NDSDj/GEyZy3w wmBOmVGw kfIILsHYtGMfGV6NZPs5V9CPrMMDS+jbriTmOxE3UX9XhuRkH4dTAjkCjMVlWJpm/eNroiVLJ8diT+EZmWMJPSQDEWiIe75LdlrWtr+P5nI5GUmqz3lZ4/qz72ownsyTQ1aqzCGpTB2MuCmXO+4tmzIaSgqN1ieIQRCy+ptW+phycb+F34hIcJrioiQOWgQFxgLpP0nsouvHvC7cWJdX1O+d4C5RuJGo/RBYR6ODozNIPR+ARH8yyLTWeoT7TpHc9I2isjGo/iVf6y+yM46Ax7Nn/SIoTamDHhJmGama9oDZ76k5yFnqhy5ZDvG8AnfT35bVz6zkRahcuW9lwkHFOxgM0bMxF8z9BRwuLUOjz9rv48DuOOkmz+czZ+hyCG9wYrqltgU1sq4NIHXZnQHUMoRakMC99igsYPw1smaXN4dNPWuo= 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: List-Subscribe: List-Unsubscribe: To avoid debug warnings while freeing reserved pages which were not allocated with usual allocators, mark their codetags as empty before freeing. Signed-off-by: Suren Baghdasaryan Reviewed-by: Kees Cook --- include/linux/alloc_tag.h | 1 + include/linux/mm.h | 9 +++++++++ include/linux/pgalloc_tag.h | 2 ++ mm/mm_init.c | 12 +++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index c30e6c944353..100ddf66eb8e 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -46,6 +46,7 @@ static inline void set_codetag_empty(union codetag_ref *ref) #else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline bool is_codetag_empty(union codetag_ref *ref) { return false; } +static inline void set_codetag_empty(union codetag_ref *ref) {} #endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 699e850d143c..9d25d449e512 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -3118,6 +3119,14 @@ extern void reserve_bootmem_region(phys_addr_t start, /* Free the reserved page into the buddy system, so it gets managed. */ static inline void free_reserved_page(struct page *page) { + if (mem_alloc_profiling_enabled()) { + union codetag_ref *ref = get_page_tag_ref(page); + + if (ref) { + set_codetag_empty(ref); + put_page_tag_ref(ref); + } + } ClearPageReserved(page); init_page_count(page); __free_page(page); diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h index 59de43172cc2..01f256234e60 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -120,6 +120,8 @@ static inline void pgalloc_tag_sub_bytes(struct alloc_tag *tag, unsigned int ord #else /* CONFIG_MEM_ALLOC_PROFILING */ +static inline union codetag_ref *get_page_tag_ref(struct page *page) { return NULL; } +static inline void put_page_tag_ref(union codetag_ref *ref) {} static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, unsigned int order) {} static inline void pgalloc_tag_sub(struct page *page, unsigned int order) {} diff --git a/mm/mm_init.c b/mm/mm_init.c index 2fd9bf044a79..f45c2b32ba82 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2567,7 +2567,6 @@ void __init set_dma_reserve(unsigned long new_dma_reserve) void __init memblock_free_pages(struct page *page, unsigned long pfn, unsigned int order) { - if (IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT)) { int nid = early_pfn_to_nid(pfn); @@ -2579,6 +2578,17 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn, /* KMSAN will take care of these pages. */ return; } + + /* pages were reserved and not allocated */ + if (mem_alloc_profiling_enabled()) { + union codetag_ref *ref = get_page_tag_ref(page); + + if (ref) { + set_codetag_empty(ref); + put_page_tag_ref(ref); + } + } + __free_pages_core(page, order); }