Skip to content

Commit f9e040e

Browse files
Mikulas Patockasnitm
authored andcommitted
dm writecache: handle DAX to partitions on persistent memory correctly
The function dax_direct_access doesn't take partitions into account, it always maps pages from the beginning of the device. Therefore, persistent_memory_claim() must get the partition offset using get_start_sect() and add it to the page offsets passed to dax_direct_access(). Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Fixes: 48debaf ("dm: add writecache target") Cc: stable@vger.kernel.org # 4.18+ Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent f75aef3 commit f9e040e

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/md/dm-writecache.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
231231
pfn_t pfn;
232232
int id;
233233
struct page **pages;
234+
sector_t offset;
234235

235236
wc->memory_vmapped = false;
236237

@@ -245,9 +246,16 @@ static int persistent_memory_claim(struct dm_writecache *wc)
245246
goto err1;
246247
}
247248

249+
offset = get_start_sect(wc->ssd_dev->bdev);
250+
if (offset & (PAGE_SIZE / 512 - 1)) {
251+
r = -EINVAL;
252+
goto err1;
253+
}
254+
offset >>= PAGE_SHIFT - 9;
255+
248256
id = dax_read_lock();
249257

250-
da = dax_direct_access(wc->ssd_dev->dax_dev, 0, p, &wc->memory_map, &pfn);
258+
da = dax_direct_access(wc->ssd_dev->dax_dev, offset, p, &wc->memory_map, &pfn);
251259
if (da < 0) {
252260
wc->memory_map = NULL;
253261
r = da;
@@ -269,7 +277,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
269277
i = 0;
270278
do {
271279
long daa;
272-
daa = dax_direct_access(wc->ssd_dev->dax_dev, i, p - i,
280+
daa = dax_direct_access(wc->ssd_dev->dax_dev, offset + i, p - i,
273281
NULL, &pfn);
274282
if (daa <= 0) {
275283
r = daa ? daa : -EINVAL;

0 commit comments

Comments
 (0)