Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3241092rwb; Fri, 20 Jan 2023 13:14:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXtHr7siR2nCTOuhYQarEL90E6M1lfGlxR0kbeTHY3fnWY4aUHogGBbK2Y4atFzTokb9REqN X-Received: by 2002:aa7:8f1a:0:b0:586:2f39:495a with SMTP id x26-20020aa78f1a000000b005862f39495amr19095098pfr.15.1674249255022; Fri, 20 Jan 2023 13:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674249255; cv=none; d=google.com; s=arc-20160816; b=M8yCjUGlNGz38ssGq1/zwL2+qFTqb+qcvI67Xaw0f64Pzy9/OSUWKLSwUR4pF7fmg8 Aa0JPUqNDsN7JSOUfWekfSOPP6icVS2VdPLhRX0p+1kxGt3L4He5N3KFb03gP1xMKpsZ 34lIqj1cs5ciprupb8JXnoNwHTo/szm1SiQSfEKGMlhqzT724RXBNUHMLe4ec3THbOJ2 h0i+k7VochBxJ59jLdPfIh+V5V1VmR0Xf/mU9da4QxzZZHXA7M0tRxppfwqAp/qWw7iT 0UepTLBYn3AFwJ59oX44lh+CZxY3076LBq9D01CQtw7qvUG/iPd8d1uMvChmrzzSBOej WS1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=W+424KJ/4eUBc5hj2I5II2IUgeWEg8+zfHrFyPZ3+UE=; b=qeof+Du5ZfVnOTISW6pS3b/kkGxNqxUItd7vdDkt/YkFV5fOYXj7FI7OmknIgX3s5u idYLYBwmBbD1MJ2hPsaVMMnZQeHCfcNbivafNCvoq65wonRj4eroOVHew0b/mGZ+ZUNK F3epMvHv4t43RHmWUPnI3aHqqNqZfs+FWKTWOrvg1dgfggKiF6ml21g40Gn4UOU8ulLC f29LVqyqUtFDtXbMTKUhiqeAp7u0io7tx/uu7apaet4golNg76Gx1Xces/xb5GVf6Y+z 2fepNUoX1ohFPlY8nK2NfRe0EvCjZ05CtLPN3EBiM6drHCR3ewCaCUPB+jI1ReNCxDeu W4GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gYFfkDTK; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f4-20020aa78b04000000b00587295f1e25si36124194pfd.240.2023.01.20.13.14.07; Fri, 20 Jan 2023 13:14:14 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=gYFfkDTK; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbjATUQB (ORCPT + 50 others); Fri, 20 Jan 2023 15:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbjATUQA (ORCPT ); Fri, 20 Jan 2023 15:16:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FCB111EB1 for ; Fri, 20 Jan 2023 12:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674245713; 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: in-reply-to:in-reply-to:references:references; bh=W+424KJ/4eUBc5hj2I5II2IUgeWEg8+zfHrFyPZ3+UE=; b=gYFfkDTKAhOM/inY1Sa2dbYkmOqBQcvHCnXssjLOe+XgM1Sknx2xrRNngtenHN13VlMe6K qc+fgQ1t0o6ZoEZdPxhCWaJCRsm4JjN0RXOsoBuGZAL9fDdCtmrgV99TMeUerI0mObTssu 5g/VKA2ePy4YpJZ0DZIBcDMAoNxFRUs= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-171--ilCNXp6OqKobq1OELsGPw-1; Fri, 20 Jan 2023 15:15:11 -0500 X-MC-Unique: -ilCNXp6OqKobq1OELsGPw-1 Received: by mail-pf1-f197.google.com with SMTP id c5-20020aa78805000000b0058d983c708aso2907485pfo.22 for ; Fri, 20 Jan 2023 12:15:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W+424KJ/4eUBc5hj2I5II2IUgeWEg8+zfHrFyPZ3+UE=; b=mPL+eH1SsqkLV3AtejOhkhLRaLRNw+722bMXqnPSGSVtocf0Ndp+e56hJdnnvYZYED GG28Dux7HLwp/1eZwgWLzQKIPbv+2u2TxkKuPiy1KSnRmHDyPhBdYeQiATXRyM75nGBT HpkY9lmh0qAotUGBXN88otQznT7p4D1PJ5gvAGhjjO7nMOTvCPtIMt/U4XqpH3BtLELL 4yk0pWS/j/pnsCFo1dnwUHs0QF+H0O5zDOXwdXF2NZ6x7+EywK/VMfzS75ZQUCidth9j Ld0qMYSRvEtTn/+vr8i0P+KzKbIHbbqTNofnpeLfoT1yU8dG8oLqg4iPhvoNPbMW814M Xadg== X-Gm-Message-State: AFqh2kqTq2z9y+WZ6NCS0mXJnCUPZwcEZ8LaXaTRt09putdxdIG/Pzm4 mXiiEk1qmZdUZ533PjzJRcmhnjEX4odny/k3ISgPljDMtpbY41MwLClycoMXVkVIRPF1FKEAKj7 r7VgoCU3usFCp80bAF6Unvgsd8o3J+I54jcH9x4Cx X-Received: by 2002:a63:d855:0:b0:4d1:6eb1:f4fd with SMTP id k21-20020a63d855000000b004d16eb1f4fdmr948949pgj.129.1674245710437; Fri, 20 Jan 2023 12:15:10 -0800 (PST) X-Received: by 2002:a63:d855:0:b0:4d1:6eb1:f4fd with SMTP id k21-20020a63d855000000b004d16eb1f4fdmr948947pgj.129.1674245710191; Fri, 20 Jan 2023 12:15:10 -0800 (PST) MIME-Version: 1.0 References: <20230120150246.20797-1-wander@redhat.com> In-Reply-To: From: Wander Lairson Costa Date: Fri, 20 Jan 2023 17:14:58 -0300 Message-ID: Subject: Re: [PATCH v2 0/4] Fix put_task_struct() calls under PREEMPT_RT To: Valentin Schneider Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , "Eric W. Biederman" , Geert Uytterhoeven , "Russell King (Oracle)" , Catalin Marinas , Oleg Nesterov , Kefeng Wang , Andrew Morton , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Fri, Jan 20, 2023 at 2:45 PM Valentin Schneider wrote: > > On 20/01/23 at 12:02, Wander Lairson Costa wrote: > > put_task_struct() decrements a usage counter and calls > > __put_task_struct() if the counter reaches zero. > > > > __put_task_struct() indirectly acquires a spinlock, which is a sleeping > > lock under PREEMPT_RT. Therefore, we can't call put_task_struct() in an > > atomic context in RT kernels. > > > > This patch series introduces put_task_struct_atomic_safe(), which defers > > the call to __put_task_struct() to a process context when compiled with > > PREEMPT_RT. > > > > It also fixes known problematic call sites. > > > > Browsing around put_task_struct() callsites gives me the impression there > are more problematic call sites lurking around, which makes me wonder: > should we make the PREEMPT_RT put_task_struct() *always* be done via > call_rcu()? > I thought about going on this route, but I was concerned about the performance side effects this approach could bring. Another idea I had was to check at runtime if we are in a preemptible context. Again, this would have a (minor?) performance penalty. > The task's stack is actually always freed that way in put_task_stack(), cf. > > e540bf3162e8 ("fork: Only cache the VMAP stack in finish_task_switch()") > > > Changelog: > > ========== > > > > v2: > > * Add the put_task_struct_atomic_safe() function that is responsible for > > handling the conditions to call put_task_struct(). > > * Replace put_task_struct() by put_task_struct_atomic_safe() in known > > atomic call sites. > > > > Wander Lairson Costa (4): > > sched/task: Add the put_task_struct_atomic_safe function > > sched/deadline: fix inactive_task_timer splat > > sched/rt: use put_task_struct_atomic_safe() to avoid potential splat > > sched/core: use put_task_struct_atomic_safe() to avoid potential splat > > > > include/linux/sched/task.h | 21 +++++++++++++++++++++ > > kernel/fork.c | 8 ++++++++ > > kernel/sched/core.c | 2 +- > > kernel/sched/deadline.c | 2 +- > > kernel/sched/rt.c | 4 ++-- > > 5 files changed, 33 insertions(+), 4 deletions(-) > > > > -- > > 2.39.0 >