Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp646997pxk; Wed, 16 Sep 2020 13:13:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrBJTQwIMj+RbeTeklDnX5/AW9kTS7awaldAvL0M/Jd5Un3qMw9KXJR2ycR98fmwMTKR95 X-Received: by 2002:a17:906:4754:: with SMTP id j20mr28148129ejs.293.1600287223151; Wed, 16 Sep 2020 13:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600287223; cv=none; d=google.com; s=arc-20160816; b=S1dLji6aLNgGVYzcXvGK50QrtUrNmhe0Cld1Ss29KVUClbnHtGoFG7slAPp92lnzZ2 jbjc6bhlNrq+DOdqZB0/gFR62xMw9aOWOodnmJ40PXqmRUnbWnNymVIhE0Jqd0PQ3tOF eUm7NyGyOpYNwn+bW/yNAUe0rDm42Knx7Tf1lanLmgXSQEgfQMh0KyOTlyq/eJWb1f5M WvMbUSpd9on9gdPkTkQWbwKB/lLwMuTQ6aTZYcO4ujdvgjM5Qo8R53nWDRJZP7xFOy5W PNot2+MZAXQBxpYr0vtWNeuPhGXaPms3kmwqQ0ehaRSvkyWVlMb5rM75DtfqcLYwdVJK ltQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ldHCQZEbH6mXJ0nQIfyxhFzRsfVxNZ4TaLzszON1d9k=; b=SgncMB5HbFTVNe0Ullc9opyASAP34Ljgi/o2yT1sZrlrnSLAfW6VfpLF2u4vcLHx18 AFL46hYvFebZ/b4nn1oVacVLzi1a5+iwfQV70Zu40/VLrJSFJAtNk+I/A5YhHaYAkI1I GiRMWm78MocBVp1Qnx5yyyiY11vDKUNBab8JM2ECWUx0upira77IqRFoOf1KzdXSpzBV /tyrDpAgMoTHGXG64NHxxd0ctedluxGUX721QUbwwEu6hg0EP/f1AYcDvZEkFJou1RYr +79HzTTnZx/Lv8ka6I/OY7CdtqbA1WLJHdPy/BlRyyxVQ3sHN87Q0Vm4mP7eXcLzqWQ8 ghzA== 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 s16si12465182ejz.557.2020.09.16.13.13.17; Wed, 16 Sep 2020 13:13:43 -0700 (PDT) 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 S1727244AbgIPUMF (ORCPT + 99 others); Wed, 16 Sep 2020 16:12:05 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50735 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727117AbgIPRdQ (ORCPT ); Wed, 16 Sep 2020 13:33:16 -0400 Received: by mail-wm1-f68.google.com with SMTP id e17so3577749wme.0; Wed, 16 Sep 2020 10:33:14 -0700 (PDT) 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=ldHCQZEbH6mXJ0nQIfyxhFzRsfVxNZ4TaLzszON1d9k=; b=tKcYuEPnMMRxhy/wAXuhZfR7duE+RlVJZ1geQRopYt+9xTP7aBKncwRlXPbDuExdPY WrNrxFlesM+qK2v3+o0Lw+IZbCWZc2sOD0YcWZaB0T4/ucjDp6F1egTnzF0ZyhQrI0n8 ok/GZL13xlr+eNRmt2PG8pNA1s6DFdORUgA2kVWkTJYqOhKszqaA/kfSRjYhSMeALmGj xKVm32iGWsagqRbqQhw5sBaK2xyIii4HV2cZ5Lm2ixO6rKX1clUkQGUM9Kpn+c2P6BOr pTQ92oNdMuVZTfSA+GJusubzR0jRLR5CWbNDaNgnsp7VgB4naGUlmfB+iDYqKSKlpf1Y 4uWA== X-Gm-Message-State: AOAM533i2WIidp+sHXdIDWxDzQ8e4xnulz/naQFsrWK8izquhddn6G9D xETdkXrcRRTxXExdE3GC2Djm8pRHyaA= X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr5502058wmg.164.1600273965104; Wed, 16 Sep 2020 09:32:45 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id z14sm32544835wrh.14.2020.09.16.09.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 09:32:44 -0700 (PDT) Date: Wed, 16 Sep 2020 16:32:43 +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 RFC v1 07/18] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary Message-ID: <20200916163243.3zkhff57gpoug6x4@liuwe-devbox-debian-v2> References: <20200914112802.80611-1-wei.liu@kernel.org> <20200914112802.80611-8-wei.liu@kernel.org> <87y2lbjpx7.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87y2lbjpx7.fsf@vitty.brq.redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2020 at 12:27:16PM +0200, Vitaly Kuznetsov wrote: > Wei Liu writes: [...] > > > > +void __init hv_get_partition_id(void) > > +{ > > + struct hv_get_partition_id *output_page; > > + int 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; > > Nit: in this case status is 'u16', we can define it as such (instead of > signed int). Fixed. > > > + if (status != HV_STATUS_SUCCESS) > > + pr_err("Failed to get partition ID: %d\n", status); > > + else > > + hv_current_partition_id = output_page->partition_id; > > + 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. > > @@ -440,6 +463,9 @@ void __init hyperv_init(void) > > > > register_syscore_ops(&hv_syscore_ops); > > > > + if (hv_root_partition) > > + hv_get_partition_id(); > > According to TLFS, partition ID is available when AccessPartitionId > privilege is granted. I'd suggest we check that instead of > hv_root_partition (and we can set hv_current_partition_id to something > like U64_MAX so we know it wasn't acuired). So the BUG_ON condition will > move here: > > hv_get_partition_id(); > BUG_ON(hv_root_partition && hv_current_partition_id == U64_MAX); > Good point. I will reorganize this a bit. Wei.