Skip to contentSkip to conversation

x86/hyperv: Remove hv_vtl_early_init initcall

PATCH Superseded Saurabh Sengar 3 participants 6 messages Sep 20, 2023 – Sep 22, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hyperv: Remove hv_vtl_early_init initcall

There has been cases reported where HYPERV_VTL_MODE is enabled by mistake, on a non Hyper-V platforms. This causes the hv_vtl_early_init function to be called in an non Hyper-V/VTL platforms which results the memory corruption.

Remove the early_initcall for vhv_vtl_early_init and call it at the end of hyperv_init to make sure it is never called in a non Hyper-V platform by mistake.

---
This patch is dependent on :
https://lore.kernel.org/lkml/[email protected]/

 arch/x86/hyperv/hv_init.c       | 3 +++
 arch/x86/hyperv/hv_vtl.c        | 3 +--
 arch/x86/include/asm/mshyperv.h | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/hyperv/hv_init.c +3 -0
index f0128fd4031d..608f4fe41fb7 100644
@@ -610,6 +610,9 @@ void __init hyperv_init(void)
 	/* Find the VTL */
 	ms_hyperv.vtl = get_vtl();
 
+	if (ms_hyperv.vtl > 0) /* non default VTL */
+		hv_vtl_early_init();
+
 	return;
 
 clean_guest_os_id:
arch/x86/hyperv/hv_vtl.c +1 -2
index 36a562218010..999f5ac82fe9 100644
@@ -215,7 +215,7 @@ static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip)
 	return hv_vtl_bringup_vcpu(vp_id, start_eip);
 }
 
-static int __init hv_vtl_early_init(void)
+int __init hv_vtl_early_init(void)
 {
 	/*
 	 * `boot_cpu_has` returns the runtime feature support,
@@ -230,4 +230,3 @@ static int __init hv_vtl_early_init(void)
 
 	return 0;
 }
-early_initcall(hv_vtl_early_init);
arch/x86/include/asm/mshyperv.h +2 -0
index 033b53f993c6..83019c3aaae9 100644
@@ -340,8 +340,10 @@ static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; }
 
 #ifdef CONFIG_HYPERV_VTL_MODE
 void __init hv_vtl_init_platform(void);
+int __init hv_vtl_early_init(void);
 #else
 static inline void __init hv_vtl_init_platform(void) {}
+static int __init hv_vtl_early_init(void) {}
 #endif
 
 #include <asm-generic/mshyperv.h>
Signature · 1 line
2.34.1
#1 lore raw
:::::: :::::: Manual check reason: "git am base is a link in commit message" ::::::

::::::
:::::: Manual check reason: "git am base is a link in commit message" ::::::

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Saurabh Sengar <[email protected]>
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
CC: [email protected]
CC: [email protected]

Hi Saurabh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.6-rc2]
[also build test WARNING on linus/master next-20230920] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Saurabh-Sengar/x86-hyperv-Remove-hv_vtl_early_init-initcall/20230920-125357
base:   v6.6-rc2
patch link:    https://lore.kernel.org/r/1695185552-19910-1-git-send-email-ssengar%40linux.microsoft.com
patch subject: [PATCH] x86/hyperv: Remove hv_vtl_early_init initcall

:::::: branch date: 59 minutes ago
:::::: commit date: 59 minutes ago
config: i386-tinyconfig (https://download.01.org/0day-ci/archive/20230920/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230920/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

All warnings (new ones prefixed by >>):

In file included from arch/x86/mm/pat/set_memory.c:36:
arch/x86/include/asm/mshyperv.h: In function 'hv_vtl_early_init':
arch/x86/include/asm/mshyperv.h:346:1: error: no return statement in function returning non-void [-Werror=return-type]

     346 | static int __init hv_vtl_early_init(void) {}
         | ^~~~~~
   arch/x86/include/asm/mshyperv.h: At top level:
>> arch/x86/include/asm/mshyperv.h:346:19: warning: 'hv_vtl_early_init' defined but not used [-Wunused-function]
     346 | static int __init hv_vtl_early_init(void) {}
         |                   ^~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/hv_vtl_early_init +346 arch/x86/include/asm/mshyperv.h

79cadff2d92bb8 Vitaly Kuznetsov 2017-08-02  339  
765e33f5211ab6 Michael Kelley   2019-05-30  340  
3be1bc2fe9d2e4 Saurabh Sengar   2023-04-10  341  #ifdef CONFIG_HYPERV_VTL_MODE
3be1bc2fe9d2e4 Saurabh Sengar   2023-04-10  342  void __init hv_vtl_init_platform(void);
9081cfc5d0e7fa Saurabh Sengar   2023-09-19  343  int __init hv_vtl_early_init(void);
3be1bc2fe9d2e4 Saurabh Sengar   2023-04-10  344  #else
3be1bc2fe9d2e4 Saurabh Sengar   2023-04-10  345  static inline void __init hv_vtl_init_platform(void) {}
9081cfc5d0e7fa Saurabh Sengar   2023-09-19 @346  static int __init hv_vtl_early_init(void) {}
3be1bc2fe9d2e4 Saurabh Sengar   2023-04-10  347  #endif
3be1bc2fe9d2e4 Saurabh Sengar   2023-04-10  348  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Mathias Krause
Quoted 7 lines · Mathias Krause
Quoted 6 lines · Saurabh Sengar

There has been cases reported where HYPERV_VTL_MODE is enabled by mistake, on a non Hyper-V platforms. This causes the hv_vtl_early_init function to be called in an non Hyper-V/VTL platforms which results the memory corruption.

Remove the early_initcall for vhv_vtl_early_init and call it at the end of

vhv_vtl_early_init need to be replaced with hv_vtl_early_init here.

Wei,

Do you need a V2 for it ?

- Saurabh

#4 lore raw
In reply to Saurabh Sengar

Missed it in my review, but the kernel bot already noticed it, so....

arch/x86/include/asm/mshyperv.h static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } · line 346

Quoted 13 lines · Saurabh Sengar

[...]

arch/x86/include/asm/mshyperv.h +2 -0
index 033b53f993c6..83019c3aaae9 100644
@@ -340,8 +340,10 @@ static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; }
 
 #ifdef CONFIG_HYPERV_VTL_MODE
 void __init hv_vtl_init_platform(void);
+int __init hv_vtl_early_init(void);
 #else
 static inline void __init hv_vtl_init_platform(void) {}
+static int __init hv_vtl_early_init(void) {}

static inline

arch/x86/include/asm/mshyperv.h static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } · line 349

Quoted 3 lines
arch/x86/include/asm/mshyperv.h +0 -0
 #endif
 
 #include <asm-generic/mshyperv.h>

Thanks,
Mathias

Acked-by on v1 1/1
#2 lore raw
In reply to Saurabh Sengar
Quoted 26 lines · Saurabh Sengar

There has been cases reported where HYPERV_VTL_MODE is enabled by mistake, on a non Hyper-V platforms. This causes the hv_vtl_early_init function to be called in an non Hyper-V/VTL platforms which results the memory corruption.

Remove the early_initcall for vhv_vtl_early_init and call it at the end of hyperv_init to make sure it is never called in a non Hyper-V platform by mistake.

---
This patch is dependent on :
https://lore.kernel.org/lkml/[email protected]/

 arch/x86/hyperv/hv_init.c       | 3 +++
 arch/x86/hyperv/hv_vtl.c        | 3 +--
 arch/x86/include/asm/mshyperv.h | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/hyperv/hv_init.c +0 -0
index f0128fd4031d..608f4fe41fb7 100644

arch/x86/hyperv/hv_init.c void __init hyperv_init(void) · line 615

Quoted 6 lines
arch/x86/hyperv/hv_init.c +3 -0
@@ -610,6 +610,9 @@ void __init hyperv_init(void)
 	/* Find the VTL */
 	ms_hyperv.vtl = get_vtl();
 
+	if (ms_hyperv.vtl > 0) /* non default VTL */
+		hv_vtl_early_init();
+

As the kernel's console will already be initialized when this code gets executed, the possible panic() in hv_vtl_early_init() will actually be visible, thereby...

Quoted 26 lines
arch/x86/hyperv/hv_init.c +0 -0
 	return;
 
 clean_guest_os_id:
arch/x86/hyperv/hv_vtl.c +1 -2
index 36a562218010..999f5ac82fe9 100644
@@ -215,7 +215,7 @@ static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip)
 	return hv_vtl_bringup_vcpu(vp_id, start_eip);
 }
 
