From patchwork Mon Jun 5 15:08:29 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: 103335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2759252vqr; Mon, 5 Jun 2023 08:18:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7H+zIPzvif8JFrlF61sdIbMq0x1xxsZo9A1q4rs+t2/Ftj0/FeTTAT7I0lCTJ8nHt1vac6 X-Received: by 2002:a17:90a:4ca4:b0:23f:962e:825d with SMTP id k33-20020a17090a4ca400b0023f962e825dmr8530475pjh.1.1685978275633; Mon, 05 Jun 2023 08:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685978274; cv=none; d=google.com; s=arc-20160816; b=XPjbe6jrCxyZjWk8GtFHdsTewNphSu6fiz/qgz3T/aia8wNggvVoZYXE+hF7L/xynQ /so2eOHuBRrJF/h8qbomfMU+EUdAQF5iDi5qiX8pOTKQx6QCiW//Yugzb66XOjeuPW8s mCQb72J9Z2ozQ6IW73lvrAIylJjuFCYWh8TAj8kVc95mEhDgwHbKNjGr163Q5U14ENNI mmBcJDmBiHvWGok42jS9cDApsH3ATheJvLE4naGESd1HLvDxAEjJbt3GvTof1fV94jV2 m90V8H4HJYAT+ecDtgrBPTk/BVsRICt61qeHYlWjSy/g2bSulKickYxwnYw6cDEyByA5 CyiQ== 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=OBdeCUFo/IU1pBwgRAOi17itc3qlLbBiaXExgTWjgC8=; b=mIjJ/gNx36n6VWeabPzIeSWpPhx7bK6QxVv9t8i/wbccGFOX8wjZVIABC2XARUqhVu Yrc8S4QRFJonkZKwQ3zH2EgeeM+pq1zehFaRkfEAHjHrRPwbDWDgvwkD6Yhq4sV/nxGX KEbCZSRXEu0Lgm3bvbPsktQq9Mn7PDaMJNQFYHBgr8ghIOLji5LLFGkARb4YCLGX77fZ 0gJs4ErQQfKq1/427Ec1ep9JQgVWby3m4bRYor21h8+VRCsH6FLIhSAl2t6FjOZkHj1V FHLIjxEvkpEsLhkfX957l2ufxR2UUkfou4CaEqTR9iW2tbB6oCOyDrTGywDlCeVwl+rE KkGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1+wmDHao; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 b18-20020a639312000000b0053ef281cfb0si5819732pge.102.2023.06.05.08.17.42; Mon, 05 Jun 2023 08:17:54 -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=1+wmDHao; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233824AbjFEPJS (ORCPT + 99 others); Mon, 5 Jun 2023 11:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234149AbjFEPIc (ORCPT ); Mon, 5 Jun 2023 11:08:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A9DDE8; Mon, 5 Jun 2023 08:08:31 -0700 (PDT) Date: Mon, 05 Jun 2023 15:08:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685977710; 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=OBdeCUFo/IU1pBwgRAOi17itc3qlLbBiaXExgTWjgC8=; b=1+wmDHao8XBiMfVll797Q6pRfFex5htu6uDgDFtq+hPBoX0eRhuwtG8qFmThIHj31UVnDi B7bMA99ZujZkjkSMA6NLOaTymYTbCVc5rWDH2I9/3sk7rbwXOhg9w77cvSKK9dXK5u1i+k Eafy1cV2yhHqDb/OSY0AeG7/Ve4CRgMNv7yVeaHtlNJFROu2mIUQ87zOpT0zJSX9NOhD3l Jj603lay0U72LRFcZWdpe2G+aGXrYACh99lt87f84iOTKXx7C7nmg9pO/0/HaQQNt0y8wc smFXNeaK3k2yqOJJNY5OyqI6nGPGszo16yine/euJoQCtHw/JoT+l2e6w7Sslw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685977710; 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=OBdeCUFo/IU1pBwgRAOi17itc3qlLbBiaXExgTWjgC8=; b=aPaY2BmLV1ycdu7pg56oqpa1lG5CLmSUd+yEmj47BTlSO3z0FhV28k9mTzq6HAMd4nCZM6 tOmAeHwKjZuw5jBQ== 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: Split release_posix_timers() Cc: Thomas Gleixner , Frederic Weisbecker , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230425183313.301432503@linutronix.de> References: <20230425183313.301432503@linutronix.de> MIME-Version: 1.0 Message-ID: <168597770958.404.15665270041131228632.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?1764175797086414200?= X-GMAIL-MSGID: =?utf-8?q?1767876355765380653?= The following commit has been merged into the timers/core branch of tip: Commit-ID: e7441aa344046cbdcb402ac173fb163613471097 Gitweb: https://git.kernel.org/tip/e7441aa344046cbdcb402ac173fb163613471097 Author: Thomas Gleixner AuthorDate: Tue, 25 Apr 2023 20:49:09 +02:00 Committer: Thomas Gleixner CommitterDate: Mon, 05 Jun 2023 17:03:37 +02:00 posix-timers: Split release_posix_timers() release_posix_timers() is called for cleaning up both hashed and unhashed timers. The cases are differentiated by an argument and the usage is hideous. Seperate the actual free path out and use it for unhashed timers. Provide a function for hashed timers. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker Link: https://lore.kernel.org/r/20230425183313.301432503@linutronix.de --- kernel/time/posix-timers.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index d8d4cdf..8153374 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -466,20 +466,21 @@ static void k_itimer_rcu_free(struct rcu_head *head) kmem_cache_free(posix_timers_cache, tmr); } -#define IT_ID_SET 1 -#define IT_ID_NOT_SET 0 -static void release_posix_timer(struct k_itimer *tmr, int it_id_set) -{ - if (it_id_set) { - spin_lock(&hash_lock, flags); - hlist_del_rcu(&tmr->t_hash); - spin_unlock(&hash_lock, flags); - } +static void posix_timer_free(struct k_itimer *tmr) +{ put_pid(tmr->it_pid); sigqueue_free(tmr->sigq); call_rcu(&tmr->rcu, k_itimer_rcu_free); } +static void posix_timer_unhash_and_free(struct k_itimer *tmr) +{ + spin_lock(&hash_lock); + hlist_del_rcu(&tmr->t_hash); + spin_unlock(&hash_lock); + posix_timer_free(tmr); +} + static int common_timer_create(struct k_itimer *new_timer) { hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0); @@ -493,7 +494,6 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, const struct k_clock *kc = clockid_to_kclock(which_clock); struct k_itimer *new_timer; int error, new_timer_id; - int it_id_set = IT_ID_NOT_SET; if (!kc) return -EINVAL; @@ -513,11 +513,10 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, */ new_timer_id = posix_timer_add(new_timer); if (new_timer_id < 0) { - error = new_timer_id; - goto out; + posix_timer_free(new_timer); + return new_timer_id; } - it_id_set = IT_ID_SET; new_timer->it_id = (timer_t) new_timer_id; new_timer->it_clock = which_clock; new_timer->kclock = kc; @@ -569,7 +568,7 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, * new_timer after the unlock call. */ out: - release_posix_timer(new_timer, it_id_set); + posix_timer_unhash_and_free(new_timer); return error; } @@ -1057,7 +1056,7 @@ retry_delete: WRITE_ONCE(timer->it_signal, NULL); unlock_timer(timer, flags); - release_posix_timer(timer, IT_ID_SET); + posix_timer_unhash_and_free(timer); return 0; } @@ -1109,7 +1108,7 @@ retry_delete: WRITE_ONCE(timer->it_signal, NULL); spin_unlock_irqrestore(&timer->it_lock, flags); - release_posix_timer(timer, IT_ID_SET); + posix_timer_unhash_and_free(timer); } /*