From nobody Mon Feb 9 03:14:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1686324874; cv=none; d=zohomail.com; s=zohoarc; b=D8U1b2lmZICKhChtxqO2fAraQjXlKagUtXGINoCsp635Gt8CtRvN1hQ5U05DOiwn/mt7h493K2HYZ+jHYulgDD8ptt/0Nz/dopSA49ege5ncO1eaJuclVnQsuSkYfGhHzpgO0ntDBL2iL5wVUVRKEVssPEvgxH4PrH3yanXSjmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686324874; 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; bh=bPguMtlISwPJyjgfrH3Zmt5rgz4SyMlLFazM5PQJvnQ=; b=eAH+QQ7yY8j/BkV8rdibtxlTsSTpZ9oRR3FAMnjJCiQ7y3insM86mTSBTboGZkcLhxh+CH0Y3BlcqGsRr+8E7P7KcLCWCVW5i6PTYIEoR06BuIZuz3x6aLrQDYZp58vOD+BBapsemTuIYy32FowC7mV31dmSW6xyvmzedwXXxvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686324874543921.6058553693729; Fri, 9 Jun 2023 08:34:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.546161.852816 (Exim 4.92) (envelope-from ) id 1q7e7o-0002do-OE; Fri, 09 Jun 2023 15:34:04 +0000 Received: by outflank-mailman (output) from mailman id 546161.852816; Fri, 09 Jun 2023 15:34:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q7e7o-0002dh-L0; Fri, 09 Jun 2023 15:34:04 +0000 Received: by outflank-mailman (input) for mailman id 546161; Fri, 09 Jun 2023 15:34:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q7e7o-0002db-0i for xen-devel@lists.xenproject.org; Fri, 09 Jun 2023 15:34:04 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0e26d241-06db-11ee-b232-6b7b168915f2; Fri, 09 Jun 2023 17:34:02 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0e26d241-06db-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1686324842; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=9g2HVasZifNxLi5ro/3MzuJQsziytjBtL1Bo+gVBQE8=; b=EAVEbRs5m5yqupLiHRVvRRsRvNOQPDqxkvwOHvNV8h1WNMCGYaMWey/Z fYLqMu1UOl1G1pl3P3Snzh48RYl08ZO8fDF3mYxq5sABcRwT6RASInlB0 zgRR5S/MEtT0zL33mDAJuvWUhHNduC4uiQ0WPtdDE8HEaB17/574+X2VZ I=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 112245805 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:LT0OxqynkPCY4Zd/qqd6t+c3xirEfRIJ4+MujC+fZmUNrF6WrkVTy 2JOW2CFOa7bNzD9Looia4jlpk9XscLTzNNlTgZqqCAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTrafYEidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw/zF8EsHUMja4mtC5QRgPaET5TcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KTp1+ cUUDigEVDaG2eOE+amjQdgyr9t2eaEHPKtH0p1h5TTQDPJgSpHfWaTao9Rf2V/chOgXQ6yYP ZBAL2MyMlKZOUYn1lQ/UfrSmM+BgHXlfiIeg1WSvactuEDYzRBr0airO93QEjCPbZwMxBzE+ zKeogwVBDkbJNe002va4068ocLBljm4aKkKF6WRo6sCbFq7mTVIVUx+uUGAiem0jAuyVsxSL 2QQ+zEytu4i+UqzVN7/Uhak5nmesXY0X8dbGqs04QeGx67Q/i6QHG1CRTlEAOHKr+dvG2Zsj AXQ2Yq0W3o26ub9pW+hGqm89gi+ACQzNWY4QypaTDk8+MHokd8akUeaJjp8K5KdgtrwEDD25 jmFqikimrke5fI2O7WHEUPv2Gz1+MWQJuIhzkCOBz/+sFslDGKwT9bwgWU3+8qsO2pworOpm HEf0/aT4+kVZX1mvHzcGb5ddF1FChvsDdE9vbKMN8N7n9hIx5JEVd443d2GDB01WvvogBewC KMphStf5YVIIFyhZrJtboS6BqwClPawS465B6qOM4UVMvCdkTNrGwk0PCatM53FyhBwwcnTx 7/GGSpTMZrqIfs+l2fnLwvs+bQq2jo/1QvuqWPTlnyaPU6lTCfNE98taQLeBt3VGYvY+G05B f4DbZrVo/ieOcWiChTqHXk7dAhVdCNjW8un86S6tIere2JbJY3oMNeJqZtJRmCvt/49ejvgl p1lZnJl9Q== IronPort-HdrOrdr: A9a23:MAw2Wayy1tZEq+Zi1cfwKrPw6L1zdoMgy1knxilNoHxuH/Bw9v re+cjzsCWftN9/Yh4dcLy7VpVoIkmsl6Kdg7NwAV7KZmCP1FdARLsI0WKI+UyCJ8SRzI9gPa cLSdkFNDXzZ2IK8PoTNmODYqodKNrsytHWuQ/HpU0dKT2D88tbnn9E4gDwKDwQeCB2QaAXOb C7/cR9qz+paR0sH7+G7ilsZZmkmzXT/qiWGCI7Ow== X-Talos-CUID: 9a23:K+Lps2Oc/bhuHu5DAxJrzUIyAskfVHiDzUXpOFezODhAV+jA X-Talos-MUID: 9a23:ayPVuQklK3xoqu2pBHbrdnpjJMxD+fXxGXwdtrgIsNPHBQdoOC+02WE= X-IronPort-AV: E=Sophos;i="6.00,229,1681185600"; d="scan'208";a="112245805" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Christian Lindig , Christian Lindig , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Rob Hoes , Luca Fancellu Subject: [PATCH v2] tools/ocaml/xc: Fix xc_physinfo() bindings Date: Fri, 9 Jun 2023 16:33:55 +0100 Message-ID: <20230609153355.2637469-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1686324880056100001 The original change doesn't compile on ARM: xenctrl_stubs.c: In function 'stub_xc_physinfo': xenctrl_stubs.c:821:16: error: unused variable 'arch_cap_flags_tag' [-Wer= ror=3Dunused-variable] 821 | int r, arch_cap_flags_tag; | ^~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors but it was buggy too. First, it tried storing an int in a pointer slot, causing heap corruption. Next, it is not legitimate to exclude arm32 in the toolstack as it explicit= ly can operate an arm64 toolstack and build arm64 domains. That in turn means that you can't stash a C uint32_t in an OCaml int. Rewrite the arch_capabilities handling from scratch. Break it out into a separate function, and make the construction of arch_physinfo_cap_flags com= mon to prevent other indirection bugs. Reintroduce arm_physinfo_caps with the fields broken out. Fixes: 56a7aaa16bfe ("tools: add physinfo arch_capabilities handling for Ar= m") Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes CC: Luca Fancellu v2: * CAMLreturn(). Tested on x86 locally. Tested on arm64 with: https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/4447272476 and a tweaked form of my local ocaml smoke test for these kinds of things: # osmoke Xen version: 4.18-unstable Physinfo: threads_per_core 1 SVE len: 0 Starting GC.compact() Done I didn't get this working for arm32, because that's all Yocto, but the arm64 test is good enough IMO. --- tools/ocaml/libs/xc/xenctrl.ml | 7 +++- tools/ocaml/libs/xc/xenctrl.mli | 7 +++- tools/ocaml/libs/xc/xenctrl_stubs.c | 52 ++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index bf23ca50bb15..d6c6eb73db44 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -128,10 +128,15 @@ type physinfo_cap_flag =3D | CAP_Gnttab_v1 | CAP_Gnttab_v2 =20 +type arm_physinfo_caps =3D + { + sve_vl: int; + } + type x86_physinfo_cap_flag =20 type arch_physinfo_cap_flags =3D - | ARM of int + | ARM of arm_physinfo_caps | X86 of x86_physinfo_cap_flag list =20 type physinfo =3D diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.= mli index ed1e28ea30a0..3bfc16edba96 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -113,10 +113,15 @@ type physinfo_cap_flag =3D | CAP_Gnttab_v1 | CAP_Gnttab_v2 =20 +type arm_physinfo_caps =3D + { + sve_vl: int; + } + type x86_physinfo_cap_flag =20 type arch_physinfo_cap_flags =3D - | ARM of int + | ARM of arm_physinfo_caps | X86 of x86_physinfo_cap_flag list =20 type physinfo =3D { diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index a03da31f6f2c..e4d9070f2d00 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -812,13 +812,46 @@ CAMLprim value stub_xc_send_debug_keys(value xch_val,= value keys) CAMLreturn(Val_unit); } =20 +CAMLprim value physinfo_arch_caps(const xc_physinfo_t *info) +{ + CAMLparam0(); + CAMLlocal2(arch_cap_flags, arch_obj); + int tag =3D -1; + +#if defined(__arm__) || defined(__aarch64__) + + tag =3D 0; /* tag ARM */ + + arch_obj =3D caml_alloc_tuple(1); + + Store_field(arch_obj, 0, + Val_int(MASK_EXTR(info->arch_capabilities, + XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK) * 128)); + +#elif defined(__i386__) || defined(__x86_64__) + + tag =3D 1; /* tag x86 */ + + arch_obj =3D Tag_cons; + +#endif + + if ( tag < 0 ) + caml_failwith("Unhandled architecture"); + + arch_cap_flags =3D caml_alloc_small(1, tag); + Store_field(arch_cap_flags, 0, arch_obj); + + CAMLreturn(arch_cap_flags); +} + CAMLprim value stub_xc_physinfo(value xch_val) { CAMLparam1(xch_val); - CAMLlocal4(physinfo, cap_list, arch_cap_flags, arch_cap_list); + CAMLlocal2(physinfo, cap_list); xc_interface *xch =3D xch_of_val(xch_val); xc_physinfo_t c_physinfo; - int r, arch_cap_flags_tag; + int r; =20 caml_enter_blocking_section(); r =3D xc_physinfo(xch, &c_physinfo); @@ -846,20 +879,7 @@ CAMLprim value stub_xc_physinfo(value xch_val) Store_field(physinfo, 7, caml_copy_nativeint(c_physinfo.scrub_pages)); Store_field(physinfo, 8, cap_list); Store_field(physinfo, 9, Val_int(c_physinfo.max_cpu_id + 1)); - -#if defined(__i386__) || defined(__x86_64__) - arch_cap_list =3D Tag_cons; - - arch_cap_flags_tag =3D 1; /* tag x86 */ - - arch_cap_flags =3D caml_alloc_small(1, arch_cap_flags_tag); - Store_field(arch_cap_flags, 0, arch_cap_list); - Store_field(physinfo, 10, arch_cap_flags); -#elif defined(__aarch64__) - Store_field(physinfo, 10, Val_int(c_physinfo.arch_capabilities)); -#else - caml_failwith("Unhandled architecture"); -#endif + Store_field(physinfo, 10, physinfo_arch_caps(&c_physinfo)); =20 CAMLreturn(physinfo); } --=20 2.30.2