diff mbox

[3/3] x86: context_tracking: avoid irq_save/irq_restore on kernel entry and exit

Message ID 1445996397-32703-4-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini Oct. 28, 2015, 1:39 a.m. UTC
x86 always calls user_enter and user_exit with interrupt disabled.
Therefore, it is not necessary to check for exceptions, nor to
save/restore the IRQ state, when context tracking functions are
called by guest_enter and guest_exit.

Use the previously introduced __context_tracking_entry and
__context_tracking_exit.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/entry/common.c          |  4 ++--
 include/linux/context_tracking.h | 42 ++++++++++++++++++++++++++--------------
 2 files changed, 30 insertions(+), 16 deletions(-)

Comments

Andy Lutomirski Oct. 28, 2015, 5:22 a.m. UTC | #1
On Tue, Oct 27, 2015 at 6:39 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> x86 always calls user_enter and user_exit with interrupt disabled.
> Therefore, it is not necessary to check for exceptions, nor to
> save/restore the IRQ state, when context tracking functions are
> called by guest_enter and guest_exit.
>
> Use the previously introduced __context_tracking_entry and
> __context_tracking_exit.

x86 isn't ready for this yet.  We could do a quick-and-dirty fix with
explicit IRQs-on-and-off much protected by the static key, or we could
just wait until I finish the syscall cleanup.  I favor the latter, but
you're all welcome to do the former and I'll review it.

BTW, Frederic, I have a static key patch coming that I think you'll
like.  I'll send it tomorrow once I'm in front of a real computer.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini Oct. 28, 2015, 2:51 p.m. UTC | #2
On 28/10/2015 06:22, Andy Lutomirski wrote:
>> > called by guest_enter and guest_exit.
>> >
>> > Use the previously introduced __context_tracking_entry and
>> > __context_tracking_exit.
> x86 isn't ready for this yet.  We could do a quick-and-dirty fix with
> explicit IRQs-on-and-off much protected by the static key, or we could
> just wait until I finish the syscall cleanup.  I favor the latter, but
> you're all welcome to do the former and I'll review it.

Or we could just do save/restore for the only call that doesn't ensure
that interrupts are disabled (syscall_trace_phase1 or whatever it's called).

But two days from the merge window, I also favor waiting until 4.5.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Lutomirski March 14, 2016, 7:23 p.m. UTC | #3
On Tue, Oct 27, 2015 at 10:22 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> On Tue, Oct 27, 2015 at 6:39 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> x86 always calls user_enter and user_exit with interrupt disabled.
>> Therefore, it is not necessary to check for exceptions, nor to
>> save/restore the IRQ state, when context tracking functions are
>> called by guest_enter and guest_exit.
>>
>> Use the previously introduced __context_tracking_entry and
>> __context_tracking_exit.
>
> x86 isn't ready for this yet.  We could do a quick-and-dirty fix with
> explicit IRQs-on-and-off much protected by the static key, or we could
> just wait until I finish the syscall cleanup.  I favor the latter, but
> you're all welcome to do the former and I'll review it.
>

Once Linus pulls tip:x86/asm, x86 should be ready for this.  Want to try again?

--Andy
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini March 15, 2016, 8:51 a.m. UTC | #4
On 14/03/2016 20:23, Andy Lutomirski wrote:
> On Tue, Oct 27, 2015 at 10:22 PM, Andy Lutomirski <luto@amacapital.net> wrote:
>> On Tue, Oct 27, 2015 at 6:39 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>> x86 always calls user_enter and user_exit with interrupt disabled.
>>> Therefore, it is not necessary to check for exceptions, nor to
>>> save/restore the IRQ state, when context tracking functions are
>>> called by guest_enter and guest_exit.
>>>
>>> Use the previously introduced __context_tracking_entry and
>>> __context_tracking_exit.
>>
>> x86 isn't ready for this yet.  We could do a quick-and-dirty fix with
>> explicit IRQs-on-and-off much protected by the static key, or we could
>> just wait until I finish the syscall cleanup.  I favor the latter, but
>> you're all welcome to do the former and I'll review it.
>>
> 
> Once Linus pulls tip:x86/asm, x86 should be ready for this.  Want to try again?

Yup, it's on my todo list. :)

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index 80dcc9261ca3..ba707c6da818 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -33,7 +33,7 @@ 
 __visible void enter_from_user_mode(void)
 {
 	CT_WARN_ON(ct_state() != CONTEXT_USER);
-	user_exit();
+	__user_exit();
 }
 #endif
 
@@ -262,7 +262,7 @@  __visible void prepare_exit_to_usermode(struct pt_regs *regs)
 		local_irq_disable();
 	}
 
-	user_enter();
+	__user_enter();
 }
 
 /*
diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index 68b575afe5f5..d36a5c8085b7 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -19,18 +19,6 @@  extern void context_tracking_exit(enum ctx_state state);
 extern void context_tracking_user_enter(void);
 extern void context_tracking_user_exit(void);
 
-static inline void user_enter(void)
-{
-	if (context_tracking_is_enabled())
-		context_tracking_enter(CONTEXT_USER);
-
-}
-static inline void user_exit(void)
-{
-	if (context_tracking_is_enabled())
-		context_tracking_exit(CONTEXT_USER);
-}
-
 static inline enum ctx_state exception_enter(void)
 {
 	enum ctx_state prev_ctx;
@@ -67,13 +55,39 @@  static inline enum ctx_state ct_state(void)
 		this_cpu_read(context_tracking.state) : CONTEXT_DISABLED;
 }
 #else
-static inline void user_enter(void) { }
-static inline void user_exit(void) { }
+static inline void __context_tracking_enter(enum ctx_state state) { }
+static inline void __context_tracking_exit(enum ctx_state state) { }
+static inline void context_tracking_enter(enum ctx_state state) { }
+static inline void context_tracking_exit(enum ctx_state state) { }
 static inline enum ctx_state exception_enter(void) { return 0; }
 static inline void exception_exit(enum ctx_state prev_ctx) { }
 static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; }
 #endif /* !CONFIG_CONTEXT_TRACKING */
 
+static inline void __user_enter(void)
+{
+	if (context_tracking_is_enabled())
+		__context_tracking_enter(CONTEXT_USER);
+
+}
+static inline void __user_exit(void)
+{
+	if (context_tracking_is_enabled())
+		__context_tracking_exit(CONTEXT_USER);
+}
+
+static inline void user_enter(void)
+{
+	if (context_tracking_is_enabled())
+		context_tracking_enter(CONTEXT_USER);
+
+}
+static inline void user_exit(void)
+{
+	if (context_tracking_is_enabled())
+		context_tracking_exit(CONTEXT_USER);
+}
+
 #define CT_WARN_ON(cond) WARN_ON(context_tracking_is_enabled() && (cond))
 
 #ifdef CONFIG_CONTEXT_TRACKING_FORCE