Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp900922pxr; Mon, 11 Apr 2022 09:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+ehor9A5quu6AAOXCd1RJYNQrIrbbNz2IGPZnaxE41QlZlQNwg8OFkn6a6OE0Cba99GyR X-Received: by 2002:a63:488:0:b0:39c:c4ec:7db1 with SMTP id 130-20020a630488000000b0039cc4ec7db1mr18705300pge.574.1649696053363; Mon, 11 Apr 2022 09:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649696053; cv=none; d=google.com; s=arc-20160816; b=EFNrdAIWK61s9/hYKqdfRxikn9IVSKej3RDR42wjoej8dzjhLonkM8nPBIL3ip6Xmu 5fa7frG7/tBqrQD/qfdetkLcSUjz2Br/ueLKGaxofQCElvPvCfRdbCCq8bB1pzd1kEL1 6H/eAQzMcpDNTIGo7OkLorSWzsQ1p6Y0yEkTnnXQPXBd/L5ZCFGwlS9oY7R2p0+2otsU XrJBSGNA6vL1pLCorSaeJZicZoBJgRidyfUxJ6C2Txl7QSKYaJ/wTUYESvMk5IBseHvm PGpxdYVkPY0JHM0LjBFOptuUBSbDm6P8seh1qn0axGT7J1C+oXpP7WW2BZrdfsnESXJ7 VreQ== 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 :ironport-hdrordr:ironport-data; bh=sLcPlS1L4QD3BAO/uKuIQCHUyrOyQRuOQZ7BjwP2QvI=; b=PU3C5vpK7Kv3FevR8dbO+SyZGGbqnF2OiJfNFPlUnzFm+gBmQJJaXXEy2TIqKjWy7J upFvBgy0Fqa/VvMvrss3jcTr5YoedKgtmABaViK+ifnlHQmMF/6Y3dLpq0zQwVKBfNNI 64CWvh5ridqBXU5mVZB4eS3dDk+V4bJkjr9AibTDDoieFHg2tiwpKXfY93YQx2TQ6Qry dMXRoBJGeUJYrgRlc1dHKjiZEp+FXetIGGcb5OYlLe/c60XckQMku3MIQLvGwf1be5RO +i5ueOt5kJUEd2qJYJymzA/xPhqIdX28FBHvN8fYSv8JKIT+gVPahHK3WZDMY1ghk7Sp cO6w== ARC-Authentication-Results: i=1; mx.google.com; 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=fujitsu.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w139-20020a627b91000000b004fa7e2947fdsi8646835pfc.147.2022.04.11.09.53.57; Mon, 11 Apr 2022 09:54:13 -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; 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=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235180AbiDJQLY (ORCPT + 99 others); Sun, 10 Apr 2022 12:11:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbiDJQLV (ORCPT ); Sun, 10 Apr 2022 12:11:21 -0400 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E7C76470; Sun, 10 Apr 2022 09:09:08 -0700 (PDT) IronPort-Data: =?us-ascii?q?A9a23=3ANRJWMap7LJOyu1k1cgxZW9IXCp9eBmJnZBIvgKr?= =?us-ascii?q?LsJaIsI5as4F+vjFKWjiOPP6DM2ujfdhyPI3j9E1VsMeDnIBlTQFs+Xs1QiMRo?= =?us-ascii?q?6IpJ/zDcB6oYHn6wu4v7a5fx5xHLIGGdajYd1eEzvuWGuWn/SkUOZ2gHOKmUra?= =?us-ascii?q?eYnkpHGeIdQ964f5ds79g6mJXqYjha++9kYuaT/z3YDdJ6RYtWo4nw/7rRCdUg?= =?us-ascii?q?RjHkGhwUmrSyhx8lAS2e3E9VPrzLEwqRpfyatE88uWSH44vwFwll1418SvBCvv?= =?us-ascii?q?9+lr6WkYMBLDPPwmSkWcQUK+n6vRAjnVqlP9la7xHMgEK49mKt4kZJNFlr4G5T?= =?us-ascii?q?xw4eKPKg/g1XQRaEj1lIOtN/7qvzX2X6JbIkxCdIyK9qxlpJARsVWECwc57CH9?= =?us-ascii?q?P+dQWMjcIaQqJhv7wy7W+IsFsjcQLLc/lJooTt3hsizbDAp4OTZnFBaeM+t5c2?= =?us-ascii?q?DY5g9tmHPDCas5fYj1qBDzMYQJIPFg/C58kmuqswH7lfFVwrFOTuLpy5m37zxJ?= =?us-ascii?q?427urN8DaEvSMW8lUm0OwomPd43+/BhAcKczZxTebmlqsje/nmTjnHo4ffJW6/?= =?us-ascii?q?/hnxlaT20QUEhQdUVb9qv684ma6WtRCOwka4SYjs6U23FKkQ8O7XBCipnOA+Bk?= =?us-ascii?q?GVLJ4F+w89RHIyafO5QudLnYLQyQHa9E8ssIyAzsw2Tehm9LvGCwqoLOOYWyS+?= =?us-ascii?q?63Srj6oPyURa2gYakc5oaEtizX4iNhryEuREZA4S+jo5uAZ0ArYm1iixBXSTZ1?= =?us-ascii?q?K5SLT65iGwA=3D=3D?= IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AxbmQbaCjPgHmaJzlHelI55DYdb4zR+YMi2TC?= =?us-ascii?q?1yhKJyC9Ffbo8fxG/c5rrCMc5wxwZJhNo7y90ey7MBbhHP1OkO4s1NWZLWrbUQ?= =?us-ascii?q?KTRekIh+bfKn/baknDH4VmtJuIHZIQNDSJNykZsS/l2njEL/8QhMmA7LuzhfrT?= =?us-ascii?q?i1NkTQRRYalm6AtjYzzraXFedU1XA4YjDpqA6o5irzqkQ34eacO2HT0rRO7Gzu?= =?us-ascii?q?e77q7OUFoXAQI98gmSgXeN4L7+KRKR2RATSHdu7N4ZgBD4rzA=3D?= X-IronPort-AV: E=Sophos;i="5.88,333,1635177600"; d="scan'208";a="123453819" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Apr 2022 00:09:08 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 3F9104D17165; Mon, 11 Apr 2022 00:09:07 +0800 (CST) Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 11 Apr 2022 00:09:10 +0800 Received: from irides.mr.mr (10.167.225.141) by G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Mon, 11 Apr 2022 00:09:05 +0800 From: Shiyang Ruan To: , , , , CC: , , , , , Christoph Hellwig Subject: [PATCH v12 2/7] mm: factor helpers for memory_failure_dev_pagemap Date: Mon, 11 Apr 2022 00:08:59 +0800 Message-ID: <20220410160904.3758789-3-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410160904.3758789-1-ruansy.fnst@fujitsu.com> References: <20220410160904.3758789-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 3F9104D17165.A02EF X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 memory_failure_dev_pagemap code is a bit complex before introduce RMAP feature for fsdax. So it is needed to factor some helper functions to simplify these code. Signed-off-by: Shiyang Ruan Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Dan Williams --- mm/memory-failure.c | 157 ++++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 70 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index ef402b490663..f1cdd39f01f7 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1499,6 +1499,90 @@ static int try_to_split_thp_page(struct page *page, const char *msg) return 0; } +static void unmap_and_kill(struct list_head *to_kill, unsigned long pfn, + struct address_space *mapping, pgoff_t index, int flags) +{ + struct to_kill *tk; + unsigned long size = 0; + + list_for_each_entry(tk, to_kill, nd) + if (tk->size_shift) + size = max(size, 1UL << tk->size_shift); + + if (size) { + /* + * Unmap the largest mapping to avoid breaking up device-dax + * mappings which are constant size. The actual size of the + * mapping being torn down is communicated in siginfo, see + * kill_proc() + */ + loff_t start = (index << PAGE_SHIFT) & ~(size - 1); + + unmap_mapping_range(mapping, start, size, 0); + } + + kill_procs(to_kill, flags & MF_MUST_KILL, false, pfn, flags); +} + +static int mf_generic_kill_procs(unsigned long long pfn, int flags, + struct dev_pagemap *pgmap) +{ + struct page *page = pfn_to_page(pfn); + LIST_HEAD(to_kill); + dax_entry_t cookie; + int rc = 0; + + /* + * Pages instantiated by device-dax (not filesystem-dax) + * may be compound pages. + */ + page = compound_head(page); + + /* + * Prevent the inode from being freed while we are interrogating + * the address_space, typically this would be handled by + * lock_page(), but dax pages do not use the page lock. This + * also prevents changes to the mapping of this pfn until + * poison signaling is complete. + */ + cookie = dax_lock_page(page); + if (!cookie) + return -EBUSY; + + if (hwpoison_filter(page)) { + rc = -EOPNOTSUPP; + goto unlock; + } + + if (pgmap->type == MEMORY_DEVICE_PRIVATE) { + /* + * TODO: Handle HMM pages which may need coordination + * with device-side memory. + */ + return -EBUSY; + } + + /* + * Use this flag as an indication that the dax page has been + * remapped UC to prevent speculative consumption of poison. + */ + SetPageHWPoison(page); + + /* + * Unlike System-RAM there is no possibility to swap in a + * different physical page at a given virtual address, so all + * userspace consumption of ZONE_DEVICE memory necessitates + * SIGBUS (i.e. MF_MUST_KILL) + */ + flags |= MF_ACTION_REQUIRED | MF_MUST_KILL; + collect_procs(page, &to_kill, true); + + unmap_and_kill(&to_kill, pfn, page->mapping, page->index, flags); +unlock: + dax_unlock_page(page, cookie); + return 0; +} + /* * Called from hugetlb code with hugetlb_lock held. * If a hugepage is successfully grabbed (so it's determined to handle @@ -1663,12 +1747,8 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, struct dev_pagemap *pgmap) { struct page *page = pfn_to_page(pfn); - unsigned long size = 0; - struct to_kill *tk; LIST_HEAD(tokill); - int rc = -EBUSY; - loff_t start; - dax_entry_t cookie; + int rc = -ENXIO; if (flags & MF_COUNT_INCREASED) /* @@ -1677,73 +1757,10 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, put_page(page); /* device metadata space is not recoverable */ - if (!pgmap_pfn_valid(pgmap, pfn)) { - rc = -ENXIO; - goto out; - } - - /* - * Pages instantiated by device-dax (not filesystem-dax) - * may be compound pages. - */ - page = compound_head(page); - - /* - * Prevent the inode from being freed while we are interrogating - * the address_space, typically this would be handled by - * lock_page(), but dax pages do not use the page lock. This - * also prevents changes to the mapping of this pfn until - * poison signaling is complete. - */ - cookie = dax_lock_page(page); - if (!cookie) + if (!pgmap_pfn_valid(pgmap, pfn)) goto out; - if (hwpoison_filter(page)) { - rc = -EOPNOTSUPP; - goto unlock; - } - - if (pgmap->type == MEMORY_DEVICE_PRIVATE) { - /* - * TODO: Handle HMM pages which may need coordination - * with device-side memory. - */ - goto unlock; - } - - /* - * Use this flag as an indication that the dax page has been - * remapped UC to prevent speculative consumption of poison. - */ - SetPageHWPoison(page); - - /* - * Unlike System-RAM there is no possibility to swap in a - * different physical page at a given virtual address, so all - * userspace consumption of ZONE_DEVICE memory necessitates - * SIGBUS (i.e. MF_MUST_KILL) - */ - flags |= MF_ACTION_REQUIRED | MF_MUST_KILL; - collect_procs(page, &tokill, true); - - list_for_each_entry(tk, &tokill, nd) - if (tk->size_shift) - size = max(size, 1UL << tk->size_shift); - if (size) { - /* - * Unmap the largest mapping to avoid breaking up - * device-dax mappings which are constant size. The - * actual size of the mapping being torn down is - * communicated in siginfo, see kill_proc() - */ - start = (page->index << PAGE_SHIFT) & ~(size - 1); - unmap_mapping_range(page->mapping, start, size, 0); - } - kill_procs(&tokill, true, false, pfn, flags); - rc = 0; -unlock: - dax_unlock_page(page, cookie); + rc = mf_generic_kill_procs(pfn, flags, pgmap); out: /* drop pgmap ref acquired in caller */ put_dev_pagemap(pgmap); -- 2.35.1