Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5028963ybv; Wed, 26 Feb 2020 07:14:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzdpCl7NSbQC9SS/PkOT9QaHmKZzEsA1+HU5oquQJIK4k6hk7WjMv9Fi9XocUI5QDyaXpwR X-Received: by 2002:a05:6830:95:: with SMTP id a21mr3501155oto.171.1582730069586; Wed, 26 Feb 2020 07:14:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582730069; cv=none; d=google.com; s=arc-20160816; b=S/h9lgw23TPUof+xCtM2h84Pud6slJuEbsdL8nTS91p8UydBYzh4RP4ivmoQIjH+G6 XpuA7Cb/j7BSAGwyoOHaoU00/mkBt/3hRu1nDH8x6jwFLU8EFr31u6Rm2CcwzBXPWhjQ zNORVsfQxbX0zG4wVKz/SharpwnYDKd027AAu9Sxuy78PiFVpGMX5Lc7qsVEp+H0XVnv OW8mhrRPs73VJ0QLTD3hXxhWIeTf+lWTYtBWupfKm4eFEcw3moYxYp/nrFbglQIJAEr3 I6sIZ6AYgD4gka1xk96fclw9oOzxuP1B2r96hP+8V8IX5cF9cBUa2fp/aw4slc7v/4kd agXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=igQz1W0l9NSpj6H/cHRjMubdVHwK+ov1fDsF+eJLpII=; b=J7XqzHXWY093bFEa4H2SltYkA9BW9dVMXBHWEm1aV3duA+kTWC+xYoReIUPLn8lZ1d pv9NJAV2gj1jrvYQ9zUAJ2Due4FZs9mbIgGYCb+X7a8pGqmE117mTk/9rAO6lDvnmuvD WzomX1/lrQVw10zhtR0srkxf3yQMt/gwbrAhRB7lIQ7rqbj2E/EgSsKfZf8qldpHVf/N NKP8NiGnNpwuUCfjLPbdwyHalMElymIN1LWsiBQ9W7DDaegBjHusKeS02TmOMdu+AHRk NCNOIlNyZSJ3dM3Ro5fB2sgkuW7xLZnCnkd+zwZHp1qKVlX+kW4MBsgL+0YAgtZt9JFD 9G0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=U0fYNBJm; 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 l6si1527382otk.134.2020.02.26.07.14.14; Wed, 26 Feb 2020 07:14:29 -0800 (PST) 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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=U0fYNBJm; 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 S1727980AbgBZPLx (ORCPT + 99 others); Wed, 26 Feb 2020 10:11:53 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40643 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbgBZPLx (ORCPT ); Wed, 26 Feb 2020 10:11:53 -0500 Received: by mail-wm1-f67.google.com with SMTP id t14so3513638wmi.5 for ; Wed, 26 Feb 2020 07:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=igQz1W0l9NSpj6H/cHRjMubdVHwK+ov1fDsF+eJLpII=; b=U0fYNBJmYSmTtT7P/ZIt8VY1Pwonp/0JTIuJTsVwyEs1dEBhDcmxSx/VVJAwdzm7Vh apwgTsKXZNfGf5O8yNzSfFh48cXmvaa4a00dENUAWWtN78Gmbm2DhRk+Co4rZIp64Oy5 YunVks4LvgcRQNEGQGOASc81Tl/y0zhlR5T8cLnuW/CtdoMAOQUcfwPV5sQBBOxofUj4 CoVvuPxXo1rVAWE84O5S3d6zSNT3taIWIC7TKBCfzLdG7Nl5ywnu3WHa92vZxYcC99Y+ KBtCqiKirwYYfLSoMxcCl6yU+akkEjyIMSs66YzLgt5bftN0JU+DvwM/erV33PCU6Hlj JIOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=igQz1W0l9NSpj6H/cHRjMubdVHwK+ov1fDsF+eJLpII=; b=IQowurDiE7Hi0xLCFksXEbZ0JZpfqna87LLPvvY+wKHeUWK08iJZ8dfU7Ym46m+ePy 06wkSUwwPbm5PdTkctkUZ07qvDbHAAXQGZ20C00lMolDqUT/hQqV8xSJB9NjaNJNmOyg 6IVLIBKJgCmi4PeV5EVncFKJWWS3eOAxPdGuAPQ1OOfxzd4DVCUSE1yH6r8egMDjmXwH 85Mu6cVVJOASIMJCC6QE534tjagWY9KpDGHD2alBohlJwigBSsQQbO2tr/rovbYFGFVR 52Szl9azwGhjHpUOlGz2a5UVygv6+RsiyGPDUULbD9QJZq96n08bS0H1qTWyO8sU1aOD dJjA== X-Gm-Message-State: APjAAAWhmL2W8pmcm6qcgeSDKJ2uaDejbmIE+AmvI9vf7Y38LOFDKzxI y/UUuQmZahfgpphB+smxvCN5KMm7v4MvMtCt/nyB8Q== X-Received: by 2002:a05:600c:2207:: with SMTP id z7mr6141680wml.138.1582729910964; Wed, 26 Feb 2020 07:11:50 -0800 (PST) MIME-Version: 1.0 References: <20200225223321.231477305@linutronix.de> <20200225224145.444611199@linutronix.de> <20200226080538.GO18400@hirez.programming.kicks-ass.net> <20200226092018.GR18400@hirez.programming.kicks-ass.net> In-Reply-To: <20200226092018.GR18400@hirez.programming.kicks-ass.net> From: Andy Lutomirski Date: Wed, 26 Feb 2020 07:11:39 -0800 Message-ID: Subject: Re: [patch 13/16] x86/entry: Move irqflags and context tracking to C for simple idtentries To: Peter Zijlstra Cc: Thomas Gleixner , LKML , X86 ML , Steven Rostedt , Brian Gerst , Juergen Gross , Paolo Bonzini , Arnd Bergmann 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 On Wed, Feb 26, 2020 at 1:20 AM Peter Zijlstra wrote: > > On Wed, Feb 26, 2020 at 09:05:38AM +0100, Peter Zijlstra wrote: > > On Tue, Feb 25, 2020 at 11:33:34PM +0100, Thomas Gleixner wrote: > > > > > --- a/arch/x86/include/asm/idtentry.h > > > +++ b/arch/x86/include/asm/idtentry.h > > > @@ -7,14 +7,31 @@ > > > > > > #ifndef __ASSEMBLY__ > > > > > > +#ifdef CONFIG_CONTEXT_TRACKING > > > +static __always_inline void enter_from_user_context(void) > > > +{ > > > + CT_WARN_ON(ct_state() != CONTEXT_USER); > > > + user_exit_irqoff(); > > > +} > > > +#else > > > +static __always_inline void enter_from_user_context(void) { } > > > +#endif > > > + > > > /** > > > * idtentry_enter - Handle state tracking on idtentry > > > * @regs: Pointer to pt_regs of interrupted context > > > * > > > - * Place holder for now. > > > + * Invokes: > > > + * - The hardirq tracer to keep the state consistent as low level ASM > > > + * entry disabled interrupts. > > > + * > > > + * - Context tracking if the exception hit user mode > > > */ > > > static __always_inline void idtentry_enter(struct pt_regs *regs) > > > { > > > + trace_hardirqs_off(); > > > + if (user_mode(regs)) > > > + enter_from_user_context(); > > > } > > > > So: > > > > asm_exc_int3 > > exc_int3 > > idtentry_enter() > > enter_from_user_context > > if (context_tracking_enabled()) > > > > poke_int3_handler(); > > > > Is, AFAICT, completely buggered. > > > > You can't have a static_branch before the poke_int3_handler that deals > > with text_poke. > > Forgot to say that this isn't new with this patch, just noticed it when > chasing after tracepoints. > > After my patch series we can actually fix this by moving the > poke_int3_handler() before idtentry_enter(). In some sense, this is a weakness of the magic macro approach. Some of the entries just want to have code that runs before all the entry fixups. This is an example of it. So are the cr2 reads. It can all be made to work, but it's a bit gross.