linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: "H. Peter Anvin" <hpa@linux.intel.com>,
	Suresh Siddha <sbsiddha@gmail.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Ming Liu <ming.liu@windriver.com>
Subject: simd: Allow simd use in kernel threads with softirqs disabled
Date: Fri, 14 Nov 2014 23:43:15 +0800	[thread overview]
Message-ID: <20141114154315.GA15771@gondor.apana.org.au> (raw)

While working on the cryptd request reordering problem, I noticed
an anomaly where kernel threads are normally allowed to use simd
per may_use_simd, but as soon as you disable softirqs, they suddenly
lose that ability for no good reason.

The problem is that in_interrupt does not distinguish between
softirq processing and simply having softirqs disabled.  This
patch creates a new helper in_serving_interrupt which makes that
distinction.  It then uses this in all current implementations
of may_use_simd.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index a9a4229..6cdaa852 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -63,7 +63,7 @@ static inline bool interrupted_user_mode(void)
  */
 bool irq_fpu_usable(void)
 {
-	return !in_interrupt() ||
+	return !in_serving_interrupt() ||
 		interrupted_user_mode() ||
 		interrupted_kernel_fpu_idle();
 }
diff --git a/include/asm-generic/simd.h b/include/asm-generic/simd.h
index f57eb7b..74e0b05 100644
--- a/include/asm-generic/simd.h
+++ b/include/asm-generic/simd.h
@@ -10,5 +10,5 @@
  */
 static __must_check inline bool may_use_simd(void)
 {
-	return !in_interrupt();
+	return !in_serving_interrupt();
 }
diff --git a/include/linux/preempt_mask.h b/include/linux/preempt_mask.h
index dbeec4d..18f3b46 100644
--- a/include/linux/preempt_mask.h
+++ b/include/linux/preempt_mask.h
@@ -65,6 +65,8 @@
 #define in_softirq()		(softirq_count())
 #define in_interrupt()		(irq_count())
 #define in_serving_softirq()	(softirq_count() & SOFTIRQ_OFFSET)
+#define in_serving_interrupt()	(irq_count() & (HARDIRQ_MASK | \
+						SOFTIRQ_OFFSET | NMI_MASK))
 
 /*
  * Are we in NMI context?

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

             reply	other threads:[~2014-11-14 15:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-14 15:43 Herbert Xu [this message]
2014-11-14 16:17 ` simd: Allow simd use in kernel threads with softirqs disabled Ard Biesheuvel
2014-11-15  2:28   ` Herbert Xu

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=20141114154315.GA15771@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=ard.biesheuvel@linaro.org \
    --cc=hpa@linux.intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.liu@windriver.com \
    --cc=sbsiddha@gmail.com \
    --cc=steffen.klassert@secunet.com \
    /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).