Merge tag 'dax-fixes-4.20-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm

Pull dax fixes from Dan Williams:
"The last of the known regression fixes and fallout from the Xarray
conversion of the filesystem-dax implementation.

On the path to debugging why the dax memory-failure injection test
started failing after the Xarray conversion a couple more fixes for
the dax_lock_mapping_entry(), now called dax_lock_page(), surfaced.
Those plus the bug that started the hunt are now addressed. These
patches have appeared in a -next release with no issues reported.

Note the touches to mm/memory-failure.c are just the conversion to the
new function signature for dax_lock_page().

Summary:

- Fix the Xarray conversion of fsdax to properly handle
dax_lock_mapping_entry() in the presense of pmd entries

- Fix inode destruction racing a new lock request"

* tag 'dax-fixes-4.20-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm:
dax: Fix unlock mismatch with updated API
dax: Don't access a freed inode
dax: Check page->mapping isn't NULL

Changed files
+50 -25
fs
include
linux
mm
+38 -17
fs/dax.c
··· 232 232 } 233 233 } 234 234 235 + /* 236 + * The only thing keeping the address space around is the i_pages lock 237 + * (it's cycled in clear_inode() after removing the entries from i_pages) 238 + * After we call xas_unlock_irq(), we cannot touch xas->xa. 239 + */ 240 + static void wait_entry_unlocked(struct xa_state *xas, void *entry) 241 + { 242 + struct wait_exceptional_entry_queue ewait; 243 + wait_queue_head_t *wq; 244 + 245 + init_wait(&ewait.wait); 246 + ewait.wait.func = wake_exceptional_entry_func; 247 + 248 + wq = dax_entry_waitqueue(xas, entry, &ewait.key); 249 + prepare_to_wait_exclusive(wq, &ewait.wait, TASK_UNINTERRUPTIBLE); 250 + xas_unlock_irq(xas); 251 + schedule(); 252 + finish_wait(wq, &ewait.wait); 253 + 254 + /* 255 + * Entry lock waits are exclusive. Wake up the next waiter since 256 + * we aren't sure we will acquire the entry lock and thus wake 257 + * the next waiter up on unlock. 258 + */ 259 + if (waitqueue_active(wq)) 260 + __wake_up(wq, TASK_NORMAL, 1, &ewait.key); 261 + } 262 + 235 263 static void put_unlocked_entry(struct xa_state *xas, void *entry) 236 264 { 237 265 /* If we were the only waiter woken, wake the next one */ ··· 379 351 * @page: The page whose entry we want to lock 380 352 * 381 353 * Context: Process context. 382 - * Return: %true if the entry was locked or does not need to be locked. 354 + * Return: A cookie to pass to dax_unlock_page() or 0 if the entry could 355 + * not be locked. 383 356 */ 384 - bool dax_lock_mapping_entry(struct page *page) 357 + dax_entry_t dax_lock_page(struct page *page) 385 358 { 386 359 XA_STATE(xas, NULL, 0); 387 360 void *entry; 388 - bool locked; 389 361 390 362 /* Ensure page->mapping isn't freed while we look at it */ 391 363 rcu_read_lock(); 392 364 for (;;) { 393 365 struct address_space *mapping = READ_ONCE(page->mapping); 394 366 395 - locked = false; 396 - if (!dax_mapping(mapping)) 367 + entry = NULL; 368 + if (!mapping || !dax_mapping(mapping)) 397 369 break; 398 370 399 371 /* ··· 403 375 * otherwise we would not have a valid pfn_to_page() 404 376 * translation. 405 377 */ 406 - locked = true; 378 + entry = (void *)~0UL; 407 379 if (S_ISCHR(mapping->host->i_mode)) 408 380 break; 409 381 ··· 417 389 entry = xas_load(&xas); 418 390 if (dax_is_locked(entry)) { 419 391 rcu_read_unlock(); 420 - entry = get_unlocked_entry(&xas); 421 - xas_unlock_irq(&xas); 422 - put_unlocked_entry(&xas, entry); 392 + wait_entry_unlocked(&xas, entry); 423 393 rcu_read_lock(); 424 394 continue; 425 395 } ··· 426 400 break; 427 401 } 428 402 rcu_read_unlock(); 429 - return locked; 403 + return (dax_entry_t)entry; 430 404 } 431 405 432 - void dax_unlock_mapping_entry(struct page *page) 406 + void dax_unlock_page(struct page *page, dax_entry_t cookie) 433 407 { 434 408 struct address_space *mapping = page->mapping; 435 409 XA_STATE(xas, &mapping->i_pages, page->index); 436 - void *entry; 437 410 438 411 if (S_ISCHR(mapping->host->i_mode)) 439 412 return; 440 413 441 - rcu_read_lock(); 442 - entry = xas_load(&xas); 443 - rcu_read_unlock(); 444 - entry = dax_make_entry(page_to_pfn_t(page), dax_is_pmd_entry(entry)); 445 - dax_unlock_entry(&xas, entry); 414 + dax_unlock_entry(&xas, (void *)cookie); 446 415 } 447 416 448 417 /*
+8 -6
include/linux/dax.h
··· 7 7 #include <linux/radix-tree.h> 8 8 #include <asm/pgtable.h> 9 9 10 + typedef unsigned long dax_entry_t; 11 + 10 12 struct iomap_ops; 11 13 struct dax_device; 12 14 struct dax_operations { ··· 90 88 struct block_device *bdev, struct writeback_control *wbc); 91 89 92 90 struct page *dax_layout_busy_page(struct address_space *mapping); 93 - bool dax_lock_mapping_entry(struct page *page); 94 - void dax_unlock_mapping_entry(struct page *page); 91 + dax_entry_t dax_lock_page(struct page *page); 92 + void dax_unlock_page(struct page *page, dax_entry_t cookie); 95 93 #else 96 94 static inline bool bdev_dax_supported(struct block_device *bdev, 97 95 int blocksize) ··· 124 122 return -EOPNOTSUPP; 125 123 } 126 124 127 - static inline bool dax_lock_mapping_entry(struct page *page) 125 + static inline dax_entry_t dax_lock_page(struct page *page) 128 126 { 129 127 if (IS_DAX(page->mapping->host)) 130 - return true; 131 - return false; 128 + return ~0UL; 129 + return 0; 132 130 } 133 131 134 - static inline void dax_unlock_mapping_entry(struct page *page) 132 + static inline void dax_unlock_page(struct page *page, dax_entry_t cookie) 135 133 { 136 134 } 137 135 #endif
+4 -2
mm/memory-failure.c
··· 1161 1161 LIST_HEAD(tokill); 1162 1162 int rc = -EBUSY; 1163 1163 loff_t start; 1164 + dax_entry_t cookie; 1164 1165 1165 1166 /* 1166 1167 * Prevent the inode from being freed while we are interrogating ··· 1170 1169 * also prevents changes to the mapping of this pfn until 1171 1170 * poison signaling is complete. 1172 1171 */ 1173 - if (!dax_lock_mapping_entry(page)) 1172 + cookie = dax_lock_page(page); 1173 + if (!cookie) 1174 1174 goto out; 1175 1175 1176 1176 if (hwpoison_filter(page)) { ··· 1222 1220 kill_procs(&tokill, flags & MF_MUST_KILL, !unmap_success, pfn, flags); 1223 1221 rc = 0; 1224 1222 unlock: 1225 - dax_unlock_mapping_entry(page); 1223 + dax_unlock_page(page, cookie); 1226 1224 out: 1227 1225 /* drop pgmap ref acquired in caller */ 1228 1226 put_dev_pagemap(pgmap);