From patchwork Fri Apr 1 13:23:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=QA3uOl3D; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=tuq3+jqL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLXy1rsjz9sFv for ; Sat, 2 Apr 2022 00:26:25 +1100 (AEDT) Received: from localhost ([::1]:54300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHIG-0002Tw-19 for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:26:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGd-0002NH-Ru; Fri, 01 Apr 2022 09:24:43 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:54468) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGa-00078x-8H; Fri, 01 Apr 2022 09:24:43 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CsYQ8018556; Fri, 1 Apr 2022 13:24:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=XGIdwlf/3ZYMBI3qFL4QVw+awho+MzUXb/Apnnlg9ww=; b=QA3uOl3DGa6Mk/WmK6GB7v+JSR9W0lYW/4zA3JpPpBVXPds+891Dzfe/3dM+Urb1y+sg xJ7NgrJt+JBqAXzTbtVZ7gSCVBICqNqjSQH5xzdGXZRqBkWsM21fMdcu3BjtyEdvp7GZ eIJUKHVZEX1f0xYqCoyJBl2oHd9trhXhlAwc082lvtb2OoPKzdrvK0Wys8MIgtSx83z6 qBP7Ch+mhF/yTmyBx9cNRMRHjJzbuMY440fxL3vySCCT0Huq9itVIXAI8SCcE/jhmOZ7 yZ8BZyL+2bCwEXxolOE+hQRzU2UR/J9DzgoJDFtpbuorIasmNGVIA1cOmDokIZiwbRth WA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1se0q29m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:16 +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 231DGaJ6003988; Fri, 1 Apr 2022 13:24:14 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2100.outbound.protection.outlook.com [104.47.70.100]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s96j1vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hQeWCOawyPKts4Fn/vjy39Btr9RMP6emg8mU2I0cq5ZAAvx7yvlK+TzMtikW4q3g6Tb/Kez01sBoxpeF86MnJcqBpXY14bdrJPv4jF9Lr+WodOs5Tk2cUS1gM6JI+v0lPVlEBJiFQQfnWaG5hPpwj9i2+SBa8Z9jh43K4BbiKdg8ptzzTsBLddJ+Tyt9JHjGHLburMW5ILrj/0ijjVnAeCyGE8550grG4EfpugLOH8mZHU64hVYwaUxK8oSnNC3JUNUFsG9DmpE7hSxdz3xGmfD7QNzT2yPS0sCCf0sXPrSJO1Z/szfpQiComYIpbGwgkUqtrgWIwhVhIwgaovSSFQ== 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=XGIdwlf/3ZYMBI3qFL4QVw+awho+MzUXb/Apnnlg9ww=; b=mMK0GYxvy7uXAjtlqh1OZla/ZrSPYK+ER6URURwx2k+eRVwMXT39fSMX3GjDqPSmLTuk3QykWZUymG+aPmX9d77patgosJ62pPWCQrfojRGvCxcuEwKBnJFlbBTaO5s/mBs81FGfDrjbBdoX3IpxpPpxJmIzRKDsbwLklanbISaIl3kk2B+I/4uwBcL9rsAbxEyXtlrRmH8/Rr7j8aBE3oCdz14BLlvZqUJAbCgrT9uKWXp4LWO1EPc5CLhOvLjslxNPoC0yzUH9NaM0wKhiin5BOrx1gqLzP+miuu8ILHz2EG2jT1z59DEhlotBjV6DcdoYTr0ABsc2adsOWKswFw== 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=XGIdwlf/3ZYMBI3qFL4QVw+awho+MzUXb/Apnnlg9ww=; b=tuq3+jqLJE9OsFRdFDkWaWmcNal+8C/43zARKvh9aMvqIu5P9V/oWEdPCetrAW9uClZvliA2PI5pv+wNEJnSCeCzV7iXkfh4Z3AQsTC/2ytq4kRgfvg85wlvCpDQy7iLXVR47zpYaBxOBd2SSm0SL1k//gka8HkZdJK7NPQnjwU= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by MN2PR10MB4302.namprd10.prod.outlook.com (2603:10b6:208:199::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.28; Fri, 1 Apr 2022 13:24:12 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:12 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 1/8] virtio: drop name parameter for virtio_init() Date: Fri, 1 Apr 2022 09:23:18 -0400 Message-Id: <1648819405-25696-2-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 518aa3d3-6e04-4174-d599-08da13e2e953 X-MS-TrafficTypeDiagnostic: MN2PR10MB4302: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: ZxKEQt/q0gM1b0M8TCbOAAaMFNIA0/+oplZyPzgU9cH7AAEZCT0wRsrt26c5Nolg/krH0kyTFdSX5iLfqYxK0zMFHITP/V+bBBDEC3khb6OxGetWvvGMoFITFwV8kZlXB3Uex3EupIlRhHrcsd9pWVEgRsrqbjSLLu5edMSWwxzGb8c0RfwcHvLkkv68Xdjm0hbZ2VnuFqmM0l05Y9Kxxpa1cRdhFJDfb0FsPwEGcaQXObebxWsy/PO7Wk54eGI2cnIKr59ldrpc6Foh4sfEzUO2UFG4qUqJzRmpiiInNtYYLApSfvkwU7o/XpDLrsU+LB+qRc4CrmhJfeRpcUZHhK8AYBh8sJD47T3jFRKjr4JPIMRm4C7gnmUMmVpahbZE0Bd9lnZFTX0rTMgjtyV1ppgBWy6dNq7vMT1sPJFqcpUZwVNeSn8n49s/rDqhj88mmaRPimQA12S5LKEy8Abn4Kf+y0mTTbcrNY8+9i8mz2L3Bb0wXlchKK6tbLrbPx04WJVXsF5jGAPA9j0LabqE6ZgJ/vCEphPXlN/0U4aEHmNbr75HsO7IrByhJjEMwkS3rL/jtogG/cOC3DhoKM+tpX6inwsN/kkhdFOZhiNaVxcxwMpqt9jyfDvcV/nBwK6gpaWVDNPe0+nI72rTEujMSSqZu7xYmTrsJMei4DfEqL2TAht9kTJ7mzg56vp89O2pXSXQdslzalOqXCWkLWkV7w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(316002)(4326008)(508600001)(66556008)(66476007)(2906002)(8676002)(6916009)(86362001)(36756003)(66946007)(38350700002)(38100700002)(6486002)(5660300002)(7416002)(30864003)(6506007)(52116002)(8936002)(44832011)(6512007)(26005)(186003)(83380400001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rh/Y1dgEBo6+31Z+7xYiUplNHjr9pmLSVHmfHRXxTeF+hscvWKo7GZfYU95/pMgyS9AO2CSoiyz5L1tvmnk9NYG/n0kla/kKJfeL1J7vDRUqCVGQONbjJXfZefyc4ucs2+iOhnwR6z8woJtjPldFSu8qF+0bthb6IcslizdRiHQqY76GRBX8j7HGWdQ1S4TFfAtgZWiWJPMgBIw9Py83a3dYAbLRuBwpPoSYYgeBCALos2b0qU1N3/oFFdNOdg2ALvr90R6xlPkx97mv/Ug4Rwo4emGrrNvgJk5EkQPDD28Z1P4V3HAVqYvGWJQGiHTgHVQtvLHD1vTtvQq/LJdNDSorkuMIz3taf76H5yHRSqVzkWGeXeMWFxJBTJ/usc3TmdZL3/O2Sx9wk39S+co3lGybBkYzt7KHyWGvU4ApRYNYdzAFuzX3VqUuBXSWX43kUR3BuZi6YFsLl3NqeUWhwAT5gZzVTEgjXXZknWeVISpv1wm3fDGrZLCH3/hND9ga6ghrxjNsRa3B/WMx9I3Y40R7AqYaNabVnOKRgFQ5Gu9b9H0fIU/+iHwtEBAB2aDzR1Q9FEQAEYoCMlvjfzpO5WLX7LBDbqEONiSBdKjKSbIpnrYSqRIFOn7hg7jNg1+GnpzdE3vakOa38X9Y+noET0nFpCc9ZlXMEE3vdRIg6zPs9TBJOqI9yJvl7llP34KkLZ4RLOS/Tq10kQlaNRXZnnzaXI56wUAZGtdgnSV4rlMM3Da0r4DH34So2y+O3PVo3Y80yIHBNNHaJ6IowU1ybDou9Y2CYZjXRR9wKmF+TMgwfKRJe8a26sN34O+hLPoVsiyAtA1r7Jy8JKggyib5o5WfFHCqQav3uywGz/qZYWeseNtbEKkVmFhmSxo/ED+yut0ec4oE9bHk7i7d3hvpCLgaatqRVNy85dDhtwWK8lVIhccfrcrjMx6glHr7hqxSpvL1lYjrr3iAnzO/8fZZ7cMyvNHGnJ1KPpaoVAs9JGf4Yxp/5MM/lE4X/mgxVizAPBWm9D2Lwg56VuG4uRupCftxh2mbFoMTizVGkGDeCYGHd6pEcQZIr7rxjX7HlCvfLOpSPR5eu0Efkdx3jCus6EifTVP46QrX25y5UtMbRg88xuyWjkOZdVc4NfH711Bj/zO8X6g5akX2m+JSJRQgB6byVid7DvINQbXZUOLnauNIdpNCVE2+FsBYVlEDnUiToYwd/OABOInjArtn2z75u59VgxfbPBN9BEfYrrJdm9UMhmWFJxxqOi/ipyZOr4aAYbCWOE8MXEf8PiqgB8A5M4cjk3rxTLKq9LEkUCWW/uBI7GDlt/rlV2Rem5avwiZpjQ/o5sWOn6hGOaLlLZLlZS3qsbiuSbJzNgmBr7V/oQAHm/J/hUwT9hDfBukh/+BbjsaqgZ8Sb5AR0DvDmKduUNq6udpe8Fb0N0L9ZvD3PrEsjE4lOJn9NkPL1zFCe0Hbvo6rxKZWYbvIRfD6N/AbThAv6OQPurIBB1wqOoc+O9BZa+609Dzkn/wGGIKarWeKd5ZROyDUVew4nAnKdCBLQeD32X3slrSZ20jOTStfvtwe9Z7+dCWQN7xB8Q9/s1McYwGeg/hEn+JwSJ/39yuNXsI2Tmx7G2pYurK2j70BdYnHpzwzToKj0LgpLtLNtC1EnhsbTdhT+5UBTUbGFGqKty3KqTobk8lDLeYRq1Bq5Y3L8rg85aeChb9QjQ1YCAwdDKOZnnCGTVWClfsCSazpaJA4mEpqyGJmjNUaqSSSD6s= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 518aa3d3-6e04-4174-d599-08da13e2e953 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:12.5718 (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: sbTbSaoLL3Mn8gbXN+jODdWx4GSBx9ToQBocbwj+5xC87Uq+G40bDLp0JcxP6s58jF5P+v5estoMw1jM0uf2KA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4302 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-ORIG-GUID: HVtizYgxSFuP-b01ibiwfreooZIseq0z X-Proofpoint-GUID: HVtizYgxSFuP-b01ibiwfreooZIseq0z Received-SPF: pass client-ip=205.220.165.32; envelope-from=jonah.palmer@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch drops the name parameter for the virtio_init function. The pair between the numeric device ID and the string device ID (name) of a virtio device already exists, but not in a way that lets us map between them. This patch lets us do this and removes the need for the name parameter in the virtio_init function. Signed-off-by: Jonah Palmer --- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/vhost-user-blk.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 3 +- hw/display/virtio-gpu-base.c | 2 +- hw/input/virtio-input.c | 3 +- hw/net/virtio-net.c | 2 +- hw/scsi/virtio-scsi.c | 3 +- hw/virtio/vhost-user-fs.c | 3 +- hw/virtio/vhost-user-i2c.c | 7 +--- hw/virtio/vhost-user-rng.c | 2 +- hw/virtio/vhost-user-vsock.c | 2 +- hw/virtio/vhost-vsock-common.c | 5 +-- hw/virtio/vhost-vsock.c | 2 +- hw/virtio/virtio-balloon.c | 3 +- hw/virtio/virtio-crypto.c | 2 +- hw/virtio/virtio-iommu.c | 3 +- hw/virtio/virtio-mem.c | 3 +- hw/virtio/virtio-pmem.c | 3 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio.c | 55 ++++++++++++++++++++++++-- include/hw/virtio/vhost-vsock-common.h | 2 +- include/hw/virtio/virtio-gpu.h | 3 +- include/hw/virtio/virtio.h | 4 +- 24 files changed, 77 insertions(+), 43 deletions(-) diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 54ee93b71f..5f522e68e9 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -216,7 +216,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp) } v->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag); - virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, v->config_size); + virtio_init(vdev, VIRTIO_ID_9P, v->config_size); v->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output); } diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1a42ae9187..e8cb170032 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -491,7 +491,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, + virtio_init(vdev, VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config)); s->virtqs = g_new(VirtQueue *, s->num_queues); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 540c38f829..27c71ad316 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1206,7 +1206,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) virtio_blk_set_config_size(s, s->host_features); - virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, s->config_size); + virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size); s->blk = conf->conf.blk; s->rq = NULL; diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 6048d408b8..7d4601cb5d 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -1044,8 +1044,7 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp) VIRTIO_CONSOLE_F_EMERG_WRITE)) { config_size = offsetof(struct virtio_console_config, emerg_wr); } - virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE, - config_size); + virtio_init(vdev, VIRTIO_ID_CONSOLE, config_size); /* Spawn a new virtio-serial bus on which the ports will ride as devices */ qbus_init(&vser->bus, sizeof(vser->bus), TYPE_VIRTIO_SERIAL_BUS, diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index fff0fb4a82..8ba5da4312 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -173,7 +173,7 @@ virtio_gpu_base_device_realize(DeviceState *qdev, } g->virtio_config.num_scanouts = cpu_to_le32(g->conf.max_outputs); - virtio_init(VIRTIO_DEVICE(g), "virtio-gpu", VIRTIO_ID_GPU, + virtio_init(VIRTIO_DEVICE(g), VIRTIO_ID_GPU, sizeof(struct virtio_gpu_config)); if (virtio_gpu_virgl_enabled(g->conf)) { diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index 54bcb46c74..5b5398b3ca 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -257,8 +257,7 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp) vinput->cfg_size += 8; assert(vinput->cfg_size <= sizeof(virtio_input_config)); - virtio_init(vdev, "virtio-input", VIRTIO_ID_INPUT, - vinput->cfg_size); + virtio_init(vdev, VIRTIO_ID_INPUT, vinput->cfg_size); vinput->evt = virtio_add_queue(vdev, 64, virtio_input_handle_evt); vinput->sts = virtio_add_queue(vdev, 64, virtio_input_handle_sts); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 1067e72b39..6fbcfd7cb7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3392,7 +3392,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) } virtio_net_set_config_size(n, n->host_features); - virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size); + virtio_init(vdev, VIRTIO_ID_NET, n->config_size); /* * We set a lower limit on RX queue size to what it always was. diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 34a968ecfb..2a6141d081 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -972,8 +972,7 @@ void virtio_scsi_common_realize(DeviceState *dev, VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev); int i; - virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI, - sizeof(VirtIOSCSIConfig)); + virtio_init(vdev, VIRTIO_ID_SCSI, sizeof(VirtIOSCSIConfig)); if (s->conf.num_queues == VIRTIO_SCSI_AUTO_NUM_QUEUES) { s->conf.num_queues = 1; diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index c595957983..b875640147 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -219,8 +219,7 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, "vhost-user-fs", VIRTIO_ID_FS, - sizeof(struct virtio_fs_config)); + virtio_init(vdev, VIRTIO_ID_FS, sizeof(struct virtio_fs_config)); /* Hiprio queue */ fs->hiprio_vq = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 42c7f6d9e5..6020eee093 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -14,11 +14,6 @@ #include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -/* Remove this once the header is updated in Linux kernel */ -#ifndef VIRTIO_ID_I2C_ADAPTER -#define VIRTIO_ID_I2C_ADAPTER 34 -#endif - static const int feature_bits[] = { VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, VHOST_INVALID_FEATURE_BIT @@ -227,7 +222,7 @@ static void vu_i2c_device_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, "vhost-user-i2c", VIRTIO_ID_I2C_ADAPTER, 0); + virtio_init(vdev, VIRTIO_ID_I2C_ADAPTER, 0); i2c->vhost_dev.nvqs = 1; i2c->vq = virtio_add_queue(vdev, 4, vu_i2c_handle_output); diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index 209ee5bf9a..08bccba9dc 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -203,7 +203,7 @@ static void vu_rng_device_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, "vhost-user-rng", VIRTIO_ID_RNG, 0); + virtio_init(vdev, VIRTIO_ID_RNG, 0); rng->req_vq = virtio_add_queue(vdev, 4, vu_rng_handle_output); if (!rng->req_vq) { diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index 52bd682c34..0f8ff99f85 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -107,7 +107,7 @@ static void vuv_device_realize(DeviceState *dev, Error **errp) return; } - vhost_vsock_common_realize(vdev, "vhost-user-vsock"); + vhost_vsock_common_realize(vdev); vhost_dev_set_config_notifier(&vvc->vhost_dev, &vsock_ops); diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index ed706681ac..ad5c8ff5d5 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -224,12 +224,11 @@ int vhost_vsock_common_post_load(void *opaque, int version_id) return 0; } -void vhost_vsock_common_realize(VirtIODevice *vdev, const char *name) +void vhost_vsock_common_realize(VirtIODevice *vdev) { VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev); - virtio_init(vdev, name, VIRTIO_ID_VSOCK, - sizeof(struct virtio_vsock_config)); + virtio_init(vdev, VIRTIO_ID_VSOCK, sizeof(struct virtio_vsock_config)); /* Receive and transmit queues belong to vhost */ vvc->recv_vq = virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 433d42d897..696635b1f7 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -166,7 +166,7 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) qemu_set_nonblock(vhostfd); } - vhost_vsock_common_realize(vdev, "vhost-vsock"); + vhost_vsock_common_realize(vdev); ret = vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd, VHOST_BACKEND_TYPE_KERNEL, 0, errp); diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 163d244eb4..193ff5261c 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -889,8 +889,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) VirtIOBalloon *s = VIRTIO_BALLOON(dev); int ret; - virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, - virtio_balloon_config_size(s)); + virtio_init(vdev, VIRTIO_ID_BALLOON, virtio_balloon_config_size(s)); ret = qemu_add_balloon_handler(virtio_balloon_to_target, virtio_balloon_stat, s); diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index dcd80b904d..0a1f3dfdbe 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -810,7 +810,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_size); + virtio_init(vdev, VIRTIO_ID_CRYPTO, vcrypto->config_size); vcrypto->curr_queues = 1; vcrypto->vqs = g_new0(VirtIOCryptoQueue, vcrypto->max_queues); for (i = 0; i < vcrypto->max_queues; i++) { diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 664cbd9583..4ed5bb16ba 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1033,8 +1033,7 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOIOMMU *s = VIRTIO_IOMMU(dev); - virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU, - sizeof(struct virtio_iommu_config)); + virtio_init(vdev, VIRTIO_ID_IOMMU, sizeof(struct virtio_iommu_config)); memset(s->iommu_pcibus_by_bus_num, 0, sizeof(s->iommu_pcibus_by_bus_num)); diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index f55dcf61f2..465a996214 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -868,8 +868,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp) vmem->block_size; vmem->bitmap = bitmap_new(vmem->bitmap_size); - virtio_init(vdev, TYPE_VIRTIO_MEM, VIRTIO_ID_MEM, - sizeof(struct virtio_mem_config)); + virtio_init(vdev, VIRTIO_ID_MEM, sizeof(struct virtio_mem_config)); vmem->vq = virtio_add_queue(vdev, 128, virtio_mem_handle_request); host_memory_backend_set_mapped(vmem->memdev, true); diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index 5419dca75e..ec74890676 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -123,8 +123,7 @@ static void virtio_pmem_realize(DeviceState *dev, Error **errp) } host_memory_backend_set_mapped(pmem->memdev, true); - virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, - sizeof(struct virtio_pmem_config)); + virtio_init(vdev, VIRTIO_ID_PMEM, sizeof(struct virtio_pmem_config)); pmem->rq_vq = virtio_add_queue(vdev, 128, virtio_pmem_flush); } diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index cc8e9f775d..7e12fc03bf 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -215,7 +215,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0); + virtio_init(vdev, VIRTIO_ID_RNG, 0); vrng->vq = virtio_add_queue(vdev, 8, handle_input); vrng->quota_remaining = vrng->conf.max_bytes; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9d637e043e..cbb4920f49 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -132,6 +132,56 @@ struct VirtQueue QLIST_ENTRY(VirtQueue) node; }; +const char *virtio_device_names[] = { + [VIRTIO_ID_NET] = "virtio-net", + [VIRTIO_ID_BLOCK] = "virtio-blk", + [VIRTIO_ID_CONSOLE] = "virtio-serial", + [VIRTIO_ID_RNG] = "virtio-rng", + [VIRTIO_ID_BALLOON] = "virtio-balloon", + [VIRTIO_ID_IOMEM] = "virtio-iomem", + [VIRTIO_ID_RPMSG] = "virtio-rpmsg", + [VIRTIO_ID_SCSI] = "virtio-scsi", + [VIRTIO_ID_9P] = "virtio-9p", + [VIRTIO_ID_MAC80211_WLAN] = "virtio-mac-wlan", + [VIRTIO_ID_RPROC_SERIAL] = "virtio-rproc-serial", + [VIRTIO_ID_CAIF] = "virtio-caif", + [VIRTIO_ID_MEMORY_BALLOON] = "virtio-mem-balloon", + [VIRTIO_ID_GPU] = "virtio-gpu", + [VIRTIO_ID_CLOCK] = "virtio-clk", + [VIRTIO_ID_INPUT] = "virtio-input", + [VIRTIO_ID_VSOCK] = "vhost-vsock", + [VIRTIO_ID_CRYPTO] = "virtio-crypto", + [VIRTIO_ID_SIGNAL_DIST] = "virtio-signal", + [VIRTIO_ID_PSTORE] = "virtio-pstore", + [VIRTIO_ID_IOMMU] = "virtio-iommu", + [VIRTIO_ID_MEM] = "virtio-mem", + [VIRTIO_ID_SOUND] = "virtio-sound", + [VIRTIO_ID_FS] = "virtio-user-fs", + [VIRTIO_ID_PMEM] = "virtio-pmem", + [VIRTIO_ID_RPMB] = "virtio-rpmb", + [VIRTIO_ID_MAC80211_HWSIM] = "virtio-mac-hwsim", + [VIRTIO_ID_VIDEO_ENCODER] = "virtio-vid-encoder", + [VIRTIO_ID_VIDEO_DECODER] = "virtio-vid-decoder", + [VIRTIO_ID_SCMI] = "virtio-scmi", + [VIRTIO_ID_NITRO_SEC_MOD] = "virtio-nitro-sec-mod", + [VIRTIO_ID_I2C_ADAPTER] = "vhost-user-i2c", + [VIRTIO_ID_WATCHDOG] = "virtio-watchdog", + [VIRTIO_ID_CAN] = "virtio-can", + [VIRTIO_ID_DMABUF] = "virtio-dmabuf", + [VIRTIO_ID_PARAM_SERV] = "virtio-param-serv", + [VIRTIO_ID_AUDIO_POLICY] = "virtio-audio-pol", + [VIRTIO_ID_BT] = "virtio-bluetooth", + [VIRTIO_ID_GPIO] = "virtio-gpio" +}; + +static const char *virtio_id_to_name(uint16_t device_id) +{ + assert(device_id < G_N_ELEMENTS(virtio_device_names)); + const char *name = virtio_device_names[device_id]; + assert(name != NULL); + return name; +} + /* Called within call_rcu(). */ static void virtio_free_region_cache(VRingMemoryRegionCaches *caches) { @@ -3207,8 +3257,7 @@ void virtio_instance_init_common(Object *proxy_obj, void *data, qdev_alias_all_properties(vdev, proxy_obj); } -void virtio_init(VirtIODevice *vdev, const char *name, - uint16_t device_id, size_t config_size) +void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size) { BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); @@ -3237,7 +3286,7 @@ void virtio_init(VirtIODevice *vdev, const char *name, vdev->vq[i].host_notifier_enabled = false; } - vdev->name = name; + vdev->name = virtio_id_to_name(device_id); vdev->config_len = config_size; if (vdev->config_len) { vdev->config = g_malloc0(config_size); diff --git a/include/hw/virtio/vhost-vsock-common.h b/include/hw/virtio/vhost-vsock-common.h index d8b565b4da..076b7ab779 100644 --- a/include/hw/virtio/vhost-vsock-common.h +++ b/include/hw/virtio/vhost-vsock-common.h @@ -44,7 +44,7 @@ int vhost_vsock_common_start(VirtIODevice *vdev); void vhost_vsock_common_stop(VirtIODevice *vdev); int vhost_vsock_common_pre_save(void *opaque); int vhost_vsock_common_post_load(void *opaque, int version_id); -void vhost_vsock_common_realize(VirtIODevice *vdev, const char *name); +void vhost_vsock_common_realize(VirtIODevice *vdev); void vhost_vsock_common_unrealize(VirtIODevice *vdev); uint64_t vhost_vsock_common_get_features(VirtIODevice *vdev, uint64_t features, Error **errp); diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 2179b75703..afff9e158e 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -22,6 +22,7 @@ #include "sysemu/vhost-user-backend.h" #include "standard-headers/linux/virtio_gpu.h" +#include "standard-headers/linux/virtio_ids.h" #include "qom/object.h" #define TYPE_VIRTIO_GPU_BASE "virtio-gpu-base" @@ -37,8 +38,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(VirtIOGPUGL, VIRTIO_GPU_GL) #define TYPE_VHOST_USER_GPU "vhost-user-gpu" OBJECT_DECLARE_SIMPLE_TYPE(VhostUserGPU, VHOST_USER_GPU) -#define VIRTIO_ID_GPU 16 - struct virtio_gpu_simple_resource { uint32_t resource_id; uint32_t width; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b31c4507f5..5d774684b1 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -165,8 +165,8 @@ struct VirtioDeviceClass { void virtio_instance_init_common(Object *proxy_obj, void *data, size_t vdev_size, const char *vdev_name); -void virtio_init(VirtIODevice *vdev, const char *name, - uint16_t device_id, size_t config_size); +void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size); + void virtio_cleanup(VirtIODevice *vdev); void virtio_error(VirtIODevice *vdev, const char *fmt, ...) G_GNUC_PRINTF(2, 3); From patchwork Fri Apr 1 13:23:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=c539yvaH; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=dsXv0Yt9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLcW3HJPz9srZ for ; Sat, 2 Apr 2022 00:29:31 +1100 (AEDT) Received: from localhost ([::1]:33690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHLF-0008VU-85 for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:29:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGd-0002Mb-Oy; Fri, 01 Apr 2022 09:24:43 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:22602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGa-00079L-9p; Fri, 01 Apr 2022 09:24:43 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CvRsZ014831; Fri, 1 Apr 2022 13:24:19 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 : mime-version; s=corp-2021-07-09; bh=zKlqX3uYMLtqym4uxszgAzpjBjv9w+D52TlkO2/ePx4=; b=c539yvaHb4U4fzbMEVtVZH1d05AZPgNTxHrbPEJ8F1gQxTmgT/a5LGqXl6nB+13aqRol /jdKDkVFllNwnudk951oKm6NYw9DP3ZR/aUB3nrtB3aNUCpCZWPNcxAvknpL+PgfbHiv K2VRetR1giofv83Gkgn5vwU/cx9fgu2Ri+EwYLp7fH6TkjSUDXfkjqF7Fb9nl/9OQ30D KPsG+FRGCrsZsOFRbdbOEn3DuHFX4W88uiRb13O8RC5+vt1uRh4/r4/QPE+zWQSGOJJZ n3cyJjC+frURCTh8pBc2AyxTcOKDjAShN1YbRouTPnDe0aqm7o3de2NOQluCllWFehSf nA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1sm2q2x1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:19 +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 231DGb4I024163; Fri, 1 Apr 2022 13:24:18 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s95t9r7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MzwicbqO0DlICwx/+3RPS7QgcpKHwSr+UYV0S5bO8NjQqV63fpf6CDNry2qHnE/2snB0o2mdux71VNr738HFPbnzVx8qQyEvmleEbQ+fYbd+w3HT3HoDN40eePNJnbw4GaqyjiIZEIv6/xWl5O9eyfLiPUIDyXS2d0DsgFshETRQ3Knd5MfN0jNvmGiGe+iKIlrX5poaSIOtzCk2PKBf8pNYTs9soTF8Qlj/xICeaDfp/W/0u2ieJYxy/EZPYXhNXF4a0q/gbgXmX1Z3w7ITDlADZ975jRqhAZ8jLmyv63O5ZUqdcAqWCCnNH5e3FQNuqJ67VZmKI2It1lyCSwBZAg== 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=zKlqX3uYMLtqym4uxszgAzpjBjv9w+D52TlkO2/ePx4=; b=Clxv2uJ/hGAtDbhW6Uw0qKQakPfoxyFhPwjC4fbzViSkEGYs2vt3Z9qYAG8ZKdgJS3/p5IzaZhp2liSz2ShO5WCwQMYi2Iew2CkiQHBhByEVuEWP3PNgXi882nBZBIasNKVSwJz9X7QV4lGjPkEn1CfHHMN5mFSZN/xrlP6wreJIQZpfhzXT+/gCQziZO9WblqEUpmiyNc0Z4NSmzPmd3LwJqVfQzzPiKY4pOduKdcYs9hmJLmc7Di2HSoad9rNy2kBWbkyv3m9Qoklr4IvXNDEtozBP0X5PJBBqQnD9QhHDNadefsbJiHJJP4DCe9pWich9lYn7Y2InJyyoeVXSrg== 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=zKlqX3uYMLtqym4uxszgAzpjBjv9w+D52TlkO2/ePx4=; b=dsXv0Yt9xdvHrNHCyOlJYcQKZDBSqkFzk2z7KLpmF/aThyNdzEwu3vACoCrxC74JKA0DbWars6E+0IcivVjOiNND8I7USgTY2FaL0IDbaMnr7BiKmymZzv65EJynT8hPue/tQeUl74hFxsTsjxb/FP6Th6Wd7SFCRZngpgWXn1s= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by MN2PR10MB4302.namprd10.prod.outlook.com (2603:10b6:208:199::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.28; Fri, 1 Apr 2022 13:24:16 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:16 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 2/8] virtio: add vhost support for virtio devices Date: Fri, 1 Apr 2022 09:23:19 -0400 Message-Id: <1648819405-25696-3-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8605f61c-b032-4a72-7a14-08da13e2eb84 X-MS-TrafficTypeDiagnostic: MN2PR10MB4302: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: cDVX+WiX6PrlphgAGeXlXupSHpjHt8LhgDf9y4SKQ0i8BWtXuln5zVZSvTLz81wnNdCobDyy/KWxKC+HUEJ1DDTIgtNF3zBxdWXMDjB/20EtVnhX0bAjlLsedygwRxsTdpJF76wlXP5/Oo32+2M4KPJpbkZh/GBlpH9fKC89XN7Ws5DEBJsuDZU8Htq+fE2R99A/TYqm8YZjPDk0fGKZ9CTz0TnAINTUbW4GrUCR+eECDdH1zetUOeYlj/x9ep0gHHe52UVG+gk4ohiUdYdrifsA04hO8hi614DLN+izw5BYD3xa97Kv8rF5HkPOJl/sD+gKFuf6i2pz6l0GIWZvUct+A+JPadXTSPYNWTEuKuTw94qL/OI/SNqFry+UJm/wKnZW6UA8sZCeZOZVzmQbvAZmGNm8sjido509wJWKOklWAZQDhfoGoVEUpUdD7/VCK8DTL6QNFpPLQfF2xJo4jY1bxfSZWqbyiMUh0Q5SryVjTuUFdB7X4zt0xjBuAsuHLqjWqNnYJsoKWVI8SG/BQk9ECidaaQwSgHFSGnTXMrVzgZ5Y8Kwd+ys+um5ysr7EvNBXZR0NdIAsshOR1SE/6WK/6P9VXNzv9DQYDqYGxo6IlX+/cm9emxKRWzuj6xDNWBodOnQxoL6g0JbH4g+uOOIH4LZw2id5T4mlGl6lFwht6mOe9+TvbIbjs2/JXz+jPYqeVBM0mnXdkyQQE2uzfA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(316002)(4326008)(508600001)(66556008)(66476007)(2906002)(8676002)(6916009)(86362001)(36756003)(66946007)(38350700002)(38100700002)(6486002)(5660300002)(7416002)(30864003)(6506007)(52116002)(8936002)(44832011)(6512007)(26005)(186003)(83380400001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hMZT1y/agJepk+iMC8v6OhFj6vQ45cr0RRZ0wp5YKEpeZY2l359/6CL+NgkUAam7kjD9oqVzq6yOyjdFPQcZ4uaHjAgghafqlilCo8Y+h68MImTzDuS5LLkBcG9a2TovlrG+kaqI25m80zNcGZL+tyoU2bViVdPVS1hmxfkkCy7U1TYF1ZEQOdwdmnVBkg0iG+zWIJAd9EluRg6YuJlVgMHcgs3Dn+nvPvBeyIPwLFMyITrr4wf1qEG2lM9o3u1TJOjzg5o8zP9+4mYj04XSGPiMA280NmlS4/NduOzvdGXgMOV76MxQdG4ifXaCZvN5nOs2I5aXHI8XEwSf8RI9D3L65Hvq56Mv8WNmLeK3B79MqIBOQWGBr4x+cEwoRWS6O01kNUGyi+EnK16e8nSn6zwbN8jjUToosKCb2yhxPFXAa0Z1yV3sfb8LHBukVWT/PNgcsHZ/E+fC3xj7hwoMvubYnkdRpFJPifX4k466edftr9Bux587+nPDGF4X73XhwTqOCQ7Y+3LRXLL65pfhjyJaLOr3LJ57tvAAavj95fmXjPwKK3d9cfFQNBeu9MhiGGcDMeV/LN6mxt3fqrVq36445dV58efIjyslspspdN9hzZMY/t0JOk6A5c1exKOjjPjQIeI+2/US2ZU1tTgoplIKjS2jormdK1ud1snhVTtFt/3d0A1wie/c0pHTtrYBXfhdX/7TV9AiHvMyWDygfbqLsFaDitqB/1Yrl8bNpHUpXry9YTZol/Tba6xpmU53D3VkRZCmpH19drGnPdTl9ZuXTnqLSgBfFTT5oJf2FvFWrxfe4I9QP3xcVKatGSdoMTf34l+6KCkaHluQQUSC71CN8ibOH7h3XNtITpzhgCP09Jus/uV8qQrDINi83+L4yfOP0ZlrWAVeuEGC6//CDKfJfAHptjvOmM/mqdwWf3F58QL8638TF9oya5YxSMoYmTVWoexpV3COWzqy+LDfJfZuAq1m/n2q8Doo+fqpWCyyJBtNSntkSNmZ52kmbwiSsQ5EDz8+M7NGfO97QFoFpzH0scpSPE7gaQJN3xhuAbXHnr452wgLr8MkILeFOo0US50zuW0b43rAFSB260BVs54AKmolQCfHKhcQXRpxdkBsNBc//iG47wk+vc1WQrRCTwCeRP8NocAnMIsW5CAiZ5MeZXrbv3mvSTXkpCtmhDYHLbD6pm8CKufUiri/C8JFdFsT+9d+jTLrfQ86M5zAZAHC3+m5T4X4/qg9x/TzBjtDAtvASx4cJM56sBsvPMGetLrwzKxKiLH5zLCKnLs+XRht7z1G3qzr7CN4b+djho87lOHUHXAQr71/4KN712bjmAZtpzWIOc74mOZX5nZmnD3schAJjcQNonsjSf1pMuYuwQhv30CRRCVAt4vY3YQU1xlDd3sdSkaGEp9oXgizX5LPVbgSPQk03/US0QLCyq7nsKss18Q+uauwbBCc2f/cZpgx0VxRDiyKatGYK+unVLJ8keJEV1Fo3fbqppca/WKaEXYkerpWTVNJques2hdjXYDqE5QNY9X/WjKKjy4OhL5ZO08sGylTfidasS607pGkBuUju55qd0Am4AnqJRlTlmVrRrt1AHK0jKS7rKD4zVefUK6XQ3Wv/QXXt5LOm7Ndh8sElTtB4guSs5hdsWobuXGbK9v0GTRqTsrTkGNbtvNm5+fnfTU2Ot5VvCqn9wQCtbi34Xxx+Sg+fL3Ktlbx5wAwXUOUT1TX5itpPeOrBX2GFlExc2ei0oQK8lEAO+g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8605f61c-b032-4a72-7a14-08da13e2eb84 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:16.2460 (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: /E5BDBzHwQ4UZGFNGmQENSXJ6t4VB8fPYeQFi5F/6GrEP7AFy2WMb9mINoUyFVvH61hArD0dIHhkvsUGl3qhCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4302 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-ORIG-GUID: wbQDGH12TtvkszXiBACO4vKFknwx04Wj X-Proofpoint-GUID: wbQDGH12TtvkszXiBACO4vKFknwx04Wj Received-SPF: pass client-ip=205.220.177.32; envelope-from=jonah.palmer@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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch adds a get_vhost() callback function for VirtIODevices that returns the device's corresponding vhost_dev structure, if the vhost device is running. This patch also adds a vhost_started flag for VirtIODevices. Previously, a VirtIODevice wouldn't be able to tell if its corresponding vhost device was active or not. Signed-off-by: Jonah Palmer --- hw/block/vhost-user-blk.c | 7 +++++++ hw/display/vhost-user-gpu.c | 7 +++++++ hw/input/vhost-user-input.c | 7 +++++++ hw/net/virtio-net.c | 9 +++++++++ hw/scsi/vhost-scsi.c | 8 ++++++++ hw/virtio/vhost-user-fs.c | 7 +++++++ hw/virtio/vhost-user-rng.c | 7 +++++++ hw/virtio/vhost-vsock-common.c | 7 +++++++ hw/virtio/vhost.c | 4 +++- hw/virtio/virtio-crypto.c | 10 ++++++++++ hw/virtio/virtio.c | 1 + include/hw/virtio/virtio.h | 3 +++ 12 files changed, 76 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index e8cb170032..5dca4eab09 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -569,6 +569,12 @@ static void vhost_user_blk_instance_init(Object *obj) "/disk@0,0", DEVICE(obj)); } +static struct vhost_dev *vhost_user_blk_get_vhost(VirtIODevice *vdev) +{ + VHostUserBlk *s = VHOST_USER_BLK(vdev); + return &s->dev; +} + static const VMStateDescription vmstate_vhost_user_blk = { .name = "vhost-user-blk", .minimum_version_id = 1, @@ -603,6 +609,7 @@ static void vhost_user_blk_class_init(ObjectClass *klass, void *data) vdc->get_features = vhost_user_blk_get_features; vdc->set_status = vhost_user_blk_set_status; vdc->reset = vhost_user_blk_reset; + vdc->get_vhost = vhost_user_blk_get_vhost; } static const TypeInfo vhost_user_blk_info = { diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 09818231bd..96e56c4467 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -565,6 +565,12 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp) g->vhost_gpu_fd = -1; } +static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev) +{ + VhostUserGPU *g = VHOST_USER_GPU(vdev); + return &g->vhost->dev; +} + static Property vhost_user_gpu_properties[] = { VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf), DEFINE_PROP_END_OF_LIST(), @@ -586,6 +592,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *data) vdc->guest_notifier_pending = vhost_user_gpu_guest_notifier_pending; vdc->get_config = vhost_user_gpu_get_config; vdc->set_config = vhost_user_gpu_set_config; + vdc->get_vhost = vhost_user_gpu_get_vhost; device_class_set_props(dc, vhost_user_gpu_properties); } diff --git a/hw/input/vhost-user-input.c b/hw/input/vhost-user-input.c index 273e96a7b1..43d2ff3816 100644 --- a/hw/input/vhost-user-input.c +++ b/hw/input/vhost-user-input.c @@ -79,6 +79,12 @@ static void vhost_input_set_config(VirtIODevice *vdev, virtio_notify_config(vdev); } +static struct vhost_dev *vhost_input_get_vhost(VirtIODevice *vdev) +{ + VHostUserInput *vhi = VHOST_USER_INPUT(vdev); + return &vhi->vhost->dev; +} + static const VMStateDescription vmstate_vhost_input = { .name = "vhost-user-input", .unmigratable = 1, @@ -93,6 +99,7 @@ static void vhost_input_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_vhost_input; vdc->get_config = vhost_input_get_config; vdc->set_config = vhost_input_set_config; + vdc->get_vhost = vhost_input_get_vhost; vic->realize = vhost_input_realize; vic->change_active = vhost_input_change_active; } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6fbcfd7cb7..027ce40c6f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3619,6 +3619,14 @@ static bool dev_unplug_pending(void *opaque) return vdc->primary_unplug_pending(dev); } +static struct vhost_dev *virtio_net_get_vhost(VirtIODevice *vdev) +{ + VirtIONet *n = VIRTIO_NET(vdev); + NetClientState *nc = qemu_get_queue(n->nic); + struct vhost_net *net = get_vhost_net(nc->peer); + return &net->dev; +} + static const VMStateDescription vmstate_virtio_net = { .name = "virtio-net", .minimum_version_id = VIRTIO_NET_VM_VERSION, @@ -3721,6 +3729,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data) vdc->post_load = virtio_net_post_load_virtio; vdc->vmsd = &vmstate_virtio_net_device; vdc->primary_unplug_pending = primary_unplug_pending; + vdc->get_vhost = virtio_net_get_vhost; } static const TypeInfo virtio_net_info = { diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 778f43e4c1..3059068175 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -273,6 +273,13 @@ static void vhost_scsi_unrealize(DeviceState *dev) virtio_scsi_common_unrealize(dev); } +static struct vhost_dev *vhost_scsi_get_vhost(VirtIODevice *vdev) +{ + VHostSCSI *s = VHOST_SCSI(vdev); + VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s); + return &vsc->dev; +} + static Property vhost_scsi_properties[] = { DEFINE_PROP_STRING("vhostfd", VirtIOSCSICommon, conf.vhostfd), DEFINE_PROP_STRING("wwpn", VirtIOSCSICommon, conf.wwpn), @@ -307,6 +314,7 @@ static void vhost_scsi_class_init(ObjectClass *klass, void *data) vdc->get_features = vhost_scsi_common_get_features; vdc->set_config = vhost_scsi_common_set_config; vdc->set_status = vhost_scsi_set_status; + vdc->get_vhost = vhost_scsi_get_vhost; fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path; } diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index b875640147..e513e4fdda 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -276,6 +276,12 @@ static void vuf_device_unrealize(DeviceState *dev) fs->vhost_dev.vqs = NULL; } +static struct vhost_dev *vuf_get_vhost(VirtIODevice *vdev) +{ + VHostUserFS *fs = VHOST_USER_FS(vdev); + return &fs->vhost_dev; +} + static const VMStateDescription vuf_vmstate = { .name = "vhost-user-fs", .unmigratable = 1, @@ -313,6 +319,7 @@ static void vuf_class_init(ObjectClass *klass, void *data) vdc->set_status = vuf_set_status; vdc->guest_notifier_mask = vuf_guest_notifier_mask; vdc->guest_notifier_pending = vuf_guest_notifier_pending; + vdc->get_vhost = vuf_get_vhost; } static const TypeInfo vuf_info = { diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index 08bccba9dc..3a7bf8e32d 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -247,6 +247,12 @@ static void vu_rng_device_unrealize(DeviceState *dev) vhost_user_cleanup(&rng->vhost_user); } +static struct vhost_dev *vu_rng_get_vhost(VirtIODevice *vdev) +{ + VHostUserRNG *rng = VHOST_USER_RNG(vdev); + return &rng->vhost_dev; +} + static const VMStateDescription vu_rng_vmstate = { .name = "vhost-user-rng", .unmigratable = 1, @@ -272,6 +278,7 @@ static void vu_rng_class_init(ObjectClass *klass, void *data) vdc->set_status = vu_rng_set_status; vdc->guest_notifier_mask = vu_rng_guest_notifier_mask; vdc->guest_notifier_pending = vu_rng_guest_notifier_pending; + vdc->get_vhost = vu_rng_get_vhost; } static const TypeInfo vu_rng_info = { diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index ad5c8ff5d5..7394818e00 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -258,6 +258,12 @@ void vhost_vsock_common_unrealize(VirtIODevice *vdev) virtio_cleanup(vdev); } +static struct vhost_dev *vhost_vsock_common_get_vhost(VirtIODevice *vdev) +{ + VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev); + return &vvc->vhost_dev; +} + static Property vhost_vsock_common_properties[] = { DEFINE_PROP_ON_OFF_AUTO("seqpacket", VHostVSockCommon, seqpacket, ON_OFF_AUTO_AUTO), @@ -273,6 +279,7 @@ static void vhost_vsock_common_class_init(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_MISC, dc->categories); vdc->guest_notifier_mask = vhost_vsock_common_guest_notifier_mask; vdc->guest_notifier_pending = vhost_vsock_common_guest_notifier_pending; + vdc->get_vhost = vhost_vsock_common_get_vhost; } static const TypeInfo vhost_vsock_common_info = { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b643f42ea4..a25ec5b032 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1739,6 +1739,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) /* should only be called after backend is connected */ assert(hdev->vhost_ops); + vdev->vhost_started = true; hdev->started = true; hdev->vdev = vdev; @@ -1811,7 +1812,7 @@ fail_vq: fail_mem: fail_features: - + vdev->vhost_started = false; hdev->started = false; return r; } @@ -1842,6 +1843,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) } vhost_log_put(hdev, true); hdev->started = false; + vdev->vhost_started = false; hdev->vdev = NULL; } diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 0a1f3dfdbe..947a11c3af 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -961,6 +961,15 @@ static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int idx) return cryptodev_vhost_virtqueue_pending(vdev, queue, idx); } +static struct vhost_dev *virtio_crypto_get_vhost(VirtIODevice *vdev) +{ + VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); + CryptoDevBackend *b = vcrypto->cryptodev; + CryptoDevBackendClient *cc = b->conf.peers.ccs[0]; + CryptoDevBackendVhost *vhost_crypto = cryptodev_get_vhost(cc, b, 0); + return &vhost_crypto->dev; +} + static void virtio_crypto_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -977,6 +986,7 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data) vdc->set_status = virtio_crypto_set_status; vdc->guest_notifier_mask = virtio_crypto_guest_notifier_mask; vdc->guest_notifier_pending = virtio_crypto_guest_notifier_pending; + vdc->get_vhost = virtio_crypto_get_vhost; } static void virtio_crypto_instance_init(Object *obj) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index cbb4920f49..80c7708c7e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3271,6 +3271,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size) vdev->start_on_kick = false; vdev->started = false; + vdev->vhost_started = false; vdev->device_id = device_id; vdev->status = 0; qatomic_set(&vdev->isr, 0); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 5d774684b1..8e12aeebc1 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -22,6 +22,7 @@ #include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" #include "qom/object.h" +#include "hw/virtio/vhost.h" /* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30 @@ -102,6 +103,7 @@ struct VirtIODevice bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */ bool disable_legacy_check; + bool vhost_started; VMChangeStateEntry *vmstate; char *bus_name; uint8_t device_endian; @@ -160,6 +162,7 @@ struct VirtioDeviceClass { int (*post_load)(VirtIODevice *vdev); const VMStateDescription *vmsd; bool (*primary_unplug_pending)(void *opaque); + struct vhost_dev *(*get_vhost)(VirtIODevice *vdev); }; void virtio_instance_init_common(Object *proxy_obj, void *data, From patchwork Fri Apr 1 13:23:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612221 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=uAhY0fPg; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=FqQj6Frb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLrb65gFz9sXM for ; Sat, 2 Apr 2022 00:39:58 +1100 (AEDT) Received: from localhost ([::1]:55358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHVL-0007uF-5Z for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:39:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGi-0002Ug-Ta; Fri, 01 Apr 2022 09:24:54 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:38700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGf-0007DL-St; Fri, 01 Apr 2022 09:24:47 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231Ctq1Z014677; Fri, 1 Apr 2022 13:24:23 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 : mime-version; s=corp-2021-07-09; bh=Ck99w8TyvDsvwLRXavpw0IIimQh2tYn8bmnm3w5tQfI=; b=uAhY0fPgnAuso82+hZ7kHoUeKHNp0Vn3Mg4ZWGyvz/kqIbXSHclXTc5Q5YeJyO5Jdvcj hViyi+7FL+1leOyUDWwU3mXdbPIWJGLlAI6sFkvif2bnK697iFpbd9fQhSX8WyMzxjZt AKqKvZl1mV5fE2Wga7xNqd5bmM3eixTLni11aYZN1nDLzbv3xCVtV78+YZiNrmX/bpAY erd7XUeeRyYJizHVabIgsDO1U0Y6DKKNWiu0LYISxAaoSoUNOAa4VON4jTlqvcwwRZK0 Aat8YWzOPmsBhIeLpJ7DABKUNC7GToerLyetkXRsCnf62QsCbqlKHS4PI89iXRPO75lE ZA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1s8cxne4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:23 +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 231DHNLP008157; Fri, 1 Apr 2022 13:24:22 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f1s96146s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CfJPL1Ra6swHm/QFGW240LSmOhVey50PTsURYQ7dLkcJ84QUH0SdvH21/qxiPuvea31c2RLl4hLj2sz1xlB1gAgxcbIWzpsA/0rSVMhQfv7KMZn4J6VEpI9Eco9tQxFeM/Mm0Hy+4AjXbq1/ApJK5eEKCwT58dn88U1F2hUdQI7F31pl+D0aKZco4z4uuAOg2Ojy8akCwlehRDmiNjkydKO8v1Ah9d07Zdx2fHAjW5W4d05HLlN0V8jO68nmzOvQNHWOorkFYbqdxH+aPVeWxVO+ZpI9qfsnHJhfdfWjG927Q1OvOcwDHAUcR1SxmxFP7pzFcuBbRq9Dgz84/9OF/w== 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=Ck99w8TyvDsvwLRXavpw0IIimQh2tYn8bmnm3w5tQfI=; b=QM6+RhAQ1CTYtNl+DhyUadwY75P2RHcitXyGkjKn1onKguc5JoY/X/KgBU0vH3an+yCb6cf4cMwiQroYY7Pz4GjC/ABjEXRaATasVk6uwtUWZwaakF1kxeqIbNYJ7SYlHzZ24Zri2R+xqEU5FNNKq+DFbGgQ3fdfgPwyiQTnXz9TgYJ2eN7WXqqZxpL5Kfrf+om97TMj5Ur8xXWo1rly627A3kASepBjlhKQAhOn7nYSGmvkq4DFoAws0JzdymU8zd29JSsHkBsfsHxmMfoandbmrQIrFvN7FOLvirFhpOmKeM/bx8GBrdwAvhdMBHdZqLQec76Cta/5j71/lZ+Crw== 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=Ck99w8TyvDsvwLRXavpw0IIimQh2tYn8bmnm3w5tQfI=; b=FqQj6Frb+Y4O5Bq7bbXc2Vg6kokx3VPHInwEed/+B8FubnnroTd52x9BbWXUapSyYiBaawnS39c2vruuGbeJA25kd/CbBc4H20NxCV8AdDEo+91wOWHuMLBPzLdbEMvuAdZ2z9IOGOQlomgv/mqo4EpupIuRUtxbGUj+JjyZRK8= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by MN2PR10MB4302.namprd10.prod.outlook.com (2603:10b6:208:199::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.28; Fri, 1 Apr 2022 13:24:19 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:19 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 3/8] qmp: add QMP command x-query-virtio Date: Fri, 1 Apr 2022 09:23:20 -0400 Message-Id: <1648819405-25696-4-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c1af1de-edfe-422a-6be1-08da13e2ed80 X-MS-TrafficTypeDiagnostic: MN2PR10MB4302: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: 7doysyVLrddqkk2WZKQ6s8FABSBoLUIqwhN+5L78YQ3ba8CwLR8D3nj4rOJwC6CTYxw2NfIVuz2VKdQ/nnTA0TsaOXzRqHrYe2xIkXchPLLnWoVxsJwkV3JO6I8l+AIWe0oY3+hXBqOCxNkdOWRoslx2OCG9SqFh8HB1D/c29Zd2KJzVvzF/HU3Q+z5kb1l1zmXU9QdwWd39i0SfexxHK6muoxFJAzp0XKrdVlqd6dhAy3bdBVxVZHPtBaZYjiO/mcfFPVi5g+xbbXdtANypke1q/GWMOa8EzC+eZxTSoy+V+TCGaxm/oS8Ehp+QovgTkCIK2fACW1bqz55md2FZhv8vF86Ud8j75U+n5eZSeHSEW/7TJPVBc/om6E8ZLjSGZ5mx+Su/B1E5+aJVM18dYlgd6ixv6/1v2yrIxr6Zs855zcEO/d+UB157rHVsnBnAAfQRdZulpArBpX3E+i6jtqJo2dTBvLxM40nuUF7G3Hgkf/q8HqyrtRXgt22MZmFXSyre3++PbJgaqTUIKWzs+a2SjfaeqI6DedCXA/nNI9jWoSKmtLLRf5A36d5fpTnR229txYAKYXMktPTHFSYvrW8qIQxw0e/RKXvbaq8cU0Rd7GrOrhlgpqGjUf3ZtJQUkKMVnvR8HBBbgb0mtkjNJcwrabxVIM6YL/7qc4xjfAp2vUlIJk3GNN0jIhSPQFPv+0bss060qokM9kPfy1vcTw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(316002)(4326008)(508600001)(66556008)(66476007)(2906002)(8676002)(6916009)(86362001)(36756003)(66946007)(38350700002)(38100700002)(6486002)(5660300002)(7416002)(6506007)(52116002)(8936002)(44832011)(6512007)(6666004)(26005)(186003)(83380400001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JBHR6MKNWo8KfAbp0AbXmtXhl5yTdA10Omn5QInCLGdQ8HDVWxDJlIqCyYeephpPuCgTm9ndoLOCSIgx2r/sncAoLCY9qYTLUHhOWFduADU/hdi11VTvkYA+gOvBx73o/CLuL2YYc6iqI63NIRUDUqKyp8/FDkA+ptaqV5asd5zqNt07HN0bnUrWnK5O/MnL/S7KT8LJiP8QrktmsEdC1Vm9ooy1iQn/2QftTMiZmWP7CHtA3CcCWNnJp0Al5UVzy7/OmxUnx80XZESzLhsmkgQjjPn3LufxGcY4N2Zt2LXjg6eeZ4OqBFrKejclR1paHrWX13w2uow3k71y6NSsSK4K2sSCcvV3ioDoZdUJT/1+rJnBE//DgXJte6lSjj+1oJrixIDRowsan2wx0oXMQqiB79fo6fGNUkn0oqZ7uhyhHjQx+c0yB+U+GeHqqr1o7D7W3k0iKFbAYHIvyd6KUwcFhvpl8dfiIa2pf93yJ4suBj0xYT0jnmcDsv8lp3rQdZ/ouJTbXlDI2bkLLCGs2l1jrgy4Hz5jegByPa+pYqJ/z3SYJpNd2vaCHfcN5n9Gpk0dKdE615QJ0UdsJw1wsn5fKE2hc8ybFnhym000WsMjvH17J2rRaop3YzyRbeMJQ7bDaCC74CHppHTh6EM6UqKJv9lMRcM8a+88P9Ar5J0blZF7Dxi1Iq4wNguxK0bcGQz2a3MuZLs02ZyQZpGpRiviRkZieDIZGocjScgDNGfW1JiUSuPTMgUcZg4WlHWCtBqnvSQLxIzkzQMwDsAQkGFcVhIH3HsdA7B/cjjNga5uzj3t63hWpjbyBcOclDsAQJFoLJ8HiXyWzSztXdwK52ti0koVTuEt221bk1t8l/UkFbs5M4Y60J4iHGRjPoNOeraU+iedhs6s1mFyDejgaj1dIBuAWK06/aYYjF3qHAbvIKMQxK0BID3XdgPqOjPNKExLuYtOUvUs2EVvFuiUh2QIQ4S70SuWZt/FfzaxigvMVkUqRi4ApOcoI7k9IZ4djW8GO0G8y9XvhZYeTUzy8HJytye1QAa1btiQKw4kQNB4I3TrMnZqeyPqcD/p2UnZEtVbVMi2sIchYFe7xE8976hsy8ivCV4o0/ALfHMtsm9uF/dtfniz/Kvclzjr6Gzl/XyLDJhx3klTKAJI8pktsPtYFXbTm2ypYY5TqL+Y2EeYgVH28fk4ZK1oko42/h+1O46gKSDh/AeNsBriVWEd4GtFvhegQ1JK0qOiIB1SRV3cJJBJHrwEk4WrXzk0Ti1g/FK43hFwpjfX/zsldYqtuYiXLz/+W7uDWrZE7Pjuq1d6pk7we2GIch/lJwlcuYKeaz+7NiybWmq3vtEvfSKsbcWwKY9kE+DTcl0bODj6wHfw+kxvm9hj+ow5C1sdmOgCT1GYjccx8I+/bE0ZCwycmyGloS0oRT9oaDDJcFA8CJ4DkRrYv4RJCdXQETCbrAB8ZQIHPOMcifvpMvrWmDk5qabkUeYoCYwxPkTWuqin2j3HLyS1yuNOYqLS2sPLWcq6wR5Ur/mj2vhkQ2xfdxLfetMNEHsH+QfBKCOhKofozfRhUT2Kd8qjGB9f9YxNLMJxyha7djDVtY8wVkNnog9O0bEVg13KAzF8DR3XRhZPOiDNOVl8a4cIV10Wwa5VuOJgnrcSAutr+V1PKKi8yoBBPSTir+SfsDlzKYKmWHc/HPxcmajmuFij63lUBC0FG8NRTfQ5IeUYkww7qSyjDrEEX9Pg1uGTQ/pK/C6E9HY/m8g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c1af1de-edfe-422a-6be1-08da13e2ed80 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:19.5749 (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: 1JUYnc3CDivY5meAV/1gPbL7uidmA8aBYryhcW7WfJ6bcQ3zAUt3Uo2aYVzON5ji64qO6M78cTToIkck0QJ63w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4302 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-GUID: xUorggwgpAilxvBbyK6Yp_McHnld_vZV X-Proofpoint-ORIG-GUID: xUorggwgpAilxvBbyK6Yp_McHnld_vZV Received-SPF: pass client-ip=205.220.177.32; envelope-from=jonah.palmer@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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier This new command lists all the instances of VirtIODevices with their canonical QOM path and name. [Jonah: @virtio_list duplicates information that already exists in the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted. Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree). Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.] Signed-off-by: Jonah Palmer --- hw/virtio/meson.build | 2 ++ hw/virtio/virtio-stub.c | 14 ++++++++ hw/virtio/virtio.c | 44 ++++++++++++++++++++++++ include/hw/virtio/virtio.h | 1 + qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/virtio.json | 68 ++++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c | 1 + 8 files changed, 132 insertions(+) create mode 100644 hw/virtio/virtio-stub.c create mode 100644 qapi/virtio.json diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 67dc77e00f..6fdc152780 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -6,8 +6,10 @@ softmmu_virtio_ss.add(when: 'CONFIG_VHOST', if_false: files('vhost-stub.c')) softmmu_ss.add_all(when: 'CONFIG_VIRTIO', if_true: softmmu_virtio_ss) softmmu_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c')) +softmmu_ss.add(when: 'CONFIG_VIRTIO', if_false: files('virtio-stub.c')) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) +softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('virtio-stub.c')) virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c new file mode 100644 index 0000000000..05a81edc92 --- /dev/null +++ b/hw/virtio/virtio-stub.c @@ -0,0 +1,14 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-virtio.h" + +static void *qmp_virtio_unsupported(Error **errp) +{ + error_setg(errp, "Virtio is disabled"); + return NULL; +} + +VirtioInfoList *qmp_x_query_virtio(Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 80c7708c7e..28f25ff83a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -13,12 +13,18 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qapi-commands-virtio.h" +#include "qapi/qapi-commands-qom.h" +#include "qapi/qapi-visit-virtio.h" +#include "qapi/qmp/qjson.h" #include "cpu.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/module.h" +#include "qom/object_interfaces.h" #include "hw/virtio/virtio.h" #include "migration/qemu-file-types.h" #include "qemu/atomic.h" @@ -29,6 +35,9 @@ #include "sysemu/runstate.h" #include "standard-headers/linux/virtio_ids.h" +/* QAPI list of realized VirtIODevices */ +static QTAILQ_HEAD(, VirtIODevice) virtio_list; + /* * The alignment to use between consumer and producer parts of vring. * x86 pagesize again. This is the default, used by transports like PCI @@ -3685,6 +3694,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp) vdev->listener.commit = virtio_memory_listener_commit; vdev->listener.name = "virtio"; memory_listener_register(&vdev->listener, vdev->dma_as); + QTAILQ_INSERT_TAIL(&virtio_list, vdev, next); } static void virtio_device_unrealize(DeviceState *dev) @@ -3699,6 +3709,7 @@ static void virtio_device_unrealize(DeviceState *dev) vdc->unrealize(dev); } + QTAILQ_REMOVE(&virtio_list, vdev, next); g_free(vdev->bus_name); vdev->bus_name = NULL; } @@ -3872,6 +3883,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data) vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl; vdc->legacy_features |= VIRTIO_LEGACY_FEATURES; + + QTAILQ_INIT(&virtio_list); } bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) @@ -3882,6 +3895,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) return virtio_bus_ioeventfd_enabled(vbus); } +VirtioInfoList *qmp_x_query_virtio(Error **errp) +{ + VirtioInfoList *list = NULL; + VirtioInfoList *node; + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev = DEVICE(vdev); + Error *err = NULL; + QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err); + + if (err == NULL) { + GString *is_realized = qobject_to_json_pretty(obj, true); + /* virtio device is NOT realized, remove it from list */ + if (!strncmp(is_realized->str, "false", 4)) { + QTAILQ_REMOVE(&virtio_list, vdev, next); + } else { + node = g_new0(VirtioInfoList, 1); + node->value = g_new(VirtioInfo, 1); + node->value->path = g_strdup(dev->canonical_path); + node->value->name = g_strdup(vdev->name); + QAPI_LIST_PREPEND(list, node->value); + } + g_string_free(is_realized, true); + } + qobject_unref(obj); + } + + return list; +} + static const TypeInfo virtio_device_info = { .name = TYPE_VIRTIO_DEVICE, .parent = TYPE_DEVICE, diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8e12aeebc1..ef99a626a8 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -110,6 +110,7 @@ struct VirtIODevice bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; + QTAILQ_ENTRY(VirtIODevice) next; }; struct VirtioDeviceClass { diff --git a/qapi/meson.build b/qapi/meson.build index 656ef0e039..10c54d68e5 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -48,6 +48,7 @@ qapi_all_modules = [ 'sockets', 'trace', 'transaction', + 'virtio', 'yank', ] if have_system diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 4912b9744e..1512adaf92 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -93,3 +93,4 @@ { 'include': 'audio.json' } { 'include': 'acpi.json' } { 'include': 'pci.json' } +{ 'include': 'virtio.json' } diff --git a/qapi/virtio.json b/qapi/virtio.json new file mode 100644 index 0000000000..aee0e40daa --- /dev/null +++ b/qapi/virtio.json @@ -0,0 +1,68 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# + +## +# = Virtio devices +## + +## +# @VirtioInfo: +# +# Basic information about a given VirtIODevice +# +# @path: The VirtIODevice's canonical QOM path +# +# @name: Name of the VirtIODevice +# +# Since: 7.0 +# +## +{ 'struct': 'VirtioInfo', + 'data': { 'path': 'str', + 'name': 'str' } } + +## +# @x-query-virtio: +# +# Returns a list of all realized VirtIODevices +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: List of gathered VirtIODevices +# +# Since: 7.0 +# +# Example: +# +# -> { "execute": "x-query-virtio" } +# <- { "return": [ +# { +# "path": "/machine/peripheral-anon/device[4]/virtio-backend", +# "name": "virtio-input" +# }, +# { +# "path": "/machine/peripheral/crypto0/virtio-backend", +# "name": "virtio-crypto" +# }, +# { +# "path": "/machine/peripheral-anon/device[2]/virtio-backend", +# "name": "virtio-scsi" +# }, +# { +# "path": "/machine/peripheral-anon/device[1]/virtio-backend", +# "name": "virtio-net" +# }, +# { +# "path": "/machine/peripheral-anon/device[0]/virtio-backend", +# "name": "virtio-serial" +# } +# ] +# } +# +## + +{ 'command': 'x-query-virtio', + 'returns': [ 'VirtioInfo' ], + 'features': [ 'unstable' ] } diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index 7f103ea3fd..fd00ee2777 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -103,6 +103,7 @@ static bool query_is_ignored(const char *cmd) "query-gic-capabilities", /* arm */ /* Success depends on target-specific build configuration: */ "query-pci", /* CONFIG_PCI */ + "x-query-virtio", /* CONFIG_VIRTIO */ /* Success depends on launching SEV guest */ "query-sev-launch-measure", /* Success depends on Host or Hypervisor SEV support */ From patchwork Fri Apr 1 13:23:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=CQj8i4Zt; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=qcHbgGqF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLjh1Z7sz9sXM for ; Sat, 2 Apr 2022 00:33:59 +1100 (AEDT) Received: from localhost ([::1]:42796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHPZ-00072l-5o for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:33:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGf-0002QZ-GS; Fri, 01 Apr 2022 09:24:45 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:25542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGb-0007A3-00; Fri, 01 Apr 2022 09:24:45 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CpucT031565; Fri, 1 Apr 2022 13:24:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=+00VnBTJiBI+vfpchJnR0dW6JRbYuLt/8V6Ik5JW1TA=; b=CQj8i4ZtFxMs5uqednJtN2mZQivjBn7FJ3btUZ79GoagYpL8XyZx5Ig9oCZKnN1awxts uBJkXfqcrkM/mAWC9VwYWZcwRYT/6Qi/rGfmzZzUZOzFTjcNRmmnZbBynEy20/+QXMzG Uh6p7XL9hLHp2TCXyGXOOPXeKkTDQ5EzwUVmvZY7uDpkHKlodx9JDgSOoDpE+DmkSgcz S8OeS11Yze3A7jhPrrVTFCvPHG+T9lHdMwEvT25nLcMlXR6gcxHj9kOWyp8UrN1gHynV /Q891j6R9vgag+djlqgsPuiXKH72wuxZofs2VOuBa7MI2Lcg+J68ayjDPFVoVFa/WShG AQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1tes6ygy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:25 +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 231DGSNR011711; Fri, 1 Apr 2022 13:24:25 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s992mdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jMrP8BihyK6moM44pvhUKdXdOaC2Mw3GjUwq1GgNxjHusIZqGhXd0biRHmAyvKzNQchL51CAKXwSJ8g59vGr1KA2V2fyvKajUIGkxYlXvR5UZuUtRUaQRmTrnofKGsXJJN5Wb/zHw15lPhPLcjNucK2vQzjtrbF9TNRpoEo7qf05+S2lz0tKAGsplzmOZSj64V3As0ZwZt1x+pQ4NSaHCyXM+i8s9yD9ey7XGNGGlNMJRRJmCybg1YLmXsDLWJsoyEWCrYXY7fsHYW0KJSWmaU3yE3vw7qiF/Yab5Yo2w6JA7bUsJfcAT9UsoU+jcIQSxof3PSaHhJIK9IVQv7mx0w== 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=+00VnBTJiBI+vfpchJnR0dW6JRbYuLt/8V6Ik5JW1TA=; b=a6FFXKclAh/crTo+PgJwqinr+L5B67xUse13NB3VmbwJJpUjkKd0+37XZsKooIXAZOxEnRAp77fIn1Zb636GCcwX+WTfWAVGsl4RwTnlB/2anZ7eOwTqDlUnY6Av2SuObk/1xLmFgvNKoqY61ZN2ZmyR6rAUsjonc++aHkdhFD5aKheiqW578l7aEGY3LR/mXwSCIhUMLMSBbEWhkiM4fjuux7CazsBQKOVgjiWcpvEHPyoSHoYbCCJ7v2DySHHaKcP2/rLGlMZYrgFt0892PCPF4Z8xV5Xj1mPg7KvSXyyCc6s941GxZ6u2cpNe85xa4+i6TsWV1ShYGG6DCptDWQ== 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=+00VnBTJiBI+vfpchJnR0dW6JRbYuLt/8V6Ik5JW1TA=; b=qcHbgGqFpKr5+SrHo/DBFSMrDt7aq4qbWozde3TI8CqqRPtQtKlxZQCiqQwTIkVKHVY65LHYpHB9ySiW90oIxmpMpbw1+GYSIBf5J2dmaTuuAdLWptkNqpjPtQVb686ixDWRnyjI27/7H2BEwFZwa5tm7RU5jfpftS+iiRoDWUQ= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by MN2PR10MB4302.namprd10.prod.outlook.com (2603:10b6:208:199::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.28; Fri, 1 Apr 2022 13:24:23 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:23 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 4/8] qmp: add QMP command x-query-virtio-status Date: Fri, 1 Apr 2022 09:23:21 -0400 Message-Id: <1648819405-25696-5-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: beeafc37-2d1c-43df-b8ef-08da13e2ef81 X-MS-TrafficTypeDiagnostic: MN2PR10MB4302: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: or23BpfPQBgLrd7LEL8Oj7zfu51pzK09CU7tmAwisWnRVuv3GnDcVuuzhxCvasER0iv1XhhcwRuhm1+BTXI4ONw+vx6XqyTuSOZKaF6fMbL0MO/cE1+pvnccTN1qrbgvkHtkV01EOD33s47/t7q4ze1d0n7BX8qGQX9YZ75sZ9LnNTxOcSoWnryMP0fSjHKHWIQg5dXzI/oLOR2k/VIrqg4ycDHtgeNYhSkJW0zfDGC9VuJhADe1s3oNaz0weKfiF2CSlOepDJdxvPsRKjIJ0oSGvvG7vPpeEIPURkJ46sKcfvNtKzlEriPWT/CffqGBp+67UejcEJrWSdqKJCkO0gDWoAVYIuahHCih0lFoBLu0qw3CxiXR9SFsHlFrcxKWUAemA1mhD9LaTCb2uajBeecRIu/f2P1lDHj93BOe8e8Kpt7wIncVR8fCZjKIeYmN4zLWRPL8jFojxHLHCp1CvsyzNZw+g8XAIPVKVfNFH85ikh0ld8rL868sbCmdxH9C8FCbMT9PxmxDyEehWennQ9AnyiStkWtDH9l2vVe9xn8/f36WQZDeOD7JjXfTm+ZWmRZGyFrIGm46VbgzNf9uREjYoKgsqHF+Z4nsa7ORJ24MCWe+WzXcqcmOc1eG+Nw0JtaQY3GjpIwhmYCNL8rUQFcld8b/t23z9LOfm+78T+IrGxJmFi/s6AfPpve/QeX5U27ZN1ys3KHdOY5veDxchA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(316002)(4326008)(508600001)(66556008)(66476007)(2906002)(8676002)(6916009)(86362001)(36756003)(66946007)(38350700002)(38100700002)(6486002)(5660300002)(7416002)(30864003)(6506007)(52116002)(8936002)(44832011)(6512007)(26005)(186003)(83380400001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jEYQfmD+9ZMSNN+GQ74kbpg+LVC6/kUkuYdyTMwdp1vudmESohLE3JHSM8egmLQUT+DrBK/HNfUG7Dn3lKKg1bJfDuNOgdS0IaWVL4+ZefaP9xEJE3uEpmfJOFRL3OnPcTYrIVa65vKPgx8tH4Guc08JcHyiNQTmTrDJiG49/Bup6Pcrb3jChp/0p7zS8JlHAmEwR6E/jFNRbUED0/UBRJHo5MUacVyLvufYeweEkqpG+wzkFRdj5JxsLWUqj0Rg+M+S/RiW9AcknwzK1e1OMv+3jDxujjEnjPX5mSXd9xEjyk+fARnUGT6pHXBuDYkntZGf73b7/JWP13BP7JpPE6VgZGIkggd+BoxislUW2ezJdi24/Ov5FxWWf+lQPGjxSQjM2hqXFcI7gX88WxHFBH4kVk0/cCTNOeYW2nqjMdYVgOgN7/n1hCUpWVbiDbeBFSXyXqDOG183rJhnw6QyqCVoCPp5QG+CA6JL/NHg4YSIgT77tYVgArhiIfjl/Fu2j+jdLt08YuRcJDr6YFg9bG34bR2uG/3d6zAlUpYhb/e6ppEaLawGbxocC2M+Vibac8Nkxn6a9O1dCrTS+uxWQ0lo3SByIkyvYjsuIrHoeD5CqqvlkdHxl0kYWvteWegIdt8LFy6Up0Oano6mlvbxQ2m38r42xsNVjsOhql2jBAoJqZGZKfDY42r2jeFmm8rv1c0DGx4hUaZ3DBFi0vb6MQvZbcc3Bh7RuWyxcxopXt+T5kHdb165LjSq07ofBzQtN2p31q9C/Xk9XZgm3ptXlPo/e9Ph8wo6lSjBYQ7MORoUzn430lcqNue4b75BWo38iOt2awCn77Or7Jpyc/D6kCeZLYEOM/WvG9MVaSE2ZS43lQIRmYe3/mSTVzovkV5/tU8Njv5wetCKCZmgVLfb628XfRqIWqYp39pN1wTZf9XM6ojQcb1h/YQpbaXVPuwbhZaHcun1XyxvAeqy4GkmeVjffSglJ5TNf3/zi0UOJk3VT4g4vCDebUE+NsuV5qOM6GkS/iInCCVUXE5coDfrGEFPvYwjsKl8VJkWFIjrnEqCz7A+Og7F4dmrx/Mn/1dvaEzQFDw9Bq127DGoWtyDkPeqVkuA+52bk0cQOszNWrw8VljwEhYqz9j+4VCIOB8ZTEIH2hqs9xcBj4AOG/nSXBndN0jvCfknaOByK5buagqbgmngvGTNCGLjucT5l3w1kKC2zxTmIVjO4SbdFiIZUDCe+Rg4b/6sshbHiaCbcJpOTNzeiDTV10S/7Pu4uNt+uo28CmBYuL8yDa5xz9hY7z2S+lBlZSdjG+mBzva5w9W9UFmz50bco8EIkhjsqwKap0Bh3Ws67S39xaL04qxBpH4whrISrw2oaGp2KctSZr23Smc7ZsVz57syIjdslF2anD1foaGX6iYDyZDEPpSGYZ/HhFPaeQCpKVsGSLhcWhlCZHX4ddkxUZR0LDA72fwyKSWG+9B2zX+6gkXa5jRrJaXIOLz8WYax6c9bNRTDrJ2otyN7WeUbVI9ovXa1mlp2i/S+ORTre9ur168Qx/yAona5tQlpuUMjeSpRt0cihWzKHGDq+0nzJ8SzCy0uJUj2glQ7L4O7s5xsMNJukgFF9vysdyMUle7F8uU6qtXYkBPfSjj58gwSUNTYLNen+IWhv7L/oniFPIBOd32U4nq8PLJQ1CoKucmcwt2Ek6RBJKwTzXrhRORGE9zigTVxLZ4G7wY9uEEmTqX6ZiuYjB0/zYmQ8GEOOKdejD1kTecWrwY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: beeafc37-2d1c-43df-b8ef-08da13e2ef81 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:22.9858 (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: M7VQPi5WmewO+3DmnlsqgXwekyZPWja/DEWmFTvQKOzgXtd9hEOHHfGwURGmUjmtJiPPAggu39s2zfOoUErVZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4302 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-GUID: f8DQIQGkHejyNedjZ4hGdWVm7y4oBMp5 X-Proofpoint-ORIG-GUID: f8DQIQGkHejyNedjZ4hGdWVm7y4oBMp5 Received-SPF: pass client-ip=205.220.177.32; envelope-from=jonah.palmer@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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier This new command shows the status of a VirtIODevice, including its corresponding vhost device's status (if active). Next patch will improve output by decoding feature bits, including vhost device's feature bits (backend, protocol, acked, and features). Also will decode status bits of a VirtIODevice. [Jonah: From patch v12; added a check to @virtio_device_find to ensure synchronicity between @virtio_list and the devices in the QOM composition tree.] Signed-off-by: Jonah Palmer --- hw/virtio/virtio-stub.c | 5 + hw/virtio/virtio.c | 104 +++++++++++++++++++ qapi/virtio.json | 222 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 331 insertions(+) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 05a81edc92..0b432e8de7 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp) { return qmp_virtio_unsupported(errp); } + +VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 28f25ff83a..7f8eb29ced 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3926,6 +3926,110 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp) return list; } +static VirtIODevice *virtio_device_find(const char *path) +{ + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev = DEVICE(vdev); + + if (strcmp(dev->canonical_path, path) != 0) { + continue; + } + + Error *err = NULL; + QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err); + if (err == NULL) { + GString *is_realized = qobject_to_json_pretty(obj, true); + /* virtio device is NOT realized, remove it from list */ + if (!strncmp(is_realized->str, "false", 4)) { + g_string_free(is_realized, true); + qobject_unref(obj); + QTAILQ_REMOVE(&virtio_list, vdev, next); + return NULL; + } + g_string_free(is_realized, true); + } else { + /* virtio device doesn't exist in QOM tree */ + QTAILQ_REMOVE(&virtio_list, vdev, next); + qobject_unref(obj); + return NULL; + } + /* device exists in QOM tree & is realized */ + qobject_unref(obj); + return vdev; + } + return NULL; +} + +VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) +{ + VirtIODevice *vdev; + VirtioStatus *status; + + vdev = virtio_device_find(path); + if (vdev == NULL) { + error_setg(errp, "Path %s is not a VirtIODevice", path); + return NULL; + } + + status = g_new0(VirtioStatus, 1); + status->name = g_strdup(vdev->name); + status->device_id = vdev->device_id; + status->vhost_started = vdev->vhost_started; + status->guest_features = vdev->guest_features; + status->host_features = vdev->host_features; + status->backend_features = vdev->backend_features; + + switch (vdev->device_endian) { + case VIRTIO_DEVICE_ENDIAN_LITTLE: + status->device_endian = g_strdup("little"); + break; + case VIRTIO_DEVICE_ENDIAN_BIG: + status->device_endian = g_strdup("big"); + break; + default: + status->device_endian = g_strdup("unknown"); + break; + } + + status->num_vqs = virtio_get_num_queues(vdev); + status->status = vdev->status; + status->isr = vdev->isr; + status->queue_sel = vdev->queue_sel; + status->vm_running = vdev->vm_running; + status->broken = vdev->broken; + status->disabled = vdev->disabled; + status->use_started = vdev->use_started; + status->started = vdev->started; + status->start_on_kick = vdev->start_on_kick; + status->disable_legacy_check = vdev->disable_legacy_check; + status->bus_name = g_strdup(vdev->bus_name); + status->use_guest_notifier_mask = vdev->use_guest_notifier_mask; + status->has_vhost_dev = vdev->vhost_started; + + if (vdev->vhost_started) { + VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev = vdc->get_vhost(vdev); + + status->vhost_dev = g_new0(VhostStatus, 1); + status->vhost_dev->n_mem_sections = hdev->n_mem_sections; + status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections; + status->vhost_dev->nvqs = hdev->nvqs; + status->vhost_dev->vq_index = hdev->vq_index; + status->vhost_dev->features = hdev->features; + status->vhost_dev->acked_features = hdev->acked_features; + status->vhost_dev->backend_features = hdev->backend_features; + status->vhost_dev->protocol_features = hdev->protocol_features; + status->vhost_dev->max_queues = hdev->max_queues; + status->vhost_dev->backend_cap = hdev->backend_cap; + status->vhost_dev->log_enabled = hdev->log_enabled; + status->vhost_dev->log_size = hdev->log_size; + } + + return status; +} + static const TypeInfo virtio_device_info = { .name = TYPE_VIRTIO_DEVICE, .parent = TYPE_DEVICE, diff --git a/qapi/virtio.json b/qapi/virtio.json index aee0e40daa..ba61d83df7 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -66,3 +66,225 @@ { 'command': 'x-query-virtio', 'returns': [ 'VirtioInfo' ], 'features': [ 'unstable' ] } + +## +# @VhostStatus: +# +# Information about a vhost device. This information will only be +# displayed if the vhost device is active. +# +# @n-mem-sections: vhost_dev n_mem_sections +# +# @n-tmp-sections: vhost_dev n_tmp_sections +# +# @nvqs: vhost_dev nvqs (number of virtqueues being used) +# +# @vq-index: vhost_dev vq_index +# +# @features: vhost_dev features +# +# @acked-features: vhost_dev acked_features +# +# @backend-features: vhost_dev backend_features +# +# @protocol-features: vhost_dev protocol_features +# +# @max-queues: vhost_dev max_queues +# +# @backend-cap: vhost_dev backend_cap +# +# @log-enabled: vhost_dev log_enabled flag +# +# @log-size: vhost_dev log_size +# +# Since: 7.0 +# +## + +{ 'struct': 'VhostStatus', + 'data': { 'n-mem-sections': 'int', + 'n-tmp-sections': 'int', + 'nvqs': 'uint32', + 'vq-index': 'int', + 'features': 'uint64', + 'acked-features': 'uint64', + 'backend-features': 'uint64', + 'protocol-features': 'uint64', + 'max-queues': 'uint64', + 'backend-cap': 'uint64', + 'log-enabled': 'bool', + 'log-size': 'uint64' } } + +## +# @VirtioStatus: +# +# Full status of the virtio device with most VirtIODevice members. +# Also includes the full status of the corresponding vhost device +# if the vhost device is active. +# +# @name: VirtIODevice name +# +# @device-id: VirtIODevice ID +# +# @vhost-started: VirtIODevice vhost_started flag +# +# @guest-features: VirtIODevice guest_features +# +# @host-features: VirtIODevice host_features +# +# @backend-features: VirtIODevice backend_features +# +# @device-endian: VirtIODevice device_endian +# +# @num-vqs: VirtIODevice virtqueue count. This is the number of active +# virtqueues being used by the VirtIODevice. +# +# @status: VirtIODevice configuration status (VirtioDeviceStatus) +# +# @isr: VirtIODevice ISR +# +# @queue-sel: VirtIODevice queue_sel +# +# @vm-running: VirtIODevice vm_running flag +# +# @broken: VirtIODevice broken flag +# +# @disabled: VirtIODevice disabled flag +# +# @use-started: VirtIODevice use_started flag +# +# @started: VirtIODevice started flag +# +# @start-on-kick: VirtIODevice start_on_kick flag +# +# @disable-legacy-check: VirtIODevice disabled_legacy_check flag +# +# @bus-name: VirtIODevice bus_name +# +# @use-guest-notifier-mask: VirtIODevice use_guest_notifier_mask flag +# +# @vhost-dev: Corresponding vhost device info for a given VirtIODevice. +# Present if the given VirtIODevice has an active vhost +# device. +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtioStatus', + 'data': { 'name': 'str', + 'device-id': 'uint16', + 'vhost-started': 'bool', + 'device-endian': 'str', + 'guest-features': 'uint64', + 'host-features': 'uint64', + 'backend-features': 'uint64', + 'num-vqs': 'int', + 'status': 'uint8', + 'isr': 'uint8', + 'queue-sel': 'uint16', + 'vm-running': 'bool', + 'broken': 'bool', + 'disabled': 'bool', + 'use-started': 'bool', + 'started': 'bool', + 'start-on-kick': 'bool', + 'disable-legacy-check': 'bool', + 'bus-name': 'str', + 'use-guest-notifier-mask': 'bool', + '*vhost-dev': 'VhostStatus' } } + +## +# @x-query-virtio-status: +# +# Poll for a comprehensive status of a given virtio device +# +# @path: Canonical QOM path of the VirtIODevice +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtioStatus of the virtio device +# +# Since: 7.0 +# +# Examples: +# +# 1. Poll for the status of virtio-crypto (no vhost-crypto active) +# +# -> { "execute": "x-query-virtio-status", +# "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend" } +# } +# <- { "return": { +# "device-endian": "little", +# "bus-name": "", +# "disable-legacy-check": false, +# "name": "virtio-crypto", +# "started": true, +# "device-id": 20, +# "backend-features": 0, +# "start-on-kick": false, +# "isr": 1, +# "broken": false, +# "status": 15, +# "num-vqs": 2, +# "guest-features": 5100273664, +# "host-features": 6325010432, +# "use-guest-notifier-mask": true, +# "vm-running": true, +# "queue-sel": 1, +# "disabled": false, +# "vhost-started": false, +# "use-started": true +# } +# } +# +# 2. Poll for the status of virtio-net (vhost-net is active) +# +# -> { "execute": "x-query-virtio-status", +# "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend" } +# } +# <- { "return": { +# "device-endian": "little", +# "bus-name": "", +# "disabled-legacy-check": false, +# "name": "virtio-net", +# "started": true, +# "device-id": 1, +# "vhost-dev": { +# "n-tmp-sections": 4, +# "n-mem-sections": 4, +# "max-queues": 1, +# "backend-cap": 2, +# "log-size": 0, +# "backend-features": 0, +# "nvqs": 2, +# "protocol-features": 0, +# "vq-index": 0, +# "log-enabled": false, +# "acked-features": 5100306432, +# "features": 13908344832 +# }, +# "backend-features": 6337593319, +# "start-on-kick": false, +# "isr": 1, +# "broken": false, +# "status": 15, +# "num-vqs": 3, +# "guest-features": 5111807911, +# "host-features": 6337593319, +# "use-guest-notifier-mask": true, +# "vm-running": true, +# "queue-sel": 2, +# "disabled": false, +# "vhost-started": true, +# "use-started": true +# } +# } +# +## + +{ 'command': 'x-query-virtio-status', + 'data': { 'path': 'str' }, + 'returns': 'VirtioStatus', + 'features': [ 'unstable' ] } From patchwork Fri Apr 1 13:23:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=iV95V1fo; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=P2o7sK1D; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLkk5czCz9srZ for ; Sat, 2 Apr 2022 00:34:53 +1100 (AEDT) Received: from localhost ([::1]:44104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHQQ-0007x8-5J for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:34:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGo-0002Va-Cp; Fri, 01 Apr 2022 09:24:54 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:17540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGh-0007Dj-92; Fri, 01 Apr 2022 09:24:51 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CsYQF018556; Fri, 1 Apr 2022 13:24:32 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 : mime-version; s=corp-2021-07-09; bh=WIaM35ZkXHMAdJkxBzf3HgfEhMrSXDnLqxttniCugUE=; b=iV95V1fo84vLpgt0GErXUnzKjT2P6hJjD86IkKbXCukF133p8yk1PEzMU/Pmnb4SQeYW 29YvAnn9yUQNbdAtqz0iGrMOT4fvXpNEeYpVNFmM0eHCJ8BJ4i6K2LilIrEjE8xhPUdj c6gSqVRgk5EwD5Uj1CvMXix6E4bbVJWGg46RWqMi7Ln73w6Mv5dl9JCqiKDfPR9z/7oA 5/p48FjiUIMF/VW1o3jvBaSeRKbxHxpIaVOde5VSW1HhYccwpMdJhway+Amao//auRwD D0/zBQpAVKZx38XqrKg815TAgEZ3R6GAF0GJnnVn6R21nJn5xq6lLC3By5GDX+8gOoII Ug== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1se0q2ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:31 +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 231DHNAJ008107; Fri, 1 Apr 2022 13:24:31 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2105.outbound.protection.outlook.com [104.47.58.105]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f1s961498-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CqfbJydke7wXGYdSXqtdVQuDpRlMVTrxVoBL5RlUVDFB6s13J8QrQf+OZWj1C2iAuhdZxgZGyp/V92zWyihTedwEgVnHQzuAE2RlccK2hkjc9LwmLbAXbXX/WKXmVibohISFq8jT595PKeXayJqi7VhmlcfezliyPjXcoMLfR/2IUy8zuRMJj2ufjjKYod/lGI6bHxHiMa6JZx7uCXFb1jN7HNSK/0MiiXmDImwxNrdzgE88gFZ5cXevo94xfREKYP4QTpMenuXVf1DoijTd5oIpAUjVkhLWW2WMC78PQ0gkQGD2xqgpiZDrXOZekBRmVWELLKKHEVAQA3asKQbecg== 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=WIaM35ZkXHMAdJkxBzf3HgfEhMrSXDnLqxttniCugUE=; b=nZnvKgrFX/9dUuJYUvhhbITlhmFJZ3fVA+uEVdji08YLwKOt035Xm9Tcwla1u18j1ajWmrs9jK/jl9KsfNYiRN8Oom322djslCuIaply1m7rIyzIUTEzdmXviJRihf0A4Stnw7CJAi2qaPddd/QPlFXwo0Xi42nrfuBXOJyQqKglskqBDOCp61sEVd9A/1sw4s8wJA5yjXKLx5xGFgOvJLWllvvvM/x6Jx1xbAP6bNZxtIcrqG3ntHrOZ7y7A5chuyspZn2qQ8kDol3w/vt4ZjW/TBRfBV1tXeMy4+cFCcl5R/g229wU3sugpBfTlNutcbnfXd1hDF77S4ctx6W67A== 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=WIaM35ZkXHMAdJkxBzf3HgfEhMrSXDnLqxttniCugUE=; b=P2o7sK1DeU/y8qgzVPwKvtr0K8rTsQ/vCfIyx6Jj7EIq06nSliZARohvNqAzuAtNhiyHBI9BBD7ZVTtcQ0JHHqpghxTV5t9lRGf0yQDRjkX6Ok4dqztWQ3OyJWzBMLfcM0EVXzyO/gx/gxOeUJqUPKp/VhQ8yttNWEtK7Q+t/YI= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by BY5PR10MB4321.namprd10.prod.outlook.com (2603:10b6:a03:202::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.25; Fri, 1 Apr 2022 13:24:28 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:28 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 5/8] qmp: decode feature & status bits in virtio-status Date: Fri, 1 Apr 2022 09:23:22 -0400 Message-Id: <1648819405-25696-6-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f28e5039-74b9-4e40-237d-08da13e2f27d X-MS-TrafficTypeDiagnostic: BY5PR10MB4321: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: Iku8K7s96sFhQbeABgYKRZiKBRtuwWuYKOTjmiqP79sB4cGZNr6IUAOs0wdAQqO4rLDHI6MxvzMPGbeC5Dc39qvrJevg4xIPcTw6ANBnMsK1pSFRFiyA7MAvbvACBq68yoFHE5Dn8tMvQKqZE/bWMeFRDU6MEIjk/TaEzMB4Zk6JL4QoWdKETLSzK0ySouZbp6tH9Ek+tkLVkEGKCc+jW0HPIz6esezzl6WePTePkgknpTJd6NXWSTJN6GYqTEpM33TVKhOU4XRYFjYQDSXZIn1I8UCiDKmIBEX17X6bC8IfsgWrdAZFo0Ak/Hvt9qP6qVrxr84gtdEYTnyUnTHXlNEqf4W9AcaX+ZDp5VPyMZqE6uRgSH1BrqFLPDjSbw9rFU4WXLvrLBG6ZBnpr8HXai5us0f166fL1r/Wes1Wsf7gN4G7Udt3qQS9YtSzJh/OZMbLEiPzqEoyyAZ5NlM9DVsN60SfMVdy9eTrasSS7mtZcQB6mSRAzc+1mFVtOoUaDeDuZInO6TlbjihVLJrg2CtvVA2MLWP1T5nFf3a1wj457ofFG0+ZHID3N8irbPqLYzYnF2YQgjv3SOZEVJdx72+0dEm4Il/JO2HyZxu5cJ13APLTHv9A/NMQ1Cj4bBkbB29cODJMeqbRs6Eok4ujEdpBatCnTP/MqWnMSYSYpvik5ip52EXC71gqSLoMgbvs8EJ3EgrSaalvrfZbmlMBOw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6506007)(30864003)(44832011)(6666004)(5660300002)(6486002)(6512007)(8676002)(52116002)(86362001)(8936002)(508600001)(66946007)(4326008)(66476007)(66556008)(83380400001)(26005)(316002)(7416002)(186003)(6916009)(36756003)(2906002)(38100700002)(38350700002)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: os+o8RQ3cxxvchF0nNxzlJLyDpxaNxWsHb5mOpvovydxhWOddX4ephgf/ZsBwSnnuGupCjAcSpZjX1yN1NHkTQ0FXpQrPxETBqW7RAKefaqZNUxq55T+F+JD5TUVNNME5QAoFJlQYoiD7KAXex4JZwkiK72YVKwEdAgvgqwEfX6kD0ssxmVRAShWtSnswRsti9UKOMpJtGA3PvgBSUCbr1RDtvVhAFWRE7YxJAez84T7vwGe1KiPpUlhPO91oVizH6s2tvVGZ9zBsnMOLFVnb6DhgfoshdzfWZ35Vn0KrjGhE670p+6KAy8xmfQBkBZhYyz/pm4C5sQ60wvQ3Vj1cTXb1vZdk/QeMawsW4aXWnVL57oII0sVlWp2N9LvVguENVBlfWss36vJSxKPpkJ5vsFGLkvVpYF1UADTSRbV6b9GEZJrPlYuBDtjR3fcIKrwBtOsoBpZxNwBTskBnsaiaxgGe1YB99Pu4vsD6qY6WstzjdzP8yidiQLoEkN3rsA1qG8o3Ol6bmby7VuTRosSMa9LSvxTdb4iuRRgCo5DuR25Jfa00klY9YVVNlbWgmqulEieLHcR8G6TKGp2JxlD/Fd+rKhepQjhJ/soHp+agDwSxmu8cII9NYpF7fAQ1F8ur4VNnxtnQKijMh6yS6Ju4A+mDjEOr+ElAUHHyjAKJg50jwDBEO6RN7PxmJMOP86/qW/9KymAx85qQaMfyIwOtrsZMJSnoDflQR47OFN18PfMLWGhYmBgTq5YxOWMk9jH4FdYBFr+3ShQcSPOTUqiOE9Mc8uM2Ze8+j/D8vhrgiZCmXzPUL2JNXJ5gHsYHmP3vmoOCzCZU7IDHaclBUxBh8gCYU3xCndcVmysQGblQ4zgtfj9jtBRJy64oJdD4/yc1rtdYyagqMpfE02LyMWT16XDZNX35yGjhNYS6oCjfIZtJXW5456ufBM4/H1GpKm1PUTudJxr7874m1IY3Cwc5/wQ68UJdm/f+8XeV4L1eVIGMddhNWP7t7M+ovzrxb03Z+6jQ0MLxg9A86+HwG5fQyunNimTgJY8XJz1EKj8Cnub+pV6WetMnd3jLyn5HmAbm3icu6iNU3wSAxcwAucG7hcFXxfavODJ6r7mroI2D44Be3KzArCap9Or+xfUJTDOoPitBR3rx2ak6eALW/nxBuCO47faXKrjXfp/dyJ8h3akW3zmxHOUw1bGu35m46t66hKamobOyrJ0Gn2LhOY5BCvNAUPwPiywkiTDztJDRFe6BhRgkkVLKnJvXQraW2RuUuJJY6o6lef5r6B1gCUbf6MOcQQJCb2EIZfWllHHln6g/9TH9yXiOEtDg9NuLJKF/NBVH2oaN5haTtffVKc9jNOUywTxaaVj4i7Qm45RmS8aL/OrGlsbf3YwvyHqzUHu6RRe0XOkhhes/4xxkn3Dn2DTYHKsbVEb/X4o4eph41aoeMG1AzuwawUjHyjL7ZPY18uZSpeZaLZafm8en6EZkqgqAsmZzie8CQZo9FLoFE5R673CY7Trt2KlEMoTP4OXWd7/DtCHE8qB3NfSNgh5ViEUPSWi3wNFzh6KygRkb4ayI5ORh8E6QWjaBsGlrGobTYE2pK3Uw2WhBHf9uMgm3tEN0mcU5B0Sx2rQJc8xUEPWbY547m6FZABPp2n1mN4GjEJUOcJJQl6GF5PY/jn/15SneqgK+TiPcVmDg5bQC6vaFHwFHp9ImukUSR7F259pFeiha0Hp/JKGjZYeSecZlo/rqfDmk8OsPP4+WOH2hEw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f28e5039-74b9-4e40-237d-08da13e2f27d X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:27.9420 (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: d/kyyebTrUzOHW02P5QIG7ZFO2vN6VWNf0bSxzvJdvUYdLwtSD+tjlpmWci/5qMhq0vs4aUlQzC8wtxeOMiAaw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4321 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-ORIG-GUID: QGIKUEQMiF4OuyTDm1u9OqaXv7DmVEAM X-Proofpoint-GUID: QGIKUEQMiF4OuyTDm1u9OqaXv7DmVEAM Received-SPF: pass client-ip=205.220.165.32; envelope-from=jonah.palmer@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier Display feature names instead of bitmaps for host, guest, and backend for VirtIODevices. Display status names instead of bitmaps for VirtIODevices. Display feature names instead of bitmaps for backend, protocol, acked, and features (hdev->features) for vhost devices. Decode features according to device ID. Decode statuses according to configuration status bitmap (config_status_map). Decode vhost user protocol features according to vhost user protocol bitmap (vhost_user_protocol_map). Transport features are on the first line. Undecoded bits (if any) are stored in a separate field. Signed-off-by: Jonah Palmer --- hw/block/virtio-blk.c | 29 ++++ hw/char/virtio-serial-bus.c | 11 ++ hw/display/virtio-gpu.c | 18 ++ hw/input/virtio-input.c | 10 ++ hw/net/virtio-net.c | 47 +++++ hw/scsi/virtio-scsi.c | 17 ++ hw/virtio/vhost-user-fs.c | 10 ++ hw/virtio/vhost-user-i2c.c | 14 ++ hw/virtio/vhost-vsock-common.c | 10 ++ hw/virtio/virtio-balloon.c | 14 ++ hw/virtio/virtio-crypto.c | 10 ++ hw/virtio/virtio-iommu.c | 14 ++ hw/virtio/virtio-mem.c | 11 ++ hw/virtio/virtio.c | 302 ++++++++++++++++++++++++++++++++- include/hw/virtio/vhost.h | 3 + include/hw/virtio/virtio.h | 19 +++ qapi/virtio.json | 156 ++++++++++++++--- 17 files changed, 667 insertions(+), 28 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 27c71ad316..f104603040 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/iov.h" #include "qemu/module.h" #include "qemu/error-report.h" @@ -33,10 +34,38 @@ #include "migration/qemu-file-types.h" #include "hw/virtio/virtio-access.h" #include "qemu/coroutine.h" +#include "standard-headers/linux/vhost_types.h" /* Config size before the discard support (hide associated config fields) */ #define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ max_discard_sectors) + +qmp_virtio_feature_map_t blk_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_BLK_F_##name, #name } + FEATURE_ENTRY(SIZE_MAX), + FEATURE_ENTRY(SEG_MAX), + FEATURE_ENTRY(GEOMETRY), + FEATURE_ENTRY(RO), + FEATURE_ENTRY(BLK_SIZE), + FEATURE_ENTRY(TOPOLOGY), + FEATURE_ENTRY(MQ), + FEATURE_ENTRY(DISCARD), + FEATURE_ENTRY(WRITE_ZEROES), +#ifndef VIRTIO_BLK_NO_LEGACY + FEATURE_ENTRY(BARRIER), + FEATURE_ENTRY(SCSI), + FEATURE_ENTRY(FLUSH), + FEATURE_ENTRY(CONFIG_WCE), +#endif /* !VIRTIO_BLK_NO_LEGACY */ +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + /* * Starting from the discard feature, we can use this array to properly * set the config size depending on the features enabled. diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 7d4601cb5d..fbb31a2b16 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/iov.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -32,6 +33,16 @@ #include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-access.h" +qmp_virtio_feature_map_t serial_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_CONSOLE_F_##name, #name } + FEATURE_ENTRY(SIZE), + FEATURE_ENTRY(MULTIPORT), + FEATURE_ENTRY(EMERG_WRITE), +#undef FEATURE_ENTRY + { -1, "" } +}; + static struct VirtIOSerialDevices { QLIST_HEAD(, VirtIOSerial) devices; } vserdevices; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 529b5246b2..0bd5dc6232 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -29,10 +29,28 @@ #include "qemu/log.h" #include "qemu/module.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/error-report.h" +#include "standard-headers/linux/vhost_types.h" #define VIRTIO_GPU_VM_VERSION 1 +qmp_virtio_feature_map_t gpu_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_GPU_F_##name, #name } + FEATURE_ENTRY(VIRGL), + FEATURE_ENTRY(EDID), + FEATURE_ENTRY(RESOURCE_UUID), + FEATURE_ENTRY(RESOURCE_BLOB), + FEATURE_ENTRY(CONTEXT_INIT), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + static struct virtio_gpu_simple_resource* virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id); static struct virtio_gpu_simple_resource * diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index 5b5398b3ca..fe0ed6d5b4 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -6,6 +6,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/iov.h" #include "qemu/module.h" #include "trace.h" @@ -14,10 +15,19 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-input.h" +#include "standard-headers/linux/vhost_types.h" #include "standard-headers/linux/input.h" #define VIRTIO_INPUT_VM_VERSION 1 +qmp_virtio_feature_map_t input_map[] = { +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + /* ----------------------------------------------------------------- */ void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 027ce40c6f..9356958fb6 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -35,9 +35,11 @@ #include "hw/qdev-properties.h" #include "qapi/qapi-types-migration.h" #include "qapi/qapi-events-migration.h" +#include "qapi/qapi-visit-virtio.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" #include "standard-headers/linux/ethtool.h" +#include "standard-headers/linux/vhost_types.h" #include "sysemu/sysemu.h" #include "trace.h" #include "monitor/qdev.h" @@ -90,6 +92,51 @@ VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | \ VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) +qmp_virtio_feature_map_t net_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_NET_F_##name, #name } + FEATURE_ENTRY(CSUM), + FEATURE_ENTRY(GUEST_CSUM), + FEATURE_ENTRY(CTRL_GUEST_OFFLOADS), + FEATURE_ENTRY(MTU), + FEATURE_ENTRY(MAC), + FEATURE_ENTRY(GUEST_TSO4), + FEATURE_ENTRY(GUEST_TSO6), + FEATURE_ENTRY(GUEST_ECN), + FEATURE_ENTRY(GUEST_UFO), + FEATURE_ENTRY(HOST_TSO4), + FEATURE_ENTRY(HOST_TSO6), + FEATURE_ENTRY(HOST_ECN), + FEATURE_ENTRY(HOST_UFO), + FEATURE_ENTRY(MRG_RXBUF), + FEATURE_ENTRY(STATUS), + FEATURE_ENTRY(CTRL_VQ), + FEATURE_ENTRY(CTRL_RX), + FEATURE_ENTRY(CTRL_VLAN), + FEATURE_ENTRY(CTRL_RX_EXTRA), + FEATURE_ENTRY(GUEST_ANNOUNCE), + FEATURE_ENTRY(MQ), + FEATURE_ENTRY(CTRL_MAC_ADDR), + FEATURE_ENTRY(HASH_REPORT), + FEATURE_ENTRY(RSS), + FEATURE_ENTRY(RSC_EXT), + FEATURE_ENTRY(STANDBY), + FEATURE_ENTRY(SPEED_DUPLEX), +#ifndef VIRTIO_NET_NO_LEGACY + FEATURE_ENTRY(GSO), +#endif /* VIRTIO_NET_NO_LEGACY */ +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_NET_F_##name, #name } + FEATURE_ENTRY(VIRTIO_NET_HDR), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + static const VirtIOFeature feature_sizes[] = { {.flags = 1ULL << VIRTIO_NET_F_MAC, .end = endof(struct virtio_net_config, mac)}, diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 2a6141d081..9ca8faa40e 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -15,7 +15,9 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/vhost_types.h" #include "hw/virtio/virtio-scsi.h" #include "migration/qemu-file-types.h" #include "qemu/error-report.h" @@ -29,6 +31,21 @@ #include "hw/virtio/virtio-access.h" #include "trace.h" +qmp_virtio_feature_map_t scsi_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_SCSI_F_##name, #name } + FEATURE_ENTRY(INOUT), + FEATURE_ENTRY(HOTPLUG), + FEATURE_ENTRY(CHANGE), + FEATURE_ENTRY(T10_PI), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + static inline int virtio_scsi_get_lun(uint8_t *lun) { return ((lun[2] << 8) | lun[3]) & 0x3FFF; diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index e513e4fdda..096cc07c44 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -15,6 +15,7 @@ #include #include "standard-headers/linux/virtio_fs.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" #include "hw/virtio/virtio-bus.h" @@ -23,6 +24,15 @@ #include "hw/virtio/vhost-user-fs.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" +#include "standard-headers/linux/vhost_types.h" + +qmp_virtio_feature_map_t fs_map[] = { +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; static const int user_feature_bits[] = { VIRTIO_F_VERSION_1, diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 6020eee093..931ec9836c 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -8,11 +8,25 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-i2c.h" #include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/vhost_types.h" + +qmp_virtio_feature_map_t i2c_map[] = { +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VIRTIO_I2C_F_##name, #name } + FEATURE_ENTRY(ZERO_LENGTH_REQUEST), +#undef FEATURE_ENTRY + { -1, "" } +}; static const int feature_bits[] = { VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index 7394818e00..b03f94d8f8 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -11,12 +11,22 @@ #include "qemu/osdep.h" #include "standard-headers/linux/virtio_vsock.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "hw/virtio/virtio-access.h" #include "qemu/error-report.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-vsock.h" #include "qemu/iov.h" #include "monitor/monitor.h" +#include "standard-headers/linux/vhost_types.h" + +qmp_virtio_feature_map_t vsock_map[] = { +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; const int feature_bits[] = { VIRTIO_VSOCK_F_SEQPACKET, diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 193ff5261c..b2ae0a4d8c 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -28,6 +28,7 @@ #include "qapi/error.h" #include "qapi/qapi-events-machine.h" #include "qapi/visitor.h" +#include "qapi/qapi-visit-virtio.h" #include "trace.h" #include "qemu/error-report.h" #include "migration/misc.h" @@ -38,6 +39,19 @@ #define BALLOON_PAGE_SIZE (1 << VIRTIO_BALLOON_PFN_SHIFT) +qmp_virtio_feature_map_t balloon_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_BALLOON_F_##name, #name } + FEATURE_ENTRY(MUST_TELL_HOST), + FEATURE_ENTRY(STATS_VQ), + FEATURE_ENTRY(DEFLATE_ON_OOM), + FEATURE_ENTRY(FREE_PAGE_HINT), + FEATURE_ENTRY(PAGE_POISON), + FEATURE_ENTRY(REPORTING), +#undef FEATURE_ENTRY + { -1, "" } +}; + typedef struct PartiallyBalloonedPage { ram_addr_t base_gpa; unsigned long *bitmap; diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 947a11c3af..5c9a3d045d 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -16,6 +16,7 @@ #include "qemu/main-loop.h" #include "qemu/module.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/error-report.h" #include "hw/virtio/virtio.h" @@ -23,10 +24,19 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-access.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/vhost_types.h" #include "sysemu/cryptodev-vhost.h" #define VIRTIO_CRYPTO_VM_VERSION 1 +qmp_virtio_feature_map_t crypto_map[] = { +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + /* * Transfer virtqueue index to crypto queue index. * The control virtqueue is after the data virtqueues diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 4ed5bb16ba..d993106d10 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -26,6 +26,7 @@ #include "sysemu/kvm.h" #include "sysemu/reset.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/error-report.h" #include "trace.h" @@ -41,6 +42,19 @@ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 #define VIOMMU_PROBE_SIZE 512 +qmp_virtio_feature_map_t iommu_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_IOMMU_F_##name, #name } + FEATURE_ENTRY(INPUT_RANGE), + FEATURE_ENTRY(DOMAIN_RANGE), + FEATURE_ENTRY(MAP_UNMAP), + FEATURE_ENTRY(BYPASS), + FEATURE_ENTRY(PROBE), + FEATURE_ENTRY(MMIO), +#undef FEATURE_ENTRY + { -1, "" } +}; + typedef struct VirtIOIOMMUDomain { uint32_t id; bool bypass; diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 465a996214..31e7af834e 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -25,6 +25,7 @@ #include "hw/virtio/virtio-mem.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "qapi/qapi-visit-virtio.h" #include "exec/ram_addr.h" #include "migration/misc.h" #include "hw/boards.h" @@ -32,6 +33,16 @@ #include CONFIG_DEVICES #include "trace.h" +qmp_virtio_feature_map_t mem_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_MEM_F_##name, #name } +#ifndef CONFIG_ACPI + FEATURE_ENTRY(ACPI_PXM), +#endif /* CONFIG_ACPI */ +#undef FEATURE_ENTRY + { -1, "" } +}; + /* * We only had legacy x86 guests that did not support * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have legacy guests. diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 7f8eb29ced..af376be933 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -34,10 +34,99 @@ #include "sysemu/dma.h" #include "sysemu/runstate.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/vhost_types.h" +#include CONFIG_DEVICES /* QAPI list of realized VirtIODevices */ static QTAILQ_HEAD(, VirtIODevice) virtio_list; +/* + * Maximum size of virtio device config space + */ +#define VHOST_USER_MAX_CONFIG_SIZE 256 + +enum VhostUserProtocolFeature { + VHOST_USER_PROTOCOL_F_MQ = 0, + VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1, + VHOST_USER_PROTOCOL_F_RARP = 2, + VHOST_USER_PROTOCOL_F_REPLY_ACK = 3, + VHOST_USER_PROTOCOL_F_NET_MTU = 4, + VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5, + VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6, + VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7, + VHOST_USER_PROTOCOL_F_PAGEFAULT = 8, + VHOST_USER_PROTOCOL_F_CONFIG = 9, + VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10, + VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11, + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12, + VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13, + VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS = 14, + VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15, + VHOST_USER_PROTOCOL_F_MAX +}; + +static qmp_virtio_feature_map_t transport_map[] = { +#define FEATURE_ENTRY(name) \ + { VIRTIO_F_##name, #name } +#ifndef VIRTIO_CONFIG_NO_LEGACY + FEATURE_ENTRY(NOTIFY_ON_EMPTY), + FEATURE_ENTRY(ANY_LAYOUT), +#endif /* VIRTIO_CONFIG_NO_LEGACY */ + FEATURE_ENTRY(VERSION_1), + FEATURE_ENTRY(IOMMU_PLATFORM), + FEATURE_ENTRY(RING_PACKED), + FEATURE_ENTRY(ORDER_PLATFORM), + FEATURE_ENTRY(SR_IOV), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VIRTIO_RING_F_##name, #name } + FEATURE_ENTRY(INDIRECT_DESC), + FEATURE_ENTRY(EVENT_IDX), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_USER_F_##name, #name } + FEATURE_ENTRY(PROTOCOL_FEATURES), +#undef FEATURE_ENTRY + { -1, "" } +}; + +static qmp_virtio_feature_map_t vhost_user_protocol_map[] = { +#define FEATURE_ENTRY(name) \ + { VHOST_USER_PROTOCOL_F_##name, #name } + FEATURE_ENTRY(MQ), + FEATURE_ENTRY(LOG_SHMFD), + FEATURE_ENTRY(RARP), + FEATURE_ENTRY(REPLY_ACK), + FEATURE_ENTRY(NET_MTU), + FEATURE_ENTRY(SLAVE_REQ), + FEATURE_ENTRY(CROSS_ENDIAN), + FEATURE_ENTRY(CRYPTO_SESSION), + FEATURE_ENTRY(PAGEFAULT), + FEATURE_ENTRY(CONFIG), + FEATURE_ENTRY(SLAVE_SEND_FD), + FEATURE_ENTRY(HOST_NOTIFIER), + FEATURE_ENTRY(INFLIGHT_SHMFD), + FEATURE_ENTRY(RESET_DEVICE), + FEATURE_ENTRY(INBAND_NOTIFICATIONS), + FEATURE_ENTRY(CONFIGURE_MEM_SLOTS), +#undef FEATURE_ENTRY + { -1, "" } +}; + +/* virtio device configuration statuses */ +static qmp_virtio_feature_map_t config_status_map[] = { +#define STATUS_ENTRY(name) \ + { VIRTIO_CONFIG_S_##name, #name } + STATUS_ENTRY(DRIVER_OK), + STATUS_ENTRY(FEATURES_OK), + STATUS_ENTRY(DRIVER), + STATUS_ENTRY(NEEDS_RESET), + STATUS_ENTRY(FAILED), + STATUS_ENTRY(ACKNOWLEDGE), +#undef STATUS_ENTRY + { -1, "" } +}; + /* * The alignment to use between consumer and producer parts of vring. * x86 pagesize again. This is the default, used by transports like PCI @@ -3962,6 +4051,196 @@ static VirtIODevice *virtio_device_find(const char *path) return NULL; } +#define CONVERT_FEATURES(type, map, is_status, bitmap) \ + ({ \ + type *list = NULL; \ + type *node; \ + for (i = 0; map[i].virtio_bit != -1; i++) { \ + if (is_status) { \ + bit = map[i].virtio_bit; \ + } \ + else { \ + bit = 1ULL << map[i].virtio_bit; \ + } \ + if ((bitmap & bit) == 0) { \ + continue; \ + } \ + node = g_new0(type, 1); \ + node->value = g_strdup(map[i].feature_name); \ + node->next = list; \ + list = node; \ + bitmap ^= bit; \ + } \ + list; \ + }) + +static VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap) +{ + VirtioDeviceStatus *status; + uint8_t bit; + int i; + + status = g_new0(VirtioDeviceStatus, 1); + status->statuses = CONVERT_FEATURES(strList, config_status_map, 1, bitmap); + status->has_unknown_statuses = bitmap != 0; + if (status->has_unknown_statuses) { + status->unknown_statuses = bitmap; + } + + return status; +} + +static VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap) +{ + VhostDeviceProtocols *vhu_protocols; + uint64_t bit; + int i; + + vhu_protocols = g_new0(VhostDeviceProtocols, 1); + vhu_protocols->protocols = + CONVERT_FEATURES(strList, + vhost_user_protocol_map, 0, bitmap); + vhu_protocols->has_unknown_protocols = bitmap != 0; + if (vhu_protocols->has_unknown_protocols) { + vhu_protocols->unknown_protocols = bitmap; + } + + return vhu_protocols; +} + +static VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, + uint64_t bitmap) +{ + VirtioDeviceFeatures *features; + uint64_t bit; + int i; + + features = g_new0(VirtioDeviceFeatures, 1); + features->has_dev_features = true; + + /* transport features */ + features->transports = CONVERT_FEATURES(strList, transport_map, 0, bitmap); + + /* device features */ + switch (device_id) { +#ifdef CONFIG_VIRTIO_SERIAL + case VIRTIO_ID_CONSOLE: + features->dev_features = + CONVERT_FEATURES(strList, serial_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_BLK + case VIRTIO_ID_BLOCK: + features->dev_features = + CONVERT_FEATURES(strList, blk_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_GPU + case VIRTIO_ID_GPU: + features->dev_features = + CONVERT_FEATURES(strList, gpu_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_NET + case VIRTIO_ID_NET: + features->dev_features = + CONVERT_FEATURES(strList, net_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_SCSI + case VIRTIO_ID_SCSI: + features->dev_features = + CONVERT_FEATURES(strList, scsi_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_BALLOON + case VIRTIO_ID_BALLOON: + features->dev_features = + CONVERT_FEATURES(strList, balloon_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_IOMMU + case VIRTIO_ID_IOMMU: + features->dev_features = + CONVERT_FEATURES(strList, iommu_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_INPUT + case VIRTIO_ID_INPUT: + features->dev_features = + CONVERT_FEATURES(strList, input_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VHOST_USER_FS + case VIRTIO_ID_FS: + features->dev_features = + CONVERT_FEATURES(strList, fs_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VHOST_VSOCK + case VIRTIO_ID_VSOCK: + features->dev_features = + CONVERT_FEATURES(strList, vsock_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_CRYPTO + case VIRTIO_ID_CRYPTO: + features->dev_features = + CONVERT_FEATURES(strList, crypto_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_MEM + case VIRTIO_ID_MEM: + features->dev_features = + CONVERT_FEATURES(strList, mem_map, 0, bitmap); + break; +#endif +#ifdef CONFIG_VIRTIO_I2C_ADAPTER + case VIRTIO_ID_I2C_ADAPTER: + features->dev_features = + CONVERT_FEATURES(strList, i2c_map, 0, bitmap); + break; +#endif + /* No features */ + case VIRTIO_ID_9P: + case VIRTIO_ID_PMEM: + case VIRTIO_ID_RNG: + case VIRTIO_ID_IOMEM: + case VIRTIO_ID_RPMSG: + case VIRTIO_ID_CLOCK: + case VIRTIO_ID_MAC80211_WLAN: + case VIRTIO_ID_MAC80211_HWSIM: + case VIRTIO_ID_RPROC_SERIAL: + case VIRTIO_ID_MEMORY_BALLOON: + case VIRTIO_ID_CAIF: + case VIRTIO_ID_SIGNAL_DIST: + case VIRTIO_ID_PSTORE: + case VIRTIO_ID_SOUND: + case VIRTIO_ID_BT: + case VIRTIO_ID_RPMB: + case VIRTIO_ID_VIDEO_ENCODER: + case VIRTIO_ID_VIDEO_DECODER: + case VIRTIO_ID_SCMI: + case VIRTIO_ID_NITRO_SEC_MOD: + case VIRTIO_ID_WATCHDOG: + case VIRTIO_ID_CAN: + case VIRTIO_ID_DMABUF: + case VIRTIO_ID_PARAM_SERV: + case VIRTIO_ID_AUDIO_POLICY: + case VIRTIO_ID_GPIO: + break; + default: + g_assert_not_reached(); + } + + features->has_unknown_dev_features = bitmap != 0; + if (features->has_unknown_dev_features) { + features->unknown_dev_features = bitmap; + } + + return features; +} + VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) { VirtIODevice *vdev; @@ -3977,9 +4256,12 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) status->name = g_strdup(vdev->name); status->device_id = vdev->device_id; status->vhost_started = vdev->vhost_started; - status->guest_features = vdev->guest_features; - status->host_features = vdev->host_features; - status->backend_features = vdev->backend_features; + status->guest_features = qmp_decode_features(vdev->device_id, + vdev->guest_features); + status->host_features = qmp_decode_features(vdev->device_id, + vdev->host_features); + status->backend_features = qmp_decode_features(vdev->device_id, + vdev->backend_features); switch (vdev->device_endian) { case VIRTIO_DEVICE_ENDIAN_LITTLE: @@ -3994,7 +4276,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) } status->num_vqs = virtio_get_num_queues(vdev); - status->status = vdev->status; + status->status = qmp_decode_status(vdev->status); status->isr = vdev->isr; status->queue_sel = vdev->queue_sel; status->vm_running = vdev->vm_running; @@ -4017,10 +4299,14 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections; status->vhost_dev->nvqs = hdev->nvqs; status->vhost_dev->vq_index = hdev->vq_index; - status->vhost_dev->features = hdev->features; - status->vhost_dev->acked_features = hdev->acked_features; - status->vhost_dev->backend_features = hdev->backend_features; - status->vhost_dev->protocol_features = hdev->protocol_features; + status->vhost_dev->features = + qmp_decode_features(vdev->device_id, hdev->features); + status->vhost_dev->acked_features = + qmp_decode_features(vdev->device_id, hdev->acked_features); + status->vhost_dev->backend_features = + qmp_decode_features(vdev->device_id, hdev->backend_features); + status->vhost_dev->protocol_features = + qmp_decode_protocols(hdev->protocol_features); status->vhost_dev->max_queues = hdev->max_queues; status->vhost_dev->backend_cap = hdev->backend_cap; status->vhost_dev->log_enabled = hdev->log_enabled; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 58a73e7b7a..4aaa21faf6 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -5,6 +5,9 @@ #include "hw/virtio/virtio.h" #include "exec/memory.h" +#define VHOST_F_DEVICE_IOTLB 63 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + /* Generic structures common for any vhost based device. */ struct vhost_inflight { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index ef99a626a8..9df4e081c9 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -71,6 +71,25 @@ typedef struct VirtQueueElement #define TYPE_VIRTIO_DEVICE "virtio-device" OBJECT_DECLARE_TYPE(VirtIODevice, VirtioDeviceClass, VIRTIO_DEVICE) +typedef struct { + int virtio_bit; + const char *feature_name; +} qmp_virtio_feature_map_t; + +extern qmp_virtio_feature_map_t serial_map[]; +extern qmp_virtio_feature_map_t blk_map[]; +extern qmp_virtio_feature_map_t gpu_map[]; +extern qmp_virtio_feature_map_t net_map[]; +extern qmp_virtio_feature_map_t scsi_map[]; +extern qmp_virtio_feature_map_t balloon_map[]; +extern qmp_virtio_feature_map_t iommu_map[]; +extern qmp_virtio_feature_map_t input_map[]; +extern qmp_virtio_feature_map_t fs_map[]; +extern qmp_virtio_feature_map_t vsock_map[]; +extern qmp_virtio_feature_map_t crypto_map[]; +extern qmp_virtio_feature_map_t mem_map[]; +extern qmp_virtio_feature_map_t i2c_map[]; + enum virtio_device_endian { VIRTIO_DEVICE_ENDIAN_UNKNOWN, VIRTIO_DEVICE_ENDIAN_LITTLE, diff --git a/qapi/virtio.json b/qapi/virtio.json index ba61d83df7..474a8bd64e 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -106,10 +106,10 @@ 'n-tmp-sections': 'int', 'nvqs': 'uint32', 'vq-index': 'int', - 'features': 'uint64', - 'acked-features': 'uint64', - 'backend-features': 'uint64', - 'protocol-features': 'uint64', + 'features': 'VirtioDeviceFeatures', + 'acked-features': 'VirtioDeviceFeatures', + 'backend-features': 'VirtioDeviceFeatures', + 'protocol-features': 'VhostDeviceProtocols', 'max-queues': 'uint64', 'backend-cap': 'uint64', 'log-enabled': 'bool', @@ -176,11 +176,11 @@ 'device-id': 'uint16', 'vhost-started': 'bool', 'device-endian': 'str', - 'guest-features': 'uint64', - 'host-features': 'uint64', - 'backend-features': 'uint64', + 'guest-features': 'VirtioDeviceFeatures', + 'host-features': 'VirtioDeviceFeatures', + 'backend-features': 'VirtioDeviceFeatures', 'num-vqs': 'int', - 'status': 'uint8', + 'status': 'VirtioDeviceStatus', 'isr': 'uint8', 'queue-sel': 'uint16', 'vm-running': 'bool', @@ -222,14 +222,28 @@ # "name": "virtio-crypto", # "started": true, # "device-id": 20, -# "backend-features": 0, +# "backend-features": { +# "transports": [], +# "dev-features": [] +# }, # "start-on-kick": false, # "isr": 1, # "broken": false, -# "status": 15, +# "status": { +# "statuses": ["ACKNOWLEDGE", "DRIVER", "FEATURES_OK", +# "DRIVER_OK"] +# }, # "num-vqs": 2, -# "guest-features": 5100273664, -# "host-features": 6325010432, +# "guest-features": { +# "transports": ["EVENT_IDX", "INDIRECT_DESC", "VERSION_1"], +# "dev-features": [] +# }, +# "host-features": { +# "transports": ["PROTOCOL_FEATURES", "EVENT_IDX", +# "INDIRECT_DESC", "VERSION_1", "ANY_LAYOUT", +# "NOTIFY_ON_EMPTY"], +# "dev-features": [] +# }, # "use-guest-notifier-mask": true, # "vm-running": true, # "queue-sel": 1, @@ -257,22 +271,65 @@ # "max-queues": 1, # "backend-cap": 2, # "log-size": 0, -# "backend-features": 0, +# "backend-features": { +# "transports": [], +# "dev-features": [] +# }, # "nvqs": 2, -# "protocol-features": 0, +# "protocol-features": { +# "protocols": [] +# }, # "vq-index": 0, # "log-enabled": false, -# "acked-features": 5100306432, -# "features": 13908344832 +# "acked-features": { +# "transports": ["EVENT_IDX", "INDIRECT_DESC", "VERSION_1", +# "ANY_LAYOUT", "NOTIFY_ON_EMPTY"], +# "dev-features": ["MRG_RXBUF"] +# }, +# "features": { +# "transports": ["EVENT_IDX", "INDIRECT_DESC", +# "IOMMU_PLATFORM", "VERSION_1", "ANY_LAYOUT", +# "NOTIFY_ON_EMPTY"], +# "dev-features": ["LOG_ALL", "MRG_RXBUF"] +# } +# }, +# "backend-features": { +# "transports": ["PROTOCOL_FEATURES", "EVENT_IDX", "INDIRECT_DESC", +# "VERSION_1", "ANY_LAYOUT", "NOTIFY_ON_EMPTY"], +# "dev-features": ["GSO", "CTRL_MAC_ADDR", "GUEST_ANNOUNCE", "CTRL_RX_EXTRA", +# "CTRL_VLAN", "CTRL_RX", "CTRL_VQ", "STATUS", "MRG_RXBUF", +# "HOST_UFO", "HOST_ECN", "HOST_TSO6", "HOST_TSO4", +# "GUEST_UFO", "GUEST_ECN", "GUEST_TSO6", "GUEST_TSO4", +# "MAC", "CTRL_GUEST_OFFLOADS", "GUEST_CSUM", "CSUM"] # }, -# "backend-features": 6337593319, # "start-on-kick": false, # "isr": 1, # "broken": false, -# "status": 15, +# "status": { +# "statuses": ["ACKNOWLEDGE", "DRIVER", "FEATURES_OK", "DRIVER_OK"] +# }, # "num-vqs": 3, -# "guest-features": 5111807911, -# "host-features": 6337593319, +# "guest-features": { +# "transports": ["EVENT_IDX", "INDIRECT_DESC", "VERSION_1"], +# "dev-features": ["CTRL_MAC_ADDR", "GUEST_ANNOUNCE", "CTRL_VLAN", +# "CTRL_RX", "CTRL_VQ", "STATUS", "MRG_RXBUF", +# "HOST_UFO", "HOST_ECN", "HOST_TSO6", +# "HOST_TSO4", "GUEST_UFO", "GUEST_ECN", +# "GUEST_TSO6", "GUEST_TSO4", "MAC", +# "CTRL_GUEST_OFFLOADS", "GUEST_CSUM", "CSUM"] +# }, +# "host-features": { +# "transports": ["PROTOCOL_FEATURES", "EVENT_IDX", +# "INDIRECT_DESC", "VERSION_1", "ANY_LAYOUT", +# "NOTIFY_ON_EMPTY"], +# "dev-features": ["GSO", "CTRL_MAC_ADDR", "GUEST_ANNOUNCE", +# "CTRL_RX_EXTRA", "CTRL_VLAN", "CTRL_RX", +# "CTRL_VQ", "STATUS", "MRG_RXBUF", "HOST_UFO", +# "HOST_ECN", "HOST_TSO4", "HOST_TSO4", +# "GUEST_UFO", "GUEST_ECN", "GUEST_TSO6", +# "GUEST_TSO4", "MAC", "CTRL_GUEST_OFFLOADS", +# "GUEST_CSUM", "CSUM"] +# }, # "use-guest-notifier-mask": true, # "vm-running": true, # "queue-sel": 2, @@ -288,3 +345,62 @@ 'data': { 'path': 'str' }, 'returns': 'VirtioStatus', 'features': [ 'unstable' ] } + +## +# @VirtioDeviceStatus: +# +# A structure defined to list the configuration statuses of a virtio +# device +# +# @statuses: List of decoded configuration statuses of the virtio +# device +# +# @unknown-statuses: Virtio device statuses bitmap that have not been decoded +# +# Since: 7.0 +## + +{ 'struct': 'VirtioDeviceStatus', + 'data': { 'statuses': [ 'str' ], + '*unknown-statuses': 'uint8' } } + +## +# @VhostDeviceProtocols: +# +# A structure defined to list the vhost user protocol features of a +# Vhost User device +# +# @protocols: List of decoded vhost user protocol features of a vhost +# user device +# +# @unknown-protocols: Vhost user device protocol features bitmap that +# have not been decoded +# +# Since: 7.0 +## + +{ 'struct': 'VhostDeviceProtocols', + 'data': { 'protocols': [ 'str' ], + '*unknown-protocols': 'uint64' } } + +## +# @VirtioDeviceFeatures: +# +# The common fields that apply to most Virtio devices. Some devices +# may not have their own device-specific features (e.g. virtio-rng). +# +# @transports: List of transport features of the virtio device +# +# @dev-features: List of device-specific features (if the device has +# unique features) +# +# @unknown-dev-features: Virtio device features bitmap that have not +# been decoded +# +# Since: 7.0 +## + +{ 'struct': 'VirtioDeviceFeatures', + 'data': { 'transports': [ 'str' ], + '*dev-features': [ 'str' ], + '*unknown-dev-features': 'uint64' } } From patchwork Fri Apr 1 13:23:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=B9Bsp3F+; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=o/PUDVZc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLw76kLCz9sXM for ; Sat, 2 Apr 2022 00:43:03 +1100 (AEDT) Received: from localhost ([::1]:60264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHYM-0002x3-0A for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:43:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGi-0002Uf-V1; Fri, 01 Apr 2022 09:24:54 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:15700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGg-0007DO-Fl; Fri, 01 Apr 2022 09:24:48 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CkYcb017617; Fri, 1 Apr 2022 13:24:35 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 : mime-version; s=corp-2021-07-09; bh=o8iQTOsQ3dz/4RO2J6MuKFEjAZAB4/RkoG8l376/Pvw=; b=B9Bsp3F+UngkiszFKaor3YoyYZQmK6O3EVZg6aIOpSiCQct+8NIrLwcaKkmFXUr7KaL6 vkz0uvnXEnJz/gF3PvCKuFbJoDBbrwkJEr5zy10qSURWniPXV4gqa2qLzTHkLuvG+iSU SSzRotc6nt+pstd6tXiuwsdUJCYv43QzNzjioxG1WD87ii/8DQHib9+YA6nTpY4XclPP uPgs2fNiYeTg5EKS8ANDrY41IyUp6DzdQE2reKwJdTRUTPmemPveRcL8BtyXc/m8eekK 7W1dC0MiFvjh6ira1x3PfGhcXMQBHSO77zK+VC6k1u9MKb1KWXFXgDdZA9Lrlorfsi4w Ug== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1ucty9xx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:35 +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 231DHPXQ011097; Fri, 1 Apr 2022 13:24:34 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f1s96j842-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mFK+zedNiQguCMqUNV0XtAHKMWjmX7jdK80luZiJVLSQ6KbZSVbKQz7vN7Jn139PytemJAeloVCu81V0LEr92AlWps+4BJGOo7ErL5furhRIRZOvYUc7NqWO2asYkHiEoTkf76Qeq+6J69adMVYf8KY7r7nE2DXQWQ6NzK46xEtZ8lfhBd/RHCnxta4HST8XqHvu28VDimK24e8I8e1DYLs4OpZuvlux84Ab7LNIWBNoFCi/E/SeVU3URx4it4OV2XjygcHFns8vDAOBXhtADfz+y8DoW9Ds5BoSlsAqyPiwO/JXwVpacoyS9qBQie2+RMSv9r08FAmpXbyml5j2GQ== 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=o8iQTOsQ3dz/4RO2J6MuKFEjAZAB4/RkoG8l376/Pvw=; b=dty0kHtiIUe2yzWc18aToZ3pdurY476u3m7GCi1lKgjJRfFzENL1HOMXHG5VxQE1r0bfpi49RmaTtvyJjYPDeZAfyEzUoABcO3OgsyawZ8ZTuvHw5nsbYIFeCp5t35mvb6tUqZEnyVFIQr7GwsyW9uTuGGlG7WevU3LBlQLz8SE/gXUYeLdonxECIz6E2lqv6pVTlSRIwt331YwHiY5buFb/TMCILbmHTaxJWp5YhBlMPy8NgnL9/zUSVLxNFklklielJcGE2lAEdQCf+wzEFfrN1y1yLku9jmZxJWCGnPzBVCCuCUckVNd8SR1OvP6YxZrhuLmxrOzpKproDGeZqw== 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=o8iQTOsQ3dz/4RO2J6MuKFEjAZAB4/RkoG8l376/Pvw=; b=o/PUDVZc/BNLlav4vyHd4dgIup+auAnuU0c42Nu4mj8TgnGaopEUcDJzcLQdWg2hp8I24TexqIQh/KEPVBOj00D0OlscGwKm6dUlRk0NjFYyxPUEgO1IzEboBMBdxzriPvxObV4o86fZaoh1M7pDagC7xcItXyOmpleLrqmRBOI= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by BY5PR10MB4321.namprd10.prod.outlook.com (2603:10b6:a03:202::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.25; Fri, 1 Apr 2022 13:24:31 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:31 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 6/8] qmp: add QMP commands for virtio/vhost queue-status Date: Fri, 1 Apr 2022 09:23:23 -0400 Message-Id: <1648819405-25696-7-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 822c2a64-512b-486d-3737-08da13e2f4b9 X-MS-TrafficTypeDiagnostic: BY5PR10MB4321: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: KMM9KiciTtbQBf6pwp3oXtn3iTbWcEJWBuyI6cGBv1HImknUmxYFS+1z3u+bwam24WAK7GgYrdG5ktriB6oqn1ilpG1d5nSoo4cspyr6b9a1lvbBePsxaDKei8R66u1aMZeqTIa/qhLzY294TVHmzFyUBWrCL0pVYSv4dPHMcC5KNKY5dOP+gGFzEIwLpxJC3T0SYslxLczWE6eNrzIvNmMBCQIwdUMULCgXdyFSzPF9qmMaqWpPHf6zCzhwobMdUis/fyFU4Zj5QoWQFfG4aobjYZRfYow2ybbwV+0E4qOo112eoyQ7kNT/h3UC8zg9S0I6ceyowIUuajG50+m2zVM++/Dm6/EJE3PjRgJqRs6EjTVC+gI2ulQahXBmHgPGH6aVWQcyNLopix4Y0FFyn1hGbWvF2XZro1I7AENvW3c/QWKoxP+Qp4Q5272JRZOGUf/0jaQf7Cf68ILwB8cGr2RQkFyJDSGq5ieiB/PMQmXenF5+w1y2gQfH/sA62kPT9o6/NbLBcP047xrj47rv2rrJYzY5oE50fIke8pAqfrUgG7u5T6kGyYd4Kk2ZzOcT1eM3M6JnH2Q+hMME+RjsDYo47ITQnBVjzSObFFTQxo82tqIz/x+eR/uJfdjuahYqgKrIWKcTWauDV1DDgeZ/VxtOYW+OS2i1UTsZIo0PBiNmEesrdw0ltw+zkmVlvTlR X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6506007)(30864003)(44832011)(6666004)(5660300002)(6486002)(6512007)(8676002)(52116002)(86362001)(8936002)(508600001)(66946007)(4326008)(66476007)(66556008)(26005)(316002)(7416002)(186003)(6916009)(36756003)(2906002)(38100700002)(38350700002)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wH1Yv/pqMQpEjJknj1maHMBDwUoj5CUQW10gwb+ky9E0wpODEmrZ75fGzuSCpuuu5O9oiH2BrysNsKShzwEhEgSgYdArnrxOimqVlCxZTe04fmBSi/9EqC0i5DpYrJxt7YhoXvzc0+PdOUE7ryrknuCSXclsQwxyyi9KP/FDsuuBANtID9pFnOuebLQ/wfwCMgqUUJx56sBNhFECfMQSVt/E4eJ/tXo3mW1eIaO4+IebqwSCujAmspxQO3JNS4QNQcNfzFAEh4Ww513OwE9QmIPCA9cZqqpFvbSOdvaGrqSekThRv7cSNiDT98kgMUuJMErnohJMl8+JjnQN9//fApr91c3UMiFXyz/7lVJhQ0KblulvP3CfduAYBqOcdxCDByKC9AxDn/VbeJIPuHLztJsh7h05jEt2vYw2hNpo4AYl4U8dgEROm3IQ/z8DsLWEPG8CX1xHUrow8MKuPmFzYWU5682GXFpszi0h2PvLax5qScqwFt6MScMi4TFckasp0nyMX7hux02rA6fIxhqJ1M7ciRBgDNfTMMiKqwYRxXhYGhU7Yfy+mRq6e8jZ08RmkBbcCKZlrCiaKZsFdDbcCmk6o2/qbOOrN1feBnRk6J1IJ0NxyPAlG8b/3yf/HTs3UorTmJCV9ktYpkdMEPhFchaXXtnx+DqCXGmfES3Cfyz73hJgiUrStZTCHLuPh3NltDwvCNOtAQ5wLr6hYZMjKjKBHwTTaSmT/y2C4gZdtufKHA49ePzoWCiIMb7rETJ/+Wx25EeBnx3AAhVvfIQ11O4p7+jfzOF1tZxsVRxVDpvMpZHoWNGEf4PbyLO5CSUGlIqP3jzbNNTtlC4JtbBYL0D3nd1YeKaCU6jw5eedWU2QmDztdAFVM8IZM0kNDid8DrOLh4D6aRYktFdpocv0AH8yvUyvO4n9XiymRwImkilmFMOqlNAZc/cwimII9mF1/c2lSEg9gDwUtMsbKEyR/z0ZY0uM0XeT4Y9zs9SrOQyFXI3eFL9YBVWjPQfJeRuRHv29G9mYWodciPILQnZJd5Hwy0ch0MnrasF8rcca4BOJUS4zaznDmXeRezOQYUg5DK+G7vtdbTQF0osDADaBpSbmmGK8AapMGdhWnTb0X2vF5yvKZ1UjxiZweq79pgEQQfFa4yGNt1w4Uv4gIHWoWf+mV2ceYLvxRUZUKgjp2mQ0EYVsjnSuZqh/Lk/otnrsz6Zm8lQ5HPnLPhOJe246g8XP1RJ/hluRELrRlTqdH9ncSJoczJSFwoQTApFQ1O4Cg5L2ymD/4YSgmxggkzXByeNC/xhwxlE0+epz2ShdWhebGePaH2yRTShATllz8HDERn4A0RNSTjNeZvNZz0LvdnlMp8Xw4omOQEPpDogU56mllshmsNSJJBAyyGV9aBtyZcqkcwiiB1+TrK4uHmb1auavEgLysZC4eIum2rqkixatIErhEukExOA6zrzvE0EEbzCUOEXxRqyN7U77//UwP3BSo1Db/Iiai+ne97uB9sHYqtPtWJNrel3IwpU0wyi9qG9dO4YwBGFWDVRJgsQzk1+F0UUsVEvMtFQAE7QeZnDd5wkNPCkCTzFeh452EDJIUXo/8lTorzsdYij13OdLunn/bKqyu4t/uhHa5Ll3ueM7DGx0uJH+i5DZ82j/hQUYNLMQPyZmJ5+xJvmPlm78FlftjYuNPaoV1eVgThy+Zy2gResLyU89ZlcKlDNhWF55KaG1stqPrg3/HO7qR+RRGY5i2knzIdCN8Rt6saO5YQU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 822c2a64-512b-486d-3737-08da13e2f4b9 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:31.7068 (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: 1Y6c6FaxiMU4ZZJ8DKwD6x00D30S67dYDdUowa59fSCBUgU8sEQOx9nbHRv9CxdrLXoQn5Kc6l6A1+rbEeSIIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4321 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-ORIG-GUID: Q2SQb7A2dC2l2UofqSMVR19QbgVHS648 X-Proofpoint-GUID: Q2SQb7A2dC2l2UofqSMVR19QbgVHS648 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jonah.palmer@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier These new commands show the internal status of a VirtIODevice's VirtQueue and a vhost device's vhost_virtqueue (if active). Signed-off-by: Jonah Palmer --- hw/virtio/virtio-stub.c | 14 +++ hw/virtio/virtio.c | 103 ++++++++++++++++ qapi/virtio.json | 252 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 0b432e8de7..13e5f93652 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -17,3 +17,17 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) { return qmp_virtio_unsupported(errp); } + +VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path, + uint16_t queue, + Error **errp) +{ + return qmp_virtio_unsupported(errp); +} + +VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path, + uint16_t queue, + Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index af376be933..6d718d4fea 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4316,6 +4316,109 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) return status; } +VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path, + uint16_t queue, + Error **errp) +{ + VirtIODevice *vdev; + VirtVhostQueueStatus *status; + + vdev = virtio_device_find(path); + if (vdev == NULL) { + error_setg(errp, "Path %s is not a VirtIODevice", path); + return NULL; + } + + if (!vdev->vhost_started) { + error_setg(errp, "Error: vhost device has not started yet"); + return NULL; + } + + VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev = vdc->get_vhost(vdev); + + if (queue < hdev->vq_index || queue >= hdev->vq_index + hdev->nvqs) { + error_setg(errp, "Invalid vhost virtqueue number %d", queue); + return NULL; + } + + status = g_new0(VirtVhostQueueStatus, 1); + status->name = g_strdup(vdev->name); + status->kick = hdev->vqs[queue].kick; + status->call = hdev->vqs[queue].call; + status->desc = (uintptr_t)hdev->vqs[queue].desc; + status->avail = (uintptr_t)hdev->vqs[queue].avail; + status->used = (uintptr_t)hdev->vqs[queue].used; + status->num = hdev->vqs[queue].num; + status->desc_phys = hdev->vqs[queue].desc_phys; + status->desc_size = hdev->vqs[queue].desc_size; + status->avail_phys = hdev->vqs[queue].avail_phys; + status->avail_size = hdev->vqs[queue].avail_size; + status->used_phys = hdev->vqs[queue].used_phys; + status->used_size = hdev->vqs[queue].used_size; + + return status; +} + +VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path, + uint16_t queue, + Error **errp) +{ + VirtIODevice *vdev; + VirtQueueStatus *status; + + vdev = virtio_device_find(path); + if (vdev == NULL) { + error_setg(errp, "Path %s is not a VirtIODevice", path); + return NULL; + } + + if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) { + error_setg(errp, "Invalid virtqueue number %d", queue); + return NULL; + } + + status = g_new0(VirtQueueStatus, 1); + status->name = g_strdup(vdev->name); + status->queue_index = vdev->vq[queue].queue_index; + status->inuse = vdev->vq[queue].inuse; + status->vring_num = vdev->vq[queue].vring.num; + status->vring_num_default = vdev->vq[queue].vring.num_default; + status->vring_align = vdev->vq[queue].vring.align; + status->vring_desc = vdev->vq[queue].vring.desc; + status->vring_avail = vdev->vq[queue].vring.avail; + status->vring_used = vdev->vq[queue].vring.used; + status->used_idx = vdev->vq[queue].used_idx; + status->signalled_used = vdev->vq[queue].signalled_used; + status->signalled_used_valid = vdev->vq[queue].signalled_used_valid; + + if (vdev->vhost_started) { + VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev = vdc->get_vhost(vdev); + + /* check if vq index exists for vhost as well */ + if (queue >= hdev->vq_index && queue < hdev->vq_index + hdev->nvqs) { + status->has_last_avail_idx = true; + + int vhost_vq_index = + hdev->vhost_ops->vhost_get_vq_index(hdev, queue); + struct vhost_vring_state state = { + .index = vhost_vq_index, + }; + + status->last_avail_idx = + hdev->vhost_ops->vhost_get_vring_base(hdev, &state); + } + } else { + status->has_shadow_avail_idx = true; + status->has_last_avail_idx = true; + status->last_avail_idx = vdev->vq[queue].last_avail_idx; + status->shadow_avail_idx = vdev->vq[queue].shadow_avail_idx; + } + + return status; +} + static const TypeInfo virtio_device_info = { .name = TYPE_VIRTIO_DEVICE, .parent = TYPE_DEVICE, diff --git a/qapi/virtio.json b/qapi/virtio.json index 474a8bd64e..44cc05ceeb 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -404,3 +404,255 @@ 'data': { 'transports': [ 'str' ], '*dev-features': [ 'str' ], '*unknown-dev-features': 'uint64' } } + +## +# @VirtQueueStatus: +# +# Information of a VirtIODevice VirtQueue, including most members of +# the VirtQueue data structure. +# +# @name: Name of the VirtIODevice that uses this VirtQueue +# +# @queue-index: VirtQueue queue_index +# +# @inuse: VirtQueue inuse +# +# @vring-num: VirtQueue vring.num +# +# @vring-num-default: VirtQueue vring.num_default +# +# @vring-align: VirtQueue vring.align +# +# @vring-desc: VirtQueue vring.desc (descriptor area) +# +# @vring-avail: VirtQueue vring.avail (driver area) +# +# @vring-used: VirtQueue vring.used (device area) +# +# @last-avail-idx: VirtQueue last_avail_idx or return of vhost_dev +# vhost_get_vring_base (if vhost active) +# +# @shadow-avail-idx: VirtQueue shadow_avail_idx +# +# @used-idx: VirtQueue used_idx +# +# @signalled-used: VirtQueue signalled_used +# +# @signalled-used-valid: VirtQueue signalled_used_valid flag +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtQueueStatus', + 'data': { 'name': 'str', + 'queue-index': 'uint16', + 'inuse': 'uint32', + 'vring-num': 'uint32', + 'vring-num-default': 'uint32', + 'vring-align': 'uint32', + 'vring-desc': 'uint64', + 'vring-avail': 'uint64', + 'vring-used': 'uint64', + '*last-avail-idx': 'uint16', + '*shadow-avail-idx': 'uint16', + 'used-idx': 'uint16', + 'signalled-used': 'uint16', + 'signalled-used-valid': 'bool' } } + +## +# @x-query-virtio-queue-status: +# +# Return the status of a given VirtIODevice's VirtQueue +# +# @path: VirtIODevice canonical QOM path +# +# @queue: VirtQueue index to examine +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtQueueStatus of the VirtQueue +# +# Notes: last_avail_idx will not be displayed in the case where +# the selected VirtIODevice has a running vhost device and +# the VirtIODevice VirtQueue index (queue) does not exist for +# the corresponding vhost device vhost_virtqueue. Also, +# shadow_avail_idx will not be displayed in the case where +# the selected VirtIODevice has a running vhost device. +# +# Since: 7.0 +# +# Examples: +# +# 1. Get VirtQueueStatus for virtio-vsock (vhost-vsock running) +# +# -> { "execute": "x-query-virtio-queue-status", +# "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend", +# "queue": 1 } +# } +# <- { "return": { +# "signalled-used": 0, +# "inuse": 0, +# "vring-align": 4096, +# "vring-desc": 5217370112, +# "signalled-used-valid": false, +# "vring-num-default": 128, +# "vring-avail": 5217372160, +# "queue-index": 1, +# "last-avail-idx": 0, +# "vring-used": 5217372480, +# "used-idx": 0, +# "name": "vhost-vsock", +# "vring-num": 128 } +# } +# +# 2. Get VirtQueueStatus for virtio-serial (no vhost) +# +# -> { "execute": "x-query-virtio-queue-status", +# "arguments": { "path": "/machine/peripheral-anon/device[0]/virtio-backend", +# "queue": 20 } +# } +# <- { "return": { +# "signalled-used": 0, +# "inuse": 0, +# "vring-align": 4096, +# "vring-desc": 5182074880, +# "signalled-used-valid": false, +# "vring-num-default": 128, +# "vring-avail": 5182076928, +# "queue-index": 20, +# "last-avail-idx": 0, +# "vring-used": 5182077248, +# "used-idx": 0, +# "name": "virtio-serial", +# "shadow-avail-idx": 0, +# "vring-num": 128 } +# } +# +## + +{ 'command': 'x-query-virtio-queue-status', + 'data': { 'path': 'str', 'queue': 'uint16' }, + 'returns': 'VirtQueueStatus', + 'features': [ 'unstable' ] } + +## +# @VirtVhostQueueStatus: +# +# Information of a vhost device's vhost_virtqueue, including most +# members of the vhost_dev vhost_virtqueue data structure. +# +# @name: Name of the VirtIODevice that uses this vhost_virtqueue +# +# @kick: vhost_virtqueue kick +# +# @call: vhost_virtqueue call +# +# @desc: vhost_virtqueue desc +# +# @avail: vhost_virtqueue avail +# +# @used: vhost_virtqueue used +# +# @num: vhost_virtqueue num +# +# @desc-phys: vhost_virtqueue desc_phys (descriptor area phys. addr.) +# +# @desc-size: vhost_virtqueue desc_size +# +# @avail-phys: vhost_virtqueue avail_phys (driver area phys. addr.) +# +# @avail-size: vhost_virtqueue avail_size +# +# @used-phys: vhost_virtqueue used_phys (device area phys. addr.) +# +# @used-size: vhost_virtqueue used_size +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtVhostQueueStatus', + 'data': { 'name': 'str', + 'kick': 'int', + 'call': 'int', + 'desc': 'uint64', + 'avail': 'uint64', + 'used': 'uint64', + 'num': 'int', + 'desc-phys': 'uint64', + 'desc-size': 'uint32', + 'avail-phys': 'uint64', + 'avail-size': 'uint32', + 'used-phys': 'uint64', + 'used-size': 'uint32' } } + +## +# @x-query-virtio-vhost-queue-status: +# +# Return information of a given vhost device's vhost_virtqueue +# +# @path: VirtIODevice canonical QOM path +# +# @queue: vhost_virtqueue index to examine +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtVhostQueueStatus of the vhost_virtqueue +# +# Since: 7.0 +# +# Examples: +# +# 1. Get vhost_virtqueue status for vhost-crypto +# +# -> { "execute": "x-query-virtio-vhost-queue-status", +# "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend", +# "queue": 0 } +# } +# <- { "return": { +# "avail-phys": 5216124928, +# "used-phys": 5216127040, +# "avail-size": 2054, +# "desc-size": 16384, +# "used-size": 8198, +# "desc": 140141447430144, +# "num": 1024, +# "name": "virtio-crypto", +# "call": 0, +# "avail": 140141447446528, +# "desc-phys": 5216108544, +# "used": 140141447448640, +# "kick": 0 } +# } +# +# 2. Get vhost_virtqueue status for vhost-vsock +# +# -> { "execute": "x-query-virtio-vhost-queue-status", +# "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend", +# "queue": 0 } +# } +# <- { "return": { +# "avail-phys": 5182261248, +# "used-phys": 5182261568, +# "avail-size": 262, +# "desc-size": 2048, +# "used-size": 1030, +# "desc": 140141413580800, +# "num": 128, +# "name": "vhost-vsock", +# "call": 0, +# "avail": 140141413582848, +# "desc-phys": 5182259200, +# "used": 140141413583168, +# "kick": 0 } +# } +# +## + +{ 'command': 'x-query-virtio-vhost-queue-status', + 'data': { 'path': 'str', 'queue': 'uint16' }, + 'returns': 'VirtVhostQueueStatus', + 'features': [ 'unstable' ] } From patchwork Fri Apr 1 13:23:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=u3/dfqbs; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=S0XLO1tC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLnh4PCDz9sXM for ; Sat, 2 Apr 2022 00:37:28 +1100 (AEDT) Received: from localhost ([::1]:49704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHSw-0003d7-LX for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:37:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGl-0002Up-Cx; Fri, 01 Apr 2022 09:24:54 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:48788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGj-0007Dy-8F; Fri, 01 Apr 2022 09:24:51 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CipW9031586; Fri, 1 Apr 2022 13:24:38 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 : mime-version; s=corp-2021-07-09; bh=Nw2JrRHPG7GtNUzSHXah9nLyMRWB9ngsf49KU+nJ80g=; b=u3/dfqbsoVgE/xCQp6HAMECHflEPXmi3v/LfecWgZn9Bi1bWC5OtdfmZnkmu/i4d/0Et 15RbOXBGFnfrM3ZkIGRbXBACuP4OWc0qC3f643esOIO+DOr0UkdN0jvObYTqdyJlH63l heFgtDrswmkoGWrN4uDuEPGy0GMp6GjCW86v7u/Fc9zkWwzOfBtMJmaa/ZTLADqyHVl/ MuuseACoMdQnMHLzOFd3dBX5IzEwHe0P+raMhdaMacxajYGQRyddfR24d+lSeAhB989M dcAd37GoDKjageqSA0e+r/YF1e0jir2DNvHw8W37/IIrVjUDd/l3htsfACZ7UnmIgAtO Ig== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1tes6yh7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:38 +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 231DGbeP024187; Fri, 1 Apr 2022 13:24:37 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s95t9x8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OvHwelOHC7Gu0YVxLCDrmGuzC8h86kXWrAOEkIVME8sgz+fGFXkiClszqqXvGGWbTyxvzhy9/8lQuP0/t9Ro8Umf4nBd7je0JDBSmRxz37cNBUfPZm7n5urGuordmHR2ZDS/YvYEcOR/mUu86Ok8JWAT3RppjfdJRYt1elPkYO2dfKF5Ceb7EDiFXvaiRbW5bJuPW3OfD7wCfskJwgdCNSBslgfPvPSKlYbjEcyHql9P23VCo0J+CU19Xo0xC7WPs+lFEw2w2jf60IbAtfqlXhW2i6byGgofZIG+lXwlr7tMhAvPiXaEySRvVmG5TvefqENwFXkI+VHnD5v+G53Dpg== 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=Nw2JrRHPG7GtNUzSHXah9nLyMRWB9ngsf49KU+nJ80g=; b=a2yv1R1UYP2BC7MaY6Nw94ea+NO+dBnNz/kl9tFX3WOxd22/1pNLE+okC0wCO1gee9RHzKCXMsxgkUJyiDZToVpnfog4rtp+b+iaTp/3Yktv554ghsrXLUwhJZqJIGbFmd883WkJw8iMyS7rRlCDmWfsI0E07oejny5RyUH/D1WJplQMbCbI0vsrxFvd6Xr4f/1rTWw2IgKkqSkXc+vOLB7BX7UAhxqBlf46m68HquqGqYgFH9tbdt+wlXY4jg9eOmo7hY4J1m9cfwpXgoRmmmxh9pUOvG9zHjWtZ3a8MWiezDvo4IRIGz88nHRRAeAfNZmrvHaOYSS3VFFAxxBO9Q== 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=Nw2JrRHPG7GtNUzSHXah9nLyMRWB9ngsf49KU+nJ80g=; b=S0XLO1tCFksoyfLBx2+Apg7fDUGYRafirxIBjl8FU0+Ww81aacdNvxomIvS3/57mrv982QCErxRINFBp6XI7h0iBn9lTE2qJ0044u9N0+ZCpwmW/hVlYQmHCCjPPSPIpF8DGCnhhgxPWL5IFoOqrC6UdxLzvUJ9U5NU8yTZ6h3c= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by BY5PR10MB4321.namprd10.prod.outlook.com (2603:10b6:a03:202::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.25; Fri, 1 Apr 2022 13:24:35 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:35 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 7/8] qmp: add QMP command x-query-virtio-queue-element Date: Fri, 1 Apr 2022 09:23:24 -0400 Message-Id: <1648819405-25696-8-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 62498a39-9747-45ad-8412-08da13e2f6f5 X-MS-TrafficTypeDiagnostic: BY5PR10MB4321: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: 6rVvZcT0GKC4GC/LyPutQ+ZEoFngEXj2p42C/hBhIN6tQ4wueHkslmYgDx4EshWYaWH8Lq5B8TPp/Vg301czyJ+2KBV6hEFQNnUhjyLPvgdYLnlMN9GqNIXWtL7R1D2679GfsRc2jLsgHB3w5VJekrMKhvV6PjP7lERBW2/j3iDqAwZEC4a7z+hI/IsokDjy6PdIFOQdKIBcIMQ3iHcj6pxllM6zddHGGfEfpRzPKaLNCOoXl6nlLeCyuKWR6bTSZW2tExmCtWGh5HZrccPq+pI7RKUf/i18q2UxEwp6DTQwt0cX5+6VCIwE8iyqKG+DgtFWBJc06Enwbf220O17LAABnD5E3g9QCyquO4CbznuPzkke+BkIZM9TZiJvPyIxl7NdLv1ijBxRwHhNeD74KKAB9ZIHuWp7ou2RbnFt0jPrsVTyvSR8jEvaD8SlEXYooL1isVEeKrmaIaNdiSRIk3/7zcmVg5AnEf1MqXpnIq7KwWB74KGKruk0DbTtl47VA7N3UPg/QWFXneKEVTeGhp6uhQuZS7MitDv1Ve9DbAvUo/gtfo+lJQKadRz0dOEemj2rVbZkFWrShwY69a/jQcXMwiLT2zOTZCqXZZ8JunI1H3pwxQOBIp7jy2g9J8QpMlAY730Fjd8Lv4EvRX5ABkZ//G8u0fw4ELW4Q2SG8CuybkD7DBcsiW3qHs6Q1G3IZ6+ZyblKhfxkSeZneP/pug== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6506007)(44832011)(6666004)(5660300002)(6486002)(6512007)(8676002)(52116002)(86362001)(8936002)(508600001)(66946007)(4326008)(66476007)(66556008)(83380400001)(26005)(316002)(7416002)(186003)(6916009)(36756003)(2906002)(38100700002)(38350700002)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O0EIFTMxoopbNncOz1flG6ntUwuimvyqQ18tiTgfmFSvlWJSB6s6aagWRvFXMgjEB/cGJQ3o/3O/kFaNAbPhR+RJAJ0KN33fD+a3QBmpLOB0nvL1lu+/b2QfeAYEkqrLouPgi6Nqckeqkz415HI5key2ugp6P/9NqJwxn3UfIFxP2v2mfOk3n1zht8QVGLqR75jrwfQbrfmAY4ZfnjZjF7j3U0qcKJ15b8jsLz4EYdnZCMVxSx6Li0+YFrkqrnd7xehXh/M2VfsNnGzT9sfMf+AxTiIhspCQzlbAhNnk5mejF5672l5ACsyMAycMfbuzm4o4Yv7AHYew5vGskMdEAusHURKMQ2Jmay+gFy5gUKyVFS1szalSF3c4PxeMqiyGO0W1cVEyDdZ6GMmOpOtg7w8M652UUxJngaWcaprvCKXGOpbO4WK/SWqxmb86R0erE0H9JpEYUpRPWBQG5m5N6UYB+bPIkzYU8D/6mBxLQErmFEMly+0dTbXOQUj1YC8fzyg/enqNQ24jQ1CQ8JLhK24210aNg3UmMADu+ojfOj+UGdrN0h1ufs/V5NozsmS6ZXcHa/1oSGLpiChgBKQrKrCOEbewQmpfnGyFWOoWs2F8eoy8gRICcfG/nM6kts3gOx+OESsvrpuYWGtcDYmnmpkeTYZRF4ATDL52B0ftXhAF3kr7kHH3aW09O8xYf1uzyAw/HHlYT4QQ7BNyeLUVCzCYwIi7t+aRoHqiEon8qiG39ozqdwK+sVjhEHgcuuXIvBdACeXNBlZEly5xnVFWTd6OzLxvkFq5YZloWGkh7DVOulPGHFRWrGKuA7+OmGjA0QfLcui3uT+A6EGyfG2tIKF+iCp4efzEKGlA7aRC5lZmxjryMwtoR74wN8otnAWTwQeV6dtTTUIGd+z6ThirHvK2JRKKuqtHWq+QTmDhSvhAY1aLFnaCpaw6XXTNJOrYDplRA739b+7RccyKz9Gsf4H41ow4pVSNYldkjOPu8V+N/b+rkzPZk6mDRT4EwDITYxAkiIsJ8W1+yB7JO0a6R/e2L9Ho/lNTFekcL3E5B/WsKd5sJzehF/++hN++RLTGtJ1rl9WUTIzwwE9BgdhjU1HCI27VXCalZ/zM+d1coeubF6FZRk4+fR4OkS+C7bat5sgQAWkdBiQA15W57jleFp3t0MS9yOtDjqLwSwqyQ6D+neAbM1TMYJNJdJqO3AoegEv8AY7/cIPVxSPeps95ykMjGADgA5BBEZO6h8VB3MRqQfTBKgWY3E+GwyCpcjVRrWJjRh0/3rfqGPpXSS8mqbnAsVcObcWghUS3CcpalVkUdYkNoJYOjNTsXaxrerRXUSwEOzJ1K+7BRzmSmR6yOqKT8xi3q+a5nFzdMR7o3R5+SoxuvphDrZZrI3UexcdWwhJ0QiKKFH6qrizElu+K//+Ud7mzoPbyCIrNF9VVTFoC2uzoW+HEjHTP+ZqbJ5gOQ64Q3QA86zwxcuBgM878gdaptKA/swnHRMEBo5+NzrihcypS/mujXgwwR+irulmF3cBggDXQLwmUX96sFNAUMOEoOhvzoLRYTATRrha6ruUFC7AWUZOIWgbwGfM/HAjfTB+LcdTayJcmMS+ALjZAL2iKE5vg1uhk0pGVZEvxZdbgOnLE6q++FXsySf1D6IgdznZbE6GI1iLPw1fz/DlG+2Kp3nr6+iKT9JnmYh8bueIzPAbEDIPvA/O5It+OKli4df+Eb51AM4ZZnCi4Dct7BVp/LMtJ34+H2mgiu08xtUc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62498a39-9747-45ad-8412-08da13e2f6f5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:35.4573 (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: TWbsnRGBwezR2BMhGGu0vsOh7sTB49Y2jEmowTKgHu7hUhhhdwlD4RYNMA2nwVJZspJX/Xfit3FhET1LdgRXJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4321 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-GUID: 4mzJHGcJaO9d3do-8C83_wNyNPZxMi8L X-Proofpoint-ORIG-GUID: 4mzJHGcJaO9d3do-8C83_wNyNPZxMi8L Received-SPF: pass client-ip=205.220.177.32; envelope-from=jonah.palmer@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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier This new command shows the information of a VirtQueue element. [Note: Up until v10 of this patch series, virtio.json had many (15+) enums defined (e.g. decoded device features, statuses, etc.). In v10 most of these enums were removed and replaced with string literals. By doing this we get (1) simpler schema, (2) smaller generated code, and (3) less maintenance burden for when new things are added (e.g. devices, device features, etc.).] Signed-off-by: Jonah Palmer --- hw/virtio/virtio-stub.c | 9 ++ hw/virtio/virtio.c | 154 +++++++++++++++++++++++++++++++++ qapi/virtio.json | 183 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 346 insertions(+) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 13e5f93652..7ddb22cc5e 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -31,3 +31,12 @@ VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path, { return qmp_virtio_unsupported(errp); } + +VirtioQueueElement *qmp_x_query_virtio_queue_element(const char *path, + uint16_t queue, + bool has_index, + uint16_t index, + Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6d718d4fea..8db6b435aa 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -489,6 +489,19 @@ static inline void vring_used_write(VirtQueue *vq, VRingUsedElem *uelem, address_space_cache_invalidate(&caches->used, pa, sizeof(VRingUsedElem)); } +/* Called within rcu_read_lock(). */ +static inline uint16_t vring_used_flags(VirtQueue *vq) +{ + VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); + hwaddr pa = offsetof(VRingUsed, flags); + + if (!caches) { + return 0; + } + + return virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); +} + /* Called within rcu_read_lock(). */ static uint16_t vring_used_idx(VirtQueue *vq) { @@ -4419,6 +4432,147 @@ VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path, return status; } +static strList *qmp_decode_vring_desc_flags(uint16_t flags) +{ + strList *list = NULL; + strList *node; + int i; + + struct { + uint16_t flag; + const char *value; + } map[] = { + { VRING_DESC_F_NEXT, "next" }, + { VRING_DESC_F_WRITE, "write" }, + { VRING_DESC_F_INDIRECT, "indirect" }, + { 1 << VRING_PACKED_DESC_F_AVAIL, "avail" }, + { 1 << VRING_PACKED_DESC_F_USED, "used" }, + { 0, "" } + }; + + for (i = 0; map[i].flag; i++) { + if ((map[i].flag & flags) == 0) { + continue; + } + node = g_malloc0(sizeof(strList)); + node->value = g_strdup(map[i].value); + node->next = list; + list = node; + } + + return list; +} + +VirtioQueueElement *qmp_x_query_virtio_queue_element(const char *path, + uint16_t queue, + bool has_index, + uint16_t index, + Error **errp) +{ + VirtIODevice *vdev; + VirtQueue *vq; + VirtioQueueElement *element = NULL; + + vdev = virtio_device_find(path); + if (vdev == NULL) { + error_setg(errp, "Path %s is not a VirtIO device", path); + return NULL; + } + + if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) { + error_setg(errp, "Invalid virtqueue number %d", queue); + return NULL; + } + vq = &vdev->vq[queue]; + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + error_setg(errp, "Packed ring not supported"); + return NULL; + } else { + unsigned int head, i, max; + VRingMemoryRegionCaches *caches; + MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID; + MemoryRegionCache *desc_cache; + VRingDesc desc; + VirtioRingDescList *list = NULL; + VirtioRingDescList *node; + int rc; int ndescs; + + RCU_READ_LOCK_GUARD(); + + max = vq->vring.num; + + if (!has_index) { + head = vring_avail_ring(vq, vq->last_avail_idx % vq->vring.num); + } else { + head = vring_avail_ring(vq, index % vq->vring.num); + } + i = head; + + caches = vring_get_region_caches(vq); + if (!caches) { + error_setg(errp, "Region caches not initialized"); + return NULL; + } + if (caches->desc.len < max * sizeof(VRingDesc)) { + error_setg(errp, "Cannot map descriptor ring"); + return NULL; + } + + desc_cache = &caches->desc; + vring_split_desc_read(vdev, &desc, desc_cache, i); + if (desc.flags & VRING_DESC_F_INDIRECT) { + int64_t len; + len = address_space_cache_init(&indirect_desc_cache, vdev->dma_as, + desc.addr, desc.len, false); + desc_cache = &indirect_desc_cache; + if (len < desc.len) { + error_setg(errp, "Cannot map indirect buffer"); + goto done; + } + + max = desc.len / sizeof(VRingDesc); + i = 0; + vring_split_desc_read(vdev, &desc, desc_cache, i); + } + + element = g_new0(VirtioQueueElement, 1); + element->avail = g_new0(VirtioRingAvail, 1); + element->used = g_new0(VirtioRingUsed, 1); + element->name = g_strdup(vdev->name); + element->index = head; + element->avail->flags = vring_avail_flags(vq); + element->avail->idx = vring_avail_idx(vq); + element->avail->ring = head; + element->used->flags = vring_used_flags(vq); + element->used->idx = vring_used_idx(vq); + ndescs = 0; + + do { + /* A buggy driver may produce an infinite loop */ + if (ndescs >= max) { + break; + } + node = g_new0(VirtioRingDescList, 1); + node->value = g_new0(VirtioRingDesc, 1); + node->value->addr = desc.addr; + node->value->len = desc.len; + node->value->flags = qmp_decode_vring_desc_flags(desc.flags); + node->next = list; + list = node; + + ndescs++; + rc = virtqueue_split_read_next_desc(vdev, &desc, desc_cache, + max, &i); + } while (rc == VIRTQUEUE_READ_DESC_MORE); + element->descs = list; +done: + address_space_cache_destroy(&indirect_desc_cache); + } + + return element; +} + static const TypeInfo virtio_device_info = { .name = TYPE_VIRTIO_DEVICE, .parent = TYPE_DEVICE, diff --git a/qapi/virtio.json b/qapi/virtio.json index 44cc05ceeb..99b9064902 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -656,3 +656,186 @@ 'data': { 'path': 'str', 'queue': 'uint16' }, 'returns': 'VirtVhostQueueStatus', 'features': [ 'unstable' ] } + +## +# @VirtioRingDesc: +# +# Information regarding the vring descriptor area +# +# @addr: Guest physical address of the descriptor area +# +# @len: Length of the descriptor area +# +# @flags: List of descriptor flags +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtioRingDesc', + 'data': { 'addr': 'uint64', + 'len': 'uint32', + 'flags': [ 'str' ] } } + +## +# @VirtioRingAvail: +# +# Information regarding the avail vring (a.k.a. driver area) +# +# @flags: VRingAvail flags +# +# @idx: VRingAvail index +# +# @ring: VRingAvail ring[] entry at provided index +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtioRingAvail', + 'data': { 'flags': 'uint16', + 'idx': 'uint16', + 'ring': 'uint16' } } + +## +# @VirtioRingUsed: +# +# Information regarding the used vring (a.k.a. device area) +# +# @flags: VRingUsed flags +# +# @idx: VRingUsed index +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtioRingUsed', + 'data': { 'flags': 'uint16', + 'idx': 'uint16' } } + +## +# @VirtioQueueElement: +# +# Information regarding a VirtQueue's VirtQueueElement including +# descriptor, driver, and device areas +# +# @name: Name of the VirtIODevice that uses this VirtQueue +# +# @index: Index of the element in the queue +# +# @descs: List of descriptors (VirtioRingDesc) +# +# @avail: VRingAvail info +# +# @used: VRingUsed info +# +# Since: 7.0 +# +## + +{ 'struct': 'VirtioQueueElement', + 'data': { 'name': 'str', + 'index': 'uint32', + 'descs': [ 'VirtioRingDesc' ], + 'avail': 'VirtioRingAvail', + 'used': 'VirtioRingUsed' } } + +## +# @x-query-virtio-queue-element: +# +# Return the information about a VirtQueue's VirtQueueElement +# +# @path: VirtIODevice canonical QOM path +# +# @queue: VirtQueue index to examine +# +# @index: Index of the element in the queue +# (default: head of the queue) +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtioQueueElement information +# +# Since: 7.0 +# +# Examples: +# +# 1. Introspect on virtio-net's VirtQueue 0 at index 5 +# +# -> { "execute": "x-query-virtio-queue-element", +# "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend", +# "queue": 0, +# "index": 5 } +# } +# <- { "return": { +# "index": 5, +# "name": "virtio-net", +# "descs": [ +# { "flags": ["write"], "len": 1536, "addr": 5257305600 } +# ], +# "avail": { +# "idx": 256, +# "flags": 0, +# "ring": 5 +# }, +# "used": { +# "idx": 13, +# "flags": 0 +# }, +# } +# +# 2. Introspect on virtio-crypto's VirtQueue 1 at head +# +# -> { "execute": "x-query-virtio-queue-element", +# "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend", +# "queue": 1 } +# } +# <- { "return": { +# "index": 0, +# "name": "virtio-crypto", +# "descs": [ +# { "flags": [], "len": 0, "addr": 8080268923184214134 } +# ], +# "avail": { +# "idx": 280, +# "flags": 0, +# "ring": 0 +# }, +# "used": { +# "idx": 280, +# "flags": 0 +# } +# } +# +# 3. Introspect on virtio-scsi's VirtQueue 2 at head +# +# -> { "execute": "x-query-virtio-queue-element", +# "arguments": { "path": "/machine/peripheral-anon/device[2]/virtio-backend", +# "queue": 2 } +# } +# <- { "return": { +# "index": 19, +# "name": "virtio-scsi", +# "descs": [ +# { "flags": ["used", "indirect", "write"], "len": 4099327944, +# "addr": 12055409292258155293 } +# ], +# "avail": { +# "idx": 1147, +# "flags": 0, +# "ring": 19 +# }, +# "used": { +# "idx": 280, +# "flags": 0 +# } +# } +# +## + +{ 'command': 'x-query-virtio-queue-element', + 'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' }, + 'returns': 'VirtioQueueElement', + 'features': [ 'unstable' ] } From patchwork Fri Apr 1 13:23:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1612233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2021-07-09 header.b=G6krgYzc; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=CXEsuBoy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KVLyD3gNPz9sXM for ; Sat, 2 Apr 2022 00:44:52 +1100 (AEDT) Received: from localhost ([::1]:39210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naHa6-0007v7-I0 for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2022 09:44:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGt-0002bK-U4; Fri, 01 Apr 2022 09:25:01 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:40522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naHGq-0007EV-A5; Fri, 01 Apr 2022 09:24:58 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231CmE1K026804; Fri, 1 Apr 2022 13:24:43 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 : mime-version; s=corp-2021-07-09; bh=g3o/0osTw/k1xjgw8ftcqt+LcPq6qcqdhBjt4DQe37o=; b=G6krgYzcaSoG7XG1S63KQ3+MgYP4ky1XTntphezRJSvFKEwb/J4jlKPwUjhVNdoBPV7H WEGdxkeZv9NpnKZSrDmomnNZAfrbxrNjxyzCzhEklwfItn5jQYU6ZJQ0gK0vK4Is4Cmy 202ZOur2ff9ID4vgbVl0zUUbxcHPRvFUA91Xl4LX5rhYnUH1demOBpUKSPjPbXpsL3VI cpYxMf37bCVIkZmaKUDKXKzXLhxwUEaPMb5TpcW4iKi7MPinblTAijSH70imjX0w6CpA ZndcQzrAW0KavasjEt9bNAmswEe+xsRfixPgkFIwLzeEz+oM/B3I6a370FllhjSJFK9T MQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1tqbesg2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:43 +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 231DHP3t011113; Fri, 1 Apr 2022 13:24:42 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2108.outbound.protection.outlook.com [104.47.70.108]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f1s96j87r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 13:24:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eZDtsFXgsVt0lldrxN7JoOz+fDSFd2xdfMoewLibWWnGzAlpwLYN21bTuSOvxeZ6gKIlYZIaL0nc7Zt1pQIumlCq85j2mPz8mnhau7SelPPprznD1ARbLr5tQ0eXqFICAej4jR1dxJZxacY4G0Sr0I9OfzoYT6QqruFzR50TAcuHzdwpMoSpxolf8a0wslRTsj4QOHeMQiIsklPiz6s+ZmjWJc1DIr/FHHYAFbcrT7Fgs71jgK+O3N7mX3vrYx8kLA1gUNqFObW1BlwJeTTbxe+3QclzGzKQNV6vmoqp6JmFo69ANF6xTTFJTsgcYrbsqRe6EJq/Hu5hLLv8dza4QA== 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=g3o/0osTw/k1xjgw8ftcqt+LcPq6qcqdhBjt4DQe37o=; b=l5LOJP45+GEvC3outxUiLg3BEJtmSGP9t2RP4NtlGuQGj6ZHP900GYgvZT7AZPyi/n/Xt0BlY0HL28tfxRVw1p+6RhVaLuADb0tyiTF5yiYC0wCp2sqkhWt5wHFnDPSryizempdhbQ1eAaN17pxHauop6uC3B2ZbYusoAHURbpInVM1xaAdfqjlKKFMnWTH5iKv5pZ28k87DU0Gdgn3ZEr2sZj2iw5nVAeutC0DQ8wcXNSh6hv6oTHmwvAu+q/tVKpTIZwvfTs3kuCdMDoSO0rXKlPJGjUTsMPnw3ZjMvUwEHBUxGZV6WIoUD0W6isU+q3pMFyrDEAVnJHCGBg7reA== 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=g3o/0osTw/k1xjgw8ftcqt+LcPq6qcqdhBjt4DQe37o=; b=CXEsuBoy+nEzEHwt+HIc8QwELFCfkfN5kAheinjdlXU9saByqtYNUCFPR1lR5Jl6Q7h0z0dgHTaK/TiRnYsUSw6ah0eWgm2j8ISYCJk2KuoVjdXayrb0ni2n5iC+hPQPnN9Q56vpwzdobo1hdL8bf0iDqTFyLtex7fIXQUxs+Gk= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by PH0PR10MB4517.namprd10.prod.outlook.com (2603:10b6:510:36::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.19; Fri, 1 Apr 2022 13:24:40 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::a2:4f33:4600:80ae%2]) with mapi id 15.20.5123.025; Fri, 1 Apr 2022 13:24:39 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v14 8/8] hmp: add virtio commands Date: Fri, 1 Apr 2022 09:23:25 -0400 Message-Id: <1648819405-25696-9-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> References: <1648819405-25696-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e413167d-4ae2-4d73-f2b7-08da13e2f99a X-MS-TrafficTypeDiagnostic: PH0PR10MB4517: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: dbmxpna7JPKisHcmh/nYLxbrBxAR2gmko7o+7vyQxlR6y4lylsDPzOTB0W1n3TWcgf9scc21/fG2t/ttMb/4CYWzg93UFMsSFZqegmNfg8Sc6IZSRZSce2ojgQOCtSPHugYMSzgXlt1m6Jhc28NgN0nSpi6kZmXdBZ+k4BqLKlv/e+OyFTgg/X86yT7mH3MI3Tw1J0cR/brfzHljxInPVk7dx2JwyqsX3XdWxG8vTRkEGy0nu2y3JKHdYl8H7P2jZXxhM81MMnNKO2XYqeMBofy3VAI1RtJD9ZKsBU7uRKcWcZorLseC1GEknQuBIIyGf797J/Ntz6N6xJ4DyMY5tiDHzrblQlEbd4t+joqe7X04GmP+a5HXMzYaifMxeuR6OajM6jYUnNjidq9wbWpu6miNzy7/WCc2v9Gwrb2ztvcFEqAI+1tHfv1V0muTebdQrI0irxbrzEhpR7HLOTgVQkuvj2Gkdjsw/fNjnAVgXB1AokvtokGqmz699qx95CXCrzV3LNU0aHNiAVgEYZ1Wr9Q6seGtksm7pSckkloYiHmCGXGc5dMBXdxA3LnamTQdMWY3Srdj/V5Oqk6niQIBT5ALFJsHEWssT/nAlLhMC4QY3WykkD35VVaMSlljAWhCQBlnPF8RYCGa10E+cPHtmyKDhm4UKH5ACBqug9Y1uUCj+jXfVLJAPq87qO6tXnWpZOQGH/wSr6h4Rxn0OTAYJQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB4664.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(52116002)(186003)(26005)(86362001)(6506007)(2616005)(38350700002)(38100700002)(6512007)(8936002)(83380400001)(4326008)(6486002)(2906002)(36756003)(7416002)(30864003)(66556008)(66476007)(6666004)(5660300002)(66946007)(44832011)(6916009)(508600001)(8676002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fUp0P8V5gnorKwT9pWK9501jQrJtuFovmFPLyd4RocujeCdp253P2rh/2Yl2o5QjgRant+PLehzU9wRUyvLRQaFZ2t93UhQiIfK+g0/Z1s0NuqtwmoMzDqcc/Ua24HMBst1UF8UNXjteFYUAUVT5VEQdYi4SqU/WjkSs0qHO4edxOlqCjMA4LaYHy/u5VGl4909i8OWyMpO/XoDap5dPaF2Tbh3l712JH0ykXyN4CGAPjWxXJ3xtuZlElWy/1wUK8lfswHVKHaUpnJ6HnqNcb6V1X6ildEl8YvgtlRc3DzplhjIuuIPOuMzR7iS7on7bJouM1CrU1dc1V2cXbKPGS2lgTCeqjP1mGQZlq/HfH3iG+2W2uiUAJi7BPbOAW7Vyp8YWa10+X4ebvDEGyatU7GdHcQ5//AfI0nK5DSGFReC9SdE4KtriPEosECPSyInYVBBw+7xBcf/hx5YSL2YM1ygz/MqQ9sQVE//a0slglGuqFiJfqV9P0taITuWg3DC6ovalCcPtkEMY4yT4zAjymHwPH2B0Ab4A92Pcs3Yyuki/Ot7LQaTV7bWDriWw22b3kzm9G/wsbreSM+vmswjpTpPIMz5ylJqP+j3H7kIjkq9wF5QP0PGxQnJI3+4537O+iRJkXCoKRWUDqPe7BWQiggOUcHzRZm+1igSOxAaF7jPmmcIcGnd7AOs8kfA7Bm3peR/0tzbNYEYSSSzJ1sJYQlAPhWjnm31uMI6A8iaa1QOsJHEEZrp4sz8ndM5q5Hfl4iJRY6AhkVfAzjSDKByf8MWfYMn0ysTFuoYIoGG6CBvn4CURK+jX7YHlUCLJikmO3/976G7rF3folq3mq9Kd3b2RCt2iEgkvbwed9f7qCd10AeQjmCTB9AygX8onw23GEFc0LflR3xaPrp7jb1IryoZx3g8Gu38u0p2u3Ukl9eaUWx6xOXJ07pqjhKMfns4EW7ePK9EzfH1kbEVfd/QDzolAATaJoj6h54cI1bb/x2eQRLBQjdXSSPW9OaKaIMZBZTeRIVl3V7Z18n2+nqOKyj3yHbhblIhYWuYIyaYS82APd8zWjtrET3OA5XQ08o6Bb59CKNSh+drOvTUoUQzq0Z0XF9QaC10XxkoU0iC6s23qvaOXRQc977DQIeWx88EPrYCZbLL7kxpOZhtYBUOAXgC+MSj8WL9YvYQxjngEg7/fOrv8iNXB4/gHXQyLOYf0xaFJdWsQ8ZqRjNc7pSKx7wXu6tPsQUFAbSx0+ZS+1nPkqtzbPAO7YF5oTVXqyok0LgqEbQypvDmzKQYpVilRyEeWjXfNhT50K3yf2JfxfquHayH9W3YOR6Q0GZ5ILEX2hZUCawsmGfTOGbqkBL2Jeu4HTg7BbSuRwDut8a6GCLJQu/Ih/L7HK6bb4/2Dy3IefCckNzasPwFTggnOoVYdOaRTXLEKbP0JRKr7qI+YDVCnCHXJY02O0Nc485r4XoXTNhh2NI+miKw10FybJRdJPXCQfsTj5ewIUZbC1Ybka//YFwoJRWkvm6a91fSf/PVQtl00HFXq3x3GQybk2UGO+/nJKr4+uQvV1PAeLOnCFA/RMZLbSmss4XzwxMolFZtp2Da4PJbtubeZkRBIbFBauHh5PsNSNg3SSSZjqm5aAMxRkK3y7VOY54Ulct75UTsKh68Nj6qgLfqiRZpqzbJndT6blsbJxXNxCGvyUYfxkyXno/cAexMBqkyqTw+9v93wuOynibj8CSc5nf3TKJUQrACJa3L49Ea5UpVNRxA0u8E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e413167d-4ae2-4d73-f2b7-08da13e2f99a X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:24:39.8970 (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: HRDomFLvb/noWzRNO7WWdHXIejTrqs6eni80ZAJ83NklL9e81v1QLr9m6/zzMeud9+WqNiI/p+kps470SOkayQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4517 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_04:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010062 X-Proofpoint-GUID: j0f3yPcar8EOoti83sShqrznlACwkDA5 X-Proofpoint-ORIG-GUID: j0f3yPcar8EOoti83sShqrznlACwkDA5 Received-SPF: pass client-ip=205.220.165.32; envelope-from=jonah.palmer@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com, si-wei.liu@oracle.com, joao.m.martins@oracle.com, eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com, armbru@redhat.com, arei.gonglei@huawei.com, marcandre.lureau@redhat.com, lvivier@redhat.com, thuth@redhat.com, michael.roth@amd.com, groug@kaod.org, dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com, boris.ostrovsky@oracle.com, kwolf@redhat.com, mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier This patch implements the HMP versions of the virtio QMP commands. [Jonah: Fixed virtio hmp command output format (e.g. use PRI types).] Signed-off-by: Jonah Palmer --- hmp-commands-info.hx | 70 ++++++++++ include/monitor/hmp.h | 5 + monitor/hmp-cmds.c | 311 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 386 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index adfa085a9b..8f204d9cb6 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -894,3 +894,73 @@ SRST ``info via`` Show guest mos6522 VIA devices. ERST + + { + .name = "virtio", + .args_type = "", + .params = "", + .help = "List all available virtio devices", + .cmd = hmp_virtio_query, + .flags = "p", + }, + +SRST + ``info virtio`` + List all available virtio devices +ERST + + { + .name = "virtio-status", + .args_type = "path:s", + .params = "path", + .help = "Display status of a given virtio device", + .cmd = hmp_virtio_status, + .flags = "p", + }, + +SRST + ``info virtio-status`` *path* + Display status of a given virtio device +ERST + + { + .name = "virtio-queue-status", + .args_type = "path:s,queue:i", + .params = "path queue", + .help = "Display status of a given virtio queue", + .cmd = hmp_virtio_queue_status, + .flags = "p", + }, + +SRST + ``info virtio-queue-status`` *path* *queue* + Display status of a given virtio queue +ERST + + { + .name = "virtio-vhost-queue-status", + .args_type = "path:s,queue:i", + .params = "path queue", + .help = "Display status of a given vhost queue", + .cmd = hmp_vhost_queue_status, + .flags = "p", + }, + +SRST + ``info virtio-vhost-queue-status`` *path* *queue* + Display status of a given vhost queue +ERST + + { + .name = "virtio-queue-element", + .args_type = "path:s,queue:i,index:i?", + .params = "path queue [index]", + .help = "Display element of a given virtio queue", + .cmd = hmp_virtio_queue_element, + .flags = "p", + }, + +SRST + ``info virtio-queue-element`` *path* *queue* [*index*] + Display element of a given virtio queue +ERST diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 96d014826a..47446d8257 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -95,6 +95,11 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict); void hmp_qom_get(Monitor *mon, const QDict *qdict); void hmp_qom_set(Monitor *mon, const QDict *qdict); void hmp_info_qom_tree(Monitor *mon, const QDict *dict); +void hmp_virtio_query(Monitor *mon, const QDict *qdict); +void hmp_virtio_status(Monitor *mon, const QDict *qdict); +void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict); +void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict); +void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict); void object_add_completion(ReadLineState *rs, int nb_args, const char *str); void object_del_completion(ReadLineState *rs, int nb_args, const char *str); void device_add_completion(ReadLineState *rs, int nb_args, const char *str); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 634968498b..2689aca228 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -42,6 +42,8 @@ #include "qapi/qapi-commands-run-state.h" #include "qapi/qapi-commands-tpm.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/qapi-commands-virtio.h" +#include "qapi/qapi-visit-virtio.h" #include "qapi/qapi-visit-net.h" #include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qdict.h" @@ -2221,3 +2223,312 @@ void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) } hmp_handle_error(mon, err); } + +static void hmp_virtio_dump_protocols(Monitor *mon, + VhostDeviceProtocols *pcol) +{ + strList *pcol_list = pcol->protocols; + while (pcol_list) { + monitor_printf(mon, "%s", pcol_list->value); + pcol_list = pcol_list->next; + if (pcol_list != NULL) { + monitor_printf(mon, ", "); + } + } + monitor_printf(mon, "\n"); + if (pcol->has_unknown_protocols) { + monitor_printf(mon, " unknown-protocols(0x%016"PRIx64")\n", + pcol->unknown_protocols); + } +} + +static void hmp_virtio_dump_status(Monitor *mon, + VirtioDeviceStatus *status) +{ + strList *status_list = status->statuses; + while (status_list) { + monitor_printf(mon, "%s", status_list->value); + status_list = status_list->next; + if (status_list != NULL) { + monitor_printf(mon, ", "); + } + } + monitor_printf(mon, "\n"); + if (status->has_unknown_statuses) { + monitor_printf(mon, " unknown-statuses(0x%016"PRIx32")\n", + status->unknown_statuses); + } +} + +static void hmp_virtio_dump_features(Monitor *mon, + VirtioDeviceFeatures *features) +{ + strList *transport_list = features->transports; + while (transport_list) { + monitor_printf(mon, "%s", transport_list->value); + transport_list = transport_list->next; + if (transport_list != NULL) { + monitor_printf(mon, ", "); + } + } + + monitor_printf(mon, "\n"); + strList *list = features->dev_features; + if (list) { + monitor_printf(mon, " "); + while (list) { + monitor_printf(mon, "%s", list->value); + list = list->next; + if (list != NULL) { + monitor_printf(mon, ", "); + } + } + monitor_printf(mon, "\n"); + } + + if (features->has_unknown_dev_features) { + monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n", + features->unknown_dev_features); + } +} + +void hmp_virtio_query(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + VirtioInfoList *list = qmp_x_query_virtio(&err); + VirtioInfoList *node; + + if (err != NULL) { + hmp_handle_error(mon, err); + return; + } + + if (list == NULL) { + monitor_printf(mon, "No VirtIO devices\n"); + return; + } + + node = list; + while (node) { + monitor_printf(mon, "%s [%s]\n", node->value->path, + node->value->name); + node = node->next; + } + qapi_free_VirtioInfoList(list); +} + +void hmp_virtio_status(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + const char *path = qdict_get_try_str(qdict, "path"); + VirtioStatus *s = qmp_x_query_virtio_status(path, &err); + + if (err != NULL) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "%s:\n", path); + monitor_printf(mon, " device_name: %s %s\n", + s->name, s->has_vhost_dev ? "(vhost)" : ""); + monitor_printf(mon, " device_id: %d\n", s->device_id); + monitor_printf(mon, " vhost_started: %s\n", + s->vhost_started ? "true" : "false"); + monitor_printf(mon, " bus_name: %s\n", s->bus_name); + monitor_printf(mon, " broken: %s\n", + s->broken ? "true" : "false"); + monitor_printf(mon, " disabled: %s\n", + s->disabled ? "true" : "false"); + monitor_printf(mon, " disable_legacy_check: %s\n", + s->disable_legacy_check ? "true" : "false"); + monitor_printf(mon, " started: %s\n", + s->started ? "true" : "false"); + monitor_printf(mon, " use_started: %s\n", + s->use_started ? "true" : "false"); + monitor_printf(mon, " start_on_kick: %s\n", + s->start_on_kick ? "true" : "false"); + monitor_printf(mon, " use_guest_notifier_mask: %s\n", + s->use_guest_notifier_mask ? "true" : "false"); + monitor_printf(mon, " vm_running: %s\n", + s->vm_running ? "true" : "false"); + monitor_printf(mon, " num_vqs: %"PRId64"\n", s->num_vqs); + monitor_printf(mon, " queue_sel: %d\n", + s->queue_sel); + monitor_printf(mon, " isr: %d\n", s->isr); + monitor_printf(mon, " endianness: %s\n", + s->device_endian); + monitor_printf(mon, " status: "); + hmp_virtio_dump_status(mon, s->status); + monitor_printf(mon, " Guest features: "); + hmp_virtio_dump_features(mon, s->guest_features); + monitor_printf(mon, " Host features: "); + hmp_virtio_dump_features(mon, s->host_features); + monitor_printf(mon, " Backend features: "); + hmp_virtio_dump_features(mon, s->backend_features); + + if (s->has_vhost_dev) { + monitor_printf(mon, " VHost:\n"); + monitor_printf(mon, " nvqs: %d\n", + s->vhost_dev->nvqs); + monitor_printf(mon, " vq_index: %"PRId64"\n", + s->vhost_dev->vq_index); + monitor_printf(mon, " max_queues: %"PRId64"\n", + s->vhost_dev->max_queues); + monitor_printf(mon, " n_mem_sections: %"PRId64"\n", + s->vhost_dev->n_mem_sections); + monitor_printf(mon, " n_tmp_sections: %"PRId64"\n", + s->vhost_dev->n_tmp_sections); + monitor_printf(mon, " backend_cap: %"PRId64"\n", + s->vhost_dev->backend_cap); + monitor_printf(mon, " log_enabled: %s\n", + s->vhost_dev->log_enabled ? "true" : "false"); + monitor_printf(mon, " log_size: %"PRId64"\n", + s->vhost_dev->log_size); + monitor_printf(mon, " Features: "); + hmp_virtio_dump_features(mon, s->vhost_dev->features); + monitor_printf(mon, " Acked features: "); + hmp_virtio_dump_features(mon, s->vhost_dev->acked_features); + monitor_printf(mon, " Backend features: "); + hmp_virtio_dump_features(mon, s->vhost_dev->backend_features); + monitor_printf(mon, " Protocol features: "); + hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features); + } + + qapi_free_VirtioStatus(s); +} + +void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + const char *path = qdict_get_try_str(qdict, "path"); + int queue = qdict_get_int(qdict, "queue"); + VirtVhostQueueStatus *s = + qmp_x_query_virtio_vhost_queue_status(path, queue, &err); + + if (err != NULL) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "%s:\n", path); + monitor_printf(mon, " device_name: %s (vhost)\n", + s->name); + monitor_printf(mon, " kick: %"PRId64"\n", s->kick); + monitor_printf(mon, " call: %"PRId64"\n", s->call); + monitor_printf(mon, " VRing:\n"); + monitor_printf(mon, " num: %"PRId64"\n", s->num); + monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->desc); + monitor_printf(mon, " desc_phys: 0x%016"PRIx64"\n", + s->desc_phys); + monitor_printf(mon, " desc_size: %"PRId32"\n", s->desc_size); + monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->avail); + monitor_printf(mon, " avail_phys: 0x%016"PRIx64"\n", + s->avail_phys); + monitor_printf(mon, " avail_size: %"PRId32"\n", s->avail_size); + monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->used); + monitor_printf(mon, " used_phys: 0x%016"PRIx64"\n", + s->used_phys); + monitor_printf(mon, " used_size: %"PRId32"\n", s->used_size); + + qapi_free_VirtVhostQueueStatus(s); +} + +void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + const char *path = qdict_get_try_str(qdict, "path"); + int queue = qdict_get_int(qdict, "queue"); + VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err); + + if (err != NULL) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "%s:\n", path); + monitor_printf(mon, " device_name: %s\n", s->name); + monitor_printf(mon, " queue_index: %d\n", s->queue_index); + monitor_printf(mon, " inuse: %d\n", s->inuse); + monitor_printf(mon, " used_idx: %d\n", s->used_idx); + monitor_printf(mon, " signalled_used: %d\n", + s->signalled_used); + monitor_printf(mon, " signalled_used_valid: %s\n", + s->signalled_used_valid ? "true" : "false"); + if (s->has_last_avail_idx) { + monitor_printf(mon, " last_avail_idx: %d\n", + s->last_avail_idx); + } + if (s->has_shadow_avail_idx) { + monitor_printf(mon, " shadow_avail_idx: %d\n", + s->shadow_avail_idx); + } + monitor_printf(mon, " VRing:\n"); + monitor_printf(mon, " num: %"PRId32"\n", s->vring_num); + monitor_printf(mon, " num_default: %"PRId32"\n", + s->vring_num_default); + monitor_printf(mon, " align: %"PRId32"\n", + s->vring_align); + monitor_printf(mon, " desc: 0x%016"PRIx64"\n", + s->vring_desc); + monitor_printf(mon, " avail: 0x%016"PRIx64"\n", + s->vring_avail); + monitor_printf(mon, " used: 0x%016"PRIx64"\n", + s->vring_used); + + qapi_free_VirtQueueStatus(s); +} + +void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + const char *path = qdict_get_try_str(qdict, "path"); + int queue = qdict_get_int(qdict, "queue"); + int index = qdict_get_try_int(qdict, "index", -1); + VirtioQueueElement *e; + VirtioRingDescList *list; + + e = qmp_x_query_virtio_queue_element(path, queue, index != -1, + index, &err); + if (err != NULL) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "%s:\n", path); + monitor_printf(mon, " device_name: %s\n", e->name); + monitor_printf(mon, " index: %d\n", e->index); + monitor_printf(mon, " desc:\n"); + monitor_printf(mon, " descs: "); + + list = e->descs; + while (list) { + monitor_printf(mon, "addr 0x%"PRIx64" len %d", list->value->addr, + list->value->len); + if (list->value->flags) { + strList *flag = list->value->flags; + monitor_printf(mon, " ("); + while (flag) { + monitor_printf(mon, "%s", flag->value); + flag = flag->next; + if (flag) { + monitor_printf(mon, ", "); + } + } + monitor_printf(mon, ")"); + } + list = list->next; + if (list) { + monitor_printf(mon, ", "); + } + } + monitor_printf(mon, "\n"); + monitor_printf(mon, " avail:\n"); + monitor_printf(mon, " flags: %d\n", e->avail->flags); + monitor_printf(mon, " idx: %d\n", e->avail->idx); + monitor_printf(mon, " ring: %d\n", e->avail->ring); + monitor_printf(mon, " used:\n"); + monitor_printf(mon, " flags: %d\n", e->used->flags); + monitor_printf(mon, " idx: %d\n", e->used->idx); + + qapi_free_VirtioQueueElement(e); +}