From nobody Wed Apr 15 00:03:02 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D684C00140 for ; Fri, 29 Jul 2022 03:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbiG2DMm (ORCPT ); Thu, 28 Jul 2022 23:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbiG2DMi (ORCPT ); Thu, 28 Jul 2022 23:12:38 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A2B7C18A for ; Thu, 28 Jul 2022 20:12:35 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LvCDL3H76zjXYG; Fri, 29 Jul 2022 11:09:38 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Jul 2022 11:12:34 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Jul 2022 11:12:33 +0800 From: Kefeng Wang To: Naoya Horiguchi , Miaohe Lin , Andrew Morton , CC: , Kefeng Wang Subject: [PATCH v3] mm: memory-failure: convert to pr_fmt() Date: Fri, 29 Jul 2022 11:19:19 +0800 Message-ID: <20220729031919.72331-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use pr_fmt to prefix all pr_ output, but unpoison_memory() and soft_offline_page() are used by error injection, which have own prefixes like "Unpoison:" and "soft offline:", meanwhile, soft_offline_page() could be used by memory hotremove, so reset pr_fmt before unpoison_pr_info definition to keep the original output for them. Acked-by: Naoya Horiguchi Reviewed-by: Miaohe Lin Signed-off-by: Kefeng Wang --- v3 - fix build error via reset pr_fmt v2 - add undef pr_fmt and update changelog=20 mm/memory-failure.c | 58 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 2bc1a47c3d46..14439806b5ef 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -33,6 +33,9 @@ * are rare we hope to get away with this. This avoids impacting the core=20 * VM. */ + +#define pr_fmt(fmt) "Memory failure: " fmt + #include #include #include @@ -258,7 +261,7 @@ static int kill_proc(struct to_kill *tk, unsigned long = pfn, int flags) short addr_lsb =3D tk->size_shift; int ret =3D 0; =20 - pr_err("Memory failure: %#lx: Sending SIGBUS to %s:%d due to hardware mem= ory corruption\n", + pr_err("%#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n= ", pfn, t->comm, t->pid); =20 if ((flags & MF_ACTION_REQUIRED) && (t =3D=3D current)) @@ -276,7 +279,7 @@ static int kill_proc(struct to_kill *tk, unsigned long = pfn, int flags) ret =3D send_sig_mceerr(BUS_MCEERR_AO, (void __user *)tk->addr, addr_lsb, t); /* synchronous? */ if (ret < 0) - pr_info("Memory failure: Error sending signal to %s:%d: %d\n", + pr_info("Error sending signal to %s:%d: %d\n", t->comm, t->pid, ret); return ret; } @@ -358,7 +361,7 @@ static void add_to_kill(struct task_struct *tsk, struct= page *p, =20 tk =3D kmalloc(sizeof(struct to_kill), GFP_ATOMIC); if (!tk) { - pr_err("Memory failure: Out of memory while machine check handling\n"); + pr_err("Out of memory while machine check handling\n"); return; } =20 @@ -385,7 +388,7 @@ static void add_to_kill(struct task_struct *tsk, struct= page *p, * has a mapping for the page. */ if (tk->addr =3D=3D -EFAULT) { - pr_info("Memory failure: Unable to find user space address %lx in %s\n", + pr_info("Unable to find user space address %lx in %s\n", page_to_pfn(p), tsk->comm); } else if (tk->size_shift =3D=3D 0) { kfree(tk); @@ -418,7 +421,7 @@ static void kill_procs(struct list_head *to_kill, int f= orcekill, bool fail, * signal and then access the memory. Just kill it. */ if (fail || tk->addr =3D=3D -EFAULT) { - pr_err("Memory failure: %#lx: forcibly killing %s:%d because of failur= e to unmap corrupted page\n", + pr_err("%#lx: forcibly killing %s:%d because of failure to unmap corru= pted page\n", pfn, tk->tsk->comm, tk->tsk->pid); do_send_sig_info(SIGKILL, SEND_SIG_PRIV, tk->tsk, PIDTYPE_PID); @@ -431,7 +434,7 @@ static void kill_procs(struct list_head *to_kill, int f= orcekill, bool fail, * process anyways. */ else if (kill_proc(tk, pfn, flags) < 0) - pr_err("Memory failure: %#lx: Cannot send advisory machine check signa= l to %s:%d\n", + pr_err("%#lx: Cannot send advisory machine check signal to %s:%d\n", pfn, tk->tsk->comm, tk->tsk->pid); } put_task_struct(tk->tsk); @@ -821,12 +824,10 @@ static int truncate_error_page(struct page *p, unsign= ed long pfn, int err =3D mapping->a_ops->error_remove_page(mapping, p); =20 if (err !=3D 0) { - pr_info("Memory failure: %#lx: Failed to punch page: %d\n", - pfn, err); + pr_info("%#lx: Failed to punch page: %d\n", pfn, err); } else if (page_has_private(p) && !try_to_release_page(p, GFP_NOIO)) { - pr_info("Memory failure: %#lx: failed to release buffers\n", - pfn); + pr_info("%#lx: failed to release buffers\n", pfn); } else { ret =3D MF_RECOVERED; } @@ -838,8 +839,7 @@ static int truncate_error_page(struct page *p, unsigned= long pfn, if (invalidate_inode_page(p)) ret =3D MF_RECOVERED; else - pr_info("Memory failure: %#lx: Failed to invalidate\n", - pfn); + pr_info("%#lx: Failed to invalidate\n", pfn); } =20 return ret; @@ -869,7 +869,7 @@ static bool has_extra_refcount(struct page_state *ps, s= truct page *p, count -=3D 1; =20 if (count > 0) { - pr_err("Memory failure: %#lx: %s still referenced by %d users\n", + pr_err("%#lx: %s still referenced by %d users\n", page_to_pfn(p), action_page_types[ps->type], count); return true; } @@ -893,7 +893,7 @@ static int me_kernel(struct page_state *ps, struct page= *p) */ static int me_unknown(struct page_state *ps, struct page *p) { - pr_err("Memory failure: %#lx: Unknown page state\n", page_to_pfn(p)); + pr_err("%#lx: Unknown page state\n", page_to_pfn(p)); unlock_page(p); return MF_FAILED; } @@ -1179,7 +1179,7 @@ static void action_result(unsigned long pfn, enum mf_= action_page_type type, trace_memory_failure_event(pfn, type, result); =20 num_poisoned_pages_inc(); - pr_err("Memory failure: %#lx: recovery action for %s: %s\n", + pr_err("%#lx: recovery action for %s: %s\n", pfn, action_page_types[type], action_name[result]); } =20 @@ -1254,8 +1254,7 @@ static int __get_hwpoison_page(struct page *page, uns= igned long flags) if (head =3D=3D compound_head(page)) return 1; =20 - pr_info("Memory failure: %#lx cannot catch tail\n", - page_to_pfn(page)); + pr_info("%#lx cannot catch tail\n", page_to_pfn(page)); put_page(head); } =20 @@ -1318,7 +1317,7 @@ static int get_any_page(struct page *p, unsigned long= flags) } out: if (ret =3D=3D -EIO) - pr_err("Memory failure: %#lx: unhandlable page.\n", page_to_pfn(p)); + pr_err("%#lx: unhandlable page.\n", page_to_pfn(p)); =20 return ret; } @@ -1417,13 +1416,12 @@ static bool hwpoison_user_mappings(struct page *p, = unsigned long pfn, return true; =20 if (PageKsm(p)) { - pr_err("Memory failure: %#lx: can't handle KSM pages.\n", pfn); + pr_err("%#lx: can't handle KSM pages.\n", pfn); return false; } =20 if (PageSwapCache(p)) { - pr_err("Memory failure: %#lx: keeping poisoned page in swap cache\n", - pfn); + pr_err("%#lx: keeping poisoned page in swap cache\n", pfn); ttu |=3D TTU_IGNORE_HWPOISON; } =20 @@ -1441,7 +1439,7 @@ static bool hwpoison_user_mappings(struct page *p, un= signed long pfn, } else { kill =3D 0; ttu |=3D TTU_IGNORE_HWPOISON; - pr_info("Memory failure: %#lx: corrupted page was clean: dropped withou= t side effects\n", + pr_info("%#lx: corrupted page was clean: dropped without side effects\n= ", pfn); } } @@ -1470,14 +1468,14 @@ static bool hwpoison_user_mappings(struct page *p, = unsigned long pfn, try_to_unmap(folio, ttu|TTU_RMAP_LOCKED); i_mmap_unlock_write(mapping); } else - pr_info("Memory failure: %#lx: could not lock mapping for mapped huge p= age\n", pfn); + pr_info("%#lx: could not lock mapping for mapped huge page\n", pfn); } else { try_to_unmap(folio, ttu); } =20 unmap_success =3D !page_mapped(hpage); if (!unmap_success) - pr_err("Memory failure: %#lx: failed to unmap page (mapcount=3D%d)\n", + pr_err("%#lx: failed to unmap page (mapcount=3D%d)\n", pfn, page_mapcount(hpage)); =20 /* @@ -1844,7 +1842,7 @@ static int try_memory_failure_hugetlb(unsigned long p= fn, int flags, int *hugetlb *hugetlb =3D 0; return 0; } else if (res =3D=3D -EHWPOISON) { - pr_err("Memory failure: %#lx: already hardware poisoned\n", pfn); + pr_err("%#lx: already hardware poisoned\n", pfn); if (flags & MF_ACTION_REQUIRED) { head =3D compound_head(p); res =3D kill_accessing_process(current, page_to_pfn(head), flags); @@ -2003,8 +2001,7 @@ int memory_failure(unsigned long pfn, int flags) goto unlock_mutex; } } - pr_err("Memory failure: %#lx: memory outside kernel control\n", - pfn); + pr_err("%#lx: memory outside kernel control\n", pfn); res =3D -ENXIO; goto unlock_mutex; } @@ -2015,8 +2012,7 @@ int memory_failure(unsigned long pfn, int flags) goto unlock_mutex; =20 if (TestSetPageHWPoison(p)) { - pr_err("Memory failure: %#lx: already hardware poisoned\n", - pfn); + pr_err("%#lx: already hardware poisoned\n", pfn); res =3D -EHWPOISON; if (flags & MF_ACTION_REQUIRED) res =3D kill_accessing_process(current, pfn, flags); @@ -2232,7 +2228,7 @@ void memory_failure_queue(unsigned long pfn, int flag= s) if (kfifo_put(&mf_cpu->fifo, entry)) schedule_work_on(smp_processor_id(), &mf_cpu->work); else - pr_err("Memory failure: buffer overflow when queuing memory failure at %= #lx\n", + pr_err("buffer overflow when queuing memory failure at %#lx\n", pfn); spin_unlock_irqrestore(&mf_cpu->lock, proc_flags); put_cpu_var(memory_failure_cpu); @@ -2289,6 +2285,8 @@ static int __init memory_failure_init(void) } core_initcall(memory_failure_init); =20 +#undef pr_fmt +#define pr_fmt(fmt) "" fmt #define unpoison_pr_info(fmt, pfn, rs) \ ({ \ if (__ratelimit(rs)) \ --=20 2.35.3