Skip to content

Commit c5d4355

Browse files
Pankaj Guptadjbw
authored andcommitted
libnvdimm: nd_region flush callback support
This patch adds functionality to perform flush from guest to host over VIRTIO. We are registering a callback based on 'nd_region' type. virtio_pmem driver requires this special flush function. For rest of the region types we are registering existing flush function. Report error returned by host fsync failure to userspace. Signed-off-by: Pankaj Gupta <pagupta@redhat.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent db5d00c commit c5d4355

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

drivers/acpi/nfit/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw,
24262426
offset = to_interleave_offset(offset, mmio);
24272427

24282428
writeq(cmd, mmio->addr.base + offset);
2429-
nvdimm_flush(nfit_blk->nd_region);
2429+
nvdimm_flush(nfit_blk->nd_region, NULL);
24302430

24312431
if (nfit_blk->dimm_flags & NFIT_BLK_DCR_LATCH)
24322432
readq(mmio->addr.base + offset);
@@ -2475,7 +2475,7 @@ static int acpi_nfit_blk_single_io(struct nfit_blk *nfit_blk,
24752475
}
24762476

24772477
if (rw)
2478-
nvdimm_flush(nfit_blk->nd_region);
2478+
nvdimm_flush(nfit_blk->nd_region, NULL);
24792479

24802480
rc = read_blk_stat(nfit_blk, lane) ? -EIO : 0;
24812481
return rc;

drivers/nvdimm/claim.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int nsio_rw_bytes(struct nd_namespace_common *ndns,
255255
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
256256
unsigned int sz_align = ALIGN(size + (offset & (512 - 1)), 512);
257257
sector_t sector = offset >> 9;
258-
int rc = 0;
258+
int rc = 0, ret = 0;
259259

260260
if (unlikely(!size))
261261
return 0;
@@ -293,7 +293,9 @@ static int nsio_rw_bytes(struct nd_namespace_common *ndns,
293293
}
294294

295295
memcpy_flushcache(nsio->addr + offset, buf, size);
296-
nvdimm_flush(to_nd_region(ndns->dev.parent));
296+
ret = nvdimm_flush(to_nd_region(ndns->dev.parent), NULL);
297+
if (ret)
298+
rc = ret;
297299

298300
return rc;
299301
}

drivers/nvdimm/nd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct nd_region {
155155
struct badblocks bb;
156156
struct nd_interleave_set *nd_set;
157157
struct nd_percpu_lane __percpu *lane;
158+
int (*flush)(struct nd_region *nd_region, struct bio *bio);
158159
struct nd_mapping mapping[0];
159160
};
160161

drivers/nvdimm/pmem.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static blk_status_t pmem_do_bvec(struct pmem_device *pmem, struct page *page,
184184

185185
static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
186186
{
187+
int ret = 0;
187188
blk_status_t rc = 0;
188189
bool do_acct;
189190
unsigned long start;
@@ -193,7 +194,7 @@ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
193194
struct nd_region *nd_region = to_region(pmem);
194195

195196
if (bio->bi_opf & REQ_PREFLUSH)
196-
nvdimm_flush(nd_region);
197+
ret = nvdimm_flush(nd_region, bio);
197198

198199
do_acct = nd_iostat_start(bio, &start);
199200
bio_for_each_segment(bvec, bio, iter) {
@@ -208,7 +209,10 @@ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
208209
nd_iostat_end(bio, start);
209210

210211
if (bio->bi_opf & REQ_FUA)
211-
nvdimm_flush(nd_region);
212+
ret = nvdimm_flush(nd_region, bio);
213+
214+
if (ret)
215+
bio->bi_status = errno_to_blk_status(ret);
212216

213217
bio_endio(bio);
214218
return BLK_QC_T_NONE;
@@ -477,7 +481,6 @@ static int pmem_attach_disk(struct device *dev,
477481
}
478482
dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
479483
pmem->dax_dev = dax_dev;
480-
481484
gendev = disk_to_dev(disk);
482485
gendev->groups = pmem_attribute_groups;
483486

@@ -535,14 +538,14 @@ static int nd_pmem_remove(struct device *dev)
535538
sysfs_put(pmem->bb_state);
536539
pmem->bb_state = NULL;
537540
}
538-
nvdimm_flush(to_nd_region(dev->parent));
541+
nvdimm_flush(to_nd_region(dev->parent), NULL);
539542

540543
return 0;
541544
}
542545

543546
static void nd_pmem_shutdown(struct device *dev)
544547
{
545-
nvdimm_flush(to_nd_region(dev->parent));
548+
nvdimm_flush(to_nd_region(dev->parent), NULL);
546549
}
547550

548551
static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)

