Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5946464ybi; Wed, 12 Jun 2019 11:10:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHpsR5DRPsjUgwn1MtBFxtWbh1oAbjkBu1nzt4STBenY1Pdh6Zj1AcaOeyz/l1QEeSrTf/ X-Received: by 2002:a17:902:6b86:: with SMTP id p6mr12866330plk.14.1560363006000; Wed, 12 Jun 2019 11:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560363005; cv=none; d=google.com; s=arc-20160816; b=BLxazqSOvMoi8pwRSo4UOHaRiE0qEiMdhJw/zf3v1NXvT5GjD8BS4O9fT1414JRfEX Q8rgNmV1fQ/o4Dk01vLyfD8rjUP8gjFIyPNSsaU2yqqQHZHfw7ifeYAZ4TBbJxfBNOAe /vZVKiYpl9nimNb22MUmB4ZAFZQHQ6uW2OWjeJmbFGbYNasO0O3ImTatfLGaRcI5pnqh mxk36WFPG9L66/dQPXZgPb7bEJCvCofoBlQCZ+oDCr/PCBmqlmU7asB3OByGRk5Fx0Gm /zazdnZi/KiRFSRzaBr0o721KODbK9Lnm8SYODSva5oVD/9YuZsTW0u4f9250jw767rE UnfA== 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=qeRjLUH/X3Ruy89C7L++Ek8YtcKL4Q76UMeawZymlkg=; b=d2dVpN7qY09HnUI+zEm+c8acaLQ8N1ssLOaASRFg6y2K6QrnxSZtytj1chUDE31Mxo vItRxj0CroVs9SYBkn3YxbjS4dVmvQzlQcMXwBRDWY2Whv0AZGxui5nG7wD0RZM9VWud E8lz3Yz2s5as9+nVdZt8upYUB8/Ljv0sMPt9DTD8SmUMVB/424K/ruGh7o4g2ejjIkA4 OybIw4nfZUx7aKlF72K/ndhtLdUBuKou+2Ka1EO6ti/KUPVrpF8uSz1VFyhx8t525iZ+ sKDnPrpaqc/q+e2LBSsvh2cPy7qLnvYwm+cj0nNUhgnT8OdFEVZ+4YipR2DF2xqPPlh9 mgow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=s1dD6nrT; 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 i97si336288plb.50.2019.06.12.11.09.51; Wed, 12 Jun 2019 11:10:05 -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=s1dD6nrT; 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 S2406548AbfFLRQl (ORCPT + 99 others); Wed, 12 Jun 2019 13:16:41 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:43706 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726696AbfFLRQk (ORCPT ); Wed, 12 Jun 2019 13:16:40 -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=qeRjLUH/X3Ruy89C7L++Ek8YtcKL4Q76UMeawZymlkg=; b=s1dD6nrTMTiC40NDmcf8GgZ0D M2s9QOLcsrg9LROHGm+imgEZWu91Cmnsq7WD6ySYqLv4mLkknasd8dVn6fJF2tSFKA36Cs5/nGEAq JgKjK7GfXGr1ERtAIu8J/K2JLKW9ne6kdeZBrp3Y+XsylXSwmhVN5kj6htku8SuoiWq+E57bNSgHm 8cQLlR8idQPBT3Sp+vbk+NCh24KNbMLP9ftPezPLgwtzdxSYj2kiV/43vNddCKDTQFCxJaFRvJIaq 92BzUELZK4Nmb1zistIFqJGz0HIVvgJJUIxcBoPpoR7P8oM89V0eLXt3KajBfsjI7zDYFQQ88JMQq +g4kTn5Fg==; 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 1hb6rB-0001Ko-O0; Wed, 12 Jun 2019 17:16:18 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C071F202C9D60; Wed, 12 Jun 2019 19:09:30 +0200 (CEST) Date: Wed, 12 Jun 2019 19:09:30 +0200 From: Peter Zijlstra To: Masami Hiramatsu Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Ard Biesheuvel , Andy Lutomirski , Steven Rostedt , 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: <20190612170930.GK3402@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190607173427.GK3436@hirez.programming.kicks-ass.net> 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 Fri, Jun 07, 2019 at 07:34:27PM +0200, Peter Zijlstra wrote: > On Sat, Jun 08, 2019 at 12:47:08AM +0900, Masami Hiramatsu wrote: > > > @@ -943,8 +949,21 @@ int poke_int3_handler(struct pt_regs *re > > > if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr) > > > return 0; > > > > > > - /* set up the specified breakpoint handler */ > > > - regs->ip = (unsigned long) bp_int3_handler; > > > + opcode = *(struct opcode *)bp_int3_opcode; > > > + > > > + switch (opcode.insn) { > > > + case 0xE8: /* CALL */ > > > + int3_emulate_call(regs, ip + opcode.rel); > > > + break; > > > + > > > + case 0xE9: /* JMP */ > > > + int3_emulate_jmp(regs, ip + opcode.rel); > > > + break; > > > + > > > + default: /* assume NOP */ > > > > Shouldn't we check whether it is actually NOP here? > > I was/am lazy and didn't want to deal with: > > arch/x86/include/asm/nops.h:#define GENERIC_NOP5_ATOMIC NOP_DS_PREFIX,GENERIC_NOP4 > arch/x86/include/asm/nops.h:#define K8_NOP5_ATOMIC 0x66,K8_NOP4 > arch/x86/include/asm/nops.h:#define K7_NOP5_ATOMIC NOP_DS_PREFIX,K7_NOP4 > arch/x86/include/asm/nops.h:#define P6_NOP5_ATOMIC P6_NOP5 > > But maybe we should check for all the various NOP5 variants and BUG() on > anything unexpected. I realized we never actually poke a !ideal nop5_atomic, so I've added that to the latest versions.