-static int __init hv_vtl_early_init(void)
+int __init hv_vtl_early_init(void)
 {
 	/*
 	 * `boot_cpu_has` returns the runtime feature support,
@@ -230,4 +230,3 @@ static int __init hv_vtl_early_init(void)
 
 	return 0;
 }
-early_initcall(hv_vtl_early_init);
arch/x86/include/asm/mshyperv.h +0 -0
index 033b53f993c6..83019c3aaae9 100644

arch/x86/include/asm/mshyperv.h static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } · line 349

Quoted 10 lines
arch/x86/include/asm/mshyperv.h +2 -0
@@ -340,8 +340,10 @@ static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; }
 
 #ifdef CONFIG_HYPERV_VTL_MODE
 void __init hv_vtl_init_platform(void);
+int __init hv_vtl_early_init(void);
 #else
 static inline void __init hv_vtl_init_platform(void) {}
+static int __init hv_vtl_early_init(void) {}
 #endif
 
 #include <asm-generic/mshyperv.h>

Thanks!

#5 lore raw
In reply to Mathias Krause
Quoted 10 lines · Mathias Krause

Missed it in my review, but the kernel bot already noticed it, so....

Quoted 7 lines · Saurabh Sengar

[...]

arch/x86/include/asm/mshyperv.h +0 -0
index 033b53f993c6..83019c3aaae9 100644
@@ -340,8 +340,10 @@ static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; }
 
Quoted 8 lines

arch/x86/include/asm/mshyperv.h static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } · line 346

Quoted 6 lines
arch/x86/include/asm/mshyperv.h +2 -0
 #ifdef CONFIG_HYPERV_VTL_MODE
 void __init hv_vtl_init_platform(void);
+int __init hv_vtl_early_init(void);
 #else
 static inline void __init hv_vtl_init_platform(void) {}
+static int __init hv_vtl_early_init(void) {}

static inline

Thanks, will send v2 fixing this and the other typo in commit

Regards,
Saurabh

Quoted 7 lines

arch/x86/include/asm/mshyperv.h static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } · line 349

Quoted 4 lines
arch/x86/include/asm/mshyperv.h +0 -0
 #endif
 
 #include <asm-generic/mshyperv.h>

Thanks,
Mathias