From patchwork Mon Jun 13 20:26: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: 12880112 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 76998C43334 for ; Mon, 13 Jun 2022 20:29:26 +0000 (UTC) Received: from localhost ([::1]:40614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qge-0001yf-V8 for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:29:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qeq-0007SN-Rg for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:34 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:22386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qej-0001q3-Iy for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:32 -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 25DJdaXa017692; Mon, 13 Jun 2022 20:26:51 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=wTG0AnFKpw9o0Sk/u5S0O8hM0u+ZhYo5tYnbm+PFelE=; b=cxCxaFANpVq/b0sIuOmlJYrTKGfYQTQj7nf3JavxMwTwtTNa1GPiJzmUll1PFeerxKH+ RYsIY5+HlPIS77bgCRaiuVdkq6vuEyTrpfp0Yn4Q8cYOstzd0ZVMpJ0JBla+OH6h2QIS HTJ0qvvNtSNVw44N1rEEd4kZC1aJHagR8t6u6GSTLl6jGUg3oG71syPC6QRpIfEHSGvL LYd7dgKrM9ZL1LZDTYOgtF9ZvUYANlW7VF4HfFkH4QIug8zjXoUv/1ExbANwZnyji2eN LvDo3ix86c5tTOW/ApoVDbtCaCzbXmVdM4F2rsiILrwcU4OWDvjt1TwGPfi0F4ygu31s xA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhfcm3as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:26:50 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25DKQoF7026251; Mon, 13 Jun 2022 20:26:50 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpc9c807k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:26:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aoxHowK3xV+7gp/Mq37wUKjQXGOf1jAwSOxAzNhnkucvXGSSszwieWrLYYTsw2TxXYNibFHrwyYpFAS5ylxPLVdBtrcQ971UhlhNNJRBhp1XzBxsnYu3HoV6pZnl8auSAFuSZVRp8CFbG/Iqds8rEtCdmrdNuNERC+uPXZlWNK0RWtbtoKwy3mVIckIEs0DxgJqCH5wUn7UDLH04IHNmat8yoV5XDs4N3lAOEvwgmy2obbxKh1sadvB96S9q4vkBoFLS+p7Hmm1KBYwNaWkNI0zTcXabSdgrDhy4mc3chiZzcSQO5h6LJUZw15ByT/MIpfNu4ixx+U2jUvs23fiK7A== 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=wTG0AnFKpw9o0Sk/u5S0O8hM0u+ZhYo5tYnbm+PFelE=; b=lMnuXHzggRi/aEkUVnVKhKsPyoOqU0sRK0Ii/IO+2sUE7am9k4XFaOHKzUQJnk8d3JDvsjS5TZQ5JRk29OFLHxHOJXGZCrnxYcpUXl7dFtUETs1buWxOxfJiz6wxba0+slN/TWbEY/+kC+VldcIAczakwn+8+1P4zwFHzc1lKzxvimuSjLCgySVC3V2HMhPD0470GciWJsogAvR/WZ1oAYf7WfFaJmBt4Q+eNgN0jXcL9SninpdDp4SiWc1QRvruBiNUpfx9S6Z2AmzXwK+krwHufiSsGzUaywLjzomW+H03MXGnPJ6XUfQeYTyTuqEd0KZQi/8AVIuEHobxKChY7g== 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=wTG0AnFKpw9o0Sk/u5S0O8hM0u+ZhYo5tYnbm+PFelE=; b=qlwYi2jkBmeUDubzV05ZoKWFFUszl3FwDd8rkIWdd2ACcjjieYXuViGhBqjurhO81FBvlknhYlsCmBSWtg9G9DItM3K+noLU/RGRwalKNTdBUdeClIzXsVvE+QzNsKFGdsSfdgcoelaicN7gJsAiEGDu81Z+SkMk67sGMGUzDRQ= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by PH7PR10MB5723.namprd10.prod.outlook.com (2603:10b6:510:127::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Mon, 13 Jun 2022 20:26:48 +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.5332.020; Mon, 13 Jun 2022 20:26:48 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 01/14] qdev: unplug blocker for devices Date: Mon, 13 Jun 2022 16:26:21 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 2c06809d-84bf-475b-0dab-08da4d7b0a6c X-MS-TrafficTypeDiagnostic: PH7PR10MB5723: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: vUFULP7TQnU8GqUnmhpY3V5ZIiX2nCIbdnOu/jGbytjgUIvU8gE4vEcdWo2RynS+PKoA54HCnY50O778FabypvcQxaqv5aQAKvOw6/LdEwUfBrAA3nGUVOgw0xtuaUqz9Pcq+w+gSLg1yRMCsLk1KUDD6mJ/ry8Ok0MStdijx33UM5UZxMKWovVoTxpFa9wCOGtFS9lh6kORJoK6ymZJm71liSqh7Dyho1VssGK/98jJXo6BG+1R2tFAE6MtrS2IDPPwjulq1Bb8K7TfTk1KgcdT/BI5bJ+mQChZsqumPNqLyaDRl5IbfRtzKMUVUNC1I6DMX2I0CaRs7hf6zYTi+HZR0DmW4uXhzkg7/g6RulAUdNlOiNzTVSOXUCWiNhAX3g/QvKujbQkHsSFqwutzZ35MqxprL2WFs013T+NcGLoDuT7rb0CUfaVFauIKK78kvOOimQ0TfiLj2JfPUGuEGq7XkdHRgFPTuvSSC6tM1b7zSWR1X9CXTBGgmSkCp8WUxfbqyzB6nHQH/qNLBgx4DmS482sTBbwsOVMnGKGUsGiPZcG7ieiIMtJcaCahX2B6DSrvNZGMpuA9nWqvtapIiXKSybdI6zo2+i+EFmsEN5yCh/WIIEMU0FUrjNNFumgElN44/hNllUjl3CIH1Gfu2FEIWHWUImB4eARofwNQDCImsjcqWhJgIJQFLkUpe0YHlJCXiaJLvoB9VgZtuPVZeQ== 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:(13230016)(366004)(8676002)(36756003)(6486002)(4326008)(6506007)(6666004)(8936002)(5660300002)(38100700002)(508600001)(86362001)(316002)(7416002)(2906002)(107886003)(2616005)(38350700002)(83380400001)(52116002)(66476007)(6512007)(66946007)(186003)(26005)(66556008)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RVhyg6pELOuohMAx0c0sFsEZ9/2/KAzAiKvD5d9RURLIMUCBiFfroDuo5vYGYBirD2cdi1bOhEuxj29pnc7Zrtma2zDrUijC1RAQpqVWFUcx+phmlQcK90ief64k7vLEb8IG0lNDMr+V/P5Rsgcs5Km1Dv/Xz7uuUSs/7h2oNANnWftG8gGWvVg4VbauL2/moi6GfMTJVeEJdmvF7Cyxsbwd5FTbaKH/yy+MhueWjEJa6BDINtMkz7A8m+QmK0/1Z0+/sjd0NiV23b4jrP3em6y3Ud3XPmr+2Xj3cFcM6Guadv/Y6YBlXzPp8t0m/0BF44cYixj5g7ol0SLmAqWcfz68kCAWlBydOVy6xe/+dCX0Ns58+9D3BHwvRQdZ5hbCJ6Cm/I/4PHDvpyzOCvPxuYv9NMQUakWSShVYS5chSSSv4SPzNnLVVFs6bh4roo9af72hVlVmbWe4sOvLQTV9LfkzE6/WV2dV3kXL55xDKO/9BfDrmJrR9L5cIP0O0RvZlvh164DySMXmCWLNuStZtzmuFlI/ApSnveKe4X40ko0rsDAu/CBCQG19WpNgnIkT7JluFI1+B74kBwfFKfg0xM19O6Y4bEm2d5j8HqFC7pZ3iMDtoWddr9zTocSraih7lywVhMIxYjO2JnIrGhCzSCTF+u6zm3Q3lPcV5zYKMZnKtCnJCEpOTOMQGJWOIcls2V+1XG0QLEK1/KHB5AFNNf1I7RjHDBGIQIXVjlfgMEesh6Yd1awL3fTpQCrwQAOQKQuNiviGbz/dxLCCFaa2YC2xiEM8US2Yyi2XSl5TWhC69hPR9rGonEM8rYNR/rC/fkXMWgIKDSYWo++1AhuN8sP/cH31dhukXOpsaXrqniHn6/C5CjrPgt7JyKljXzNjPiPs6g/S0rRxyV0HlfOqgsUJUdVEICvd9Oyhsm1JtMyd2xnphklvfRC1+EvuckU7rszrr2JOoByCwc3h7onxEu3XwGj4ZW9xJWRnnnCdG3LvjpOErF84th646H5ktyiyQZJ5K6SNMlvhrkCkWhDEj7o8Jwv2gMV8JUsK82KbtNV8W9nEE3pS6f0r71JIfTZlX5UvXxTseus8bqIMWEUPWEibxgDntBIsEVKA7cLdJQNef/2OIUMz4BGkrwBJ8dfdEBP2tlDd6JJ8OQsJHipIs6SYCGjal5+jVwJrsORvGBYDKmHk3TzKLDe3p8REZzppy1oGaFi/LpRDQUzPp8hTnDBQSjzA3Osf03fQ4bNodVhT+pXgYL4l+kbbyf5HakOnmk90y/522w6Dn7pv+0HsDvQr+wvJEdFBYw6k9HKiINWDVNsv/2MlCAgpmKh17KG3o4Njqg2473tKCGNSDswuksQIsKOHJOeBAXh3RhAh3JNZ5Xd8Qb920B/arrQGX+uHeElxQDMNDJI1+7XZKKY6aYyidiS4V3peHzM/meTXMLGzLRZdNQTTfvBFFuru2ZhYGgMSlA29jZ2pMWLb3qlXsO1XXKfoOx09gm9D82GZILs7HsQ+mMZrVMlSzbO51wGGpE+Y+l0aBN453Uv1NjV98VJWr0/2jYyrzgTIJJ5j//YxahNQfqVkNP5wXMwsWfuApKbjf762WMvWeB7R4HABaPO5v25JTW31+rzI015mMuP2mk2QA+u95p+KnjeVO4aU7s3hCjgnk798HOtIn6szU3f5MDTp0+mKt0I6+3a4t5ZhqQiwf66vtIbGbNP0vrtaBT5rhC3IaHU4w46v7PpZqQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c06809d-84bf-475b-0dab-08da4d7b0a6c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:26:47.9547 (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: oYRICriH3fs9IErVHO6xBr6ROUXkFPa+XGpCgOdNL0RzHCyq/YtbmmKpYWwIUYetjl7Y1+JSbJfermXFB/UVIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5723 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-ORIG-GUID: 7WaRbXrZXT-VVuehfEyCAOJwcd4FCQnk X-Proofpoint-GUID: 7WaRbXrZXT-VVuehfEyCAOJwcd4FCQnk 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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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 bb5897fc76..4b0ef65780 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -899,6 +899,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 Mon Jun 13 20:26: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: 12880113 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 CEA44C43334 for ; Mon, 13 Jun 2022 20:29:29 +0000 (UTC) Received: from localhost ([::1]:40776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qgi-00024d-QU for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:29:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qem-0007OK-27 for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:28 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:22684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qej-0001q4-Kp for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:27 -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 25DJdRDB027247; Mon, 13 Jun 2022 20:26: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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=ezs4Sf67fjK10WgD/7RvcUDz7aSscd9W02JfSQT2ykc=; b=ZsWTZj4xKiBT1vb0raGbE7N2BQtE6CQKPnM0DnRHw8t8MZwxomL1lloo7xcVNOptpokl E4PItnGvm7M07jBVYwlvnYbwm0mD9KPBK5X84iji8G8i7VRFNRzjrd5liLfTKgF8zKAM HZ+5RxI4oHJJCmoImMMDvWbvexQ37vkk3TZAAJr1bH5FJJAieji39A2nPJfEbWBz6K25 1lCiTIoxgzF39d5gQFkpW3x4QtB2BNEzvJg6Hk6MstJltv8PryHwNykWQIzIpsNeqqeo FD3BDK7xWl6PNbqTgwyZnE9EdpuUBc99lhvIw3m4OpOfloi+9hJCEKB2RI3yzRvys4QB 3g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjns42n4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:26:58 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25DKQkYw026213; Mon, 13 Jun 2022 20:26:57 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpc9c809y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:26:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I99WH3hd8WLhP64krmIoPrT/zLjDt/lJPz7Q1JDYwNmMGX9RgTdFxVmLGUi6fCFh+D9wllqkmFS4mq7kXTQQFuWlUTfjoxsso+kHD/OOVxyZHVfkvnsdWlB5vOnBwAjA+3m17CHshZDF6uUGz8RjEMtswTB186gMTeFcwYYTtWHXIgfwoIRbrCBONxKaA8QW31Amvd/Rc9n5rCBMNBT65l2ieofFC5fHMlNDwbjcqaqic/Fn5Mmc6f2IhgJCTUhtWB0ZDD8gn9c7nKvthhw4JdqLNVaFnZPCr9jiLe5qSM/VuDa5TGQ/f7Fl0OPn2l5tbMF3cXyn2NcEH3b82Lqmvg== 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=MDn4vK9vb3D+I+ZeqnWtn5aghsqlD19v8DKfQGk6bEGuOiqiWqj0fUGDd16t1i9D40Cg8fpEHvIPN4BE6NUdbziyVsH/Bj0OS9MSs4GvEYTHPnWYph8+fFC0ZmazRGwoTDFgKoc7sN3+jhx/cV1EnkdWmqYS8I+EeHuv+wMG5w/EYcP/w0yzG/5L5HNxv0XEL6OaxWl7YhRBGdK8Vl85AnFXcAUf3yWwcpMBwgtWUobXVJKsaWpfKvLwvqCDpusNwTObO0ku/NDDwp8lzUYOrhMPcuctsqE7gWRC2gsQIULG+zp3tYWpoadzQFUTbg6afe3qsGGq8HdU6AUPj5oDUg== 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=t1YP+mLxZTEPvxBKzFOUQIs5BNSaFb0yu7vjNKI6zqdBLcCqSG85YhP0dJy5hnk80eIO+T/48jmr1ceNqlR0BB4hyMqRTjoG4bvUkr62OfAUMpTqSuSnFrp7BqDktbJix9qUc0GwwrANzcD1lZ5nkcPeOTcKWxnGTN3+hFU7xmQ= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by PH7PR10MB5723.namprd10.prod.outlook.com (2603:10b6:510:127::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Mon, 13 Jun 2022 20:26:55 +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.5332.020; Mon, 13 Jun 2022 20:26:55 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 02/14] remote/machine: add HotplugHandler for remote machine Date: Mon, 13 Jun 2022 16:26:22 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: f10f3451-1627-407c-5337-08da4d7b0e93 X-MS-TrafficTypeDiagnostic: PH7PR10MB5723: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: DTlyxwL8QVa1vnf5fHQtQWLvb9psATpfjHGb+K2EfpTFGY5nr3D7PyUXuYZXJlg3FxZfsg8rUhtd7pHC0v+AhOi7+DfbNmy8+Rl8il/TSXV6levjL/LfwS8jsP4lLpZaXXNCT+3BFFRq9zQcMOEv80nflCqXWjGstunzO/XsG5El05j3+zkjhI/d261vBRSWnisD1y8C9CFEPuqBX+LlIdY78p8wbMIidL2WRR3sqq7GOFtUYs/5dnVuR5e7nWkfgSjhihzLEVvUzkm57GN3fK+8lprqM+nWnbSPUcHZOGYdkzcLmUjvDbN8ULSurcJfDwmX0Mpc9BN1ZP7yeJnM+GAKG5pBuNQe60TdzaJHavP2fyejrASzvs4RFM1pbppfT4BIm7pd5d/fs0T6dSOP7J8z858XZKRV7wKXkHXZd4Ont0nfy77FA6VIQvNX8QXeLIpBAUMGLqYVy1r0WCe7+L8MseiqqjkEVWXlVcHhy999AsgfoO09QyiROJT9K+zfwGeMDPV65cXbxjhdLZNtIpohg5ofNpCymPVO/eDDqiJyMLJcwy6kmSURUMKtjS7H8rT8PpdlDWO6lXyxD+fqC9DtDTLP7ZXIZdUk99pgmpk+fTgajGVo4U/g1WCAhqHN01KvDrQRxBTnjEQj62FeX40WJ065hOqyI0gmzMa9Uqs78K1P963/mZ69+OuAiYgGvel0Be8WJCS1bvy1Abd0jw== 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:(13230016)(366004)(8676002)(36756003)(6486002)(4326008)(6506007)(6666004)(8936002)(5660300002)(38100700002)(508600001)(86362001)(316002)(7416002)(2906002)(107886003)(2616005)(38350700002)(52116002)(66476007)(6512007)(66946007)(186003)(26005)(66556008)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NzXyO1TL+tn4WNPuoPJXdG/LkO/aRqQNxzBxiXbIigJeOdiHMdxAQrByBR/Qj1NmBC5NQpm3AKs627N81rHAjydZ3w1FQNkonpkapj2vw8WGdhflQ1IvadFSUqi6iHnnjuWT49c2ipRBC90NfvSYnJMUjqYuzX2SMe4xzXphvNcSFGFAaEnCkD1MAs5LZ2fiVVP+vaqaQWOTy52uif8sZWhBOp7GwcKI1W5gFSJ8FFrvdKZyaT2KKzc6VVL7IGatie9ZN595NmRN67pBD71YjSBfgcx2iT+r4cFT12EJ3l4h8HUplFd/wq/aPChJOKgFYp9Hjv4OmcBnNe9ELx/eDDFNu9cFdK/VGi3lmV8UDpR6HNQMbNDJLKmZ0jYIrqalGQBH5zpqRy2W7mzrJGgw9AdW/gAJvUBn+1ES1+HM54nlwjmbNptFXhsiaMEAyRPEWja+v8Vm83rA/jT6BzSU8/FC8xs0d509YdRJ6qO1bE9MzPGdErylAMtvpdPHs7oQnJMv5sboVdxBRJ58msJVb7CepqCUrHpLgkgI9+RdWnQF0znFz7ya7pWX2IqgLamxG+7VYul79/d8p6N8Y0/DyxXjs8F7f17bO1hLn6k/pr0VMTnNxudklBVz4evUgTXFhf0/KOKHxhGZPYdKvV9mICE4jftlSmqa8z1mDetsDjXHsNRqMg71aSEWu3+0YWpRHFdKSWbSF+gIFVvsr+Za1CyEQJ3wdFUjF5h2sabrVZw3JfRRnW602cwX7hCiM4aBVZUFjjTD8/wsan+UIzaspyc5lpfLHwtI/pzBi1DjbTaigUjLM5hch+HcS+7hW2d7rzXXl6BJqPQFsUMC7zA+XMHd3Lpk4fSulOwKfwdULfOqTTUJr3d23HsJjLBDbAiPSzo5GcA+ks4sx5g4OGdBIq/xlCBGQ3Z+eUL6RdYGuxDsaO0ys5adpAn/Y78EY/tKIWNd9MobF27dLRmRasUSA98kkGZjnX7uRnmQOY/JaOfCJ2eTOEtCGcpulr8eN6BdYjieGzn6hhQ4ZFR2CRdO9gm8bUWv2msChP084mTmf46IWME58PQbiUcRLLDOvnYh1nWmYK2meNA7twS8n4A/0JSquRIL3EGeaoEwXLvpwFM6qN+ToLj7CK5V2tfQlmrKMxil3buT2nsYULQ6o9bGNGejW9k46MaK8i3vd7DMpX1tRY36FPz8RWAPZAGSbAkDbloclkXweb18roJe3bajDHHuxqStu/77XUbH9W1Dl3bWcF9kEdTfD/s6O4oqxSm0Om+pzdg/J/tNhMS6rmKAS+1sblSBWRYmu7/tUA76jQJ4gOKcgXBCfaJcICOexmY3O7LbOzdDseX04F5GdmaofOzXbIJ1bXpXvp5jAyO49h1hZldPD0ZbiEfRs6YBvAKhxC1uAReFyFGXHxBOaD9DQD8JZtY+Nb6ivy432TG/AKRmeQd+TZE0nB+PVszMRg16S2CBxIArn+0Wr3lZUlWyhCDQehjkY2xaUWgSZcbwHdiodII5sEv9QBdawPQ1PRKDhsv7EVEO71e0GDJfzgbbwzO0xry/2MrL90meJJY51pT4RAMaWmj2Ohk+Q+37E088zQePvq8Tt64Jx+9JyrUvfL8tn78zrrJDCcxuAjkCVJNTBDxK1CLx7gxwAhdd8Fh9Aw8GdWILnYagf3gFOWbsgUYqXD0f3bV8tzOsywpFTWwtecU0fbDlTMG6rF/ImIGGPGc6SQ/NwRqp9sUOazqYpQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f10f3451-1627-407c-5337-08da4d7b0e93 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:26:55.0323 (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: o70HK0Ix8KNvh3osGnhbpu54jEyRbu+rLaQuWzwzakwBJjXfmCvqkE2XDIXDX/C9Q7fsRKUoKgvcRmAi8UA++A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5723 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: SWhTfwBkHZqpBhOa-B7C7A1_tQGKb2SP X-Proofpoint-ORIG-GUID: SWhTfwBkHZqpBhOa-B7C7A1_tQGKb2SP 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 Mon Jun 13 20:26: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: 12880114 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 AE9C4C433EF for ; Mon, 13 Jun 2022 20:29:31 +0000 (UTC) Received: from localhost ([::1]:40820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qgk-00026X-Mt for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:29:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qes-0007Vz-A1 for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:34 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:35828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qeq-0001qa-Ja for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:34 -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 25DJdXZd027265; Mon, 13 Jun 2022 20:27: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=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=zRVsJxAoQEV0fbZOo4uOpYPqQk/ibvWVPUxh/EAfj8kTa598J4NEhvj9LGMyXM75NpYk +IT9idmeu9m7IuxAcn8Wu8aZXdIfTRC4p0H+H+iI1O0+h7MDUhCd6r5JlhTy3idsa65+ 7rrHT+R+eL7SCuRbI9u1zjNEuj/368eYUc3FB9J123PHv19v3aLUoTxAuHkQ3ryYSBhZ q7jD2vNy/KjUC/WZST+ozC5xaHHqba36zRhaK04oDeLa1U3SbqAG/9tau7q/EhyX3e/i FL8SjvjocrcBGH08mbi7nL98Vso3gTXBBk0p8dy30nXCyVf4dTwcHLnvX1muHx+cvdMP zg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjns42p7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:27:06 +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 25DK5VbF037985; Mon, 13 Jun 2022 20:27:05 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpbuggrf5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:27:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KDCqByA+XNsftd1N0oveMB0jZSDDx8TEdPtFwjJfEQDMDEMXsVU2YW04HtszJInTpHLNi2E5GpW/1Z9QINjrbi67U8iNADC1ycGdwflsAk1pZUiEvW8btjyY1+YPDpf2tqmCLneJxucwic1I2Mmrdp7hD8kjPbxsIBguKi8k7quSdmeq09oj4WO5bYeTD/CksK7wFH5Ca/0nPbejyKLk07ErtHYoEgoOUrPBl9oNDO6vRWUutgokdfPtAIGzNLqwPT2WdWZzCspUP/EFA2M5iFFuS9XqedtffsLU/RpdTS8tVngw+201MvxOKzm4jieCOpbZD39q052XzWivw/nszg== 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=XS1bsvWjUstrnMfVAnpqyExr+Hia+7jlomfPG5D5Fyyq5ZcMw2mYNjNf3n8u0isj8aii3NpBoDeeK04LAN3fgjmi3h7HGxdLlfMaLVeiJCSvDvxXeoLZSiR2gJ2CaXXa4VG7KVZ6+KaK3ynl1AU2ivch7umXtb6WkEAbdcQEbPzeFuwgXAG79AiPp8MqbCZV+/MuT95cprGVnzLz5sDmsnuaz0y236vC+pxihyZDTBs0ppAwImS+3sQ9YSOcB53HV5/Z5XbE95bTFK4Prc++KrxtOqX7aaJZVey37KNutDSAr8tCVDuTDI/uxX8aE6WzSYThLRBhGWhbdkVzv0Es0A== 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=b9dNrE/OdelPeWttESCUSA32J3+2w4aKZrgl6Rey/sb//tJSrXAwMCmQWvmrGf0fBOMWQNwWlIkVFtUjaJQPKF7Sz9nVpzxHpHETVcUvF5bjCigGiUYfxpotwiANzB+HHFMaUAh0EgUoTUEckg3xYj2AC4KlYo5F/HtIGoJ3UFU= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by PH7PR10MB5723.namprd10.prod.outlook.com (2603:10b6:510:127::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Mon, 13 Jun 2022 20:27:03 +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.5332.020; Mon, 13 Jun 2022 20:27:03 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 03/14] remote/machine: add vfio-user property Date: Mon, 13 Jun 2022 16:26:23 -0400 Message-Id: <5d51a152a419cbda35d070b8e49b772b60a7230a.1655151679.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 6895d026-7318-4640-18e5-08da4d7b135f X-MS-TrafficTypeDiagnostic: PH7PR10MB5723: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: K/pqGD14Y+yXTowPAHu6gBWdJ6oyGX54inBnZ2yeM42kPVyOaLWh5lU/6Fu4UZJnBjKETexerphiwFWUDkH9Xlay/p9Fjy/XyI6ZxFhYvEyKF6sm0aKf69Zln3JIe7m6ho5eg5fzvmzVee4MO7LiDA7hMoQ/x8aEv7GP6uzGdptWFdvimvV1Z/12baIqeYNPqINuIywIc8Pos+9m6xovQ71Az60vVhyoUPX8pV3PczcFahtifFNOl2qdNDbTes7QNmh+zSDi/rqRcSsNK1XJ7zve2MGbPvSfIj+7dZimxA82YjsT3XXJRdYMLViODKx3Y/q03KYvMpfBi9SLIpFEW01ntIcN6BhsyUAOz6hY4hXQonUvX6YlvEi6dd51QsAxAOm0exHpIO40Jn8C903qHOC2Ro13JhbAm4M9Exp3+N1rP7unHswxYbsDrMkekVEzPZ9G02foP4FPPM6kK/EaZiiwBdR8zR2LxpgQwtf/Mqf01DhvLoFEedAcsGnwGj4KonWEMadZ6IF+vMN0vgTNJHnwDY27ouFaaPtDXbg0vfbAXkfiECf6OQlB5HN9+xf/A1MdC41aajgV+y68A5QEZfN8EbxAjmiaAlaGnLV6iG6cU+gqkWd5lbCL2WybPB+FVICOnYTA0ydr5J0IStJDuiHDvNoOMaPeCJ9IHox9DIOpJQyJNe07pTjUqXDTeI/GUwb5tO1xzK0B08Iho/Q6pw== 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:(13230016)(366004)(8676002)(36756003)(6486002)(4326008)(6506007)(6666004)(8936002)(5660300002)(38100700002)(508600001)(86362001)(316002)(7416002)(2906002)(107886003)(2616005)(38350700002)(52116002)(66476007)(6512007)(66946007)(186003)(26005)(66556008)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YyBuSjs89Sp/cOWE7H9aGxpGIvQ5nJy+4Olvir5g/w8nfTQyT8YSET9repJPgk67nsmNGPvk3+Tt/H9P8ANdGjBGjylrvWEO6yyGdIFZrCO9gBfL88rpyC/cYy/k7xtnZUTEROppacrowYRBMaJZUKmDEnvSpoS1CP413DD1zYzMvIpaXuK8HB1gUX3mTLnUMzluKqq1nYr0wzhjgEYNRX0x7RCkaHM4XbrWNY61KcqBcpv6bPDDSz0/WULEO6EDbu+ksl2WSyok/RROFt45KbgOYiSIT4Ukc26ZtK9kIxeReVELrN/hVPho0JFzkTUUMQwe/A/DIxbCs2kCfbnsZO1r8b/o4GAWiOIQbEuKJMJZgvfAUW+Wp+VlhnLkbCfwwVTukC9W5lVjQlGSBqO+oY7ECDFnZJAWqmEm3U6HP3Q8HVSHvZIaVrqehqGWfC6RHGt4fqL4ZhC8dqdrsTM3dENF+LBEddJ6nS4o+mzimI6rT5R7K8zjcGhjKa1fIY4zEyLEqp0gp1Qba3bFhHEm7dq4h8vcKolZ2zVEJ0ZVDLLcRK8Gv4F8r/tf7l5P+/sjLDuijVlbGiNNGjxOWCjtQA/seHCd1XlXdxvzmKRWVvloWezEjv8gUJqXOgP8fqubGE/2Mg19PXDcE2/7ON/jYZdJwsN/vNX/xxmlyvJ/6OKjEQfnr0AkQswSOP8Urgyzu/clmkJLlNLZV/UADF6tGuThidoPKH5T+OFLbMWyczqHgJ0y3OqaEHKRnUXzUFxvYTPEh0GPdS38NpMx88ueCrPM75SBzhwzPhjJzw0BCZ3m3CePql1z62q81kRJ1kCoC3kKRUSLmZWPmzngewWF4+BmZmyPDqysGGJs5DHjBkeXBTqK/iqh6fujRnHs8VzBlo8Ih7VnUSeWXGP33h6OFhfJs9gg9hDif34t+5g6QfOr+dMIjqi2qx/d0DpldKNFq55U3CtVvE7vNRyZyGLUjq57VMqQpyD6E/Ztl+KH92PPcQGwTge+nAS6z883GCZMlp5O+Wl4z10j6y77VmXoJISty8goqWUY3OMUBdK3brMfFw92om/F+XXfxvYTlLSERUxNs4PCYZ8nlDsErPcRPocaB9CIfvp0d0m6Rxa+8Plq2/vIQl65EkHRCpJLI9/m49AHqwCZ+CgJxXSd+v8m4QLoYBxQmvh3D4fV64KRlJPTUCZgVzTH6OXFTsLYgkuwP7sZyivis/qupdZrfTaxdnOsrYec1Q1VV40foCVQpWV3KorhrAlrV59OrLqGUc/yKFkZ5gzEpmT762O3my2oSvzS6KOhpCac4GKD4EhPhg7KnG0vM9jzaokIEsyvIqsPn2UwOfVV8v6wU5kjZxjDHUeU5kOtpzzW+Yjz5QLnna2qDvw08rK6TL6Owig/8rGXxNCpifxudc6RR5+4rTFF2oVyWQEGGGc2OGEfFOO4TlCnEM4h00SaoPWbdoVk+DbPTsi18War+e8Ry4SGLpu05N9hmYBzysn6xer4/stQ8i3rvZtIu7cg35CsHEZeDelJ+E/TKLz2K86GcIB0bC4Cf0FLZEyIXFGZcYWPruFLzpVh2EeltiXZjS9fBHLiYQaMxfMHIUcbbf2lqwctziBfHpWROrrgwlBkwQQ5CQHD35ZALVJ9xkV4KswGL1Vbpe7JhX7mDW1SgDLgr1pkojTjCNp6bn7QWcbfB9Qs6ofaH/YMVyHq5Lk7vBdNfzz4kgQc+AzasgXxZKfVY0ueB2j66w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6895d026-7318-4640-18e5-08da4d7b135f X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:03.0943 (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: NUyreUfaQE6aPEwMhjeaUsVH2pGzVqLcxJVk/yuNzRxqrxH1x7uYp+EsabVWUEDOPg1i/60/ltbRU32r7K9o6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5723 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: C-IlOr3Pbvq20XR6Boa_qKEh1ukQ7hV9 X-Proofpoint-ORIG-GUID: C-IlOr3Pbvq20XR6Boa_qKEh1ukQ7hV9 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 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 Mon Jun 13 20:26:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12880117 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 BCA47C43334 for ; Mon, 13 Jun 2022 20:32:24 +0000 (UTC) Received: from localhost ([::1]:49328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qjX-0007rq-Pl for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:32:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qey-0007Zi-GB for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:40 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:46312) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qew-0001r1-9E for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:40 -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 25DJdO0V027238; Mon, 13 Jun 2022 20:27:12 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=rzHBQVd+a95oHAbpgPqfzOEkSg2VthnJGZGdYTQEnTM=; b=bUSWZA0E5ks0hxMCYnjSI+FwXabWQA6Ec715EivajQahbbrxn+KzR9l9qG+MDev0A2sr wNUOEoqsqsM5bLh0JSpRiVVMuMpx0PK8qzkHRjPkDAojxnf66+ZWW4rujiTMJ8lDk5A6 ZaM/B45cNsM8N0r3gZYS1CYBVBWeGZs/mJjN5SnFb6JQDdKarD7qLW34wMPnumORt/JS 6+4cIWnLSNCFDgCOvdoZBCHMVuhdsnpbwbFXwKqQlDo4om161C0QoCRPPt7objGLUnPb 2d6NbaGTVwcG01b4jWbu4MvRpGnT5qUHEO+CmmBn3V3o4UjdagTkMCkHlvzjEoz7bln9 Kg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjns42pf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:27:12 +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 25DKG5SB007030; Mon, 13 Jun 2022 20:27:11 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2043.outbound.protection.outlook.com [104.47.66.43]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d08ug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:27:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=npIghsRTDbS/GnFCbSW+RYy6LEw96Bpir4JNzEKd2KmIdTe2GtCzDOgTm4pCOGUnj+WPRtC6fRmXiwSkqATj5H+4NkuPOzRikUEZtEiPEBRiP6J3wV4J4itcWhybt+MzjU9oBjhgPShuyF1s9ttdGYuaRBxDo3ovYzzkZbt6bRBpT80We5CNKwmLZcAdXSjHABZIjR8wSKRA509WOasQo1TmoKRdX9Ps/2tH4dg4J0+txF4EriCU0XRx4G3F05oFPRcDxe5LXObrMPkbe3GiQSbzZ6Uoc4xmuMTg0QEcHgGP9ocpETJ7d9iLXMYxc4wvg2LWSKROXMxWWKd+SVkgEQ== 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=rzHBQVd+a95oHAbpgPqfzOEkSg2VthnJGZGdYTQEnTM=; b=UbKBv6ulNhGfxwsjVW0p0+ObQl5IsDRf0ikXp97UoayeCZJk077hZGEf/JgFdA/wlw3t2pGYi+xmkqS11NHyvhwLIbY9chwuHtoJXGux2dWApfluginZFDuPnpee9qaiNk3HuG0sIyDVKruqBsCGwX6MoMTe1QBRGSS0jZlm4jglORSlmnTIFJcDDti0xi7TlknWt5auP82eQbUMUlgWorCAidKzpGkvWMKUg1cnTmeD7wyw6h2jQKZxIOf/pCih2aMM+FKW7exktkCrhZBuAYjwPlP3NxSQrdrGGDqtX7BBVm6OGT3lKRYtRDiZaaButDsgG77dUfmCn2QLj5/HqQ== 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=rzHBQVd+a95oHAbpgPqfzOEkSg2VthnJGZGdYTQEnTM=; b=SzQYMBWIooRLJYMohEdRZmJTr41Am7qGIpJqaMqmuimeTjTD/xlgi8jUGmrwNpyYqWgunSZdM28WgL0GK8YAuBIwZC99WqrYYgbap4HjU7P9Rk5qINb1YY6RUhWne+GyGaRSigdm5uj/hMQ83rxwDenTQmCMUDBTPFsQyOH7+AU= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by PH7PR10MB5723.namprd10.prod.outlook.com (2603:10b6:510:127::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Mon, 13 Jun 2022 20:27:09 +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.5332.020; Mon, 13 Jun 2022 20:27:09 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 04/14] vfio-user: build library Date: Mon, 13 Jun 2022 16:26:24 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 69694352-19a3-4dd8-a4d3-08da4d7b16e6 X-MS-TrafficTypeDiagnostic: PH7PR10MB5723: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: effZ/4kucOLKc4Vd0JRUtH7SJhfTHOStxpVtJP5D5/8LAwENBGWTE+foN9y6cRFSIQKk88gS3ngAoOtJ9Ga4IiCWmqmGy28o+/T1igBYrps/5zpC/si7LRk0x4STiHTgvc6n2kapBDY75xcZefNLjEgrD3DX/NPUgNFajsSCh7FaeYDjKJyWFeaMv/IdkkmuHIpxrBxu2njjIu9Tompkv3iaaaX0c+izHHuaDXvj/cEZ9zISIgv/vju1r8nVrGjKqKYD8vN3ijRw9jaxRN6qa9ANgr881KrUeUd3zkz7337cJ/xu/EQDicrERoQoHDrE3Ag7Ztz3duM8W8knrcNxzIFxE3Omrk+L+FWzDP2hsU0HHgbKw0iT2oCc6dclG1ufxwOLyJmebD+gX61y2/gtJs2wyHJsxXBUjIaGgldTkT0/6YJKnSwktpxWAXg4DKJDKctI1p7mnaRkXoGkXTIjsDWYwyP+qH8wwiT5+qMmj+1mCxP0YQearcZRi6klxz3RqGPCB+de5TT1t7+pQgFGOFYtZdRLBi256dtvlj2c0MPeXsYEfiqw+TrGAAIIWA9fqe6MYZ5xrfPR5rq8Nn47z5LtV9pStrx8XsLfonssUeABXVBVtDDiO0vD9MdMN7GncKkMHA1nfRfUjJ+auhmF9b3PrsWc7FxLCiEpRPnQGCg0Iv/FFOnmp7R2OQCW23m5cNCSLcnyLLS5u6MBS1CIySKh7dO0+hF//YUoUwcxsdVBjNrZtU7c8qnINpZ1DB2h+HiEeisol4c/mHs6TeTDR9dODgtJuKmc5VPTOfyxGwIDI2snSvsa6Q6SK4kVWgd9 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:(13230016)(366004)(8676002)(36756003)(6486002)(4326008)(6506007)(966005)(6666004)(8936002)(5660300002)(38100700002)(508600001)(86362001)(316002)(7416002)(2906002)(107886003)(2616005)(38350700002)(83380400001)(52116002)(66476007)(6512007)(66946007)(186003)(26005)(66556008)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vjT3q2hwOHjoIeMZ3DQFYMwOLqVb4+Z52UVQgivHUO9gcGM4f7zgtesYUeHKzZ+ML+lZHAo69mtbpUfyhMAM4yRiPLmG/GVlr0c9E112ehLHLcoMWN2qISxMyu61ezl+g8z0JA65n/f76223QiBhnhFQrE8NttwBAcvMks8v7pxmZRnhW5/mXxv6MxKyMfzrTTKCMUbD1+k5uTl/uby5sYJva0GIkgFp/SDD/fI6EF08lLgbJ+BKhl1wPpcWHVgklZXR/+RcZSwD1esRtKdcu7BfS4MPyHnmhX2giV7edsQzO1tjvpMpXqaiNq1Kr6y7iSKzDyrERb8XRUsqsE7B8Jz9FW5sIPZ5Co/JUyGmj25aWzo2QRiqCEVJXY1Xz1QQGA7ltHZgoRyFPvK6g/BR7wqjlmsff3GCtTWzTZUG/DHxYmF4IrV690XbjAoQISfva/gYH5+fOA62lxrDyeJT2BMBDQM2kY7gdvSVQby2m8XoDD8AUtYPQ16RB6sgEEaV/C771sQ/Edo8lOdHdYfeRHzDiO3DZPshysSJLd0NJNUHaeTsYaQyqzjYe/S84I0Z86PlYiV5prw0rBfUy4D5Dr5PZAQJ058rAFDH/1iXA63ZNQkgVASbXSU1lFcUmO/7WkDcL6kqpnyF9XXpPrSqrte1jikPXIodagDgeAxXOpsfwAduvJYjx+B83qtzedgQ/8cezsxN8q1u8tuIXhsD6Q7CbazLPEhqXDoTBzYmOsVPNiq7i8Z1kJ8MchKb9pK6tYw8f7Mv73zfKzYsvToafZI4jU8rtUaPutqWi1nALq6XLspSHNe2UtL5wq8/tsUKjOSyEGFPMpm88+bbMjwmqJwpqfsww3trzEHO8hlvzUwUqp2nToG533LXRtHrB6DzNNEggWwmXc+oSwhBKXb1yvxxxRaGewUNg/HxkDsd51cVLx/zNZx6SOFx4dhdITuzMHmgDBvjYJ34Okn1pH02JcKeDssMtzs/7r3cuf1pEYA+Dvx0u8IKYWRkBM2Gd+Qe9MLSBxP+HLQ7J3UKIQNKQl2dH14HEl0qlK5DJsqFZ4EJMtek5IQL2e5KjuYwMrccmMglVtpv3sR2nvaYVIoK0mmfRH+uaVnb6YmAr1Oofx5ydv8AfT4FyGnd+kaqwFPL1YsDL6WGbA8aWXuAjpGupjXKfCHi6+8oYc1kihi4Ho9+HjuTVgGbnlcx2zLsRn5cbzO5gDj6/Mc9jT5uL6t47vDOOMEX/PoGHtp4RF7gAjoKlasdxbr2Pq9uuuOt91OjKqS9hOaS+JbP46waB4gnNmHi/LjVV4NPs827CA4xQmYfJHS8cgUBBeoHzU5JYm6u8/x/momt5CiS6lJFOWfYcjKsNvPdQqHA3U3aud4PQaPMp78xLUFUg6SRHdJm1EJjxqwc91rhAsAI34qhYNv+pZwl2VPylAmWyWiPy5ZpkoHaAwbN++/DkS/6iE/AoNzaifpi3nTv26f2nZHc9eDgmIOm1QyxmTOISFnviZLmJ8QKRGCPcByKuoOrQGlhR+anzWK9T+DCC/5QoXkAYT5ZEXtofJV1pkvz4EK0F3kOzPj5faCSVYqDdQ/CKrfBInb/qv4u78z65W0W/HUJu7v1KOBHg4IYxuhoX+QqdVucItA3lOwQafMhQYJmnq/iM6ZlfnxrBza9YWf+EjwX6qf+8dXVleWpIN7h0h0mQIacNJO8Xn2OIvk2r9X7f8i8dR1yFSuZl7a3lQUMFcNc6kGUNg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69694352-19a3-4dd8-a4d3-08da4d7b16e6 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:08.9845 (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: v0+aQXZwENg6iskFOgSDWGoHxwXqq4Q5wnOPCWwtWfNsMIYTDE5Msd8mRHzNgnb0TKnc75fuRlua2LRfbRePKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5723 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: kPx-n2Zmw4-1IO_RsRUh1SjYE7cvM4HX X-Proofpoint-ORIG-GUID: kPx-n2Zmw4-1IO_RsRUh1SjYE7cvM4HX 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 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 e69537c756..39f30c0283 100755 --- a/configure +++ b/configure @@ -315,6 +315,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) @@ -909,6 +910,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 @@ -2133,6 +2138,17 @@ write_container_target_makefile() { +########################################## +# 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 @@ -2669,6 +2685,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 21cd949082..fac9853254 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() @@ -2373,7 +2377,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' ] @@ -2665,6 +2670,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') @@ -3783,6 +3803,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 544385f5be..fe8d34b022 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -168,6 +168,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 0df25ed4b0..bc2241576e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3632,6 +3632,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..0b28d20557 --- /dev/null +++ b/subprojects/libvfio-user @@ -0,0 +1 @@ +Subproject commit 0b28d205572c80b568a1003db2c8f37ca333e4d7 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 Mon Jun 13 20:26:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12880147 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 28A9FC433EF for ; Mon, 13 Jun 2022 20:45:23 +0000 (UTC) Received: from localhost ([::1]:41994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qw6-0005TW-1n for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:45:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qff-000099-Rj for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:23 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:45750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfd-0001vK-Cl for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:23 -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 25DJXYGT025664; Mon, 13 Jun 2022 20:28: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=vuYAcUE2qctPVMyHcVmyaRPy4HZtBnw4XbP6RD7gzN8=; b=kdLjVKgZrytLyiDmIHiSSuPfHexuQnnl9bkylsqBlfa2i00AkBI/zYEC/if7MSkoV9oK 7BysjDFpHUVfGc/ovxOJTRcrKeTQ0C8heYNfNtgQO9VFhn+imJ6SAboHs4hklDXqUvRj VlZfOW+x7qXIqF28AWyu4OSDM3DKfBSuDZDn7fID8ZYZ+lYHt6a1dAKBl998+2xTb0Uc jvG4hDTzVRUNtB+n1f1pNUfgd6A8T0pBbFVYkOe27BdJG6N9B7ZGtdjRpcBTUclF+Mzd nSIor8DVsHtJ9WaaGABhCnBHXfAPKyCQ68voHhsWCfPFj/foS3ZQbp70FowzQGrvCOpx Ww== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjx9c1yu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:16 +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 25DK66oo030851; Mon, 13 Jun 2022 20:28:14 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2044.outbound.protection.outlook.com [104.47.66.44]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpbv8ruve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OD2DszWNHkDs7ZjNc4wFhlsed5dep+sR6At2lW3E+TZKPcxPAm5X6UdSs8lkCIv6dEgts0QQk1xKWKtKd2z7cxm3F0Rr725Uaqb4Vnd9FRjNmJqEy6VDj6L4VbuaEe5JkELOldvxhEvteYoGGB83w4dAVvFI2O/kIWmhLeRA5yMsePMS6W3/qqjUb1YbWu8Lm8QKUDkKlBLTL493Y9L78RcQDENt/mmlEjfpCmhq171fxLV7XcFcTqi8GuWMeAzc40heWlaYsGNkKhfycR3NaZC2BN1fHuO7dZXuGB8R3YnlTdreX8X1WwUO7FdNlfTAxgdwna51Fk3figrg5Y+dMw== 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=vuYAcUE2qctPVMyHcVmyaRPy4HZtBnw4XbP6RD7gzN8=; b=ecm4ujXE4sybbVbt4X1yJvoJmdPAKfQC0s6+To3zuFBSUpbGFVmHZ7KrvnoUf195yXuvC5UBdIB8W9U5MkFPwd8997NMiKFo1vsuLivkoRwoe9+d+fO1XFdSagj8yj1MpMPS0YKbQ57F/qwKvKVHbkIHb2oOkzsNzenT7aqPqOYwoL1cKWMoocwPr4QW7kC/fRUG5npfoO1XLpMnFis82hP0cxXf4RK2JBAYCl3xbEn8c3JEgzynbKTQEWrc07KbsyVZ+umnm0VkrLnJgSbCylp45DQA9w3eMSsvfOsy1jZzeu9KG1sIGhYOXLG/HZHaNNv+a5jCG7pdR5RGk36XPQ== 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=vuYAcUE2qctPVMyHcVmyaRPy4HZtBnw4XbP6RD7gzN8=; b=NIFizbaOm+4QBIqHx1X5nZdNa4mNXv2vS72ujSbo1z9Rcd7Iey1znDVPNMjqid0apoeJCuTkU7Fpsy2P7WJ2xXDNSbMSq4vDCAhD8B20ARJDsdQULjlmlZ6QwofazTSQVG0kL9RbL0mIlWpJv7XZlnI3rVd8qZTvkIkoVZkMdYI= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by PH7PR10MB5723.namprd10.prod.outlook.com (2603:10b6:510:127::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Mon, 13 Jun 2022 20:27: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.5332.020; Mon, 13 Jun 2022 20:27:13 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 05/14] vfio-user: define vfio-user-server object Date: Mon, 13 Jun 2022 16:26:25 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 8c6a53d9-c5f0-4e4f-ecac-08da4d7b19c4 X-MS-TrafficTypeDiagnostic: PH7PR10MB5723: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: 3XMEBX+sHtX6IEqh84onrpollw8ZHbEx47nIwwUwfzyR/D61zO/asYvY1h5vqaPPrqkupKj05w4OlaSAkNF0iLRj5nhyiEEoPaZR17xB2v0G+K3jfDCfxZq6zIGSFQ5epyDd9/3sPFilQd8j4h4upAxkh3sx7GWJ7Xt31mol+d4rw5G4i+pY+uHJp7yibVAeISN2L8xcGCAtgDZZIDwXQpUFeF/OYHUTLwFs+XgEPwwXQ2pH4/Xi62bCFkuhy78lXPjkB8oVsO5midUBAi7Pci7zepeJ6t6dR2CvCbpmSPCycFqCFyr16y0zpUuwE0zoQnuB6AE4uYwWFQk0FrbMdW1zFynxjoz3WibGFogMtLxiBeDNmBq9rxw65swzq+BC97oja/I+Be5O+mhp4tSrHVTLRcCsajAvbjFNksYYLxk6Odyb6eqApdnxTzje8a6iLUh6tRr9ty+Je9iTj2RVnUZGB81YOFzU3RJ+O9ocHxUA2UupSg+3Z29wjZcyFLmAPR6/eW8UFWX/XMkjdqYRwpyQI3MNrZMrZQ70nK4ZzCIrxUO+mRJCx8MtY6h/H+aBoj5+8kz4p7xgz5Hxs1rJOX5i2R2OAusfcQ/5fFdbMCxAd8qT63mbK4qEhW2tGhwMkfd87SqvJ8D3iE7FQZNoWabDakkYH93B/Ckn/DczdM7ls0IeFZhWbJeSONjOe+hkb0JaWAAvYv57KkEvbAsIOg== 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:(13230016)(366004)(8676002)(36756003)(6486002)(4326008)(6506007)(6666004)(8936002)(5660300002)(38100700002)(508600001)(86362001)(316002)(7416002)(2906002)(107886003)(2616005)(38350700002)(30864003)(83380400001)(52116002)(66476007)(6512007)(66946007)(186003)(26005)(66556008)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7xXoIsQHt6KLvr6rtIFL0Gfvv3bs?= =?utf-8?q?98jOCI0xKqzv4jLZl/+YWhbRf2PGnlskju4PHLAsuhe2VBYQY6XQAwa4qNiNj8RqI?= =?utf-8?q?oI19SQ2keNDoslis2Nh4vt9iRxJX2UlfusVFm9Tu46JNzu+0ykGz/E6+VLoWYZleG?= =?utf-8?q?lMc8hhuifvbhWYfZVUn33j+LOkOAmyRdcFhK6xHpSz88b/P4hLNRzU02AKSMQEBj1?= =?utf-8?q?XSuCr5mPEAlC6baDKyjZ52PVRoIew6/MNp/0qtUw078iP5UDi4JCL+eV2DbPfezS5?= =?utf-8?q?HqPobKP/9rbuGuc3fG/2bM4pI8qyApBb7sH4CRCE4BpiYQN4rec/o5hnOmJ7utPwc?= =?utf-8?q?VEh1WiBpFM/hB/6pudB8QUwAycZWKnT5+tqseNpGSi+GvxUkdwR1tZQDh1epWwK08?= =?utf-8?q?P+zT/YSAKJeLzigIzjYT2FUftOL6vpVxPqIeAXkGiT30/Vwv1x/Bvp8jOtgte74Ug?= =?utf-8?q?i+8brM61z4dVg/AVgFRokQtRPGYlNwMomMEdG/9TNeA2TBLBDaOrsUwITsWnb8LNV?= =?utf-8?q?ZYHGUezhz2P23Vx8cF7aqbR2EMThuXSdzGz9RLmGVbxat9+3Hl4hG3SMuqmShMu14?= =?utf-8?q?aPR4gG6lWQAGhoPJ3BbHIxrxzeO++zreIt6WoA/u3OlwHcmhsY6IR0kCxkLT9BhMp?= =?utf-8?q?QK4zspfZaX4NeBJAltHSNn/pscCrtq0fXRaFwuJKBX10E9MjPY7dbPEvsLypXr6h5?= =?utf-8?q?X3vqNwR9sgYReq+vHRSFVdc1DVYa8Ju29DdpXGnP2/QDJzFQCohtAgAlz6FQFin1A?= =?utf-8?q?fjR9+k/tuaXpiTFlNTpyCT9VlcyJL5dVK3m99IAK/3z3D6DerC+VxibyRgU8f79MT?= =?utf-8?q?rR9/YTWCPWl2ccMxt7tEvtt5A+rCeS7lgDkNfvZ2e+zLiixqov5IamyG559cLRzMb?= =?utf-8?q?S2hqHPkmeL00mky9k+fuDfVw3ElPKCD7Ee3tGHwrnnsg2iDDlEP1Vkz7VFjizL+tf?= =?utf-8?q?lKOLT1/kO0xYB3S6naOeNRHkmo306ojWsXkU+7tgFt54IiFeDwwHokZ20BleVbyiQ?= =?utf-8?q?Ns1IF6EvDL6DKyWnwZ9qGjWq5LZCQBOJ+6kR229kOd9T7FztLAK6+EJ/eFSUfEa8j?= =?utf-8?q?c3fXuVz0rp57/rVb6u6k9YYB9p/ZaQe5J8Am/CvC/bLzoO64C7StgyxzX4hDEGiMH?= =?utf-8?q?GQdbjVc0uvX61aEENPNeSwwnfRWhdsK05hiiHR9yqC7vnwMPc5zH6umgKRRlBWKm6?= =?utf-8?q?sIclhdVVP5qdet8iDcS/Q45FNshKzRRObuh53cGKZOpLRxIGeC6WUAFeB4npOwUQC?= =?utf-8?q?JONRX8qaEsVqek/NkAaVQgSIWC37eiHeba9L0ebk8mfmIjLrLIyLh2yakzdPTuc5x?= =?utf-8?q?V4f7K0qvefanJId9MUrwYoYsggT6OWkQbAkoGVUSRduxXQMThJntAY5of9I9JaN5K?= =?utf-8?q?G8+Disxc/B+pjIJZK84FK7jVcajFzLPJjNddIJQucUYtG5ted7uuRcOUXyT1bWRIP?= =?utf-8?q?gJtC2z+RDLgsSRbKUWtSbwYF8qqlym7Dsv5Xv3eRSWpglPhBUE6T4tiEMgnF1M4zn?= =?utf-8?q?kX4Z/zQzFu8pk0dgqSWMsl4WUhmSDWXaW5ZOwTEOnWuN7wWY+tFwQvbGiShUALOWG?= =?utf-8?q?PbRV9GukOOtdLC4FNCRMIC+qCqDsHKadIIMr2ZEz4MzakSUERV1JtMM7KhxcidjxN?= =?utf-8?q?XLMNhWDztZlYylNGKl+sYIX28ORa7fHw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c6a53d9-c5f0-4e4f-ecac-08da4d7b19c4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:13.8435 (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: MeIMAbRUwFDlB2MOXUBU1gwTDUZbKqWTjRtvRmVjAXgVbl78RZfz/5alD5s+dFEa5jJJZISkid60D+gVnSu8DQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5723 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-ORIG-GUID: xYzbeEqihTJIoTBjB2CjOFonPbVlergm X-Proofpoint-GUID: xYzbeEqihTJIoTBjB2CjOFonPbVlergm Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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 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 bc2241576e..6bddfe3197 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3633,6 +3633,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 Mon Jun 13 20:26: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: 12880115 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 91EC2C43334 for ; Mon, 13 Jun 2022 20:32:22 +0000 (UTC) Received: from localhost ([::1]:49158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qjV-0007lH-Mm for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:32:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfG-0008ES-Mb for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:01 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:16342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfE-0001s9-0s for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:27:57 -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 25DJdPie004110; Mon, 13 Jun 2022 20:27: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=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=hauruMwmw+q+IKREg7TRCzwMHuh7cJkyWCF+uATC1tdPQ0fcKOZx2I42i85VjwMyBGx0 XEyqVRek2ovnZd3kE3oaSHTrYosAdD3RXFr3cdG8xFN/5jpzukGryeIbXzum5GeMXbh/ 4+DwlK0BCUNC7qhlOu7xTaYa8yLP6xAPtKZG4Yq3WOma50mV/jCvxiSErvYfA2ue0PFb RBrdKGmjZX/rfGZMTSbix3pkcfVYk7TMrx8S3ThzVsO5imS6em+nIRZzbhrGqyXnVKdW pbljXL7FWjlHjkBsfLKmwoZFAzwFt1sN9hPKpftHDIaGkgn6NSI9WOeN4A/oaozCWlsf 4A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhu2m56j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:27: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 25DKGPxL000729; Mon, 13 Jun 2022 20:27:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpc4hr9ke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:27:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jh00T1BMwk8++lEyi9fB2nBvFVznvYqNNw3+4sUqd1heHVmFMu+2ocrYUH28/06l/ctr8J38LH8XtZwHZ3rhTkRdaPWANCACVczcdRHCFGjNNCEU5K48z1hnwG/uakAQJiTteJ4Ge6gQFva4B+T9oKgVG8WUGyH+z6cCqWaAxBIDZKh8dLEHA0H53COcjj1IL8esFQwqTTxvh/T/75rxZ6/rnxS8/WscFy3jsJhZulwEceK1ACOFOeOCv5pJLWP11Z9CV+K6RRkj5UAP4Nm0Hc8KLAIsAlge6GRYfTlQOrqZ9QlhURuKQxa3lUKoqggomYTnUI0xf/lC8nR6lmTYjw== 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=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=XsC+yVRYlAek4gGi6KoGXKo+qWtdj/vZQWMQP7GkCJjW3PaGPuUdv0DcHR8KvZdC/xE9Lg6l5RuwY8hzFLuKN7aHM9GIP4xadpnbTmnkytKm41C1VCI2OZg3xSJqGG+SIuw7lV+0z3p+2EwgCJ7ua5Rp5Z1gKnbtvsJfDQN9u94LzzEeYQv5TKyuWBNuJ+74SkCP2UgdpaQv+YACw0h0NszAg83/nIRZWEsaC549sRppStIqyYKP17BsWR/f6DvSwNFq/Ai5aFeTO4GFoJ7AY30MEhTpiByGAGA1PeqjJVmmr3wfhIU34xRS6mZ31o7FqIlo1o6eZnrKkJAX2kwzvw== 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=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=S9UJYW7tZw3k5kABfJ2xgziLeQ2coq3iKFvxv4yCZU+SIxtOOb+4eDPZHWPwBeKaDg17V9c3u609WIDsGI4XbpdQ4+g2zJVPdK+FkkgIF6DQSP+JjbcCsRjZx/wFnkvsVG/lnS0upgFzrG9NchI+B65kNHTueqmFMw+yKbiK2jQ= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by PH7PR10MB5723.namprd10.prod.outlook.com (2603:10b6:510:127::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Mon, 13 Jun 2022 20:27:19 +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.5332.020; Mon, 13 Jun 2022 20:27:19 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 06/14] vfio-user: instantiate vfio-user context Date: Mon, 13 Jun 2022 16:26:26 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 48a30acc-57eb-4f24-1c20-08da4d7b1ced X-MS-TrafficTypeDiagnostic: PH7PR10MB5723: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: eVt7ZCVaJQJRRtpeyst6XgtMVABP6GZdbiQuxS2jkDaxCGArEIT/ruV6noVJxoJvZv093Ln+60hrXJd8mGjg7LlNZdB6lI2vDgHgoQx6yx1pME+VvI0PlOS5PwEfMlE4qh+MNPjPHKkciZruhJI8hGGwVGo2Fwua3ARay066264Bn9Txyz8CePai+drszTAmBrkxOjxr4ZC3/4NAy/eupPNqc6U0NutwTxYY9t6cVBMtIyPS80lKAFOsLdSg4GpprPakepDbOTHsG7RlB9yDKI8Zz+qbEUQJkvGA1H2GoT5JPQR9C5LDsPraoG25TXU39HFCr8Sjc2K2zjlPhu7F0jy/J20tGgv7ZPNEtyeaBS6lPh3ZPk0ljobBKC6B0kGkKRoQ1OsjwKEnMpxwXtLwfmlha9qpFB1cYa1na7uJ2+dNZkAV4MhSL2IYrDvSidHjQS9K2EaBTMkQlwNLSegzpcGyaVwqrUBXYFAe6YOLfTNP4SXr6PljpxH0J9Rv5+1lM6mf3uhYpRGzBemJOC60T//0nXdZ9ktMbuFBiJK7GT1Q5WkY6+Cz7C/sgSJq3cVqQwjxaDCaNdDzbrQJub6AuRsHD0jXKx5PHwbBfRGmei/pfT8Ded50tIq3b5AfMtkz6QdCyOy41sFEbzvgo0I7F9iRH72nIsQV74Yjr1w01Sq5qPDV0+u1xEjbME/w4LF3+KXyTiF8Aqf5O64bLmHsuw== 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:(13230016)(366004)(8676002)(36756003)(6486002)(4326008)(6506007)(6666004)(8936002)(5660300002)(38100700002)(508600001)(86362001)(316002)(7416002)(2906002)(107886003)(2616005)(38350700002)(83380400001)(52116002)(66476007)(6512007)(66946007)(186003)(26005)(66556008)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sSUAV/TiDU8aczYlbLBrweJBNI3+hr1mRHPwert/jWeH6lQVnDGwgWEoFl8hO+NgQYfsEgutwoV2IcyDoulYhaEMfc9YmJ0QVCBMZjWEwd3WjQInL5ACNxwPP2SIQxUNJmTsGkpTYRpIht8YOR6oj8N4wt2YjLSzjaWo6ZJg+R1AHnTtyNi5WKZHmtCWYKlizrAcvEwp3JzrtRS07l4B+inttkpT3hFNnAPLvhXaJSgqHZ7s67IFkMEjwfoTwojakVAlw/CAyUAB0EwyxOTY+0QId0+IG3vnDZH1INvuoUTB2Vfle0wR64JbLklzqmciURwacqMfi6bgLxdktXOPU6dYIiBFU4meCcZGy5fZZJY93YVGdfL0chS+OcWCRO7eOcf3cpiov19oL33PcJCowJ+XxfkDl2GNngytg93aLhJ6HvAYj8p1LOsoGtldEmC5zUWnr1ASUdqA21VFgAeCQlTo+wbkKsyFKPaGNeYR1UeMY+bGRd8nctxMeMqtVBuKl/1PLXINzNcOb40Ac3SDlMDXyaZrTa1E0RGBeFnJraGFXStUtBt0hlUpH+UJ6rZOthKz2xgjkivq4D1mEGBHTAvSvyRAMMuBg0IoxrLyMHFfoPQ78UKonkT0kQNTwLx6KQ068gSeodPHJ6Naqp3Otp4WzQJLTZAVnxHS1KoY0LMejMQyV6t4xL7bqrrh9AB6IbhMQPePJ8SEcfhHvWwbaNngVgdvQbwe0uqte5WRF5d8dlUBY7xU9ZsIO1uLHh24YZoMQgM3ngzZJjpV8+f6jCCuRaxZlFzubPU6GRFghc2KyDN7B3qDkaiG+NoOruUTFNn38VbFKbM1CqtbaAKmov4836OKEAoDEmyoApWGL2rAB9JZnFg2hKutbsO6uWSXpmH4/skppJ3PNoFxeEKdgiwORb0sCTsVlOAdH3jXjiSA5Acc/nCJiI3/fT5I5Q5A+HB38aLT/0w4OJORt/Pv5gQ3kc3JKSwySdgyf5bHMR/qH35Cino5/5Td0WsAkvJCQxTjG2tVHUOR+moMnfLFvgJx331z4ZnhHAYWR/htTRJ/5qQJajD9omRkfJsHXrXAU/VV/kUHfSrxYhIq4MmnUYbkvEwzoLBX2vmmY3CgvCpeoqO5gcGwC2KJNlxpHoYjRxCbQAG3xuRkqDubcYZrAaf7bZ6RltH6LgQx/NiyybRoPjFdp+nDuD8aompD0StXliIIDYFTtQyPejNPePYsCmclV/bSuudQjvqeWM3OEndE1zoZaZ42NlhdDxd8lYmgFXcSBnwlilXfakQU2QNcBkFRuLnEPUym4V42CYuxaFPL+tE8R4NvgEa4aVb98A/+WTxKowKb8+EF5sPaqdWToyL2z+ZRwSl2KHwHMIYzOQJXDLmX+faer8PWuZ1kRnS6FBku6hojGNiMf4zynftdyuv9MX+gQ+EuNMZakeAdDfyiAnoAUTPBD5DBm+a8Jw4Me95oFMY1xaPPeOZCIw/lvmZHCxP1IJK+lgWbE2kvFptnSzTDOkgxegmphJqA5ip+dNH/tSuAmyTBciRUUgcYafsfiJ8wAd5fnXe9yvx37IuxzUUANi0j3oELF5q5l3Qx3kiyAJo6mcWi0xJFdiWMY/VrTsDLeszh3jKf2MatCPCFE5tV4G+R8Gcny0BltGpjRmyslUGSXm2jk+thBA4nrRvVrX+ts0t1NPcDhiZdSsX6loAEtfUfyXgyRItlsyl7eetqriMLMC75JgU3ib9gqA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48a30acc-57eb-4f24-1c20-08da4d7b1ced X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:19.0307 (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: bsuteyT4/8PPt2v1GWzv5xrkdpwhznAbINbyJ7syQq4mPIWIEtbtbaSuPtGjIWX1bLUhUyNTcs3IGP2ZA/ythg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5723 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: J9axoV9iT7XwrsRfBuivBRGTt06kOaG3 X-Proofpoint-ORIG-GUID: J9axoV9iT7XwrsRfBuivBRGTt06kOaG3 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 | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index bc49adcc27..68f8a9dfa9 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,69 @@ 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); + } +} + +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 +213,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 +232,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 +244,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 Mon Jun 13 20:26: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: 12880136 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 D5A0EC433EF for ; Mon, 13 Jun 2022 20:43:00 +0000 (UTC) Received: from localhost ([::1]:39886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qtn-00040P-KL for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:42:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfb-0008P9-SV for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:20 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:56560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfa-0001up-0z for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:19 -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 25DJdW62004207; Mon, 13 Jun 2022 20:28:15 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=og3us9aVU7yjthCZgrvB6Da6iAnNXBLh7W3BZoEvEMY=; b=hYefvBJoTS81DDG7Czqr7Z+IYuWtQOSwS5biBLdwOp4k9T42QW9gJsnMMZZzqicvs02Q rycIwjhb4A9PHjcUipbP+KxqQXO3no9pdkmWcxZgv0A7zhw8ja0R7DnBEJYfruA19Kxw pI62isoKzlDUE3KMkcnBYcaJhK84gA+PzFbtQlurUCw2Fmdsroj6Fm0dsapErjLJrkmm hIg9IYAKqYtznwfti3isy9f0c8rNHH55LCS6gSeDDv2clRVU+vx9E1udmljNOnN7ST3P MMuPqrfIAGywJk27lizfaf/Sas4CeZfT1GQpaTNlUku/Os2OQMxTnziYpvO+XxyIkOqL cA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhu2m57f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:15 +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 25DKGGHk040826; Mon, 13 Jun 2022 20:28:14 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpc4hr9tc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ad/EfOXmas3N73Rlh85ccG0zQm6K+CQ5Rmtc7FEHOgkJcmy5DE38o2kW8EpQdNt/okor8iHth0MXjzOi9zJ0aaS1Z2BNYL0V6LhV5eME4zmm4RRNZ6kQShJRfDKNqz81niYZzVXj+Lw1XqXmWaTBrJgd3dM3umgZrzCaaf77xs/M6S58U4A0d0zgVFQzPuKwC298R+fYoDP6P+a9QWVr/F4v3zrDxY1RxKaCc92UsUnpA6aCik369WTisGErQi90UNpcjeCDmEHEqRGFS9BsdGh50Rnc6YDs61Y6a7rZo0ZmVtZF6t89gzKw0eCTHLteQ4vxSfxuS5Q95m5+vP7cpQ== 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=og3us9aVU7yjthCZgrvB6Da6iAnNXBLh7W3BZoEvEMY=; b=k13YlRd1XAVhCzzveRmPZmGMrqA0FrUCRzRRLqNvle9LeNRek8pggVA9yA1L9VAoc5EXSeZzLMu2GDc3kb0zj2D+kK8Q0xN+FwQgpCHm7f5Qb95ZNhQODOGeuKW2F3euVb6dHFPtGlTTiDbk65sdR38aCzAeqZ36zQMvrFoUC6ZVQMl5pPo7upkWidCOHC+xYT1Mg/RoCaHNqC3gPC3D5+6Qx2GyME2oHvs6LP2EBn3wsNXb54I1N2aQl4mW7QhfOzmT8vHcYh+l24UaYs/LYWWNdKlIi3ZfLTaN8jQGmuLYMkMVjefXvJIZYUcCvsTq7bkKGylPaGWoN4ajjx2GAQ== 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=og3us9aVU7yjthCZgrvB6Da6iAnNXBLh7W3BZoEvEMY=; b=TE44VV4kYc4cV1utchfEzDGV2cCTvdTY8TZZZYxRvyWzTingFLyoit5TIy1UaBP0B4c3QMYXNv0YMXMow5OmL9hQ3svoF7BgPwrV0GltrYiP5gYGzPFyLBJ+TO9v4191LYRMliedU0SjUgodZMsXa3SsqFSU+giFYI+JEtIZKCA= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN6PR10MB1585.namprd10.prod.outlook.com (2603:10b6:404:49::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13; Mon, 13 Jun 2022 20:27: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.5332.020; Mon, 13 Jun 2022 20:27:23 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 07/14] vfio-user: find and init PCI device Date: Mon, 13 Jun 2022 16:26:27 -0400 Message-Id: <7798dbd730099b33fdd00c4c202cfe79e5c5c151.1655151679.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: da98f986-84ed-429d-786e-08da4d7b1fbf X-MS-TrafficTypeDiagnostic: BN6PR10MB1585: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: b8D20+R2jP7hNTCEvgUuA/fQGScGyQDF7cyiv8Qmd/6789F2sKzitKeJynEjLcQ9bLVAgTYMxJr0X5SSsN9kPJZ0U4OpVDT4pnKb0M2ZKdkpVUsxnPiLZIrNKd+6PM3Saoiv1qhuDsPO64R6YTn9Ll7vb9u+JKYYSFkZXrJcg0es8i32E9eFWWDDCHxB5ntiruRfm6xVawbVE82rV+a8Quli3Z841fkcgK/v/k7kfEZK6noOxAeaBhVdP1+rBrOc716SuO7nNDov/+hgkC3lpSd5PdzXitxD0PC4cOLHW4J7GPi0Ixzvu28Wz+CiLTUuTgrVTvtpcpREbacmw0ksm6w6X7gbSWm9TRcKUAN8uKXyleiC2NmNh/2xHBq4jXqPg+4HK0q9w2abATHQS+NHt9FVdP7U6JzEZhU1ZsbtQ7KnI63z7WwjsUbUufK4Rw2+mz0zDBNmqGFWRyhMcf2uiw+LpJjivvDVAXoh9E64842sbi84jFxZTIstccjfzGiE0T3i8dCo76wUAnXZBrjFWunodHFNlwT8Fb+BCLGd8qjBDE8s1e8ZRHfaI3SN46lxUA6q6bsPPmrPMG5O3Cop6bPaCuTT2O0U2GchPZR3qcwP+F2uHA9Cxi+RFI5RoxsKmp1W18yJkag9LG1xsV2jwOL8L7xrWLCYnXl1vALgyoSfPdqn+eTqUPxIcN4o12d8Pwzbc5rufpQ4xZ/80J2bdA== 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:(13230016)(366004)(38350700002)(38100700002)(6916009)(316002)(36756003)(6506007)(52116002)(86362001)(26005)(66476007)(66556008)(5660300002)(66946007)(107886003)(2906002)(2616005)(8936002)(508600001)(6512007)(6486002)(83380400001)(8676002)(4326008)(7416002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s8hVgnqOhUKN4l00V/0WLxZjGXfMYvV5ohiGwKuWyN3SP6byOtnybsyaq2WauPkBYHU6eXqwZrIq/yI8A9C5IcBGhL6jN/0hyfeQ8UIdWBtK/1KaA++P4294PiLXSsYY/SlRFon8jzW512C2Uy0pUOwBXK42UmqSLgZiv7/zvTS6mMCXEuG6WJxNmCl7TSCU8fbFWkOEfnvxaypm5Kq5xSYtDIdCF+Yf11Od1ymImi1zCt3tv8JLsviqRytBZfczA5A+fPnqNx/r0MvCctje8x/x/PUQ+BCua740D8rorMzmkk+3nqB7xApzO5j95JqdXl/w0T1okKoAbGqReElg5pl2+1WiAiYdRW8eN0YxMRo6hgzFGM1/Yfbmp5BnDldN9uhD2bI7HIje+KwVyq3dDgFmlUMCIXVdQceeKHT70D9+w9yfuUOh6aqo978WwfW2YYw/tBS8BXHpE61Or2UVQ8RlmEmvXvBuEuXz9lkIOmc4D5YsDtlXYZmJwYP9Zerkx65ACszh84M1iRo+OSDDZq3jzuHMsCRtRJP1U9Cj6wMcCVYecPdwRdpOY/ZS/OEA05XdFio1V+DZZGbsOtRPetqb/Rs6xK8vzfTc+hrvvzpUH6dlac5/JNjvmvnyUpUcOpn+WPxVH5X48ASkfzLDbGngq3tCk6aFqNt0MmSzD/H965j8zQWtEw9Fy+ZLkFD7tkZxwE1hgPs5TUSZL38oB5U/YuB+5XngObuOfVfJxRZ8ektPd2SP9Twg73vKGmGQ+/zmxPJ/yE7Nr26r1necx+NVLFWDUw7z299pDmp5dpUX65sC2+Uh+A1AIgEa0bIJwLklRAqLSquZKwwc7MIzgXO66eXnLtg1lxCpkI9iNdgn6KwELmWmuQN0YjKvpzJIdVpjvB+TgOw5dupQ6LTtieLbGNKphgEf5kPznGrmSD54f2pcFRthuNARn7yRz/UwS/9KvaNIheyakvbh9DKmgW0JOSCzTVQ6OLeL8R+dUVUOq9TRKnV4/1jYEaXX6E5RTxTw3//9ZBSKZ4zWtR0R9O6TuURq91f7W6cbrpJv9bWuFXZwus8Gbny16HOxV8BaBO2XUHfN+DfcRI3oyyLFz6Od2xmVlA8DS4BU9qVRtNlMDMWeNd345siGWR3cTk7HV6GDXRn1QsCOB9v6lupxlKFwW5FRKznFQ4GMCf0SFqFnFqTQKpfoEWA3cC4MhupDG/NQdzqZo8VsT9VFtIGqj9VKYc/6lv8VHcoUUUMnWQava0KYz8Fm7JXVT1xN39DSDiMkgsFPIoQaXGUcBDmURvtEr9ayuvRPPzuDs4nEuHGLybZHC9I11oGmfYLMJEw5KXyZiELwNlcOD/AdMJEJ63viqJm7NLHxh892d1Db1vWq633ctwWcGqWb9Se4fJynq1Ky/9cWe/TtQF/aP4vYjff3oENfPDKOWCqwQFzbnEM7vVbjkPMbzu6zbCFyVTZHFf6EwnoJrttuLDMxJEWv/flZ+x/9bJsc2NTLf2uapzJrlsOaXqARvjpgQj/qAJKhwqZcW8F07MJ/g1Mj7Hgye7jlE1sg/NOzhxGUPH7W7FYoOsSxPZdICdNTJmGUwSaO4fmRzUZ57X1uCwJEe+TOWBfTOPjosmAF5YF6i4lq4yRkH6aJpmTdwQc6HEyZgqVaktFmGkZlWJCijpG86/Hi8P+tOofeoMV2VuFNuImOl6mocj0aV+SYlUvk783VkDAF9JPR/1VwoIW6srsRTw/veA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da98f986-84ed-429d-786e-08da4d7b1fbf X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:23.7648 (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: pwxbrBysinx49yJvttNh8PYdkiCNuimxI6QmPWdhMwK1KM8oQRYkixWcsoHATSXCmijAwPVgXVhBlkzFf9Vv9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR10MB1585 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: M1jI47RjUIo1vtVADM9qGhTLmU3hnc1Y X-Proofpoint-ORIG-GUID: M1jI47RjUIo1vtVADM9qGhTLmU3hnc1Y 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" 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 68f8a9dfa9..3ca6aa2b45 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); @@ -181,6 +187,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)) { @@ -199,6 +208,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) @@ -241,6 +297,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 Mon Jun 13 20:26: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: 12880118 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 46004C43334 for ; Mon, 13 Jun 2022 20:32:28 +0000 (UTC) Received: from localhost ([::1]:49710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qjb-00088P-CU for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:32:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfc-0008PA-62 for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:20 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:55022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfZ-0001ui-4Y for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:19 -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 25DJdaXw017692; Mon, 13 Jun 2022 20:28:14 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=bxB1j/mLLxFP2ZU5OMxJEGAjd5aoDWFj+Kc9VTbPREY=; b=ocitA+0U7/osmgIhd3Oy/9r+EFEYBYvrUPmes+4bsWf8iBXvyxXkNGV1UJnmdTsMEfa2 By5qnrHAimDtDuA4O22hc4fKtGn2cjkgMNIXSfQ4qIdriAuhR/yMf5c6PWSo45AqV8mG /FqTQa8Jej/ImurURoeY6QPruBmiM1a4pur1ttG6K+s6Bl3MC3sgq69/9HkNCrS7fGxR 8ebb7OVihSbxOGrLGprGTX0B5ZSsi9Kck8Zmuh6oAVlhhH5t0E8pLtKfK+xl+cNYL1fS ZbfM3HKSLYqKTclBnH+VEtYIeBxkcXEQlmt8+8EjgIIiTbCk482idMeKaCwgqJpK9eOb yg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhfcm3ea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28: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 25DKFuQ6006771; Mon, 13 Jun 2022 20:28:14 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d09eq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FqTlPtv1DjiZ6z4qHAcC6WUiqPfMLpzKZmakSfigWSHXSF/WpS7TfhAvRrREwpiXOI+ANd6CenjvNTLtqJsEPQa4LBhaEEHXFss8HNieaiUKbS2/Q7iR/CSsA/qEsNPKqvif4msvsmBpyBmD2w+r9dEGDf0AqXKfURTq6ZZpz6WGbKcUmIIFnuJevqT63L1hTlLVPDp9sow5edJ61UDzjHvMXmAZ9Tg8P6MgiNvVV55iX5cnArABxKwsoeMFa3kM+hojLmjVxaENKqeC7i87yH0QKNAGzt7Csx0+Wm43ic/REBQECMUNg63nLqTc5i4a3rYEtR/vPG5drasad1cb8Q== 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=bxB1j/mLLxFP2ZU5OMxJEGAjd5aoDWFj+Kc9VTbPREY=; b=ar0H+7xKalNrYUzXA2LxvynXkHD4vEb9Q4lXQwsrw+jxy7ZyBMn8ppQyjm45q0dMKP6PSaJe6Waa5ydC/s26ZhpiScUOVLGNpRID0zZBoENYZ1BZQAQ3TrBVQ3EhEvRR1D6AT2CWnC8z63JXY0ufxttXU9IEU4qVTHpDhKIC+vy+Z5Smpc+cDsbKksQSSWpaV6pupu7/7GXsIfL70WFPis4cpj7Yih6g2BY2sfn97zS4AIahTtoIlyPHDQVvhQqvgubXmto1mH4QjvqR0XJzx0sm0v0aj4oEhGHnoDd6o4oIS6XdefqEtXabT9A2Jb0B0a2JEdTrY5E5ab3we0QfVw== 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=bxB1j/mLLxFP2ZU5OMxJEGAjd5aoDWFj+Kc9VTbPREY=; b=OVJkHG7QSKzENz3JRZqlfttPZgIF68G8KX4UQcqEOyyV9Vf0MNxqxS17jpxTTDXla9VQOkTKZUcXeNf9EPhvoPxxFn2ssBnX5S1zX12stx7qOlG+dJyyoOqPdXArSkWEd5HGTY0ykDin/at0+rG3Mc62HLSK7Igz5AdJHxC8byc= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB2045.namprd10.prod.outlook.com (2603:10b6:300:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Mon, 13 Jun 2022 20:27:28 +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.5332.020; Mon, 13 Jun 2022 20:27:28 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 08/14] vfio-user: run vfio-user context Date: Mon, 13 Jun 2022 16:26:28 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: a1d6e609-4667-4de7-4962-08da4d7b22a7 X-MS-TrafficTypeDiagnostic: MWHPR10MB2045: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: uZNjwF3RDlx2At9nChaVkyBAesw3sEqU0BDl+9BnDnzb/wmP9b4LbeAzgU35TBgQ6ybTiLI6jc81xuGNUajnD3erTPdzCGQqWPXq1mr4E4l0JhE+2X4GwO8puAJHlblNU+HlF03hD/X5bdVyjQ3t/BOJNyOL4zbNl7dR2SW70V984ksBeTFeUVioTjWqPTM+mDDy74pRZSzhdbZqqUOJMN/i8X6wwG/es9eL9vosKvdU0QWQmW/6e8QpR5GIcZ7w5Denp0bxNLS45gBEMGcuYbvzDemdv+bTgCvvR72dUH+miPzgxRURssDeRsGgUzaqHsVHjp0ZluVcwDDJO3ER17w1hg7v2RFV6mrWMzmChEwve/23qO0JKIIPwg6ifJYLuo2UdbMBTEf8Lyb9KWPAo1Tg5swmiZ0jovwzEjU7ewOBx41rk9twQ4DEQM+SS5MEpXk4BhFE3SJoHhiWYM1hOCXIOGxu90bP5VWCV3b3pNJjnMYuUgR0fjbbVZqSAyDrwhY5nRmjSYaNmh0oYmLU/FE/iHe7JOttgZk/VaOcfLfoOn1klacYpBhoF+9ZGgFmV6OCrvT5xlU4t+xOCdp8RInCYEj4oyx2flhxOvZfUM89wxnhg+VR4SkhAY3XTAkesiUdYTckxMRAV7aCn3yGxX3J3zp6xQCyWSMQZVzFlNAz3j9GJFcXCMPFlAFkaUdVi+7VJcBlSJQDqQO/G/OxVg== 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:(13230016)(366004)(5660300002)(7416002)(508600001)(8936002)(6486002)(66946007)(66556008)(66476007)(26005)(6512007)(2906002)(2616005)(86362001)(83380400001)(186003)(6506007)(52116002)(107886003)(38100700002)(36756003)(6916009)(38350700002)(316002)(4326008)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /MZla/qmvtXE4ZGzRF9ep9IuBdhctSixf17IRJ8F4K3KxsYyrgTTPyIdb2sWTxBQJSzqe/+VNqFHOFy4PLYayQznPSetiJumbC8dcXx5mWXPB3Sl5zCGPQfDHZjCGzXcNrrT+Cdzx9aWnPWoj7R+2gTKFk7AGhVTj8Z4qeWXBJUZYFOkavM1DJ0UbFEHjJQYCJWklEqvnwWeytOSBe+6o5Q+JWlr3fOLRSEawf3v+dSJ7b+eIwteJY1IenBZQXnPTTO+1oZ65jTzgR1r+CbM3b58LlrYZAheJIqus5OP7ecW+ysSLI72f6DUu+xjQwO5Y4SgMUvdi8xbsjn/yyPcCU2dikhTgrWLtI7iVzumLIi4rGnUPoIsGBaTLqssfieqd5uVCgjK+2MgzMd5D3WA5RD8+z8lqYgMluePnemrqLR4fbktYM9TFMfa2coJKRMLIdxSPyNT9cNrditTM+ximf3o0uIRdW90iLMX8UULYtN+RQj2s14VLib3udL+CJ2JzAakcBabJfpaTpTGw8bgxJrZ2zHTr4dW4rYgvPF2fzO369/is5e+q6xs3a9OxWVTfMAsDIMDTOTVz+gKIskUQuAd1cw5gq2wmSkYZxLoZJH9ulTsFyu5ttmqU9VYIXWFv2vGwf3VrjHo4WmLGZlVKOoHTXwcWeXwKN4kk7admAPAzsfLheM2Nus/VJjxNcrIwrIPigppp2Ht2bfkQcPFEnxcC3nl62SgTEOHN9j8UWFesLmXQ8fZ0cXHSwP6K+ExeZnLiJdYENSc92uIdRRTj+BGb0YaSn+INfz1BCuOmzUdn+DV5ZNZBJnbxbysgWMCy/NnJMbjN9lja09/9DKA7xgLJKYskZfVGdZX6qAGv3vVg1Czt6k8JLOMdUBaIf64g5dDP5JCqXvHvuVHBbJSBakJNB0i1B8OS8TovxVYk2hl1/eIBtM0vX8WM3Avo91Jwn6BX37c7zQMnOb+01Nvxp5MC5BTGqVBhzBFE3G/jrKcffWlf2nqHuoOO7MSOsr28hTMo3EmYqIGJrx+5t5jFTZ+wpXXq/EUZV+8FN/yuvhVtCoO46P8DA7QrQgj9SvZ3Xp0OW7PCI3i896UIoaGbSDJrLdCZnT2l8qlVY1DYIxNzTootH/7DJR1FuREv6uzz/B6elU2Iu0nBVcgzz5UPEOSffugXC/AIix+pmxUTXWEFB3C0OzqbUp2zLxivMpl8ObyYTXJFd4iVeDvR/QscRHP5flOtOijptS9bgMzD43rmpQYdKKeofkC9WjvkkKD/NNhjb8SnfY2WmxhxnVoAmEuBJqcg8m9H4e1Iaty5yoVJZuKTVYdIsWwMdBGvEpNKcqWHMvFl7WX1l0Koflsle9yi9kuFoz7vm3NqgwlfTrNVaQPwgQWU8xwKWf32wbQt3ok4BdZwZ0RyjZy8v2SyX8+e4LII3AB05dH8aEsjPHlim7QCgP3YoiwZ/Upj6PMNAhPMoVwWa+/t1bMXSeQWZQE3p2JK/U6uvYQ3vGDyorN8t/2b/61OH1ZfGQKFh+qNDXKRg737eXOq3m4duglOjsI5JqC7MxUVYlve2B1uOkB4akQTlTLcuCKM2gg4Nb1HeyXkfrVLe/ZK4QfqG31wtUxmRMq2yYCyxAuoBCXRVcaicBJw/8K7Him3IPA6OeKfD8j84SNCCg3dQNW96A7gHSQ29si1t/QxgJGHNRmBlANQ/7VFHk+w69JvX1ylj7lMe0kDx+qaxD3Irq0+4sC3A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1d6e609-4667-4de7-4962-08da4d7b22a7 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:28.7957 (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: JKD2Nf2LsJ3u5M0slKEZl/kbCiV60rfODSEl7mtpXfhXLMwkp54TYI6GCtA+aXE9xL9dJNf9U5iPf/jebiU1UQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB2045 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-ORIG-GUID: O8gzUWb-EUAWrE--noMDpyLqWWLrbVmL X-Proofpoint-GUID: O8gzUWb-EUAWrE--noMDpyLqWWLrbVmL 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 | 118 +++++++++++++++++++++++++++++++++++++- 2 files changed, 148 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 3ca6aa2b45..178bd6f8ed 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 @@ -184,6 +264,20 @@ static void vfu_object_machine_done(Notifier *notifier, void *data) } } +/** + * 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(); @@ -202,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)); @@ -241,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: @@ -275,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) @@ -288,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 Mon Jun 13 20:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12880134 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 43007C43334 for ; Mon, 13 Jun 2022 20:39:03 +0000 (UTC) Received: from localhost ([::1]:34758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qpy-0000NP-Aa for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:39:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfY-0008Ms-KX for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:18 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:30724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfW-0001uN-NC for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:16 -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 25DJdgnL014531; Mon, 13 Jun 2022 20:28:02 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=1ZR+Sgedi2tGRBAxcarfr88tCeKGr2svlbOvCPCek2g=; b=fz3jm2GAzc1GLZcrUqH3Od7sIh75a+jjNV5uif38Zs5CI/hSRp2O4PSKnLqNjps1eS01 mQdikCEnlZxANWwWI4KLPMK5rAfEIxTFdWLM4eE2Zo4xEKxd2IJwdCnmjs3c+MZqAPyu 33zeJQKPOdG3NpztEONM+VTanXMNQmK64d9reVvFhTC0HZicXhTCtBXjO0IReesWTCil tldTgaCh8WF/Of+ameYQg7AUNy0u/RcdxXwTO8o0MupQPi7SSGswEGMuW0bYf8NY9huE BTAceB8RYxv5hLclCIrMaKIB4MGaOK+AVoctLjT6siTRVbNGoYNcD0r7e7Z2iD9zzOsJ vA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmkktc3q1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:02 +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 25DKG5SQ007030; Mon, 13 Jun 2022 20:28:01 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d09aj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GCsionLOWhQUdLKoj4VoS3vSOaY5VB/Gy5HOjUUv4gcl/rPVZ5IBR1G9hbFWxy732iA/KHEF1kuX/TStKjhPvo+1AoRA4MsSqICev0krtfeNUPhjfC8EZpRMrhakDoeV6Xh0lTmR/OfhxSaNrMPW32vCfgsWLOV5HeIjU+HdBvUK8EuMU3QX+rab8lk7m94CYBxlYiIl24gel3wHyRqn7nVyvjPWqMoBo6sokNHT0rwi9jAwho2DpFVdToF0OmLogDI5DNb9PhFcZ80fYOlcgCNrHI8UAyijk714lbK+UKLIsmKzrF2Uti6G5uNtxEw4V1jvAM5dKoAl7nsaY1/CzQ== 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=1ZR+Sgedi2tGRBAxcarfr88tCeKGr2svlbOvCPCek2g=; b=ULDqepWFridYyVv3JZjam+EpK9gEIZWDiMKSVcZ93VRJurLCx0Qk4T8dGsLBrKzlb8iyH+szGWRFGCnbt84Rx3uJ4673tpl0eXeT4xM9GtzrqdnH9HHU9FBvSaxk2fQQbHFoc86t3KGcNcMkpYAfZRfadusXpd5qHcTosydRhgDBx9l/mZlK8Ofk8+EztooBvRsbVEWYlhEnM6aE1ZFA9YSLe1uJ4w07XBJwQ749AsyLiQfVIkq2hN/hEDvidTeNRSOSuDFnkOt9SWgJi8owQ8FS9QI3njGJ1NT/3PgxHVLhh2Gcgdrgwq5vE42ih5ZnOODc5Nyv37UX8uNXx7FukA== 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=1ZR+Sgedi2tGRBAxcarfr88tCeKGr2svlbOvCPCek2g=; b=qTlYqzFtSNusyj+FvC8nogOhteRm5+W5sDfQQY2lDvIHSiu1+dt/odlY2wLBwPWvYzUYRo8nbI8OJdsQq4+y1x4aAe9kuzIW874QkBnNtTVvu+hyLfdReEN0i3XF7I/6CUS9eQc3G+4DuDxGvk6xGxihsMP5zxidNJyiiQU8ZAs= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB2045.namprd10.prod.outlook.com (2603:10b6:300:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Mon, 13 Jun 2022 20:27:33 +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.5332.020; Mon, 13 Jun 2022 20:27:33 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 09/14] vfio-user: handle PCI config space accesses Date: Mon, 13 Jun 2022 16:26:29 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: de369c76-1417-47d2-57bc-08da4d7b256b X-MS-TrafficTypeDiagnostic: MWHPR10MB2045: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: MdKkgyimmjNPW7/hkENtisMc2I/rWhWjE6pxWgIlBvQy58GzR1DLOxsjlSaRRlWYPOY5bJ6xfiwNdDTTpn4Cn/1PEyOOn9p+EmiLgEdsSSggi1ALXCeR7eQk3nvPC00S3qACKmU8w4L0VzfAwwnbHf3IH6thtjtSk6XdIoh7+w84BtzYZxXE3k3YZPX1BGHiDcgh1E9PIDPMqzSgJeA62Vv8ckYnt3QBOiXlzLXddnZiwajjxBW9cCPjzbYVf9ydRq/2fsQarxJgvY9nmbY16LQOU/jrfYc5wvhZonlL4oET12IbHrvuqXS0Z0Cl7xqOvnT2kmuZCGW/sPAY6IrT5g2gYZ+Bnk/W+AjhSgUbBw70aeQsO/U4qa6m5rhAbl+20bZpgRprk1v6HbhsOHT4fOLSZNPLY/9p8DUhUfrYIcGcTDM8CnY/VYzpCsd3zaWRKrcZMEXZRF8kvLXK/d90JMYWNJQVUOGG48tdNaVaekT8PrJuLYeHsuchNYTq+cXj+UoClSmSiEQtoe3tmH0wKf82F4yzxjKnJheX0/Oci1PqHPyuTMvCgxYRcf6kLsf2WS+0KQTgAQ03DOV42TRKDwxusunV/YPlxh8z4Wr9G+yyMwrOiyxgM3l3ZJ/wcKztmHDX+YymYw09SFvjWK+JzQrN4O5l6MH1sJMVe3hJL3qSWVwuXle5eiEPH9Xy4af/Ui3WQu5n8Sd2BPjBHc1ydA== 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:(13230016)(366004)(5660300002)(7416002)(508600001)(8936002)(6486002)(66946007)(66556008)(66476007)(26005)(6512007)(2906002)(2616005)(86362001)(6666004)(83380400001)(186003)(6506007)(52116002)(107886003)(38100700002)(36756003)(6916009)(38350700002)(316002)(4326008)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: twdNQHVRJJIl7MAhBRzUgXyN/OJR/O56KirfLdg1X75EXkmxex7cucpDDzFUnrCcF3zwwMwteBWW4gc8/hOLLdqlDBlg0WaOxllzM2M58djZAspVXsoRR+FelzVOfssZrMxdXUS6HdmxQsJhy0KTiKX47OrA0eHYIaJDDwp1T/wENeuUD8gJH2GUFTzsCvjQzBM3AAesRrpTvR0e+MPRCaR62DcpIZVO7QFyVoY/S0jnf2wjEDyxjem3PhwmGL0mt90WjCn6oWplFYSC7AKU/t0LM0AyaItXOacpJyuMHQUYqods1NgwXQtZsbjM4s/R1iuxNPBsrbys2p7+iEQYjuWwLvAcwLD0Rc0VivX4oZVEfLnxcWMRCtF+qDOpyXER7bDtVvvv7Uv4cjzuikwaxhkgJLYhzIR3IWiq4J8aIJ3J6Cp5sIz3ZzXbCBT6nCrzkrpU5AwsE+XtsEAV0uNOniu4AkIUax8RSa1FNdNpFcf4h2pY1bEA/3zURdA6I3cre9vnJ1AJqAXVu4P0gvZFzHR37qa3cGxFwV0DKhCdW31Ew9FFrMtktziVwveTJX5I4vOhdKvH4f/thcZE9PUNDWxuCw9QlqTcRGnwGosw0bzE1ixX8fG10vi2/jgeTURwZPWdQ2c62m4ioIh3z3QcE1oAUqJ8xiomVfXWO9+KRhvstxUgoaKmVyBuNmzJ+A2cR3qOEpKuACk/GhlH7YFj2GbJ0klK4CofUE9+ORndo0HJQqh5oOzh+w9Q/D+ZdHuVDMhMX46wK/2UldcWItIpo9QU9Liv2mm4n4rkpdG34GztYNvlDTHIlW+coD5/wDM2V819MKFe+W2i1zoEVsUs7n/7m3o3jCJj7LgTWY6JV6DCh2uARtX5/h96xojS1Q2yvIq8Tnki6jt2qngdmAKgIYn927hlJJs9o54CnRC1I1owGwToxOfEzYNYpgFhIWkKq8QyJsoga6ka+5dlTHSAeFtM5zZDGpdmetiKccAv+o/txF8eEzrx21fs4Pk/zzdF7Q/QrXHqbqVEtbUvTbZ3MkCze+hXKMbtcpUb9moXmLhLYkAKg7dhN+T9cos1oqg8y6cou3Yb0G6kCrtTpAAZ/DFWawHOrKV0QoqZnaUKWOeDn7DJ0Hb20tYJQ4d6tNYxHpIcEJQju4oPmN4xtR2m2H0W/5+i9sooB3lBoqCjIrOTCvRjNiM/a3Ba2GEcQOjno5+S7ahuQ+s6HRQcRwz8r4OHQiLWNalYxpNzYtWIpcqzC8CmQrrsqXYMU2LlG0zn17tWFlYiIUD2wbn+AtiCgfLwC76/7AsrVFQgFLeuPKZZvksy91YRjgeU5aNArQ8kYzfbmGmKKYj528OKJTeswoPeMcGIaaWB++q3QHwVZWmmzjqsmur6b4fsu7zGQYo3FhBaHJJOYC77Z/jlMVWe/CkupwSlnpKinwZ/A3BR3atfWBeOr8pPosbCbzM+3HABQOrXoy+nzGUTgdwpNPtzQlO72M8XPLTI0/4PULNsopH5El4lUDk+T4/f91etfXyfZwVAJ1HvRflMSVLzH2yGa9j0ymNhXdXuh764oUmR/yh7jSWLQo2f2baCSgQ15hPTejehV/YDkP789WgW+zFFivn1HOuEIpwK9hgvTf79pMVI5jwafeBrCPOmtRQy5Gh0fiz7rFnCX3LfjTLWvObE1IDZnMvHxpHaGwLDFqV+vflVJ9sSunNXgjfcvLysmI69Enofat4VCa9NI6ZizaLgiQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: de369c76-1417-47d2-57bc-08da4d7b256b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:33.2641 (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: 3uS+idQAd6AKs6Unp+ypei1FLvl06ve0zfKfkQyHq3ofVFPXgu2OZG2+VoCz8XyD5CpkaJSBCkhKnOD1JGrZWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB2045 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: 5W4m1-orqrNtO_zDrdSF06kwOmV3vcq3 X-Proofpoint-ORIG-GUID: 5W4m1-orqrNtO_zDrdSF06kwOmV3vcq3 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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 178bd6f8ed..cef473cb98 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 Mon Jun 13 20:26:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12880122 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 8F03EC43334 for ; Mon, 13 Jun 2022 20:35:37 +0000 (UTC) Received: from localhost ([::1]:56788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qme-0004SC-KA for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:35:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfO-0008JC-UE for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:07 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:31760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfM-0001sk-Vo for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:06 -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 25DJdaXt017692; Mon, 13 Jun 2022 20:28:02 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=M0mOea4gCbBlM8Fj9z9DGIpjVUGGhsKIIdnvxnapc4A=; b=0EyzOmeu2hy/2ts3KRm9GQb0NWLj6HOII9eZsMARTLcnhZZrHxCPfCsdZqyG43gwp/yz V2ODF3HtcRT3WV4+arUSgXQcyvn/BYzNxUAfTa+rgFtL7AJsCsHEdcuuxtD0dwuNwEop Zz4r5Y9gUe0htzuHEXiNhwunLJBTxZgdcro56/skxH3vNDndzoDUi2yVmwTPCXFXTmbE rFNQ4Mlun/uIgw9qhbvJpDUsz03Q22Hxf1pKzmgosbkaTzsEVdcIYcutqeWV4DpjCTYF EeP8T4zCmj7aPzuo0+h4XRB9Tw4bkkH+YMjPgUinV8uHhPM1/zDwZLMJnuoZhw8D5yPg TA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhfcm3du-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:02 +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 25DKG5SR007030; Mon, 13 Jun 2022 20:28:01 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d09aj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OVmnOFcbdWJldUyevnQcpQ7eOpL6xY8IAEz84wASpax3otG+2Lgr5DVy1BuxjR7CyHMGuwVqTu1bT/Y6NdwPpniL5vkf56hMUQAV1buyIi6eNidIA/iOP+FmoMrGMcu/vmzrynW3kmNd3I8T2d2jo8MtJIeGeTK7Sm2wdMNZ6i+v5QJGkAU3T3lhAEMDXcBGX067k/Nk1PpVNGgPSxWTXRjdCX6rgjDK4XPhTNe7Ix5L5/d7x1xUxhGQgrWdAse2Li9e+XVfkopatFqlDr6TMwATSrTq2j/XA/duZczoLUXHQ+zrfXQkNkVO45/dc9gJAytcxKGW7h3i/N2LDRYg1A== 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=M0mOea4gCbBlM8Fj9z9DGIpjVUGGhsKIIdnvxnapc4A=; b=hhRq3HtdpX83Tf+9yBOByzzVCcop0zGbuS2ffst3UWar9pC7xfZ/rFE9JXLKVXgvJ7RD021wSmbJRQgCljvnreq8ZUhJiBTOdh+wlHzElfdWGNPlFTMUoE9377XPA2jQcq4qIGF2KBfWPaWukWkbvROfoBaJwFk1W5f+pVWjS5Fwn6/ku4EjW9Z4qs9nEOQhjCOz+U95INf1efTzFShLFPH9KFgnNKgXhOw/84VAgq03FX8pDDbbpLRKO2L2qZ2q2fMkx+EEWLAFAHjsj0gLrWHRxZy/bptwnKsMmbiiUGaWYiAAW979ijVzCchG2motzbjIdV/C8GC6I3+lCFsDjQ== 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=M0mOea4gCbBlM8Fj9z9DGIpjVUGGhsKIIdnvxnapc4A=; b=EngZOuVtwe8ugYxTrxU+7gKUSt8qnh06WkXIQE50/obuxXSiC74/Lmi97sta8accDflvhHzcJ0hN2y73nDMFcL3CjZnoUI1KKwwfVt9DZPiopUBsMPtNenga4u6lXDuRpjWfX8StwuDN+yzJ4VTnySoRMohnCte9fC6ymgqps3w= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB2045.namprd10.prod.outlook.com (2603:10b6:300:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Mon, 13 Jun 2022 20:27:38 +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.5332.020; Mon, 13 Jun 2022 20:27:38 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 10/14] vfio-user: IOMMU support for remote device Date: Mon, 13 Jun 2022 16:26:30 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 6e9c27bc-7e2f-4315-51aa-08da4d7b283b X-MS-TrafficTypeDiagnostic: MWHPR10MB2045: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: 0RMm9z8qFseqRGsvZoIn9uoD26GZ9Lz1yW+NiwJuEJA+DvbSNOM/QKEvUplDwMhGPNp9OTCQNWBCsSyvXz4jn2SctmrgUoy4z6kUvqpq6n7JGcZ2SPqRIQlrMq1r7XSA4OlMjrqLHbo70TEZefBk3dbsX/j+QUd93zl6DfbFcIQVvI9y0zhOJxIbjYAxc6cYAV7kLzly0X2gkZV5RUyCZHT+kMLPPUZ7sIMrMzil4ZDBaWME2xGc8wVo9nkuOSg7UEoPIQwIB0Wz3Qn36RTrYGS6+Ed/w+3z8c+m8GHCQ70Sv4wYxYWn85x6eq0sfKObSLnbd3t8YjuaZS1MC1enjbJaxurHA1+bP/6hts30ze2a2UIIWtqVNEcQyTGDNLoaEpmb4yanuvEpBmpK9fQlnDlHa8HMBY5c341foFvtWTTHp+5bioEOQYq8wBuOqiiXCxLrJFCqjAogB2LcyxGq7i0Y/+5YMc9Kmg6Gp338llYcbSQOvdDRXi7XYR5Wr4QPpG/0+frqR1i5uLsm9B2HuYDryJgkhhAHjfzRhxUib1nyBqwcwVohEceo8EopPYUhBb5tD4Pdj2fBrSv8vEv/cmdqNIkndmOLszdMK5UftjEJMI3XIzyIIjkSeOZSzOPvmfA2NBcxRpK1/I+AGSBIV+rOI1QsLiuJWamqXRkdcKRZm84DW/zFZiunrKMSGGFAYpWe4r90lVcEFjEpncCUcg== 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:(13230016)(366004)(5660300002)(7416002)(508600001)(8936002)(6486002)(66946007)(66556008)(66476007)(26005)(6512007)(2906002)(2616005)(86362001)(6666004)(83380400001)(186003)(6506007)(52116002)(107886003)(38100700002)(36756003)(6916009)(38350700002)(316002)(4326008)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?9EYWH8gtff14Ul+zBo7cZTJpUqbU?= =?utf-8?q?SjpyBygLDam5/IKQ8fYXqLpNgdRI2cvaR2MUkDEHwa2b3y5518HmxE76M+cous1Ex?= =?utf-8?q?iVLLr2fdeDgFa+JHCR16cwu7UdRnvBJtneBhQPCpIOERGyrDsTOJGcKPx3sizbSVL?= =?utf-8?q?BdNDhnMgZvubaJ6vVljGfc/gslnbW54aZpdi93gki5V0jFc8+iLJ5bPljtCjVc+JA?= =?utf-8?q?ETMWrUXkbc6LmH2MgrWat4Bi52n/H9rlwZ9h9nJpZCwJIbWr75C0BfHrgWnXb0Kku?= =?utf-8?q?wgORlo5ZsM5THcrv2X6Ek48Z33/Aop05qtNrMlIKPLfQwnKAb0tGmDama4Gd/KC3T?= =?utf-8?q?xP6DeqGFtV2u8CqGRLYg9P9GeNWeCg3ZhcB4sKNgFAkjgwFwfXUkYGANu+LFsn4fk?= =?utf-8?q?WOI9qZHUYZ/Kml2T3rGfTnRyaHp0lmnUebl+n1zsLnQplyKfb3RnfCRPgQHrA4Ljl?= =?utf-8?q?hcq04zN34+i18S9SH/HoXlPpxUfD+/xMPPeaPKWrzEvbeh0QfNKu9jx5LGkZe31ga?= =?utf-8?q?r+r6ol41YXzbzRXgd9+LsmkPv7zbW3TvPsFibuLgjz5ftqWFbs4kxz1xb5MUQi33/?= =?utf-8?q?BjxA1G7ao8CplMX/7HnTiAetqPiFo711JmZd1sNIc8qz2R6vgaqIel66JYuL4wpR8?= =?utf-8?q?ZZZueGbY+PHCV2f2spzvAG6yGPokNMaeSBRamn1Ez1xdpjFzGil2UP5ZrF+G9PIRp?= =?utf-8?q?2tsn59YAO7m8oSiK8qJJoX4NFYzyREjCvFizQc/fhUuUb9YHmEOSmKHEsZX5XKYXs?= =?utf-8?q?+7u2ARTxmTfFcoCinE9UquzF8X5DGaSGjBVKPfd0S9ecnG6LlJZT7TYt6iTyagKhl?= =?utf-8?q?oSZwg5dTP9hGjLTN9nKdV9FlP/FAdKYf0kQopJRFk2jl9xR5YQjv5ZjBT2kFcmO58?= =?utf-8?q?WHaigAtASguW+E9GLDMyWU6YMJM9W3rKf2u4NieiadBdVUCa9Nmt8ZiyRln79T2H9?= =?utf-8?q?kiYIfr7qwi1VkbHWBVMMIB0KPt5Sqm2AoloOnUXI/o81NR6LFdBgO22/zqZPA0z+J?= =?utf-8?q?BI3i6YCkvvYppI1iEM9esBpT2tDNoyxz56+PwQ2WxlgixNwY8+cCcKUcmahCkMm2A?= =?utf-8?q?QRGibniZ2oL3092zhJfG+cqoUsyCOjY/l3LGb3tiLzo9ZyMNVIIFgPGf85X2SKcXd?= =?utf-8?q?uVcwUYym9eDym8yS3olaeMmjNiT2f5hL8Q+FKKMWEFw/yKTNY6hV7JI2X5PtfsTtf?= =?utf-8?q?2oYLC/iPNzjTakua9tkeY5S858hfYOsdfMf74s6bnWpOJxK3ooQAIs1weMgM/Ipwt?= =?utf-8?q?hWjFvigN/Xigct6juZJrFp+cCanzlftdtLsr2LXIJYo+gGAkNn4F+C2UDM/vrt1ln?= =?utf-8?q?/ni1KuQjNUzMlYNOI75gFwIAnCtB5FWyPQLyy0EbeQ60PuXzBTDQ7lfYNPf2LE2i4?= =?utf-8?q?hIDuVLAyj9pz1jikQAACl5qodotM8hMHlBi568rBMKHRgSfh0Z3rT2MhtsXBaYRHI?= =?utf-8?q?CYbJLLte6mmZjIsq1BI/OmQC0PC2ymwFAmENX0AXn0m8I1DtwzuyZXzcpUrliEfCW?= =?utf-8?q?kFT0NhUeJl40j/fBye+n5r7G9AuchshMvX00UPHGvOXVzn+lteXqD2HUjz94cttrp?= =?utf-8?q?S0U2zNUxF4Y10PsqKd3wechbXu/YXJqZlFFMCJNnJpMl77C2qxilk2Rb6e65KMy2u?= =?utf-8?q?goOT5SOJkMZkAk70dQkOIp8YDdfjZajw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e9c27bc-7e2f-4315-51aa-08da4d7b283b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:38.1388 (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: hmDgMJzCu24FbaEi/1vQh2OYVB5clRyX1UH31TEqbUyhfVQ5faGgITFccgCrIQPaZ70RekI7E9hqW/5hIUbJIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB2045 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-ORIG-GUID: FIdIi7QeKpCfwi56pENjqnmdsuWKriGX X-Proofpoint-GUID: FIdIi7QeKpCfwi56pENjqnmdsuWKriGX 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 6bddfe3197..64f6216379 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3634,6 +3634,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 Mon Jun 13 20:26: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: 12880123 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 9FA18C43334 for ; Mon, 13 Jun 2022 20:36:08 +0000 (UTC) Received: from localhost ([::1]:57208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qn9-0004ji-Kz for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:36:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfd-0008US-PF for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:21 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:58326) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfc-0001v2-02 for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:21 -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 25DJdXZx027265; Mon, 13 Jun 2022 20:28:17 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=v0TtMtb4msHN7hub68kHMLkIaVoFhkiYdKR+pNRRZvw=; b=vcw47KoTz8i59U0YH9+TYMsXt5wBO/GN2+kXWgK+Og1tum/5+LXK1B7ogf3YRvzc6djd RQqbzHkh7QmScVt38qcu1VLzCxJ33Jl1cGkYkpK0Me8ryKFH5Lfw6mwys6QLJ9Ajmman sM5dI5Vu+Lb1X6bTmC5Zitr7XwlX34Z43U0y2vuZdsw2qPU6GFYqmfCqJUW5xlJA5qnV 7eJkbGs5oK9utP4+BNLl0g6rH3/8OkEJNRC/0+P7KEgm/BxKR4k11AaOyTDxHs2v1YJ1 uhdYrlikAbF0M9qJBsZ4E5Um2E/dM3VCHd9Ke8HEuPxvD4jCaHKCjas7Cf7BfEPqUh7s gg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjns42ra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:16 +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 25DKGGHn040826; Mon, 13 Jun 2022 20:28:15 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpc4hr9tc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ENuePLVzJvfuHvHW6uwj4jm9nESX11pQOs/bvhVIADm4drMwyJJznVjz+YrYvLW/v9KN7mcYv5qf9nYqyFdVi/2ojPxn4mZ4KDjVxv4Fj7LrlXvLU1ZFiDp/O/OnJJApN/k2D1ubxPfJDJZl7gSscughsrSVqmNXt+j8aG+PJ3aL3j5+7LXfzlb9pSRfXf8fXp+LJBezOV4UlC5OqVRJy/D+Jt9UHLFu+rUdV1tP/IdlgtKhWpGWjMS8a0bUmxGWAvBahveTnQhvzFrq5GRB/tSnfWoF06iKML/LcheFLrwAxjW97uVUZDPMqLofF8mds0SVWygEvdAahPCMaOKk/g== 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=v0TtMtb4msHN7hub68kHMLkIaVoFhkiYdKR+pNRRZvw=; b=CH9g0mNg7zyxBOKi7h3s8cI9qDrgzoqRVtPHts5R/BRF8pirC3Rmb+6TA92i33w1YKLp0dxM6Smxuldqi5xWhrukNeHQeLOSnB66rN6/oVw5MM1XfFnDds5Yu7KZkegEgxb8K9ai55nYFE0yXM5EcX4myO5xdxg8olyzIP9N5bBipVDe/+WFdrE069dXaI1ivKatzpl4IZoGZ2Rxf+6T0YOgUlsRIUgdETN/604uO4d2glhLxB0OTTCu+mBKW6fMlaTdn441OgdFQtsqPbUdwSby+pKLQSSHdIVvpPbbNZOoT2427wAvWQwJMvffDC4RSQa+BGfkQUBwRAQh3cDC4w== 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=v0TtMtb4msHN7hub68kHMLkIaVoFhkiYdKR+pNRRZvw=; b=gwM1fXINTIrgWVm8yxBq6NCD1CERiQth88wWUfuZYSqcs0oQSthMr/ydPvgGiMn7DB05HAuJLgHQiZHB9JBYbYDgx5cSH1JaIKbyTJGrpYrT7s1KF2myuoqaX7haFrvfBxtYhjXu/BFpy61M0VPedgfLeYBHtJpCqppxipv2DKs= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by BN6PR10MB1585.namprd10.prod.outlook.com (2603:10b6:404:49::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13; Mon, 13 Jun 2022 20:27:43 +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.5332.020; Mon, 13 Jun 2022 20:27:43 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 11/14] vfio-user: handle DMA mappings Date: Mon, 13 Jun 2022 16:26:31 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 34370228-f813-4227-84f0-08da4d7b2b25 X-MS-TrafficTypeDiagnostic: BN6PR10MB1585: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: TmEFBK/Aec0UQUhjc/S/zivsVuyoe/xZB/m0MbADUW1COLJto8OHCNW/4r58NjmcxyZ785/ByPqgv13w3fJH/tWD99QlLaZX0PgFlQ699YFWv+8L/uPLukscrAVftIX5voABlWiEUjDHdxNNOPgq4St707hROkcbWhi7xsnS7DJnGCJUxVIH2SGkd/0KqdkR49UWVw+rYKRGftoaHz+YM2UHrWtNq82VaX2iIwvU8fujd1r1oGb1xWvQ0e3E6mW+upS7nVp+Tk372tvv/DQWsiUcIQnCz1wGpX8wLLT6e5MsLq3jkZ5m66FcMqdqmjoCB/S4k0zGWQJG/YemZgh0gJ7d4nE6oIL+5BsBhBjVNURMsNJh0SwbQHgkl3v1g4T3JJlYCazwxeRdjVMReR0qa+hVGAXvNzNBPCruM/S+V2BX04UxPZRoilGKHAJb6EwNXAF9wSjt3XdH+Cr0GTmaD16v3KDfnJ1QdIgsYdEwTXCBKXc5DBQmv2vXInYc5HwDupGwXjOQm8JkTs37st7LHjd1o8mAhLRS8Y4Bzd7K8xDFV6rsE6TzH4Urdr+pXYst8eJMUXiklmvYOFRJ8/uH1AZ8xhUG+wO9ZXeDAHoyVJ7J87F/NN+KS+/20THKmrlIULDeP7iXJ0Gl1k1IoH/B2WgPHm+uRCep/BdA7IpBQZG0zTTuT7eTPVZ8Nz8K2L7l589asWSevjFMA2OvYsd/dQ== 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:(13230016)(366004)(38350700002)(38100700002)(6916009)(316002)(36756003)(6506007)(52116002)(86362001)(26005)(66476007)(66556008)(5660300002)(66946007)(107886003)(2906002)(2616005)(8936002)(508600001)(6512007)(6486002)(6666004)(83380400001)(8676002)(4326008)(7416002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kRox2oVqM8bIqSPHAn1UiME8iC2JC47v+w+BK6XBPoaP4aCqucEVBzlSjV3bvvXC19dDd+hWtT1z9y7mZyt3N7ekgt+IhO/KP7DL81DwwlHaF6TDmonMl/kNtfxKmvnUFqvwX5aZBrl2PWu9RZcs+vPdUjLy195jfIaJLNvWCDCxYkMbxX+AqFo1i/co8Dp8GoVRFMycJQLmr/gjEHCUaWQAdSCs62ZAIxYibAbw6V8sbZHIWDpq9vxTf5BrqOpReGdB0l6q07F6mAkLcDMRcQmEgegknvUqf5lnNieHEZzzuakO+X5ICHf6hOyvREyCV6u5+qiTJZViYLEklUbWXVh1+OYLmjNU4YqR+ZIgtCW3WPMiYicR6ubGVdlsKMtCipZmi2tJv2zj4LHhjyAQsT7VQSGRFoH0wWCD8Y8cYfLrsnpxl7A/Zws6nuz4k7fuLnvt8JbzBl7HACLusRdy9O2NwdggQYQOgXBh7fwhQ7KIN9CPN9rRrrLYD8IWZK4t5KIToXx/Che8rQorpaMzgmkxaqba3XSfnCzElxR4RfIUUuNEQpqazdCD1jmg7UbNxoiq+qC9WEk7dhV7DvKLAb3T/tcYy8jaTHM8pzYiLlnrmGcEyFcN9KPe640r3gKQ5FKrRlcZQxKx8Ei+UkSOWL8N/W3HaDRS9YL3uAb+4m4VHA2IpdBJkcRFlpiQxAFZ8jm1KMOexhBKdXyj8I3VyjATBUNw4LMRoe0Ouhk7FD+386v4WPvJfyzM58VF1renfpNSfvfuoLsfJFksiBKmDgsvceDqezU7PO8RzXv1+1FqA9f8eTMW3Eaxo6mgjqqmBdJBjlytR83CZKK/s3FHSYLak5a5F12nqhMKUy00eqQxdEGCU9V18iPl+uuw62MvtpQi9mfQHf6J7KW5Y3AMr2+lXFSYezn5pVlF6i97d3HkxrnODdHsDGy6dBJdiHuxrdHbX/MB5Kptd/wUdvOLAS++YvHU5eXJ6loBxSIKVuebFxHZXIK4Z9TcJfB6FK3djrmTTW0ebrIwU4gUKJ4/P2jWsqNQ1ETxm6mC/GlvSCaOBGadVsUoWe1wfLmcveU141deeAG6oLt7f2atjKjtWT9scDxwE2mnaNXMDu7JXYuzF1a5pCdnRhDCR6TiFHj4uPvKBG3c5nWkNQZufV5X7ACxy8IdEE5RFaYlW3fft0lqUZCDQ4zDeUb1QrV0lqTorfvfkiuZa6vpozKgSkPQkCkTHKDPgc7nOHCy8e4LENLayMmMzwOgp8aJ6WK2e8WxabOHH0Vd3djC2FwR1QrifYhVMgQVtpi8bPBOBWiNjkqMe3jSwP8oI/wGebcmDmL8t3bsmdjQm4458vlXoYx+gxKCq8Q22KbX5V/UEFx9TqDBjDSfmfvDYQ3jsR/k4Ti/T/g2EJSHZ3ky1dGpSdCPT7fj+ew0/axnbpqcBi2ZkQQ0fzll+UxyqTGs/hZPJS8bb9zgj6oq8j9C9DXIJANHGqttcZH8P+Nd6P8v0e8EKqBxhsJJ1IGVtC8UBdNAcremEhKuLY02owNHMWHsClqR9Jl5tbKfahKKhUGscNT5C5PFruBLwmHJv805YfoHPQaRakAufbhWR0+jIUy6If4xdJTdm68F22xkXZXbvKmVrTh48KCxkqgggW/pqoElFluKun+5D4RloeW+JvzztZ880IokNbqBK/kMko98PnP5XlU6o7U4wCsx875csYZcXa8yz7nAZKLausPP34FrBvc1Yw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34370228-f813-4227-84f0-08da4d7b2b25 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:42.9979 (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: B6rWfB8tDfa9jMjCUOKu2CMr7mXwTc6KIeaFNNGyAtExmYTZfL4z8Yr06OINnP+UmULCpGR3VZG8lhXx+/J4Mw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR10MB1585 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: 7yox3AYuyQzf63kBRIcQ-ckausqGw7gr X-Proofpoint-ORIG-GUID: 7yox3AYuyQzf63kBRIcQ-ckausqGw7gr 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 cef473cb98..7b21f77052 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 Mon Jun 13 20:26: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: 12880124 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 6EF4FC433EF for ; Mon, 13 Jun 2022 20:37:46 +0000 (UTC) Received: from localhost ([::1]:58772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qoj-0005vh-HG for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:37:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfZ-0008Mt-Qi for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:18 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:32754) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfX-0001uU-Ij for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:17 -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 25DJXYlU025660; Mon, 13 Jun 2022 20:28:04 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=gvk5wPP/GPdxf1Y112oPgycOePUd1nl9QNDGaClKGfg=; b=gCu0BSbI2LMc5WgOIWfEAGit7QePEvlRoO4IKzuNgxacvOLjsBggixcDh1lmvvyIXDkk NZwF9ybMca6TzCbXvTrekLn5DErxTAsdsG0BonS63tQAzdkPGR8zI6YkN9CL1rSzmLEC dSJq+bUezmPBGbJY1xg6sokJ0rnsTHuIWd66frKq4+r0rXZcpSrkqoLFve5yqt6nzu0k 5Vy2dHTGiPuBu51Nox1Aun63v6xF+ZcVphocbWvCUx5CFSxDMGDsg/ez6aA6bur5LHvK SEEd/f3jykxpFz+VPTnb4G2fw0swiiAJJxDC1K4HIotC/caoE2yI0rTkIOH8+tIB5iwG 6g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjx9c1ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:03 +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 25DKG5SS007030; Mon, 13 Jun 2022 20:28:02 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d09aj-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CetYI68PEBpQh3eh+SbOAtSm73fRELF98yB0j+Xjn6OHLSG09yKOSnafSQPHBoaLPmtr0KQDRqNJ1stJ0NipgrbW3FWgjFY7YLRwegBAtj9qxsvp6SwncdmctU6xesGtrz7x/mBI4dfQLl5FMM4ugi234MVHt6t2+oDrXgRylrRIGaBwg0wQVXfw+74loOG16GJ+9HfRkxzwVLjIKqvZpuqA1iHnHwb0VxfUJ69kJ9I7Jg6+xS5gfZ7u03KPGdXR1VSRKJ3gVVOU/qyjPSIA2Js0BZD2UcFpSDzQaxlSNn5fjijKlyuhWybXuYVd9XTteYbAek80LTL5Dg9Wrm5eQA== 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=gvk5wPP/GPdxf1Y112oPgycOePUd1nl9QNDGaClKGfg=; b=dtUWAMFtKhlT2TxRMMZNksrkcqI8X91l9BLJhMG9Vtavb6KQVc4UcMU6RFI7/MKXxTo88ie5ANIxU5KXzSucExgLPdzn3gPubk7dytxOaQvltzRlwCkxZJ1bkJekT3Xv13+3hVOLaaaCUKnbB5Z6JAVxU0N1MeGf46mdSveVg+L7egjqCNtIUiVZ7P8iEdc22qyyVTRa5D73fhmjbsHfV6hr+pKmN1KhboMtxAxRrWYsFxWdLx6jRngQKgnWfb1kyRcU27vLfDRBGWC5DE0e1NRp1gTppbCQrEg6gDktWpzZ7qUooRZUinUNRa/xP3ExbUkSaSblZxc8/Wk9h0rfRA== 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=gvk5wPP/GPdxf1Y112oPgycOePUd1nl9QNDGaClKGfg=; b=kCI8ETKJG1HWmvQrpSAoLuGDze6Anr1cdbQwJkjrjtMRz7AI7LjH0ckevgb+LpG0RRjIcR2T1de5xSlk7c8+OAnUqJpeqhum8ETOZXYeFLHRws0yR9oDymg5y3GfqYnqGSo+qNS3pOxnfW9/dLG8XKHpnmJbsAFVzdP+szPyY3o= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB2045.namprd10.prod.outlook.com (2603:10b6:300:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Mon, 13 Jun 2022 20:27:48 +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.5332.020; Mon, 13 Jun 2022 20:27:48 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 12/14] vfio-user: handle PCI BAR accesses Date: Mon, 13 Jun 2022 16:26:32 -0400 Message-Id: <3373e10b5be5f42846f0632d4382466e1698c505.1655151679.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 88314628-f741-4d41-53f6-08da4d7b2e2c X-MS-TrafficTypeDiagnostic: MWHPR10MB2045: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: rhb8Tws46Wox7SMrpE/J65oi6/EfymVqHO7aoYDAmuqFtIH8E8XRIy1IQhiJPbTx4MXujR5OzdN1g6sbpCrUrcVeSwiRKHwXtfTQzRPTQuXFjdyBem1XsfGPdEyBtwxHa/P4ZzG/VRHxGXTXK693VWmM/4wqqLA6dkBcZ274r33f6i5Ugbzd71EC+EASIoAbSGvzWnuhkcoytzpTWFKfjyaSbSBdCNNnG/awSRXFzqAmV3X/W8nnfX9jY6/je/huY42cQnvkN0RXTYERnE2CAC4OvHjLcQ9nCUeNNFMZpL0iZnBpFKRKj4Rxti3y5wY3uVATYr/Lt0NvQoFyYoKB1xAYliAAL7Ce5xir6xE52H9JBAqgXICJmLH0iSEWlzaTMkJDqpR+8MZ16WpzpCeYQDm7bJqlpPFv3vY3SxxjaEUd6VwjJri9zOHqNbWAVhEKUZSMrquAIQnTNEbgywHDs2VGPKIDFZ/DA7O37j4nXg1fIXFuY2576LFTZwMvflDGExasPpdBXfEEEfHoAERwWThVslqSuahGy/cH8mKjVbepsMMSxOBSFRR6gvIGoJDzYf0spzRXT9RB89xdPSoeYRoowclnyDBGpNHCb2EAIgsY1UpBtq9tOM5Nb8CUb9ShE7Ma1oJZCVffbA8JIxLLUnpgBVezfv2Lm+fOqX5EKzVjmMdDin1pwxW2Hcr+bRfkNtGZ+wkiaArThygF3WQ1vA== 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:(13230016)(366004)(5660300002)(7416002)(508600001)(8936002)(6486002)(66946007)(66556008)(66476007)(26005)(6512007)(2906002)(2616005)(86362001)(6666004)(83380400001)(186003)(6506007)(52116002)(107886003)(38100700002)(36756003)(6916009)(38350700002)(316002)(4326008)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lmwylXoAbns2X36OhOdwRzwFXmx3LVfG7scIPh8hkHNzi21V9+EltiTIQSTCUN6S1OXEpTNyarlPBQfsRnip5XfutnU4ja0di2DxjVYeGU6rEMkrIJjO4fburBmdqjLkIii6ccYxvF2BskhLCb138coKfaw2VKkE/KuGVWa9+OwK6gJvcOkt4mtys1ObxENtQishIh5IXgXvRWBX4TAhjMbQpDaQ4XiOPP0gzfpDSThQTSnaI4n3SCU15e1ILOHdb2Z4Cx+ak/nJADseU4kCpfs8qAg9St6G8qZNvf9Xvi5wy3M7WRgHAauOnQs8wC+yF41+9ZLe2yMeyvNBTnP8WPL8g8X9kXEUsNsRcLvDE4k72ByXPqLUZZdbanYQ14YEDXkmttTuqMxF5QMzwS4wCenlRcwZa9QF/dFmeYeS6TpHScRpPUDg6NA70Mp5O1W1sz/GEycIrRY+oTvIST31HZ39UA1wtQUzSK8QGdK+s4448z9wQaP+CkzHkf4Xd/gDKxNgirCvh2+KPbm3/+lZM8ZwHAc/hfSVJSczT5Q18o6QozlGDMaNRwdcj3c6Ft8RhR+2ARv8KNXR3DMSUORxjnFR8dnpaLHQgOvCOhi4TLFbCzSUBhCv/GLkHesfox75fgch6EBJCfpRrGOaSxPS3z00DYNhaqKiyQAvjxeJmGviuTdcJXNm7gmOJx+Cm+p67Aa1vmQSG1ft2u6O2TgC2JkXMWll4vb323IQJ237jpPJ+Zpxijk9du2n9N9GcuV1MZhHBty7rh3ss8UWa/9IP/Rc2pbC6GP1PYHEfwt6nYit9p6xBuLp/jFrtdA4TTGN6Zbcwi0aKRGeWRgGxjNXmiDf4MOqhWo5ckf2tDR/U1JsgcPClsExkhlsGOIxboCx9Y4UG+oi5gEHJChjZv4fXQ1WfIyED7HNZBqQ4IF27tI5LH25T3MKe0/icfR12shSVtrmSm16sXQdiZyEKCpdhg/QjgbfSaFgq1H99W2G2L9L9sisMf1T7HU6ghYE+j8vSpMR6x+ON6j5VQeMXB8RNE/ZSfjOM5h5qSi5vUGt1O+o5LUe8bfS3K7AMoLO3oISgG7jdgQIw46cQIdDO2fV74b4XLYNn4P41xV8xEHPmJDa1RjeSe+VU7KJXzThKwPzYlHMMiDQ+relOqLF4iHaFIEgTpjZgqkYqDdGnm8jecDtN2y91xOOpY0SyRpsyBldr1ZGIevTQL7zToCTXkZgsanzmeUmQlQI621tGjftzVTQxPjeIXBNSoO3uL4kbR4JZwutqKLG0miGx9bMRX8buJo2PGzHwSbZjWJEHeC08Bi5cvxae5FZhNEojzTtAuijoJ0Tt9jDJmhr9zVB8WXaeFicaBU2lcLVA8pA1tRdY/H3GULnqT3aaB1sMNx89VdNjSCZmUXTQcob51kulSBKL1rcn08Uz/xqkOaupnVgSg6xh8VTLL1iURfbm6Zx+qcfig75OJKlyd4SD1ANj5OcBzBmy9ZjJCBjEeMpojrWnUJkh++sdP2KK4yIAGOJmnbUmm+HRw+9co+qsS7YrnxGABmvuEvnsoFUKjpDbvlknd6QjfVoXv06tF5CCDAdP3b763Mj+ErCQ9KcHwuzKR+RbdBxAIs8bQEQLC+5TF81WkoRW2WAEp80P9LNuDdocx7Z60htC3RQP+zCXdcECk27rF5SWJVXmHyYf6X+7NGfr/B2qhXx+FCNbdVx3EHPk22+731NK07CxI4+EHonU6YF8Q== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88314628-f741-4d41-53f6-08da4d7b2e2c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:48.7787 (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: rNatQO1dkcNwgRCZaZ5esmP+/PrJXYHCocJrJtlZAHBHbddWWqsg9a4mYUdYLUCmfHt9BqbyAIHk4af8uCWXAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB2045 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-ORIG-GUID: 2dJhxoAGVqxMzxRSy8MS4aInDKdud94p X-Proofpoint-GUID: 2dJhxoAGVqxMzxRSy8MS4aInDKdud94p Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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" 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 7b21f77052..dd760a99e2 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 Mon Jun 13 20:26: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: 12880116 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 42B2CC433EF for ; Mon, 13 Jun 2022 20:32:24 +0000 (UTC) Received: from localhost ([::1]:49198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qjX-0007mp-4j for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:32:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfR-0008Kj-A9 for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:10 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:33388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfN-0001so-GX for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:09 -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 25DJdXZr027265; Mon, 13 Jun 2022 20:28: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=JoxHVgeQ64hXyYidg5FqzuQdopwTF9sDDSMW1Pc5DxA=; b=0Q1LntlIqWf6tX1o2uWWFXWFfU4RqEVIxwe7SPt3AoVaTlKt7PhX7C2vU8k3hncHLuLS kOn8OlO2a1p1yzfkpolw+6jEvuey/tUkeNlZKP6cwdGkUUdaTgloSkK4o9QGsynYPLEy MtTqm0u/EOA4JjuTbX2S87b2dwK7M17YjhpEp81SWAbIph45B13wj8/oLs91TsgGaqNo GuwPm8gecMnogpyPWLeQ9845s0uIwTLw8FMd6c90gpZcyDhkGmLBnclj4KsjqAxvf0Q9 3QZ2Lkub21GIH3WyD6A2u7F4zehJzReSh8A2d/e25jx3rBMw+Lj32F2avNYWA2rQD7o3 kw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjns42qv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:03 +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 25DKG5ST007030; Mon, 13 Jun 2022 20:28:02 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d09aj-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sj/1tq59Oell83tM4FZIghyumKVSnE1tw+iMimiPpIB2axjz7l4AnBQdvv3XgAga2Oe/uwCxAUFkCb5BNyVIeD4JnxcafmQCK1VsXwEHthEeqzFFRD6+pGSaqz/u239ssOC6aMYdtHZIzfQJ9/lYxdiy5TNJbWRj6cx6Wk/Rm3H17snaVVQEU6Kq65XTtximiqBMs+tv2IaqAzJyzIf2sDKRlqZZYSKtOjT2g9jsV1C4MauoEbVYerWoXR0q0wGBWi6qKe2tG7Tox7ul+AyXeYHy8Xo7eE3DrNAJIkEIPISFggJNwfh5x/7xuZT6qZvqY/bc39oFhIAGXo8uXHu6QA== 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=JoxHVgeQ64hXyYidg5FqzuQdopwTF9sDDSMW1Pc5DxA=; b=BJJCwfuWkpSV0ccSNmcQ1jLX7HAxgSu4+zjt9DBfkuYdXCvdPBgFLojeiftdb165UAKpy9jNed6pcdAZsvX3+CNqFcop/LPDnjW7qq2huQDm7qpLeQeOBscGHdimjk0adlTDZMADrBfZJsX8yz7pHsfavM/icfNAf1v4dFLvA+crGxWSR1J1EML/mf//8vbobO3GKEZtyrwN2+6s18/B8HK6ltoTD4Zo534uwRlvI4hxUZZjqZZdKibKCs2zB3LfY9zrfweT/toJLHWT6h+f7BI+kU30Ho/ISlfCTzavT7NYOF0mz9pdHw4FMt+T0SCHhEIRI7+5hMz2pztvcciUzg== 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=JoxHVgeQ64hXyYidg5FqzuQdopwTF9sDDSMW1Pc5DxA=; b=eO/wLHTFivwayNnON9SIltJJWgZsovLQUX3zMPbRn4AfzvvBnMYoPJLlEcVNpd+KkGKoYwuU17qj3IlpERi+UTcbsJ7Sy4fiGzCykQXjeyn26UqiPyC5s/wy8SOOXQ0yhFQS1pwLJzhbUFBjujdpbBYTo8CAT+HxkGap4qopOn4= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB2045.namprd10.prod.outlook.com (2603:10b6:300:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Mon, 13 Jun 2022 20:27:53 +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.5332.020; Mon, 13 Jun 2022 20:27:53 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 13/14] vfio-user: handle device interrupts Date: Mon, 13 Jun 2022 16:26:33 -0400 Message-Id: <9523479eaafe050677f4de2af5dd0df18c27cfd9.1655151679.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 36478914-08b6-4708-5c60-08da4d7b314d X-MS-TrafficTypeDiagnostic: MWHPR10MB2045: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: K+p98nS2AYfoBi+s76yO4VGpU20Btq58RmGMpZgjO88/QSrT1ZYzj0ORC7SfHi5+VUsrr0UvKKaQLMxcXvAijc0942wLV7TzY5GK1T3kZoXJflQdRlbKnDrg9qx/RVEjmcI5DNUAxty8+qUdxnDE6Bo1yUlO4tLisgll76Wcqyytt/12nWAIGRG76FCDGBT1jQfOfjAuV53huSISHnAV9PKwklP3GWwj85fwdMvljWpVliBssfEMWEfytlQ3ASOEGKmdK5W/HWG22d3iktcFGd23g4aPIUGn210lM8tyaJxTUVB3VDqENIfMddcKf23A89AWdjh1Im4ta95OkKLlP3nKVGdXV45fhK41VETKluSaSurEDX/wRAb4JbKmA7lJw5P16H26FTEQ7yUAdZqZo0ofLDZE6XVcvSkwvFlr18N66pPfMJjLKbm5yteIGqvDg3ZIIZ1Aa6cHr0nVMGVD+axmqEdFqCyF6sjBe1dVyocmwhJllK8S/HX4z8yhOegQLS6P3FGw2yCG6sn65RMoRaGAOcMC8QtI4U/vVfEWMaDgAsJMnA2gFxf7tOBzhd1fttNsyFqutfwyenz6GNNjkF1fqDn+EGQdK4QKiqN7zzRYNMgoN/OJQ2CdzjoAzMXv0uMMJ6sf9kK3jDAA8E4r87nKPknX+dEBWz3I2VH5CrCusoUqBqbcCbp0TXmqgPPEK4dHtymbBnKz88e4pGpt0w== 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:(13230016)(366004)(5660300002)(7416002)(30864003)(508600001)(8936002)(6486002)(66946007)(66556008)(66476007)(26005)(6512007)(2906002)(2616005)(86362001)(6666004)(83380400001)(186003)(6506007)(52116002)(107886003)(38100700002)(36756003)(6916009)(38350700002)(316002)(4326008)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GqDwcsals/Dv8XnI4YVi+z4FpTyydpssPsNc0LOpOctsphKzuzfgsX1WRYCxX6l3mwMh4KvGWoAHz89wGAQlGSAxldF9hHlEKy56O2WMS0hWvQ7M+idFuiL6J5HSsfSYdjzPPT+YDJxkih99I3aH8vmBl7GH8z/viwyGqQg9SMX2rCgk7bW4Jtu9kDMSr54A9KHzvotjdnAtGxxgOxVMUBcZjfMWz/OKNlmBCcg4/TRzOn5pLIafEORHCoKfT8lYHMeSz+IwkPcjQDgSzSyyspKj9QpRYIhig4/DwT9HrxonUpER7u+ZCyKYWJ82zXnZy7nGwW9d14HtvTdygAECRsW/2+5fQDWyUtFeVCNp7n5jpIuE/C72/uoQU/q+o+CJGjL539hE4LiW4bGORafxTQTJmQgZmqgG+AEQZKHOu6M93mCLD+kUH5xy6OzGn1X9Ck4yLiHCz6zQvhdfY+fOpr1dWcq1tS135QbB8zWcaCrpzY3++Md4i1kQAa30NMsU1j2arE6RWrS1bOLUPHe83tTOxPS+CGiGqNrrtcnV8dUw3k/hpKaYawHTazIVt8ynTK9sSSg9bn45ieqXOmhkwrvrcvIrm7lwSk+5CHzg1nbIMV/uKIkDvGA7w5LfP2U0mtvDR9Fe7uD65Kx35AXVBaVul8wo/EEKFn67LetpxrCiM7SistiQTa2FWPYLfN0RYGQvTJX2yFfT/MVUkK48PWtpthYoLIWw3Ou4B4SaiNCMcf3F18WQDZbUxJuNQGmqiwVrnrwdZYrI0MpYtNd0EtWt8qmzy6dQ6XbUvlc752c5GANgHw+RCIPoUFRStftpv5E3Jju2LmvlywfzKkvPWvk9/JN2E/i03K1dpUjNLsgUlc0dYtw9stJ2dIqD9RAn7nl1HMYKshUR+viKI9nejogEAZMbzoKelv5UENvrlsTaFmklzLbMWrUSSp7Kt/on46LzoPZBF8GWBgDA74NlKXW0Qw0zTUGjx9GYYXklCjicX3931zZYhyzNN10RdUVrfm/hIQxNxBmq+KgB/LWK634TxDigTFcFvVcS2UjMXwerkBqlLWWT/aLW+Z2d0CI2CB6SUb0yimW/GXaXe644azxBFOhs/TMvdtnCDRi1ulyr3KXaPSs+hUmJDBMBmlnVZQ/KV5xsxXzB+r/hNsZT3WYlIMRtNGXd0nMc6lbRQmJK7PQQ5e6vZHQAB+MAclJoNIuTectk51BRQx+zOvyCR63NCeifl7devtos+u/Xekd+L5JD1DRe1zXaQWYDqJoyNxI2sjDaQKCHuMIDUBoSMjRzbF3pPvQiLofVloVGVzh8G1Nw7wHR65I0rblsHEnPTFiZutCqSPO0F8w6uKjALDRTPoyQI7zCfxBc4sILu2Ni920E6DvDqV6PuApAcLhTI93lMdH1d7b+Uxaz7YJscC1BaQ64MytQBMgEEMzPly2iSaEexO406zFk3bG1gX6CraJokpQB9oawL3E3zjrlTaFyZ1boYbaJJ+RMW2m37CBHnjtUzXuvxqWiWHAlai9ORxKC5bApqaS8wNyrp2CTLwbfiiPKmd9/SGOwKCBGT5seSbqYrwymYSFMDo7FQv4Tefz7xXhFrfIdp3UPL214+mQhBf8I79eoFVSprW9G3O2eEEOcNGABu3020nasfx8mVY615rb2G8pg+1xZbdv2NSva6ZBH3Jk2KOQlcWmA9y+hVUQ5HNYqrTCGYkr2AOvtS7HQHguemUrTvwDNsagRNQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36478914-08b6-4708-5c60-08da4d7b314d X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:53.6221 (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: d8WUx8HDceG+a9dwYZHCYGn+ht5cd/vYi3x+rPsbKv4fMW8paetcCu3SUBgzTNZr8KX7HimFuhpxmpZU1VU+PQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB2045 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-GUID: 3px6BrBcXPzx819K_ZymSmOFwUmilFPE X-Proofpoint-ORIG-GUID: 3px6BrBcXPzx819K_ZymSmOFwUmilFPE 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" 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 --- include/hw/pci/msi.h | 1 + include/hw/pci/msix.h | 1 + include/hw/pci/pci.h | 13 +++ include/hw/remote/vfio-user-obj.h | 6 ++ hw/pci/msi.c | 49 +++++++-- hw/pci/msix.c | 35 ++++++- hw/pci/pci.c | 13 +++ hw/remote/machine.c | 14 ++- hw/remote/vfio-user-obj.c | 167 ++++++++++++++++++++++++++++++ stubs/vfio-user-obj.c | 6 ++ MAINTAINERS | 1 + hw/remote/trace-events | 1 + stubs/meson.build | 1 + 13 files changed, 297 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/msi.h b/include/hw/pci/msi.h index 4087688486..58aa576215 100644 --- a/include/hw/pci/msi.h +++ b/include/hw/pci/msi.h @@ -43,6 +43,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector); void msi_send_message(PCIDevice *dev, MSIMessage msg); void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len); unsigned int msi_nr_vectors_allocated(const PCIDevice *dev); +void msi_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp); static inline bool msi_present(const PCIDevice *dev) { diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h index 4c4a60c739..4f1cda0ebe 100644 --- a/include/hw/pci/msix.h +++ b/include/hw/pci/msix.h @@ -36,6 +36,7 @@ void msix_clr_pending(PCIDevice *dev, int vector); int msix_vector_use(PCIDevice *dev, unsigned vector); void msix_vector_unuse(PCIDevice *dev, unsigned vector); void msix_unuse_all_vectors(PCIDevice *dev); +void msix_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp); void msix_notify(PCIDevice *dev, unsigned vector); 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..5c471b9616 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"); } @@ -307,6 +315,39 @@ bool msi_is_masked(const PCIDevice *dev, unsigned int vector) return mask & (1U << vector); } +void msi_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp) +{ + ERRP_GUARD(); + uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); + bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; + uint32_t irq_state, vector_mask, pending; + + if (vector > PCI_MSI_VECTORS_MAX) { + error_setg(errp, "msi: vector %d not allocated. max vector is %d", + vector, PCI_MSI_VECTORS_MAX); + return; + } + + vector_mask = (1U << vector); + + irq_state = pci_get_long(dev->config + msi_mask_off(dev, msi64bit)); + + if (mask) { + irq_state |= vector_mask; + } else { + irq_state &= ~vector_mask; + } + + pci_set_long(dev->config + msi_mask_off(dev, msi64bit), irq_state); + + pending = pci_get_long(dev->config + msi_pending_off(dev, msi64bit)); + if (!mask && (pending & vector_mask)) { + pending &= ~vector_mask; + pci_set_long(dev->config + msi_pending_off(dev, msi64bit), pending); + msi_notify(dev, vector); + } +} + void msi_notify(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); @@ -334,11 +375,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..1e381a9813 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. @@ -131,6 +136,31 @@ static void msix_handle_mask_update(PCIDevice *dev, int vector, bool was_masked) } } +void msix_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp) +{ + ERRP_GUARD(); + unsigned offset; + bool was_masked; + + if (vector > dev->msix_entries_nr) { + error_setg(errp, "msix: vector %d not allocated. max vector is %d", + vector, dev->msix_entries_nr); + return; + } + + offset = vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL; + + was_masked = msix_is_masked(dev, vector); + + if (mask) { + dev->msix_table[offset] |= PCI_MSIX_ENTRY_CTRL_MASKBIT; + } else { + dev->msix_table[offset] &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT; + } + + msix_handle_mask_update(dev, vector, was_masked); +} + static bool msix_masked(PCIDevice *dev) { return dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK; @@ -344,6 +374,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 +461,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 6e7015329c..2f450f6a72 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 dd760a99e2..5ecdec06f6 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,155 @@ 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 void vfu_msix_irq_state(vfu_ctx_t *vfu_ctx, uint32_t start, + uint32_t count, bool mask) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + Error *err = NULL; + uint32_t vector; + + for (vector = start; vector < count; vector++) { + msix_set_mask(o->pci_dev, vector, mask, &err); + if (err) { + VFU_OBJECT_ERROR(o, "vfu: %s: %s", o->device, + error_get_pretty(err)); + error_free(err); + err = NULL; + } + } +} + +static void vfu_msi_irq_state(vfu_ctx_t *vfu_ctx, uint32_t start, + uint32_t count, bool mask) +{ + VfuObject *o = vfu_get_private(vfu_ctx); + Error *err = NULL; + uint32_t vector; + + for (vector = start; vector < count; vector++) { + msi_set_mask(o->pci_dev, vector, mask, &err); + if (err) { + VFU_OBJECT_ERROR(o, "vfu: %s: %s", o->device, + error_get_pretty(err)); + error_free(err); + err = NULL; + } + } +} + +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)); + vfu_setup_irq_state_callback(vfu_ctx, VFU_DEV_MSIX_IRQ, + &vfu_msix_irq_state); + } 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)); + vfu_setup_irq_state_callback(vfu_ctx, VFU_DEV_MSI_IRQ, + &vfu_msi_irq_state); + } + + 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) +{ + int bus_num = pci_bus_num(pci_bus); + int max_bdf = PCI_BUILD_BDF(bus_num, PCI_DEVFN_MAX - 1); + + pci_bus_irqs(pci_bus, vfu_object_set_irq, vfu_object_map_irq, pci_bus, + max_bdf); +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -632,6 +788,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 +820,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 +881,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 64f6216379..29a7f36e41 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3634,6 +3634,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 Mon Jun 13 20:26:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12880135 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 D4839C43334 for ; Mon, 13 Jun 2022 20:39:49 +0000 (UTC) Received: from localhost ([::1]:36020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0qqi-0001Di-S4 for qemu-devel@archiver.kernel.org; Mon, 13 Jun 2022 16:39:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfZ-0008Mu-UX for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:18 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:33904) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0qfX-0001uV-L3 for qemu-devel@nongnu.org; Mon, 13 Jun 2022 16:28:17 -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 25DJXY5N025671; Mon, 13 Jun 2022 20:28:05 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=3pyG/jPM5VqWezzm2L3INpES3eG9Ud6O0N+XuBe5B+A=; b=eBSQI7oFhmnrkDxSdgG/QzoOE69kAfp8nxw3xOjYIDeRB8TjOEuXnlEOLIk3I+nmdAia Lo0CBlPAiYfqxsd0+gDrRncFMMjlwWFoP0vmpJx9dfNurJvONTYticbOkfgXObS098lC ybN2m5oROPJMiuDSw1nadUcFlh9eOr2P09/CInLMjCnG1esVC4qe4wu6I7ii7iFhG4Tv TclTleFLJClrviRJTqIRrwGyOPiIbi4nnTPxAjowOPVOoNtnlU3f3MjqMRoej6eDwcwP KZtWO3M+Y5WJ7+8dxyk2/hSdKX3GzyxSxxxYoJVTU6dLZ6pF67WtRKofTPWeumEfFTJ3 Pg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjx9c1yb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:04 +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 25DKG5SU007030; Mon, 13 Jun 2022 20:28:03 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpc4d09aj-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jun 2022 20:28:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fEuZn6V39ddrBxrp03SafEKZloSQ0+qO5fFz8Q2SOkL1fv/nLbWCRLGpve67joiFeg71iHLbCJDyJR2bbdPf/3Z7s+IT3HhhJ4GZDPD9IgNXE/dOK9JWo1xNNenCKRf/QzCf/GozhrYczIZhIAtfQDGUP08tfBXAjwKtR38HtjAsbDEnzC9YFAG3LL8F/sQrrpiiIQj+IW5p3DydI03pD7hnWSaSWM1haxhwDNRw/6mpPy0G+1wSPJyqS2heel04Ttkau947iNnb9dK1qeyuDUq/VVG2fY+SDAf3GXuGpEgWpJBwLVNOsD7sf75L2eiMJAsrICl0SRPApTUq4KYS+A== 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=3pyG/jPM5VqWezzm2L3INpES3eG9Ud6O0N+XuBe5B+A=; b=mYnY9EXo4nEFHi46NjqU51ECQpilQrt+dh+cBZXVpg2+4S228ecdVX37vPYzJfznHed6UGHEmGiTXEXZah141yeR6DeP+DN35JN04Qz9rDIDx2YSRoWjXcnYAPmjOELqDNRXOK6x4hCL8z+R54WWkIXgQybYilmv1fVQmEJxrZkW0V/hXmT5P7bwWQOIzDZIamcMm+8XzW65xwg5VoWohAqJJhsu3E6Le0SiI1U5RTImpny7tkNhv6mlVeh+Iv+swHH++0x8qjowRpyRtX+9Jm1UgUpCd47+u8QuwMgHy8ew8ZxZEO1Dl3RGTq5cSgJYve5L+aWww1w0fE4Zg36/tw== 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=3pyG/jPM5VqWezzm2L3INpES3eG9Ud6O0N+XuBe5B+A=; b=pACtxNsSTH84mP9ljBHu86CEE3s3JbiTEiKYZsU9YbIwZ4mKNyBmOvxFZNCdOTWjyS7ygDLb/Jrds3j/Luci6wkS1dJlIzV0QwtJ5llbZ3toMUMmArKmBCOqSSzzTy3yhLZtk2kdt6mz6Sc9TdsPFhy7FddmcCfqUPSNCbKyIBM= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by MWHPR10MB2045.namprd10.prod.outlook.com (2603:10b6:300:109::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Mon, 13 Jun 2022 20:27:58 +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.5332.020; Mon, 13 Jun 2022 20:27:58 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@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 v12 14/14] vfio-user: handle reset of remote device Date: Mon, 13 Jun 2022 16:26:34 -0400 Message-Id: <112eeadf3bc4c6cdb100bc3f9a6fcfc20b467c1b.1655151679.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) 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: 10ba0c9d-dfe1-4102-68ac-08da4d7b3430 X-MS-TrafficTypeDiagnostic: MWHPR10MB2045: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: UeaOEiM3EJXwh/e9EL5FbZX2GQpkDttWhYHnD5OFVkBvY3XfB3bfiWcONLn6b8RqfWSf2GZJPIZo+IdyK46EOXxdzPnnSs+MlP182gyWkmEZ0HGZo5J/tKLnvVBf27EQdFRz6Tc6hqTCWaZQs4sZL31swIkRe+8kqplIZDu5nqHImVHhu2wb38Vfp17rdPD1SV5/zAnoDLXNIVMpld7dBsSdGd9Pz7wocKSLc5LYd/Ti5A52dgxHv/Xvalyco6JdwrmLRBEkB8wnDWF5yjpsaCeTCDH8yQf500w6DY1KD/nj1MgvrNQgzZ3axF06B6pCFmevwemqs6XG15sbxROXXAe64toR8KfkdobaqsIrTBnxDw7gIpUn92BAoBYlschD1KlzpedvHgoxvLRc4HuKKEtDSXMBGFr3jteGvcM5uxDvnP2ABXPHhAquxcLepbdZazOuSCGAqE44EY8Z2vQf07utTh4YTxXfTiL6puD/vUPj1cpJdR91nDiUaqoRvqUp+wFSuf0f2VKJDaDqBa7TKabisvaacZzXwUjv2RLePeRnlCW4m8GcR0KPvvFzM+EmE/2kiI7tAOhlpXFEmCW2l9U4+kaUC5vg4iqXuEqrpqHjuUwfKqDeBPN3GoRinN/56HTazhkSmff+AcAGFNlUv4erlZICTFE2rLIxg7hXrnSvM4Zz0ejjovdZaWx+dLN0IH+gN7n0yXOY/VrIA0bYcQ== 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:(13230016)(366004)(5660300002)(7416002)(508600001)(8936002)(6486002)(66946007)(66556008)(66476007)(26005)(6512007)(2906002)(2616005)(86362001)(6666004)(186003)(6506007)(52116002)(107886003)(38100700002)(36756003)(6916009)(38350700002)(316002)(4326008)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fj9gEUhTvjmqtS1YGwWqCJZZTO6/Rs5HwhFinYXldYIKiolcvrlN6UEqvBv9smIrMoq6x4/5kcGYLaFl05jpM8uFRjpl3/r+Gm7fYNW+SQ6L7TRcK59H81UEcOlXC7kWtqjO6U+4dN5hSoHMyNUGeg2haEojd7+v6WfuHVrAZL7AKLAlEltC7d87fIbpxyvCylakupE16HSAOrs6HWdZaU6miPU+x6FVHRcq3eB8JEz4csubiea0yn485vsIz+qX9n09pLrZxiUZPv1ACMxNo4bJ0ufZzCNbEDxHfvUQ66umLs9LZ+t5PxXxqbOkWJpJSu7mG0Pw2HUAhFzqDCT8EZ7l+5FmXeh9caWgh1UPNpFwqY/5AXrAgvEIEoi1y+IIzzxRodoEZZUmdru3yDsj/G7LWbCfq8ZABvfdZMtCgYZ0tR/leEkSeolZOCS8sOun0fiJQU4N00b5K3UTqlWN3jhVLsoGZRyrjmEr90Mf+on+5SK6exaddS3thqa1LHM/vG+bZSyxep9/S6l1cxmtPCk7Gft2huWoihu2mv7UxWOgnvHfW7oIyGAqkf9hQBQdqg2YYZEuqqBGBxPxBs1b9isuEokWx5mD4J0WkaYSxi+E3NQYGG3pj4YEYj7mrICuEGc6gjrJ70DL+Tw8xks3IBncdha/Ud4aiDIR7TBy7YtE5BzemmI7qz2jbyFHLXR1JsxUK976uqvFYEPlfrrKxHzJ2GU/FUsC8075FIyU3FVeq2fO9HkJj1gw0f+KRAg++RANzgeJdHzyOGOv3v8TfoWqh4IUGYhnxSXQP7Vs9+NEq9N5ybGWuMCvkMxur59HB+mBVCmbQ/tJsMde4DrLfzyWzCP3+H/0MPDv67nVFhJNJQIXDbLJB4KpnoE1fekeP/8u06p56DPX3yrQ0EKvJOHOQzZ6+01amjQdjrHKwClo+oeaHiKzAixvsvocT1LhP38qZU4OZ+Vy2+h50FSoqDMmzlKvLIPrNAg1oCxlSis1J0HfWMVnOK953mo+/FqxC8yrdv0my1Ufp3DWLP9+j+HSsxIsFnyFTMz0LKr9oBSId6pFQa5M+sXjvKpusRwVfPgGkhue/8WXdVYSmWJ8CMGJPkD0NtwZdOnoUR6LHBUyA6l5Ksp/l2s8woj3fjPkLwoc0GtrLqj2beVmk5H6d/uiqclcJIff/pU2TiUmRV87L11KwOCufcumsxvVnKddmL8/SrvQ+aPenEZTTkgfpJ/cxn7YYlt1E3XX32/eFJPI8v8iaPqrTb+ex2/K7uKp4KA7E44X3fVookPBJdDf1gyKxBz43wQw5y9UTSgzDBfWPWGKC7Q2nWLWJctgYSBrwlkTJIvpIraWvk1e8zk6T5yu6Ubr8KdFIe/gp9jseiTBTzWAwhM8B+XUuJJfspw2B+VATXqICOqFG/5LSk8FD4Lxk96o02qvJjECS0C7B9pX9nrkPnH504+YOCq+oYBx+EHW529iqNNGbAfVvZbGFb47M06f1OjwZAZdl5SHgrtq1cNDcyWzw6mmGD3gjIb52lbiD9IIQfB2Cvk3di7Hpf42xiO47WdfvKJiEdMptxRhiqdJvYcyvfvIOUOQQxJF6/CYNJYIF8dlJMyyi4fYVGZptJXoB/fci3Ek2iNpSrml4S4Nvxp3CY/oicJ+hf5QGv+Nh4LMW4Pgc7uxRYbYOYkdI2XZ1s9AmS8k1xQlgwFhHL9Qs/Qpu/lgg0nkZXRKIeFoqn8vLdv9iZzHzbDKAA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10ba0c9d-dfe1-4102-68ac-08da4d7b3430 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2022 20:27:58.1375 (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: rkPRYLZzS8yyr0X1XV9WHigxAW+z2lZKOJ3tdsOal3r6Wl0gqmdW1Axv2ye/pbhAD3vphmCq0XyYPwv9jD9btg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB2045 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-13_08:2022-06-13, 2022-06-13 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206130082 X-Proofpoint-ORIG-GUID: xPjExnL5klZlFKXmGfv6Pt7wNn4mDu2h X-Proofpoint-GUID: xPjExnL5klZlFKXmGfv6Pt7wNn4mDu2h Received-SPF: pass client-ip=205.220.165.32; envelope-from=jag.raman@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_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 5ecdec06f6..c6cc53acf2 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -676,6 +676,20 @@ void vfu_object_set_bus_irq(PCIBus *pci_bus) max_bdf); } +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 @@ -795,6 +809,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",