Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1261741ybi; Fri, 14 Jun 2019 11:22:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0wy97LOuFt7ly9o0lFkSFxBbtrFuvU+T6utpSpinDkoV/gLKmxm/IcHkRXtWxhWMAYPr8 X-Received: by 2002:a62:38c6:: with SMTP id f189mr23960436pfa.157.1560536532234; Fri, 14 Jun 2019 11:22:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560536532; cv=none; d=google.com; s=arc-20160816; b=aBDBFILE6hKttTHv1v3T+hWhsUknKhGCSqhJ2BtzbbfddIegj5Rw9paw5O0UvAnw/u u+DoVK0h+khTkJQbJ79ok9qcvSDJWdfuk5JzOOkew3UiudVbvEq6LKUM2di1sOwNmoAK IZrVengVoXrl6IXEnIRCcK1zxz2T8pcr45539xrHXUPJ9DyeXn6L5DZr6Hh9drH2YgiK zysvRwI8QDmJuwS0L0mJnBL+AtNFYfgwR2C15bj18QRIuYFAFOBfacsNMtf1vK5/i5Sj qGdqrYZCNwv0gKVORcFAEe9doACMT3x/r9XmskAJ3Ip8AFJncSfaEW97iuPrnWk+7PTX OwgA== 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; bh=YCgaCSDt2iUdF8dVp4GR2Ta+DN/YUZtQlRmgGkIHIKs=; b=K9cHovJRNVUzNpii/8bF6Ky//gXqtLRTlC5CC/HpldrShnCWQRg3OGr9ZBK4umPSOG bdk8FG3J7nyW1rf/EanyQZc4aXA7ic7QI3f0Om5/onAevYqNAMkh8PGN1mNQdOeMkkND JjstDUMgupQX9w4RP34H0j2NpWFgdUPOYkwxxZ8qhu8c8BBsgdDmXKMw2VDNNRTiiyzG +xTVOw2byeEQp2KT8GLwjef5KFdPm/gIgcY5GwSVZb0Lf8wWRjnncFG4/KOYgc6hQjmC r6KwjRrOKytvG3WFDxCzAWV1MmJiBdskpyCr/7dJfDCU5dlnmTDfm3p6472UopJVEGUZ 8rgw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59si2963240plp.90.2019.06.14.11.21.57; Fri, 14 Jun 2019 11:22:12 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726071AbfFNSVf (ORCPT + 99 others); Fri, 14 Jun 2019 14:21:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51196 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725814AbfFNSVf (ORCPT ); Fri, 14 Jun 2019 14:21:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B42D02F8BCC; Fri, 14 Jun 2019 18:21:29 +0000 (UTC) Received: from treble (ovpn-121-232.rdu2.redhat.com [10.10.121.232]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEA534E6DE; Fri, 14 Jun 2019 18:21:22 +0000 (UTC) Date: Fri, 14 Jun 2019 13:21:21 -0500 From: Josh Poimboeuf To: Petr Mladek Cc: Jessica Yu , Steven Rostedt , Jiri Kosina , Miroslav Benes , Joe Lawrence , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Johannes Erdfelt , Ingo Molnar Subject: Re: [PATCH 2/3] module: Add text_mutex lockdep assertions for page attribute changes Message-ID: <20190614182121.l4qvrfsjettoc7mi@treble> References: <20190614140457.urqjlosesvdtmiia@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190614140457.urqjlosesvdtmiia@pathway.suse.cz> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 14 Jun 2019 18:21:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 14, 2019 at 04:04:57PM +0200, Petr Mladek wrote: > On Thu 2019-06-13 20:07:23, Josh Poimboeuf wrote: > > External callers of the module page attribute change functions now need > > to have the text_mutex. Enforce that with lockdep assertions. > > > > diff --git a/kernel/module.c b/kernel/module.c > > index 6e6712b3aaf5..e43a90ee2d23 100644 > > --- a/kernel/module.c > > +++ b/kernel/module.c > > @@ -3519,7 +3534,7 @@ static noinline int do_init_module(struct module *mod) > > /* Switch to core kallsyms now init is done: kallsyms may be walking! */ > > rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); > > #endif > > - module_enable_ro(mod, true); > > + __module_enable_ro(mod, true); > > This one must be called under text_mutex. Otherwise it might get > called when ftrace is in the middle of modifying the functions. > > It should be enough to take text_mutex right around this call. > It will prevent making the code ro when ftrace is doing > the modification. It safe also the other way. > set_all_modules_text_ro() does not call frob_ro_after_init(). > Therefore ftrace could not make the after_init section RO prematurely. > > > mod_tree_remove_init(mod); > > module_arch_freeing_init(mod); > > mod->init_layout.base = NULL; > > @@ -3626,8 +3641,8 @@ static int complete_formation(struct module *mod, struct load_info *info) > > /* This relies on module_mutex for list integrity. */ > > module_bug_finalize(info->hdr, info->sechdrs, mod); > > > > - module_enable_ro(mod, false); > > - module_enable_nx(mod); > > + __module_enable_ro(mod, false); > > + __module_enable_nx(mod); > > This one is OK. It is called when the module is in > MODULE_STATE_UNFORMED. Therefore it is ignored by ftrace. > The module state is manipulated and checked under module_mutex. Yes, good catch. Thanks. -- Josh