Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2089659iob; Fri, 20 May 2022 01:30:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfZzaPUpeFrUr914QhveLmb3SA0oiqjQPymGpnFEx1H4rmUIwWbFUsrXbPKB7cC1kmN4z3 X-Received: by 2002:a17:90a:1f4f:b0:1d8:23d9:de1e with SMTP id y15-20020a17090a1f4f00b001d823d9de1emr9687158pjy.42.1653035446694; Fri, 20 May 2022 01:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653035446; cv=none; d=google.com; s=arc-20160816; b=LOPGl8tJcFhEH9FDDmTJfOcPiJTqIllvWxQc2QhMqwYHG2fmi44unk8HK3OUpmGaQb Ixfo9Qa5m/cN678tjmJvvLt3v0lA0Ncdo28pQ2gUACfEfOhGHc68wet82R9MBmn14R4N 8+JVkV6aFMZdI4mLkhlQfdi8cPM4QLZK0Z/Td32ihDJi60bdNcaG75cegDAR8KGsI1Qu WpSBmqTvhkTfcHiPWRwvj9A3Z2a879whc0foGFRQcGenB1qTrfJ1aPMHYpcOJKXTty7b b/LmkHpl4OkVlMCppHediu0jrVzIdjy+mtzJMFpcQACcFS3DzAXYqZYR1RjCGhj0PDmW 0olQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0KUgn4q69DG5zIlC1bOLKat5AESimquHJFEcH7Mymww=; b=E4CqKOLtD88LFtNIf/Nt9no51zUbWX/UZ8qh0NKGkX1Ab6iGZ8e4h/48Aj3dYgEm9B 5VXHcE6E5HqgV51db9n5BkazXCzfU80I3tS1BL4gMrYnCPrF7Su1g2QDnkjudHjtpuJB VG8Uz57XKRtE83JPi8/oZHkFR3hXwDljqGy/lYx7ZbzWIDPqY57PPBfNnGoFbhtbitw1 1V51/odIta4T1QPbg9mrhss+7KO55vERxnOwqkE6vc+fGN3ZR6e8ane8GuT3tGa/zwz3 NSXTZzr7f58QGJ9xXpsZm59v6B6NnQTozaCO+uYe9qpmrIJTCf5kkx0mtcp15d4aCIoT sDnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RnsS8rlc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 200-20020a6301d1000000b003f84815e5d8si1016933pgb.634.2022.05.20.01.30.34; Fri, 20 May 2022 01:30:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RnsS8rlc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346446AbiETHLx (ORCPT + 99 others); Fri, 20 May 2022 03:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346318AbiETHLK (ORCPT ); Fri, 20 May 2022 03:11:10 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 363D512616 for ; Fri, 20 May 2022 00:11:07 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id v10so7003023pgl.11 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=0OfK5DNbTqN3Yr40VO6F2dLE9dLyMVvdBrEXDJI96LYjgaBt/ixTcR/m95dcFP00x/ 4wB8OaV2T1DyVmajnIcfzRBBsY3knZss4vLdJxE6wrShMGb6EYDUqDISFVnc3elsvhvH 2l2/uSkDIQq4u7ee8wjvUeFuFN+p/GLDld0Kh5gDnZM3CYb/B9gVHTgWv3H2qjdngIdj egQ3nVzLenuadJLrmHsUbcMvg0kAVnVtk6hj9vIoLcACEMh1gSqECckLYrp8L4lDBBGA ZpJCe0MKSyP43Jd+NnQzX6R/auLjHenX8NdrqKpnhmoyAhVw/iB7hBoPcUY0aJ+2QArV G2Ng== X-Gm-Message-State: AOAM533SVqfzaRdCXNBpKMS8PfG3PoPpgn7mntKhSvirgX2hAQJ+erV/ eJOefKfONd0Z6jrB2YQgIQAYkqv/vBprFQ== 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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