Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1229363pxb; Fri, 13 Nov 2020 07:25:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPRwlXuTQlwBDr2mKT6qfb7yv9ksEnHGoSsqJG03NN7yukPznpDuK2A/0eeWJLe+b0Lp/K X-Received: by 2002:a05:6402:1155:: with SMTP id g21mr2959892edw.53.1605281126911; Fri, 13 Nov 2020 07:25:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605281126; cv=none; d=google.com; s=arc-20160816; b=MmA4k578oLSFMRlQIM9dxgdWlqrxDambzZr1I/3CJZBwtRlwXzXyRwiMSXm7nC8Gqs jEn6AhOB7mC2Mmk/UnKOuKas630GYloAvWITF3w/kFjGd68Hx13Pz/eDyV47PViKsGi9 1KW+zSHPb2ivqUuYgwrqXc19AQnmfVPsA3lC7YIB54+LdQBGTd53qawefrs7yhtU/Zur HNEWpXRptS9xkI5M87e8b6xk4mQMNXRRtlS7R/wFbv1P19nkGIWAh8tWpFC8RVqEPNVv kFO+I4ygYbUmYjiQ3nV/+DQbQ1L5HK8SWdCrmpZbSviEWCV2T6lGQyhG/hDSBiUV353p 3uwA== 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=jZZec1UP1XPcIdy5fKYFw1mzad8DvYZuIK/MWVjeSRM=; b=NyLjcq6jSxeNjFl2DZZ5OLV9BlfoKD7J2cbS65tGw12kDBOXg0dIh41A/HYxm9u582 RzajWpzFDiALSbA9ejiVByt07qg123x+L9/iRySzdcD/X38/W9heFlWG33i1DtceylZX 2fNLOoMC25bZF0MwHLroyB/RIYejUobwksEE5p8ZmvyMonPpXJyKcAHtCofniIZNDQ1U ga4TjA3rjS7o0RBVGcuPokwLzISgrc6aPiAFKboz1FbRrz4zVjjbcKRhexn7TA63BTk0 BbANXfVSvIdj8qAGi7/XBqxvTxoTSzZxHLY0KBYKzLMWnOr8gVRjoaXqc2EsFNe7XJOP IbvA== 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 v7si8821688edj.402.2020.11.13.07.25.04; Fri, 13 Nov 2020 07:25:26 -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 S1726899AbgKMPWA (ORCPT + 99 others); Fri, 13 Nov 2020 10:22:00 -0500 Received: from mail-wr1-f51.google.com ([209.85.221.51]:35887 "EHLO mail-wr1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbgKMPV7 (ORCPT ); Fri, 13 Nov 2020 10:21:59 -0500 Received: by mail-wr1-f51.google.com with SMTP id j7so10324181wrp.3; Fri, 13 Nov 2020 07:21:58 -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=jZZec1UP1XPcIdy5fKYFw1mzad8DvYZuIK/MWVjeSRM=; b=KmL9sj03sEWqqN6nS0jNLOulUUGm4URpZlB5CxQ4r/FAlHcSKxV95Q1hVldHBxoyaG 2p6h5fCC2+6ihK2TYtyABFqVj278YRSEVnVdPQyMYFSeNRhXRSMNO1K9S1aK9HU/A1JH 3Xnzz9O2DHIO6oRPieCI0oYD1704mAHPcKyTl2UTwURhGjx2Oc9zqMN6NkNv62PbzYX6 o/GrY5geSuEXBiVePoPrtstgBuLBWa0v7lIMdWIGcqTxhVbIq4pDihyfgl+kWRn/IIXl SSEpW6T1HJkMMutnNclfRGQKxsDSJeVzc7+RuKZY6jvM8pgUC4ABU2z4K8n9skLnCBN+ 7lMA== X-Gm-Message-State: AOAM532orn0zZugeB4FMXHFVzNwIDEFO6FQnyBGEcqL1IprjamhguE5p ETvSx6/xZRZFaqfH62+1P54= X-Received: by 2002:a5d:4b8f:: with SMTP id b15mr4384031wrt.38.1605280914863; Fri, 13 Nov 2020 07:21:54 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id m20sm13924160wrg.81.2020.11.13.07.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 07:21:54 -0800 (PST) Date: Fri, 13 Nov 2020 15:21:52 +0000 From: Wei Liu To: Vitaly Kuznetsov Cc: Wei Liu , Linux on Hyper-V List , virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , 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 Message-ID: <20201113152152.omo6pljscvlrzpsc@liuwe-devbox-debian-v2> References: <20201105165814.29233-1-wei.liu@kernel.org> <20201105165814.29233-8-wei.liu@kernel.org> <877dqqy3yw.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877dqqy3yw.fsf@vitty.brq.redhat.com> User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 12, 2020 at 04:44:39PM +0100, Vitaly Kuznetsov wrote: [...] > > +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: > Yes. Root should always have that permission. That's my understanding. > 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. > I've changed both places. Wei.