Skip to content

Commit 0a70bd4

Browse files
djbwstellarhopper
authored andcommitted
dax: enable dax in the presence of known media errors (badblocks)
1/ If a mapping overlaps a bad sector fail the request. 2/ Do not opportunistically report more dax-capable capacity than is requested when errors present. Reviewed-by: Jeff Moyer <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Dan Williams <[email protected]> [vishal: fix a conflict with system RAM collision patches] [vishal: add a 'size' parameter to ->direct_access] [vishal: fix a conflict with DAX alignment check patches] Signed-off-by: Vishal Verma <[email protected]>
1 parent 8b3db97 commit 0a70bd4

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

arch/powerpc/sysdev/axonram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ axon_ram_make_request(struct request_queue *queue, struct bio *bio)
143143
*/
144144
static long
145145
axon_ram_direct_access(struct block_device *device, sector_t sector,
146-
void __pmem **kaddr, pfn_t *pfn)
146+
void __pmem **kaddr, pfn_t *pfn, long size)
147147
{
148148
struct axon_ram_bank *bank = device->bd_disk->private_data;
149149
loff_t offset = (loff_t)sector << AXON_RAM_SECTOR_SHIFT;

drivers/block/brd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static int brd_rw_page(struct block_device *bdev, sector_t sector,
381381

382382
#ifdef CONFIG_BLK_DEV_RAM_DAX
383383
static long brd_direct_access(struct block_device *bdev, sector_t sector,
384-
void __pmem **kaddr, pfn_t *pfn)
384+
void __pmem **kaddr, pfn_t *pfn, long size)
385385
{
386386
struct brd_device *brd = bdev->bd_disk->private_data;
387387
struct page *page;

drivers/nvdimm/pmem.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,22 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector,
182182
}
183183

184184
static long pmem_direct_access(struct block_device *bdev, sector_t sector,
185-
void __pmem **kaddr, pfn_t *pfn)
185+
void __pmem **kaddr, pfn_t *pfn, long size)
186186
{
187187
struct pmem_device *pmem = bdev->bd_disk->private_data;
188188
resource_size_t offset = sector * 512 + pmem->data_offset;
189189

190+
if (unlikely(is_bad_pmem(&pmem->bb, sector, size)))
191+
return -EIO;
190192
*kaddr = pmem->virt_addr + offset;
191193
*pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
192194

195+
/*
196+
* If badblocks are present, limit known good range to the
197+
* requested range.
198+
*/
199+
if (unlikely(pmem->bb.count))
200+
return size;
193201
return pmem->size - pmem->pfn_pad - offset;
194202
}
195203

drivers/s390/block/dcssblk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void dcssblk_release(struct gendisk *disk, fmode_t mode);
3131
static blk_qc_t dcssblk_make_request(struct request_queue *q,
3232
struct bio *bio);
3333
static long dcssblk_direct_access(struct block_device *bdev, sector_t secnum,
34-
void __pmem **kaddr, pfn_t *pfn);
34+
void __pmem **kaddr, pfn_t *pfn, long size);
3535

3636
static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0";
3737

@@ -883,7 +883,7 @@ dcssblk_make_request(struct request_queue *q, struct bio *bio)
883883

884884
static long
885885
dcssblk_direct_access (struct block_device *bdev, sector_t secnum,
886-
void __pmem **kaddr, pfn_t *pfn)
886+
void __pmem **kaddr, pfn_t *pfn, long size)
887887
{
888888
struct dcssblk_dev_info *dev_info;
889889
unsigned long offset, dev_sz;

fs/block_dev.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <linux/log2.h>
3030
#include <linux/cleancache.h>
3131
#include <linux/dax.h>
32-
#include <linux/badblocks.h>
3332
#include <asm/uaccess.h>
3433
#include "internal.h"
3534

@@ -501,7 +500,7 @@ long bdev_direct_access(struct block_device *bdev, struct blk_dax_ctl *dax)
501500
sector += get_start_sect(bdev);
502501
if (sector % (PAGE_SIZE / 512))
503502
return -EINVAL;
504-
avail = ops->direct_access(bdev, sector, &dax->addr, &dax->pfn);
503+
avail = ops->direct_access(bdev, sector, &dax->addr, &dax->pfn, size);
505504
if (!avail)
506505
return -ERANGE;
507506
if (avail > 0 && avail & ~PAGE_MASK)
@@ -561,7 +560,6 @@ EXPORT_SYMBOL_GPL(bdev_dax_supported);
561560
*/
562561
bool bdev_dax_capable(struct block_device *bdev)
563562
{
564-
struct gendisk *disk = bdev->bd_disk;
565563
struct blk_dax_ctl dax = {
566564
.size = PAGE_SIZE,
567565
};
@@ -577,15 +575,6 @@ bool bdev_dax_capable(struct block_device *bdev)
577575
if (bdev_direct_access(bdev, &dax) < 0)
578576
return false;
579577

580-
/*
581-
* If the device has known bad blocks, force all I/O through the
582-
* driver / page cache.
583-
*
584-
* TODO: support finer grained dax error handling
585-
*/
586-
if (disk->bb && disk->bb->count)
587-
return false;
588-
589578
return true;
590579
}
591580

include/linux/blkdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ struct block_device_operations {
16681668
int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
16691669
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
16701670
long (*direct_access)(struct block_device *, sector_t, void __pmem **,
1671-
pfn_t *);
1671+
pfn_t *, long);
16721672
unsigned int (*check_events) (struct gendisk *disk,
16731673
unsigned int clearing);
16741674
/* ->media_changed() is DEPRECATED, use ->check_events() instead */

0 commit comments

Comments
 (0)