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 X-Spam-Level: X-Spam-Status: No, score=-2.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE847C83002 for ; Tue, 28 Apr 2020 01:39:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A3A95206D9 for ; Tue, 28 Apr 2020 01:39:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ouxne/II" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3A95206D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 54FB48E0006; Mon, 27 Apr 2020 21:39:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 500A68E0001; Mon, 27 Apr 2020 21:39:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 415C58E0006; Mon, 27 Apr 2020 21:39:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 27A278E0001 for ; Mon, 27 Apr 2020 21:39:56 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E32E88248047 for ; Tue, 28 Apr 2020 01:39:55 +0000 (UTC) X-FDA: 76755557550.19.bulb00_90e0d1c997356 X-HE-Tag: bulb00_90e0d1c997356 X-Filterd-Recvd-Size: 4526 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Apr 2020 01:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588037995; 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=AWt0oKx+pB01zuowl3HYopTA8sOUDIn9j7BD+UlNWuQ=; b=Ouxne/IIEAnH0KL7fRqf8jqXc+MyoCV+MG/DFOHJ2JUOiZWOuIpHSckKTXcIFMkQAxrB7G 58ELjB7iHbLsKus6uw70DYwyKKInSklS92JQ/pOnZKSYmGcT+mpp5ETiS+GfH5pZN24O8Y 1qHmFOMifiyQz0FKGI+wCgOVSAFj2ss= 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-369--721LIx2PCSItKIXH4hrrA-1; Mon, 27 Apr 2020 21:39:53 -0400 X-MC-Unique: -721LIx2PCSItKIXH4hrrA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A52B835B40; Tue, 28 Apr 2020 01:39:50 +0000 (UTC) Received: from llong.remote.csb (ovpn-112-176.rdu2.redhat.com [10.10.112.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F8A4196AE; Tue, 28 Apr 2020 01:39:44 +0000 (UTC) Subject: Re: [PATCH v2 4/4] mm/slub: Fix sysfs shrink circular locking dependency To: Qian Cai Cc: Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Johannes Weiner , Michal Hocko , Vladimir Davydov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Juri Lelli References: <20200427235621.7823-5-longman@redhat.com> <55509F31-A503-4148-B209-B4D062AD0ED7@lca.pw> From: Waiman Long Organization: Red Hat Message-ID: Date: Mon, 27 Apr 2020 21:39:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <55509F31-A503-4148-B209-B4D062AD0ED7@lca.pw> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Content-Transfer-Encoding: quoted-printable 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 4/27/20 8:13 PM, Qian Cai wrote: > >> On Apr 27, 2020, at 7:56 PM, Waiman Long wrote: >> >> A lockdep splat is observed by echoing "1" to the shrink sysfs file >> and then shutting down the system: >> >> [ 167.473392] Chain exists of: >> [ 167.473392] kn->count#279 --> mem_hotplug_lock.rw_sem --> slab_mu= tex >> [ 167.473392] >> [ 167.484323] Possible unsafe locking scenario: >> [ 167.484323] >> [ 167.490273] CPU0 CPU1 >> [ 167.494825] ---- ---- >> [ 167.499376] lock(slab_mutex); >> [ 167.502530] lock(mem_hotplug_lock.rw= _sem); >> [ 167.509356] lock(slab_mutex); >> [ 167.515044] lock(kn->count#279); >> [ 167.518462] >> [ 167.518462] *** DEADLOCK *** >> >> It is because of the get_online_cpus() and get_online_mems() calls in >> kmem_cache_shrink() invoked via the shrink sysfs file. To fix that, we >> have to use trylock to get the memory and cpu hotplug read locks. Sinc= e >> hotplug events are rare, it should be fine to refuse a kmem caches >> shrink operation when some hotplug events are in progress. > I don=E2=80=99t understand how trylock could prevent a splat. The funda= mental issue is that in sysfs slab store case, the locking order (once tr= ylock succeed) is, > > kn->count =E2=80=94> cpu/memory_hotplug > > But we have the existing reverse chain everywhere. > > cpu/memory_hotplug =E2=80=94> slab_mutex =E2=80=94> kn->count > The sequence that was prevented by this patch is "kn->count -->=20 mem_hotplug_lock.rwsem". This sequence isn't directly in the splat. Once=20 this link is broken, the 3-lock circular loop cannot be formed. Maybe I=20 should modify the commit log to make this point more clear. Cheers, Longman