Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp851552ybh; Wed, 22 Jul 2020 15:12:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwkDmmOjqyFlSISP5CpgO+uETzNCxBSzFnFQjydzqZukNrchyeb2kUVSMbJwCBbQt04Rew X-Received: by 2002:aa7:c2cf:: with SMTP id m15mr1425009edp.27.1595455956457; Wed, 22 Jul 2020 15:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595455956; cv=none; d=google.com; s=arc-20160816; b=zeFShmIGt0RuyPZMVZ2kObievmsl9jO22t5eWYbLOKNdwyjopC+/36RiedFaTE7mp0 QGm6wjDFebVmB9mYRAX22OBEGazoXOHll2KSDMOAT0Y4TjH2vDSbnaXPz5AlDwKohuXY YlV1a9Shpw9wF710BOBW2VqwwK2Ksk1L9pTiGcVEu6Gx+fMwqlGA7dSQVR+TP8+Tpnk6 b3QyAYxY3GsVNCXQ56A0fCqaKYxm2yxc0lgSmlbM72Xhd5BT5mTVJ7QS0k6LXGGqrXxT fdBuSHJL7kefA//dUS7aqmhq1RR2klfcnJrZODq5Y82i+gHpn7k3xV34E6P3hwkEZzg4 3eDg== 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=bWVGXey2lJ1irAVnA4O/ihpzfVujSYh2rHOVl6EK2E4=; b=LzAp13tqJ8mtLKDLloibV2fnhpK5m5ijALSgNUp217UdD+LGLF4NjAEEVMfNvzA0Wd NvSQIiXTu1P7hKAregT5DXSlR6W58hlxqFmIbPmo/By7IbQheTrOEAkCQIeNJMbNarZk ++oEOI14TljOXL5kB4VfFULpUd1lQZ8um5emFDHaLeKfCMcSSBQhJwHbGHvS4BcSdEWR loH+8TOvMJoZnlz9Ie9WTQJ8JLv3/61w29nQaXJw3IzuVDzqsSOB/IRZmZTIcvBVh7FQ lSc82cq4tDiMmIrRTUrunOX/eNWFYPRpv6IJFYyCI4fdS2Mbp0hLLqYLp8q7GKg38YQg 0LBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZNcGnPir; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 n15si841123eje.289.2020.07.22.15.12.13; Wed, 22 Jul 2020 15:12:36 -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=ZNcGnPir; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S1733188AbgGVWLm (ORCPT + 99 others); Wed, 22 Jul 2020 18:11:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:52552 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733097AbgGVWLe (ORCPT ); Wed, 22 Jul 2020 18:11:34 -0400 Message-Id: <20200722220520.159112003@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595455892; 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=bWVGXey2lJ1irAVnA4O/ihpzfVujSYh2rHOVl6EK2E4=; b=ZNcGnPirO7GVvvAKk9/7xCrJWwZ6f+4PeCHE1jv4M7ohUxPI0xu+EbEiolyQPIg/6FrIG1 X/YXtnhorLabIwG7Lg5vAmTdWFHTuD56ik6uBsel6qkZrixIBYA+ZSTKrDgl1hv6P4VcWu rFgZfdPFrqBqcMYG/uRvkdOw6Z03RvrsSTBx80O6FgbiJpaecp+GnNjkg0jK5jmUovzmjN 0LzCfkPm/RaAlUpxpN0GKakOPhrKh6z8RIJIWHJYr73MVi5ReuMKgVi26cFaCN18vhVs3f LaYhpfBrD3riByGsqsDgadOlBdWiqqYNv2EiyOVUjKnl8MXPeCD+1VAR7CQ9mg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595455892; 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=bWVGXey2lJ1irAVnA4O/ihpzfVujSYh2rHOVl6EK2E4=; b=/a03u3noJLM9zDItsYn43MQPIsBHcRhqWneRAGKvqbAQY+vFZMWFjARoDT/BzzbQ+AU7KF HPkC7UtN0E83yQAA== Date: Thu, 23 Jul 2020 00:00:02 +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 , Sean Christopherson Subject: [patch V5 08/15] x86/entry: Move user return notifier out of loop References: <20200722215954.464281930@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 From: Thomas Gleixner Guests and user space share certain MSRs. KVM sets these MSRs to guest values once and does not set them back to user space values on every VM exit to spare the costly MSR operations. User return notifiers ensure that these MSRs are set back to the correct values before returning to user space in exit_to_usermode_loop(). There is no reason to evaluate the TIF flag indicating that user return notifiers need to be invoked in the loop. The important point is that they are invoked before returning to user space. Move the invocation out of the loop into the section which does the last preperatory steps before returning to user space. That section is not preemptible and runs with interrupts disabled until the actual return. Signed-off-by: Thomas Gleixner --- V4: New patch --- arch/x86/entry/common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -208,7 +208,7 @@ static long syscall_trace_enter(struct p #define EXIT_TO_USERMODE_LOOP_FLAGS \ (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \ - _TIF_NEED_RESCHED | _TIF_USER_RETURN_NOTIFY | _TIF_PATCH_PENDING) + _TIF_NEED_RESCHED | _TIF_PATCH_PENDING) static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags) { @@ -242,9 +242,6 @@ static void exit_to_usermode_loop(struct rseq_handle_notify_resume(NULL, regs); } - if (cached_flags & _TIF_USER_RETURN_NOTIFY) - fire_user_return_notifiers(); - /* Disable IRQs and retry */ local_irq_disable(); @@ -273,6 +270,9 @@ static void __prepare_exit_to_usermode(s /* Reload ti->flags; we may have rescheduled above. */ cached_flags = READ_ONCE(ti->flags); + if (cached_flags & _TIF_USER_RETURN_NOTIFY) + fire_user_return_notifiers(); + if (unlikely(cached_flags & _TIF_IO_BITMAP)) tss_update_io_bitmap();