Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1632975rwl; Wed, 5 Apr 2023 21:45:03 -0700 (PDT) X-Google-Smtp-Source: AKy350YNPL+bjp1P6+t1TP1X/Rd0nhVhLrgKa5QeeKoZ/91sRnNihyNYEcB3vjqaBZRdiWxS7cwD X-Received: by 2002:aa7:9af9:0:b0:624:b4f3:398f with SMTP id y25-20020aa79af9000000b00624b4f3398fmr7603096pfp.0.1680756303480; Wed, 05 Apr 2023 21:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680756303; cv=none; d=google.com; s=arc-20160816; b=Zo9azA8ts893uIQPqS60kvV16ts3Z0VzFSs1ZsEnqIgoLAZkMhJrsJDDyGvxlwMy3O SP0GJ6eA0nUFl+K2lUgBr9GZn5t5wsjCd3OrVljGyK2wwPFDhRseHa4LC8G4SGji/SbD E0TkMRFBhHYaswkg2cW0B42znw1GlimtOH0bun0yocGbk3zbsxyAOxrDtHb7nKyJtctB aqXkhXCEP2aYFWk9eWuTdDt0TIxDki3JeDFG/OL3Mm1fg4Z6Hgy4VkKuHPPVcs6zr/iL LsbdfUwCNBJUlWCv0rg+5DbI9OdPUvjptnDscfwirG6+Syy9xPfLgIGrics2vjKwj45W wP5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=xjmsZjVp+RHs53GtXmmi/MP0iaPYipjPhPYHzuWzSjY=; b=W+gAiVqsLvXJyY32UCn1sEmdd89SRxUbXrFMH9lwlw+ID23bD7P1MyzlIiVNKTXKd7 OknEIonyxPwMt/kSElH9VnUukwbpz9//6Bf+gMdUxzxhDN4EWZVi+pkJrVtgU1AwOPp3 U9H47w/5j73tV1H9H5DM8RI42n8jL1Pp9fHGtSYKX1//wz+MoWlI8YB8L4WOb5pFPkVu rKWOhBvOmAZ2Fl2R06nB8w4SDRp/I46qqE695oBp2Z0BR1GVYNnkKzn+gsJVcfw7IsoD aWYxJpITwlEQMRbWKbdXQWYrJtoItkmVugo5dVwdwEVcey20t0dRTfhtdMSSVMs3tiLU 0YhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cshu7b59; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y187-20020a638ac4000000b004fc274006ddsi332235pgd.670.2023.04.05.21.44.51; Wed, 05 Apr 2023 21:45:03 -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=@gmail.com header.s=20210112 header.b=cshu7b59; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234787AbjDFEoW (ORCPT + 99 others); Thu, 6 Apr 2023 00:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbjDFEoV (ORCPT ); Thu, 6 Apr 2023 00:44:21 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1C472A3; Wed, 5 Apr 2023 21:44:19 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id h8so146353338ede.8; Wed, 05 Apr 2023 21:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680756258; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=xjmsZjVp+RHs53GtXmmi/MP0iaPYipjPhPYHzuWzSjY=; b=cshu7b59hlBuIgkp7jFp8eXASNV+7N8rZcktacOvUJtMb+N4yNXilVLl+b4JadkAPT 3zmaYCH/aerIPEjWpptkuPOsuWenQI+7oHuBMhVVECRo/yf29sLGO6y9S8CkiwiXN06/ QtI7ZdJ4Pddwy2dn/c4BAzZr233KsI78UamYnKHtiOKRN7k7gpaGE8no9TFETtjmc9M1 rMESFHm8pc7F9a/hpKjH9CGdS54PhJTxauaAcoG2zkqX51oo1T4L2tsBScnCswtn4Bz8 AU9Oo82AUAGRFBQzq2bLuaw0+f5Pg6OITfMeVsnGRlEk2kd7GKdU8r7yp45YwTlj4vwt QhoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680756258; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xjmsZjVp+RHs53GtXmmi/MP0iaPYipjPhPYHzuWzSjY=; b=PLOrkX8dhAxFyWMpMIJLXtaIsaxCBf+SltpwN4fE/jHPCSN0+PDU9ONQ4UDhdr4eO3 IOWgANP3kvPdpxVeBJDTLeNDpLe3+XRQJAV0Do20XBKERQVzjb0wXr2soU3JaEeHcrpd if7u/DHWo48p/1YiEVuY5l3OX5SqTrjIdL1DO/ZiAJwCRNAFKtMxJU+0agO1mhzhmpEm VOu652pJ9ZRExeFGAkBYySX2PuM5cZT997izi/dPlxHN7O7IpEzEI6Wxmlz2YeqxPyop ck0MxZ2viYKz8vrtTkN9ALUThfKBkFqLXhGc8qp5zNwIloArcFxNDWSk7aYHQu2X/Qdi zaMw== X-Gm-Message-State: AAQBX9dtx2Z+zNZw3y5OLCfUWaBsyEDXwpmZW06dXEFVImNCIVIOAnLV CA/M5ZsljLxPVR99XIKmN3M= X-Received: by 2002:a17:906:b88a:b0:92e:b1dd:cff2 with SMTP id hb10-20020a170906b88a00b0092eb1ddcff2mr4552948ejb.28.1680756258204; Wed, 05 Apr 2023 21:44:18 -0700 (PDT) Received: from pc636 ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id i17-20020a17090671d100b0092973e209f2sm254503ejk.109.2023.04.05.21.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 21:44:17 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 6 Apr 2023 06:44:15 +0200 To: "Paul E. McKenney" Cc: =?utf-8?B?5Luj5a2Q5Li6IChaaXdlaSBEYWkp?= , Joel Fernandes , "urezki@gmail.com" , "frederic@kernel.org" , "quic_neeraju@quicinc.com" , "josh@joshtriplett.org" , "rostedt@goodmis.org" , "mathieu.desnoyers@efficios.com" , "jiangshanlai@gmail.com" , "rcu@vger.kernel.org" , "linux-kernel@vger.kernel.org" , =?utf-8?B?546L5Y+MIChTaHVhbmcgV2FuZyk=?= , =?utf-8?B?6L6b5L6d5YehIChZaWZhbiBYaW4p?= , =?utf-8?B?546L56eRIChLZSBXYW5nKQ==?= , =?utf-8?B?6Zer5a2m5paHIChYdWV3ZW4gWWFuKQ==?= , =?utf-8?B?54mb5b+X5Zu9IChaaGlndW8gTml1KQ==?= , =?utf-8?B?6buE5pyd6ZizIChaaGFveWFuZyBIdWFuZyk=?= Subject: Re: =?utf-8?B?562U5aSNOiBbUEFUQ0ggVjJdIHJj?= =?utf-8?Q?u=3A_Make_sure_new_krc?= =?utf-8?Q?p?= free business is handled after the wanted rcu grace period. Message-ID: References: <1680266529-28429-1-git-send-email-ziwei.dai@unisoc.com> <94c28b46617e46d1804a397a54f9fd8d@BJMBX01.spreadtrum.com> <6ff4eb09-13df-403f-ba4a-c5abb0f3fa8f@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6ff4eb09-13df-403f-ba4a-c5abb0f3fa8f@paulmck-laptop> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_PDS_OTHER_BAD_TLD 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 Wed, Apr 05, 2023 at 08:46:15PM -0700, Paul E. McKenney wrote: > On Thu, Apr 06, 2023 at 01:38:09AM +0000, 代子为 (Ziwei Dai) wrote: > > > > > > > -----邮件原件----- > > > 发件人: Paul E. McKenney > > > 发送时间: 2023年4月6日 2:46 > > > 收件人: Joel Fernandes > > > 抄送: 代子为 (Ziwei Dai) ; urezki@gmail.com; frederic@kernel.org; quic_neeraju@quicinc.com; > > > josh@joshtriplett.org; rostedt@goodmis.org; mathieu.desnoyers@efficios.com; jiangshanlai@gmail.com; rcu@vger.kernel.org; > > > linux-kernel@vger.kernel.org; 王双 (Shuang Wang) ; 辛依凡 (Yifan Xin) ; 王科 > > > (Ke Wang) ; 闫学文 (Xuewen Yan) ; 牛志国 (Zhiguo Niu) > > > ; 黄朝阳 (Zhaoyang Huang) > > > 主题: Re: [PATCH V2] rcu: Make sure new krcp free business is handled after the wanted rcu grace period. > > > > > > > > > 注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。 > > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the > > > sender and know the content is safe. > > > > > > > > > > > > On Wed, Apr 05, 2023 at 02:12:02PM -0400, Joel Fernandes wrote: > > > > On Wed, Apr 5, 2023 at 1:39 PM Joel Fernandes wrote: > > > > > > > > > > On Fri, Mar 31, 2023 at 8:43 AM Ziwei Dai wrote: > > > > > > > > > > > > In kfree_rcu_monitor(), new free business at krcp is attached to > > > > > > any free channel at krwp. kfree_rcu_monitor() is responsible to > > > > > > make sure new free business is handled after the rcu grace period. > > > > > > But if there is any none-free channel at krwp already, that means > > > > > > there is an on-going rcu work, which will cause the > > > > > > kvfree_call_rcu()-triggered free business is done before the wanted rcu grace period ends. > > > > > > > > > > > > This commit ignore krwp which has non-free channel at > > > > > > kfree_rcu_monitor(), to fix the issue that kvfree_call_rcu() loses effectiveness. > > > > > > > > > > > > Below is the css_set obj "from_cset" use-after-free case caused by > > > > > > kvfree_call_rcu() losing effectiveness. > > > > > > CPU 0 calls rcu_read_lock(), then use "from_cset", then hard irq > > > > > > comes, the task is schedule out. > > > > > > CPU 1 calls kfree_rcu(cset, rcu_head), willing to free "from_cset" after new gp. > > > > > > But "from_cset" is freed right after current gp end. "from_cset" is reallocated. > > > > > > CPU 0 's task arrives back, references "from_cset"'s member, which causes crash. > > > > > > > > > > > > CPU 0 CPU 1 > > > > > > count_memcg_event_mm() > > > > > > |rcu_read_lock() <--- > > > > > > |mem_cgroup_from_task() > > > > > > |// css_set_ptr is the "from_cset" mentioned on CPU 1 > > > > > > |css_set_ptr = rcu_dereference((task)->cgroups) |// Hard irq > > > > > > comes, current task is scheduled out. > > > > > > > > > > > > cgroup_attach_task() > > > > > > |cgroup_migrate() > > > > > > |cgroup_migrate_execute() > > > > > > |css_set_move_task(task, from_cset, to_cset, true) > > > > > > |cgroup_move_task(task, to_cset) > > > > > > |rcu_assign_pointer(.., to_cset) > > > > > > |... > > > > > > |cgroup_migrate_finish() > > > > > > |put_css_set_locked(from_cset) > > > > > > |from_cset->refcount return 0 > > > > > > |kfree_rcu(cset, rcu_head) // means to free from_cset after new gp > > > > > > |add_ptr_to_bulk_krc_lock() > > > > > > > > > > > > |schedule_delayed_work(&krcp->monitor_work, ..) > > > > > > > > > > > > kfree_rcu_monitor() > > > > > > |krcp->bulk_head[0]'s work attached to krwp->bulk_head_free[] > > > > > > |queue_rcu_work(system_wq, &krwp->rcu_work) > > > > > > |if rwork->rcu.work is not in WORK_STRUCT_PENDING_BIT state, > > > > > > |call_rcu(&rwork->rcu, > > > > > > rcu_work_rcufn) <--- request a new gp > > > > > > > > > > > > // There is a perious call_rcu(.., rcu_work_rcufn) > > > > > > // gp end, rcu_work_rcufn() is called. > > > > > > rcu_work_rcufn() > > > > > > |__queue_work(.., > > > > > > rwork->wq, &rwork->work); > > > > > > > > > > > > |kfree_rcu_work() > > > > > > |krwp->bulk_head_free[0] bulk is freed before new gp end!!! > > > > > > |The "from_cset" is freed before new gp end. > > > > > > > > > > > > // the task is scheduled in after many ms. > > > > > > |css_set_ptr->subsys[(subsys_id) <--- Caused kernel crash, because css_set_ptr is freed. > > > > > > > > > > > > v2: Use helper function instead of inserted code block at kfree_rcu_monitor(). > > > > > > > > > > > > Fixes: c014efeef76a ("rcu: Add multiple in-flight batches of > > > > > > kfree_rcu() work") > > > > > > Signed-off-by: Ziwei Dai > > > > > > > > > > Please update the fixes tag to: > > > > > 5f3c8d620447 ("rcu/tree: Maintain separate array for vmalloc ptrs") > > > > > > > > Vlad pointed out in another thread that the fix is actually to 34c881745549. > > > > > > > > So just to be sure, it could be updated to: > > > > Fixes: 34c881745549 ("rcu: Support kfree_bulk() interface in > > > > kfree_rcu()") > > > > Fixes: 5f3c8d620447 ("rcu/tree: Maintain separate array for vmalloc > > > > ptrs") > > > > > > Ziwei Dai, does this change in Fixes look good to you? > > > > > > If so, I will update the commit log in this commit that I am planning to submit into v6.3. It is strictly speaking not a v6.3 regression, > > > but it is starting to show up in the wild and the patch is contained enough to be considered an urgent fix. > > > > > > Thanx, Paul > > > > Hi Paul, it looks good to me and thanks! > > Thank you, and I will fix on my next rebase. > After heavy testing over night i do not see that any warnings are triggered: Tested-by: Uladzislau Rezki (Sony) -- Uladzislau Rezki