From patchwork Thu Dec 12 04:01:04 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: 13904627 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 1F39EE7717F for ; Thu, 12 Dec 2024 04:03:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 395896B007B; Wed, 11 Dec 2024 23:03:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 345516B0082; Wed, 11 Dec 2024 23:03:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 233FE6B0083; Wed, 11 Dec 2024 23:03:42 -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 056056B007B for ; Wed, 11 Dec 2024 23:03:41 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9E41340BF5 for ; Thu, 12 Dec 2024 04:03:41 +0000 (UTC) X-FDA: 82884962118.07.6FE7C3E Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by imf01.hostedemail.com (Postfix) with ESMTP id B1E1B40007 for ; Thu, 12 Dec 2024 04:03:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b="kmq6t/PY"; spf=pass (imf01.hostedemail.com: domain of 00107082@163.com designates 220.197.31.3 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=1733976201; 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=NISGIFQ99jxLIPdLWNb92see1Jj4Nxu/t+MRtsryHa8=; b=KAnKhdfFqrN7iJs6+V+vvxmMDeDX7jBd3Zq1tSLj/0ZyW0eEgKkQon04stjrmn2KguUPVj YWUDgJHT21eP2+L1D8QbFC7j1bsfpg3SaL8s8X1+ilG9fCCoGvHJg8SOiHaUJvY1bTMjEs o8+fsfSw8wFJSJtCZDZtMVhkT8jtsIQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b="kmq6t/PY"; spf=pass (imf01.hostedemail.com: domain of 00107082@163.com designates 220.197.31.3 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733976201; a=rsa-sha256; cv=none; b=K9+sr19OmxoRobiec985ol74Ge4v4LZ0jsBdIfYsPqG4nIc6N5w0IneO2qOJFe77VOq43p bo+h8UpS8LwmukqIxUzRo9XgmATIicS+wfNQkVLdwLzcEpLaUOpzNdahW89PontFaUpDhP gVNrP9Slf7UTtAyEM4E8BfprWqYzR0s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=NISGI FQ99jxLIPdLWNb92see1Jj4Nxu/t+MRtsryHa8=; b=kmq6t/PYPITh7s39rMDDY SU5sxVMP4JTbAtorTdPT63bba1XjfQbsF00WyEjWvAGFlO1tMgYQJzeCC/KyzDoG Dm9WxTuhw+mRi/7aTrR+rKIloNipcJCw/llhopAlvVNbp9SMvJxUSo/Wtcm64C22 uDqYk8v5t9GpDOrcMZ+sgM= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wD3HzQCYFpnKtQfAA--.12556S4; Thu, 12 Dec 2024 12:01:28 +0800 (CST) From: David Wang <00107082@163.com> To: surenb@google.com, kent.overstreet@linux.dev Cc: yuzhao@google.com, oliver.sang@intel.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lkp@intel.com, oe-lkp@lists.linux.dev, David Wang <00107082@163.com> Subject: [PATCH] mm/codetag: clear tags before swap Date: Thu, 12 Dec 2024 12:01:04 +0800 Message-Id: <20241212040104.507310-1-00107082@163.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <202412112227.df61ebb-lkp@intel.com> References: <202412112227.df61ebb-lkp@intel.com> MIME-Version: 1.0 X-CM-TRANSID: _____wD3HzQCYFpnKtQfAA--.12556S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Wry3Zw4rJw1xWFyxGFWruFg_yoW8CFW7pr 4UWr1UGa95Jry7CrWvgw12vr15Xw45t3W5GFWY9as5ZryYyr47Gr4kWFy2qFnrZFWkGF4I yrnFgrWIk3WUJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piGjg7UUUUU= X-Originating-IP: [111.35.188.140] X-CM-SenderInfo: qqqrilqqysqiywtou0bp/xtbB0hizqmdaUlMGXgABs2 X-Rspamd-Queue-Id: B1E1B40007 X-Rspamd-Server: rspam12 X-Stat-Signature: ks6zxaiwbq9asu68nefoca83sir8rf8w X-Rspam-User: X-HE-Tag: 1733976200-715073 X-HE-Meta: U2FsdGVkX18XvTgcjz4QAWnhECCuO6xhEgb215ANvTwci6/onEPoxOTRrfr9wtt2jyekgClNAmxXo/PgDOOzsM+KGnxu3nKiaHh3jQfvDus/xqMBlTVc1p0RnzhGXPNdyGo/4NEcn/aUy57CWnBG6DBLtQm0ZrzQXJzxy6gOYLrA4ADEx8cbhol+VD2iAErFHLcqFdo4ExEx0glXq9ubGSBJm5ycF8PGLDDP4fG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CVUtM7FzIo8q96WrPKqVUs2jyGBY4bwVbdJk9tBp2mHqv1uNtVhBV0N96PZLKJLo5S2zRRZuh6mdGbcnpg5mfHFywlWcOW24kyKMXb7ZtsXIQ= 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 --- include/linux/alloc_tag.h | 2 +- lib/alloc_tag.c | 4 ++++ 2 files changed, 5 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..cc5fda9901c2 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -209,6 +209,10 @@ void pgalloc_tag_swap(struct folio *new, struct folio *old) return; } + /* clear tags before swap */ + 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);