Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7459535ybi; Thu, 1 Aug 2019 08:29:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsHfYtJZ3Q+cmeXmS4tfauDVERXIkrXtGNixNW+wrZnKFzFmrGS3TqY2lK4CticRJO0FMK X-Received: by 2002:a17:90b:f0f:: with SMTP id br15mr9446175pjb.101.1564673389052; Thu, 01 Aug 2019 08:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564673389; cv=none; d=google.com; s=arc-20160816; b=yszPA1q5d1Cf5ZAdOIt3EwhytJtqJ8wAUWcT31F6QIMSxO+F5leyHdwsjBe9cHiCr0 55zZ9y+49vlOxccUG0b917f47w1TNKiD+26FgFMJ/BNFkUalRt1iGPl5o+Pdd22hq+Kv OgNMSYV8HIIA6Bt+ms1+tFJTX2XiNuR8TKnlla50MApJX10M/OnBkASVI4qAiPoocPW4 zEvNvtJchNPTQw+ipZtPaR5G09UY6TJ8kPRBTKnFwIoyuH2f04lUuH5qJ0vw4+5nrVJD UlUwTu6bm9pT07tzj4tyDdkS/FOwzFN1zNuI16JE5U5CIRPzXa8BuVder1IR4jfjchLV X5aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id; bh=p/9yzYpggNkDclBZF9ZxMERxiceFvA/TnxgybNjCtQ8=; b=BGVwiD264MgG1N6wlrx1KesUDLFw/+O0XwoVgMw6RZmANdrPhXJx9W/ZxH7W5kE7Xk jx94GQfbQk8ohXE3a6+/ueb/IOKpDp/d7zY3V7FsWZ6mb0CPZ2BBWDsP7yEZ0wqf7sEk hU+McwFAJTrEd6DAzjpnTUxggdGMuwoIY2V9poB9geScUETmVXp9kHnn0c9uGTI/8B2w 8xEpnc7dXSAgtwgRgJIGvm1FRrKQQLi66f8JFlGkm3MSBLt/P4AueuJtjer3tdBDxjWa 4slpUShkEMbfh+9yxKYz1Y231cJO01KsZ/R6afVI993C1jZuyPVyFYq+wioxPtTD+zl/ j/qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si39974520pfb.132.2019.08.01.08.29.33; Thu, 01 Aug 2019 08:29:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732136AbfHAOiU (ORCPT + 99 others); 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