From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F712C4709D for ; Fri, 4 Jun 2021 01:19:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03A74610E7 for ; Fri, 4 Jun 2021 01:19:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03A74610E7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=fujitsu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9C8476B0075; Thu, 3 Jun 2021 21:19:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99E8C6B0078; Thu, 3 Jun 2021 21:19:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 840556B007B; Thu, 3 Jun 2021 21:19:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id 51B326B0075 for ; Thu, 3 Jun 2021 21:19:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DEBFF8249980 for ; Fri, 4 Jun 2021 01:19:27 +0000 (UTC) X-FDA: 78214283574.24.6F789F3 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by imf19.hostedemail.com (Postfix) with ESMTP id 53AB69001E70 for ; Fri, 4 Jun 2021 01:19:06 +0000 (UTC) IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AciOndaGMdrd53wsKpLqEjceALOsnbusQ8zAX?= =?us-ascii?q?PiFKKSC9Hfb0qynDpp4mPHzP6Qr5OktOpTnoAsDpKk80naQFgrX5Vo3PYOCJgg?= =?us-ascii?q?WVEL0=3D?= X-IronPort-AV: E=Sophos;i="5.83,246,1616428800"; d="scan'208";a="109209802" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Jun 2021 09:19:06 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id D3F604C36A00; Fri, 4 Jun 2021 09:19:01 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 4 Jun 2021 09:19:02 +0800 Received: from G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 4 Jun 2021 09:18:55 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 4 Jun 2021 09:18:54 +0800 From: Shiyang Ruan To: , , , , , CC: , , , , , , Subject: [PATCH v4 05/10] mm, pmem: Implement ->memory_failure() in pmem driver Date: Fri, 4 Jun 2021 09:18:39 +0800 Message-ID: <20210604011844.1756145-6-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210604011844.1756145-1-ruansy.fnst@fujitsu.com> References: <20210604011844.1756145-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-yoursite-MailScanner-ID: D3F604C36A00.A0E01 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf19.hostedemail.com: 183.91.158.132 is neither permitted nor denied by domain of ruansy.fnst@fujitsu.com) smtp.mailfrom=ruansy.fnst@fujitsu.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 53AB69001E70 X-Stat-Signature: u57kzbnoj6x8xu3tazg4btp6nu9jtgfe X-HE-Tag: 1622769546-44652 Content-Transfer-Encoding: quoted-printable 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: Call the ->memory_failure() which is implemented by pmem driver, in order to finally notify filesystem to handle the corrupted data. The handler which collects and kills processes are moved into mf_dax_kill_procs(), which will be called by filesystem. Keep the old handler in order to roll back if driver or filesystem does not support ->memory_failure()/->corrupted_range(). Signed-off-by: Shiyang Ruan --- block/genhd.c | 30 ++++++++++++++++++ drivers/nvdimm/pmem.c | 14 +++++++++ include/linux/genhd.h | 1 + mm/memory-failure.c | 71 +++++++++++++++++++++++++++---------------- 4 files changed, 90 insertions(+), 26 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 9f8cb7beaad1..75834bd057df 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -718,6 +718,36 @@ struct block_device *bdget_disk(struct gendisk *disk= , int partno) return bdev; } =20 +/** + * bdget_disk_sector - get block device by given sector number + * @disk: gendisk of interest + * @sector: sector number + * + * RETURNS: the found block device where sector locates in + */ +struct block_device *bdget_disk_sector(struct gendisk *disk, sector_t se= ctor) +{ + struct block_device *part =3D NULL, *p; + unsigned long idx; + + rcu_read_lock(); + xa_for_each(&disk->part_tbl, idx, p) { + if (p->bd_partno =3D=3D 0) + continue; + if (p->bd_start_sect <=3D sector && + sector < p->bd_start_sect + bdev_nr_sectors(p)) { + part =3D p; + break; + } + } + rcu_read_unlock(); + if (!part) + part =3D disk->part0; + + return bdget_disk(disk, part->bd_partno); +} +EXPORT_SYMBOL(bdget_disk_sector); + /* * print a full list of all partitions - intended for places where the r= oot * filesystem can't be mounted and thus to give the victim some idea of = what diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index ed10a8b66068..98349e7d0a28 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -364,9 +364,23 @@ static void pmem_release_disk(void *__pmem) put_disk(pmem->disk); } =20 +static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap, + unsigned long pfn, int flags) +{ + struct pmem_device *pdev =3D + container_of(pgmap, struct pmem_device, pgmap); + loff_t offset =3D PFN_PHYS(pfn) - pdev->phys_addr - pdev->data_offset; + struct block_device *bdev =3D + bdget_disk_sector(pdev->disk, offset >> SECTOR_SHIFT); + + return dax_corrupted_range(pdev->dax_dev, bdev, offset, + page_size(pfn_to_page(pfn)), &flags); +} + static const struct dev_pagemap_ops fsdax_pagemap_ops =3D { .kill =3D pmem_pagemap_kill, .cleanup =3D pmem_pagemap_cleanup, + .memory_failure =3D pmem_pagemap_memory_failure, }; =20 static int pmem_attach_disk(struct device *dev, diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 6fc26f7bdf71..2ad70c02c343 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -219,6 +219,7 @@ static inline void add_disk_no_queue_reg(struct gendi= sk *disk) =20 extern void del_gendisk(struct gendisk *gp); extern struct block_device *bdget_disk(struct gendisk *disk, int partno)= ; +extern struct block_device *bdget_disk_sector(struct gendisk *disk, sect= or_t sector); =20 void set_disk_ro(struct gendisk *disk, bool read_only); =20 diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 4377e727d478..43017d7f3918 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1247,6 +1247,36 @@ static void unmap_and_kill(struct list_head *to_ki= ll, unsigned long pfn, kill_procs(to_kill, flags & MF_MUST_KILL, false, pfn, flags); } =20 +static int mf_generic_kill_procs(unsigned long long pfn, int flags) +{ + struct page *page =3D pfn_to_page(pfn); + LIST_HEAD(to_kill); + dax_entry_t cookie; + + /* + * Prevent the inode from being freed while we are interrogating + * the address_space, typically this would be handled by + * lock_page(), but dax pages do not use the page lock. This + * also prevents changes to the mapping of this pfn until + * poison signaling is complete. + */ + cookie =3D dax_lock_page(page); + if (!cookie) + return -EBUSY; + /* + * Unlike System-RAM there is no possibility to swap in a + * different physical page at a given virtual address, so all + * userspace consumption of ZONE_DEVICE memory necessitates + * SIGBUS (i.e. MF_MUST_KILL) + */ + flags |=3D MF_ACTION_REQUIRED | MF_MUST_KILL; + collect_procs(page, &to_kill, flags & MF_ACTION_REQUIRED); + + unmap_and_kill(&to_kill, pfn, page->mapping, page->index, flags); + dax_unlock_page(page, cookie); + return 0; +} + int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, int = flags) { LIST_HEAD(to_kill); @@ -1348,9 +1378,7 @@ static int memory_failure_dev_pagemap(unsigned long= pfn, int flags, struct dev_pagemap *pgmap) { struct page *page =3D pfn_to_page(pfn); - LIST_HEAD(to_kill); int rc =3D -EBUSY; - dax_entry_t cookie; =20 if (flags & MF_COUNT_INCREASED) /* @@ -1364,20 +1392,9 @@ static int memory_failure_dev_pagemap(unsigned lon= g pfn, int flags, goto out; } =20 - /* - * Prevent the inode from being freed while we are interrogating - * the address_space, typically this would be handled by - * lock_page(), but dax pages do not use the page lock. This - * also prevents changes to the mapping of this pfn until - * poison signaling is complete. - */ - cookie =3D dax_lock_page(page); - if (!cookie) - goto out; - if (hwpoison_filter(page)) { rc =3D 0; - goto unlock; + goto out; } =20 if (pgmap->type =3D=3D MEMORY_DEVICE_PRIVATE) { @@ -1385,7 +1402,7 @@ static int memory_failure_dev_pagemap(unsigned long= pfn, int flags, * TODO: Handle HMM pages which may need coordination * with device-side memory. */ - goto unlock; + goto out; } =20 /* @@ -1395,19 +1412,21 @@ static int memory_failure_dev_pagemap(unsigned lo= ng pfn, int flags, SetPageHWPoison(page); =20 /* - * Unlike System-RAM there is no possibility to swap in a - * different physical page at a given virtual address, so all - * userspace consumption of ZONE_DEVICE memory necessitates - * SIGBUS (i.e. MF_MUST_KILL) + * Call driver's implementation to handle the memory failure, + * otherwise roll back to generic handler. */ - flags |=3D MF_ACTION_REQUIRED | MF_MUST_KILL; - collect_procs_file(page, page->mapping, page->index, &to_kill, - flags & MF_ACTION_REQUIRED); + if (pgmap->ops->memory_failure) { + rc =3D pgmap->ops->memory_failure(pgmap, pfn, flags); + /* + * Roll back to generic handler too if operation is not + * supported inside the driver/device/filesystem. + */ + if (rc !=3D EOPNOTSUPP) + goto out; + } + + rc =3D mf_generic_kill_procs(pfn, flags); =20 - unmap_and_kill(&to_kill, pfn, page->mapping, page->index, flags); - rc =3D 0; -unlock: - dax_unlock_page(page, cookie); out: /* drop pgmap ref acquired in caller */ put_dev_pagemap(pgmap); --=20 2.31.1