Skip to content

Commit 0fe49f7

Browse files
committed
Merge tag 'dax-for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull dax updates from Dan Williams: "The fruits of a bug hunt in the fsdax implementation with Willy and a small feature update for device-dax: - Fix a hang condition that started triggering after the Xarray conversion of fsdax in the v4.20 kernel. - Add a 'resource' (root-only physical base address) sysfs attribute to device-dax instances to correlate memory-blocks onlined via the kmem driver with a given device instance" * tag 'dax-for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: dax: Fix missed wakeup with PMD faults device-dax: Add a 'resource' attribute
2 parents f8c3500 + 23c84eb commit 0fe49f7

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

drivers/dax/bus.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,22 @@ static ssize_t target_node_show(struct device *dev,
295295
}
296296
static DEVICE_ATTR_RO(target_node);
297297

298+
static unsigned long long dev_dax_resource(struct dev_dax *dev_dax)
299+
{
300+
struct dax_region *dax_region = dev_dax->region;
301+
302+
return dax_region->res.start;
303+
}
304+
305+
static ssize_t resource_show(struct device *dev,
306+
struct device_attribute *attr, char *buf)
307+
{
308+
struct dev_dax *dev_dax = to_dev_dax(dev);
309+
310+
return sprintf(buf, "%#llx\n", dev_dax_resource(dev_dax));
311+
}
312+
static DEVICE_ATTR_RO(resource);
313+
298314
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
299315
char *buf)
300316
{
@@ -313,13 +329,16 @@ static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n)
313329

314330
if (a == &dev_attr_target_node.attr && dev_dax_target_node(dev_dax) < 0)
315331
return 0;
332+
if (a == &dev_attr_resource.attr)
333+
return 0400;
316334
return a->mode;
317335
}
318336

319337
static struct attribute *dev_dax_attributes[] = {
320338
&dev_attr_modalias.attr,
321339
&dev_attr_size.attr,
322340
&dev_attr_target_node.attr,
341+
&dev_attr_resource.attr,
323342
NULL,
324343
};
325344

fs/dax.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ static int dax_is_empty_entry(void *entry)
123123
return xa_to_value(entry) & DAX_EMPTY;
124124
}
125125

