Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3358326pxb; Fri, 5 Nov 2021 14:21:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmAC4lbL8KljW3zKD+KtLjGpebEG73iOIAwlnv/05f4FhXleN2bVESi4Hl2x7sBcv3kIsv X-Received: by 2002:a05:6402:17c6:: with SMTP id s6mr65856002edy.11.1636147288578; Fri, 05 Nov 2021 14:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636147288; cv=none; d=google.com; s=arc-20160816; b=dkb3TXT/1AQ33J462K2m3Hd3mQ64OjL8UKQhAPL9RgUYkv3RSvcIjsSd923qsd1654 rZIItyIe+LStqQBemIegu6VuO0BnkW/F97w0R8ICCuhHU58KCpEdv29sAGTVFu27SAk8 dd4DpzcomvY/Hn0X39IZHSoYF7qhleed36l+YjQgb+l5Pvl40gts8UsDWL/ebI4Iz1oq PHM7KXEr2X8qhJXRq+TPAHwtnqPvp8anbtFnn3C5VxRzUqWzYuUdNVv1p7x9ODivoowW dPW1UbfXizqTHiSz4vomW/gQWGLlxPnioEQgtnT7xDV9kfDT1nGrQRj9sZyV7wn0u+W2 IDLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=MOlxXXwYAdTlFvZzrk87+YU73kZFfsVil59MoDSPjJw=; b=PgsEnBVT1CFzVwI5VUz+CCs0zoBtUA5bdaq3Dvt/YW051ki7v/FBelGJUYZveYdZHK J0XNEgsWBFETgfQ+XkWVqdJLaeUPNS3KcMMGnwDJOU/rcqi7P23SDUsBMcZRD0gekkQ1 uglpKw3l99O35T3xpwuK2XAQptRHW/qDnBZvoRBn9L+K6ric8pK6Q9OMod3N/GcLbS5j aoYvEfW9EAwGa/nM3oClT2ZXIegL9H6O7ahw86oM8iWvC1a+CT18BPOaJZpsrMMWPUpi EEytRUcb+teAn1ZYwSMhnhruFO2KDjYhBRTynkdAY4gvNrY5p3pucfdUMXBSodetvj0H sIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@grsecurity.net header.s=grsec header.b=NDbD1m0+; 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=grsecurity.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si4136924edz.134.2021.11.05.14.21.01; Fri, 05 Nov 2021 14:21:28 -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=@grsecurity.net header.s=grsec header.b=NDbD1m0+; 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=grsecurity.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234305AbhKERmy (ORCPT + 99 others); Fri, 5 Nov 2021 13:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232041AbhKERmy (ORCPT ); Fri, 5 Nov 2021 13:42:54 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13528C061714 for ; Fri, 5 Nov 2021 10:40:14 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id o4-20020a1c7504000000b0032cab7473caso7156210wmc.1 for ; Fri, 05 Nov 2021 10:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; h=to:cc:references:from:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=MOlxXXwYAdTlFvZzrk87+YU73kZFfsVil59MoDSPjJw=; b=NDbD1m0+Isz2boRWDrdWYCFIq8jQlSJ9x+g2EQVSlhOYS0ZpS5mD+XZZW2TPU4mPO0 d0T34sJcxjuyQn8hPPkZJ1aOiEX4gFKqfFSB+Tuy4wRrXVU/R7HzCOG8vwqAwhn2ex+h iduoJLxXn5ZEgBTNkcOQQWLOv7ZukXPSRxMzzykHTUhE44Be7UGsiqJvmIlloOBZwcML 0u43sOIEGkzDEFNx38TOEp5v3I53MnsivObnKMM8JRc6XiyMduvoG4yn7Su+j/jr1soU 2D7Hzo2ICZbln5LUOkhYIC79AHz+ahtcJh953rH0LuXxL2FtY2P4smgZ2m0hZlt+7WKs eMsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MOlxXXwYAdTlFvZzrk87+YU73kZFfsVil59MoDSPjJw=; b=0o0BCERfqezNIETmDyWUBfuELwe4TKqjUJuFXHwBJVR79bmGrWi31nRmrUJ1FUZYTd bLSgHtYSE28I5y5dGut+RZc//LwA2FYlyv5fuC1f30ezu+fjnpNEnDuxNWNnK6l3YXpY n104AoQvjEPziyRvfyQQDq7rsgqO08uTvn386BypHOL8UNAbAfWUVY1+wWKtq2da9IBF 2PUqcSHlihnujzqf4YlscJWUp8xFQwytTFNSqFq/XFxKPPUsCzJ9mMrd/ffdN2dDP0yD 1hcjHNr62EWKOIEDJl4BZXAcSfaPwjK+sFU0cdPDqthb6DNEL3ixTHzq4RYyvi7Mtzug xGQA== X-Gm-Message-State: AOAM533n6ihfuaaOylZFQZKkI7GIkcONnZo2SgungOrmVy2M0V/DFhMi wDhoAsIrVo7rIiI4jMtMcyrB4w== X-Received: by 2002:a1c:447:: with SMTP id 68mr32177094wme.69.1636134012652; Fri, 05 Nov 2021 10:40:12 -0700 (PDT) Received: from ?IPv6:2003:f6:af04:5300:7c00:c62b:b3aa:158b? (p200300f6af0453007c00c62bb3aa158b.dip0.t-ipconnect.de. [2003:f6:af04:5300:7c00:c62b:b3aa:158b]) by smtp.gmail.com with ESMTPSA id m125sm11666647wmm.39.2021.11.05.10.40.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Nov 2021 10:40:12 -0700 (PDT) To: Peter Zijlstra Cc: Vincent Guittot , =?UTF-8?Q?Michal_Koutn=c3=bd?= , Benjamin Segall , Ingo Molnar , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, Odin Ugedal , Kevin Tanguy , Brad Spengler References: <8f4ed996-e6e5-75f4-b5fa-dffb7b7da05b@grsecurity.net> <20211105162914.215420-1-minipli@grsecurity.net> From: Mathias Krause Subject: Re: [PATCH] sched/fair: Prevent dead task groups from regaining cfs_rq's Message-ID: <00ec3c8e-6462-5cc4-ab79-e8887bcedad8@grsecurity.net> Date: Fri, 5 Nov 2021 18:40:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 05.11.21 um 18:27 schrieb Peter Zijlstra: > On Fri, Nov 05, 2021 at 06:14:33PM +0100, Mathias Krause wrote: >> Am 05.11.21 um 17:58 schrieb Peter Zijlstra: >>> On Fri, Nov 05, 2021 at 05:29:14PM +0100, Mathias Krause wrote: >>>>> Looks like it needs to be the kfree_rcu() one in this case. I'll prepare >>>>> a patch. >>>> >>>> Testing the below patch right now. Looking good so far. Will prepare a >>>> proper patch later, if we all can agree that this covers all cases. >>>> >>>> But the basic idea is to defer the kfree()'s to after the next RCU GP, >>>> which also means we need to free the tg object itself later. Slightly >>>> ugly. :/ >>> >>> Can't we add an rcu_head to struct task_group and simply call_rcu() the >>> thing with a free function? >> >> There is already one and this patch makes use of it for the second RCU >> GP requirement. Basically, the patch is doing what you request, no? See >> the new free_fair_sched_group(). > > For some reason I thought you still did kfree_rcu(), I suppose reading > is hard. I'll give it another go after dinner. I wanted to go for kfree_rcu() initially, true. But after realizing, that adding a rcu_head to struct cfs_rg, sched_entity and task_group (which already has one) might be too much for what's needed, I went the call_rcu() route instead and re-used the rcu_head of task_group. Actually re-using the rcu_head in task_group is safe, as we'll use it only sequentially: first in sched_destroy_group() to schedule sched_free_group_rcu() and then, when it's executing, in free_fair_sched_group() to schedule free_tg(). rcu_head's get unlinked prior to getting their callback function invoked, which makes the above a valid use case. Thanks, Mathias