Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2555739rwb; Mon, 15 Aug 2022 07:21:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR47U+4LKXAM7GjdBsa2P6ERrQWiyI7ULahuPknJongnFKeodYIE6uyIU/TFMwOmJkUR2imm X-Received: by 2002:a17:906:ef90:b0:730:9cd8:56d7 with SMTP id ze16-20020a170906ef9000b007309cd856d7mr10079837ejb.94.1660573269602; Mon, 15 Aug 2022 07:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660573269; cv=none; d=google.com; s=arc-20160816; b=lizIYliC9QD98OgOuG+Xg3ZEMjbHfdGLutBSjBllLeJJCYenmsijsa5owLkqM+CQCd /FdduuTCBZhWoAubNk+nqb+P6zWXvdXwJwFfZJpHSrANGE4ID3ZTs1TwWwviLl8d4a3R RseJFlDbdhq817mPJEDKZpdCjbgjQIU8sZDF0nJrXcGgDjJ8Ji5xmcbyvHwyVTJpsmQv ijinY6S5FXR3SmkaDVgArErJPaQolbi6MaUgOGpRXdq2bR9O2Z9eXfWVMrujM+LDhzyp iqSjgHoTY/lt7Rb2YWKMF0dHfkPnSIHYTkF5/36Wi5S7AX3Q0xOm4GBxWO47MF94Cc3D lXOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=lXDAAl+x9MWatG+p/VTcB+8mkDyPasS5scLcX2zyIyQ=; b=dzx7FdnpKXnLsBlGAhTRV1HMALh1EUQnwdkWJnsKo0eTd3WMvZBTqILaVtCXyL8KFI BrmE6qHbs+Z2SNTHieK8QCt5flZdC3c2ouPIbB5S8VR4iPp6pR2aDHaV2rqJIbLUA+jJ OtqRl3iJdhqmbu7ifINKtnk/UcA8yy4PZggAHUiCVm8OhcGUoVcn0OTnlzA1XinP7LZB vjScHcQICw3MExvBskEovT3doml+2WkE6dX/CufxOShclWw4u6Nd6fiyr/LwQVc6oS2c mbTcVi1/Gx5DstZN6QJNw0mH8dQ2P+W1wIwoY8kwP4k212hujybvFp4oCp8qwWzX9l1x vUew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TvzVGGxy; 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 ho36-20020a1709070ea400b0072ed45a17dbsi11166106ejc.267.2022.08.15.07.20.44; Mon, 15 Aug 2022 07:21:09 -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=TvzVGGxy; 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 S242581AbiHOOCT (ORCPT + 99 others); Mon, 15 Aug 2022 10:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231584AbiHOOCQ (ORCPT ); Mon, 15 Aug 2022 10:02:16 -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 ESMTP id 2E36222BCE for ; Mon, 15 Aug 2022 07:02:15 -0700 (PDT) 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-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,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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