126+
/*
127+
* true if the entry that was found is of a smaller order than the entry
128+
* we were looking for
129+
*/
130+
static bool dax_is_conflict(void *entry)
131+
{
132+
return entry == XA_RETRY_ENTRY;
133+
}
134+
126135
/*
127136
* DAX page cache entry locking
128137
*/
@@ -195,11 +204,13 @@ static void dax_wake_entry(struct xa_state *xas, void *entry, bool wake_all)
195204
* Look up entry in page cache, wait for it to become unlocked if it
196205
* is a DAX entry and return it. The caller must subsequently call
197206
* put_unlocked_entry() if it did not lock the entry or dax_unlock_entry()
198-
* if it did.
207+
* if it did. The entry returned may have a larger order than @order.
208+
* If @order is larger than the order of the entry found in i_pages, this
209+
* function returns a dax_is_conflict entry.
199210
*
200211
* Must be called with the i_pages lock held.
201212
*/
202-
static void *get_unlocked_entry(struct xa_state *xas)
213+
static void *get_unlocked_entry(struct xa_state *xas, unsigned int order)
203214
{
204215
void *entry;
205216
struct wait_exceptional_entry_queue ewait;
@@ -210,6 +221,8 @@ static void *get_unlocked_entry(struct xa_state *xas)
210221

211222
for (;;) {
212223
entry = xas_find_conflict(xas);
224+
if (dax_entry_order(entry) < order)
225+
return XA_RETRY_ENTRY;
213226
if (!entry || WARN_ON_ONCE(!xa_is_value(entry)) ||
214227
!dax_is_locked(entry))
215228
return entry;
@@ -254,7 +267,7 @@ static void wait_entry_unlocked(struct xa_state *xas, void *entry)
254267
static void put_unlocked_entry(struct xa_state *xas, void *entry)
255268
{
256269
/* If we were the only waiter woken, wake the next one */
257-
if (entry)
270+
if (entry && dax_is_conflict(entry))
258271
dax_wake_entry(xas, entry, false);
259272
}
260273

@@ -461,28 +474,25 @@ void dax_unlock_page(struct page *page, dax_entry_t cookie)
461474
* overlap with xarray value entries.
462475
*/
463476
static void *grab_mapping_entry(struct xa_state *xas,
464-
struct address_space *mapping, unsigned long size_flag)
477+
struct address_space *mapping, unsigned int order)
465478
{
466479
unsigned long index = xas->xa_index;
467480
bool pmd_downgrade = false; /* splitting PMD entry into PTE entries? */
468481
void *entry;
469482

470483
retry:
471484
xas_lock_irq(xas);
472-
entry = get_unlocked_entry(xas);
485+
entry = get_unlocked_entry(xas, order);
473486

474487
if (entry) {
488+
if (dax_is_conflict(entry))
489+
goto fallback;
475490
if (!xa_is_value(entry)) {
476491
xas_set_err(xas, EIO);
477492
goto out_unlock;
478493
}
479494

480-
if (size_flag & DAX_PMD) {
481-
if (dax_is_pte_entry(entry)) {
482-
put_unlocked_entry(xas, entry);
483-
goto fallback;
484-
}
485-
} else { /* trying to grab a PTE entry */
495+
if (order == 0) {
486496
if (dax_is_pmd_entry(entry) &&
487497
(dax_is_zero_entry(entry) ||
488498
dax_is_empty_entry(entry))) {
@@ -523,7 +533,11 @@ static void *grab_mapping_entry(struct xa_state *xas,
523533
if (entry) {
524534
dax_lock_entry(xas, entry);
525535
} else {
526-
entry = dax_make_entry(pfn_to_pfn_t(0), size_flag | DAX_EMPTY);
536+
unsigned long flags = DAX_EMPTY;
537+
538+
if (order > 0)
539+
flags |= DAX_PMD;
540+
entry = dax_make_entry(pfn_to_pfn_t(0), flags);
527541
dax_lock_entry(xas, entry);
528542
if (xas_error(xas))
529543
goto out_unlock;
@@ -594,7 +608,7 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
594608
if (WARN_ON_ONCE(!xa_is_value(entry)))
595609
continue;
596610
if (unlikely(dax_is_locked(entry)))
597-
entry = get_unlocked_entry(&xas);
611+
entry = get_unlocked_entry(&xas, 0);
598612
if (entry)
599613
page = dax_busy_page(entry);
600614
put_unlocked_entry(&xas, entry);
@@ -621,7 +635,7 @@ static int __dax_invalidate_entry(struct address_space *mapping,
621635
void *entry;
622636

623637
xas_lock_irq(&xas);
624-
entry = get_unlocked_entry(&xas);
638+
entry = get_unlocked_entry(&xas, 0);
625639
if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
626640
goto out;
627641
if (!trunc &&
@@ -848,7 +862,7 @@ static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev,
848862
if (unlikely(dax_is_locked(entry))) {
849863
void *old_entry = entry;
850864

851-
entry = get_unlocked_entry(xas);
865+
entry = get_unlocked_entry(xas, 0);
852866

853867
/* Entry got punched out / reallocated? */
854868
if (!entry || WARN_ON_ONCE(!xa_is_value(entry)))
@@ -1509,7 +1523,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
15091523
* entry is already in the array, for instance), it will return
15101524
* VM_FAULT_FALLBACK.
15111525
*/
1512-
entry = grab_mapping_entry(&xas, mapping, DAX_PMD);
1526+
entry = grab_mapping_entry(&xas, mapping, PMD_ORDER);
15131527
if (xa_is_internal(entry)) {
15141528
result = xa_to_internal(entry);
15151529
goto fallback;
@@ -1658,11 +1672,10 @@ dax_insert_pfn_mkwrite(struct vm_fault *vmf, pfn_t pfn, unsigned int order)
16581672
vm_fault_t ret;
16591673

16601674
xas_lock_irq(&xas);
1661-
entry = get_unlocked_entry(&xas);
1675+
entry = get_unlocked_entry(&xas, order);
16621676
/* Did we race with someone splitting entry or so? */
1663-
if (!entry ||
1664-
(order == 0 && !dax_is_pte_entry(entry)) ||
1665-
(order == PMD_ORDER && !dax_is_pmd_entry(entry))) {
1677+
if (!entry || dax_is_conflict(entry) ||
1678+
(order == 0 && !dax_is_pte_entry(entry))) {
16661679
put_unlocked_entry(&xas, entry);
16671680
xas_unlock_irq(&xas);
16681681
trace_dax_insert_pfn_mkwrite_no_entry(mapping->host, vmf,

0 commit comments

Comments
 (0)