From: Dan Williams <dan.j.williams@intel.com> To: linux-nvdimm@lists.01.org Cc: linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>, linux-kernel@vger.kernel.org, Matthew Wilcox <willy@infradead.org> Subject: [PATCH] dax: Fix Xarray conversion of dax_unlock_mapping_entry() Date: Thu, 29 Nov 2018 16:13:46 -0800 [thread overview] Message-ID: <154353682674.1676897.15440708268545845062.stgit@dwillia2-desk3.amr.corp.intel.com> (raw) Internal to dax_unlock_mapping_entry(), dax_unlock_entry() is used to store a replacement entry in the Xarray at the given xas-index with the DAX_LOCKED bit clear. When called, dax_unlock_entry() expects the unlocked value of the entry relative to the current Xarray state to be specified. In most contexts dax_unlock_entry() is operating in the same scope as the matched dax_lock_entry(). However, in the dax_unlock_mapping_entry() case the implementation needs to recall the original entry. In the case where the original entry is a 'pmd' entry it is possible that the pfn performed to do the lookup is misaligned to the value retrieved in the Xarray. When creating the 'unlocked' entry be sure to align it to the expected size as reflected by the DAX_PMD flag. Otherwise, future lookups become confused by finding a 'pte' aligned value at an index that should return a 'pmd' aligned value. This mismatch results in failure signatures like the following: WARNING: CPU: 38 PID: 1396 at fs/dax.c:340 dax_insert_entry+0x2b2/0x2d0 RIP: 0010:dax_insert_entry+0x2b2/0x2d0 [..] Call Trace: dax_iomap_pte_fault.isra.41+0x791/0xde0 ext4_dax_huge_fault+0x16f/0x1f0 ? up_read+0x1c/0xa0 __do_fault+0x1f/0x160 __handle_mm_fault+0x1033/0x1490 handle_mm_fault+0x18b/0x3d0 ...and potential corruption of nearby page state as housekeeping routines, like dax_disassociate_entry(), may overshoot their expected bounds starting at the wrong page. Cc: Matthew Wilcox <willy@infradead.org> Cc: Jan Kara <jack@suse.cz> Fixes: 9f32d221301c ("dax: Convert dax_lock_mapping_entry to XArray") Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- fs/dax.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 3f592dc18d67..6c5f8f345b1a 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -59,6 +59,7 @@ static inline unsigned int pe_order(enum page_entry_size pe_size) /* The order of a PMD entry */ #define PMD_ORDER (PMD_SHIFT - PAGE_SHIFT) +#define PMD_ORDER_MASK ~((1UL << PMD_ORDER) - 1) static wait_queue_head_t wait_table[DAX_WAIT_TABLE_ENTRIES]; @@ -93,9 +94,13 @@ static unsigned long dax_to_pfn(void *entry) return xa_to_value(entry) >> DAX_SHIFT; } -static void *dax_make_entry(pfn_t pfn, unsigned long flags) +static void *dax_make_entry(pfn_t pfn_t, unsigned long flags) { - return xa_mk_value(flags | (pfn_t_to_pfn(pfn) << DAX_SHIFT)); + unsigned long pfn = pfn_t_to_pfn(pfn_t); + + if (flags & DAX_PMD) + pfn &= PMD_ORDER_MASK; + return xa_mk_value(flags | (pfn << DAX_SHIFT)); } static bool dax_is_locked(void *entry) _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm
WARNING: multiple messages have this Message-ID (diff)
From: Dan Williams <dan.j.williams@intel.com> To: linux-nvdimm@lists.01.org Cc: Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] dax: Fix Xarray conversion of dax_unlock_mapping_entry() Date: Thu, 29 Nov 2018 16:13:46 -0800 [thread overview] Message-ID: <154353682674.1676897.15440708268545845062.stgit@dwillia2-desk3.amr.corp.intel.com> (raw) Internal to dax_unlock_mapping_entry(), dax_unlock_entry() is used to store a replacement entry in the Xarray at the given xas-index with the DAX_LOCKED bit clear. When called, dax_unlock_entry() expects the unlocked value of the entry relative to the current Xarray state to be specified. In most contexts dax_unlock_entry() is operating in the same scope as the matched dax_lock_entry(). However, in the dax_unlock_mapping_entry() case the implementation needs to recall the original entry. In the case where the original entry is a 'pmd' entry it is possible that the pfn performed to do the lookup is misaligned to the value retrieved in the Xarray. When creating the 'unlocked' entry be sure to align it to the expected size as reflected by the DAX_PMD flag. Otherwise, future lookups become confused by finding a 'pte' aligned value at an index that should return a 'pmd' aligned value. This mismatch results in failure signatures like the following: WARNING: CPU: 38 PID: 1396 at fs/dax.c:340 dax_insert_entry+0x2b2/0x2d0 RIP: 0010:dax_insert_entry+0x2b2/0x2d0 [..] Call Trace: dax_iomap_pte_fault.isra.41+0x791/0xde0 ext4_dax_huge_fault+0x16f/0x1f0 ? up_read+0x1c/0xa0 __do_fault+0x1f/0x160 __handle_mm_fault+0x1033/0x1490 handle_mm_fault+0x18b/0x3d0 ...and potential corruption of nearby page state as housekeeping routines, like dax_disassociate_entry(), may overshoot their expected bounds starting at the wrong page. Cc: Matthew Wilcox <willy@infradead.org> Cc: Jan Kara <jack@suse.cz> Fixes: 9f32d221301c ("dax: Convert dax_lock_mapping_entry to XArray") Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- fs/dax.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 3f592dc18d67..6c5f8f345b1a 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -59,6 +59,7 @@ static inline unsigned int pe_order(enum page_entry_size pe_size) /* The order of a PMD entry */ #define PMD_ORDER (PMD_SHIFT - PAGE_SHIFT) +#define PMD_ORDER_MASK ~((1UL << PMD_ORDER) - 1) static wait_queue_head_t wait_table[DAX_WAIT_TABLE_ENTRIES]; @@ -93,9 +94,13 @@ static unsigned long dax_to_pfn(void *entry) return xa_to_value(entry) >> DAX_SHIFT; } -static void *dax_make_entry(pfn_t pfn, unsigned long flags) +static void *dax_make_entry(pfn_t pfn_t, unsigned long flags) { - return xa_mk_value(flags | (pfn_t_to_pfn(pfn) << DAX_SHIFT)); + unsigned long pfn = pfn_t_to_pfn(pfn_t); + + if (flags & DAX_PMD) + pfn &= PMD_ORDER_MASK; + return xa_mk_value(flags | (pfn << DAX_SHIFT)); } static bool dax_is_locked(void *entry)
next reply other threads:[~2018-11-30 0:26 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-11-30 0:13 Dan Williams [this message] 2018-11-30 0:13 ` [PATCH] dax: Fix Xarray conversion of dax_unlock_mapping_entry() Dan Williams 2018-11-30 15:49 ` Matthew Wilcox 2018-11-30 15:49 ` Matthew Wilcox 2018-11-30 15:54 ` Dan Williams 2018-11-30 15:54 ` Dan Williams 2018-11-30 16:24 ` Matthew Wilcox 2018-11-30 16:24 ` Matthew Wilcox 2018-11-30 16:33 ` Dan Williams 2018-11-30 16:33 ` Dan Williams 2018-11-30 17:01 ` Dan Williams 2018-11-30 17:01 ` Dan Williams 2018-11-30 19:50 ` Matthew Wilcox 2018-11-30 19:50 ` Matthew Wilcox 2018-11-30 19:50 ` Matthew Wilcox 2018-11-30 20:05 ` Dan Williams 2018-11-30 20:05 ` Dan Williams 2018-12-04 3:33 ` Dan Williams 2018-12-04 3:33 ` Dan Williams 2018-12-05 1:34 ` Matthew Wilcox 2018-12-05 1:34 ` Matthew Wilcox 2018-12-05 6:11 ` Dan Williams 2018-12-05 9:22 ` Jan Kara 2018-12-05 9:22 ` Jan Kara
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=154353682674.1676897.15440708268545845062.stgit@dwillia2-desk3.amr.corp.intel.com \ --to=dan.j.williams@intel.com \ --cc=jack@suse.cz \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-nvdimm@lists.01.org \ --cc=willy@infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.