From patchwork Tue May 24 15:30:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1635097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=mF4euonF; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=hQM78QFY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4L6zTf5CgJz9sGH for ; Wed, 25 May 2022 02:01:42 +1000 (AEST) Received: from localhost ([::1]:45026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWya-0001it-8u for incoming@patchwork.ozlabs.org; Tue, 24 May 2022 12:01:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV9-00086Q-N2 for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:15 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:23432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV6-0003QS-C1 for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:14 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFHHId019083; Tue, 24 May 2022 15:30:59 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=qe8AyEZeDbIRcOJOCNoa0AywoGhC9qnxLKj+tpWkUrk=; b=mF4euonFXhNF1F46kLlD0oAidYuMbNj9sAsVo0vFKYpaMJu4o23qKgV9NvdOfh8EfIS6 +hE1Qyn9gokE9QTzpNC8ZurepPQZrcVS/UOrwOaudw148s89sBOTc4TiNLldXkasUIpk QqtgCH7Ibia2vJdcnYOBRUZ6fLEC+7jgSmbmySuxDmJ472Su1c0T7VVjDFy+PJ/ulqtC r0XYZYIR3nK+9+yLiveuwF1QafbmoHrBiW5ATPWVqAmbCH8i5vtrTZmGdycIc27eYCFi LXdiOm9Gg4iz3tanSUBpbG3awvRz1v5zHXrC1gzoV2ccgvxge3zXakL9XGskhsF4/Qa6 nQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pp06sb7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:59 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFQNej015857; Tue, 24 May 2022 15:30:58 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2040.outbound.protection.outlook.com [104.47.74.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2rhy2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mFv5rvZh2d2qRO2y/dRvJj5br55sTQcZKEX97lhVxDVZYyj+6/1HKFsxuFpbr24HdyfS3hDnK2E/mmZgGZ8d0tl0UCbhm7Sls4tmwtjtM0b6jryZkqNd2Z+Hx9INASnTlmNUn/xNIloJRoP50JSELYm+109xXcxLG/3BmygT2ai5cDKiGevK0Azq1eOm35aG9MDCar/fIs2JiHBPHQZILz/FF/Jtkc/6ZK8nMwY45rPoUMpqdpiGSoHhM2ct9J0t/2SPp0ZYjt7FGLeHoeC7a7H6BlQXGU04ub8KV5ujIrebVf+JT5jO+PagywHcD1yoqBjZVkNcydlLimFAC7+NVQ== 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=qe8AyEZeDbIRcOJOCNoa0AywoGhC9qnxLKj+tpWkUrk=; b=h8oHAwV6PD9Fa+RsHb9Qw62GpBdAqDqkoU64SGyH2zeYlSFDnYu+/UQCG8ogv4AxV+AYaJ2oszF+Pcjv+2TPS7ABWGXmJfN1TFw94dCGqyhW3MnneCldMY2FfO2BqWuxaqRsrX+uBZOsnAD6DK7YGE2DDnnUpEv0Za01TIGw5nbA+SJ9AaiAqkOFRCgmIJfNsb35xzlAVi5KOF++FNDdB2ppZtbF4cmNboH40pMgZcdGxicxliNwnEOFE96b4NACROFRN+MGvZroiKpBkKtIc2dLDI0/ocmSidv4CGmFbPqSRFIV0NvAg6tfVEC9PlMecBJ/8uJaEGEKgNmhIe02ww== 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=qe8AyEZeDbIRcOJOCNoa0AywoGhC9qnxLKj+tpWkUrk=; b=hQM78QFYNSN8+++dl9fjPxb5ej94JBhL452+bXUpNt1ydnY1bHyuhnYkCffp5iavqV2Wg44BWvVN+NvM9V+367U3sxLN2Dp6PMEQeUlhig3R91HDY9fkBVofKUrcXsxECoZz0u7B5n7rGQ9ORu91cfbW/UV+F8JXsqcgdi7bOos= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MN2PR10MB3117.namprd10.prod.outlook.com (2603:10b6:208:12f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Tue, 24 May 2022 15:30:56 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5273.023; Tue, 24 May 2022 15:30:55 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, f4bug@amsat.org, pbonzini@redhat.com, marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com, berrange@redhat.com, peter.maydell@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, quintela@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com, john.levon@nutanix.com, thanos.makatos@nutanix.com, elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, kanth.ghatraju@oracle.com, jag.raman@oracle.com Subject: [PATCH v10 05/14] vfio-user: define vfio-user-server object Date: Tue, 24 May 2022 11:30:24 -0400 Message-Id: <4908eb950f336421d900b64727dda2ba230aa2fa.1653404595.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SA9P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::17) 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: 838ea086-acd9-4aa2-e5f0-08da3d9a64bc X-MS-TrafficTypeDiagnostic: MN2PR10MB3117: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: k8gNjXnUgESp4DpeqvbW/HaJglGYFG2an4i9tlYwCMyzntzN1S7svK+Kwm+VEdaZZcu6VwA9xfISKGGPxO629dBrh+kVUVw3LSCmk9VRYyBpLK6aRZo49WG2sCdoAKvyVIys38l8Fv19bLolbRI2asZjvCBEksJJUS8WjQ0aEcDAn2FonihggyeZyXeSkCLcb/pJgeoMbp9eJKpIcAnyDPP0n21AS4aBFekfxD7gj1r8JTY1n6wQ6He0qEU+fnLmhKMfiIKRDElpLX8y0fSyjLGmSAQ3qMuWDzCTJwmI0BzuUOyBF8NOq2geWwDJLtaGQcbr6TxU4qH7ajZ4qZC8DCFX1OPy0KQH4S7s032GFY36dveYGPci2rkv2ALQhRp6zHmb/gId4+1U9nwn1J08/h+2XMFhf9awUqlsLINtwK0+z/L7v/1qQ3Il1O/fsOxogpm+FCh1lyAqrpEqZx8t8+J3pUOiyvxBUIoizPdFSVNHUoqlExAY24plQLYnWfb6PZDi3GqHPcm+rzOVaHHvmd4GAc+DYzdOeAIilDJ8Sf3E0PfAJwSH+p/Pt9Z94Q9WKB0rRo8Z0gMtTCJPj4Ku4g8ru+9WmkpDoo7dciTlbMFOYtAQAPyQINNE9eAaHw6ow8dqJ0FvrS1PN/fR8zk2ZX251xYAkMUfn+lHiBCnAjOpaVSfN06KXiDSY511RNWUrQwDkTb7kISaYuczioYFhg== 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)(2906002)(66556008)(38350700002)(5660300002)(38100700002)(7416002)(30864003)(86362001)(508600001)(36756003)(4326008)(66946007)(2616005)(6486002)(186003)(6666004)(66476007)(83380400001)(107886003)(8676002)(6506007)(26005)(52116002)(316002)(6916009)(8936002)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7rPTNuArrABhwofLMPkDuP5bJeM2?= =?utf-8?q?rVavkvCtIoQX9lulmNWJqqNnKFWG7Ap1yGNOwivwgy0zUcU7dLnYZhTr64ICLBWp0?= =?utf-8?q?6WkDfc3q3b9W+eZ+84TgxsW8T7mDpaeKJokV00H+RCHX7CQEimH4aIFm6lgaXBTHB?= =?utf-8?q?1FNr2tHRCzBrS5CEMpACjnDL4cdO0T8f7yuJR3KJFyN7yMMJDsKQ7SQUlPLrdKXNl?= =?utf-8?q?VMMSWtEmneYYVvlNVDmbbr70C+eBibNpymA5NfuHOduW9ZHPlBki6Z80t5jHBjOhP?= =?utf-8?q?18IKwTnXyWjbj0ewZDwN5SWljOJNOt4Irzs004oJM/tsRrS5KQS1U0XghrccnPcrv?= =?utf-8?q?QA4btRaToLirSu8vGkJwgeKa8lK5bUR2A6MP3zgxtlw2b6PVhn+dA/I/YNbCIzH6w?= =?utf-8?q?rkTpOItNWb1Xt1W29qRaMZQRbBS/MW2w4b+xDV/WJIonMajcCfiogZBpG30v3mI4S?= =?utf-8?q?TjehRIg/9UBL9A+Y750dgQICFryXx45y1q+KzovXftlfS6+xRvaVS3AsqkwtnkJxx?= =?utf-8?q?qUQTwvJRRX9cTVtscKb0YYtYlIfLAJejtsXJos13t4t6Bry/PwWpgMT/gdVmi91r2?= =?utf-8?q?Y4fnwpC/NwSPdHK0P/RpsaGQM3T1b1jMzDAnXX5Cs8/ORmjlVKC4IMYY7AQuZus0S?= =?utf-8?q?t8rNBesTeBvpZF0eTKqiYQ/eniYK2g5DYl3ddqJRDp4TNK4+pz7pxPj1bChmhs+h1?= =?utf-8?q?b4I6ulqpaIpuR+lsnTAnj3KBFCRQGOk3CXltGAMclQNfb5BpPrHJoTYJJvgba7w17?= =?utf-8?q?g0EvGCI+7oMcpN9qNTVNIex4K7j3eJIXbFI2ga1DF51Cz5xea4YltOHlSVieRK7u1?= =?utf-8?q?gJzThbrYvNmSUW8giW0Sr+h8kUBt/PlQyTl3o2et8rN2SeDXCOWudJSIg2NQ/Lp2g?= =?utf-8?q?N0BmRvRzUbm8Mms6FiVOBPTBh6F5xcTnVGYxAXufvm5eao+bCdW71Dh3w36bHnPIq?= =?utf-8?q?nFHwS65PUr8MZB1c4493e97ByGcy1lyd+fPrXI0Ne/AEc9mNBwUgybBj8BbrJiJzV?= =?utf-8?q?3+fw4vLE4XNcgC5p0JQXlQ1Marym5EE50jg7zvs6hpnPw9FnaJ1bL6mwZIZiG9Soi?= =?utf-8?q?bIezcA6BxShjZeaWHafZslJd0KYy8l/Vbq6IhL+Us37rk2GfbRztNYcnK20Z/+bBt?= =?utf-8?q?SdVVxPLiugq7OdSvW8VnrCjkkzaefqAJk0lVrxg4+XopK1RMOo53iwR220WBPIEd/?= =?utf-8?q?BHkVB2a0x04pCUhlbEvntH2o1w8z45+OQm4XB0i7YLK92EdAusSvsOfYIYrqUQttf?= =?utf-8?q?ZblHKH74s8/bRAAOvLp1qRgsOlAJ+s5rVCPYj0Wl2hy1eWcEWHEPC0EMOseI/EgrJ?= =?utf-8?q?bkVvWRtUadYQA2EmVEmOWZn9VNxujNlQjEQdhz1X0frg4Fq/D4JP8U4iWXtU46xD5?= =?utf-8?q?pDLt2I227jbUW5liPNy9VzIYCIph8UMTRMMpnmzN2Dtwlkwcm3LXpfXWenVKo9iiO?= =?utf-8?q?FrV18Bs+B4j/mEjkYNfDZ9ix1w20Qz9Ufa6PPWvhyBCnCk0sibO1bzxfZiW5UNxFh?= =?utf-8?q?dJDW0Npe47ChrZIZx6r4dDbsxh3KCYAbW+1B5tYhmaNWPO4YhJlh5286HD23dijtU?= =?utf-8?q?lTBtWziaTjcC+3Iy0UIzfPV6t3F9mdEa6uGM/I6HrO3fh9KxeduPKfyfp6Ss5g65e?= =?utf-8?q?4SAXxxwG9dIIPDleiU29/dB1ksqWv0zw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 838ea086-acd9-4aa2-e5f0-08da3d9a64bc X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2022 15:30:55.5236 (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: HdbJNSBS+xjXzyox8lzgG1NsAkLLwF7/ucMFGBOGvxQv2wi+tXnZlIBt2JrJM0pjIt7jwgS9afzuWfQE4Ay+RA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3117 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.874 definitions=2022-05-24_05:2022-05-23, 2022-05-24 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: rGHYwFVQ4ehySEUdvzg5ILuoo8m7g7US X-Proofpoint-GUID: rGHYwFVQ4ehySEUdvzg5ILuoo8m7g7US 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, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Reviewed-by: Stefan Hajnoczi --- qapi/qom.json | 20 +++- include/hw/remote/machine.h | 2 + hw/remote/machine.c | 27 +++++ hw/remote/vfio-user-obj.c | 210 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + hw/remote/trace-events | 3 + 7 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 hw/remote/vfio-user-obj.c diff --git a/qapi/qom.json b/qapi/qom.json index 6a653c6636..80dd419b39 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -734,6 +734,20 @@ { 'struct': 'RemoteObjectProperties', 'data': { 'fd': 'str', 'devid': 'str' } } +## +# @VfioUserServerProperties: +# +# Properties for x-vfio-user-server objects. +# +# @socket: socket to be used by the libvfio-user library +# +# @device: the ID of the device to be emulated at the server +# +# Since: 7.1 +## +{ 'struct': 'VfioUserServerProperties', + 'data': { 'socket': 'SocketAddress', 'device': 'str' } } + ## # @RngProperties: # @@ -874,7 +888,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' ] } ] } ## @@ -938,7 +953,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..ac32fda387 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -24,6 +24,8 @@ struct RemoteMachineState { RemoteIOHubState iohub; bool vfio_user; + + bool auto_shutdown; }; /* Used to pass to co-routine device and ioc. */ diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 9f3cdc55c3..4d008ed721 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -77,6 +77,28 @@ 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) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + return s->auto_shutdown; +} + +static void remote_machine_set_auto_shutdown(Object *obj, bool value, + Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + s->auto_shutdown = value; +} + +static void remote_machine_instance_init(Object *obj) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + s->auto_shutdown = true; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -90,12 +112,17 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) 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), + .instance_init = remote_machine_instance_init, .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..bc49adcc27 --- /dev/null +++ b/hw/remote/vfio-user-obj.c @@ -0,0 +1,210 @@ +/** + * 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 "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 c92d87daac..8121671228 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3603,6 +3603,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 7da83350c8..0eb5a0f375 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: libvfio_user_dep) 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"