Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4631212ybi; Tue, 11 Jun 2019 09:44:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE90He5qPYhUZuIpI2UScVDH2DwQ/v6GTYGxGYOdB3oB+9N4odqpGYJ95qHrzr2jrVkedW X-Received: by 2002:a17:90a:fa07:: with SMTP id cm7mr2086469pjb.115.1560271495825; Tue, 11 Jun 2019 09:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560271495; cv=none; d=google.com; s=arc-20160816; b=q4FyuYboUSqOrU4ONi2DoZ4b0CnAWReNJl1Fgmvj/Sp947SEND9aWUq5Jih7AM//sj a/mDMtWg0u2fBbRIR17MzdiJ5REQL7ZVQ3fzadDDOCclYX+85Ec/oIiWUbVE7lT2XxE6 cKHQoQ0m+2fhBnoDavO8wmY0oDgnakHn2JmdRxq+DFbCJPFBAdHU/JipG8NTfWAi43vd eulRWECVwPpjc4YUdV8de0y7o4GnYYSkDcyqobLLmNEn+tm8fM1GbIMAQaSncBXlu0lm v1FXGKjKxPfp7qs18s+k0Gja9OlOPpCcsSBL7CKpHS6vqjDqwYGqYwA1jNZoQsYbHc+B 0bPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=dYWF8dg5ZWwrOvlmpQU8/b1U7j2GS0cV9KF8ci48uQA=; b=xI0NlsQQfCYeXp25OpFQedyKONnwG1NHyznCwWGXh4tn887WN88TnCjyQodRjR3yxE BXni1FFHr4DC6BAPhKBjCFz5pUqXZ6OnHVp2W5y4hXnktxILBYgEA0qw6tAJ6CRrMtU5 8zP5hkHFmiIv/DVKbbsjd1YzUaTlxGrZDwsRciiTyMrbM2aZAxrptQ0159IPU33J2lUF nYd/n5EFE+S+1ZwS1ixEn+o0YSv8Gg8hdq7wKFOez11A3wo5YJcpYkaxb51kSuhRx7Ez iACR7xeKJDnkpmxIQwlYjhWAtVVY+TxMHj/owHrws7Y4Zh1bs7I29dad6AOu5qw36ql0 qykA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=UO4Up5c8; 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 d4si12927930pla.358.2019.06.11.09.44.41; Tue, 11 Jun 2019 09:44:55 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=UO4Up5c8; 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 S2405481AbfFKP4M (ORCPT + 99 others); Tue, 11 Jun 2019 11:56:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:33226 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391859AbfFKP4L (ORCPT ); Tue, 11 Jun 2019 11:56:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dYWF8dg5ZWwrOvlmpQU8/b1U7j2GS0cV9KF8ci48uQA=; b=UO4Up5c8sxzI2qusz/vGAYQOu +QwryOTTYPx6psOLJBQIF4rNOo6mPv28IbkjmvcvaR6QPL8LzVVW9D7fCKgOw5o0P3F+2EHE2S3lV feKBFI2c8bb8M2xx42ivpb/hRUsXPsVWHX5hYWDY1k/y7NP2G+hqyI8fe11VYhntf8EFYBidqSHou MAz97neHt3+nmuK60pH2EyctnEi4CxcIKmNRf7Qj3OMuCK52uOT5vKlgO6GuG7jbvcl9dlgUzX7DU WxuEzW3SPEJZK4FQVgW6m6QE/tM9hm/FJo+N9aQy/pSU/86ldKDldOIjUCrHd7K4KqdYC0c2m7OZF 5URSSNUUA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1haj7a-0008Fj-Sg; Tue, 11 Jun 2019 15:55:39 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5E6A42023E4A7; Tue, 11 Jun 2019 17:55:37 +0200 (CEST) Date: Tue, 11 Jun 2019 17:55:37 +0200 From: Peter Zijlstra To: Steven Rostedt 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: <20190611155537.GB3436@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> <20190611112254.576226fe@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190611112254.576226fe@gandalf.local.home> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 11, 2019 at 11:22:54AM -0400, Steven Rostedt wrote: > 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. Right, something like this could work (although I cannot currently find synchronize_tasks), but it would make the optprobe stuff fairly slow (iirc this sync_tasks() thing could be pretty horrible).