Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp656059pxb; Tue, 2 Feb 2021 14:33:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyV3Pk+LeUmf01b+SouI2bCh7TnBhCoYqpHHF5zFJzieMEyDBjb+9TOic4bWrUbJNjHZFgj X-Received: by 2002:a17:906:9619:: with SMTP id s25mr176130ejx.345.1612305194428; Tue, 02 Feb 2021 14:33:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612305194; cv=none; d=google.com; s=arc-20160816; b=k7u06YDPQlk7YAdafDVZnhVD8U+qXmjc4PI2+Z43PjyJlVUc5QwczUYQlYqVWvd3oj vTPYsC5iky9jjgEEdBjCY4OXB/j8mUm1BB9XqhhPY+NHKKswyL7y4dqrN6GT7/p+kONO HyzI/w9ARjGbyeccE0LIdmITnvUF1cDW5aAggR5ipgfIpRLKQoKL2xwlspyoEgneB1e9 Nn6J8wMN+G6ojRxLpo4Va9Sq9+KD0CoqI9CFSRz0YhUuVv/SKB0WMjaE3vEGKYKndUlQ c+kkj5NVcA6R2AjSrmnJnM+JCfYOyFnK99x4SNahjL9zwgOg/rRAazjaZGm2bPZVKDVj dB3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=iVYfyMGBBAdTwlcTSqM4uE3+4I43aqu6Fgew0A9CUJo=; b=GrdYfvwR3eYN3YkFNBeXvVLCBtiY9hMrOl//zWMQ4xSXN2ulhl+MqnMkF3Syim2c0X 3BP/GVNAPJSmYUgB/SERc+zBzxtUq6OuOC+pRQ+xf+0f/s4ujMW3E0wTyd/o8ShHTJON h0wv3MWq7Cm4se5GMUe7E4aZbXIFlbhoxsCpYp6dh5xQ8LvDp56i/PnpgkqIspOn8Sz9 GRTGT3f2Jxv/Wi6j6ZgMrnIuxuBgfQuV//Xx4bQoU22I/gplB6Lx+fd7fQ2sX40SW2nz FEGV1YRQi3WVyZGVPYEThwZZPfsHgj5YEDecGX5QKq/wgKpknJCfGz5cbke5wY5UXlzG Z4bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx15si120088ejc.300.2021.02.02.14.32.48; Tue, 02 Feb 2021 14:33:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234805AbhBBPF4 (ORCPT + 99 others); Tue, 2 Feb 2021 10:05:56 -0500 Received: from mail-wr1-f46.google.com ([209.85.221.46]:36517 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234936AbhBBPEj (ORCPT ); Tue, 2 Feb 2021 10:04:39 -0500 Received: by mail-wr1-f46.google.com with SMTP id 6so20813460wri.3; Tue, 02 Feb 2021 07:04:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=iVYfyMGBBAdTwlcTSqM4uE3+4I43aqu6Fgew0A9CUJo=; b=mFab0TAT4rf17zoJsCwDhYWKGjt2vNQnR4sUsVBV8kINshGedIeHKsjONAL79j+bj3 zUJMRcw4e0bZeteVcC8nZfr6/YQOpgf0Rk3s/pbKopV1EFZb3r2X7bH4jTXLaZ8p1TLi jmQmpaChKuPFzq4c4o1QvbSGwNMoTBuMGrUD5lN6aXVpVQWRH5YVQXNfvjWEmsfNK7XH +WWfTawVzwslAv/O3AAt+bcG0uvUdln19rf1UzCE3+r3pbOFCxbwzlCn2IL4bXMjHuz2 tSQrf0o0BkmBqxkHpZrKI59x6lTFp64aS6d0+8E6v1ujRASd1H6XVjG0xi1DC74q4qEU MFLg== X-Gm-Message-State: AOAM5327wX+UXrMKyGmd1SxPnYrFUtyoYMId1o9K4Z7r+oOdAAqVfXXC 2U1ca5KEv00d9o8sw+qZVD8= X-Received: by 2002:adf:f183:: with SMTP id h3mr24722949wro.30.1612278236320; Tue, 02 Feb 2021 07:03:56 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id r13sm3840262wmh.9.2021.02.02.07.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 07:03:55 -0800 (PST) Date: Tue, 2 Feb 2021 15:03:53 +0000 From: Wei Liu To: Michael Kelley Cc: Wei Liu , Linux on Hyper-V List , "virtualization@lists.linux-foundation.org" , Linux Kernel List , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , "pasha.tatashin@soleen.com" , Lillian Grassin-Drake , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Arnd Bergmann , "open list:GENERIC INCLUDE/ASM HEADER FILES" Subject: Re: [PATCH v5 07/16] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary Message-ID: <20210202150353.6npksy7tobrvfqlt@liuwe-devbox-debian-v2> References: <20210120120058.29138-1-wei.liu@kernel.org> <20210120120058.29138-8-wei.liu@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 26, 2021 at 12:48:37AM +0000, Michael Kelley wrote: > From: Wei Liu Sent: Wednesday, January 20, 2021 4:01 AM > > > > We will need the partition ID for executing some hypercalls later. > > > > Signed-off-by: Lillian Grassin-Drake > > Co-Developed-by: Sunil Muthuswamy > > Signed-off-by: Wei Liu > > --- > > v3: > > 1. Make hv_get_partition_id static. > > 2. Change code structure a bit. > > --- > > arch/x86/hyperv/hv_init.c | 27 +++++++++++++++++++++++++++ > > arch/x86/include/asm/mshyperv.h | 2 ++ > > include/asm-generic/hyperv-tlfs.h | 6 ++++++ > > 3 files changed, 35 insertions(+) > > > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > > index 6f4cb40e53fe..fc9941bd8653 100644 > > --- a/arch/x86/hyperv/hv_init.c > > +++ b/arch/x86/hyperv/hv_init.c > > @@ -26,6 +26,9 @@ > > #include > > #include > > > > +u64 hv_current_partition_id = ~0ull; > > +EXPORT_SYMBOL_GPL(hv_current_partition_id); > > + > > void *hv_hypercall_pg; > > EXPORT_SYMBOL_GPL(hv_hypercall_pg); > > > > @@ -331,6 +334,25 @@ static struct syscore_ops hv_syscore_ops = { > > .resume = hv_resume, > > }; > > > > +static void __init hv_get_partition_id(void) > > +{ > > + struct hv_get_partition_id *output_page; > > + u16 status; > > + unsigned long flags; > > + > > + local_irq_save(flags); > > + output_page = *this_cpu_ptr(hyperv_pcpu_output_arg); > > + status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page) & > > + HV_HYPERCALL_RESULT_MASK; > > + if (status != HV_STATUS_SUCCESS) { > > Across the Hyper-V code in Linux, the way we check the hypercall result > is very inconsistent. IMHO, the and'ing of hv_do_hypercall() with > HV_HYPERCALL_RESULT_MASK so that status can be a u16 is stylistically > a bit unusual. > > I'd like to see the hypercall result being stored into a u64 local variable. > Then the subsequent test for the status should 'and' the u64 with > HV_HYPERCALL_RESULT_MASK to determine the result code. > I've made a note to go fix the places that aren't doing it that way. > I will fold in the following diff in the next version. I will also check if there are other instances in this patch series that need fixing. Pretty sure there are a few. diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index fc9941bd8653..6064f64a1295 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -337,14 +337,13 @@ static struct syscore_ops hv_syscore_ops = { static void __init hv_get_partition_id(void) { struct hv_get_partition_id *output_page; - u16 status; + u64 status; unsigned long flags; local_irq_save(flags); output_page = *this_cpu_ptr(hyperv_pcpu_output_arg); - status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page) & - HV_HYPERCALL_RESULT_MASK; - if (status != HV_STATUS_SUCCESS) { + status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page); + if ((status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS) { /* No point in proceeding if this failed */ pr_err("Failed to get partition ID: %d\n", status); BUG(); > > + /* No point in proceeding if this failed */ > > + pr_err("Failed to get partition ID: %d\n", status); > > + BUG(); > > + } > > + hv_current_partition_id = output_page->partition_id; > > + local_irq_restore(flags); > > +} > > + > > /* > > * This function is to be invoked early in the boot sequence after the > > * hypervisor has been detected. > > @@ -426,6 +448,11 @@ void __init hyperv_init(void) > > > > register_syscore_ops(&hv_syscore_ops); > > > > + if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID) > > + hv_get_partition_id(); > > Another place where the EBX value saved into the ms_hyperv structure > could be used. If you're okay with my response earlier, this will be handled later in another patch (series). Wei.