From patchwork Fri Mar 25 19:19:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12791915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30A77C433EF for ; Fri, 25 Mar 2022 19:24:20 +0000 (UTC) Received: from localhost ([::1]:60302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXpXn-0007qj-BF for qemu-devel@archiver.kernel.org; Fri, 25 Mar 2022 15:24:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTx-0007VZ-4C for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:25 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:11658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXpTu-00035r-FA for qemu-devel@nongnu.org; Fri, 25 Mar 2022 15:20:20 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22PHJCs2031416; Fri, 25 Mar 2022 19:20:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=qTPNoJb++i62u9jPgOKXnaF+7uWbatISZSIia3W0U20=; b=vdnOu3OIM6ieJnh7BOnVeE3esCcP1xy/yzF17rpOJ44jOJXBLSBkNY3ZJy3s7ZAkvIBP TI/LDCCGGIyBt+Hf7Jm6lxjtAvnuRXSFC48vh/JH2f2UmE3HMBBW6+gR2+ugObzC7YfV q78vsbKV+dk3WyRg1ses7iQ5ENgKZMxSKBtlr0tLwIchbI3CSWoLOqUrW3HXaAfBP4LZ t6vFJB90eOj6nkTCtRSiaTquH0pIwgA4b2fJ8Qb24DJK3F+9Jbp+dT9qnh0u5ZA5Zm0J 9AeaEZwS1Lv4MPZ2c69wu4JR3H5N9jt9Ifj1F9MzP8Kv6C8f8RHW+LDSqa13Bp0M7V9N 1w== Received: from aserp3030.oracle.com ([141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ew7qtgb2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:12 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22PJIFXe015896; Fri, 25 Mar 2022 19:20:10 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2044.outbound.protection.outlook.com [104.47.56.44]) by aserp3030.oracle.com with ESMTP id 3ew5793v0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Mar 2022 19:20:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OyVOktu09QEHnWPfxOiMya3r6eSB7eVtCtdCYEl5L3og4ZDlMqM3xqNS/yA4UV9hVxUYkMLNTZPp7t5ddn1V47nHepTUtXozvFT6JQhZ0brbbbHwtw8C+0sMGqkXSrfQXkddJEAHltsA4OYv3yECT1Z9weuTJ8uu81xbExeqivrthTvmY0lehjcj6a3GLZm+Cw1cMtlkxsGGyqivULt5jQGR+MXJiEjH5ViLwgFbJWD58fgURDPhD0xvRL7MXgpzqRM7LnNaV34ISH/Mztf6/jAljFCoOhR2ni2kDFEgAGloWrTatoGCxOhwIptUgcSTtUzkWOabev1oUZG8XNKx6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qTPNoJb++i62u9jPgOKXnaF+7uWbatISZSIia3W0U20=; b=WTgS22iAzEjGQCWWBKV1Y/KaqKixN+kgQalZ9UjERAptu/xilWKYxhoEQmQrjjtC55BLuDLE7s+GB3NMXZShOe8Wm7LhN7YQUMiWyunJhWY/cba8cNvLAEUCENkJMNKWFkfxE+JEb7i8IFgLV6tDEFijIjvOGxD1SMgWUfFHPYtKr2iLk3tBs1ez8PIqS8R1j6DRiecUEZis1maiTs/9bjWJudpglAaEBX+HryIqjS4j/bvg3717EtlX2h2uxt+pgqC7pRP/4nJZCxptocd53rJvkF/Bdt14lcETT/bmJeP97ebVd388nfW+kWyMSdrye3MekM3d9pB+yBjypgIKyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qTPNoJb++i62u9jPgOKXnaF+7uWbatISZSIia3W0U20=; b=vTnAGSvICnqxWR4TwP16kh2eu3mpUT9fzmy10zSklJUP10z8HLvb5WVIcNqa1QX4XTNlvaXSbmyWgOvMf+F3pqCJ3Iaa9h2sKIGSkaj1HHWmXz7JqfUyrJ3B/xo0aHdnZ7uc86YU8QHaTyOObBcaRbJvF9t/1zACoIfFD51s9Vo= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN0PR10MB5206.namprd10.prod.outlook.com (2603:10b6:408:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Fri, 25 Mar 2022 19:20:08 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::508e:7f79:394:563a%5]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 19:20:08 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v7 07/17] vfio-user: define vfio-user-server object Date: Fri, 25 Mar 2022 15:19:36 -0400 Message-Id: <35c1c4121dab88dc66548b8d47b27db275ac08d8.1648234157.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:805:106::34) To MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2879cec7-73e1-4747-d28a-08da0e94798b X-MS-TrafficTypeDiagnostic: BN0PR10MB5206:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7XTD6pW4vg43ppm9Go4mjGEqn+8n67uW4W+5N2mFCJ11kAuCy5A+bV4OpDJ70V1bFFN+qZU1efFHqRp0y1S+4aGadHnw4GvS4fya7m3lnZ2A4xmrUQ8K4Ywp1u2A21g0msp9596E992UZn1QHXt9A72LZIc/vIC+8gSYq7tJ45Mp2qkYnFhTY4hZPjClPUvVmPMCDOSEYB7LQAQ1qUNXaCdUBKy6Unq6ReioPhCpnkZPW3Toluq4milBrDvBVEen7J1sSxsy0a04RUXSZfQmzoxgNOKnfePkCUmY66Pwhy9tKWOz389yDdBFusP7FKkXVQYt3Pt7z1b0P0kKGiFe91llil0+NPYPCa+nmnUUIpaKLDLeGqkU4zPk6O+OKUKeekbLOtQAvYn9xIt5vXaRz4iphdf7j7/7c85mXfUgJWdsNmzImnOh3aP1FsHGT0r9h0M5ZnVD8Fyo3p2JfaO1yeyVA2hKlMB9z6aA0I4WSHtkYaC+Oe+61t0OEWyuKXl6A7x4KG48LGM9SYBKn5R/jAYzHlABEVe21yY5a9BDTfMwDlKbHzhf6XftUL5ok3q0eCBKbupyHP33FeT6mLkaTz6tGwU6A4QBZ51VA57Tg3saBI7bhuH5daiz8skCBrDVKUGjlb/rPv3EopweNlY6TtbE6cmy9nem25TzprAIRDfff5vILyByQawgGlTGZaazlhrrMWyaXIPm0u7KkUPW2Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4013.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(186003)(107886003)(316002)(2616005)(26005)(83380400001)(6486002)(36756003)(6666004)(6512007)(6506007)(52116002)(30864003)(66946007)(2906002)(86362001)(508600001)(38100700002)(38350700002)(6916009)(66476007)(8936002)(7416002)(5660300002)(66556008)(8676002)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?9J0UnwPa0bwgdCZk+rxyF9c7LzKu?= =?utf-8?q?fupjWM/Cm1cXF99l4GUmQMe0HZkdYvounWATeVWaM8ej22z+oxPpUpFtQ0YY/TQX1?= =?utf-8?q?XMsLfc1OUoHCiSxllp5PmNgNIW2I7OY75sAi56MtAkG9gDbcFkV+GQetyo2sJbrM+?= =?utf-8?q?RQq8cIIrGhedMQP/JcUp4IIAvP826hZvSLD+iN8Nj3NdpW6ogDquI96o7xCjWjgID?= =?utf-8?q?EoN6IKJg+2Uph3YI0oin5BRcwunNfqSuYsCSZ0+gcKy6Uw9Tzseax40WHxa+/O6qD?= =?utf-8?q?rPeP3qCWIhVtp6Bb1ypV4MRUiGK069gWbVaPQAM0y7DNWR1uB49KNoOnAYJqXZMfz?= =?utf-8?q?8fJJiQECU8EbGHvlh707Rq8s66BBFX9xC9/M+f+05f3Ky/GSAd/XIQqzqhpSJpYyP?= =?utf-8?q?LlxDHOBcSLfGOXPKhxGDFUwoNYea/MvwSjvS9cN+UZIdqZMG/0HoGsXKsW3l/t09S?= =?utf-8?q?mmnPtETtS0zNIJSBWNddf9XskTEzLf7+wskSpl0qR8OVdEmrWMeZTk6uAghUP0jH1?= =?utf-8?q?TxMVJ73qIDlsO2WcpBZ8ehyH/JrpavjQKZUP8gQIq4WQ0QAUcDkX5pRJE9NgLHLRj?= =?utf-8?q?E7WtJVQ5kdecML0ECWun1bKRnDV+uFdKnwa8+IV6VLgGuWqLQCkdgJaEgNMVxY0Ve?= =?utf-8?q?TdePr+5AKi9j2YqFq7dmSx+PngW9TjvPaW6nv/XRP7rpeJ8n/VyYRCOaJMVWp6Fs2?= =?utf-8?q?aDGC7Sbfk2htPWwPmNYuh9oUB2kezDYmMmueZmNuPOerJSnARJ9ok/Oo2yDcey0mY?= =?utf-8?q?9KmKdNla5YoHJw4mdrSZyBIhxml7gLH4pl8fJ/n9eaOB7o5Amp4htrfh/bzAUr8tW?= =?utf-8?q?vcB1AI32Fg1ly49alJ72pNXzzjjhyvgQ7GvqLuBqLgldmpYzAku87qIgmYnTsLeaq?= =?utf-8?q?p6gQALrUtdZTlHNSPQkOVMJbH5rMUzY0etEEkv2W489KCxOAck0cc+nQ6ObiQBKmY?= =?utf-8?q?6pp0QDqSMDR/lMKQqyQ0NkTCnx6RxYEWnbp29RgwazCbPBP1dCDK2gowrUtsL8r+1?= =?utf-8?q?qcWcQ/Efr7shc5DgZxUYAdfH8J3ZEslnRCIwtx/mjbCO49FAsTlBwt2MMEiRvAAPJ?= =?utf-8?q?CwHhu/Ratwun4ophLQoSTfxSkfAN6ebKvfzAhkzf9iYr6smfg53sOhxE6pW5mFuki?= =?utf-8?q?9gfav0OalMUz0Eu66OcdN2zdKrPaiiyNXfpnTG9cb7e/iDh6oGfr1AUO1h+8WbAbh?= =?utf-8?q?jjNF5v33dc8DlMLKUOfaICSruh2BgyYlTGgyexZWo1gp0wU8GhNzE5S10+WTuV4i2?= =?utf-8?q?9tVWXvW0XihMQWtB+Dt4rD/DlTUK1yYaORfA3CcDPSREZUM+ACQH9MxIv8g9HbejL?= =?utf-8?q?XrLpgmuJz7+E/FFCx85G8PL8NLjJW2VwEJj+FVMCX0hMOZUA5iiu620sp2JJzdZoc?= =?utf-8?q?ejBtGDw97M+Vu+tUs8BFWmPYA587ZnTF/bEllm5zB0upZIqHhJs9onLxskzGFaZKT?= =?utf-8?q?sSEP63lSR7S5FoiiwVTXANUoXqp6LrXN8PZsiI6sBi6VA4wHwypArTdouB8oiEjcb?= =?utf-8?q?hONnIDtVLeAI0LmJDsdbYupOQyVuTrfJVX4aSMew9Q06WuaFWlmpLHnjeoZt+H/bj?= =?utf-8?q?KOpy837FfEC4gXdMYC4tuRY3IMYAsKeoNmTviXhWKra2Ej1AQ+ksYyE63TTz99+Sp?= =?utf-8?q?9/JHMVbxiG/Fli/tE+068CxEqaGoh95Q=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2879cec7-73e1-4747-d28a-08da0e94798b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 19:20:08.5845 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MwZZ/72irX9ADU+mvEx0uED7PM20R5uiYgoIeMMMzOGEDPs8wpDOza/TO2f2bH51SZrXsfmA/3xJseGyeY32uQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5206 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10297 signatures=694973 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203250106 X-Proofpoint-GUID: tGQWrJz1nWiTFeLC5BU72Tifa8x4Ptd9 X-Proofpoint-ORIG-GUID: tGQWrJz1nWiTFeLC5BU72Tifa8x4Ptd9 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eduardo@habkost.net, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, berrange@redhat.com, bleal@redhat.com, john.levon@nutanix.com, mst@redhat.com, armbru@redhat.com, quintela@redhat.com, f4bug@amsat.org, alex.williamson@redhat.com, kanth.ghatraju@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, pbonzini@redhat.com, jag.raman@oracle.com, eblake@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define vfio-user object which is remote process server for QEMU. Setup object initialization functions and properties necessary to instantiate the object Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- qapi/qom.json | 20 +++- include/hw/remote/machine.h | 8 +- hw/remote/machine.c | 23 ++++ hw/remote/vfio-user-obj.c | 211 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 7 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index eeb5395ff3..e7b1758a11 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -703,6 +703,20 @@ { 'struct': 'RemoteObjectProperties', 'data': { 'fd': 'str', 'devid': 'str' } } +## +# @VfioUserServerProperties: +# +# Properties for x-vfio-user-server objects. +# +# @socket: socket to be used by the libvfiouser library +# +# @device: the id of the device to be emulated at the server +# +# Since: 7.1 +## +{ 'struct': 'VfioUserServerProperties', + 'data': { 'socket': 'SocketAddress', 'device': 'str' } } + ## # @RngProperties: # @@ -842,7 +856,8 @@ 'tls-creds-psk', 'tls-creds-x509', 'tls-cipher-suites', - { 'name': 'x-remote-object', 'features': [ 'unstable' ] } + { 'name': 'x-remote-object', 'features': [ 'unstable' ] }, + { 'name': 'x-vfio-user-server', 'features': [ 'unstable' ] } ] } ## @@ -905,7 +920,8 @@ 'tls-creds-psk': 'TlsCredsPskProperties', 'tls-creds-x509': 'TlsCredsX509Properties', 'tls-cipher-suites': 'TlsCredsProperties', - 'x-remote-object': 'RemoteObjectProperties' + 'x-remote-object': 'RemoteObjectProperties', + 'x-vfio-user-server': 'VfioUserServerProperties' } } ## diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index 8d0fa98d33..2fcb9dada5 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -26,6 +26,12 @@ struct RemoteMachineState { bool vfio_user; }; +struct RemoteMachineClass { + MachineClass parent_class; + + bool auto_shutdown; +}; + /* Used to pass to co-routine device and ioc. */ typedef struct RemoteCommDev { PCIDevice *dev; @@ -33,7 +39,7 @@ typedef struct RemoteCommDev { } RemoteCommDev; #define TYPE_REMOTE_MACHINE "x-remote-machine" -OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE) +OBJECT_DECLARE_TYPE(RemoteMachineState, RemoteMachineClass, REMOTE_MACHINE) void coroutine_fn mpqemu_remote_msg_loop_co(void *data); diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a9a75e170f..70178b222c 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -78,25 +78,48 @@ static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) s->vfio_user = value; } +static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp) +{ + RemoteMachineClass *rmc = REMOTE_MACHINE_GET_CLASS(obj); + + return rmc->auto_shutdown; +} + +static void remote_machine_set_auto_shutdown(Object *obj, bool value, + Error **errp) +{ + RemoteMachineClass *rmc = REMOTE_MACHINE_GET_CLASS(obj); + + rmc->auto_shutdown = value; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + RemoteMachineClass *rmc = REMOTE_MACHINE_CLASS(oc); HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; + rmc->auto_shutdown = true; + hc->unplug = qdev_simple_device_unplug_cb; object_class_property_add_bool(oc, "vfio-user", remote_machine_get_vfio_user, remote_machine_set_vfio_user); + + object_class_property_add_bool(oc, "auto-shutdown", + remote_machine_get_auto_shutdown, + remote_machine_set_auto_shutdown); } static const TypeInfo remote_machine = { .name = TYPE_REMOTE_MACHINE, .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), + .class_size = sizeof(RemoteMachineClass), .class_init = remote_machine_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_HOTPLUG_HANDLER }, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c new file mode 100644 index 0000000000..c4d59b4d9d --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,211 @@ +/** + * QEMU vfio-user-server server object + * + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. + * + * See the COPYING file in the top-level directory. + * + */ + +/** + * Usage: add options: + * -machine x-remote,vfio-user=on,auto-shutdown=on + * -device ,id= + * -object x-vfio-user-server,id=,type=unix,path=, + * device= + * + * Note that x-vfio-user-server object must be used with x-remote machine only. + * This server could only support PCI devices for now. + * + * type - SocketAddress type - presently "unix" alone is supported. Required + * option + * + * path - named unix socket, it will be created by the server. It is + * a required option + * + * device - id of a device on the server, a required option. PCI devices + * alone are supported presently. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qom/object.h" +#include "qom/object_interfaces.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "sysemu/runstate.h" +#include "hw/boards.h" +#include "hw/remote/machine.h" +#include "qapi/error.h" +#include "qapi/qapi-visit-sockets.h" + +#define TYPE_VFU_OBJECT "x-vfio-user-server" +OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) + +/** + * VFU_OBJECT_ERROR - reports an error message. If auto_shutdown + * is set, it aborts the machine on error. Otherwise, it logs an + * error message without aborting. + */ +#define VFU_OBJECT_ERROR(o, fmt, ...) \ + { \ + if (vfu_object_auto_shutdown()) { \ + error_setg(&error_abort, (fmt), ## __VA_ARGS__); \ + } else { \ + error_report((fmt), ## __VA_ARGS__); \ + } \ + } \ + +struct VfuObjectClass { + ObjectClass parent_class; + + unsigned int nr_devs; +}; + +struct VfuObject { + /* private */ + Object parent; + + SocketAddress *socket; + + char *device; + + Error *err; +}; + +static bool vfu_object_auto_shutdown(void) +{ + bool auto_shutdown = true; + Error *local_err = NULL; + + if (!current_machine) { + return auto_shutdown; + } + + auto_shutdown = object_property_get_bool(OBJECT(current_machine), + "auto-shutdown", + &local_err); + + /* + * local_err would be set if no such property exists - safe to ignore. + * Unlikely scenario as auto-shutdown is always defined for + * TYPE_REMOTE_MACHINE, and TYPE_VFU_OBJECT only works with + * TYPE_REMOTE_MACHINE + */ + if (local_err) { + auto_shutdown = true; + error_free(local_err); + } + + return auto_shutdown; +} + +static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + visit_type_SocketAddress(v, name, &o->socket, errp); + + if (o->socket->type != SOCKET_ADDRESS_TYPE_UNIX) { + error_setg(errp, "vfu: Unsupported socket type - %s", + SocketAddressType_str(o->socket->type)); + qapi_free_SocketAddress(o->socket); + o->socket = NULL; + return; + } + + trace_vfu_prop("socket", o->socket->u.q_unix.path); +} + +static void vfu_object_set_device(Object *obj, const char *str, Error **errp) +{ + VfuObject *o = VFU_OBJECT(obj); + + g_free(o->device); + + o->device = g_strdup(str); + + trace_vfu_prop("device", str); +} + +static void vfu_object_init(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs++; + + if (!object_dynamic_cast(OBJECT(current_machine), TYPE_REMOTE_MACHINE)) { + error_setg(&o->err, "vfu: %s only compatible with %s machine", + TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); + return; + } +} + +static void vfu_object_finalize(Object *obj) +{ + VfuObjectClass *k = VFU_OBJECT_GET_CLASS(obj); + VfuObject *o = VFU_OBJECT(obj); + + k->nr_devs--; + + qapi_free_SocketAddress(o->socket); + + o->socket = NULL; + + g_free(o->device); + + o->device = NULL; + + if (!k->nr_devs && vfu_object_auto_shutdown()) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static void vfu_object_class_init(ObjectClass *klass, void *data) +{ + VfuObjectClass *k = VFU_OBJECT_CLASS(klass); + + k->nr_devs = 0; + + object_class_property_add(klass, "socket", "SocketAddress", NULL, + vfu_object_set_socket, NULL, NULL); + object_class_property_set_description(klass, "socket", + "SocketAddress " + "(ex: type=unix,path=/tmp/sock). " + "Only UNIX is presently supported"); + object_class_property_add_str(klass, "device", NULL, + vfu_object_set_device); + object_class_property_set_description(klass, "device", + "device ID - only PCI devices " + "are presently supported"); +} + +static const TypeInfo vfu_object_info = { + .name = TYPE_VFU_OBJECT, + .parent = TYPE_OBJECT, + .instance_size = sizeof(VfuObject), + .instance_init = vfu_object_init, + .instance_finalize = vfu_object_finalize, + .class_size = sizeof(VfuObjectClass), + .class_init = vfu_object_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void vfu_register_types(void) +{ + type_register_static(&vfu_object_info); +} + +type_init(vfu_register_types); diff --git a/MAINTAINERS b/MAINTAINERS index 0488bae9d0..e7b0297a63 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3598,6 +3598,7 @@ F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user +F: hw/remote/vfio-user-obj.c EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index dfea6b533b..534ac5df79 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -6,6 +6,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) +remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: files('vfio-user-obj.c')) remote_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_true: vfiouser) diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 0b23974f90..7da12f0d96 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -2,3 +2,6 @@ mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process" mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process" + +# vfio-user-obj.c +vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"