Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5971367ybp; Tue, 15 Oct 2019 07:45:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKQQfKcOz74870HpfdZ6zpeqMaohWZ8gHaqWpsFG8rk0YZJw4gdeNkr6Lhg36a6pkDxcPw X-Received: by 2002:a17:906:5e07:: with SMTP id n7mr34410789eju.271.1571150726438; Tue, 15 Oct 2019 07:45:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571150726; cv=none; d=google.com; s=arc-20160816; b=BdcrgjK/KqbuMD1jxUGRiBH1v1aHlu0SJf/oqQiSPqdb6cxCuH1VbNfEMTl/4tDFpn JIAT9gKnV2rMpJCZlds1GdtTQaumLqzsZPfwgmn0dpTccYia/Y8pUQ1sWvUDq3xHCiWf xsrkb+HSdtZRur/wcqfcA5Q+UeTXQzaq7BzCUsWw6y6yprUl9e3N0643+VaxN0HgMQVc ebksKgDDz9Lp4rKSNIQlydhk2RgoBmOC2yqOzy1e2ydt9u4/c0J0pfa/ONeDoGVy6j0g TncXeNJOuPct3oUe2qVTh0dnvXgNTODOC3WT8Q/O+9LgOpcmxwqvr4nsZfo4dvkhPzo5 lyqg== 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=BWcOBQNedloFMcUSVBi+lak7wlJILq9dGz2dM7VJlk8=; b=Phcma5/CkyipaSb2lTjm8aGozD76is5XOie/Gt2ag/yLMWHAQJ/IJEbQjRCkZrj7KH ONcYM8OdUrHbWNC/ixyE4Fj+WtqLLKM1FW4WTzzaLV9p/LdzKt2L4vLIkDvhr7Y5d0lQ IaxnB2Got/QBlqoQJSxe9pvabVDmKUnrSA383Hb30s4g+JdmzNkTBpFcgfZbjVi8n3/0 /xYX4Td0vYQJJrHSHex0CU//h3tHuoFOLqf9E/aVlXUmhpuyVag3MKdsrVhwd8PyeBoZ ec+KTygsOCKjIDxqXZz0Kc6Aq6I5D9qLQLsRdPJUAHE/zRezsENIhc5JHTB4wR7y7RSp 6+cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=J9tnel2M; 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 h13si12350537edw.348.2019.10.15.07.45.02; Tue, 15 Oct 2019 07:45:26 -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=merlin.20170209 header.b=J9tnel2M; 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 S1732896AbfJOOno (ORCPT + 99 others); Tue, 15 Oct 2019 10:43:44 -0400 Received: from merlin.infradead.org ([205.233.59.134]:35924 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732636AbfJOOno (ORCPT ); Tue, 15 Oct 2019 10:43:44 -0400 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=BWcOBQNedloFMcUSVBi+lak7wlJILq9dGz2dM7VJlk8=; b=J9tnel2MY8snkRQeHAsYz5LCe UeEUx2I+ZDYSbmgEVBL19PvOgu0QMWOQss1xYsKIG8OEjoduL6sAv7OQNhoFDuRF0n8vMuJHXf6UQ XuQlft80tmm6WaWMSr9vv2UADNSKNEIccOYllMcVh4pFUprNCeKgmAkdA+Urbmm5dmccp+dJmZCsT v4BTuaTFZZ/TBPABReXkDVDjwia5lPAHVhkzOp07grmKH7/1o7Ys5GAeuNa5J70Di6T1XLSHdpYvJ 9EVEU7t+jcfJZTpCzSXyFw4XgA+SR18mnoXJOxqoESSYW0KAWTjbKiHuNxYs8MnqoTBvZ3zvaHexn aBNOSR+2g==; 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 1iKO2R-0005d2-2Q; Tue, 15 Oct 2019 14:43:03 +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 62A42304637; Tue, 15 Oct 2019 16:42:04 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DA4FF2023D649; Tue, 15 Oct 2019 16:42:58 +0200 (CEST) Date: Tue, 15 Oct 2019 16:42:58 +0200 From: Peter Zijlstra To: Jessica Yu Cc: Steven Rostedt , x86@kernel.org, linux-kernel@vger.kernel.org, mhiramat@kernel.org, bristot@redhat.com, jbaron@akamai.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, namit@vmware.com, hpa@zytor.com, luto@kernel.org, ard.biesheuvel@linaro.org, jpoimboe@redhat.com, rabin@rab.in, Mark Rutland , Will Deacon , james.morse@arm.com Subject: Re: [PATCH v3 5/6] x86/ftrace: Use text_poke() Message-ID: <20191015144258.GQ2359@hirez.programming.kicks-ass.net> References: <20191008104335.6fcd78c9@gandalf.local.home> <20191009224135.2dcf7767@oasis.local.home> <20191010092054.GR2311@hirez.programming.kicks-ass.net> <20191010091956.48fbcf42@gandalf.local.home> <20191010140513.GT2311@hirez.programming.kicks-ass.net> <20191010115449.22044b53@gandalf.local.home> <20191010172819.GS2328@hirez.programming.kicks-ass.net> <20191011125903.GN2359@hirez.programming.kicks-ass.net> <20191015130739.GA23565@linux-8ccs> <20191015135634.GK2328@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191015135634.GK2328@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 Tue, Oct 15, 2019 at 03:56:34PM +0200, Peter Zijlstra wrote: > Right, the problem is set_all_modules_text_*(), that relies on COMING > having made the protection changes. > > After the x86 changes, there's only 2 more architectures that use that > function. I'll work on getting those converted and then we can delete > that function and worry no more about it. Here's a possible patch for arch/arm, which only leaves arch/nds32/. --- arch/arm/kernel/ftrace.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index bda949fd84e8..c87e68e4ccf7 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef CONFIG_THUMB2_KERNEL #define NOP 0xf85deb04 /* pop.w {lr} */ @@ -31,13 +32,15 @@ #ifdef CONFIG_DYNAMIC_FTRACE +static int patch_text_remap = 0; + static int __ftrace_modify_code(void *data) { int *command = data; - set_kernel_text_rw(); + patch_text_remap = 1; ftrace_modify_all_code(*command); - set_kernel_text_ro(); + patch_text_remap = 0; return 0; } @@ -59,13 +62,13 @@ static unsigned long adjust_address(struct dyn_ftrace *rec, unsigned long addr) int ftrace_arch_code_modify_prepare(void) { - set_all_modules_text_rw(); + patch_text_remap = 1; return 0; } int ftrace_arch_code_modify_post_process(void) { - set_all_modules_text_ro(); + patch_text_remap = 0; /* Make sure any TLB misses during machine stop are cleared. */ flush_tlb_all(); return 0; @@ -97,10 +100,7 @@ static int ftrace_modify_code(unsigned long pc, unsigned long old, return -EINVAL; } - if (probe_kernel_write((void *)pc, &new, MCOUNT_INSN_SIZE)) - return -EPERM; - - flush_icache_range(pc, pc + MCOUNT_INSN_SIZE); + __patch_text_real((void *)pc, new, patch_text_remap); return 0; }