From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martijn Coenen Subject: [PATCH 1/6] export: explicitly align struct kernel_symbol. Date: Mon, 16 Jul 2018 14:21:20 +0200 Message-ID: <20180716122125.175792-2-maco@android.com> References: <20180716122125.175792-1-maco@android.com> Return-path: In-Reply-To: <20180716122125.175792-1-maco@android.com> Sender: linux-kernel-owner@vger.kernel.org To: linux-kernel@vger.kernel.org Cc: Martijn Coenen , Masahiro Yamada , Michal Marek , Geert Uytterhoeven , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Alan Stern , Greg Kroah-Hartman , Oliver Neukum , Arnd Bergmann , Jessica Yu , Stephen Boyd , Philippe Ombredanne , Kate Stewart , Sam Ravnborg , linux-kbuild@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-scsi List-Id: linux-arch.vger.kernel.org This change allows growing struct kernel_symbol without wasting bytes to alignment. struct kernel_symbol was already implicitly being aligned to the word size, except on x86_64 and m68k, where it is aligned to 16 and 2 bytes, respectively. As far as I can tell there is no requirement for aligning struct kernel_symbol to 16 bytes on x86_64, but gcc aligns structs to their size, and the linker aligns the custom __ksymtab sections to the largest data type contained within, so setting KSYM_ALIGN to 16 was necessary to stay consistent with the code generated for non-ASM EXPORT_SYMBOL(). Now that non-ASM EXPORT_SYMBOL() explicitly aligns to word size (8), KSYM_ALIGN is no longer necessary. As for m68k, struct kernel_symbol is aligned to 2 bytes even though the structure itself is 8 bytes; using a 4-byte alignment shouldn't hurt. I manually verified the output of the __ksymtab sections didn't change on x86, x86_64, arm, arm64 and m68k. As expected, the section contents didn't change, and the ELF section alignment only changed on x86_64 and m68k. Feedback from other archs more than welcome. Signed-off-by: Martijn Coenen --- arch/m68k/include/asm/export.h | 1 - arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/export.h | 5 ----- include/linux/export.h | 1 + 4 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 arch/x86/include/asm/export.h diff --git a/arch/m68k/include/asm/export.h b/arch/m68k/include/asm/export.h index 0af20f48bd07..b53008b67ce1 100644 --- a/arch/m68k/include/asm/export.h +++ b/arch/m68k/include/asm/export.h @@ -1,3 +1,2 @@ -#define KSYM_ALIGN 2 #define KCRC_ALIGN 2 #include diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild index de690c2d2e33..a0ab9ab61c75 100644 --- a/arch/x86/include/asm/Kbuild +++ b/arch/x86/include/asm/Kbuild @@ -8,5 +8,6 @@ generated-y += xen-hypercalls.h generic-y += dma-contiguous.h generic-y += early_ioremap.h +generic-y += export.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h diff --git a/arch/x86/include/asm/export.h b/arch/x86/include/asm/export.h deleted file mode 100644 index 2a51d66689c5..000000000000 --- a/arch/x86/include/asm/export.h +++ /dev/null @@ -1,5 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifdef CONFIG_64BIT -#define KSYM_ALIGN 16 -#endif -#include diff --git a/include/linux/export.h b/include/linux/export.h index b768d6dd3c90..ad6b8e697b27 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -64,6 +64,7 @@ extern struct module __this_module; static const struct kernel_symbol __ksymtab_##sym \ __used \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \ + __attribute__((aligned(sizeof(void *)))) \ = { (unsigned long)&sym, __kstrtab_##sym } #if defined(__KSYM_DEPS__) -- 2.18.0.203.gfac676dfb9-goog From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f68.google.com ([209.85.208.68]:43199 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729606AbeGPMsq (ORCPT ); Mon, 16 Jul 2018 08:48:46 -0400 Received: by mail-ed1-f68.google.com with SMTP id b20-v6so4263927edt.10 for ; Mon, 16 Jul 2018 05:21:34 -0700 (PDT) From: Martijn Coenen Subject: [PATCH 1/6] export: explicitly align struct kernel_symbol. Date: Mon, 16 Jul 2018 14:21:20 +0200 Message-ID: <20180716122125.175792-2-maco@android.com> In-Reply-To: <20180716122125.175792-1-maco@android.com> References: <20180716122125.175792-1-maco@android.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: linux-kernel@vger.kernel.org Cc: Martijn Coenen , Masahiro Yamada , Michal Marek , Geert Uytterhoeven , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Alan Stern , Greg Kroah-Hartman , Oliver Neukum , Arnd Bergmann , Jessica Yu , Stephen Boyd , Philippe Ombredanne , Kate Stewart , Sam Ravnborg , linux-kbuild@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-arch@vger.kernel.org, maco@google.com, sspatil@google.com, malchev@google.com, joelaf@google.com Message-ID: <20180716122120.i2z9ma79Dwo8IF09qPlM154-3ActbWyokC4jncKcBzI@z> This change allows growing struct kernel_symbol without wasting bytes to alignment. struct kernel_symbol was already implicitly being aligned to the word size, except on x86_64 and m68k, where it is aligned to 16 and 2 bytes, respectively. As far as I can tell there is no requirement for aligning struct kernel_symbol to 16 bytes on x86_64, but gcc aligns structs to their size, and the linker aligns the custom __ksymtab sections to the largest data type contained within, so setting KSYM_ALIGN to 16 was necessary to stay consistent with the code generated for non-ASM EXPORT_SYMBOL(). Now that non-ASM EXPORT_SYMBOL() explicitly aligns to word size (8), KSYM_ALIGN is no longer necessary. As for m68k, struct kernel_symbol is aligned to 2 bytes even though the structure itself is 8 bytes; using a 4-byte alignment shouldn't hurt. I manually verified the output of the __ksymtab sections didn't change on x86, x86_64, arm, arm64 and m68k. As expected, the section contents didn't change, and the ELF section alignment only changed on x86_64 and m68k. Feedback from other archs more than welcome. Signed-off-by: Martijn Coenen --- arch/m68k/include/asm/export.h | 1 - arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/export.h | 5 ----- include/linux/export.h | 1 + 4 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 arch/x86/include/asm/export.h diff --git a/arch/m68k/include/asm/export.h b/arch/m68k/include/asm/export.h index 0af20f48bd07..b53008b67ce1 100644 --- a/arch/m68k/include/asm/export.h +++ b/arch/m68k/include/asm/export.h @@ -1,3 +1,2 @@ -#define KSYM_ALIGN 2 #define KCRC_ALIGN 2 #include diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild index de690c2d2e33..a0ab9ab61c75 100644 --- a/arch/x86/include/asm/Kbuild +++ b/arch/x86/include/asm/Kbuild @@ -8,5 +8,6 @@ generated-y += xen-hypercalls.h generic-y += dma-contiguous.h generic-y += early_ioremap.h +generic-y += export.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h diff --git a/arch/x86/include/asm/export.h b/arch/x86/include/asm/export.h deleted file mode 100644 index 2a51d66689c5..000000000000 --- a/arch/x86/include/asm/export.h +++ /dev/null @@ -1,5 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifdef CONFIG_64BIT -#define KSYM_ALIGN 16 -#endif -#include diff --git a/include/linux/export.h b/include/linux/export.h index b768d6dd3c90..ad6b8e697b27 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -64,6 +64,7 @@ extern struct module __this_module; static const struct kernel_symbol __ksymtab_##sym \ __used \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \ + __attribute__((aligned(sizeof(void *)))) \ = { (unsigned long)&sym, __kstrtab_##sym } #if defined(__KSYM_DEPS__) -- 2.18.0.203.gfac676dfb9-goog From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Subject: [1/6] export: explicitly align struct kernel_symbol. From: Martijn Coenen Message-Id: <20180716122125.175792-2-maco@android.com> Date: Mon, 16 Jul 2018 14:21:20 +0200 To: linux-kernel@vger.kernel.org Cc: Martijn Coenen , Masahiro Yamada , Michal Marek , Geert Uytterhoeven , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Alan Stern , Greg Kroah-Hartman , Oliver Neukum , Arnd Bergmann , Jessica Yu , Stephen Boyd , Philippe Ombredanne , Kate Stewart , Sam Ravnborg , linux-kbuild@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-arch@vger.kernel.org, maco@google.com, sspatil@google.com, malchev@google.com, joelaf@google.com List-ID: VGhpcyBjaGFuZ2UgYWxsb3dzIGdyb3dpbmcgc3RydWN0IGtlcm5lbF9zeW1ib2wgd2l0aG91dCB3 YXN0aW5nIGJ5dGVzIHRvCmFsaWdubWVudC4KCnN0cnVjdCBrZXJuZWxfc3ltYm9sIHdhcyBhbHJl YWR5IGltcGxpY2l0bHkgYmVpbmcgYWxpZ25lZCB0byB0aGUgd29yZApzaXplLCBleGNlcHQgb24g eDg2XzY0IGFuZCBtNjhrLCB3aGVyZSBpdCBpcyBhbGlnbmVkIHRvIDE2IGFuZCAyIGJ5dGVzLApy ZXNwZWN0aXZlbHkuCgpBcyBmYXIgYXMgSSBjYW4gdGVsbCB0aGVyZSBpcyBubyByZXF1aXJlbWVu dCBmb3IgYWxpZ25pbmcgc3RydWN0Cmtlcm5lbF9zeW1ib2wgdG8gMTYgYnl0ZXMgb24geDg2XzY0 LCBidXQgZ2NjIGFsaWducyBzdHJ1Y3RzIHRvIHRoZWlyCnNpemUsIGFuZCB0aGUgbGlua2VyIGFs aWducyB0aGUgY3VzdG9tIF9fa3N5bXRhYiBzZWN0aW9ucyB0byB0aGUgbGFyZ2VzdApkYXRhIHR5 cGUgY29udGFpbmVkIHdpdGhpbiwgc28gc2V0dGluZyBLU1lNX0FMSUdOIHRvIDE2IHdhcyBuZWNl c3NhcnkgdG8Kc3RheSBjb25zaXN0ZW50IHdpdGggdGhlIGNvZGUgZ2VuZXJhdGVkIGZvciBub24t QVNNIEVYUE9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