Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6839496rwr; Tue, 25 Apr 2023 04:46:25 -0700 (PDT) X-Google-Smtp-Source: AKy350aBfLf8oXm9mMorlI1Pshdz65FKyLVZL6wT48tVn4PFD/B8dw8dECOnmCFQ6gQ6YhTWNLpO X-Received: by 2002:a05:6a00:1806:b0:63b:67d5:be9c with SMTP id y6-20020a056a00180600b0063b67d5be9cmr24364741pfa.29.1682423184721; Tue, 25 Apr 2023 04:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682423184; cv=none; d=google.com; s=arc-20160816; b=DTpktgOBDebkr52mPuLkwhysYhp9N9ymOklgNYs2/0qhZ/H4K1zeMW8s5JNWzgXqnr hXDE7gx1be9IwmR66dkCT1PpznhFGSHlV0gGlvIf9nAdi/MOl0Lzu4oBrPGbgN/H0Gnv YEgRdC9xQubfjC3n6B4O343NZEFnI0qoiBMfEqJursJWjsN9cKXOFBVuY0Pu5EONsFgV SRL9mgZbzIkR+x4P0unZrA2FYC2n6f9R4XVJMx8Y84gRKt8BHYHiepd5eblAfar/OyQv Q3rmL72r/U3+mvJ6afmqBzU6Swla8wnUErAnEg50erXVxMLqnnWFCkYtSIa6ktUc6CCA OYkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vFQziVpAX6XaFGXqO40sBdWG90AbxvK36TAoQxxNkWo=; b=Gu3A9nqjEV/vpzM39ldnY0aiKeyAbE9X6SN00U+C6PXJuBe+M0dOhEt2/VNTTjQDrG S8IZh+tnrKNL5rEXV+LfSwok2EbABqMuAUAvq7InH95QEtqDPnQQSQ+0imB+naUxrEEy 8iMvErdip70Lduff/hJOmLFdv3C0Q7/Fvzw0XuiT1wLD8LgVlN2q1ozXlvXx4Krhs/LX dYusy8n1vyA4pQvcgammF8Dvsgs1WZ+SHBh93XoN8FkGcEN7iKDxp+U1VznZAXJN3yFl B3IadCcXGDx/JkYIED8zdQ8teH8rP3l6YACbmdZL8Y+Il9kQW0LKK2lzmYlJcg63mJ+O DXPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GgepjmAX; 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 q23-20020aa79837000000b0063b80f4bfa6si13471900pfl.132.2023.04.25.04.46.11; Tue, 25 Apr 2023 04:46:24 -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=@redhat.com header.s=mimecast20190719 header.b=GgepjmAX; 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 S230195AbjDYLoh (ORCPT + 99 others); Tue, 25 Apr 2023 07:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233922AbjDYLof (ORCPT ); Tue, 25 Apr 2023 07:44:35 -0400 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 B1EF3468A for ; Tue, 25 Apr 2023 04:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682423027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vFQziVpAX6XaFGXqO40sBdWG90AbxvK36TAoQxxNkWo=; b=GgepjmAX5XZDbs2iWgz7WO0AkEgp8pYpWEMR9O3VbW1AkBDyFdMZgLMXklCB2lXg6P3adW BoKM+yBR7X8jQR3blI0qJyOgCc/+x0A05Q4xxUoFykYISnuk795v+n0G/HbwqPUD75GpMW 9x88WOx7UYQ119qagw5NU1xvrKE+0SQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-131-UQkMa4ztO0O8A3npY_Q1aA-1; Tue, 25 Apr 2023 07:43:43 -0400 X-MC-Unique: UQkMa4ztO0O8A3npY_Q1aA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5506F1C08786; Tue, 25 Apr 2023 11:43:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.32.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A307C15BA0; Tue, 25 Apr 2023 11:43:35 +0000 (UTC) From: Wander Lairson Costa To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Will Deacon , Waiman Long , Boqun Feng , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Wander Lairson Costa , Kefeng Wang , Michael Ellerman , Oleg Nesterov , Andrew Morton , "Liam R. Howlett" , Christian Brauner , Kees Cook , Andrei Vagin , Shakeel Butt , linux-kernel@vger.kernel.org (open list), linux-perf-users@vger.kernel.org (open list:PERFORMANCE EVENTS SUBSYSTEM) Cc: Sebastian Andrzej Siewior Subject: [PATCH v7 1/3] sched/core: warn on call put_task_struct in invalid context Date: Tue, 25 Apr 2023 08:43:01 -0300 Message-Id: <20230425114307.36889-2-wander@redhat.com> In-Reply-To: <20230425114307.36889-1-wander@redhat.com> References: <20230425114307.36889-1-wander@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.3 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,T_SCC_BODY_TEXT_LINE 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 Under PREEMPT_RT, spinlocks become sleepable locks. put_task_struct() indirectly acquires a spinlock. Therefore, it can't be called in atomic/interrupt context in RT kernels. To prevent such conditions, add a check for atomic/interrupt context before calling put_task_struct(). Signed-off-by: Wander Lairson Costa Suggested-by: Sebastian Andrzej Siewior --- include/linux/sched/task.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 357e0068497c..b597b97b1f8f 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -113,14 +113,28 @@ static inline struct task_struct *get_task_struct(struct task_struct *t) extern void __put_task_struct(struct task_struct *t); +#define PUT_TASK_RESCHED_OFFSETS \ + (rcu_preempt_depth() << MIGHT_RESCHED_RCU_SHIFT) + +#define __put_task_might_resched() \ + __might_resched(__FILE__, __LINE__, PUT_TASK_RESCHED_OFFSETS) + +#define put_task_might_resched() \ + do { \ + if (IS_ENABLED(CONFIG_PREEMPT_RT)) \ + __put_task_might_resched(); \ + } while (0) + static inline void put_task_struct(struct task_struct *t) { + put_task_might_resched(); if (refcount_dec_and_test(&t->usage)) __put_task_struct(t); } static inline void put_task_struct_many(struct task_struct *t, int nr) { + put_task_might_resched(); if (refcount_sub_and_test(nr, &t->usage)) __put_task_struct(t); } -- 2.40.0