Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1006419ybi; Fri, 14 Jun 2019 07:05:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6zzUMEGh5OB57rD1GMo5sJ5fodzakCRCCis7+2gjlKXbuYegNd7kJdarA2/wQZXt8Go4K X-Received: by 2002:a17:90a:ca11:: with SMTP id x17mr11496609pjt.107.1560521144927; Fri, 14 Jun 2019 07:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560521144; cv=none; d=google.com; s=arc-20160816; b=Vh22Ugja0dGWd1v7O+lmnwCfoOTpzoLabeERapsrJYu5oI3WtAkCRmMS6F4O8+Sn34 dHPH+yP4TNx/KIdnIPZXfLZg6sMJC8mzk5yYhdj2MovVbz9BS7BOuddQaP1InmNwHIHL kXD0uLY5GUqbLYrTUYHvVUONyxHB5e9lNIlaGnxM6nn02oCqzv9ip1TvqRmrEkA6I9Ni 2UmcPbDhwETzuozM78etSydOcXfGJCx0pBeGoFelPX96wQt3Y7uHOmL7uMBVmAsngo+W 79y7oFLVoxR7mKTQ5o6tIHbO0UFiEEhoMRjfs7cF5bUwxMlyvbQhv0dlIJwVLAtQ/xRE P2gQ== 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=H5Qkxfag8Q1LMIQpuRXJ8+48bU2nxnHSebOpJfgB9aY=; b=aL1BxPIMwo3KseQiRAJJzcr8Uvnw3ah67k8ZLzmwnT0nauiXobd2nWTGnIsJ7EfTkH D2m2+iZll/XUmf8um+5+9y8yMr5hYWpaU1xlDCyCmvstSSqHxkisft0+3YQnx+ucAs// aNn3qezRAu8nqPQKOE7o/VQus4+NT5CmOK8lV47DAZVs2c4jFg31lMQpnGkoekboNlMq Sw30C3Avc8wy2a2uGf1R6h2/0Rb1+6ia7jLxpTSNz1DOukf4ISSFVSr/0fX/3kFGl8BL lW3pVITEAU9+bHM/59sNh5UcXeAXvPRnEnoTmU0FSkXNBfZkHZ5RyP3raaZxv6NTcErG NqzQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si1217929pfn.99.2019.06.14.07.05.27; Fri, 14 Jun 2019 07:05:44 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbfFNOE7 (ORCPT + 99 others); Fri, 14 Jun 2019 10:04:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:59840 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728251AbfFNOE7 (ORCPT ); Fri, 14 Jun 2019 10:04:59 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E3287AEAF; Fri, 14 Jun 2019 14:04:57 +0000 (UTC) Date: Fri, 14 Jun 2019 16:04:57 +0200 From: Petr Mladek To: Josh Poimboeuf 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: <20190614140457.urqjlosesvdtmiia@pathway.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Best Regards, Petr