提交 1571c029 编写于 作者: J Jan Kara 提交者: Dan Williams

dax: Fix xarray entry association for mixed mappings

When inserting entry into xarray, we store mapping and index in
corresponding struct pages for memory error handling. When it happened
that one process was mapping file at PMD granularity while another
process at PTE granularity, we could wrongly deassociate PMD range and
then reassociate PTE range leaving the rest of struct pages in PMD range
without mapping information which could later cause missed notifications
about memory errors. Fix the problem by calling the association /
deassociation code if and only if we are really going to update the
xarray (deassociating and associating zero or empty entries is just
no-op so there's no reason to complicate the code with trying to avoid
the calls for these cases).

Cc: <stable@vger.kernel.org>
Fixes: d2c997c0 ("fs, dax: use page->mapping to warn if truncate...")
Signed-off-by: NJan Kara <jack@suse.cz>
Signed-off-by: NDan Williams <dan.j.williams@intel.com>
上级 f2c7c76c
...@@ -728,12 +728,11 @@ static void *dax_insert_entry(struct xa_state *xas, ...@@ -728,12 +728,11 @@ static void *dax_insert_entry(struct xa_state *xas,
xas_reset(xas); xas_reset(xas);
xas_lock_irq(xas); xas_lock_irq(xas);
if (dax_entry_size(entry) != dax_entry_size(new_entry)) { if (dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) {
void *old;
dax_disassociate_entry(entry, mapping, false); dax_disassociate_entry(entry, mapping, false);
dax_associate_entry(new_entry, mapping, vmf->vma, vmf->address); dax_associate_entry(new_entry, mapping, vmf->vma, vmf->address);
}
if (dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) {
/* /*
* Only swap our new entry into the page cache if the current * Only swap our new entry into the page cache if the current
* entry is a zero page or an empty entry. If a normal PTE or * entry is a zero page or an empty entry. If a normal PTE or
...@@ -742,7 +741,7 @@ static void *dax_insert_entry(struct xa_state *xas, ...@@ -742,7 +741,7 @@ static void *dax_insert_entry(struct xa_state *xas,
* existing entry is a PMD, we will just leave the PMD in the * existing entry is a PMD, we will just leave the PMD in the
* tree and dirty it if necessary. * tree and dirty it if necessary.
*/ */
void *old = dax_lock_entry(xas, new_entry); old = dax_lock_entry(xas, new_entry);
WARN_ON_ONCE(old != xa_mk_value(xa_to_value(entry) | WARN_ON_ONCE(old != xa_mk_value(xa_to_value(entry) |
DAX_LOCKED)); DAX_LOCKED));
entry = new_entry; entry = new_entry;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册