From patchwork Mon Oct 31 20:10:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Luck X-Patchwork-Id: 13026307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07585FA3743 for ; Mon, 31 Oct 2022 20:10:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BA176B0074; Mon, 31 Oct 2022 16:10:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F3F86B0075; Mon, 31 Oct 2022 16:10:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61EF96B0078; Mon, 31 Oct 2022 16:10:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 565716B0074 for ; Mon, 31 Oct 2022 16:10:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 32A311C65A1 for ; Mon, 31 Oct 2022 20:10:52 +0000 (UTC) X-FDA: 80082337944.15.3447F95 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf13.hostedemail.com (Postfix) with ESMTP id 9D7CA20007 for ; Mon, 31 Oct 2022 20:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667247051; x=1698783051; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/v2ZvqyUX9QuQjryssW2yaZzhbAsEUWDkNYvgzcoQls=; b=EtCJ6PwSxidCGX9bFtktguciFI4ccg0i+EI70JwXA+vxPhrPBvJuU4Ze UfzuVogq53JQY/PIl6F+NoVuF2NRMZ0J8simeHWdd32hvWI5V9HwQQVWj hMxC8bCCps1fjpg1xaDrZ8rpLVXBj07BIl5DfK6o/irRIn8RJsXu8GVZB BiaZsYyDc6rcGt0/LGbB7tf4hd4UAN+MAP/LMAUMhKZC5n3XIbjb5D7DG vGM3KIxPiQUsrSIELH286+Cwk+9uMq2FEoOkTDzyH7nuCUyV+wBOgtEpP 8japoqSKg3ZqGpbwda37bKXvaVidKke/WuC5CB0Whw7yxsuUPIfce2IjQ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="289379581" X-IronPort-AV: E=Sophos;i="5.95,228,1661842800"; d="scan'208";a="289379581" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 13:10:47 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="722931446" X-IronPort-AV: E=Sophos;i="5.95,228,1661842800"; d="scan'208";a="722931446" Received: from agluck-desk3.sc.intel.com ([172.25.222.78]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 13:10:47 -0700 From: Tony Luck To: Andrew Morton Cc: Alexander Potapenko , Naoya Horiguchi , Miaohe Lin , Matthew Wilcox , Shuai Xue , Dan Williams , Michael Ellerman , Nicholas Piggin , Christophe Leroy , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Tony Luck Subject: [PATCH v4 2/2] mm, hwpoison: When copy-on-write hits poison, take page offline Date: Mon, 31 Oct 2022 13:10:29 -0700 Message-Id: <20221031201029.102123-3-tony.luck@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221031201029.102123-1-tony.luck@intel.com> References: <20221021200120.175753-1-tony.luck@intel.com> <20221031201029.102123-1-tony.luck@intel.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667247051; a=rsa-sha256; cv=none; b=7aO+fua0+T22B0CP065RzjUWQTuEs93tFiAeua0TVyc4uoFATbYOxI7KAXlNmxx7pzUXGh FY/YSoajgN3ZySToP2AoQJnxeI8bw6uQkCnU2gAOwOdSQfceNFXdxSuIlS+QG7ynv2K27w raLUgW09uZFr3xB6jps4X6sJoinzsWs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=EtCJ6PwS; spf=pass (imf13.hostedemail.com: domain of tony.luck@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=tony.luck@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667247051; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HybuBLpFrKjUpj8nbH2WjkWYl9KfidiuqjYNV1CeozA=; b=2Vmic0XZCUZS1Y68tPtJ81nv41I10k+pHjBwNjLuFdZGokYaByAf2VWN/SajCoCZotWh2R WBIXAvT1bRfmUYKyJAhZIS0aEObGW87O331vpWveFYw9F7znelNHIqD7ZdCFH5xq04gkDI Xza7kvUQrVDuyqCMViRMK7ZJsq/Sb24= Authentication-Results: imf13.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=EtCJ6PwS; spf=pass (imf13.hostedemail.com: domain of tony.luck@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=tony.luck@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9D7CA20007 X-Stat-Signature: eeyc79q4ssg4wz8pirw11ijycpwwf3e4 X-Rspam-User: X-HE-Tag: 1667247051-156627 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Cannot call memory_failure() directly from the fault handler because mmap_lock (and others) are held. It is important, but not urgent, to mark the source page as h/w poisoned and unmap it from other tasks. Use memory_failure_queue() to request a call to memory_failure() for the page with the error. Also provide a stub version for CONFIG_MEMORY_FAILURE=n Reviewed-by: Miaohe Lin Tested-by: Shuai Xue Signed-off-by: Tony Luck Message-Id: <20221021200120.175753-3-tony.luck@intel.com> Signed-off-by: Tony Luck --- include/linux/mm.h | 5 ++++- mm/memory.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 8bbcccbc5565..03ced659eb58 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3268,7 +3268,6 @@ enum mf_flags { int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, unsigned long count, int mf_flags); extern int memory_failure(unsigned long pfn, int flags); -extern void memory_failure_queue(unsigned long pfn, int flags); extern void memory_failure_queue_kick(int cpu); extern int unpoison_memory(unsigned long pfn); extern int sysctl_memory_failure_early_kill; @@ -3277,8 +3276,12 @@ 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); #ifdef CONFIG_MEMORY_FAILURE +extern void memory_failure_queue(unsigned long pfn, int flags); extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags); #else +static inline void memory_failure_queue(unsigned long pfn, int flags) +{ +} static inline int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) { return 0; diff --git a/mm/memory.c b/mm/memory.c index b6056eef2f72..eae242351726 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2866,8 +2866,10 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, unsigned long addr = vmf->address; if (likely(src)) { - if (copy_mc_user_highpage(dst, src, addr, vma)) + if (copy_mc_user_highpage(dst, src, addr, vma)) { + memory_failure_queue(page_to_pfn(src), 0); return -EHWPOISON; + } return 0; }