From patchwork Fri Aug 26 17:18:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 12956334 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 9FDF1ECAAA3 for ; Fri, 26 Aug 2022 17:18:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35E5A940009; Fri, 26 Aug 2022 13:18:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E75C940007; Fri, 26 Aug 2022 13:18:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16105940009; Fri, 26 Aug 2022 13:18:18 -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 007AB940007 for ; Fri, 26 Aug 2022 13:18:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C6A1E1C66C0 for ; Fri, 26 Aug 2022 17:18:17 +0000 (UTC) X-FDA: 79842402234.14.C35B71E Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf30.hostedemail.com (Postfix) with ESMTP id 3451380039 for ; Fri, 26 Aug 2022 17:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661534297; x=1693070297; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LsOnSwP3WX7FSaGrxr4QTRIs8WWv2jITSkmOpyZ+1Mk=; b=GVjrFzbEJYpMt8oHROFop4AREKqJtA7I03SeXkpep7qBna4kpJuzLD4o vofWk29u6JPkrpITJjzpQr3jUJJC94fdYT233B1CrecCaiQD/fVTKhHIp iA53UScUDEkHwe6gwRmUMOIGvXgZ2EqiPUGLyxINvqMVyeRF40BMDu2JI 8afVXhXNvxuSCh7tXZq5d9BSA8UcaL69NSps2q6aChCZVmQrZGfEZZF5p /YnpwwRpfK35nd6QJ4MBxtNX2S9bqO7XfpwCfvicQgZYHStlo88iYLEhQ N9/3oo6lWk7GSo5UxBmC5TnO815Wh41PFo8WbDWQlv1wM8xDTkbJfN3IL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="281525253" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="281525253" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 10:18:15 -0700 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678933461" Received: from jodirobx-mobl2.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.108.22]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 10:18:14 -0700 Subject: [PATCH 4/4] mm/memory-failure: Fall back to vma_address() when ->notify_failure() fails From: Dan Williams To: akpm@linux-foundation.org, djwong@kernel.org Cc: Shiyang Ruan , Christoph Hellwig , Naoya Horiguchi , Al Viro , Dave Chinner , Goldwyn Rodrigues , Jane Chu , Matthew Wilcox , Miaohe Lin , Ritesh Harjani , nvdimm@lists.linux.dev, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Date: Fri, 26 Aug 2022 10:18:14 -0700 Message-ID: <166153429427.2758201.14605968329933175594.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <166153426798.2758201.15108211981034512993.stgit@dwillia2-xfh.jf.intel.com> References: <166153426798.2758201.15108211981034512993.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661534297; a=rsa-sha256; cv=none; b=AtoVpmklzmaVDC8ULwA52/wjS6dEzaGrcub230H9AczToQGwADMo1XRpk2UcX6O95hJfXD FnFf4/1GZZZZgKCus+kDPOJ8NMRRNdC7nIwMjaevVP9LVL72jJie4Yr/+cgfwHwwcbGoi8 b+/LjjjEejozzM66Ctt/RUY8JZ5Svpc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=GVjrFzbE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf30.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661534297; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=K9YvEPrW8YXSd/Y9gP4Lhzsbnd7nog6kf2LqSVcADMQ=; b=3POpSpApYMGc0o53OeLwNZBkNcEMZuZBytXud9DGS+lK6i05ZrRhoDq0KCv6ZcoSDEebHs o3kn7p8lV8HFYMHn7TsTRoLE52AtWWmO3LSLc92bTrtvNhMxsDKxWrkwsIGcVDeSYIYhM2 HdvNasVzH86CEu7eKkRRGOC06kWBpuQ= X-Rspamd-Queue-Id: 3451380039 Authentication-Results: imf30.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=GVjrFzbE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf30.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Stat-Signature: eio7tq5qhjey6om71en7k5ytkepryiab X-HE-Tag: 1661534296-811716 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: In the case where a filesystem is polled to take over the memory failure and receives -EOPNOTSUPP it indicates that page->index and page->mapping are valid for reverse mapping the failure address. Introduce FSDAX_INVALID_PGOFF to distinguish when add_to_kill() is being called from mf_dax_kill_procs() by a filesytem vs the typical memory_failure() path. Otherwise, vma_pgoff_address() is called with an invalid fsdax_pgoff which then trips this failing signature: kernel BUG at mm/memory-failure.c:319! invalid opcode: 0000 [#1] PREEMPT SMP PTI CPU: 13 PID: 1262 Comm: dax-pmd Tainted: G OE N 6.0.0-rc2+ #62 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 RIP: 0010:add_to_kill.cold+0x19d/0x209 [..] Call Trace: collect_procs.part.0+0x2c4/0x460 memory_failure+0x71b/0xba0 ? _printk+0x58/0x73 do_madvise.part.0.cold+0xaf/0xc5 Fixes: c36e20249571 ("mm: introduce mf_dax_kill_procs() for fsdax case") Cc: Shiyang Ruan Cc: Christoph Hellwig Cc: Darrick J. Wong Cc: Naoya Horiguchi Cc: Al Viro Cc: Dave Chinner Cc: Goldwyn Rodrigues Cc: Jane Chu Cc: Matthew Wilcox Cc: Miaohe Lin Cc: Ritesh Harjani Cc: Andrew Morton Signed-off-by: Dan Williams Acked-by: Naoya Horiguchi Reviewed-by: Miaohe Lin Reviewed-by: Christoph Hellwig --- mm/memory-failure.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 8a4294afbfa0..e424a9dac749 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -345,13 +345,17 @@ static unsigned long dev_pagemap_mapping_shift(struct vm_area_struct *vma, * not much we can do. We just print a message and ignore otherwise. */ +#define FSDAX_INVALID_PGOFF ULONG_MAX + /* * Schedule a process for later kill. * Uses GFP_ATOMIC allocations to avoid potential recursions in the VM. * - * Notice: @fsdax_pgoff is used only when @p is a fsdax page. - * In other cases, such as anonymous and file-backend page, the address to be - * killed can be caculated by @p itself. + * Note: @fsdax_pgoff is used only when @p is a fsdax page and a + * filesystem with a memory failure handler has claimed the + * memory_failure event. In all other cases, page->index and + * page->mapping are sufficient for mapping the page back to its + * corresponding user virtual address. */ static void add_to_kill(struct task_struct *tsk, struct page *p, pgoff_t fsdax_pgoff, struct vm_area_struct *vma, @@ -367,11 +371,7 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, tk->addr = page_address_in_vma(p, vma); if (is_zone_device_page(p)) { - /* - * Since page->mapping is not used for fsdax, we need - * calculate the address based on the vma. - */ - if (p->pgmap->type == MEMORY_DEVICE_FS_DAX) + if (fsdax_pgoff != FSDAX_INVALID_PGOFF) tk->addr = vma_pgoff_address(fsdax_pgoff, 1, vma); tk->size_shift = dev_pagemap_mapping_shift(vma, tk->addr); } else @@ -523,7 +523,8 @@ static void collect_procs_anon(struct page *page, struct list_head *to_kill, if (!page_mapped_in_vma(page, vma)) continue; if (vma->vm_mm == t->mm) - add_to_kill(t, page, 0, vma, to_kill); + add_to_kill(t, page, FSDAX_INVALID_PGOFF, vma, + to_kill); } } read_unlock(&tasklist_lock); @@ -559,7 +560,8 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, * to be informed of all such data corruptions. */ if (vma->vm_mm == t->mm) - add_to_kill(t, page, 0, vma, to_kill); + add_to_kill(t, page, FSDAX_INVALID_PGOFF, vma, + to_kill); } } read_unlock(&tasklist_lock);