Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp338734rdb; Thu, 22 Feb 2024 05:33:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUWimSkXZl+ikvExHXlQ6qKnxm2PntAru0ZaE9okNJFYC50OTEHxr8h3gKVpBZ4/a7a9a++XhMA0dmcFyQQvBidSvi/PWqqU8UvzLVM2w== X-Google-Smtp-Source: AGHT+IF/pVqMOg2RQbOAaV0VLUOhjnaVIpZZ9z03ewZ7fKHZSe0Z0Vk4vK10G+EMRD7MNawdtq93 X-Received: by 2002:a05:6402:1045:b0:561:cec7:cb1b with SMTP id e5-20020a056402104500b00561cec7cb1bmr14447660edu.32.1708608831558; Thu, 22 Feb 2024 05:33:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708608831; cv=pass; d=google.com; s=arc-20160816; b=AD27z8GLvG/JXsAIPHGI8Ce+ZRqdOKxUR+Vck6DdTCDDz8wg5Xi1+hXQ78N/dl/RRw XGildXrW6ZroAfUJzUf0ZWZhsplejGhQosUwFbMK7mkgoPkKjpeyMQM15UFT5+/Qbzn0 7neOk6xk1b7W5Jtc0RayOZ23vdkSnNL5SMtzdCLc5q43B9vTIZOjmF0tda/CYLgICpii GoIsQC6Mu6WfF4YKF8TbvwvBM/Pz40YalG3lS5z4h8wiZLQc5hsmL8YvXy2LJ1UkCGxV GC7C1/VhsBzlVMyVrRS7ca1E/MCvUZkmexNYjGMeI7kubPXfeFuRWTCNL1c5gOIm0GeO hs4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Kf5vbm46zvCvirSgaBCAUyipa0OcueyRJ9iBoOT/nVY=; fh=N5fTIFf2i7nvF8Om7kdprA8Zy2dleTNav/f0ArIISzo=; b=S/DKVdDPtmO/G1awbHA/C4R+uDg00sjO/Cy9VI4o9mA31rnNZba4fsGy9r/Uo6Xaj7 DGBLc/DSyD0de/KIwu53VCBijEPFWy43zizzULgK8LbtWJNTu2s7HRwo3uL832x7qXzC u0Rmz18i8UzOJxYFmIVTVobuwlZ2B462w0ZuzVgmKNTQgL8bmnqWeKhRjn/OHiPSS5cp isomT8MmJRPJDyBwYTGxDraUhMDYBwk5V7gJ5nYkZ1fT08re3fie5f1zPG/8d2fC85AM Do69CJhVF4mUQlSwtjhE+mjvj6UVbhyK0h0ni3fsSIbUsV30pzgA+0odTnFJ6XEfdq4G gIEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=v6OiMPTE; 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-76604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g10-20020a0564021eca00b005640b40a448si4624838edg.657.2024.02.22.05.33.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:33:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=v6OiMPTE; 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-76604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76604-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 547591F21399 for ; Thu, 22 Feb 2024 13:33:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D269B1350DA; Thu, 22 Feb 2024 13:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="v6OiMPTE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dQwuMnN1" 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 9B18B134CF7 for ; Thu, 22 Feb 2024 13:33:30 +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=1708608812; cv=none; b=C7zIPjj6rmeUZtd/Wa2vbyPGxLb6cB+HJ3wzZYjBkgc+dla32y15ecmcC7K5ajcUqtROJvbzvzRhvvmK3Yw/HmgyLou2YeqnlGsIqgIcZohORugEcb+E/4UMFiLdwCLhUG+ZlDHUNXLUF6P9IMUzdknJ2kZfso0jn3lfzLMzLpg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608812; c=relaxed/simple; bh=Qk4e68m7L/wYYFcyfUP3vhvzpWn6XgmiyH7aWBw11Ng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qOZPob07AhPnLuyPEyNWccwYQVPV+CFJHhsyEjJLBT+IjRetZ0rOH2wZ2YSXXRO7CgOMJWXAuEkhIlarttm8mLiNjkx87OAyPgxxiko6FIHTax6PPG4qWHnMcBB38C4CJ1KXOlJv4cgXCgH0wc4sNPidpTzkYyX/1qD6tCS2wiY= 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=v6OiMPTE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dQwuMnN1; 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 From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708608808; 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=Kf5vbm46zvCvirSgaBCAUyipa0OcueyRJ9iBoOT/nVY=; b=v6OiMPTEDAXg/94M8UJiTcACAOoAQu61hw8Dc8QyG08GP6thPgPGO9aBDnDTdIk+l1Rx44 sxmbbq9T/J7bmxqlEDijSgdP8WjzsgFQwyBNGAhQcfVtUCiHZlQDgQHQab5K/mZQ0GJKJ4 CkcMdicrXu/4CyKOiBiZSpt42LAJbdCAUbxLK4cwnl1dVF3a9NdKs39iyeryWHsOIMpKRl 50NRwA+NxMa5JCo5OS8KHFnDJrGvk1svbJMSOfk6mOU/a+eJ2VZTQLqkbZCFDlWytxpZCC 281YXffru71Buo/052IfwXqz8vohaZZdxdDAtQNDBQ/DrF+SU/IKLDJh0/Vj7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708608808; 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=Kf5vbm46zvCvirSgaBCAUyipa0OcueyRJ9iBoOT/nVY=; b=dQwuMnN1TIWItdH9T5jbQIeuRd2HEbuaTIAxaI1YBftInQN2LhNroG4NpQgm7FtDzfIV4b VPXEHr8eEesTMiAQ== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Frederic Weisbecker , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak , Christian Loehle , Anna-Maria Behnsen Subject: [PATCH] timers/timer_migration: Fix memory barrier comment Date: Thu, 22 Feb 2024 14:33:20 +0100 Message-Id: <20240222133320.43780-1-anna-maria@linutronix.de> In-Reply-To: <20240221090548.36600-1-anna-maria@linutronix.de> References: <20240221090548.36600-1-anna-maria@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Comment about the required memory barrier in tmigr_inactive_up() is not written properly. Rewrite it and add also new comments to the other memory barrier related places. Also make clear, why a memory barrier in tmigr_active_up() is not required. Signed-off-by: Anna-Maria Behnsen --- This is a fix for the patch 'timers: Implement the hierarchical pull model' v11b. --- kernel/time/timer_migration.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 0825ccdcfae4..23cb6ea3d44e 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -623,6 +623,11 @@ static bool tmigr_active_up(struct tmigr_group *group, u8 childmask; childmask = data->childmask; + /* + * No memory barrier is required here in contrast to + * tmigr_inactive_up(), as the group state change does not depend on the + * child state. + */ curstate.state = atomic_read(&group->migr_state); do { @@ -1215,9 +1220,16 @@ static bool tmigr_inactive_up(struct tmigr_group *group, u8 childmask; childmask = data->childmask; - curstate.state = atomic_read_acquire(&group->migr_state); childstate.state = 0; + /* + * The memory barrier is paired with the cmpxchg() in tmigr_active_up() + * to make sure the updates of child and group states are ordered. The + * ordering is mandatory, as the group state change depends on the child + * state. + */ + curstate.state = atomic_read_acquire(&group->migr_state); + for (;;) { if (child) childstate.state = atomic_read(&child->migr_state); @@ -1257,10 +1269,12 @@ static bool tmigr_inactive_up(struct tmigr_group *group, if (atomic_try_cmpxchg(&group->migr_state, &curstate.state, newstate.state)) break; + /* - * Add memory barrier to make sure child and group states order - * of read is preserved. This barrier is only required when - * atomic_try_cmpxchg() failed. + * The memory barrier is paired with the cmpxchg() in + * tmigr_active_up() to make sure the updates of child and group + * states are ordered. It is required only when the above + * try_cmpxchg() fails. */ smp_mb__after_atomic(); } -- 2.39.2