From nobody Fri Apr 26 07:32:52 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1557422826; cv=none; d=zoho.com; s=zohoarc; b=V56pDusvDe3EFKr83OflZEzdLYl8sXQptFlkP8Hf3qytFjf27yH5AiVujIPFJwCZuQpzusY3TyxHR/vVVlXJkxK50hR2eFTF60oTTa+V4EQ+wbi+gzv2nvgICSkq0Q11cITGAEeZ1Pngg2RYKmmY90KnYqxWFTNYidpMeo0isAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557422826; 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:ARC-Authentication-Results; bh=cAhiINoshalRnwq5USHPfAlRi3RaVIyIZOD6us+y6wM=; b=ixayaq+vCjP7BG9H0U2gznM0qeglzRyvISnSP0Z21iV3qW5mnxkWJALlzAVsNwZL5pnRqaoOCxx9DhmCkT83CmoAsHKvTnyY2oL3NFR68nrPZZyAX98x4HA8F76q1juLauj37ioCUtF/M7USNoXE+Goo81xNaZl9wnfeqc4PmJU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557422826479609.5197710867699; Thu, 9 May 2019 10:27:06 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOmnk-0000fA-RZ; Thu, 09 May 2019 17:25:48 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOmnj-0000eD-Bs for xen-devel@lists.xenproject.org; Thu, 09 May 2019 17:25:47 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 7a8fd6bb-727f-11e9-8980-bc764e045a96; Thu, 09 May 2019 17:25:45 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x49HJNDR162267; Thu, 9 May 2019 17:25:44 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 2s94b6ceyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 May 2019 17:25:44 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x49HPh5B086806; Thu, 9 May 2019 17:25:43 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2s94agwu19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 May 2019 17:25:43 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x49HPadr013211; Thu, 9 May 2019 17:25:36 GMT Received: from aa1-ca-oracle-com.ca.oracle.com (/10.156.75.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 09 May 2019 10:25:36 -0700 X-Inumbo-ID: 7a8fd6bb-727f-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=zCzFQDoK69hNVAh8gq852QANu8+0XDEc/eDcX80GMqk=; b=OgaV2BVA2iW8FAFJxgTjjlCJjgqKAbnyuKTgPt7MyPWTUZEcIShqzFMgSiFsYB178J4t WePWZgCCPzdZypVU20IPA2gHQxUIxry3uq5hYU9jJWDEjhZML6l5gcIO6YvJ2mEOrora 9HEpRnMZ9X0NnHq8UYv7Q8teUybowuzcPDVy6vq0kUiZlZmZM5pPYr5GCpDCXG/qeIho g4VlX/CojoagSg9ND2/LOM0ezOpa/2RhMW3HLIs2GVZnoEWJaliFmdsgs5tSY1/142Ax zzRGYVeCzOxmfSHmUCV8+kwBWs5XisxVL7vLuuPsVIXpsIcAnWJTWkxpJN+R/4nVRWBy KQ== From: Ankur Arora To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Date: Thu, 9 May 2019 10:25:26 -0700 Message-Id: <20190509172540.12398-3-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190509172540.12398-1-ankur.a.arora@oracle.com> References: <20190509172540.12398-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9252 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905090100 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9252 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905090100 Subject: [Xen-devel] [RFC PATCH 02/16] x86/xen: cpuid support in xenhost_t 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: jgross@suse.com, sstabellini@kernel.org, konrad.wilk@oracle.com, ankur.a.arora@oracle.com, pbonzini@redhat.com, boris.ostrovsky@oracle.com, joao.m.martins@oracle.com 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) xen_cpuid_base() is used to probe and setup features early in a guest's lifetime. We want this to behave differently depending on xenhost->type: for instance, local xenhosts cannot intercept the cpuid instruction at all. Add op (*cpuid_base)() in xenhost_ops_t. Signed-off-by: Ankur Arora --- arch/x86/include/asm/xen/hypervisor.h | 2 +- arch/x86/pci/xen.c | 2 +- arch/x86/xen/enlighten_hvm.c | 7 +++++-- arch/x86/xen/enlighten_pv.c | 16 +++++++++++++++- arch/x86/xen/enlighten_pvh.c | 4 ++++ drivers/tty/hvc/hvc_xen.c | 2 +- drivers/xen/grant-table.c | 3 ++- drivers/xen/xenbus/xenbus_xs.c | 3 ++- include/xen/xenhost.h | 21 +++++++++++++++++++++ 9 files changed, 52 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/x= en/hypervisor.h index 39171b3646bb..6c4cdcdf997d 100644 --- a/arch/x86/include/asm/xen/hypervisor.h +++ b/arch/x86/include/asm/xen/hypervisor.h @@ -53,7 +53,7 @@ static inline bool xen_x2apic_para_available(void) #else static inline bool xen_x2apic_para_available(void) { - return (xen_cpuid_base() !=3D 0); + return (xen_cpuid_base(NULL) !=3D 0); } #endif =20 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c index 9112d1cb397b..d1a3b9f08289 100644 --- a/arch/x86/pci/xen.c +++ b/arch/x86/pci/xen.c @@ -431,7 +431,7 @@ void __init xen_msi_init(void) * event channels for MSI handling and instead use regular * APIC processing */ - uint32_t eax =3D cpuid_eax(xen_cpuid_base() + 4); + uint32_t eax =3D cpuid_eax(xenhost_cpuid_base(xh_default) + 4); =20 if (((eax & XEN_HVM_CPUID_X2APIC_VIRT) && x2apic_mode) || ((eax & XEN_HVM_CPUID_APIC_ACCESS_VIRT) && boot_cpu_has(X86_FEATURE_= APIC))) diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 100452f4f44c..ffc5791675b2 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -83,7 +83,10 @@ static void __init xen_hvm_init_mem_mapping(void) xen_vcpu_info_reset(0); } =20 +extern uint32_t xen_pv_cpuid_base(xenhost_t *xh); + xenhost_ops_t xh_hvm_ops =3D { + .cpuid_base =3D xen_pv_cpuid_base, }; =20 xenhost_ops_t xh_hvm_nested_ops =3D { @@ -94,7 +97,7 @@ static void __init init_hvm_pv_info(void) int major, minor; uint32_t eax, ebx, ecx, edx, base; =20 - base =3D xen_cpuid_base(); + base =3D xenhost_cpuid_base(xh_default); eax =3D cpuid_eax(base + 1); =20 major =3D eax >> 16; @@ -250,7 +253,7 @@ static uint32_t __init xen_platform_hvm(void) if (xen_pv_domain() || xen_nopv) return 0; =20 - return xen_cpuid_base(); + return xenhost_cpuid_base(xh_default); } =20 static __init void xen_hvm_guest_late_init(void) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index bb6e811c1525..a4e04b0cc596 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1189,10 +1189,23 @@ static void __init xen_dom0_set_legacy_features(voi= d) x86_platform.legacy.rtc =3D 1; } =20 +uint32_t xen_pv_cpuid_base(xenhost_t *xh) +{ + return hypervisor_cpuid_base("XenVMMXenVMM", 2); +} + +uint32_t xen_pv_nested_cpuid_base(xenhost_t *xh) +{ + return hypervisor_cpuid_base("XenVMMXenVMM", + 2 /* nested specific leaf? */); +} + xenhost_ops_t xh_pv_ops =3D { + .cpuid_base =3D xen_pv_cpuid_base, }; =20 xenhost_ops_t xh_pv_nested_ops =3D { + .cpuid_base =3D xen_pv_nested_cpuid_base, }; =20 /* First C function to be called on Xen boot */ @@ -1469,7 +1482,8 @@ static int xen_cpu_dead_pv(unsigned int cpu) static uint32_t __init xen_platform_pv(void) { if (xen_pv_domain()) - return xen_cpuid_base(); + /* xenhost is setup in xen_start_kernel. */ + return xenhost_cpuid_base(xh_default); =20 return 0; } diff --git a/arch/x86/xen/enlighten_pvh.c b/arch/x86/xen/enlighten_pvh.c index 826c296d27a3..c07eba169572 100644 --- a/arch/x86/xen/enlighten_pvh.c +++ b/arch/x86/xen/enlighten_pvh.c @@ -29,6 +29,10 @@ void __init xen_pvh_init(void) u32 msr; u64 pfn; =20 + /* + * Note: we have already called xen_cpuid_base() in + * hypervisor_specific_init() + */ xenhost_register(xenhost_r1, &xh_hvm_ops); =20 /* diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c index dc43fa96c3de..5e5ca35d7187 100644 --- a/drivers/tty/hvc/hvc_xen.c +++ b/drivers/tty/hvc/hvc_xen.c @@ -595,7 +595,7 @@ console_initcall(xen_cons_init); #ifdef CONFIG_X86 static void xen_hvm_early_write(uint32_t vtermno, const char *str, int len) { - if (xen_cpuid_base()) + if (xen_cpuid_base(xh_default)) outsb(0xe9, str, len); } #else diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 7ea6fb6a2e5d..98af259d0d4f 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -50,6 +50,7 @@ #endif =20 #include +#include #include #include #include @@ -1318,7 +1319,7 @@ static bool gnttab_need_v2(void) uint32_t base, width; =20 if (xen_pv_domain()) { - base =3D xen_cpuid_base(); + base =3D xenhost_cpuid_base(xh_default); if (cpuid_eax(base) < 5) return false; /* Information not available, use V1. */ width =3D cpuid_ebx(base + 5) & diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index 49a3874ae6bb..3236d1b1fa01 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -49,6 +49,7 @@ #include #include #include +#include #include "xenbus.h" =20 /* @@ -722,7 +723,7 @@ static bool xen_strict_xenbus_quirk(void) #ifdef CONFIG_X86 uint32_t eax, ebx, ecx, edx, base; =20 - base =3D xen_cpuid_base(); + base =3D xenhost_cpuid_base(xh_default); cpuid(base + 1, &eax, &ebx, &ecx, &edx); =20 if ((eax >> 16) < 4) diff --git a/include/xen/xenhost.h b/include/xen/xenhost.h index a58e883f144e..13a70bdadfd2 100644 --- a/include/xen/xenhost.h +++ b/include/xen/xenhost.h @@ -1,6 +1,9 @@ #ifndef __XENHOST_H #define __XENHOST_H =20 +#include +#include +#include /* * Xenhost abstracts out the Xen interface. It co-exists with the PV/HVM/P= VH * abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to @@ -70,6 +73,16 @@ typedef struct { } xenhost_t; =20 typedef struct xenhost_ops { + /* + * xen_cpuid is used to probe features early. + * xenhost_r0: + * Implementation could not use cpuid at all: it's difficult to + * intercept cpuid instruction locally. + * xenhost_r1: + * xenhost_r2: + * Separate cpuid-leafs? + */ + uint32_t (*cpuid_base)(xenhost_t *xenhost); } xenhost_ops_t; =20 extern xenhost_t *xh_default, *xh_remote; @@ -92,4 +105,12 @@ void __xenhost_unregister(enum xenhost_type type); for ((xh) =3D (xenhost_t **) &xenhosts[0]; \ (((xh) - (xenhost_t **)&xenhosts) < 2) && (*xh)->type !=3D xenhost_inval= id; (xh)++) =20 +static inline uint32_t xenhost_cpuid_base(xenhost_t *xh) +{ + if (xh) + return (xh->ops->cpuid_base)(xh); + else + return xen_cpuid_base(); +} + #endif /* __XENHOST_H */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel