From patchwork Wed Mar 1 14:17:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 62916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3658521wrd; Wed, 1 Mar 2023 06:22:52 -0800 (PST) X-Google-Smtp-Source: AK7set9KvWtkiw3QPV+g3kpsr5GCvvoCkhev2DOp/nVY9ijGI7krJ4CQfTtOPJICSm2f2+iKB156 X-Received: by 2002:a05:6402:652:b0:49d:a60f:7827 with SMTP id u18-20020a056402065200b0049da60f7827mr7625957edx.6.1677680572034; Wed, 01 Mar 2023 06:22:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677680572; cv=none; d=google.com; s=arc-20160816; b=xlEhinZoXG1ICPCG49pgEoxnT8cGB72r5pAjWv3LvVBawg+/DfCqL/Jn2uJCU3Ba9E hNybYirXBVNzKhSr7EfKUlEHagL9o+Mw1QUv+J/Z7bF4UO6wKi9H5JrUT8t5UgA2bkcI lzdtB10SFYceoDwmLZkaLLAVRNSjk/UoQONudfCTPslXQONEXSAqv3ca1ppRdPtzWXlg i0oncxuaiLA0cdAlWMp+iIT+fI8En4GkvvhQZvubpW19YmI2F2JiCNP9T/72tuB8oXrP 5MgvY4Yoao7zYgy4bhSh7Hyh8riCF/0iTGrDskub9eHWfPA6rJ3hbSnwURjbsMGdC3Q1 Z+DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=61R/6m3cWzpu0i+kgy8BBTevSM03VxMJMhiETBOD2eY=; b=B2LK2cbYMRLwAP8Jl8XjX3jwhZ/QXE3FxuUcdzkKofCv8wVUOxU9YVPtoPLy3X3b+/ yxtoG6jkE9U5FWENcdrITBQxfuNT5q0EMFHAIBD1z8nU06bVF5tzDzbCIW2fMBmKOqfr 47KUXl0tDmdlQ1JVoz+CePLzTB/JN4F6lm5BLo3aAypYM5BiHElD/ANxBv0M3FIGL1YW p0ZZFtBBIfy5huGGPolTJMCTnZOi16/EFC1XLY/b2hYzrblxiHC3jSzcDamO5UATA7ni SJj+A5RrzgYohRQc7YboppOGM5E25Tx6vc4hwm9rxmmPre22I0ZO4Qe1mJE2Dz2+mfQ9 b5XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hJGMDtSm; dkim=neutral (no key) header.i=@linutronix.de header.b="EfG+Pih/"; 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 by14-20020a0564021b0e00b004accb68cc93si2477028edb.387.2023.03.01.06.22.27; Wed, 01 Mar 2023 06:22:52 -0800 (PST) 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=hJGMDtSm; dkim=neutral (no key) header.i=@linutronix.de header.b="EfG+Pih/"; 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 S230088AbjCAOSc (ORCPT + 99 others); Wed, 1 Mar 2023 09:18:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230057AbjCAOSK (ORCPT ); Wed, 1 Mar 2023 09:18:10 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA3122331A for ; Wed, 1 Mar 2023 06:18:07 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677680285; 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=61R/6m3cWzpu0i+kgy8BBTevSM03VxMJMhiETBOD2eY=; b=hJGMDtSmaW6X+SmKXImqcyNQ41a6XFWvmTIEMMKcClZ2tyoL4yyvd/rL6PtyPF6gPwbVEa NmNsfJrEF82YQLynRZ8T/QGvXijl9QHlBcLZX/xch6QeK2ETGvGnlcI6pP5a88C+pcPrIW uf3w/UakWz9nM5hqk9Vd36nhRPZL0ieTWjSDPtZ5KuAcE08aK7X2nDwhGibHuwEb6oSxRL sjMPcs7R/TXKNZikPJ7UKa6NciIIM4Ks0+dZBBw5YD88BbNstfPKqoXyOb8JC3LVmf+fAo /pzmKe47Lm4j4KhPBuRANu1lt77XwJ3G7swxcIWuwoGwBPrFWXrJAavG2MjzXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677680285; 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=61R/6m3cWzpu0i+kgy8BBTevSM03VxMJMhiETBOD2eY=; b=EfG+Pih/pAPGwXQLXhIy/5G1cbdLAIxWy49IZB0zbJf7Hyl29HbCpokJIlDMoEkhctkA/+ Z+sCzFUC1d6jasCw== 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 , Anna-Maria Behnsen , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Theodore Ts'o" , "Jason A. Donenfeld" , Stephen Boyd , Tejun Heo , Lai Jiangshan Subject: [PATCH v5 06/18] add_timer_on(): Make sure callers have TIMER_PINNED flag Date: Wed, 1 Mar 2023 15:17:32 +0100 Message-Id: <20230301141744.16063-7-anna-maria@linutronix.de> In-Reply-To: <20230301141744.16063-1-anna-maria@linutronix.de> References: <20230301141744.16063-1-anna-maria@linutronix.de> MIME-Version: 1.0 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 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?1759175583888852093?= X-GMAIL-MSGID: =?utf-8?q?1759175583888852093?= The implementation of the hierachical timer pull model will change the timer bases per CPU. Timers, that have to expire on a specific CPU, require the TIMER_PINNED flag. Otherwise they will be queued on the dedicated CPU but in global timer base and those timers could also expire on other CPUs. Timers with TIMER_DEFERRABLE flag end up in a separate base anyway and are executed on the local CPU only. Therefore add the missing TIMER_PINNED flag for those callers who use add_timer_on() without the flag. No functional change. Signed-off-by: Anna-Maria Behnsen Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: "Theodore Ts'o" Cc: "Jason A. Donenfeld" Cc: John Stultz Cc: Stephen Boyd Cc: Tejun Heo Cc: Lai Jiangshan --- v5: Add comment in workqueue.c that it's only a workaround for now --- arch/x86/kernel/tsc_sync.c | 3 ++- drivers/char/random.c | 2 +- kernel/time/clocksource.c | 2 +- kernel/workqueue.c | 15 +++++++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/tsc_sync.c b/arch/x86/kernel/tsc_sync.c index 9452dc9664b5..eab827288e0f 100644 --- a/arch/x86/kernel/tsc_sync.c +++ b/arch/x86/kernel/tsc_sync.c @@ -110,7 +110,8 @@ static int __init start_sync_check_timer(void) if (!cpu_feature_enabled(X86_FEATURE_TSC_ADJUST) || tsc_clocksource_reliable) return 0; - timer_setup(&tsc_sync_check_timer, tsc_sync_check_timer_fn, 0); + timer_setup(&tsc_sync_check_timer, tsc_sync_check_timer_fn, + TIMER_PINNED); tsc_sync_check_timer.expires = jiffies + SYNC_CHECK_INTERVAL; add_timer(&tsc_sync_check_timer); diff --git a/drivers/char/random.c b/drivers/char/random.c index ce3ccd172cc8..db6a7c0695de 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1007,7 +1007,7 @@ static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = { #define FASTMIX_PERM HSIPHASH_PERMUTATION .pool = { HSIPHASH_CONST_0, HSIPHASH_CONST_1, HSIPHASH_CONST_2, HSIPHASH_CONST_3 }, #endif - .mix = __TIMER_INITIALIZER(mix_interrupt_randomness, 0) + .mix = __TIMER_INITIALIZER(mix_interrupt_randomness, TIMER_PINNED) }; /* diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 91836b727cef..e982c119e3c9 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -561,7 +561,7 @@ static inline void clocksource_start_watchdog(void) { if (watchdog_running || !watchdog || list_empty(&watchdog_list)) return; - timer_setup(&watchdog_timer, clocksource_watchdog, 0); + timer_setup(&watchdog_timer, clocksource_watchdog, TIMER_PINNED); watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL; add_timer_on(&watchdog_timer, cpumask_first(cpu_online_mask)); watchdog_running = 1; diff --git a/kernel/workqueue.c b/kernel/workqueue.c index b8b541caed48..a428d94084ee 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1677,10 +1677,21 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, dwork->cpu = cpu; timer->expires = jiffies + delay; - if (unlikely(cpu != WORK_CPU_UNBOUND)) + if (unlikely(cpu != WORK_CPU_UNBOUND)) { + /* + * TODO: Setting the flag is a workaround for now; needs to + * be cleaned up with new work initializers and defines + */ + timer->flags |= TIMER_PINNED; add_timer_on(timer, cpu); - else + } else { + /* + * TODO: Resetting the flag is a workaround for now; needs + * to be cleaned up with new work initializers and defines + */ + timer->flags &= ~TIMER_PINNED; add_timer(timer); + } } /**