drivers/nvdimm/region_devs.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ static ssize_t deep_flush_store(struct device *dev, struct device_attribute *att
287287
return rc;
288288
if (!flush)
289289
return -EINVAL;
290-
nvdimm_flush(nd_region);
290+
rc = nvdimm_flush(nd_region, NULL);
291+
if (rc)
292+
return rc;
291293

292294
return len;
293295
}
@@ -1077,6 +1079,11 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
10771079
dev->of_node = ndr_desc->of_node;
10781080
nd_region->ndr_size = resource_size(ndr_desc->res);
10791081
nd_region->ndr_start = ndr_desc->res->start;
1082+
if (ndr_desc->flush)
1083+
nd_region->flush = ndr_desc->flush;
1084+
else
1085+
nd_region->flush = NULL;
1086+
10801087
nd_device_register(dev);
10811088

10821089
return nd_region;
@@ -1117,11 +1124,24 @@ struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
11171124
}
11181125
EXPORT_SYMBOL_GPL(nvdimm_volatile_region_create);
11191126

1127+
int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
1128+
{
1129+
int rc = 0;
1130+
1131+
if (!nd_region->flush)
1132+
rc = generic_nvdimm_flush(nd_region);
1133+
else {
1134+
if (nd_region->flush(nd_region, bio))
1135+
rc = -EIO;
1136+
}
1137+
1138+
return rc;
1139+
}
11201140
/**
11211141
* nvdimm_flush - flush any posted write queues between the cpu and pmem media
11221142
* @nd_region: blk or interleaved pmem region
11231143
*/
1124-
void nvdimm_flush(struct nd_region *nd_region)
1144+
int generic_nvdimm_flush(struct nd_region *nd_region)
11251145
{
11261146
struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev);
11271147
int i, idx;
@@ -1145,6 +1165,8 @@ void nvdimm_flush(struct nd_region *nd_region)
11451165
if (ndrd_get_flush_wpq(ndrd, i, 0))
11461166
writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
11471167
wmb();
1168+
1169+
return 0;
11481170
}
11491171
EXPORT_SYMBOL_GPL(nvdimm_flush);
11501172

include/linux/libnvdimm.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/types.h>
1212
#include <linux/uuid.h>
1313
#include <linux/spinlock.h>
14+
#include <linux/bio.h>
1415

1516
struct badrange_entry {
1617
u64 start;
@@ -57,6 +58,9 @@ enum {
5758
*/
5859
ND_REGION_PERSIST_MEMCTRL = 2,
5960

61+
/* Platform provides asynchronous flush mechanism */
62+
ND_REGION_ASYNC = 3,
63+
6064
/* mark newly adjusted resources as requiring a label update */
6165
DPA_RESOURCE_ADJUSTED = 1 << 0,
6266
};
@@ -113,6 +117,7 @@ struct nd_mapping_desc {
113117
int position;
114118
};
115119

120+
struct nd_region;
116121
struct nd_region_desc {
117122
struct resource *res;
118123
struct nd_mapping_desc *mapping;
@@ -125,6 +130,7 @@ struct nd_region_desc {
125130
int target_node;
126131
unsigned long flags;
127132
struct device_node *of_node;
133+
int (*flush)(struct nd_region *nd_region, struct bio *bio);
128134
};
129135

130136
struct device;
@@ -252,7 +258,8 @@ unsigned long nd_blk_memremap_flags(struct nd_blk_region *ndbr);
252258
unsigned int nd_region_acquire_lane(struct nd_region *nd_region);
253259
void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane);
254260
u64 nd_fletcher64(void *addr, size_t len, bool le);
255-
void nvdimm_flush(struct nd_region *nd_region);
261+
int nvdimm_flush(struct nd_region *nd_region, struct bio *bio);
262+
int generic_nvdimm_flush(struct nd_region *nd_region);
256263
int nvdimm_has_flush(struct nd_region *nd_region);
257264
int nvdimm_has_cache(struct nd_region *nd_region);
258265
int nvdimm_in_overwrite(struct nvdimm *nvdimm);

0 commit comments

Comments
 (0)