From patchwork Tue Sep 15 10:13:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruan Shiyang X-Patchwork-Id: 11775965 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D35A618 for ; Tue, 15 Sep 2020 10:13:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09C7521D80 for ; Tue, 15 Sep 2020 10:13:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09C7521D80 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 94DA46B009A; Tue, 15 Sep 2020 06:13:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8FE166B009D; Tue, 15 Sep 2020 06:13:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C9D36B009E; Tue, 15 Sep 2020 06:13:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 667946B009A for ; Tue, 15 Sep 2020 06:13:25 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 181231EF1 for ; Tue, 15 Sep 2020 10:13:25 +0000 (UTC) X-FDA: 77264883570.17.able49_440b16527110 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 11D68180D01AD for ; Tue, 15 Sep 2020 10:13:22 +0000 (UTC) X-Spam-Summary: 1,0,0,7b9799f83c06fe6b,d41d8cd98f00b204,ruansy.fnst@cn.fujitsu.com,,RULES_HIT:41:355:371:372:379:541:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1544:1605:1711:1730:1747:1777:1792:2198:2199:2307:2393:2553:2559:2562:2693:2899:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4117:4250:4321:4605:5007:6120:6261:7875:7903:8660:9010:9036:10004:11026:11473:11537:11658:11914:12043:12048:12291:12296:12297:12438:12521:12555:12683:12895:12986:13019:13148:13184:13229:13230:13894:14096:14097:14181:14721:21080:21324:21451:21627:21789:21939:21987:21990:30054:30090,0,RBL:183.91.158.132:@cn.fujitsu.com:.lbl8.mailshell.net-64.201.201.201 62.16.2.100;04yf37yj3kw99trrujkh3xornu5rjopadcyu1ub4jwxh38qj5uwxnc9e88744en.h6pynwgsdkuyx7rnh1k7yhz4n797speuriqogq6jf47kcjghor4k9r9fbzq7chk.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0 ,LFtime: X-HE-Tag: able49_440b16527110 X-Filterd-Recvd-Size: 6224 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 10:13:21 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.76,429,1592841600"; d="scan'208";a="99252002" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 15 Sep 2020 18:13:18 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 60C5548990ED; Tue, 15 Sep 2020 18:13:17 +0800 (CST) Received: from G08CNEXCHPEKD05.g08.fujitsu.local (10.167.33.203) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 15 Sep 2020 18:13:15 +0800 Received: from localhost.localdomain (10.167.225.141) by G08CNEXCHPEKD05.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 15 Sep 2020 18:13:15 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , Subject: [RFC PATCH 2/4] pagemap: introduce ->memory_failure() Date: Tue, 15 Sep 2020 18:13:09 +0800 Message-ID: <20200915101311.144269-3-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915101311.144269-1-ruansy.fnst@cn.fujitsu.com> References: <20200915101311.144269-1-ruansy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 60C5548990ED.AC46D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com X-Spam-Status: No X-Rspamd-Queue-Id: 11D68180D01AD X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: When memory-failure occurs, we call this function which is implemented by each devices. For fsdax, pmem device implements it. Pmem device will find out the block device where the error page located in, gets the filesystem on this block device, and finally call ->storage_lost() to handle the error in filesystem layer. Normally, a pmem device may contain one or more partitions, each partition contains a block device, each block device contains a filesystem. So we are able to find out the filesystem by one offset on this pmem device. However, in other cases, such as mapped device, I didn't find a way to obtain the filesystem laying on it. It is a problem need to be fixed. Signed-off-by: Shiyang Ruan --- block/genhd.c | 12 ++++++++++++ drivers/nvdimm/pmem.c | 31 +++++++++++++++++++++++++++++++ include/linux/genhd.h | 2 ++ include/linux/memremap.h | 3 +++ 4 files changed, 48 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 99c64641c314..e7442b60683e 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1063,6 +1063,18 @@ struct block_device *bdget_disk(struct gendisk *disk, int partno) } EXPORT_SYMBOL(bdget_disk); +struct block_device *bdget_disk_sector(struct gendisk *disk, sector_t sector) +{ + struct block_device *bdev = NULL; + struct hd_struct *part = disk_map_sector_rcu(disk, sector); + + if (part) + bdev = bdget(part_devt(part)); + + return bdev; +} +EXPORT_SYMBOL(bdget_disk_sector); + /* * print a full list of all partitions - intended for places where the root * 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 fab29b514372..3ed96486c883 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -364,9 +364,40 @@ static void pmem_release_disk(void *__pmem) put_disk(pmem->disk); } +static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap, + struct mf_recover_controller *mfrc) +{ + struct pmem_device *pdev; + struct block_device *bdev; + sector_t disk_sector; + loff_t bdev_offset; + + pdev = container_of(pgmap, struct pmem_device, pgmap); + if (!pdev->disk) + return -ENXIO; + + disk_sector = (PFN_PHYS(mfrc->pfn) - pdev->phys_addr) >> SECTOR_SHIFT; + bdev = bdget_disk_sector(pdev->disk, disk_sector); + if (!bdev) + return -ENXIO; + + // TODO what if block device contains a mapped device + if (!bdev->bd_super) + goto out; + + bdev_offset = ((disk_sector - get_start_sect(bdev)) << SECTOR_SHIFT) - + pdev->data_offset; + bdev->bd_super->s_op->storage_lost(bdev->bd_super, bdev_offset, mfrc); + +out: + bdput(bdev); + return 0; +} + static const struct dev_pagemap_ops fsdax_pagemap_ops = { .kill = pmem_pagemap_kill, .cleanup = pmem_pagemap_cleanup, + .memory_failure = pmem_pagemap_memory_failure, }; static int pmem_attach_disk(struct device *dev, diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 4ab853461dff..16e9e13e0841 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -303,6 +303,8 @@ static inline void add_disk_no_queue_reg(struct gendisk *disk) extern void del_gendisk(struct gendisk *gp); extern struct gendisk *get_gendisk(dev_t dev, int *partno); extern struct block_device *bdget_disk(struct gendisk *disk, int partno); +extern struct block_device *bdget_disk_sector(struct gendisk *disk, + sector_t sector); extern void set_device_ro(struct block_device *bdev, int flag); extern void set_disk_ro(struct gendisk *disk, int flag); diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 5f5b2df06e61..efebefa70d00 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -6,6 +6,7 @@ struct resource; struct device; +struct mf_recover_controller; /** * struct vmem_altmap - pre-allocated storage for vmemmap_populate @@ -87,6 +88,8 @@ struct dev_pagemap_ops { * the page back to a CPU accessible page. */ vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); + int (*memory_failure)(struct dev_pagemap *pgmap, + struct mf_recover_controller *mfrc); }; #define PGMAP_ALTMAP_VALID (1 << 0)