From patchwork Mon Feb 12 21:39:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13554071 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 C901FC4829D for ; Mon, 12 Feb 2024 21:41:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2484A6B00BA; Mon, 12 Feb 2024 16:40:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D00C6B00BB; Mon, 12 Feb 2024 16:40:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA1576B00BC; Mon, 12 Feb 2024 16:40:46 -0500 (EST) 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 D49676B00BA for ; Mon, 12 Feb 2024 16:40:46 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A85DB1C125A for ; Mon, 12 Feb 2024 21:40:46 +0000 (UTC) X-FDA: 81784471692.25.C8F0807 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 09E9BA000C for ; Mon, 12 Feb 2024 21:40:44 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=C1UZQ67g; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3XJDKZQYKCNsPROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3XJDKZQYKCNsPROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707774045; 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=DSEwnOfj2VuhpdkIHZ8VNVuKfvBXo1I5xAUr9MF0J1M=; b=xSltOd1mniaELI2yWbweesyp5U8u+4LuMcH1kLtxresgxa97C9YfevkSe9P0rUmiYZPip1 osS+ddotRne6e8CWURiTtt310neC+jKhLiW3871qia3c2tw9OiNsd8MwHE23ZQsSSPNAKW 1z0zTozExcXzJjdzjgkVcAtkxnQQJE8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=C1UZQ67g; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3XJDKZQYKCNsPROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3XJDKZQYKCNsPROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707774045; a=rsa-sha256; cv=none; b=DZG4WZUBtIgAJ7zeFeFFKLRA9JwuYx1fTs1VwF2SXldp7SzSp9lUXpBiteqyl6FEtaPwEv Qxz3Z6TFWRe3bJ6j/nzbu0i/shcgJFkeByQQQ9P0J688g/OVCPj1MxKnvaRWdUqgPqxK1D WnuMACIVHvIgpz8ZQ/x8mN/5qS0LNps= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60753c3fab9so16582267b3.0 for ; Mon, 12 Feb 2024 13:40:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707774044; x=1708378844; 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=DSEwnOfj2VuhpdkIHZ8VNVuKfvBXo1I5xAUr9MF0J1M=; b=C1UZQ67gSuC6snaJmQ0Tq4S6qRLyJLV8cAuZqBT//6L7F6AQU1e/j7nCt0OHhHPEj0 6OSLMqf+2oFi+feAIkPuMi9recQQIc78SsPxIHEXfAvt2TiVHaJ9Fpp4gDWH4ihbt7c+ e1p/fENOa5rowQGKm6Wbm0NozRXDGUErnyiOT0EiYX5aefPC9M65YUvVFTZREDyi/2dr fXJJTU21LbuAcP6q5A0C5vfy4Y//K31IEGRWAheXkxNkv81APUMUe8wbhdyj9CWQ4gpw SsTy5z8XYyGNmIQ//MWCgMqEdIBkv/6gysPAHeP272TRj/Hc5I+GiGGGjotRiiDAq662 /ciA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707774044; x=1708378844; 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=DSEwnOfj2VuhpdkIHZ8VNVuKfvBXo1I5xAUr9MF0J1M=; b=CRvoqZOAuNuOKIREGWuJ3Oj+rrP1Aw1s5xIUKA1vZuQ3M40h4hQOktXMm6ZlUpZn3E C2Cvnw4UXeaWw58u9+er0NSOTMC6CnlofMUoj5kiT1pEN91VwWEaoHEGyQ0swF2mqSFR Mjnu3nEjOYf4baa2AjwaBp2ak93eEfmpu+CT5IiSUdAm+kyn7vzyt/kLioe7t8gVygIO 1zvKvD7RLvQXrV9AjxCNMMMvGVst8htwdD/paLQF1eFnfpwDW+K/cqcuWbWCtcz56NGs lwp3fNcYOVnHzZ3l2Q/HvbzVcAJe+6RnO+XEI81HgfctBaC+zF0mTJow9VOHbVkMmfBG UThA== X-Forwarded-Encrypted: i=1; AJvYcCWrz0KWBv5S32bA8ZKZtFAOV10Pkq98eY8JJJteshtvFD6o8YVxMYc4tKe9A4GSy98fbmy9vB3NeAehzeYoB11s1bY= X-Gm-Message-State: AOJu0YwveO+qXRBuSc/m2ollFWhyo+ZnNwYgAe72CEHLfz/tP0u4aRx4 ZT3KZIvbmJwY99SnK1mU8xS6WAFvG5ahUM0HKIY7ZVt0055GrNrtFnv7rFqKoMP0aI7ah42AA95 r8Q== X-Google-Smtp-Source: AGHT+IFtNaKOZcDNkW8O/y0IS6dfwCCkuRAaS6+IZN21h1P/6QI7aHSb74NpkK/DZ6QgX1s1BGxeLh90Utw= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b848:2b3f:be49:9cbc]) (user=surenb job=sendgmr) by 2002:a0d:e8c2:0:b0:607:79be:9120 with SMTP id r185-20020a0de8c2000000b0060779be9120mr169543ywe.0.1707774044127; Mon, 12 Feb 2024 13:40:44 -0800 (PST) Date: Mon, 12 Feb 2024 13:39:19 -0800 In-Reply-To: <20240212213922.783301-1-surenb@google.com> Mime-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240212213922.783301-34-surenb@google.com> Subject: [PATCH v3 33/35] 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, 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, 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, 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: rspam09 X-Rspamd-Queue-Id: 09E9BA000C X-Stat-Signature: aonjuh4cmy49ppiizhk78j9umybnco8g X-Rspam-User: X-HE-Tag: 1707774044-835676 X-HE-Meta: U2FsdGVkX1/ow9YOQ0jhITfin/a+/z2cLgY5EROCTX1k9bO2tczum3avWK3dJ1yGQsbLS36l3SmtIUczw4X4ksXGaWrHIqP3yU2arztyFegSEgh6L/oR5opVbJ40EkS2yrMS9piil5JobRtLHslmANB+E/3ign9+B5HEuqq7MoNOoaBiDg2ztSvFIBmfgAFDYtFzo+C3MrwHnbItHmTPs/vYBcdtcapTwjrJDlym83kktF3a8oj11kbWtZJgXzhzO33bVwPU5yXKpbn5f6CSWXYhP0a4NCrQf1WwO9oPevxjy6+o4U26UBRhRw5mNGzaZUypUEmAkU964jX0PKh7Du/Ya1nrHXNWVUU9/nJiWuAguVrbK4ktzZrnVevzfAuIvOA0uoequ2W/ufYBbheDApm8n4+Ovd3qQvqQ8fm1xJtxhNZXWOdjCcd6GoNMdRo6SXa9PB4bq6GPgFcyDqFFdofX3s15R8hO9q/kjlWr0N77kNrhY2qOaYyfutDYwSrUsPBgfXEjJXW9egMLnLdOLnzxPqKB+JohP3hEas/FW9N4NOejxjJR/GW0f+eZ9TSk3yqxReZR+Ndt60ElojkETCjv6zcMWNYivM2WrH8fImdtggL7xLKB/333WuwN3ZcwG5NaskKVy/J6SVpo3GzfqaUE8TN3/nnrjIHzS6Xn1kWlAUIoumitDCjAj8oRw5UvUGPNctBe/RiEwsYsCq3KfdiTuGCBUF3NEYywDOXPv/ugVp5KKiFgj34sJt/jHinB/TDb0+3J7simsmL533m3rV1FVG7pGUg3+BUSEdrn7HFtrsbIIXIRsNZ+OWynpEvIyiL5xEnjnY3S4MlAnl0+ZsN4LNMkmjPlpmXnSTe0vIeL9ByckHgjz8m3bQ+qQOPfedxgab+PaqTpZYuSgGUs7J5wecdGOSSNz+gNTc7uQb1vGlp9QFibd3vsQSQ8fEDja/rC/MbYmaOUQAVFfkv I6Gb14Vw 3akkxwQ4t1872Zm39f++bJ6wrthDgDLU5e46eme3tGN52l5rppUz7f/dpsNUL/oE+jLtDzvVYiGl+Lk7hRI7UmWVQunn8zOA2auNYPDVbmzWvyPC6L5fz+Bp1BhdmimyExBrhWA3zJgP3yNF335DGizNaqUTYlQvb+1lpiE7l5dn7lK91KN2s5v1x6fNDsuJt1hZvUhQSrYkrGj8sjd7DEGN5EeovqiPPUlhNxDSECIG/5w/8sZ550xt5Nf6pVKOifLa673PJi8d61Yp9IGDxjJmyabJTvJjZ1lrRJlqeM6HwKq+I9b6wvWvfYAwteK/i1QYSI55OuTZeJMXCaRc+ee9JDjKmWzFecofIRcPcEY84LepAwkw0dPpJB6RBbIDQgDmnpyBnMhmCoim1A8WtiLy7KyMovFYqZs1p1pMBxBjzFeg= 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 | 2 ++ include/linux/mm.h | 8 ++++++++ include/linux/pgalloc_tag.h | 2 ++ mm/mm_init.c | 9 +++++++++ 4 files changed, 21 insertions(+) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 1f3207097b03..102caf62c2a9 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -95,6 +95,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 */ @@ -155,6 +156,7 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} static inline void alloc_tag_sub_noalloc(union codetag_ref *ref, size_t bytes) {} static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes) {} +static inline void set_codetag_empty(union codetag_ref *ref) {} #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index f5a97dec5169..ac1b661987ed 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -3112,6 +3113,13 @@ 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) { + union codetag_ref *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 0174aff5e871..ae9b0f359264 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -93,6 +93,8 @@ static inline void pgalloc_tag_split(struct page *page, 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 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 e9ea2919d02d..f5386632fe86 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2566,6 +2566,7 @@ void __init set_dma_reserve(unsigned long new_dma_reserve) void __init memblock_free_pages(struct page *page, unsigned long pfn, unsigned int order) { + union codetag_ref *ref; if (IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT)) { int nid = early_pfn_to_nid(pfn); @@ -2578,6 +2579,14 @@ 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 */ + ref = get_page_tag_ref(page); + if (ref) { + set_codetag_empty(ref); + put_page_tag_ref(ref); + } + __free_pages_core(page, order); }