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 D3E09C43334 for ; Tue, 14 Jun 2022 05:12:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC9B68D020D; Tue, 14 Jun 2022 01:12:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E78CD8D020C; Tue, 14 Jun 2022 01:12:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D40BB8D020D; Tue, 14 Jun 2022 01:12:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C55568D020C for ; Tue, 14 Jun 2022 01:12:26 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8B7E435104 for ; Tue, 14 Jun 2022 05:12:26 +0000 (UTC) X-FDA: 79575670692.21.F50CCA1 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf14.hostedemail.com (Postfix) with ESMTP id 97E2B100075 for ; Tue, 14 Jun 2022 05:12:24 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id f8so6832194plo.9 for ; Mon, 13 Jun 2022 22:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ufPnLDgaYxht70tLLUiqZA8dThtkFoWrcgzlo7+rnvk=; b=0AIe2LL5xmtOlNhSILqjHDcZU7IdvM4jPiMIDm35r8c3YaR5D6nwtugk9Fy9q8DaUu X5+Hq5QdkI/s+PM6o+CkuRZILKZK+iajjLH37mtBG3Q49r6Z3n8YQ6FLd2Nz7amVIvKY lObfW1UTUg9SFwm0tpf6nZsp7UQU4WPoHad/h1Y7EwRv91Mksa7dNc07DFQXcyz+5QMJ /U/sKSHAV1CkV1vmPhSFy9Fl6w0jD7jj5b5pWhZJk3WWXt8O9byk0gk/ZUa4Wy44YAG3 FzJWusijJA7in9u6jTinz2BrlmkqabhlRDh/wlQMmCCC8mrRB+ZU+JFjs1DjFY5seG77 BARg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ufPnLDgaYxht70tLLUiqZA8dThtkFoWrcgzlo7+rnvk=; b=w5h0/pUGsPpIoLSrPujNC2ZJ/yP6nPEGDqknSFJYmL+IRri/Wc/rt41avc3xhhRrmM cLQgO5FpW5J9YgPTtquP9nIuDl96AT6D4UIZd8wni2rZu2wHMsiNPKl73Gd2pV9MpsFj FjzBHLS2Y1gYujdExsl9v6gDuBS3RMwQwZxTb0sRkZpkjA2A2M6UANLOJFBSVPI6rVQa ptq8+xAZNRBJiys+TYSz14o8W7z21FQ2QkBcy7MQogRDrQoUlU6uHs9kqhdOMhCEE7GI RZQTNLykrmPK8TMGhi4yA3CWjItivOobB7WtmrVi8MA2t8w3+7vhwv7oi0dUSsbYwl7R ou6w== X-Gm-Message-State: AJIora8LmVGNYlZJm62/Gy7SHiSulFKqmLDjww4qCobUJjhasNjhQZxN z8A60Y9kujr6a1Q80XrdRJrCIA== X-Google-Smtp-Source: AGRyM1tQwkW+HlUIhq6W6mrhyIk2sljgLbIYjCY1xRcIjccNFw0xruYrMV4U2QVGJ3dnCRA0b3CJGA== X-Received: by 2002:a17:902:ec92:b0:166:3502:ecb1 with SMTP id x18-20020a170902ec9200b001663502ecb1mr2498151plg.62.1655183543347; Mon, 13 Jun 2022 22:12:23 -0700 (PDT) Received: from localhost ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id 207-20020a6215d8000000b005183434ec84sm6594630pfv.145.2022.06.13.22.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:12:23 -0700 (PDT) Date: Tue, 14 Jun 2022 13:12:19 +0800 From: Muchun Song To: zhenwei pi Cc: akpm@linux-foundation.org, naoya.horiguchi@nec.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, linmiaohe@huawei.com Subject: Re: [PATCH v4 1/2] mm/memory-failure: introduce "hwpoisoned-pages" entry Message-ID: References: <20220614043830.99607-1-pizhenwei@bytedance.com> <20220614043830.99607-2-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220614043830.99607-2-pizhenwei@bytedance.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655183546; a=rsa-sha256; cv=none; b=b7SsmYevFvsKN4SXqRJ7vpAGjb+YDgmcsw5wabqJ9qEOcYkDPQQdfrEVQQIGTwknBXazky OEt65rAwTF089x6HHOHv4mDNa8qsLtMplO80BjAkq2/nHOLnQShNkzDTBkkZIospEIiFAr E2H8/LDE1CrYPfhf5PdAQ6m0SDbtivU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655183546; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ufPnLDgaYxht70tLLUiqZA8dThtkFoWrcgzlo7+rnvk=; b=VwBA6rfYFVuiQKOGz25l4AMZ+vE8M0S7/lT5xRqJ/FlfdLwBENUBFAsprA3+hMUE5LO6hf vufrj3P9d5PAMuedKaXcfZcZOeEr0EM7My0qYPclDIQSvpgNwaqRpmN1ENCSZ0mULewE7v 1sK+CHKD2DSdboO0FbfRYrjsbjiifiQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=0AIe2LL5; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=0AIe2LL5; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 97E2B100075 X-Stat-Signature: 53zfwap3fachtixu9cfr31ssih7k6nyd X-HE-Tag: 1655183544-867716 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: On Tue, Jun 14, 2022 at 12:38:29PM +0800, zhenwei pi wrote: > Add a new debug entry to show the number of hwpoisoned pages. And > use module_get/module_put to manager this kernel module, don't allow > to remove this module unless hwpoisoned-pages is zero. > > Signed-off-by: zhenwei pi > --- > Documentation/vm/hwpoison.rst | 4 ++++ > mm/hwpoison-inject.c | 19 ++++++++++++++++++- > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/Documentation/vm/hwpoison.rst b/Documentation/vm/hwpoison.rst > index c742de1769d1..c832a8b192d4 100644 > --- a/Documentation/vm/hwpoison.rst > +++ b/Documentation/vm/hwpoison.rst > @@ -155,6 +155,10 @@ Testing > flag bits are defined in include/linux/kernel-page-flags.h and > documented in Documentation/admin-guide/mm/pagemap.rst > > + hwpoisoned-pages A bit weird to me. IIUC, this means the number of **software** poisoned pages instead of **hardware**. The prefix "hw" may be not suitable. How about "poisoned-pages" (a little simplified), "poisoned-pfns" (keep the name consistent with "corrupt-pfn" and "unpoison-pfn") or "swpoisoned-pages" (sw means software)? > + The number of hwpoisoned pages. The hwpoison kernel module can not be > + removed unless this count is zero. > + > * Architecture specific MCE injector > > x86 has mce-inject, mce-test > diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c > index 5c0cddd81505..9e522ecedeef 100644 > --- a/mm/hwpoison-inject.c > +++ b/mm/hwpoison-inject.c > @@ -10,6 +10,7 @@ > #include "internal.h" > > static struct dentry *hwpoison_dir; > +static atomic_t hwpoisoned_pages; > > static int hwpoison_inject(void *data, u64 val) > { > @@ -49,15 +50,28 @@ static int hwpoison_inject(void *data, u64 val) > inject: > pr_info("Injecting memory failure at pfn %#lx\n", pfn); > err = memory_failure(pfn, 0); > + if (!err) { > + WARN_ON(!try_module_get(THIS_MODULE)); __module_get() is enough since we already hold a refcount at open time. This WARN_ON() will not be triggered unless something unexpected happens. > + atomic_inc(&hwpoisoned_pages); > + } > + > return (err == -EOPNOTSUPP) ? 0 : err; > } > > static int hwpoison_unpoison(void *data, u64 val) > { > + int ret; > + > if (!capable(CAP_SYS_ADMIN)) > return -EPERM; > > - return unpoison_memory(val); > + ret = unpoison_memory(val); > + if (!ret) { > + atomic_dec(&hwpoisoned_pages); > + module_put(THIS_MODULE); > + } > + > + return ret; > } > > DEFINE_DEBUGFS_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n"); > @@ -99,6 +113,9 @@ static int pfn_inject_init(void) > debugfs_create_u64("corrupt-filter-flags-value", 0600, hwpoison_dir, > &hwpoison_filter_flags_value); > > + debugfs_create_atomic_t("hwpoisoned-pages", 0400, hwpoison_dir, > + &hwpoisoned_pages); > + > #ifdef CONFIG_MEMCG > debugfs_create_u64("corrupt-filter-memcg", 0600, hwpoison_dir, > &hwpoison_filter_memcg); > -- > 2.20.1 > >