From nobody Tue Nov 11 05:23:34 2025 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=1575115122; cv=none; d=zohomail.com; s=zohoarc; b=TNzgTQPlIlDlUNyM2/tO2/2opkzyEwgk2fKTa/RCccAjAxWbTPGhDaDnV9pH9w9JF9h6pIET4mJzLZzMlVu91N6m3kIcranVMut37E1+/ZvwgO46bDLS3PiSY1+GXEEizNr78B14P/jfZn3h71po1x5QsEdhhh2UoJuheI91qGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575115122; 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=ADcBy7wMm8Pi3m2qUrBjpZd8OiEHVQDFOvnQY3AdF4s=; b=nDzMs9iKGrsYHx0TPGQYtep1iiecu2rZcbKEpqtKAoAP+pOlib8fFAPUV8nC5WPgWUOeCTXJN2DrGTIBaKfgLhQcCu2+21+4B5/Wtbe2dkyP2EksnSaAgAvKFteU/0/FDCSOSEV1Hq8ChhQktSxRCVpPuEbwdUAI4Rm6IwoIAsA= 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 1575115122496522.4741284927919; Sat, 30 Nov 2019 03:58:42 -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 1ib1O9-0004v8-UM; Sat, 30 Nov 2019 11:58:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ib1O8-0004uQ-Kh for xen-devel@lists.xenproject.org; Sat, 30 Nov 2019 11:58:12 +0000 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a02b3010-1368-11ea-a55d-bc764e2007e4; Sat, 30 Nov 2019 11:57:47 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id c14so13532190wrn.7 for ; Sat, 30 Nov 2019 03:57:47 -0800 (PST) Received: from debian.mshome.net (122.163.200.146.dyn.plus.net. [146.200.163.122]) by smtp.gmail.com with ESMTPSA id z11sm2227769wrt.82.2019.11.30.03.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2019 03:57:46 -0800 (PST) X-Inumbo-ID: a02b3010-1368-11ea-a55d-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=hAlY2mNPHIbwQq8gmJ9oB1h1pr+UFRMqeVy8IETeg28=; b=YPbuyCZvZnlI09kHn8Lw23Wii9VkaVhL1vxtP6HwQIxQb0TdpclkJFdNjeE/qkJPxh 1L4f5loM6BjTcEgkE4O4u0mPItM3o2BZgOBRi3TO4j1J49Vh3HsyViO05Sxdh9m+6qCv +TVjsyckaJ/sxYsOBbrt1CTN4rNXwOBVn50svIyJJI0JaPufppg1UqfdNzZL+yRcXriO F8UsLcNZSqf1vqcI0wQPFn+1wi2c02Fs5fw9MAmymcZb2Hd3FfQxER2VV+pmP+gUhFp0 wUkQHb/2+a23Hp07Wp/tljrcyuAwbg0QA9qYbxEyVOxhgWo993oixzYGPr7Ll8KuUsuo Oe0Q== 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=hAlY2mNPHIbwQq8gmJ9oB1h1pr+UFRMqeVy8IETeg28=; b=KtrhDl/Lj0i9xAzh6udN7fHeIZs7CmIOBIQS3MiZNOA88xATEp0QPaRRIDpvvX7CBV TbFmiGH2JE/+2Iq3/6Oj5mxRqdfdZmODYPpDEtBLIoKoxX9QJRMcoj3eIm9c3OOOgqaG g0bHLBHiRYFkRkoGJoJ9yhHPs7WHDHFAl4ffKtz07VAcenbrA+NVYTUCElMsKmZPj3JJ XgmN2BYzbXrMp7iHFZNrIohTOl5EH0arhnq7hKJnzC87hQyfBcs8Z6xKzohIQT1kKP0Q qZB+/74dsWMCTyx2KZYtvwzm7+chgFvplYtkvMfJdcis/zIzlOLoDtUkNI085hGvWiB7 bPXw== X-Gm-Message-State: APjAAAUeyAJU7wRLMUeNDUgpxsA6gy/MJDG3E+3qRP96GzHFjpLQyivn 5V6/JLy1ROXZTIh4SeDlRosvA+RBOUs= X-Google-Smtp-Source: APXvYqycs0h31dIHSKhfIZX/ghtUZItEZeYZVZMfs/23yh/x17ubMGmEiMZXC4p9qof5fXXgCl5Q6A== X-Received: by 2002:a5d:548e:: with SMTP id h14mr3081916wrv.380.1575115066753; Sat, 30 Nov 2019 03:57:46 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sat, 30 Nov 2019 11:57:35 +0000 Message-Id: <20191130115737.15752-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191130115737.15752-1-liuwe@microsoft.com> References: <20191130115737.15752-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 6/8] x86: switch xen guest implementation to use hypervisor framework 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 , Andrew Cooper , Michael Kelley , Jan Beulich , =?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) Signed-off-by: Wei Liu Acked-by: Jan Beulich --- Changes in v5: 1. xen_probe -> xg_probe 2. Drop xen_ prefix for private functions --- xen/arch/x86/guest/hypervisor.c | 27 +++++++++++++++++- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/guest/xen/xen.c | 47 ++++++++++++++++++------------- xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/guest/xen.h | 5 ++-- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hyperviso= r.c index c35c610d01..6cd86d0c02 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -22,18 +22,43 @@ #include =20 #include -#include +#include =20 static const struct hypervisor_ops __read_mostly *ops; =20 const char *__init hypervisor_probe(void) { + if ( !cpu_has_hypervisor ) + return NULL; + + if ( ops ) + return ops->name; + + ops =3D xg_probe(); if ( ops ) return ops->name; =20 return NULL; } =20 +void __init hypervisor_setup(void) +{ + if ( ops && ops->setup ) + ops->setup(); +} + +void hypervisor_ap_setup(void) +{ + if ( ops && ops->ap_setup ) + ops->ap_setup(); +} + +void hypervisor_resume(void) +{ + if ( ops && ops->resume ) + ops->resume(); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh= -boot.c index ca8e156f7d..498625eae0 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t *= *mod) { convert_pvh_info(mbi, mod); =20 - probe_hypervisor(); + hypervisor_probe(); ASSERT(xen_guest); =20 get_memory_map(); diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 0f5b5267c5..10daa043e4 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -67,22 +67,6 @@ static void __init find_xen_leaves(void) } } =20 -void __init probe_hypervisor(void) -{ - if ( xen_guest || !cpu_has_hypervisor ) - return; - - find_xen_leaves(); - - if ( !xen_cpuid_base ) - return; - - /* Fill the hypercall page. */ - wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); - - xen_guest =3D true; -} - static void map_shared_info(void) { mfn_t mfn; @@ -245,7 +229,7 @@ static void init_evtchn(void) } } =20 -void __init hypervisor_setup(void) +static void __init setup(void) { init_memmap(); =20 @@ -273,7 +257,7 @@ void __init hypervisor_setup(void) init_evtchn(); } =20 -void hypervisor_ap_setup(void) +static void ap_setup(void) { set_vcpu_id(); map_vcpuinfo(); @@ -303,7 +287,7 @@ static void ap_resume(void *unused) init_evtchn(); } =20 -void hypervisor_resume(void) +static void resume(void) { /* Reset shared info page. */ map_shared_info(); @@ -326,6 +310,31 @@ void hypervisor_resume(void) pv_console_init(); } =20 +static const struct hypervisor_ops xg_ops =3D { + .name =3D "Xen", + .setup =3D setup, + .ap_setup =3D ap_setup, + .resume =3D resume, +}; + +const struct hypervisor_ops *__init xg_probe(void) +{ + if ( xen_guest ) + return &xg_ops; + + find_xen_leaves(); + + if ( !xen_cpuid_base ) + return NULL; + + /* Fill the hypercall page. */ + wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); + + xen_guest =3D true; + + return &xg_ops; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 7d27f36053..a6b354c29f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations(); =20 - probe_hypervisor(); + hypervisor_probe(); =20 parse_video_info(); =20 diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xe= n.h index 01dc3ee6f6..2042a9a0c2 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -23,6 +23,7 @@ =20 #include #include +#include =20 #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_= INFO)) =20 @@ -32,7 +33,7 @@ extern bool xen_guest; extern bool pv_console; extern uint32_t xen_cpuid_base; =20 -void probe_hypervisor(void); +const struct hypervisor_ops *xg_probe(void); int xg_alloc_unused_page(mfn_t *mfn); int xg_free_unused_page(mfn_t mfn); =20 @@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); #define xen_guest 0 #define pv_console 0 =20 -static inline void probe_hypervisor(void) {} +static inline const struct hypervisor_ops *xg_probe(void) { return NULL; } =20 #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel