linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zhaoyang Huang <huangzhaoyang@gmail.com>
To: hailong liu <hailong.liu@oppo.com>
Cc: "zhaoyang.huang" <zhaoyang.huang@unisoc.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Uladzislau Rezki <urezki@gmail.com>,
	Christoph Hellwig <hch@infradead.org>,
	 Lorenzo Stoakes <lstoakes@gmail.com>,
	Baoquan He <bhe@redhat.com>,
	 Thomas Gleixner <tglx@linutronix.de>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 steve.kang@unisoc.com
Subject: Re: [PATCHv2] mm: fix incorrect vbq reference in purge_fragmented_block
Date: Fri, 31 May 2024 09:40:01 +0800	[thread overview]
Message-ID: <CAGWkznHdbC_RJWYonKkHXpma+ioi7aRn+pDMnQBr=3KpsN8MkA@mail.gmail.com> (raw)
In-Reply-To: <20240531012718.ogitylhpsrrvvczo@oppo.com>

On Fri, May 31, 2024 at 9:27 AM hailong liu <hailong.liu@oppo.com> wrote:
>
> On Fri, 31. May 08:50, zhaoyang.huang wrote:
> > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> >
> > vmalloc area runs out in our ARM64 system during an erofs test as
> > vm_map_ram failed[1]. By following the debug log, we find that
> > vm_map_ram()->vb_alloc() will allocate new vb->va which corresponding
> > to 4MB vmalloc area as list_for_each_entry_rcu returns immediately
> > when vbq->free->next points to vbq->free. That is to say, 65536 times
> > of page fault after the list's broken will run out of the whole
> > vmalloc area. This should be introduced by one vbq->free->next point to
> > vbq->free which makes list_for_each_entry_rcu can not iterate the list
> > and find the BUG.
> >
> > [1]
> > PID: 1        TASK: ffffff80802b4e00  CPU: 6    COMMAND: "init"
> >  #0 [ffffffc08006afe0] __switch_to at ffffffc08111d5cc
> >  #1 [ffffffc08006b040] __schedule at ffffffc08111dde0
> >  #2 [ffffffc08006b0a0] schedule at ffffffc08111e294
> >  #3 [ffffffc08006b0d0] schedule_preempt_disabled at ffffffc08111e3f0
> >  #4 [ffffffc08006b140] __mutex_lock at ffffffc08112068c
> >  #5 [ffffffc08006b180] __mutex_lock_slowpath at ffffffc08111f8f8
> >  #6 [ffffffc08006b1a0] mutex_lock at ffffffc08111f834
> >  #7 [ffffffc08006b1d0] reclaim_and_purge_vmap_areas at ffffffc0803ebc3c
> >  #8 [ffffffc08006b290] alloc_vmap_area at ffffffc0803e83fc
> >  #9 [ffffffc08006b300] vm_map_ram at ffffffc0803e78c0
> >
> > Fixes: fc1e0d980037 ("mm/vmalloc: prevent stale TLBs in fully utilized blocks")
> >
> > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > ---
> > v2: introduce cpu in vmap_block to record the right CPU number
> > ---
> > ---
> >  mm/vmalloc.c | 11 +++++++----
> >  1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 22aa63f4ef63..ca962b554fa0 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -2458,6 +2458,7 @@ struct vmap_block {
> >       struct list_head free_list;
> >       struct rcu_head rcu_head;
> >       struct list_head purge;
> > +     unsigned int cpu;
> >  };
> >
> >  /* Queue of free and dirty vmap blocks, for allocation and flushing purposes */
> > @@ -2574,6 +2575,7 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
> >       vb->dirty = 0;
> >       vb->dirty_min = VMAP_BBMAP_BITS;
> >       vb->dirty_max = 0;
> if task migration to other CPU at this time, this may lead to get incorrect vbq.
ok, thanks for the prompt. If this works?
    vb->cpu =get_cpu();
    ...
    put_cpu();
    return vaddr;

> > +     vb->cpu = smp_processor_id();
> >       bitmap_set(vb->used_map, 0, (1UL << order));
> >       INIT_LIST_HEAD(&vb->free_list);
> >
> > @@ -2614,9 +2616,10 @@ static void free_vmap_block(struct vmap_block *vb)
> >  }
> >
> >  static bool purge_fragmented_block(struct vmap_block *vb,
> > -             struct vmap_block_queue *vbq, struct list_head *purge_list,
> > -             bool force_purge)
> > +             struct list_head *purge_list, bool force_purge)
> >  {
> > +     struct vmap_block_queue *vbq = &per_cpu(vmap_block_queue, vb->cpu);
> > +
> >       if (vb->free + vb->dirty != VMAP_BBMAP_BITS ||
> >           vb->dirty == VMAP_BBMAP_BITS)
> >               return false;
> > @@ -2664,7 +2667,7 @@ static void purge_fragmented_blocks(int cpu)
> >                       continue;
> >
> >               spin_lock(&vb->lock);
> > -             purge_fragmented_block(vb, vbq, &purge, true);
> > +             purge_fragmented_block(vb, &purge, true);
> >               spin_unlock(&vb->lock);
> >       }
> >       rcu_read_unlock();
> > @@ -2801,7 +2804,7 @@ static void _vm_unmap_aliases(unsigned long start, unsigned long end, int flush)
> >                        * not purgeable, check whether there is dirty
> >                        * space to be flushed.
> >                        */
> > -                     if (!purge_fragmented_block(vb, vbq, &purge_list, false) &&
> > +                     if (!purge_fragmented_block(vb, &purge_list, false) &&
> >                           vb->dirty_max && vb->dirty != VMAP_BBMAP_BITS) {
> >                               unsigned long va_start = vb->va->va_start;
> >                               unsigned long s, e;
> > --
> > 2.25.1
> >
> >
>
> --
>
> Best Regards,
> Hailong.


      reply	other threads:[~2024-05-31  1:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  0:50 zhaoyang.huang
2024-05-31  1:27 ` hailong liu
2024-05-31  1:40   ` Zhaoyang Huang [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='CAGWkznHdbC_RJWYonKkHXpma+ioi7aRn+pDMnQBr=3KpsN8MkA@mail.gmail.com' \
    --to=huangzhaoyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=hailong.liu@oppo.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=steve.kang@unisoc.com \
    --cc=tglx@linutronix.de \
    --cc=urezki@gmail.com \
    --cc=zhaoyang.huang@unisoc.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