From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_NEOMUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FBCBC48BD6 for ; Wed, 26 Jun 2019 14:52:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 107BD2053B for ; Wed, 26 Jun 2019 14:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728174AbfFZOwj (ORCPT ); Wed, 26 Jun 2019 10:52:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32822 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726484AbfFZOwi (ORCPT ); Wed, 26 Jun 2019 10:52:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A728681DEC; Wed, 26 Jun 2019 14:52:24 +0000 (UTC) Received: from treble (ovpn-126-66.rdu2.redhat.com [10.10.126.66]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1A2560BE5; Wed, 26 Jun 2019 14:52:09 +0000 (UTC) Date: Wed, 26 Jun 2019 09:52:06 -0500 From: Josh Poimboeuf To: Thomas Gleixner Cc: Petr Mladek , Miroslav Benes , Steven Rostedt , Jessica Yu , Jiri Kosina , Joe Lawrence , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Johannes Erdfelt , Ingo Molnar , mhiramat@kernel.org, torvalds@linux-foundation.org Subject: Re: [PATCH 1/3] module: Fix livepatch/ftrace module text permissions race Message-ID: <20190626145206.vqp4nivxva4oshvw@treble> References: <20190614170408.1b1162dc@gandalf.local.home> <20190626133721.ea2iuqqu4to2jpbv@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 26 Jun 2019 14:52:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 26, 2019 at 04:44:45PM +0200, Thomas Gleixner wrote: > On Wed, 26 Jun 2019, Petr Mladek wrote: > > On Wed 2019-06-26 10:22:45, Miroslav Benes wrote: > > It is similar problem that has been solved by 2d1e38f56622b9bb5af8 > > ("kprobes: Cure hotplug lock ordering issues"). This commit solved > > it by always taking cpu_hotplug_lock.rw_sem before text_mutex inside. > > > > If we follow the lock ordering then ftrace has to take text_mutex > > only when stop_machine() is not called or from code called via > > stop_machine() parameter. > > > > This is not easy with the current design. For example, arm calls > > set_all_modules_text_rw() already in ftrace_arch_code_modify_prepare(), > > see arch/arm/kernel/ftrace.c. And it is called: > > > > + outside stop_machine() from ftrace_run_update_code() > > + without stop_machine() from ftrace_module_enable() > > > > A conservative solution for 5.2 release would be to move text_mutex > > locking from the generic kernel/trace/ftrace.c into > > arch/x86/kernel/ftrace.c: > > > > ftrace_arch_code_modify_prepare() > > ftrace_arch_code_modify_post_process() > > > > It should be enough to fix the original problem because > > x86 is the only architecture that calls set_all_modules_text_rw() > > in ftrace path and supports livepatching at the same time. > > Looks correct, but I've paged out all the gory details vs. lock ordering in > that area. Looks good to me as well, Petr can you post a proper patch? -- Josh