Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 22 Jan 2019 05:07:40 -0000 Received: from aserp2130.oracle.com ([141.146.126.79]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1gloHj-0004eO-F0 for speck@linutronix.de; Tue, 22 Jan 2019 06:07:39 +0100 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0M54hpv055218 for ; Tue, 22 Jan 2019 05:07:32 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2q3sde9j75-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 22 Jan 2019 05:07:32 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0M57W8C010790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 22 Jan 2019 05:07:32 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0M57Wu5015511 for ; Tue, 22 Jan 2019 05:07:32 GMT Date: Tue, 22 Jan 2019 00:07:31 -0500 From: Konrad Rzeszutek Wilk Subject: [MODERATED] Re: [PATCH v5 18/27] MDSv5 8 Message-ID: <20190122050731.GN12859@char.us.oracle.com> References: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Fri, Jan 18, 2019 at 04:50:33PM -0800, speck for Andi Kleen wrote: > From: Andi Kleen > Subject: mds: Clear CPU on tasklets, unless opted-out > > By default we assume tasklets might touch user data and schedule > a cpu clear on next kernel exit. > > Add new interfaces to allow audited tasklets to opt-out. > > Signed-off-by: Andi Kleen > --- > include/linux/interrupt.h | 16 +++++++++++++++- > kernel/softirq.c | 25 +++++++++++++++++++------ > 2 files changed, 34 insertions(+), 7 deletions(-) > > diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h > index 291b7fee3afe..81b852fb5ecf 100644 > --- a/include/linux/interrupt.h > +++ b/include/linux/interrupt.h > @@ -571,11 +571,22 @@ struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data } > #define DECLARE_TASKLET_DISABLED(name, func, data) \ > struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data } > > +#define DECLARE_TASKLET_NOUSER(name, func, data) \ > +struct tasklet_struct name = { NULL, TASKLET_NO_USER, ATOMIC_INIT(0), func, data } > + > +#define DECLARE_TASKLET_DISABLED_NOUSER(name, func, data) \ > +struct tasklet_struct name = { NULL, TASKLET_NO_USER, ATOMIC_INIT(1), func, data } > > enum > { > TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */ > - TASKLET_STATE_RUN /* Tasklet is running (SMP only) */ > + TASKLET_STATE_RUN, /* Tasklet is running (SMP only) */ I think it would be worth converting these to values like below. That is 1<< 0 and 1 << 1 And so on. > + > + /* > + * Set this flag when the tasklet is known to not touch user data, > + * so doesn't need extra CPU state clearing. > + */ > + TASKLET_NO_USER = 1 << 5, > }; > > #ifdef CONFIG_SMP > @@ -639,6 +650,9 @@ extern void tasklet_kill(struct tasklet_struct *t); > extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu); > extern void tasklet_init(struct tasklet_struct *t, > void (*func)(unsigned long), unsigned long data); > +extern void tasklet_init_flags(struct tasklet_struct *t, > + void (*func)(unsigned long), unsigned long data, > + unsigned flags); > > struct tasklet_hrtimer { > struct hrtimer timer; > diff --git a/kernel/softirq.c b/kernel/softirq.c > index d28813306b2c..fdd4e3be3db7 100644 > --- a/kernel/softirq.c > +++ b/kernel/softirq.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include > @@ -522,6 +523,8 @@ static void tasklet_action_common(struct softirq_action *a, > BUG(); > t->func(t->data); > tasklet_unlock(t); > + if (!(t->state & TASKLET_NO_USER)) > + lazy_clear_cpu(); > continue; > } > tasklet_unlock(t); > @@ -546,15 +549,23 @@ static __latent_entropy void tasklet_hi_action(struct softirq_action *a) > tasklet_action_common(a, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ); > } > > -void tasklet_init(struct tasklet_struct *t, > - void (*func)(unsigned long), unsigned long data) > +void tasklet_init_flags(struct tasklet_struct *t, > + void (*func)(unsigned long), unsigned long data, > + unsigned flags) > { > t->next = NULL; > - t->state = 0; > + t->state = flags; So say we have another customer setting state to TASKLET_NO_USER. That means the check in ksoftirqd_running will return 92 return tsk && (tsk->state == TASK_RUNNING); always false. That is state will have both 1<<5 and 1<<1 set. But the check above is for 1<<1 only. 76 if (tsk && tsk->state != TASK_RUNNING) 77 wake_up_process(tsk); Also wakeup_softirqd may multiple times call wake_up_process. Could you modify those functions please? > atomic_set(&t->count, 0); > t->func = func; > t->data = data; > } > +EXPORT_SYMBOL(tasklet_init_flags); > + > +void tasklet_init(struct tasklet_struct *t, > + void (*func)(unsigned long), unsigned long data) > +{ > + tasklet_init_flags(t, func, data, 0); > +} > EXPORT_SYMBOL(tasklet_init); > > void tasklet_kill(struct tasklet_struct *t) > @@ -609,7 +620,8 @@ static void __tasklet_hrtimer_trampoline(unsigned long data) > * @ttimer: tasklet_hrtimer which is initialized > * @function: hrtimer callback function which gets called from softirq context > * @which_clock: clock id (CLOCK_MONOTONIC/CLOCK_REALTIME) > - * @mode: hrtimer mode (HRTIMER_MODE_ABS/HRTIMER_MODE_REL) > + * @mode: hrtimer mode (HRTIMER_MODE_ABS/HRTIMER_MODE_REL), > + * HRTIMER_MODE_NO_USER > */ > void tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer, > enum hrtimer_restart (*function)(struct hrtimer *), > @@ -617,8 +629,9 @@ void tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer, > { > hrtimer_init(&ttimer->timer, which_clock, mode); > ttimer->timer.function = __hrtimer_tasklet_trampoline; > - tasklet_init(&ttimer->tasklet, __tasklet_hrtimer_trampoline, > - (unsigned long)ttimer); > + tasklet_init_flags(&ttimer->tasklet, __tasklet_hrtimer_trampoline, > + (unsigned long)ttimer, > + (mode & HRTIMER_MODE_NO_USER) ? TASKLET_NO_USER : 0); > ttimer->function = function; > } > EXPORT_SYMBOL_GPL(tasklet_hrtimer_init); > -- > 2.17.2