Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp453219pxb; Thu, 12 Nov 2020 07:49:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyof/uhJMl4BkCb5y0bYz2ny1vdl2VaoMKwJBBybHIgq3Twl2JoM9UPa0mkA7vHWjhxh2Or X-Received: by 2002:a17:906:3b89:: with SMTP id u9mr30297021ejf.436.1605196167025; Thu, 12 Nov 2020 07:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605196167; cv=none; d=google.com; s=arc-20160816; b=FyI8WE8Ychj+IAPPPCMcUAL3QGLev7SZxlQma8Xo9Kb1104AgRC3rVV0vextPL1S6v NAn+5kFO5RuPuyinwN75w3ExCkZwJdBJfGkqB4msDDEHWZH7W+jTHz5nFSHKAWqguPdJ GZLJgSGCnZKK5/U0lAShnwWEFp7w1DZm5JA3L/txEaSLRx9CPQ4OTrvQXtwOnQjnd2oA xiBhQcgtw2sSgeX/6W1L3/6/y3EKXRdCHUYKRD0l3XiFM4a4PmmwmQRAH8E7YmLj85vN cy3bGh0IxYWjtF1Fqv/uFQag0OXvRrcqNpmNmkmorhWmauKcd+ksgvlWIH4PIoQO7kus mvbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=qxjTdSqsz6xIg1WvznsPF+RZUGZ5GXFMr8Y82HN6228=; b=vob0YtdqOOfEtpa3AmjB80s5Cc+6soqhE+Cq7QFmjSAABkKxdF946og7Tqf/FY6n0g WFhK8zCl7an6ssxiyp6RFN37JAE7PpmxzskAYTRTIwmc7ZWXkAzrAjZysDvWpZkpJVKj 1W6VkeEngPpKYVbRU5rtyyfQyQp4sqSaETpFnOoo7WgmRyUrssw3+DeaLZYt0KzA8Cha L9GKcBl7eVtiLva3Z7XDHKfs6pYOME94O3ipITUfHw3FjwQuz8GUih5FO+BM0c9tLpK+ 6Cs8xazDuH4QjCM0uqKAxHGjba/VHeXZIugD6NMrna1AQyD6sN+VUUHg5sDWZqFS3Y55 lhjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I0SZ/ntC"; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd12si3975463edb.382.2020.11.12.07.49.02; Thu, 12 Nov 2020 07:49:27 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I0SZ/ntC"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728696AbgKLPor (ORCPT + 99 others); Thu, 12 Nov 2020 10:44:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38396 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728198AbgKLPor (ORCPT ); Thu, 12 Nov 2020 10:44:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605195885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qxjTdSqsz6xIg1WvznsPF+RZUGZ5GXFMr8Y82HN6228=; b=I0SZ/ntCb+D9zfYo+shM2A6nh7iDqy89a16ox4QkwhYplApxBMuhRbBEZEAYDgb2ElDPLe JV9lBT8eesqQPS3zBrjkiI0dmsl7ReTgkoW+bo3GQmAGKOi+5tqhPcaDxvLXLMrWpEb8kq OsEIAd2kkbnRVCDVFcOjNjw11oOg6vc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-587-OzkiRePrMwy2vZuIWbiV2Q-1; Thu, 12 Nov 2020 10:44:44 -0500 X-MC-Unique: OzkiRePrMwy2vZuIWbiV2Q-1 Received: by mail-wr1-f72.google.com with SMTP id p16so2116859wrx.4 for ; Thu, 12 Nov 2020 07:44:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=qxjTdSqsz6xIg1WvznsPF+RZUGZ5GXFMr8Y82HN6228=; b=Lr0R/rkUmMJA2jab/Fs3CjjdVY/PXXXKLUiaAGnEL+c/M2EUxAJP+qisA98NPNN2mS Mfm3cGKEWiMjXgZsF5P5upRH3+6QY09tEMc4L06tVtTEnTFWbQREfPq6WK7oOjzepvzm 1yRK82oyX/8HJ1ynxMm/2xao3kuv5VDU7gP4ErAGAaBEg0qtoSrRFhSuZhX1YlTy88J/ 4S1TzUbw/lungagrGtoWXOTmR28EzYij6EDiQVTt9cCKEw2fZMiIJh9aUr+RDTX0hP7P ReAryS3U+YWT02usokEnq662urr5PAi1ebW/8eUmjhY0SuJT/QSnQeZkvfE3mAkB91kv 64sw== X-Gm-Message-State: AOAM533+EGxv6i7yJT7km0/69B1FcdosSfwYhjme6lwI1z6I36r1Bv8N 9PVwIXZE5gwivDVkhvKOsyzJtBgNz4UuR9iK3F5e3/MQiJRZaPQKrZ296qsvRGKMr5eNWJYlnby xHg2GtmQaygvv+VoPQrr2vhSg X-Received: by 2002:a7b:c309:: with SMTP id k9mr292680wmj.14.1605195881880; Thu, 12 Nov 2020 07:44:41 -0800 (PST) X-Received: by 2002:a7b:c309:: with SMTP id k9mr292640wmj.14.1605195881639; Thu, 12 Nov 2020 07:44:41 -0800 (PST) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id 34sm7209189wrq.27.2020.11.12.07.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 07:44:41 -0800 (PST) From: Vitaly Kuznetsov To: Wei Liu , Linux on Hyper-V List Cc: virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , Wei Liu , Lillian Grassin-Drake , "K. Y. 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 v2 07/17] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary In-Reply-To: <20201105165814.29233-8-wei.liu@kernel.org> References: <20201105165814.29233-1-wei.liu@kernel.org> <20201105165814.29233-8-wei.liu@kernel.org> Date: Thu, 12 Nov 2020 16:44:39 +0100 Message-ID: <877dqqy3yw.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wei Liu writes: > 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 > --- > arch/x86/hyperv/hv_init.c | 26 ++++++++++++++++++++++++++ > arch/x86/include/asm/mshyperv.h | 2 ++ > include/asm-generic/hyperv-tlfs.h | 6 ++++++ > 3 files changed, 34 insertions(+) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index 7a2e37f025b0..73b0fb851f76 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -30,6 +30,9 @@ > bool hv_root_partition; > EXPORT_SYMBOL_GPL(hv_root_partition); > > +u64 hv_current_partition_id; > +EXPORT_SYMBOL_GPL(hv_current_partition_id); > + > void *hv_hypercall_pg; > EXPORT_SYMBOL_GPL(hv_hypercall_pg); > > @@ -335,6 +338,26 @@ static struct syscore_ops hv_syscore_ops = { > .resume = hv_resume, > }; > > +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) > + pr_err("Failed to get partition ID: %d\n", status); > + else > + hv_current_partition_id = output_page->partition_id; Nit: I'd suggest we simplify this to: if (status != HV_STATUS_SUCCESS) { pr_err("Failed to get partition ID: %d\n", status); BUG(); } hv_current_partition_id = output_page->partition_id; and drop BUG_ON() below; > + local_irq_restore(flags); > + > + /* No point in proceeding if this failed */ > + BUG_ON(status != HV_STATUS_SUCCESS); > +} > + > /* > * This function is to be invoked early in the boot sequence after the > * hypervisor has been detected. > @@ -430,6 +453,9 @@ void __init hyperv_init(void) > > register_syscore_ops(&hv_syscore_ops); > > + if (hv_root_partition) > + hv_get_partition_id(); > + We don't seem to check that the partition has AccessPartitionId privilege. While I guess that root partitions always have it, I'd suggest we write this as: if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID) hv_get_partition_id(); BUG_ON(hv_root_partition && !hv_current_partition_id); for correctness. Also, we need to make sure '0' is not a valid partition id and use e.g. -1 otherwise. > return; > > remove_cpuhp_state: > diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h > index 62d9390f1ddf..67f5d35a73d3 100644 > --- a/arch/x86/include/asm/mshyperv.h > +++ b/arch/x86/include/asm/mshyperv.h > @@ -78,6 +78,8 @@ extern void *hv_hypercall_pg; > extern void __percpu **hyperv_pcpu_input_arg; > extern void __percpu **hyperv_pcpu_output_arg; > > +extern u64 hv_current_partition_id; > + > static inline u64 hv_do_hypercall(u64 control, void *input, void *output) > { > u64 input_address = input ? virt_to_phys(input) : 0; > diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h > index e6903589a82a..87b1a79b19eb 100644 > --- a/include/asm-generic/hyperv-tlfs.h > +++ b/include/asm-generic/hyperv-tlfs.h > @@ -141,6 +141,7 @@ struct ms_hyperv_tsc_page { > #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 > #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014 > #define HVCALL_SEND_IPI_EX 0x0015 > +#define HVCALL_GET_PARTITION_ID 0x0046 > #define HVCALL_GET_VP_REGISTERS 0x0050 > #define HVCALL_SET_VP_REGISTERS 0x0051 > #define HVCALL_POST_MESSAGE 0x005c > @@ -407,6 +408,11 @@ struct hv_tlb_flush_ex { > u64 gva_list[]; > } __packed; > > +/* HvGetPartitionId hypercall (output only) */ > +struct hv_get_partition_id { > + u64 partition_id; > +} __packed; > + > /* HvRetargetDeviceInterrupt hypercall */ > union hv_msi_entry { > u64 as_uint64; -- Vitaly