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=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 870F3C2D0E0 for ; Tue, 15 Sep 2020 10:27:27 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 045F421D7B for ; Tue, 15 Sep 2020 10:27:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="N4ta0p49" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 045F421D7B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 9B58087117; Tue, 15 Sep 2020 10:27:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YHZS6DB+cItX; Tue, 15 Sep 2020 10:27:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id DAE8487118; Tue, 15 Sep 2020 10:27:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B11EDC0864; Tue, 15 Sep 2020 10:27:25 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 35EE6C0051 for ; Tue, 15 Sep 2020 10:27:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 216FE86686 for ; Tue, 15 Sep 2020 10:27:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6I1oiFsJv5+V for ; Tue, 15 Sep 2020 10:27:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by whitealder.osuosl.org (Postfix) with ESMTPS id 094B285D5F for ; Tue, 15 Sep 2020 10:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600165641; 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=fkoLRj4CpMUCFaAU/c0cpXEpa6XQZl3hQi3pkjeuyww=; b=N4ta0p4905FLUxM52TPf34cmfw5NFMR/Kgyk6rLeTVuM3cgkYkOlIHppH4FfugeV4fNITP y+g6x/f1JTBC53Nq82+4lwW7Cs2fkhVIGkdATbud7JgKSJRlGOKap5HEDTNTH/qh5JupVP gP8frDOvAP4uKPjgH8FNqwR72Cgo1TI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-zvngBc5PM5i2-xMPZqTioA-1; Tue, 15 Sep 2020 06:27:20 -0400 X-MC-Unique: zvngBc5PM5i2-xMPZqTioA-1 Received: by mail-wr1-f69.google.com with SMTP id v12so1056477wrm.9 for ; Tue, 15 Sep 2020 03:27:20 -0700 (PDT) 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=fkoLRj4CpMUCFaAU/c0cpXEpa6XQZl3hQi3pkjeuyww=; b=Jzv3b89oqX8Eok5YHeVjMWGxuwQU2MSf4MF6D1yQ/J9CGcrxM6LooDbBOE35hKSAAY t2p/NX1rAOGLjbSp70Xgfcz8aTBl9Mm0/T4iOY7iGgI+QH23nOU3hEmZjhj/aXHTfPrO yDsBVsDQJU6zw+Wg80Cbx5Bay0vSUVcugYmAEBGGt1f2B8uXbxEy1qs7773QaNyvAxkM vxSpdgB/OUXkFSAbBt21goVYxf31nB2W9E3tdkxi0cRJXSTP2wo9s1W0paXNB0dK4gID I7tOgB3KfLZXSnqlrIg7duWhFKJu1/McxLEAi121A4ilpcXtIgEB3vQEMIYswCqT1Nn9 P7SA== X-Gm-Message-State: AOAM5302mIXz3L6xNqaohv3NBoj/1EFkaio0HUFxDwgISX4BDH9RX6Qz 5s6in0BcDD3Oj0o4jY/aXMxFz2dRQSOW758vM9bZ63WXQrRohKw/NBJGODLsPBhhdAMrtyPrkZy S+aCdHJSZWwUmkUTB1Jb576IYY0x2CKF0oDCXv9GcVQ== X-Received: by 2002:a1c:7c1a:: with SMTP id x26mr4181810wmc.112.1600165638453; Tue, 15 Sep 2020 03:27:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV7+MNnmdJ7LoABeyhT5kZ24BSMQZtr2CvPEQVPzv2SqkmoR19M8GCrVTONoAPOxgeK7xVNw== X-Received: by 2002:a1c:7c1a:: with SMTP id x26mr4181777wmc.112.1600165638158; Tue, 15 Sep 2020 03:27:18 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id z15sm25217526wrv.94.2020.09.15.03.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 03:27:17 -0700 (PDT) From: Vitaly Kuznetsov To: Wei Liu , Linux on Hyper-V List Subject: Re: [PATCH RFC v1 07/18] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary In-Reply-To: <20200914112802.80611-8-wei.liu@kernel.org> References: <20200914112802.80611-1-wei.liu@kernel.org> <20200914112802.80611-8-wei.liu@kernel.org> Date: Tue, 15 Sep 2020 12:27:16 +0200 Message-ID: <87y2lbjpx7.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0.003 X-Mimecast-Originator: redhat.com Cc: "open list:GENERIC INCLUDE/ASM HEADER FILES" , Wei Liu , Stephen Hemminger , Arnd Bergmann , Haiyang Zhang , "maintainer:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)" , virtualization@lists.linux-foundation.org, Linux Kernel List , Nuno Das Neves , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Borislav Petkov , Sunil Muthuswamy , Michael Kelley , Vineeth Pillai , Lillian Grassin-Drake X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" 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 ebba4be4185d..0eec1ed32023 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); > > @@ -345,6 +348,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; > + 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). > + 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); > + > return; > > remove_cpuhp_state: > diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h > index f5c62140f28d..4039302e0ae9 100644 > --- a/arch/x86/include/asm/mshyperv.h > +++ b/arch/x86/include/asm/mshyperv.h > @@ -65,6 +65,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 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization