Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp566730lqp; Fri, 5 Apr 2024 02:11:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyCEickNY5FdC1l+o47lkUKz7Qt7uLGxLARVc1vDnHle1TcbpxgqSNikWuLC0mieqOUXt1Cf8yIoUNRDo9Af9MYlLB8ua/fiiUhYjGjA== X-Google-Smtp-Source: AGHT+IFaIRyGyhGIDg0gMuG/592bELHkazmuDkZk83A5/GvAKOVRy5zmb4BBT5sXjVe3vWgpVtGb X-Received: by 2002:a05:6870:3753:b0:229:f403:136e with SMTP id a19-20020a056870375300b00229f403136emr849675oak.56.1712308302816; Fri, 05 Apr 2024 02:11:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712308302; cv=pass; d=google.com; s=arc-20160816; b=FBIRYvuTY37R9jHkJ1ZDnENkn9TVHSGn4P3Mc51KhQvGeHViVrYxYd+WhPKh4MY3Z7 tQGT9Xvoz9qKbeFGOsQf+9Tztd2VDP54oRTdkwFL4JOTFXcMmzlffkZvMLGHRqyvAs9c 6wZJ46wbt7ohsebfi1WaCSLmO/XB1aPPZ9jeJ91rqVQ1LKdjAFHdkovNeeiKuu/mHe9n FDlEylfEGXL2zmU31ApjDDgtDjjY/qp72yOskP4GrqjD2nHy6kvezm0Fp12Bb1+NwGSU qRLAa6tPNEHBTXqWbSoBmoL2N9sK/UwHktLWRne6Aq4+FG+xXFPY2dUw/WcIfqQz8r3n qayQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=1zGzV+I7AEheSHfzAb4K16/iiWoyWFVRjcXBcFqSIjM=; fh=IdquJyaazQ3wXWxdOExnpctJRLX4Jw3HEb/tnyKonzY=; b=JZ4cycizkD1YUIx4Ig3H+Ki40FsGDrZkpFXgLCjm7wyHvXc5/Sw1TACUgvVSg9n5pp Ww2HBdgLgUPCxcrCPNIRB8LRTr1Q9KlWnPrN2ipyUH3XAjkQLZaox+yP7AxdLBHe6wji 5w98+GU81f9yhr30QSYbx5CsRfz6wGXvVZlCl0IWFJhijUyroIu0SrR8MwKsodDx62eW g3A4msmfJM61is+ikb1VawvmnBw4bOc8uYm0VHdy9Xpp4tPSDo6pxld//GNQYJUCD8b6 xLaw4VfmitqSp/pd1y4/xx6RTR9X/4bDiRX/ydZbcL0PBtcEmwlEfvqhWvNTxwcWMmfa 7AUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Gj5bL1St; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-132706-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132706-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m17-20020a62f211000000b006ecfc7f651asi1031984pfh.285.2024.04.05.02.11.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 02:11:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132706-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Gj5bL1St; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-132706-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132706-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6A22E283735 for ; Fri, 5 Apr 2024 09:11:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6528515FCF5; Fri, 5 Apr 2024 09:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Gj5bL1St"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UAPO0tr7" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 832AE15FCEA; Fri, 5 Apr 2024 09:11:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712308296; cv=none; b=EOjHdofc94w0wRo8tqGQBN5KQCTNFbH1xXSRAmre5xGbaAfyl5nzmUsDG5imc5vUNvTcuxTrEEEfTITry3VfK3EnZrvp1NR7F8Hhoc42n2baHqgMgwaQ2RYQmHMhCzGnWNASKnUEbeGMDm+o2tFqqbI0an2Q2EvuS5rXr2O1Na4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712308296; c=relaxed/simple; bh=3fM1sBTrWSY49lNY8xf7sHtghdnUv2AGy1br7QxCdwM=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=S3zY/SIpjY5j9cIBnyWcRqb8h0L0liequHgjzMDC0qPnBQK7457AZiCwX2eOSN+ID6NCZ4CxO1DbVngwuQNgvhSVPMHXbWmmFWjIP/Lyona6eAFC/uAnBw/ELKCcl5t230qRzlxXi9XJmeHuiT682KbTo0Cxw2+E9ZfY9v8mExg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Gj5bL1St; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UAPO0tr7; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 05 Apr 2024 09:11:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712308292; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1zGzV+I7AEheSHfzAb4K16/iiWoyWFVRjcXBcFqSIjM=; b=Gj5bL1StbnrNKCWIg4Gch2EqAcDWZR7cRa/LsgwsQSuq3KhdfIBE4JNg4N6juPybomsS1G VmklLNIXtbgnRnYd0dtQMBbklWEp0e3DW8tFP7ovzW5oEZquS54eY/3Wcc7ra0rXcfywvU t5puKiLqhEuiWtcfSDcLKOzrSQ2JxDnGCCgFmIzoFKVx3mLCbCABGQmn5RNc37rhg4Frvw UQflRe+vqvzA4E+G+RG41w+nG3uQ7/YiaQ9Djy5XkzOIzggIIzk5MeKSICzONCrq2ToOCU Zf3ArYRQBBUMIEpA4OtLQWutwkvEpfVlgjSFlevJkRUh5YsimXwNGJPerFE+qw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712308292; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1zGzV+I7AEheSHfzAb4K16/iiWoyWFVRjcXBcFqSIjM=; b=UAPO0tr7EShuISW/alaR6rEhPbizbf9LF2IaEzKUqFrnINoSakWLmK9ubZB14PTp6hmjRg 0n1eJR508482pGAg== From: "tip-bot2 for Anna-Maria Behnsen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] timers/migration: Return early on deactivation Cc: "Anna-Maria Behnsen" , Thomas Gleixner , Frederic Weisbecker , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <87cyr49on2.fsf@somnus> References: <87cyr49on2.fsf@somnus> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171230829183.10875.12362342443387420509.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the timers/urgent branch of tip: Commit-ID: 7a96a84bfbee96871bb16c70ee3e93d564e190f4 Gitweb: https://git.kernel.org/tip/7a96a84bfbee96871bb16c70ee3e93d564e190f4 Author: Anna-Maria Behnsen AuthorDate: Fri, 05 Apr 2024 10:53:21 +02:00 Committer: Thomas Gleixner CommitterDate: Fri, 05 Apr 2024 11:05:16 +02:00 timers/migration: Return early on deactivation Commit 4b6f4c5a67c0 ("timer/migration: Remove buggy early return on deactivation") removed the logic to return early in tmigr_update_events() on deactivation. With this the problem with a not properly updated first global event in a hierarchy containing only a single group was fixed. But when having a look at this code path with a hierarchy with more than a single level, now unnecessary work is done (example is partially copied from the message of the commit mentioned above): [GRP1:0] migrator = GRP0:0 active = GRP0:0 nextevt = T0:0i, T0:1 / \ [GRP0:0] [GRP0:1] migrator = 0 migrator = NONE active = 0 active = NONE nextevt = T0i, T1 nextevt = T2 / \ / \ 0 (T0i) 1 (T1) 2 (T2) 3 active idle idle idle 0) CPU 0 is active thus its event is ignored (the letter 'i') and so are upper levels' events. CPU 1 is idle and has the timer T1 enqueued. CPU 2 also has a timer. The expiry order is T0 (ignored) < T1 < T2 [GRP1:0] migrator = GRP0:0 active = GRP0:0 nextevt = T0:0i, T0:1 / \ [GRP0:0] [GRP0:1] migrator = NONE migrator = NONE active = NONE active = NONE nextevt = T1 nextevt = T2 / \ / \ 0 (T0i) 1 (T1) 2 (T2) 3 idle idle idle idle 1) CPU 0 goes idle without global event queued. Therefore KTIME_MAX is pushed as its next expiry and its own event kept as "ignore". Without this early return the following steps happen in tmigr_update_events() when child = null and group = GRP0:0 : lock(GRP0:0->lock); timerqueue_del(GRP0:0, T0i); unlock(GRP0:0->lock); [GRP1:0] migrator = NONE active = NONE nextevt = T0:0, T0:1 / \ [GRP0:0] [GRP0:1] migrator = NONE migrator = NONE active = NONE active = NONE nextevt = T1 nextevt = T2 / \ / \ 0 (T0i) 1 (T1) 2 (T2) 3 idle idle idle idle 2) The change now propagates up to the top. Then tmigr_update_events() updates the group event of GRP0:0 and executes the following steps (child = GRP0:0 and group = GRP0:0): lock(GRP0:0->lock); lock(GRP1:0->lock); evt = tmigr_next_groupevt(GRP0:0); -> this removes the ignored events in GRP0:0 ... update GRP1:0 group event and timerqueue ... unlock(GRP1:0->lock); unlock(GRP0:0->lock); So the dance in 1) with locking the GRP0:0->lock and removing the T0i from the timerqueue is redundand as this is done nevertheless in 2) when tmigr_next_groupevt(GRP0:0) is executed. Revert commit 4b6f4c5a67c0 ("timer/migration: Remove buggy early return on deactivation") and add a condition into return path to skip the return only, when hierarchy contains a single group. Adapt comments accordingly. Fixes: 4b6f4c5a67c0 ("timer/migration: Remove buggy early return on deactivation") Signed-off-by: Anna-Maria Behnsen Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker Link: https://lore.kernel.org/r/87cyr49on2.fsf@somnus --- kernel/time/timer_migration.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index e3075e4..ccba875 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -751,6 +751,33 @@ bool tmigr_update_events(struct tmigr_group *group, struct tmigr_group *child, first_childevt = evt = data->evt; + /* + * Walking the hierarchy is required in any case when a + * remote expiry was done before. This ensures to not lose + * already queued events in non active groups (see section + * "Required event and timerqueue update after a remote + * expiry" in the documentation at the top). + * + * The two call sites which are executed without a remote expiry + * before, are not prevented from propagating changes through + * the hierarchy by the return: + * - When entering this path by tmigr_new_timer(), @evt->ignore + * is never set. + * - tmigr_inactive_up() takes care of the propagation by + * itself and ignores the return value. But an immediate + * return is possible if there is a parent, sparing group + * locking at this level, because the upper walking call to + * the parent will take care about removing this event from + * within the group and update next_expiry accordingly. + * + * However if there is no parent, ie: the hierarchy has only a + * single level so @group is the top level group, make sure the + * first event information of the group is updated properly and + * also handled properly, so skip this fast return path. + */ + if (evt->ignore && !remote && group->parent) + return true; + raw_spin_lock(&group->lock); childstate.state = 0;