From patchwork Thu Mar 21 16:36:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13599191 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 3A31BC54E58 for ; Thu, 21 Mar 2024 16:38:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC5286B00C4; Thu, 21 Mar 2024 12:38:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDBAA6B00C5; Thu, 21 Mar 2024 12:38:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A04E66B00C6; Thu, 21 Mar 2024 12:38:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 89FD06B00C4 for ; Thu, 21 Mar 2024 12:38:26 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6161F120485 for ; Thu, 21 Mar 2024 16:38:26 +0000 (UTC) X-FDA: 81921604212.09.7DA8199 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf16.hostedemail.com (Postfix) with ESMTP id 88B7018000F for ; Thu, 21 Mar 2024 16:38:24 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=i6I0cwro; spf=pass (imf16.hostedemail.com: domain of 3f2L8ZQYKCGwcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3f2L8ZQYKCGwcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711039104; a=rsa-sha256; cv=none; b=1jbl9Uxi5eAx7BwCLruZA6ukHDgVG2mDOApydhXwidjBUuQk+beh9yrwEGopIv2llux4bv 4IXT7ZVnYLxgbzRbT7i8lvpTN3SP1c1cN1S/3tGXhyYmQrgna+gBnfMP39sZrDvc8iWiTw r5V5jpdkYimqzqSj8BL+vVbIWxUQlgM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=i6I0cwro; spf=pass (imf16.hostedemail.com: domain of 3f2L8ZQYKCGwcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3f2L8ZQYKCGwcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@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=1711039104; 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=fkzGAdcAIO9V5Ziif/kwje70ys4aQ86/VyfgELZXTD4=; b=8pE44KknU/dPQGPTtAG6A/9wZfkOJpFr6zeUCmoChMjg9C6t4LBWZZPGQINGBZFG9junqU qRWBiCUKrGZbhS3F59wp3XTLUfmfZe9m6TToJ4kMHYFOvvWmBVrzFMokbOSCcu7ytWSGv/ K43E9oqdHnYQptX7jHgooKsv6WEyZqY= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcdc3db67f0so2777690276.1 for ; Thu, 21 Mar 2024 09:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039104; x=1711643904; 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=fkzGAdcAIO9V5Ziif/kwje70ys4aQ86/VyfgELZXTD4=; b=i6I0cwrokHTRSWAl9Xfs4rL8zfUemla8j6nu8wfbWQ2afGyPfKkEvmwf6S9Wf/6p6o czhk6bcCMLJB1/WYChCW5999pKfl4YjEvNXfP1Qf7p4zgBHQC7oc1giAhaDyt2mVyjbU TUXqCbnFalWL3dLqRTUpuDcyZ+coEQ2EKxgnZV/JAD4agjJ8BjsdTt4gq8Ks+d38JbJV YsVr02IdPEeUMl6iNZhLZ0poNoDqItr6csVjFhKztAlCgJt7di2z55osB44sxIf4RLzj XfDsI5vtcUd5z42HyaIb6IeApny5257GFfaeVqv4MNU/cBACBIfDEuOs1O/zHbID1JGl CWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039104; x=1711643904; 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=fkzGAdcAIO9V5Ziif/kwje70ys4aQ86/VyfgELZXTD4=; b=r39Ekw2XQwiFt1LGf07VzuLVJVTuS/U3Z2hoP/zOD5V1gI4Ups5NzMmJNdDKNFAG3W VEo4sjsEsD2rPTvgSEfxJO4jv+pR4RxE8S0WXx+ZXLLEcU2t8X5U4AB6H2LcyDsJRqfl XjGyvhOCFzSnXfXdoFlxIl1LqNm0WJRjEiCnzG0+sXXk5j5jytit6dOQdYEEiuRIaEnw buEhdqprF4hvZFE8oSVP4zEp9cI8DCW2db1AvTNQlJuTgEQtxxUz3fXlbucnhYkC0nSR l3O1P8AAavDBcfGDEGw5Ni7tOG7+UCO2Hg6DWDpki8ZQ2d2YVpdj9mY55rdakGLY5pdf JIew== X-Forwarded-Encrypted: i=1; AJvYcCU76kFSckm0zduLW5n0Y1wmT34So12l2opJ8OowBb/HbS4afTY55PhLa1SnokDjsGoc7UDvy0HacuofhM9h1yKJlqg= X-Gm-Message-State: AOJu0YwyaBHc1nwewbhTD6ziXHYH/VOABqaZnCTRnpQVy+8JNlGIfd+H Vt6fOEs0lrgtwIpVHMif9c3iImlnGV6qtRejOo0LoCoOl5Kjxuhca7paTKw5cSa8BqEG32/E7d7 z3g== X-Google-Smtp-Source: AGHT+IGsZeht1WnRv54WdZCsHHkevoWEcBuLsOMdDTLOZ/BEZ/G/n2nCv8k8gfmNzlHHNHWmAN7X+BiTyog= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:a489:6433:be5d:e639]) (user=surenb job=sendgmr) by 2002:a25:dbd2:0:b0:dc6:b7c2:176e with SMTP id g201-20020a25dbd2000000b00dc6b7c2176emr610053ybf.4.1711039103623; Thu, 21 Mar 2024 09:38:23 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:56 -0700 In-Reply-To: <20240321163705.3067592-1-surenb@google.com> Mime-Version: 1.0 References: <20240321163705.3067592-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240321163705.3067592-35-surenb@google.com> Subject: [PATCH v6 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, 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-Server: rspam08 X-Rspamd-Queue-Id: 88B7018000F X-Stat-Signature: y9z7we5tsutfxumgt9b31u1ad9pyfugy X-Rspam-User: X-HE-Tag: 1711039104-619664 X-HE-Meta: U2FsdGVkX19EEev7rMNYTgYYpalw+ZOlqSbyIHV4UE4obmR1QwDb9nyCjlEHS4+YFAxOUxuuW2qBLamDvZJJDi5s1y/sMGqqv62+pycz6r1u71gTDuWNIxGMjVGJPiWP3xOaosLLJNqxzMqVsKYphxBZkm6koT17iDO+AtsjtD8WvbVj2hkzbJZlvK55H94JNWnm9N3XgsEmogX0JriNbm35Ae4MghulJELbMReEHodKXQS+W9eceTJf5Inarj0O6TWhdNsshpdWTgDi9Yko4S1MPVDQA1odrMH+y/6IIPcfb92vEzCv3n/9bvs+F8cUByNRhojgplE7l6p3P8oX5XIsAlOVzjInYeGDQ8+EEc8gYLAvP1xMF00212UDe5+/kPdSHNcGcCDqyk9yf21wXmxi2KgAvHE8koJ1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5fAi50dirceBgL+knxcyxFOxPml4JGhZ+PG49MPgxUkyjaktvnANam7bDrXtLeroy5Tf0gWob5kAyQlLroDtB4yZ36aBnIYyF/WRo9hiWEIRM0dq+VZWuQQTKisWsqgEHdSobg6TcrpB2z+/zIGJ2EV/9K/PLdyCcpKGHTMKivDHEchYhCxpBhcVTtDwbAQ97xXAqcdZ7EGK57DNqqXKkf8dndKtIXWqQvhH5 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 8147b1302413..2615aa69c823 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -3132,6 +3133,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 50d212330bbb..62d8dad74b37 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -120,6 +120,8 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) #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 nr) {} static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {} diff --git a/mm/mm_init.c b/mm/mm_init.c index 3e48afcd0faa..c7d6376a180c 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2510,7 +2510,6 @@ void *__init alloc_large_system_hash(const char *tablename, 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); @@ -2522,6 +2521,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); }