Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp266600img; Thu, 21 Mar 2019 19:54:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAlFfdksCJrMaX5ZeSDS6d0uOeKTy8Aulhfn2M1BDAGiZasbmmxs8Si4zFLDfmbgc0UqSS X-Received: by 2002:a63:87c1:: with SMTP id i184mr6585120pge.265.1553223267454; Thu, 21 Mar 2019 19:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553223267; cv=none; d=google.com; s=arc-20160816; b=UvGHHTHRhI3WKeiTTZeLaQ3MlMhnxRBth+bNJ4g7GcmZoaRfXLRFOAWXxGaE049Uxn l/gIlqN2d1rr6AU4hJMrJSbUTYDNOvTuOsj8aYrnGeGZrykgUSYdxy5zd/MkR7330vgr kA6MxAivaydekD6mNdHiO+7RZbefUWDLt6AoTq5vOuhFNjN/Vcv6kK4yEDzrVNN6cgAg JH+JvNVI5gBoa/U7/t1Dqc0J67GXm0HEfrig/4niiXVAO1kJBbi40UPobGm9PQXEt6Zz 2iXscfqcm3Ldn1ZI3oSPHbP/pefKLfFrxHYVms5D1bBWXCWgChlvOWLEHSn0Maceh0qU 1m8Q== 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=xW7Fo7JlC6XxXesRCcy5ybTmwITqaKbo2hoIlPCD5dw=; b=XG1uNQAVWdHZ0+IcxmsM2WfdUXEm0mWlLCjG3NRr4p2jrHR0AJ1STfk9lsXLnsdLQs 52o46euNPB+pWdCnqwZ2q7g4bZc9vMTDH4ZDoup3JHVWcq7ql6lWpntbJLbua29YrwKB ZnNvuVtVRccOw0uO3N7SFfoIfA/9TxF6KjoprixxlWRTJ9rVLQpuk6NkmpyMqSbv16gM /jh6pM09wggRBznbEY59/F3iPnV044KcxoJ6IYozjV2sQFFK6FKv1rO7Cehi0c+DWV+A 3GzBS69SgwK4Nwe4iPSQpjultA6vvVsy75q+TRBY2ao97kp9G07DG8hYaFe5D4sSU7e+ Kglg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c6tRLYSa; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si5416452pgo.43.2019.03.21.19.54.09; Thu, 21 Mar 2019 19:54:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b=c6tRLYSa; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727581AbfCVCw3 (ORCPT + 99 others); Thu, 21 Mar 2019 22:52:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:46348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727439AbfCVCw2 (ORCPT ); Thu, 21 Mar 2019 22:52:28 -0400 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 652BE2190A for ; Fri, 22 Mar 2019 02:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553223147; bh=2NpbcW6cxEiyvRyH1XuHWQ1FUFXWq2d4xM5L+GBfKpQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=c6tRLYSa0EDMGZOql2zBtSJy3nQ1lg3R7j44hacenLtdton6kwDIrDUR0KUVHoLeG EqjXsXcwOCPP1QpuXFseuxuzaizd0hEHjlx7ETz0J9FVn2k5K4zl5ozjguph71nUjz /6UmQhhrr6B21uFp2Vf4LH/GzMOCLpoEGEdaxBBw= Received: by mail-wr1-f51.google.com with SMTP id s15so664274wra.12 for ; Thu, 21 Mar 2019 19:52:27 -0700 (PDT) X-Gm-Message-State: APjAAAWrX2O7Q6n52bJgYuIaLBwzc9JHoH0oEmfhNnocbH4Lnu8WAUjq ubf6SbaUXYIssAosU/6gd+q5O6oO0Cc4ZbHt1qxnOA== X-Received: by 2002:a5d:4710:: with SMTP id y16mr4465895wrq.176.1553223145982; Thu, 21 Mar 2019 19:52:25 -0700 (PDT) MIME-Version: 1.0 References: <20190320221534.165ab87b@oasis.local.home> <20190321083317.GL6058@hirez.programming.kicks-ass.net> <20190321090241.GL6521@hirez.programming.kicks-ass.net> <20190321104517.GM6521@hirez.programming.kicks-ass.net> <20190321093242.4a948198@gandalf.local.home> <20190321172203.GS5996@hirez.programming.kicks-ass.net> <20190321141020.641e313f@gandalf.local.home> <20190321205011.GE2490@worktop.programming.kicks-ass.net> In-Reply-To: <20190321205011.GE2490@worktop.programming.kicks-ass.net> From: Andy Lutomirski Date: Thu, 21 Mar 2019 19:52:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH] tracing/x86: Save CR2 before tracing irqsoff on error_entry To: Peter Zijlstra Cc: Andy Lutomirski , Steven Rostedt , Juergen Gross , LKML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Joel Fernandes , He Zhe , Linus Torvalds , Clark Williams 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 Thu, Mar 21, 2019 at 1:50 PM Peter Zijlstra wrote: > > On Thu, Mar 21, 2019 at 11:27:00AM -0700, Andy Lutomirski wrote: > > Well, here's pass zero at this. Untested, because it obviously > > doesn't work. Here are just a few things that are almost certainly > > wrong with it > > Aah, you're proposing to simply not do TRACE_IRQS_OFF and > CALL_enter_from_user_mode and let \do_sym deal with it all. > > Yes, that looks like it could almost work; esp. if you start by only > doing this for the idtentry stuff. > > > - The IRQ tracing needs to be re-added. > > > > - Some real semantics need to be defined for precisely what code is > > responsible for tracing. > > So we get passed \do_sym, how about we do: > > call __\do_sym > > And then use some CPP magic to generate the those functions such that we > have a consistent part of C glue between our asm and our 'real' C > handler. > > This glue can then do the tracing in a consistent manner. > > #define IDT_HANDLER(do_sym) \ > asmlinkage __visible notrace void __do_sym(struct pt_regs *regs) \ > { \ > trace_hardirqs_off(); \ > if (user_mode(regs)) \ > enter_from_user_mode(); \ > do_sym(regs); \ > } > > Except more complicated I'm afraid, we need to handle more args etc.. Seems reasonable. We should drop the asmlinkage, and if do_sym is static, the code should be pretty good. > > > - We need some asm-callable assertions to check the following > > conditions as appropriate: > > > > (a) that IRQ flags are currently traced as off. > > What do you need this for? When returning from do_sym ? > > > (b) that IRQ flags are currently traced to match the IRET frame. > > idem. Can't we have our C glue do that? The idea was to sanity check the C glue. Maybe this isn't such a big deal. > > > (c) that our context tracking is currently in good shape. I'm not > > 100% sure how to define this. > > So looking at this more; I used the %ebx games employed by > paranoid_entry to convey the state, but I didn't have to do that, the > actual condition seems to be: > > regs->cs & 3 > > aka. user_mode(regs). In this case our C glue would need to do the > context tracking user exit. > > In fact, I can change my patch to use that and reduce the ebx ugly. > > > - We need to do some serious don't-instrument-me stuff to all the C > > entries, since we're now in an awful context when calling them. > > Yah, but that's not new. do_page_fault(), sync_regs() at the very least > have this, so we can easily have our C glue have this too. True.