From patchwork Mon Jun 5 15:08:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 103327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2753601vqr; Mon, 5 Jun 2023 08:10:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hGJA1bpWeHVASGQfAaKlz52H1OawgwShPN1ECyb3XQWBmb1O+Xldt7/H+qHhdL+HZqCfH X-Received: by 2002:a05:6a00:cd3:b0:656:5f06:ffa1 with SMTP id b19-20020a056a000cd300b006565f06ffa1mr11498pfv.1.1685977829941; Mon, 05 Jun 2023 08:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685977829; cv=none; d=google.com; s=arc-20160816; b=rwuk3j5W3Xy2+sGbMOPRJLVbjjUOkD8e/L9c1X3tgLtrNEMV2E4ew0P7lpdHhnUVd1 jeUcsq+aa12TO7pliacuD3jH1zXr6tQIletVSaJgKVyYrT0NcjPFRxvo4rby9FyQnPV3 RQ2LsRL2P6N/6Crk+/TYMDDTvKjjYlDzCaQc9/5z0jp11MqQVLSseZb0Rl5Kqa/qNzBq NaeuypSxo97nu4AGUrmj//DbUGaJa1cG9zC3nlDcMwRru0p3UAHsbCyjWZk8HKwWi1X3 M4HqKG9ZRad6CPvklitmVt6jbYB54Bj3Pt1rmi47NOG5WViB7MRo0b+rBuZT1s7JdpMh 2/Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=qQgeEb9hS2OwslC7UYMEj5kd+JcImTvjidFJIvXXFOs=; b=lIXDaT6wgqwcvK5KkaKnIPZjZuwlZ5GOv3F0QkfMRq7/md2AMCkKiS5XdmL1SYjGsM gHh8n4cj3OFb/eEQTvEmWyGfYD8n2+8CJUlOFn/doGErmivqiQcSCc0GfWu3FIQXSMwx lftzycyVDasW4mijhXRqHchIS1UcII1FONPHjCnk1ohYdw/lCkhOg/tflOv6wM5XxjHz I+6U/22yQkLLKTUyR3jQvr7pIppZwoiJ4b4amb5fQjP3CyQYjOKDzGeLyi7KWep720ZU BTNS6V2bRB6E4GyHRm+6qpk2v2Upkk1pi81AtdnrLlWVQMu00Mmn16cRzIHIEcEO/uju 9DIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jS1DOadp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=U1LBd8Er; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020a637155000000b00542d1731d1fsi4273847pgn.320.2023.06.05.08.10.14; Mon, 05 Jun 2023 08:10:29 -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=@linutronix.de header.s=2020 header.b=jS1DOadp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=U1LBd8Er; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234724AbjFEPJK (ORCPT + 99 others); Mon, 5 Jun 2023 11:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234179AbjFEPId (ORCPT ); Mon, 5 Jun 2023 11:08:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6920BF3; Mon, 5 Jun 2023 08:08:32 -0700 (PDT) Date: Mon, 05 Jun 2023 15:08:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685977711; 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=qQgeEb9hS2OwslC7UYMEj5kd+JcImTvjidFJIvXXFOs=; b=jS1DOadp3IhmJDNaG14EhTQmT1+W7/QTKKTf9jWhDcFOqUERAJOz6qQj+meKSGzKlL15jM cLWMmwISBltGwbP0QllEHbHoMtBtD6DqNZ6lARHu6AOu3vTfR342xmkdoXT9C4MWMREe3m 7ZjeN3+HnKrEC8yzPhEnCKhicuRy7n6KkF3cJtvJ9sD5uioDjoZxOYAbYxX3QEPL37MBX8 +VaKVyPRDTGm17Tm1oRj75Xjqd3uyUM8/Pwi1hpCH4RX6s9iXtHiFPt+Y5XWzLW0cksVax yu68vNV4/innosGKBKwrQLooQsmKRwbtE88VfIaSIPZCd0SfF8kn9PIm7nBaTA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685977711; 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=qQgeEb9hS2OwslC7UYMEj5kd+JcImTvjidFJIvXXFOs=; b=U1LBd8ErHQ6NvkVNFsv3pPQjmXOlBLNmWR2jKXS3khWdYoR0/qA3uL+HUsNIFtpA67Bc/6 2loI/UUxOhuYq0CQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] posix-timers: Annotate concurrent access to k_itimer:: It_signal Cc: Thomas Gleixner , Frederic Weisbecker , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230425183313.143596887@linutronix.de> References: <20230425183313.143596887@linutronix.de> MIME-Version: 1.0 Message-ID: <168597771061.404.17723098484982029633.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767875889079343801?= X-GMAIL-MSGID: =?utf-8?q?1767875889079343801?= The following commit has been merged into the timers/core branch of tip: Commit-ID: d69e873ee50459e3b77019263cf95236f063a97b Gitweb: https://git.kernel.org/tip/d69e873ee50459e3b77019263cf95236f063a97b Author: Thomas Gleixner AuthorDate: Tue, 25 Apr 2023 20:49:05 +02:00 Committer: Thomas Gleixner CommitterDate: Mon, 05 Jun 2023 17:03:37 +02:00 posix-timers: Annotate concurrent access to k_itimer:: It_signal k_itimer::it_signal is read lockless in the RCU protected hash lookup, but it can be written concurrently in the timer_create() and timer_delete() path. Annotate these places with READ_ONCE() and WRITE_ONCE() Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker Link: https://lore.kernel.org/r/20230425183313.143596887@linutronix.de --- kernel/time/posix-timers.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index f6650c1..4333334 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -109,9 +109,9 @@ static struct k_itimer *__posix_timers_find(struct hlist_head *head, { struct k_itimer *timer; - hlist_for_each_entry_rcu(timer, head, t_hash, - lockdep_is_held(&hash_lock)) { - if ((timer->it_signal == sig) && (timer->it_id == id)) + hlist_for_each_entry_rcu(timer, head, t_hash, lockdep_is_held(&hash_lock)) { + /* timer->it_signal can be set concurrently */ + if ((READ_ONCE(timer->it_signal) == sig) && (timer->it_id == id)) return timer; } return NULL; @@ -558,7 +558,7 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, spin_lock_irq(¤t->sighand->siglock); /* This makes the timer valid in the hash table */ - new_timer->it_signal = current->signal; + WRITE_ONCE(new_timer->it_signal, current->signal); list_add(&new_timer->list, ¤t->signal->posix_timers); spin_unlock_irq(¤t->sighand->siglock); @@ -1052,10 +1052,10 @@ retry_delete: list_del(&timer->list); spin_unlock(¤t->sighand->siglock); /* - * This keeps any tasks waiting on the spin lock from thinking - * they got something (see the lock code above). + * A concurrent lookup could check timer::it_signal lockless. It + * will reevaluate with timer::it_lock held and observe the NULL. */ - timer->it_signal = NULL; + WRITE_ONCE(timer->it_signal, NULL); unlock_timer(timer, flags); release_posix_timer(timer, IT_ID_SET);