Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp113932imj; Fri, 8 Feb 2019 16:09:54 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib6e1xPkwRMrYfdjbado8HXpve/Ix4vdbZuVR8jouAbndFldkKEFAVKdb883tZwp6hcEmuB X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr25968882plb.254.1549670993994; Fri, 08 Feb 2019 16:09:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549670993; cv=none; d=google.com; s=arc-20160816; b=msJGcZmmZw0aIL4xY5Pgc0ZrX9I0+OoMTmcX/cYF8lSMQy5UuATeo7BERT1ulptpm4 ih34pTN67hyujBXo7JQauoRbkIV5q2LNio+7xJ4skZsaxLvNfqALnY85TLxhXuaCwDck L5TtgyHUZOmJT17H8rPyhDS/q7kVbjvk8P/1d2PS2rY5i+h7eZ7NdqmZNpalC6dl85YU qW/x9UZOl7+iQ6b1uZFgz16KpDNNNCd6ZU3wETmf1INLm8ooH+EDQCR1XapFfltTr/JB ac/VUmKC4ft9UBj2NV7taQTnjxS2q+Ikx8w9MA+AZe8Gjcqzah7q5WEBNHglOO45gu4G qWjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=yxdwW1DyOtKem0WF782kU0A9egQwo4Qvb/PrColHLsc=; b=WpSlpcpOPRyPQuvHsyyqIf3Su89+x6yG+heuNwvkMWD6+fQFEzaGFKSYmO+kdt8xuj tDVhy4NEA5XsYrbBevZgV2Yyafcw1n7lfVyMM1to0V8olqcT71Z0IR2H8PtFfw5pTXbx uxGENNsW2S7CB359aKY+zW0gXDQGKEcUyTK3B/jSd8GXlLK1opPeVLZ1VeVWGJNMI95D IWRUPTE8uyRGu85+xCqMsdsjHYnPrTl3TDNKvRZYj6W4ZV5nUItUfZzmD9SV7LS7YSkO yKhQo76UHRdckOAQQ/ixlKshGaAyyyBZcufn0p8QFUQ2stsF0dO0Nk4YesHDvLEKoMHR 9VUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="fnSxCEl/"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si3313540pgb.231.2019.02.08.16.09.13; Fri, 08 Feb 2019 16:09:53 -0800 (PST) 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=pass header.i=@gmail.com header.s=20161025 header.b="fnSxCEl/"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726941AbfBIAJK (ORCPT + 99 others); Fri, 8 Feb 2019 19:09:10 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37227 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726222AbfBIAJJ (ORCPT ); Fri, 8 Feb 2019 19:09:09 -0500 Received: by mail-wm1-f67.google.com with SMTP id x10so824565wmg.2 for ; Fri, 08 Feb 2019 16:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yxdwW1DyOtKem0WF782kU0A9egQwo4Qvb/PrColHLsc=; b=fnSxCEl/bREIP3RAd8NIp5N+R5sUUw7aoHfWroXeUgHAbdmejiO7oc5wXLAEpd6Cyp 8XcURtp1dY/UuFEsajmGDsm1LkrPE4I1ktUNwpanSsFo2g1ULWf1wKXBOWLcQz96OHCO 6oiWOvAOyiYggXqmUIY0QmCgVEPeHbqi2NhAxrfHPw5K2iIyg6eJdlLjheNZQe4cLR// H3LdjPgINUDp5Y9qXSw9RThVXi/2m4QX1NSRVkcYrMqmMrksKSnIEPmCVY2DZh+IgXpd 74G4pIpPNLg0jSx3uYpwyCYpxjFmm6YtPJU4ZuGrEPQpoSyyUFzIWYBe5q/zMDPztB2k K8LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yxdwW1DyOtKem0WF782kU0A9egQwo4Qvb/PrColHLsc=; b=qL21kr4jTNpUZHGZD8TyHhmvC5NRGgE9y5IPFZE3B5xdL0qXg0QO1v/EaOgcJOBKxl IBiKPeG3mVZyegERqZ97HKpql3G9ZO5wLcJTChAYGS8nR/XkJrXsK8ZXkGoG2aVcMxtO lFrflsQtbHrCZZbdhgoYJAYpT9oDRWzi1I8px5OugXDFY9Bbf8zl9ASW+FS2OYDNpcIp 8SEnQoVP+ZZrhGbni/RJWmuXZjvahkEPE4hRG9AKgtH3GjUbMZNRFqmEa34kS0hyq2g8 6W2AzI4TqAzXXpL+uMH7eBYsTO3l5/CGqq8LcnKY6yEfIgJV3ktPHv+p97VPwPTRCt/3 ssIA== X-Gm-Message-State: AHQUAub5NqVrELwrJIP8cP/Vg6X05+ZcDkdfa2wGjXecLMafbzXuXQ0T 7htXMP3NJ7Ag3oZrUsS7nlE= X-Received: by 2002:a7b:c4cb:: with SMTP id g11mr742497wmk.149.1549670947426; Fri, 08 Feb 2019 16:09:07 -0800 (PST) Received: from localhost.localdomain (79.108.96.12.dyn.user.ono.com. [79.108.96.12]) by smtp.gmail.com with ESMTPSA id 65sm10483171wrb.62.2019.02.08.16.09.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 16:09:06 -0800 (PST) From: Miguel Ojeda To: Jessica Yu Cc: Miguel Ojeda , Laura Abbott , Martin Sebor , Arnd Bergmann , Masahiro Yamada , James Morris , Mathieu Desnoyers , Borislav Petkov , Kees Cook , Matt Mullins , Vincent Whitchurch , WANG Chao , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] include/linux/module.h: copy __init/__exit attrs to init/cleanup_module Date: Sat, 9 Feb 2019 01:08:40 +0100 Message-Id: <20190209000840.11018-4-miguel.ojeda.sandonis@gmail.com> In-Reply-To: <20190209000840.11018-1-miguel.ojeda.sandonis@gmail.com> References: <20190209000840.11018-1-miguel.ojeda.sandonis@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The upcoming GCC 9 release extends the -Wmissing-attributes warnings (enabled by -Wall) to C and aliases: it warns when particular function attributes are missing in the aliases but not in their target. In particular, it triggers for all the init/cleanup_module aliases in the kernel (defined by the module_init/exit macros), ending up being very noisy. These aliases point to the __init/__exit functions of a module, which are defined as __cold (among other attributes). However, the aliases themselves do not have the __cold attribute. Since the compiler behaves differently when compiling a __cold function as well as when compiling paths leading to calls to __cold functions, the warning is trying to point out the possibly-forgotten attribute in the alias. In order to keep the warning enabled, we decided to silence this case. Ideally, we would mark the aliases directly as __init/__exit. However, there are currently around 132 modules in the kernel which are missing __init/__exit in their init/cleanup functions (either because they are missing, or for other reasons, e.g. the functions being called from somewhere else); and a section mismatch is a hard error. A conservative alternative was to mark the aliases as __cold only. However, since we would like to eventually enforce __init/__exit to be always marked, we chose to use the new __copy function attribute (introduced by GCC 9 as well to deal with this). With it, we copy the attributes used by the target functions into the aliases. This way, functions that were not marked as __init/__exit won't have their aliases marked either, and therefore there won't be a section mismatch. Note that the warning would go away marking either the extern declaration, the definition, or both. However, we only mark the definition of the alias, since we do not want callers (which only see the declaration) to be compiled as if the function was __cold (and therefore the paths leading to those calls would be assumed to be unlikely). Link: https://lore.kernel.org/lkml/20190123173707.GA16603@gmail.com/ Link: https://lore.kernel.org/lkml/20190206175627.GA20399@gmail.com/ Suggested-by: Martin Sebor Signed-off-by: Miguel Ojeda --- include/linux/module.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 8fa38d3e7538..f5bc4c046461 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -129,13 +129,13 @@ extern void cleanup_module(void); #define module_init(initfn) \ static inline initcall_t __maybe_unused __inittest(void) \ { return initfn; } \ - int init_module(void) __attribute__((alias(#initfn))); + int init_module(void) __copy(initfn) __attribute__((alias(#initfn))); /* This is only required if you want to be unloadable. */ #define module_exit(exitfn) \ static inline exitcall_t __maybe_unused __exittest(void) \ { return exitfn; } \ - void cleanup_module(void) __attribute__((alias(#exitfn))); + void cleanup_module(void) __copy(exitfn) __attribute__((alias(#exitfn))); #endif -- 2.17.1