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 74C1BC433F5 for ; Fri, 20 May 2022 07:11:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D80E06B0072; Fri, 20 May 2022 03:11:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D30036B0073; Fri, 20 May 2022 03:11:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF8EB8D0001; Fri, 20 May 2022 03:11:08 -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 B34BA6B0072 for ; Fri, 20 May 2022 03:11:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 83CAD21757 for ; Fri, 20 May 2022 07:11:08 +0000 (UTC) X-FDA: 79485249816.15.44E8E2A Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf17.hostedemail.com (Postfix) with ESMTP id 53A53400DC for ; Fri, 20 May 2022 07:10:42 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id h186so7022844pgc.3 for ; Fri, 20 May 2022 00:11:07 -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=0KUgn4q69DG5zIlC1bOLKat5AESimquHJFEcH7Mymww=; b=RnsS8rlcaqrcj3RhK36pn8NouGunnnwM0GWKWK3X1PoabzQ9x/1iAvkQLVXobtqqiM ckZSnIumZQpT0Pn4mHGXaQGJs831i9051mt2zMMjIB2XhqpiqHY8bdQK0fBaG0UzRLoL naPm0yF6A6L94p3Q2Soc1gjNiohCOmp8PNK2xsJ1qIt96FT3yDkxJr3YdN+/AofbvEvv viiJ12IC5jdwnOJpCr2ZYAjcUz0d5cNGgjyvZNDDRv2FFmf08kbSdTBBLUn+EpnaRT41 YrATyb3OhG5XZvVh8xQe3R/6NeJ9DaM/oG6826oJKua/ka22lR8KaQ90kEd3mlS4ekaU 2VZg== 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=0KUgn4q69DG5zIlC1bOLKat5AESimquHJFEcH7Mymww=; b=kDL8GO41JyN1r7+avpxjcjQ8mHNRYSHjEUNHf85a3vLVxS00guaogqCNh69UWcIDAN wE2zxhMhyRaxEkyk6xiNeANpUiKhcsAOh/theptr2Do1R/3mVSXjn89oOa5GHhR/Yvst EkSoz0gb16a6fXbWFQilClBQK6LmM7ynPpIuUGV5+OY+kPBwR+1uH4D8K7Cxx/k6ZRab 8zAymnXBml8GnXJj1qsLagJe3VfDFVD70Bf2WxPKsO+kuXoYnAikqDYBftp0cdcDvvH5 utwxIY4ZpWR7IiSjF1qI1swizgXciYdyKBsJRMQRZxggJ/3utGzR7bJkATcN4LstX1TP VE8w== X-Gm-Message-State: AOAM532S2PPOwTChq5UhU/tZ8Oaa9fC2tx7jOBil0ysk0rDCJrkAFRnG vn7ZMj2r9A9PqYZDX4j167Ai3w== X-Google-Smtp-Source: ABdhPJy2CdwQr543isCK/keOAsVtpqVPpZ286CuyvQTXDJe5qsQURjhpmTDYka3gLq4fZ2UvZmCJZg== X-Received: by 2002:a63:5a09:0:b0:3c2:5dfa:285c with SMTP id o9-20020a635a09000000b003c25dfa285cmr7271718pgb.381.1653030667026; Fri, 20 May 2022 00:11:07 -0700 (PDT) Received: from always-x1.www.tendawifi.com ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id t18-20020a170902d21200b00161b3d5e3e4sm4965168ply.304.2022.05.20.00.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 00:11:05 -0700 (PDT) From: zhenwei pi To: akpm@linux-foundation.org, naoya.horiguchi@nec.com, mst@redhat.com, david@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jasowang@redhat.com, virtualization@lists.linux-foundation.org, pbonzini@redhat.com, peterx@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH 1/3] memory-failure: Introduce memory failure notifier Date: Fri, 20 May 2022 15:06:46 +0800 Message-Id: <20220520070648.1794132-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520070648.1794132-1-pizhenwei@bytedance.com> References: <20220520070648.1794132-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RnsS8rlc; spf=pass (imf17.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 53A53400DC X-Stat-Signature: 3pjakihnuxms79uz9jfun5znicim7prw X-HE-Tag: 1653030642-219073 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: Introduce memory failure notifier, once hardware memory failure occurs, after the kernel handles the corrupted page successfully, someone who registered this chain gets noticed of the corrupted PFN. Signed-off-by: zhenwei pi --- include/linux/mm.h | 2 ++ mm/memory-failure.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9f44254af8ce..665873c2788c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3197,6 +3197,8 @@ extern int sysctl_memory_failure_recovery; extern void shake_page(struct page *p); extern atomic_long_t num_poisoned_pages __read_mostly; extern int soft_offline_page(unsigned long pfn, int flags); +extern int register_memory_failure_notifier(struct notifier_block *nb); +extern int unregister_memory_failure_notifier(struct notifier_block *nb); #ifdef CONFIG_MEMORY_FAILURE extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags); #else diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 2d590cba412c..95c218bb0a37 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -68,6 +68,35 @@ int sysctl_memory_failure_recovery __read_mostly = 1; atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); +static BLOCKING_NOTIFIER_HEAD(mf_notifier_list); + +/** + * register_memory_failure_notifier - Register function to be called if a + * corrupted page gets handled successfully + * @nb: Info about notifier function to be called + * + * Currently always returns zero, as blocking_notifier_chain_register() + * always returns zero. + */ +int register_memory_failure_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&mf_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(register_memory_failure_notifier); + +/** + * unregister_memory_failure_notifier - Unregister previously registered + * memory failure notifier + * @nb: Hook to be unregistered + * + * Returns zero on success, or %-ENOENT on failure. + */ +int unregister_memory_failure_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&mf_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_memory_failure_notifier); + static bool __page_handle_poison(struct page *page) { int ret; @@ -1136,6 +1165,10 @@ static void action_result(unsigned long pfn, enum mf_action_page_type type, num_poisoned_pages_inc(); pr_err("Memory failure: %#lx: recovery action for %s: %s\n", pfn, action_page_types[type], action_name[result]); + + /* notify the chain if we handle successfully only */ + if (result == MF_RECOVERED) + blocking_notifier_call_chain(&mf_notifier_list, pfn, NULL); } static int page_action(struct page_state *ps, struct page *p, -- 2.20.1