linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5] hyperv: simplify and rename generate_guest_id
@ 2022-09-27  7:45 Li kunyu
  2022-09-27 21:08 ` Michael Kelley (LINUX)
  0 siblings, 1 reply; 2+ messages in thread
From: Li kunyu @ 2022-09-27  7:45 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, catalin.marinas, will,
	tglx, mingo, bp, dave.hansen, hpa, arnd
  Cc: x86, linux-hyperv, linux-arm-kernel, linux-kernel, linux-arch, Li kunyu

The generate_guest_id function is more suitable for use after the
following modifications.
1. Modify the type of the guest_id variable to u64, which is compatible
with the caller.
2. Remove all parameters from the function, and write the parameter
(LINUX_VERSION_CODE) passed in by the actual call into the function
implementation.
3. Rename the function to make it clearly a Hyper-V related function,
and modify it to hv_generate_guest_id.

Signed-off-by: Li kunyu <kunyu@nfschina.com>

--------
 v2: Fix generate_guest_id to hv_generate_guest_id.
 v3: Fix [PATCH v2] asm-generic: Remove the ... to [PATCH v3] hyperv: simp
     lify ... and remove extra spaces
 v4: Remove #include <linux/version.h> in the calling file, and add #inclu
     de <linux/version.h> in the function implementation file
 v5: <linux/version.h> is changed to the definition position before v4, an
     d the LINUX_VERSION_CODE macro is passed in the function call
---
 arch/arm64/hyperv/mshyperv.c   | 2 +-
 arch/x86/hyperv/hv_init.c      | 2 +-
 include/asm-generic/mshyperv.h | 9 +++------
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c
index bbbe351e9045..a406454578f0 100644
--- a/arch/arm64/hyperv/mshyperv.c
+++ b/arch/arm64/hyperv/mshyperv.c
@@ -38,7 +38,7 @@ static int __init hyperv_init(void)
 		return 0;
 
 	/* Setup the guest ID */
-	guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
+	guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
 	hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id);
 
 	/* Get the features and hints from Hyper-V */
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 3de6d8b53367..032d85ac33fa 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -426,7 +426,7 @@ void __init hyperv_init(void)
 	 * 1. Register the guest ID
 	 * 2. Enable the hypercall and register the hypercall page
 	 */
-	guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
+	guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
 
 	/* Hyper-V requires to write guest os id via ghcb in SNP IVM. */
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index c05d2ce9b6cd..bfb9eb9d7215 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -105,15 +105,12 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16 rep_count, u16 varhead_size,
 }
 
 /* Generate the guest OS identifier as described in the Hyper-V TLFS */
-static inline  __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,
-				       __u64 d_info2)
+static inline u64 hv_generate_guest_id(u64 kernel_version)
 {
-	__u64 guest_id = 0;
+	u64 guest_id;
 
-	guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48);
-	guest_id |= (d_info1 << 48);
+	guest_id = (((u64)HV_LINUX_VENDOR_ID) << 48);
 	guest_id |= (kernel_version << 16);
-	guest_id |= d_info2;
 
 	return guest_id;
 }
-- 
2.18.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH v5] hyperv: simplify and rename generate_guest_id
  2022-09-27  7:45 [PATCH v5] hyperv: simplify and rename generate_guest_id Li kunyu
@ 2022-09-27 21:08 ` Michael Kelley (LINUX)
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kelley (LINUX) @ 2022-09-27 21:08 UTC (permalink / raw)
  To: Li kunyu, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, catalin.marinas, will, tglx, mingo, bp,
	dave.hansen, hpa, arnd
  Cc: x86, linux-hyperv, linux-arm-kernel, linux-kernel, linux-arch

From: Li kunyu <kunyu@nfschina.com> Sent: Tuesday, September 27, 2022 12:46 AM
> 
> The generate_guest_id function is more suitable for use after the
> following modifications.
> 1. Modify the type of the guest_id variable to u64, which is compatible
> with the caller.
> 2. Remove all parameters from the function, and write the parameter
> (LINUX_VERSION_CODE) passed in by the actual call into the function
> implementation.

The above statement is no longer true.

> 3. Rename the function to make it clearly a Hyper-V related function,
> and modify it to hv_generate_guest_id.
> 
> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> 
> --------
>  v2: Fix generate_guest_id to hv_generate_guest_id.
>  v3: Fix [PATCH v2] asm-generic: Remove the ... to [PATCH v3] hyperv: simp
>      lify ... and remove extra spaces
>  v4: Remove #include <linux/version.h> in the calling file, and add #inclu
>      de <linux/version.h> in the function implementation file
>  v5: <linux/version.h> is changed to the definition position before v4, an
>      d the LINUX_VERSION_CODE macro is passed in the function call
> ---
>  arch/arm64/hyperv/mshyperv.c   | 2 +-
>  arch/x86/hyperv/hv_init.c      | 2 +-
>  include/asm-generic/mshyperv.h | 9 +++------
>  3 files changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c
> index bbbe351e9045..a406454578f0 100644
> --- a/arch/arm64/hyperv/mshyperv.c
> +++ b/arch/arm64/hyperv/mshyperv.c
> @@ -38,7 +38,7 @@ static int __init hyperv_init(void)
>  		return 0;
> 
>  	/* Setup the guest ID */
> -	guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
> +	guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
>  	hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id);
> 
>  	/* Get the features and hints from Hyper-V */
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index 3de6d8b53367..032d85ac33fa 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -426,7 +426,7 @@ void __init hyperv_init(void)
>  	 * 1. Register the guest ID
>  	 * 2. Enable the hypercall and register the hypercall page
>  	 */
> -	guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
> +	guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
>  	wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
> 
>  	/* Hyper-V requires to write guest os id via ghcb in SNP IVM. */
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index c05d2ce9b6cd..bfb9eb9d7215 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -105,15 +105,12 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16
> rep_count, u16 varhead_size,
>  }
> 
>  /* Generate the guest OS identifier as described in the Hyper-V TLFS */
> -static inline  __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,
> -				       __u64 d_info2)
> +static inline u64 hv_generate_guest_id(u64 kernel_version)
>  {
> -	__u64 guest_id = 0;
> +	u64 guest_id;
> 
> -	guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48);
> -	guest_id |= (d_info1 << 48);
> +	guest_id = (((u64)HV_LINUX_VENDOR_ID) << 48);
>  	guest_id |= (kernel_version << 16);
> -	guest_id |= d_info2;
> 
>  	return guest_id;
>  }
> --
> 2.18.2

I'm good with the code.  Thanks for taking into the account the input
from Olaf Hering.  But per my comment above, the commit message
needs to be updated to reflect this last change.

Michael


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-27 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27  7:45 [PATCH v5] hyperv: simplify and rename generate_guest_id Li kunyu
2022-09-27 21:08 ` Michael Kelley (LINUX)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).