Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1542870pxk; Fri, 25 Sep 2020 18:44:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxT6J23PJ3W63UxsOXcMtO6S/L+OHtup2cRb2XHMNpehlnN6Fbd2w6a8yNsZM6KRWhDW3OM X-Received: by 2002:a05:6402:1503:: with SMTP id f3mr4539440edw.307.1601084666547; Fri, 25 Sep 2020 18:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601084666; cv=none; d=google.com; s=arc-20160816; b=oNbRgV8SQDkq9U3YjHl4QVs2jE8x4vn8bRZnEs64S86TtD3BfQ86NryRhmG+Y35EOd rGhufkxDTeZ6LveDzCVAdUe50QgWVl6TgKbIRWNsIMP6ek4y0BW35oJ18MQ1PnwXx1DT fHuodAOnUqBeNI8A5/pB6S8eUF5XanltQnDy0hXjOGe9M9qb6irmUpdFjy/cWEHN0rCM o2T0ao2Vv+y6nh80f2a+BTz31aaWgFu9+0f4sm6PbqN6BCsIRqav8irzoX0d2qI5aZhC cCDWFlAa4SyX50ly2yj1+4ZlQdMjnXZbtlSp6+2jofiACT+Hy0+Fiye+8yI/CMw19wRZ A4fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=anuXvW7DT2NGfM0wi3fUi3pbzDhxv6S3wuJYHpV9+T8=; b=SVITEiF0BwQu1GCZ3MFgrXCGjZs7Xb6bltD33I468GPF0HCdl0QGB+ykRnwO1f/cy9 Z+JPQ4lri95FNJxxTzjODfhFu0EyPsj8xasVlqSgKSxOYfxrsHcrAztBtkmG7qDF8wUL hMwHCRQdxrZ2QCos9y6LZv7vKxVosjm0f2y8xGK+sfl+tYiDEie4ZFRtUrv1ShPv2sqj 86o6y98bkMa0/LIoipetvy1YSodpMOwOC2rjplBztjI7YyhfR+1oSVfT6dSUkp6lsh5f OCsk0oOw8qc8t6SU5sQAmjaxRzKZyth7K5DI0nRnJ+yQTXJZ1sLWXbmdJrxSTQZfP46L yNHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EU0gZ+3e; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si3175493edq.182.2020.09.25.18.43.47; Fri, 25 Sep 2020 18:44:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EU0gZ+3e; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728974AbgIZBno (ORCPT + 99 others); Fri, 25 Sep 2020 21:43:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60300 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728967AbgIZBno (ORCPT ); Fri, 25 Sep 2020 21:43:44 -0400 Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601084623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=anuXvW7DT2NGfM0wi3fUi3pbzDhxv6S3wuJYHpV9+T8=; b=EU0gZ+3ei23xvRE7eIJx8jJLkutPGQzDWfKK8ztmlTz/BzdzHeeEC9IEkKos0yu83pzWuH tJ+sPTC9aU8EuPzj1ASm+6/JlARwwntNZUWNRavavyz/Bv/Us20Q6ZxhHSx5ubVHGHGDHb 2eqgGgrIlsIsa6hwz7SoGFZijsvnjPg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-53-3ub8DGkqMci6FOxNU-m3_g-1; Fri, 25 Sep 2020 21:43:41 -0400 X-MC-Unique: 3ub8DGkqMci6FOxNU-m3_g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFBE910066FC; Sat, 26 Sep 2020 01:43:38 +0000 (UTC) Received: from T590 (ovpn-12-20.pek2.redhat.com [10.72.12.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E771373662; Sat, 26 Sep 2020 01:43:29 +0000 (UTC) Date: Sat, 26 Sep 2020 09:43:25 +0800 From: Ming Lei To: Shakeel Butt Cc: Roman Gushchin , Johannes Weiner , Andrew Morton , Linus Torvalds , "Theodore Y . Ts'o" , Jens Axboe , Ext4 Developers List , linux-block , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: REGRESSION: 37f4a24c2469: blk-mq: centralise related handling into blk_mq_get_driver_tag Message-ID: <20200926014325.GA2516054@T590> References: <20200925191902.543953-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200925191902.543953-1-shakeelb@google.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Sep 25, 2020 at 12:19:02PM -0700, Shakeel Butt wrote: > On Fri, Sep 25, 2020 at 10:58 AM Shakeel Butt > wrote: > > > [snip] > > > > I don't think you can ignore the flushing. The __free_once() in > > ___cache_free() assumes there is a space available. > > > > BTW do_drain() also have the same issue. > > > > Why not move slabs_destroy() after we update ac->avail and memmove()? > > Ming, can you please try the following patch? > > > From: Shakeel Butt > > [PATCH] mm: slab: fix potential infinite recursion in ___cache_free > > With the commit 10befea91b61 ("mm: memcg/slab: use a single set of > kmem_caches for all allocations"), it becomes possible to call kfree() > from the slabs_destroy(). However if slabs_destroy() is being called for > the array_cache of the local CPU then this opens the potential scenario > of infinite recursion because kfree() called from slabs_destroy() can > call slabs_destroy() with the same array_cache of the local CPU. Since > the array_cache of the local CPU is not updated before calling > slabs_destroy(), it will try to free the same pages. > > To fix the issue, simply update the cache before calling > slabs_destroy(). > > Signed-off-by: Shakeel Butt > --- > mm/slab.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/mm/slab.c b/mm/slab.c > index 3160dff6fd76..f658e86ec8ce 100644 > --- a/mm/slab.c > +++ b/mm/slab.c > @@ -1632,6 +1632,10 @@ static void slab_destroy(struct kmem_cache *cachep, struct page *page) > kmem_cache_free(cachep->freelist_cache, freelist); > } > > +/* > + * Update the size of the caches before calling slabs_destroy as it may > + * recursively call kfree. > + */ > static void slabs_destroy(struct kmem_cache *cachep, struct list_head *list) > { > struct page *page, *n; > @@ -2153,8 +2157,8 @@ static void do_drain(void *arg) > spin_lock(&n->list_lock); > free_block(cachep, ac->entry, ac->avail, node, &list); > spin_unlock(&n->list_lock); > - slabs_destroy(cachep, &list); > ac->avail = 0; > + slabs_destroy(cachep, &list); > } > > static void drain_cpu_caches(struct kmem_cache *cachep) > @@ -3402,9 +3406,9 @@ static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac) > } > #endif > spin_unlock(&n->list_lock); > - slabs_destroy(cachep, &list); > ac->avail -= batchcount; > memmove(ac->entry, &(ac->entry[batchcount]), sizeof(void *)*ac->avail); > + slabs_destroy(cachep, &list); > } The issue can't be reproduced after applying this patch: Tested-by: Ming Lei Thanks, Ming