From patchwork Fri Oct 21 20:01:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Luck X-Patchwork-Id: 13015349 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 2BB7BC433FE for ; Fri, 21 Oct 2022 20:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD0C78E0005; Fri, 21 Oct 2022 16:01:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A09B38E0003; Fri, 21 Oct 2022 16:01:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AB2E8E0005; Fri, 21 Oct 2022 16:01:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 76C508E0001 for ; Fri, 21 Oct 2022 16:01:32 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4307741500 for ; Fri, 21 Oct 2022 20:01:32 +0000 (UTC) X-FDA: 80046026424.13.85F6102 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf15.hostedemail.com (Postfix) with ESMTP id B7B55A003F for ; Fri, 21 Oct 2022 20:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666382491; x=1697918491; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V6m+YOfy5sxTfMqFs+Sj5pHdQRZvXRPoJwkK0Nyet44=; b=fXRkKuGBnm9sQtLaKRcWOgVl82mupyEn618Ph+5tVwVTNKWhSZ2oCYi3 pnRAkA4tyDLgh6vixCSG8IWCQOfZ8mbS3e/lRg1I4ynHadQtIQorpoJdh SKvCEou/NmSLrT65Ag6Q6G//414+OwalPgURkoPVSgvtfbRohvJ4ROpi9 /0S05B35XaqFI6JvUj/CL5JyCIsHhMYUEIsSmpVb8SQnVzwnFHKJHr/n+ CAOjLFCAfQz4yl1T5dk7vpnDLyCYxEmHRryEpO6yoYJ3G82GVJ4bdhGUq p+lxRVt82SCqudEZtmb0lXYq0dfrOMpkLPbRXfMF5y4iCjQNhO2hxggE3 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10507"; a="369153376" X-IronPort-AV: E=Sophos;i="5.95,203,1661842800"; d="scan'208";a="369153376" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 13:01:28 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10507"; a="633069091" X-IronPort-AV: E=Sophos;i="5.95,203,1661842800"; d="scan'208";a="633069091" Received: from agluck-desk3.sc.intel.com ([172.25.222.78]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 13:01:27 -0700 From: Tony Luck To: Naoya Horiguchi , Andrew Morton Cc: 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 v3 2/2] mm, hwpoison: When copy-on-write hits poison, take page offline Date: Fri, 21 Oct 2022 13:01:20 -0700 Message-Id: <20221021200120.175753-3-tony.luck@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221021200120.175753-1-tony.luck@intel.com> References: <20221019170835.155381-1-tony.luck@intel.com> <20221021200120.175753-1-tony.luck@intel.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=fXRkKuGB; spf=pass (imf15.hostedemail.com: domain of tony.luck@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=tony.luck@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666382491; a=rsa-sha256; cv=none; b=bj+roOHGp9FfoojumEjQ5TkqONWr4fAgc515Hx/oyuCQqbr5mauKO5ixznFqUqfvUvEUty FbcY2VgE8CPPbcZSkIeLsiUXRBx21XQwtpmzUsB0bhxc4BKRM1uXs6Kae2GTj9HZIpbmh4 3RajOpRn05wZEnqHZI5Xr95KzatFRIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666382491; 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=DtzjFiVfsz6uRTaunxk9mK5vEo7zwX7ecg9qpP3wQuw=; b=uF2ul/mj699UVOzAK4yRWlU+9i8NW+j25k08V6HUQ60Sn8x8DNDy5nlTPvJpRo/jACXq0n 53xpDfR4vBP1jiyNH89taGBL2K2hdYaRepVy2EmACnVdtQn3isuYPagszb2QNSQiEZIeTd fx4PG008zOeVd1TEpZKM8uTw2A0UIjk= Authentication-Results: imf15.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=fXRkKuGB; spf=pass (imf15.hostedemail.com: domain of tony.luck@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=tony.luck@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: 11n5waf5wqapsr5qr8ax7kzmmef7j9wo X-Rspamd-Queue-Id: B7B55A003F X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666382491-982932 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 Signed-off-by: Tony Luck Reviewed-by: Miaohe Lin --- 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; }