Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6749051imu; Mon, 3 Dec 2018 02:04:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vev5BrQ3UGpg1/BGe7r4odD7mFbXdfj4CFJf0Tmpu+9F0Ykat+YZ7VK5A1gedoH455muRE X-Received: by 2002:a17:902:96a:: with SMTP id 97mr14912342plm.45.1543831455443; Mon, 03 Dec 2018 02:04:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543831455; cv=none; d=google.com; s=arc-20160816; b=kBwkZbsJ8oM8zt22tZ1nNv9HY6NfKSJsmaqaj4s2wMIrdibRAydmIVaioRcyUZ1954 ldJYf4XjEINPZVpm3dvqdBaQG5VFctRJMpXg1f+UvOIXcjm4AmXRCcPaI8XrTv2jBMPJ Y7qfs1QP9Z83yHoNbIPJ4xWjeHSElVhkzwLfmK8Wq1n8sFxJ0Q32TUy58bZgZbE/6Kio j4AvIYm5Jd0I4tuUP8pF2Je4k8YNBjMVmQJEZ1HDo8sF3nMCIE+oboa61qRSu5xgDeI3 uEZXI8GcMrueiMI0Ko7g+GyPZNZ48D2ildubMY759lkINmJltjc4CatnthF8BrQNtlQ1 rksQ== 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:mime-version :message-id:date:subject:cc:to:from; bh=jPdQ2xohPGQO5/youIzdD6XhrzLSdiPyktb/A7gR3XQ=; b=yu0HFL4YBD4zcdNClOf1U0eEZrYthJclgFxNnUz2jKbtaSN4nJvGCBKSMne55jmdee vWxDy93bXgPPQMqzdMzGpIbm7wyAkT9JtWbleJRo+/R9Vfb9fdPiEymxb2mW1OZPxffl vpWF7F3W5cNQ4Ts4QH+5FmushFf/dv9QGChd5/3N77EQzJO5AWEESiJRF9wm+uFXxkJg t5nGsLUsfPn643YZtnDz8R8oXxv7zyiILMeVORb7gMuHJlWq1Pl/bmR0SlKLcZNMN/kZ 5LpalG/VzJUyGkZQPtAQ59SO0ExPlFg9bSxov1LX91EOcAE0i7QYmRORCgnCR4EyEBK3 CplA== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si12483790pgh.560.2018.12.03.02.03.59; Mon, 03 Dec 2018 02:04:15 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726117AbeLCKDm (ORCPT + 99 others); Mon, 3 Dec 2018 05:03:42 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:33691 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbeLCKDm (ORCPT ); Mon, 3 Dec 2018 05:03:42 -0500 Received: by mail-ed1-f65.google.com with SMTP id p6so1911685eds.0; Mon, 03 Dec 2018 02:03:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jPdQ2xohPGQO5/youIzdD6XhrzLSdiPyktb/A7gR3XQ=; b=FD2m9KSZo+Xaqpa4MotfpPMcdfbtbMX/yvJphPYOm8iJTSHggeEeRYFPru0qKClOqF 538HCrdL2sO7Q94jDD1l/pY4h+fjcu+iaKMf+NSBoHNcc/EZRMr3mMnkpTHrTUCPGEsJ /S+kxjODTx2y4RA3ahjoUf6cj9Qup4g0Y5rWUmX7WaMOgSRWPUqRz+fRFPAIsjQ5M+qG ly5k0roJuw6gt3OUsk3B9YLJHZV/Jg8cE1cum922J6PkIyJ0cCYw5SvS7EZOcjmy/pQM dv4P+AjReLRq9+hoeD2KbFV1kJSAOYlG2Dc/2jH7FQ7MeS8xutSBcDQIQP/V3MIO3uqQ zz0A== X-Gm-Message-State: AA+aEWYA1/W99F7PsAOxVt1vl7asYmU8Y4EsNvduucQijRcyHzOHDRqv 3V6PLZktkg7aFwUlfySLRDA= X-Received: by 2002:a17:906:279a:: with SMTP id j26-v6mr12480469ejc.112.1543831400455; Mon, 03 Dec 2018 02:03:20 -0800 (PST) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id w13sm3719321edl.54.2018.12.03.02.03.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 02:03:19 -0800 (PST) From: Michal Hocko To: Naoya Horiguchi , Oscar Salvador Cc: Andrew Morton , Dan Williams , Pavel Tatashin , , LKML , Michal Hocko , Stable tree Subject: [RFC PATCH] hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined Date: Mon, 3 Dec 2018 11:03:09 +0100 Message-Id: <20181203100309.14784-1-mhocko@kernel.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Hocko We have received a bug report that an injected MCE about faulty memory prevents memory offline to succeed. The underlying reason is 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 it is the elevated reference count from memory_failure that is confusing the offlining path. HWPoisoned pages are isolated from the LRU list but __offline_pages might still try to migrate them if there is any preceding migrateable pages in the pfn range. Such a migration would fail due to the reference count but the migration code would put it back on the LRU list. This is quite wrong in itself but it would also make scan_movable_pages stumble over it again without any way out. This means that the hotremove with hwpoisoned pages has never really worked (without a luck). HWPoisoning really needs a larger surgery but an immediate and backportable fix is to skip over these pages during offlining. Even if they are still mapped for some reason then try_to_unmap should turn those mappings into hwpoison ptes and cause SIGBUS on access. Nobody should be really touching the content of the page so it should be safe to ignore them even when there is a pending reference count. Debugged-by: Oscar Salvador Cc: stable Signed-off-by: Michal Hocko --- Hi, I am sending this as an RFC now because I am not fully sure I see all the consequences myself yet. This has passed a testing by Oscar but I would highly appreciate a review from Naoya about my assumptions about hwpoisoning. E.g. it is not entirely clear to me whether there is a potential case where the page might be still mapped. I have put try_to_unmap just to be sure. It would be really great if I could drop that part because then it is not really great which of the TTU flags to use to cover all potential cases. I have marked the patch for stable but I have no idea how far back it should go. Probably everything that already has hotremove and hwpoison code. Thanks in advance! mm/memory_hotplug.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c6c42a7425e5..08c576d5a633 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -1366,6 +1367,17 @@ 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. + */ + if (PageHWPoison(page)) { + if (page_mapped(page)) + try_to_unmap(page, TTU_IGNORE_MLOCK | TTU_IGNORE_ACCESS); + continue; + } + if (!get_page_unless_zero(page)) continue; /* -- 2.19.1