* [PATCH] fix crash on ocfs2_duplicate_clusters_by_page
@ 2018-08-29 7:47 Larry Chen
2018-08-29 22:25 ` Andrew Morton
0 siblings, 1 reply; 6+ messages in thread
From: Larry Chen @ 2018-08-29 7:47 UTC (permalink / raw)
To: mfasheh, jlbec; +Cc: linux-kernel, ocfs2-devel, akpm
ocfs2_duplicate_clusters_by_page may crash if one of extent's pages is dirty.
When a page has not been written back, it is still in dirty state. If
ocfs2_duplicate_clusters_by_page is called against the
dirty page, the crash happens.
To fix this bug, we can just unlock the page and wait the page until
it's not dirty.
The following is the buck trace dump:
kernel BUG at /root/code/ocfs2/refcounttree.c:2961!
[exception RIP: ocfs2_duplicate_clusters_by_page+822]
__ocfs2_move_extent+0x80/0x450 [ocfs2]
? __ocfs2_claim_clusters+0x130/0x250 [ocfs2]
ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2]
__ocfs2_move_extents_range+0x2a4/0x470 [ocfs2]
ocfs2_move_extents+0x180/0x3b0 [ocfs2]
? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2]
ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2]
ocfs2_ioctl+0x253/0x640 [ocfs2]
do_vfs_ioctl+0x90/0x5f0
SyS_ioctl+0x74/0x80
do_syscall_64+0x74/0x140
entry_SYSCALL_64_after_hwframe+0x3d/0xa2
Change-log:
1. Once we founce the page is dirty, we do not wait until it's clean,
but rather we use write_one_page to write it back
2. write_one_page arguments list changed, adjust and retest this patch.
Signed-off-by: Larry Chen <lchen@suse.com>
---
fs/ocfs2/refcounttree.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 7869622af22a..d6022e04c35a 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
if (map_end & (PAGE_SIZE - 1))
to = map_end & (PAGE_SIZE - 1);
+retry:
page = find_or_create_page(mapping, page_index, GFP_NOFS);
if (!page) {
ret = -ENOMEM;
@@ -2957,8 +2958,15 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
* In case PAGE_SIZE <= CLUSTER_SIZE, This page
* can't be dirtied before we CoW it out.
*/
- if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize)
- BUG_ON(PageDirty(page));
+ if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
+ if (PageDirty(page)) {
+ /*
+ * write_on_page will unlock the page on return
+ */
+ ret = write_one_page(page);
+ goto retry;
+ }
+ }
if (!PageUptodate(page)) {
ret = block_read_full_page(page, ocfs2_get_block);
--
2.13.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] fix crash on ocfs2_duplicate_clusters_by_page
2018-08-29 7:47 [PATCH] fix crash on ocfs2_duplicate_clusters_by_page Larry Chen
@ 2018-08-29 22:25 ` Andrew Morton
2018-08-30 2:29 ` [Ocfs2-devel] " Changwei Ge
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2018-08-29 22:25 UTC (permalink / raw)
To: Larry Chen; +Cc: mfasheh, jlbec, linux-kernel, ocfs2-devel
On Wed, 29 Aug 2018 15:47:40 +0800 Larry Chen <lchen@suse.com> wrote:
> ocfs2_duplicate_clusters_by_page may crash if one of extent's pages is dirty.
> When a page has not been written back, it is still in dirty state. If
> ocfs2_duplicate_clusters_by_page is called against the
> dirty page, the crash happens.
>
> To fix this bug, we can just unlock the page and wait the page until
> it's not dirty.
>
> The following is the buck trace dump:
>
> kernel BUG at /root/code/ocfs2/refcounttree.c:2961!
> [exception RIP: ocfs2_duplicate_clusters_by_page+822]
> __ocfs2_move_extent+0x80/0x450 [ocfs2]
> ? __ocfs2_claim_clusters+0x130/0x250 [ocfs2]
> ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2]
> __ocfs2_move_extents_range+0x2a4/0x470 [ocfs2]
> ocfs2_move_extents+0x180/0x3b0 [ocfs2]
> ? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2]
> ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2]
> ocfs2_ioctl+0x253/0x640 [ocfs2]
> do_vfs_ioctl+0x90/0x5f0
> SyS_ioctl+0x74/0x80
> do_syscall_64+0x74/0x140
> entry_SYSCALL_64_after_hwframe+0x3d/0xa2
>
> --- a/fs/ocfs2/refcounttree.c
> +++ b/fs/ocfs2/refcounttree.c
> @@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
> if (map_end & (PAGE_SIZE - 1))
> to = map_end & (PAGE_SIZE - 1);
>
> +retry:
> page = find_or_create_page(mapping, page_index, GFP_NOFS);
> if (!page) {
> ret = -ENOMEM;
> @@ -2957,8 +2958,15 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
> * In case PAGE_SIZE <= CLUSTER_SIZE, This page
> * can't be dirtied before we CoW it out.
> */
Looks sane, but the below change shows that the above comment is
untrue. Can we please update the comment as well?
> - if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize)
> - BUG_ON(PageDirty(page));
> + if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
> + if (PageDirty(page)) {
> + /*
> + * write_on_page will unlock the page on return
> + */
> + ret = write_one_page(page);
> + goto retry;
> + }
> + }
>
> if (!PageUptodate(page)) {
> ret = block_read_full_page(page, ocfs2_get_block);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Ocfs2-devel] [PATCH] fix crash on ocfs2_duplicate_clusters_by_page
2018-08-29 22:25 ` Andrew Morton
@ 2018-08-30 2:29 ` Changwei Ge
2018-08-30 2:40 ` Larry Chen
0 siblings, 1 reply; 6+ messages in thread
From: Changwei Ge @ 2018-08-30 2:29 UTC (permalink / raw)
To: Andrew Morton, Larry Chen; +Cc: mfasheh, ocfs2-devel, linux-kernel
Hi Larry,
Besides Andrew's comments, other parts of this patch look good to me.
Thanks,
Changwei
On 2018/8/30 6:25, Andrew Morton wrote:
> On Wed, 29 Aug 2018 15:47:40 +0800 Larry Chen <lchen@suse.com> wrote:
>
>> ocfs2_duplicate_clusters_by_page may crash if one of extent's pages is dirty.
>> When a page has not been written back, it is still in dirty state. If
>> ocfs2_duplicate_clusters_by_page is called against the
>> dirty page, the crash happens.
>>
>> To fix this bug, we can just unlock the page and wait the page until
>> it's not dirty.
>>
>> The following is the buck trace dump:
>>
>> kernel BUG at /root/code/ocfs2/refcounttree.c:2961!
>> [exception RIP: ocfs2_duplicate_clusters_by_page+822]
>> __ocfs2_move_extent+0x80/0x450 [ocfs2]
>> ? __ocfs2_claim_clusters+0x130/0x250 [ocfs2]
>> ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2]
>> __ocfs2_move_extents_range+0x2a4/0x470 [ocfs2]
>> ocfs2_move_extents+0x180/0x3b0 [ocfs2]
>> ? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2]
>> ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2]
>> ocfs2_ioctl+0x253/0x640 [ocfs2]
>> do_vfs_ioctl+0x90/0x5f0
>> SyS_ioctl+0x74/0x80
>> do_syscall_64+0x74/0x140
>> entry_SYSCALL_64_after_hwframe+0x3d/0xa2
>>
>> --- a/fs/ocfs2/refcounttree.c
>> +++ b/fs/ocfs2/refcounttree.c
>> @@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
>> if (map_end & (PAGE_SIZE - 1))
>> to = map_end & (PAGE_SIZE - 1);
>>
>> +retry:
>> page = find_or_create_page(mapping, page_index, GFP_NOFS);
>> if (!page) {
>> ret = -ENOMEM;
>> @@ -2957,8 +2958,15 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
>> * In case PAGE_SIZE <= CLUSTER_SIZE, This page
>> * can't be dirtied before we CoW it out.
>> */
> Looks sane, but the below change shows that the above comment is
> untrue. Can we please update the comment as well?
>
>
>> - if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize)
>> - BUG_ON(PageDirty(page));
>> + if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
>> + if (PageDirty(page)) {
>> + /*
>> + * write_on_page will unlock the page on return
>> + */
>> + ret = write_one_page(page);
>> + goto retry;
>> + }
>> + }
>>
>> if (!PageUptodate(page)) {
>> ret = block_read_full_page(page, ocfs2_get_block);
>
> _______________________________________________
> Ocfs2-devel mailing list
> Ocfs2-devel@oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/ocfs2-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Ocfs2-devel] [PATCH] fix crash on ocfs2_duplicate_clusters_by_page
2018-08-30 2:29 ` [Ocfs2-devel] " Changwei Ge
@ 2018-08-30 2:40 ` Larry Chen
0 siblings, 0 replies; 6+ messages in thread
From: Larry Chen @ 2018-08-30 2:40 UTC (permalink / raw)
To: Changwei Ge, Andrew Morton; +Cc: ocfs2-devel, linux-kernel
Hi Andrew and Changwei,
Thanks for your review, I'll propose a new version with comments corrected.
Thanks,
Larry
On 08/30/2018 10:29 AM, Changwei Ge wrote:
> Hi Larry,
>
> Besides Andrew's comments, other parts of this patch look good to me.
>
> Thanks,
>
> Changwei
>
>
> On 2018/8/30 6:25, Andrew Morton wrote:
>> On Wed, 29 Aug 2018 15:47:40 +0800 Larry Chen <lchen@suse.com> wrote:
>>
>>> ocfs2_duplicate_clusters_by_page may crash if one of extent's pages is dirty.
>>> When a page has not been written back, it is still in dirty state. If
>>> ocfs2_duplicate_clusters_by_page is called against the
>>> dirty page, the crash happens.
>>>
>>> To fix this bug, we can just unlock the page and wait the page until
>>> it's not dirty.
>>>
>>> The following is the buck trace dump:
>>>
>>> kernel BUG at /root/code/ocfs2/refcounttree.c:2961!
>>> [exception RIP: ocfs2_duplicate_clusters_by_page+822]
>>> __ocfs2_move_extent+0x80/0x450 [ocfs2]
>>> ? __ocfs2_claim_clusters+0x130/0x250 [ocfs2]
>>> ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2]
>>> __ocfs2_move_extents_range+0x2a4/0x470 [ocfs2]
>>> ocfs2_move_extents+0x180/0x3b0 [ocfs2]
>>> ? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2]
>>> ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2]
>>> ocfs2_ioctl+0x253/0x640 [ocfs2]
>>> do_vfs_ioctl+0x90/0x5f0
>>> SyS_ioctl+0x74/0x80
>>> do_syscall_64+0x74/0x140
>>> entry_SYSCALL_64_after_hwframe+0x3d/0xa2
>>>
>>> --- a/fs/ocfs2/refcounttree.c
>>> +++ b/fs/ocfs2/refcounttree.c
>>> @@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
>>> if (map_end & (PAGE_SIZE - 1))
>>> to = map_end & (PAGE_SIZE - 1);
>>>
>>> +retry:
>>> page = find_or_create_page(mapping, page_index, GFP_NOFS);
>>> if (!page) {
>>> ret = -ENOMEM;
>>> @@ -2957,8 +2958,15 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
>>> * In case PAGE_SIZE <= CLUSTER_SIZE, This page
>>> * can't be dirtied before we CoW it out.
>>> */
>> Looks sane, but the below change shows that the above comment is
>> untrue. Can we please update the comment as well?
>>
>>
>>> - if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize)
>>> - BUG_ON(PageDirty(page));
>>> + if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
>>> + if (PageDirty(page)) {
>>> + /*
>>> + * write_on_page will unlock the page on return
>>> + */
>>> + ret = write_one_page(page);
>>> + goto retry;
>>> + }
>>> + }
>>>
>>> if (!PageUptodate(page)) {
>>> ret = block_read_full_page(page, ocfs2_get_block);
>>
>> _______________________________________________
>> Ocfs2-devel mailing list
>> Ocfs2-devel@oss.oracle.com
>> https://oss.oracle.com/mailman/listinfo/ocfs2-devel
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] fix crash on ocfs2_duplicate_clusters_by_page
@ 2018-08-16 11:24 Larry Chen
0 siblings, 0 replies; 6+ messages in thread
From: Larry Chen @ 2018-08-16 11:24 UTC (permalink / raw)
To: mfasheh, jlbec; +Cc: linux-kernel, ocfs2-devel, akpm
ocfs2_duplicate_clusters_by_page may crash if an extent's page is dirty.
When a page has not been written back, it is still in dirty state. If at
that moment, ocfs2_duplicate_clusters_by_page is called against this
page, the crash happens.
To fix this bug, we can just unlock the page and wait the page until
it's not dirty.
I don't know whether the patch is appropriate, so I need comments,
thanks.
The following is the core dump:
kernel BUG at /root/code/ocfs2/refcounttree.c:2961!
__ocfs2_move_extent+0x80/0x450 [ocfs2]
? __ocfs2_claim_clusters+0x130/0x250 [ocfs2]
ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2]
__ocfs2_move_extents_range+0x2a4/0x470 [ocfs2]
ocfs2_move_extents+0x180/0x3b0 [ocfs2]
? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2]
ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2]
ocfs2_ioctl+0x253/0x640 [ocfs2]
do_vfs_ioctl+0x90/0x5f0
SyS_ioctl+0x74/0x80
do_syscall_64+0x74/0x140
entry_SYSCALL_64_after_hwframe+0x3d/0xa2
To: mfasheh@versity.com,
jlbec@evilplan.org
Cc: linux-kernel@vger.kernel.org,
ocfs2-devel@oss.oracle.com,
akpm@linux-foundation.org
Signed-off-by: Larry Chen <lchen@suse.com>
---
fs/ocfs2/refcounttree.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 7869622af22a..ee3b9dbbc310 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
if (map_end & (PAGE_SIZE - 1))
to = map_end & (PAGE_SIZE - 1);
+retry:
page = find_or_create_page(mapping, page_index, GFP_NOFS);
if (!page) {
ret = -ENOMEM;
@@ -2957,8 +2958,13 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
* In case PAGE_SIZE <= CLUSTER_SIZE, This page
* can't be dirtied before we CoW it out.
*/
- if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize)
- BUG_ON(PageDirty(page));
+ if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
+ if (PageDirty(page)) {
+ unlock_page(page);
+ cond_resched();
+ goto retry;
+ }
+ }
if (!PageUptodate(page)) {
ret = block_read_full_page(page, ocfs2_get_block);
--
2.13.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] fix crash on ocfs2_duplicate_clusters_by_page
@ 2018-08-16 11:18 Larry Chen
0 siblings, 0 replies; 6+ messages in thread
From: Larry Chen @ 2018-08-16 11:18 UTC (permalink / raw)
Cc: linux-kernel
ocfs2_duplicate_clusters_by_page may crash if an extent's page is dirty.
When a page has not been written back, it is still in dirty state. If at
that moment, ocfs2_duplicate_clusters_by_page is called against this
page, the crash happens.
To fix this bug, we can just unlock the page and wait the page until
it's not dirty.
I don't know whether the patch is appropriate, so I need comments,
thanks.
The following is the core dump:
kernel BUG at /root/code/ocfs2/refcounttree.c:2961!
__ocfs2_move_extent+0x80/0x450 [ocfs2]
? __ocfs2_claim_clusters+0x130/0x250 [ocfs2]
ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2]
__ocfs2_move_extents_range+0x2a4/0x470 [ocfs2]
ocfs2_move_extents+0x180/0x3b0 [ocfs2]
? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2]
ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2]
ocfs2_ioctl+0x253/0x640 [ocfs2]
do_vfs_ioctl+0x90/0x5f0
SyS_ioctl+0x74/0x80
do_syscall_64+0x74/0x140
entry_SYSCALL_64_after_hwframe+0x3d/0xa2
To: mfasheh@versity.com,
jlbec@evilplan.org
Cc: linux-kernel@vger.kernel.org,
ocfs2-devel@oss.oracle.com,
akpm@linux-foundation.org
Signed-off-by: Larry Chen <lchen@suse.com>
---
fs/ocfs2/refcounttree.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 7869622af22a..ee3b9dbbc310 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
if (map_end & (PAGE_SIZE - 1))
to = map_end & (PAGE_SIZE - 1);
+retry:
page = find_or_create_page(mapping, page_index, GFP_NOFS);
if (!page) {
ret = -ENOMEM;
@@ -2957,8 +2958,13 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
* In case PAGE_SIZE <= CLUSTER_SIZE, This page
* can't be dirtied before we CoW it out.
*/
- if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize)
- BUG_ON(PageDirty(page));
+ if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
+ if (PageDirty(page)) {
+ unlock_page(page);
+ cond_resched();
+ goto retry;
+ }
+ }
if (!PageUptodate(page)) {
ret = block_read_full_page(page, ocfs2_get_block);
--
2.13.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-08-30 2:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-29 7:47 [PATCH] fix crash on ocfs2_duplicate_clusters_by_page Larry Chen
2018-08-29 22:25 ` Andrew Morton
2018-08-30 2:29 ` [Ocfs2-devel] " Changwei Ge
2018-08-30 2:40 ` Larry Chen
-- strict thread matches above, loose matches on Subject: below --
2018-08-16 11:24 Larry Chen
2018-08-16 11:18 Larry Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).