mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: Chao Yu <yuchao0@huawei.com>,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: check sit bitmap under sentry_lock
Date: Wed, 15 Nov 2017 08:30:40 -0800	[thread overview]
Message-ID: <20171115163040.GD33528@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <126ac734-9ff4-8b27-ea0b-386f0caaff55@kernel.org>

On 11/15, Chao Yu wrote:
> Hi Jaegeuk,
> 
> Please drop this patch first, as it still can trigger deadlock as below, sorry
> about this mistake.

Got it. Thank you.

> 
> - f2fs_put_super
>  - f2fs_wait_discard_bios
>   - __issue_discard_cmd
>    - lock(&dcc->cmd_lock);		A
>    - __check_sit_bitmap
>     - down_read(&sit_i->sentry_lock)	B
> 
> - do_write_page
>  - allocate_data_block
>   - down_write(&sit_i->sentry_lock)	B
>   - locate_dirty_segment
>    - lock(&dirty_i->seglist_lock)	C
> 
> - write_checkpoint
>  - clear_prefree_segments
>   - lock(&dirty_i->seglist_lock)	C
>    - f2fs_issue_discard
>     - __issue_discard_async
>      - __queue_discard_cmd
>       - __update_discard_tree_range
>        - lock(&dcc->cmd_lock)		A
> 
> Thanks,
> 
> On 2017/11/13 17:54, Chao Yu wrote:
> > This patch protects sit bitmap accessing in __check_sit_bitmap with
> > sentry_lock, meanwhile, in allocate_data_block, f2fs_wait_discard_bio
> > will not access/update sit cache, let's exclude it from sentry_lock's
> > region.>
> > Signed-off-by: Chao Yu <yuchao0@huawei.com>
> > ---
> >  fs/f2fs/segment.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > index c117e0913f2a..464696b1612a 100644
> > --- a/fs/f2fs/segment.c
> > +++ b/fs/f2fs/segment.c
> > @@ -894,6 +894,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
> >  	unsigned long offset, size, max_blocks = sbi->blocks_per_seg;
> >  	unsigned long *map;
> >  
> > +	down_read(&SIT_I(sbi)->sentry_lock);
> > +
> >  	while (blk < end) {
> >  		segno = GET_SEGNO(sbi, blk);
> >  		sentry = get_seg_entry(sbi, segno);
> > @@ -908,6 +910,8 @@ void __check_sit_bitmap(struct f2fs_sb_info *sbi,
> >  		f2fs_bug_on(sbi, offset != size);
> >  		blk = START_BLOCK(sbi, segno + 1);
> >  	}
> > +
> > +	up_read(&SIT_I(sbi)->sentry_lock);
> >  #endif
> >  }
> >  
> > @@ -2527,12 +2531,13 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
> >  	down_read(&SM_I(sbi)->curseg_lock);
> >  
> >  	mutex_lock(&curseg->curseg_mutex);
> > -	down_write(&sit_i->sentry_lock);
> >  
> >  	*new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
> >  
> >  	f2fs_wait_discard_bio(sbi, *new_blkaddr);
> >  
> > +	down_write(&sit_i->sentry_lock);
> > +
> >  	/*
> >  	 * __add_sum_entry should be resided under the curseg_mutex
> >  	 * because, this function updates a summary entry in the
> > 

      reply	other threads:[~2017-11-15 16:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13  9:54 Chao Yu
2017-11-15 12:33 ` Chao Yu
2017-11-15 16:30   ` Jaegeuk Kim [this message]

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=20171115163040.GD33528@jaegeuk-macbookpro.roam.corp.google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.com \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®