git: 205821a70ddd - main - kernel linker: Eliminate unneeded vnet propagation

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Sat, 09 Sep 2023 08:21:16 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=205821a70dddfa106f6792e95693f411e8ce52d4

commit 205821a70dddfa106f6792e95693f411e8ce52d4
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-09-09 08:06:23 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-09-09 08:06:24 +0000

    kernel linker: Eliminate unneeded vnet propagation
    
    The module preload happens before vnet0 creation, at this moment the vnet
    list is empty thus invoking vnet_data_copy() during preload is a noop.
    
    With recent change 110113bc086f, for dynamic module load, aka via kldload,
    linker will do vnet propagation right after registering sysctls which
    happens after module load, then previous propagation (during module load)
    is redundant.
    
    No functional change intended.
    
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D39852
---
 sys/kern/link_elf.c     |  2 +-
 sys/kern/link_elf_obj.c | 10 +---------
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c
index 3e9998f27baa..568f1e1dbd95 100644
--- a/sys/kern/link_elf.c
+++ b/sys/kern/link_elf.c
@@ -724,6 +724,7 @@ parse_vnet(elf_file_t ef)
 
 	ef->vnet_start = 0;
 	ef->vnet_stop = 0;
+	ef->vnet_base = 0;
 	error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start,
 	    (void ***)&ef->vnet_stop, NULL);
 	/* Error just means there is no vnet data set to relocate. */
@@ -766,7 +767,6 @@ parse_vnet(elf_file_t ef)
 		return (ENOSPC);
 	}
 	memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, size);
-	vnet_data_copy((void *)ef->vnet_base, size);
 	elf_set_add(&set_vnet_list, ef->vnet_start, ef->vnet_stop,
 	    ef->vnet_base);
 
diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c
index 768808d2102e..d4ad963e8181 100644
--- a/sys/kern/link_elf_obj.c
+++ b/sys/kern/link_elf_obj.c
@@ -546,7 +546,6 @@ link_elf_link_preload(linker_class_t cls, const char *filename,
 				}
 				memcpy(vnet_data, ef->progtab[pb].addr,
 				    ef->progtab[pb].size);
-				vnet_data_copy(vnet_data, shdr[i].sh_size);
 				ef->progtab[pb].addr = vnet_data;
 #endif
 			} else if ((ef->progtab[pb].name != NULL &&
@@ -1113,18 +1112,11 @@ link_elf_load_file(linker_class_t cls, const char *filename,
 					error = EINVAL;
 					goto out;
 				}
-				/* Initialize the per-cpu or vnet area. */
+				/* Initialize the per-cpu area. */
 				if (ef->progtab[pb].addr != (void *)mapbase &&
 				    !strcmp(ef->progtab[pb].name, DPCPU_SETNAME))
 					dpcpu_copy(ef->progtab[pb].addr,
 					    shdr[i].sh_size);
-#ifdef VIMAGE
-				else if (ef->progtab[pb].addr !=
-				    (void *)mapbase &&
-				    !strcmp(ef->progtab[pb].name, VNET_SETNAME))
-					vnet_data_copy(ef->progtab[pb].addr,
-					    shdr[i].sh_size);
-#endif
 			} else
 				bzero(ef->progtab[pb].addr, shdr[i].sh_size);