From nobody Mon Feb 9 04:45:05 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1579724679; cv=none; d=zohomail.com; s=zohoarc; b=InyBm+EgZUVuNjp1LeefLrySAuQ4+J3j43eYrzNABqsfNb4uDnbIO2Xf+rcU+CxFimEOQiUBHAMJVD9gpWWDdjUb1VMTKBsqB7TAWPt/zTL8d5lQS39tgWg19BF/uzbSpM+DkltV7Yfnd/eMH7gRJ3AG081JAm/eVokTPDRsmP8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579724679; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4Yh7ORVhiF8nppMLYMGq1riU7rmZfFtWnFHR0HFf8hI=; b=FVOocvQtlZksuLvDuBg1ytf8wicpKGGNyOrEGQkIn3zvFwXsUZnOdgPUZfgOciqmg7TJNQMTqk+w2eurPtq4rldUgrUaxfm5ZjBXDyncVNMC3shERGR6Il2bH2aHeMlt2WWvW/YAT/AkLEky95en166qV0EPqqzWks9C7iVDbZw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 157972467973481.75201068670708; Wed, 22 Jan 2020 12:24:39 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXf-0006FG-GE; Wed, 22 Jan 2020 20:23:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXd-0006F4-W4 for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:23:58 +0000 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 18ff56fe-3d55-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 20:23:49 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id c9so489391wrw.8 for ; Wed, 22 Jan 2020 12:23:49 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:47 -0800 (PST) X-Inumbo-ID: 18ff56fe-3d55-11ea-9fd7-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hpuNmbi3NIrtI9XWZDVNmn3N4Ap+/HsCumpfsYCUB1I=; b=ek8LREQWmkE4UZkuzuoFdRiExdWuOvPpFXnb/VaGIGsKeRHaFzssk0985Q0dL7MW1h 29jo8FjCpdspmZTenycoLce5Rs9Y5xaqUNivkmne0tPC4tN3Ai7awP+S//InxVUk8wS4 snPen59LdYtXNbAX44gqs5anvqHIz4ZEDkNePNzyDX8O0yP+jfWn0Sbqd58WfRfl+rF7 JVPrhAeW4ucnXoAExhm3SMS+O9ljvWX39Mn4nUhwYijPtPvTkpopxjaFg6O0W5CnK/uL UrABcI80LQf6vgKf56bHCiLePhNZtLFNp8EirB9vsqUsmQSH8zRpeYqgaR31ywfTiJ5M Q51A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hpuNmbi3NIrtI9XWZDVNmn3N4Ap+/HsCumpfsYCUB1I=; b=Snrf4/hyeQCE2FNs/RMf+eXBfPeCtqVSEdo4nHgHWjZZQCe0crdst8wrWhyqGcZyJ4 9zqI767Epi96Abf/mJfO6PfON5GYz9WjC06Ossb02gnJQfTsX3e+hl7zcymjS5pV3X2q nkp2KRlWE5rY4qTIdySe0Xu7SWY63LizvzCWZ1i/BeyAzVlKKSoBBPNhBAx9S9bzToT1 X6B74FBFjgQow2pWh8cZfttaw0rmNQxv6wyhcCoIPDXlSaBY6wV82emCYE0kxTEfSuOz mQ6Ylt29URAlt+mXdHs99+UETWpJucQEA3JYEOsQ8fRtBp7Bzo8SslVLfTSsIv+Y/rw8 SHbQ== X-Gm-Message-State: APjAAAVHPjcC4mYRDkzIx8uv7Dkb0tcg+kGfRLY9gUZ0obS/uAkl8ehL ZN0eoUJP9OfsuiKlpGY0coI4OoAn8PrTwg== X-Google-Smtp-Source: APXvYqyioxSeD5rpVA3j5CgzuYV6XmhP+dr2avBDbBfm6ov1Sv/aGALiB9fl3Zui9KSiTbHvPy5bdg== X-Received: by 2002:a5d:6048:: with SMTP id j8mr13625476wrt.41.1579724628294; Wed, 22 Jan 2020 12:23:48 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:38 +0000 Message-Id: <20200122202343.5703-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 2/7] x86/hyperv: setup hypercall page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Paul Durrant , Michael Kelley , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Use the top-most addressable page for that purpose. Adjust e820 code accordingly. We also need to register Xen's guest OS ID to Hyper-V. Use 0x300 as the OS type. Signed-off-by: Wei Liu --- XXX the decision on Xen's vendor ID is pending. v4: 1. Use fixmap 2. Follow routines listed in TLFS --- xen/arch/x86/e820.c | 41 +++++++++++++++---- xen/arch/x86/guest/hyperv/hyperv.c | 53 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index 082f9928a1..5a4ef27a0b 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -36,6 +36,22 @@ boolean_param("e820-verbose", e820_verbose); struct e820map e820; struct e820map __initdata e820_raw; =20 +static unsigned int find_phys_addr_bits(void) +{ + uint32_t eax; + unsigned int phys_bits =3D 36; + + eax =3D cpuid_eax(0x80000000); + if ( (eax >> 16) =3D=3D 0x8000 && eax >=3D 0x80000008 ) + { + phys_bits =3D (uint8_t)cpuid_eax(0x80000008); + if ( phys_bits > PADDR_BITS ) + phys_bits =3D PADDR_BITS; + } + + return phys_bits; +} + /* * This function checks if the entire range is mapped with typ= e. * @@ -357,6 +373,21 @@ static unsigned long __init find_max_pfn(void) max_pfn =3D end; } =20 +#ifdef CONFIG_HYPERV_GUEST + { + /* + * We reserve the top-most page for hypercall page. Adjust + * max_pfn if necessary. + */ + unsigned int phys_bits =3D find_phys_addr_bits(); + unsigned long hcall_pfn =3D + ((1ull << phys_bits) - 1) >> PAGE_SHIFT; + + if ( max_pfn >=3D hcall_pfn ) + max_pfn =3D hcall_pfn - 1; + } +#endif + return max_pfn; } =20 @@ -420,7 +451,7 @@ static uint64_t __init mtrr_top_of_ram(void) { uint32_t eax, ebx, ecx, edx; uint64_t mtrr_cap, mtrr_def, addr_mask, base, mask, top; - unsigned int i, phys_bits =3D 36; + unsigned int i, phys_bits; =20 /* By default we check only Intel systems. */ if ( e820_mtrr_clip =3D=3D -1 ) @@ -446,13 +477,7 @@ static uint64_t __init mtrr_top_of_ram(void) return 0; =20 /* Find the physical address size for this CPU. */ - eax =3D cpuid_eax(0x80000000); - if ( (eax >> 16) =3D=3D 0x8000 && eax >=3D 0x80000008 ) - { - phys_bits =3D (uint8_t)cpuid_eax(0x80000008); - if ( phys_bits > PADDR_BITS ) - phys_bits =3D PADDR_BITS; - } + phys_bits =3D find_phys_addr_bits(); addr_mask =3D ((1ull << phys_bits) - 1) & ~((1ull << 12) - 1); =20 rdmsrl(MSR_MTRRcap, mtrr_cap); diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv= /hyperv.c index 8d38313d7a..f986c1a805 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -18,17 +18,27 @@ * * Copyright (c) 2019 Microsoft. */ +#include #include =20 +#include #include #include +#include =20 struct ms_hyperv_info __read_mostly ms_hyperv; =20 -static const struct hypervisor_ops ops =3D { - .name =3D "Hyper-V", -}; +static uint64_t generate_guest_id(void) +{ + uint64_t id =3D 0; + + id =3D (uint64_t)HV_XEN_VENDOR_ID << 48; + id |=3D (xen_major_version() << 16) | xen_minor_version(); + + return id; +} =20 +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { uint32_t eax, ebx, ecx, edx; @@ -72,6 +82,43 @@ const struct hypervisor_ops *__init hyperv_probe(void) return &ops; } =20 +static void __init setup_hypercall_page(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + union hv_guest_os_id guest_id; + unsigned long mfn; + + rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + if ( !guest_id.raw ) + { + guest_id.raw =3D generate_guest_id(); + wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + } + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + if ( !hypercall_msr.enable ) + { + mfn =3D ((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT; + hypercall_msr.enable =3D 1; + hypercall_msr.guest_physical_address =3D mfn; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + } else { + mfn =3D hypercall_msr.guest_physical_address; + } + + set_fixmap_x(FIX_X_HYPERV_HCALL, mfn << PAGE_SHIFT); +} + +static void __init setup(void) +{ + setup_hypercall_page(); +} + +static const struct hypervisor_ops ops =3D { + .name =3D "Hyper-V", + .setup =3D setup, +}; + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/guest/hyperv-tlfs.h b/xen/include/asm-x86/= guest/hyperv-tlfs.h index 05c4044976..5d37efd2d2 100644 --- a/xen/include/asm-x86/guest/hyperv-tlfs.h +++ b/xen/include/asm-x86/guest/hyperv-tlfs.h @@ -318,15 +318,16 @@ struct ms_hyperv_tsc_page { * * Bit(s) * 63 - Indicates if the OS is Open Source or not; 1 is Open Source - * 62:56 - Os Type; Linux is 0x100 + * 62:56 - Os Type; Linux 0x100, FreeBSD 0x200, Xen 0x300 * 55:48 - Distro specific identification - * 47:16 - Linux kernel version number + * 47:16 - Guest OS version number * 15:0 - Distro specific identification * * */ =20 #define HV_LINUX_VENDOR_ID 0x8100 +#define HV_XEN_VENDOR_ID 0x8300 union hv_guest_os_id { uint64_t raw; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel