From nobody Thu Mar 28 22:14:54 2024 Delivered-To: importer@patchew.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 ARC-Seal: i=1; a=rsa-sha256; t=1568036030; cv=none; d=zoho.com; s=zohoarc; b=PVskTAeyJVFVDp49dprsu5KrH/iNXnvOaPdJmzt8obeIRMFKudfDW8MLjh6zn5gZcAV5xgNyUTyeohO7qGsbhjiMyV9oiT7PlXaeI39EW1pFVIvgj0mYWfBbAtSdC4ui9qDp/MRY10GONzEnO7JRlFEoz5TCu4YW+LgW63zSSfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568036030; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=bTS5YX5UVCmIGFRSUeQnavTJt5IxMtZaELDz1wgSiuE=; b=GDzXTrAnBrcZTR8YvTz8dqhAw6aBfjVMKp96UaC1E+H5raNtBLDL7VztT8TgnyssOXk4Zwvxqwv1/9p8vW+YLB0esoTDL2YLH3QsMEt0CyXXV0P91hyP7iWd3ClfaXuqVVBNy6fUp/Zcym4Qsn2ARWIOqS2gpMTy3YEQy6TNgv4= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568036030733198.42664916717604; Mon, 9 Sep 2019 06:33:50 -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 1i7JmF-0003uM-R3; Mon, 09 Sep 2019 13:32:19 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7JmF-0003uH-7R for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 13:32:19 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3e1b4a06-d306-11e9-b76c-bc764e2007e4; Mon, 09 Sep 2019 13:32:18 +0000 (UTC) X-Inumbo-ID: 3e1b4a06-d306-11e9-b76c-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568035937; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=I1XXJikGsCZRCeYeYnKNKvHpStBJcSeHRI0n1OqoLAM=; b=YXB/HFuznbxIwUPq5VejPbOZvbs+hCnW2FjFtkb6A6jZRa4BIvkl1kUq lizM2YIxJFyPcRCoOAvZWluTDJLecR1UWxhkQ7IbgE7Xprme23XPQ18Cu FOI7gltFaiz2LS/KKUmrtEK2f/2bKTMcnWA+hnaXwfrCW6mx0BSfehhCj Y=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: XWy379v+uBdrSNYCd/v7vQ0t7aGdevIvC3BUkIihtbAW50yuFiEWVPcvTjmcd38RzTD759mx32 e4Ruogyg5cQHbyEobR+qvavCiqxiwpouhfRo5xbgck3NS/LfcSJiCo8/fsDxXFFE0ust1C6G8j kfC11G509HJRV1Su9EJTlXHW8uCN5NCg0zskmI6a58YEpVdLRIksi8Jqlzj3s0WBneGOuDyhTF hNG3q0jDktXuve+HJ8Uk+HNmKWLbc6WKxicypgxMI6s3QTYtFK5adXNLkTxIakZdFamom2xZph s2o= X-SBRS: 2.7 X-MesageID: 5551143 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,484,1559534400"; d="scan'208";a="5551143" From: Andrew Cooper To: Xen-devel Date: Mon, 9 Sep 2019 14:32:14 +0100 Message-ID: <20190909133214.29298-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] tools/ocaml: Fix xenctrl ABI and introduce build-time checks 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 , Andrew Cooper , Rob Hoes , Christian Lindig , Ian Jackson , =?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) c/s f089fddd941 broke the Ocaml ABI by renumering XEN_SYSCTL_PHYSCAP_direct= io without adjusting the Ocaml physinfo_cap_flag enumeration. Fix this by inserting CAP_PV between CAP_HVM and CAP_DirectIO. c/s 82239182eb3 extended the XEN_SYSCTL_PHYSCAP_* ABI with a HAP bit. Exte= nd the physinfo_cap_flag enumeration to match. Factor out the bitmap-to-list conversion logic into a helper, to avoid an opencoded truncation of the bitmap. To cover this, add BUILD_BUG_ON()'s at the caller for each constant in the C-to-Ocaml conversion, and for the the applicable max/all constant. This will result in a compile time failure whenever constants get renumbered/added without a compatible adjustment to the Ocaml ABI. Signed-off-by: Andrew Cooper --- CC: Ian Jackson CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Christian Lindig CC: Rob Hoes A patch along these lines wants backporting to at least 4.12, but without t= he HAP constant. I'm happy to do the backport. --- tools/ocaml/libs/xc/xenctrl.ml | 2 + tools/ocaml/libs/xc/xenctrl.mli | 6 ++- tools/ocaml/libs/xc/xenctrl_stubs.c | 78 +++++++++++++++++++++++++++------= ---- xen/include/public/sysctl.h | 3 ++ 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 35958b94d5..5da7c96cee 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -99,7 +99,9 @@ type sched_control =3D =20 type physinfo_cap_flag =3D | CAP_HVM + | CAP_PV | CAP_DirectIO + | CAP_HAP =20 type physinfo =3D { diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.= mli index 6c4268d453..b4e76b827e 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -82,7 +82,11 @@ type domaininfo =3D { arch_config : arch_domainconfig; } type sched_control =3D { weight : int; cap : int; } -type physinfo_cap_flag =3D CAP_HVM | CAP_DirectIO +type physinfo_cap_flag =3D + | CAP_HVM + | CAP_PV + | CAP_DirectIO + | CAP_HAP type physinfo =3D { threads_per_core : int; cores_per_socket : int; diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 2e1b29ce33..10b306f9f8 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -32,6 +32,7 @@ =20 #define XC_WANT_COMPAT_MAP_FOREIGN_API #include +#include =20 #include "mmap_stubs.h" =20 @@ -119,6 +120,31 @@ static void domain_handle_of_uuid_string(xen_domain_ha= ndle_t h, #undef X } =20 +/* + * Various fields which are a bitmap in the C ABI are converted to lists of + * integers in the Ocaml ABI for more idiomatic handling. + */ +static value c_bitmap_to_ocaml_list(unsigned int bitmap) +{ + CAMLparam0(); + CAMLlocal2(list, tmp); + + list =3D tmp =3D Val_emptylist; + + for ( unsigned int i =3D 0; bitmap; i++, bitmap >>=3D 1 ) + { + if ( !(bitmap & 1) ) + continue; + + tmp =3D caml_alloc_small(2, Tag_cons); + Field(tmp, 0) =3D Val_int(i); + Field(tmp, 1) =3D list; + list =3D tmp; + } + + CAMLreturn(list); +} + CAMLprim value stub_xc_domain_create(value xch, value config) { CAMLparam2(xch, config); @@ -315,16 +341,25 @@ static value alloc_domaininfo(xc_domaininfo_t * info) Store_field(result, 15, tmp); =20 #if defined(__i386__) || defined(__x86_64__) - /* emulation_flags: x86_arch_emulation_flags list; */ - tmp =3D emul_list =3D Val_emptylist; - for (i =3D 0; i < 10; i++) { - if ((info->arch_config.emulation_flags >> i) & 1) { - tmp =3D caml_alloc_small(2, Tag_cons); - Field(tmp, 0) =3D Val_int(i); - Field(tmp, 1) =3D emul_list; - emul_list =3D tmp; - } - } + /* + * emulation_flags: x86_arch_emulation_flags list; + * + * These BUILD_BUG_ON()'s map the C ABI to the Ocaml ABI. If they + * trip, xenctrl.ml{,i} need updating to match. + */ + BUILD_BUG_ON(XEN_X86_EMU_LAPIC !=3D (1u << 0)); + BUILD_BUG_ON(XEN_X86_EMU_HPET !=3D (1u << 1)); + BUILD_BUG_ON(XEN_X86_EMU_PM !=3D (1u << 2)); + BUILD_BUG_ON(XEN_X86_EMU_RTC !=3D (1u << 3)); + BUILD_BUG_ON(XEN_X86_EMU_IOAPIC !=3D (1u << 4)); + BUILD_BUG_ON(XEN_X86_EMU_PIC !=3D (1u << 5)); + BUILD_BUG_ON(XEN_X86_EMU_VGA !=3D (1u << 6)); + BUILD_BUG_ON(XEN_X86_EMU_IOMMU !=3D (1u << 7)); + BUILD_BUG_ON(XEN_X86_EMU_PIT !=3D (1u << 8)); + BUILD_BUG_ON(XEN_X86_EMU_USE_PIRQ !=3D (1u << 9)); + BUILD_BUG_ON(XEN_X86_EMU_VPCI !=3D (1u << 10)); + BUILD_BUG_ON(XEN_X86_EMU_ALL !=3D 0x7ff); + emul_list =3D c_bitmap_to_ocaml_list(info->arch_config.emulation_flags); =20 /* xen_x86_arch_domainconfig */ x86_arch_config =3D caml_alloc_tuple(1); @@ -635,7 +670,7 @@ CAMLprim value stub_xc_send_debug_keys(value xch, value= keys) CAMLprim value stub_xc_physinfo(value xch) { CAMLparam1(xch); - CAMLlocal3(physinfo, cap_list, tmp); + CAMLlocal2(physinfo, cap_list); xc_physinfo_t c_physinfo; int r; =20 @@ -646,15 +681,18 @@ CAMLprim value stub_xc_physinfo(value xch) if (r) failwith_xc(_H(xch)); =20 - tmp =3D cap_list =3D Val_emptylist; - for (r =3D 0; r < 2; r++) { - if ((c_physinfo.capabilities >> r) & 1) { - tmp =3D caml_alloc_small(2, Tag_cons); - Field(tmp, 0) =3D Val_int(r); - Field(tmp, 1) =3D cap_list; - cap_list =3D tmp; - } - } + /* + * capabilities: physinfo_cap_flag list; + * + * These BUILD_BUG_ON()'s map the C ABI to the Ocaml ABI. If they + * trip, xenctrl.ml{,i} need updating to match. + */ + BUILD_BUG_ON(XEN_SYSCTL_PHYSCAP_hvm !=3D (1u << 0)); + BUILD_BUG_ON(XEN_SYSCTL_PHYSCAP_pv !=3D (1u << 1)); + BUILD_BUG_ON(XEN_SYSCTL_PHYSCAP_directio !=3D (1u << 2)); + BUILD_BUG_ON(XEN_SYSCTL_PHYSCAP_hap !=3D (1u << 3)); + BUILD_BUG_ON(XEN_SYSCTL_PHYSCAP_MAX !=3D XEN_SYSCTL_PHYSCAP_hap); + cap_list =3D c_bitmap_to_ocaml_list(c_physinfo.capabilities); =20 physinfo =3D caml_alloc_tuple(10); Store_field(physinfo, 0, Val_int(c_physinfo.threads_per_core)); diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index e02d7ce4c6..d4b455619c 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -94,6 +94,9 @@ struct xen_sysctl_tbuf_op { #define _XEN_SYSCTL_PHYSCAP_hap 3 #define XEN_SYSCTL_PHYSCAP_hap (1u<<_XEN_SYSCTL_PHYSCAP_hap) =20 +/* Max XEN_SYSCTL_PHYSCAP_* constant. Used for ABI checking. */ +#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_hap + struct xen_sysctl_physinfo { uint32_t threads_per_core; uint32_t cores_per_socket; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel