From mboxrd@z Thu Jan 1 00:00:00 1970 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 1F03FC52D7C for ; Fri, 23 Aug 2024 16:39:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73D686B0284; Fri, 23 Aug 2024 12:39:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ED976B0285; Fri, 23 Aug 2024 12:39:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B4A26B0286; Fri, 23 Aug 2024 12:39:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3F09F6B0284 for ; Fri, 23 Aug 2024 12:39:45 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E33E6161E71 for ; Fri, 23 Aug 2024 16:39:44 +0000 (UTC) X-FDA: 82484071488.16.BA6369C Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by imf14.hostedemail.com (Postfix) with ESMTP id 26D8C100012 for ; Fri, 23 Aug 2024 16:39:42 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=E2TRmkqY; spf=pass (imf14.hostedemail.com: domain of surenb@google.com designates 209.85.160.178 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724431118; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OWCZVGAlZgiRQ76TnTfciwWkaeUiO7Q9jJrOr7a++YM=; b=zoC9vsMi25qVWUuhjMHufpgs96Q9WfPpVA4EPnJMyE9jN271d1fP4FPp3fy2VSUTs9dBdZ itFj0whgVlSqQFg2wrEe9vh9h3ex3ezd+oPZio7ukD5QEqw6WuFT/KkDDmdg39u053oY58 zwDOUeyLeOP0MIU8eoKkSO6mIzseaDU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=E2TRmkqY; spf=pass (imf14.hostedemail.com: domain of surenb@google.com designates 209.85.160.178 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724431118; a=rsa-sha256; cv=none; b=4DrS65+6S06LsplrX7tHJDm0xxhCM7uT9jmGgM6iS1uIq0UmQAHbHiygFoI1cLhD0pdJ8l ML2wkfU8PIhu9cHJ7KQlPQgkl+RH7KiJVMQ6WDO+u9JE3MLx7KimC4qnwkDTnF0CtRJKxd C+p+GFqtKumEYKFkwEE8/6qB459BZFg= Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-4518d9fa2f4so3151cf.0 for ; Fri, 23 Aug 2024 09:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724431182; x=1725035982; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OWCZVGAlZgiRQ76TnTfciwWkaeUiO7Q9jJrOr7a++YM=; b=E2TRmkqYqT0XcT6tZXN+O+y2ASIssrubIDW7A6DuHwBiCRW333hLj1Gb0RbnAqoLz+ 6/MvHp8kpm+BcFvneOhHxcSRx5pPH+xxQbpEaQDmqixLexPxVKKtPR0BNUpA35GzsYn9 OLUeK3XL03Fvhup30Ebftpn/H9LbiKCl7zTyNvLW1TTP9DmxGymDmyDAQAqnZe9EGQWz E3Tq/sCif97O+VoHe5Ge0cHrzSs1zAiWPwaiw5t2Wkqasl8OfkP/WqKJVvF6MG+Y7Iqy oYycKAGP1ziuR1hLSELfmFI7dQ0mKOmUftGMb+mH+lDJHqyMOiqoP+tMTllL3pOOEaLb j30Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724431182; x=1725035982; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OWCZVGAlZgiRQ76TnTfciwWkaeUiO7Q9jJrOr7a++YM=; b=P18elkjGHQz8ZhfveEUEseEgjH+OkAr8jpXf6UB8Xa1CJgVlji15ZbbKiOHuSxPYlZ 8AB2uYZBCAf7/6JIhLcK/Y6FwPk2+4pvMklRsc/MB9SrSeoN9yZ0mDudxepq8ZMApqvm DBkYlg3MCsME/zzQx2Iip5aNWB0/z6gOpsauLqAQ2Cu9nVGghqUCRWcihkyCRr5sStEG bKCCVUwpxjGKD8UuzvHE5W+jbSHJl3F0EyzwcYasE/kw+I74hB8FjUIqFPQcQBk2IHt8 GXFj83ZsNVaiqqPjVhLFy6HlPe1zcGx2gpp9I/yc+bnw6A2mgFnkXsfsXeXaU/IUYPhG bcQQ== X-Forwarded-Encrypted: i=1; AJvYcCUI9cC2ZQ2QemdQLVdlAFzBfQefFDKf9tuBB7QlHF/f1aRAk4P7qZSDCaGHtewTMuPWUqwzcu2EkQ==@kvack.org X-Gm-Message-State: AOJu0YyRMGHay0iJ0cB3Y85s1CG0AKYpiMbBxqNvvdZil4vpHwoU5NUl zOJSXK7JNJ1z4RNQJIqa5WXNSH04OyVRZ3LGNH44OQaV0owkvLGRYW68wBpu2VX2JPq1vc91NlJ xbCQi8CfEy+Qg5Wk+xK/KqEkJ4n1U6k7lj3Tg X-Google-Smtp-Source: AGHT+IFoUZAQeCvqN+NjxXRErz71IIQZhTN00AkX1g1s0tHX14bey0qIKs+NzKWVaf59WcugpqvHyCzlUGndZY5N0uE= X-Received: by 2002:ac8:5a8a:0:b0:44f:e12e:3015 with SMTP id d75a77b69052e-45509ebc0demr3093081cf.25.1724431181755; Fri, 23 Aug 2024 09:39:41 -0700 (PDT) MIME-Version: 1.0 References: <20240823062002.21165-1-hao.ge@linux.dev> In-Reply-To: <20240823062002.21165-1-hao.ge@linux.dev> From: Suren Baghdasaryan Date: Fri, 23 Aug 2024 09:39:30 -0700 Message-ID: Subject: Re: [PATCH] codetag: debug: mark codetags for poisoned page as empty To: Hao Ge Cc: akpm@linux-foundation.org, david@redhat.com, kent.overstreet@linux.dev, linmiaohe@huawei.com, nao.horiguchi@gmail.com, pasha.tatashin@soleen.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hao Ge , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: u6r89fqhzzxrcz6th7cx583kkpjuyczc X-Rspam-User: X-Rspamd-Queue-Id: 26D8C100012 X-Rspamd-Server: rspam02 X-HE-Tag: 1724431182-877077 X-HE-Meta: U2FsdGVkX1/zsIvOehYbjwHYL0wr6XPL/BypIcG9RSAp3vNool0kfM0lQsyF+vaY+da1eacf6g0kp6Yousv8+17CQXkfW0xDny6EnSTCIIz/fUABC/6rymtUGlRVkHvzF+iDBPTXhXci028COq7mc1qxaTiuaaLsbOyTuZPsjnDDvIeKbZWHlrvtRN+1Q2K7qDypslGY0+KcipE3kCJQjptstflMuLV0O3x8yr+avCYaOn14fN71AsgFLs0VYIohn3jLvLHmqz+k1qc7Nvu12jagPTmDnbf2r/f8AJ4expdEU9asF3l/znXo2eCe75ihwLwG4zc9g5HLZnWTr4WflNB0R/YjAFkKhRSP/wPKQy67yY0WZdVOHZUnsOKIkraTUVOM9W9iuHw5dDexRnCk/DuSY1eX/tuVqqJz6+I/WuSnngp/PalnePPqd1XZT+sj9WrU3bLQz7oStzLS5KNK/RIGXX0dyUBPan8fK7hbuPj3VvVDGZsQmedEMWSgsTQWQgrIlIC728sbSeCllW5qOr0Pv1M79pQM9Lwh6OkLIybsMxAUwcgr6YfYVwv1aJXyfKTOhf1dSmkp7sH3227gd7FQHGuUcmKSurXsr1u6i28kRBO/GU81lecc42hV6AUD8XwgfgoQHfB1oOt9J32JasckcrEky3AhLuFyQOacKSBCQIFPUEBjOLkKyEYYnlYN/02WT31fXpt4Djt1Yhs/NSuUcddZEEshrbo4rDHIry9a49KQm9DC5zJVuIsN/i6yvulbrnF9lTFRK4F1Q+J5NkHdcpm1awd9sxFcVIgZc69PIUYGOW/MCVX10rEoNNrA6sTHsWXVdLysEUP0umhJByU6XL6wMjqgtuh+ouO6mGhQy65yuJh0PCaW2ZGdrU2N9NaHc+F7xyskydbN7pMCEmm6OxjTIZcgPY8JjFSGzGFNNIBbpeim4FIVE4i7nsYmV1N9iDHJDXxTsaYaE+i S3SNZKnR oO7PqaelZAlTrhlGCMb2aPhIC+6XPMYlsXKZ6pykOLOkktRbX62qVDr36zIU37PemcoDfP7h0sd/29MV7zYfzeGXIfPu/pGH050gtvSFavwYaB9/uUfO50IdIx4CTRqV2DN3y06Df3jebiVCZv3+4cyfhHI0gvVfbhH3WNq+1or+zicq7DD7wpEt3SoIkLfYun2c9QFgQXKqtWIAkY+pSCklv4i08Rgijswmkcdh1jnoAtA5Vk54IYA1D6KcJ3BV8On7IEFjcfwtluO2MoPl+fBCHNHCyWh0J9osDteSf7AHHmZG+Ud52uEZBQs03m1ifX1If X-Bogosity: Ham, tests=bogofilter, spamicity=0.000058, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Aug 22, 2024 at 11:21=E2=80=AFPM Hao Ge wrote: > > From: Hao Ge > > The PG_hwpoison page will be caught and isolated on the entrance to > the free buddy page pool. > > But for poisoned pages which software injected errors, > we can reclaim it through unpoison_memory. > > So mark codetags for it as empty,just like when a page > is first added to the buddy system. > > It was detected by [1] and the following WARN occurred: Hi Hao, Thanks for fixing this. I find this description a bit unclear. How about something like this: 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_rpfil= ter ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_conntrack ebtab= le_nat ebtable_broute ip6table_nat ip6table_man4 > [ 113.941638][ T3282] CPU: 2 UID: 0 PID: 3282 Comm: madvise11 Kdump: loa= ded Tainted: G W 6.11.0-rc4-dirty #18 > [ 113.943003][ T3282] Tainted: [W]=3DWARN > [ 113.943453][ T3282] Hardware name: QEMU KVM Virtual Machine, BIOS unkn= own 2/2/2022 > [ 113.944378][ T3282] pstate: 40400005 (nZcv daif +PAN -UAO -TCO -DIT -S= SBS BTYPE=3D--) > [ 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: f= fff80008249f0a0 > [ 113.948165][ T3282] x26: 0000000000000000 x25: ffff80008249f2b0 x24: 0= 000000000000000 > [ 113.949134][ T3282] x23: 0000000000000001 x22: 0000000000000001 x21: 0= 000000000000000 > [ 113.950597][ T3282] x20: ffff0000c08fcad8 x19: ffff80008251e000 x18: f= fffffffffffffff > [ 113.952207][ T3282] x17: 0000000000000000 x16: 0000000000000000 x15: f= fff800081746210 > [ 113.953161][ T3282] x14: 0000000000000000 x13: 205d323832335420 x12: 5= b5d353031313339 > [ 113.954120][ T3282] x11: ffff800087093500 x10: 000000000000005d x9 : 0= 0000000ffffffd0 > [ 113.955078][ T3282] x8 : 7f7f7f7f7f7f7f7f x7 : ffff80008236ba90 x6 : c= 0000000ffff7fff > [ 113.956036][ T3282] x5 : ffff000b34bf4dc8 x4 : ffff8000820aba90 x3 : 0= 000000000000001 > [ 113.956994][ T3282] x2 : ffff800ab320f000 x1 : 841d1e35ac932e00 x0 : 0= 000000000000000 > [ 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 ]--- > > Link [1]: https://github.com/linux-test-project/ltp/blob/master/testcases= /kernel/syscalls/madvise/madvise11.c To fix this, clear the page tag reference after the page got isolated and accounted for. > > Fixes: a8fc28dad6d5 ("alloc_tag: introduce clear_page_tag_ref() helper fu= nction") This would be more appropriate: Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty") > Cc: stable@vger.kernel.org # v6.10 > Signed-off-by: Hao Ge > --- > mm/page_alloc.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index c565de8f48e9..7ccd2157d092 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1054,6 +1054,14 @@ __always_inline bool free_pages_prepare(struct pag= e *page, > reset_page_owner(page, order); > page_table_check_free(page, order); > pgalloc_tag_sub(page, 1 << order); > + > + /* > + * For poisoned pages which software injected errors, Not sure what you mean by "which software injected errors". Maybe it's a typo and should be "with software injected errors"? > + * we can reclaim it through unpoison_memory. > + * so mark codetags for it as empty, > + * just like when a page is first added to the buddy syst= em. > + */ I think you can simply say here that: /* * The page is isolated and accounted for. Mark the codetag as empty to avo= id * accounting error when the page is freed by unpoison_memory(). */ > + clear_page_tag_ref(page); > return false; > } > > -- > 2.25.1 >