Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2866342rwb; Mon, 19 Sep 2022 11:08:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MyM6NgosMhfcJQHr6YtMv+ypxHRdcVTYan/NsE2KGhZBNgA4ETRt6b04w/v0sHqPcjLrK X-Received: by 2002:a17:90a:6c45:b0:202:7883:5239 with SMTP id x63-20020a17090a6c4500b0020278835239mr21168688pjj.225.1663610891243; Mon, 19 Sep 2022 11:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663610891; cv=none; d=google.com; s=arc-20160816; b=Rw8v0/ScLnwlHOiPxtbUx3jQkGdKEPiFGQdkgRv5eVac1XkfXm9phJe0rfcsXqtdCg i/h91+DI4NIbv0mTCwosliw5UvQSMiI5nK4Duzh7Qh/S/57yvZtC1jKNjLpGq7y94icE X+yKtTRWL4cYhUhqDmm2wFiNsDtDqQ5HT5r81HDl4l17+5DBgwsO67N03KWDmSFelIs9 gCzd683b6SB0V9CsypHiWUo9PHnNStWEvbpSZYJDEghwBAc5R1shbiwLtD2GA5jzKz5i Z3coc7mdNfvbFM+ATAoXcO63+hnAipmchtabnyhX9+SDTg5a/gnaiamEfZBkU9kuqvV+ x7Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=s3aQ3mNOXvUI82qCNmM4rRvK0fQP5iRzzY1v7eC67g8=; b=VXD48TTtnlfi6GDH4OC6JJrZDJOUrhjWP5A252f7qPypYmkmkf5klzKhZk97eleeDP 9cSwIQ2rWW/DFFyl2Prd130/Dt3UyvOdcDfsUcj8nTk63aEGFclDww0GCIpg7ca8YwS1 t6MjR24rDeFEtapph3jQ2eOk5Isx1gwrqhcryUTC134yu+GGripqTVMdAxxVo9N7TypH GkuA/P9glz9igspC5Odmet0+ZUuucrma4I788Cs+WxWgn9alIbm6t3HcHEsP4htIh0zU Ss+KYEwhfSPTFK6AcI4Qb0jOFrNceh0BkaZxc/qoaoH/Wrtnl8DvwXgiUGYIM3KSnR6K pGcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UfbeqgSB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e13-20020a170902ef4d00b001749d6132a7si31865323plx.251.2022.09.19.11.07.56; Mon, 19 Sep 2022 11:08:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UfbeqgSB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S229717AbiISQjm (ORCPT + 99 others); Mon, 19 Sep 2022 12:39:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbiISQjj (ORCPT ); Mon, 19 Sep 2022 12:39:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB692AE6 for ; Mon, 19 Sep 2022 09:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663605576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=s3aQ3mNOXvUI82qCNmM4rRvK0fQP5iRzzY1v7eC67g8=; b=UfbeqgSBkvwkC+2IHC5N1kKWQ40JkdFHF2mJ9/WXnpqqtrA2gpmIxYftM5Aeubl2GmyJf4 cVxvU/oWVWocEvFy1IZJKjtDcUpog8k1YWzDnbeSR7pjHrrz2SkXLLzgvSjYiwEKnUfVNA nYHozVHCNutFGzXNZxJwqQxCKuP5rUk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-59-thqDVXE3MCu2hUdXlspK_w-1; Mon, 19 Sep 2022 12:39:32 -0400 X-MC-Unique: thqDVXE3MCu2hUdXlspK_w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C9E685A59D; Mon, 19 Sep 2022 16:39:32 +0000 (UTC) Received: from raketa.redhat.com (unknown [10.40.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF71E492CA2; Mon, 19 Sep 2022 16:39:30 +0000 (UTC) From: Maurizio Lombardi To: vbabka@suse.cz Cc: linux-mm@kvack.org, rientjes@google.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, bigeasy@linutronix.de Subject: [PATCH V3] mm: slub: fix flush_cpu_slab()/__free_slab() invocations in task context. Date: Mon, 19 Sep 2022 18:39:29 +0200 Message-Id: <20220919163929.351068-1-mlombard@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 5a836bf6b09f ("mm: slub: move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context") moved all flush_cpu_slab() invocations to the global workqueue to avoid a problem related with deactivate_slab()/__free_slab() being called from an IRQ context on PREEMPT_RT kernels. When the flush_all_cpu_locked() function is called from a task context it may happen that a workqueue with WQ_MEM_RECLAIM bit set ends up flushing the global workqueue, this will cause a dependency issue. workqueue: WQ_MEM_RECLAIM nvme-delete-wq:nvme_delete_ctrl_work [nvme_core] is flushing !WQ_MEM_RECLAIM events:flush_cpu_slab WARNING: CPU: 37 PID: 410 at kernel/workqueue.c:2637 check_flush_dependency+0x10a/0x120 Workqueue: nvme-delete-wq nvme_delete_ctrl_work [nvme_core] RIP: 0010:check_flush_dependency+0x10a/0x120[ 453.262125] Call Trace: __flush_work.isra.0+0xbf/0x220 ? __queue_work+0x1dc/0x420 flush_all_cpus_locked+0xfb/0x120 __kmem_cache_shutdown+0x2b/0x320 kmem_cache_destroy+0x49/0x100 bioset_exit+0x143/0x190 blk_release_queue+0xb9/0x100 kobject_cleanup+0x37/0x130 nvme_fc_ctrl_free+0xc6/0x150 [nvme_fc] nvme_free_ctrl+0x1ac/0x2b0 [nvme_core] Fix this bug by creating a workqueue for the flush operation with the WQ_MEM_RECLAIM bit set. v2: Create a workqueue with WQ_MEM_RECLAIM instead of trying to revert the changes. v3: replace create_workqueue() with alloc_workqueue() and BUG_ON() with WARN_ON() Signed-off-by: Maurizio Lombardi --- mm/slub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 862dbd9af4f5..016da09608fb 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -310,6 +310,11 @@ static inline void stat(const struct kmem_cache *s, enum stat_item si) */ static nodemask_t slab_nodes; +/* + * Workqueue used for flush_cpu_slab(). + */ +static struct workqueue_struct *flushwq; + /******************************************************************** * Core slab cache functions *******************************************************************/ @@ -2730,7 +2735,7 @@ static void flush_all_cpus_locked(struct kmem_cache *s) INIT_WORK(&sfw->work, flush_cpu_slab); sfw->skip = false; sfw->s = s; - schedule_work_on(cpu, &sfw->work); + queue_work_on(cpu, flushwq, &sfw->work); } for_each_online_cpu(cpu) { @@ -4858,6 +4863,8 @@ void __init kmem_cache_init(void) void __init kmem_cache_init_late(void) { + flushwq = alloc_workqueue("slub_flushwq", WQ_MEM_RECLAIM, 0); + WARN_ON(!flushwq); } struct kmem_cache * -- 2.31.1