From patchwork Sun Aug 25 16:36:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Ge X-Patchwork-Id: 13776830 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 F116EC5320E for ; Sun, 25 Aug 2024 16:37:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89EDB8D000B; Sun, 25 Aug 2024 12:37:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8008B8D0006; Sun, 25 Aug 2024 12:37:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 653438D000B; Sun, 25 Aug 2024 12:37:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 445C68D0006 for ; Sun, 25 Aug 2024 12:37:03 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E74DCA8072 for ; Sun, 25 Aug 2024 16:37:02 +0000 (UTC) X-FDA: 82491322284.16.A55355D Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by imf03.hostedemail.com (Postfix) with ESMTP id 1CE322001F for ; Sun, 25 Aug 2024 16:36:59 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aImeBj+X; spf=pass (imf03.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.170 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724603753; 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=aeMNQe0tBKS3oiPHgYZoJ2ZhIrMsmPhNpyzgPq5fx+k=; b=khLVU2+LLMnSjgHgB4UlzBKj9gW3ayed8vx7CXS30TmXjfZJuPxXawnHc185KlMIa5hM/y +kbxAbiFJv66GwXtYF39582D3LN8S/2ZkjdGlnBuhWaokQgQWqIFMWnAB0TbW/cEghk3O3 neo9ImqsRtqVYbqsJho7fVjFFvZQRSY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aImeBj+X; spf=pass (imf03.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.170 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724603753; a=rsa-sha256; cv=none; b=YobwGrZG9Xzf00BzO13wMF4cZkVfTTVF8ntFRhjrC3hI0xproPTzm6iu6zfJhw2On9Oywh t99jPhBsCMFSDrU81/9V7ttcJAWZe1bthNXfGXyk1gWXk88psc8yFq+MZ/LCYW8wXnJjCi j4tvKqyQlVg0g20g4o9ALW80N1m25kM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724603818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aeMNQe0tBKS3oiPHgYZoJ2ZhIrMsmPhNpyzgPq5fx+k=; b=aImeBj+X5Tdaji6fVQN5YhFXRfjZGFHg6IFQPEigGIvNQj9L0IQpiNuD6s3q56H8si4y4B T+8p7O6SmEZ4CYduT9EKdmhfKFsUeDH2nfpKUJytaBTEL9/2+88DdoGB8SXa3F7I1TvNGd p/z0nWVmYdSlu7tXt7D4aSDIbjGyuBA= From: Hao Ge To: akpm@linux-foundation.org, surenb@google.com, linmiaohe@huawei.com Cc: hao.ge@linux.dev, david@redhat.com, kent.overstreet@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nao.horiguchi@gmail.com, pasha.tatashin@soleen.com, Hao Ge , stable@vger.kernel.org Subject: [PATCH v2] codetag: debug: mark codetags for poisoned page as empty Date: Mon, 26 Aug 2024 00:36:49 +0800 Message-Id: <20240825163649.33294-1-hao.ge@linux.dev> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: nm5jn6rihye9ynbee7a4jiqwe7p6rbnm X-Rspam-User: X-Rspamd-Queue-Id: 1CE322001F X-Rspamd-Server: rspam02 X-HE-Tag: 1724603819-583512 X-HE-Meta: U2FsdGVkX1+0DIquB0WGusecAdkr5uASB+41w8OI0yqNptsNBETsiKmL36SPt1CpRYpfmEytXwVX221pFl+uj063QEJzA9CbG8YGAe+oYWO70etGdbDzZuflIfFihfXaDa8qoGzmqSBwRmckUoua9OUfvOLaCIXmLqKBLcGybwQPjxWr1CkEs+yfac7k7OUIrndudrOPHc/fX/ELDRxbmNVp2fBexUlQ0frRY8kbWCkAvQiEtF/uLhpK73/+NORqLV3eWTv3JNp3ZrdPOLtuHRa+BfmRlcHV3N3EttQEWB2hSnFl7MhhAcwH3jl8cCtofYv1bJVofhC788GDtixpvBPO3DWUb7PAIiyzgsbI1LGEpxXKTln/ATCpwlKznOmr6eYVttPsBp/S7QP711KWE+gZ1C0mY9AxdBV677zQJifVcjzOMzhxYN1D1Dvcnt0GoRDx+sV5/2pjRUdj/Y/mGKffksqx+l03AlOJ1AFoX7D8k7gb0mAhSWPEVVS41nRBGs4nJbqrzEGJeEMnLgspJzu/ZcK1ki5Hy0nuee1HLtvtLu/2xKuJhnt/Y416npGupWYNZAXbLWq6W3jLRKeD2LiZsCCDgP/er/G+4gUix9cHmWzQzjXgK3QAjAk2icrveGzmKsCQvdJjTIeUPxR5Ekcs2jKzMFPtMlJh1zJNTG8m6o+WtqIDmkONstgvDf6sVjYmaItduzwIvm0SiLLOguPuxWyDHSt/VdQxEvBhzwDWfBdnPflhxckie4m7LsLk5JzzsMTf3syouTo+xzEBeXSYn/qklz+wG///wtI/YDluF4/BlvltbZu9M361Kc1nU3t15JgiwKh7VTpLBJq0pnarlPe60w+iqe/82XHDoKHnfJUrsgxDRIuWnkipfmiC0qFjDDmDcUo1CGwk/LM38WsGCeQ3pNl2VO8TE9+TNALR3i7uLiZUrSgk+j+rF17s5jdCGQsMhWdm1Jq5EIL 3vQhUzoZ uWp+dtSajg7bzb80n9RHCB3bMLGbyaTF11cHWKuKS63+/uotaOTYC+HmoGs9TIOvrGln5+PtnsCPJsW+WqyBt85RQTYXK9BE3pcpJ76U0NSoPOilBauwEw/RYEBAG6ZXMtVdDyf8SIkufkgGCNcQOS5HLDocay4CdwRilDQtC1tFGDQCSzYuFvZAn3ysjqjBabgbdURD+X/ZTf2RM18P3zYdjMgt9FU5BiLXKpNNmUNPvaA+uxFJ9Q3vEyA== 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: From: Hao Ge When PG_hwpoison pages are freed,they are treated differently in free_pages_prepare() and instead of being released they are isolated. Page allocation tag counters are decremented at this point since the page is considered not in use. Later on when such pages are released by unpoison_memory(), the allocation tag counters will be decremented again and the following warning gets reported: [ 113.930443][ T3282] ------------[ cut here ]------------ [ 113.931105][ T3282] alloc_tag was not set [ 113.931576][ T3282] WARNING: CPU: 2 PID: 3282 at ./include/linux/alloc_tag.h:130 pgalloc_tag_sub.part.66+0x154/0x164 [ 113.932866][ T3282] Modules linked in: hwpoison_inject fuse ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_conntrack ebtable_nat ebtable_broute ip6table_nat ip6table_man4 [ 113.941638][ T3282] CPU: 2 UID: 0 PID: 3282 Comm: madvise11 Kdump: loaded Tainted: G W 6.11.0-rc4-dirty #18 [ 113.943003][ T3282] Tainted: [W]=WARN [ 113.943453][ T3282] Hardware name: QEMU KVM Virtual Machine, BIOS unknown 2/2/2022 [ 113.944378][ T3282] pstate: 40400005 (nZcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 113.945319][ T3282] pc : pgalloc_tag_sub.part.66+0x154/0x164 [ 113.946016][ T3282] lr : pgalloc_tag_sub.part.66+0x154/0x164 [ 113.946706][ T3282] sp : ffff800087093a10 [ 113.947197][ T3282] x29: ffff800087093a10 x28: ffff0000d7a9d400 x27: ffff80008249f0a0 [ 113.948165][ T3282] x26: 0000000000000000 x25: ffff80008249f2b0 x24: 0000000000000000 [ 113.949134][ T3282] x23: 0000000000000001 x22: 0000000000000001 x21: 0000000000000000 [ 113.950597][ T3282] x20: ffff0000c08fcad8 x19: ffff80008251e000 x18: ffffffffffffffff [ 113.952207][ T3282] x17: 0000000000000000 x16: 0000000000000000 x15: ffff800081746210 [ 113.953161][ T3282] x14: 0000000000000000 x13: 205d323832335420 x12: 5b5d353031313339 [ 113.954120][ T3282] x11: ffff800087093500 x10: 000000000000005d x9 : 00000000ffffffd0 [ 113.955078][ T3282] x8 : 7f7f7f7f7f7f7f7f x7 : ffff80008236ba90 x6 : c0000000ffff7fff [ 113.956036][ T3282] x5 : ffff000b34bf4dc8 x4 : ffff8000820aba90 x3 : 0000000000000001 [ 113.956994][ T3282] x2 : ffff800ab320f000 x1 : 841d1e35ac932e00 x0 : 0000000000000000 [ 113.957962][ T3282] Call trace: [ 113.958350][ T3282] pgalloc_tag_sub.part.66+0x154/0x164 [ 113.959000][ T3282] pgalloc_tag_sub+0x14/0x1c [ 113.959539][ T3282] free_unref_page+0xf4/0x4b8 [ 113.960096][ T3282] __folio_put+0xd4/0x120 [ 113.960614][ T3282] folio_put+0x24/0x50 [ 113.961103][ T3282] unpoison_memory+0x4f0/0x5b0 [ 113.961678][ T3282] hwpoison_unpoison+0x30/0x48 [hwpoison_inject] [ 113.962436][ T3282] simple_attr_write_xsigned.isra.34+0xec/0x1cc [ 113.963183][ T3282] simple_attr_write+0x38/0x48 [ 113.963750][ T3282] debugfs_attr_write+0x54/0x80 [ 113.964330][ T3282] full_proxy_write+0x68/0x98 [ 113.964880][ T3282] vfs_write+0xdc/0x4d0 [ 113.965372][ T3282] ksys_write+0x78/0x100 [ 113.965875][ T3282] __arm64_sys_write+0x24/0x30 [ 113.966440][ T3282] invoke_syscall+0x7c/0x104 [ 113.966984][ T3282] el0_svc_common.constprop.1+0x88/0x104 [ 113.967652][ T3282] do_el0_svc+0x2c/0x38 [ 113.968893][ T3282] el0_svc+0x3c/0x1b8 [ 113.969379][ T3282] el0t_64_sync_handler+0x98/0xbc [ 113.969980][ T3282] el0t_64_sync+0x19c/0x1a0 [ 113.970511][ T3282] ---[ end trace 0000000000000000 ]--- To fix this, clear the page tag reference after the page got isolated and accounted for. Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty") Cc: stable@vger.kernel.org # v6.10 Signed-off-by: Hao Ge Reviewed-by: Miaohe Lin Acked-by: Suren Baghdasaryan --- v2: adjusting the commit message and comments in the code based on Suren's suggestions. --- mm/page_alloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c565de8f48e9..91ace8ca97e2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1054,6 +1054,13 @@ __always_inline bool free_pages_prepare(struct page *page, reset_page_owner(page, order); page_table_check_free(page, order); pgalloc_tag_sub(page, 1 << order); + + /* + * The page is isolated and accounted for. + * Mark the codetag as empty to avoid accounting error + * when the page is freed by unpoison_memory(). + */ + clear_page_tag_ref(page); return false; }