From patchwork Fri Jun 10 19:50: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: 12878016 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 C2EB9CCA47B for ; Fri, 10 Jun 2022 19:54:00 +0000 (UTC) Received: from localhost ([::1]:38992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkhj-0004Eq-Te for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:53:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkez-0000Am-Om for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:09 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:56914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkeu-0000PL-VD for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:09 -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 25AJi0IT021319; Fri, 10 Jun 2022 19:50: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=wTG0AnFKpw9o0Sk/u5S0O8hM0u+ZhYo5tYnbm+PFelE=; b=ydmSrLg3kzuINDuSdSJfc83NsO8DIG9Fd0tEVZxj+w3g3xYBeMskqj24y3+BigtuG4KP K/osS1qPWwGD1eTQ76g/hZxcC915OzZQbA+WlNSOvnVnyx02wmOrBsUxbGOaQ8j2hwcz 1OGFPLanoZ58eUE6DOnKhB2Wd7Iq1AMFIXWH8YYYGLZ2xs7KR8NKcxZEPzj/mqS+nPAB J1YRzh584MKNiSvqD4J0n9rfwFo7tGqH5jm6sVJX30o5m2iQd666Onyxbr0Okhw1YR9P 2UUNFcHgBPCyCfV+Fa0yknhaKa+2paXx7wgblHRRmDbkclnFTYyZ7TPqVLQaEeJAWpDA RQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfyxsprd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:53 +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 25AJjLKR030549; Fri, 10 Jun 2022 19:50:51 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwudf28r-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BTZvlDlkAzisEER+5Lj2QgoSMKCOUr9uWBF5hYqyyx+voiqxTeeXTQlfEbjIPwQNcRwd99+Zr7tC5R4fre22MqTy4+pZqU4a2nsyBJISwIhPqzb1QeOqijfJoRyC7CNgbhglrH1aEmQwJqwhnpmTxOSAxzTAz8baDItpKn/CWfBUuqmvsUky+XDxr8pazCya3yL/zkRvTzP569g1h3hPwCcqgh3FAEVNOMqgu7Q2xWavdRfuuA20qj7TJVd8StZgjfOiV0bdXy2+VDgllqZAlKDLdiWkS4byZc3DQA52gmP6mKSIuDpwDTbXPUoPxdZJmLASDTspnp+b2+ZDh8q3IQ== 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=Sla1OPWwxS4xIu07li6PoNTSn8FfKij/joZDz+RfLODKMPDWWh+r/QiklD2aNqscYpINaGlIJx9x4d11BAsMxbGKAsePM6BgOJtbmO7/XaUAgUCkCZ9xcpC4gg2H2O3ho2V6pLqi4n8Rhd0Ok1o1B0uJOrTpwG2u343sI/GigsnOnNnvYhK6vzqbhKZDnKsX6hZNKWEcjuvXl13pUxouUiC8lzcOqIc4FJTC+JTG3D/ZkS14ruhiy/LzgeA5xce1FTtRWPsjcghx9S2qN09GHVC5SlSto9TXs313GtOE5FlLjuoVoH8aFFXWcocy4qlw84GXtE4ajUdNUCX610ziRQ== 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=ZtkI4rcmDCs0viZE9tsVMtzna8MFyybOvoR86fEPc+9zsV5PKVS0JxR8XdVal09bT0Z5Qnqdixt5v2PsgrabUmNxhYpyWGGN4hRy4K8JC3UDaT3To7Ni9oOW4UvLjhF6ORQQcpGCO2Ep3kbkPKsV1H2/G3v3Cb9OMz27TQi977k= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM4PR10MB6254.namprd10.prod.outlook.com (2603:10b6:8:8f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Fri, 10 Jun 2022 19:50:50 +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.5314.020; Fri, 10 Jun 2022 19:50:50 +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 v11 01/14] qdev: unplug blocker for devices Date: Fri, 10 Jun 2022 15:50:28 -0400 Message-Id: <00fca23089d8abd03581b7fa7fdbfb0d79bb16e4.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 36117f7a-ee32-46d2-f661-08da4b1a84fb X-MS-TrafficTypeDiagnostic: DM4PR10MB6254: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: AobAcgzN+kAyZuKUBVKmFIdla/1ES3dk6NbZVDIN0c2Ws6gvSFCPnzNcyC/Pgle+Byk3tw7iC6cOAsuSVIs07rRTG11BC5NdVALm02gfawAumkuGNBv3ahjfOgUxF/VX1XtSRTYt9tX3k+YtudeuGfdOKwan6WLtiP+wzv5t1hfERzvbzOGxLCz/wxKPlIdayQ9hRw14yDIleEdCx8CgIY+scGB65bXRf29F/m8N5Uxwnu+dyx1y70z2GS8pF3gDkoP3tE96TyEFdM/cLuqtVmmBiGs3OF+EgO00l/fOBGkP5GlzuGvuim1K2dw/q71HW3R9qWW4LkJQxF0Q9IMor/wc+9I0Qg8E3d9HTq1pAn3XLYCu/P/xPktGB+0D91vEFzK6Rjqe/E6SstCf76CDqXkD7c9tpMySQxSi0EBZNtVtyJPeKP7jjVSH07R4DbOQWyOiE0w1tA65dnbK+QeDvpf7W6D/XUC1FGbUvR3Z46segV4tbOC71EJkT8yZY2Uzb7gGwOrlevfDhY3H3GWSnTytjP/3cdK+IXMjjwrYc8ZLtzJUIQfwBHjze9C6gXECYujGr7Y4Vf4yrB1Tm5m86+9uvVGRKLHpq8O0CBjEOl0HNgQi+dMIelnkac/iHIgqRIKApPDWeM3GUBAsuvTEjpRKKyXfNN0FEJWqVSJZ+JZkk9J9R3eBz0RYJskoCNHDtUcPgj0bW4w1hoTq3/cCdw== 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)(38100700002)(26005)(8936002)(2616005)(6512007)(6666004)(36756003)(186003)(6916009)(316002)(83380400001)(6486002)(38350700002)(2906002)(6506007)(86362001)(107886003)(66946007)(8676002)(4326008)(66556008)(5660300002)(7416002)(52116002)(508600001)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tYw/JGkH1PDSbwjBoSQ0+xq4E7QS8HJ18rEB/9IikLQq5Q9YExgJ03MmJ7AYjhwqm5SXLHZsxUk9fJiL2bxUZS8fjYtIyZuCEHO0hkIGvnAoxRRoURMoivJ+X/kXlhULFt8JM9Ev6Wr4BQp9PcqmFyXk/EqAw3EcAM+nzhORzIjwCypFelTx4TcD7NhCFoVPgQ4YPWJgNTqy7OplnolLPVus5liJnVxr0UhMlI8KCNInmXzzpNDhYMkO2iwh7zUHO2ZzYR63mDO9Z/FJigfoMDMiQskzQMi38y+kw3v7EHRL+cO41n3Q0833IzkpNsP9RrnD9b2GqtguWZ7elaApjfz9gxAoeWrljxLnLvZnGuBTMuDL6aovyE0GxA7An8ZOP79EdzIe7IAvRHS6hyKxLDuPEeoyCDAdS7Pc0rGuBSI+YvBa19l6WzeDKAjLaSFfS2ZAPJ0Wye1mCeB48Ne27i+ZCP1nkbNIXHTo1/hyWptV81yn7wch14VZgUsaYN8QMDly+/cvHZqs1/bcsjDJIoWM6bOwWlg8sehzGgEx5/QV9PwZrp8fe67GaVi8D+0wnJMewq4p5yza2gwJzUY7Z70kDTLjdQwPfk5iQhT0tODtrTKlCoccN5HWDPZih1FcDGI9LYIBfcnPE8tBCo+fzthJT3gZSPX4xlp51Qtt8XO9JD2d0SoPmXXshi9NwNHPiqKz36hK+W99BvEzr/S/UaJM5YT+Fh58SBURHRRN/sX8LjXI3NzJWZO/SaNK1xe5COyfGI+60PW2bY6JccuJr748rz/s9ord/4o7/OD9haufNzK3DlyK8O/HPjleWcb75PD8Ws7JmzbFpzq8vLEAkW1auFfTaQ2iy3UGqmEtwlph9saKAKYl+J1+JWPb+umMq0Hh3cdXn+Sot5QR7EgeFkk7PJ34eMShApAHtTgIsCPIl9L1erkRPGNFf9dqFOoBxl72btQUuPxS8OHnAhpaJyNpFhzihQ+itGWR3uQ3GfupOqTF7LDr71HNRPbZDxpS+cUDU2uaF7e61MqYvuC7ZN+swjNEjdI6ayXDVDtL4vDROrPpuqTgUv1Itzf9zxaLerjV7o16jW4zHxzod7Qohio/Ol+u1IEauz40SlJ+XPgjANimG/O0T5wnQJP4aSm5QheumBEwJmig6UM9EIJ2R0MTsDcZCoBaDjOEiGw20iyBxphXNSay/EYwmjH9tYfqylrFRBuwei8KQRSHjYYLU+ESHWOLn38h9hpdWoHPYmig3SHv6S+WaLCIN05vdI+zznwj7F4PObrYQnqkGagTvle1YfwGnke5xViua87UvCGlZXpjHo7I+9GGBtEVnjZDhmEK99ZWRkYwB0OIS8fHdXfcoFTt6d0uf1Vw/h0vxdoswhf/KMy5jZgYu0bg9xpq4xjp3eqsiTgBXje1REQvPHD/O3ZOnSsTlo130bMHDZZMsTR3hdhVJinEF4cYHOIGXlvE1HhYMnAM5sC4eysRbJHcdK82U0G0yOA52+xB9bAzdWrW8WL+XnL1yM5Ii5hIs3i2XsFI1HIIjaeYGeAoLo/PIVowcsop/A/5+3N+efeA6XouvJSdgEMiJvGUYgqBEVszFEWs9UuVZtwvKt7QofbuH5tPGwtMl+seqygV+s2joCiEub848G1UIvL7gxUiAoXKToDWkuWVFI8JQQjii1SiTXeCub/CRq4jOyt7RnQlZIcSCOeVXC0RIaLrE01BIgM/FiMsXqGFhbV4P1sLuQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36117f7a-ee32-46d2-f661-08da4b1a84fb X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:50:50.0090 (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: j2bQiU+NjRufSzz5BcSjOQufCUvAWK4OBar86VhqW/8ZxVHgJbff1jzsBY7G8VLeI5rmKtCCNSGTfFC6IhFPAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6254 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-ORIG-GUID: LztsvXDuS4_lsCbr2S63zLBNmyq6pw-1 X-Proofpoint-GUID: LztsvXDuS4_lsCbr2S63zLBNmyq6pw-1 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" 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 Fri Jun 10 19:50: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: 12878043 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 121BDC43334 for ; Fri, 10 Jun 2022 20:03:26 +0000 (UTC) Received: from localhost ([::1]:59952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkqs-0001bb-3X for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:03:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf0-0000Bl-N4 for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:10 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:59262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkev-0000PT-SI for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:10 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25AJiBnp009130; Fri, 10 Jun 2022 19:50:55 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=Y8kM+OsNZ+kdm6IgYuuPutKAvdXnm/tKWRKjQV/d8G2cp6V20qbL+So0xDSN6tmBrn+8 8e2FDgJY/nfuZkEz0LrNk7BvLXWbVA6lcfAHqwvGFM9wccHGB+3ZSRRyVeVjnZz1irYA 1YEcOySxWB6GICpsOMiggqJPM87BeAtMH9u5hu4jFFz0tAlkadZusSuS9x//bRxugYke e0Zqm6+65nbXzcOGeI7Pg72sonhkd109SCoJ0d2fX+oeOnTlNJfD/MOPDYRQUOckRFSq W6JIZL4FSZkY3iCeaBo9Q1yf++Jmmwy+AmgGoDJP+epq9AFTOy4T0kPCTbHEBzPJZ09J pg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfydqxdes-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:55 +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 25AJkgoC023013; Fri, 10 Jun 2022 19:50:54 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6egag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hx/KVra+b5fL15e+q5CFcFpXktzW2b9vQXQAL04yO6os2JNpQFl8Rb5dSE0ajToVcN/Mo3Frbvac4E5Ncb4OPqvO+0/17oWGQqFI2VOYiUslOOVXkZUoaKF3HKS/OsKBmKwp93wddXLaxjk8NkSZCbUzCqAivlQ5YGD+Me9IUd1jf3U2mX2p+C9Q01XGrWQtP4A5JrIMPYx0Kko0LJsBI1+BOeFsyMQJgofq0i20NpVGestkPC0bY67As/IKFzXzrEyS6XYK7CosmX1OsaS8+y0FtQp+cAC2cNuVuOseKllmT8dgAhdP6Zs97Jhm1gTca+tvTRMrtg3/zTiwfC1Wug== 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=JrrXMWOm000yS8X95/4RXgMux+7hrWYM8tYNazqkicsthL8ZgOAHVTwpkLa8+dkP84YZ0xG+CZ4d39QO38ZAHJWbgw93N08BYxA9fbATYLucUXj2qnzHrt23hOjw200k13dL5nW8MNCGmNfL5wT54eJR7rM7jXD5HrJ+58vyrpIS0gjpJ3XLkKhzZ14C1fyaHGUOgbKubeqz7MqJCHizjGXHecvOd1nnMNKo6v2gsQi1gnp6qKZMcE7w4HwGXwCBmNJgPC0rDtj/y/nwHdLxXBe0qowONov9jBgkYbQ+S27Me4PTY6Cf+vJ3JzOWKa7OG4R+pnRMqwuCZKqYe86IyA== 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=fV4J/nrsS05OihU6zpM8VgfJxvzt3uejFmmNZh0jJuOwTafG1KkYe9Pti9+f+zbc6nYm9eG/gdnvCLkVmfSlx2uqoReHEZEPJPqL8Af2qRs54TsXJfjgjsvIfrfus3e8T19OujsAUsaRUrQ0EZrZ4wuY0iGih++uFAp0GoHBM3g= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM4PR10MB6254.namprd10.prod.outlook.com (2603:10b6:8:8f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Fri, 10 Jun 2022 19:50:52 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5314.020; Fri, 10 Jun 2022 19:50:52 +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 v11 02/14] remote/machine: add HotplugHandler for remote machine Date: Fri, 10 Jun 2022 15:50:29 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 22f63981-24d9-465a-cbf4-08da4b1a865c X-MS-TrafficTypeDiagnostic: DM4PR10MB6254: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: p92CBdItwvytW3f+BE8i3PVcjy6MYM9aGEDiTld/Wa0w9Q2XrpUjoJ1a5UHidJmv5rzO5scn+IBMRBjxVe0k3WMAszf7JZ2b9z62O0w1UzSnSiP18Jcr9bDgUWGPC7V3sdmnIlHv183eTuvqyZRVVimDO5LqdlVs/q1iRDuXHWSCLJRygrwqBnd6i3LyW/E8rYdLIHpK7sW4dd35gsbwf+/oZMo1QFlY5CYk0bjS/5FxtKnU9I/S+wOSIwhunMfLjfmH3LfB5CkmvIw2YZMMDv9klqObQCeS55f1t53kluXTCqJhk1i/lB9P928y8iJiW01XElFC0C/eOpbMVFQR/RE1To8GMDoaIJ7jul3lab5gFz9hiusfhTd1+NftozBN/jjTO6s9vumzIU8b44HNebJ2cPXmvPgDXryfumzD317ekTDP+xo+O7blEMGT84lFyDvNGQNXUnRB7UZ/UOE84uxHq2OMPsbPpa7864UAVxd54qd654JXHNJcthiKGIMvFMOWI2gVmOB3Z2eRIhJVZuc4hyOJiEgejwp5UAEBxQ3uc97Hy3nETr0Wxn8qeZ3N/fhIopWJgd3LSYyHrHN7iXkKbwJo1VwizD7Vv69WWqYbKi69uW5QkM81gfhMTdrv828JgTDnGqTbP69LLM800pFiQbw7AJh8VbBsvYcpqL/nOCpSWgPupZTWJuaYhCDf0Hp8rVtisIk41sVFYMlfJQ== 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)(38100700002)(26005)(8936002)(2616005)(6512007)(6666004)(36756003)(186003)(6916009)(316002)(6486002)(38350700002)(2906002)(6506007)(86362001)(107886003)(66946007)(8676002)(4326008)(66556008)(5660300002)(7416002)(52116002)(508600001)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7x1Hh5O2geNQZCnEhJMlDwuP2RghP5Sp8CEml8bYxv2ALHPXDerZYeI4trYS7unMW3chgDy5bvEVI1c9k8SzWzyVlgLWK/t+Nam3RZJqYCQaFNUtUhRTvCAJ3Gr2ifeESf5SEypQLDGMe7Gynbbup/iWto979I3IBQbWG26Rcv0qPdMCiTNO59fBggsQMDvF4PJwvm9ShIvQnleLlvY33p2+trxLHzGGYqNMHqPPPj8MZ2KSoyAGViH2+7UZOyU1aYjautIsM8+BllOo/pGSHr4h9pV0xyIkeHdJjwoMmbydB5pO51YTDsjoY2eoMEAQir8YfjaVFEFGZqo3iKpXoljtDaShHmagLLWqkbTDvGguceO16sBPKeIMvCa8/w6RHEBPdkeSH66wZ+SL0DZAnTtQLmxrnqCcAobSTVEAFuvLEd/L7L8iP6c1fK06WoJHuGZrqiDhFXbDSeXX0W/JYCb+mN5xbVva2C+UFy1VisCQ9N0Mouv2Qsq9resTamMmetskrp7n1uhePbr0v8/cbTvFNVIL1X0TsnI+Kt00XvY7kYhwE5s/SQilxJoV5pQ02qfTHgEsyku+WmBnvgqmYiZB8xrogSmEWSsWZHFTeGaHRrTsoMpt/Ws2sTnADism3w4rvcYLs3zkR1r6tNRVMt8OlnI7SII7nHBAlmIw4XS/1KLC2c1ruq041yhPUt/WPTqy/WEM6yyi1eC+hqIVImUxTAdIEsrJWXZWBOKB74Hdsc9F73PHk5QoNzs6Q/chQIYkjGLYXbQ47rlVz6IALPG5+0c6/6fLUJMZVtenb8v/nWajY/98DdYMNLSvVaMISXSt2ke6nhZQsB0HSjDPRop6Kd83OGW0mrZ5S84XSfpAxJuxwrZuIL4jnj0f2sPvi53nptYxFfTsoCMlScOsc9OpM5gRF+fghdxEOu6v7Kx4QjwUExoPuLfnjDOCxmIr2tcY+QhEFJPR7Urz83qN4VqDdRH+FkANlclenBMsBd1zIR1rymwfqjLUKhjOh/ic5rF28FzxnKtsxBslbihy8k6zxL5qpNKVWeJM17OWS+N2ViBuQOSWEt8tKY4EliApXOLwc8M6J9qdwqcWRpv/1Hrxf7Tm4EPYP/y0hJnynUIsxEBaz3juFUnmzETg6LGn2raYHrItxi+OEXC2GeVcM93I+wBIY5tjRX9v8BW1NIB9ji3AqXxVLcSNP9JZ8X7nGXtQMX00Vot2Av3Dk0Nc+YG4xHvuCZxy5D+K9JdnmVf0MlyJjBlCToVTTJgTwMG4HpMzRMBebYCXmPNcZfjDgbF9MQXCGp06iYTMb3ZGQ08Pl/ObKWIDJi9hXOxtiVLWZCBd/7/YHg7WfY1r9K5L8pv/xoREK85WLiJw+MSoABZUhaDsBe0RItbUuJKFihu0qJyetX99aHrelCacp35Itb+zc9rhu8erbjpsYJU5Hr3L3+S75dckhtjQamFG45ro03MDAFTFkgnceTA6Z1bSZCZOedNJLzDuIudXOF8wbQD2dOuIikMS7uDndXnRGFpdk/1AzL3fRPtCZFDRVAsk91oYmUwgHQgkEH1uuEaHcBF3uHfj2fGP37LSYsTnZ5NPAtbFGvHPNarigMNFlhsfYfxboMcdgbnMj1+Pzathe9e7LVtNR5Xo2a7yKzIPhugKBr6YnyKPNrztaby8EqVytosr/ADLcUdDK9CoDMi5XQO+I4tsejlh8fdjGJP1QgNXTajVTpGiyh5yDTdiMWBwlA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22f63981-24d9-465a-cbf4-08da4b1a865c X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:50:52.3682 (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: wmShbvqYvMK3/Hvl1wzuj2MtHBgB1CuCmYdWldiqgkJvdKheqDTPx6HJP3irnbE1XkiVS+PYovXJWPRbEGDBoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6254 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: 0B01p0Hvv-oRSwHd86a8cCiNg4RPS86v X-Proofpoint-ORIG-GUID: 0B01p0Hvv-oRSwHd86a8cCiNg4RPS86v 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" 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 Fri Jun 10 19:50:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878017 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 5AED7C43334 for ; Fri, 10 Jun 2022 19:56:48 +0000 (UTC) Received: from localhost ([::1]:45382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkkR-00005k-7A for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:56:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkez-0000AU-7c for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:09 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:59406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkeu-0000Nm-Sv for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:08 -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 25AJhr41003365; Fri, 10 Jun 2022 19:50:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=PEYd92Oj4S4zXZHW4xEXu9y46a7Vp5wnXLld9qaD9Ys=; b=RodLz/GXKsoI739LjdbeczDbY0BetOTwp2y7R5UgWnUdFJ3ODp+SpDRknmy2/4rs8dRn 8v2IQcD3jxN8KWYOEr8rJSNmJNcKZqLcCtZA0wkC7q7XB7MQvLqJxyjiIFKxDqxKZ1B3 BczlENNnE8CfgbIrQwXACGF4IQgv/OzUPTvWykOYFphz+U7pqcFwAxLruiippvHonRfo VkUUIm5ePSUXS5mMFVBnpOe4p/Y8FPamVQoW1OOTTu1GBgROLgiXPQlWhj/9rSJoF3Cf DNjb/lMBAjr8DLVY+7avNOSrEnWxwzy6S3qmdyxb2jlCHzwDoHSApS3q8E5C28UUXlgl Ig== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfyekpdmj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:57 +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 25AJjLQ9030546; Fri, 10 Jun 2022 19:50:57 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwudf2bw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Or/4HNKi+6XWS2P/l47BiL2lQxW4l7cdZ2MjD30tTZsYDBYffv15lSwIKUvZgupYa0ekCuxFrNrDIOEaQQzeusZEN3Gpka7ZiL1t3J4gv1GMrPgD5De/I+Ex1TsdEADoLjsuT8Cc1qd0a5upqtQAl1L2ceBwASyoAuMWqN4L8WJ5Uv7oycVCK5PMXlTwXP04V22w8un6xVG8r8iPfm01zhWz6cb1YIZCP8Clv1yP8xOMnKnNFLqHjwGFs4ximbJojrbYj/9cFexR/zJKzz9khMZouBXgfr8HMK9/5VtMYUOwCFvbDl1/iaKRS7xkJ7Kc7I/ZQ+ewz7aGI7nEr7a0IA== 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=OVcAOAaM66JiTcj2nO0fGn7X9Kdpa1tac6xX0MOOFB3frRxlaFph6pz3OZy6WRy5IU2PtCju5VLBJgps33Qs+WOXv8u9DRclRqGUBT0f3gni2fAehxpalxr73QXFHrK6KbZ+KSQkoscHmt7LtE4hpi107j4A5FOZdTUPp8lIyZ547RrbKjGlRu40NhFQlMQ8VHK2bniI6EEtcNA5MDbMJQruOBPqFEhR/ofkA4IqZXmpFsZ8VO38ZHXJIvj8nPruRT736iaG6cUp8uBo4o4mPZcdwhiuwWQhB1Tz/6w0aTHyq+wfHz/ASlLgucItEsMU3aDL4n4saYjKAAXbq6h6+A== 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=DTljw9JUXZTT7EWKQsJvmqQ1QsAcBekw19ZNVYiHaUdIAZ9oCfzTr1m+KutlnImPx+joyeA3Xgrr2BJ6ZIMT8G0LyjoyKAZULBFSpi34CgH2o4Bmcxq7gqlUtYxOm1I3V39XJAwzxkHgyimdX+EF4pnANe7n2yaZjyXFwja4Sfw= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:50:54 +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.5314.020; Fri, 10 Jun 2022 19:50:54 +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 v11 03/14] remote/machine: add vfio-user property Date: Fri, 10 Jun 2022 15:50:30 -0400 Message-Id: <3ee846cd9c591b63f06686d5d7bce7ca4b8e3a89.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 28ac8131-1cb2-4210-c87e-08da4b1a87c4 X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: fMh9MAWtTZXJW2zknxm1KeHPRrJQFZe7K3BSg7vjLdC/GieqUKnz2+vkPlph4TxdaG5MZfFLKv+4WVXoiFo7zC447glmUriSErU0sBE46u1kjGvqoDgGcyl5JEca6DfhCvWVhvfvsXNQ4mDdqBz3BtJG3J5GQQGfbK13dXuOOOrX2Gct5OD1SnRE1K4CXCiPWR1ZlktkPf+BM3rBaENLVRKQrPukwNFlYFHEPef830SimR18Igpvy5Dtkh76CP7jfOxCMk+e7KJ2wYyi08yYhKDM0JR6qL3OYA78vHKcf5q9PzvrqEIYNsr196HIKKmW0EBwgC5M5Y3+JlhKgiZ/8jUpppezJdy0ma/O1alwUVHUsIIZdE+0rqEIgJMCiun+2UQ+bW6F4BoKmYkwKm+L885FGAsmZb1zMq3tzT/wz7E4cckn8+ilreoL09JkLvjkfwMjClS50WzL/GTriNGBhaV8IH4V7xsBRFjCIsQV4zJ28N6JZiEWd8CKxKqGsFlxOapCfP9ejyW4uGaSfOfENDW1ODbg/+7jMfD1iPa0xaN1XtWJ+r/mFkjVqy6GijZpJ1OqsW760mFlXbQlRG0nWQGMZPjLCQ4Hg8iyW9nT3Ljya3YZY28CrUkOGG7YrWS7YhEY7DmKwmCPJ+MD3giJO8T8UJjVV7T/s+ncL80dxBZW23sVNFP/ACxbSyoGGwJ/CDmqRd59AjKXS9b6BdG4Vg== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(6666004)(8676002)(508600001)(6486002)(316002)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9OUTk5AihUPUwfhffEZt42Z/A+zziK22zvCLh2AxVNjBzhv1SVfkFNl/n7lsCWjcxB+pf2Zm2D+KvR07cZkVy4rQu44neyS2lsgwSN4eLhoifJ+tSqJmXB7Im5L0Ol4S/Lh9nikp45jA8IhLaCb78GVEqyT9m4VIUCiTM5WkykXQxGKvpe+bP+JZAzX+O0zFztTg8I+XCtMlghjqyojKxvy6Vl6f1cmcEwg5bZUhDwFivCaH1sU8EYrvzovo7vXUTpem/CUT0iO5kxnhjQyvGfoQErzhcyHBGCyHK6glgHIaBnqh+vSUaM1NRumdy8ou3zW1TCcCc8lvGfMDAqwCApruANT+3Uo2KLE7r/XEnCAoNDn6HK8s6QerkKn53CQkHpbgCaBQq6D9NlzTCI2CxHXJi72nb4aaWFrjKIKOeNZfLToVxJu+c3iOV0EcNc+OueRHY7svh/JNZHHf0rVwpGUMVHOv5RrZMPBmxCZWzNdtVTxNIFdSvuGME19aU89Q8kjBUaNvtPuK4WcRMtPGXqFR16mlclYTzxnwR+9GvibFsDGQVJsZ849x1NIG49GUB8XyjWSQu3p/yzIemacGUD1zHRWcnwF4rusbbQH6D+cGdx5b9N1VRv31PQm9FWOKkRtJfku6v4NleWDKpD9p5NHMK8WKf7ugebg2M1S3md9sAGq72TTocLygl85GyZAoY53OhUtfZAQ/JfHrVvRuzrpaL5TwEw8OQfYarNrxjOxpnvG88AxwuSeXR0FhAL+VNpAAEHi4D3Hmomwo88GBu3KUA6hQUCK1m0QeE6izG45YZpHAhXrrL5Ychv+in8oECmrDUjpSA/Kbf9Mz3i/xJx9zgoLebugNZU+fwN6qv8kNz0offNpUqJF98gJEU0ZpwIeCvrKFcOx5WknN92DG4Ey0j38ZVBA1CTLAS6YJYCz6iCTjfeJfIFe7DR5W8toad/ShevbfOz4yIWOtNQ1WlMCW5HpQx0czoOQlYHfkYFN3RaLSehi3GKZ6CM0sr9Uc29YKGkTrikhIBh7WR4LgktieiTLKeQ+TWJxeU/IEo1EugPViaaj81/GPTwetxA10LDX5fNdaW5Skww252nefMlbgRGd2aOw+hSgKpwEU+9EWQlKsfM0Hq6hch+htfvM2uIhuugEXJ7ktVW08z+mKx6Vmq3RlyTY99xRcetJjIpnoRoPCVUeGkyHl9/dQG2UqPD3VhuluHLXIXAzQkoqy61xTjKl8AMN7A5hiffoybapwuF1WAnjOmDaePwS9vWxfzgSTfhpaLUhYR54jKS+ZP1aEStKw4OmRdL65mbqLw1qf9L0gPL5GclwzMOh8XP8NTMGKMz/rOkaeNPLSSWTFAnI2txbrChDCTeCc/1rLW3OozUN6LbKeq6/MfDrorBXcxVkq7qhQ6FhpX9/QbD6KB3Ok8PLayitlJWjYdcmvLsn6y2WPAG6yZJPv0U5w13GbzpWFm0Unb+Jzf0A6lwsamZW+WtUGavmy4nZ6CmEiHueAeZXsT8QvnvKj7oTuQMx6Lj8zD1ePHDFUts164QsMFAuXmU2iN5ODv7YvA+yYrtm1vbUCuVa5YDm1b7Gx5Snzc+JJ2NI+jz6FuaDlmnXq6DrR6apRjBKhz95DTDHV7Xz6BCuRejKiZjCo8H6LWC2BsTfRO5/+/VdGhqVqxuyQm/r80oRlUGIiKPisODfPcgJqMbK2P0+YlJp5peAz6pjUDjiMGxYEbLgFQwOLbXxuvw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28ac8131-1cb2-4210-c87e-08da4b1a87c4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:50:54.6806 (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: aXWFpX+rEYojFYSSbHm70gkjbW7ZoLJBAe7XA6iauC3O+LUSiVpnDUdB++jyaY4w8SIVjPOOcsyE+/XVGEXekA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: Qe4CuiAe4ByhQb9VqsjZPwRXzOvl2bsg X-Proofpoint-ORIG-GUID: Qe4CuiAe4ByhQb9VqsjZPwRXzOvl2bsg 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 Fri Jun 10 19:50: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: 12878037 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 81344C433EF for ; Fri, 10 Jun 2022 20:00:59 +0000 (UTC) Received: from localhost ([::1]:53736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkoU-0005i2-MG for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:00:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf0-0000BZ-Dl for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:10 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:63192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkeu-0000P9-Re for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:10 -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 25AJhqND016299; Fri, 10 Jun 2022 19:51:00 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=2dnGMjhIbhSHpuTnKaf5YwvSB7NNKyj11NLaPe8JCpg=; b=zcH9ps9Yn8JmBuNz2rAcsQUVrkuiHuKa3LDmnPiS5VIcftCS4aHgoyz/1fi2+UEOljXV SmRnKocJieCQ7tw55w/TCYrwYqNL9muidxPCOhOOuNQ4YaRvOKbvz5e683A/gG3gs5mY /LNo/1E+vGcAku332NPk3D9al38IHZ9+PIewGMvSL9hlv+x8ISBQBSbBWY2Ow0RyUx0C LX/HwcJeSVZobldee1UPYL4qq92eLNI/qQDKeFK0L6P2krs62u5KeBmXjbIbPsS+SFxP zLf/b739J5UrURi061+t4rzUY0bmMDkOYPG3rRm5picPyVApnzKy54HQwdHizIouNDiu aQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ggvxn4fag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:00 +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 25AJjMGm030599; Fri, 10 Jun 2022 19:50:59 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwudf2dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:50:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RPr8zpLDcRYB/ab+aLb1OBS4kNjwovqx3ICapOjcDi9T9WlLOcqR1xaDdtHRKhSTK/Y70UeJYuJjiQkd9Xi1LPQI2xnyEc0kVL5uSfFtjQemcNCwypKjRz3Wb0Qy6A4pJtHzCGqt/vHvkzvBWxBB8lFapXmqPQ40IOiJtoZCYZrZZrvPICkavtTTQ4uOUApJSghYr3x6FkVIRZv9VS8fqDrb69M8OwLrVN+gNcyNluzIhGFUk9MnviqwYttt/wZWI1koYA67sJXhNoywDjTzcPH3y8AlilFRqH6UHV//rL/dBLL9mUT04N0gmi9s7H6E+vPRk7WhC/hoPZ2ldTP0ng== 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=2dnGMjhIbhSHpuTnKaf5YwvSB7NNKyj11NLaPe8JCpg=; b=JCId3O1ahKbKA2q+ZyKy4iltAuIk4c98tjSCdukIZujWMfHQOZl5Mq8SMjPhBqC6KZXxEq6oci40T3PtzHVncLFrsHOERUuflQ/I4Sty1R3/YotBimcGp5Xr0OO81XD+Pe6Q5Fdm9xdEg/Alq/pMcy5xF1DROhmo3HJye4LwFRLySqX1RjIF9HLOasLm+396IN9u97udOWmlOiNlosqTk8YMXMSaa/LCaPdy63ynL8RmVyH2yfKkuoWEj3yGL6a5Iw+kyg94ZjHP36F6cM981bibYbOGo6DPb6dgazO3nM+wrgQceZf38P1k4hcdr6kT2/24N98n93vBlABeXcpMcg== 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=2dnGMjhIbhSHpuTnKaf5YwvSB7NNKyj11NLaPe8JCpg=; b=E3Db7G6Khq8Hmse/BSGnfFwV85VeAj4fJE5Dm2meQ7uXQ98xHjL4brq3k1Q7MFY4dMpBdE40g/WqO9GhKomCX8SXQGJDKyXKHlSjqdiCxTl0bulDNV6FoD07jnomHrNPXh6cHN29vFTU+BVfIQgJmCvMDjEco6USRjLHB6gCq6E= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:50:57 +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.5314.020; Fri, 10 Jun 2022 19:50:57 +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 v11 04/14] vfio-user: build library Date: Fri, 10 Jun 2022 15:50:31 -0400 Message-Id: <7ba5766a59baec1c527bf4594dcf1dd55615aa59.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 2f4ceeb1-8281-4671-62bf-08da4b1a892a X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: 3mG3qh6Vu1m0ddb7rpbedsdEMP7/xLvA4IAsOiAP3TFMo8KRRp1VsHEaEfd2BtFC4Bl0hL0mSsJ6Y423WycAQ/FE5sMxRcb8fdzbrAXfkJnOT7dy6f5gDAut4U6MbMOdIVC6U+OYtHmm52roQbxsN1DyrNCDvw+AD+jxD/OcmYHOs0x8jyOiEfzx8jIAODVqJg7+V1L1w0Wt8c2J0hR5VUncqhw1ZWtxpf3SdmIxBJ/FULr9uNfmKi2O4UuzBwnHOvO8adEPPBfyCjFnYeoG6bDce0gb73VL2PNNjyJEfsapwtws/6+U1Zi1Y2+2BC7tcrpHMH/8TCj3D21FCBOuapX7FVAX0kE9/a+RMMj+I+hKtcQX2vN4yQ9gHgO6DpxfC5pCj8Nck2YjiTr/vZlKzZhBT/6eZB5tjefkOYfPimKCNEqbUtdlLH+lDPdCSFXuArmXaiU3x20KUSx0EIRYddMhXpWsq/Wsldrx9nWOmfgS3tom1wQM+Z2B+ICkz7DVn2AwSFxwT51QUs2Ehi4sRO1oaDpuJu/IJTzjaiKsOSs1zipzBrmxJs+nsl7d7qQSCRo9W79GtoK6Ax3Gym6qPTfralU1VwuEiQiLt7/Dtcu+oM3MYRYqobrORunaUR5BS96Dau6O17ORwOwBFAgUxQlmtuTn0TMYFKKyS75NkO4jF/VR5hfHH3RsWSWdykJPU0ZJ1Tk4VGItjNYCim2kL4n9MSrLDBkGurjc8E55W/BvHgOZh9EE9hN9vOadwUQXy3gpggOA1NdKQ0Pgg13YiLzG/Tv8LuTguNyUo/NL3t/dQ3skdpnldiEgqoLFtCRb 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(966005)(66556008)(66476007)(7416002)(6666004)(8676002)(508600001)(6486002)(316002)(83380400001)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8kMV0c7ZtveCOLkf4tbOKuNanAtMSg4+tt0gIBrjUV6XMgX+sh1vyI4gNeNnE+fNO/f+fLcYo5Xb5Kkhz6GNd47j0MkOEcHKgfTOP/y+wdfBaWabzHDHKsKd1EhNF+ICANBnzKSOjyh3fI6bWXY6V7vcIiQMYLnKI7Bai/0vqAYRQkJSvvClzu6damF6VkAWG+BBd9eQMMcLNkx+xsGerFkAdzz4+n6oV6BeSviQCNXyaMYUNrsdKW8zYD4Sq1CUNuHAOAXeLnEqKeA11KpJqGzsWs0Azq6PgnVQ91MBMb6VNZROYRQvljEvT4i2koEcB/70f0/LV5SUftDUrhJqzrgIWtneTTf5Akg+0WKPTdYN26YKs0CrtkOTyq2sFKuVUnXYbImUPpq4dnJgUcCqtvot12ZzH8Qsfnje+mnxVqhvpr+6U4voYthSQ73H1kJdFNSFWZUCQuiMiCys3KCHAck+klYYJMg++7h3iZyMA55FiD3dPLvHedM1hoCI4O50YJ+JBSGj4HecuvtGRcSa+MLMeGi13atbY6WxyeeqYkVxMZHUgaAzMuyvfljN62GJ3aoCcn3deFiFBo944l+45//2fkSF8dlgvJZoN8bTw/NMN/j26WHbtFY55BAegQdzXhtQI0S/0Uvva7kEpaRwzO/ztLRN4uEMydPFnx/pU4lZMppcTCEPczv8zWSye2vmxJ/iAiRMSRjnBBhe8mS9Efz16Zl0FDsF2PxBpNyMnC+dFTEQKK7x7qwoSX6wu/7kM27fFF4PXYzpAbYZMyHeMuiDtR2iaPUJinnEwZoUfXOj4Tmf37yedmUirr4QF9VusnaUP9SZI4S9DFw4RPQGcmEIkAobaTnmADfBZuFrVxa0WacNAII4/btpOlgg4Kz7sCS6h/c99MmtifznksmTgodgv2XwX4zG1S/TqtH/RzNq0tMJL46TV6P1aVhBZMoNICo2SHtmXWMx0H4aIOwCjQBsW2TJ+x9yqQBMCRqF8zT+bqSEYuywIyVafyCQUqYUNjxNaIKS/ObVOltm3fn7pdYAT/DeEY6MTSb9Jwsvrx8szUOTE+7S3HtzjRcp6V+9tpCaj59Br9Tf259wDVU+flp6xZ47D0V6U8G5YmESXw1VONv8RV/gD04W6iRUOYP8splzoBJZxx3OJ3C9/MjleF34gCay3p7lHWYggHEuWOq///hxAjPHIIG8itD3SH6nt8h0ub2SE8UHNm62OMD/OWr/9xqGUNIhvXY+OiS5DxOucgeaOqUjGR+LeLOYBDGq3Jsr9N1Ss5aaQpZ43uf6Czj0uupbV10bLjXIZoX1mP78xr2ZK2R+/kECHQfMpgAb6ePEzlAGx0xW/CPj8M0Prgp3v9FpFs54Kdr/fHyQha3tolK+j/rTpmSnoXR7pf/h2nvHptmQI9ZXMH8lGacYVbBEIUDgiaCT1mGabxQ2ILzYaFIzHjYrCxlycB9th6dQM29NZn5ohsogLmxYVQ8pNhz2vf0LVX5X1CE0+USRKgetF6jWsP7REKK7UT6XSNR0V15pmTiNlmuhEP6TdJMnJ6r/8HaIfCwmroPnesKBRLcwhdFHH/SBHk0p5Am3tTKIp3GpFsNSvDCg8Mgf3gDCxaurVFas+FCBIlzEVNtpgF7rNjgIsLmjYewjawneEhP6xk1nT5CY4sYpJcaowtAGaeBvXJvaSTaA1kVGrrQnTsa8aQJ2ABnstEh/xGUQrIcZ3UMvvMb90RkRiTUPbunGcQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f4ceeb1-8281-4671-62bf-08da4b1a892a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:50:57.0398 (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: mChNINqetB7nxJTeeMlTtdX7xSoP3AA6KD+ZMN9ARHZI/b6s12OZjjzKgbRRMMUG3yiGf8jloOpVyha5GiXQ7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: ioBlo-q5LeaU14vy6432C-w6qOc8Izyr X-Proofpoint-ORIG-GUID: ioBlo-q5LeaU14vy6432C-w6qOc8Izyr 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 b3af081c51..ef8f227fbb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3631,6 +3631,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 Fri Jun 10 19:50:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878019 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 AAA24C43334 for ; Fri, 10 Jun 2022 19:57:49 +0000 (UTC) Received: from localhost ([::1]:47566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzklQ-0001cM-Qg for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:57:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf0-0000BY-DP for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:10 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:4276) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkev-0000PR-ET for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:10 -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 25AJhufb021488; Fri, 10 Jun 2022 19:51: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-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=tYZgsr9yL+X1AZdVUWueMJDrqbokKMijg5WzTSCrlFo=; b=hZMLtrkk6d8mFrpoo8TxDtjbTTMTZ+pSuJkiu4WXDhJowmdtqX8aWwLYQpLbTiFs9w3y DzUFNVeduSI+dURpfXjSP/GMk74240ummGYbiSz2SAoYsyZfHQiBKE1oL4FzXSTMjCqF 4il8Rm8JBA2dBRimHgIQnAOqG+CIquGQaD67Z5ZFNJOfctnPINlcyksvHISk8Lv8ve+N d+AguwNltsieJ16Cnv6/6Hx42HaXXGCNdIlq+tBJ9NrF8GzninC1PQGz4dJsl/Z2t7pV lSW8BAJUnlBuK565Gad6F6cyWJAAL1dhRSQW9qXsoG8HZAhh/pLQBaB1/jKL5ZzrouJs fg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ghexem0uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:02 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25AJk8m3018455; Fri, 10 Jun 2022 19:51:02 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwu6cuu4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mv8l1RIcVshGCFwWv1ZsXto+QVZMkzLcN5yTJ6ubYFfaMEPcX9qM3497drRPmeC7XajMSzkgKESqCfS750FDjwqB7Rax+pg1vg+MTGe2/5VGqTDVTMKM/xxY5eNIWM6OBS6dM5oLxPsY90ygsXykKyqAYjXWzriKtxE4VwcECHpget/aeXa3zUsR7e/g3fdVley5lMlUNQiWz0HrrKNwyMnoR4UGm4zAlaS0CoOxt0o4sALSaKRn5IozjHOAuTlHhUcHMFzJDdH0SGT39F3yDas5oVsQukzfr3rc8K8WCe4ZTICUS0WtOoWcD/KTc+TeAJspNUtjz+sEq+KK7Sb5kQ== 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=tYZgsr9yL+X1AZdVUWueMJDrqbokKMijg5WzTSCrlFo=; b=iTFKIdQ1fyCBnzTKHE3ovcHWOPPaAfXjxy7uI1JTr7tOfeW6Pt5MfLmIN5QmvG05etY4XiFNhYGZDx5/xw4kH7zGRTMd9YZvMIAaKprRY3oeloWU4hasO6FhCIMBgarclSfKH72kKqnya1I9TtZPLt83A3R72jCIn/lovQyhXUjoWfZ44FMVf19HJtQoTyK6B2pETorELM0KhNl98oeAyZVWXMJHSJKMlQz5j+b4e6N18F5FWFWXOwDFZH6ULxM3iyDui1EpyYKS0i55rWBBExVQ4Z8WleVy8tJpWb4jl1bZZVcD72Eiexbg0HW4gljpFv56rzp3xG5KJVGyLYxPnw== 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=tYZgsr9yL+X1AZdVUWueMJDrqbokKMijg5WzTSCrlFo=; b=HD42WOnWDloAzBICP5V71ad8due8C+o+OYABUQNt/QxiS6n76sh7wDkgXONmVOurO8mewbSEMrxbiGHHZlPhNm6tYsGRXatPRbD9frXbMsJGZpeq1Kjgj7JZDKDS6ApZDzg+K+s8FGjoeH31aT7YDYw2YLbhXiIJ4nPy7i2IyjU= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:50:59 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5314.020; Fri, 10 Jun 2022 19:50:59 +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 v11 05/14] vfio-user: define vfio-user-server object Date: Fri, 10 Jun 2022 15:50:32 -0400 Message-Id: <47a665da9676a1ad676933e2d1c187ce3b54b308.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: bc185c3d-bdf0-4e3f-fcd8-08da4b1a8a8f X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: cllZQBRYl8ri7NVmIt2kHTRhbjX9l8O0Fl2RkaXXAMhUbXSeoq0rPGkK8f2jyAXPKp0Klm3F3+VfnJmN1e4+Mrvk12YP4NNkD2t+8sGzts4ioMpHBdUvI2XyqiDjz+VeT5SzqR5mL/lNL4Hk/cWO/lhDm4Wuku01+lQ6RB9n0gOv1eqIMEH44EKRxT5wqTDpKEXjd6bQKn2yV950+Ud5WrIdxtPaCOYRtS+e+ye1tLU60CfLrIUhR+8Ca464sKPWa6oKc8qzvVzTfo8GJlXLMhWbFgWBkhms8yHrCD/7q4yGYUvmdDzLulnHUX/+TJh/OsrAGj/DJWq1EOfWuAFiLVUNdUErC5LJKllhb4pphXOiNiSX5NhVmNbG4Zb5J9dS+HJ2jbeTjX1CDSn8pkcYIykzp5xAJmK9Mjq1fYtcCXUiVTpHS2fehHFi5vMWxeApKnt3gfckB0o8DQCjLa2MFKqK9JusniTD10ZTJL1ziq2ipIenD/aiQyJHncAfx6LEpR3/jSPjkywgXx1L77oA6OFtCLywc7mPnW8hK/0jicSsfeMm8cElOtUpQJfJEsUJRQwjaHTnQqWej7zxXTR8i50F0rNhLJFFaoRbCsjgV0siHT16uPQaoYgiYD1xtwggPJNFuAUbxqtILPIQh/GCt9b3uG7zmTBXX5jq2ZMA0StkblyedFWQx6/+6eXFT9E4DMEQFTkvw7UrgE+TdVsNfg== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(30864003)(6666004)(8676002)(508600001)(6486002)(316002)(83380400001)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cDYNI4GcLYHdrTmxttgwCNsjx8ch?= =?utf-8?q?MJYLRGhX56ukV/OMl9bEvzoivEFCQyxJVk8RCG2UXmDNcTHgXrBZilxZ+Et17AA6Z?= =?utf-8?q?FcoPVf9cD2wrDLG6uh6x4ukBK5j32jZoejSPMrEErfBzk1vqFbiXHw19V/RWEHFor?= =?utf-8?q?KIFcBHDwOGfeUO4U8oFXT+NWUpSYwTLcdp5PVVzsAvPQA9Lkcx4iPt6hAx8IUJ6LL?= =?utf-8?q?uMaKuJW9CV8aHwbta96EjMfz3hzfWrDB2AKJM/QralZtWPqwy8TH5YCAXF1Ol2Htr?= =?utf-8?q?sgYnX3PI82LPCF6h8kem/6xb4nnUoHYF7yAtPQ8GF7VBvgP4PGCdiI3Fpl90rWuRX?= =?utf-8?q?vsww4w7KMsGqtK/mCqAlGJicDjhunG+97ayfibqlKZwg1hoN3KDKsH5mGf3nHGjqa?= =?utf-8?q?QdDOdtJZSZWNtwJpK1yVaIw7J7OCRxDMANGuCIqkbWGBCUbuFRQ9wo9GFM+kfVsCL?= =?utf-8?q?p8R6a403Ej9qLP+/OgKe91CsMuYyQp6iDiuHUhMim9RSg1oJpnDyx/0dLIi8ZlaQM?= =?utf-8?q?4mMZCvYd/8IfO0LBJEAa9IOZ2B76uiG1+qUU0bQGmoIxi7cz70WsvgokhwCwDxjgp?= =?utf-8?q?xVg4oVjT9qo4fuvMFLGCNFlUmfpXjVRNQc3sgyNa2uozymSgNWzWzOFkAL1phDktO?= =?utf-8?q?fi8U79E0Fx7FTHqdkZQ9q81Tx4vAm1JyTKgAkLOlcw4tKt2/MAwJTOs6wOjhl8lVJ?= =?utf-8?q?8fJQK4ha39D8ystitF4Q3sS8+ODKMru+aHMwgzaxndAFX6xNdh4vwGjJYRFB5cu5I?= =?utf-8?q?SxiuDi6HVKvG3oEtdOvMWRWrWknRRy4Ix5D50YQACgQq7RzysjpFdrSPRqKhbufvI?= =?utf-8?q?9bf5Ycq7+xYgPt08Kp53eDH9ZpcuAqg6cZNpEv8ldk+qpOB5NlYD3TP0YVikU8eBZ?= =?utf-8?q?q8U7d+OOZZgZjHaqQ17ScLTFaKd7ehWqSeA48Oh9BHgp2vONbcSUFpubLbQnDA6fl?= =?utf-8?q?WAXutXA5rMZU07e+NYw4jYijzRrQHuLYaOd9Bzk9SXVSX1zIW3+zuseXuUyjuftjx?= =?utf-8?q?PyFnD1lbGcViLfWTVQFlbawBK78YepCdrSnISl5APXCfUE0Jo0/9aR5S40X6dnVi1?= =?utf-8?q?eBlxwGLVF1Dv+S3Od/AUfq62uDkcoIAD1CTmplHYK1uugppT7o4Nu6vyJ0xXud6RZ?= =?utf-8?q?ePieEGTkbxQFRYsh69yZCV9W/nVYcVFR/+sxFiRUroiw/AeEzydnp1UneuDYwbOH1?= =?utf-8?q?cq/42q7zhcQMTYYPZ/UyvycXr6Yl7CiLSIF9NdSuO13drKOQNh3S+0q8Q9iTFYB3x?= =?utf-8?q?G9I2iVZvMtaqLRvFqltZhRcwr2MfIWTbIS/s4hcFQxrYlm48Po0UflX74ikdJwbG6?= =?utf-8?q?4uHoClyejWlrdMQIuxU0iwc1HQYHlPgMX3if/v4C6SYTi9CwhHwpQZNjiRxp+w+rW?= =?utf-8?q?JrhJKr686u26mqLVbwCU4fSNTJ6i5iwAgHfmYbXej7JiAV/QRIQtKcZsW9BKv4PFt?= =?utf-8?q?51cmxKk9tew3I8Pku/OtQ8euESrSjDZygt4ygLZBxkfqjeFzlVU7fa0tu6O5TH8aO?= =?utf-8?q?4W4yiebT1n4WmvVOg+3thbdYZYD9BSLuMWjRw1uVmxkffQIbdfF82bAgd0T4Qd7sA?= =?utf-8?q?wV+2AkdskTAbhlTwu6Txa8zLbuUQH0acHj8c8yYXlDtyUEGCuHpXzITfdOS4tCPx4?= =?utf-8?q?xlQreVnwgU3UwRexSSLGGFR6CNm8/URQ=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc185c3d-bdf0-4e3f-fcd8-08da4b1a8a8f X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:50:59.3990 (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: F4g8ubWekkS3bo+ICXlzC3s7KRlDwoa8uo+5iUcGGUfGP8SvaQzQQ5DnSX4TZBMz/lj62DJ4vUKKaFgdc5NLSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: 4H_wF6J8gEr27VWbHmvp3EH5qUEx8XrW X-Proofpoint-ORIG-GUID: 4H_wF6J8gEr27VWbHmvp3EH5qUEx8XrW 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 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 ef8f227fbb..3518833711 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3632,6 +3632,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 Fri Jun 10 19:50: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: 12878014 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 A0A25C433EF for ; Fri, 10 Jun 2022 19:53:28 +0000 (UTC) Received: from localhost ([::1]:37120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkhD-00030w-Gh for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:53:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf2-0000EZ-OF for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:12 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:3660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf0-0000SM-PM for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:12 -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 25AJhws4021178; Fri, 10 Jun 2022 19:51: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=yfvTV6vlX9EDqMW8rNGhZe3NOqy+Kyc+RI+1Wm67LXs=; b=aQWeqzL/FY+W8gli+5+OqS4Fsv/EedLbBPmffTG1RBTIWoNp4+V+m2uqZv4qBUddervT 0HJP6jtAD84JBihkIzkutCHxqfIZQQoFoyPsXkNYteCt/a3q/f/dK9Y5c8g2WVbHz6PL 1ay0zhN4KfSnqVJNDOnmxm9taSkEtXEMcHYQJrj14591cu6RKSPHBXEmvTPyre3x0WSk Ehlmyh4SkbdjSANDkH8o84Pj3Nu9oaDpROwF1W3q0/jhznVuY8boGxJgjSLiNQjapjJd GQbGnzpMGkarue1iUlaNtHfhzhswpWbLgHX0W+9U0DoAQqjW8jjm7rWaOsDMiFQkDUyS Gg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfyxsprda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:05 +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 25AJjxAa004500; Fri, 10 Jun 2022 19:51:04 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwuccjdq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jOGHAcWQLMEdjfUz4UYwUMQQqgFGX+eZIyQSYGSFzBAgP3tdnx6NPfYXK7qsxm4EjH3/2Ug+tVWvhpa23a0VTg/TK9IM4HfxjxZh571aRwqjXrMxkExufGN82hmNbvQXhx7FliMwsFGSwlMNfhVLdYaqeX69U2W8DN/3k5eqOAt31sMEnxHO57+WfqdnZRQg88ZybXOb4ZiHgcUWL6kPlf0OWPlIru5kMUtYCN+9Lz9Y3fMxWMbs+Vd7p/nLqKGwX+MavUmB5htsjvHS/O+FMkMpcdZFu4GZuSivSLScLK+1vAwiMrsw/Aqa84JXpRBt+GZmrk6H4fL89cnRuzgQFg== 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=BOq/moN0ObwYHpOaR8D+uP75wE61buBxVagmXAk7JrxMD/aUBVRi0uESLIfYkSB3tOzJEg8R+XgrLYqM4yDjEEsIKej4twwWwdSvO1pyl4R4YW/p9Gt54tlpQX+DD8G9HD/Tl3qBQyjkBBDq9IisDw7fhbnyWb9faqqZVnXBcNEX2RiEO5AzEf81VWx0kA0sLZRfERHvPo0hijsVGLvMSX1+EyEXEwy43AyJaPQ9BSLRMbl+2fYlLnLn8Q+/X4/Sb3jqw89HxDaSRdec8mxArCAXj+SBqzvtlWl0yq/UevHno3APGRc2UybithI/XQj7A4vp9EGGWUihNPL9oNHxmw== 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=nvnLgNYTuTldvNbIRyHox2nSTmcTgNGiUE2TxJ9thurWKslnJWEUj37hwQjcUALMcr2AlSUxCeotcOuLgIP8e7xK4ibRHm+6VnWm1azgamqMwnkkat+jcunhjtg4tmE2OIZ43UfyqIoB0KhaVSOZ6iQOyC91sGgWezjFIiDd+/8= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:51:01 +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.5314.020; Fri, 10 Jun 2022 19:51:01 +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 v11 06/14] vfio-user: instantiate vfio-user context Date: Fri, 10 Jun 2022 15:50:33 -0400 Message-Id: <1e6e6d54e8f84144da6f02497f9e6d3b30c3488a.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 75c5148b-cf4b-4d9a-f96b-08da4b1a8bf7 X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: xC9XQDiBkgBc3vYAigqvNreDEx5eXJ1DjXlFOJUkA/2OGk94sIIuvc/bkkiETw5U7Qh1aDN1eLxVclA3iX7OqKOfNCvChWfoQtWb+Xzokcwiby0rmXKi6XSR0+NH9psJULGh2mBm4lUg4NGHrRa/SIZuRrX8NH6gFhw179cVVubc/E/bWA4a4n+W84Ygh8SkQd+TvWoDyvU8H+0P/hpwH0s+UelVEPvR2wE07qIQ/pwQHw2YH7RqmnOdQCLqIwdbgZjFOMnmHm+SRO/rHdWPlxaUZ7itIYK60yD7Uyv56eKHLYgj1vDRQt0F+56xRkME7IwV4rnsLIqXi9gUix+0sOWUMFNdpTsTYfOgmgOQA4VEgOmGnT+v3P55aDcBfs0XIdicUyRa+EPSd5ut/Wi0YGChNRfgGQh+Wa7IIitZ2ktsY7T6ZD4/IEy0iX0N0CD4BGZsY5yG+rnxOfO8gwENJwvl+kf5TobTWoYlMdAnWzjVGNNLULkpXoy+iNz6z/0wB5ctPoUFXr610zxE8YW3RqbYCVm53oD6V3CRNbKk2qZJREqxvVplwyxdsoBj2X7iGqDwgghdu9d/+Sb6SLhwaUKuUFpdh4s+KarEn+hqa9ahGJjabMpUF+89bs3HN/JpgFheWbF4O/DVwxnNQcmTh1Gz8Brh593XOgUBrs939bqtARJYnoc+b9skFbXNg2Bx2tAin8wYyvjncFV1v49TsQ== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(6666004)(8676002)(508600001)(6486002)(316002)(83380400001)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NEYKsWwwoWsIKAC26bx+lC0Ua1Vow5T/qZsnwDuRDczIxI8OGaeRG3v8S8G4UHx/JAj3B5HRlJQzXKjHq3IFQKIaR7stNcYLwFSZXFw/aDtC+si/dryJztecG8Vdzr/1s9qEN+8f4qwLsgxj9YZ13dZ5LVhh+FC+OHBAbhNyPwClrWILL6uNrAXgFsqC1+ifZvaKd94djEiP0XO1cPufc/LBixm/pVcmLfQAhUFd6gYD2/rBdM0MOyb+U+LMB7gIfZDIwwR6zL13SN08HEjDxfOFYxVS5zk2K+MDlCmq8/StMaAs1EKv12aU6oPzae1mGq1Nafk0+RpA02nuD/E7hcy0UU75jzlOiDSNRI/qJVneIoD+beCuNeYiRGtO7AKEieqDbFnwmLtpmQtHICaVC2eqtrJMLDjtbnvVo6QE1DyyqbZWDcEj3V3hAl/V3xtSP1iUIz+yyYZi96LvQaLGOJDdrNdQqexFQUxxQ40Z4Uc7YtLCE0tPdRoOe0MaCLJUI7G7cFY0OPAGOBsnllZwzg4AEBzdtbEPjq/CwaomMEhZVubcXeXI29Hn2aaa+RRl70yikCbtBY3OMKdn+woU+29AUu1muIkLwCyCedRC6l+NjQj5HUWAAh5sRcOVeoowWgyk6vd9TX/HQy/D/8S5Owtwp2LbuH5Qb8yvDZsfnaIJDj03dlYAXzWbVDbQeJCVYm/zAjQUfJCYAbkPpB/Eb7FcPuvFmchTpM+/VCnRC2OxZXpO2+Cxg5wrzP6R3/LdgSVD2W6QPxPBFSEt1VgevRsRV3Ws0sdMGzXZMaKXLhcEpFXqQj7uNebmSofFlm4Ueqkqd/ZZh6b7/LNhfgXnUv+WATBA4LsO4FyraFQ8fz8oLBAGwp+Sb7klsxx5xCD9qgGsQkpl8L8SrS+i7IPqMfWM5GJj7GRrEbhu4d+buJOOX1xfQztIgrtVQufOslZok78iiiL440CyFinPdtILbkar683r5MOpez7F8n8KCcG9m7Mk9zLkJ76M9kk3lXSWnBz6U2QKlq15dGV+XaFLf2XNkex55+WCRo0GvlLvtO7HXCNZHITcvNy24bAaPuLRyMOIglgA0gHI8m8QhfArzbTKLBv61A+4qOtYJo9KsQkern+ziFPdC6145SP5cDtgEX9rh6DSsrYhnUdSPYVTt0scIoUYDO+axdcgalIbUo4aWYIo/RIW7A8+/BdJ65wnSOGoglS5qcGU77O7Rca20w7OG5NS9srYGC7pIV0KM8lsLs8HjnEVrc47Fxe7FRSshcq/gktRJvLQyiqRxPmhULyAdgpVwkpY7kT4qvQejkigf+oYl2jeOr/ksvCCc07N1WrDzUtoHJCtxmUbUY6kGoJ0ARJ0qj6AR9PMuiAzx8T7tGn43ylP9jq7lhY98oazxgh947FwMtd2RpjnZtivMkCJhXCplrDyvRG4jed2R6FOzQanYjCUMPuABqv1l5AMfK8z2ZJtCEqrhr0jbaK7/IK4FxI/QhJh4UemtuUxpOkHZ7TLEz9lw1f0myH6nVyvUeYffXkI+SNU3taKY/mJtQqIfA9IdZNGor5wLS3Ioszy115qUqolif1tDE3VSMuAz9w28et6JWzI5vKmqA6y5fBsZ2Hd7z7nc2daruTcsQypgWAekDFUmWaFe8NTKQqe7JW6uC/eVnVZCnR3VI45a8fRO6I0ilo3eaYb+W+xT+zT8eDIKl5X2lO9MCrcnH4K+SrwLQi7sEZ7Gd/qOA1GMw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75c5148b-cf4b-4d9a-f96b-08da4b1a8bf7 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:01.7269 (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: jRMESVXJfTFHt9jPkHCeiyICPPEtRwtIeKRNklwXdoeCyRX6999uWb7KRw8LeO2DzJjPgh0YTU409s3DuO2R6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-ORIG-GUID: oLerfarVDDi7alnBP5tE-Qy-kER6Iunm X-Proofpoint-GUID: oLerfarVDDi7alnBP5tE-Qy-kER6Iunm 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" 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 Fri Jun 10 19:50: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: 12878018 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 8DBBAC43334 for ; Fri, 10 Jun 2022 19:57:13 +0000 (UTC) Received: from localhost ([::1]:45768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkkq-0000Pj-Br for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:57:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf4-0000GP-PS for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:14 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:6796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf2-0000Un-Ur for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:14 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25AJhws5021178; Fri, 10 Jun 2022 19:51:07 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=kjuvSOXShuWtOj+Tn15twgPzLKHCZVlNrylsXvHuLRVbC1cakABeDvdl4Mre7gJr9cII dfgqNBV4jKAoB7eML2meQjOM+0+GaY1CbBwXZC6isMgRcQifE/B81i/+oEEcMa3Obcy/ 5rUQZJeybwHh3L3Rj+vyO7psZ/LGwiahJwKahHsAG9QE0cjBpPZ0ZWzbTeR08zDkb3vy 4XSMLCu8vus6PqcsLeSaFCDcORmhyLqsc0AOhkTxomdhmc/uMwPgnBvsnHQ2OnuLndAl 1aEAyjlAMfKwdb4/yVxn9zu7U54F3iEDGlHPFGmf9EK3nZvxJiiJqPYkEt2ONqosZd9k xw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfyxsprdc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:07 +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 25AJkb7i009322; Fri, 10 Jun 2022 19:51:06 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2106.outbound.protection.outlook.com [104.47.55.106]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6bb18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lMkyQAz5lUiJm7cybccCJodilXthSDEyw3NfSEC7zTxvxV13npHj/IO7BClFk8o5SRoCfNSaUBq/+9oL8GDqs6SuZcU4JL+cyo76rbDrvGIZMhPShQu8g+UawKkpUdlEzIawpzLrhTXJKQD12as+b48dWzygxq4w2fuFi3cTWFXtL4yeqClrKfdk7TWomtzhDe4Zi45WxF3hGFx19oKX2veNenHTVECDGWm1XhsC0l5ARRBeNM00jz68ia00++OQWeuUO7ohneNTBAdsMhlgDspqF4sYmYFYfRLS+mx3GdGPk5l+G8SqeMfY+dDPLX3y7FhwKOzbR1yTcbpiRpI1ng== 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=WQYrHF3zuYpJQ+TKDfaSB5aBxAVYgVdecmxsXJqZXytxSF9wL/5yvxz99orBZT7jjsdRXkutVfCdizlQME7f+I/GYVxEXhj/9SOfuyHqIYHBQMMcaUbE/88qDYlRExg/oj2meVUiPoWhwLj8HSooVwjeMhw0OPKSJ8EWiZIbl2sLgjniZhXdxcGKKjL1iP9xzn2ksMmUCxk0yA4OGWa3aScHXxYblfFi9BVFbLkq7HA/tvVPZSbWMN4QqTV47R+NFW36NH/OkblZpUIWvjniYA+P2OOc0xZdfjFZ1CE82rBc52KXBEvCI4TEtYOrcexgcViU2qOZQWBcpSXlIApttw== 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=gZOgiDQzeGDJl/CPq3GEGE8Y/wV6HathsQEU3oQau0xQavNUEOqosNUHUSAeiSXhbhUk/EKvt8KU08HmFrjFG3bLu2qcqFz+WjnqDIW9ASrgb5fI3CSdf4zdrbJuEDTMNiTbXcKZFODj+xHa4Kt5EfyF8d2ZmKNiBX6TsHhHLUk= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:51:04 +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.5314.020; Fri, 10 Jun 2022 19:51:04 +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 v11 07/14] vfio-user: find and init PCI device Date: Fri, 10 Jun 2022 15:50:34 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 579c9a13-f984-4b89-2d40-08da4b1a8d99 X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: pxLN3U7y9d8mZkEfngwYjAeZ7VAXO7jPWK0v3za4nfWh5ayMY9P3fOOTRQOWreDwMRRgiXUytpsk8+B/EOaqG6OY0+J2eXaH3zv97go0bHKVatlC9ASuQWCIHmPtQ+f9+Wz0C2PMPAR/gVmnZE/RmtJzvxes6Y7PcB/meGKWCU67630ulpskagc4r4God/WT/SomCdZE5NDAmbCoo1rYPH83sJwN36SKkku3lm3pNTjlPGDeq6mDJPI55KBw67mg6xXmJ3/xnObhr+r++1X7D93Qnx6faf5o1XgxLZ9v2k8s34MoiYWE7TufrP2XgZ1EArsEoNKWec27Z5JwNrJTru13NC6nYnL7P6RGd2WA69aNdujLKAd1mW/Y/4+L4jcuhEG8vW2n4YEHDUprWvKoYBWClRU0f+vxxdEoPBvjEv29jGP8ih4tS4n1MrbRqhlzRvOsAND5AGiLSgdRV5niU8haaI8UKJ89nX6LY5v78V1V6RqHkTMxQy6uCLnqevBeJg/xcIpfJK8FlnWcLVH5G1Wdi0SHGs95fPiWTgT+mG11R89RONhugtjlyGtZea6NU6rft0Yvaw/sytOuuNAMcZJOfvwH5ELI3Bpp5VNecUt8Yek/EVJSsMNgM+wNezIB/I+eT1/nResXjpSqOTWVt/x/1Jdv/r4G9SrszlqAyQEjzuSDxdqUkq2K43Mtke4Iejt3amWkOWw0WIW0P361qQ== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(6666004)(8676002)(508600001)(6486002)(316002)(83380400001)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jObRkgS0cjSi80ENR0DsPCFmHQRUKSbthd1DfVpl1pVQV/9bL+yi85ZNq/q+MiB4rlndEkKPOV/zcPzVCsDSn2+mfDl36iJmoJGKG/iS5mY7iM8QNEoHZx7WwKIVYssiG676nVjm4G9GdGeORfuAp2R53ppTYVIjdqBW722Sx8fUGOW+aBt4vG8a6rNJDHcUPJuuKVyr3HOaLWUUDfkM5wkz/juMaJy+hy7rQxVHM9CD5vodd2DJQP8/1NhMYmtxId1/caAisG19HR4G5JD0aOiReVF6DXvkYG7v+zrGVTLUz2pTf5G8duofSQrO+YXpfsBBxKYMWElbHjHCRAGgWAT2SL9dd6BskXxmMx5yOHwLytnbb/Cv/vTiQPLgcq8MjFIx1uwux4lIMQ89Hi+UDIFTQ9i6oJnfPab4rORZ7nXlS/KQJo6j7ULhL9Pao5JKnn0ADGYcXLEQRsCK9l1AiJEuNSnKqLPmryaGdNR4wT/we5qXMJ9YiCsGV9xcVX/FX81BTu3smcJw9/fiX7VeBkGAYLGLqQIY7FWcudWsQixqTWn1yDufw8pvfXU1i1me3orWi7MS91m8jF6t92GBDPdSBGSCOb97YG0AzdbRX/c6o5DCmtviosvIEyWc3vV2Op0MYJQ++An/ET7GqH4BRqfqCstpV/WbkqRe9K7DZ5sOd/Or2122PFYkkvxEiy4geSYR5QT+uugaC4MFVKTtYYJHAJhysKactn6HzbvIQsnm4ijyzAEmOvSYfSCEZhloRuQm7omOx2BOOD+9x/eBjtnA4rzfBLjgjpUMgm8usJ5XuQcQvsKGZmuG5gSwSBXXce4icHFinohGBGbeVYcz9o4Y+Y4+uAOhI3y5L/T0EaKXeYF6enM2j2xFC9T2toxuMv9usJByIlYmTghUwBaN/lntYnIr8OM/+Ojhlc4/dLBu2y+KIWyNB0i+dhursuk56sjsGHnEccm6V4ZzG9kOpUGaMQg4LJq+y+pWqcBoKsQQwz5aU5yqcJ3M+ZkaOMfVbXQNuc+vmTXUgL8umhKZRm/oopc4RKMRPhiI8GR3C1GJRV2RLtJF+gZ2bJtj/XCSK0Oo4HLNAxH/80lJuMqQGXXsI8uY/lwACjoZGHA1nVTP6q/XOGkc8/UleSSQk4pM/DWWcfsUmXuYm+SL98mArHEleDr2YHuL3iUmeJIF9EOySW1pIfGVZRUJ/8azNr9tOowggw0jVjd0cASTje48oKA2UxfdNyUjPTMz7meqmB0f+JUl4XX66SuECoBYEHQt/kJpK25D8OZf8vYhzb0jzj7dWWFQKA1baygckVpRic9pPGKIqhC3iSNCEHENR8ZwNzT1d2MMmX2CDGuPElP/dAhRha7FdDm4LANfYsU79bQLuWhQbCXE/y+PfXy89GWwyH8tMyXiKQ6sIXdh+YxiBKrmc2IknLkXQ8mJYAA0+3Oc8A8dBprNJJ7Yf0laOHkHNgRQXj1nbFvH6Oc0MgvYRyy2ToYv0ChJd1slyIq1djQHh+tiKPrs/lNgeOGISWYBlu30XBk4V7UFQM19ruVg3QJLA+LOYBwQwGiFo+LaXKceZKD75c835nXLGBVMHEpcqQlmibXpwGiYvhuaChezHnA2+up5H8XnLuPBpA8f4sWwEM+QiomvILQcS+OAYEQ2HSa4ylklh8Ipxc0X9t0nSwv/0He0FcO5nSng0V/Fhr3ke7dc6/LKMnvZI7ulxNvE7GtITOcTWDRwC6o+a0Xy/A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 579c9a13-f984-4b89-2d40-08da4b1a8d99 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:04.4767 (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: q2gppwRYBX9kiqx0bjKfygekmyhbT5AaLXbERLrtFsDJf5jDVJz1tahLo+Q+E/yWOKyYW2ZNOggwEm1d52/SwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-ORIG-GUID: gtK1etmBd8nd4II2dQ-iwwHvM2hTPE7m X-Proofpoint-GUID: gtK1etmBd8nd4II2dQ-iwwHvM2hTPE7m 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" 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 Fri Jun 10 19:50:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878039 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 B22AFC43334 for ; Fri, 10 Jun 2022 20:01:34 +0000 (UTC) Received: from localhost ([::1]:55448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkp3-0006xf-SJ for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:01:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf5-0000IG-E1 for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:15 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:18122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf3-0000V1-9W for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:15 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25AJhufc021488; Fri, 10 Jun 2022 19:51:10 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=hfNaw4hNyFdEt6EkHam3pLV7nuotXSHrEMYy8obzo9CLlVdYZ6Vyhz1Ei+MfIfSNEPog HgszXmokrGfcF0MHiG77lvc1yzc2ddTtZtIHELHdnebIr+pmmFRj0bH04MZYwTbArNai szUFr36CpmgxTbsgIHTUBTR7loej6P9/MMvKo5yHIz2bEms6KxeLdwqhru7NZyf370kZ hccbte9awqXGJ9I536LJwLGwRzOkEp89YQ9MRfmLT/NhQqDaUvV7tTtA6x+XJSehFrMU 55dgeJFYqaLpzzdIh9Sa+Ulo0nVqywrT0EdNTyZMF8l5qZywcxjfzbB4RIyAlVcYZNkK 1w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ghexem0ut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:09 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25AJklFC023143; Fri, 10 Jun 2022 19:51:08 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6egpt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JIP720iTqiUVZNvpB8Bz2zu3zSWNh5CsDPosejM4QdcypTaKXQDV90sqtd4AAeLB8DKkCamO8W9hoxOQrEz2jKp1tAQqGTQpfwEyInt7x3aGD2LRz7uZfgMVJ7RFOHdwoZownhUaho4hoZ+4rv6iwL2psynLiWM+E7WGHMWesSMtRV8NW9QeE5AGQugrncRbRh2yHxTsM7rG2Qm3w0NwFQ9PSLmfNHBP2HxGmdtlkWAAPBzmR4NTvano3FbIksP4hQAVtk7L99knLnwsR/x74HBQslhG1wjWSxBYyzAHEn18VjC6mDHCXIl9d9r7ss3utXRfERKekJUMsD7c3Dfk4Q== 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=aCPgByc/3XfSuBimVgmIpZinHDwaUZBt1QtgoSH90PC22QxUO0hJkE/Tf9TIKN5UBZqbYQyYQFUaJ4WIh0CMy4E3VWewQXHJHOAnvNOkvnoe5e8uMh7HIinryzANHmDRw+yRu6dw9qRX2j2DzXS37YPc7Rk+JRdp0HX1pOTOveVSfgl+dKY47MLCo380QEykh6uxHKso6NvhN/ygfsP/b9WNxCjOQgC7w0uwSG3tSbT2G9IMvTnMiesQYta+AGAx2onklmzJ0KuxjNz6HwjYF093I9b64S8DBIRe9lkT6SOoDNIoY+vlUIQkSylNuBrNkJsUUROhZpS6VxUQPnhgxg== 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=gKhufIfhdrrooec+y5Ox2jB8KoIKwq1CSQOr2CBUTXpXC+tCtQ983zhKAu/lWh6MobGeMK4s0PF84noS+B6pmktalQhylATwvA6u2QZPbxxOgnq16UTIvxwIaKo5Z2bojMirKQm8Wq5nV/ZJQMZIsIXx2JcW/ocjAX9lv//i4zI= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM4PR10MB6254.namprd10.prod.outlook.com (2603:10b6:8:8f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Fri, 10 Jun 2022 19:51:06 +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.5314.020; Fri, 10 Jun 2022 19:51:06 +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 v11 08/14] vfio-user: run vfio-user context Date: Fri, 10 Jun 2022 15:50:35 -0400 Message-Id: <5e7944c5fd8afdeb2c6f8b1084407a4d57e86f99.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: fde30a75-6035-4d68-6530-08da4b1a8efc X-MS-TrafficTypeDiagnostic: DM4PR10MB6254: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: gtpmwq5vUD6Mf8rGHzkCso76vaSqvgRJEaQ1iTRfQt6Uhcb8eqTdIYdA3GneY2v4Nujgq/rySH0OKOywuNJ8oIS/pxWt/kmw1RKWETqLjGojw5a7wWGTM4q539Dhw8+QI1k9BfdN1sVe0ZEzpMrMYMpRWCNFEUAp2oKXg7N7tADgk5B/m4kRZ8/BhvaVBbqPoqQdVovbqOiy+ZkPUpBXh4xsTtJK5U/rEQuo2nO0HbRL8BGDDnxtZv76cTIKB1vQASCBE1L6lVDITlon61B7THBIB6LJElNralyXVKwZ19lgGsf4k4fsamN9Mxe7myJkLmUyFgLw/C80FIZ7gLLa3q+kq3eY3CTrvF0ao2VNwh3Wvvdsx+qSirxwGF38Tk4SBwdLjlMErp9Val3ehLZu1lUFLyGWpzX9gAGDmANNfMRerhPnM77eD1+qRoBlxJXZu7OUeDLmQpiwDaXICUnAcQxo32qt6i60qaifUynqgRoMKjIxYyQwWlWwbCpmGPpvc76ge/bk/6ub/l6LYBpECjWdWCUuTcFlecLRXBUvnquZs+92TZeNvq8GkI1ySlXgDdTsLInCk2pED/Wg4Nz0B7O182ZRSlWQaXVZIRLlY7DuvewnUhMyGJ+rYmHcuSq4lu53htlQsI/PgDE/TduR7ne+PKKQDF2N1FnImCUcVWnHZjlQHID83HoH1iiWr4jcBEgyWK8rxvaNA2EBlppZHw== 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)(38100700002)(26005)(8936002)(2616005)(6512007)(6666004)(36756003)(186003)(6916009)(316002)(83380400001)(6486002)(38350700002)(2906002)(6506007)(86362001)(107886003)(66946007)(8676002)(4326008)(66556008)(5660300002)(7416002)(52116002)(508600001)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QNOE30ZO1qqim5fL8NWTpMqA8dvo7zkDliBuTaZ0ewpSMBSzDtrGEbsf9AFYBmN7T4mjBr9P6AKAliaKk/onKHSJRsR3PLB+Pm35Z5cGRTJHhxMflvKM3VeAMXT8XLpCvzEyID81LF9xBWDihB4Ug57qWxnbMbR+jZw7AH20+B6TJjRrEikesXDU2S8hzFcE+wc+zEWZYfCDYabli44VoAazCv+2aJvfujwfjnsU/+xB552xNZ2VBdyerBubeTHA3VwfRlzTe7reO5Q7d7s0cuTnKJaWuyr58/ozvy/rlCX9779Aoxu5jGoIiVX84Ah6RuVoEu7N9Johs0gV0MNXeYGfmHiyPbNwTdfR0+4983xThtBL4VEgI+1P+W2PuoGL+vVIRIMT5X2/DBXNiN4c0b1sFRcqrO8Q3rvLFVMQAR1AAP0/ot/zp/ZbuH31SqcdBUb4rDd8NfSCj/ahVMBFMTkzElCEJuwyExMlnFtd/1bL5d/QzfTEn8+h2zRCIP4ME5ZxEpWp/xJ+YUggu3AYX3epT4Be375ByFdiWBGMComJKo8kDZtP74YlggkXejYZ9lJwRMBXS5KVlxhI2hkXIS+jAUob2du2j/O22CtqqDwQkeuYIs0kmGqb7Wi8Yo3EcQ5LVpANcjJkgA0TKn8B4Rw6QIdFL5sZOxRH39ajD97Nc4bMNKAIiT0WOoFlHKrlo2f7nch07v5fS2RrAPYYFsacBiojtEHC5+6uwKqi014v3d9b+TcP2atJwDFd0Dw3ChEXup5ilC2Idm8lexJOzzvEh5Cfa/52EC56xFNyFpZMDwd53TtvllmRZ+NLVPFPC4J1/XSv1fvLWRhDLWnr0xJW8+Yzs0qgusmoYm+OTKVaVt/L4gSd1x2l7CodGoNUvuLtO63q/x6ezPJC6t4waG40STo8dCXmXTa8p/4dUqqVTpiAsgwe51m9bjbivFMwnqQKl+zhYgcv38ltAK63y0GE9wIbEo8Wrzss+xaYI2wWy5j+Crf07YFfGmmTvzEk3k4ozVssXQqvqcKxeGFFBrzEidiLmmtKOBQZccqNtmXDdgnGVHW1g5II0/eAwgWmN6d/i49qrHzvEhubOosOYd5dS4zUft0qFLs8UfOiyITH6yZPwUHMcj1RNlmSD29N7ZFUlOQv1lRnDWhpw8rJxvFyJlWi8vD7+okNVJAZWwHiIJhwBWSm77/BNdA64r0pr+66RyNlUMGqeImm7JY3Bmyd/HAoDl+dv2o7fBndHt9gD/Cj+8E4caKJVxW3G12uI9H++jShbFL4jzYT9vjYXpGyhiEvo3S3HRVgMcosoFEEVIggDS+EEyd9mTQESmHgMgJ9rGheR6CbXDk78LJqeToqOEBr77I8g9lvsq9vot2UVnqxnbgnNFoZ9CrVOOxDTNq3kw7c3M9cavn83hi2Yvc6v+QEcGwsJ5ZlVEfiGUVuqYCghS00QNi5CmgoOHe3La6ApxzKB5xjcUiadDJa03taxdM8qT1zEBag5TkH0+y5DmQOa663URUleusHNnnasW0ez9f47/DcaHF2IW5YkllQJTxKDCIzOUgTm4zaaOieolE0brW3VSCyCkbDTIvhL4VzsmQvG146/PPkUdOgUqfcA4uzqAMRuYF1wg8C/xBxLTn1EuCEpa4t4wwV+t9YdkFV9ZYc8gfhaAGOYAu+A4bMmxiXKJBgOPkbMbUHL/UeZu4UDHHt+fS+bKPtQVfe+vOb9UXveuO1f8Xej7jTmw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fde30a75-6035-4d68-6530-08da4b1a8efc X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:06.8203 (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: ZkHH9AWVnNnElGmQQPdoOJBhjqn+00UxD8R0+SpMCUA6JAFeRaaBuvEfc2cUJtZQwC5oXSZ3c0SdWfzV6+aXnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6254 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: MLjhGrpXEiAPMHtbrCAinkquBIcjOEnU X-Proofpoint-ORIG-GUID: MLjhGrpXEiAPMHtbrCAinkquBIcjOEnU 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 Fri Jun 10 19:50:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878015 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 45D26C433EF for ; Fri, 10 Jun 2022 19:53:32 +0000 (UTC) Received: from localhost ([::1]:37350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkhG-0003AA-UL for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:53:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfA-0000RW-F4 for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:20 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:17228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf8-0000Y2-FU for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:20 -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 25AJhws6021178; Fri, 10 Jun 2022 19:51:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=1ZR+Sgedi2tGRBAxcarfr88tCeKGr2svlbOvCPCek2g=; b=r6oj/w3FVTi0j2vVT1G8fz9QZy/byyfFeDZ4DAUhLsMoBLyv6JMFHZOUpndBqNoV6/8I eo0bHdUZoK5EpNP5ePPPY9hYpInkdgW1Ia9PVvRSEekbrThSU0ZaHAjkaxhYtUd2tks9 TP6+WKtza3heVgN8WoHmmzGTY7NPeQTjCEcpmhva8bWLQU6mQ6R29qXDqbtI/vzsQXSn Z5HQGdapDRi/ZfHs/9mvzKOFBSU9HIsGriBLSiHd8l4LDD8/pHltNfk3Fn3Ol2uxtDAS V3XVGHE2Zz8fBRwH/sHXF0yV/CO60i023tTmHlFpUcf3zcX5+wQiEJRISa5NlvtTgib3 2w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfyxsprdh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:13 +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 25AJkbDF009380; Fri, 10 Jun 2022 19:51:12 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6bb5b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WNomZmvu+X7CGapxP7WyVC0K3nHAjg+rueZHlycvt+94kJXvyX48ePSfL4BWUMlK7q7NtRdgVNCa6PytKRVq3wHTMZpjeOosKrjirR5T0FbNHE24nJbmfOD+Zui7GPUxC9Ut6aOh4HRPIZfo/Ke8XM3tncCjOQ+Pxz1HVuOmsXCAyremXtbPphnrhaHgZV9qzAZUmUnqjEOKonDXUCvuKOjFU9IwA2O7kJSa5SJXCxlWPCVm/gCmJVEIe0OrsA7v55PhqdTs8R8nHYOWnG5v372ykd4W2MPO42K3PKmG7LrwSDAuXY9cuHeMEhcxfIeijRTQNxF9CZwafI4XCwhYgQ== 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=XtEF3wOQvap8b/NRavnxW5wj9vcnIzpdDqoUTYtDjS0Pdh0yop+GP4k9NiPOfHFyWm1DW38Cuy8LSYDG1nJ7Y8Xq3xpfDz3a/3SxJynmUmcl5qFvwvdDJdmm5AEduuzrSLBVfjYJoG64w+I6EPjbZ4P957dagxddfEWIC8jJL3urE3TGMY5DodUjub204+QemlLdsAUtTy9RGY7GojJ2dGtXtag6I+sBLthY0fLFH3S3SayVs9HJ4t3RIwQecr5taBQYbUeV0QgRKJ7skCis6+oKptFQtUJJtuQarYMzkoHZpxlb1PrJYbbLZ+OGwqZUE7s/otEQ0LUdBcpbRBETkg== 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=FSuYVMGgLreB76njS/2Db/o4hdvGelZSv28jJLC6KHeaMB0D9sIuXzY/vPiF4YCHcQLjm2CAAcmdM3EEaCqs1j8K0yZ4sfG7mZCJeTznv3KszPwxkUGT0PVsKyvuE3ST5LwUrmh6EhOm+eiRj31GM4GuvFX1QC0QQgoRwOCaWXE= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR1001MB2410.namprd10.prod.outlook.com (2603:10b6:4:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.19; Fri, 10 Jun 2022 19:51: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.5314.020; Fri, 10 Jun 2022 19:51: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 v11 09/14] vfio-user: handle PCI config space accesses Date: Fri, 10 Jun 2022 15:50:36 -0400 Message-Id: <5b7b7a37251e6b4c8ab7ba4b26ee26785f9069fb.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: 670dc2bd-b355-4aef-61b4-08da4b1a9064 X-MS-TrafficTypeDiagnostic: DM5PR1001MB2410: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: 49CY3Cowlf11Zy4cEoBiNWe81DlN/59S0fBvPG3HnQpAj0tjWAou/0wLwvCfJOw3+nblkvvaFuZ+awvwpkzlIT4aAvgLziSZqAsfr2sRVQzvEXI0RFl0A/O9jmrU8T0eOnf7P/POC7itmCbX1vXO35bc0kBORP+KxJnAy3syribcc7wZfijeaBV4QUPolMzTeEQ9TBz04tikKrxMcYhqoFg1KSvHRMqexuGIE9tRU0+IM1z6N4tAzQ4ZyRuhYJagnPCN2AVaRJuNi1IKrqzPcv4vF4DMOW6B1Lw2Wuhl5aQu8k2XRGbdYQ6GpG8aeAbLan1gG4Sw2LOWOWaJDaE8k/zYkHFWpBbpJloW6ivSMc3vemP4VOx61CPg70/cVfZ10scetwQ/rFraINXilquv1Pdq5qqFhTDhrRsZ3iyOE8+5nNuIiuSiPezyA7q90VepSsqNiQcsCuS7vJuP4WfhjRB0vD5h9NlFygw7YOOCEM2F4H+ofJCoSsCelUf3mh8KOCIRCPzkbFTUCgOkvOw61GLY2LN5UOjFtZ4icasUv5QI1ii8wdNhhWbs8pP/Y7hhu6b9wZBZ5EVMa5qliSmOHXxcT7bouuvpfpB5t5R/jURojyjZXylW5/fCH2qqiWzlnCcj07L1t9whIVSqu03sIAN5wjojHMqYGDi0TH2rUpJlbqho/DGYdFnHTqxDrVwBK/pO5539o5J181HMo5+cUQ== 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)(86362001)(66476007)(6512007)(26005)(6506007)(6666004)(107886003)(6486002)(186003)(508600001)(2906002)(8936002)(2616005)(36756003)(316002)(6916009)(52116002)(66556008)(38350700002)(38100700002)(8676002)(5660300002)(4326008)(66946007)(83380400001)(7416002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aHY2NZOrZjOXYBy7Rh0T/qwg0ezv8gyBPiK6GMADldcgTW9mBYGp2OgyMn8coy4mNuu7Qfjk5+uPx0/bbhqEGMqAmJ9uos1ia7ual4toEKiQCYhsXCukqonHVV2DcQXEFMjgRJpsBL4jrM0xwGp2pLczeJd5jTo7tdUNsZpqHEp1tJR7qSRornE5HQePYaXwShAiNlEBcylXH6375sNKTCx0GUlJxiSGtdeXjYC4Dj4ZaQlOGB+05gKmuGrGLcGTFvw+kHYNIy45cLcLQOWiDFHhBV+5alsdkCF0zr16+NjyUrgfxX9T+H5mVP2mIO9i9DVEvN4LD9I7kKdNcLBEmw65kSEQdaxWy6XwkQEFndmXiSVjcGent1UdApCvT/Du66VmjoV26oLQmevRP24kD+3QTHFGnrrdzsehHBfI1ZRlQkY9KNOI8AmKE5tFtXzg3Ze9tDa7yNg9VVrsM+4jFO2lFYY0sXWH14o4V3ft/Zl/jko5QtZwdF6tcUNvJs316Z3gIVNb+oQiBzg1ipkcQ70ivXn6Dn+0uA38UfS6iga85+aS1CDoGWI5mPxmay5S5qSZKPXCQYzEb+69Ai5LlzdmhduMP/oJkTbbPo0g06o3jSlGhMSNMr2Ywo7YNPTbBiuSArJmVQxYY6QU6oX0CKTs8OAFh7gBDeabWF4h4fuhslu7yt+zAK2RNBjFO3oIpLixGQMXc8pS3qnXJ1UmT9MCW2duoGhrk+eCKSpp2OPe+KhD5wNMSOylCmCoFC2dtjZL4B7FAscWvCM7/U6T1XShpYov5W+yBggfVH3qYprM5BEmbftKnx0RyK0kLxiHzFRO2wUdK9cqFNrsssaDS38J0QbBfQJ0hv6zwFjp/iQaUQFRdygVf/K7NwunqnCnL43moP8o4lI9zwlZLKjJsP3cZUxZUxjguT1ppIa7dmznd2wg4S/o0R+9Qk7R6gRfIYUstUVTpMSZ8fkxx/evBkxMOcX3aV2OCxiv9JuFauqWqIdZUwIMvkvKYuaEJW9pFVihL38F2yNhKTKK8W03dnsZ94OQ/StKxnMQc3/HG1xMVmL2jb5rCCtAamWCBAkWiNOijEA3AlyBuC1I/jw+f+z48H7bl4NBFl4/W1k24vpyNYjHXVxyiU5B9kBGpKcqvNmtyxYbXfxnjVtABssN4RB3Jve29THpLK8jshPB7ZrEMyN12RM159Afc/YB/wwlpYg946Cw8Drob9H4GptyZeFVvqdV42dLPee30zpLOy0rxEJqTKK7FkgcBcaTZNzB/NklySkqKzjcJW+1KRWiPUfpg7Ij4x/2Ma4ZRnz26psTzmgzblszOYEbNyfAHJNT+mWe/XwBzlKZGzPagpeH6wHdwescMh9YYiAjJYe3dXgvcuHx/CQkQfkDUWafrQVzxbTCBmvom2RtZ4EKRxjks3fCGnHybPac1k1rReB19E4uRa7GeOJOz/Dz6vh9g9WmbsKjK+8H/3DblH13XgI8QBx3CVBWqxQJ0tSmnPmmwx6dWgOmFj9O6S7BHIP1yZCxiKzjmHu7RVz0d3oe1y+RFvjcqRC2aeTR2v8Gvdtu+UoDdrtH+zZyO2aCdMsT9VViGiGvlNONwETqUVuvVQbb/PnC15Ho7OtapllKIpwxdh9ym8HfDOJ7xb4p3aNLSMA2U2bhJ5WuvyGKqXxFd508E08ZTWwD4btOX6sSpu9DcljBUJVCzTy/sRoG+EmdPaWy8WfZ5JybpCGK+iO6xIgQGQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 670dc2bd-b355-4aef-61b4-08da4b1a9064 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:09.1795 (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: 0VkxxRIHz2Z1sSM+BgfLY5tRTzhBzLjvL6novt+b+3IQ7GYdIRmKwlXn5tSWo+XVXkKwS2Vn45a4OcgCzjmJxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1001MB2410 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-ORIG-GUID: fzu7p23l563lBYLjfgFf4INZy4TYDHll X-Proofpoint-GUID: fzu7p23l563lBYLjfgFf4INZy4TYDHll 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 Fri Jun 10 19:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878038 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 85B51C433EF for ; Fri, 10 Jun 2022 20:01:03 +0000 (UTC) Received: from localhost ([::1]:53944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkoY-0005qQ-Je for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:01:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf9-0000QH-Qq for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:19 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:28198) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf7-0000Xy-IE for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:19 -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 25AJhvHF021493; Fri, 10 Jun 2022 19:51: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-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=9oE7nv4UN98dpjHJ+kWUFMPHqGsWZViNlu0UZ2S2HYM=; b=dbxsRHD6NaX9sW2y/39jFcNW/gk7cS5wBkm2eyd+NxnkXsLbmuFObQ9bEp2bLtkno7sM 1PYGrUNB8j9qcQMkevq7KpRC39toMBbdx0hg7sFE8lvaGj9m3Wkor4Rq4xLSyN66s/Za Gw4ZKhW/GzThcmI6FhKmsnikxhNaO9uyenJknXbfuMH7yh4xX12na/U/PzhGmNjEnZ6r eo2wdDEb3eMaqPH4JWINQidv5aTnW5HoPHsLj1bM7hlaICDT35Z+xVtDrKH8OiMoQc9Q mZvR0vXwllbmk8YBYlK/RGFXFgo/jlMXQhkBASUvO7u9MEhiM7ZlKZ1cgkfQVlB/I1wz 0A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ghexem0v0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51: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 25AJkRgU012900; Fri, 10 Jun 2022 19:51:14 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2175.outbound.protection.outlook.com [104.47.58.175]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6v6ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MrQQe9aGdqZRQ6E2c2D0fk1tRdS42pkgT3h5LdYLgjfYJDdkiF9jpyF4Smi+pBZT3q5ca7eNDDmR3clEbz0x8x9tMwizOFtDWHbBrY2CydXM0YmKKn5fin8Kplzl4+FoagRBmQF/oprVkEfq/M33n6ivGOxTutB1JLWw637vDKeT+ignQreJLdVSMBNppUIiMEg0EfuoxQNMKWfpiUoJoULGKVuH6//vyOPiT9qSEP5esvdOKBbY9fC2kMUEpmyemxw52fM78hJ4ovlOe2Fsih6obb/oJ+7xe5l2FvIDoQGy0qFbMu/Z1+q9FTXI4STMKCeavUrORJDlbuG1jOpPSg== 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=9oE7nv4UN98dpjHJ+kWUFMPHqGsWZViNlu0UZ2S2HYM=; b=T5LRouzJ6fi4wcQYnC6i2CD5w0PZ/ScqVZDaVZFxsl+gDc0q1C7ddf+T2i2OmQsiVjMl5aDB7Ni7C9+T9vfDFCBIA/Z0OdQ6VsiUmQrubky16LOP2YUlgJfF/ALYRpKfvSZ0lCF6eWTOX9MJVRctsGBKt9+m37MjoXp5Dw6R5uXCr+V0DTx15Qr48NghJwaKep9abNgZJ+1cmlZF5gXndjUDXgdzhVBBfo6MfIfriCjfzjiF7y7C658V4R2gFkwXC6RT7BfHF5XFsyY14j5oIR1chi4MEaZelzW8PeDMTHhs8F77KpG8ip5Ycsl1GuZOuFxm/+8UEetJpnzU77EtDQ== 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=9oE7nv4UN98dpjHJ+kWUFMPHqGsWZViNlu0UZ2S2HYM=; b=R/5wtc5CWlWAOZ3n0lXFTI3U2jJ57CIFpY8z9CViJjSO39AAENcI51A4ixJ18Jb4HLScKqUTT/TFoUP5e+N63qDrmxmD10Rw44iGhvYU98bIE/1Cbx/obathrhn7uX1Q/tTCnurN67/Mzrk9ohI1RHUJcqhZ88ql3klD34cRFIY= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR1001MB2410.namprd10.prod.outlook.com (2603:10b6:4:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.19; Fri, 10 Jun 2022 19:51:11 +0000 Received: from MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191]) by MN2PR10MB4013.namprd10.prod.outlook.com ([fe80::e9cb:e1ca:8189:f191%7]) with mapi id 15.20.5314.020; Fri, 10 Jun 2022 19:51:11 +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 v11 10/14] vfio-user: IOMMU support for remote device Date: Fri, 10 Jun 2022 15:50:37 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: e0188381-8545-4fba-c06f-08da4b1a91ce X-MS-TrafficTypeDiagnostic: DM5PR1001MB2410: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: ay5B1lXmanaFswlznWk9EehXxlJHJJJs+eOGgXgEUkQd/PB4sVJNlm+TBzpJzk+jGPLmYauDDh5wz3yW8PrDIQ/HbCBXAerJrMKyRnc/4NSzyRvVOsjEQ46O233pV9p++svmixhc9QvsSPC45QoVYX85z9lhFiL9cHC6TDWPY3IrcFTwjJPN98AeDnx3MJCIGE3KOp3gei5z0RPsPRSzwCaIN6j4sLyDot8aesChOMjGPjAxpHRV9U/Lz1drLgLj4Mb1a5+6z0ab2issQemhz1l649r3CdHlLgf33sA2l5fAjd6/qUT1vnO9hL8gQK4IIEdpjCRTFZZDD1Ssy5857nFOFOcCg2tj8eXJXTR7xZkogX6U5NCemqOYCk6q8fWO3MZZrOu6iM3rX37dtB4unBvowRlrI4XeY6N4s37c8EErdd5CxDU7O894JGwgQp9+OGyE/KEh52z0fTdDMgfhUQvA39z+n9RdfkGYXcIW6iPkuU9QyY/SBrlsV1wmyhK3Vz3Rwfo6xRV5jNggizaJisB1LKITpmySHZShB65HCzH8B5hUyaAf1cPLXc0r161bXDIb6VUGPG33uH8iM5Wd6ZKzU2zM33t/3V7qT0tOU4dNofK1dCr9DzKo9zyxbTEnhZMlqSFuAL3W/eu34hKx5I/Dx2izkbSlbjwLEvyOBYbKQ2NTrO/rIKvg7m2NT1Y/oEu+JlCFEtOuhlhuR9umKg== 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)(86362001)(66476007)(6512007)(26005)(6506007)(6666004)(107886003)(6486002)(186003)(508600001)(2906002)(8936002)(2616005)(36756003)(316002)(6916009)(52116002)(66556008)(38350700002)(38100700002)(8676002)(5660300002)(4326008)(66946007)(83380400001)(7416002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?72Pw1LpJt4NYXWAoj0qrwu28xkWI?= =?utf-8?q?j963CCHbfUx/6+ECNQi+HTKIL1m/LavKDqjZLk3gvm94b06AIiPXIJczMCI3+k8jT?= =?utf-8?q?l16FsD/X5zoaEX0RSazrzZFbv8+Wie2XTU41IeAbgLfzRREG/rxiHZCSSCTMtblmh?= =?utf-8?q?4gPFe5GgfbwcejVmZ7AJuuYUTYJ9ttBrII87TO/UbKBmqhzSSwieHn394bpJYmPHY?= =?utf-8?q?P9iSwyHyDF/lmOjkbk1DqBktmSj8U2M2kOMNgEiD4BubkgJyZNa2XivsXXJPpA1r2?= =?utf-8?q?06t3OBKDnvxBtZzBXFkvSiM/oFiZYj2vyZNu1c3dzHEo9kx8+sbwd1EPjBHVAa0oV?= =?utf-8?q?0eoocx1zQrlfIqUogI82q+cQsZGfHtGhfbrVlXkJdCvCU6YR06rxQN3ncUTRKK8sn?= =?utf-8?q?FGOoYk6nPw+SWYgyfKz9iyU9TehpnntchiYJ6bYYk+OROzQyfhF0YQ6V/RDDJ6JjC?= =?utf-8?q?BT3XzTJ8kruwJF1Jg+N7IYkaysFh6MONkbwbB2kwBLGmNj/ihdH9OY2XsxWhAFZLp?= =?utf-8?q?LJWT4OvoZlEsHYNGqz7YNw+Vn5WmvR4ITuRdzLEyd/XUtZ3g2xxlh4mwJhZhye4A0?= =?utf-8?q?INl0n0LHIcGuAisMe/zqGDRWOpKt8d3rMcM4j3P7azgfyxZK++Lt45Jy0eis8J92S?= =?utf-8?q?OcxS6DH4BTz5lMefL7QFGdHgVnOeEu0LuJQZV2GUJmReBUBkZGtdHxOgRGd1qH++F?= =?utf-8?q?BPGw5jXuV7NahRxLF/pslK5FgM+fLfCpY8Is8OT3P2eg+Jywkwj/PpRK6h7Jhj9hO?= =?utf-8?q?VhxBBjvm09Noha370lMAbVs+UO5Tv1flm/pFjy0MuW+AUaqB/vHFqx/cKQf3ylH1T?= =?utf-8?q?CUTb/UuZTFPTl/VHM+bQ4tz5Gax6BTvrlH/HAtzKyd6SkzhoMJJFuq+QjkfOnlcyj?= =?utf-8?q?8W9fmXstPTUrlssJg6Z/B86vFPeowtqCD2tgCsLxyNrGutj0iTICnPiSCv8iIwysA?= =?utf-8?q?lPuAIw3R7D9WjTEjr/Qhw85rHPVXiQUKpal8nNtVvO1Q1yfig0Mh0+oSe2/0GEKCU?= =?utf-8?q?k+lo+gnEXCbYubMKyIFx2YTAQnXNvWtIxWRKCxnoeCp36ls2Sed02T+jfoayXSnBG?= =?utf-8?q?VCMJ0TB0VWtK/QDGsn+6yqrYyw1dzt0tG4uh66xyFpDMfeoKoAAbld5oNb7+JSbMO?= =?utf-8?q?CqjYfA0Nhvh4si46xA4r7efIe4PJ+Gp3eOuuk0rr0/v5Wh9Fxz2JHcmEdHvixC/ek?= =?utf-8?q?A20rbx9gaJKsIOTqB3QA+mFM8aANL+pILvum2JHoSisfY14kuswPCg2Zigzcs7+hF?= =?utf-8?q?UQgnXxN0ZHkA6yMPG9zziJMYBlNn/pAx0vFJF5LBs/R8JJjAUQuyX/ZbTNAKuOC+5?= =?utf-8?q?seuVRPbVNFXBFvQH9jTCW3b2tX9j2rCRQ1zNRTrzNXtu8eC1baN6Chpan1nfcglmx?= =?utf-8?q?a5jYOG5LqVeRXJQ/Qu1BKb/Z0cs5fEBkKg2rwKGj3wmdaR2D1ytiImwSBXe81a62/?= =?utf-8?q?wuxhye1exUlPwpQIvmJwuTuHeiIjhIoNRbcWfeyBahkKLA7J8DoIehwbQIqzo535/?= =?utf-8?q?GRuA95nqJ6cvUj+jWIRDm9hPI2nRq2/i3i/byhkSYgEw61H59zm9C6mLkwL1mEQzQ?= =?utf-8?q?1QX4qVBRR14AmBPnRARAZBQ6v9b0QlPBZGRWPTYkKKOhQfGFU/fsSgpJobsUGiowz?= =?utf-8?q?2LgYA+GA1dj0BWCBtwn1l+jSW5KBCf/A=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0188381-8545-4fba-c06f-08da4b1a91ce X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:11.5544 (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: FhYjcfsbPWaMVBGQA5UZEYTy+5/Zfk7FsNUZg8CRSTpfyEY/s234gEj+rIwD2nXDRWPrYwJIcOCCIQoMThteRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1001MB2410 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: b6Krr6SDlXyRlQmC_vJ5g60-TMfxZjmw X-Proofpoint-ORIG-GUID: b6Krr6SDlXyRlQmC_vJ5g60-TMfxZjmw 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 3518833711..2e84bce970 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3633,6 +3633,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 Fri Jun 10 19:50:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878044 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 ED34CC43334 for ; Fri, 10 Jun 2022 20:03:32 +0000 (UTC) Received: from localhost ([::1]:60366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkqy-0001se-1T for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:03:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfB-0000Sw-BX for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:21 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:31016) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkf9-0000Z2-2Y for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:21 -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 25AJhqNG016299; Fri, 10 Jun 2022 19:51: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-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=v0TtMtb4msHN7hub68kHMLkIaVoFhkiYdKR+pNRRZvw=; b=t/VueAvH+N/oj/k0toMCyG0tob2rGQSVrE+aMhFMop5b7+JGY/T3kC/hM4x4FhEYhdu5 45RFydJSTtqhOrSwQdd00ZPsEEGmuzVQOMmTwDj2yBe9jfeE0Cwv/am9zxywj3h96ADl uZ37xyiwKyJ6Puj5thpkYtNowUHUx73a3uhTSwXerCRkY4JSGMwo3nZ+Jo7Yr2qWO6nr SXuyqui1sNskQG7TlPAiuDgHNN7ns1WAxTYAFsjqK5DVup5j4BPJYKmVCRGzC6R4Xj1K r9gz7Uzkr5Lt+XDDK4Mx0Otstf8djPWWenIpNxIw+q/R30+/pHcIwzL3AbN9lL/xT7ma RQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ggvxn4faw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:16 +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 25AJjLKc030549; Fri, 10 Jun 2022 19:51:15 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwudf2re-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hGyTK1RJf6YkkfHLOLE4xbnKRNIeCuFUvM5rUrKSg2p0TVXjnfhofStbl99ULCP+Bzw4c3zGUpXyKye5ThVkAi/FkpaCLV3ja/1aaLLE3EFeMtJmIP/BmBswLyHlwPq1I/pouGECgXjirvnCr7Tx9oE7sdIKyZSKJUR2Coqy2mbzMu5NThEi+cr/l2CQ7i+yrRMrMh+QpdFH4tMWe83ONw6njuLg71cgVy4xiRwrlhxpQOh1WXRFpdtS4DIMAp+WP5pWeM+HicsK/DKWENjqPfQXkYE+YZeiK1RTQ5NmPmIHvMQudjwBf1iIco2v+WZ3yFmdsHgVcm0f1Mzvmo51KQ== 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=RKdYiTPrkwKsijKVFQMTpvxi2RYLW+NlEN6QVbCpCShsiJ4EwOuEOZSPhgxYncdTOt29tpkBS6Lh5zQViTK5gDo4K51rWfh65zrSRIXezDhSNUOFDtAtzzZ9EYlt0hKNUgLE1NtlKLAywXdK9tTONvDvHJ/EVb5AL+Ymj2lXbGtE7QjBpVAYkNPO23NiEjvR6JdAeL4IFbwzul2u9EpaoJEuzXxAzlXwQqOMmQLVNptOtoUtZno+/ckV8d/W543DN6FdIz6WksXJ+CZ6ijMFD8p7JatE+V6g9s4ADAwsZPqXIBMwsbuy8jIWnt+Nhe7T93UGTWhgAW+nFgqQB3yGlg== 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=e/7Ts1N3a9XEdFHB7wDl6FIzgo1eQOk61Su0mFIpQSOO8wuLbA7Ggp+3yqofWU8b6NEkStGh9b++3yLh20MhEuZmLCgT8KcNGqmODtgOBiG3KBgZ3lAc1HWZejKYPLcOYWUr6vcc15yv8Dhmmm8PMMcO2Jz8ILlURZRAdsW6WjE= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR1001MB2410.namprd10.prod.outlook.com (2603:10b6:4:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.19; Fri, 10 Jun 2022 19:51: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.5314.020; Fri, 10 Jun 2022 19:51:14 +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 v11 11/14] vfio-user: handle DMA mappings Date: Fri, 10 Jun 2022 15:50:38 -0400 Message-Id: <3ac09c447310f028ba53bec701749831a4df852c.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: d2aff2c5-c5d0-4374-1f58-08da4b1a9339 X-MS-TrafficTypeDiagnostic: DM5PR1001MB2410: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: EIpF2bDt+VkyhZzl56vvDtLf7En+h/52aRtPG3g8SSxQR4f6NA7M6ziZbhpHcsFFPy4PuBKveqqWdmyOOTbFs4g7/hQfn/ulu+A/1ksq1FyG5tNH56jaoziiuCc8Z3nxYlle+Lvx4AUqiCpztqkwPhvLJt407DyEdjcGxj913sgrcL4AWT1ys7ljIQKyLnvb2s7QaxMPilTqbRuXWgl6fJYOMJCUkk7kFOkBCTrVnVN+Oz6NF/nJ3bFL0Glx07ZFx9xtjzJOoepfkMsWW3HGxz7LKZ6rZaIDXIgmcuIg64ogLw19j6mZEVCI4+9wKgJWztSjl5ozKYOS1d32y+G5OpJvPl05vdVFHRYHZEhO0W1Sdqg56AaeLkDa7Nyhc5AAHaEinZ4awGycBnDa8UVaxEh667dvUf/XkhJIeSjTR2nRUi+tlmlbAdvwF/XejDZoR7TkoGvc6oXxtxAMTA0rtgrGfhXCYnvRQ9IrzFP3NHwZSewPUKR61kgfuma6qEgGy5Yz9iO5EHnK0iBYD+XxROsN1UhBka/9G8g2BjPfroTX56bMADVpe8YjJ2B0Y3kwsHkHCnfL4nC1ZaPbzlE+EavqtOuPc/g8QoEN+fW/dn78DB8ogn3rlh+3/khYT67Ho2jvew1POtE4OE+qVR/xo52pZYUqcBCPcx/mz2p5DBU12DhL/tZQBDhfYLUa4O4ZWQ3DGIJaSBW5FrrPk4sv5Q== 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)(86362001)(66476007)(6512007)(26005)(6506007)(6666004)(107886003)(6486002)(186003)(508600001)(2906002)(8936002)(2616005)(36756003)(316002)(6916009)(52116002)(66556008)(38350700002)(38100700002)(8676002)(5660300002)(4326008)(66946007)(83380400001)(7416002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IxgkcClNGP8zXoYQ8GqKM6qMSzsji0D+k/i1ea3ghqpxNO7PoPnvg8ELriMQoFLozd7jsdujNSBpktKw2QjkQOpTQesDbRgF2L786kDI2/Ts5BBHtSOiFuqHMs9PTfTYOdMfrLErh+mgH5QO/vOld6yjSSKtq+/Q/TGkjxb9dAmwg3aI9cPq4gIM1bJ1wBhoDg7d2dVKWzG7gRH5qDDh2tPRAdNGTPboKrqOiERso6dtK0Gdi2OQk5IjvcGmO3IMgLrwn1SgEpnlFEcOEiWWLzkdimSsp3rfcEIHGkpxo3gDG2w+iosEFofgxK4xZu9ShEFHxEc69PWWyZ62FNMj7NC7TwDPmt2bZEoWRLnYJZNeHmfiGdZwomB6EfdJE20V8uB8okViXSYJntO5mgZBKtcOfBFaixkVq3oOofIGwr3RVu3hcgfQ7R0gXz1cLp5a7CGVN+hp7ayHIRcbRamaTFC9c3SQtK+BW7Qxtlrwh36UVt34V5GYjzytfBzA4xYTncOXGRh+ceggKb10veJcArMRF5YqsLZT9FmqmrZOpgqxdy5riFeEV4LKUsE/VpdVUQ3nzIH0m9J9j2dkjvae7cBzAnSae1PahElmmuqbtm0DAERpFNzKeuDECYi4VIOxl0IBClFumYNMbwYnNy8hD01RQdWatYoSoQ4D/t9wtZRxg/YYKJbaOtxuifm2SgGHrODKMl54S3EaK18+fDi2dA0JhmGNTCsZxh6cmz/LiIKGHv1ieNcbdzsrowxX8a9pYNwFtBUJkYOpk6ouvIejdoA6j3ine72C1Oq2VgQCFi+wJuN86Skqw8yJFHbg5d5o3vDkcad5JypFoUiKSLjOlGxZFtq36oi3mz/uA01GaX9Y53tmagA/+EzcIFKWpx5mjZeoO7aYpysqk0/8A7bdCF6a5PC5nPC29hpdFDfRicDgqit9zmFM36JsFqmfKDvI5j/CMavfhZrajisZ0BA2Zb7ceiuUEA3BV1lIow1Zfz6e7RTrQ2XoSVxhEpIhVvZJ78r0oFyZ9GIIiWhTMbY0OJQ8c01QuU4ebFszsmPIXIEpGmdoZvz1F2h5zxtffuhyB0JeLZbx8snXCH1/vz9TROUC1eUSvYaf9iklpVBZkNDqdBypYJ23BnxnXCivU4W+ot+7B4KIRMgQzrmzBSBT9mdq2LAlvsi5sx9dXRk1CwsRmPzDpwK4URbfzZbuN18a0Qc7Do/SYGQe9mm6niLtl9YotF+w6x5v4cj2mrPhci27a8/XXELzG4h+bXOn5HLx6l2C3iHaT2cL8WUJbELFIPhCRipvmU8efGArIKpeIHzDyR/8RBI1w8oE671UNOI75Wj9eBEvutamsKYzCAEz37DmO0gAydtHNTG4a/sDdDHWgz7ZCjk4nPI8pcq93fMD3iSNIEOd9kpNhmsIfZlpraFhEzqRI3vaAWt77NSKbxGg6Xw9hDym+WB/iZA0CJhWI5kSsMI6974jEgmPJ6XMmnN4uEetOPzW4hQHHgFobnnhuQ6CbHe9xxtwET3R1tsNKeuxpifl8NR9ZDfRGZoApHIYbIB1HzNfn155et/qwTwn9CzryA8dQaurw+Efr6kIRxlshz2enXmlaIiDP8/g1Rf3tyb+85XEkxGWM5p02hWUiV5JspSSa3/mohIkJNCTfExM/+FasZ6uAif44hPMKDz+OxGs7+TXIF1IAtxnMQUueCKr3IA7IBGBVD05n6Cd/I5MhjiFDwxaE4kNSdqGKQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2aff2c5-c5d0-4374-1f58-08da4b1a9339 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:13.9604 (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: kCokZE8XBRirSJ2BK418sZG/DKaKLjFS2hkK4X9b1sBDjZkXfg2itDPbEKpcmPGAIlNUge2mH4DSn+xX1sgGXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1001MB2410 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: e7jQiSG0ZPFJLx8gDlZZoIaHfr0Ra9Ld X-Proofpoint-ORIG-GUID: e7jQiSG0ZPFJLx8gDlZZoIaHfr0Ra9Ld 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 Fri Jun 10 19:50:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878045 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 DB3B7C433EF for ; Fri, 10 Jun 2022 20:04:23 +0000 (UTC) Received: from localhost ([::1]:33518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzkrj-0002mt-Bu for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:04:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfE-0000Xp-AB for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:24 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:37078) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfC-0000be-3F for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:24 -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 25AJhqxQ016294; Fri, 10 Jun 2022 19:51:20 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=q0ZoQiqQ8VNWRyoVcRrRZ52S60UByGZKM5tvl8s8qtXa8p9jG4iYuwM4X7zjes4vun2n b4BSWb+n9UsYfPHZSIQU61mqJ2aOD6EYAeBqfld6xd9TEal4XntGdX2K89sYLv8WbN4/ oAIbWHXuCwcyfqJp1JE7nx8u4Wh3MOjdqxPKIzliIBuy9/dF/8oTYUlPYPZ39Di3x1uv RllwuMDVhNUjZEa21VqiDfwctLxhTM61KwQyojjcfd/6SW7SFS+gf2fseSRhMmhUXYMC ourALAb2Uqu9XDU6dTdWyPZyNDqPNoJPIQ6JcwLnNmdGRWU89Gu8rj160+sfE5rKK8Sv aQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ggvxn4fay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:19 +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 25AJkjxQ023113; Fri, 10 Jun 2022 19:51:18 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2104.outbound.protection.outlook.com [104.47.55.104]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6egxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OKDJHQaj1DROCqe6tgCmd5uC9zg+QkzYWDSLYgV8vbFF8rljDgoBwNWEKLFznbMxrAXPhRXERP28Wo/OQAuH3oAVr5UMRx/b7QQgrs/+8KLuhqKgJ7B5UmHRdKviAWfxoPscLlp+PJPecqPtKr/20P6kmjZ2MZ19p47nE7fGE13028ZcPlvDZ8RnCGpJdWYkY4NQHMBLKiQ+uQZVf1uTPdUH3Ysa5DjETd6DWh0HXc7vTAXn1LO8LbmD3u0mEE8PIGhlHM6ZGRseyvqy2imJ3O6VEIYdtNbiOkFA7lMhSpZl1j0gt/tiCaMR8sIjQkLOuSvk5gY2inlJp6K6dqK55g== 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=C50vgmBiYFYEhoscrpnUrrxe+lG6MpTK77+eFLE/V2ihZGApzt9fbQXb2pqgOhMgz1tgxA0StbE8URArXe2ePGbs82cpRYX7brf8ocZoNe2whsEVu2w/B5DMB+cw5/Ogcg/4w11SKg9j1X8eeXNDPYBjNv4ONMIz78wkZMUEqKxxxrWbzWax1WN236OI/jdgV7DNBnfxK8SsUd1B22bmAQp2BeU3lHJ9FZzlD8GQwOtudv7oG5VNApneKVp5yAxxb7ai1ho2w3i4gwF+hPxB0igw6jMRLAj4a59O/t5tkXXEk1qPDh6nED/9uNjTvV0boqTxub63FgMQKS4BBx1Kfw== 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=Ejb6g3biZQy9k48GsrRs8Cn2DwnFQ9tvq8n8CvMhWZVuvKke56u3rj0A4k9C4sSCbirxHslRJlvx1ZHuKlagmfUN12Lyx+IcW/BJSaWExximMqFxteoiTcNNzcjyR7r7R3XTHFHMMM/bIaOGrKNf8x6DNqkrwboix0akJrm0jGw= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:51:16 +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.5314.020; Fri, 10 Jun 2022 19:51:16 +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 v11 12/14] vfio-user: handle PCI BAR accesses Date: Fri, 10 Jun 2022 15:50:39 -0400 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: c00e8df1-1172-4e28-e06a-08da4b1a94a5 X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: SSr9agw645w8vpa6F1yl9qDSOowQXklv8oU7BHvwLg4O0N1inAywaAnOTkbK4S6QAMZLbMOaavDr2uCBOb6oPBwUKaNRjXCDMO+RG3rRn0UsUQuxiKwvG7mMTghzDMUmbjXniO4ihWxB98yPTK2OR/3xSIFh8CiaiRvoQwODvhdDtC3UDO7DMni/twrd/GKH93XYkXK3xIsyvdGEIH4qEzIPIUOgIz2ZvtUrmhqPLZmNsgT7QNIc7H6IsfP2oTipmHUAH7h2lH1x3N90cgo0R4vV7f3rH4CalDrHBUyDaoJf+PJsNu6jU+umYypYC11cUfX5KWBUlPIFUydrB6DSaD4IUeWTNJSzzOt2yQHV9HnKG88nKqE1HFHZLDWMSSnEhXtBLhomFGuyvk2lnqOrdb7EWKQqjVLRsGeIlrvtbaJ+TkY4Tgcw4BzixXwuz2VqVsfVZ7eKRCHz/+gx4k3O7d+Zsm8ZZSww7KNNM/AMrXw1EkQ8aOvBw+whXe+g9ssMRg9qTBhISpzA188Nn0pzITjZHoWQfYFxZRsS1SobJz/tpkaRNHbb8/jEpF84SLMpCTCfzAq3llSKfZ8oDN15QRSEsMhEImHImtRbSgpzQZ2D+sREtd5NwpW5LRwmQEg/KohpCgZ0AwaUsGpi/dxEflLIwbWxH6SWKMwuKaErbEeKWUb9jaVwhsP6n+s1sAxtXTnj4wrN02qenohhWP6dAw== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(6666004)(8676002)(508600001)(6486002)(316002)(83380400001)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3GUpqyMZpOSSW8kbWcbZoBA2fTqQJkHqdppDfESKi3IioValLXNcg7g3j7BXY0gtsjKkMVjTfz4lG/jROf32fZFW74q9FKQqbotuNvTt7VTq0L6eo1L685SHNzeQgWQJXMZb+cDzsXKs+XA9pQrGPu7hG4VjeBdmdFax1MixSivcnHMS0NKWcS1x0bMG8XIdbnHLfc0j5LMwTxunH2qqr1opGez3WjgSRa3g7YpVAC1I+D01z7BCJ873ON/pRwrkJxPV0Tya94pr2OpvcQvEXv94P1tV3XZZ6sbXmHFwkhwh9P55L5ChjguxDavXspO51lEihmEzNZJs9L83Wo36yAW0FfdBTyNAt6m8MRQ69Hmi2Ne7Vk0DcJNFHoGY+XT6WRlksF4NSbePXOuuIVI0yat/xIwCoKg5OoM0UIAifzTjyN4bsuV1XuRPm+KRcmdB6M00annSzUYkNQKJbbWc3Io7UtSYgc9qhXrPDboNxGCg+OoE5Js50SkQ6NcVhNgTYigXNsy9Iw1XiLIGOFimcCV7PSIh0Csz0W5X+I3tYivBb/1agsHWGLSkyc7ce/wylvEAZOkGeKzz2Zg+Dw7ZDYTQ+cWPjIenDmo+PG1nFW+Ynru8i+YJOiqS7rT6oZn+jMPZEyDClel1UQnNHTrljLgGjvJcJOyK+TSAaBC3seCCIPHyYHFfmeam7F1xV72ygavRnAJsFSLcNglUAMBU4bO4IXQYg4EbFnb9I+9o6Tp/IYDyRQ4kpDcMhh6yw49Ymhtp35rivT65mygGyHVuZzlifWqZUaXb+pZ/NRLvlJAHtwzr0McQL5+7euC00efX8tVQ7X7aHUlQ+VhdGIff6vAL+S7lBcFQaCy5/95Z7Dn4u9V9wYxGPw5vAiuj5tl05cnjQX7hjr8vcWPnLAaprTHfYPGjSg04SYK1saTpzWBFI18YfFbuDAYChd2A2BmWFZgXD8pduYDG7rgIYArmaOBVmwMXeW945W79zZlSQtnzTrj3U72o+9cI+w5K69q7V+zH9+FSAkAZKqi3MPIql73v9VttuGVGJ+q4B6k8I/Hf6aZxOJFH/n8zsIt8i4pHOsZxHsNunrxCYl0JCSoIs0CuXupdz74ZJz78A4+eKDlxpVYTOBG3UNc1+V2treYls1X45Gx8MpjM/WVjeHssWJkRuSjBMT4eTkhO71rhDVsalfN59Yi0QJ113bg//xsB04pESU+2r2TdIgqinOyHz2DfWHC5PWfpj1Ny2Nx5FHRLblChZrsTFZVjiiVQvmC/PbVJ1k7+bTULkV25tSJ6PcQl5osSq7//isVI6vzUiY2rjBHmMYz4MmHsXNQP7xVOgEXV7L9pjR1sE70ZtrD0vxrAaeTqDin5hkM7oRXCPxRt5lzSOtYCr5zY6jvAUzOxQs0wTifmi/4/tSde8FUQBy5VGvtqE0E6w8fT5XynizQwWMgqL1QIgfWD9ruqcH0wMfXFiAMvGQ30om6uDu8aFGSDgEBnWV4AxI3DvduGihnktE43QCehZGvfgRAc3V97sGKMqiuc7JvJwqMIIDbz7exgPW/slEMfsOaD/Y3ZJad/eoarzPhRhlI2REEPVGldO7mC87m3bRZVs42WvevWR6J0YN+5XiQ9zgSAQMcb//P1f1/0XwDKNcmo4NrD92E6PDXsdlXKGV1monO+DulzLW7F+GzMfm6GKovnjGM2Ym5HGIEd8dfmp9f4Li4Hkn6PMeiu6ZQsDi3H5AeqB5ueQA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c00e8df1-1172-4e28-e06a-08da4b1a94a5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:16.3821 (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: Cz+eEoxc7MDt5QshAbHyC+eMYRetsKeWWp96eHcWdOm2CRIKcyhA/ZdWxEmo2Qun11/YiD5bMHAvVBOuQ6pdHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: 7wM_BRr7VMS4ouG2uJIu9B8aUTlBpp6a X-Proofpoint-ORIG-GUID: 7wM_BRr7VMS4ouG2uJIu9B8aUTlBpp6a 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" 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 Fri Jun 10 19:50:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878046 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 56E5CC433EF for ; Fri, 10 Jun 2022 20:06:42 +0000 (UTC) Received: from localhost ([::1]:39532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzku1-0006vc-Ej for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 16:06:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfH-0000av-IJ for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:27 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:42444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfE-0000cK-U5 for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:27 -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 25AJhrZD003361; Fri, 10 Jun 2022 19:51:22 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=u0ebSYNx3tiF4jHpj7HOISwBWc9Ym88GW1qxizqK5a0=; b=gtsqN5T15TXeAsCzLUjfPw5/a5xYmhBPvGgRY1qx3HAcggx42n0UeptD4U1ZtULs9fH6 95y2toz8HQMy53u9SPXixjy1/e479xgnhQ7VUiOsFAvcsX91JMytpPtUmmF8Li5FVsQp peqHWLLmpUp0C9CSiUWxUj6qiSZx/mng0sOMZUFe14JdPNUU2n8AjZHE2O/EYwAlHJfv MI13WLgUwNBsOOHaKXhuW0HXSBkf4CXEzROK4acPTOpMjp4xrf8aGuUbvZTMPCcec0He e/b1uZu95NOju4Dj+ApZbrSgd0WD/BOwB/hWCnuOaBqONspeb5lu7G+qnmuy4gzHtPZI uA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gfyekpdn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:22 +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 25AJjx9j004508; Fri, 10 Jun 2022 19:51:21 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gfwuccjqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UdVJi/GzmieOwxHdvhPNsvCayo8WFC9QNkA0pVGJtToiniFXIKfgc8BKnu/laD3zgNpLkKs8pWPuUBwnNFqDT134oMYFBm5KaNddK5dVl/qaf507qbF65Yp205jKr3Y+uv6RLXTweuL2KffNwKzNX10ZRMHqE4Phuru8ddCWohg1EC8lxihOq2P0TRIgmsBcY3rsDKbAJDs6pUmCYlnrhcwENW7Vifk+S7jaoPRJrjeMQnMHYcaOK4Ja4WHC+BqS0zW7HkN0SkezJRGyheiszDia0T5F9QHxgEXGj194vgIqNC1wZCACTR2+2FcMYJruP29AVAEMavMBfUOe0UvLpw== 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=u0ebSYNx3tiF4jHpj7HOISwBWc9Ym88GW1qxizqK5a0=; b=NoWGEg5LpVj/uHdmUn2xOqge0W/jKRWTNYwG8EC9cSkSeBOAXbea/crW7cdr+ApZGOJvoTvIX3q5KQ/QXfscaIKd5YH7P3rDDyj88m8Uv5DQYBfuSNtT9KYlcZTAZ+ecPaHdpqrIYbeJwfhsuHPfMe61+EPYoa89+0Sx23ENybqnp8VqNFwR2e+8VV/9lDrYkxb/4rjEWCZNAptdHmmUceFhju8X02TQyXq5YWrzIl9ZmPE4bJbM2gNBCRtglxjCkJP02ASVs1NmAC5AyRgqIyUTA5XgkLWOCSNiGhJEwc54mj4B7lM4t5p/5PlIbyWQMrvcSuNXxbdxML8B/Wnw0w== 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=u0ebSYNx3tiF4jHpj7HOISwBWc9Ym88GW1qxizqK5a0=; b=WRXobG1AMp6Fqbifxp4+qtUdjZZuCPwFnmzQwnt7DXlvhPb7odackglkpQ10xHPi9LnlCFTgoXRrMai7Uc2IKGz+pdWzgNTfCNHUXYGDzvOpX13EeLB9rLbf4W6LTrlL0eVh9IX89tBdcalSelCCP7MQThIhos3UqExV/CZ8/W8= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:51:18 +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.5314.020; Fri, 10 Jun 2022 19:51:18 +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 v11 13/14] vfio-user: handle device interrupts Date: Fri, 10 Jun 2022 15:50:40 -0400 Message-Id: <1baf753065d5d135b7638fa099c6929767aba1f5.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: ffe65517-e85e-401a-c87c-08da4b1a9619 X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: RUa54/+++BI2SSVaDXeNISOGuKwZtGkSZWOtgDZteJNMgP6ivXROkDqjKHw287ScEfxAeer0ILSEzT11FPzx/FD9aQ6qy1TqjEu/xdBmk3tLuGh3O6h6hUQKmnlOiTvUd5TlG/n1GdLGSH0CyQ5ujtTV8fMy7sRxNIEAfZo1bMjeKw/Of8d80oAeM90I9eHuqZa6l3IcoE/5t4IUlMp0fP2e/E+Y8HvrIigTo5H7wwJGvrqkSQbxOr28EO8MdgWNvuTyLE5BBmo+/FzP3EBk0kDgeTC5tti4CKw3CDd2URrdZMBkk8TXykqc4rASbVAJIBeTZw8B+aaArrg5YxqKCH7KJxxR3SbQBnjVY4hlYPB94bnMRwZdwQm9BMoBWjLUKQeuQhAZTwHcpEAgUqi5XkQ5J3o2C6a/as8LvjRnQa6FFVbsnc9liI2K2aIuu/t7rq/y3A9ZuAfLf6ZpLD4OxokpAQI0lLklKMFxELRL/S9b9b/3i3GOaqlP5aBfqorTGH1SGMGIbJR7yYKJAinDl+L5g7fdYwvWQZg0og735sxwilCnabzTKNx6PT5h9bu1w1uQPEvAgGL8lHf+kEx5cau4Wgp3g4YPy16jdmh8ueVXCUSyA6K8wif7HDFKbRdxkiI1vSk66GxBxZACUQaMXXNoClmQTuK4OafLE52y+IF3UFyjKDCwmtEwB63Q6+wuNnngts2Hn4k6dR/ZmPENhg== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(30864003)(6666004)(8676002)(508600001)(6486002)(316002)(83380400001)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XJLUgj/nje8rJyY4T7zN2wqltxmwZQ3V5EKb5rqUPhEstQP8ubi1HeItIsh5xtp1FGc5MGnTa2dmaFST71ioqFRGikRciOL34U6A4iyi3rfsMk/vO8Q0PDffer5mQYd//5/+/RYouOxM30ILfHZAk/YZtbeLh55FRdIG7q59SD6Kdu2JsT8JcF/a9UtNSYkPILKw0eJ4FCSDiZQWn/eVyfVbpqm10BTynWGyr5FIRMGgOuv3LkPuiJrNRwva1qWguPBaVW9YRYhavbvy+ECOSjkPXEOqOMmXhr0anIkLQOQjsB24NRSlvEB4cCdBjre3yuBI+0CAR9U7QEDxTgOpUPR6KQ9dniwepbvIWsLvBiorLe4r8En1x3ShtTlLe5T8QpuUeccsyX0aZpd9QkAdTnU055B2s9zesF3qPb/3AGjyqOElgbojlezxKGkyhbErNUHjOEclPgaxK7cW1d7fUPpUBoHV47832k30BPcs0ruiahvf4mJ5eydJGbrH1eCwnvlB7I+ByhJ+H1nxw0xmFJOAQAGUHzr5W9lRNpGwxR/9JKqS3cYgpNs8gcvMnkbqx2pzQqZiw+WyVxXxZCUU4KefDSOTbJ01UcCK1WWAHl8whttKX2NP61jbr+jCXujE6YPdBMy7SHmrjOGsI1ecOGEsJBV1G1due3z49EHljDCnRI3BHK7NCCxy6GnHxEAaz72GWSsS8OG2KhQtUcO1TETI3Qi0KgYSXDu1i3MOf7IkK1AAQOmkJE63Wr5TR7gHsz7ZGbFTrLRNK4o4uy87eWOkNKjKILH9k16uCibbsCZRxb6qerMJZCBL9quCQ+1/fUkbmGvfvF3AnzbbG17kV6fTUGSKPr1t8WH6AqhmLrgNsR2nY6QxVcEWnIUtsCNY8K8Sed2COI08kI3NxWs/ZW4aG7FxfacZdKKK5sS0Unr1mo2yZhSgaiS0j7L8xS96hdXMk/zgX1qFDOnbQsA5Lk7p60GUxvG/1WKlePY/FNABOqsNpw2WTz/dPTeVuSKbYQ3EiSFBvN0t1QCcsi/Va6R7LYqCTpk+Hi2Gfv5mhGncgELApVL7cm9L7Jx6knLa/wKoof0ydCA+/xyG/DCZoFFLgh+0RTyxTtX+Fhq0K5v4r3wLxnsZ1jZ3F4GbePbQySdrxsQd41spPE8tCL7EAkj08xMyDnFE8SlTTj+EAfWPQ0czssHrwreKl7OxE5HNYoJ8ZCm/vIuWFV11evW9ZE4YJYq4csKI3uZHLBL++hRV1Xy+ZAXZDdtqzyyuAz7PzBdBJFTfeFI9NZBwO496qzIKmqKDQ5MbvRudrpkBM3scVRXpAFxL8nQ8Uil8OpUri8pGIwnbvU8F4KqsJLPzltaHNA+Wo0smRoB4klJpIdv95cQ9SEv2ff8YJTrOU4yFFx3XI/a91ZSqN7Am3/puePsjzRQh5Dx44kpe295lRP6lljR8V+U3x8c9QS9tq4V1TWvunsGnGdZpPghHB4NfScOWvYQG8OZmanWjfxbpua8toI1hB57FYjtnusL1yWyaTEtVmcu6o1m5P8LwG4pYa9bR3cd9sqwTCtSwkNRKt1qK7kSrTphlS07h1IWR80zWl+ThF7X7jYPlu/Ef6X6UmI0Of/K1ki6uGc80BycWyeUIEzSLRPgzoMymiIt7IglPv2LYbJnt7Tb5VSyDIM9Si6hqK1d6g6RQdKS6UmKeWIqhDwPltZ1mtb2nbiAu133cXuphtcgzwaOaYFuT+fR2sA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ffe65517-e85e-401a-c87c-08da4b1a9619 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:18.7882 (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: S07MqrA7TmiJCCuY9MQFBW+f+AwM7/uN6OccioCC/d05aeiAaK8UMmxR3uSwKc7Lwe6V//hu6Dmgnn9vWYmUiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: NQXIfhGMSAwZG-5Jp_Dlgcu4yy6wrqjs X-Proofpoint-ORIG-GUID: NQXIfhGMSAwZG-5Jp_Dlgcu4yy6wrqjs 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 --- 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 | 48 +++++++-- 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, 296 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..127f3d5111 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_irq_state(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..f6ab96ed93 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_irq_state(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..59f34e3568 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,38 @@ bool msi_is_masked(const PCIDevice *dev, unsigned int vector) return mask & (1U << vector); } +void msi_set_irq_state(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); + } + + 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 +374,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..8f774c88ba 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_irq_state(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 a9b37f8000..435f84393c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -317,6 +317,15 @@ void pci_device_deassert_intx(PCIDevice *dev) } } +static void pci_msi_trigger(PCIDevice *dev, MSIMessage msg) +{ + MemTxAttrs attrs = {}; + + attrs.requester_id = pci_requester_id(dev); + address_space_stl_le(&dev->bus_master_as, msg.address, msg.data, + attrs, NULL); +} + static void pci_reset_regions(PCIDevice *dev) { int r; @@ -1212,6 +1221,8 @@ static void pci_qdev_unrealize(DeviceState *dev) pci_device_deassert_intx(pci_dev); do_pci_unregister_device(pci_dev); + + pci_dev->msi_trigger = NULL; } void pci_register_bar(PCIDevice *pci_dev, int region_num, @@ -2251,6 +2262,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) } pci_set_power(pci_dev, true); + + pci_dev->msi_trigger = pci_msi_trigger; } PCIDevice *pci_new_multifunction(int devfn, bool multifunction, diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 645b54343d..75d550daae 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -23,6 +23,8 @@ #include "hw/remote/iommu.h" #include "hw/qdev-core.h" #include "hw/remote/iommu.h" +#include "hw/remote/vfio-user-obj.h" +#include "hw/pci/msi.h" static void remote_machine_init(MachineState *machine) { @@ -54,12 +56,16 @@ static void remote_machine_init(MachineState *machine) if (s->vfio_user) { remote_iommu_setup(pci_host->bus); - } - remote_iohub_init(&s->iohub); + msi_nonbroken = true; + + vfu_object_set_bus_irq(pci_host->bus); + } else { + remote_iohub_init(&s->iohub); - pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, - &s->iohub, REMOTE_IOHUB_NB_PIRQS); + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); + } qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index dd760a99e2..2d716e6391 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_irq_state(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_irq_state(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 2e84bce970..be7de50270 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3633,6 +3633,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 Fri Jun 10 19:50:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12878020 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 65B09C43334 for ; Fri, 10 Jun 2022 19:58:05 +0000 (UTC) Received: from localhost ([::1]:48532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzklg-0002FW-Cp for qemu-devel@archiver.kernel.org; Fri, 10 Jun 2022 15:58:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfI-0000bG-TK for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:31 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:46288) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzkfG-0000cU-TO for qemu-devel@nongnu.org; Fri, 10 Jun 2022 15:51:28 -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 25AJhuHE021480; Fri, 10 Jun 2022 19:51:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=WYJzEwinvFw5eeirBfYBuhwEJrv973cyD+cgG6PxnXg=; b=IqsFtFZ3hsBrNXM1DSzNP7SnMuIlaWHKgWvtBAFcQjDd+eNNROEux04X0lWzwcd359pT O157lnc5OTUbzaEpcOMRpnvtUOfk9bLS3ZYSwjFNPRdY6KopPEuh2IhoPo8wI4LebdOX oDU/g+DWIkuyV5aXMu05gMIc+/U3V1yi9HzFJjmx3l4yH8D3j/mLtwkrLEHyate2IbuH SY6/280OD+R0Sp4mLv3r3cfsRyr3wwNu7EiGvYZv2qKwBHFI1Cuf8eSCVHx2DQIXunJb mxrA6wnAwyuXvjISUZyK42utCS8i+0lPSrI315pyCuWYulEWQKLK+an9EiN31C+tXTl/ FQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ghexem0vc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:24 +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 25AJkbGq009283; Fri, 10 Jun 2022 19:51:23 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gfwu6bbbb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 19:51:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjttBUas4BMaNErZqxtAS8Jos0M4jaRx+292KZnjWG0hPvCA6RUuz9NAJRnfpPHAYz4WqrpD4onQNwl5sy1CJau3nkoNDLGKh1XjO27mAnSPUAFtGokiKImeDg+6c4hrGbpR3tcT6ZTBxQQMJnYMuZLCaVR7d39JfFApnv8WwLuddqIzksNCLCn2HXsAOD6Q3UN0JpjdfvMTCcQUgdFSxrZ0FEKpWAryIdQuk8hYaOLUSJLAYavOPKw9uw4B3RlZyOz5pfOCICFlNkxIDCsr+juyD2t5M2OG5mo7FPerdkgeXcXr1KLy9VzSGL0msJ53Iro87sEp4MCC/tjFGo3arA== 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=WYJzEwinvFw5eeirBfYBuhwEJrv973cyD+cgG6PxnXg=; b=eUYFASVx5WMNdYLbfHc+O+W5Bke4MHCme7Uk8v70jLEyDtx1qFpJO8UpTzQMyE/LrumYppC95/h4ZY3bymv0XGDvArhd/dRUXj/lmkf76vHknatB5PCfdPwFwpHoqQXHAZR65HH6YQFIgBWleaai/f2UNrKs9UYDjkFumJyqFU7IHiptYZ55QPK2YD+J19TAFGgO6T496gTqqBdFlhR78RgX6HmoNUBuyUxjeJiIEoTtozM8cedFOI/0EyIYHzt+ujhS6Djc82pj/HbfvrVWVVskMbQ8SqNLcyZvOI1QR3rIlU5PtpvIB/0XV8M4TP/GFlH2odZ9+W5pfNzkYwWQvA== 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=WYJzEwinvFw5eeirBfYBuhwEJrv973cyD+cgG6PxnXg=; b=SYshn0B5qxhhEfk95RPHgtIJjSD8+OLYLihv9EHsvJQjwSyqzg1q0rBEOyFur8/ngBgFQnMzYlXH6CrRd9z6xlGMILrSMYw+TqmI2kUie1HHdifP4ZmNYkb5UHi1jo1yYjuOEpfJOBg9dKT0HFMZtqVPj8Qb9IGIPTJzx2Gc7QQ= Received: from MN2PR10MB4013.namprd10.prod.outlook.com (2603:10b6:208:185::25) by DM5PR10MB1915.namprd10.prod.outlook.com (2603:10b6:3:107::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Fri, 10 Jun 2022 19:51:21 +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.5314.020; Fri, 10 Jun 2022 19:51:21 +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 v11 14/14] vfio-user: handle reset of remote device Date: Fri, 10 Jun 2022 15:50:41 -0400 Message-Id: <73a2c43596d9fa5d04c3faa4ebbf045f87f7cabc.1654889541.git.jag.raman@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0046.namprd04.prod.outlook.com (2603:10b6:3:12b::32) 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: aa8963d1-5c14-41ae-ebde-08da4b1a9788 X-MS-TrafficTypeDiagnostic: DM5PR10MB1915: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: aFRfbOnxMHTWB76TyEGllwmjy51U0kpvoA1ktocVBPuobwt/mZ9WD6UIC1DI9X6a6v6nqj+9q5G8aMvuroFj1j22HXbTIfIK8FaxGJVEUPSM4qJrSrEC3+ERFgXYiPFb7BR8xaQ8Y1/F7KOzbslkqudIgQ+nInFwzO4GZZ3K9haPt2bwnb1PQVzeKxY+c5jMJLuE1OIThs5WkH5sxx46d7YCMwkUr943AWQ4HuCBAU02ApeqhvR3i+JI2ieL7XsmhUN7XtUZ/BG/fHsk5Hwb5MFpIEKXtYsQ9gvluIojmExfmYq5ePRSufYfGnYdQTpI2HH7DIQNsILrrCO8v5/F1qAcDoPIZkI8zBZ9hEPrwCgpGA8DLuiKtcoLJ32QTaTQ6SH1EXbBKAHafjqWHc70N0jtHexRGbOuIdm5OCSUFZzDVUspXh47xoQHvfVuRNgxuf4BPW90tpmpZ1hUucuujlkff7VxmQadJA3o5mC/hkG7ckDHIt856CwZpiT7KgGWn5XEV4fE0HUpDqXlLG7VVQiD8wg5TypMdzw/kPe7hoJGI8LGypDnz5jnB6wHfqWm43Y0gvOQnRTyDrPUNqocWKY7f4VF3g/3LkpUVJTggjacfUsZn2oTWGedHp6KaRNlkf3bkBlB9x1fQsszG0BGr4IX6UQ1blnQfqvr+KnXufdHKXpadY2bHFDOHbGFTBR7A+IMmu+OA81JUlxnHzkJPw== 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)(6506007)(6916009)(2906002)(107886003)(38100700002)(38350700002)(6512007)(26005)(8936002)(2616005)(86362001)(52116002)(186003)(36756003)(66556008)(66476007)(7416002)(6666004)(8676002)(508600001)(6486002)(316002)(66946007)(4326008)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N+Ban8QifD3q1jDgHm3wTsPyUzD8m85jGGHPze3cvfoH0Rll+aKIw7srD/2s7PRbkpQKVIQaunGybpM57mnhP+bS3TVBEgTFC8tOIu86uyDbJorN4CWkeb4CFLg+SbrxRbEtkQrZsmhU8CurfZE2x7WIZDLIf2cSUaHtmJnGwmpLjg8mc+iEkGbFXiGD6Pnk2woq1d8uhnxdosPfBxhobaRn0EvakV8Em2XCp6AWEe/CXYoufPVts66KoFgxhKgfUxKSXMVLgHAzCxEXtmogG4EOaZNH5KAK7YDjsIxK2aFJJKqqD/iyxhPnZiBU8y6Ds0+EyMReBXbaL2fEl0AXQxBEjuarSL9eCdNNZCMyIAPC8VzIRsLG8qkI5jKRxSkQK6pLpjy6whL35pCdhyPcQ8wmuKfHNFoWjkoGvohWR5TMjJeraFErq9NGsRGKt3v3qhcIn3csntqCuVU6t2wcXhpGIkJcwx3agz4wXWL/Mht3dp0pkT0LaHBvUHKb4ZgaY9v+YOOmqI6vFi1IgP9DegYbsS5WEOK9BwPEfx4qc+Kb/cC6P6CHQvAmDCseGxbg9gIn/Japfzb0ZVJ9xUpIJofboH/gJQs+JI4zlUaSwrlcnsNQSudxbA50VvqkusINbst5fz7sZo8QseeAx7lLjJoIBDUQia778S6FmO1LboAmvVVkgYDWir7CbrAJW/G3nN/YMhCGA2hnHaXo4R7KsCSPC9oU0an/d6XMHLndOdklD/KSBVyX1uSKKSub9Pd5rsVtFGJdkRl2m/g0Ti8kk8nFuM63Yw5aQdRlDbW/CMI0XfXUuzp4CX8s4wVZErcaLHyCvoXqBryeyVogZ1zw+OBXUcc0+g3AuNK31lgkB9yM1U5G+ZgC/cESRsRwcn1m1bXrmbsJGopfWVNmPL9jzEfIttuoXY8VH4w/htJRzAT4jot4pJWav1VH55VFms7TrDy4IPR6KrmJPTnMFrZvSkmQU9X+TnNZjgECAt5EFylYLrQ+QjmoVWwZJBlJKpcTexH9ikeMgydMLPfZohSOGtxHtrkFGhWsFKYI8XlSbQA+fEMVOVtAXcsIS6HdAawz6hUgExY9aQGM1I2QN8HAdEMYLb++dzaxTkNVOtIH/SNXYTJ2rGBVSdazjOuYiOdaaSiipLBo0GCSWCUbZd6kNWrZARrdAu9GwnCbJYRqR5MPnIm6asDJGJDYzkFe1Da9cShVmyIDXALmi03VdBs4tZzthf6+w/IzgdTgLLHydU208GoKJlM9wBP2Qr8tn4j04GH68EGTmfEl9dlaakEEjGL4+YMmOVRTiyHN8sCxEEJB/DKUmnVsi5peQhLRlXEh3cm+EwBARcutf32NE4COb6FyluPzWVnynaIj5h+50dLKfUkFzGs+wZdS9db0UUlwq3uXnfU7XBBbFrTdVoTfurl/iM8+f0h5XkJjLmwnMAXDS3dYvwe7sAn3tvJGsS4K2l/6VPfqqN7A3DHDLXddJevUClWuXlBmnAPnZf7u7O0JnQwyLsM7zjMQdDjxNQMJpoqEiXBzNbrjIp1AEUxkzAyc+xERRxZmqgRfDwtuePS4uHSDmyyHhSIVl8yrYOQTA4Th93F62AQB9ikKwCOV/DtURxg9JMGq+2sT3nisHPJLDMwho5IMse5NOGRLoA48TfwgyGQvooVDtEHVYuI2i7bqjKwZVtl715hie3iXzEoMoHYnRSV7S75M6M2n6fPMVfekvSEaLcp1krM4xVhcig== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa8963d1-5c14-41ae-ebde-08da4b1a9788 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4013.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 19:51:21.1474 (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: k31ymjwfDGSXOdNcmtIotziutKP3r3NiexXIwMbnSkCghCWxLImi3rbYQWH7lcZjGXyfncVSBnb6tNaYMvn8gA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1915 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.874 definitions=2022-06-10_08:2022-06-09, 2022-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100076 X-Proofpoint-GUID: 3MyjKp1FRNvnRstKJYpHBtI4mGwgETyk X-Proofpoint-ORIG-GUID: 3MyjKp1FRNvnRstKJYpHBtI4mGwgETyk Received-SPF: pass client-ip=205.220.177.32; envelope-from=jag.raman@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds handler to reset a remote device Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 2d716e6391..c8c61494dd 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",