Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8999574ybi; Fri, 7 Jun 2019 01:39:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzH94p6GU0MRaGTMC0xhvpDfNJMfWHieAOYS2YQEkWv9GPnBh5JEDrCgCfpD4KTr40jSm29 X-Received: by 2002:a62:7994:: with SMTP id u142mr13813714pfc.39.1559896790135; Fri, 07 Jun 2019 01:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559896790; cv=none; d=google.com; s=arc-20160816; b=nSIY8e8Krh3UYoIvKetHKYoFYjXWGSSVW6mK3rpE036vqdvV+BdT4UuBZP9m6Lf4XL maNL7VQUhh0iKKxurFwszRO/8iuKeCjyPtCmfJ+IXMKDKBIOdaxTc/XRX6vBrbnlgcCb KVdgkoqlS38sE/lr0SQercBb/3/5F2tvUUE9lMtStlkrVk9ST+bt9pdB/6G53Pkc1kCy bC9aG6YH6HRQ0igKoMKsmmG4Yvxw9FSzVOeOFT4SldeFGWhuToopgzFsE+rRyZk96mo0 uQ6QrlPJvAQIQ6iSFMb/Vt6Jca53czanqJNgfc3F82UnNA2LAddmGHSXI9Hy5PbQP18g qgOw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=k/hSXiJNYL8ZZMcx5p3mdI6yQL+dQlYirDFwee3TyA8=; b=FkJptz6Qu+LQTsrve4wTxC0i4vkquetW1FSgu3z3dyLF5fPM3FH07lSVOmwq6RMvoK Mt7h1KqT+x8gP41nU0Xl6H5n720MKcpQ3Treh25PjwIcTbgxSRTNTPDp1G7A4UOdFQiu YXuWL2VvDCIuqSmIXfGirnM2qkvtEgtUoCLnm75Xbv/0mc3MaJBK208/eoG8KwZo9W2r kxeptKfFEJ611m7QkyPzgIoAOa30KFBX9szCvRB2NZ2Em9ky310vml7LvI6FS9vANk05 52ZIJFD3GpSD0AuMYHVZJfKAdQZLoPXl01IolaAfTJkdeFWMu/EPfMP2gLvtlbwiAxlU U4kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="Y3j/2KLM"; 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 w2si1270220pga.495.2019.06.07.01.39.33; Fri, 07 Jun 2019 01:39:50 -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=bombadil.20170209 header.b="Y3j/2KLM"; 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 S1727109AbfFGIi2 (ORCPT + 99 others); Fri, 7 Jun 2019 04:38:28 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:53472 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbfFGIi2 (ORCPT ); Fri, 7 Jun 2019 04:38:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To: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=k/hSXiJNYL8ZZMcx5p3mdI6yQL+dQlYirDFwee3TyA8=; b=Y3j/2KLMjClLjbFHxrK61ft9av Dhtg566DgBSkgsz90tn/bfe4B0KA0BKuVckCdMV/GbQkM7A2iqVAg1ceL7wMoszxKQ9nuWosMjl44 SowmZlIEDuWjJVy/7Z9zXxPPoHcjXL97FImAHdGe1oKUxxtMDICmkORZ5QlbtEKylm/b8qBUx2KBU eKd8j7Hujy8ZAu3mKKNtW3FHFp6oqNBulBC+nifpCxNr3dXNxqZhdVIJthw04qCEhz5UOnupjXfoM ugTSwgUSnv6WwnMVUzRDraOVhcerLQp0InJFwvXap2ZDEi8tYdT924mLjRc2+KOC4jmQ+nzykKUIx VrjppsYQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hZANq-0004e8-GJ; Fri, 07 Jun 2019 08:37:58 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B6C0320973578; Fri, 7 Jun 2019 10:37:56 +0200 (CEST) Date: Fri, 7 Jun 2019 10:37:56 +0200 From: Peter Zijlstra To: Nadav Amit Cc: the arch/x86 maintainers , LKML , Ard Biesheuvel , Andy Lutomirski , Steven Rostedt , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , "H. Peter Anvin" , Rasmus Villemoes , Edward Cree , Daniel Bristot de Oliveira , Josh Poimboeuf Subject: Re: [PATCH 11/15] static_call: Add inline static call infrastructure Message-ID: <20190607083756.GW3419@hirez.programming.kicks-ass.net> References: <20190605130753.327195108@infradead.org> <20190605131945.193241464@infradead.org> <37CFAEC1-6D36-4A6D-8C44-F85FCFA053AA@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <37CFAEC1-6D36-4A6D-8C44-F85FCFA053AA@vmware.com> 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 Thu, Jun 06, 2019 at 10:24:17PM +0000, Nadav Amit wrote: > > +static void static_call_del_module(struct module *mod) > > +{ > > + struct static_call_site *start = mod->static_call_sites; > > + struct static_call_site *stop = mod->static_call_sites + > > + mod->num_static_call_sites; > > + struct static_call_site *site; > > + struct static_call_key *key, *prev_key = NULL; > > + struct static_call_mod *site_mod; > > + > > + for (site = start; site < stop; site++) { > > + key = static_call_key(site); > > + if (key == prev_key) > > + continue; > > + prev_key = key; > > + > > + list_for_each_entry(site_mod, &key->site_mods, list) { > > + if (site_mod->mod == mod) { > > + list_del(&site_mod->list); > > + kfree(site_mod); > > + break; > > + } > > + } > > + } > > I think that for safety, when a module is removed, all the static-calls > should be traversed to check that none of them calls any function in the > removed module. If that happens, perhaps it should be poisoned. We don't do that for normal indirect calls either.. I suppose we could here, but meh. > > +} > > + > > +static int static_call_module_notify(struct notifier_block *nb, > > + unsigned long val, void *data) > > +{ > > + struct module *mod = data; > > + int ret = 0; > > + > > + cpus_read_lock(); > > + static_call_lock(); > > + > > + switch (val) { > > + case MODULE_STATE_COMING: > > + module_disable_ro(mod); > > + ret = static_call_add_module(mod); > > + module_enable_ro(mod, false); > > Doesn’t it cause some pages to be W+X ? Can it be avoided? I don't know why it does this, jump_labels doesn't seem to need this, and I'm not seeing what static_call needs differently. > > + if (ret) { > > + WARN(1, "Failed to allocate memory for static calls"); > > + static_call_del_module(mod); > > If static_call_add_module() succeeded in changing some of the calls, but not > all, I don’t think that static_call_del_module() will correctly undo > static_call_add_module(). The code transformations, I think, will remain. Hurm, jump_labels has the same problem. I wonder why kernel/module.c:prepare_coming_module() doesn't propagate the error from the notifier call. If it were to do that, I think we'll abort the module load and any modifications get lost anyway.