From nobody Tue Jan 16 17:52:17 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TDxRQ0b1Jz57jff; Tue, 16 Jan 2024 17:52:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TDxRQ07Yqz4ptl; Tue, 16 Jan 2024 17:52:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705427538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mSQVSDG0WhJDplf2/jbt71/RFZmcec8s0NxOmET0soU=; b=ShzCYJhz3Jli68n9iPX//nb87ZAm02MmH6yiUr5/2p1FRjUn5Rcgf7qRCCd8ABuDsZ8rOc l8MEo0c9QsBbySpeq+n4ZiaSosbZiP8XV5lvESirEbhanmE8t7zHXEjnbtIvppjUdjGvZX vbmubiDzcgpWJLB5ujNYNGmBt+E05WGWDYogYSwB/Agfb0nbODn3r0aSJeIejaYaj+jDrp nrVJNBEgrUhFqP5uCC/tbMyI3K5CAnFLCEPwxF8qtveZFR/B2esL3943hLrVo+lj3ytBzB 06nFOO1LNrkiI5xfwnqTeAXXWahqXAJXMU+7M2O6UeVbljqgMiLw99/5nZDf+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705427538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mSQVSDG0WhJDplf2/jbt71/RFZmcec8s0NxOmET0soU=; b=AMNVSz3gYs7OfJOzks+gIDbPcACdVnOaM3NPZL5PPJjLbMTRrGQ/WXGqiP1WVmsxlwOIRm 3EpJND6I8AqIr42L0u1H3DzIhTkRXtG4+VMEy5/yLhapKlzEM004hV7ddRHVP9ijhUb9Dj c/T4qDnicHzfbpTf65IU0DMGTKuz9hW8mF6AnarlrkWc33Wde9D8x6Pmp8IkoXl0fe2ZVs C800MUj8iTplFlNRYuuwX/auThccHVsUXUrba2bI9IX9fT7BWJHmMajMxyGp7ZqoZ9oahR 4oUJOAD2uBOXJ+FqfKRtBVno91H9czSgA7ptGPNbuUJWuyQB4K3KjZR+cvY40A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705427538; a=rsa-sha256; cv=none; b=dryNHtgPzH5DUm8qMaLiXFxibwcuByko4WXGdf3ZHKVGHVe0qY8mmutfyUIQQO2Cmh6Rxw G++tFr3uoPSbpaAZiiptySWST571py63Z39pDmG0yn4FjggrpCPmIoZhK04ZSFKyJf+lk6 KJWFpfGX18HCkVuUux7Da2Og9qLY2kRi8hI3V1SYqQaKacqT16zKhlq7SiK2mdk1dzeafP grerUH43Lvd663eUEmlqx+pItoMIVkZ8YYMPkF7ervtRg49AWvK3Rqdv0b1go9Lr/+v0LM 1jajXjEaX/fECzeB2Z1QWfCrTbmmJZV1zGMfvDn/jFgqu+HTV8opAB/C95+xPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TDxRP60VszqSb; Tue, 16 Jan 2024 17:52:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40GHqHQB089961; Tue, 16 Jan 2024 17:52:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40GHqHIA089959; Tue, 16 Jan 2024 17:52:17 GMT (envelope-from git) Date: Tue, 16 Jan 2024 17:52:17 GMT Message-Id: <202401161752.40GHqHIA089959@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: b0165dc4539f - main - x86/xen: fix HVM guest hypercall page setup List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b0165dc4539fdfc84351a719b58850e4e7a6cbb6 Auto-Submitted: auto-generated The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=b0165dc4539fdfc84351a719b58850e4e7a6cbb6 commit b0165dc4539fdfc84351a719b58850e4e7a6cbb6 Author: Roger Pau Monné AuthorDate: 2024-01-16 15:32:56 +0000 Commit: Roger Pau Monné CommitDate: 2024-01-16 17:50:54 +0000 x86/xen: fix HVM guest hypercall page setup c7368ccb6801 didn't take into account that vm_guest will also get setup by generic identify CPU code, and hence by the time xen_hvm_init() gets called vm_guest will always be set if running as a Xen guest, either by the PVH entry point code, or by generic CPU identification. xen_hvm_init() and xen_hvm_init_hypercall_stubs() were relying on xen_domain() returning false when running as an HVM guest, and used that into order to figure out whether hypercall page needed to be populated. Get rid of such assumptions and simplify the code since legacy PVH is no longer supported. This fixes booting FreeBSD as a Xen HVM guest. Fixes: c7368ccb6801 ('xen: remove xen_domain_type enum/variable') Sponsored by: Cloud Software Group --- sys/x86/xen/hvm.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c index e096559711a3..b8125e230b6f 100644 --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -155,25 +155,14 @@ xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type) { uint32_t regs[4]; - /* Legacy PVH will get here without the cpuid leaf being set. */ - if (xen_cpuid_base == 0) - xen_cpuid_base = xen_hvm_cpuid_base(); + if (xen_cpuid_base != 0) + /* Already setup. */ + goto out; + + xen_cpuid_base = xen_hvm_cpuid_base(); if (xen_cpuid_base == 0) return (ENXIO); - if (xen_domain() && init_type == XEN_HVM_INIT_LATE) { - /* - * If the domain type is already set we can assume that the - * hypercall page has been populated too, so just print the - * version (and apply any quirks) and exit. - */ - hypervisor_version(); - return 0; - } - - if (init_type == XEN_HVM_INIT_LATE) - hypervisor_version(); - /* * Find the hypercall pages. */ @@ -185,6 +174,8 @@ xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type) ? (vm_paddr_t)((uintptr_t)&hypercall_page - KERNBASE) : vtophys(&hypercall_page)); +out: + hypervisor_version(); return (0); } @@ -334,7 +325,8 @@ xen_hvm_init(enum xen_hvm_init_type init_type) int error; int i; - if (init_type == XEN_HVM_INIT_CANCELLED_SUSPEND) + if (!xen_domain() || + init_type == XEN_HVM_INIT_CANCELLED_SUSPEND) return; error = xen_hvm_init_hypercall_stubs(init_type); @@ -344,15 +336,6 @@ xen_hvm_init(enum xen_hvm_init_type init_type) if (error != 0) return; - /* - * If the Xen domain type is not set at this point - * it means we are inside a (PV)HVM guest, because - * for PVH the guest type is set much earlier - * (see hammer_time_xen). - */ - if (!xen_domain()) - vm_guest = VM_GUEST_XEN; - setup_xen_features(); #ifdef SMP cpu_ops = xen_hvm_cpu_ops;