From patchwork Fri Sep 23 11:42:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 12986483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45A46C6FA82 for ; Fri, 23 Sep 2022 11:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=WqspjrLSwrIzccgTAlk3g7J+StLBEvoOslw/nVgKcss=; b=Eg3PbRQ+En5lc2 gKPGZH1QgsVTcqKqY5/SAoEpVfessJKr2uLj4GjMNsZ6HPSMkAcCEwM8ZJ36W5FaqrAkluLWK/nc7 Nd2wwUkNWRQcCj1I0aVMKS6cOociC/fagqUMAIjxaMQXPDFsy75RC348sKb/L68fKQxd5UTdbBSHR ayEOjwqvy6iKd9Ftda2LI32r9ixKiBkYdfPs7fVycic3KLe5YqtqnwGvQcxeIox8MFrt/7BjaPA1L DswZ/LiBMaFdB2jk0zfKq/nmxFe/ROf4vU1GSi7LIXXWggAEaFPhsUzljQYsKEUSh/tnceiqwGaKx KOZJxwPiNnBry7thJ36g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obh5R-003zlF-Us; Fri, 23 Sep 2022 11:43:18 +0000 Received: from mail.nfschina.com ([124.16.136.209]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obh5N-003zjG-KP for linux-arm-kernel@lists.infradead.org; Fri, 23 Sep 2022 11:43:16 +0000 Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 0A00B1E80D97; Fri, 23 Sep 2022 19:39:36 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0Jz4Zr8rHdcv; Fri, 23 Sep 2022 19:39:33 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id BDBB11E80D94; Fri, 23 Sep 2022 19:39:31 +0800 (CST) From: Li kunyu To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Li kunyu Subject: [PATCH v3] hyperv: simplify and rename generate_guest_id Date: Fri, 23 Sep 2022 19:42:59 +0800 Message-Id: <20220923114259.2945-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220923_044314_066673_3FD627E3 X-CRM114-Status: GOOD ( 12.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 -------- 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 --- arch/arm64/hyperv/mshyperv.c | 2 +- arch/x86/hyperv/hv_init.c | 2 +- include/asm-generic/mshyperv.h | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index bbbe351e9045..3863fd226e0e 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(); 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..93770791b858 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(); 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..7f4a23cee56f 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -25,6 +25,7 @@ #include #include #include +#include struct ms_hyperv_info { u32 features; @@ -105,15 +106,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(void) { - __u64 guest_id = 0; + u64 guest_id; - guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48); - guest_id |= (d_info1 << 48); - guest_id |= (kernel_version << 16); - guest_id |= d_info2; + guest_id = (((u64)HV_LINUX_VENDOR_ID) << 48); + guest_id |= (((u64)LINUX_VERSION_CODE) << 16); return guest_id; }