linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Changbin Du <changbin.du@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	linux-kernel@vger.kernel.org, rcu@vger.kernel.org
Subject: Re: [PATCH] preempt: add in_serving_irq() and apply to rcutiny and vsprintf
Date: Tue, 17 Aug 2021 00:03:16 +0800	[thread overview]
Message-ID: <YRqMRFPDL0U9Orec@boqun-archlinux> (raw)
In-Reply-To: <20210814014234.51395-1-changbin.du@gmail.com>

On Sat, Aug 14, 2021 at 09:42:34AM +0800, Changbin Du wrote:
> At some places we need to determine whether we're in nmi, hardirq or
> softirq context. This adds a macro in_serving_irq() as a shortcut for
> that.
> 
> Meanwhile, apply this new macro to existing code in rcutiny and vsprintf.
> 
> Signed-off-by: Changbin Du <changbin.du@gmail.com>
> ---
>  include/linux/preempt.h | 4 +++-
>  include/linux/rcutiny.h | 3 +--
>  lib/vsprintf.c          | 2 +-
>  3 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/preempt.h b/include/linux/preempt.h
> index 9881eac0698f..9a1c924e2c6c 100644
> --- a/include/linux/preempt.h
> +++ b/include/linux/preempt.h
> @@ -92,12 +92,14 @@
>   * in_nmi()		- We're in NMI context
>   * in_hardirq()		- We're in hard IRQ context
>   * in_serving_softirq()	- We're in softirq context
> + * in_serving_irq()	- We're in nmi, hardirq or softirq context
>   * in_task()		- We're in task context
>   */
>  #define in_nmi()		(nmi_count())
>  #define in_hardirq()		(hardirq_count())
>  #define in_serving_softirq()	(softirq_count() & SOFTIRQ_OFFSET)
> -#define in_task()		(!(in_nmi() | in_hardirq() | in_serving_softirq()))
> +#define in_serving_irq()	(in_nmi() | in_hardirq() | in_serving_softirq())
> +#define in_task()		(!in_serving_irq())
>  

So in_serving_irq() is !in_task(), right? If so, why not...

>  /*
>   * The following macros are deprecated and should not be used in new code:
> diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
> index 7fedbd33d5d2..812d42f22e9c 100644
> --- a/include/linux/rcutiny.h
> +++ b/include/linux/rcutiny.h
> @@ -87,8 +87,7 @@ static inline void rcu_irq_exit_irqson(void) { }
>  static inline void rcu_irq_enter_irqson(void) { }
>  static inline void rcu_irq_exit(void) { }
>  static inline void rcu_irq_exit_check_preempt(void) { }
> -#define rcu_is_idle_cpu(cpu) \
> -	(is_idle_task(current) && !in_nmi() && !in_hardirq() && !in_serving_softirq())
> +#define rcu_is_idle_cpu(cpu) (is_idle_task(current) && !in_serving_irq())

... use in_task() here, and ...

>  static inline void exit_rcu(void) { }
>  static inline bool rcu_preempt_need_deferred_qs(struct task_struct *t)
>  {
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 2c5b4351330c..9324439c8543 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -865,7 +865,7 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,
>  		 * kptr_restrict==1 cannot be used in IRQ context
>  		 * because its test for CAP_SYSLOG would be meaningless.
>  		 */
> -		if (in_hardirq() || in_serving_softirq() || in_nmi()) {
> +		if (in_serving_irq()) {

... use !in_task() here?

And don't introduce the in_serving_irq() at all.

Regards,
Boqun

>  			if (spec.field_width == -1)
>  				spec.field_width = 2 * sizeof(ptr);
>  			return error_string(buf, end, "pK-error", spec);
> -- 
> 2.30.2
> 

  reply	other threads:[~2021-08-16 16:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-14  1:42 [PATCH] preempt: add in_serving_irq() and apply to rcutiny and vsprintf Changbin Du
2021-08-16 16:03 ` Boqun Feng [this message]
2021-08-18 23:59   ` Changbin Du
2021-08-19  1:56     ` Boqun Feng
2021-08-19 23:00       ` Changbin Du

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YRqMRFPDL0U9Orec@boqun-archlinux \
    --to=boqun.feng@gmail.com \
    --cc=changbin.du@gmail.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=josh@joshtriplett.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).