From patchwork Tue May 24 15:30:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860318 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 95DB4C433EF for ; Tue, 24 May 2022 15:37:21 +0000 (UTC) Received: from localhost ([::1]:33936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWb2-0006p2-JW for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:37:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWUt-0007i9-7s for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:00 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:35498) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWUo-0003IY-AW for qemu-devel@nongnu.org; Tue, 24 May 2022 11:30:58 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFSBd8001529; Tue, 24 May 2022 15:30:45 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=0uRayL5z567S29gFcHMdZGvSeJLG07vFw920SLWsmfk=; b=uBtrBTVaHzUOv8XWb8Hnib4ZKz+JDsU6mQBTcCJBgt4FdAqEjzlSZq6aU5ah4EZUoM3v euo4p2/K8lVRzxnaDGuZPVVG9uRbmpbA5+oSTkFQVLUK/AGiOGR4Yit/J/863ktpfrQE 3KQqLx8K8GhjtqR1/faCVMKBHiVtSGr7O1JKpGHEKXnFR5EHwkwa+J+zV0I7NfE3NELq 7IhkEA0+8IKGK5Lunuyri3vhekWG1g6sQkvZgQm4GfCobWds3PwU3xJqGNIvpTZGlo1p MvpLFRoBsItIhJtrtNpWPZJQNqWqlPYTHSbB9gjE76rlV9aKbAb7G0RJYI2C+jIK7sg7 KA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pgbpq8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:45 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFSHaY013144; Tue, 24 May 2022 15:30:44 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2046.outbound.protection.outlook.com [104.47.74.46]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph8x0pw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jo71oPyTIomTwfsL+pSTpR4DZfCzMA0vEGB0g/KE4aACFOtoYi3ys89c4VyZTf3l/d+XOvT5AtsEQCEaB1rgFZ0OnEcDP68AgFbClWKgo1HPqUCsqWJSQ/UM8KiVuZojg474xQ9d76uQnl49a4i0wJdbmXXc+VIkuW9MEO9oufuLUU9V58h/jGO17ixmypG1U+YDsa/n26l/Hyg3BNCB2eKSTKXpnBIH3EDKBCTKi43D+ybakRZxuo+MiYdvj/L7kDGVWg/2EcBughfnrF2jcp6f/wJdYA19biTLIVG6e4IJgr1X5LIFSRDOAbfMfDd6Hxm4s6VnCcv9qoDPf4+cuw== 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=0uRayL5z567S29gFcHMdZGvSeJLG07vFw920SLWsmfk=; b=IBcMhGvrGearud73vw8almwVYSvNYFBc8OlZX7e7uni4c9XbTalUF+fEVcNExn9uAv3TN6FsycftvrUclOF5JqFMLJlJvwz3RaCIMmduAEqm9DSf90HLj6WabaoXFLWntkd9MuEmw6u2MU5k4peJtEjA7UIF9EOPwFc4J/idNBjsc2zgQf0ELjGLHmzrIyidGnWq6cgxi+zDxaYR4hUWU88mHEh6soI6xyBtQF2VEmMDdN46zCgBI74BLAFth9FxaDg4LhtnAd9rLdsrIsq/YH7qOYh2UA21u1nCITYbnwcnDz9DSksOvDeNL2At0PUFqz5FRpdrbbU7pHEx9D/EoA== 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=0uRayL5z567S29gFcHMdZGvSeJLG07vFw920SLWsmfk=; b=JKsIBza0hePK77u8hwClfpnjp5jCwa9N3JxuH+mg6+lvnpJ781QyjhwqB0P5NqE3E9AMvj3noqzNM4hVzuYqnVpsLJyw8NIUAOTY5duMgrV0fDkRGDW258tPSlBSuDplDh804uEoFDddzkE9x9FwXd9dc2bTUBLfmOUFGl2Zuic= 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:42 +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:42 +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 01/14] qdev: unplug blocker for devices Date: Tue, 24 May 2022 11:30:20 -0400 Message-Id: <55ce4f2ff38a5c38b81ceef0eb175a40ccc9ef6f.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: a0ba6173-f1eb-46bf-4d6a-08da3d9a5d47 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: IcTpX0ZD0v7z4xkYJnaq9p/P8Llb3SDXZvdtSzQXV7otNDQpQDzgDdIZmtpWjG0WjDC3AEHWTIcY1hswKCHtCl8nVbl3sh0xrM6nyFWkKbo6YEfQOdp9kVRvApFw/h40holQnOml0wvkc6tv/ydzwHG/87gzPwnZZmmjWQUmG3GsDotuQIJAyDQUK9AB3KWoDJ1CcNE0DZCZW2cGk+Oo+md+VS1jLGi1PnCbkNx+dmsKX29WLNIwj1bT2j28WiSSkbvIIgF78Pkq+qmdvqxmgp9gUb6wmr7z6ypStECxAI0ve+SGxBYkZ0WNx7RaxGCkczU16FxGlphL1KLz6NwHQQkxqwLnhXxdJ4C2ZBThfuAtQVADE7YqOaNefqBZ6Nf69/mjfDFxVQpgvY++e/RE6kFRwcDzxj1tlX2r16TQs4QjJ+0dgeq5ZJntnqVky2yWpoXseFaMIxS+sYWaexutyXw1rwiUEFJ/0QLjfembK7nh24fjgE61zFmwJNN4D2uQ+zNbRMiZPjDT5zNoMS1QxIbv5r50zFjP3N7/jctDN+Scr4ODY77k+u1zM7e67FsLPgrcwX+ITbZV2dnVtki9gBjW3qr6PK+8gv5BnPTYuBrpkpNfFGMk3zlkmMlbe3gewyreJON7DT9WIB0ucjpE2BX7YLawWxNp2eDbrLadAkD5MHW6w+8mGuFc6JXGNM1op3ohKsezyvQMS6z9zmgYdQ== 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)(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: 2lJGOKy2KGHJeajGuI923DKfMsMZqNm8ENH+DhhwbFglMrDPiLI9/5fIc4q0jakDI7tjOMEKJnggCxwbQEsQsqPBJRWmopMVpCJohIOX9NC/QNmNZsEekpd9fMlfpxhdUQfLukx0HYpWsRG1HpojlfpTJEnm2ggqHcu5XU3F5/YUnUDoU+v7aJcE6jchgnpCOEaWXuVbsdCm7sl0wByh6KRsvc0fUpKohFiNuu0uH0S+JTsCFxI75QAcrJwU2yNtjhva0SaWkMwILzDLXevR7RC25rK3RLTQVPZovJTFN05AT1zs1lBs72gCEDn/4PN/z4bkqs80v/bn3ezhOT8D+Ma2U/tBgHA2mz8rK+v6J16iCtnD42N2yyifeuWO8oamw3Kos3j3pnVKmUMwWgxo3/aOkuBUBM6tY/bnj5Shxs/5W+gtC7ARYfH1ILIiHx4EefW/dCHsM/HzmRsLjsfgt3q3lA0ZbQMVVPZhQe0lTuZNwaeOhqGsOpXRzSK4BaBos0EnGtoKWXKQ26FJBnZ8LGPGu5Fdk/Rnl9asStnvPxusYdei1bkXMJ5Sq1PXz3bEhy1v3vX0dtuwpiUzsYDDILB+fXtCUI2I1ztYf0jqwfLTJ/qOdLwAwD/bYd/Ihia5glyngcTz8O9Kyys1nBRviR5dVIFJjYui13Bsu83LIZbTJYoMyTOjuzxr+V6RElfkwhSfCPj+SW45tL3GmjUzNrWuqEm8PSvu6wiGN32zIaiuQfjZEpGPcois4y05S5lSpWj7L2jrC/sb7NJqBrr9S3nGXu9tUTjAW9MM3B3BUi34I8chmZyevrHyqH7LBW00dW7tfykkwc9n36LUVHQNr6s2a2NZxn0XV1wi1HC8+gTLAcU9c7Z6WVqSDd87jNi3jWkissSw2ACfCJKW4EnsdumWFJKq83DByzQJe5t1uYQNTTq3BDKxMgH0CVE2NbHLBKn6r6onqUt8v8gGSthrBagBCNUnE1FYUlqzMezuDmRrmq4Gigrg0RGLN1FDYfZT+PSVxqXpWVuOYyxhgPYXj8YmaV07O03ephFhjgbUeHdEAZnUhocXmruCH3m+xFPwYUDQ/qkaZCKVNbT2I0DFmBGqkzvAxoB1IZagT5OgBnOZrqVVo6yVYtB2RiQfaOMFc/oiQtUnTDwfgz1Cvk+C3gW6tJXcm0Ncfn/Et5ALXNb0a1htVwmqy6AuaH06gc901SgAz7YiiJchnamv6fnvHs2Xqm5xhq5uysYQBELUihtw5BINfxdGaTZJUQmf5hKp1Mu8YLNDO3k9KesIryfXqDRrY6cPoW8r429pBPf8BiCvhMKHeGNwgOFXI7JKJxv+sEVL6eeZLmeDlKe4uzA5NvoOEWOKn/s6npNl4fkChjXGlkJ1xbc5yrqgNU8JME8vKyRWb2aDsR31yTdvVVvbZ6Ik4Omj/u6rf9sQM+ooueJ7SZMW15bwBUuWbpeb4JYm4gJNxy6qDheb6Fy4FGEn/ejDeGEVQ40CXIAd3r9X9/qyuNN6Zjd8jL/X/2cGPf6Kb3xKR0SkCJPXjVxiCWQJncYuzzmt5YszVq44V8MxUkgMmDbwHXS2u1nH/9bmDpYGkCjT2UL8UEn87FGW/Sik6KZ40qS0I+eVUfaaVFYwww6KvUeDdiNgWVDyXPtEiuZXhJVr4wPVLZ4d6EXzmNEnpFmqaP0pkK0cmUfeAkF2Z4Ks1vNg1UhxwdZgkUkRS/CGyhygjcvFtQgmdeAHSLQQyw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0ba6173-f1eb-46bf-4d6a-08da3d9a5d47 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:42.8058 (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: pzrdFioKKUDb8t0CwIjm0mRYBP+AvRCYlOQGYGV1bzqPWx/HqPiln6twwdqF49UOrsUpL1a1lTQ3FjclnHQzbA== 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 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 malwarescore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: -qz-Q-EvC5xdzEGtY_Y4ztUI7sQSQo2g X-Proofpoint-GUID: -qz-Q-EvC5xdzEGtY_Y4ztUI7sQSQo2g Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add blocker to prevent hot-unplug of devices TYPE_VFIO_USER_SERVER, which is introduced shortly, attaches itself to a PCIDevice on which it depends. If the attached PCIDevice gets removed while the server in use, it could cause it crash. To prevent this, TYPE_VFIO_USER_SERVER adds an unplug blocker for the PCIDevice. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/qdev-core.h | 29 +++++++++++++++++++++++++++++ hw/core/qdev.c | 24 ++++++++++++++++++++++++ softmmu/qdev-monitor.c | 4 ++++ 3 files changed, 57 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..98774e2835 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -193,6 +193,7 @@ struct DeviceState { int instance_id_alias; int alias_required_for_version; ResettableState reset; + GSList *unplug_blockers; }; struct DeviceListener { @@ -419,6 +420,34 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); +/** + * qdev_add_unplug_blocker: Add an unplug blocker to a device + * + * @dev: Device to be blocked from unplug + * @reason: Reason for blocking + */ +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason); + +/** + * qdev_del_unplug_blocker: Remove an unplug blocker from a device + * + * @dev: Device to be unblocked + * @reason: Pointer to the Error used with qdev_add_unplug_blocker. + * Used as a handle to lookup the blocker for deletion. + */ +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason); + +/** + * qdev_unplug_blocked: Confirm if a device is blocked from unplug + * + * @dev: Device to be tested + * @reason: Returns one of the reasons why the device is blocked, + * if any + * + * Returns: true if device is blocked from unplug, false otherwise + */ +bool qdev_unplug_blocked(DeviceState *dev, Error **errp); + /** * GpioPolarity: Polarity of a GPIO line * diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 84f3019440..0806d8fcaa 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -468,6 +468,28 @@ char *qdev_get_dev_path(DeviceState *dev) return NULL; } +void qdev_add_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason); +} + +void qdev_del_unplug_blocker(DeviceState *dev, Error *reason) +{ + dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason); +} + +bool qdev_unplug_blocked(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + + if (dev->unplug_blockers) { + error_propagate(errp, error_copy(dev->unplug_blockers->data)); + return true; + } + + return false; +} + static bool device_get_realized(Object *obj, Error **errp) { DeviceState *dev = DEVICE(obj); @@ -704,6 +726,8 @@ static void device_finalize(Object *obj) DeviceState *dev = DEVICE(obj); + g_assert(!dev->unplug_blockers); + QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); qemu_free_irqs(ngl->in, ngl->num_in); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 12fe60c467..9cfd59d17c 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -898,6 +898,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) HotplugHandlerClass *hdc; Error *local_err = NULL; + if (qdev_unplug_blocked(dev, errp)) { + return; + } + if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); return; From patchwork Tue May 24 15:30:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860316 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 AD646C433EF for ; Tue, 24 May 2022 15:33:22 +0000 (UTC) Received: from localhost ([::1]:55570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWXA-0002C1-ID for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:33:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWUr-0007hl-Fq for qemu-devel@nongnu.org; Tue, 24 May 2022 11:30:57 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:34780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWUp-0003IR-0N for qemu-devel@nongnu.org; Tue, 24 May 2022 11:30:56 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFJgGe015053; Tue, 24 May 2022 15:30:49 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=t5tgMMmXpRvBP2cJyjBHcmYEbrGfrdT/NzKncbAou6rb2A2GD8H3tVxbzt6SpnIhhfgP J1DSRj8/EPRfWbd92qofQ/1MpejitxLOjuAA1jcIqSlDKD/EsdA/jocQ6O5zv3scYTrg ligaMUtcIiHRbavw26JvdvvUn31z4gMAebvRpfAR3WaDdwLssw7Quz2erNR468VZRo7k 9dceRyP1UhvqjQSzjqkYTl8swWubXoyNJBfPcq0sja0TBzYDVnDhVDHwoYbTHIZMwgyL rNT3+Ow69KmvzA/P3kszWfhRCdwlS+6+ffG9ws2rkzbvaEjRdbOr2xndNjl5qCd//4yL pQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pv26wcq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:48 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFFrjE015045; Tue, 24 May 2022 15:30:48 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2042.outbound.protection.outlook.com [104.47.74.42]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph8x0r8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gLxM4lVfnvsulH7uC6D5Y/ab6odHnNfgKXAn/zxluylkdoMgRuNsTXFHHfdiATEFXNLhPO71guhdg8XEHsd3Z97tf65D32/e89/60idMzMSgctuKHEZQOcJz0lrq5RVwqzzOVKqcMZWzv6QC+nOByxP3V5fNciyPS/t/kCNRobOeB1EIPC4ZTDneJTQTB7OpIYRYgCLnvXlc0cZxSn/oTyvWeN7V5WKIRYIKojXJyHEpj5y5c+UEysOspt4j1wzSTISF9svCA3FLln2Co59bkWOfvS4pzZMdHTw7a4zDpADql9mtNGidnaeGMmSfkMRdHD1M3SA/UtRoC9UeYEwrcg== 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=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=cXt7R36Ox/lQ1hcd+RAxy/JLIY6FtvI8qkqIjakWlMZ+JhwDW6HMREudlmvBiN0mo5Ga4xNIR5X8ktpVW3WwgBlpZsAyb9zmTsYZbX2r3NY0ij2C9Zq2q866inZMuoXCwtj9Etznv0IoeKngXIOGl2+CpsGDHW+OCEyDDIxDSCI1otZS+6g8nCQPV/bFOOJsuAw1YB0SNU7sx+DVjWcWoqyczklcoBHfyMOveCobqigtVUwWLq9ixUpqIVWoI3+LBOXfQ0AUuI5U80jmF6sUZbSlHO8cOndgMSoibZR26HOKoIuHsP8yzSBYg4wucJQOk4RhiV7LZ4Ujm/Up7SXzEA== 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=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=RfB6RYYZJ8s9yIU0YGLwr+AVVt+wQPuHmvR3kJX0HPPy7i4A5sykORIz5eD6qExrDbMAdYWif9ANqxbFl4u9Nl+aXldEwPsld7kWB2AXsqkSkD69UQxuiSP675W9PM2BgoTfUQl0gwAiKamzZZ9txSJQTBKVOSJzK1CB5qyGDxU= 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:46 +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:46 +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 02/14] remote/machine: add HotplugHandler for remote machine Date: Tue, 24 May 2022 11:30:21 -0400 Message-Id: <7b044dc32307309fb0e03dc6453ee075e4e39096.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: 62c35254-1611-4661-7f61-08da3d9a5f07 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: /cH4z6guJzaRZwCuDwNHH+B2aIhO5LPJtftOni0RcRJcKXBJkV7GgelzfjEzl2oO3FrU1X9sv5ZT4f+myLtIHfTEANaNmV1FU2ZNeesy40+NRlsbzPzW3LX//QTjRN6Or3hIUyLoqcg1JPdJv4e+iiX2fj2yzD0HUpPAXFVhrrx5sjZnKWEItTrl1tZIgCVUbvNSbFcNRrClke9Hh4XSAd+jzRlw/84hrDiffxY1Qsd7FOaPju1JyxNTq0aXh037/939MKRco4cOUYM87oXCNPjbl831fUOdSZk7Q34RlgEoW9N5gi89fCtd44SGzlbCEdrVG3ZG6Ns1ymYoipk96icU4sNbAwgx0OpMiPvB/WegKJBrT5brvtYmG6HgEKDytWMjAyhAuLU5rSWS6yXcJEGaNE4YTjol6NOna7Zu9Uc5eR549xj8FGws2oZyZqufeDP6LVwu31SxFvnnI3x7fZE3hJ2Gmb7gaqR09MUi0anWxtw+jDgMWLT0c1q1KSBVqI9c3stHr3CrVuS9g0MXZPYF+qo0N1DZgYfdmva9FxA5zZ5mbEfGC7juFE7VP0JmuGKExQrCFhLiVHTLojRJeeHngv/YcSqMmIom3B52HupOgfVBa2iEXIyi+myE6GP+K6rTrtcHZ7Jti1Xi+6yflLr82fUEUQfo83cnWjamY+KYVSqZldd4hXCih0UhM5k+AmAaXqyNCNQOD2BekNlVQQ== 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)(86362001)(508600001)(36756003)(4326008)(66946007)(2616005)(6486002)(186003)(6666004)(66476007)(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: r+5P0XvcAEhlpC+31PjAzBfGduiespRcTqHzV9z9oS0XzYy6reOeQhg2qKAvhbmLsiawtcD2pqtlugb04cI5w3sbo75TUjXZgasN6XkCwCgaMNvuiWIEbVPiMM0v/a9QV5awyjiL9iMeK8sBxQBRhRTgkg1xUsgDU59g6UV0RWv51JfJUqBHqQLZHorpa+My3Y+UNDy1vfiWa9OGiThCBLaCIfC6lzefLnp70vXosaI/2lZqDNOATiKZKApiUFHrDgnmBCeQWcSC38oTMtkqNmddz42TddPKOd6Ci6NV/76AC9rUX6Haq9lt25x7NSnBaA/LasM4Hyzj2XV40z2ougJsqTlCP60r41uhGQyxEP9ruGGNMfdY76GiWqQTh+AQ0B5UiZOSa0oL74xvt0mQXcUXAzQ1WUAzHD+4K1tfZH8VHB8CJMMs1GsWwJ+4M6ACZQbsTuUmk0wYZbQFgoh2iLkHeqlo2nhaD7AD5jOrdNquxQy+DT5Ty/31c2j5beRGYSVEy0CY8pcGPTv1RHjTHG7eJ7uBRAtM/cAEkKq2hR0yeTe5+l1o2If2O1ccxVLXL19CczLkjjQExBCbRHr7nZZrldvY6PHZ8npaMyWd3mWxw7Y0ZsuTHlrJcqFNBiBQpxtglDrhLI6oozYnCgqqLQTpE19phE6n10ZC7r5rNn8I5zIoU+y5Zjv0R4WOT96lBZHAtZFJ50V/Uj1oSpB2/DblZT0iQysPMSZ360vqyMNfYg24b2A6/a4orEI6FcbcEYKc7bCbqI8GsYdKz4AZpM7XBlXJcgGJLyEJ/1Acarhyduw7qmtB5UzoUhz2qy0SNzh9o53tyNmn64rQ/kM+k8+TpWxGVx+pueCOs1LHm3s9VctAP2Sm6HnEvtrWb30XGycyX5YrVMuEdz7ckByTFld4dsJR1b7cbQtbKsN2mhkH3aFlNQsIghV8aRbNFsmEzwhJm07cm0iJUgoTfFSF7cyWhW9TPOCV1TUhGWH6Irbh4PWr6SYlNoSS9t3tnqiho5robDcOAFgDIx/S1Dm/m5FEq9tV6vP/mdx+Vk/N1cQtkRTgc0US9pjq9eYAX7HZjEVoFQZOpCRDxA7POSK5TvkLF3vk2VlJcihcuAkBeXy/axrWGi3+NAX8zOnBKtwM8pArqVKflbZTUUIChdJCI61uKrubGf6qheQzBiVUJdAfF3TRZOs82XqoLNH/vCbBpm2DeRG8MUpOOsRJJdem7nV7plgSLbY9uWA3RsrY9G5mIVmur2iskHedz4GYiK/+s4wjhcZgXQ/UDRo8PnVEt2LnuAjJw4mLDCVSXGG7uQrxNXEWLkBImfKyYwuz5f6UdTAfWiIXrPxlxcxFoij0X6nrg9unTOxF7T2vUFzyJAa2P+2AndzcccgKhpTNvmPfzHrUTX+FJFsN3QrPdoFmwjX0c9dEAU5JNTDwF20tGmfHgKUr1JCQr6njxHfKCBl46PyCSRqcKoZqP0t6xoM/BBJO2klL4NOxYdFSNVak62j2sfdpexUIpKB2rcvm4x89o3BDB/UIDlYcf1JzZI1deNAECE7ya5nSH9Ibc0g2RqR7OdsLeo2m9i4bxy0WAX7CZ66+829aGwNtRCUfuyPKk7texV1bvayREkGuZ50RtzmzYK2h+eWFGs101SiJCydDNgg9q/PUy0tLQasqjVw8P6XVX6FJ0JhQceSGkyTIAfKU7o2MGS9ifRWWJ3f3gYq2SD1IE5ENS5F2/cqWo90Yiw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62c35254-1611-4661-7f61-08da3d9a5f07 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:46.7430 (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: 6rs3hxSWQe+pNA++a725Ov/kjSWD6IEEIN+seE72H9vkLY6Q90aHvd7XxR/gDNconnmO/dx90DXDqd835r8hbQ== 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 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 malwarescore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-GUID: 95WGRL0njyJgU-uM2kL6tG48frVzSqe1 X-Proofpoint-ORIG-GUID: 95WGRL0njyJgU-uM2kL6tG48frVzSqe1 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow hotplugging of PCI(e) devices to remote machine Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/machine.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 92d71d47bb..a97e53e250 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -20,6 +20,7 @@ #include "qapi/error.h" #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" +#include "hw/qdev-core.h" static void remote_machine_init(MachineState *machine) { @@ -53,14 +54,19 @@ static void remote_machine_init(MachineState *machine) pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, &s->iohub, REMOTE_IOHUB_NB_PIRQS); + + qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; + + hc->unplug = qdev_simple_device_unplug_cb; } static const TypeInfo remote_machine = { @@ -68,6 +74,10 @@ static const TypeInfo remote_machine = { .parent = TYPE_MACHINE, .instance_size = sizeof(RemoteMachineState), .class_init = remote_machine_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } }; static void remote_machine_register_types(void) From patchwork Tue May 24 15:30:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860327 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 C5CD2C433F5 for ; Tue, 24 May 2022 15:41:58 +0000 (UTC) Received: from localhost ([::1]:41950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWfV-0004Cq-PX for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:41:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV4-0007wY-Jk for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:10 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:12430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV2-0003PN-Ap for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:10 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFETSj009629; Tue, 24 May 2022 15:30:53 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=IdFAbH93PmRiCbpyTq5R0UwRSe8f18zWoPloE0ypbWy72Gj0zJ/K6gP4MGSpwU8moQAb C/Ac73ZQo7+LRAYCCX9Xo0apEiwzISNhhV6JoDTbnrYSboZtfGgWp7UbY77+XG6RY8s7 XWcWopFFrChWgcR2FsrKhQl3Apb2kp0ajs4n1ge+tw6NZ8innOW23xQvtbPfzLt3AlAB JnEh2C0dClb4b8p1XZZ90opcSljhPw8T+zBzJnpPtObWhpGaDCt8rsQvMxSl84iK370Q eD2qaf1RXAmHwJw/Un7fvv25Fsnbd+i8J3CINf5Lr3o0KNzcCMqqDwpfV1EFJdHn6+JX aA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6rmtxrh6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:53 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFGKdw040364; Tue, 24 May 2022 15:30:52 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2044.outbound.protection.outlook.com [104.47.74.44]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2h27f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lI+qCPRmtwpnlEoyDAYQ1eUJaNKPq9ZDKAV0f6iqkv7buC8l6Ve1Op+DOL7eYS/U/h2CjDLLal1fFSLOMhXtr2Tt9exFXVH8EEnavfscF4D8fhODXGtgo3e09n4oh4jzAwc3xp0GX1Pha0vEAr0lggWdS6V+OFwyK6D94uB3thVnnUCczF/OVIk+JzQq3cye+Llj6gi5ivgHPGtf6Tt/7/1zK8jPwjYlhzWKeALdX6VqiXz7JaYwUUmZhwOlOky7z7j5YTcPq17LfB9RXca1Uh9g6JS5tmgttbpSZUxMMoz1TXM+Qdxdv736QbkvjRWniThtulGD+ncUMre5RNRrAA== 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=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=icx/2JpG6EF6bTCLbCz8g2reKLy0rhhUxbDmKTkxMUC6u8QtPONUgrIu7jrUFZrgZfw9N8ofNFOv2AiULMJpENTpUQq4mKMnd/BUa8ovJ0idHTAfakJdqN4zzAed4RJbzmllvCk/loPy3d7sZNTMmrI0Wd7yiuUkvAIvQn4tlgRxQCpYHoJXqgwgW3PjqYCEcjBhWUTohw/SahCiBCO/+oQCT883WMJ+8+Z88WOQMbKTEFz4jaotXUvaofq4gkuyjFjOUMOKDBLQth8s/DQE9utWmbQ+GWMFOk1bLZ+qhF3XM0bgI7sUTQV5ysEyFO90My4SbxrhG7fAGENMHD7iYQ== 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=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=rCEctZ6aqC8EmS1UilIzxch/t9zLG9peq45HSv35o1Qh/0yPcfG9Q1O+9TLOmyMt8DPWaLl4wXIBGvS6TbbVpKvqNIyI4OUF3ciwt/qaBIThnXzIddAXyE4A5quo16nrqL/zw1R0y28KOF9rNFjG8gJbpNDIdfBHCGSSznFcIGY= 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:49 +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:49 +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 03/14] remote/machine: add vfio-user property Date: Tue, 24 May 2022 11:30:22 -0400 Message-Id: <3743013d991f74576e4b114f3839cc858408fa91.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: 3dd424a3-5d65-40cb-92c1-08da3d9a616e 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: /BItTB7cxrbYnuR2gMIvGkgh9D8mNwGAPzp70UYwYhJJHPZ2gwRI4o+6kZYm94yAsTgytGCJLDCQefDkg53Nm1FRw89DG601V99Cze6FrSDAFdMV4Lnimrw4Afbg+qxIIbRrYvzfRNGQEPpUpD8N+ersqN5F3c4DnfT5v8q1ukUVwPAtyUm7Qxj3viPED0W2WoaOmbCUr0j67hoSHdu9jWlT2LrcHFqJavBi0zgzOd8twlgn990Kd7EhbTzZ8DQRbwCjxpou34IuPfz0R2lYDKAXhvTGire7rL0xPpCapGSqHxVNjHMFJyk56sx+B74qxPldDFESswziQ5uBXG0jDa9ZoEbRkgf9lsFBACGl7o5KFhTGU/5nJdSgmu2Zafj0zV2OXD2X9tWz43rJ1VJa2MdP+qcvYA70OWLNSa00Qraw7rdM2Lf2RNA7ivcWh0n91kYpQAPH6cubZdJ9Fm88mKiiv4mjmOxMHkUUUxiJ79Ghyet6sXDF0It5EuJmWvfjC9YPLszvrazJqERTKPiPJhSgVC5UP076De6wRJMJFgFosfl0/0xnwKD1SijAa8LcK64sheSVFFbPw9bLn4dBo07ddkRJ4IxtYwt1i8QsyuvrhY2bcXv15YWe2dH0lNy1XuzwpucLbrztuVkBi1Cm84EcGU6hQVfGsx+04BD/LsuUSCIOeLhudgMagopYHAd08VX8MQvAXtVKzrlA1xuM1A== 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)(86362001)(508600001)(36756003)(4326008)(66946007)(2616005)(6486002)(186003)(6666004)(66476007)(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: OlRcuciIKZHwyCBnjnEiGysL+SojYvUbVBpJKREw6iQC/fTt5QNH//01kJrg6Bo++hzSz/0XabJiDU5C8x9jc58x+6HZwyMwMJZmX6MVSnfKVCnec6lT0xJ1WRJSgGYwtw1z8Vh7TuMrau1SUF8i4Nkji6KSXbzppQdjwUJxpyPA5a1O+GPoekdm3rO2tPuBPrJwN5Ne+50MOtZW7/twZBHo4wz+eohSI3RJUjnImgEjUZEHzC+vpiVc95aijTjMKtHckBckp+OQfjIaVfv/q21nuO4kexYcfAlwV7LJSYzeykXP0+fyzaxO5S5eQAi9sbG9kurOegIwrEWFLT/OlSDHZEMftX3ZSIL993lHzGRdj7NecganKlpijQJnt6rnkKKMv3+nCLKjQFlg82jatYEW5GYbi7LUJRkP13v+11+5EDMQRY8/HuMnGH8QKuqtHNTCaVOoDJ0Mx88QalvqkeIuWH9+/rgJlQvGNWUnrabhFJkSRxSFwwJdevSRJsqdcliFEXgqFJmN6oTWpI76J1Djc88wW/k3ElDNniNY90uwYZ4zIl3JtnL0YaWV+n7KcxINh5JjDebtfCGOsS3HHQwCCNEPu8Z2wJKyFovW3T7DRnlj7a+l2x2jErtzIxVC1TYj/DLERHO0rLWlRmI+P4R78JWoxtJrvdHN8bdA7ieUDNGYlAygoT9z24B4qsnT4Xw9MPnCdO+ub94/I0kqFAWVrqLzXNmQjCTfyuVRgy0m+7GNWs8b7T4M//aEk//6vLoPVBozPUINyZV16Oj/l0fkRKY9yBRz5fV/euZCxvRyNCZXMfTfdeQyWvfwENgnWNoqURvzvAGHGMnuiCyaJXZ64ADSS/q5wCcbpFvu22lvPqjPEAzba30uP8/EIxzvnmGqy9+WQarmtaM4wvl9kB4xW0LAoHg3JjCvDEwQ9rdKzLSkBgwrvNmhH70elgryrJJ3MhA4k7Ef2m7BMnz/4Bs+Ty4vF7k/25yCA44mD8hph8WbqxKPp4hzHtS45HC/M5SxFbynMnPGzCP7UhEA8WI3QVnnt+c3zSL2NnzSCCYa4pcoR3Jhlw1V0VJfuIud47XeSPsyEpaDuIO8Ogg65fk1IkzFqiNQRzwyu3+24h7VNESkVU1PUUhVNX9Joeoi264EgIdWhdrI7ynsI/4qjwFZnX7azQXgKfX4j1uzHY59Lj7xGDWNRzMr9dwMWlh1l71pxVJfRsB654ojGn06ccjyjHUK7YPAxIy18IdXAHjFrScgll6QOeGKCylMFt0cvL4bXyc5LMoZUmytt4nGt4fG7R2KUKCCdsFj45vlRubayu+zB31JV7cJPOSZVslOL2zOxtBOuaX6wcOdn8uR1Jcrgzyk5MH5LYS7lnn44vaFKpvfhzhrYaW4D+sbzfyjYzJEedt2TRun7XKVnnGE8YMsGJs/9Q/3Rm2+7Var9Xl0VfLqHqcuxjgCE3T14i6ZdHn9tWw9yK2reYpLt1jsihKccvj1U2/vfyRZXCwmoqEWM2xD9tLbllRAwa2q6+kqeXsN0B37hnO7DGDaT31mBibval9ddMXPWP+PXf5E0M9d2lvGFQTliKgPil0HuTAHGfSRxxVTcowQTJUcd7DFnqqKFM88769QvY+9Tjitr/Xvj48rQUN2DfHSZ0EH5qXfy/oOL9Ssp3J9qZ2uKnsXImOgmD8AerxpAFpHDUNpQEn7ICATaPhJLb9k8OOlmyl66Bnyh1ICOV0L5opcWfC+0A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dd424a3-5d65-40cb-92c1-08da3d9a616e 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:49.7428 (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: lghO2KMPEsmozKgBCJORo7u5v4x3r0t2aKCZisDh/AZD5oQdTI6nJguAhGgrOYG55KmlV1z3qV/eO++TshdUHg== 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 spamscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-GUID: LSPaUW0vE5vYLethJoL-mpta8rj03NDh X-Proofpoint-ORIG-GUID: LSPaUW0vE5vYLethJoL-mpta8rj03NDh 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add vfio-user to x-remote machine. It is a boolean, which indicates if the machine supports vfio-user protocol. The machine configures the bus differently vfio-user and multiprocess protocols, so this property informs it on how to configure the bus. This property should be short lived. Once vfio-user fully replaces multiprocess, this property could be removed. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/remote/machine.h | 2 ++ hw/remote/machine.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index 2a2a33c4b2..8d0fa98d33 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -22,6 +22,8 @@ struct RemoteMachineState { RemotePCIHost *host; RemoteIOHubState iohub; + + bool vfio_user; }; /* Used to pass to co-routine device and ioc. */ diff --git a/hw/remote/machine.c b/hw/remote/machine.c index a97e53e250..9f3cdc55c3 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -58,6 +58,25 @@ static void remote_machine_init(MachineState *machine) qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } +static bool remote_machine_get_vfio_user(Object *obj, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + return s->vfio_user; +} + +static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) +{ + RemoteMachineState *s = REMOTE_MACHINE(obj); + + if (phase_check(PHASE_MACHINE_CREATED)) { + error_setg(errp, "Error enabling vfio-user - machine already created"); + return; + } + + s->vfio_user = value; +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -67,6 +86,10 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) mc->desc = "Experimental remote machine"; 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); } static const TypeInfo remote_machine = { From patchwork Tue May 24 15:30:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860330 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 05BFDC433F5 for ; Tue, 24 May 2022 15:46:39 +0000 (UTC) Received: from localhost ([::1]:50630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWk1-0001th-V5 for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:46:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV8-00084Q-Ag for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:14 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:22228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV5-0003Q6-Pa for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:14 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFQFWo001866; Tue, 24 May 2022 15:30:58 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=XjbUDJSsQG+4X535tz3BzbjtqJBfYtJlCnSMhr4Uu2Y=; b=LxuqLcp71TbHKo85zW6nZWIdTgGTJRae4St5gzYhlieeTR9neTanzZ4mJunlsCCRsLa/ OrdE4B6PQwkTEqYfg/jZ8TXBSpFj08sWjfdBAiXX3JwxGtqHRGBEjkBaaPQ7ZnLj3ZXw VCi0SCKuntHoJ2ApT5pl89t4NpjqR1vhaRAgO65jw2PwF63bLpsO5pgkeMahM6aZeoqP G/rPbsM5xfFgzzG04lJeNw3iI2EZXDErwBsUyF8IA/v9PG5SKRcVxHZSJEAXRK1gqPGe G/M4YM/hAWtCZWI7F5zqDJ5mR9lnKWwxNtvbZwGiX3CX8vErELIS5Lmv3LApM9zBG7ys rQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6qya6kkv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:58 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFSPgP017641; Tue, 24 May 2022 15:30:56 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2049.outbound.protection.outlook.com [104.47.74.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph2k4x7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:30:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V2qVu/anCTMaPagmjaMG2oByBftIM7MABEtXNHqMVOSNNzf3dxW8XoQr7YcOwEUBSc045ocwvV50u9pnNtRiWzJuFkg4l8Lu0s8MxG2DiZVcLrLTEczViy/RjzutBjwmH9smQDhXf8f7tUyJ0Ws2y/0JIiWmRgzrmWbgbYehjZRiLuiPixziNlbBKYXiya12eaRTx/WL2dh32XyZiR47rzu1sPrrj57HdRqLLAtH6QC52bdDT6mMhcSFw+GrsXY88/bt2+TQbBCwYtchGQQ8TVap0M1lPiIFqKTfarQksJp0rhrsABcmYElVefPUeIHmRtBaxepQEZuEKkqJ5ODU0g== 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=XjbUDJSsQG+4X535tz3BzbjtqJBfYtJlCnSMhr4Uu2Y=; b=kaZ2oa2w9hv/7Q67FkJ4lMqsYQKoxHa9NOUdUyZTHwerzLOUhMxF2T5pBL3oLSEGKQL3WEn3w73nfCuZ0d8TSu0cUnLQSRT4z13Pv+2J8EkgGSzcNMhIktAnG4sqZNaD41dzHl9L9W1ZpLM8HokvMIM5Q0zmJvYoYV3mYRu2yFt1jPd4TUSxNyiTsKNEujDzQtM3lIC9fBJHlL5vM6JnvueVCOCyaG1Bp3KHULGvkIK/SnNPgfvlj+yV3OSHJ0TnWkdOr9pqWuep1GER+E+l0COYOebIu7f2fUJTbBqcjxjrS2diaYI9N7EkS5VOMFOGBptCp9PW9w3HvG98ZMaDGg== 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=XjbUDJSsQG+4X535tz3BzbjtqJBfYtJlCnSMhr4Uu2Y=; b=wnIMWh1Yar22GbcZ1+yJMY4kF97PMYgmvlNKVveA4MJfvquiY8he+saWH0XpZnpRR3BKqDUAKpa/lvLCi/HjUJ55OhxhVefbyQTdf7SQwJMmP86BS4igGqwH85yGHfxIln1fqMcYwgTMnBws4pAPH1RHJsw+Kcf9mZKf3fJl1Tg= 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:52 +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:52 +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 04/14] vfio-user: build library Date: Tue, 24 May 2022 11:30:23 -0400 Message-Id: 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: 3e9847f5-fb96-4b20-db08-08da3d9a6303 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: 3y8NTR+TRsXntuQvZUWl681SXcVrMbAlKVntuVfFB8JrX/5AwHY0MbNGFP0onyiw7piE1MV38tGfXKPTtfet5Zd/N9n9YqthCs74TAKfuAmxuMRNib5pozeHT+G194sfc4pp0kEyMe3aTcwV0gHKLiRedD4QQ2dOjgPM3l5HgsTs4wQe7IHDoGFCVPYmnP8f85p11qMgoOEkba3FZ4tqd1k/L71mNGkwOsn3DbCpEfINK6mqJPDT/9Q0rUqgWZmKUmCestQlfNOt1YTAmn2koJZ/3r79nTiF47vRgrQMr18H+WDT3lPPIgepu4hbvdIVvZIvIWKmXx7KWMORsY9v9evD83ZWYQYkKs+khOLaVmPsd8raXVBSoglYhs/cF5olvHiF6Cv1QCjNimj7xm4RfCNto++btz0CwaXl6MQBe84LgA3dcM/h28t2d2C3Bwtbe49iZkVe+ekpcdvUHLO9s0s9cy1cLqx1Y7GANzXMoGXDrD03XpH4+BBCntPuUD0SFFEtMzYdnpy98Vi3gAFxLVx/g+5lEQBIcggRpQyMOoYCWL5sS3Bv5yboX/Jhy8UM8y5irBJLd7J7dCBPdzFvD/ogjm15tMG+pZPGLhz5YwQDyNvXHvlmYJehx1AdEkay+3DfxzOWtCUiWwjlqqdvCPVFQVLW3OuRilRsCL8JQMP59+qGX4uqkhbPIbTTGGXhidB/r3QelIU+m5HFzDSFlooGvwYF39ihCqGTLVORPURFCGUeIkIQ1PNXTWXWznWizchcHR1xuayBXp4sg0MYlXzw/GMmseAcLX6nJGMiRmJXAyXdZz1LeeoGAXu1zzdbeBinH0InKocFG8zX+xMIGA== 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)(966005)(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: PT6D1FdKUh+ZpGrWm2Zjeg4GWzMB2QH24b5qEXJJdJRoJh0o/EwM/wur53NTQVS3+beU19iLzblwHx4eiZd/5Ci9LXEtzRxpiuSfqIjsh/0kdX515Fs9NKDsPk9p36TraytgduzLDmz/CtdtgB5Lg2qd3D50vnz+R2SxLzs0dBvuM0hGi0eZRt2Q+wM3D+rSrng0Jm1iZhRIZQDxdFzdhFgrlwduXw4L7LlLmhvBUDwJrVN8Cnd0LTsoCQo21ORhi1RDkewktfZhnFU8Jyyz0m03phEsEuI1E4kZNxUzcwQi5Wg8tBigeVB+8a1xOp5Guo7yERY0flVlodoqAzzT15eTjMxkj+8dVBmJ6h4RFrv7czPptjeH4O7wZNVXIbfNr85kRf/8m6MwTvCPCOxHWwg+xlD/1NxUBAXvLvGdOTF5AnI/gvtTJKiOsoSdSup2SpMK1FkBXLE5J8hBn9L7mPzblq83qzNOFOBICq1ADL6gB0khNaHyCuFnNBnMfHljctc1pcIM1DtR8UJXIocjo4+3zLZStw1Ehuls4zUUydqf+tstyEEUaB+vJarkfPwfQx+OV/RrwERR3l6mqoPNSY6urCu6VFKQ2b3NK9kHpJ3xtFOmW+OcyeYUiLYhNDpsypPRkjL6OTw/HRK5b95NXt9/pTZttqc/xeB/6Saew42JW/yJuNc0YwaGvM5YslFtjwnAg3bOeHJx92ZpMwLV3NXDw7CJoejzxvkLoTfMM8rjwKxa3l29BLudWFrm8SpCA9GU2B/Q9tFbUFUPA+5mfFCU+ccg9O9EBD3iFem+FvpKEtnX4NyZL+PCPCaEjjh1gmSZ3QVIkWOD7TTp2cPKibRjtgWLLFtF+iraZSFv2J/OrrAYSJnZztwkVNgP43+SIUXK3qdh51kfntYC81YJwOU6zmjT+UxZPz2cY/iG6AyS1qrn5nP5U0vJepqG+nNhOkWqGCQX2DEH3R67oMupEuKLqgpFeWSDP3LUGrt+RQqumJFYK8c2SgtGozrbX7/WjYiVXXmNkBjX2TpcYPLWytoa5aeA0lLU/++0bkZ55p2H5UCXXlM8m7oNFd7QxKeQYwYaGk3vlnA9xt9VevZwy+deybzP2RRsmqYnv8IqcVTd37+TW10enCe38tGPXhkXFc+ZVBAInw1zropGVWysIklGy6ukpVBdJPtuySBdfz0xlfeL3lGKNP639IJjO4G9J7WJzZdzrQGqjT0VPTbJIhp/ieXh67R43UNb44t1Nku7Y3JiYma+A/esdZZiXz1yEbKNJFdVtx0n/+T61rLBKCvrH7ZwwSykYrPf6jcSudIEV4W0erGLpQMtwQ+jyyqXX8KyboQzpkekKC6Zy8NeWTuE0KFQCm9YOBtxVlJIzQqLRMOZRfTsQ8KTAg9uaPPqOfXpbLm3Ul+iIVloIaj2Vpr7B0FIAOEVFrnMa1Do7blvXkD8jXvMUoJhM5udycZB48AbziDVBaKzfnh++9JoFUoXORgku9dnivO9AoHEEghalVtW8mlHZ902eLSiGnFJ3HR3E5GtusYGi2AiQ++aRm1kiVE00Irtg7fIDwEKHyukpqBfPLl14PEqkA3xxpzMZrAGm3e5ccumdE4f9Ywdn/kgs1pdRwjOGj0tBYSj7s/VbAov7Lv7xKjoPLmEClortGPniGQBNkW0NYeoL4jgarv3WflZEMFxziAlj472UwFsSojV/it3zZYjprLydHoe9AGM7LJED9hyZddUIw6OkA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e9847f5-fb96-4b20-db08-08da3d9a6303 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:52.6332 (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: dEZjlaqpVuoLfTssjGP36tir/D0XbqbBfVg6yJPiHNsA9JDKeojoScDpHcJg3fkNdWKvUGUuTKL+U2dhxjsqBA== 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 adultscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-GUID: 8QRa2tkcQfwo51-Ja1bp-8LieMipg2FA X-Proofpoint-ORIG-GUID: 8QRa2tkcQfwo51-Ja1bp-8LieMipg2FA 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" add the libvfio-user library as a submodule. build it as a meson subproject. libvfio-user is distributed with BSD 3-Clause license and json-c with MIT (Expat) license Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- configure | 17 +++++++++++++++++ meson.build | 23 ++++++++++++++++++++++- .gitlab-ci.d/buildtest.yml | 1 + .gitmodules | 3 +++ Kconfig.host | 4 ++++ MAINTAINERS | 1 + hw/remote/Kconfig | 4 ++++ hw/remote/meson.build | 2 ++ meson_options.txt | 2 ++ subprojects/libvfio-user | 1 + tests/docker/dockerfiles/centos8.docker | 2 ++ 11 files changed, 59 insertions(+), 1 deletion(-) create mode 160000 subprojects/libvfio-user diff --git a/configure b/configure index 180ee688dc..d6a36ba8e6 100755 --- a/configure +++ b/configure @@ -301,6 +301,7 @@ meson_args="" ninja="" bindir="bin" skip_meson=no +vfio_user_server="disabled" # The following Meson options are handled manually (still they # are included in the automatically generated help message) @@ -891,6 +892,10 @@ for opt do ;; --disable-blobs) meson_option_parse --disable-install-blobs "" ;; + --enable-vfio-user-server) vfio_user_server="enabled" + ;; + --disable-vfio-user-server) vfio_user_server="disabled" + ;; --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc ;; --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc @@ -1796,6 +1801,17 @@ case "$slirp" in ;; esac +########################################## +# check for vfio_user_server + +case "$vfio_user_server" in + enabled ) + if test "$git_submodules_action" != "ignore"; then + git_submodules="${git_submodules} subprojects/libvfio-user" + fi + ;; +esac + ########################################## # End of CC checks # After here, no more $cc or $ld runs @@ -2207,6 +2223,7 @@ if test "$skip_meson" = no; then test "$slirp" != auto && meson_option_add "-Dslirp=$slirp" test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd" test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg" + test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server" run_meson() { NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path" } diff --git a/meson.build b/meson.build index 9ebc00f032..6e66bb5a8c 100644 --- a/meson.build +++ b/meson.build @@ -308,6 +308,10 @@ multiprocess_allowed = get_option('multiprocess') \ .require(targetos == 'linux', error_message: 'Multiprocess QEMU is supported only on Linux') \ .allowed() +vfio_user_server_allowed = get_option('vfio_user_server') \ + .require(targetos == 'linux', error_message: 'vfio-user server is supported only on Linux') \ + .allowed() + have_tpm = get_option('tpm') \ .require(targetos != 'windows', error_message: 'TPM emulation only available on POSIX systems') \ .allowed() @@ -2358,7 +2362,8 @@ host_kconfig = \ (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \ ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ (have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \ - (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \ + (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ] @@ -2650,6 +2655,21 @@ if have_system endif endif +libvfio_user_dep = not_found +if have_system and vfio_user_server_allowed + have_internal = fs.exists(meson.current_source_dir() / 'subprojects/libvfio-user/meson.build') + + if not have_internal + error('libvfio-user source not found - please pull git submodule') + endif + + libvfio_user_proj = subproject('libvfio-user') + + libvfio_user_lib = libvfio_user_proj.get_variable('libvfio_user_dep') + + libvfio_user_dep = declare_dependency(dependencies: [libvfio_user_lib]) +endif + fdt = not_found if have_system fdt_opt = get_option('fdt') @@ -3760,6 +3780,7 @@ summary_info += {'target list': ' '.join(target_dirs)} if have_system summary_info += {'default devices': get_option('default_devices')} summary_info += {'out of process emulation': multiprocess_allowed} + summary_info += {'vfio-user server': vfio_user_server_allowed} endif summary(summary_info, bool_yn: true, section: 'Targets and accelerators') diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index e9620c3074..2263a412e8 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -166,6 +166,7 @@ build-system-centos: IMAGE: centos8 CONFIGURE_ARGS: --disable-nettle --enable-gcrypt --enable-fdt=system --enable-modules --enable-trace-backends=dtrace --enable-docs + --enable-vfio-user-server TARGETS: ppc64-softmmu or1k-softmmu s390x-softmmu x86_64-softmmu rx-softmmu sh4-softmmu nios2-softmmu MAKE_CHECK_ARGS: check-build diff --git a/.gitmodules b/.gitmodules index b8bff47df8..c4e66ddb6f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -64,3 +64,6 @@ [submodule "tests/lcitool/libvirt-ci"] path = tests/lcitool/libvirt-ci url = https://gitlab.com/libvirt/libvirt-ci.git +[submodule "subprojects/libvfio-user"] + path = subprojects/libvfio-user + url = https://github.com/nutanix/libvfio-user.git diff --git a/Kconfig.host b/Kconfig.host index 1165c4eacd..d763d89269 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -42,3 +42,7 @@ config MULTIPROCESS_ALLOWED config FUZZ bool select SPARSE_MEM + +config VFIO_USER_SERVER_ALLOWED + bool + imply VFIO_USER_SERVER diff --git a/MAINTAINERS b/MAINTAINERS index dff0200f70..c92d87daac 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3602,6 +3602,7 @@ F: hw/remote/proxy-memory-listener.c F: include/hw/remote/proxy-memory-listener.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h +F: subprojects/libvfio-user EBPF: M: Jason Wang diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig index 08c16e235f..2d6b4f4cf4 100644 --- a/hw/remote/Kconfig +++ b/hw/remote/Kconfig @@ -2,3 +2,7 @@ config MULTIPROCESS bool depends on PCI && PCI_EXPRESS && KVM select REMOTE_PCIHOST + +config VFIO_USER_SERVER + bool + depends on MULTIPROCESS diff --git a/hw/remote/meson.build b/hw/remote/meson.build index e6a5574242..7da83350c8 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -7,6 +7,8 @@ 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: libvfio_user_dep) + specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) diff --git a/meson_options.txt b/meson_options.txt index 2de94af037..2bf2d20b42 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -88,6 +88,8 @@ option('cfi_debug', type: 'boolean', value: 'false', description: 'Verbose errors in case of CFI violation') option('multiprocess', type: 'feature', value: 'auto', description: 'Out of process device emulation support') +option('vfio_user_server', type: 'feature', value: 'disabled', + description: 'vfio-user server support') option('dbus_display', type: 'feature', value: 'auto', description: '-display dbus support') option('tpm', type : 'feature', value : 'auto', diff --git a/subprojects/libvfio-user b/subprojects/libvfio-user new file mode 160000 index 0000000000..b52bff72d4 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit b52bff72d4eb646a453d19e19ddbd13ed6111a09 diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker index 4b20925bbf..10618bfa83 100644 --- a/tests/docker/dockerfiles/centos8.docker +++ b/tests/docker/dockerfiles/centos8.docker @@ -51,6 +51,7 @@ RUN dnf update -y && \ libbpf-devel \ libcacard-devel \ libcap-ng-devel \ + libcmocka-devel \ libcurl-devel \ libdrm-devel \ libepoxy-devel \ @@ -59,6 +60,7 @@ RUN dnf update -y && \ libgcrypt-devel \ libiscsi-devel \ libjpeg-devel \ + json-c-devel \ libnfs-devel \ libpmem-devel \ libpng-devel \ 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: 12860343 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 7128EC433EF for ; Tue, 24 May 2022 16:03:41 +0000 (UTC) Received: from localhost ([::1]:49164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntX0W-000507-An for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 12:03: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+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 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" From patchwork Tue May 24 15:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860317 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 C167DC433EF for ; Tue, 24 May 2022 15:33:27 +0000 (UTC) Received: from localhost ([::1]:56092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWXG-0002YI-LE for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:33:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV2-0007sC-TF for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:08 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:4906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV0-0003P8-9n for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:08 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFSBdG001529; Tue, 24 May 2022 15:31:03 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=BTtlySDlLng/K1IiRZ5NpCjL6JerC3eFuMJCe1bmrmU=; b=Ii0uQ03x2be4Cg/FejtsCyVlf/M/MOX5FiNqTkxVR94u4LQu4vmwY+2P1clYxMNRvPv+ v5ZrZn6mDhFJ7HDe0m80mxdJYrMBZlMEW/STkEb6Yt7N3ES0RGbOdce1qd2nl5rgnw9p vB6GHdhYldU+KKen6svxYgCOXa1nQs4EAduTpRvtzVlUsufO2IiM6UMw6d+wxe4On67m FVUKMI9D98OpjFTEjZv4XbyUnvv3Hz4X3z0+FuVyWTqMiUYMDpKhZxO6+kEpcQ6Nyjzj qEv6nXal/WeLdeWytT5PfsQXJUNOwQBGzTVoyE390zCVPHcSCUbh7XitXAWyYsyjr/Tm 8A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pgbpq9f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:02 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFFYet016795; Tue, 24 May 2022 15:31:02 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2049.outbound.protection.outlook.com [104.47.74.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph2k52m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XhLVZkUI/rSBA2PTAR9/S6X8pnXVnFjY2aL+m8URxVcqhC9nbp4+w0F/Qf4MGymNgKPRDqLL+1YKQ3CBxfDvvvKNiwmomuKjeBL32dZliP8Z0vTXLv7q2PhXiXzf6FCvMUnAe9xqYv8WDJjbQP4QTKRcEAsjA0mcnut6JQ1C2n+FoB2SZ3z+vEOq4LvLsGQdgsClAQ+Sx8Adb8MsxW9XLpQ95eZIbUV0zbIKNVI7YSR3Agi7QrN+U3sjbfz7sVFTmk6jJSo/I3HHiYH2IaZ5rwnQ31C2trVcI1BcxC7E8eFIwAQWMT/ofRMpJ3Kdq5VhBD7HYQu6oKNVzD8b0rw1yg== 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=BTtlySDlLng/K1IiRZ5NpCjL6JerC3eFuMJCe1bmrmU=; b=iE3T4Z5CwGev14+hXQJ5tZgss/OpsZ4Vx3anCu+cTL90SH5MMKCjbOwkmJxwDOksJ2MiZbRT5137CK7X+KQZcs1+D4Laf/Mq2dK2rMX0ZyLw4qwhge8OqU/b/3eZ5S43XUEMvj1/sGydR4jmNHA46bGS3XtzRAyX2ol+O0CeGI2kSOcqvbVWzuvwiXzc8V7wJYdTTjRZTHZ0wqP4S/7OnJmeEEkZi0PljfzzdCuaznlcPfz0J/25khMl4dOv+K0AxDMJWfHCC3cAgU6ZZrkfGYFB1nCsrsGkZWLRiMyAN8U15AGgfC1erKIQPPkX2vYSex3ByaFDvGJXdHxKlFQ5ag== 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=BTtlySDlLng/K1IiRZ5NpCjL6JerC3eFuMJCe1bmrmU=; b=ycP1hVgww7LmF4AV95Od1uoIEUZV6npk2uAd3ZT9eznXHSNsW2lEqzmOV41yT0gmC9SqpDXsyyKOOVHLEUDca1KyVTi17KiQqklxHe+yxW8+A5jdGVRwzpyDq/Vm7wy2o3yTHV1qorFjuadNJULNkbRsyAl3lvo7N0kgfVczlos= 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:59 +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:59 +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 06/14] vfio-user: instantiate vfio-user context Date: Tue, 24 May 2022 11:30:25 -0400 Message-Id: <38676caf167ae5205a4179e6a1256d2586b801af.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: 49a87500-5de2-4b61-38b8-08da3d9a66e1 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: 4UNESoZUwjVttqSMzjYhai3SYUepJW/OCRKECNYrJmk23ENuE5R1zi6IqfzSzkfEK1UNgJbOHxxx5/5g4kzeAEIsVhKIkCm0vzH+l0mQ4ecVFIdP6hrDDfrZGQpe0+15C1MC4D8R8H5iF3fXx9moMOyOJHj42UjE9yjh0ygFp44YkgotVL86f9UmISYCgyfU39A18DE6h1XM/RerOOxERv4r5QzW+9pfHZd4YhIpGi3qQSRIrwa91IFrdVV1VzL/aIRSTu94HLRg1ESThQZVdiCFvdMJSJ7gwHY2VWn0cC2Ngn4dsd1jzapYDPS2NNfE1+YSHmnlNpVv5dq+aYvPEiVLF6sQxFszX+aPb7Xk7uea3NBqDJTMBSJpFGfqQE/m2TERTxR99Bc/ysVKi83jlfJoEp+1qhluztM+e5w543KFZ2Xy636pojaMt7Y3/rDqLswd0qzyLxRp7yYjqaDrW7tzFGJIGplO5wlMFKMElgvaLR9QClBN0vqjJAuYHAYQqqFAJ6DDF9W0PrlzEUWy7yF5mp0rmMIBpUpbgDcQN2nI/D8uW2qgKn+IrxeY8tWUYFJKNsdv89JJIu3ED03TJKThg1vYUo/qZhJdwFcSx7IJ7nosAIfjWESQQd+4PDAdc9aBVfCkLiLAe5KAEs1v9VSMJjSEJQ+WK/j77pFUsQqhfULaqkNtIt2UpPChpTNPUrzp88dX09oJfazVTkeN/A== 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)(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: zq5XJWXr6Hc3m9gF5ufTEIcjse5II1dh4L31rSYfVpgaBRfDTZjkhHq1hzict+/b5UdPGQy8D5NUSbr0jBdX8MCYsyUZxfFdzh6RpKOWnqGUmU9cyyD9DGzTqKSORtJOgPxF1l0M4FQOV0UBvbmJuobMG3hJBdsViAgc4knWO4K/F4HENNDB02nyzhd5F0rpJwjRtbXAyCeSt5/jVtWNQJgRMSkf5895k22IPy9b4c9ocOzQPJ6jcYPi18qMDmconLgd2wt5JtJArhEh3I50OtYIivpb6BB9uhMN8Hs2fg3lKGAlPlkU+DjsCuGcWimIvBjki+ajhI2Nayko5IwjHw76iXNdn5yRbOJvtpIV9jW+Hc5up2ScnnDF9N95FyfDtQk3VWN+swhO8g7K/LN1jpKBSMhU5ZkciQjVUJguDEJvVTJr/NSiGrjRcscV1NpmGYHVzwMVAvEDHbqjpkI14hpMQVY2rrsbSEsBWTnTVUL92ZpinISVej068h9oY1rM1DOEqRyp4VjP6KQUsQ5N8cKM2mX1yC5IQ6PWJMaERhpfFWIDJpPz+fDIB5QVSJVlNB5tmD1VJNmHaPtaycUnNcQwfxNOCbd1qevSl7wjyLFT/bpyBdcmK+H0CcpXyuPfSFVd/udsGenuoTH/cCBXP3oF7JZEQlIN4R1IFGVYcQ1QesHQwb4LXfuekaTT93C1zFAXyzLL8kV5UNPe2J7plN8nO4l7Yc7vqM+v5INu3Sj27pUquf4ihsSaYTcVGx1zrDuA8nPpYpuHs6M1diPqy5OUcNbS1z4TBaVqR+y7ydNid31Lyn/kXPAQGzxD60bwQBW8NXx6xsjCy9f+PI/igp+mw6FvWb0AwumJE+EjhuzS4KswkDljOpBVRyhycJY1NWX9VBYM503tijdctwWSxZNyFscJ/x4JUrJMiytRFWpXyIDvgYa9k6FzI8Y8gkNufwLB+hpf8CMTadgOCMzlLm24Pm5GxqYMR/PlVoYV2EicPR1EJMMsqUN8ykjNJviE+8lKeCJ92yHONMnLCpFxQbOW73be8K3+EIjPC/5/ovWJ/gLcghEew77cSpQHg30pBii/ODNQdUQulbnKLb0Lzn16oP0ecaUQ9J1ucMB+YG4tjN7nHT+zfc9c89Ko7elams7gmxd/rqcSn48ijzDfOIkUCnL1Av08M/gdJbhTYu/vExrlqBr0tQ6KCGq/0gBfyatkAa/J6kR4OY0U6Wpgko+JssIFO8GQMCQahvx4TjLW0yX8lQU9hSaPuDsjjekfIF9ZHMve67zQCSu3fibQGQ3JUZDHebKbz+mJC5SE1vSHBpIO0KeoDv46wtu9mqkG8dY8lncb2lZ9FuyeDt6guniiSfLBoUj9SSO4t4W43535LyCgqwexhvSAASGJBrIuXtaAZbms8b5gfFEXb3zW/a9CAdtbsPhnS2jHjisYJJ1iUDuN18vzXzGEywmkzF3TzPTEe999QRBGSqOber34SHbd78MFp3Udc5XZHmB1/LPXLpSJznroFaNRvYilr+3SOD3nVd2xWS9EU5TAGQnhpnGKoIviNXQviB+tLPRSTnUTjjabQchnJqtNWE3wggM+mEcMb1qUYZfE82wDZ7hfgqUzN+Cy17nVJrW4VBbM4qAA8wl08bkRyE+aKfky+672BMnGu+1Qs57kUf4YC04/l32mgZ2m3aLiiK2Fd34TGTfp5L30I2FVhpigds3jtopsUsKU52V2ENjY88+pXkI0gw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 49a87500-5de2-4b61-38b8-08da3d9a66e1 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:59.8202 (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: W8Pn/NHFtRfvFvjE2CyHzBLeYmSqpw7mqZRapNutWED5EgWANmAB8HL76rjtQmPLpQVxQn3X5AWYmgVYjXcWjA== 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 adultscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: GET_f6etv10SDt93r90XlvS_SX8VU9j4 X-Proofpoint-GUID: GET_f6etv10SDt93r90XlvS_SX8VU9j4 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" create a context with the vfio-user library to run a PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index bc49adcc27..68aac0c2b9 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -40,6 +40,9 @@ #include "hw/remote/machine.h" #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" +#include "qemu/notify.h" +#include "sysemu/sysemu.h" +#include "libvfio-user.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -73,8 +76,14 @@ struct VfuObject { char *device; Error *err; + + Notifier machine_done; + + vfu_ctx_t *vfu_ctx; }; +static void vfu_object_init_ctx(VfuObject *o, Error **errp); + static bool vfu_object_auto_shutdown(void) { bool auto_shutdown = true; @@ -107,6 +116,11 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + error_setg(errp, "vfu: Unable to set socket property - server busy"); + return; + } + qapi_free_SocketAddress(o->socket); o->socket = NULL; @@ -122,17 +136,83 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name, } trace_vfu_prop("socket", o->socket->u.q_unix.path); + + vfu_object_init_ctx(o, errp); } static void vfu_object_set_device(Object *obj, const char *str, Error **errp) { VfuObject *o = VFU_OBJECT(obj); + if (o->vfu_ctx) { + error_setg(errp, "vfu: Unable to set device property - server busy"); + return; + } + g_free(o->device); o->device = g_strdup(str); trace_vfu_prop("device", str); + + vfu_object_init_ctx(o, errp); +} + +/* + * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' + * properties. It also depends on devices instantiated in QEMU. These + * dependencies are not available during the instance_init phase of this + * object's life-cycle. As such, the server is initialized after the + * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT + * when the machine is setup, and the dependencies are available. + */ +static void vfu_object_machine_done(Notifier *notifier, void *data) +{ + VfuObject *o = container_of(notifier, VfuObject, machine_done); + Error *err = NULL; + + vfu_object_init_ctx(o, &err); + + if (err) { + error_propagate(&error_abort, err); + } +} + +/** + * vfu_object_init_ctx: Create and initialize libvfio-user context. Add + * an unplug blocker for the associated PCI device. Setup a FD handler + * to process incoming messages in the context's socket. + * + * The socket and device properties are mandatory, and this function + * will not create the context without them - the setters for these + * properties should call this function when the property is set. The + * machine should also be ready when this function is invoked - it is + * because QEMU objects are initialized before devices, and the + * associated PCI device wouldn't be available at the object + * initialization time. Until these conditions are satisfied, this + * function would return early without performing any task. + */ +static void vfu_object_init_ctx(VfuObject *o, Error **errp) +{ + ERRP_GUARD(); + + if (o->vfu_ctx || !o->socket || !o->device || + !phase_check(PHASE_MACHINE_READY)) { + return; + } + + if (o->err) { + error_propagate(errp, o->err); + o->err = NULL; + return; + } + + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o, VFU_DEV_TYPE_PCI); + if (o->vfu_ctx == NULL) { + error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); + return; + } } static void vfu_object_init(Object *obj) @@ -147,6 +227,12 @@ static void vfu_object_init(Object *obj) TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE); return; } + + if (!phase_check(PHASE_MACHINE_READY)) { + o->machine_done.notify = vfu_object_machine_done; + qemu_add_machine_init_done_notifier(&o->machine_done); + } + } static void vfu_object_finalize(Object *obj) @@ -160,6 +246,11 @@ static void vfu_object_finalize(Object *obj) o->socket = NULL; + if (o->vfu_ctx) { + vfu_destroy_ctx(o->vfu_ctx); + o->vfu_ctx = NULL; + } + g_free(o->device); o->device = NULL; @@ -167,6 +258,11 @@ static void vfu_object_finalize(Object *obj) if (!k->nr_devs && vfu_object_auto_shutdown()) { qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } + + if (o->machine_done.notify) { + qemu_remove_machine_init_done_notifier(&o->machine_done); + o->machine_done.notify = NULL; + } } static void vfu_object_class_init(ObjectClass *klass, void *data) From patchwork Tue May 24 15:30:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860333 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 7108AC433EF for ; Tue, 24 May 2022 15:51:15 +0000 (UTC) Received: from localhost ([::1]:59452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWoU-0008S5-GX for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:51:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV8-00085U-NX for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:14 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:21224) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV5-0003Pv-KD for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:14 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFF3S6010172; Tue, 24 May 2022 15:31:06 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=tB4tSjLFXis3Dh7vLjuloDknQ3HMz27ejhAtdDiTzcE=; b=AgB1flx7ystC49dSfjuShKdugQjgnsguML1ewKpbZHlM5qB9YlvqAzYuIXzPa9mBZMD3 g/voQBpKvcxF5BWJmVKcdWITrRnENgaG1dfzjEcIj6jgO3u7F9h5ZQ7Ht5g5v9GjHAXi naNFSGGlLlQImzBjjDp9g+UUv/a5W2RqdJG4bhvJT+1k5BC59vtAdsv63Ky5UwnQYAb3 WXZlBDtxaFnLkAn+Wgkprdk8fMirmXTBe+Fom2amN1k3da16VTO4XqvH8Frz0FVxbdBy dQ6oPXrbOYUGD2vI7AC6MgSAsOrqaXLQ9fwks1X1oLcmbwTDZ1SFCP3qJl+AGWzWYU3m yg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6rmtxrhw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:05 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFSHU2001101; Tue, 24 May 2022 15:31:05 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2042.outbound.protection.outlook.com [104.47.74.42]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2h2f4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nRLzFXuZJ/yZM8UbBOP85dWjlf0WRupIX6uaRTktD+jS3MqLYhJXwbAAv63fQlsXOru4aNsv865tsFHhbykA2T/fGhllhnf4dC3WrNe0Tq6LGRjG8Uw2Aahuq/eKZD+OIO4bd1I/J74DdS4Y6yzIz/Ryznx8MCYObp/0uN36HRak/DIQjDoq8vUg5/6fWV95khcFQW5C3u/fsnTQrka5ekZNEt21nLG6RWe4oLL0n+pgfdppg110mLLctA2XyD+F2bytXFtLCWsVK77YM4GkdvSjTXxyQiDvElC5+In8EpcJO3p5xaUzbTsJnZTF5h0/t0tbkqeTB9QWCUeCpkQNPA== 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=tB4tSjLFXis3Dh7vLjuloDknQ3HMz27ejhAtdDiTzcE=; b=ZxiomGrEd37BGgKMaA36qcm0bTXKuZWmfypJU7RTlkFWCIDtbICubZTluZZYI/NJLt/cJDAMUyKw8qfDuzTZG/+ikb395iwolg+JlfW6pHYPcJfUztiwv1b5arBHw3zls3V8g+MDXj9A0g4+1m5WdX1loG55tilKtb5+HdgL5E++c5Kgq8sF00EWJxPOtezv1MBoy2AbmXQYHDvyqcz+yli6SQ2VlEtrivHZ4KZDX62eeJM8XHKGAmsp6pD/YquyvY8ajAHafif26pgQd6+CFvSjdC+9qujeVxu6Dk6TutALEq6eHoFBEWiAsFkce42L3cuZJaZ9FNiobPsAPNWlKQ== 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=tB4tSjLFXis3Dh7vLjuloDknQ3HMz27ejhAtdDiTzcE=; b=SuRLJnqRsr226BPBEQHJGZLBed/T2/8iyOin6k+ZzGVPlWIvGokVcIxbV7J7tny3i5lRaz1NuyQanLn8xwg9tzLWtVd0sPbPb0x8jlueUaTXoUCpv0Za8MRMjfve7r6hQm5QC3hel42RFgLwlsEVGCJk9jS+p+1pnJFCjBr/DXU= 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:31:02 +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:31:02 +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 07/14] vfio-user: find and init PCI device Date: Tue, 24 May 2022 11:30:26 -0400 Message-Id: <6cc3abf55fce74eaa7a0f596cf3e09b4426fe98f.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: 3e1f33d7-e4dd-4a0e-edd3-08da3d9a6907 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: LtBP99NLPdOJBckoegRGaPfKfP+bAE2l3Ei0Z1kDnRNn5Iyoyc1yhKGuZP+vh961Azergio3EVZZBWLhD3wBdmTZvKIFNPTPCZQsZLEFtZ5hUBcEP9Txk9mG7e4BNovZ8cYCElWFGd1RRWQJAcKSw2sr3rnp2EfOv0JXDSiQtpueB29SOtLPt7QQnd4HcLVfXLGmrECxqESYF5PEvaBAGg+4AKxPcBqn33PQYNKdqBXPTHZ0ax9UNLT/h9kYBick4X0H+Ff/As9WxffAWgq7pZW+cb9eFp1PtifTdm4uuQkzsu9NUVG2LWtcbYXrjoAMDltztyBrKwTrdNSQc/zyBEmJ59rEa7gz60nEumRJLYWdKO2uiyW8vr2+tjxJZB6+r7YhaickPvVDt4GKBwy5ASd6HD+ecMo28aBC73AFPdZ7FXWllNhoQR+ry+t52l9Esj0I0pIsLAw0YW6YAx6E4tRLgaQJhYk6TLp0iK8owA6fMqlly8/O+NPDfbWZkZuGFgToX3+KeLZbo4eSDVAlQ5mtrHsms9a1DfatTZPxTZI+zxohJR3/Wm47mLVil7ReoCB5HR/dfM7Gr77zeqgzw7xzKEws6U7u8LDIKfWyow0Z49q9WYGgfdJu66whDBArqhqkk/Qihb0L9dzPVkheCULOdcgm1cbdRazT++M0On+p4MxqQvW2rSafkArZ0MYrO9A+B+7IwUdpEhQu61EfUw== 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)(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: sbm3lrL9tKikzqo9y49Vw9c4RbjwXUanTQCNXDb0mE+zaIEYp7zydD542pL261zvapNbRlyBxZPEyYlmn8wmlcIs/aDOtvjvHyYOBBUyXouQNy/UtjjvB2WwBLDKRogBScx1HmfR9vpD+58Rqu4dtQPWCUmq2mwbh3EMwjGqme8OlM+qsIX5widGPJ6M5UAFfvO+sFNFiBeY+ZB4ROfeaBSlhbCFE9nxRIPXYIMQ/D40zlGSyI5hTyhuEmJAcFCIWlmjQezDbDL3ovjhO93XF3seafSlvt7J44h/d1YqMHRN3T+AsSuSWCJl9IevU4BTacKKNUcXp202BfzcUJWV8xYl4f9WBN+Rya60wrpUudnDvkgKy7vcRrvzWfKw4SNHk3MtSSm7fLsjK4DBtiJ7CkRGeYq3cJxLICn9uyQSQ1CDsXVgoXyzTbg9gOIOBaLp+HkLao9Viix2AeHZOdK2qNQ+RLDqxJyCNKmEI6qDPs/7nVoWtk5h3QQCzMUZJJE20yVdkX0UdG8L0dmLCB5PCNqKwZwXDfHI6gA/YRTh+nMrFBTW83c2F4NMYgbY5AxGLBf9czwBzcHUskgX9Zfp/n03Vy1hQOTaU/3gUObSO7I1YFMd2O3Wp9ydhvLQc87y+TOUxLW/qB+Y3bxdxO2BTb84T65QuykdW9V7/yfhVeyfBEb+QWO3EA4vokzTrJsLEyqdRw+p7ogJCCGB6xwYIzX0vLwy9u0GwYDGW2/KnwGrQ7JdqonhlkmjjfpV13IeYJKeer474x60H1ZDxrj+nE2gMFBLLAcOoyKGVeQ+I3ESblC3nn2Z2eJBRAlX8RXsgfHFQHJv5YKF10XG/5YZsxooMD3XeqsmEETzJOiT+u6vIdCt/o6zU69J2+7bm3706U5HNq4rltnJome1ctPqnTf07U7U52pH7RlzJXuOTrk0u8783B0jYq7kwQGGI8IXovkoikt/HZUjR4/mZgfMa5zKrXG/ZvvbrPc9uFA9Qdvgu+6OD17x98VZjBEfJ+ITvurHs5EtSgJShIVb+KVPRaf/YUtb8Bv1ZWTWNAu9wQbu2B3Oixtjkzrvg7gna0nDq9a8EnC3ERZrjbrr1q0sGEwk8JrtJSL/GJaVDXUrBb9+dolufNUpAYC/hQ0BHr7PkHhoGTd6E4wgJQD1njwSlvl9/CUX4KneLc/KDWrrvZxK3rzidWkhVzZEGK3sN/sDFzosuWtaFJql4B940dAzBslR/NhkcKH6x32rzCLmw0CuPXVqQGaj/jhuXi1dNOvXWAxyYNjoz91ZTj0RKNRVbe9/1qJm2YYGj728QIPJN1QhExlOExlm9SNs359qbVnBTWQaBc3haSukKSBQHyM8JE1UyFAAOMc6cmTO6/KS9hg4rde3pJoMWMt5yCMXxCZgjfErUYT6XBNFf92qQ+8jfFFq7uNJIBfokAFzssVvfi1Z3L/gs645CzSgzNag/FjOA1nz69rVKa39qNNol/rzR+mePOia2blvYNp/871BcwX0gnmegojiV740eKCgAt73Bq6+Byo76eb72867iYsWYE/+Xrxbv4b/1wWjlbnLY+JypWVU0lJC3+ucj31U+gl9TI8AMEstprWeDuCR9/n1wnmCxvoOpkutITAhmNJ2YVfsGwj3XlgjUVRj5rKULhMJQdUnNOsNpPmwDNb6aQr0obre6jSPpkGupfe7DYBuzpWaOijRHiJEZ6FFCkT1L6JMCKBtuZOgQ6+v0gVEB4Vhxw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e1f33d7-e4dd-4a0e-edd3-08da3d9a6907 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:31:02.6637 (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: i8RhoDKoy4MeEjEmVKL/axvslCqrGCKPft9V6N+Nu5AVAYaL8QERIDU1itGfwtqCrd7eLVbQOcW4K42rRNSxwA== 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 spamscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-GUID: B5Q9GKGHohA0q_Dhlcr04sOXJtt2Mfd2 X-Proofpoint-ORIG-GUID: B5Q9GKGHohA0q_Dhlcr04sOXJtt2Mfd2 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Find the PCI device with specified id. Initialize the device context with the QEMU PCI device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 68aac0c2b9..fdee274933 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -43,6 +43,8 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" +#include "hw/qdev-core.h" +#include "hw/pci/pci.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -80,6 +82,10 @@ struct VfuObject { Notifier machine_done; vfu_ctx_t *vfu_ctx; + + PCIDevice *pci_dev; + + Error *unplug_blocker; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -195,6 +201,9 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) static void vfu_object_init_ctx(VfuObject *o, Error **errp) { ERRP_GUARD(); + DeviceState *dev = NULL; + vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL; + int ret; if (o->vfu_ctx || !o->socket || !o->device || !phase_check(PHASE_MACHINE_READY)) { @@ -213,6 +222,53 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); return; } + + dev = qdev_find_recursive(sysbus_get_default(), o->device); + if (dev == NULL) { + error_setg(errp, "vfu: Device %s not found", o->device); + goto fail; + } + + if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_setg(errp, "vfu: %s not a PCI device", o->device); + goto fail; + } + + o->pci_dev = PCI_DEVICE(dev); + + object_ref(OBJECT(o->pci_dev)); + + if (pci_is_express(o->pci_dev)) { + pci_type = VFU_PCI_TYPE_EXPRESS; + } + + ret = vfu_pci_init(o->vfu_ctx, pci_type, PCI_HEADER_TYPE_NORMAL, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to attach PCI device %s to context - %s", + o->device, strerror(errno)); + goto fail; + } + + error_setg(&o->unplug_blocker, + "vfu: %s for %s must be deleted before unplugging", + TYPE_VFU_OBJECT, o->device); + qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + + return; + +fail: + vfu_destroy_ctx(o->vfu_ctx); + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + if (o->pci_dev) { + object_unref(OBJECT(o->pci_dev)); + o->pci_dev = NULL; + } + o->vfu_ctx = NULL; } static void vfu_object_init(Object *obj) @@ -255,6 +311,17 @@ static void vfu_object_finalize(Object *obj) o->device = NULL; + if (o->unplug_blocker && o->pci_dev) { + qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + error_free(o->unplug_blocker); + o->unplug_blocker = NULL; + } + + if (o->pci_dev) { + object_unref(OBJECT(o->pci_dev)); + o->pci_dev = NULL; + } + if (!k->nr_devs && vfu_object_auto_shutdown()) { qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } From patchwork Tue May 24 15:30:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860337 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 1B96DC433EF for ; Tue, 24 May 2022 15:56:01 +0000 (UTC) Received: from localhost ([::1]:40202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWt6-0006X6-76 for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:56:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV9-000887-Iu for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:15 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:23972) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV6-0003Qa-5x for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:15 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFKeGP018506; Tue, 24 May 2022 15:31:09 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=j8vynFuMKk+VtVYki2MYIQ22Ib/yp/L8kwk9dzLMwE4=; b=VSKZfoWTKLvHB8Kr1zBUc7E4AjHsBQ788fib9x0YQWvqMTNhGYCmXdVjZFJwRw2DLaFa CIFQFInNbautekDhPw1LvIeTFAduEGl2EyBjuVfZ3Dsm5o+9Wfzq7lUGzj8IZIpcM4Jr 32h19Iy+P/1aeyfU8YTDsd1+bvu48oEdNV5rkTgpPPLlRGy9r5g0qagLnpE/F7vyiet+ Gh7ehic6UGqP6cC6E0eTlAGL02qCc8gnpFJPTAQOWDOL5X1wf3flDXxEokTGieHxiMdX TQ/9j3llkwDcwP8sUYKggPJc9xIL0K9SmQjEP3aLsKh4bmmZkdQOTjZPeBPMQzksVagp 7w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6qps6tjg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:09 +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 24OFGUop024248; Tue, 24 May 2022 15:31:08 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2041.outbound.protection.outlook.com [104.47.74.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2rj6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Axmyaor3j1ElCDMHmizh+mnr3ES12lb/mHvchymVnUrI9ybO6Z7AUg17bClHB+L7R1cVYjhSA1bhXhmSSCIzpppXWLacoxX05JlGPd2l7fBayymGMgKcHEsEh7MhWG6Z6gXYHSFtIt651DqnI9ELkGZp/1gh2e7q3BzDl0HIHYRmKNANj5zamE8EKKKMGKRmcgBdnPLwYXORB6jQZFHRyLBXNxEc33U4G1WentRy6DxI8aU3SDCzO/mxiJelNQU2+cNCrFXZPtkeUUIi5Y75XjTf7NL3XDZwonXGzsOUflgKKLU1cTlku9rWaCCtB66Mj+ujEUKTmLd6Z/J8bwYJYQ== 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=j8vynFuMKk+VtVYki2MYIQ22Ib/yp/L8kwk9dzLMwE4=; b=n9OefYjww/IvTl6PfFS0llbbydNuMeLTQuYYH4PIh2F7SVVP1C/24/Z730mTz0Xjm5JOeMSTzt+bbB6jPnpagyWicwEsh+jVFrdqkqDqT7l+cd96nz3bY6Q7w3Lu1yvkiK2Ih/p7uik3IAPxnFBnOFopaQappmaAMqCLHNOEiwwlgzXY0pj+5A3WLZkonEwvg7AenM0R311d6FjYPK92pGEooE6b+1Ksw6ZiOCCfQMx4YkwxAotGY5/FN9yjssx3Kek8JzoXX3Pl5FRHCFVa/At13VCLdXd+ndSpdb+0aN64qyUnb1an9foC97fQs2vFaxBz8X1ZH/TNn5OhZgkixw== 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=j8vynFuMKk+VtVYki2MYIQ22Ib/yp/L8kwk9dzLMwE4=; b=S1Y+O3CMauzGCUgW5fJ4LWH0o70GSml9WVAUUDiP90dJsXqegIMgV2EKY9GTUjJ97F3yhssdsz9gBwJ/rMhqoAYBo84TkXyQ0i5Yd/03OFRAS8Xozfemhhzuirvmg+tpQb7Zi4deaLgBLDdI07Y6JcVj/JsAcKqkYanU2kxtlGI= 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:31:05 +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:31:05 +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 08/14] vfio-user: run vfio-user context Date: Tue, 24 May 2022 11:30:27 -0400 Message-Id: <112c34713cbc8c0e917384288a10d7e3dfec941f.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: 78dd6afb-c4b0-418d-e23d-08da3d9a6aeb 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: ncI6emB/SD+bHdIEZ8k8X/iT/3slPolRxUZrwtclksu61CbRwlI1evpxD5em6XYh9QpBYlISPVlAfXzr96smJ33JpXTougVF+hWG3VOhx5H16gr2oF+2LqGFZ3c4U2P+UbC6JAiYk8Hunbuu0oJbGwA/R6zYDglq3AyG1HB0POZdKOU0iImnLN2Lh8fsWEjhQ7sRZxl5YrQD4u5VSouE4k6/qyDtnzJrxd780PFh5K1uz2usLor9f0J1QAGj9TjzHOOSfiK9NcrabeFe09J/lxVTaAw94HPoQJOiXaeDeSEyt666tPbO/snsAIL4mLj8Lw8yaxPekL3hevhWJ5wQl5RSDd1U7LbtP3kcqo4IamRvsd3s3HdA6XZljwVy7B8TzD3d8yEXt5ZwPQ428/Z2G3egiL6bCn+xpPBqlaHVFOhRlrKRsEonR7GAa1RGJZ2nrNRzFYDWo8rCKeGNzzAw29StlhryuyuEPF3QeNrOQM9ZrzBoiZNobJe/uLQply51x41rBiLO1P6k/kH0k5x20o0SufWDMS3QLh98UAGoD+ENbRm8/g0tb3ugNtELiSIeZfrcZH0AAOURfFddobzcBU0ndXnEpX2tyRI1qp72dUFdX50nfzxdR++NTYQZww6SRwBRcp3+AxxqN6jZ6VQmk8vznLrnqLRUxXh6z5LCv0jXnm5ZGsfc2SxpjKfoONGD3GlYRrKdnV08dIdS+Uf6sg== 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)(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: 3aBr4Widizk3wdBNRb05YtqJiJx5bmNohFS7JR+UdSBNTB57c/e38kROf/MHJVerbBQmgL8MiaT+kTJsBG6UaMQTvC2cD1fccR15O2zasUipGjSyPWkSpbtEO4bG480iFQyfClfGVYvGBNgrALgtDwYI7W4cLWCREPFLuk1398RbIKw+GRZovdxLiXbQtsWJ1ZztlYdqavIx8euhrBOy/FhKMCM9Zr3MXRodFAU9z704yM7wDBw4fPg4n+4vB0rAQ1U8dQkQi7JtCuj1/M6svfDgCYg93i2keawvMzAWSWTkW1KCxeStQHpy5rthwwM3371qsIzx4zWlpTXpMtspnDZlMSO6QIMaqdcpxvZH7firw8nWsokQFJxp9z/Nqfqz7Hy4xcgWEmh2N+ghDgrKZyJS6GnfSuN1i/hJa0IteXaptBhcSCzDzKWCMAS8Gd5ecpYJqTgrKedmWUF3qHvTPGWIzCX9CR+FMkV6bVlqG9KU+awH9NAq96AXiVlwlchaIC2emmW0/Q/eHt6xiEjiFxSQuhXxtAxtB0zrRP6jjyg5dfU4eiHNu1jSUweAhDeuAHZrW80AOx5DGgNVnxN48LTa5EmDTtx+sINSDWnpRpNw0QsxFcLUC2cGuklUSkBBR0858RyFCRqXGtE/xgAL1HLs2dqqAAbi1U4j2fp2CjhPdYQVIyJy7EV/lppOLaGCbFCFvaF8NJaFfAf0vcvLVEp5AVtKr5uNPVb+MZNIxEtPqM4/OvImqLyNMJBblNAvPwI06dhqdB2H7MZWyNOogJlXHB3t1+PBEYUXXdag0j7BvPVBOf1WIXkdl3jpPCAnPlCnqQ4y5+nushLpD69wRYh/fIPh+LeiXJHbhUKBMgFZnv3qnMoMqmQVeXnG2rU0eThrQpCWyER4FC4t+pmuiZd9Nc/BGemdV2q1jD0Zj0J3oSWCsEDeMfkJsIyk2mKPCmHtanLPnOhDPch70glKOSELUyvKfCBTzSf7VFFpK/Fr5G03JvzshRg42MQbHQqJKxilUk9lU66uGh+WtJ11Psofcgjni7Z28tmDiaT/cfIqG5OGu+d1g6bIJ/fWXG5eJ8xu+Cw0rWAD8uQEO6yYu0TcJ+qQTrSPZyhIUyLo+cUZHZ3HM19aAFKODPLTil+oo8rDAPrj2DfeY7qD5ct52QyWuISdqDZCbYhc+87UZGyTGHCbWTGogHi9pmPLcw0nEvj6Syni78rl3Ivrjwd/EWEy5eoJMu9ILKRc5f2+Q+ghXT/TFw9u1vgT04DwuoTihzkR7wyigLDya5NHWvtejgCJ9fkxHYb+DwpCcKYn/gxRnBRz1qI2ZXaOuVz/paw+na2bnyGd764LeNL/oc1jxUjsywIo8fUjvR67lK+Gsnr0rKUpBEUkiXoWKH4lt3nsUV+b8SjmUqdbEAaA0sHJh1fmLNjscNO9MgDFnUdtpe+ZRmvOBq3u3iKQfoaG2VPeGuPylSq8DN0QNi/sr+2LfwH+ADu4o5XvrV/VbDNZ9vG5Cj7vLGterVUf9gPO4/1tpZxwoekoQv3vw6Dvi42TdtVIZerbJ3VL6Y3qtrFPf+BqYX/I2Otcvt/SIeyA5xAjBDnHoFw8LmFrJFcFavWYeVrAF67iDald6JeEkJw0Kz9bt3jdmaF3G2WvTS4CWUULzGC/IYIU5qFOQb/Ykw0acz/HWqxOh3Ci0uVZVrmxMqwXBTx2RcfqWgnUfuUK3m/cLFYCMuh3zMv0e6aHL7RimQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78dd6afb-c4b0-418d-e23d-08da3d9a6aeb 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:31:05.7572 (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: +mIl0UKKsumIldBQYJ8UoD+O8d4RLS/NEaetz135sjsK4G027TshObxVRqcnaBXSyqoVYP8H0WxOf8eS/PH94w== 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: V_L1TAGeULHH4mEf0yfUV7SD8JRgLM_a X-Proofpoint-GUID: V_L1TAGeULHH4mEf0yfUV7SD8JRgLM_a Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Setup a handler to run vfio-user context. The context is driven by messages to the file descriptor associated with it - get the fd for the context and hook up the handler with it Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- qapi/misc.json | 31 ++++++++++++ hw/remote/vfio-user-obj.c | 104 +++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/qapi/misc.json b/qapi/misc.json index 45344483cd..27ef5a2b20 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -553,3 +553,34 @@ ## { 'event': 'RTC_CHANGE', 'data': { 'offset': 'int', 'qom-path': 'str' } } + +## +# @VFU_CLIENT_HANGUP: +# +# Emitted when the client of a TYPE_VFIO_USER_SERVER closes the +# communication channel +# +# @vfu-id: ID of the TYPE_VFIO_USER_SERVER object. It is the last component +# of @vfu-qom-path referenced below +# +# @vfu-qom-path: path to the TYPE_VFIO_USER_SERVER object in the QOM tree +# +# @dev-id: ID of attached PCI device +# +# @dev-qom-path: path to attached PCI device in the QOM tree +# +# Since: 7.1 +# +# Example: +# +# <- { "event": "VFU_CLIENT_HANGUP", +# "data": { "vfu-id": "vfu1", +# "vfu-qom-path": "/objects/vfu1", +# "dev-id": "sas1", +# "dev-qom-path": "/machine/peripheral/sas1" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'VFU_CLIENT_HANGUP', + 'data': { 'vfu-id': 'str', 'vfu-qom-path': 'str', + 'dev-id': 'str', 'dev-qom-path': 'str' } } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index fdee274933..fb5c46331c 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -27,6 +27,9 @@ * * device - id of a device on the server, a required option. PCI devices * alone are supported presently. + * + * notes - x-vfio-user-server could block IO and monitor during the + * initialization phase. */ #include "qemu/osdep.h" @@ -40,11 +43,14 @@ #include "hw/remote/machine.h" #include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" +#include "qapi/qapi-events-misc.h" #include "qemu/notify.h" +#include "qemu/thread.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "qemu/timer.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -86,6 +92,8 @@ struct VfuObject { PCIDevice *pci_dev; Error *unplug_blocker; + + int vfu_poll_fd; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -164,6 +172,78 @@ static void vfu_object_set_device(Object *obj, const char *str, Error **errp) vfu_object_init_ctx(o, errp); } +static void vfu_object_ctx_run(void *opaque) +{ + VfuObject *o = opaque; + const char *vfu_id; + char *vfu_path, *pci_dev_path; + int ret = -1; + + while (ret != 0) { + ret = vfu_run_ctx(o->vfu_ctx); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else if (errno == ENOTCONN) { + vfu_id = object_get_canonical_path_component(OBJECT(o)); + vfu_path = object_get_canonical_path(OBJECT(o)); + g_assert(o->pci_dev); + pci_dev_path = object_get_canonical_path(OBJECT(o->pci_dev)); + /* o->device is a required property and is non-NULL here */ + g_assert(o->device); + qapi_event_send_vfu_client_hangup(vfu_id, vfu_path, + o->device, pci_dev_path); + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + object_unparent(OBJECT(o)); + g_free(vfu_path); + g_free(pci_dev_path); + break; + } else { + VFU_OBJECT_ERROR(o, "vfu: Failed to run device %s - %s", + o->device, strerror(errno)); + break; + } + } + } +} + +static void vfu_object_attach_ctx(void *opaque) +{ + VfuObject *o = opaque; + GPollFD pfds[1]; + int ret; + + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + + pfds[0].fd = o->vfu_poll_fd; + pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR; + +retry_attach: + ret = vfu_attach_ctx(o->vfu_ctx); + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + /** + * vfu_object_attach_ctx can block QEMU's main loop + * during attach - the monitor and other IO + * could be unresponsive during this time. + */ + (void)qemu_poll_ns(pfds, 1, 500 * (int64_t)SCALE_MS); + goto retry_attach; + } else if (ret < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to attach device %s to context - %s", + o->device, strerror(errno)); + return; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + VFU_OBJECT_ERROR(o, "vfu: Failed to get poll fd %s", o->device); + return; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -216,7 +296,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) return; } - o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0, + o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, + LIBVFIO_USER_FLAG_ATTACH_NB, o, VFU_DEV_TYPE_PCI); if (o->vfu_ctx == NULL) { error_setg(errp, "vfu: Failed to create context - %s", strerror(errno)); @@ -255,6 +336,21 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + ret = vfu_realize_ctx(o->vfu_ctx); + if (ret < 0) { + error_setg(errp, "vfu: Failed to realize device %s- %s", + o->device, strerror(errno)); + goto fail; + } + + o->vfu_poll_fd = vfu_get_poll_fd(o->vfu_ctx); + if (o->vfu_poll_fd < 0) { + error_setg(errp, "vfu: Failed to get poll fd %s", o->device); + goto fail; + } + + qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_attach_ctx, NULL, o); + return; fail: @@ -289,6 +385,7 @@ static void vfu_object_init(Object *obj) qemu_add_machine_init_done_notifier(&o->machine_done); } + o->vfu_poll_fd = -1; } static void vfu_object_finalize(Object *obj) @@ -302,6 +399,11 @@ static void vfu_object_finalize(Object *obj) o->socket = NULL; + if (o->vfu_poll_fd != -1) { + qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL); + o->vfu_poll_fd = -1; + } + if (o->vfu_ctx) { vfu_destroy_ctx(o->vfu_ctx); o->vfu_ctx = NULL; From patchwork Tue May 24 15:30:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860324 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 A41B0C433F5 for ; Tue, 24 May 2022 15:37:32 +0000 (UTC) Received: from localhost ([::1]:34354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWbD-00078S-Pi for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:37:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVB-0008Co-1p for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:17 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:28892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWV8-0003RE-VX for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:16 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFKeGQ018506; Tue, 24 May 2022 15:31:11 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=uqM4fo1oaHQDQh56XS1RRp5KeUjXcP5uwdV6i5UnzOg=; b=THWEF9av5xELBCWGeg8f6GlWyiRnhzDuyKfrvx8mQ0iGcY6hkYq5Ok4WO1BxNWMiPsp/ S/36hzJATyefCU6teBUb0Pqew6/boi+W/YeKaslVbLc8ORD829AoASVfIyJPlENyuniG CSrYOlpbgp0nCh8QDaNiavrnX1MVcHr/orI4w2paG8/K0ulY/zZlopfdZtIxl4qknkV9 86pXNMCOgcb96ASiFcY7QBWWM952m10ue/3YTUSJSEGKwfmcLM4dOjZGknyD6nAlX2np hcDuGQjoLxST3qlI8ZRAsd+9hSbQd0N8Xdt8YAF1/nMyOdBk+eywIPtrtbhPdilUyosR hA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6qps6tjn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:11 +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 24OFSSVx020986; Tue, 24 May 2022 15:31:10 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2043.outbound.protection.outlook.com [104.47.74.43]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2rj84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OdWzG355mhzHgfv0ZfGNQQqpIT/GKLOFSb5lg2sWwll31rm31mTriuT8rAj9ovWYbPFwm2/zrtmeZKR+nJzWxys9oHvZY8fFUJoH81YUJBhH/bEhjw5HJnYF6xPDHAa3A2sPDYLYrYSitFFnCe9zGoWL9+rcXtLKhglH6mjSQrks1b1AQcGLzqyr8KtgX8JNXsIiq/EX50OrreVP/xmUQS+8BxTlNV3vnhCDffv44Pq3t2FkRKG9oPWVSGRHtyYHefNrSGS2VIAqJDWySds7nDsMSIovSVsTgc5rhYpxKbPgo8lpL270Omizuw9dQdEk/UukzY3McWEehE+RjvZdYw== 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=uqM4fo1oaHQDQh56XS1RRp5KeUjXcP5uwdV6i5UnzOg=; b=RlLvucuTw1bNOronYTy8uc89lYMIv2TScTx5XUBBq2zNL20tWkpbWZsoVlz3YVsfbA+U4z5kFbttrOPNMboV/I3Yhq06c4j3SIzyrXLL4MnNkTH4g3LxSFyO2au6YS0Kbk8UYZjSKkSriZAiP14kfyE1JWjez2QvGclyDD7DfY7NQLDd3Gt/inItS032S4WdxhkiVmOjrJtlCK3+MLjbCAKEMEOr5SonG8BB2gmZaTRWEnHGygX/5GWJ+FnYe/NMLIcsbeBrAn9NMW/reI7y/qWglRUN+XOzF/9exgd7PmKUBEzBsMlJNBhwlQyBoPLTENHBUQR8OjpQ1Sws/o80lQ== 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=uqM4fo1oaHQDQh56XS1RRp5KeUjXcP5uwdV6i5UnzOg=; b=J7Ia1CuZLCjOJw8J0F190UC/IJB33QRSPYQnOxEb2L3O46LOIKUSqXlo8xQsyD9PwrRLPhdEZB9EBP6uYUhKgICoOURfuGQAlNe35inGSATtsFK5Lsa/Gqih0oDM+E+cFidrNW6o/eGX1Wua/Ix0jL7/Zx2lk6QFiA3jp+t2zEw= 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:31:08 +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:31:08 +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 09/14] vfio-user: handle PCI config space accesses Date: Tue, 24 May 2022 11:30:28 -0400 Message-Id: <497de95cd7abe46350f62c748d45e691f7d64a8c.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: 6f8f8567-5738-426e-2884-08da3d9a6ca0 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: /HTupOOUwoHvGuGl6BRTbHpt7dFSe20roRhDGZMQQf+IlZYqqJYzBsOl85+H4iCyZI0LMfXNGvDWrcskylJbGdwo5QiuOF0y+0yZswauGSaiqFvapePeAJtEAGE1LcrV38N1Hva440tlFOvUMHG3PR6fi9R+l7v6FRr+ZsYI/nPoL3nk424J28J5vTCYmagV1NcG4hWgaQu/shYT3xGNpv5wWvburv0WkdTgQkG+mlD61xGvntotVqngSRltOcgY8mUZ2lSFc5YS5AbqcoB+mm7x+YuRQQ95JstSMy9KwzoksREoCJMIIohGbv8cboD/WEEkHqsbwdrYcVCyZjKWJIkWN2Xa0m30nin1hXmv7nENujGgHDAlK7LroY+zRMsiZ4IYQdCJRUMewPfbNgV6o9PY5+2vDD1Y2VZcOAh6/wuLQlky3Pcr8EWEELrZccCyV8Uq434R01Si21gmsiAih/NaQXY8c7nLXeX9EuBVQceIgg/gdm/ZfyUS/vUB57P5cyMtt4+4kpzn73DF8xaP3LUs/RE7BQtw+EoBeSfECCGOcztf/mKDE9ULifIz3kR/PLw2xdJsiArmUSmxp0x7TGsD8SOPz7VFNokToxQ2nYpNeBr9pfbTY33Kh3W7Rumb9wQCJ3YtwVqXhPERDMGx++bZw+Qjgys1bfSbb0OIKeR4UXarj9I2Pk3pAljJL7in9u6nwMfwF5CSSiFggl2UWw== 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)(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: 2Z2CKHujXs0EUIiqF0s08ih+O8oZcsKfp+bH686aWN+fi3hdjvhKk2iEQElgoc0ycc0yO4obAd+sTlAFHFohduCx4fhbKXRdvetnqdOrA2wR4jrIhDYURgur8yyDDOneBGR8X/dwiAYJ9N63til+iif0O/4G+HV86/fFtjslUZukVEAItORH5t+/SY88w9k99psl8+OxEkhQeHovDNNaYAnx4CSlBg6Mvn9htvUH8FHqpnwY1Pm8+uUuEHTS/RXpK6Pef3fFcxdL/KOOWXP4EMZ+0IJE2Nk6vJ67j0SHKfXdpMwqDdwq376rf5dZD/oJhkyXOOcXhEx591SVXSPhm3YoaFQHICfBDMyHgpd4XuodBvSMX5L1asILd4mLZXeeO/pKOlGpi404WlRGw2IAK8PvdnuUPuckl+xmidonrSsd40XhnPc8eyCtFT8t0jTAZafClyt4oh09ebCV+4TSgxd6Juu1BB0C2daCYngBRdzwIhsaUQbyURyYWi41AWHHMn/yz20VdQhM2zEeQoelbJfZML6W1l8NFAn40YEEZPBAcSeV49w6e1WmGNxCB3t+8ENpP0XffJUev2nowCZ/4Bq2xrdFma2cLEPOn+NCHG7R/q9ThPgLBc2ChIxPYc3QznEdHsR1LQhkeoVUvB2zsqRtxDDD9qojzhjcdbGU2NyN5oi+WHQDFNzic54HqXSAhJDcWbPhFkzxz4Yg7/hB0Hy0Qw132y/unbunqkWKIbpZao/hmoH5Wui41s8aD57Al1/ehIseGwyh8+8cQyPtwfogsXujqhE/AeN+tB6Wu1gt+oPqRoUyHc9skx8BS4H+9IfFJ3PQH/7MoB5AbX+e4MpLoIFZl+HW0bIbAdM50Ngdze2RiEGhtfg4CdHwT80+FfsFm6DjKwKZHMgWIY9xDU9rgha1eK0zPRINIVkAcS3ku+5KJR9bxceXWSfwHHq5jbCxwjpLWYGkG9wkZv2fQ/SXudVN42atDvRTHvFGh/AR+UJe35eBJkaHo2VIKClJc/PGHXfqZpp1nJKk6YmJuPBh3nT24CUbf6/BMdAh6Xo5ZV+voYnR4h0dbMcpSAqFkl6mHXXhIoWD3ED6g7C+cejBZvUDOiC7xapSoTUuialvYpO8BMaiOHPnae4IqxjykqrNsbDf5QWnTSo3kEU8HaTDeZ7+lqKHKAuZ8DHtc2EvDqtMtvHofd3FbKChSDAp/YHwrI8Ni5s/rluI2mBx03ITXoNfEfnSU4WNIDDbtRQwi3K3M3z3ltM0ut1oaJm9mDyvAcWMtsioQUWTFD6Zu2K5LC08ZskC/wSY5s5IdEbyaFKtN90y1sX6bFIIBk6dbCWMYZCzErUzYLDqq1AOAryH12dpRONIJEw4/55JwcXiiIcbAumaHOIcyExnV5sKEbbBSCBHVXOpb8YU0mEc8gLZ7yEhJTDcLLGGNOjB5lCT7B7LL71T0MHNQ1v1JYPv0JliLbAVpn++cCn260YCPaESiLQWEb6z++LPgbaSGUewLJ39hQKFJMyOggQOLfw6cU3e9n2ywF9BYj363iWwMhTo6gRSP3KZq44jf3Anhf6lV+genlwsdUFpwkUKH/IcvDDRpaqZkaOeXfNteSlbg4C9ovXkklDnR4qaoKILK9DhmCV8Bvtvzil4V38E0j3nOSspydKE2Ze/dgjRNTTKnBRiVWWDldbIbXCxje1ZrmYaAN/CjEsTel8vrcJB8KYm4nw7wG+V7aNe2mkutsSYxg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f8f8567-5738-426e-2884-08da3d9a6ca0 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:31:08.5852 (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: cT3VfRrPM2fE2LaCAej4gfcSU8ZDI4/jH6/hDwlW1iiu0uaF9Y7cBcN2Lh5a/8BNvul8Jjya+GJErq+76EyA3A== 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: nPAuumOLT1cCLY8XOTN2CiUv6kvhEx80 X-Proofpoint-GUID: nPAuumOLT1cCLY8XOTN2CiUv6kvhEx80 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register handlers for PCI config space accesses Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 51 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 53 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index fb5c46331c..575bd47397 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -46,6 +46,7 @@ #include "qapi/qapi-events-misc.h" #include "qemu/notify.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" @@ -244,6 +245,45 @@ retry_attach: qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); } +static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, + size_t count, loff_t offset, + const bool is_write) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + uint32_t pci_access_width = sizeof(uint32_t); + size_t bytes = count; + uint32_t val = 0; + char *ptr = buf; + int len; + + /* + * Writes to the BAR registers would trigger an update to the + * global Memory and IO AddressSpaces. But the remote device + * never uses the global AddressSpaces, therefore overlapping + * memory regions are not a problem + */ + while (bytes > 0) { + len = (bytes > pci_access_width) ? pci_access_width : bytes; + if (is_write) { + memcpy(&val, ptr, len); + pci_host_config_write_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), + val, len); + trace_vfu_cfg_write(offset, val); + } else { + val = pci_host_config_read_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), len); + memcpy(ptr, &val, len); + trace_vfu_cfg_read(offset, val); + } + offset += len; + ptr += len; + bytes -= len; + } + + return count; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -336,6 +376,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); + ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX, + pci_config_size(o->pci_dev), &vfu_object_cfg_access, + VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB, + NULL, 0, -1, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to setup config space handlers for %s- %s", + o->device, strerror(errno)); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 7da12f0d96..2ef7884346 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, # vfio-user-obj.c vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" +vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" +vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" From patchwork Tue May 24 15:30:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860346 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 76100C433EF for ; Tue, 24 May 2022 16:07:48 +0000 (UTC) Received: from localhost ([::1]:58376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntX4V-0003Db-E4 for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 12:07:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVF-0008FN-5n for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:22 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:43264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVC-0003UK-Vq for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:20 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFPMQb001520; Tue, 24 May 2022 15:31:16 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=B51K62cS6ZkPHiXp68MWw29OqPcqZq+rplOVlnmUwks=; b=0GkEne4Csis9M8YWqCnCUkle9wV84pyqcz9Gl0Y6K0lFer3ubwIAqTaVUsgvRmrCR+Js WaIemlmZCrpqSmXNmgi1Xk38Rnz5fdobhuU1sn1x/juM0UnuKwrwHPNzPYMfQCXqj8pz S3gi1vneAo2XDqJHSj4b4JW8eMRYEwfJehfjdEJtYxevgHm5NfCQbRRqPNE1JHmA93yn YFasWKGnohYFxC8tyEQ1ibuusYJ2La0Unc8goGVFuwPTxpqNkuTIN8eex+QrctXP9/wG 7X+DVLqZT/6A5sEQy91/4GwRk/pf9DB7iNEW9uanwqKzTpf4gzatwtBNvFfKCKpIoH4v eQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pgbpqa4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:14 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFFrjN015045; Tue, 24 May 2022 15:31:14 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2047.outbound.protection.outlook.com [104.47.74.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph8x15x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VfGuVmWrNiE/mQtQBrS6NduVIXltEx3QAdsyGd50XC7rze+wMj8iSOYZjIbKXa7BqYv83gDoxcEHIP/RFhnw03Sku+M5/A2B36gpBmZd+T/ItR1WH/Ry8Ry7QbdTjYzYcgdZktIwAhlQjzYudjNah0CksVnOrRV/7I95PMy7eYsoJaCsYNPGWztBK7zN6P8FgmKU0nYIIBfwjcu7ckWjGEBvzJmKZmLqMh1FtABKwv9iF9xzfaXoBQxV/+pfMBNSZ66C1mdDaP98pevBsY7Vtk8mSXrl4hRmvS0asOH0Nu6AHVwd+I+m36ocuhFnM5xzG15Qv1yO9FjjcnBif1qDcA== 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=B51K62cS6ZkPHiXp68MWw29OqPcqZq+rplOVlnmUwks=; b=ZS7iEFwLEgNzdh2ZXFaJ4APxFnzbAfd5ZvW/t4ejoNBFWlR49KsMPJfrAHaioc8z505xb0ac/qgQQ5g6QOFWKOrKMup2WvSCAF1gURHdZJpObpZLpohs+Rh70AlIHzghvruMguo7mJujLAwbYK6oNRz0xIj7ygcliBPXFsevvBK4oXNYON3nCWip0lmIzyLU9ohege3VQLySGhU6R++3bZfKR4ywFQUHp5mRhwXdJW+CSDFxcTomk28hK4jaPex6LZ/zO1wyvS0tC5zGcT83gSBw82tZrqQwZUYzbXZ/NSBhnYUSdw0mlqVToF5sgbUQF3jCOxAduvdoawaeLG6a+w== 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=B51K62cS6ZkPHiXp68MWw29OqPcqZq+rplOVlnmUwks=; b=O6QxL8gyAmQKErZ8wMCslfmGBaYxDo3cyWLIWGocQe6WMe9KGxThdpu25eThdxQzQHi5xwGFwKkRV6OQiulKoguBRFCU9bsYdRoyU7PCbfqsFgZFZdqT/f9eQbiFZiIxPQYhms37GkwBvI8hHJBh4KBDUmW/ZrACfdOBnFR0hM4= 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:31:11 +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:31:11 +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 10/14] vfio-user: IOMMU support for remote device Date: Tue, 24 May 2022 11:30:29 -0400 Message-Id: <94611f75e1b7bda8a85b2cbb2b81f976c2d2e338.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: e1901279-1c3c-441a-cf2a-08da3d9a6e75 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: XXLa9iDURxKeQtjh5p5XhOearzL1M7Md8z8yqeILuXX4ZSxPgXJl0z5aC6llnZgM0iIoDwDsUzhSsqb4v5IrozpiQmh03HPq6PHxBS0uDRbXnmM7DaJ8fh213c14nqoi9SJWKyvzYjrHvsmXBzIYAfEOOOSC/KO14EjBtqqKZY7KV5o+595D0cj/ovQx4zVEMLOh8kDDw3ssapwLO05bQT2y7t+1I+Vq34GvCMYWiuBenN27NNDw1o/s+Huyb1xV9GU8TvnvFTzjshK5gIq8Ko9JIhmEB0CwMnWAaJQG4u3i9tDEKqERc3pGdEJrIH8p3+kI1n8UrWObD/PPUes5VsGkDC9NCKgk5KYUocPBw+mCcB7Xj6gCrwLJmaCWz62v+4l0u2SAyFBOKpVc/H+TAWoLuiiI7YsXjN1j1/sJovOISHn8DM+5WXBdTxkPrqVGYQJUFq3tE4BeMkfBKzaKsGdrrxeNI3yldk3wwUWSPL8Roi+c/OisAgpbzXyfrlJ7wJuvRKMk5dmmtc7ieDSJ15ti3PGUnm5Gpj9r54RJjWX1PeABDg+4vFbfukDphkPR9dR18+Jc4hqe+jqYJll+A83WYg30DeEfLlwnwMd9Ge3AIuwVfweYDBqH73fk89gV7TZsYVKPuaR9fDTPitGWm6HGZ9A8t7Psaoi5g+lhvYb4wAxT1S3FcyDcooIa/AGIeb0uBpvAEb0d1/9m5+mEeA== 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)(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?Qo2Xgw1HadAbz5sPnrkOBwLtY40G?= =?utf-8?q?usfgzPjIyX7udc7p4Cv2yEYyeK6Lp+Hr98GSnueyKR7ONJH5xO6qa67Dn+4wdEBGy?= =?utf-8?q?Z6u1gXBNrcMIn32379t1ash17K+Rn7fovsuPvwyRaMbbizkVAe0dsM9INxeF+LwCa?= =?utf-8?q?8mw4ycom2u4ohovyULBY1PxqMxEUIZzJ/pp4jULS38fTE0UfzKOiYtAo4yDqCIp/b?= =?utf-8?q?Sc472GZTH7g0JbqKd1K+9oEmMW//kAgyec2neqBKKHY0qhJHaVY1rbxy32rbEbNOe?= =?utf-8?q?bBj189sgXzPAEh7oOBtQhfFogM8wCYxiBq1Itct+fVFue9jO5CbdrMz0TzQTFX9Va?= =?utf-8?q?AE4DE/JJWcB5t8oyIuPCKvZNVmoHjUieNFH8G+svsFW7JqTsi0OU6eSpsY7Snbg0l?= =?utf-8?q?n9EV40MS5hHdwkjkH1VC0w2qR2aJ/7Zlt/T/bzYY015LH0VmyKaeA6UvJ1hXakqzT?= =?utf-8?q?KghkEd7GlA8rrGsEo3O1viV04dY3nYrzZlTSVk7A9OW1VrB7YnRfNOrdLdmxKqBjT?= =?utf-8?q?TTub2bTt6dCEXpKl7Qc0Bosu/lHGpnDLiMTep9bevWkZU1wt+ICZKj103+VDsrRq8?= =?utf-8?q?Uypdz+clRmMoJFN7bvbS0HExMQH8NfBbHEvavGuzdVVN3KgRYtBLV4nZwCs+K4TCj?= =?utf-8?q?weH9hgfuheA6Bzh/n6Z+AjqKaAjT+Tbsi8s3tH963+nCAPVXGKywgFB/BzE/AOWVj?= =?utf-8?q?JhyWeP+kXKMSk3eWsOFQh45qRC3Ky0ntO4yMV51Efn3wbXSgs35zjiTH8DMVkWLrL?= =?utf-8?q?O9LbuQSEPUocdA2+KeHHz4PH5QiJTbfJzQVMJqe1R7a+UCM0BBpYEZCUnvPtYocOn?= =?utf-8?q?SeNfcILcoxs2khzrtFsBcyl2k7ZZVhC8a+uWgzBhjZGkx7EDgw2NoNc1nJF1h5f+k?= =?utf-8?q?SU/td9vN4yRMg4+XLLRcVfhgU/P/vF1Y5ZNCir2A0GXPz9Y/4htKzPpxTccDNLFR/?= =?utf-8?q?4EB6UWkOQwLp++OR5FSEvIOSPhIJDfdTklj06pu+iiRJfEOQn20y8dMkEDHfIlC/W?= =?utf-8?q?ScfSzsdoTVxt6kyGHVjAOHSe5zWeB6J8c9VounNWxUedDEohiWoqFrGsSHkqN9bds?= =?utf-8?q?H6BNMIS48Zt+ImLBCLPDhoKbo4NuyLpXHdae5MFYp5JhScVhlUH8wqsrRkeGsBORV?= =?utf-8?q?LP6X8C584oypVDK5KpnxA0ybs6RjURPbRH/8itCd1cQn4S2hRZHwFnlU8uLM9o/+B?= =?utf-8?q?NxUtNABAm9b5bAy4Gmkdrr+v6y6RhSKTiTvOZ10IOzjugM7pwbv4AG6CEnzXxUcxT?= =?utf-8?q?JbRxIgqIAUd5fIiw1/GewsVab0x3ZY6Vh85NC8I0oMSIRrZiwNfPHi6Fs/VDjjSOc?= =?utf-8?q?5eiSS4+kJa3pSPqPOhetuuTOhEypGzQSR9CNYk0xqaN9Ox92M4ZMa69cYLhTgRGMX?= =?utf-8?q?C+izctZ96d0zM45nwAtNI7v+2gmkwDp3R1xuIKkmV9u2pFJi49HSmdAh73sZXJoiq?= =?utf-8?q?0jg/Yh6J5mak6/qv4lIuO5Eke7FslZl1p/cxbXn0K7blv5E5D15Y3ufeYGX+BnqX7?= =?utf-8?q?0lIIytYCcfQunbqlJtS87fFryqlmXcOsaKAWQ2YEzygP+01WBEHRTtfL7Ly6oP7Ow?= =?utf-8?q?x28Pndf4yEmWibbR7+cCueS+xTXZrF0fni0YzWHWOkePRa5ntiG/qdmmdz4XGW0S+?= =?utf-8?q?yHlDlVtWEe2MYbIKoK5w4LLnu50bhQ3Q=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1901279-1c3c-441a-cf2a-08da3d9a6e75 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:31:11.6787 (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: G7kTMmZM3VcXD1KdmogID+krkzitz/DoUZv4hozo5gESTSvU5/Bmg8nzv6NiBldEvo8TPRMK9dtzcjy5vmCMIg== 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 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 malwarescore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: 5HBA81X-xCiw6vzHp-rgVqApoLSgbUjr X-Proofpoint-GUID: 5HBA81X-xCiw6vzHp-rgVqApoLSgbUjr Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Assign separate address space for each device in the remote processes. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/hw/remote/iommu.h | 40 ++++++++++++ hw/remote/iommu.c | 131 ++++++++++++++++++++++++++++++++++++++ hw/remote/machine.c | 13 +++- MAINTAINERS | 2 + hw/remote/meson.build | 1 + 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 include/hw/remote/iommu.h create mode 100644 hw/remote/iommu.c diff --git a/include/hw/remote/iommu.h b/include/hw/remote/iommu.h new file mode 100644 index 0000000000..33b68a8f4b --- /dev/null +++ b/include/hw/remote/iommu.h @@ -0,0 +1,40 @@ +/** + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_IOMMU_H +#define REMOTE_IOMMU_H + +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" + +#ifndef INT2VOIDP +#define INT2VOIDP(i) (void *)(uintptr_t)(i) +#endif + +typedef struct RemoteIommuElem { + MemoryRegion *mr; + + AddressSpace as; +} RemoteIommuElem; + +#define TYPE_REMOTE_IOMMU "x-remote-iommu" +OBJECT_DECLARE_SIMPLE_TYPE(RemoteIommu, REMOTE_IOMMU) + +struct RemoteIommu { + Object parent; + + GHashTable *elem_by_devfn; + + QemuMutex lock; +}; + +void remote_iommu_setup(PCIBus *pci_bus); + +void remote_iommu_unplug_dev(PCIDevice *pci_dev); + +#endif diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c new file mode 100644 index 0000000000..fd723d91f3 --- /dev/null +++ b/hw/remote/iommu.c @@ -0,0 +1,131 @@ +/** + * IOMMU for remote device + * + * Copyright © 2022 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "hw/remote/iommu.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" +#include "trace.h" + +/** + * IOMMU for TYPE_REMOTE_MACHINE - manages DMA address space isolation + * for remote machine. It is used by TYPE_VFIO_USER_SERVER. + * + * - Each TYPE_VFIO_USER_SERVER instance handles one PCIDevice on a PCIBus. + * There is one RemoteIommu per PCIBus, so the RemoteIommu tracks multiple + * PCIDevices by maintaining a ->elem_by_devfn mapping. + * + * - memory_region_init_iommu() is not used because vfio-user MemoryRegions + * will be added to the elem->mr container instead. This is more natural + * than implementing the IOMMUMemoryRegionClass APIs since vfio-user + * provides something that is close to a full-fledged MemoryRegion and + * not like an IOMMU mapping. + * + * - When a device is hot unplugged, the elem->mr reference is dropped so + * all vfio-user MemoryRegions associated with this vfio-user server are + * destroyed. + */ + +static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, + void *opaque, int devfn) +{ + RemoteIommu *iommu = opaque; + RemoteIommuElem *elem = NULL; + + qemu_mutex_lock(&iommu->lock); + + elem = g_hash_table_lookup(iommu->elem_by_devfn, INT2VOIDP(devfn)); + + if (!elem) { + elem = g_malloc0(sizeof(RemoteIommuElem)); + g_hash_table_insert(iommu->elem_by_devfn, INT2VOIDP(devfn), elem); + } + + if (!elem->mr) { + elem->mr = MEMORY_REGION(object_new(TYPE_MEMORY_REGION)); + memory_region_set_size(elem->mr, UINT64_MAX); + address_space_init(&elem->as, elem->mr, NULL); + } + + qemu_mutex_unlock(&iommu->lock); + + return &elem->as; +} + +void remote_iommu_unplug_dev(PCIDevice *pci_dev) +{ + AddressSpace *as = pci_device_iommu_address_space(pci_dev); + RemoteIommuElem *elem = NULL; + + if (as == &address_space_memory) { + return; + } + + elem = container_of(as, RemoteIommuElem, as); + + address_space_destroy(&elem->as); + + object_unref(elem->mr); + + elem->mr = NULL; +} + +static void remote_iommu_init(Object *obj) +{ + RemoteIommu *iommu = REMOTE_IOMMU(obj); + + iommu->elem_by_devfn = g_hash_table_new_full(NULL, NULL, NULL, g_free); + + qemu_mutex_init(&iommu->lock); +} + +static void remote_iommu_finalize(Object *obj) +{ + RemoteIommu *iommu = REMOTE_IOMMU(obj); + + qemu_mutex_destroy(&iommu->lock); + + g_hash_table_destroy(iommu->elem_by_devfn); + + iommu->elem_by_devfn = NULL; +} + +void remote_iommu_setup(PCIBus *pci_bus) +{ + RemoteIommu *iommu = NULL; + + g_assert(pci_bus); + + iommu = REMOTE_IOMMU(object_new(TYPE_REMOTE_IOMMU)); + + pci_setup_iommu(pci_bus, remote_iommu_find_add_as, iommu); + + object_property_add_child(OBJECT(pci_bus), "remote-iommu", OBJECT(iommu)); + + object_unref(OBJECT(iommu)); +} + +static const TypeInfo remote_iommu_info = { + .name = TYPE_REMOTE_IOMMU, + .parent = TYPE_OBJECT, + .instance_size = sizeof(RemoteIommu), + .instance_init = remote_iommu_init, + .instance_finalize = remote_iommu_finalize, +}; + +static void remote_iommu_register_types(void) +{ + type_register_static(&remote_iommu_info); +} + +type_init(remote_iommu_register_types) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 4d008ed721..cbb2add291 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -20,6 +20,7 @@ #include "qapi/error.h" #include "hw/pci/pci_host.h" #include "hw/remote/iohub.h" +#include "hw/remote/iommu.h" #include "hw/qdev-core.h" static void remote_machine_init(MachineState *machine) @@ -99,6 +100,16 @@ static void remote_machine_instance_init(Object *obj) s->auto_shutdown = true; } +static void remote_machine_dev_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + qdev_unrealize(dev); + + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_iommu_unplug_dev(PCI_DEVICE(dev)); + } +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -107,7 +118,7 @@ static void remote_machine_class_init(ObjectClass *oc, void *data) mc->init = remote_machine_init; mc->desc = "Experimental remote machine"; - hc->unplug = qdev_simple_device_unplug_cb; + hc->unplug = remote_machine_dev_unplug_cb; object_class_property_add_bool(oc, "vfio-user", remote_machine_get_vfio_user, diff --git a/MAINTAINERS b/MAINTAINERS index 8121671228..9d8695b68d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3604,6 +3604,8 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: hw/remote/iommu.c +F: include/hw/remote/iommu.h EBPF: M: Jason Wang diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 0eb5a0f375..ab25c04906 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_MULTIPROCESS', if_true: files('iommu.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) From patchwork Tue May 24 15:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860325 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 35916C433F5 for ; Tue, 24 May 2022 15:37:37 +0000 (UTC) Received: from localhost ([::1]:34694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWbI-0007Mk-Bf for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:37:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVK-0008Ht-I1 for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:30 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:49102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVF-0003VP-0z for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:26 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFHS5S018477; Tue, 24 May 2022 15:31:18 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=uS3rE0whJxtQmZ5hawMvWyrClqljIpiOyCbvhsJlICI=; b=yDP4jJVgd+RXUREsisxhkCex8tljbmSJJN+i7J6Tgs2oYsHi9/xcgfdvh8ZXgB415CMG 8ElxXQkOJkokhRvuh/tQetuVcNHQeFEXM29kwUBfrjoc2aSGgiO1D4sOcQjWUF2QtlKS pp9rv/mactflH1VKF2iLP/cdwxDj/jJe9tF3eQtxasYZnwqi+4Fm+z1U4GIe7QtZ2wfQ SRTbD+DZr0WY7/0JPr6sHuZGxp1IHeEUt9EXrkp4WCGin7F6Pe2bDBzmLUzuNm/zZxfP S/tCHRwSwqrxlFFWVRuujfIZ1rBlt/KqRZ9jNfuwf9dN3BPcd0CpORajQNdADn51ZvtD 2A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6qps6tk2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:18 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFGJLX040315; Tue, 24 May 2022 15:31:17 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2049.outbound.protection.outlook.com [104.47.74.49]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3g6ph2h2n8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ReytFWxZ2AI8j/321As2PCLGzT8EFqNUsSyv1iq56ZRgsrJOPZmMdicPTNzA13IH2UU6FEfiDp88p2gXxFK0KtNmpiobUXZJX8avRUeGT2zU4Zd5F1NHsT98cfiG4uMeAPf+nYdPqPtdELeY+TYv5BcVntK/9Vw9hlkh4b4gNvSlUKLxKfkYw8xHUPVYWUWR2ZjPhVXsQ18+H607CW1jdeQ93U1sljoHYjmRyrMmOIVX2PLKC5VNJ6xpok51BMUGFTWVAWLNdGKz4WMgaQl76k5vpssHGPsqWc4wA98et4vqZU68MFHH6HH6nYHyI3+zouM/pabCalPaBT2W5PxZnA== 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=uS3rE0whJxtQmZ5hawMvWyrClqljIpiOyCbvhsJlICI=; b=WATcVm0pMbjqAmnqPlri0r9PsZHNZGt70ywA9UjiQplIo27g8KOVStvBcOHykTa1QIfKob4nsHxUXwK932MatscgFHJuOD3mQhLqzcJMPXjk9tGnPkd5Q1VxvtI2Zgp1P9WVquD3oWSwCxPgkqMvDSScO6OBJYFD8d5gPztUsidI6TAuSOY0Y0QRxORZFikjjdgwhvMqwKfMMmTKnkQ+fwGlRxfgP47QJh1rRdifZokJvB1XR5WT4J9pQXIr1i2jPuY63O1R3a85rxw7A2dnoYQjqY1Dh1Uzlds+zF5d+P7SXM633HXC0PUm/iuUvnvE3cMa/9bP0tr/noEHQ6a7iA== 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=uS3rE0whJxtQmZ5hawMvWyrClqljIpiOyCbvhsJlICI=; b=GknIpqjc9WO7jYnFVc8Z4KIlTdsgFAvNQdk7CV33IcunbQqI4cchovXPmce0XgCWmSx8uUI1HN2zi9PQsizA/+3D+cVaTGbk48dnuEp4NUc0i36z6p3azrKebw9YSxphPZLzBuW6nVf7/JSzYVdjhzmGEm9TZDCxZy8LWnQ7bmE= 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:31:14 +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:31:14 +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 11/14] vfio-user: handle DMA mappings Date: Tue, 24 May 2022 11:30:30 -0400 Message-Id: <52415ba6025ed886828cd49744ed833c121e58ff.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: 90a250a8-5ccb-47c5-52dd-08da3d9a7006 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: CY8LcUK2/OUdLWTWtydjPK1wMGwTz64foolaMznh4fM+GTy4or5rYWd2M7q8V2xQwjNzA8x+K6hH1NGNLXInQgce5oNdewWUOSJS+LYqrSSO6qbMKsLczgTPaI0OK7H32jePylNdV/wDOEozzOzLAjkP4yI3ZCEbgY8S1X+pl+kwawEExqkaAM7cNoezXU/7e+Ovpe0ILjA/bmdtiEnzYVE/dk0VKllNz1VOfud/rwDQnzEcJ1Nz7sK9L69cjxlptO+vwNAVuxJWxwreksuhbTnBNqv9g+IDvdoYgtPKOmpGwl6hznJxGPDVsTkYrgVEQ7RGX2+23rZJaoZ9pZxvSN1O5xURwcLm1J1F/9psAz4nlFgkB1mOCZOc5eVzeZilIO6A2pHOLd4WmH5Gtz79xJwaOrmsJ/a0EyZwGfIO7Xr1OF6moNsdwjhO82IweW8LqA2Vt5K+Mr39LLImwe1C2Vuo2Z4ZC00GMVikcJCjerFEh2WZhsgxV95OF2hyvnUWQV4N50cRxgV9CfnV0UOhgnLUbj9X2OYndcLxaTPEUZ1AJe3hr8vO1PPOTJpvYK1Y0rmM3RVo1qh2VN65pd1H5tU/gVHANlIqTNRLa+Y6LKJ1KSBGWFDTJvgKBK2SUq4XZxGX7dV5b7Gbz/zMcl825y40lZQvwv85AGqMGqJDgvRPKmiBjhpXUFcswKql+TQWbA4v8r3Z6vKsx6j1YbTYFg== 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)(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: VerpWRtS1Rea/DGKUZ8oIYA+iw9OuNCBQOjVf8FI8vhrhlf6LdHcGEzAoVwc0DO2MEa3PAiyMZ6qwKtfHClV9HOVP5iz/U8fG85s8VRaMfjexRH6PvcQr7C6Bh5oObEsCHylHnFn0D363NkUcNq3fiOVCvyn4VLJhm8tc6nKBLfhqwqQsJGP45M/+OjmbzOyGYCSBqEaqnNvK6tgxxZWPSUDAm7x4RT9sjSsNsBHkw70mB7woyrDX9DXVgBkbarFWAAabzpEvMZ17gUsOlOdPCVIVu4omvKp+V75NJT4YTOqQqhtFRmNba03EdNkKjuVEpCUe1Egsdwjps+046ieZ8ikqHyxpCydSLbzNMJNZuv4T7kGZw5dk9B7n1vOIUoYc/xzK53gO3YKKm1uogaYoHRu9aXe6WlS6a7AHQnsNX5echTQAic0LUQLSgfbvJQtkp/mkUfKXENW3Zjx92QHyVUVoZXy8nDNxgNtzIBwT/QNGVg8xGdsTv7W3wpR7fnar3MEMcWm+rXcyYGpMiRYaKR+i752c/dyAW2tTYjBpxSQMpm7gOJROGpfTb53nEbvA7R9v1WcRtbSBW2qf6x9XaGsIDrbRnYFAU3v/4q5sNSr8lTpJ5GovwL3KlNexfxBI545/aQ8U8OVA9K0255FBfXMxRAmPFGFdAw3Akc6mhddb1t9qK07P7OCO2hOupHuLMaxangYWXcJz2Jo5c6y45ngyZ5w271RJP7vmbXCWkTIdHmQG1UF2lw62AzWCXYJR/pRJWmYlXUHQm3fS+D6KFemWYOBwVSwTyAnY9Q0RW3ZWxH2ve18FctnYPL+fg5swwP3IVpnQtxoeBawLykJzPCpBIRJl9RbOl+4QmxnPstgWP4ZFO5AWsohwJ3OjB/X3TwWfHj381xZgzLS0VT9NsBSRvaRJWFBVeYloZUW1XS37PwRsGnrK9BxL15uu0J2sh3/KlESMn6/4JNnfdSmBtGcdArRweRSQOBF+CnBsphDVH4mxk5qXVp2DX988X07yOVQ3ITYQBaASHcgM2trnSZ8zto+7KyEGyujLsfEnzxD++cuyjX4oXWCPovo5bRVm9lm9GOaAF2w65Qhb1up8etDS+0kSYtRLj71+09cKvWjm28pvEBA917B8KeLlumxnB8JqRtakzByN41l5xr9kq3QeANoyVq8CHCyyb0hhvaEZ6x3spcDRH8spmEUqdiCNXGvEk690dWNRiOaYmeKDCJypM2CqZoy7j7lzv447i+1ZGG1CqNT7t8S8/S10yeSrT2KRhaN28QzlhWNOK2c7/Pxw3q/a7vL10jM1gcxHNHkZAliU3eUtwGXaUKOAlwxaYAbigWs6BzpxErb4wW0P+5SFRMbMZ3uaN0j6UF8K2T7DwJzszVcFl0DtkkELlIitls+fulX98C8oNbZjCk+R5tx5XC7zqnHbi95CCA5co6IrazFKdltt9cbVhNhuC73aRN67loxHKF/6fkg7W2JLiMvi/utp/vcbK3y62kZ6YSJebWkMR1YxIvc+4KZQXpKh5hQybpE+p0MbP6m5AGDKDpfMmDasyYcTIWHIo+1v4yTK0xet2p4QMttAt5uASPAUQ1wRqcTjrDNxDbpYYTiOSzFThdsXkJ5TiOQbNDz61nxte2pS7+xu7qPAbfnjNz4GAYSZRYkdNF/y/eTrpvo/x8FCaBCwVu+WS9cA0zF8L2fhumijMGKeKq5IFv1q9I/+lzg1Hdg2yFFausv2BsM5g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90a250a8-5ccb-47c5-52dd-08da3d9a7006 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:31:14.6629 (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: 58Y+BPzAVbIdxb6aGpxtIELgwtppNkVbsgZZX736ZbuUkjOaqLB4EI0Nw9Uaw3eTVUKAZY5cTkTVas/pYbJYsg== 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 spamscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: NJTiss-91wzjdeqv-VqyWhZdCwFI80Pn X-Proofpoint-GUID: NJTiss-91wzjdeqv-VqyWhZdCwFI80Pn Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define and register callbacks to manage the RAM regions used for device DMA Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/machine.c | 5 ++++ hw/remote/vfio-user-obj.c | 55 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 3 files changed, 62 insertions(+) diff --git a/hw/remote/machine.c b/hw/remote/machine.c index cbb2add291..645b54343d 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -22,6 +22,7 @@ #include "hw/remote/iohub.h" #include "hw/remote/iommu.h" #include "hw/qdev-core.h" +#include "hw/remote/iommu.h" static void remote_machine_init(MachineState *machine) { @@ -51,6 +52,10 @@ static void remote_machine_init(MachineState *machine) pci_host = PCI_HOST_BRIDGE(rem_host); + if (s->vfio_user) { + remote_iommu_setup(pci_host->bus); + } + remote_iohub_init(&s->iohub); pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 575bd47397..8d208f1294 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -284,6 +284,54 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, return count; } +static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + AddressSpace *dma_as = NULL; + MemoryRegion *subregion = NULL; + g_autofree char *name = NULL; + struct iovec *iov = &info->iova; + + if (!info->vaddr) { + return; + } + + name = g_strdup_printf("mem-%s-%"PRIx64"", o->device, + (uint64_t)info->vaddr); + + subregion = g_new0(MemoryRegion, 1); + + memory_region_init_ram_ptr(subregion, NULL, name, + iov->iov_len, info->vaddr); + + dma_as = pci_device_iommu_address_space(o->pci_dev); + + memory_region_add_subregion(dma_as->root, (hwaddr)iov->iov_base, subregion); + + trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len); +} + +static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + AddressSpace *dma_as = NULL; + MemoryRegion *mr = NULL; + ram_addr_t offset; + + mr = memory_region_from_host(info->vaddr, &offset); + if (!mr) { + return; + } + + dma_as = pci_device_iommu_address_space(o->pci_dev); + + memory_region_del_subregion(dma_as->root, mr); + + object_unparent((OBJECT(mr))); + + trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -387,6 +435,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_dma(o->vfu_ctx, &dma_register, &dma_unregister); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup DMA handlers for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 2ef7884346..f945c7e33b 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -7,3 +7,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" +vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" +vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" From patchwork Tue May 24 15:30:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860326 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 84433C433F5 for ; Tue, 24 May 2022 15:41:55 +0000 (UTC) Received: from localhost ([::1]:41624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWfS-00040D-Ij for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:41:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVO-0008Ik-Gi for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:31 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:64492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVM-0003Z0-3y for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:30 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFETSv009629; Tue, 24 May 2022 15:31:21 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=DH8Elj0BsRu9v/C7IDK76GSZTh9yRKpXnqnoY2xHMv8=; b=pYgzRZGoIkDvHkXGXO4tIu7j1nu2ZAmAKWOg8OG9UkQZtwqwsqpGxXpR5/2tJlxVRYEi 1C4vstS0sY3s3N3rQhmhqOO781HSEflNDYDXKY2GjPIO3z6wq1cIscvGpMYXBO88Pkl3 dZPmHCQ9B8a74lNcJmWHVDcPWEMT8zZXFRD2r4Rlfv+AyBZO/k2Nles+mTeqDmElO2fu rn73PSkvi12GzpcDNlSgbilSUmm9lOOwInVhgUoO/onf1PucqH7d5MVshmj39+d9OjEX 6E5jiza2M0MzTwrFx6j4jOF1+duBtndPFVSDjooJ/mgkQ7wKN5OXSeTj1sOkOKicssl7 Xw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6rmtxrjb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:21 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFGJmQ025923; Tue, 24 May 2022 15:31:19 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2041.outbound.protection.outlook.com [104.47.74.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph8drc9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ftAHHqD9n4WFzEbbK1SC/1xsetOFQkVTP75jqJrknSIOovX/TqBJ68e66OSWzqmAqFYs1LWF0G/YZ+DEQR1Dauc0ZP+80pDyR1kSnuhy7MSwPzhKTNHtcGNHiwC8nHPLX6a1mHTZ9bDHxd1ZW9IUEJFp1d8ZmX+I3aSImGFIXuvG/bKDYwyqVSiREd+6SqPFowyuLnaRQj0YHrNm7hKrKnU9A9a9WyIY1uSoi7YYZUHs3Nce026IbLcvOjAvd9+RHkjgUCMUAdkhPgeJmowINhW7dUQ6zI7fBo605H/2GARgZQsWteiy2iDCoJrXNOwZn6R0Aez1dLiEDEnJ+Dy+ZQ== 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=DH8Elj0BsRu9v/C7IDK76GSZTh9yRKpXnqnoY2xHMv8=; b=Iy2FlCY8vyMQiT3oMCp2mSjuOScliG3TD71/oRCsy2GotR/Iyewl+urc/uFx9UvWk5bRRcp54i7I81RQHgZ4iITmVwjgPVKBJW+i/a1MzNRcjh4Nri4wGINfjOWWOmom2ftFnMZ8JPsl911jEaVMRj1Vdxzq8Le6zxaujefgJXKjXBWmxYWCkICvLJWnMqZgOURh382RfCBgedtJZrVu+CSnAd04CgFoD84dJCm5IJQUHYA4ZUTmEl6vGqAhA2JWmcacrIQ1QHiQRr1Jm0joggI4aWnE8TY/M1xi3dw0apyRXijCkfXti/9Yh8zXw2ZONrgvXsLhXJKFld0pXLPZiA== 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=DH8Elj0BsRu9v/C7IDK76GSZTh9yRKpXnqnoY2xHMv8=; b=qMjZykBBxLxmNIzGb9wze8SMBMcEPh1gSWYSJ5Tq1ghAbcceSHdVnfC7Tnm7zIkfmc7Zmwarv3NLPOB/4layZhcNIARys7fI19CvwvQbVEp0xqGQLuk3QS9r7OiBWYFVVJD9Nza8ojUjcJ9YOmelEGDmnx/KVx3CEmHuK/iw5Z0= 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:31:17 +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:31:17 +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 12/14] vfio-user: handle PCI BAR accesses Date: Tue, 24 May 2022 11:30:31 -0400 Message-Id: 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: 9335400c-9013-41ef-9744-08da3d9a71d9 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: dJVQkeFtolSMDeVxjTsvOa+CfsrcuDG1prT+SG3vsFV7QnUjEKBcfjJTqANGoIG5bUsUEAR8yc3kljCr8ELWtu0iEdMkHnI3o4n/FYPM1lL0/SJumTAnpoDmcXymFIbcEw1nWmNpetLyq1vBw0uzqaQ8aMSfQfbuFg4aqMpxq1DPT6nZWQMfWkHchFT+XInlYJTwKH2Yz29zbbfDRctSklPVsHYQRLzxwcbX/v6H04QNuYNcd//igVrjwztbYLsxWhFU/htxn6NdEy/MqqKbPDEFoKZvhZKyEdTvhntIgOCrDAmUmf/bdbDE4FH/dS4U8DypNgfj4S8nIQAhUJlNoY3SW8fwXP8sbjPaK1hJ/BrZxjwdlqA7PCqtp/xixeXtNBIXBZ0s2M9LlTJRb+g1nU/DEpvMGhCN5s3+UGNGfrYsWMP/vioTv2sswk9DgLG/Ojhi5fes5ObFaXqDXutQ9y1NIsYP5+H9RjUsHyH6LPbZaLTBazD9XOhnfrp9Bpa8W+bFofh/pvFa6cWOu3D6+Dhp7cQOw3zEVBES/Lqksp1sh+e4dUdq13yxXVmapEgmA0ivlORWtx6WPU7HJ5GWnZbDnBXhcYYvLXfEgIJmuQeTlx33/U6imDt3pB8f0mz1p4dCVmAXCvc2oryFpJz+4R3ctYEx2A+KziDSR2FsQLvzZhyCTtgJYV0H/6lpcr2s+G8LQ0Cdq3OgnKJ56dOO8g== 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)(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: 1JJj7SOGX2nHCmZgL7SfrM47wuxxLEtbc00kGnnOsHVmNN3JcvcyxKMWB+uLFWo+ZP7fjc9ufsnGoTfgzp+wjwy0kkLztxmNUA5kQmjZCzslyeWORl3j9SCy+pTFggAnLyWU6AS2p1Cbvsx53HZkxnvADsOvRYkRJTAKPeMDOwxsIcUl6/yoIJOl4X3k+xn5p6cdaD6pd81EWN/mkkYEXuunWV1mg+50Zws2gJje+Cf0riVYqY8zHFoo89NjpZXbQxpvDPeSjC+kia826DNkieRgwfnluImnMCUlWYrYXnpD83PaBaAg+OqEHlWCiYSoaVPunUS4NMAymuC947hLWxOofIOxN2tcr1E0ri3M2uCaqYeb3qp7FyKskr96qKgRENkQds2SWZaqrfjkf5ZybUEfNnd5f9eSI6dY/UsW5ur5mwCifPtIijFxPcrZ0qw79mBFHbb4Xu1oxSimHcAzq/sVCe058k4gnodybBllas1JtEsJmPAtQFHlXUXzCooHQI6dZy3yj3Iw0Rv8sWsLBweSxgG433ODeqKx/ZIrCSoklO5YbE02Nsttr5yez77G3qBxxpZ87tAIOpGjftmC7riK9pfAgfT7dxy757MsJzJYIULdHRCLh1NMIEM0ZtjuqnrffTGjFec0svQ8cxT1dJ0/I7sMs0xRQA0e/vJcpAOfeHwi+reu5hSKs2kJ7pSlUYr6dtRuKKMhyEdsAVWrqHS1+bf7n6xE9jPA3V46gtEnE2a3JA+ouWE7VuCVEujOpFr2rmwjjoWCgWtNenXddHC6o4D+QFd1TapCt9I6mhrLrYtXdoE43ar6mv1bIHDQzIG+V6vC+9+SOi5yCo3fnUZu+A257ARJ2BmzKtWToG3Ij9Vv0ooTVSXMWss6Q4pBwrd63iomW+1nDMipPoi2c3Wz0+F61EmvK8YraduNBsBX6qYquBqD/SBko3pKm4tMbhaAYIcbL54cb7OxgukKAnDVby6dFVRwl7/k40oLTzV3ZrY9J8MeUBEDf5F/w/HPu05M4N4IxvsVGVk7DpTwIngQlGpnPSOLYigpQjAerykx8Fs5Mgc3fgR8R2nroAE/jKaZlLsRbF/PZ3ZJAvPcLvDlt3MK7mU18OF7cQZCIsYrIOplPBhtoQxaI5q2a6mocvIrPTe3x2XizFyV91Qdqxu5YrALsaa3q2rAH0FdPd7c/lzP+bP9+253r2j7RQmAw/gJo0FK13EHlpzUPPtz19s2xA2vklkTL7dL1Fzbe9cgoataf7UoXjuZc5RCRL97RtxnpxXh8JD1lc76lFZ515KiGg35diRS4Fkj/JwFAuyF3kXpWIOGvRYlfR3pYgTKW+4r+4MVpIG1KKnVGHflnse/ICc0bn9pYyrzxVnwCS6fpAb/nsodMs6TCIOxac0ilLYkOclqRJzBhg05ikNUT7ntFCs+78Cphb/PFP3FsSFBsdiWEsZMteblURB2c3cjd3rzOm389czx1krtznueXnnQ3bjT6w/72lq6VmyVY9/DrJ40U59H9CucO4NM457TAszxc8c+nFojR88QF+RtfTJcDqcOigp9TN1cEfLOrAUCEDmIIhya5VLVi96T+fx+JNV9EZF7EU4DGzNW4GdykIZQjXlpnNNSKVS/ujyuJjxKUdCfhU7Eht2zku9Cb/G8wlv1jPCj6I4D4kKzoA0kTUslOxlC3Bfn46fj5bIdrk+zKZPHeMrSLWWdj0YDajaWwkXHS65igYzjDQsL6bS9BQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9335400c-9013-41ef-9744-08da3d9a71d9 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:31:17.3345 (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: UsjPY+KGxCZheHpP5YMw2KPU7XBxFOJfNbKwNoBJlKBQCMGZDsViTFiqXXTrCHJ8AJoCFijUkZVXUrRd2WWPDA== 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 mlxlogscore=999 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-GUID: 4yGIGeY6Al0NH9gWrUVPBfHuz1PyCVWd X-Proofpoint-ORIG-GUID: 4yGIGeY6Al0NH9gWrUVPBfHuz1PyCVWd 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Determine the BARs used by the PCI device and register handlers to manage the access to the same. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/exec/memory.h | 3 + hw/remote/vfio-user-obj.c | 190 ++++++++++++++++++++++++++++++++ softmmu/physmem.c | 4 +- tests/qtest/fuzz/generic_fuzz.c | 9 +- hw/remote/trace-events | 3 + 5 files changed, 203 insertions(+), 6 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index f1c19451bc..a6a0f4d8ad 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2810,6 +2810,9 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr, const void *buf, hwaddr len); +int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr); +bool prepare_mmio_access(MemoryRegion *mr); + static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { if (is_write) { diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 8d208f1294..ee28a93782 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -52,6 +52,7 @@ #include "hw/qdev-core.h" #include "hw/pci/pci.h" #include "qemu/timer.h" +#include "exec/memory.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -332,6 +333,193 @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info) trace_vfu_dma_unregister((uint64_t)info->iova.iov_base); } +static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, + hwaddr size, const bool is_write) +{ + uint8_t *ptr = buf; + bool release_lock = false; + uint8_t *ram_ptr = NULL; + MemTxResult result; + int access_size; + uint64_t val; + + if (memory_access_is_direct(mr, is_write)) { + /** + * Some devices expose a PCI expansion ROM, which could be buffer + * based as compared to other regions which are primarily based on + * MemoryRegionOps. memory_region_find() would already check + * for buffer overflow, we don't need to repeat it here. + */ + ram_ptr = memory_region_get_ram_ptr(mr); + + if (is_write) { + memcpy((ram_ptr + offset), buf, size); + } else { + memcpy(buf, (ram_ptr + offset), size); + } + + return 0; + } + + while (size) { + /** + * The read/write logic used below is similar to the ones in + * flatview_read/write_continue() + */ + release_lock = prepare_mmio_access(mr); + + access_size = memory_access_size(mr, size, offset); + + if (is_write) { + val = ldn_he_p(ptr, access_size); + + result = memory_region_dispatch_write(mr, offset, val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + } else { + result = memory_region_dispatch_read(mr, offset, &val, + size_memop(access_size), + MEMTXATTRS_UNSPECIFIED); + + stn_he_p(ptr, access_size, val); + } + + if (release_lock) { + qemu_mutex_unlock_iothread(); + release_lock = false; + } + + if (result != MEMTX_OK) { + return -1; + } + + size -= access_size; + ptr += access_size; + offset += access_size; + } + + return 0; +} + +static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar, + hwaddr bar_offset, char * const buf, + hwaddr len, const bool is_write) +{ + MemoryRegionSection section = { 0 }; + uint8_t *ptr = (uint8_t *)buf; + MemoryRegion *section_mr = NULL; + uint64_t section_size; + hwaddr section_offset; + hwaddr size = 0; + + while (len) { + section = memory_region_find(pci_dev->io_regions[pci_bar].memory, + bar_offset, len); + + if (!section.mr) { + warn_report("vfu: invalid address 0x%"PRIx64"", bar_offset); + return size; + } + + section_mr = section.mr; + section_offset = section.offset_within_region; + section_size = int128_get64(section.size); + + if (is_write && section_mr->readonly) { + warn_report("vfu: attempting to write to readonly region in " + "bar %d - [0x%"PRIx64" - 0x%"PRIx64"]", + pci_bar, bar_offset, + (bar_offset + section_size)); + memory_region_unref(section_mr); + return size; + } + + if (vfu_object_mr_rw(section_mr, ptr, section_offset, + section_size, is_write)) { + warn_report("vfu: failed to %s " + "[0x%"PRIx64" - 0x%"PRIx64"] in bar %d", + is_write ? "write to" : "read from", bar_offset, + (bar_offset + section_size), pci_bar); + memory_region_unref(section_mr); + return size; + } + + size += section_size; + bar_offset += section_size; + ptr += section_size; + len -= section_size; + + memory_region_unref(section_mr); + } + + return size; +} + +/** + * VFU_OBJECT_BAR_HANDLER - macro for defining handlers for PCI BARs. + * + * To create handler for BAR number 2, VFU_OBJECT_BAR_HANDLER(2) would + * define vfu_object_bar2_handler + */ +#define VFU_OBJECT_BAR_HANDLER(BAR_NO) \ + static ssize_t vfu_object_bar##BAR_NO##_handler(vfu_ctx_t *vfu_ctx, \ + char * const buf, size_t count, \ + loff_t offset, const bool is_write) \ + { \ + VfuObject *o = vfu_get_private(vfu_ctx); \ + PCIDevice *pci_dev = o->pci_dev; \ + \ + return vfu_object_bar_rw(pci_dev, BAR_NO, offset, \ + buf, count, is_write); \ + } \ + +VFU_OBJECT_BAR_HANDLER(0) +VFU_OBJECT_BAR_HANDLER(1) +VFU_OBJECT_BAR_HANDLER(2) +VFU_OBJECT_BAR_HANDLER(3) +VFU_OBJECT_BAR_HANDLER(4) +VFU_OBJECT_BAR_HANDLER(5) +VFU_OBJECT_BAR_HANDLER(6) + +static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = { + &vfu_object_bar0_handler, + &vfu_object_bar1_handler, + &vfu_object_bar2_handler, + &vfu_object_bar3_handler, + &vfu_object_bar4_handler, + &vfu_object_bar5_handler, + &vfu_object_bar6_handler, +}; + +/** + * vfu_object_register_bars - Identify active BAR regions of pdev and setup + * callbacks to handle read/write accesses + */ +static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) +{ + int flags = VFU_REGION_FLAG_RW; + int i; + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + if (!pdev->io_regions[i].size) { + continue; + } + + if ((i == VFU_PCI_DEV_ROM_REGION_IDX) || + pdev->io_regions[i].memory->readonly) { + flags &= ~VFU_REGION_FLAG_WRITE; + } + + vfu_setup_region(vfu_ctx, VFU_PCI_DEV_BAR0_REGION_IDX + i, + (size_t)pdev->io_regions[i].size, + vfu_object_bar_handlers[i], + flags, NULL, 0, -1, 0); + + trace_vfu_bar_register(i, pdev->io_regions[i].addr, + pdev->io_regions[i].size); + } +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -442,6 +630,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 657841eed0..fb16be57a6 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2719,7 +2719,7 @@ void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr size) invalidate_and_set_dirty(mr, addr, size); } -static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) +int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max = mr->ops->valid.max_access_size; @@ -2746,7 +2746,7 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) return l; } -static bool prepare_mmio_access(MemoryRegion *mr) +bool prepare_mmio_access(MemoryRegion *mr) { bool release_lock = false; diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c index 25df19fd5a..447ffe8178 100644 --- a/tests/qtest/fuzz/generic_fuzz.c +++ b/tests/qtest/fuzz/generic_fuzz.c @@ -144,7 +144,7 @@ static void *pattern_alloc(pattern p, size_t len) return buf; } -static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) +static int fuzz_memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max = mr->ops->valid.max_access_size; @@ -242,11 +242,12 @@ void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr) /* * If mr1 isn't RAM, address_space_translate doesn't update l. Use - * memory_access_size to identify the number of bytes that it is safe - * to write without accidentally writing to another MemoryRegion. + * fuzz_memory_access_size to identify the number of bytes that it + * is safe to write without accidentally writing to another + * MemoryRegion. */ if (!memory_region_is_ram(mr1)) { - l = memory_access_size(mr1, l, addr1); + l = fuzz_memory_access_size(mr1, l, addr1); } if (memory_region_is_ram(mr1) || memory_region_is_romd(mr1) || diff --git a/hw/remote/trace-events b/hw/remote/trace-events index f945c7e33b..847d50d88f 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -9,3 +9,6 @@ vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", %zu bytes" vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" +vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" +vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" +vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" From patchwork Tue May 24 15:30:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860349 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 C1F22C433F5 for ; Tue, 24 May 2022 16:13:34 +0000 (UTC) Received: from localhost ([::1]:39442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntXA5-0001IS-Rt for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 12:13:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVQ-0008JT-CK for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:36 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:5482) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVN-0003ZU-HL for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:32 -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 24OFJ4l9018983; Tue, 24 May 2022 15:31:24 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=oA3buILgr1opUPXBGKpMa2LPGfj42Ra/K46zYSugDbM=; b=RhsFS8wwVRpssQdantQxdtgvN9TJg6kgKzCcGor3Tw18rW3n8hnKDTv+yTbOjjVT7Vu3 hbASdXAA09jGOgZUWBS26LrQLUgxJaOMHBZw8f+Jpc5IA6tCG00Fkl5semkZT+Ms6vh0 57BTlUpUR2bJ42zv86CJHxrZApDGdPkhRfKvwxNHRa33udimSMSlKDdaWif0fPRhkbYP biGYWPe67rLcYMSnwj/3SNTvCwak9KmR6LVhymA+fUqUJji/dODYwIw55t0LGUFh9ZnV yv6hVLc8vvyMg4Qt2Av5Tv8hVIf4qnFD5j4mC4NPxfNiykpDFIqtVPfTkiui/ZcQWoR+ yA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6pp06scc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:23 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFGNNJ026316; Tue, 24 May 2022 15:31:22 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2043.outbound.protection.outlook.com [104.47.73.43]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph8drdv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EpP88F3nz1C4KqM3DL4rggpLPD66vl7feXPZl6TYAt+OgauhuvQJVlIhEdJlqapjdpc9jdhKjT4xVavd7awBgxXc/WiCgI8SHwoAU0tUTG+pa2lWLjBYKsDhYKFqVc6JNAsXs02RrZDQfSJI/POZtNXqWrVBZ8FHh89gBleDmJSV9TfU00aaoJA5SYWZUOkhsfFd0dyH3Tr7u093SISNe4gIZlPh8ake9YdcDZv1DkEDA9vjsM2GMraYJi8qV8TodKDdNUR1il/TeUP8cy0bcCTRUxCqx62FbT4lpoubKNSyHzCm0BAzSHP4UhjmIuZVCk0l93d/vk5JqMoxAkzS9w== 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=oA3buILgr1opUPXBGKpMa2LPGfj42Ra/K46zYSugDbM=; b=lohEj2oXdtjCOTZTewT3mPbB/Vb0jlijF9c7/AZmWyDvGyvFVf5E8kqpucX+MaElAgsqOBhZrxPLZeiV3xaJyp8jw6qkYariU0ImbsOGItDor3hBuBDCwKlPRWuL0AkERG0GWEFUgqVHFpy8fN1Footd6QYlhQPz4pAgaeuiecrwRq5YcdEELK65/oF2dQF1JFIZuF4Ba14rz0geXLHT1WPZv6/4oKRGSmFute9SgYaD59E/2ACUrnkjug1QAVXufVXc4Wm50Jr//F8M61NpqEdMxVz8RpwV9UvL6TC1m8+iRsIewpNPVhlDnqAiKkJEplbq+O8MpJwceZ4u5sigUw== 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=oA3buILgr1opUPXBGKpMa2LPGfj42Ra/K46zYSugDbM=; b=js4OcV4zHEHvDM30blVup6+7oqVdgb6+CdAtQ+r5oHKUfbl1EamXA9dwEXh31HQ/JkATWWePATZNwWf9qX0hM5mQju0jRUKRO5Wc86jZ07MHPB99oKqkUJRf3iw5iRmkTj8lhIpit0wL8tpM+VmfOU5wL0Ajw5Za+FaKr5qV8Q8= 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:31:20 +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:31:20 +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 13/14] vfio-user: handle device interrupts Date: Tue, 24 May 2022 11:30:32 -0400 Message-Id: <2a492c16e0464f70f7be1fd9c04172f4f18d14ca.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: 86a064a3-157e-4def-68b9-08da3d9a7378 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: 2ILZiBBPIMUG1bfbOe73cCF77WXdFUWbQYebJp1k6lk6HdLyw7YbIdKCUolepOxVWqRqJ/bXLVAKQhTYmYohcJIpaZQri72jbC+S1+41isfH9O3DeU78hcVInTys7GvaQKoV3Vg7pEEPvPYmMsgkR6O9hoQWFDXvTIQvEbAk86bcGQPrd4bsTtKNgmrZ8HW74aEvxI9gcVmkCYwi9RCvvBKU5b1Cb96ozrNeP39bUJyJLR69upO4a83EqzVZbCTcbwigxcJzZLwdcmuBYhT9NQCdsKdDrh0Wbd9E1GP6STvNvqbeFBQe5m21SIL8Viazwyt8s9qUS66+mDRumXtgbtem51tf/Ls4L/XLe+6v3p3Mf/pW3n0FrNISxd2xPCwNd3S1F8cGZFGqIrWi0fx7PfLPs6ZCBurkaxZSx8DhQsgUI4SDT99IigEszyZsL6nKjViMRb9GktusgZs4LqSw/qdzwWj40xyQQf8jIxvgifPibhAA86aGvgnozuPoKmathA99Zmz2fLJlnumblmR5BJgPd0e0td56mGboIGY+y2iVfOUGiF3V1LfAYrY2eKEJ9Mg9ldMLC7bIQpd6dIKXFa3IKSa5t5ByTORXRb5VZ8is4tj+JJ69E0/IFD4SW1pbryUPnxuZJkWb5jQdkl7IvnsaT0S9cDma7pYTT2WD8GbutkVj4HLYr3SiJpZ3VRiVJZFqccOLQdRvDu2HU2hRxA== 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: Yn/SGMVJ3II3PPZJcDPg3Bst9tmkpJXlYPl7U0FF2P16t3zAkAXy3Ke+WEG+eNz2AMG7HLCGQu9JNc3vsVeEX3/I4zDBYFiK8oAJ+I01le3SdpVjKiWJsmTg251IyqKbiI5G0Z9UL0p/d4C/cFVoq+HOmsfw0b0L2TXm/SLsk2UwPg9bZvndfqtmIxeG5Yq9+04o2xmPpSsGVNothwa6+VruDgxDvbekMnoSinqRt+e4/mceSSz1y1CiE8ADRDU7BE636e9v3eOzQSzAyVbFubBaSWlGvnYCUiL63FWKJ8JY6u/AN1y2jQwoLrsUqFv8Z0i4vNfyVJp/11P1Bs2SxinhSD3iw6rRJ7uPvXx4noQRJm0TWmx/zoZrS2IbQLifC1BsuEOKdIx5cTYWjsJCpjC+KD529vPG455XWAbg+jLJQUEIp8S/p3Lh/z8CmM4zJJ+dJvwnwoBMR5G0aVFVIXUJ9A8vKS2jCxVFsq5RqgQ9FFWvbGtCeCRff1EDR2uUbWoH39Uf0HyeOuyLcdmT08KiQcdMFPPudSNxBn2NnL3sRd7umib02zZAiQFLrHmXHqrfdWG5xvNRYXxEXqzDwP0ks7+/tUVvEnmn25xxyx6yCmq3e0I9uaYv5bJoRcUyaRqJ0lyb/Sdq5twC09OfOY0hL5Us9B6zLNSzk2lwFus5E3TsV9aqzrEboPd9L/3a+C/NsI5WSZzu3kLzgvZE1YXyk7m+F2sYXYGThpU6H3++60Bp0wC4k03A3T6qGy4DfNaVQEB9WIVFDr+X+OaJd5VurkH48PiozoE2w+XvKj9hCa1oAW7S2xKUqZc705RLh5rW2K2zI6R1mUgeOBv40ZB6rIwkIAgRoVKqnFBkXfleNpz6eBoPsN/C7Z025H/jDgxJUxrZMIpwHyL1J8gviEiGQEyUFJ8dgo5ZG0QSgbH/apn6KWEFIBM3aYb+doBdknu+uLAyA4QKFWot2IrCL2MjprUNTko8CQsIiwyo7rnEDkP3iNb3wxo5IbAWVx/V4+O+T4EwJ4D68wHqzXIgaNeM2dW/Ngsf6xSi7zLqQXwMK/8uDfUPZqFfboUgYZPRBce9cPTSGz250Ab4kuxuUPGvI12lJy8A84P+17gPw0CBwp4Rw1hEwb4vxD/LelMlF6EjdtYeizYKEd5WQXJykZDmh2YzG/Akne+9r/OJca+si/WrnVJmAjLXYuhn3S4Fx1qLv8X4Ll5zCFunqmJ0OjC5NdYOQEIUeWUBx2dW+IBS9mzTzaz6eNlglr/CgteoeCgWBTUe++kFZjxD9lZDPVsTWo2KW6mRg5yeUU8+DXJiuFqqj1vll6919u8bLl0NxG9kxojN9EWTAK3vKb0pu8t7JCmwDw4wGSmvfDc1/CoApGO0gDj6s3gsyfJg93QHuLTYMaPoKEkjJ23FuVe65yA7yOcEyjl3qsdojcI22coBdEhkBbGt7wE8K78+jtxHlPWTbBTrnU63YRemGB8LXPFzz9jQwpsI3J3VviBl5o7/ut03n2wEVAGW3bOeGUIegTDLBJvIPOPqjUthOLFTUvAFxgpQI/WzVgKKHqRSa2pJU2j5rC8QQQGM3UipR0KX3sv+51TjcdEK6ZvfvkiiN29CwrKnGubMfldq2eFiZNsG271bK8WLdZptNAYM+lJKuWDucfOjq4I38hDu1AuMhAK0miFozUz5nYj2eRXhNp9162v3IlsUkTd6SUfTJgqH21HrT1ZGQmQk2HUjbqlpug== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86a064a3-157e-4def-68b9-08da3d9a7378 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:31:20.0687 (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: xtsraG8Hx25jt8L+h/j7YwsiF4bYRpW46hVwDeYRZu483BQk/4D93IPJOVp5KZHHhfIOYc96HpWm65q4Vd8Btg== 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 mlxlogscore=999 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: 7lttbeJv89BJa6CbBFP-zEeDsF2wLgap X-Proofpoint-GUID: 7lttbeJv89BJa6CbBFP-zEeDsF2wLgap 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Forward remote device's interrupts to the guest Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi Signed-off-by: Elena Ufimtseva > Signed-off-by: John G Johnson > Signed-off-by: Jagannathan Raman > --- include/hw/pci/pci.h | 13 ++++ include/hw/remote/vfio-user-obj.h | 6 ++ hw/pci/msi.c | 16 ++-- hw/pci/msix.c | 10 ++- hw/pci/pci.c | 13 ++++ hw/remote/machine.c | 14 +++- hw/remote/vfio-user-obj.c | 123 ++++++++++++++++++++++++++++++ stubs/vfio-user-obj.c | 6 ++ MAINTAINERS | 1 + hw/remote/trace-events | 1 + stubs/meson.build | 1 + 11 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 include/hw/remote/vfio-user-obj.h create mode 100644 stubs/vfio-user-obj.c diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 44dacfa224..b54b6ef88f 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -16,6 +16,7 @@ extern bool pci_available; #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) #define PCI_BUILD_BDF(bus, devfn) ((bus << 8) | (devfn)) +#define PCI_BDF_TO_DEVFN(x) ((x) & 0xff) #define PCI_BUS_MAX 256 #define PCI_DEVFN_MAX 256 #define PCI_SLOT_MAX 32 @@ -127,6 +128,10 @@ typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type); typedef void PCIUnregisterFunc(PCIDevice *pci_dev); +typedef void MSITriggerFunc(PCIDevice *dev, MSIMessage msg); +typedef MSIMessage MSIPrepareMessageFunc(PCIDevice *dev, unsigned vector); +typedef MSIMessage MSIxPrepareMessageFunc(PCIDevice *dev, unsigned vector); + typedef struct PCIIORegion { pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ #define PCI_BAR_UNMAPPED (~(pcibus_t)0) @@ -329,6 +334,14 @@ struct PCIDevice { /* Space to store MSIX table & pending bit array */ uint8_t *msix_table; uint8_t *msix_pba; + + /* May be used by INTx or MSI during interrupt notification */ + void *irq_opaque; + + MSITriggerFunc *msi_trigger; + MSIPrepareMessageFunc *msi_prepare_message; + MSIxPrepareMessageFunc *msix_prepare_message; + /* MemoryRegion container for msix exclusive BAR setup */ MemoryRegion msix_exclusive_bar; /* Memory Regions for MSIX table and pending bit entries. */ diff --git a/include/hw/remote/vfio-user-obj.h b/include/hw/remote/vfio-user-obj.h new file mode 100644 index 0000000000..87ab78b875 --- /dev/null +++ b/include/hw/remote/vfio-user-obj.h @@ -0,0 +1,6 @@ +#ifndef VFIO_USER_OBJ_H +#define VFIO_USER_OBJ_H + +void vfu_object_set_bus_irq(PCIBus *pci_bus); + +#endif diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 47d2b0f33c..d556e17a09 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -134,7 +134,7 @@ void msi_set_message(PCIDevice *dev, MSIMessage msg) pci_set_word(dev->config + msi_data_off(dev, msi64bit), msg.data); } -MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +static MSIMessage msi_prepare_message(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; @@ -159,6 +159,11 @@ MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) return msg; } +MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +{ + return dev->msi_prepare_message(dev, vector); +} + bool msi_enabled(const PCIDevice *dev) { return msi_present(dev) && @@ -241,6 +246,8 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, 0xffffffff >> (PCI_MSI_VECTORS_MAX - nr_vectors)); } + dev->msi_prepare_message = msi_prepare_message; + return 0; } @@ -256,6 +263,7 @@ void msi_uninit(struct PCIDevice *dev) cap_size = msi_cap_sizeof(flags); pci_del_capability(dev, PCI_CAP_ID_MSI, cap_size); dev->cap_present &= ~QEMU_PCI_CAP_MSI; + dev->msi_prepare_message = NULL; MSI_DEV_PRINTF(dev, "uninit\n"); } @@ -334,11 +342,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector) void msi_send_message(PCIDevice *dev, MSIMessage msg) { - MemTxAttrs attrs = {}; - - attrs.requester_id = pci_requester_id(dev); - address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, - attrs, NULL); + dev->msi_trigger(dev, msg); } /* Normally called by pci_default_write_config(). */ diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331cd0b..6f85192d6f 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -31,7 +31,7 @@ #define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8) #define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8) -MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) +static MSIMessage msix_prepare_message(PCIDevice *dev, unsigned vector) { uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE; MSIMessage msg; @@ -41,6 +41,11 @@ MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) return msg; } +MSIMessage msix_get_message(PCIDevice *dev, unsigned vector) +{ + return dev->msix_prepare_message(dev, vector); +} + /* * Special API for POWER to configure the vectors through * a side channel. Should never be used by devices. @@ -344,6 +349,8 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, "msix-pba", pba_size); memory_region_add_subregion(pba_bar, pba_offset, &dev->msix_pba_mmio); + dev->msix_prepare_message = msix_prepare_message; + return 0; } @@ -429,6 +436,7 @@ void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar, MemoryRegion *pba_bar) g_free(dev->msix_entry_used); dev->msix_entry_used = NULL; dev->cap_present &= ~QEMU_PCI_CAP_MSIX; + dev->msix_prepare_message = NULL; } void msix_uninit_exclusive_bar(PCIDevice *dev) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a9b37f8000..435f84393c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -317,6 +317,15 @@ void pci_device_deassert_intx(PCIDevice *dev) } } +static void pci_msi_trigger(PCIDevice *dev, MSIMessage msg) +{ + MemTxAttrs attrs = {}; + + attrs.requester_id = pci_requester_id(dev); + address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, + attrs, NULL); +} + static void pci_reset_regions(PCIDevice *dev) { int r; @@ -1212,6 +1221,8 @@ static void pci_qdev_unrealize(DeviceState *dev) pci_device_deassert_intx(pci_dev); do_pci_unregister_device(pci_dev); + + pci_dev->msi_trigger = NULL; } void pci_register_bar(PCIDevice *pci_dev, int region_num, @@ -2251,6 +2262,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) } pci_set_power(pci_dev, true); + + pci_dev->msi_trigger = pci_msi_trigger; } PCIDevice *pci_new_multifunction(int devfn, bool multifunction, diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 645b54343d..75d550daae 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -23,6 +23,8 @@ #include "hw/remote/iommu.h" #include "hw/qdev-core.h" #include "hw/remote/iommu.h" +#include "hw/remote/vfio-user-obj.h" +#include "hw/pci/msi.h" static void remote_machine_init(MachineState *machine) { @@ -54,12 +56,16 @@ static void remote_machine_init(MachineState *machine) if (s->vfio_user) { remote_iommu_setup(pci_host->bus); - } - remote_iohub_init(&s->iohub); + msi_nonbroken = true; + + vfu_object_set_bus_irq(pci_host->bus); + } else { + remote_iohub_init(&s->iohub); - pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, - &s->iohub, REMOTE_IOHUB_NB_PIRQS); + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); + } qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index ee28a93782..eeb165a805 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -53,6 +53,9 @@ #include "hw/pci/pci.h" #include "qemu/timer.h" #include "exec/memory.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" +#include "hw/remote/vfio-user-obj.h" #define TYPE_VFU_OBJECT "x-vfio-user-server" OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT) @@ -96,6 +99,10 @@ struct VfuObject { Error *unplug_blocker; int vfu_poll_fd; + + MSITriggerFunc *default_msi_trigger; + MSIPrepareMessageFunc *default_msi_prepare_message; + MSIxPrepareMessageFunc *default_msix_prepare_message; }; static void vfu_object_init_ctx(VfuObject *o, Error **errp); @@ -520,6 +527,111 @@ static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev) } } +static int vfu_object_map_irq(PCIDevice *pci_dev, int intx) +{ + int pci_bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), + pci_dev->devfn); + + return pci_bdf; +} + +static void vfu_object_set_irq(void *opaque, int pirq, int level) +{ + PCIBus *pci_bus = opaque; + PCIDevice *pci_dev = NULL; + vfu_ctx_t *vfu_ctx = NULL; + int pci_bus_num, devfn; + + if (level) { + pci_bus_num = PCI_BUS_NUM(pirq); + devfn = PCI_BDF_TO_DEVFN(pirq); + + /* + * pci_find_device() performs at O(1) if the device is attached + * to the root PCI bus. Whereas, if the device is attached to a + * secondary PCI bus (such as when a root port is involved), + * finding the parent PCI bus could take O(n) + */ + pci_dev = pci_find_device(pci_bus, pci_bus_num, devfn); + + vfu_ctx = pci_dev->irq_opaque; + + g_assert(vfu_ctx); + + vfu_irq_trigger(vfu_ctx, 0); + } +} + +static MSIMessage vfu_object_msi_prepare_msg(PCIDevice *pci_dev, + unsigned int vector) +{ + MSIMessage msg; + + msg.address = 0; + msg.data = vector; + + return msg; +} + +static void vfu_object_msi_trigger(PCIDevice *pci_dev, MSIMessage msg) +{ + vfu_ctx_t *vfu_ctx = pci_dev->irq_opaque; + + vfu_irq_trigger(vfu_ctx, msg.data); +} + +static void vfu_object_setup_msi_cbs(VfuObject *o) +{ + o->default_msi_trigger = o->pci_dev->msi_trigger; + o->default_msi_prepare_message = o->pci_dev->msi_prepare_message; + o->default_msix_prepare_message = o->pci_dev->msix_prepare_message; + + o->pci_dev->msi_trigger = vfu_object_msi_trigger; + o->pci_dev->msi_prepare_message = vfu_object_msi_prepare_msg; + o->pci_dev->msix_prepare_message = vfu_object_msi_prepare_msg; +} + +static void vfu_object_restore_msi_cbs(VfuObject *o) +{ + o->pci_dev->msi_trigger = o->default_msi_trigger; + o->pci_dev->msi_prepare_message = o->default_msi_prepare_message; + o->pci_dev->msix_prepare_message = o->default_msix_prepare_message; +} + +static int vfu_object_setup_irqs(VfuObject *o, PCIDevice *pci_dev) +{ + vfu_ctx_t *vfu_ctx = o->vfu_ctx; + int ret; + + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_INTX_IRQ, 1); + if (ret < 0) { + return ret; + } + + if (msix_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSIX_IRQ, + msix_nr_vectors_allocated(pci_dev)); + } else if (msi_nr_vectors_allocated(pci_dev)) { + ret = vfu_setup_device_nr_irqs(vfu_ctx, VFU_DEV_MSI_IRQ, + msi_nr_vectors_allocated(pci_dev)); + } + + if (ret < 0) { + return ret; + } + + vfu_object_setup_msi_cbs(o); + + pci_dev->irq_opaque = vfu_ctx; + + return 0; +} + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ + pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus, 1); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -632,6 +744,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) vfu_object_register_bars(o->vfu_ctx, o->pci_dev); + ret = vfu_object_setup_irqs(o, o->pci_dev); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup interrupts for %s", + o->device); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", @@ -657,6 +776,8 @@ fail: o->unplug_blocker = NULL; } if (o->pci_dev) { + vfu_object_restore_msi_cbs(o); + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } @@ -716,6 +837,8 @@ static void vfu_object_finalize(Object *obj) } if (o->pci_dev) { + vfu_object_restore_msi_cbs(o); + o->pci_dev->irq_opaque = NULL; object_unref(OBJECT(o->pci_dev)); o->pci_dev = NULL; } diff --git a/stubs/vfio-user-obj.c b/stubs/vfio-user-obj.c new file mode 100644 index 0000000000..79100d768e --- /dev/null +++ b/stubs/vfio-user-obj.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/remote/vfio-user-obj.h" + +void vfu_object_set_bus_irq(PCIBus *pci_bus) +{ +} diff --git a/MAINTAINERS b/MAINTAINERS index 9d8695b68d..844ed75834 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3604,6 +3604,7 @@ F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: subprojects/libvfio-user F: hw/remote/vfio-user-obj.c +F: include/hw/remote/vfio-user-obj.h F: hw/remote/iommu.c F: include/hw/remote/iommu.h diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 847d50d88f..c167b3c7a5 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -12,3 +12,4 @@ vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64"" vfu_bar_register(int i, uint64_t addr, uint64_t size) "vfu: BAR %d: addr 0x%"PRIx64" size 0x%"PRIx64"" vfu_bar_rw_enter(const char *op, uint64_t addr) "vfu: %s request for BAR address 0x%"PRIx64"" vfu_bar_rw_exit(const char *op, uint64_t addr) "vfu: Finished %s of BAR address 0x%"PRIx64"" +vfu_interrupt(int pirq) "vfu: sending interrupt to device - PIRQ %d" diff --git a/stubs/meson.build b/stubs/meson.build index 6f80fec761..d8f3fd5c44 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -60,3 +60,4 @@ if have_system else stub_ss.add(files('qdev.c')) endif +stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) From patchwork Tue May 24 15:30:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12860329 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 694F9C433EF for ; Tue, 24 May 2022 15:46:37 +0000 (UTC) Received: from localhost ([::1]:50530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntWk0-0001pl-GU for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 11:46:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVP-0008JQ-NN for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:36 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:5450) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntWVM-0003ZP-GE for qemu-devel@nongnu.org; Tue, 24 May 2022 11:31:31 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24OFK8Mh018480; Tue, 24 May 2022 15:31:26 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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=TvzdtBJDcjTurNjzEr+mWbyhTwdThGjpTnc2Gd+SlLg=; b=OdIglgS91t8t2hn8s3uyS3omtlYTMWg638oJ7t3rxavTvhtDu8cGaDTz+7jcJtnxNRIb ZphmLeZKguePZQmWBrS9t6paJ4kcC3NyQwpGwqIKexRYGL7QDuEio9TRImYcZx5Fo46C lzQfbADkxDuJVMQQQbfMJCgXm+v+QMlE1S3zkyrcWaXf+66sd2VoDP713idjqi22wtdf E6J86HA5YTzXh9IN9mHTr5vcqEEnmAmxNe7C5dXpwaId3SBz6Ti5oehQSG6ngWCA9/Xt 7f+SijwpPcC57DHyxktQ6sQrWth9/bJaWAfkpu8ZB8/UW1JvYfEflnMiFi49ZTTTAWKa wA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3g6qps6tkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:25 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24OFSIb5025577; Tue, 24 May 2022 15:31:25 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2046.outbound.protection.outlook.com [104.47.73.46]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3g6ph8drft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 May 2022 15:31:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ip/g5vNRwjYUDecvHzjRbxsqxekovxNS4x2tnc+qm0NsaGTVmLHSW8wEGWxKZAX/fKshv5uS9Rkm4HpaeBgjEbtrVvpQOg6eYlLx/P5HqhVjGhHpiqw96/cdXiYDdW1RielRxgGjdB7OPxNQwAT1NfgWi0pZEguhYoraPO8IruTt34pYPq5sprj1DlV1aPt6lGybA4U9CK2iF0pEPm20QIqKBgHJ8C+hCLV4Pll2jc4m32FvGEvmAUQPn+GbDPYZzlcg/zZqO4yUMdzcjvVBoKcZW/SY5syq1KrmK9e+IOYFk8jk2QWQh6b7bHompwzpkdiGVMi1CHzzN8MBUJahDw== 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=TvzdtBJDcjTurNjzEr+mWbyhTwdThGjpTnc2Gd+SlLg=; b=hZFLIod2IIIeJ9pCP5EY4rDvyTcG++j1wf54ynC3sSTtZ7VmgQMDBdTE5JvonXX7+mdfCQRO1GgPe9sZX7uQpQBwMSYGh5/frd6ahhUZfzgAvxkgqj7ZmEY1GS+MGyN1qhcvtx6rzq4c3m4IYHMS2KKheTR6n1V2YIbVjKPyHksjOhpDJVcqmjECsbIEdW03O6jttjlzMdhjHa3GuvuVEaZH62o/JM9J+zWFk247m2Bb8OSRMWJrhlWY3Izc0hp1NoyRa5uNhrl0tC0DmFmGLkLbXZfn3pBHu3B3WWK9cySz+rAE/dlOzwYXPzw1keF7Z7Ba9dQTSGKCfHyE+CzkFg== 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=TvzdtBJDcjTurNjzEr+mWbyhTwdThGjpTnc2Gd+SlLg=; b=PLbEqo2kdknXzc/TJQvwvS8cy0Rh/L0Olcwb44TXJ82XMgMcu764E3EV1Nv8a75yIgeapRo7cN2oIdAfyyigDEVtS7hdzwps7ECnWE1Gb9pCL5WuL5vxrEEVnq7DF3IwfGcezwOlQ3yE2IrHtbzgVX0aNgmJrd4+0B/+ieQtiJQ= 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:31:23 +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:31:23 +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 14/14] vfio-user: handle reset of remote device Date: Tue, 24 May 2022 11:30:33 -0400 Message-Id: <3f087d0e6eb70ca0ae2454b9f219b1c532290d1d.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: a20a1d08-e587-4850-75a6-08da3d9a7512 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: jIlgoCFLc6E5pLBdyOomalqvIhVgHNR0TuI376p/RpZuI5baYb+lRPdSz7Sz93zUFnRCA9D3XTyHXnjWN0ZXALB6sbHWMB8w4gLxTeGFHCw3VQtwewwolgvlbVH/x5WRAWYGsNoym9ws5WYUWwBnlfMBrCWxDMDKgvKO9xXVgCF1IioZE2cq27PcXKZ4bgPsvUxQ/ZcQksZHMkLPhnjB+XXn12w/+5g1rbYwydlHNoCOMrsFjeGntgV+hwFIUVlQSy/TT1zPtkZc6VbRC3LOPTNx3S21ejugHLQqdLpqmK4BPW+VBQC2ivxsKKnxbngx+OkppBAiqD7amDauZU0grjUFsVRvHc1G9VOILmPLRg6dFliW8cM2GHzH11nczVGgWOyD/QfCh49kQxvsUYlR/Q6TgDsY2k8Imve/NbMIw9kuVMPcW+nP6qROoP5fyipfpyyUHTRmLO8/8BVpiyx4mqwJt7ijPMtzwyeINUi+sBY42WMCgN1bZtkLJaoRs/LMb0R2UmJ4VfG7HUgfZwHtcFMBSqna8kLC2T3Num63Zw7zs8DYtjSpYoQ6VmLffP2qVJ+ZsyRtTUCrkFl0LPQxZ3vMjSSs6oDSTfaYxJnsLjrZ8rIRbuEGb1T6yUSO0KvMHnoE014cgumKE+cVydpBUpQTjOGyis+uNRauNR67sJmlpvoqfH0jWejJuOFlzMqeURyNVoq33nIR8iAv6EoCjQ== 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)(86362001)(508600001)(36756003)(4326008)(66946007)(2616005)(6486002)(186003)(6666004)(66476007)(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: VrPZOxNKZ0epay+3xkDECrSjhhpJGbEvLNqVPGC6Cj1/b0NM0+AVqz6VN9g0DrSYI5XJ6qSmYmviFDpb8ezgvjh4+r47nJ25u8AIEyZAUgqdYr6zO+RPu3C39xrJlqx9pJ2XI7jFNDt0Q26hn+Lhr4/DAtc94nIcqWV742VOxVkGwNmcI6dRaW1YTMmMGfE4805LmbHTBnneSz6T+zhdlM8yQZzuixTu6GPvgFbqnqwXCI9Fi29OxXix6H7p8xecqHgcfJjQnyMh/TbBGaYg7vKjk5TgDSiH83YQyAV+eHvjsEJY597SgJ2/kDpoVn7cF+hymDCovCzpSNUc3+MOwlj3Vu5tP4EcSkK92ZgiU3d3tUSeKOZBaAe80AqkZvSESI44gbNLu/oQDiducat+PZW2RGn3HOLgHCLXbmWSPZW0KtBCzajVEZa+mhmtxUWcjxP+4FgFuJ473Y4COEhm/rqMT0ixdQIeK+coitoRdAxY3sXucVhz/9Ha71rSZ5dYz4IiRdMhcMRwqeuZ+FNJN3KQGOb+HhSe76xL3bshnC9M0DJ//pw4NeiSnabDO34jcwlIKg74+aoCtSPdO8g+eI02c5+rLq35OQDdlzaUbQcQoCh/1b/CeJ+zNue58j30Kcv+cptohpzX2uV23edR6Ii5cUSFRWV0LbDKnpJhSHdZOBvPAoQS5n3tcIqGpfZkID7ofqXicwOPwZhFMwMAVXY83Dj/NAPXjGGPVLa+6td8SVMXP2ppqWnntPGBmuOcc+p4hqbGlnniH1p0k7SvKgKIZtSWL0G41GDWBS4qsq9ta+YtukxMuRbpm9/qajLwdMHCjmb3mM58z+l5tCtrTUzS73dbs3O5pHSCaVRvzmdJ9H9LAzvXF4Ye9NPfLAYhmKMTMSY3Cpk05zvTB/LBVolvE8kuUFNdTmwA/1J5bxAPONap2vONXcCCL8L47NGUGiCJ6ZEAXPPN/c3lsRGtBGBoNmoUHtI7AWvLigsaOnTTt/Piu4DnE/UfDzBitRr56tCe/ybxYOlNyiAGDzGFKyhzFcD71/JcJopiry4fzeLCEs3kHYsJS9Ij1GeZdgEye2h+A9gAAc0IaryZjpkG1fgux+qsM127qt6nCIDshxO3VHyAtMjFjDAEd0q/0VhB2XPedoZy1Cws+Fdc7rXO3AaNtZ2fS2lEzpWCTm4t9M7I2WREGka3hvlCjnxvHlsJ1zVbtK4xWUVlziaYYoI7KjjwB0edkprz15PLayYoIEqAFHeGtZFa7ev63EsPEN5XRKjw/dwjL07GT77dCrVYTB1hgsGnKz8m2oOrVdCMH+sbHPRZv5Gxc8JIU1iyEhtP6K8kiZWOMcyTXsNwDgeBWWJwp4EX47VArF6Nje+uoVNCR6grBY/AJhNcUEuBIsNfrOvE5Cz7X+FawX6hdQgkyjaCD2pzwDH0l0HQQhvfhHL78OBSi3c/V+5TxvrFxMAzs7Xlj2bMpXUZxrFVYY2kYYDzPcJSfPg4x4OPR0gZ1deCjqx3YM3iLlb5ulE7Ovl6l6t2fFiqC7TJLw1EI8E4TwKg8ZCHu4lGF1V+lUyGh1rXa5JMd5giJO6iWCU1nPckW0iQrsEemahYJQqiaA0/pH8FSlssgquWPxzvteAiQVzC99E8FGOFLzbraJbcU78++ZXUPpdfEEjj11hSsklVjwSnQlUGBn8X08VEUfZmDvE4V6x3Ja1gbtgBCp3AxCGtqrFsHj1bW+I1N7J00N5wcQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a20a1d08-e587-4850-75a6-08da3d9a7512 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:31:23.1622 (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: idehzOtJ/nu8BceAFvKUx9Ooc2b0ytNlxkKdDXATP0oKFtLbYe9LBQhJFrbZFq5oEb500V6dFuSwv+Uvi6KgWw== 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 mlxlogscore=999 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205240079 X-Proofpoint-ORIG-GUID: eMDWUexXzDI5S3kFOyiA5GO4-Aza3CyM X-Proofpoint-GUID: eMDWUexXzDI5S3kFOyiA5GO4-Aza3CyM Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-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_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds handler to reset a remote device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index eeb165a805..c0c2277bfc 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -632,6 +632,20 @@ void vfu_object_set_bus_irq(PCIBus *pci_bus) pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus, 1); } +static int vfu_object_device_reset(vfu_ctx_t *vfu_ctx, vfu_reset_type_t type) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + + /* vfu_object_ctx_run() handles lost connection */ + if (type == VFU_RESET_LOST_CONN) { + return 0; + } + + qdev_reset_all(DEVICE(o->pci_dev)); + + return 0; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -751,6 +765,12 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp) goto fail; } + ret = vfu_setup_device_reset_cb(o->vfu_ctx, &vfu_object_device_reset); + if (ret < 0) { + error_setg(errp, "vfu: Failed to setup reset callback"); + goto fail; + } + ret = vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s",