// SPDX-License-Identifier: GPL-2.0-only1/*2* Context tracking: Probe on high level context boundaries such as kernel,3* userspace, guest or idle.4*5* This is used by RCU to remove its dependency on the timer tick while a CPU6* runs in idle, userspace or guest mode.7*8* User/guest tracking started by Frederic Weisbecker:9*10* Copyright (C) 2012 Red Hat, Inc., Frederic Weisbecker11*12* Many thanks to Gilad Ben-Yossef, Paul McKenney, Ingo Molnar, Andrew Morton,13* Steven Rostedt, Peter Zijlstra for suggestions and improvements.14*15* RCU extended quiescent state bits imported from kernel/rcu/tree.c16* where the relevant authorship may be found.17*/1819#include <linux/context_tracking.h>20#include <linux/rcupdate.h>21#include <linux/sched.h>22#include <linux/hardirq.h>23#include <linux/export.h>24#include <linux/kprobes.h>25#include <trace/events/rcu.h>262728DEFINE_PER_CPU(struct context_tracking, context_tracking) = {29#ifdef CONFIG_CONTEXT_TRACKING_IDLE30.nesting = 1,31.nmi_nesting = CT_NESTING_IRQ_NONIDLE,32#endif33.state = ATOMIC_INIT(CT_RCU_WATCHING),34};35EXPORT_SYMBOL_GPL(context_tracking);3637#ifdef CONFIG_CONTEXT_TRACKING_IDLE38#define TPS(x) tracepoint_string(x)3940/* Record the current task on exiting RCU-tasks (dyntick-idle entry). */41static __always_inline void rcu_task_exit(void)42{43#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)44WRITE_ONCE(current->rcu_tasks_idle_cpu, smp_processor_id());45#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */46}4748/* Record no current task on entering RCU-tasks (dyntick-idle exit). */49static __always_inline void rcu_task_enter(void)50{51#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)52WRITE_ONCE(current->rcu_tasks_idle_cpu, -1);53#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */54}5556/* Turn on heavyweight RCU tasks trace readers on kernel exit. */57static __always_inline void rcu_task_trace_heavyweight_enter(void)58{59#ifdef CONFIG_TASKS_TRACE_RCU60if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB))61current->trc_reader_special.b.need_mb = true;62#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */63}6465/* Turn off heavyweight RCU tasks trace readers on kernel entry. */66static __always_inline void rcu_task_trace_heavyweight_exit(void)67{68#ifdef CONFIG_TASKS_TRACE_RCU69if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB))70current->trc_reader_special.b.need_mb = false;71#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */72}7374/*75* Record entry into an extended quiescent state. This is only to be76* called when not already in an extended quiescent state, that is,77* RCU is watching prior to the call to this function and is no longer78* watching upon return.79*/80static noinstr void ct_kernel_exit_state(int offset)81{82/*83* CPUs seeing atomic_add_return() must see prior RCU read-side84* critical sections, and we also must force ordering with the85* next idle sojourn.86*/87rcu_task_trace_heavyweight_enter(); // Before CT state update!88// RCU is still watching. Better not be in extended quiescent state!89WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !rcu_is_watching_curr_cpu());90(void)ct_state_inc(offset);91// RCU is no longer watching.92}9394/*95* Record exit from an extended quiescent state. This is only to be96* called from an extended quiescent state, that is, RCU is not watching97* prior to the call to this function and is watching upon return.98*/99static noinstr void ct_kernel_enter_state(int offset)100{101int seq;102103/*104* CPUs seeing atomic_add_return() must see prior idle sojourns,105* and we also must force ordering with the next RCU read-side106* critical section.107*/108seq = ct_state_inc(offset);109// RCU is now watching. Better not be in an extended quiescent state!110rcu_task_trace_heavyweight_exit(); // After CT state update!111WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !(seq & CT_RCU_WATCHING));112}113114/*115* Enter an RCU extended quiescent state, which can be either the116* idle loop or adaptive-tickless usermode execution.117*118* We crowbar the ->nmi_nesting field to zero to allow for119* the possibility of usermode upcalls having messed up our count120* of interrupt nesting level during the prior busy period.121*/122static void noinstr ct_kernel_exit(bool user, int offset)123{124struct context_tracking *ct = this_cpu_ptr(&context_tracking);125126WARN_ON_ONCE(ct_nmi_nesting() != CT_NESTING_IRQ_NONIDLE);127WRITE_ONCE(ct->nmi_nesting, 0);128WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&129ct_nesting() == 0);130if (ct_nesting() != 1) {131// RCU will still be watching, so just do accounting and leave.132ct->nesting--;133return;134}135136instrumentation_begin();137lockdep_assert_irqs_disabled();138trace_rcu_watching(TPS("End"), ct_nesting(), 0, ct_rcu_watching());139WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));140rcu_preempt_deferred_qs(current);141142// instrumentation for the noinstr ct_kernel_exit_state()143instrument_atomic_write(&ct->state, sizeof(ct->state));144145instrumentation_end();146WRITE_ONCE(ct->nesting, 0); /* Avoid irq-access tearing. */147// RCU is watching here ...148ct_kernel_exit_state(offset);149// ... but is no longer watching here.150rcu_task_exit();151}152153/*154* Exit an RCU extended quiescent state, which can be either the155* idle loop or adaptive-tickless usermode execution.156*157* We crowbar the ->nmi_nesting field to CT_NESTING_IRQ_NONIDLE to158* allow for the possibility of usermode upcalls messing up our count of159* interrupt nesting level during the busy period that is just now starting.160*/161static void noinstr ct_kernel_enter(bool user, int offset)162{163struct context_tracking *ct = this_cpu_ptr(&context_tracking);164long oldval;165166WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !raw_irqs_disabled());167oldval = ct_nesting();168WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && oldval < 0);169if (oldval) {170// RCU was already watching, so just do accounting and leave.171ct->nesting++;172return;173}174rcu_task_enter();175// RCU is not watching here ...176ct_kernel_enter_state(offset);177// ... but is watching here.178instrumentation_begin();179180// instrumentation for the noinstr ct_kernel_enter_state()181instrument_atomic_write(&ct->state, sizeof(ct->state));182183trace_rcu_watching(TPS("Start"), ct_nesting(), 1, ct_rcu_watching());184WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));185WRITE_ONCE(ct->nesting, 1);186WARN_ON_ONCE(ct_nmi_nesting());187WRITE_ONCE(ct->nmi_nesting, CT_NESTING_IRQ_NONIDLE);188instrumentation_end();189}190191/**192* ct_nmi_exit - inform RCU of exit from NMI context193*194* If we are returning from the outermost NMI handler that interrupted an195* RCU-idle period, update ct->state and ct->nmi_nesting196* to let the RCU grace-period handling know that the CPU is back to197* being RCU-idle.198*199* If you add or remove a call to ct_nmi_exit(), be sure to test200* with CONFIG_RCU_EQS_DEBUG=y.201*/202void noinstr ct_nmi_exit(void)203{204struct context_tracking *ct = this_cpu_ptr(&context_tracking);205206instrumentation_begin();207/*208* Check for ->nmi_nesting underflow and bad CT state.209* (We are exiting an NMI handler, so RCU better be paying attention210* to us!)211*/212WARN_ON_ONCE(ct_nmi_nesting() <= 0);213WARN_ON_ONCE(!rcu_is_watching_curr_cpu());214215/*216* If the nesting level is not 1, the CPU wasn't RCU-idle, so217* leave it in non-RCU-idle state.218*/219if (ct_nmi_nesting() != 1) {220trace_rcu_watching(TPS("--="), ct_nmi_nesting(), ct_nmi_nesting() - 2,221ct_rcu_watching());222WRITE_ONCE(ct->nmi_nesting, /* No store tearing. */223ct_nmi_nesting() - 2);224instrumentation_end();225return;226}227228/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */229trace_rcu_watching(TPS("Endirq"), ct_nmi_nesting(), 0, ct_rcu_watching());230WRITE_ONCE(ct->nmi_nesting, 0); /* Avoid store tearing. */231232// instrumentation for the noinstr ct_kernel_exit_state()233instrument_atomic_write(&ct->state, sizeof(ct->state));234instrumentation_end();235236// RCU is watching here ...237ct_kernel_exit_state(CT_RCU_WATCHING);238// ... but is no longer watching here.239240if (!in_nmi())241rcu_task_exit();242}243244/**245* ct_nmi_enter - inform RCU of entry to NMI context246*247* If the CPU was idle from RCU's viewpoint, update ct->state and248* ct->nmi_nesting to let the RCU grace-period handling know249* that the CPU is active. This implementation permits nested NMIs, as250* long as the nesting level does not overflow an int. (You will probably251* run out of stack space first.)252*253* If you add or remove a call to ct_nmi_enter(), be sure to test254* with CONFIG_RCU_EQS_DEBUG=y.255*/256void noinstr ct_nmi_enter(void)257{258long incby = 2;259struct context_tracking *ct = this_cpu_ptr(&context_tracking);260261/* Complain about underflow. */262WARN_ON_ONCE(ct_nmi_nesting() < 0);263264/*265* If idle from RCU viewpoint, atomically increment CT state266* to mark non-idle and increment ->nmi_nesting by one.267* Otherwise, increment ->nmi_nesting by two. This means268* if ->nmi_nesting is equal to one, we are guaranteed269* to be in the outermost NMI handler that interrupted an RCU-idle270* period (observation due to Andy Lutomirski).271*/272if (!rcu_is_watching_curr_cpu()) {273274if (!in_nmi())275rcu_task_enter();276277// RCU is not watching here ...278ct_kernel_enter_state(CT_RCU_WATCHING);279// ... but is watching here.280281instrumentation_begin();282// instrumentation for the noinstr rcu_is_watching_curr_cpu()283instrument_atomic_read(&ct->state, sizeof(ct->state));284// instrumentation for the noinstr ct_kernel_enter_state()285instrument_atomic_write(&ct->state, sizeof(ct->state));286287incby = 1;288} else if (!in_nmi()) {289instrumentation_begin();290rcu_irq_enter_check_tick();291} else {292instrumentation_begin();293}294295trace_rcu_watching(incby == 1 ? TPS("Startirq") : TPS("++="),296ct_nmi_nesting(),297ct_nmi_nesting() + incby, ct_rcu_watching());298instrumentation_end();299WRITE_ONCE(ct->nmi_nesting, /* Prevent store tearing. */300ct_nmi_nesting() + incby);301barrier();302}303304/**305* ct_idle_enter - inform RCU that current CPU is entering idle306*307* Enter idle mode, in other words, -leave- the mode in which RCU308* read-side critical sections can occur. (Though RCU read-side309* critical sections can occur in irq handlers in idle, a possibility310* handled by irq_enter() and irq_exit().)311*312* If you add or remove a call to ct_idle_enter(), be sure to test with313* CONFIG_RCU_EQS_DEBUG=y.314*/315void noinstr ct_idle_enter(void)316{317WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !raw_irqs_disabled());318ct_kernel_exit(false, CT_RCU_WATCHING + CT_STATE_IDLE);319}320EXPORT_SYMBOL_GPL(ct_idle_enter);321322/**323* ct_idle_exit - inform RCU that current CPU is leaving idle324*325* Exit idle mode, in other words, -enter- the mode in which RCU326* read-side critical sections can occur.327*328* If you add or remove a call to ct_idle_exit(), be sure to test with329* CONFIG_RCU_EQS_DEBUG=y.330*/331void noinstr ct_idle_exit(void)332{333unsigned long flags;334335raw_local_irq_save(flags);336ct_kernel_enter(false, CT_RCU_WATCHING - CT_STATE_IDLE);337raw_local_irq_restore(flags);338}339EXPORT_SYMBOL_GPL(ct_idle_exit);340341/**342* ct_irq_enter - inform RCU that current CPU is entering irq away from idle343*344* Enter an interrupt handler, which might possibly result in exiting345* idle mode, in other words, entering the mode in which read-side critical346* sections can occur. The caller must have disabled interrupts.347*348* Note that the Linux kernel is fully capable of entering an interrupt349* handler that it never exits, for example when doing upcalls to user mode!350* This code assumes that the idle loop never does upcalls to user mode.351* If your architecture's idle loop does do upcalls to user mode (or does352* anything else that results in unbalanced calls to the irq_enter() and353* irq_exit() functions), RCU will give you what you deserve, good and hard.354* But very infrequently and irreproducibly.355*356* Use things like work queues to work around this limitation.357*358* You have been warned.359*360* If you add or remove a call to ct_irq_enter(), be sure to test with361* CONFIG_RCU_EQS_DEBUG=y.362*/363noinstr void ct_irq_enter(void)364{365lockdep_assert_irqs_disabled();366ct_nmi_enter();367}368369/**370* ct_irq_exit - inform RCU that current CPU is exiting irq towards idle371*372* Exit from an interrupt handler, which might possibly result in entering373* idle mode, in other words, leaving the mode in which read-side critical374* sections can occur. The caller must have disabled interrupts.375*376* This code assumes that the idle loop never does anything that might377* result in unbalanced calls to irq_enter() and irq_exit(). If your378* architecture's idle loop violates this assumption, RCU will give you what379* you deserve, good and hard. But very infrequently and irreproducibly.380*381* Use things like work queues to work around this limitation.382*383* You have been warned.384*385* If you add or remove a call to ct_irq_exit(), be sure to test with386* CONFIG_RCU_EQS_DEBUG=y.387*/388noinstr void ct_irq_exit(void)389{390lockdep_assert_irqs_disabled();391ct_nmi_exit();392}393394/*395* Wrapper for ct_irq_enter() where interrupts are enabled.396*397* If you add or remove a call to ct_irq_enter_irqson(), be sure to test398* with CONFIG_RCU_EQS_DEBUG=y.399*/400void ct_irq_enter_irqson(void)401{402unsigned long flags;403404local_irq_save(flags);405ct_irq_enter();406local_irq_restore(flags);407}408409/*410* Wrapper for ct_irq_exit() where interrupts are enabled.411*412* If you add or remove a call to ct_irq_exit_irqson(), be sure to test413* with CONFIG_RCU_EQS_DEBUG=y.414*/415void ct_irq_exit_irqson(void)416{417unsigned long flags;418419local_irq_save(flags);420ct_irq_exit();421local_irq_restore(flags);422}423#else424static __always_inline void ct_kernel_exit(bool user, int offset) { }425static __always_inline void ct_kernel_enter(bool user, int offset) { }426#endif /* #ifdef CONFIG_CONTEXT_TRACKING_IDLE */427428#ifdef CONFIG_CONTEXT_TRACKING_USER429430#define CREATE_TRACE_POINTS431#include <trace/events/context_tracking.h>432433DEFINE_STATIC_KEY_FALSE_RO(context_tracking_key);434EXPORT_SYMBOL_GPL(context_tracking_key);435436static noinstr bool context_tracking_recursion_enter(void)437{438int recursion;439440recursion = __this_cpu_inc_return(context_tracking.recursion);441if (recursion == 1)442return true;443444WARN_ONCE((recursion < 1), "Invalid context tracking recursion value %d\n", recursion);445__this_cpu_dec(context_tracking.recursion);446447return false;448}449450static __always_inline void context_tracking_recursion_exit(void)451{452__this_cpu_dec(context_tracking.recursion);453}454455/**456* __ct_user_enter - Inform the context tracking that the CPU is going457* to enter user or guest space mode.458*459* @state: userspace context-tracking state to enter.460*461* This function must be called right before we switch from the kernel462* to user or guest space, when it's guaranteed the remaining kernel463* instructions to execute won't use any RCU read side critical section464* because this function sets RCU in extended quiescent state.465*/466void noinstr __ct_user_enter(enum ctx_state state)467{468struct context_tracking *ct = this_cpu_ptr(&context_tracking);469lockdep_assert_irqs_disabled();470471/* Kernel threads aren't supposed to go to userspace */472WARN_ON_ONCE(!current->mm);473474if (!context_tracking_recursion_enter())475return;476477if (__ct_state() != state) {478if (ct->active) {479/*480* At this stage, only low level arch entry code remains and481* then we'll run in userspace. We can assume there won't be482* any RCU read-side critical section until the next call to483* user_exit() or ct_irq_enter(). Let's remove RCU's dependency484* on the tick.485*/486if (state == CT_STATE_USER) {487instrumentation_begin();488trace_user_enter(0);489vtime_user_enter(current);490instrumentation_end();491}492/*493* Other than generic entry implementation, we may be past the last494* rescheduling opportunity in the entry code. Trigger a self IPI495* that will fire and reschedule once we resume in user/guest mode.496*/497rcu_irq_work_resched();498499/*500* Enter RCU idle mode right before resuming userspace. No use of RCU501* is permitted between this call and rcu_eqs_exit(). This way the502* CPU doesn't need to maintain the tick for RCU maintenance purposes503* when the CPU runs in userspace.504*/505ct_kernel_exit(true, CT_RCU_WATCHING + state);506507/*508* Special case if we only track user <-> kernel transitions for tickless509* cputime accounting but we don't support RCU extended quiescent state.510* In this we case we don't care about any concurrency/ordering.511*/512if (!IS_ENABLED(CONFIG_CONTEXT_TRACKING_IDLE))513raw_atomic_set(&ct->state, state);514} else {515/*516* Even if context tracking is disabled on this CPU, because it's outside517* the full dynticks mask for example, we still have to keep track of the518* context transitions and states to prevent inconsistency on those of519* other CPUs.520* If a task triggers an exception in userspace, sleep on the exception521* handler and then migrate to another CPU, that new CPU must know where522* the exception returns by the time we call exception_exit().523* This information can only be provided by the previous CPU when it called524* exception_enter().525* OTOH we can spare the calls to vtime and RCU when context_tracking.active526* is false because we know that CPU is not tickless.527*/528if (!IS_ENABLED(CONFIG_CONTEXT_TRACKING_IDLE)) {529/* Tracking for vtime only, no concurrent RCU EQS accounting */530raw_atomic_set(&ct->state, state);531} else {532/*533* Tracking for vtime and RCU EQS. Make sure we don't race534* with NMIs. OTOH we don't care about ordering here since535* RCU only requires CT_RCU_WATCHING increments to be fully536* ordered.537*/538raw_atomic_add(state, &ct->state);539}540}541}542context_tracking_recursion_exit();543}544EXPORT_SYMBOL_GPL(__ct_user_enter);545546/*547* OBSOLETE:548* This function should be noinstr but the below local_irq_restore() is549* unsafe because it involves illegal RCU uses through tracing and lockdep.550* This is unlikely to be fixed as this function is obsolete. The preferred551* way is to call __context_tracking_enter() through user_enter_irqoff()552* or context_tracking_guest_enter(). It should be the arch entry code553* responsibility to call into context tracking with IRQs disabled.554*/555void ct_user_enter(enum ctx_state state)556{557unsigned long flags;558559/*560* Some contexts may involve an exception occuring in an irq,561* leading to that nesting:562* ct_irq_enter() rcu_eqs_exit(true) rcu_eqs_enter(true) ct_irq_exit()563* This would mess up the dyntick_nesting count though. And rcu_irq_*()564* helpers are enough to protect RCU uses inside the exception. So565* just return immediately if we detect we are in an IRQ.566*/567if (in_interrupt())568return;569570local_irq_save(flags);571__ct_user_enter(state);572local_irq_restore(flags);573}574NOKPROBE_SYMBOL(ct_user_enter);575EXPORT_SYMBOL_GPL(ct_user_enter);576577/**578* user_enter_callable() - Unfortunate ASM callable version of user_enter() for579* archs that didn't manage to check the context tracking580* static key from low level code.581*582* This OBSOLETE function should be noinstr but it unsafely calls583* local_irq_restore(), involving illegal RCU uses through tracing and lockdep.584* This is unlikely to be fixed as this function is obsolete. The preferred585* way is to call user_enter_irqoff(). It should be the arch entry code586* responsibility to call into context tracking with IRQs disabled.587*/588void user_enter_callable(void)589{590user_enter();591}592NOKPROBE_SYMBOL(user_enter_callable);593594/**595* __ct_user_exit - Inform the context tracking that the CPU is596* exiting user or guest mode and entering the kernel.597*598* @state: userspace context-tracking state being exited from.599*600* This function must be called after we entered the kernel from user or601* guest space before any use of RCU read side critical section. This602* potentially include any high level kernel code like syscalls, exceptions,603* signal handling, etc...604*605* This call supports re-entrancy. This way it can be called from any exception606* handler without needing to know if we came from userspace or not.607*/608void noinstr __ct_user_exit(enum ctx_state state)609{610struct context_tracking *ct = this_cpu_ptr(&context_tracking);611612if (!context_tracking_recursion_enter())613return;614615if (__ct_state() == state) {616if (ct->active) {617/*618* Exit RCU idle mode while entering the kernel because it can619* run a RCU read side critical section anytime.620*/621ct_kernel_enter(true, CT_RCU_WATCHING - state);622if (state == CT_STATE_USER) {623instrumentation_begin();624vtime_user_exit(current);625trace_user_exit(0);626instrumentation_end();627}628629/*630* Special case if we only track user <-> kernel transitions for tickless631* cputime accounting but we don't support RCU extended quiescent state.632* In this we case we don't care about any concurrency/ordering.633*/634if (!IS_ENABLED(CONFIG_CONTEXT_TRACKING_IDLE))635raw_atomic_set(&ct->state, CT_STATE_KERNEL);636637} else {638if (!IS_ENABLED(CONFIG_CONTEXT_TRACKING_IDLE)) {639/* Tracking for vtime only, no concurrent RCU EQS accounting */640raw_atomic_set(&ct->state, CT_STATE_KERNEL);641} else {642/*643* Tracking for vtime and RCU EQS. Make sure we don't race644* with NMIs. OTOH we don't care about ordering here since645* RCU only requires CT_RCU_WATCHING increments to be fully646* ordered.647*/648raw_atomic_sub(state, &ct->state);649}650}651}652context_tracking_recursion_exit();653}654EXPORT_SYMBOL_GPL(__ct_user_exit);655656/*657* OBSOLETE:658* This function should be noinstr but the below local_irq_save() is659* unsafe because it involves illegal RCU uses through tracing and lockdep.660* This is unlikely to be fixed as this function is obsolete. The preferred661* way is to call __context_tracking_exit() through user_exit_irqoff()662* or context_tracking_guest_exit(). It should be the arch entry code663* responsibility to call into context tracking with IRQs disabled.664*/665void ct_user_exit(enum ctx_state state)666{667unsigned long flags;668669if (in_interrupt())670return;671672local_irq_save(flags);673__ct_user_exit(state);674local_irq_restore(flags);675}676NOKPROBE_SYMBOL(ct_user_exit);677EXPORT_SYMBOL_GPL(ct_user_exit);678679/**680* user_exit_callable() - Unfortunate ASM callable version of user_exit() for681* archs that didn't manage to check the context tracking682* static key from low level code.683*684* This OBSOLETE function should be noinstr but it unsafely calls local_irq_save(),685* involving illegal RCU uses through tracing and lockdep. This is unlikely686* to be fixed as this function is obsolete. The preferred way is to call687* user_exit_irqoff(). It should be the arch entry code responsibility to688* call into context tracking with IRQs disabled.689*/690void user_exit_callable(void)691{692user_exit();693}694NOKPROBE_SYMBOL(user_exit_callable);695696void __init ct_cpu_track_user(int cpu)697{698static __initdata bool initialized = false;699700if (!per_cpu(context_tracking.active, cpu)) {701per_cpu(context_tracking.active, cpu) = true;702static_branch_inc(&context_tracking_key);703}704705if (initialized)706return;707708#ifdef CONFIG_HAVE_TIF_NOHZ709/*710* Set TIF_NOHZ to init/0 and let it propagate to all tasks through fork711* This assumes that init is the only task at this early boot stage.712*/713set_tsk_thread_flag(&init_task, TIF_NOHZ);714#endif715WARN_ON_ONCE(!tasklist_empty());716717initialized = true;718}719720#ifdef CONFIG_CONTEXT_TRACKING_USER_FORCE721void __init context_tracking_init(void)722{723int cpu;724725for_each_possible_cpu(cpu)726ct_cpu_track_user(cpu);727}728#endif729730#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */731732733