Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4625704ybi; Tue, 11 Jun 2019 09:38:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwrWd5BoEJmVXgVNt+9a9il6ZddM+8z9yxhi5w0x7gLgCyMFw+TmEMOiq157F4fokktbQln X-Received: by 2002:a17:902:a504:: with SMTP id s4mr7938114plq.117.1560271130717; Tue, 11 Jun 2019 09:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560271130; cv=none; d=google.com; s=arc-20160816; b=jISUb+xfEHkDMMKhzerfyNnBmXc61EMkajHBPoRieJWyyWapZYL7IvAh/djYmi49c4 nMhFOqHdDyLT6Y1he3WXwZShi13Ec2o20hLSwDr6Lzkx073G9tE7TuYWjqg9pX+FDDv4 euYWFgkUQdbXmmZgLjly0YWDYbvwKk5pE6GtC/W30I+JNVuVsfv/TVr3l0Z8rhO9FcRE Bwa35CCVU7OAcnlbTxlNYtM4BGm2wWpTP9GddQJKHZRU1i9u+/KwIRAPVjVm3t7JGoDY DlLrEGJXMDh87TOMFjKW8OWLNgUo+EQr2e6efR3sAP4MwK+bpl89EYk4V66JPv+qWJ7g MYPw== 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:in-reply-to:message-id:subject:cc:to:from:date; bh=uggC90ttefvwdp8oMrR/Lf127J9+jP97X7jbe6GDRQo=; b=hZB7ffMDi13L2P5Rr5UI6P2A0PnQX10SZ2qjM0LDVLeQoT7W/sdyv/0chiaow+YA2w fNlYLK8PRhkSe00WTMd1L++LukV15P/Uu4qeg75nT5i0CqCsMsX5M/ZvnN3URwP/4ie/ dbfxZJ/tN1gnShU7eYcIz6KVA3nsXRCUHDLuouKR1AUVuPMTI1mkgVP/C71KCxjP9a7w kp8cgLFdBCRVWJ+iiOLFbHhGSdzJg/gDgCzaOdSBe8mR5AznDlGKy4+Y46HqnWusDTFe WmpJ1Agof0JCUR/HS+bTx6Zc2ZZxgDrC+TbYfieo41WRpRYsKTmamWNagyOXnK/GXtX/ xwUg== 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 a17si2725339pjs.98.2019.06.11.09.38.35; Tue, 11 Jun 2019 09:38:50 -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 S2404701AbfFKPW6 (ORCPT + 99 others); Tue, 11 Jun 2019 11:22:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:56138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388810AbfFKPW6 (ORCPT ); Tue, 11 Jun 2019 11:22:58 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9937E2080A; Tue, 11 Jun 2019 15:22:55 +0000 (UTC) Date: Tue, 11 Jun 2019 11:22:54 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: Andy Lutomirski , Masami Hiramatsu , x86@kernel.org, linux-kernel@vger.kernel.org, Ard Biesheuvel , Andy Lutomirski , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , "H. Peter Anvin" , Nadav Amit , Rasmus Villemoes , Edward Cree , Daniel Bristot de Oliveira Subject: Re: [PATCH 08/15] x86/alternatives: Teach text_poke_bp() to emulate instructions Message-ID: <20190611112254.576226fe@gandalf.local.home> In-Reply-To: <20190611080307.GN3436@hirez.programming.kicks-ass.net> References: <20190605130753.327195108@infradead.org> <20190605131945.005681046@infradead.org> <20190608004708.7646b287151cf613838ce05f@kernel.org> <20190607173427.GK3436@hirez.programming.kicks-ass.net> <3DA961AB-950B-4886-9656-C0D268D521F1@amacapital.net> <20190611080307.GN3436@hirez.programming.kicks-ass.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Jun 2019 10:03:07 +0200 Peter Zijlstra wrote: > So what happens is that arch_prepare_optimized_kprobe() <- > copy_optimized_instructions() copies however much of the instruction > stream is required such that we can overwrite the instruction at @addr > with a 5 byte jump. > > arch_optimize_kprobe() then does the text_poke_bp() that replaces the > instruction @addr with int3, copies the rel jump address and overwrites > the int3 with jmp. > > And I'm thinking the problem is with something like: > > @addr: nop nop nop nop nop What would work would be to: add breakpoint to first opcode. call synchronize_tasks(); /* All tasks now hitting breakpoint and jumping over affected code */ update the rest of the instructions. replace breakpoint with jmp. One caveat is that the replaced instructions must not be a call function. As if the call function calls schedule then it will circumvent the synchronize_tasks(). It would be OK if that call is the last of the instructions. But I doubt we modify anything more then a call size anyway, so this should still work for all current instances. -- Steve > > We copy out the nops into the trampoline, overwrite the first nop with > an INT3, overwrite the remaining nops with the rel addr, but oops, > another CPU can still be executing one of those NOPs, right? > > I'm thinking we could fix this by first writing INT3 into all relevant > instructions, which is going to be messy, given the current code base.