Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4389920ioa; Wed, 27 Apr 2022 02:46:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOgDlD7yIQl+YoIhAKM0TpdTma+fv37KE/4dSaiXswN9AyQcDoc5Wc8nl2GiuFyXk95grz X-Received: by 2002:a63:f14f:0:b0:39d:9761:c0c7 with SMTP id o15-20020a63f14f000000b0039d9761c0c7mr23165725pgk.529.1651052811060; Wed, 27 Apr 2022 02:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651052811; cv=none; d=google.com; s=arc-20160816; b=vNQrVJm3VzFHL3tH4cWNdM6GFbw8DpqVNuOQvzuUoD3HWfgS+tbpZDf7vFbKkFZuHE F8Vw1Ux97HePikvfpEVYEtVZh1pw7Byip151b+rAQ41cSMWJmLLflAxIIh0Uu88vvV3c EuSBn2KBA3g+w2lkSCG+PXEQF92oPMV5i4p47MoePpMgnrGVdV6kVUfDs7ndw6OmlMwz teWA5SmRhNvu9ODwnaixMhpjMwjE9bDoGlQBG7VE5ltCq/hbnHAAVjAprPq4O7JSE5VU HJo0y8FaH0KWPBGbtvpyklzExVgDRbXPbpVZGyFBqpcshd3AqxR1Ag1RIN95RRoZePDv fp8Q== 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=4aX7odo5pcxf80dhjL+1ki2q7oMjNnbh5/VzkH5pVqg=; b=N2R15MlKzHyLvxRKEX8lIAJKY9hQq8bUtUcf51HYxLIfF/mP5WYumMWMNLTbJqB7AP mktcofPqxgGXNWspey9zl3ZEciENxizQNPEtAQEW9W86w+pqpIY5WcIanSFBmElQyrgM 4HupfCx7IMzwORIRECEQPSGGRbze2Qx0VgQzdbdwlQDma41S3K4mBSecsn11zKROvlpe JH7b8Z8QfmSKag7Ef/J0ywh0vN8P2iCInJd+ABgW3UKm4QECCfwxAU0lmzfMQcSsJEpG bZNtYpAkytWSCbTfAI+Opk6lTh3uwC5g7HMByNZFsVkgMy/6UOsVEg2HsulvsNtNlCGx QQLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=EKimL9To; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g124-20020a636b82000000b0039a14e00b48si980929pgc.567.2022.04.27.02.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 02:46:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=EKimL9To; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 85DDF1569C3; Wed, 27 Apr 2022 02:20:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357683AbiD0EcQ (ORCPT + 99 others); Wed, 27 Apr 2022 00:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357674AbiD0EcN (ORCPT ); Wed, 27 Apr 2022 00:32:13 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C31C94BB95 for ; Tue, 26 Apr 2022 21:29:02 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1651033741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4aX7odo5pcxf80dhjL+1ki2q7oMjNnbh5/VzkH5pVqg=; b=EKimL9Toxeqt4HnHJHW5pRSliyYwJNFr9WPy84AXTdu3zPV6CCK1gzxtzJ+LCRxxYt2BYh gBkQNKGYCvwoIb+XERgEhAUCTZaC2S9/q/TpjM5aTQQhpyvlef1g3TGgjrTU99sAcs+N71 F52kfL5TtQhvSQrQwaNLhxnNHymIzlA= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , Miaohe Lin , David Hildenbrand , Mike Kravetz , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 2/4] mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage Date: Wed, 27 Apr 2022 13:28:39 +0900 Message-Id: <20220427042841.678351-3-naoya.horiguchi@linux.dev> In-Reply-To: <20220427042841.678351-1-naoya.horiguchi@linux.dev> References: <20220427042841.678351-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no 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 From: Naoya Horiguchi HWPoisoned page is not supposed to prevent memory hotremove, but currently this does not properly work for hwpoisoned hugepages and the kernel tries to migrate them, which could cause consuming corrupted data. Move dissolve_free_huge_pages() before scan_movable_pages(). This is because the result of the movable check depends on the result of the dissolve. Now delayed dissolve is available, so hwpoisoned hugepages can be turned into 4kB hwpoison page which memory hotplug can handle. And clear HPageMigratable pseudo flag for hwpoisoned hugepages. This is also important because dissolve_free_huge_page() can fail. So it's still necessary to prevent do_migrate_pages() from trying to migrate hwpoison hugepages. Reported-by: Miaohe Lin Signed-off-by: Naoya Horiguchi --- mm/hugetlb.c | 11 +++++++++++ mm/memory-failure.c | 2 ++ mm/memory_hotplug.c | 23 +++++++++++------------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6867ea8345d1..95b1db852ca9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2159,6 +2159,17 @@ int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn) for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { page = pfn_to_page(pfn); + + if (PageHuge(page) && PageHWPoison(page)) { + /* + * Release the last refcount from hwpoison to turn into + * a free hugepage. + */ + if (page_count(page) == 1) + put_page(page); + page = hugetlb_page_hwpoison(page); + } + rc = dissolve_free_huge_page(page); if (rc) break; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 73948a00ad4a..4a2e22bf0983 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1607,6 +1607,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb return res == MF_RECOVERED ? 0 : -EBUSY; } + ClearHPageMigratable(head); + page_flags = head->flags; /* diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 416b38ca8def..4bc0590f4334 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1864,6 +1864,17 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, cond_resched(); + /* + * Dissolve free hugepages in the memory block before doing + * offlining actually in order to make hugetlbfs's object + * counting consistent. + */ + ret = dissolve_free_huge_pages(start_pfn, end_pfn); + if (ret) { + reason = "failure to dissolve huge pages"; + goto failed_removal_isolated; + } + ret = scan_movable_pages(pfn, end_pfn, &pfn); if (!ret) { /* @@ -1879,19 +1890,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, goto failed_removal_isolated; } - /* - * Dissolve free hugepages in the memory block before doing - * offlining actually in order to make hugetlbfs's object - * counting consistent. - */ - ret = dissolve_free_huge_pages(start_pfn, end_pfn); - if (ret) { - reason = "failure to dissolve huge pages"; - goto failed_removal_isolated; - } - ret = test_pages_isolated(start_pfn, end_pfn, MEMORY_OFFLINE); - } while (ret); /* Mark all sections offline and remove free pages from the buddy. */ -- 2.25.1