From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3F93C25B06 for ; Mon, 15 Aug 2022 14:02:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44B628D0002; Mon, 15 Aug 2022 10:02:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FAEE8D0001; Mon, 15 Aug 2022 10:02:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D02F8D0002; Mon, 15 Aug 2022 10:02:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1BD428D0001 for ; Mon, 15 Aug 2022 10:02:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D455B120F0D for ; Mon, 15 Aug 2022 14:02:24 +0000 (UTC) X-FDA: 79801991808.23.EC626EF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 43CF6C01A6 for ; Mon, 15 Aug 2022 14:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660572134; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lXDAAl+x9MWatG+p/VTcB+8mkDyPasS5scLcX2zyIyQ=; b=TvzVGGxy6wBroF3HDpgZMez/tbQQQZTYsEag4ryuBK25x3MLKX7AlAoHWZZWvDap1ezigE ZRBuMRqG+2fwVxzBQWR99AX+1EbZKHSO+Qn0H5IZI5bitw2aN+dAAD2HNA64zjdmA7wIOE 1rL9w2mJZEiHB4qXRUWqWJVYPKC1/Zo= 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-665-uMEmCIL0Nzqvc952K71zXw-1; Mon, 15 Aug 2022 10:02:11 -0400 X-MC-Unique: uMEmCIL0Nzqvc952K71zXw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 663A880600D; Mon, 15 Aug 2022 14:01:51 +0000 (UTC) Received: from [10.18.17.215] (dhcp-17-215.bos.redhat.com [10.18.17.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14A94140EBE3; Mon, 15 Aug 2022 14:01:51 +0000 (UTC) Message-ID: Date: Mon, 15 Aug 2022 10:01:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3] mm/slab_common: Deleting kobject in kmem_cache_destroy() without holding slab_mutex/cpu_hotplug_lock Content-Language: en-US To: Roman Gushchin Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220812183033.346425-1-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 43CF6C01A6 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TvzVGGxy; spf=pass (imf22.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com X-Stat-Signature: auicw9mfqkryidq49t7gozegapw7z931 X-HE-Tag: 1660572135-351167 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 8/13/22 14:25, Roman Gushchin wrote: > On Fri, Aug 12, 2022 at 02:30:33PM -0400, Waiman Long wrote: >> A circular locking problem is reported by lockdep due to the following >> circular locking dependency. >> >> +--> cpu_hotplug_lock --> slab_mutex --> kn->active --+ >> | | >> +-----------------------------------------------------+ >> >> The forward cpu_hotplug_lock ==> slab_mutex ==> kn->active dependency >> happens in >> >> kmem_cache_destroy(): cpus_read_lock(); mutex_lock(&slab_mutex); >> ==> sysfs_slab_unlink() >> ==> kobject_del() >> ==> kernfs_remove() >> ==> __kernfs_remove() >> ==> kernfs_drain(): rwsem_acquire(&kn->dep_map, ...); >> >> The backward kn->active ==> cpu_hotplug_lock dependency happens in >> >> kernfs_fop_write_iter(): kernfs_get_active(); >> ==> slab_attr_store() >> ==> cpu_partial_store() >> ==> flush_all(): cpus_read_lock() >> >> One way to break this circular locking chain is to avoid holding >> cpu_hotplug_lock and slab_mutex while deleting the kobject in >> sysfs_slab_unlink() which should be equivalent to doing a write_lock >> and write_unlock pair of the kn->active virtual lock. >> >> Since the kobject structures are not protected by slab_mutex or the >> cpu_hotplug_lock, we can certainly release those locks before doing >> the delete operation. >> >> Move sysfs_slab_unlink() and sysfs_slab_release() to the newly >> created kmem_cache_release() and call it outside the slab_mutex & >> cpu_hotplug_lock critical sections. There will be a slight delay >> in the deletion of sysfs files if kmem_cache_release() is called >> indirectly from a work function. >> >> Signed-off-by: Waiman Long > Reviewed-by: Roman Gushchin > > Thank you, Waiman! > Thanks for your suggestions that make this patch better. Cheers, Longman