Received: by 2002:a05:6358:579e:b0:115:34ad:32ad with SMTP id m30csp21899rwf; Thu, 6 Apr 2023 12:05:21 -0700 (PDT) X-Google-Smtp-Source: AKy350ZKM51f9eaVx2fycQ89AsIEUjXl6EeMtTM4k0D8dzM7mclN0QPYVkWwUr8ZAKrMZjcq5Wnc X-Received: by 2002:a17:906:774a:b0:93e:3194:99cd with SMTP id o10-20020a170906774a00b0093e319499cdmr7939908ejn.12.1680807921062; Thu, 06 Apr 2023 12:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680807921; cv=none; d=google.com; s=arc-20160816; b=f1hGcCZZafo67WTeGkHx45wc1vjUiew2Nvu6xMkGcEq+OyY4FlVhuNaofuvDVInIDk Fzl6zER63CiTMssAl3aG2ITtcyP+m6+WdwwdWLLQPUiDD+4t4DS6+BeOXjXLx2RzOlkK ZpluXWXkknYWwKr+JMW14J4IBvEOjz7qcFhEUm/IghAisO8IWPEaGU95ZlYNC0BJx8xD tYRrGdhO6XLgsXAL9Sxn67xPhyhvrfT9AiE9Ilb4xgLu9aaGyG3chPtRw2ZzkWjBoBbT LRt2sEhwaiuX0R4+ef2kgIp5/dWXvrIYFxOd37l/esbFKP5Pcgt+yEAMyCycT2xP7P0g HCgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=lY1ByN87FMvQLmIB6FmZa+RzwBjVh5nyLSYhKEEms/o=; b=SaxryjBdGTkd5psDHIiaHXHuIrAux8vFKOA4qUbWrqvnFifo0KV0nwHU0d1xcbjII7 uOr8PVM7c7ysH/nEL4u/cmqZYKCDB868SMK742jUpiH8lI0X0O/1GQhnLyTT2YCTLs8G LaRML+vlt5EiTdQzAqvjdF3k+wrsWvwsJOGph4041dkUuMluHPh8TUX6OrfVGeUho+Xc wliLVPWg4x6ZUGMTSyux78V8DqwusHC4993jFhAEPDM9YvJAXUhcnj7ccRgCz0Is4OJY R+KnHHRQ+o4hprnGjYzkTUxUO1JvLgXZk9tOaCqc/R+fFpdFsVmKWC9V1nVGwRWMpTk4 eF0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TXJhoFce; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020a1709064c4300b009316736fd97si1557159ejw.405.2023.04.06.12.04.48; Thu, 06 Apr 2023 12:05:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TXJhoFce; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240346AbjDFTBM (ORCPT + 99 others); Thu, 6 Apr 2023 15:01:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240342AbjDFTBG (ORCPT ); Thu, 6 Apr 2023 15:01:06 -0400 Received: from mail-il1-x14a.google.com (mail-il1-x14a.google.com [IPv6:2607:f8b0:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA24E4217 for ; Thu, 6 Apr 2023 12:01:02 -0700 (PDT) Received: by mail-il1-x14a.google.com with SMTP id s6-20020a056e02216600b003264c778ef1so13306585ilv.23 for ; Thu, 06 Apr 2023 12:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680807662; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lY1ByN87FMvQLmIB6FmZa+RzwBjVh5nyLSYhKEEms/o=; b=TXJhoFceFs9wdYTRZd708YmwDXv6ZmJEZM5qsCVnFNFux6VSIy2sN485OdoLj6gH/u AQsSA/pqWjyYGM48tvaIncpfU2OLAUpCMQfGEUljMQY32VJVtir3KfI0/oLx5XXuijgt IdQDFo/dXt9qgNaakCRBJpEPF2lgHkdbMkFeyywUgZbfu/OiLuvJ3B+dRHj3/Osu3wFs Igv3FoQJ+xdCyHBUlOkjbozloyiEts0oRkMIvsUAEiq5xM+8ae/xA8FEMfg2w3bV7nHX XXgsLfahva+s2fFRR2U9HW32kdVcssWxj7eIV8JYkxojb7lCllY002RCrgMUSAo+vdRi BYJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680807662; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lY1ByN87FMvQLmIB6FmZa+RzwBjVh5nyLSYhKEEms/o=; b=kRYGlyjec6IOgdNQgx/U0dAKkeOCwoVLA/hwI5e4x+AKsxRld1HcmjJSYwSjhOjF7T 00T4UPTBwZZptagQ/8PzZiweu85erJpKFS3UC1xgpWfGJiR58fAEBa6ZleeAQaxKuopc 4glkW6S0wRwFM9zoh71l3dxu+DA2BPb+bpDteBMY/8W5HaW1KUwGafAf1wSmUrb0S9eR lXZErpUN6ELuluWg/E8uwsa3bHgm5buvgy9QwuSJWAXlndsmnhZpisPzT0BRDzwAKLfc I+y2UpuvN+Hfryr6iPgFwkOC6mearMB2QnnfiWGJT7CwghG6MP29XwBd1RQLdBhVWac6 i+xA== X-Gm-Message-State: AAQBX9dRPsl6Y0XbSAVlX6vJLSaN4bptSikWuKN2E+RrHRMsGEgoUthg y67j+qWEryI9AJRYWg171NvIM4lkjDeDv1g= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a02:8503:0:b0:3a9:75c9:da25 with SMTP id g3-20020a028503000000b003a975c9da25mr5548851jai.1.1680807662053; Thu, 06 Apr 2023 12:01:02 -0700 (PDT) Date: Thu, 6 Apr 2023 14:00:23 -0500 In-Reply-To: <20230406190030.968972-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221219204619.2205248-1-allenwebb@google.com> <20230406190030.968972-1-allenwebb@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230406190030.968972-5-allenwebb@google.com> Subject: [PATCH v10 04/11] module.h: MODULE_DEVICE_TABLE for built-in modules From: Allen Webb To: "linux-modules@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: gregkh@linuxfoundation.org, mcgrof@kernel.org, christophe.leroy@csgroup.eu, nick.alcock@oracle.com, Allen Webb Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement MODULE_DEVICE_TABLE for build-in modules to make it possible to generate a builtin.alias file to complement modules.alias. Signed-off-by: Allen Webb --- include/linux/module.h | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 4435ad9439ab..b1cb12e06996 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -237,14 +237,36 @@ extern void cleanup_module(void); /* What your module does. */ #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) -#ifdef MODULE -/* Creates an alias so file2alias.c can find device table. */ +/* + * Creates an alias so file2alias.c can find device table. + * + * Use this in cases where a device table is used to match devices because it + * surfaces match-id based module aliases to userspace for: + * - Automatic module loading through modules.alias. + * - Tools like USBGuard which block devices based on policy such as which + * modules match a device. + * + * The only use-case for built-in drivers today is to enable userspace to + * prevent / allow probe for devices on certain subsystems even if the driver is + * already loaded. An example is the USB subsystem with its authorized_default + * sysfs attribute. For more details refer to the kernel's Documentation for USB + * about authorized_default. + * + * The module name is included in the alias for two reasons: + * - It avoids creating two aliases with the same name for built-in modules. + * Historically MODULE_DEVICE_TABLE was a no-op for built-in modules, so + * there was nothing to stop different modules from having the same device + * table name and consequently the same alias when building as a module. + * - The module name is needed by files2alias.c to associate a particular + * device table with its associated module for built-in modules since + * files2alias would otherwise see the module name as `vmlinuz.o`. + */ #define MODULE_DEVICE_TABLE(type, name) \ -extern typeof(name) __mod_##type##__##name##_device_table \ - __attribute__ ((unused, alias(__stringify(name)))) -#else /* !MODULE */ -#define MODULE_DEVICE_TABLE(type, name) -#endif +extern void *CONCATENATE( \ + CONCATENATE(__mod_##type##__##name##__, \ + __KBUILD_MODNAME), \ + _device_table) \ + __attribute__ ((unused, alias(__stringify(name)))) /* Version of form [:][-]. * Or for CVS/RCS ID version, everything but the number is stripped. -- 2.39.2