From nobody Sat Sep 21 03:20:00 2024 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=1675200598; cv=none; d=zohomail.com; s=zohoarc; b=I4bf9Bm1EVOegR0Oh1btktHzG5wfpMjMhO+4GxlEeAo8Ceu1R/MQjznfoBP6dm1jNsbYuf1tTFcZkAUOeWoQy+gCsuEmmJUM7i5ONLMtBFJ4UY4Urxu38JKphtlJi3rxzfb5HZ8c+gr/O02QJ89yCUiobLHyqqqiiUHOtjiA+j0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200598; 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=p20tHrivnSUo0jYxnH2bA88tSc5sKQutOOnFgLtA//4=; b=LB+jqfzSk7xCRHD57HOUKvgTUVB45r8sNiXfeJKWfwfdxKIn3/g8fiDpGHgyrVr/hrttd7A4DXT1BXV9CEHq083HEFb2AiVL725ah4b5r8q1JZbEZUAhUk+YjLumEmRFOJUwH6tFUwfuKKCXm2Zf48MDSdg6Nglqh1Ud/RuQJu8= 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 1675200598700799.5175707723296; Tue, 31 Jan 2023 13:29:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487844.755557 (Exim 4.92) (envelope-from ) id 1pMyC4-0000Nz-6D; Tue, 31 Jan 2023 21:29:32 +0000 Received: by outflank-mailman (output) from mailman id 487844.755557; Tue, 31 Jan 2023 21:29:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC4-0000Ns-23; Tue, 31 Jan 2023 21:29:32 +0000 Received: by outflank-mailman (input) for mailman id 487844; Tue, 31 Jan 2023 21:29:30 +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 1pMyC2-0000Nb-CI for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:30 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 54e58ec1-a1ae-11ed-933c-83870f6b2ba8; Tue, 31 Jan 2023 22:29:28 +0100 (CET) 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: 54e58ec1-a1ae-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jNU72Uu2tmrcqHFCNgIV8t/XfjcVgtHdUCV/DbhunZ0=; b=QMTAIaJm5uUkfYsHhHh2hOmT50uppvvn2vGnDBTiyGu9DAV8jDMUCRHI deD4VWRrMcJ8iF4eZBFHj1uUyUTGWch1DkfbvylTBb428J9UtTjolI0s9 +3zUzq1u89Eb8QCyeAhb3jWz95EGclaGS6TXrvLTyzEadp/LYwBXR092n 4=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95499176 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:DRPIu6rBBa1a1sQTvyEoYRPaRKNeBmIZZRIvgKrLsJaIsI4StFCzt garIBmGOayJYmr3L4onPYrg9k1XucfSz4BjHQZtrC9kQy0WoJuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpAFc+E0/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06WxwUmAWP6gR5weHzCBNV/rzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXABkVS0ixwMCo+auyR+VI3ZgKHvv6BapK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFOUslWcOSA3xETdxVxrl6PqLVxyG/U1AFri5DmMcbPe8zMTsJQ9qqdj jObozWoW05EXDCZ4XmM3SylpNbppgPcQLIbD6y90aJ7gULGkwT/DzVJDADm8JFVkHWWS99Zb kAZ5Ccqhawz71CwCMnwWQWip3yJtQJaXMBfe8U24R+A4rDZ6AGYAi4DVDEpVTA9nJZoH3pwj AbPxo63Q2U169V5VE5x6J+9tRbqC283M1YbbCIIaVBZyuvRsbga20enoslYLIa5idj8GDfVy j+MrTQji7h7sfPnx5lX7nic3Wvy+8Ghohodo1yOAzn7tl8RiJuNPdTA1LTN0RpXwG91pHGlt WNMpcWR5ftm4XqlxH3UG7Vl8F1ECp+43NzgbbxHRcFJG9eFoSTLkWVsDNZWei9U3j4sI2OBX aMqkVo5CGVvFHWrd7RrRIm6Ft4ny6Ptffy8CK+JN4sWOsAsLlXYlM2LWaJ39zm9+HXAbIllY cvLGSpSJSly5VtbIMqeGL5GjO5DKtEWzmLPX5HrpylLIpLHDEN5vYwtaQPUBshgtfPsnekg2 4oHXyd840kFAbKWj+i+2dJ7EG3m2lBgXMyo8JMKKrTTSuekcUl4Y8LsLXoaU9QNt8xoei3gp xlRhmcwJILDuED6 IronPort-HdrOrdr: A9a23:zKvS1q9/wraM3VeHjKxuk+HBdr1zdoMgy1knxilNoENuH/Bwxv rFoB1E73TJYW4qKQkdcdDpAsm9qADnhOVICOgqTP6ftWbdyQ+Vxe1Zg7cKhgeQYhEWldQtnZ uIEZIOb+EYZGIS5aqU3OD7KadH/DDtytHKuQ6q9QYJcegcUdAD0+4WMGemO3wzYDMDKYsyFZ Ka6MYCjz28eU4PZsD+KmgZU/PFr9jrkoujRRIdHRYo5CSHkDvtsdfBYlKl9yZbdwkK7aYp8G DDnQC8zqK/s8ujwhuZ+37P449QkN7BzMIGIMCXkMAaJhjllw7tToV8XL+puiwzvYiUmR0Xue iJhy1lE9V46nvXcG3wiwDqwRPc3DEn7GKn4UOEgFP4yPaJCA4SOo5kv8Z0YxHZ400vsJVXy6 RQxV+UsJJREFfpgDn93d7VTBtn/3DE7kbK0NRjwUC3Y7FuKIO5nrZvv3+9161wXh4S3bpXUd WGyvusocq+P2nqK0wx9VMfuuBEFk5DYytuBHJy9/B9mgIm4ExR3g8WwtcSkWwH8494Q55Y5/ 7cOqAtj71WSNQKBJgNcNvpbPHHeFAleyi8RV66MBDiDuUKKnjNo5n47PE84/yrYoUByN83lI 7aWF1VuGYucwa2YPf+qqFj41TIWiGwTD7twsZR69xwvaD9XqPiNWmGREo1m8Wtrv0DConQWu q1OphRH/j/RFGebrphzkn7Qd1fOHMeWMoatpIyXE+PuNvCLsnwuunSYJ/oVcnQ+PYfKxPC61 c4LUnOzZ97nz+Ws1fD8WbsZ08= X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95499176" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Andrew Cooper , Christian Lindig , David Scott , Rob Hoes Subject: [PATCH 1/7] tools/ocaml/libs: Don't declare stubs as taking void Date: Tue, 31 Jan 2023 21:29:07 +0000 Message-ID: <20230131212913.6199-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200599685100005 From: Edwin T=C3=B6r=C3=B6k There is no such thing as an Ocaml function (C stub or otherwise) taking no parameters. In the absence of any other parameters, unit is still passed. This doesn't explode with any ABI we care about, but would malfunction for = an ABI environment such as stdcall. Fixes: c3afd398ba7f ("ocaml: Add XS bindings.") Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.") Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/xb/xenbus_stubs.c | 5 ++--- tools/ocaml/libs/xc/xenctrl_stubs.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/ocaml/libs/xb/xenbus_stubs.c b/tools/ocaml/libs/xb/xenbu= s_stubs.c index 3065181a55e6..97116b07826a 100644 --- a/tools/ocaml/libs/xb/xenbus_stubs.c +++ b/tools/ocaml/libs/xb/xenbus_stubs.c @@ -30,10 +30,9 @@ #include #include =20 -CAMLprim value stub_header_size(void) +CAMLprim value stub_header_size(value unit) { - CAMLparam0(); - CAMLreturn(Val_int(sizeof(struct xsd_sockmsg))); + return Val_int(sizeof(struct xsd_sockmsg)); } =20 CAMLprim value stub_header_of_string(value s) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 2fba9c5e94d6..728818445975 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -86,9 +86,9 @@ static void Noreturn failwith_xc(xc_interface *xch) caml_raise_with_string(*caml_named_value("xc.error"), error_str); } =20 -CAMLprim value stub_xc_interface_open(void) +CAMLprim value stub_xc_interface_open(value unit) { - CAMLparam0(); + CAMLparam1(unit); CAMLlocal1(result); xc_interface *xch; =20 --=20 2.11.0 From nobody Sat Sep 21 03:20:00 2024 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=1675200598; cv=none; d=zohomail.com; s=zohoarc; b=ayaif7PsjhBCt5DY4Jfu4Ing3ajm84yKBag0QCGZvebTRkkzErqLCn+ZiL/yBEEHgTfBhFsfde9hojMLUd5/JmBd0QOQMvaxrOND9sUf/8prrDpdsX9bTsRYUp6yadYuEYZ8tg1CHNCZPTUjJ7UP/0yBlV/ZzJKzWAV4J0dkGOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200598; 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=QUeB6tNZE7IPjyugDVSD0+aF2N6eaF/lZ2cncven+CI=; b=Nkq8lF1jA8ObldhR8g6WvZrPMjCA4B7VQPZ39A9WHlF3u4BAGpwVAE3OUtUARXtU9u6atTZMXHSZZZ055T8paaiE1wmMZY3P6rFxPagm/jIRbSyw6m0259WiJ7eODvowDH25B+1spcMg1fhn2Ozgod270iqNQqLarFep7rrA0D8= 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 1675200597993890.4645723203801; Tue, 31 Jan 2023 13:29:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487847.755590 (Exim 4.92) (envelope-from ) id 1pMyC6-00015d-35; Tue, 31 Jan 2023 21:29:34 +0000 Received: by outflank-mailman (output) from mailman id 487847.755590; Tue, 31 Jan 2023 21:29:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC5-000159-Ty; Tue, 31 Jan 2023 21:29:33 +0000 Received: by outflank-mailman (input) for mailman id 487847; Tue, 31 Jan 2023 21:29:32 +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 1pMyC4-0000Nb-Kh for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:32 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 58eef30c-a1ae-11ed-933c-83870f6b2ba8; Tue, 31 Jan 2023 22:29:31 +0100 (CET) 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: 58eef30c-a1ae-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h6tenPYxyZVuTbfcgU9nfxQU9sqSsuEBVjFHdCiT8ok=; b=ZqQqvOdX5KKbbBc3TH9V8JrKxTvwFWztDm1k7EmLlFMal2Qc2wD+TqMZ MZj+V/IaN4scW7KbBhxfC/5ayssWolx4KVrtyEtccb5tDt0lvvDBvtvEV N8h6tAFJtwyY9c0q7TKebPETQ/bQV7g9QRc9QqhlA2PoLcfTTsmXI2xWG U=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95499179 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:dbqxyaKz/vJ8W1YuFE+R0JUlxSXFcZb7ZxGr2PjKsXjdYENShDMOz 2QcXGCPaPuNajDyKNkiPYmy8E1S6JTWm4MyQVBlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHv+kUrWs1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPcwP9TlK6q4mhA5wdnPasjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5eGUQWx 7s6NgkUZx2Po7nq6YCJW9BF05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGQpNU6bC/FMEg5/5JYWteGknHTgNRZfr0qYv/Ef6GnP1g1hlrPqNbI5f/TbGJkEzx/H9 woq+UziPB9CZYSR+AaI91ypgM70xDrZcYE7QejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasshcCVvJKHuY96QXLzbDbizt1HUBdEGQHMoZ/8pZrG3pzj AThc87V6SJHmaWwEUDa1KmttDq/NQxOcUYwVz49ZF5QizX8m70bghXKR9dlNae6iNzpBD39q wy3QDgCa6Y71pBSifjilbzTq3f1/8WSEFZpjunCdjj9hj6VcrJJcGBBBbLzyf9bZLiUQVCa1 JTvs5jPtbteZX1hecHkfQnsIF1Lz6zdWNE/qQQ1d3XEy9hK0yDLQGyoyGsiTHqFy+5dEdMTX GfduBlK+LhYN2awYKl8buqZUpp1kPGxTYy9C6qOMbKih6SdkyferElTibO4hTixwCDAb4lgU XtkTSpcJSlDUvk2pNZHb+wczaUq1kgDKZD7HPjGI+Cc+ePGPha9EO5VWGZim8hltMtoVi2Jq YcAXyZLoj0DONDDjt7/qtdPcwtVcCRhVfgbaaV/L4a+H+avI0l5Y9e5/F/rU9UNc3h9/gsQw kyAZw== IronPort-HdrOrdr: A9a23:x/ZWIKsggLX9ZL7yRf0m/2E77skCb4Aji2hC6mlwRA09TyXGra 2TdaUgvyMc1gx7ZJh5o6H5BEGBKUm9yXcH2/hrAV7CZniuhILGFvAH0WKP+VPd8mjFh5dgPM RbAuBD4b/LfD9HZK/BiWHVfOrIguP3lpxA7t2urEuFODsaDp2ImD0JaDpzfHcWeCB2Qb4CUL aM7MtOoDStPVwRc8SAH3EAG8TTutHRk5riQBgeQzoq8hOHgz+E4KPzV0Hw5GZVbxp/hZMZtU TVmQ3w4auu99m91x/nzmfWq7hGhdf7zdNHJcqUzuwYMC/lhAqEbJloH5eCoDc2iuey70tCqq iGnz4Qe+BIr1/BdGC8phXgnyP61iw11nPkwViExVP+vM3QXlsBeoZ8rLMcViGcx1srvdl63q 4O9XmerYBrARTJmzm4z8TUVittilG/rRMZ4KEuZj1kIMUjgY1q3MwiFXBuYdQ99eXBmcIa+d xVfYDhDTBtABanhj7izy1SKZeXLw4O91+9MzU/U4quonVrdTlCvjcl7d1akXEa+J0nTZ5Yo+ zCL6RzjblLCtQbdKRnGY46ML+K40H2MGDx2VipUCHaPbBCP2iIp4/84b0z6u3vcJsUzIEqkJ CEVF9Dr2Y9d0/nFMXLhfRwg2bwaXT4WS6oxtBV5pB/tLG5TL33MTebQFRrl8e7uf0QDsDSRv 72MpNLBP3oK3foBO9yrnrDcogXLWNbXNweu949VV7LqsXXKpfyvuiea/rXLKqFK0dWZoo+OA pyYNHeHrQw0qnwYA6GvPH4YQKSRnDC X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95499179" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Christian Lindig , David Scott , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Rob Hoes Subject: [PATCH 2/7] tools/ocaml/libs: Allocate the correct amount of memory for Abstract_tag Date: Tue, 31 Jan 2023 21:29:08 +0000 Message-ID: <20230131212913.6199-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200599494100001 caml_alloc() takes units of Wsize (word size), not bytes. As a consequence, we're allocating 4 or 8 times too much memory. Ocaml has a helper, Wsize_bsize(), but it truncates cases which aren't an exact multiple. Use a BUILD_BUG_ON() to cover the potential for truncation, as there's no rounding-up form of the helper. Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.") Fixes: d3e649277a13 ("ocaml: add mmap bindings implementation.") Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/mmap/Makefile | 2 ++ tools/ocaml/libs/mmap/xenmmap_stubs.c | 6 +++++- tools/ocaml/libs/xc/xenctrl_stubs.c | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/ocaml/libs/mmap/Makefile b/tools/ocaml/libs/mmap/Makefile index a62153713571..855b8b2c9877 100644 --- a/tools/ocaml/libs/mmap/Makefile +++ b/tools/ocaml/libs/mmap/Makefile @@ -2,6 +2,8 @@ OCAML_TOPLEVEL=3D$(CURDIR)/../.. XEN_ROOT=3D$(OCAML_TOPLEVEL)/../.. include $(OCAML_TOPLEVEL)/common.make =20 +CFLAGS +=3D $(CFLAGS_xeninclude) + OBJS =3D xenmmap INTF =3D $(foreach obj, $(OBJS),$(obj).cmi) LIBS =3D xenmmap.cma xenmmap.cmxa diff --git a/tools/ocaml/libs/mmap/xenmmap_stubs.c b/tools/ocaml/libs/mmap/= xenmmap_stubs.c index e03951d781bb..d623ad390e40 100644 --- a/tools/ocaml/libs/mmap/xenmmap_stubs.c +++ b/tools/ocaml/libs/mmap/xenmmap_stubs.c @@ -21,6 +21,8 @@ #include #include "mmap_stubs.h" =20 +#include + #include #include #include @@ -59,7 +61,9 @@ CAMLprim value stub_mmap_init(value fd, value pflag, valu= e mflag, default: caml_invalid_argument("maptype"); } =20 - result =3D caml_alloc(sizeof(struct mmap_interface), Abstract_tag); + BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) !=3D 0); + result =3D caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)), + Abstract_tag); =20 if (mmap_interface_init(Intf_val(result), Int_val(fd), c_pflag, c_mflag, diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 728818445975..fd1f306f0202 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -1031,7 +1031,10 @@ CAMLprim value stub_map_foreign_range(value xch, val= ue dom, uint32_t c_dom; unsigned long c_mfn; =20 - result =3D caml_alloc(sizeof(struct mmap_interface), Abstract_tag); + BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) !=3D 0); + result =3D caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)), + Abstract_tag); + intf =3D (struct mmap_interface *) result; =20 intf->len =3D Int_val(size); --=20 2.11.0 From nobody Sat Sep 21 03:20:00 2024 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=1675200602; cv=none; d=zohomail.com; s=zohoarc; b=ZrG1kj8sc0PFf+d1qruH2lH1FCI25JOhN1OeKdVkyDTSKqHezW4CNBdwLDXCRTT+VP+ZWGvgm2nj+B/FsXatPZk6+Fqdw9Xut8nEeYoS7xX7tZRGNsrRJAWRHBw7zP/WYXc/n0MF6Q5e+F4XPISmBMHgKQpmlzzFufAAqj5I9Hc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200602; 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=uH+4y/GH9LJgD5km3xMcgAzRbQv82T++YAg2mM1qcLM=; b=i9319tN0e3p89Oe6ljduv9reLgmUy2KdfiZ7IVzK8YS6aFGz/v0axpIYp95PKH4+RhYuoFc/TVdnVpsLbTk3wE3gV5bUu/nZy6QFhyDSVwBAemwnpWk//G5+y3ftvJF80dHadhJZOS3DfQJJ+LGrDVeX2BTao5/FyDNANmgfa2c= 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 16752006025402.2275498705336076; Tue, 31 Jan 2023 13:30:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487845.755562 (Exim 4.92) (envelope-from ) id 1pMyC4-0000QS-E2; Tue, 31 Jan 2023 21:29:32 +0000 Received: by outflank-mailman (output) from mailman id 487845.755562; Tue, 31 Jan 2023 21:29:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC4-0000Pl-9d; Tue, 31 Jan 2023 21:29:32 +0000 Received: by outflank-mailman (input) for mailman id 487845; Tue, 31 Jan 2023 21:29:30 +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 1pMyC2-0000Nb-NH for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:30 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 55eb48d0-a1ae-11ed-933c-83870f6b2ba8; Tue, 31 Jan 2023 22:29:28 +0100 (CET) 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: 55eb48d0-a1ae-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Epp3wFTJjIGliIjbWr7uyY/q1naoD6A5ExyqnrFK5rI=; b=UJUr2HlDbZcKqqNgMq7dcLaPSyT+kXj+eeYjDK03mMc1fylKIMJ91E1y TaCNb/sumgXKP+nVlPEe2xdRk53pUKRw01M9gA7M6QMpBLI+LyZCY6qQC eKpIF+bQGFDtYfCUrJFlVkh6B2hfxOLNL7ya53W/Kst+FxGF+K/Fs+6yL M=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95024398 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:V4+TD6+/ZY02RbRFWKniDrUDgX6TJUtcMsCJ2f8bNWPcYEJGY0x3m GRJCz2Gb/iCYGX3fIwgOYiw9UkA6JeByNRrGlNlpSs8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKucYHsZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kIw1BjOkGlA5AdmPKsS5AS2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDkkUy u0nARFdLSqioMmR4ZeHavlmoMcKeZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGOkcUUrsUIMtWcOOAr3/zaTBH7nmSorI6+TP7xw1tyrn9dtHSf7RmQO0Ewx7C+ jmXrwwVBDlACIyBxheP60umj96I3gDhVLIfL4ano6sCbFq7mTVIVUx+uUGAiem0jAuyVsxSL 2QQ+zEytu4i+UqzVN7/Uhak5nmesXY0V9NOHsUg5QqKy66S5ByWblXoVRYYNoZg7pVvA2V3i BnQxYiB6SFTXKO9E02MyZ61/XCIGA8+Ck4nWQ8URy0Gyoy2yG0stS7nQtFmGa+zq9T6HzDs3 jyHxBQDa6UvYd0jjPviow2e6964jt2QF1NuuF2LNo6wxlkhDLNJcbBE/rQyARxoCI+CBmeMs 3Ef8yR1xLBfVMrd/MBhrQhkIV1I2xpnGGeE6bKMN8N7n9hIx5JEVd443d2GDB01WvvogBewC KMphStf5YVIIFyhZrJtboS6BqwClPa/SI20DqiMM4AUPfCdkTNrGwk3NSatM53FyhBwwcnTx 7/EGSpTMZrqIfs+l2fnLwvs+bQq2jo/1QvuqWPTlnyaPU6lTCfNE98taQLeBt3VGYvY+G05B f4DbZrVo/ieOcWiChTqHXk7dglWcyNkWMys+6S6tIere2JbJY3oMNeJqZtJRmCvt/09ejvgl p1lZnJl9Q== IronPort-HdrOrdr: A9a23:9jBw2K20Bzub96R4VOQEwAqjBEgkLtp133Aq2lEZdPU0SKGlfg 6V/MjztCWE7Ar5PUtLpTnuAsa9qB/nm6KdgrNhWItKPjOW21dARbsKheffKlXbcBEWndQtt5 uIHZIeNDXxZ2IK8PoT4mODYqodKA/sytHWuQ/cpU0dMz2Dc8tbnmBE4p7wKDwMeOFBb6BJcq a01458iBeLX28YVci/DmltZZm4mzWa/KiWGCLvHnQcmXGzsQ8= X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95024398" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Andrew Cooper , Christian Lindig , David Scott , Rob Hoes Subject: [PATCH 3/7] tools/ocaml/evtchn: Don't reference Custom objects with the GC lock released Date: Tue, 31 Jan 2023 21:29:09 +0000 Message-ID: <20230131212913.6199-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200603661100012 From: Edwin T=C3=B6r=C3=B6k The modification to the _H() macro for Ocaml 5 support introduced a subtle bug. From the manual: https://ocaml.org/manual/intfc.html#ss:parallel-execution-long-running-c-= code "After caml_release_runtime_system() was called and until caml_acquire_runtime_system() is called, the C code must not access any OCa= ml data, nor call any function of the run-time system, nor call back into OCaml code." Previously, the value was a naked C pointer, so dereferencing it wasn't "accessing any Ocaml data", but the fix to avoid naked C pointers added a layer of indirection through an Ocaml Custom object, meaning that the common pattern of using _H() in a blocking section is unsafe. In order to fix: * Drop the _H() macro and replace it with a static inline xce_of_val(). * Opencode the assignment into Data_custom_val() in the two constructors. * Rename "value xce" parameters to "value xce_val" so we can consistently have "xenevtchn_handle *xce" on the stack, and obtain the pointer with t= he GC lock still held. Fixes: 22d5affdf0ce ("tools/ocaml/evtchn: OCaml 5 support, fix potential re= source leak") Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 60 ++++++++++++++++-------= ---- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/li= bs/eventchn/xeneventchn_stubs.c index aa8a69cc1ecb..d7881ca95f98 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c +++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c @@ -33,11 +33,14 @@ #include #include =20 -#define _H(__h) (*((xenevtchn_handle **)Data_custom_val(__h))) +static inline xenevtchn_handle *xce_of_val(value v) +{ + return *(xenevtchn_handle **)Data_custom_val(v); +} =20 static void stub_evtchn_finalize(value v) { - xenevtchn_close(_H(v)); + xenevtchn_close(xce_of_val(v)); } =20 static struct custom_operations xenevtchn_ops =3D { @@ -68,7 +71,7 @@ CAMLprim value stub_eventchn_init(value cloexec) caml_failwith("open failed"); =20 result =3D caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 0, 1); - _H(result) =3D xce; + *(xenevtchn_handle **)Data_custom_val(result) =3D xce; =20 CAMLreturn(result); } @@ -87,18 +90,19 @@ CAMLprim value stub_eventchn_fdopen(value fdval) caml_failwith("evtchn fdopen failed"); =20 result =3D caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 0, 1); - _H(result) =3D xce; + *(xenevtchn_handle **)Data_custom_val(result) =3D xce; =20 CAMLreturn(result); } =20 -CAMLprim value stub_eventchn_fd(value xce) +CAMLprim value stub_eventchn_fd(value xce_val) { - CAMLparam1(xce); + CAMLparam1(xce_val); CAMLlocal1(result); + xenevtchn_handle *xce =3D xce_of_val(xce_val); int fd; =20 - fd =3D xenevtchn_fd(_H(xce)); + fd =3D xenevtchn_fd(xce); if (fd =3D=3D -1) caml_failwith("evtchn fd failed"); =20 @@ -107,13 +111,14 @@ CAMLprim value stub_eventchn_fd(value xce) CAMLreturn(result); } =20 -CAMLprim value stub_eventchn_notify(value xce, value port) +CAMLprim value stub_eventchn_notify(value xce_val, value port) { - CAMLparam2(xce, port); + CAMLparam2(xce_val, port); + xenevtchn_handle *xce =3D xce_of_val(xce_val); int rc; =20 caml_enter_blocking_section(); - rc =3D xenevtchn_notify(_H(xce), Int_val(port)); + rc =3D xenevtchn_notify(xce, Int_val(port)); caml_leave_blocking_section(); =20 if (rc =3D=3D -1) @@ -122,15 +127,16 @@ CAMLprim value stub_eventchn_notify(value xce, value = port) CAMLreturn(Val_unit); } =20 -CAMLprim value stub_eventchn_bind_interdomain(value xce, value domid, +CAMLprim value stub_eventchn_bind_interdomain(value xce_val, value domid, value remote_port) { - CAMLparam3(xce, domid, remote_port); + CAMLparam3(xce_val, domid, remote_port); CAMLlocal1(port); + xenevtchn_handle *xce =3D xce_of_val(xce_val); xenevtchn_port_or_error_t rc; =20 caml_enter_blocking_section(); - rc =3D xenevtchn_bind_interdomain(_H(xce), Int_val(domid), Int_val(remote= _port)); + rc =3D xenevtchn_bind_interdomain(xce, Int_val(domid), Int_val(remote_por= t)); caml_leave_blocking_section(); =20 if (rc =3D=3D -1) @@ -140,14 +146,15 @@ CAMLprim value stub_eventchn_bind_interdomain(value x= ce, value domid, CAMLreturn(port); } =20 -CAMLprim value stub_eventchn_bind_virq(value xce, value virq_type) +CAMLprim value stub_eventchn_bind_virq(value xce_val, value virq_type) { - CAMLparam2(xce, virq_type); + CAMLparam2(xce_val, virq_type); CAMLlocal1(port); + xenevtchn_handle *xce =3D xce_of_val(xce_val); xenevtchn_port_or_error_t rc; =20 caml_enter_blocking_section(); - rc =3D xenevtchn_bind_virq(_H(xce), Int_val(virq_type)); + rc =3D xenevtchn_bind_virq(xce, Int_val(virq_type)); caml_leave_blocking_section(); =20 if (rc =3D=3D -1) @@ -157,13 +164,14 @@ CAMLprim value stub_eventchn_bind_virq(value xce, val= ue virq_type) CAMLreturn(port); } =20 -CAMLprim value stub_eventchn_unbind(value xce, value port) +CAMLprim value stub_eventchn_unbind(value xce_val, value port) { - CAMLparam2(xce, port); + CAMLparam2(xce_val, port); + xenevtchn_handle *xce =3D xce_of_val(xce_val); int rc; =20 caml_enter_blocking_section(); - rc =3D xenevtchn_unbind(_H(xce), Int_val(port)); + rc =3D xenevtchn_unbind(xce, Int_val(port)); caml_leave_blocking_section(); =20 if (rc =3D=3D -1) @@ -172,14 +180,15 @@ CAMLprim value stub_eventchn_unbind(value xce, value = port) CAMLreturn(Val_unit); } =20 -CAMLprim value stub_eventchn_pending(value xce) +CAMLprim value stub_eventchn_pending(value xce_val) { - CAMLparam1(xce); + CAMLparam1(xce_val); CAMLlocal1(result); + xenevtchn_handle *xce =3D xce_of_val(xce_val); xenevtchn_port_or_error_t port; =20 caml_enter_blocking_section(); - port =3D xenevtchn_pending(_H(xce)); + port =3D xenevtchn_pending(xce); caml_leave_blocking_section(); =20 if (port =3D=3D -1) @@ -189,16 +198,17 @@ CAMLprim value stub_eventchn_pending(value xce) CAMLreturn(result); } =20 -CAMLprim value stub_eventchn_unmask(value xce, value _port) +CAMLprim value stub_eventchn_unmask(value xce_val, value _port) { - CAMLparam2(xce, _port); + CAMLparam2(xce_val, _port); + xenevtchn_handle *xce =3D xce_of_val(xce_val); evtchn_port_t port; int rc; =20 port =3D Int_val(_port); =20 caml_enter_blocking_section(); - rc =3D xenevtchn_unmask(_H(xce), port); + rc =3D xenevtchn_unmask(xce, port); caml_leave_blocking_section(); =20 if (rc) --=20 2.11.0 From nobody Sat Sep 21 03:20:00 2024 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=1675200601; cv=none; d=zohomail.com; s=zohoarc; b=K3hdymvFeJhwOaapW53yt7S3HT3oLLnK/QzWofCGwmKRVuZi6y8NdQoOtGyBDWfQ65il5aqGs3BTftOde5JMkSBJn4EGkUezYPxQe3vvF0gAjBLRkZwm2lhRW5Sb10ewnfGGg2HjUmaXlZu8tyre81cvE3t3y6DtbaX36IMd1uY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200601; 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=6WvvWDdgfDzpkKM3DodqxFrF3iPnq3Gob5/g0RSuphQ=; b=G7zHiICSmJ9nJD89t0gPV1wkExCpusDzE+Amnd9uux19YZivuIPclPo0izO9qe/fagmmISuOf5AzVIWto0cDtG0RfK8rK0d8w1zGn2BzGbVz3m82I5d/wzKdO/wOOCyQkwBLFPyfkkewwwfgCY2AEYKzTGF0ZSe1xcb8/pT35GU= 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 1675200601295130.23696571066182; Tue, 31 Jan 2023 13:30:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487849.755604 (Exim 4.92) (envelope-from ) id 1pMyC7-0001QU-Q9; Tue, 31 Jan 2023 21:29:35 +0000 Received: by outflank-mailman (output) from mailman id 487849.755604; Tue, 31 Jan 2023 21:29:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC7-0001PN-LU; Tue, 31 Jan 2023 21:29:35 +0000 Received: by outflank-mailman (input) for mailman id 487849; Tue, 31 Jan 2023 21:29:33 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC5-0000Nm-Kb for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:33 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 58685249-a1ae-11ed-b63b-5f92e7d2e73a; Tue, 31 Jan 2023 22:29:31 +0100 (CET) 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: 58685249-a1ae-11ed-b63b-5f92e7d2e73a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D6fomBGSmJOQ8kYSoARFYZfJ7J0cbqAWh1IAdPyYhsE=; b=JYEzherDJoTOePts40n4Aw3VyqbG07cKdW3/nIiXhQDQl4rtz2h72RNi PL75zCAHkKhjEVHCL41hn6+/1ve1Xfp2v5iOkk7UP2tD4wymOE25Z025/ vQcXVrnvZa+PdpAgj8BOfli07zt620i73jBCXIWNkrrA5xeZQaVIQjE/c k=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95499181 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:UaIn26Dp78IZrxVW/yjjw5YqxClBgxIJ4kV8jS/XYbTApG8ghmNWy TcbCG+EOvyDYmOgL4t1O4Ti9RsHuZ/Wm9M1QQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nNHuCnYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFtMpvlDs15K6p4GpD5wRlDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIw0/5SWVMJ1 +IhMTkAYjTY28uE8qOCY7w57igjBJGD0II3v3hhyXfSDOo8QICFSKLPjTNa9G5u3IYUR6+YP pdHL2M1N3wsYDUWUrsTILs4kP2lmT/UdDpApUjOjaE2/3LS3Ep6172F3N/9K4HWFJQMzh/wS mTu2zrFWkslF8Wl8BWZ8m6QivTwwy3UcddHfFG/3qEz2wDCroAJMzUGWF3+rfSnh0qWX9NEN 1dS6icotbI19kGgUp/6RRLQiHKNoBM0QddbFOw+rgaXxcLpDx2xXzZeCGQbMZp/6ZFwHGZxv rOUoz/3LRV3leWnDlCDz66doD+WYnQ8H10TXAZRGGPp/OLfiI00ixvOSPNqH6i0ksD5FFnM/ tyakMQtr+5N1JBWjs1X6XiC2mvx/caREmbZ8y2NBgqYAhVFiJlJjmBCwXzS9r5+IYmQVTFtV 1BUypHFvIji4Xxg/RFhodnh/pnzv55p0xWG2zaD+qXNEBzzk0NPhagKvFlDyL5Ba67ogwPBb k7Joh9275ROJnasZqIfS9vvVJlznPC4TYm/DK+8gj9yjn9ZLV/vwc2TTRTIgzCFfLYEzsnTx qt3ge7zVC1HWMyLPRK9RvsH0K9D+8zN7Tq7eHwP9Dz+ieD2TCfMGd843K6mMrhRAFWs/F+Er L6y9qKil31ibQEJSnKOrdBIcg1WdyhT6FKfg5U/S9Nv6zFOQAkJY8I9C5t4E2C5t8y5Ttv1w 0w= IronPort-HdrOrdr: A9a23:6YTmlaFIAcvJGvc6pLqF8ZLXdLJyesId70hD6qkvc3Fom52j/f xGws5x6fatskdoZJkh8erhBEDyewKmyXcV2/hZAV7MZniDhILFFu9fBM7ZskTd8k7Fh6ZgPM VbAs9D4bTLZDAX4voSojPIderIq+P3k5xA8N2uqkuFOjsaCZ2IgT0ZNi+rVmlNACVWD5swE5 SRouJBujqbYHwSKuirG3UfWODHhtvT0LbrewQPCRIL4BSHyWrA0s+xLzGomjMlFx9fy7Yr9m bI1yT/+6WYqvm+jjPMymPJ6JxSud35jv9OHtaFhMQ5IijlziyoeINicbufuy1dmpDl1H8a1P 335zswNcV67H3cOkuvpwH25gXm2DEyr1f/1F6xmxLY0IDEbQN/L/AEqZNScxPf5UZllsp7yr h302WQsIcSJQ/cnR76+8PDW3hR5wWJSDsZ4KAuZk5kIMsjgYxq3M8iFYRuYdU99RfBmcEa+S 9VfYThDbhtABenhjvizxNSKZSXLwkO91G9MwU/U4WuokRrtWE8wE0CyMMFmHAcsJo7Vplf/u zBdr9ljbdUU6YtHNZA7co6MLmK41b2MGfxGXPXJU6iGLAMOnrLpZKy6LIp5PuycJhNyJcpgp zOXF5RqGZ3IivVeLuz9YwO9gqITHS2XDzrxM0b759luqfkTL6uNSGYUlghn8apvv1aCMzGXP S4Po5QHpbYXBzTMJcM2xe7V4hZKHEYXsFQstEnW0iWqsaOMYHuvvyzSoehGFMsK0dVZorSOA pzYNGoHrQ+0qmCYA6HvCTs X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95499181" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Christian Lindig , David Scott , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Rob Hoes Subject: [PATCH 4/7] tools/ocaml/evtchn: Misc cleanup Date: Tue, 31 Jan 2023 21:29:10 +0000 Message-ID: <20230131212913.6199-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200601743100009 * Remove local integers when all we're returning is Val_int() of another variable. The CAMLlocal*() can't be optimised automatically, as it's registered with the GC. * Rename "virq_type" to "virq" and "_port" to "port". * In stub_eventchn_pending(), rename 'port' to 'rc', to be consistent with all other stubs that return xenevtchn_port_or_error_t. * In stub_eventchn_unmask(), check for rc =3D=3D -1 to be consistent with = all other stubs. No practical change. Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 45 +++++++++++------------= ---- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/li= bs/eventchn/xeneventchn_stubs.c index d7881ca95f98..34dcfed30275 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c +++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c @@ -98,17 +98,15 @@ CAMLprim value stub_eventchn_fdopen(value fdval) CAMLprim value stub_eventchn_fd(value xce_val) { CAMLparam1(xce_val); - CAMLlocal1(result); xenevtchn_handle *xce =3D xce_of_val(xce_val); int fd; =20 + /* Don't drop the GC lock. This is a simple read out of memory */ fd =3D xenevtchn_fd(xce); if (fd =3D=3D -1) caml_failwith("evtchn fd failed"); =20 - result =3D Val_int(fd); - - CAMLreturn(result); + CAMLreturn(Val_int(fd)); } =20 CAMLprim value stub_eventchn_notify(value xce_val, value port) @@ -131,37 +129,34 @@ CAMLprim value stub_eventchn_bind_interdomain(value x= ce_val, value domid, value remote_port) { CAMLparam3(xce_val, domid, remote_port); - CAMLlocal1(port); xenevtchn_handle *xce =3D xce_of_val(xce_val); xenevtchn_port_or_error_t rc; =20 caml_enter_blocking_section(); - rc =3D xenevtchn_bind_interdomain(xce, Int_val(domid), Int_val(remote_por= t)); + rc =3D xenevtchn_bind_interdomain(xce, Int_val(domid), + Int_val(remote_port)); caml_leave_blocking_section(); =20 if (rc =3D=3D -1) caml_failwith("evtchn bind_interdomain failed"); - port =3D Val_int(rc); =20 - CAMLreturn(port); + CAMLreturn(Val_int(rc)); } =20 -CAMLprim value stub_eventchn_bind_virq(value xce_val, value virq_type) +CAMLprim value stub_eventchn_bind_virq(value xce_val, value virq) { - CAMLparam2(xce_val, virq_type); - CAMLlocal1(port); + CAMLparam2(xce_val, virq); xenevtchn_handle *xce =3D xce_of_val(xce_val); xenevtchn_port_or_error_t rc; =20 caml_enter_blocking_section(); - rc =3D xenevtchn_bind_virq(xce, Int_val(virq_type)); + rc =3D xenevtchn_bind_virq(xce, Int_val(virq)); caml_leave_blocking_section(); =20 if (rc =3D=3D -1) caml_failwith("evtchn bind_virq failed"); - port =3D Val_int(rc); =20 - CAMLreturn(port); + CAMLreturn(Val_int(rc)); } =20 CAMLprim value stub_eventchn_unbind(value xce_val, value port) @@ -183,35 +178,31 @@ CAMLprim value stub_eventchn_unbind(value xce_val, va= lue port) CAMLprim value stub_eventchn_pending(value xce_val) { CAMLparam1(xce_val); - CAMLlocal1(result); xenevtchn_handle *xce =3D xce_of_val(xce_val); - xenevtchn_port_or_error_t port; + xenevtchn_port_or_error_t rc; =20 caml_enter_blocking_section(); - port =3D xenevtchn_pending(xce); + rc =3D xenevtchn_pending(xce); caml_leave_blocking_section(); =20 - if (port =3D=3D -1) + if (rc =3D=3D -1) caml_failwith("evtchn pending failed"); - result =3D Val_int(port); =20 - CAMLreturn(result); + CAMLreturn(Val_int(rc)); } =20 -CAMLprim value stub_eventchn_unmask(value xce_val, value _port) +CAMLprim value stub_eventchn_unmask(value xce_val, value port) { - CAMLparam2(xce_val, _port); + CAMLparam2(xce_val, port); xenevtchn_handle *xce =3D xce_of_val(xce_val); - evtchn_port_t port; int rc; =20 - port =3D Int_val(_port); - caml_enter_blocking_section(); - rc =3D xenevtchn_unmask(xce, port); + rc =3D xenevtchn_unmask(xce, Int_val(port)); caml_leave_blocking_section(); =20 - if (rc) + if (rc =3D=3D -1) caml_failwith("evtchn unmask failed"); + CAMLreturn(Val_unit); } --=20 2.11.0 From nobody Sat Sep 21 03:20:00 2024 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=1675200594; cv=none; d=zohomail.com; s=zohoarc; b=eU9ljuGpxb39apBc1K0yXrEvdmPx9gLZgdDx6k9VuYeo+rRLoRekob30nnEgUhITGZGRKTxEbuPTeqfPws2E5kmxzf2ypEMEzZrKUxyiXASmYW6d0CeNnkBki9+cUA1TcarKio+x5dLKnABX164UwR1vRzhQvnan1KtYGMLDa7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200594; 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=bPrl3LvoPJwWnwsdtx7GCzhCQ37d4a0YyLuQtV49+Ao=; b=n3IF0VKGjTM/szXgvtrbs8wBM7KS4mwNtExeYjdarsJJNigduR7xIZ2R76AOQCXdObCKWUkFZT+4TtGfdlDFAyGaBXW3+Kq1/FF+q8dkhOYszh5IkXxgqtKVz2kjUjvHEy4Ih6ZXmKyebVyONLxfkoUrRrFv4tylidGFOV82WjI= 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 1675200594843265.26454632503703; Tue, 31 Jan 2023 13:29:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487850.755613 (Exim 4.92) (envelope-from ) id 1pMyC8-0001Xy-CO; Tue, 31 Jan 2023 21:29:36 +0000 Received: by outflank-mailman (output) from mailman id 487850.755613; Tue, 31 Jan 2023 21:29:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC8-0001VA-1g; Tue, 31 Jan 2023 21:29:36 +0000 Received: by outflank-mailman (input) for mailman id 487850; Tue, 31 Jan 2023 21:29:33 +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 1pMyC5-0000Nb-Kl for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:33 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 599ac36b-a1ae-11ed-933c-83870f6b2ba8; Tue, 31 Jan 2023 22:29:32 +0100 (CET) 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: 599ac36b-a1ae-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YZc3Qe4tQu/04xfxAwG/P7vQhM7bvhY61z2fO5lZ86M=; b=FotiXju3+4liJe4vHjhgOMTCs9TVfB+zVgxBhtX9ltBoKjhWldW57DsF jgDX8ZTyCF3y2Py+klAHfyo7CvrW1UwBAUlmPKhiKZ/dBWo/swI09+eW7 gXS/5P7YIe+u3+XgvypS2cJw+GZJt1RIcTD3loiooBiPJ42kKPMbIxbeE c=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95499183 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:rHDd5a7tMly7k5beTkGK4QxRtDnHchMFZxGqfqrLsTDasY5as4F+v mEcD23TOqzfMWenftsnPozjpEkP6MLXztRrQQNs+CEzHi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvynTraBYnoqLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9VU+45wehBtC5gZlPakQ5QeF/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5m3 OQ9cAJKTA66nuu7zJbgFsBetNUaBZy+VG8fkikIITDxCP8nRdbIQrnQ5M8e1zA17ixMNa+AP YxDM2MpNUmeJUQVYT/7C7pn9AusrlD5fydVtxS+oq0v7nKI5AdwzKLsIJzefdniqcB9zxvE9 zOfrz+R7hcyF/yP8zuL8niWr/b+kwL/ZL80T52V36s/6LGU7jNKU0BHPbehmtGph0j7V99BJ kg8/is1sbN05EGtVsP6XRCzvDiDpBF0c9ZZDeAS8gyGzavQpQGDCQA5oiVpMYJ88pVsHHpzi wHPxomybdByjFGLYVuF0++m6hGsADEcIGMmPnMtfzkU2vC29enfkSnzZtpkFae0iPj8Fjfx3 y2GoUACulkDsSIY//7lpA6a2lpAsrCMF1dovVuPAgpJ+ysjPOaYi5qUBU83BBqqBKKQVRG/s XcNgKByB8heXMjWxERhrAjgdYxFBspp0hWG2TaD/LF7rVxBHkJPmqgOiAyS3G8zbq45lcbBO Sc/Qz956p5JJ2eNZqRqeY+3AMlC5fG+Som8B6iMNocUOMcZmOq7EMZGPB744owQuBJ0zfFX1 WmzLq5A8kr2+Yw4lWHrFo/xIJcgxzwkxHO7eHwI503P7FZqX1bMEe1tGALXPogEAFas/F29H yB3a5HblH2ykYTWPkHqzGLkBQtTcSZgWs2q8Zw/myzqClMOJVzNwsT5mdsJE7GJVYwM/gsU1 hlRgnNl9Wc= IronPort-HdrOrdr: A9a23:hVYwJq3ICPaAWKoFIX7QPwqjBatxeYIsimQD101hICG9Lfb0qy n+pp4mPEHP4wr5AEtQ4expOMG7IU80hqQFmrX5XI3SFTUO11HYSL2KgbGN/9SkIVyGygc/79 YpT0EdMqyWMbESt6+TjGaF+pQbsb+6GcuT9ITjJgJWPGRXgtZbnmVE42igc3FedU1jP94UBZ Cc7s1Iq36JfmkWVN2yAj0oTvXOvNrCkbPheFojCwQ84AeDoDu04PqieiLolCs2Yndq+/MP4G LFmwv26uGKtOy68AbV0yv+/olbg9zoz/pEHYiphtIOIjvhpw60bMBKWqGEvhoyvOazgWxa2+ XkklMFBYBe+nnRdma6rV/GwA/7ygsj7Hfk1BuxnWbjidaRfkN3N+NxwaZiNjfJ4Uspu99xlI hR2XiCipZRBRTc2Azg+tnzUQ1wnEbcmwtsrQdTtQ0QbWItUs4QkWUtxjIXLH7GJlO51GkTKp guMCgb3ocSTbrVVQGcgoAl+q3XYp16JGb6fqFFgL3Z79EepgEE82IIgMMYhXsO75Q7Vt1N4P nFKL1hkPVUQtYRdr8VPpZ0fSKbMB2+ffv3ChPmHX33UKUcf37doZ/+57s4oOmsZZwT1ZM33J DMSklRu2I+c1/nTZTm5uw8zjndBGGmGTj9wMBX4JZ0/rX6WbrwKCWGDFQjidGprfkTCtDSH/ yzJJVVCfn+KnaGI/c/4yTuH51JbXUOWswcvdg2H1qIv8LQM4Xv8vfWdf7CTYCdYgrMmlmPck frcAKDVfmotHrbJUMQqCKhJU/QRg== X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95499183" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Andrew Cooper , Christian Lindig , David Scott , Rob Hoes Subject: [PATCH 5/7] tools/ocaml/xc: Fix binding for xc_domain_assign_device() Date: Tue, 31 Jan 2023 21:29:11 +0000 Message-ID: <20230131212913.6199-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200595965100001 From: Edwin T=C3=B6r=C3=B6k The patch adding this binding was plain broken, and unreviewed. It modified the C stub to add a 4th parameter without an equivalent adjustment in the Ocaml side of the bindings. In 64bit builds, this causes us to dereference whatever dead value is in %r= cx when trying to interpret the rflags parameter. This has gone unnoticed because Xapi doesn't use this binding (it has its own), but unbreak the binding by passing RDM_RELAXED unconditionally for now (matching the libxl default behaviour). Fixes: 9b34056cb4 ("tools: extend xc_assign_device() to support rdm reserva= tion policy") Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/xc/xenctrl_stubs.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index fd1f306f0202..291663bb278a 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -1245,17 +1245,12 @@ CAMLprim value stub_xc_domain_test_assign_device(va= lue xch, value domid, value d CAMLreturn(Val_bool(ret =3D=3D 0)); } =20 -static int domain_assign_device_rdm_flag_table[] =3D { - XEN_DOMCTL_DEV_RDM_RELAXED, -}; - -CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value = desc, - value rflag) +CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value = desc) { - CAMLparam4(xch, domid, desc, rflag); + CAMLparam3(xch, domid, desc); int ret; int domain, bus, dev, func; - uint32_t sbdf, flag; + uint32_t sbdf; =20 domain =3D Int_val(Field(desc, 0)); bus =3D Int_val(Field(desc, 1)); @@ -1263,10 +1258,8 @@ CAMLprim value stub_xc_domain_assign_device(value xc= h, value domid, value desc, func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D Int_val(Field(rflag, 0)); - flag =3D domain_assign_device_rdm_flag_table[ret]; - - ret =3D xc_assign_device(_H(xch), _D(domid), sbdf, flag); + ret =3D xc_assign_device(_H(xch), _D(domid), sbdf, + XEN_DOMCTL_DEV_RDM_RELAXED); =20 if (ret < 0) failwith_xc(_H(xch)); --=20 2.11.0 From nobody Sat Sep 21 03:20:00 2024 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=1675200597; cv=none; d=zohomail.com; s=zohoarc; b=bW7mD6Otop5M+OnbA9dbcRN0JlJ996zRAGA2U/lnhhXHaK7RBOlVCxbVoBA3m/YAExhtek6sG/MiK1Id7f0yexx/NfYtKP9ZbIRH5aeZnb+0uR+muY6h80Bb+B3h/4ykA5cszh/EX9gcIhDiqijh2an8ldye+EkunzpMoUXSmOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200597; 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=qVVA70P9/qYLOR2QmymZICImaE5GgQYPwFqHPmqmX5U=; b=RginT+mBxOi0A9oiCYTqOtnnmC9MXDMH5Ur457fXnAyDOuA+vBqLPXtmUtsmKTPbM0d79u+A1WG4v6iKb2VkzI3uohp0UEYcftHeRmAmQyo+cdWeRQyYndXmSza16UEV3gTIkh4NkmBdolP/FXACQbWQFSWox9rfq8EKucVF29I= 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 1675200597535968.9656435197966; Tue, 31 Jan 2023 13:29:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487851.755623 (Exim 4.92) (envelope-from ) id 1pMyC9-0001lE-2r; Tue, 31 Jan 2023 21:29:37 +0000 Received: by outflank-mailman (output) from mailman id 487851.755623; Tue, 31 Jan 2023 21:29:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC8-0001j6-PF; Tue, 31 Jan 2023 21:29:36 +0000 Received: by outflank-mailman (input) for mailman id 487851; Tue, 31 Jan 2023 21:29:34 +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 1pMyC6-0000Nb-Km for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:34 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5908c139-a1ae-11ed-933c-83870f6b2ba8; Tue, 31 Jan 2023 22:29:32 +0100 (CET) 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: 5908c139-a1ae-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DuMXyrr37uOetL3gBS1wPn+orSXwgbl8VJbcI3sGhvc=; b=Ualea35HX4y91C5TstnZbZvNo7xjd/wVtHCYkgPb/79wLexkIhn8FGS5 8R4yewTlbnn0PswKqrQ/g7D0IHilaEizMxQ6vDJIjf3ws1B5d4bAblvpB wiH7KwSZcNP7JRuBueqnDJ+RSW7lczhNEY1DcYk9YJYgjhYTlQBZOoFgT Y=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95499184 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:Gk3+MazYHRxfxxsTyDp6t+c2xirEfRIJ4+MujC+fZmUNrF6WrkUGz 2MYWjuBPKmIYTH8L4onOYvjo0gE75SDydNhSAc5rSAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTbaeYUidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw//F+UwHUMja4mtC5QRnPqkT5zcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KUhW0 KQqbxITVwmKiu6Sm+6SeNt9v+12eaEHPKtH0p1h5TTQDPJgSpHfWaTao9Rf2V/chOgXQ6yYP ZBAL2MyMlKZOUYn1lQ/UfrSmM+BgHXlfiIeg1WSvactuEDYzRBr0airO93QEjCPbZQIwhfJ/ zKal4j/Ki8lNMbA6AurzmKDueXSkg/ZXZwxEYTto5aGh3XMnzdOWXX6T2CTsfS/z0KzRd9bA 0gV4TY167g/8lSxSdvwVAH+p2SL1jYQUsRdO/c34waMzuzT+QnxO4QfZmcfMpp87pZwHGF0k AbTxLsFGACDrpW8UVfFxPC2swqrMCUZCTReTB02XDIstoyLTJ4IsjrDSdNqEaiQh9LzGC3tz z3ikBXSl4n/nuZQifzloAmvbyaE48GQE1Vrvlm/sneNtFsRWWKzW2C/BbE3B95kJZ3RcFSOt WNsdyO2vLFXVsHleMBgrYww8FCVCxStamW0bb1HRcNJG9GRF5mLI+htDMlWfhsBDyr9UWaBj LXvkQ1Q/oRPG3ChcLV6ZYm8Y+xzk/e9TIW9DqiJNIARCnSUSONg1Hg+DXN8Iki3yBR8+U3BE cjznTmQ4YYyVv08kWveqxY12r433CEurV4/triipylLJYG2PSbPIZ9caQvmUwzMxP/cyOkj2 4oFZpTiJtQ2eLGWXxQ7BqZIdAxUdidmWcqmwyGVH8baSjdb9KgaI6e56dscl0ZNxsy5Ss+gE qmBZ3Jl IronPort-HdrOrdr: A9a23:nQbdZ6p2m/YJiPBfwBbHvWUaV5syLNV00zEX/kB9WHVpm5Oj+v xGzc5w6farsl0ssSkb6Ki90KnpexPhHO1OkPIs1NaZLUDbUQSTXeVfBOfZrQEIXheOj9K1tp 0QO5SWaueAamSS5PySiGXWLz9j+qjgzEnCv5a8854Zd3AOV0gW1XYaNu/0KCxLbTgDIaB8OI uX58JBqTblUXMLbv6jDn1Ac/nfq8bNnJfGZwdDIxI88gGBgR6h9ba/SnGjr10jegIK5Y1n3X nOkgT/6Knmm/anyiXE32uWw4VKlMDnwt5jAtXJrsQOMD3jhiuheYwkcbyfuzIepv2p9T8R4Z LxiiZlG/42x2Laf2mzrxeo8RLnyiwS53jrzkLdqWf/oOTiLQhKR/ZptMZ8SF/0+kAgtNZz3O ZgxGSCradaChvGgWDU+8XIbRd3jUC5yEBS3tL7zkYvH7f2WoUh7bD3z3klU6vo2xiKqrzPJd MeTf00IswmNG9yIUqp+lWHi+bcJEjbVi32P3Tq/PblngS+1UoJs3cw1YgRmGwN+4k6TIQB7+ PYMr5wnLULVcMOa7lhbd1xNfdfJ1a9My4kCljiVGjPBeUCITbAupT36LI66KWjf4EJ1oI7nN DEXElDvWA/dkryAYnWtac7hCzlUSG4R3Dg28te7592tvn1Q6fqKzSKTBQrn9G7q/sSD8XHU7 K4OY5QAfXkMWzycLw5qDHWSt1XMz0TQccVstE0VxaHpd/KMJTjsqjBfPPaNNPWYEUZs6PEcw s+tRTIVbR9BxqQKwDFaTDqKg3QRnA= X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95499184" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Christian Lindig , David Scott , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Rob Hoes Subject: [PATCH 6/7] tools/ocaml/xc: Don't reference Abstract_Tag objects with the GC lock released Date: Tue, 31 Jan 2023 21:29:12 +0000 Message-ID: <20230131212913.6199-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200601519100007 The intf->{addr,len} references in the xc_map_foreign_range() call are unsa= fe. From the manual: https://ocaml.org/manual/intfc.html#ss:parallel-execution-long-running-c-= code "After caml_release_runtime_system() was called and until caml_acquire_runtime_system() is called, the C code must not access any OCa= ml data, nor call any function of the run-time system, nor call back into OCaml code." More than what the manual says, the intf pointer is (potentially) invalidat= ed by caml_enter_blocking_section() if another thread happens to perform garba= ge collection at just the right (wrong) moment. Rewrite the logic. There's no need to stash data in the Ocaml object until the success path at the very end. Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.") Signed-off-by: Andrew Cooper Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes Note: the mmap stub has a similar pattern when constructing a mmap_interfac= e, but, but it's not actually unsafe because it doesn't drop the GC lock. _H() is buggy too, but this patch needs backporting further than that fix. --- tools/ocaml/libs/xc/xenctrl_stubs.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 291663bb278a..e5277f6f19a2 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -1028,26 +1028,25 @@ CAMLprim value stub_map_foreign_range(value xch, va= lue dom, CAMLparam4(xch, dom, size, mfn); CAMLlocal1(result); struct mmap_interface *intf; - uint32_t c_dom; - unsigned long c_mfn; + unsigned long c_mfn =3D Nativeint_val(mfn); + int len =3D Int_val(size); + void *ptr; =20 BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) !=3D 0); result =3D caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)), Abstract_tag); =20 - intf =3D (struct mmap_interface *) result; - - intf->len =3D Int_val(size); - - c_dom =3D _D(dom); - c_mfn =3D Nativeint_val(mfn); caml_enter_blocking_section(); - intf->addr =3D xc_map_foreign_range(_H(xch), c_dom, - intf->len, PROT_READ|PROT_WRITE, - c_mfn); + ptr =3D xc_map_foreign_range(_H(xch), _D(dom), len, + PROT_READ|PROT_WRITE, c_mfn); caml_leave_blocking_section(); - if (!intf->addr) + + if (!ptr) caml_failwith("xc_map_foreign_range error"); + + intf =3D Data_abstract_val(result); + *intf =3D (struct mmap_interface){ ptr, len }; + CAMLreturn(result); } =20 --=20 2.11.0 From nobody Sat Sep 21 03:20:00 2024 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=1675200601; cv=none; d=zohomail.com; s=zohoarc; b=iPfbruZRnI/zd093A4bDAQUTMvkUhH7vN9HdPk0/i32Cy03Iy3sC3XptIxyzDPAKQA/nFTNwQslFSOpSRTnuJEfl8Fqn5biU0FK75RZFhLse/+rLLZ4wy7617xXx7uvX+YCGE9oDt1+xsKHOHwg52R5fNe4LC/v/j1wpSf8eqb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200601; 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=GJgGl/n8kVPBQafhcBQAxx1GIxT0M3Nh4gvH+y0Vrpw=; b=ZHnK/sNP5rY4lClu8zBY4xiZD6JQzXYhPuGu+YuE012wsr8c+hWY/FkVWmtpNm8zQvUyA/Ni81cCqKe9aT6uXIgjzrRqSUj6nzjQye+Hm6HDwFDhSkNdBOCgMpd/ryxaP5YEnvHMzXRUxN+nMSBj+3HHsd1iphALJWlfOKGOTPw= 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 167520060192812.480629982920163; Tue, 31 Jan 2023 13:30:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487848.755601 (Exim 4.92) (envelope-from ) id 1pMyC7-0001NM-EG; Tue, 31 Jan 2023 21:29:35 +0000 Received: by outflank-mailman (output) from mailman id 487848.755601; Tue, 31 Jan 2023 21:29:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC7-0001NA-9y; Tue, 31 Jan 2023 21:29:35 +0000 Received: by outflank-mailman (input) for mailman id 487848; Tue, 31 Jan 2023 21:29:33 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC4-0000Nm-Ku for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:33 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5645ffb5-a1ae-11ed-b63b-5f92e7d2e73a; Tue, 31 Jan 2023 22:29:27 +0100 (CET) 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: 5645ffb5-a1ae-11ed-b63b-5f92e7d2e73a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tJ4tTGgnhHKyde+wF8qU4LPiC92eyP3hCl2+Pked3dE=; b=h0RIaL/CLB2RtKjhN19reXDuj+bnJZI4CkqtOSzxdvot/NfOX9gbYNeq LHjrL/ZM75xHvyaBL7giR6WQk9kQC8YRhZ2bELP3EHGJVE6KsZ7dzjKEM OhR+Rffut5fpnwEilSmol6HdB32rbB36TXdH0E+Z7d3jG1brKmKKcd9a1 s=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95097287 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:rLtUSq9AKfsAhmGvWTVPDrUDgX6TJUtcMsCJ2f8bNWPcYEJGY0x3x jAZXG3TbP2MNzajedp3Ydvn8UNS6JKEmoRgTQFsqyo8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKucYHsZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kIw1BjOkGlA5AdmPKsS5AS2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklz2 acxGmAiciucrMvn3rPiE+RQlpkaeZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGOkcUUrsUIMtWcOOAr3/zaTBH7nmSorI6+TP7xw1tyrn9dtHSf7RmQO0Ewx7J+ TiWoAwVBDlBKYyHxBG3wEmK3MPdlATpWqkIBIWRo6sCbFq7mTVIVUx+uUGAifWwlEOWQd9UL E0QvC00osAa5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWblXoVRYYNoZg7pVvA2V3i BnQxYiB6SFTXKO9dF7G34XEgi+JJgM8fHEDPHYJcRtY2oy2yG0stS7nQtFmGa+zq9T6HzDs3 jyHxBQDa6UvYd0jjPviow2e6964jt2QF1NuuF2LNo6wxlkhDLNJcbBE/rQyARxoCI+CBmeMs 3Ef8yR1xLBfVMrd/MBhrQhkIV1I2xpnGGeE6bKMN8N7n9hIx5JEVd443d2GDB01WvvogBewC KMphStf5YVIIFyhZrJtboS6BqwClPa/SI20DqiMM4AUPfCdkTNrGwk3NSatM53FyhBwwcnTx 7/EGSpTMZrqIfs+l2fnLwvs+bQq2jo/1QvuqWPTlnyaPU6lTCfNE98taQLeBt3VGYvY+G05B f4DbZrVo/ieOcWiChTqHXk7dglWcyNkWMys+6S6tIere2JbJY3oMNeJqZtJRmCvt/49ejvgl p1lZnJl9Q== IronPort-HdrOrdr: A9a23:Mzq3j6hycse6p0DbZoBFeMqRMnBQXuUji2hC6mlwRA09TyVXrb HWoB17726NtN91YhsdcL+7Scy9qB/nhPxICMwqTNSftWrd2VdATrsSibcKqgeIc0bDH6xmtZ uIGJIOb+EYY2IK6/oSIzPVLz/j+rS6GWyT6ts2Bk0CcT1X X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95097287" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , "Christian Lindig" , David Scott , Rob Hoes Subject: [PATCH 7/7] tools/ocaml/xc: Don't reference Custom objects with the GC lock released Date: Tue, 31 Jan 2023 21:29:13 +0000 Message-ID: <20230131212913.6199-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> 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: 1675200603650100011 From: Edwin T=C3=B6r=C3=B6k The modification to the _H() macro for Ocaml 5 support introduced a subtle bug. From the manual: https://ocaml.org/manual/intfc.html#ss:parallel-execution-long-running-c-= code "After caml_release_runtime_system() was called and until caml_acquire_runtime_system() is called, the C code must not access any OCa= ml data, nor call any function of the run-time system, nor call back into OCaml code." Previously, the value was a naked C pointer, so dereferencing it wasn't "accessing any Ocaml data", but the fix to avoid naked C pointers added a layer of indirection through an Ocaml Custom object, meaning that the common pattern of using _H() in a blocking section is unsafe. In order to fix: * Drop the _H() macro and replace it with a static inline xch_of_val(). * Opencode the assignment into Data_custom_val() in the constructors. * Rename "value xch" parameters to "value xch_val" so we can consistently have "xc_interface *xch" on the stack, and obtain the pointer with the GC lock still held. * Drop the _D() macro while at it, because it's just pointless indirection. Fixes: 8b3c06a3e545 ("tools/ocaml/xenctrl: OCaml 5 support, fix use-after-f= ree") Signed-off-by: Edwin T=C3=B6r=C3=B6k Acked-by: Christian Lindig --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/xc/xenctrl_stubs.c | 454 ++++++++++++++++++++------------= ---- 1 file changed, 251 insertions(+), 203 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index e5277f6f19a2..f9006c662382 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -37,9 +37,6 @@ =20 #include "mmap_stubs.h" =20 -#define _H(__h) (*((xc_interface **)Data_custom_val(__h))) -#define _D(__d) ((uint32_t)Int_val(__d)) - #ifndef Val_none #define Val_none (Val_int(0)) #endif @@ -48,9 +45,18 @@ #define Tag_some 0 #endif =20 +static inline xc_interface *xch_of_val(value v) +{ + xc_interface *xch =3D *(xc_interface **)Data_custom_val(v); + + return xch; +} + static void stub_xenctrl_finalize(value v) { - xc_interface_close(_H(v)); + xc_interface *xch =3D xch_of_val(v); + + xc_interface_close(xch); } =20 static struct custom_operations xenctrl_ops =3D { @@ -100,7 +106,7 @@ CAMLprim value stub_xc_interface_open(value unit) failwith_xc(xch); =20 result =3D caml_alloc_custom(&xenctrl_ops, sizeof(xch), 0, 1); - _H(result) =3D xch; + *(xc_interface **)Data_custom_val(result) =3D xch; =20 CAMLreturn(result); } @@ -187,10 +193,11 @@ static unsigned int ocaml_list_to_c_bitmap(value l) return val; } =20 -CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value = config) +CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, va= lue config) { - CAMLparam3(xch, wanted_domid, config); + CAMLparam3(xch_val, wanted_domid, config); CAMLlocal2(l, arch_domconfig); + xc_interface *xch =3D xch_of_val(xch_val); =20 /* Mnemonics for the named fields inside domctl_create_config */ #define VAL_SSIDREF Field(config, 0) @@ -282,98 +289,104 @@ CAMLprim value stub_xc_domain_create(value xch, valu= e wanted_domid, value config #undef VAL_SSIDREF =20 caml_enter_blocking_section(); - result =3D xc_domain_create(_H(xch), &domid, &cfg); + result =3D xc_domain_create(xch, &domid, &cfg); caml_leave_blocking_section(); =20 if (result < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_int(domid)); } =20 -CAMLprim value stub_xc_domain_max_vcpus(value xch, value domid, +CAMLprim value stub_xc_domain_max_vcpus(value xch_val, value domid, value max_vcpus) { - CAMLparam3(xch, domid, max_vcpus); + CAMLparam3(xch_val, domid, max_vcpus); + xc_interface *xch =3D xch_of_val(xch_val); int r; =20 - r =3D xc_domain_max_vcpus(_H(xch), _D(domid), Int_val(max_vcpus)); + r =3D xc_domain_max_vcpus(xch, Int_val(domid), Int_val(max_vcpus)); if (r) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 =20 -value stub_xc_domain_sethandle(value xch, value domid, value handle) +value stub_xc_domain_sethandle(value xch_val, value domid, value handle) { - CAMLparam3(xch, domid, handle); + CAMLparam3(xch_val, domid, handle); + xc_interface *xch =3D xch_of_val(xch_val); xen_domain_handle_t h; int i; =20 domain_handle_of_uuid_string(h, String_val(handle)); =20 - i =3D xc_domain_sethandle(_H(xch), _D(domid), h); + i =3D xc_domain_sethandle(xch, Int_val(domid), h); if (i) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -static value dom_op(value xch, value domid, int (*fn)(xc_interface *, uint= 32_t)) +static value dom_op(value xch_val, value domid, + int (*fn)(xc_interface *, uint32_t)) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); + xc_interface *xch =3D xch_of_val(xch_val); int result; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); =20 caml_enter_blocking_section(); - result =3D fn(_H(xch), c_domid); + result =3D fn(xch, c_domid); caml_leave_blocking_section(); if (result) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_pause(value xch, value domid) +CAMLprim value stub_xc_domain_pause(value xch_val, value domid) { - return dom_op(xch, domid, xc_domain_pause); + return dom_op(xch_val, domid, xc_domain_pause); } =20 =20 -CAMLprim value stub_xc_domain_unpause(value xch, value domid) +CAMLprim value stub_xc_domain_unpause(value xch_val, value domid) { - return dom_op(xch, domid, xc_domain_unpause); + return dom_op(xch_val, domid, xc_domain_unpause); } =20 -CAMLprim value stub_xc_domain_destroy(value xch, value domid) +CAMLprim value stub_xc_domain_destroy(value xch_val, value domid) { - return dom_op(xch, domid, xc_domain_destroy); + return dom_op(xch_val, domid, xc_domain_destroy); } =20 -CAMLprim value stub_xc_domain_resume_fast(value xch, value domid) +CAMLprim value stub_xc_domain_resume_fast(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); + xc_interface *xch =3D xch_of_val(xch_val); int result; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); =20 caml_enter_blocking_section(); - result =3D xc_domain_resume(_H(xch), c_domid, 1); + result =3D xc_domain_resume(xch, c_domid, 1); caml_leave_blocking_section(); if (result) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_shutdown(value xch, value domid, value reaso= n) +CAMLprim value stub_xc_domain_shutdown(value xch_val, value domid, value r= eason) { - CAMLparam3(xch, domid, reason); + CAMLparam3(xch_val, domid, reason); + xc_interface *xch =3D xch_of_val(xch_val); int ret; =20 - ret =3D xc_domain_shutdown(_H(xch), _D(domid), Int_val(reason)); + ret =3D xc_domain_shutdown(xch, Int_val(domid), Int_val(reason)); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } @@ -433,10 +446,11 @@ static value alloc_domaininfo(xc_domaininfo_t * info) CAMLreturn(result); } =20 -CAMLprim value stub_xc_domain_getinfolist(value xch, value first_domain, v= alue nb) +CAMLprim value stub_xc_domain_getinfolist(value xch_val, value first_domai= n, value nb) { - CAMLparam3(xch, first_domain, nb); + CAMLparam3(xch_val, first_domain, nb); CAMLlocal2(result, temp); + xc_interface *xch =3D xch_of_val(xch_val); xc_domaininfo_t * info; int i, ret, toalloc, retval; unsigned int c_max_domains; @@ -450,16 +464,16 @@ CAMLprim value stub_xc_domain_getinfolist(value xch, = value first_domain, value n =20 result =3D temp =3D Val_emptylist; =20 - c_first_domain =3D _D(first_domain); + c_first_domain =3D Int_val(first_domain); c_max_domains =3D Int_val(nb); caml_enter_blocking_section(); - retval =3D xc_domain_getinfolist(_H(xch), c_first_domain, + retval =3D xc_domain_getinfolist(xch, c_first_domain, c_max_domains, info); caml_leave_blocking_section(); =20 if (retval < 0) { free(info); - failwith_xc(_H(xch)); + failwith_xc(xch); } for (i =3D 0; i < retval; i++) { result =3D caml_alloc_small(2, Tag_cons); @@ -474,38 +488,39 @@ CAMLprim value stub_xc_domain_getinfolist(value xch, = value first_domain, value n CAMLreturn(result); } =20 -CAMLprim value stub_xc_domain_getinfo(value xch, value domid) +CAMLprim value stub_xc_domain_getinfo(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xc_domaininfo_t info; int ret; =20 - ret =3D xc_domain_getinfolist(_H(xch), _D(domid), 1, &info); + ret =3D xc_domain_getinfolist(xch, Int_val(domid), 1, &info); if (ret !=3D 1) - failwith_xc(_H(xch)); - if (info.domain !=3D _D(domid)) - failwith_xc(_H(xch)); + failwith_xc(xch); + if (info.domain !=3D Int_val(domid)) + failwith_xc(xch); =20 result =3D alloc_domaininfo(&info); CAMLreturn(result); } =20 -CAMLprim value stub_xc_vcpu_getinfo(value xch, value domid, value vcpu) +CAMLprim value stub_xc_vcpu_getinfo(value xch_val, value domid, value vcpu) { - CAMLparam3(xch, domid, vcpu); + CAMLparam3(xch_val, domid, vcpu); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xc_vcpuinfo_t info; int retval; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); uint32_t c_vcpu =3D Int_val(vcpu); caml_enter_blocking_section(); - retval =3D xc_vcpu_getinfo(_H(xch), c_domid, - c_vcpu, &info); + retval =3D xc_vcpu_getinfo(xch, c_domid, c_vcpu, &info); caml_leave_blocking_section(); if (retval < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 result =3D caml_alloc_tuple(5); Store_field(result, 0, Val_bool(info.online)); @@ -517,17 +532,18 @@ CAMLprim value stub_xc_vcpu_getinfo(value xch, value = domid, value vcpu) CAMLreturn(result); } =20 -CAMLprim value stub_xc_vcpu_context_get(value xch, value domid, +CAMLprim value stub_xc_vcpu_context_get(value xch_val, value domid, value cpu) { - CAMLparam3(xch, domid, cpu); + CAMLparam3(xch_val, domid, cpu); + xc_interface *xch =3D xch_of_val(xch_val); CAMLlocal1(context); int ret; vcpu_guest_context_any_t ctxt; =20 - ret =3D xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt); + ret =3D xc_vcpu_getcontext(xch, Int_val(domid), Int_val(cpu), &ctxt); if ( ret < 0 ) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 context =3D caml_alloc_string(sizeof(ctxt)); memcpy((char *) String_val(context), &ctxt.c, sizeof(ctxt.c)); @@ -535,10 +551,10 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, va= lue domid, CAMLreturn(context); } =20 -static int get_cpumap_len(value xch, value cpumap) +static int get_cpumap_len(xc_interface *xch, value cpumap) { int ml_len =3D Wosize_val(cpumap); - int xc_len =3D xc_get_max_cpus(_H(xch)); + int xc_len =3D xc_get_max_cpus(xch); =20 if (ml_len < xc_len) return ml_len; @@ -546,56 +562,58 @@ static int get_cpumap_len(value xch, value cpumap) return xc_len; } =20 -CAMLprim value stub_xc_vcpu_setaffinity(value xch, value domid, +CAMLprim value stub_xc_vcpu_setaffinity(value xch_val, value domid, value vcpu, value cpumap) { - CAMLparam4(xch, domid, vcpu, cpumap); + CAMLparam4(xch_val, domid, vcpu, cpumap); + xc_interface *xch =3D xch_of_val(xch_val); int i, len =3D get_cpumap_len(xch, cpumap); xc_cpumap_t c_cpumap; int retval; =20 - c_cpumap =3D xc_cpumap_alloc(_H(xch)); + c_cpumap =3D xc_cpumap_alloc(xch); if (c_cpumap =3D=3D NULL) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 for (i=3D0; i=3D 0) { @@ -755,7 +779,7 @@ CAMLprim value stub_xc_readconsolering(value xch) count =3D size - count; =20 caml_enter_blocking_section(); - ret =3D xc_readconsolering(_H(xch), str, &count, 0, 1, &index); + ret =3D xc_readconsolering(xch, str, &count, 0, 1, &index); caml_leave_blocking_section(); =20 count +=3D str - ptr; @@ -777,30 +801,32 @@ CAMLprim value stub_xc_readconsolering(value xch) CAMLreturn(ring); } =20 -CAMLprim value stub_xc_send_debug_keys(value xch, value keys) +CAMLprim value stub_xc_send_debug_keys(value xch_val, value keys) { - CAMLparam2(xch, keys); + CAMLparam2(xch_val, keys); + xc_interface *xch =3D xch_of_val(xch_val); int r; =20 - r =3D xc_send_debug_keys(_H(xch), String_val(keys)); + r =3D xc_send_debug_keys(xch, String_val(keys)); if (r) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_physinfo(value xch) +CAMLprim value stub_xc_physinfo(value xch_val) { - CAMLparam1(xch); + CAMLparam1(xch_val); CAMLlocal4(physinfo, cap_list, arch_cap_flags, arch_cap_list); + xc_interface *xch =3D xch_of_val(xch_val); xc_physinfo_t c_physinfo; int r, arch_cap_flags_tag; =20 caml_enter_blocking_section(); - r =3D xc_physinfo(_H(xch), &c_physinfo); + r =3D xc_physinfo(xch, &c_physinfo); caml_leave_blocking_section(); =20 if (r) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 /* * capabilities: physinfo_cap_flag list; @@ -837,10 +863,11 @@ CAMLprim value stub_xc_physinfo(value xch) CAMLreturn(physinfo); } =20 -CAMLprim value stub_xc_pcpu_info(value xch, value nr_cpus) +CAMLprim value stub_xc_pcpu_info(value xch_val, value nr_cpus) { - CAMLparam2(xch, nr_cpus); + CAMLparam2(xch_val, nr_cpus); CAMLlocal2(pcpus, v); + xc_interface *xch =3D xch_of_val(xch_val); xc_cpuinfo_t *info; int r, size; =20 @@ -852,12 +879,12 @@ CAMLprim value stub_xc_pcpu_info(value xch, value nr_= cpus) caml_raise_out_of_memory(); =20 caml_enter_blocking_section(); - r =3D xc_getcpuinfo(_H(xch), Int_val(nr_cpus), info, &size); + r =3D xc_getcpuinfo(xch, Int_val(nr_cpus), info, &size); caml_leave_blocking_section(); =20 if (r) { free(info); - failwith_xc(_H(xch)); + failwith_xc(xch); } =20 if (size > 0) { @@ -873,79 +900,82 @@ CAMLprim value stub_xc_pcpu_info(value xch, value nr_= cpus) CAMLreturn(pcpus); } =20 -CAMLprim value stub_xc_domain_setmaxmem(value xch, value domid, +CAMLprim value stub_xc_domain_setmaxmem(value xch_val, value domid, value max_memkb) { - CAMLparam3(xch, domid, max_memkb); + CAMLparam3(xch_val, domid, max_memkb); + xc_interface *xch =3D xch_of_val(xch_val); int retval; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); unsigned int c_max_memkb =3D Int64_val(max_memkb); caml_enter_blocking_section(); - retval =3D xc_domain_setmaxmem(_H(xch), c_domid, - c_max_memkb); + retval =3D xc_domain_setmaxmem(xch, c_domid, c_max_memkb); caml_leave_blocking_section(); if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_set_memmap_limit(value xch, value domid, +CAMLprim value stub_xc_domain_set_memmap_limit(value xch_val, value domid, value map_limitkb) { - CAMLparam3(xch, domid, map_limitkb); + CAMLparam3(xch_val, domid, map_limitkb); + xc_interface *xch =3D xch_of_val(xch_val); unsigned long v; int retval; =20 v =3D Int64_val(map_limitkb); - retval =3D xc_domain_set_memmap_limit(_H(xch), _D(domid), v); + retval =3D xc_domain_set_memmap_limit(xch, Int_val(domid), v); if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_memory_increase_reservation(value xch, +CAMLprim value stub_xc_domain_memory_increase_reservation(value xch_val, value domid, value mem_kb) { - CAMLparam3(xch, domid, mem_kb); + CAMLparam3(xch_val, domid, mem_kb); + xc_interface *xch =3D xch_of_val(xch_val); int retval; =20 unsigned long nr_extents =3D ((unsigned long)(Int64_val(mem_kb))) >> (XC_= PAGE_SHIFT - 10); =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); caml_enter_blocking_section(); - retval =3D xc_domain_increase_reservation_exact(_H(xch), c_domid, + retval =3D xc_domain_increase_reservation_exact(xch, c_domid, nr_extents, 0, 0, NULL); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_version_version(value xch) +CAMLprim value stub_xc_version_version(value xch_val) { - CAMLparam1(xch); + CAMLparam1(xch_val); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xen_extraversion_t extra; long packed; int retval; =20 caml_enter_blocking_section(); - packed =3D xc_version(_H(xch), XENVER_version, NULL); + packed =3D xc_version(xch, XENVER_version, NULL); caml_leave_blocking_section(); =20 if (packed < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 caml_enter_blocking_section(); - retval =3D xc_version(_H(xch), XENVER_extraversion, &extra); + retval =3D xc_version(xch, XENVER_extraversion, &extra); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 result =3D caml_alloc_tuple(3); =20 @@ -957,19 +987,20 @@ CAMLprim value stub_xc_version_version(value xch) } =20 =20 -CAMLprim value stub_xc_version_compile_info(value xch) +CAMLprim value stub_xc_version_compile_info(value xch_val) { - CAMLparam1(xch); + CAMLparam1(xch_val); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xen_compile_info_t ci; int retval; =20 caml_enter_blocking_section(); - retval =3D xc_version(_H(xch), XENVER_compile_info, &ci); + retval =3D xc_version(xch, XENVER_compile_info, &ci); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 result =3D caml_alloc_tuple(4); =20 @@ -982,35 +1013,36 @@ CAMLprim value stub_xc_version_compile_info(value xc= h) } =20 =20 -static value xc_version_single_string(value xch, int code, void *info) +static value xc_version_single_string(value xch_val, int code, void *info) { - CAMLparam1(xch); + CAMLparam1(xch_val); + xc_interface *xch =3D xch_of_val(xch_val); int retval; =20 caml_enter_blocking_section(); - retval =3D xc_version(_H(xch), code, info); + retval =3D xc_version(xch, code, info); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(caml_copy_string((char *)info)); } =20 =20 -CAMLprim value stub_xc_version_changeset(value xch) +CAMLprim value stub_xc_version_changeset(value xch_val) { xen_changeset_info_t ci; =20 - return xc_version_single_string(xch, XENVER_changeset, &ci); + return xc_version_single_string(xch_val, XENVER_changeset, &ci); } =20 =20 -CAMLprim value stub_xc_version_capabilities(value xch) +CAMLprim value stub_xc_version_capabilities(value xch_val) { xen_capabilities_info_t ci; =20 - return xc_version_single_string(xch, XENVER_capabilities, &ci); + return xc_version_single_string(xch_val, XENVER_capabilities, &ci); } =20 =20 @@ -1022,11 +1054,12 @@ CAMLprim value stub_pages_to_kib(value pages) } =20 =20 -CAMLprim value stub_map_foreign_range(value xch, value dom, +CAMLprim value stub_map_foreign_range(value xch_val, value dom, value size, value mfn) { - CAMLparam4(xch, dom, size, mfn); + CAMLparam4(xch_val, dom, size, mfn); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); struct mmap_interface *intf; unsigned long c_mfn =3D Nativeint_val(mfn); int len =3D Int_val(size); @@ -1037,7 +1070,7 @@ CAMLprim value stub_map_foreign_range(value xch, valu= e dom, Abstract_tag); =20 caml_enter_blocking_section(); - ptr =3D xc_map_foreign_range(_H(xch), _D(dom), len, + ptr =3D xc_map_foreign_range(xch, Int_val(dom), len, PROT_READ|PROT_WRITE, c_mfn); caml_leave_blocking_section(); =20 @@ -1050,18 +1083,19 @@ CAMLprim value stub_map_foreign_range(value xch, va= lue dom, CAMLreturn(result); } =20 -CAMLprim value stub_sched_credit_domain_get(value xch, value domid) +CAMLprim value stub_sched_credit_domain_get(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); CAMLlocal1(sdom); + xc_interface *xch =3D xch_of_val(xch_val); struct xen_domctl_sched_credit c_sdom; int ret; =20 caml_enter_blocking_section(); - ret =3D xc_sched_credit_domain_get(_H(xch), _D(domid), &c_sdom); + ret =3D xc_sched_credit_domain_get(xch, Int_val(domid), &c_sdom); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 sdom =3D caml_alloc_tuple(2); Store_field(sdom, 0, Val_int(c_sdom.weight)); @@ -1070,67 +1104,71 @@ CAMLprim value stub_sched_credit_domain_get(value x= ch, value domid) CAMLreturn(sdom); } =20 -CAMLprim value stub_sched_credit_domain_set(value xch, value domid, +CAMLprim value stub_sched_credit_domain_set(value xch_val, value domid, value sdom) { - CAMLparam3(xch, domid, sdom); + CAMLparam3(xch_val, domid, sdom); + xc_interface *xch =3D xch_of_val(xch_val); struct xen_domctl_sched_credit c_sdom; int ret; =20 c_sdom.weight =3D Int_val(Field(sdom, 0)); c_sdom.cap =3D Int_val(Field(sdom, 1)); caml_enter_blocking_section(); - ret =3D xc_sched_credit_domain_set(_H(xch), _D(domid), &c_sdom); + ret =3D xc_sched_credit_domain_set(xch, Int_val(domid), &c_sdom); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_shadow_allocation_get(value xch, value domid) +CAMLprim value stub_shadow_allocation_get(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); CAMLlocal1(mb); + xc_interface *xch =3D xch_of_val(xch_val); unsigned int c_mb; int ret; =20 caml_enter_blocking_section(); - ret =3D xc_shadow_control(_H(xch), _D(domid), + ret =3D xc_shadow_control(xch, Int_val(domid), XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION, &c_mb, 0); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 mb =3D Val_int(c_mb); CAMLreturn(mb); } =20 -CAMLprim value stub_shadow_allocation_set(value xch, value domid, +CAMLprim value stub_shadow_allocation_set(value xch_val, value domid, value mb) { - CAMLparam3(xch, domid, mb); + CAMLparam3(xch_val, domid, mb); + xc_interface *xch =3D xch_of_val(xch_val); unsigned int c_mb; int ret; =20 c_mb =3D Int_val(mb); caml_enter_blocking_section(); - ret =3D xc_shadow_control(_H(xch), _D(domid), + ret =3D xc_shadow_control(xch, Int_val(domid), XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, &c_mb, 0); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_ioport_permission(value xch, value domid, +CAMLprim value stub_xc_domain_ioport_permission(value xch_val, value domid, value start_port, value nr_ports, value allow) { - CAMLparam5(xch, domid, start_port, nr_ports, allow); + CAMLparam5(xch_val, domid, start_port, nr_ports, allow); + xc_interface *xch =3D xch_of_val(xch_val); uint32_t c_start_port, c_nr_ports; uint8_t c_allow; int ret; @@ -1139,19 +1177,20 @@ CAMLprim value stub_xc_domain_ioport_permission(val= ue xch, value domid, c_nr_ports =3D Int_val(nr_ports); c_allow =3D Bool_val(allow); =20 - ret =3D xc_domain_ioport_permission(_H(xch), _D(domid), + ret =3D xc_domain_ioport_permission(xch, Int_val(domid), c_start_port, c_nr_ports, c_allow); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_iomem_permission(value xch, value domid, +CAMLprim value stub_xc_domain_iomem_permission(value xch_val, value domid, value start_pfn, value nr_pfns, value allow) { - CAMLparam5(xch, domid, start_pfn, nr_pfns, allow); + CAMLparam5(xch_val, domid, start_pfn, nr_pfns, allow); + xc_interface *xch =3D xch_of_val(xch_val); unsigned long c_start_pfn, c_nr_pfns; uint8_t c_allow; int ret; @@ -1160,18 +1199,19 @@ CAMLprim value stub_xc_domain_iomem_permission(valu= e xch, value domid, c_nr_pfns =3D Nativeint_val(nr_pfns); c_allow =3D Bool_val(allow); =20 - ret =3D xc_domain_iomem_permission(_H(xch), _D(domid), + ret =3D xc_domain_iomem_permission(xch, Int_val(domid), c_start_pfn, c_nr_pfns, c_allow); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_irq_permission(value xch, value domid, +CAMLprim value stub_xc_domain_irq_permission(value xch_val, value domid, value pirq, value allow) { - CAMLparam4(xch, domid, pirq, allow); + CAMLparam4(xch_val, domid, pirq, allow); + xc_interface *xch =3D xch_of_val(xch_val); uint32_t c_pirq; bool c_allow; int ret; @@ -1179,41 +1219,44 @@ CAMLprim value stub_xc_domain_irq_permission(value = xch, value domid, c_pirq =3D Int_val(pirq); c_allow =3D Bool_val(allow); =20 - ret =3D xc_domain_irq_permission(_H(xch), _D(domid), + ret =3D xc_domain_irq_permission(xch, Int_val(domid), c_pirq, c_allow); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_hvm_param_get(value xch, value domid, value param) +CAMLprim value stub_xc_hvm_param_get(value xch_val, value domid, value par= am) { - CAMLparam3(xch, domid, param); + CAMLparam3(xch_val, domid, param); + xc_interface *xch =3D xch_of_val(xch_val); uint64_t val; int ret; =20 caml_enter_blocking_section(); - ret =3D xc_hvm_param_get(_H(xch), _D(domid), Int_val(param), &val); + ret =3D xc_hvm_param_get(xch, Int_val(domid), Int_val(param), &val); caml_leave_blocking_section(); =20 if ( ret ) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(caml_copy_int64(val)); } =20 -CAMLprim value stub_xc_hvm_param_set(value xch, value domid, value param, = value val) +CAMLprim value stub_xc_hvm_param_set(value xch_val, value domid, value par= am, value val) { - CAMLparam4(xch, domid, param, val); + CAMLparam4(xch_val, domid, param, val); + xc_interface *xch =3D xch_of_val(xch_val); + uint64_t val64 =3D Int64_val(val); int ret; =20 caml_enter_blocking_section(); - ret =3D xc_hvm_param_set(_H(xch), _D(domid), Int_val(param), Int64_val(va= l)); + ret =3D xc_hvm_param_set(xch, Int_val(domid), Int_val(param), val64); caml_leave_blocking_section(); =20 if ( ret ) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } @@ -1226,9 +1269,10 @@ static uint32_t encode_sbdf(int domain, int bus, int= dev, int func) ((uint32_t)func & 0x7); } =20 -CAMLprim value stub_xc_domain_test_assign_device(value xch, value domid, v= alue desc) +CAMLprim value stub_xc_domain_test_assign_device(value xch_val, value domi= d, value desc) { - CAMLparam3(xch, domid, desc); + CAMLparam3(xch_val, domid, desc); + xc_interface *xch =3D xch_of_val(xch_val); int ret; int domain, bus, dev, func; uint32_t sbdf; @@ -1239,14 +1283,15 @@ CAMLprim value stub_xc_domain_test_assign_device(va= lue xch, value domid, value d func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D xc_test_assign_device(_H(xch), _D(domid), sbdf); + ret =3D xc_test_assign_device(xch, Int_val(domid), sbdf); =20 CAMLreturn(Val_bool(ret =3D=3D 0)); } =20 -CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value = desc) +CAMLprim value stub_xc_domain_assign_device(value xch_val, value domid, va= lue desc) { - CAMLparam3(xch, domid, desc); + CAMLparam3(xch_val, domid, desc); + xc_interface *xch =3D xch_of_val(xch_val); int ret; int domain, bus, dev, func; uint32_t sbdf; @@ -1257,17 +1302,18 @@ CAMLprim value stub_xc_domain_assign_device(value x= ch, value domid, value desc) func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D xc_assign_device(_H(xch), _D(domid), sbdf, + ret =3D xc_assign_device(xch, Int_val(domid), sbdf, XEN_DOMCTL_DEV_RDM_RELAXED); =20 if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_deassign_device(value xch, value domid, valu= e desc) +CAMLprim value stub_xc_domain_deassign_device(value xch_val, value domid, = value desc) { - CAMLparam3(xch, domid, desc); + CAMLparam3(xch_val, domid, desc); + xc_interface *xch =3D xch_of_val(xch_val); int ret; int domain, bus, dev, func; uint32_t sbdf; @@ -1278,28 +1324,29 @@ CAMLprim value stub_xc_domain_deassign_device(value= xch, value domid, value desc func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D xc_deassign_device(_H(xch), _D(domid), sbdf); + ret =3D xc_deassign_device(xch, Int_val(domid), sbdf); =20 if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_get_cpu_featureset(value xch, value idx) +CAMLprim value stub_xc_get_cpu_featureset(value xch_val, value idx) { - CAMLparam2(xch, idx); + CAMLparam2(xch_val, idx); CAMLlocal1(bitmap_val); #if defined(__i386__) || defined(__x86_64__) + xc_interface *xch =3D xch_of_val(xch_val); =20 /* Safe, because of the global ocaml lock. */ static uint32_t fs_len; =20 if (fs_len =3D=3D 0) { - int ret =3D xc_get_cpu_featureset(_H(xch), 0, &fs_len, NULL); + int ret =3D xc_get_cpu_featureset(xch, 0, &fs_len, NULL); =20 if (ret || (fs_len =3D=3D 0)) - failwith_xc(_H(xch)); + failwith_xc(xch); } =20 { @@ -1307,10 +1354,10 @@ CAMLprim value stub_xc_get_cpu_featureset(value xch= , value idx) uint32_t fs[fs_len], len =3D fs_len; unsigned int i; =20 - int ret =3D xc_get_cpu_featureset(_H(xch), Int_val(idx), &len, fs); + int ret =3D xc_get_cpu_featureset(xch, Int_val(idx), &len, fs); =20 if (ret) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 bitmap_val =3D caml_alloc(len, 0); =20 @@ -1323,15 +1370,16 @@ CAMLprim value stub_xc_get_cpu_featureset(value xch= , value idx) CAMLreturn(bitmap_val); } =20 -CAMLprim value stub_xc_watchdog(value xch, value domid, value timeout) +CAMLprim value stub_xc_watchdog(value xch_val, value domid, value timeout) { - CAMLparam3(xch, domid, timeout); + CAMLparam3(xch_val, domid, timeout); + xc_interface *xch =3D xch_of_val(xch_val); int ret; unsigned int c_timeout =3D Int32_val(timeout); =20 - ret =3D xc_watchdog(_H(xch), _D(domid), c_timeout); + ret =3D xc_watchdog(xch, Int_val(domid), c_timeout); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_int(ret)); } --=20 2.11.0