From patchwork Fri Dec 13 01:33:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wang <00107082@163.com> X-Patchwork-Id: 13906336 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 668E6E7717F for ; Fri, 13 Dec 2024 01:34:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB9806B0085; Thu, 12 Dec 2024 20:34:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A68A56B0088; Thu, 12 Dec 2024 20:34:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9096C6B0089; Thu, 12 Dec 2024 20:34:08 -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 719766B0085 for ; Thu, 12 Dec 2024 20:34:08 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EA78E1A0A92 for ; Fri, 13 Dec 2024 01:34:07 +0000 (UTC) X-FDA: 82888213800.03.DE09943 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) by imf04.hostedemail.com (Postfix) with ESMTP id 8FC6340007 for ; Fri, 13 Dec 2024 01:33:38 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=Oz3iCFXp; spf=pass (imf04.hostedemail.com: domain of 00107082@163.com designates 220.197.31.4 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734053629; 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=QSqfE9gWL2eSEncQbXA9WzU3XQBVueorn8PymwoOkrw=; b=rh8iOHcdXJmU/9jmMBglQKswK/kKbdPBtMep+A07MvnDOiq4Z/58hnlC+eMc3qM1kZtptC XANGgR8HenxPMV86htbfIkskfbJ23qthfnaY/SqmjuSJJlBPSihay8UBeEVaVKZb7iRYm7 OefcC/TVqnqkFWvODJiFOkcuhzW3aCc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734053629; a=rsa-sha256; cv=none; b=RZyeGrweOOr7wAHaCCXFeOaIDCoqdqOmiljij8+euZf8ooSVCovYD9rK2iph1Eslk1NI9Y xnwv0fDPkTRr4PNsEB+MCmcUhAhkf/BG4v0ZaB1I8d/aJOSmgpdiIBlvos8qWGApFqzBu+ SyPa1QWWH7mON/Yo+ZecAO7Hu1bHf2c= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=Oz3iCFXp; spf=pass (imf04.hostedemail.com: domain of 00107082@163.com designates 220.197.31.4 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=QSqfE 9gWL2eSEncQbXA9WzU3XQBVueorn8PymwoOkrw=; b=Oz3iCFXpZt85h5EDcULaL IUEpyQKOLU8jKm+VzQJJhRwlHmKCV78aD4P4cdHnx5ok0nHR40s3p/0u7YgJF32M f/NkKksdSksMIU70+nej6izwYU0ovVRGdPy+bL51sVF61JgKxHG3YavwQDczGh9j 8hiHWnR2bHzJ6UeOVJa+mc= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wD3n9XujltnbdXUAA--.513S4; Fri, 13 Dec 2024 09:33:49 +0800 (CST) From: David Wang <00107082@163.com> To: surenb@google.com Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lkp@intel.com, oe-lkp@lists.linux.dev, oliver.sang@intel.com, yuzhao@google.com, David Wang <00107082@163.com> Subject: [PATCH v3] mm/codetag: clear tags before swap Date: Fri, 13 Dec 2024 09:33:32 +0800 Message-Id: <20241213013332.89910-1-00107082@163.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: _____wD3n9XujltnbdXUAA--.513S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Wry3Zw4rJw1xWFyxGFWruFg_yoW8Zw4Dpr 47Wr1UGa95JryxCrWkK3W2vr13Xw45tw15GFWa9a9YvryayrsrGrn5WFW2qFnrZFWkAF4S yrsFgrWIk3WUJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piJ5rxUUUUU= X-Originating-IP: [111.35.188.140] X-CM-SenderInfo: qqqrilqqysqiywtou0bp/xtbB0hC0qmdbjOs+3QAAsk X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8FC6340007 X-Stat-Signature: 4xiedmwp9foizbg5uo5hknnfar3uuzqg X-Rspam-User: X-HE-Tag: 1734053618-723542 X-HE-Meta: U2FsdGVkX18YyKw3PhJNSieaYyz3+IZEYNpKmD/+PXPRivYe55tSOwx88rSVLwLyVq8zeZWFvMUsVQ2HSjdxZ3OalMs2Qp0o8u2kvcENJzMW5+0vdCmYxh5kMLTNWD4blv12jWfJXPGr0B2+jE+jrC/zqVOnGxuMJFullqxevP2EvTKBeEICRhT0FUP392foxyDQL+L43eDMCqK7a0Km2iWteVThaQKg0+Xsvp0OeF1/xfR6QyC3MRt09RQ/CnofmLYhMsIYgs5hAcqv1or5cQODajTH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S6SxtIRoQXLnd2dENbbHuXdhkaRLcGVbplfJGiOwT3TZ79Eoc81auEMwLN3qFrwJW/bPJstuF1V143O1SfT6Pa0ftnv4uafp1zpPtcu 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: When CONFIG_MEM_ALLOC_PROFILING_DEBUG is set, kernel WARN would be triggered when calling __alloc_tag_ref_set() during swap: alloc_tag was not cleared (got tag for mm/filemap.c:1951) WARNING: CPU: 0 PID: 816 at ./include/linux/alloc_tag.h... Clear code tags before swap can fix the warning. And this patch also fix a potential invalid address dereference in alloc_tag_add_check() when CONFIG_MEM_ALLOC_PROFILING_DEBUG is set and ref->ct is CODETAG_EMPTY, which is defined as ((void *)1). Signed-off-by: David Wang <00107082@163.com> Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202412112227.df61ebb-lkp@intel.com Acked-by: Suren Baghdasaryan --- include/linux/alloc_tag.h | 2 +- lib/alloc_tag.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 7c0786bdf9af..cba024bf2db3 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -135,7 +135,7 @@ static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag) #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG static inline void alloc_tag_add_check(union codetag_ref *ref, struct alloc_tag *tag) { - WARN_ONCE(ref && ref->ct, + WARN_ONCE(ref && ref->ct && !is_codetag_empty(ref), "alloc_tag was not cleared (got tag for %s:%u)\n", ref->ct->filename, ref->ct->lineno); diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 35f7560a309a..3a0413462e9f 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -209,6 +209,13 @@ void pgalloc_tag_swap(struct folio *new, struct folio *old) return; } + /* + * Clear tag references to avoid debug warning when using + * __alloc_tag_ref_set() with non-empty reference. + */ + set_codetag_empty(&ref_old); + set_codetag_empty(&ref_new); + /* swap tags */ __alloc_tag_ref_set(&ref_old, tag_new); update_page_tag_ref(handle_old, &ref_old);