From nobody Mon Feb 9 08:10:34 2026 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=1568117106; cv=none; d=zoho.com; s=zohoarc; b=TR5pEaK4nxO/3fuoyIGo91L/9zS2+gentIaJgvwS7dU2Iw77LFqH1pnme9UZ7pp9x5pHNBfonfePh+gudxNU6lc2wtocs3i24QUABKZGL/7h+gPdTKKXvujE6uqzdUBlh++ZcdGdaAfdc9kEP57LRyWWhPabeOWSRk7+RUnv/V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568117106; 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=+HpdmbpWCDWk6UklGEMl1DwEUXcYISbRmlAaVhwdwq0=; b=YseNVTgVViROngXKS9eBOw/iNT+wMD6WEIK029BYq6G0ndvyTaF5anXT3ndZ0U9EYA882eraFHQkm4iKKXJV1kq8dfZGuc0u170jWw8Bw20iJjEPPnxcfXYNZQAXq+iDcIO6rmVvkj3IUk8NbHgKjEg7K4fpJzvQGTTPtGBhAz8= 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 1568117106946803.4535791524157; Tue, 10 Sep 2019 05:05: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 1i7erv-0007JO-13; Tue, 10 Sep 2019 12:03:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7ert-0007J8-Gz for xen-devel@lists.xenproject.org; Tue, 10 Sep 2019 12:03:33 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 023dd3c4-d3c3-11e9-b76c-bc764e2007e4; Tue, 10 Sep 2019 12:03:32 +0000 (UTC) X-Inumbo-ID: 023dd3c4-d3c3-11e9-b76c-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568117012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=GdG1GUx2C2bfbt3BcVZ15QeOPSMirqqexR8VrrfAw6s=; b=UXl1teE3YV5BEGlzGQH/t2mEkEaSGaTTFtUSbVXgtqO1R8DqQyb4uP5h 3ix/t4BuIDWxJo5ronz8xwhG6NLyEhXw/eRPs3gc94a9zjYENPd9vJ+ZP 7PbowH9YgTiSkJBPlqcoxEjN18mxwlC8spaYN6jNmQPuYremuLoI7+/Eh Y=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=ian.jackson@eu.citrix.com; spf=Pass smtp.mailfrom=Ian.Jackson@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 (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of ian.jackson@eu.citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Ian.Jackson@citrix.com"; x-sender="ian.jackson@eu.citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Ian.Jackson@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Ian.Jackson@citrix.com"; x-sender="Ian.Jackson@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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="Ian.Jackson@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: RMCj5lAmd70QmpWWspQZOVhFKv3LcE/W1jMCyh/4rTAPEChXsZ4BJT4IV7h8whV+kVHLBmsI63 7tClAIlcZRK3OhZFZyuULQHbei8t3wVgTsVqIsLuFt13idMkoKFibOlOd5g9f5ax/b4hxIRgAJ w0QSH+Ibomu3KR45F0pV3VeY8Xbx3XJjzSWkZyZpgtD5u6hOJS3wez/Q2DItgHNrfJ3D9neoNc 1xbFTu7VYbmG4gEnmYujHtQXVdBFLoMAIulO2SDMobs0z5KlD6NnaQlCdSjN3QngFzEERA0mCw K1I= X-SBRS: 2.7 X-MesageID: 5555873 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,489,1559534400"; d="scan'208";a="5555873" From: Ian Jackson To: Date: Tue, 10 Sep 2019 13:01:58 +0100 Message-ID: <20190910120207.10358-4-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190910120207.10358-1-ian.jackson@eu.citrix.com> References: <20190910120207.10358-1-ian.jackson@eu.citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 03/12] tools/ocaml: Introduce xenctrl ABI 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: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Tim Deegan , Ian Jackson , Julien Grall , Andrew Cooper , Christian Lindig , Jan Beulich , David Scott 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_directio without adjusting the Ocaml physinfo_cap_flag enumeration. Add build machinery which will check the ABI correspondence. 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 Signed-off-by: Ian Jackson Acked-by: Christian Lindig Acked-by: Jan Beulich --- .gitignore | 1 + tools/ocaml/libs/xc/Makefile | 5 +++ tools/ocaml/libs/xc/abi-check | 84 +++++++++++++++++++++++++++++++++= ++++ tools/ocaml/libs/xc/xenctrl_stubs.c | 69 +++++++++++++++++++++--------- xen/include/public/sysctl.h | 4 ++ 5 files changed, 143 insertions(+), 20 deletions(-) create mode 100755 tools/ocaml/libs/xc/abi-check diff --git a/.gitignore b/.gitignore index 3c947ac948..3ada0c4f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -392,6 +392,7 @@ tools/ocaml/libs/xentoollog/_xtl_levels.* tools/ocaml/libs/xentoollog/xentoollog.ml tools/ocaml/libs/xentoollog/xentoollog.mli tools/ocaml/libs/xs/paths.ml +tools/ocaml/libs/xc/xenctrl_abi_check.h tools/ocaml/xenstored/_paths.h tools/ocaml/xenstored/oxenstored tools/ocaml/xenstored/oxenstored.conf diff --git a/tools/ocaml/libs/xc/Makefile b/tools/ocaml/libs/xc/Makefile index d24b0144d0..ac780627d2 100644 --- a/tools/ocaml/libs/xc/Makefile +++ b/tools/ocaml/libs/xc/Makefile @@ -31,4 +31,9 @@ install: $(LIBS) META uninstall: $(OCAMLFIND) remove -destdir $(OCAMLDESTDIR) xenctrl =20 +xenctrl_stubs.o: xenctrl_abi_check.h + +xenctrl_abi_check.h: abi-check xenctrl_stubs.c xenctrl.ml + $(PERL) -w $^ >$@.tmp && mv -f $@.tmp $@ + include $(TOPLEVEL)/Makefile.rules diff --git a/tools/ocaml/libs/xc/abi-check b/tools/ocaml/libs/xc/abi-check new file mode 100755 index 0000000000..c987cd8454 --- /dev/null +++ b/tools/ocaml/libs/xc/abi-check @@ -0,0 +1,84 @@ +#!/usr/bin/perl -w + +use strict; +use Data::Dumper; + +our %enums; + +@ARGV =3D=3D 2 or die; +our ($c, $o) =3D @ARGV; + +open STDIN, "<", $c or die $!; + +our $cline =3D -1; +our $ei; + +while (<>) { + if ($cline =3D=3D -1) { + if (m/c_bitmap_to_ocaml_list/) { + $cline =3D 0; + $ei =3D { }; + } + } else { + $cline++; + m{^\s+/\* \s+ ! \s+ (.*?) \s* \*/\s*$}x or die "$cline $_ ?"; + my @vals =3D split /\s+/, $1; + if ($cline =3D=3D 1 && !@vals) { + $cline =3D -1; + } elsif ($cline =3D=3D 1 && @vals =3D=3D 3) { + $ei->{$_} =3D shift @vals foreach qw(OType OPrefix Mangle); + } elsif ($cline =3D=3D 2 && @vals =3D=3D 3) { + $ei->{$_} =3D shift @vals foreach qw(CPrefix CFinal CFinalHow); + die if $enums{ $ei->{OType} }; + $enums{ $ei->{OType} } =3D $ei; + $cline =3D -1; + } else { + die "$_ ?"; + } + } +} + +sub expect ($$) { + printf "BUILD_BUG_ON( %-30s !=3D %-10s );\n", @_ or die $!; +} + +open STDIN, "<", $o or die $!; +my $cval; +$ei =3D undef; +my $bitnum =3D 0; +while (<>) { + if (!$ei) { + if (m{^type \s+ (\w+) \s* \=3D \s* $/}x && $enums{$1}) { + $ei =3D $enums{$1}; + $cval =3D ''; + $bitnum =3D 0; + } + } else { + if (m{^\s+ \| \s* $ei->{OPrefix} (\w+) \s*$}x) { + $cval =3D $1; + if ($ei->{Mangle} eq 'lc') { + $cval =3D lc $cval; + } elsif ($ei->{Mangle} eq 'none') { + } else { + die; + } + $cval =3D $ei->{CPrefix}.$cval; + expect($cval, "(1u << $bitnum)"); + $bitnum++; + } elsif (m/^\w|\{/) { + if ($ei->{CFinalHow} eq 'max') { + expect($ei->{CFinal}, "(1u << ".($bitnum-1).")"); + } elsif ($ei->{CFinalHow} eq 'all') { + expect($ei->{CFinal}, "(1u << $bitnum)-1u"); + } else { + die Dumper($ei)." ?"; + } + $ei =3D undef; + } elsif (!m{\S}) { + } else { + die "$_ ?"; + } + } +} + +close STDOUT or die $!; diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 2e1b29ce33..352a6bd2d6 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,39 @@ 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 + /* ! */ + /* + * All calls to this function must be in a form suitable + * for xenctrl_abi_check. The parsing there is ad-hoc. + */ + (unsigned int bitmap) +{ + CAMLparam0(); + CAMLlocal2(list, tmp); + +#include "xenctrl_abi_check.h" + + 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 +349,13 @@ 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; + */ + emul_list =3D c_bitmap_to_ocaml_list + /* ! x86_arch_emulation_flags X86_EMU_ none */ + /* ! XEN_X86_EMU_ XEN_X86_EMU_ALL all */ + (info->arch_config.emulation_flags); =20 /* xen_x86_arch_domainconfig */ x86_arch_config =3D caml_alloc_tuple(1); @@ -635,7 +666,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 +677,13 @@ 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; + */ + cap_list =3D c_bitmap_to_ocaml_list + /* ! physinfo_cap_flag CAP_ lc */ + /* ! XEN_SYSCTL_PHYSCAP_ XEN_SYSCTL_PHYSCAP_MAX max */ + (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 36b3f8c429..5401f9c2fe 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -90,6 +90,10 @@ struct xen_sysctl_tbuf_op { /* The platform supports direct access to I/O devices with IOMMU. */ #define _XEN_SYSCTL_PHYSCAP_directio 2 #define XEN_SYSCTL_PHYSCAP_directio (1u<<_XEN_SYSCTL_PHYSCAP_directio) + +/* Max XEN_SYSCTL_PHYSCAP_* constant. Used for ABI checking. */ +#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_directio + 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