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 289A3C43334 for ; Tue, 14 Jun 2022 04:36:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93B1F8D020A; Tue, 14 Jun 2022 00:36:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C3D58D0207; Tue, 14 Jun 2022 00:36:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7645A8D020A; Tue, 14 Jun 2022 00:36:16 -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 66DBC8D0207 for ; Tue, 14 Jun 2022 00:36:16 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 444E860D7F for ; Tue, 14 Jun 2022 04:36:16 +0000 (UTC) X-FDA: 79575579552.04.FE125EE Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf08.hostedemail.com (Postfix) with ESMTP id E942916008F for ; Tue, 14 Jun 2022 04:36:15 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id z14so2701520pjb.4 for ; Mon, 13 Jun 2022 21:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ajU2JKBBSSrp0S5lhDPG058tqKeZBFJb0LEOJsnhgqE=; b=vJQo2n6BSwWuglebOG3yrGi72g3v8zO9xmkNzssq+aV4KOs8zg+NgNezh2HCdamdSE 0CihdbGc9IufBkOSqbntOh/567FMMZB1TyT3e2MR9eTQS7VXIx32NAWb5cbo7uZk20/f pMvlYBxWICZ8ym1c/YAXjzv8VaNeBID+yrIeH17PQk1TzrPic81geaFlnGzL/EWjEF6t LgKXZx+P8PkXGsM+t8Ru3/wGr3ZaPgWV/hzapIK4Iw1X+S23fdiWeBAwf46xW7IXctxf kWqZFFWZL9+iE+TvcP/ULgxCryIG7h9UehP5aQI2VJarK8IN6LhhR2nFKa+jqAwFcDLh fY4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ajU2JKBBSSrp0S5lhDPG058tqKeZBFJb0LEOJsnhgqE=; b=2HoSoJliY3S2bdJuDZlpwfFwIeuPYME9f4C6JS9V/FCTYXJsPmqpqyDvyFa4PjLGKI YUIBzuEBPfkqm2Ioy+NIXz0i05/KfIw+BPpQSwVFmyLnSCJ7blTrSWrvW1bFNjwZ5iBF OVgPvgUNKIwpqaIs5eUq1F6Fs2Yyxy3xnDkPBtTEhcE2m+NJO//vszoX1VeYvADeVDz9 +iEOuoUXESep7FuQdnkvIOjVofEr6UC8calhyGXVGXYHs4HtlplkSgEa8pSUQ/dg9q+N KuoeO4XWZ3CHI6ltfSAJJG5sN4ItuM3NCzD8hrUU08Hee2nY2/bV2UtPB2ufRHR67eHq 2CiQ== X-Gm-Message-State: AJIora9ypW5GWnhY1HlvCvWvtX4FZ7mOMvXV4qEQyce6qtU/7nYAKM2C gYzouFY19eE+wsuH6LeEOF/6HQ== X-Google-Smtp-Source: AGRyM1vFA1HcMbNLf45HPEWAlxQMUPIqHnxVbUm2xPe6/RAnOg1R4/b7PXltR54zt+IuHgq5nmU2bQ== X-Received: by 2002:a17:902:cf0c:b0:15b:63a4:9f47 with SMTP id i12-20020a170902cf0c00b0015b63a49f47mr2528770plg.1.1655181374892; Mon, 13 Jun 2022 21:36:14 -0700 (PDT) Received: from always-T480.www.tendawifi.com ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id t16-20020a63b250000000b00401a7b4f137sm6469120pgo.41.2022.06.13.21.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 21:36:14 -0700 (PDT) From: zhenwei pi To: akpm@linux-foundation.org, naoya.horiguchi@nec.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, linmiaohe@huawei.com, zhenwei pi Subject: [PATCH v4 1/2] mm/memory-failure: introduce "hwpoisoned-pages" entry Date: Tue, 14 Jun 2022 12:38:29 +0800 Message-Id: <20220614043830.99607-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614043830.99607-1-pizhenwei@bytedance.com> References: <20220614043830.99607-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655181376; 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=ajU2JKBBSSrp0S5lhDPG058tqKeZBFJb0LEOJsnhgqE=; b=5v5/DsxOZN7LrTty9HeXjJmZ7nFqjh+a4hUSVWBAdpwnhST8+WXgEeKWd9TdcZhqeHwqAf qyIOEsOqnV/QqJPDecAUcx0GPT4Gg2IpPbspUNR2taCtbludjjVQpTHYQjtuWjH+LSIC47 ao3p8xszQh/y9kZKE71ioQXOIdi8+Fc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=vJQo2n6B; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655181376; a=rsa-sha256; cv=none; b=og8v7l8bxyDlznUnEjpiwCLW+YmKLvcHmuIsq2giRQfecnMqk7uS5NxpBg3v7rFO9jKIt3 qkG8g74p3k3wkv+qYyjKE1uKdfxv5PD2DL2eocsuZ4WmdA3jiUsVFu4rgoALWSIs7Xw40t hrvNA+EDtkJXA4WblMtmo6Oj8s3SUh4= X-Stat-Signature: 4nzr5ce9qawidjkijxde9mydnatcfmky X-Rspamd-Queue-Id: E942916008F X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=vJQo2n6B; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com X-HE-Tag: 1655181375-10298 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: 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 + 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)); + 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