Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6282537ybx; Mon, 11 Nov 2019 06:50:30 -0800 (PST) X-Google-Smtp-Source: APXvYqzQlxnVXRoG586pp3xp9G7KgKOW2Yo1QxKn2X2VKqApsYlHCKciuoYMRxMUf94E84r0RBC5 X-Received: by 2002:a05:6402:148d:: with SMTP id e13mr19728181edv.290.1573483830170; Mon, 11 Nov 2019 06:50:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573483830; cv=none; d=google.com; s=arc-20160816; b=puUeZVEGLA/za5FqOzm3VZ7ku5wEpMQuS5bA7tQPAJk1awq6FmmZebwAU071aPvxvz +oe1Mq5oD1+PEgg3yVmQjnUZRh2pTWGm3IDerEdUh4CjoaKZoM0Z/iBCsSgocwCzXdkD CnUD+m5IQyzh0CGJLtLgEj5exuD0XgyEMeyb78OdMkAMxuPi+sRK4wZ4oiHVUurKoR5U 2i73d/Ek2Fw8h1mEQVzaYmf75XLwnnmDbubS09DXUg7nBDZz0b3OyqcBvgGDGKX5EXso RP4tugc8/S0M2JvnBfrOCZWOG1mVvUu0AOLhn3zJiEjiuQSP/vcwLx4W3d87jQq8lymX U5CQ== 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=KacwoM/PURyvxk09Q1LWi5n4/p0zOHyHZBnPkZyRKqk=; b=yTq6c02/ib/2355Mg5BE0Ck0y3cUFcxhBlJv/3Z+Z44DqcdOhctDSy8V8mqQqoyHQ5 9yFAaKojLJAInRh5JQD5T+nYOU5r3y4YHn3xjvJEYVgpOILSX8rgunSg5oS9RMk1LCLj IRu5BXgbLpbYLjbADUIy0jNCw9V2SCusqvu1E0p1pJhZrqCTieB8TPybcbGrrpslNDKT tSzAjnmpbfF2eoMMTWR3SG5pYdq8hiLgzMhtV/aYEvH0yx8mIFCKqNwBEox3EgRLfOIr uQxBmlizp8XW21u7o6ptIgNhVFdKxLWV3bitltkQtnJY3WFb8eivkRoAb1wIEu9aijYi rfVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CjGArxSg; 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 s14si9787658ejq.257.2019.11.11.06.50.05; Mon, 11 Nov 2019 06:50:30 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CjGArxSg; 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 S1727196AbfKKOrH (ORCPT + 99 others); Mon, 11 Nov 2019 09:47:07 -0500 Received: from merlin.infradead.org ([205.233.59.134]:40854 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727159AbfKKOrG (ORCPT ); Mon, 11 Nov 2019 09:47:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=KacwoM/PURyvxk09Q1LWi5n4/p0zOHyHZBnPkZyRKqk=; b=CjGArxSgB2NHoy6hOoUjWIeIr 6Gquvm5IpmPSJo4vNAhZ2Ns7La5TzCzqKPISOZUj8ZO1KbRpG3q4SEQ/eJbk7MhIoHppHCu5wsVDJ Psh9WjRvwJaZrIw7fP8GM0RTzHTwy6Hui8481Hei6QOOEglBdDJltqpzKQHgv+DAi+JyFsAfddm0s j4rmj36cL8qHgFaHVBgWK7tSEP0qkoTwjXw6uKxfRFQx6P2idyxwfoJLQuQM4J5ASQZX0JA8NkXIr EHOugtYKHm4ovdNMXHX3gO3JwWmaYh4GbRARC0u7XaRrMAjMrDMGwjFVx2fKblzzS4iljpJ/+k0/z /0+IWqySw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iUAxo-0003sO-LR; Mon, 11 Nov 2019 14:46:45 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B9CFA305ED5; Mon, 11 Nov 2019 15:45:35 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 11E9C201CB728; Mon, 11 Nov 2019 15:46:42 +0100 (CET) Date: Mon, 11 Nov 2019 15:46:42 +0100 From: Peter Zijlstra To: Leo Yan Cc: Will Deacon , Mark Rutland , Mike Leach , Adrian Hunter , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, Alexander Shishkin , Mathieu Poirier , Arnaldo Carvalho de Melo , Jiri Olsa , linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC 1/6] perf/x86: Add perf text poke event Message-ID: <20191111144642.GM4114@hirez.programming.kicks-ass.net> References: <20191025130000.13032-1-adrian.hunter@intel.com> <20191025130000.13032-2-adrian.hunter@intel.com> <20191030104747.GA21153@leoy-ThinkPad-X240s> <20191030124659.GQ4114@hirez.programming.kicks-ass.net> <20191030141950.GB21153@leoy-ThinkPad-X240s> <20191030162325.GT4114@hirez.programming.kicks-ass.net> <20191031073136.GC21153@leoy-ThinkPad-X240s> <20191101100440.GU4131@hirez.programming.kicks-ass.net> <20191104022346.GC26019@leoy-ThinkPad-X240s> <20191108150530.GA7721@leoy-ThinkPad-X240s> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191108150530.GA7721@leoy-ThinkPad-X240s> 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, Nov 08, 2019 at 11:05:30PM +0800, Leo Yan wrote: > I will update some status for prototype (the code has been uploaded into > git server [1]) and found some issues for text poke perf event on arm64. > These issues are mainly related with arch64 architecture. > > - The first issue is for the nosync instruction emulation. On arm64, > some instructions need to be single stepped and some instructions > is emulated. Especially, after I read the code for kprobe > implementation on Arm64. So the main idea for prototyping is to use > the almos same method with kprobe for nosync instruction. This makes no sense to me what so ever. What actual instructions are patched with _nosync() ? ftrace/jump_label only use 'NOP/JMP/CALL' For NOP you can advance regs->ip, for JMP you can adjust regs->ip, for CALL you adjust regs->ip and regs->r14 (IIUC you do something like: regs->r14 = regs->ip+4; regs->ip = func;) (FWIW emulating CALL on x86 is fun because we get to PUSH something on the stack, let me know if you want to see the patches that were required to make that happen :-) > - The second issue is race condition between the CPU alters > instructions and other CPUs hit the altered instructions (and > breakpointed). > > Peter's suggestion uses global variables 'nosync_insn' and > 'nosync_addr' to record the altered instruction. But from the > testing I found for single static key, usually it will change for > multiple address at once. > > So this might cause the issue is: CPU(a) will loop to alter > instructions for different address (sometimes the opcode also is > different for different address), at the meantime, CPU(b) hits an > altered instruction and handle exception for the breakpoint, if > CPU(a) is continuing to alter instruction for the next address, thne > CPU(a) might wrongly to use the value from 'nosync_insn' and > 'nosync_addr'. > > Simply to say, we cannot only support single nosync instruction but > need to support multiple nosync instructions in the loop. On x86 all actual text poking is serialized by text_mutex. > - The third issue is might be nested issue. E.g. for the injected > break instruction, we have no method to pass perf event for this > instruction; and if we connect with the first issue, if the > instruction is single stepped with slot (the slot is allocated with > get_insn_slot()), we cannot to allow the perf user space to know > the instructions which are executed in the slots. > > I am not sure if I think too complex here. But seems to me, we > inject more instructions for poke text event, and if these injected > instructions are executed but the userspace decoder has no way to > pass the related info. That's a misunderstanding, the text_poke event is a side-band event and as such delivered to all events that expressed interest in it. You don't need any exception to event mapping yourself. > Just clarify, I am fine for merging this patch set, but we might > consider more what's the best way on Arm64. Welcome any public > comments and suggestions; I will sync internally for how to follow up > this functionality. Thanks!