From patchwork Thu Dec 12 08:29:10 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: 13904807 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 BD071E7717F for ; Thu, 12 Dec 2024 08:30:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28F3F6B0082; Thu, 12 Dec 2024 03:30:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2185D6B0083; Thu, 12 Dec 2024 03:30:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B9726B0085; Thu, 12 Dec 2024 03:30:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E47C16B0082 for ; Thu, 12 Dec 2024 03:30:01 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9DF4743F04 for ; Thu, 12 Dec 2024 08:30:01 +0000 (UTC) X-FDA: 82885633698.18.FC05E19 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) by imf09.hostedemail.com (Postfix) with ESMTP id 82787140002 for ; Thu, 12 Dec 2024 08:29:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=VvRyHYPG; dmarc=pass (policy=none) header.from=163.com; spf=pass (imf09.hostedemail.com: domain of 00107082@163.com designates 117.135.210.3 as permitted sender) smtp.mailfrom=00107082@163.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733992188; a=rsa-sha256; cv=none; b=m5EeAa/bxXKdyS7vnvMxXylu3RIhkmsGA82wRKKGNALVn9T/aFx2cDcj3gc8B4i141gD6R SanOkCTkHyMwLPZpI4cuj0AvZVDUSU7MeGOxG8KfhtQ3w5UHYFGBvEihRckah3cVkd6FtX +vSataEHwkBvquqJq0ZoRIRhJ6Zdlds= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=VvRyHYPG; dmarc=pass (policy=none) header.from=163.com; spf=pass (imf09.hostedemail.com: domain of 00107082@163.com designates 117.135.210.3 as permitted sender) smtp.mailfrom=00107082@163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733992188; 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=1SQUAwjf40SnLqWEK57sKLEKKy0eFYKmxOuVnk0xUog=; b=EHm7JWpVAkqZLup5t094j49dd/vTVPoL4ujgaLD+xnh1xxgaGBlasL3GsEBMnULMXa7rBG /B5c4NVmy3Sbg9NszVA15YEQ5Rd5h3JTasBTeM45/ekE9vN/ivvS0hQskgRDtCzEf4mHPm Wb+pbUIM+IjDbTTuP0aWhjMfdk2bVQY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=1SQUA wjf40SnLqWEK57sKLEKKy0eFYKmxOuVnk0xUog=; b=VvRyHYPGgH+pQ9hjlLZlt nnfoxeMWlfy4ke2KlON/dTYw1pEvN50OX7JiphJ4dEEnXBML55BPflS3gUBS2ILs ysdeMFZUcMEUrs5WgjKWC6yO8/XL0tYhyliOSGDVxGdCsj4s653AHPyOL1vK7Z9D /3WfNgdSKNa22Xw+UimdxI= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wD3FzrXnlpnfupOAA--.30434S4; Thu, 12 Dec 2024 16:29:26 +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 v2] mm/codetag: clear tags before swap Date: Thu, 12 Dec 2024 16:29:10 +0800 Message-Id: <20241212082910.30826-1-00107082@163.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: _____wD3FzrXnlpnfupOAA--.30434S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Wry3Zw4rJw1xWFyxGFWruFg_yoW8ur15pr 47Wr1UGa95JryxCrWkK3W2vr13Xw45tw15GFWa9a95Zryayr47Gr1kWFW2qFnrZFWkAF4S yrsrWrWIk3WUA37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pilfO7UUUUU= X-Originating-IP: [111.35.188.140] X-CM-SenderInfo: qqqrilqqysqiywtou0bp/xtbB0gOzqmdalpSqGAABsE X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 82787140002 X-Stat-Signature: r38d9b9cj7hzrxioz5hkz95rxstez4a5 X-HE-Tag: 1733992182-386449 X-HE-Meta: U2FsdGVkX1+5ZfoZ/AqcEuq66E6g81BrptcZePQP52YKSUI0RcQNgJ2Yo5dT0lqBnNJ1w2SfTdfZ5yFxNh3eBcXI49eB+KaRbN1MwEjEozwSoyeIfdwMeA2glE+JG6ogx6upv1IJ/+xr2YvA+UteX2nsWvvP3WBSKSvVw99Sb7sQAijPri4UNZKq06QUl0G/pAYZb/rZEVnIWXZsrsqFieKPPB8vv+WjS9fo2jQLJ9rJPSu/xNXgnxZq4NLBQLO7YP+NumS7324Utyrtp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ZaVDjYmXT5Dnw0LxkDXP7WEo3C3r2LgR/9wYpnpJ9XUThDZK+EC7JAQl1QxI7gorWtVaqOPJoxOCW+1q8YJusZVHQ8twYO5uE5M= 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 Suggested-by: Suren Baghdasaryan 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);