From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26B22C433FF for ; Thu, 1 Aug 2019 14:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDC2C20B7C for ; Thu, 1 Aug 2019 14:38:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732140AbfHAOiU (ORCPT ); Thu, 1 Aug 2019 10:38:20 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:36213 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729084AbfHAOiU (ORCPT ); Thu, 1 Aug 2019 10:38:20 -0400 Received: from localhost ([127.0.0.1] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1htCDV-0000lz-DQ; Thu, 01 Aug 2019 16:38:05 +0200 Message-Id: <20190801143657.785902257@linutronix.de> User-Agent: quilt/0.65 Date: Thu, 01 Aug 2019 16:32:51 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Peter Zijlstra , Ingo Molnar , Sebastian Siewior , Anna-Maria Gleixner , Steven Rostedt , Julia Cartwright , Paul McKenney , Frederic Weisbecker , Oleg Nesterov , kvm@vger.kernel.org, Radim Krcmar , Paolo Bonzini , John Stultz , Andy Lutomirski , "Paul E. McKenney" Subject: [patch 1/5] tracehook: Provide TIF_NOTIFY_RESUME handling for KVM References: <20190801143250.370326052@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TIF_NOTITY_RESUME is evaluated on return to user space along with other TIF flags. >>From the kernels point of view a VMENTER is more or less equivalent to return to user space which means that at least a subset of TIF flags needs to be evaluated and handled. Currently KVM handles only TIF_SIGPENDING and TIF_NEED_RESCHED, but TIF_NOTIFY_RESUME is ignored. So pending task_work etc, is completely ignored until the vCPU thread actually goes all the way back into userspace/qemu. Provide notify_resume_pending() and tracehook_handle_notify_resume() so this can be handled similar to SIGPENDING. Signed-off-by: Thomas Gleixner Cc: Oleg Nesterov --- include/linux/tracehook.h | 15 +++++++++++++++ kernel/task_work.c | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) --- a/include/linux/tracehook.h +++ b/include/linux/tracehook.h @@ -163,6 +163,21 @@ static inline void set_notify_resume(str #endif } +#ifdef CONFIG_HAVE_ARCH_TRACEHOOK +/** + * notify_resume_pending - Check whether current has TIF_NOTIFY_RESUME set + */ +static inline bool notify_resume_pending(void) +{ + return test_thread_flag(TIF_NOTIFY_RESUME); +} + +void tracehook_handle_notify_resume(void); +#else +static inline bool notify_resume_pending(void) { return false; } +static inline void tracehook_handle_notify_resume(void) { } +#endif + /** * tracehook_notify_resume - report when about to return to user mode * @regs: user-mode registers of @current task --- a/kernel/task_work.c +++ b/kernel/task_work.c @@ -116,3 +116,22 @@ void task_work_run(void) } while (work); } } + +#ifdef CONFIG_HAVE_ARCH_TRACEHOOK +/** + * tracehook_handle_notify_resume - Notify resume handling for virt + * + * Called with interrupts and preemption enabled from VMENTER/EXIT. + */ +void tracehook_handle_notify_resume(void) +{ + local_irq_disable(); + while (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) { + local_irq_enable(); + tracehook_notify_resume(NULL); + local_irq_disable(); + } + local_irq_enable(); +} +EXPORT_SYMBOL_GPL(tracehook_handle_notify_resume); +#endif