Skip to contentSkip to conversation

x86/vdso: Remove remnants of the fake section table

PATCH In review Sean Christopherson 3 participants 9 messages Dec 4, 2018 – Dec 5, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover x86/vdso: Remove remnants of the fake section table

Remove pieces of the vDSO's fake section table mechanism that were left behind when the vDSO build process reverted to using "objdump -S" to strip the userspace image.

One of the removed pieces is a 0x340 byte reservation (for 64-bit) in the .rodata section. Trimming that fat drops the current image's size to under 4k, i.e. reduces the effective size of the userspace vDSO mapping by a full page.

v1->v2:
- Remove the definition of sym_VDSO_FAKE_SECTION_TABLE_*
- Add patches 3/4 and 4/4 for additional cleanup

Sean Christopherson (4):
x86/vdso: Remove obsolete "fake section table" reservation x86/vdso: Remove a stale/misleading comment from the linker script x86/vdso: Remove struct vdso_sym and its associated export option x86/vdso: Rename "required_syms" to "requested_syms"

 arch/x86/entry/vdso/vdso-layout.lds.S | 27 -------------------
 arch/x86/entry/vdso/vdso2c.c          | 37 +++++++++------------------
 arch/x86/entry/vdso/vdso2c.h          | 15 +++++------
 3 files changed, 19 insertions(+), 60 deletions(-)
Signature · 1 line
2.19.2
#1 lore raw

PATCH v2 1/4 x86/vdso: Remove obsolete "fake section table" reservation

At one point the vDSO image was manually stripped down by vdso2c in an attempt to minimize the size of the image mapped into userspace. Part of that stripping process involved building a fake section table so as not to break userspace processes that parse the section table. Memory for the fake section table was reserved in the .rodata section so that vdso2c could simply copy the entire PT_LOAD segment into the userspace image after building the fake table.

Eventually, the entire fake section table approach was dropped in favor of stripping the vdso "the old fashioned way", i.e. via objdump -S. But, the reservation in .rodata for the fake table was left behind. Remove the reserveration along with a few other related defines and section entries.

Removing the fake section table placeholder zaps a whopping 0x340 bytes from the 64-bit vDSO image, which drops the current image's size to under 4k, i.e. reduces the effective size of the userspace vDSO mapping by a full page.

Fixes da861e18eccc ("x86, vdso: Get rid of the fake section mechanism")
Cc Andy Lutomirski <[email protected]>
---
 arch/x86/entry/vdso/vdso-layout.lds.S | 22 ----------------------
 arch/x86/entry/vdso/vdso2c.c          |  8 --------
 2 files changed, 30 deletions(-)
arch/x86/entry/vdso/vdso-layout.lds.S +0 -22
index acfd5ba7d943..0cedc905c8d6 100644
@@ -7,16 +7,6 @@
  * This script controls its layout.
  */
 
-#if defined(BUILD_VDSO64)
-# define SHDR_SIZE 64
-#elif defined(BUILD_VDSO32) || defined(BUILD_VDSOX32)
-# define SHDR_SIZE 40
-#else
-# error unknown VDSO target
-#endif
-
-#define NUM_FAKE_SHDRS 13
-
 SECTIONS
 {
 	/*
@@ -60,20 +50,8 @@ SECTIONS
 		*(.bss*)
 		*(.dynbss*)
 		*(.gnu.linkonce.b.*)
-
-		/*
-		 * Ideally this would live in a C file, but that won't
-		 * work cleanly for x32 until we start building the x32
-		 * C code using an x32 toolchain.
-		 */
-		VDSO_FAKE_SECTION_TABLE_START = .;
-		. = . + NUM_FAKE_SHDRS * SHDR_SIZE;
-		VDSO_FAKE_SECTION_TABLE_END = .;
 	}						:text
 
-	.fake_shstrtab	: { *(.fake_shstrtab) }		:text
-
-
 	.note		: { *(.note.*) }		:text	:note
 
 	.eh_frame_hdr	: { *(.eh_frame_hdr) }		:text	:eh_frame_hdr
