From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5608BC43461 for ; Wed, 16 Sep 2020 20:12:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6A5B206B7 for ; Wed, 16 Sep 2020 20:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600287141; bh=vzWS9EzHiimLXZ027QxNP7+5zm0L+WfvO4sFMPnUD5c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=LD9ls9cWsM3SUyThK01Jn7vp/noJe+ONoBhtqD+gigS4wraty3jVukFPwJaglzeKd 9iD0Qa5MrG/kV8kUmAk++zcKf5zdrQXVGu2yRMtLcMMKE9eNV94l2r98pdt2eN3y3s 1TZ+hW2q4VTADZGDWr+8QqtcKYIlWSvbAMrC0qTs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727151AbgIPUMN (ORCPT ); Wed, 16 Sep 2020 16:12:13 -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-Google-Smtp-Source: ABdhPJxKE9LndKWPqE9c0rk+ywJAV/cod/ghoctHMJq5VT/1ihI9WVcOOfs570RwJJYaVmhfZp36RQ== 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.