From patchwork Thu Feb 22 13:33:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 204765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp256830dyb; Thu, 22 Feb 2024 05:40:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV8q2+8EoB+PdEGmPqWXIYV+WMo1uktV9Uz0xZf8csGs8F6JmszMoS+xkXN7m2beCUuKDO61jd1VZ7TgM/xd2lCU4NL8w== X-Google-Smtp-Source: AGHT+IFjf5LScSiuW2fXQjWA1dmg1dOyqnr/1w8E10vNdQC0o3cM7vgScCtPbl2xB+EvSwAMXQd2 X-Received: by 2002:a05:6358:78b:b0:17b:58a6:5172 with SMTP id n11-20020a056358078b00b0017b58a65172mr4582591rwj.21.1708609201837; Thu, 22 Feb 2024 05:40:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708609201; cv=pass; d=google.com; s=arc-20160816; b=E68RLA4wIDoDK5AOBVU1iz8oD1phXboCN9HpqnedCdsSTX0kicyLrjFFyhofP1ShGd ZjMBixW+SC8vg5NkPKRs/kC0WyN9Vz9rH+EGXv0iz2ypwd6KKWAumPpb8slWaLdI8WNA FlPoxG+XnhA10o1z1X5M+aqiwYak0PP1EheXmq2XGGKb3khMfs/aiGLtxU46gWBDqs9e 7Cc0pRDviwlOdYj7BKpBpzBJ2ePjAQ+uPKn/ULeQhQgtLyGksdoiKZQiCjDkqVrHmkAQ 4EXAcWxwa5zwwAxBBKz3VzWDM9Rlfd147dIvj3azD2Mt+y0H/tFGmmtlJ9/LF6AnOx2B v0PA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76604-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lp17-20020a056a003d5100b006e48bbb4be9si3863772pfb.334.2024.02.22.05.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:40:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76604-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76604-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A63B4B24C36 for ; Thu, 22 Feb 2024 13:33:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87A62135410; Thu, 22 Feb 2024 13:33:34 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791606602296210411 X-GMAIL-MSGID: 1791606602296210411 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 Reviewed-by: Frederic Weisbecker --- 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(); }