Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp629436ybh; Tue, 21 Jul 2020 04:10:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzM48ddNIa7IP9IJxP1VQlzI8XBB/4Yyzbg9z1bVKnDArB+lKV5bOcbqRKo0ZS8VcSk6HU X-Received: by 2002:a17:906:4a45:: with SMTP id a5mr24254395ejv.384.1595329805150; Tue, 21 Jul 2020 04:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595329805; cv=none; d=google.com; s=arc-20160816; b=Kde3JDPwlvxrSxoAdfXAkae5XtiuWW2UxrDqkGg4/qoY2GLhnYXnR6ht3pBF95OXdm OK1jV0SIW/naLq7FTxIo6paLLkpIyz5S3gZtVcWBOc6ZDmIk6Sk+essrW23N5+m9wrOP ekr2ug9NdDDR+aHRlp261HVFI18sjQL7SvbHEX/5oR/5zTH404zoDFz23ABnOf7Ot3Ju pbownOGWdNHjhIAlF7BaSud9KKSD4OGxy6Z6yshHrs6GRISAP0O7sVHsJUKsb/HJvs82 5q6/Mp6NYcqDZaPsEe65dnB1TGtcPFHyY7gKqZRK2EidgiCqMisFERbSS74HRhNUI2JI 97VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:subject:cc:to:from:date:dkim-signature:dkim-signature :message-id; bh=gzKkA/2fPeA+5UOM9THMgnEGFcc10CtBaLDGCq6hU48=; b=0mL5jBi7EEjKMEV4HTK86ex4A9mzdqyHsMr5x/ZQKc2CKAQrOXbjTVkK2g9xNwFM+x zZDwaUj49oRgL131jOhWAomhPf70Q8hMNwmvb5gO0Y+D4N6/ai0VXB3mZkaQ4KlgDs3N oVj1q5uOCqku3CNfSrNk9fQ8MTCB6pGV1HnIauFqJb8ga4Fkho/HYG16gHu7LQNxtL1E X417EoAwj5rhHUSa/wbSSf1IcmWqrdK03/AogMoEcXpUkzoluxpx1qwuHU48SCzuS8QT KIxUaXQhGaD2HcIeKz2cr5Z3MtDm0UzsUhy6XuMaUzpf43faj7csTJKEGeHSVWxn+/lF KB5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HMx26h36; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk5si11930556edb.116.2020.07.21.04.09.42; Tue, 21 Jul 2020 04:10:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HMx26h36; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729746AbgGULJC (ORCPT + 99 others); Tue, 21 Jul 2020 07:09:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729702AbgGULIy (ORCPT ); Tue, 21 Jul 2020 07:08:54 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC664C061794; Tue, 21 Jul 2020 04:08:53 -0700 (PDT) Message-Id: <20200721110809.855490955@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595329732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=gzKkA/2fPeA+5UOM9THMgnEGFcc10CtBaLDGCq6hU48=; b=HMx26h367Q98P4nRRiTr3bc3xI9ZA0AKz+Z8IquAY0A/CNvC18rDXbyDYHXrqrvEXpnNUq DoGjzoGZUMSxXWcgaxwpTLBbCGMo+chR+K9s6L4vGCSV7K+q9U8Unt2nrEvE8TxerrNVRD tctP8lLzwK0EggyCOgvsjOUfVeihoQL58E/syHeHeXNNxwF48l8/ku9bjhik37A4/L7WdY /Z7u4FL3Jej8RTkPA23lvFw7Xr1HUslDbxToUZDE10ISoiKbkkSeRrJS5oLHdineNZbyA0 J9lDBKBUJNvV7tz1MdyYRgQ5a5Bw+Q/pHPaKvE5ty5lrei3Bwmff9anfH9j7uA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595329732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=gzKkA/2fPeA+5UOM9THMgnEGFcc10CtBaLDGCq6hU48=; b=hibn6cAHmgKEXLEnFx3UeZc14IDl2dVkwLHho2hoK6FWEl9BwmFgvPVk6qBxRlQ5kQSBy5 dyKO8b1x+NuaLAAw== Date: Tue, 21 Jul 2020 12:57:21 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, linux-arch@vger.kernel.org, Will Deacon , Arnd Bergmann , Mark Rutland , Kees Cook , Keno Fischer , Paolo Bonzini , kvm@vger.kernel.org, Gabriel Krisman Bertazi Subject: [patch V4 15/15] x86/kvm: Use generic exit to guest work function References: <20200721105706.030914876@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the generic infrastructure to check for and handle pending work before entering into guest mode. This now handles TIF_NOTIFY_RESUME as well which was ignored so far. Handling it is important as this covers task work and task work will be used to offload the heavy lifting of POSIX CPU timers to thread context. Signed-off-by: Thomas Gleixner --- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/vmx/vmx.c | 11 +++++------ arch/x86/kvm/x86.c | 15 ++++++--------- 3 files changed, 12 insertions(+), 15 deletions(-) --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -42,6 +42,7 @@ config KVM select HAVE_KVM_MSI select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_NO_POLL + select KVM_EXIT_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_VFIO select SRCU --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -5376,14 +5377,12 @@ static int handle_invalid_guest_state(st } /* - * Note, return 1 and not 0, vcpu_run() is responsible for - * morphing the pending signal into the proper return code. + * Note, return 1 and not 0, vcpu_run() will invoke + * exit_to_guest_mode() which will create a proper return + * code. */ - if (signal_pending(current)) + if (__exit_to_guest_mode_work_pending()) return 1; - - if (need_resched()) - schedule(); } return 1; --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -56,6 +56,7 @@ #include #include #include +#include #include @@ -1585,7 +1586,7 @@ EXPORT_SYMBOL_GPL(kvm_emulate_wrmsr); bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu) { return vcpu->mode == EXITING_GUEST_MODE || kvm_request_pending(vcpu) || - need_resched() || signal_pending(current); + exit_to_guest_mode_work_pending(); } EXPORT_SYMBOL_GPL(kvm_vcpu_exit_request); @@ -8676,15 +8677,11 @@ static int vcpu_run(struct kvm_vcpu *vcp break; } - if (signal_pending(current)) { - r = -EINTR; - vcpu->run->exit_reason = KVM_EXIT_INTR; - ++vcpu->stat.signal_exits; - break; - } - if (need_resched()) { + if (exit_to_guest_mode_work_pending()) { srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); - cond_resched(); + r = exit_to_guest_mode(vcpu); + if (r) + return r; vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); } }