Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10451811imu; Thu, 6 Dec 2018 01:04:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wg1BXm/dN0WcOoIBRitxEXI2X3Y69hYxI8CgEeTnpA0KjivAVJ1ZEQRfLHinpMbSv38x1b X-Received: by 2002:a17:902:2c03:: with SMTP id m3mr28494578plb.125.1544087064296; Thu, 06 Dec 2018 01:04:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544087064; cv=none; d=google.com; s=arc-20160816; b=LtCqZ5Odr7g/8MF88C/v/bNBYz3oPabzYiEYnWhNblCE/uG+X187mggylXgDsNVN7s ZIkVZax+gm/23TpYH1f68g8KxRgSjOVvKdPG5tqxtLP/0ldq+7EadaZoBB8KzQzIe+9w dXOujPzb6DldY2E2agPcRWnLvH96bnfcv/+UX6BSAX8ANzftf0AbtoGGAWQMKCnQtEVD Oc0MlJLXMVIET2rM0w39Mn1gU8S+I76sfqaaSC4LaPHgF6hk+2dKKjDNLknhsu9KEc6l r6+2SLzIMX3jtXThCN8cQ7PvUDj2CAPW9JygBZLIHEHiFVStdRAMuUYs/3O4R2aviPtl 9iCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject; bh=d5osq9ho1mjcpAgg1Dfp1jqOB1j12fFII/6vq7wke0E=; b=O6HwbBsZCH9La8dDlt9t3mW2sHzvG6TFBn8bDA6EXeHrx+gyITVybJZf7VC7e6ze9a TbGAZxgnBMV4neRICZIMeXNT9wDogRDkWhlU7KDGgumm72u57aWcr2yUiEARgrsLXn90 NLDRWp5WM5M/kGl0u9iONxnZF41jHUNTcCTXawyS5jRCWXXGYkuIrlr/ajGZExhl0iqP uBlNEe04+ofh29+bE+LMBL0znrdKULd6vfUK+ZCeT50b4vdch4iWLJEZXY+YMvndEt+9 GILB643BCSwd+9kj25MwXj6gKoxOTWc0DcZudMDN30REMm5+C7Mp79h16ynGW0Eswpsl clgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34si14458615pgt.455.2018.12.06.01.04.07; Thu, 06 Dec 2018 01:04:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729163AbeLFJCN (ORCPT + 99 others); Thu, 6 Dec 2018 04:02:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57878 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727575AbeLFJCM (ORCPT ); Thu, 6 Dec 2018 04:02:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6F6B307D85F; Thu, 6 Dec 2018 09:02:11 +0000 (UTC) Received: from [10.36.117.102] (ovpn-117-102.ams2.redhat.com [10.36.117.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA636101961E; Thu, 6 Dec 2018 09:02:09 +0000 (UTC) Subject: Re: [RFC PATCH] hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined To: Michal Hocko , Naoya Horiguchi , Oscar Salvador Cc: Andrew Morton , Dan Williams , Pavel Tatashin , linux-mm@kvack.org, LKML , Stable tree References: <20181203100309.14784-1-mhocko@kernel.org> <20181205122918.GL1286@dhcp22.suse.cz> <20181205165716.GS1286@dhcp22.suse.cz> From: David Hildenbrand Openpgp: preference=signencrypt Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwX4EEwECACgFAljj9eoCGwMFCQlmAYAGCwkI BwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEE3eEPcA/4Na5II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-e53e-9cf3-500b-1fddd4466e33@redhat.com> Date: Thu, 6 Dec 2018 10:02:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20181205165716.GS1286@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 06 Dec 2018 09:02:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05.12.18 17:57, Michal Hocko wrote: > On Wed 05-12-18 13:29:18, Michal Hocko wrote: > [...] >> After some more thinking I am not really sure the above reasoning is >> still true with the current upstream kernel. Maybe I just managed to >> confuse myself so please hold off on this patch for now. Testing by >> Oscar has shown this patch is helping but the changelog might need to be >> updated. > > OK, so Oscar has nailed it down and it seems that 4.4 kernel we have > been debugging on behaves slightly different. The underlying problem is > the same though. So I have reworded the changelog and added "just in > case" PageLRU handling. Naoya, maybe you have an argument that would > make this void for current upstream kernels. > > I have dropped all the reviewed tags as the patch has changed slightly. > Thanks a lot to Oscar for his patience and testing he has devoted to > this issue. > > Btw. the way how we drop all the work on the first page that we cannot > isolate is just goofy. Why don't we simply migrate all that we already > have on the list and go on? Something for a followup cleanup though. > --- > From 909521051f41ae46a841b481acaf1ed9c695ae7b Mon Sep 17 00:00:00 2001 > From: Michal Hocko > Date: Mon, 3 Dec 2018 10:27:18 +0100 > Subject: [PATCH] hwpoison, memory_hotplug: allow hwpoisoned pages to be > offlined > > We have received a bug report that an injected MCE about faulty memory > prevents memory offline to succeed on 4.4 base kernel. The underlying > reason was that the HWPoison page has an elevated reference count and > the migration keeps failing. There are two problems with that. First > of all it is dubious to migrate the poisoned page because we know that > accessing that memory is possible to fail. Secondly it doesn't make any > sense to migrate a potentially broken content and preserve the memory > corruption over to a new location. > > Oscar has found out that 4.4 and the current upstream kernels behave > slightly differently with his simply testcase > === > > int main(void) > { > int ret; > int i; > int fd; > char *array = malloc(4096); > char *array_locked = malloc(4096); > > fd = open("/tmp/data", O_RDONLY); > read(fd, array, 4095); > > for (i = 0; i < 4096; i++) > array_locked[i] = 'd'; > > ret = mlock((void *)PAGE_ALIGN((unsigned long)array_locked), sizeof(array_locked)); > if (ret) > perror("mlock"); > > sleep (20); > > ret = madvise((void *)PAGE_ALIGN((unsigned long)array_locked), 4096, MADV_HWPOISON); > if (ret) > perror("madvise"); > > for (i = 0; i < 4096; i++) > array_locked[i] = 'd'; > > return 0; > } > === > > + offline this memory. > > In 4.4 kernels he saw the hwpoisoned page to be returned back to the LRU > list > kernel: [] dump_trace+0x59/0x340 > kernel: [] show_stack_log_lvl+0xea/0x170 > kernel: [] show_stack+0x21/0x40 > kernel: [] dump_stack+0x5c/0x7c > kernel: [] warn_slowpath_common+0x81/0xb0 > kernel: [] __pagevec_lru_add_fn+0x14c/0x160 > kernel: [] pagevec_lru_move_fn+0xad/0x100 > kernel: [] __lru_cache_add+0x6c/0xb0 > kernel: [] add_to_page_cache_lru+0x46/0x70 > kernel: [] extent_readpages+0xc3/0x1a0 [btrfs] > kernel: [] __do_page_cache_readahead+0x177/0x200 > kernel: [] ondemand_readahead+0x168/0x2a0 > kernel: [] generic_file_read_iter+0x41f/0x660 > kernel: [] __vfs_read+0xcd/0x140 > kernel: [] vfs_read+0x7a/0x120 > kernel: [] kernel_read+0x3b/0x50 > kernel: [] do_execveat_common.isra.29+0x490/0x6f0 > kernel: [] do_execve+0x28/0x30 > kernel: [] call_usermodehelper_exec_async+0xfb/0x130 > kernel: [] ret_from_fork+0x55/0x80 > > And that later confuses the hotremove path because an LRU page is > attempted to be migrated and that fails due to an elevated reference > count. It is quite possible that the reuse of the HWPoisoned page is > some kind of fixed race condition but I am not really sure about that. > > With the upstream kernel the failure is slightly different. The page > doesn't seem to have LRU bit set but isolate_movable_page simply fails > and do_migrate_range simply puts all the isolated pages back to LRU and > therefore no progress is made and scan_movable_pages finds same set of > pages over and over again. > > Fix both cases by explicitly checking HWPoisoned pages before we even > try to get a reference on the page, try to unmap it if it is still > mapped. As explained by Naoya > : Hwpoison code never unmapped those for no big reason because > : Ksm pages never dominate memory, so we simply didn't have strong > : motivation to save the pages. > > Also put WARN_ON(PageLRU) in case there is a race and we can hit LRU > HWPoison pages which shouldn't happen but I couldn't convince myself > about that. > > Debugged-by: Oscar Salvador > Cc: stable > Signed-off-by: Michal Hocko > --- > mm/memory_hotplug.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index c6c42a7425e5..cfa1a2736876 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -34,6 +34,7 @@ > #include > #include > #include > +#include > > #include > > @@ -1366,6 +1367,21 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) > pfn = page_to_pfn(compound_head(page)) > + hpage_nr_pages(page) - 1; > > + /* > + * HWPoison pages have elevated reference counts so the migration would > + * fail on them. It also doesn't make any sense to migrate them in the > + * first place. Still try to unmap such a page in case it is still mapped > + * (e.g. current hwpoison implementation doesn't unmap KSM pages but keep > + * the unmap as the catch all safety net). > + */ > + if (PageHWPoison(page)) { > + if (WARN_ON(PageLRU(page))) > + isolate_lru_page(page); > + if (page_mapped(page)) > + try_to_unmap(page, TTU_IGNORE_MLOCK | TTU_IGNORE_ACCESS); > + continue; > + } > + > if (!get_page_unless_zero(page)) > continue; > /* > Complicated stuff. With or without the LRU handling Acked-by: David Hildenbrand -- Thanks, David / dhildenb