Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3567387ybz; Mon, 27 Apr 2020 18:45:01 -0700 (PDT) X-Google-Smtp-Source: APiQypLYvBMvPgUMa63HuwIh12u+FMkVMxfYT2CJlNCZCLN6Kz5Wxjoh2nc/HMd5+IX/OXivlMuH X-Received: by 2002:a50:f61b:: with SMTP id c27mr19766488edn.256.1588038301395; Mon, 27 Apr 2020 18:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588038301; cv=none; d=google.com; s=arc-20160816; b=UO9TD5ETc/WqwLkKQ/dYv82UxZeXKrC/XQFRVzT62YEg9+9LZqXZixUk20CjUJRbj3 NB4whUEVZJdCAmBq0F3ZrQjDDIVuS4FzDDWOXjDD7pjQcRlYbm/cGqsFxC8Qc+MK0dhO JuPvuj6QzX0JqDI2+hZhVF16A4KEQwthZLWCGzRji3qlap6DUzIasWSZHeOG1LbZ+lWJ pU+8zHQZCTG9qUv3Ms/XJIJkAlWhlkJvXzYyzVfz4itrRqIysNRqmWWhfDr9bJ3acDGi qUh63y9pZx23AD0/FiaYvhfZbrRGmTJbn46BPWYxx5DGHeQgF26FsFyMKYfvRMbDP/Yg Ij+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature; bh=AWt0oKx+pB01zuowl3HYopTA8sOUDIn9j7BD+UlNWuQ=; b=foE1j1UIcgK56HHVODJ4Q+rOO7jNJSihIAUSa0nc/nON5FEd95zTUyyDBkZX1+WYcT 9IckHeD2GPEpkaeR240E5+CECfHfQQKn5WfHGpf0fEhrFHabaDfxZQfmAeLwpUIQm5DP rZBr1ombY2jkGIZKmqU92K3WWdM3oGTbLSsQQGrPhcIX7wwIT9rYc1NeOY6+XffqJKTE 2WSg/b0Kj2Y01YgarfxAzQcfIl5Es0MVVMj5vBPx2FB92uB8Z9eEBhfuvQYLVBwd1pMO Xmz1DxxX4STLSOnbZqdjugaz0+6+N/nu16gO7ES6nFfkhoZuw1FGZ5wDfYuTKlMlRl/z VNug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ouxne/II"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l21si802869eds.265.2020.04.27.18.44.37; Mon, 27 Apr 2020 18:45:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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="Ouxne/II"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726396AbgD1Bj4 (ORCPT + 99 others); Mon, 27 Apr 2020 21:39:56 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:43371 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726259AbgD1Bj4 (ORCPT ); Mon, 27 Apr 2020 21:39:56 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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