Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5979711ioo; Wed, 1 Jun 2022 17:41:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdQE2yglGh65LWupZ26h49vlaIY7/Zn5XGsSO/AS9khK2TJuKlVNdb0i2VpuRo6dZCQhng X-Received: by 2002:a17:90b:38cc:b0:1e0:1c6f:d3e3 with SMTP id nn12-20020a17090b38cc00b001e01c6fd3e3mr37041087pjb.86.1654130465304; Wed, 01 Jun 2022 17:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654130465; cv=none; d=google.com; s=arc-20160816; b=JU+2ClPnxgn3iMg1RBxHPO1hLyqUMWpRMqNz35Jk3Du5pQJl79XYGSRIijz2PQCUr3 hsixZBCuEiKdyyDYhbmQ05WCHC1ubZ0MN1rQv92juZg1zYUg5ijbb8K8bmBFuGu5Ae/V e6cbV0qbck4qIRmpGYrRuy3jZxRPXaP5VfVaONBJ2Ulv3zlmf+/IBRNvZspb2L16j0Ab gXXOKDdy7DiCPHMhkTKqQBUu+vd1dtA+FrohSxecqfC39AOfgiwwoemrQVvt78chETxj SU1d911wKhyx6pAUhmeXO92N3qU+nh4jlmcUw4pwQjPoDqg8J9T33etYdkB7rEYR1vgp vF3g== 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:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=bCg75JCW+pfC2cBeuVcFJREBBHmfucnS3ebVUyU/JTo=; b=aauJic8S8GG2qfuxjpVfMrkpBJ+Ju9xHhyVKryd4BJ3CPCF7k3ij47EfggDv1Y0CeS arUXfOhOrtUKRwfM0ZS92rwss9JyrvWkhVJA3uH+a+ZZOTUO7h87+zemV19Z/OEYHKob kxei+lXFzTud77eFgTFpN0e813hZT4OM0ymBDD3suPpG6Dwh/AYV5R3j2RKMfvbJx7Kk UC4M5BuTLo1ZBnQLTH73bqG+U+9W+1uCMaXGk1PQc3JtOpYWKqN/5Tg8sDN7iusJHO7z pchb3/VFDI27qPDYD41AdYZca2fnK0+4fQIP+/ZjZ6ua2YBaF9CQ6Nkusg2WEICOBiBp 7d1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nvakCz5X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s7-20020a63ff47000000b003c18351c4c1si4099013pgk.673.2022.06.01.17.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:41:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nvakCz5X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 456991842D5; Wed, 1 Jun 2022 17:41:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232808AbiFBAkz (ORCPT + 99 others); Wed, 1 Jun 2022 20:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232784AbiFBAkx (ORCPT ); Wed, 1 Jun 2022 20:40:53 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E9C0234295 for ; Wed, 1 Jun 2022 17:40:53 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so7891293pjo.0 for ; Wed, 01 Jun 2022 17:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:content-language:to:cc :references:from:subject:in-reply-to:content-transfer-encoding; bh=bCg75JCW+pfC2cBeuVcFJREBBHmfucnS3ebVUyU/JTo=; b=nvakCz5XU4OHW+crILNG26v7+vQ2IiR6NULuMci2uYtam+NThJ/3HpJrQJFMfg8a14 Mqux8+tlKQRiYmlV6wq6o/Bwvjv63JmaCKuMD3fu2InTMyQscdIpanE/tjFmLJSdihfc dDqfD112MsNKtlgnntpgBLaMJHKh/NnByZpxbkseO5IHgidWzXLN1ccFm7YnOHm20b2t hwTzKwFPdaBmu67/KqpRwxh2Mqk4Y2fxy8TM5+nNQPIAPg2Hz1YEZ1OvwuiauFRp3Ysv wI3HHcEptwZcEIO5D6eY3mbSIq99WSH/HnNAlvUFfeRLa9oTmyvDXpWIijtl+2tBRKgy FP/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:subject:in-reply-to :content-transfer-encoding; bh=bCg75JCW+pfC2cBeuVcFJREBBHmfucnS3ebVUyU/JTo=; b=3rrSPvUzn3p/ybrho2dqhofXUynDErdhuzDr5vPmVsfUNugQFFUmBZC06xFYf6GkNa LDPjuYg+opbq8nmuPJZ8gThb2P8/R40hzcaprTiSfRSBvcdItbaC/aNnfRRU5+/PtJA3 O+PZCE4R8V8CZK/yenv8v/I0OgoPJF0LFj4/A3e8s8R2DBly/ziD9uBLgt/M4AHb/M/I e50vjJg5omwGcyBPnF82fjNRiGAho9QH5IkfaZvu2zadqVSQaYArTo6hfRV88apsVr+n pL+ILa1Y8wy970ZNkC+j6QJnrpcYyY6WxHPkUjCnW5w3oj8YXJtenmTz2UYq7I92VXxs DhIQ== X-Gm-Message-State: AOAM5316XjAdsrhpc0qgnxn9xet4Hbfx7FihRHC3wb9YhHJskuXrkZqb k201UUoW1MEjzVuzttF7WDX8ycPU7gYEhg== X-Received: by 2002:a17:902:9349:b0:158:a6f7:e280 with SMTP id g9-20020a170902934900b00158a6f7e280mr2060476plp.155.1654130452700; Wed, 01 Jun 2022 17:40:52 -0700 (PDT) Received: from [192.168.254.36] ([50.39.160.154]) by smtp.gmail.com with ESMTPSA id b5-20020a170902650500b0015e8d4eb23asm2144288plk.132.2022.06.01.17.40.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Jun 2022 17:40:52 -0700 (PDT) Message-ID: <0fd1c3fd-fa86-dbed-f3f0-74c91b1efa11@linaro.org> Date: Wed, 1 Jun 2022 17:40:51 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: Tejun Heo Cc: =?UTF-8?Q?Michal_Koutn=c3=bd?= , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Zefan Li , Johannes Weiner , Bui Quang Minh References: <20220525161455.GA16134@blackbody.suse.cz> <0babd7df-bdef-9edc-3682-1144bc0c2d2b@linaro.org> <1fb4d8d7-ccc0-b020-715e-38c2dfd94c23@linaro.org> <416dc60a-f0e5-7d05-1613-3cd0ca415768@linaro.org> From: Tadeusz Struk Subject: Re: [PATCH 2/2] cgroup: Use separate work structs on css release path In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 6/1/22 17:29, Tejun Heo wrote: > On Wed, Jun 01, 2022 at 05:26:34PM -0700, Tadeusz Struk wrote: >> Ok the problem is that >> >> 1. kill_css() triggers css_killed_ref_fn(), which enqueues &css->destroy_work on cgroup_destroy_wq >> 2. Last put_css() calls css_release(), which enqueues &css->destroy_work on cgroup_destroy_wq >> >> We have two instances of the same work struct enqueued on the same WQ (cgroup_destroy_wq), >> which causes "BUG: corrupted list in insert_work" > > #2 shouldn't be happening before kill_ref_fn() is done with the css. If what > you're saying is happening, what's broken is the fact that the refcnt is > reaching 0 prematurely. css_killed_ref_fn() will be called regardless of the value of refcnt (via percpu_ref_kill_and_confirm()) and it will only enqueue the css_killed_work_fn() to be called later. Then css_put()->css_release() will be called before the css_killed_work_fn() will even get a chance to run, and it will also *only* enqueue css_release_work_fn() to be called later. The problem happens on the second enqueue. So there need to be something in place that will make sure that css_killed_work_fn() is done before css_release() can enqueue the second job. Does it sound right? >> So I think the easiest way to solve this would be to have two separate work_structs, >> one for the killed_ref path and css_release path as in: > > If you do that, you'd just be racing the free path against the kill path and > the css might get freed while the kill path is still accessing it. > > Thanks. > -- Thanks, Tadeusz