linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zhaoyang Huang <huangzhaoyang@gmail.com>
To: Baoquan He <bhe@redhat.com>
Cc: Uladzislau Rezki <urezki@gmail.com>,
	"zhaoyang.huang" <zhaoyang.huang@unisoc.com>,
	 hailong liu <hailong.liu@oppo.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Christoph Hellwig <hch@infradead.org>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	 Thomas Gleixner <tglx@linutronix.de>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 steve.kang@unisoc.com
Subject: Re: [PATCHv3] mm: fix incorrect vbq reference in purge_fragmented_block
Date: Sun, 2 Jun 2024 19:02:28 +0800	[thread overview]
Message-ID: <CAGWkznGCF23_q1=d-oHY7QVqf+D7DM7ndN082Dy+X5JBeaYTgA@mail.gmail.com> (raw)
In-Reply-To: <ZlqIp9V1Jknm7axa@MiWiFi-R3L-srv>

On Sat, Jun 1, 2024 at 10:34 AM Baoquan He <bhe@redhat.com> wrote:
>
> On 05/31/24 at 10:04am, Uladzislau Rezki wrote:
> > On Fri, May 31, 2024 at 11:05:20AM +0800, 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")
> > >
> > > Suggested-by: Hailong.Liu <hailong.liu@oppo.com>
> > > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > >
> > Is a problem related to run out of vmalloc space _only_ or it is a problem
> > with broken list? From the commit message it is hard to follow the reason.
>
> This should fix the broken list.
>
> Hi Zhaoyang and Hailong,
>
> Could any of you test below patch in your testing environment?
>
> From b56dcc7d98c4dbb7ea197516bd129c30c0e9d1ef Mon Sep 17 00:00:00 2001
> From: Baoquan He <bhe@redhat.com>
> Date: Fri, 31 May 2024 23:44:57 +0800
> Subject: [PATCH] mm/vmalloc.c: add vb into appropriate vbq->free
> Content-type: text/plain
>
> The current vbq is organized into per-cpu data structure, including a xa
> and list. However, its adding into vba->free list is not handled
> correctly. The new vmap_block allocation could be done in one cpu, while
> it's actually belong into anohter cpu's percpu vbq. Then the
> list_for_each_entry_rcu() on the vbq->free and its deletion could cause
> list breakage.
>
> This fix the wrong vb adding to make it be added into expected
> vba->free.
>
> Signed-off-by: Baoquan He <bhe@redhat.com>
> ---
>  mm/vmalloc.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index b921baf0ef8a..47659b41259a 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2547,6 +2547,14 @@ addr_to_vb_xa(unsigned long addr)
>         return &per_cpu(vmap_block_queue, index).vmap_blocks;
>  }
>
> +static struct vmap_block_queue *
> +addr_to_vbq(unsigned long addr)
> +{
> +       int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus();
> +
> +       return &per_cpu(vmap_block_queue, index);
> +}
emm, I am wondering if it make sense to add addr to vbp[CPU1] from
CPU0 etc which is against per_cpu variable's goal?
> +
>  /*
>   * We should probably have a fallback mechanism to allocate virtual memory
>   * out of partially filled vmap blocks. However vmap block sizing should be
> @@ -2626,7 +2634,7 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
>                 return ERR_PTR(err);
>         }
>
> -       vbq = raw_cpu_ptr(&vmap_block_queue);
> +       vbq = addr_to_vbq(va->va_start);

>         spin_lock(&vbq->lock);
>         list_add_tail_rcu(&vb->free_list, &vbq->free);
>         spin_unlock(&vbq->lock);
> --
> 2.41.0
>


      reply	other threads:[~2024-06-02 11:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  3:05 zhaoyang.huang
2024-05-31  3:23 ` hailong liu
2024-05-31  8:04 ` Uladzislau Rezki
2024-05-31  8:53   ` hailong liu
2024-05-31  9:11   ` Zhaoyang Huang
2024-05-31  9:55     ` Barry Song
2024-05-31 10:17       ` Zhaoyang Huang
2024-05-31 10:52         ` hailong liu
2024-05-31 10:03   ` Baoquan He
2024-05-31 10:44   ` Hillf Danton
2024-05-31 10:57     ` Hailong Liu
2024-06-01  2:34   ` Baoquan He
2024-06-02 11:02     ` 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='CAGWkznGCF23_q1=d-oHY7QVqf+D7DM7ndN082Dy+X5JBeaYTgA@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