arch/x86/entry/vdso/vdso2c.c +0 -8
index 4674f58581a1..8e470b018512 100644
@@ -76,8 +76,6 @@ enum {
 	sym_hpet_page,
 	sym_pvclock_page,
 	sym_hvclock_page,
-	sym_VDSO_FAKE_SECTION_TABLE_START,
-	sym_VDSO_FAKE_SECTION_TABLE_END,
 };
 
 const int special_pages[] = {
@@ -98,12 +96,6 @@ struct vdso_sym required_syms[] = {
 	[sym_hpet_page] = {"hpet_page", true},
 	[sym_pvclock_page] = {"pvclock_page", true},
 	[sym_hvclock_page] = {"hvclock_page", true},
-	[sym_VDSO_FAKE_SECTION_TABLE_START] = {
-		"VDSO_FAKE_SECTION_TABLE_START", false
-	},
-	[sym_VDSO_FAKE_SECTION_TABLE_END] = {
-		"VDSO_FAKE_SECTION_TABLE_END", false
-	},
 	{"VDSO32_NOTE_MASK", true},
 	{"__kernel_vsyscall", true},
 	{"__kernel_sigreturn", true},
Signature · 1 line
2.19.2
maintainer Acked-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] x86/vdso: Remove obsolete "fake section table" reservation

Quoted 15 lines · Sean Christopherson

At one point the vDSO image was manually stripped down by vdso2c in an attempt to minimize the size of the image mapped into userspace. Part of that stripping process involved building a fake section table so as not to break userspace processes that parse the section table. Memory for the fake section table was reserved in the .rodata section so that vdso2c could simply copy the entire PT_LOAD segment into the userspace image after building the fake table.

Eventually, the entire fake section table approach was dropped in favor of stripping the vdso "the old fashioned way", i.e. via objdump -S. But, the reservation in .rodata for the fake table was left behind. Remove the reserveration along with a few other related defines and section entries.

Quoted 4 lines

Removing the fake section table placeholder zaps a whopping 0x340 bytes from the 64-bit vDSO image, which drops the current image's size to under 4k, i.e. reduces the effective size of the userspace vDSO mapping by a full page.

#3 lore raw

[tip:x86/asm] x86/vdso: Remove obsolete "fake section table" reservation

In reply to Sean Christopherson
x86/vdso: Remove obsolete "fake section table" reservation
Commit-ID:  24b7c77bbb24f129beead93574ff248c3db1288e
Gitweb:     https://git.kernel.org/tip/24b7c77bbb24f129beead93574ff248c3db1288e
Author:     Sean Christopherson <[email protected]>
AuthorDate: Tue, 4 Dec 2018 13:25:57 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 5 Dec 2018 08:58:11 +0100

x86/vdso: Remove obsolete "fake section table" reservation

At one point the vDSO image was manually stripped down by vdso2c in an attempt to minimize the size of the image mapped into userspace. Part of that stripping process involved building a fake section table so as not to break userspace processes that parse the section table. Memory for the fake section table was reserved in the .rodata section so that vdso2c could simply copy the entire PT_LOAD segment into the userspace image after building the fake table.

Eventually, the entire fake section table approach was dropped in favor of stripping the vdso "the old fashioned way", i.e. via objdump -S. But, the reservation in .rodata for the fake table was left behind. Remove the reserveration along with a few other related defines and section entries.

Removing the fake section table placeholder zaps a whopping 0x340 bytes from the 64-bit vDSO image, which drops the current image's size to under 4k, i.e. reduces the effective size of the userspace vDSO mapping by a full page.

Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes da861e18eccc ("x86, vdso: Get rid of the fake section mechanism")
---
 arch/x86/entry/vdso/vdso-layout.lds.S | 22 ----------------------
 arch/x86/entry/vdso/vdso2c.c          |  8 --------
 2 files changed, 30 deletions(-)
arch/x86/entry/vdso/vdso-layout.lds.S +0 -22
index acfd5ba7d943..0cedc905c8d6 100644
@@ -7,16 +7,6 @@
  * This script controls its layout.
  */
 
-#if defined(BUILD_VDSO64)
-# define SHDR_SIZE 64
-#elif defined(BUILD_VDSO32) || defined(BUILD_VDSOX32)
-# define SHDR_SIZE 40
-#else
-# error unknown VDSO target
-#endif
-
-#define NUM_FAKE_SHDRS 13
-
 SECTIONS
 {
 	/*
@@ -60,20 +50,8 @@ SECTIONS
 		*(.bss*)
 		*(.dynbss*)
 		*(.gnu.linkonce.b.*)
-
-		/*
-		 * Ideally this would live in a C file, but that won't
-		 * work cleanly for x32 until we start building the x32
-		 * C code using an x32 toolchain.
-		 */
-		VDSO_FAKE_SECTION_TABLE_START = .;
-		. = . + NUM_FAKE_SHDRS * SHDR_SIZE;
-		VDSO_FAKE_SECTION_TABLE_END = .;
 	}						:text
 
-	.fake_shstrtab	: { *(.fake_shstrtab) }		:text
-
-
 	.note		: { *(.note.*) }		:text	:note
 
 	.eh_frame_hdr	: { *(.eh_frame_hdr) }		:text	:eh_frame_hdr
arch/x86/entry/vdso/vdso2c.c +0 -8
index 4674f58581a1..8e470b018512 100644
@@ -76,8 +76,6 @@ enum {
 	sym_hpet_page,
 	sym_pvclock_page,
 	sym_hvclock_page,
-	sym_VDSO_FAKE_SECTION_TABLE_START,
-	sym_VDSO_FAKE_SECTION_TABLE_END,
 };
 
 const int special_pages[] = {
@@ -98,12 +96,6 @@ struct vdso_sym required_syms[] = {
 	[sym_hpet_page] = {"hpet_page", true},
 	[sym_pvclock_page] = {"pvclock_page", true},
 	[sym_hvclock_page] = {"hvclock_page", true},
-	[sym_VDSO_FAKE_SECTION_TABLE_START] = {
-		"VDSO_FAKE_SECTION_TABLE_START", false
-	},
-	[sym_VDSO_FAKE_SECTION_TABLE_END] = {
-		"VDSO_FAKE_SECTION_TABLE_END", false
-	},
 	{"VDSO32_NOTE_MASK", true},
 	{"__kernel_vsyscall", true},
 	{"__kernel_sigreturn", true},
#4 lore raw

PATCH v2 2/4 x86/vdso: Remove a stale/misleading comment from the linker script

In reply to Sean Christopherson

Once upon a time, vdso2c aggressively stripped data from the vDSO image when generating the final userspace image. This included stripping the .altinstructions and .altinstr_replacement sections. Eventually, the stripping process reverted to "objdump -S" and no longer removed the aforementioned sections, but the comment remained.

Keeping the .alt* sections at the end of the PT_LOAD segment is no longer necessary, but there's no harm in doing so and it's a helpful reminder that they don't need to be included in the final vDSO image, i.e. someone may want to take another stab at zapping/stripping the unneeded sections.

Fixes da861e18eccc ("x86, vdso: Get rid of the fake section mechanism")
Cc Andy Lutomirski <[email protected]>
---
 arch/x86/entry/vdso/vdso-layout.lds.S | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/entry/vdso/vdso-layout.lds.S +0 -5
index 0cedc905c8d6..93c6dc7812d0 100644
@@ -65,11 +65,6 @@ SECTIONS
 
 	.text		: { *(.text*) }			:text	=0x90909090,
 
-	/*
-	 * At the end so that eu-elflint stays happy when vdso2c strips
-	 * these.  A better implementation would avoid allocating space
-	 * for these.
-	 */
 	.altinstructions	: { *(.altinstructions) }	:text
 	.altinstr_replacement	: { *(.altinstr_replacement) }	:text
 
Signature · 1 line
2.19.2
maintainer Acked-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] x86/vdso: Remove a stale/misleading comment from the linker script

Quoted 7 lines · Sean Christopherson

Once upon a time, vdso2c aggressively stripped data from the vDSO image when generating the final userspace image. This included stripping the .altinstructions and .altinstr_replacement sections. Eventually, the stripping process reverted to "objdump -S" and no longer removed the aforementioned sections, but the comment remained.

Quoted 5 lines

Keeping the .alt* sections at the end of the PT_LOAD segment is no longer necessary, but there's no harm in doing so and it's a helpful reminder that they don't need to be included in the final vDSO image, i.e. someone may want to take another stab at zapping/stripping the unneeded sections.

#6 lore raw

[tip:x86/asm] x86/vdso: Remove a stale/misleading comment from the linker script

In reply to Sean Christopherson
x86/vdso: Remove a stale/misleading comment from the linker script
Commit-ID:  29434801e7e9c6d05fbea4533b3c0bd6be612f62
Gitweb:     https://git.kernel.org/tip/29434801e7e9c6d05fbea4533b3c0bd6be612f62
Author:     Sean Christopherson <[email protected]>
AuthorDate: Tue, 4 Dec 2018 13:25:58 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 5 Dec 2018 08:58:12 +0100

x86/vdso: Remove a stale/misleading comment from the linker script

Once upon a time, vdso2c aggressively stripped data from the vDSO image when generating the final userspace image. This included stripping the .altinstructions and .altinstr_replacement sections. Eventually, the stripping process reverted to "objdump -S" and no longer removed the aforementioned sections, but the comment remained.

Keeping the .alt* sections at the end of the PT_LOAD segment is no longer necessary, but there's no harm in doing so and it's a helpful reminder that they don't need to be included in the final vDSO image, i.e. someone may want to take another stab at zapping/stripping the unneeded sections.

Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes da861e18eccc ("x86, vdso: Get rid of the fake section mechanism")
---
 arch/x86/entry/vdso/vdso-layout.lds.S | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/entry/vdso/vdso-layout.lds.S +0 -5
index 0cedc905c8d6..93c6dc7812d0 100644
@@ -65,11 +65,6 @@ SECTIONS
 
 	.text		: { *(.text*) }			:text	=0x90909090,
 
-	/*
-	 * At the end so that eu-elflint stays happy when vdso2c strips
-	 * these.  A better implementation would avoid allocating space
-	 * for these.
-	 */
 	.altinstructions	: { *(.altinstructions) }	:text
 	.altinstr_replacement	: { *(.altinstr_replacement) }	:text
 
#7 lore raw

PATCH v2 3/4 x86/vdso: Remove struct vdso_sym and its associated export option

In reply to Sean Christopherson

...now that all required symbols are exported by vdso2c.

---

Regarding Andy's concern that we might want the exported flag in the future for exception fixup, I prototyped a few approaches and in the end we always need to know at least the base of the original extable so that we have an anchor point for the relative IPs. Technically it's possible to omit the length/end, but doing so requires making either vdso2c or the kernel code more complex than it needs to be. So, regardless of whether we use symbols or sections for extable, I'm fairly confident we'll want to export the result to the .c file.

 arch/x86/entry/vdso/vdso2c.c | 27 +++++++++++----------------
 arch/x86/entry/vdso/vdso2c.h | 15 +++++++--------
 2 files changed, 18 insertions(+), 24 deletions(-)
arch/x86/entry/vdso/vdso2c.c +11 -16
index 8e470b018512..a175cd2016c9 100644
@@ -85,22 +85,17 @@ const int special_pages[] = {
 	sym_hvclock_page,
 };
 
-struct vdso_sym {
-	const char *name;
-	bool export;
-};
-
-struct vdso_sym required_syms[] = {
-	[sym_vvar_start] = {"vvar_start", true},
-	[sym_vvar_page] = {"vvar_page", true},
-	[sym_hpet_page] = {"hpet_page", true},
-	[sym_pvclock_page] = {"pvclock_page", true},
-	[sym_hvclock_page] = {"hvclock_page", true},
-	{"VDSO32_NOTE_MASK", true},
-	{"__kernel_vsyscall", true},
-	{"__kernel_sigreturn", true},
-	{"__kernel_rt_sigreturn", true},
-	{"int80_landing_pad", true},
+const char *required_syms[] = {
+	[sym_vvar_start] = "vvar_start",
+	[sym_vvar_page] = "vvar_page",
+	[sym_hpet_page] = "hpet_page",
+	[sym_pvclock_page] = "pvclock_page",
+	[sym_hvclock_page] = "hvclock_page",
+	"VDSO32_NOTE_MASK",
+	"__kernel_vsyscall",
+	"__kernel_sigreturn",
+	"__kernel_rt_sigreturn",
+	"int80_landing_pad",
 };
 
 __attribute__((format(printf, 1, 2))) __attribute__((noreturn))
arch/x86/entry/vdso/vdso2c.h +7 -8
index fa847a620f40..14003d311298 100644
@@ -97,10 +97,10 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 			GET_LE(&sym->st_name);
 
 		for (k = 0; k < NSYMS; k++) {
-			if (!strcmp(name, required_syms[k].name)) {
+			if (!strcmp(name, required_syms[k])) {
 				if (syms[k]) {
 					fail("duplicate symbol %s\n",
-					     required_syms[k].name);
+					     required_syms[k]);
 				}
 
 				/*
@@ -123,13 +123,12 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 
 		if (symval % 4096)
 			fail("%s must be a multiple of 4096\n",
-			     required_syms[i].name);
+			     required_syms[i]);
 		if (symval + 4096 < syms[sym_vvar_start])
-			fail("%s underruns vvar_start\n",
-			     required_syms[i].name);
+			fail("%s underruns vvar_start\n", required_syms[i]);
 		if (symval + 4096 > 0)
 			fail("%s is on the wrong side of the vdso text\n",
-			     required_syms[i].name);
+			     required_syms[i]);
 	}
 	if (syms[sym_vvar_start] % 4096)
 		fail("vvar_begin must be a multiple of 4096\n");
@@ -167,9 +166,9 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 			(unsigned long)GET_LE(&alt_sec->sh_size));
 	}
 	for (i = 0; i < NSYMS; i++) {
-		if (required_syms[i].export && syms[i])
+		if (syms[i])
 			fprintf(outfile, "\t.sym_%s = %" PRIi64 ",\n",
-				required_syms[i].name, (int64_t)syms[i]);
+				required_syms[i], (int64_t)syms[i]);
 	}
 	fprintf(outfile, "};\n");
 }
Signature · 1 line
2.19.2
#8 lore raw

PATCH v2 4/4 x86/vdso: Rename "required_syms" to "requested_syms"

In reply to Sean Christopherson

The "required" moniker implies that vdso2c will fail if one of the defined symbols is not found, which is simply not true, e.g. VDSO32_NOTE_MASK is quite obviously 32-bit only and not required for the 64-bit image.

---
 arch/x86/entry/vdso/vdso2c.c |  4 ++--
 arch/x86/entry/vdso/vdso2c.h | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/entry/vdso/vdso2c.c +2 -2
index a175cd2016c9..b2acdaffc66d 100644
@@ -85,7 +85,7 @@ const int special_pages[] = {
 	sym_hvclock_page,
 };
 
-const char *required_syms[] = {
+const char *requested_syms[] = {
 	[sym_vvar_start] = "vvar_start",
 	[sym_vvar_page] = "vvar_page",
 	[sym_hpet_page] = "hpet_page",
@@ -139,7 +139,7 @@ extern void bad_put_le(void);
 	PLE(x, val, 64, PLE(x, val, 32, PLE(x, val, 16, LAST_PLE(x, val))))
 
 
-#define NSYMS ARRAY_SIZE(required_syms)
+#define NSYMS ARRAY_SIZE(requested_syms)
 
 #define BITSFUNC3(name, bits, suffix) name##bits##suffix
 #define BITSFUNC2(name, bits, suffix) BITSFUNC3(name, bits, suffix)
arch/x86/entry/vdso/vdso2c.h +6 -6
index 14003d311298..6c5a290ce468 100644
@@ -97,10 +97,10 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 			GET_LE(&sym->st_name);
 
 		for (k = 0; k < NSYMS; k++) {
-			if (!strcmp(name, required_syms[k])) {
+			if (!strcmp(name, requested_syms[k])) {
 				if (syms[k]) {
 					fail("duplicate symbol %s\n",
-					     required_syms[k]);
+					     requested_syms[k]);
 				}
 
 				/*
@@ -123,12 +123,12 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 
 		if (symval % 4096)
 			fail("%s must be a multiple of 4096\n",
-			     required_syms[i]);
+			     requested_syms[i]);
 		if (symval + 4096 < syms[sym_vvar_start])
-			fail("%s underruns vvar_start\n", required_syms[i]);
+			fail("%s underruns vvar_start\n", requested_syms[i]);
 		if (symval + 4096 > 0)
 			fail("%s is on the wrong side of the vdso text\n",
-			     required_syms[i]);
+			     requested_syms[i]);
 	}
 	if (syms[sym_vvar_start] % 4096)
 		fail("vvar_begin must be a multiple of 4096\n");
@@ -168,7 +168,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 	for (i = 0; i < NSYMS; i++) {
 		if (syms[i])
 			fprintf(outfile, "\t.sym_%s = %" PRIi64 ",\n",
-				required_syms[i], (int64_t)syms[i]);
+				requested_syms[i], (int64_t)syms[i]);
 	}
 	fprintf(outfile, "};\n");
 }
Signature · 1 line
2.19.2