From patchwork Mon Mar 7 13:08:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602169 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=oOGhIi9x; 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=K4FyTMjr; 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 4KBzQ61PChz9sFr for ; Tue, 8 Mar 2022 00:12:14 +1100 (AEDT) Received: from localhost ([::1]:56948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRD9o-00087c-8R for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:12:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7g-0007Sj-Ql; Mon, 07 Mar 2022 08:10:00 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:52764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7Q-0000ST-EK; Mon, 07 Mar 2022 08:09:57 -0500 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 227Cibia009917; Mon, 7 Mar 2022 13:09:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=zqpht8XHRF3sXe6XJisiTy28fNLvwb9YnPRqpwFN8qk=; b=oOGhIi9xOzl3h0PJmjEaHJ0MkQee0qGmgEzRbAnuEeMEKrCdQS+aR0jIRxqCNZ09sS/d rWfCVxmIDRz8i6f82FZDzrV01VH/z0aFskeNINhUkMbmktjO3KbOwHkARQSlVTuYni8e Ej/yV0Idb7MArlZjIPJkyfVrcbTYvFRu5bTNls1WtKvZev1pMxtxVgdYfcIxJnmpyMwq wCd9jd3VulLHrHEh1gpOdZP2R9zC5pzwpebGu7FxSqN7ZkXL9UAtNjAETqLZKF+z45Er eEJHkeixBmowfpxiSZwOSWxaAMIxmDwA3Bra6AImxit0meEbiLmLR7Y+r9qZPBzrn6X7 /A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyraknkx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:21 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D72rX062997; Mon, 7 Mar 2022 13:09:20 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by userp3020.oracle.com with ESMTP id 3em1ahyuw5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BpZVSJqjegkPBD4Me7cCCZ4x5ms6ES64X//dNetVnDM2vU+tJlNyUwAAo83emhv/kGa9MsfvRg1Tyca9nDv+w19mU5O83FmvuwMhpfCpcQ/ge4xELKXMa7ZVPjT4YEWDZufT/ske+1EesWjJy2IfeXESF16zbmiXKa8P1rC3Hj/bxCJxp10ArozrWhRYORU8+ZWIAbbQ69eJBsUP9VpFEv8wYxBcw9n6F+SwkqrTKj2PqNQ7OL/9EHfA6lFQBH9IQ3iP0NYQITGCzrDW7FRdZBXgtkjUfXEj4/pvru6Y64XPJtApW9IAPzs/qKNb/1K5nbQ4YoqHYB+fmFUA+KZbKg== 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=zqpht8XHRF3sXe6XJisiTy28fNLvwb9YnPRqpwFN8qk=; b=Edv8ueo3j7OzRvjlHG2pFhJElBqvT71LIzRsi9ICEDULWTcGWNqHY2SKcxDW446WgrWHts3Z/6MKCge67U5glQ0KvmDWBCDUSFxjVIbJq8gPfk0eQqy3tOIE0fxuM0RIgi5t/xz896PUUq0rAUwwXo3MX3h9ys2n7CmojNpaeWb8sbe3edeaU8Hdp3MDCgYij9hNXdmf+atG8J9tiCr8fS2EA2vCU+z9DiizsdLe/LWr5LdtwnlxIwmUFI6EKmDnZeUV7d1FZTNc7OGQGTo4pLttjYxREhm7XViULneb44bcdM+ZV0hLzDlepy9iXbJ02pX7sXyyjBz0S7wk7jeJKA== 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=zqpht8XHRF3sXe6XJisiTy28fNLvwb9YnPRqpwFN8qk=; b=K4FyTMjriy4F5fqEIf5KsPQLjKxY78+EvpTv/J4e6WxlwfBgJia9tMa/+xAZJDy3Lt8O+76xoTTTZ0oI5JuhfRUVboOVnFwnnn6mzt7sKLxsn5C0WWr1CBAyMT5Z6LGh8BWD4K1lx0alx/4Xo3haCL9m+wQUXtRqxiWbWT7evEQ= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by DM6PR10MB2619.namprd10.prod.outlook.com (2603:10b6:5:aa::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:17 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:17 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 1/8] virtio: drop name parameter for virtio_init() Date: Mon, 7 Mar 2022 08:08:34 -0500 Message-Id: <1646658521-31652-2-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: 6d462c2c-004e-4fa0-52f8-08da003baf24 X-MS-TrafficTypeDiagnostic: DM6PR10MB2619: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: NmpxLJSQGtJ+wfgdEnVp15fs/aRUNTsjM9z/BKJjA3vN/314vTA5Aj+zCceiiHGJXLsts/ID8veSeDTHtxZmUkGRC/TxtuZhsDOXLEs5TZNsRcahv7SJ/g0Uz/cz1qlrZYM4I7aBuDB0r4SXNod4xvDJM/P7O84eGDG0iStAgKz5HzqnslpeY7ss4VdzhdDDVSqSop1XNgUuR55oNt83VqtTwNmtAid9tbsq28IWR1myIeXc4wSyfIdJor9W+ERd2+JAbyRkGGyZR+fY5+yj4noRnA/O+mrxW8Y6e+Q/iFRzEguLv9ucwW5msR0m+IiVPISasNiC9LoO1lqlDQuhGDqrx6xE5ioZ47ro/fmI4ykZS3J2p3a5Xdlc6X0TF4zTJ/PdL74xQpjHJE+e9Hr5dNK9KxmYHAl3K9oFLQUr17VWhsMCozkZQ/Pil/VOC3jVXiaWzy8B3ee3Db3iu5q3NLFaxEKG5/3mPiJ2u8z+QXxLGGqKrJIW96a/qXyktZ3/EYZd7H0ah1KCVYf/vLBfajzQngNKSapNX6hj1ZtWI1KbbjpVhb5V/CiIm3Dl29RWlN7Lb6dbxGJ2BdkXXkV2HxSDag2k2VnN+u3N0riP2nV9hsmkyWdUZ5OkYUzcHD3M1JVhhHr/jcxNxsTi4kVW9+x+1xsl3qugPSht3nZklr0o0giJquZf1VtrJeuFUyzl2DFHGEmWzPhY5NrlaQZwvQ== 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)(4326008)(66946007)(508600001)(66556008)(66476007)(8676002)(6486002)(83380400001)(5660300002)(8936002)(6506007)(6666004)(36756003)(30864003)(52116002)(38100700002)(26005)(38350700002)(44832011)(7416002)(86362001)(316002)(186003)(2906002)(6512007)(2616005)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YU5PE1eu4nLYlRbJK88NHFqxwD6Y5cDJxUoWZnzdvlz13spFGQVNIpyJGsh6Tf1Gu8GZ2K9udTD/hZGmUmVgVNwXG9do56Kw5MUtencDDfpsRaZ1+Z4uvVhl/lOrMbyyV2cQwCsOrhLLEShdCUJBSXEWbIOwjc4/7UJEWCzj0oeffAhml5uhaVv2WqqIKMwnVhT8sOlQPVQbrSjS1jyEY9j6eXt4WbiQKGPX5kN1bjuc8F7ra9GXM0B7H4NaeReXxIE31fn5BNUctWie/VE3HF05L4RCNw1EPCg2Bp7LDbwgRLGj72Q0q95dGjqhwOLuq9ErUwesg3FDRbfWfpP/BL2svpVoU02cBYWnAeLDT7vWsxTPuJ8j1+rUXUcDFMYP5NfwlDXHcIMlOW2F2X4sg7qS2SveeGWwLpnd0J1rdVl98YmK+22kA5E3m94LcDvP4+RjF1FX+0mxp/wwt3B5euzqRbgougxb23iMwzgnrRhPiBewvLOqp1I+11rn5PqJwguF86ccMXioWHinP7OjXo+rTo/qUxiCE7A85FHqDTmnQR0ykzSZpVsRIHIDQakwZcQFNGo2hYbLsPmbn9fXs44aVht+OrxjyFc3VDSSLqh+G0pZMtISH7jQ5fVWvvC53YmcgiZpuQX66w+8qHqNmIJB3io4EjSgstJeWRFThnF21yncdnoBCc3tDgubx9v2B0/dMqEjtl7ZyKslOWCLP0lPoBFSWNRBEgIvv32PKuEunHjjns8mJ+9t0zBvLyDNNSYRwmWge1c68tn7FEmvMwZfw/xeHvROWPtom+hs2jKbHRqCkcqgP0TLcgsUf8LkPQcHAQSyYcmuZOS7cMZOGdqiRIi4IFkT6TLYfP0aOeiN4QFtrEDub9IVHLWuYRZbYI3b+zU0O4M/n96r2VDYoPWl11ebA8bCH/WDJzD/jTIizOXJfVXxLmgFqf3TNiElMvwZQdsNsEc8eUpH2xbrQ0mcidK0qvwGWmRs1M7/B0FQhHsb025qtnjkIR9QhMG2ofJWjrOKsX4cgszpf0QkJTiP9vDUOlWAFxoqpghnWfCbLZ8l7wEG0I17vDzUK7Sqamn1XjGRRcnYXIeVrUu1pFHv/P6pzwIz6cGUj/lgBQZtXWaonyZ3xgBzSUzjdEV9Zs5lX7htPzrabBk/AOyTcPQjlcggOPkCxdCnQ2w+rNNwB4+jYy04xhpMD0GgQoI+fv/amjDudr4k+sBPwL4CsppgQG/NiurOJqg54Jnf6OJ5YWeVbOmTWYG00dXtXsHgfegWLbAHD+fOkxpLXV8f83HTasvz9swR7h71EBxyY+1bvG0u3aNfrfPlS8UXW0bXDtQh6GKp1ajVcpMlUsF8/t9t/ETSgs6P4StAVzucx8MJ8ldDNkSONC1QAc14VjEP8qXfGbMIY6w294QuQAp+uExZmj7RNYwgqqmV7G/1NmO3mLXejUh7m7/YsO+C1+70LduSKACINeCui6QZO4w/NYBkrouzBwYqAiaLgRgjmCyHRoHUv8nMRhmosNHm6wkQemXKw+ht+XvXgETCsqPIhuTG5AapN3M7H1SMpcRU06Nnsl8T3xhPNHk7iQk9UH14lNexATHv77A3PQIJ7aSI5rTGnanyjD/pcvjB+3Uf2Ig= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d462c2c-004e-4fa0-52f8-08da003baf24 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:16.9528 (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: 7N1XTLWmPpWfxwk3kOTuYk2Yi+TjPAUbFetmPlth+D20E5dTY1ZfKxjGio9SjpZEw9Jew2qc+vYMdz0jmpJRhA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB2619 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-GUID: faTnPIl40Qp9JbqJ32aW3QyOOb7gCowB X-Proofpoint-ORIG-GUID: faTnPIl40Qp9JbqJ32aW3QyOOb7gCowB 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 54ee93b..5f522e6 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 1a42ae9..e8cb170 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 540c38f..27c71ad 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 f01ec21..9f19fd0 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 fff0fb4..8ba5da4 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 54bcb46..5b5398b 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 cf8ab0f..25f494c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3388,7 +3388,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 34a968e..2a6141d 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 c595957..b875640 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 d172632..58fd729 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 void vu_i2c_start(VirtIODevice *vdev) { BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); @@ -220,7 +215,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 209ee5b..08bccba 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 52bd682..0f8ff99 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 3f37712..6146d25 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -220,12 +220,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 433d42d..696635b 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 e6c1b0a..c9cdadc 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 54f9bbb..cca5237 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_malloc0(sizeof(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 aa9c16a..15b3fa0 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -968,8 +968,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 f55dcf6..465a996 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 5419dca..ec74890 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 cc8e9f7..7e12fc0 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 9e8f51d..500f15e 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) { @@ -3208,8 +3258,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); @@ -3238,7 +3287,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 d8b565b..076b7ab 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 2179b75..afff9e1 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 f095637..2a0be70 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, ...) GCC_FMT_ATTR(2, 3); From patchwork Mon Mar 7 13:08:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602170 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=gX3ScIgY; 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=yUHVBhqE; 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 4KBzVK3F1Pz9sFr for ; Tue, 8 Mar 2022 00:15:52 +1100 (AEDT) Received: from localhost ([::1]:35384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRDDJ-0004Ha-Dt for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:15:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7d-0007R7-1u; Mon, 07 Mar 2022 08:09:57 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:37634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7Q-0000Rz-4l; Mon, 07 Mar 2022 08:09:54 -0500 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 227C7jkF010192; Mon, 7 Mar 2022 13:09: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=dUueYDBjFBfuPV+2TXQMy6RAu24YiI3lUrixiZvJtxs=; b=gX3ScIgYuaa0PKP9yb7DqxEGEwlpDBVMt6SJyZfNchV2lfa1Adg29yH70T1hZ4WaXD9x OQTCZfNY3TNA8PjUTM9NJ1eTWbpktIJDGlB+w8RJ9m3rvUBS0Z8JhqbY+AUo4qAWO2Ym UefbDnR37svG9gYLEI7HbgcsyfYsR157uEiQovXAh2+JrmwVP1bTXY6p3i7CFMv2sV+b PmMOnOD/kP/jhzQ3dpop1xRtdXCW3gvfgiltG/7heRvSmEByojnOXFb0wr0sGhhajTyu gawfCm5cEKAYUjIjqB5pOiGwEbnRDAFmn/4XwYmMrr0OIY1S4XIPGTiJFB/FEQT6YSXW qA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekx9cbpy8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:23 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D5WOU124845; Mon, 7 Mar 2022 13:09:22 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by aserp3030.oracle.com with ESMTP id 3ekwwaywj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOYrtlMsh2HEL+5Quasgjy4ndFPEGOTeg00QVaE3xtHTl2uaxVWxR9fv8VNX1/Sxfa3b1Kt8PvyUel0sqKrPw1gHteEkEx4vNDP1HDYpO/nSRNcUlgSj785sTuvoCsRFWXjNGWqxCSt0kPvyFKGRRzCvo/xRBLBt1eou7K1ZNvLY0QyxObannrveWH0rabV2qAyrHUgbTv4QSWk4uxT9U5gNhPx3JNboCBcS0+wOoSrO7YNdtBp+a+wHXR+n8/UT9MQHkdxEHpLIAsB4U+ktz2suWvl0MHpLu3LaTWb9bGL+p2nsNj7jX7iK9mp+6ls15noN/5T8icwAjfpGmOMySQ== 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=dUueYDBjFBfuPV+2TXQMy6RAu24YiI3lUrixiZvJtxs=; b=Bo0jKPDKnnQalnFuY1NEqHFcAyY3s5cjt9wsaXP+pFYpsPSyzppAxRbR7Qt23Ae9Z7YDUsPXOeObbxtWSN6GOBGQkply3sP8GCGCe4wTgTKsSTkczsBpVA4pBKYvJoOH7CUxOPVVWBt5gZ7SI81v0V40WMTZaXgB3u8enYoDzWFvJKl41JFf17RB7dougGx5RKDOmujawiD8bc52d2Dganpu+s9XciPxesjXcLUCfOEW1RzWsBBy+i7MOPZY+tVIyW6FT3fLpP6/ezZsxH2KUJAEaPZ0o1xPiKQhaY6gUBr/JFUSwIJlR54oB3UtHp1Na2vxtvXbG9wQv15+liYmMg== 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=dUueYDBjFBfuPV+2TXQMy6RAu24YiI3lUrixiZvJtxs=; b=yUHVBhqEvpskqlADP9znVEesipbh8mPOFbm1XYd4uixnUs/iPzUG5cQIMhFHyR1+V96AZGMe7O9xSXIsysMl25fo0w5Z4poJQh/8EK6nCfrIGwSoGlF0MnqfpRw5qFr6orL1UkHimZcOhcOPw5NdaAy2Nph8mrXNhakXzhn13i0= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by DM6PR10MB2619.namprd10.prod.outlook.com (2603:10b6:5:aa::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:20 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:19 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 2/8] virtio: add vhost support for virtio devices Date: Mon, 7 Mar 2022 08:08:35 -0500 Message-Id: <1646658521-31652-3-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: 6b8fa3a0-578d-4836-7843-08da003bb0e9 X-MS-TrafficTypeDiagnostic: DM6PR10MB2619: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: YxIle691lOgI9Aifd3ZsOkC0Jxww5a5THCJOwfEzRtWaHZ0Lzg5CTiKp27iT93mW/7EWR4H+/v1Pf3nnanAodbIsdPcpOG5lmWUWtrItVVeiro0NVJTR970SDQuNEvspGi6x3A3u3EyYLP1V/U4I4KLXIatu5JEeAo1DzgRWEurRuciKq4KfbIR66xuUg1hNISp70B6ehxCos4MGNI+uhFBiADWEXIQjJ4VyZ6CQD0QV+PvD5ZYjg2TnPJF5hrZz0sdheMjWO007YzNuKj+/uk+yG0jwr9TIwPHLh+HobCRSKkNbh4FHOJYE7wRyu7cO0Rd3cuwMy5M6KraQ4S+ofufFwA+HBO7EnzsXKuWmAXvkgPckcbcdXlapGwPZPxKV6txf2pZS53VwvEmdmsjRssEXI3py7fZrsAzHsCseW17mlJfL3NcJESHzyjUCNIyWB2urfbJz1bQxjj0PxxRiPAS3dDI1J7rnStsqMsExzJwx6daKYxE9Vl4QmOro+eqXAPmU77MDA2y5MNYykba5j+KCJPmoV7tKzrQ9/TZ2bVhuL7ZHV/8+2keHsYtSzqP9pJh1TqftHnkZs1KXbOAb8yEMySaUKkO/Wg6Wotl4aQtpOslPBzvdtvKDvPfmxJpQ/zYH+UzTzNMrEFeEBLUHSKthXGpd3vxtJCiaXocLrXoV52Q1QbRXhny0Zp1bqEnRf3uakoOZ5pIjtGnKQl/wsQ== 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)(4326008)(66946007)(508600001)(66556008)(66476007)(8676002)(6486002)(83380400001)(5660300002)(8936002)(6506007)(6666004)(36756003)(30864003)(52116002)(38100700002)(26005)(38350700002)(44832011)(7416002)(86362001)(316002)(186003)(2906002)(6512007)(2616005)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: inSVKDpb5aKJwzr/MX9gYrRNo6U1FRc+692f2oxuWFfyuxPcdXJo/ck5PEkb7W/g5BhINspGtimQeRs5efJrur00i6kl3QXvrUe0ha4HXKcGGNaGBs2SC6MLXzYF6hKjJNTI8/bMHUgyBguEH+EtC9r3Gc7UU4BKgwJe4lDB7FufCdD77T22WgTnxjHSS57PmJwUDoQ5nOjfbkYrCveUcSiB71BJoc4vlSnAdvGXHLzObchaCWqoimy7ApX8FdNJ7yGzL3vD+jhZzlqHtGmQ00GzeyIxULbS/SlH+QeQe2fRO5tKyiS1+tEYJEU5y8eTiNe2C4h7d7xk9HmmR8wQ5sO+wnRcwiLlikAtb8qtL/0xWyuLpNHyqLjT9SZYtckBvTCP1p0W2/r3SrBaaNosgDkkn/NQUpTbH0PrJzGpCBWOebseavoUoVzOrfhdD1eRTa3biveC78bZDU+5VFz3n9yO5kJTvFXQCukBw1jYY2PEK4voNsjek0PiZ+MrSFCVh+7xK8Tu3vuz2VyKI1tkDTglQo2YoEXlr+0ebINuuvbrVfwVgcA8Nf0SH4UupNEube0WgVrkG5AjqWTSKP1eMVk9R9dmU/3cfM357kJeVwa3mNlL6DnQOP6nbdYqhg8FVXfrVwySDxeKYRNBJ+wAggAKUUdgY9hbxm4MTsGO6axYq5hAlwK4zWvadw8xh+JOMpL3g8TuA1zdm6S4MsE7rSCuXXVoYAjgg0xaj+0E/GztS57hkrmTdHrjmjQQXLJDu3QqiVmSMRNAnSjiou1gF6SdlEQSUlmbpZ7jd0F32dHAL9PkLgULTV9GCkbwZe9KcgljeJDjPfTbR9Za9+gG2TZZkss1i1jPZ43CCh9cFCTXqiLK132ipN9xN5+qFHliTc6W874etIpPrK0i4xd9Brgukxd4CHdbXL0oHxoL0xlePJvV3frIWIBrL3gIx1p0d0E7YRaNTvjPRLetgoYJv+oZVzFBLIKSX6BiTjd1FYDdIpN3TzZENK3GXsTWIba4pHIFvcsWzaHtrsPXY6KwNNoSxQpFzzUtgkYV/fC/mvcBQsWCXUj2up9FwZuQ/MoMLXGnBEeY08FA0ktW2MQgN7gI/WnyIXN88PDHGkMAqFBijBhxhhliO3pJLGMvzMMyIQAYXtX/tqA/CMjZe+DUBhvMxZon4JC6L7t2I1GOiLrymuCGAKvOV79jAxX/YDwj+cSbyGfiw29HEq69Aj8ZqyUkEODn0Ol/AGlL9Rt4P6uFXYDxb1E+vLjcPqq9cThpQm+PmKfMGXgLZ00tsRWzh0sreHHDfgB8tXy9/j+zA+aqIGctxcX8iNXWTCHobvp88aCVMOaA8YJdr+GezDSPSXfU/BxXn7GodCvjmExF5YSYCa+H2tAuHZtqAEBRXD2k8B1/YbhGF7vsONZUpXl9zE85TXbKSb3qkUnVbbBwsYVMkUuNAMaIgVmiqdp0tsa5EKtrFH5WRIz/JIVoSvDYCjCcdW8Tqf8XMPDomdvoSbnWDe47uYcRJMTprZYKyWga0QaqAFAytDttb+69eUqFpd2UAzk1QruT2Z4W6sx0jGrnU6bu3WtQMfERs7yGuga2QF9IT1egKI6qR201IG6URDqORpp9Mia0VdJjtLMPnfk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b8fa3a0-578d-4836-7843-08da003bb0e9 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:19.8913 (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: W65sm4EyTSxcEmf14EGzoFXjmXdonvh45+0tVBYL2Dyuf7ZSF7QRT3wZI29Az17rOkLsyItOZ1Gx2CKlsxGaAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB2619 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 malwarescore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-ORIG-GUID: Rmn6P6TxLulGP3p0xSc5kHgJhHPK4tNX X-Proofpoint-GUID: Rmn6P6TxLulGP3p0xSc5kHgJhHPK4tNX 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 e8cb170..5dca4ea 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 0981823..96e56c4 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 273e96a..43d2ff3 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 25f494c..21328dc 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3615,6 +3615,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, @@ -3717,6 +3725,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 778f43e..3059068 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 b875640..e513e4f 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 08bccba..3a7bf8e 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 6146d25..416daf8 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -254,6 +254,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), @@ -269,6 +275,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 7b03efc..34f8c12 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 cca5237..7d63b8c 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 500f15e..443475b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3272,6 +3272,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 2a0be70..90e6080 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 Mon Mar 7 13:08:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602167 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=HHHPiOyd; 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=VZtW/5F8; 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 4KBzNx13DKz9sFh for ; Tue, 8 Mar 2022 00:11:12 +1100 (AEDT) Received: from localhost ([::1]:56208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRD8n-0007Ua-A8 for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:11:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7g-0007Sf-Po; Mon, 07 Mar 2022 08:10:00 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:50152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7Q-0000SK-4l; Mon, 07 Mar 2022 08:09:57 -0500 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 227C4lqX009900; Mon, 7 Mar 2022 13:09: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=Jmlg8kLLObSjMw65EBnpH+hE3PgRU8IKLMQ1Dfr/fQw=; b=HHHPiOydmJrBg9fqCNNOjL1rnl518ggAinPc3vzIwCJTyeJ68kApaaVjUu+O7BGQPIqX viaW7xFLZiYaF5RBVYH7xawBVeiW2zVKD8YCtsAFW3F5pGLRjRvJ4JBAdjKYhT3InSyY GWnk4ZPLNoE2IMaePtVpuXuUCROrKJZ27J8EdwKpRNRjCXWYDIqrgoYhYheQhy0aet8X odA2PZ1LbgiF5VgirkgmT9A+KnPckDzwjs9ABqKVBUYMWDkNyRwCEjxIbUuwRZqS/x0z GouPkIsuVYy1HpoZD3msGXFXpuJSmaKjwmbaOQMqIUmrbzMGxzzfXBF+Q83CI//XzJ00 ug== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyraknm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:26 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D56sQ070204; Mon, 7 Mar 2022 13:09:25 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by aserp3020.oracle.com with ESMTP id 3ekyp15pbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RveugmoZwhLLhy6Y8c6FODN2vB2d9n2C/LgLWXQDSmoXQ1GXNcfsap4QKYyig+cTjsThFNgrg/YXqXJ6wHwEQTpnS5hebIXQ1B0EEOuudQv9RhjPlO/gYFkN7zCmnYwxW95uYDTiNnId3nIoMKzkLcS9tinCD9j5ksM+bZJhEwOqsAs8lI1Cuvh2lnIcET67+Nh1q6m5oFfQBJKrVNXC+3h3T/wLUEY+tc8fUosuuXR8Wy5eP7gVYx9ZNDcjdluhtzZhtgApO3l6dtZoH4GTnYP12P2Aqo4MHXToB+LuahA+lStNxeQG+xJk3puTkN57cyGJ8xW8yul3u/owYsFsFw== 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=Jmlg8kLLObSjMw65EBnpH+hE3PgRU8IKLMQ1Dfr/fQw=; b=f1XA6ZDfNUDV3v9IQFDXwvSl7XlqzrYcf8mhnINFLRIRUKrScdhnIUgXbn4gtgf7pnJmsF2oCarCzlNWEbFoYcCEtjTvb7O/5jXz2ZNXI6GHk8JdkZLGKRvh6Bi2rsOI/CDAPjXLSzwTOlZzajjuSXFwEs4D3ctTdUNUtGKS3qYMWa9D+WsfZK0OjztsFefKb7Oj2xeuAFNq3CTnKJrPbkGhhfekr8OyUiDOVT9mzaqTpr5AeBqAMKryDrEVJEwdfgA6x2+gNnfbJ7FP4gC8TxIgoOv1ymTnIz5eWGFDFHRV5X1H7ZluStL60uBLbYHpHaNZiCdfI4Q0icdy7hSGKQ== 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=Jmlg8kLLObSjMw65EBnpH+hE3PgRU8IKLMQ1Dfr/fQw=; b=VZtW/5F8So2e/T/iLIT/wHDzR+f3HTg0rLtx0mBVZ4rUB8FsW/R6wLI8j3OVstl9dHB11uIfp2qP8PFgAqcfYKqPacDkIQ/7jWm8PZS3jqs9re2odgWIkhzqKNXbnJXl/k3xe4aRkLeaAeyuJWZKelaLI70C803opBTimcr0HqM= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by DM6PR10MB2619.namprd10.prod.outlook.com (2603:10b6:5:aa::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:22 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:22 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 3/8] qmp: add QMP command x-query-virtio Date: Mon, 7 Mar 2022 08:08:36 -0500 Message-Id: <1646658521-31652-4-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: 0e01055f-49a6-4c6b-97f8-08da003bb2a2 X-MS-TrafficTypeDiagnostic: DM6PR10MB2619: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: QDgBGMjwVkBdjg68YNqru1DM/2rACWecPLgZeyYmgw+AV98akLZhApbfqCnWQHGbXCogm7d+XkR5eApIIAmLerUa7Csf2IqZSAZf4m77QWVilIDJdybCXrayzLWeXSFe7X95eaMTYwdvyL6EOpMKABlmRjQzAdXchIhIVKULr7Tab+Hp/XKU/SlKevcnmkcn+ayrT2tOGM/AYV24S+2S/jMbaF/saKKw5ptw5r0eXSDodQOWIj2slg/eDF+1YNjrPpCYyQ6Efe1ItwxQ30FBmW7GThRIynikV2o41PvpX1JKj7SR5ck4fH7X3naSlxtMN34AGjuO4kNvFO5plOiifPX/ujxYqFsTNJi5q8XXgoHSUJLj60xA3QlbfloQ7jOf6zmJYJuzoaayHdH3qq4nL2mzwPLhmymoLvJRsHoTFHNSzCgTpgMx4tjES/R6Wl9RsIKIrl+KrAHj9/VSNQxtgrQ0hg1/YcBc3FqMk4kzeAe78EMroUNKnAumkS0HVV9MbXiBv7zO/PrnNWe+0ElUOky89v4AIcaKGNHYMLfBHz+hAo4wRXQL5HRb4ZK9xt2LeeBGeV0IXXvg4b5DpFTx5eNv0Gf7kH73zueApJunC3TIk8Faq1x79S3U1kFqCUfy9fLeDInpkGKuwFMXqUOBAejUGBhWLIQhlgFrlka03NCmDKnQKjABmARVV7gO6XcJNh3CdD3EBBlE8cVmU6GQqQ== 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)(4326008)(66946007)(508600001)(66556008)(66476007)(8676002)(6486002)(83380400001)(5660300002)(8936002)(6506007)(6666004)(36756003)(52116002)(38100700002)(26005)(38350700002)(44832011)(7416002)(86362001)(316002)(186003)(2906002)(6512007)(2616005)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: M3AauvrHP4kch3WJobkDL0MwgJhSehbjrpK6eRreMfqOf1kvNT+rWDKhHwVkdV1rWsnLTdJoNDRORbPEkYXC5nYl60dLyp0+hataZYUs/SYMhY5DLeDjscFYsO2F9STQsrbDC60J1iuKenViFIlQavV8v8raPV0/EorzzCWTFd/TyRwJCmQcCL4q72CpWHlv17t64gPNHmToFo1ggI18ZAO5tl7EUnKIglVLMVDta72qqBgxoyvepSSaRq3m8wGShpG1Q72KWxNXiQiscPk+YCPFq1UuwjtqCNfUdQHOXv66Hjel7LaalTk0+cOG21PykmlU+Y68HGlm5St7u0BubwfswNdFJBkYa2GnR6Iyb6BkXtiL9dc6y25bp6zlcnMqp0NmpDa3WNQxCyQ72UtguZzhvpCVjgTg/xa6U/+Q55khRB8h5yuUgvPLK2M9/XX6tQJyR5qkzIqxKc8BN2Cd88bPzy6GtABfxdYNeZqq+yiPWdhh/ucGMv/JuwwDdoQgDmycqDcGhxOGWTHZTpqPTMLv+RkbNmVt7s6gQh2IBPxRAYcDMcFgnWaxu26OGOHLOR7fW675Ym8M0pPPpTS7S8gkPkiOzq2UJA7VitZK7o+7fV33IG4OGxPCrEvTlXwgTURdES0oIXqfS+OCkoQ6jqw6qUDTb8OZixn8hp4lYAD0rLkHSDtKglAzx/ltZEnexmixNCmVz1rzDrJOyNZ200PrhGkLf/NsV2rJnLEvdxG2HXTYO/q7X4VIuXfTQ4TAk1KZ7ZZWn72qhEmM3inKSQnb9/e3zdbzZU/2EliTXG4hxCsy0F2g62fA5SmU1MLJmVNnXoSiiJZWDgcZJM1auLGHHQI3QlW4IvK2qVvgK0trNUj5KqUvUXWk4PQKKGauTP8xuDxBgYinO7Fqwlwhlntqm5VNvFNt7RLeWqEscluu3/ubUjRlbNUreTCJ1MpdUKENeD20balPYYtp1P+b60ZTVP5Om/VkYs/0pKyOTA8CSbcZ2UF5zEKRbDTU2CCpFkji99MhX+RJxHb2JnK0b1Lxpt7YCKiYpHdgKSZdi0X9xw/TZ28TTo6/j1I0LIH/mWiScGzGlCQG2sw9L9kyMXqznu7SrIXV40RzAEvWe4BPw5unw+jC3w6AaN+FYcsNKOULZ+UljaERHWICjNcA9B4l2NM3KLZN1bEbnX6JEkstzdcytR33sRrGcga7A+JegVOpeI5LrXFSdDwJRJd8WZgAJsA49hOvcLfDrEyGfllR3DZ6+QWz8nFXdBaEidQAw2+wpOFZbUcsNKx4EECcgwBGgQhlLGVn50PlquUANsnoZUQjgl+PfRMuDnZo4dDFuC3br2FwpmQd688q0pfLEltDkib0Tvnj+67ijL66cRMfqYVC5kEtJaC4QDfIlRaGpTYkk8RDB8hLXSUsePk4Yt9grXv9dTEPg1/2PYRXUythJWlXzYJqBPBJaT1T+KWIa4ZVqTnFEk4iu0oe/0rygWl66En7pdjACgFu5jmXSgIhHMD3qObxfxlr4silHy+wT4ktHjPDBR+CbEeV6Azv6N5gTBTm+FSf4Yj7F+1gkxOwge0cy+lhjMlt4Qt75XDlyxDovjwOV3KEJIB2uOAylZkrm/iKX33XCjUBkpJsuQk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e01055f-49a6-4c6b-97f8-08da003bb2a2 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:22.7666 (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: kwGBJATHwovn3o0Y4wtgEIopfHWrOG8E0nCJksGIgdc/Zu6xdbEnLFFOWqMX50CoDIZZiRr4EZOsE2L8hOMqIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB2619 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-GUID: ZQv_I4AWe0uRkbcrUdWj_jqBS_UBPgFv X-Proofpoint-ORIG-GUID: ZQv_I4AWe0uRkbcrUdWj_jqBS_UBPgFv 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 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 521f7d6..d893f5f 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 0000000..05a81ed --- /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 443475b..dd02909 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 @@ -3686,6 +3695,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) @@ -3700,6 +3710,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; } @@ -3873,6 +3884,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) @@ -3883,6 +3896,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 90e6080..8f4e4c1 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 656ef0e..10c54d6 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 4912b97..1512ada 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 0000000..aee0e40 --- /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 7f103ea..fd00ee2 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 Mon Mar 7 13:08:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602172 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=ysmPFK9k; 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=sSWS+u0l; 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 4KBzcw2ZfSz9sFr for ; Tue, 8 Mar 2022 00:21:34 +1100 (AEDT) Received: from localhost ([::1]:41952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRDIp-0000Va-BG for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:21:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7g-0007Sg-QA; Mon, 07 Mar 2022 08:10:00 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:54692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7Q-0000Sb-DF; Mon, 07 Mar 2022 08:09:57 -0500 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 227Bgfkn008819; Mon, 7 Mar 2022 13:09:31 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=Oeizfcx6ghfbN+v8NBJUtaUldcms17wOoJG43XBOgnc=; b=ysmPFK9kOfo52/bldXfShhW1DOCuT9QcsHQkAPJZ3yXtl546PHXUiVFwFcwnN/V+mZ1v eKJrgyr1LjhjnAzO8iC8joRUJGMQZWAIgaUoJJW445lRd3ePehtJQ5ZNX36ubrMJgBij U4Ge10aBVBjOO8/kO5sr0LYi0za8v/NXMQfXgpe3mo9/M2Ll9gjsbQeW8YLo2pW27nz+ /PagC0eI2YhqSWWFcqwXg8dxSg6BnWdMTgHcWzbSU+2mLtfmMC+xCuNtOb3fyTLg6Krh XATjGEpl/W+/EsLYlGx35FENfMIvEKu0PF/RFbrgYsPQ33tsTMf3kQAUPYrODM1GQQ1e jw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekxf0ktex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:30 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D5CY2070324; Mon, 7 Mar 2022 13:09:29 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by aserp3020.oracle.com with ESMTP id 3ekyp15pc7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9JdAgsVGAhJDhZPIgE3GdrE10hMq1Ws4j6ex1snzMfwdPkQW9JORgQCKFXHbl2EhFzuX7QGt5x0/LsPGKOdOmOnjV+TiUCgMp6hDrBady1OLfEzDmTVWTg398Ay/FR30eXvN83S680ZxD6jH+WG178nZY90m1m7oLEZvndlNdvnmcYTI+BD3avsR7tsmgZa11zMDFdEIQlIcktcQ57IO6eWC+TYAR1uy+L94hB5IcebuZoBpEX4lSgFY+lPt1Odu/xBSFwK8rz6phVhfS823P8E48vcpzPIQ2Uk1SKCB4RVVfJHRPZ9rv/w4Pnfi+zttLN3I9Psk15th78q2jxwsA== 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=Oeizfcx6ghfbN+v8NBJUtaUldcms17wOoJG43XBOgnc=; b=aGHwyNCOXzp1PGKFrWfJl5F0hbSqWQ6Bex1qmANgOVa9QFcvasaIWTMlbEggJ78qY4Bp5a78GNSlq1oQeaRaUgZdqXKiH2vj0/jXTKA8bE2zDZ1PhsxX9f3m1OfHa2SKAiswwvRoobGWVbplJh82/yjOCzlK0n9cAFceY9aM9ElCxSLUX+kyVb6KnLAqZe180Cq1B/p+NT0S84oqST+IutyKW/aVO6T6j3UGkQZjHJ/teEa56Xj1zZag2s9q1FvDrEXVuaWxeHeToF4zIxEc+7RZ1/LxBtQAb7cYeU3kDzwr1EUsFkyQwCLeQIXWA3e5SzaHwYyBV0typQvvj6K1lw== 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=Oeizfcx6ghfbN+v8NBJUtaUldcms17wOoJG43XBOgnc=; b=sSWS+u0ldIu4h/hwpiVqC8NQnBJHFMqzbEl9SHdZxfntxVGTS12bOXGzMHHNhH8cdTfUrTlwG6ErKKQKoshnw7jQB4H6NVt23QJa4gMv++/vI1xCquva2Fq4hopbuhQYT0/JvtP8fWc+qgID2roooW7QCEo02sOVHyJLAELSyCM= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by SN4PR10MB5608.namprd10.prod.outlook.com (2603:10b6:806:20b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:25 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:25 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 4/8] qmp: add QMP command x-query-virtio-status Date: Mon, 7 Mar 2022 08:08:37 -0500 Message-Id: <1646658521-31652-5-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: c3b1ab8f-176e-43f4-1179-08da003bb452 X-MS-TrafficTypeDiagnostic: SN4PR10MB5608: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: fkmjPfk8ld7Kt5Khiu4GEnFm+1/S7tc0eZJs3vshRkDgiqggTvzbJHQsDrEtpsARiuzR1syStcakEL430VqpkqKSWJwhruirzNNiAmqiug9sALliBuHOI/vCN473KcdlqxOR9+MvNa2cRx/+0x0VxW5YMKzKM4I722qsJZPnTazwyyrG9FJP0lPcUZJXObobu8DqLXYLwphhG98NkwLkNEBxkBl57PsDd8EwjAUP4ilzuZhfG5pnCYubpRXPMjWj0rLKeKUwccU90tqiZTEuUH6RNw8OUnAEi5kfzo1jHWnKqWxrdWouERDzV5cW91U/fTGvu3n7+iJ12dDY7sYBIzJaCgl7fWAYu4LJqrtIzuQQpZllRMiUVy3O98pdl/xZMptXmv0Z1T0WHLCu/UHrCgjBlbHxWQ2yDTJvnjbh1R754MwDtXzEtXPdngowJj2wh76groMh6uxKHoea7xSm4MnpOYNzGgoJVmay3WJisnHxw421vBFDoyw8t4VqCqlnhRaDLA/7BCDuXrFTaAxDda4zteRq1e+xCTttN6qrPBeHSOlsSSbiUywCv7yOMnXXkqz7wnpWFklzt2ySyQZuOpp+ySVMp3a0PBwt/45bl5KwuVUV87YW1+8CXoxKiLZBsKWt3yfveewn2KFf4Tw2i/W5Nh/7DXIh2iX9/DsFoVnjEllaW7EV/hUUEHFUeH4Y1tKQ9N1+yuU5j95KAdHiGg== 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)(83380400001)(44832011)(30864003)(86362001)(26005)(186003)(38100700002)(6916009)(316002)(38350700002)(2906002)(8676002)(66946007)(4326008)(66476007)(66556008)(8936002)(5660300002)(7416002)(6666004)(6506007)(6512007)(52116002)(6486002)(36756003)(508600001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gahMtxjJbUG2Nx0yvsS21ofPa9k6ByTzq3S/kf6asl/Fv3kQeLR7R5lVqHKttTQ6FKlyR9VcLElYSnWEz4Z/WwHxRpMOn3Q2DG6BkjA5aQ6P3fbD5zlmYofmOED/tKCooaemlog24nfXxRJGHKG2o73Fgn9LnugHICczt4WCl/178mSXQ7NskXZt2nf/HJSk9kmnC3UWAns5Mi8nFfaNj6gOberGm8qwDGcwg2y0RSpKUl5RkQQJd9gl3pBW0XEUUm1a+R+XVj7329e6b8pGB3PDBemRsR2G1cx8V5WOGAeRPAuYsM+qkkIzXNYqlYIOpqFG5Yvm3gVPbSeJ52mW5u5fGpL++iMcStLEn57Dg593DTMneBTn+MektArKpnAppdaQNwk3mug1O/6lUHeCLba9WTKwb9iBg7D000gsdVxuOieT2kjc6gmzbPSwUDxi1HNMQrdyJSye3JAUT3B2CG+WdpDiNENjv/Uvwem4/8OlSxLBYS9UpJNfrgTFRp04G/JiTPCBxocY8COlbIrb5fwHagWStlV8cxW+pmp/mV/HWDmpsW1GtkzeTWrJ44jPUFtCx/ysmS+IsFTgbCxetu10fDYDxXlAQEVlxz8AXUgjSHKwY/feVDDjkey3lzd+44FGcq/oH+s+YnN/XjNRNlhqir4gPKw4G0e4SlHVI2KjbZTKpm4rImzFKL5PJXUSI+89Gukl/NRlO/kZLtcnUdNk0L4vIANR4/6EqmMJw6G4OQ7Jp+Yz0ZsdZtvbbNj5O0TwBFeSMeqHSpeUBJPlqGbv6UtpTw4ZHF1HkB2AFIq8Zkx/iYuelksH6W8vRmm6u6k/hOapjW/QWnuSdyD/g46JzOuQdi6sBzXuKnmEo7LWrLbEoJ9aJdzBy53vgJ7l+sdfxzNzj9kc8GXSScZg8z26UNGNfvz79A6koMJqHO9J2LNPLw/mN3PbKF8l1v31ObcTdlytnv7wB/l2icvs2L3KYYkWohmHY2UbZ0lMw+JQLT3EZrQqWQYJLqZ6NPrDw/2hw240Cr//Mj2OVsOLlpLO1dxt1R8R2b8jsTShoO+vDUruZA8Hm3t9fAbwBJq8m9tza8YJ4WPWsyLD4OvS0xEQTnBwwdwlIjI3EkD07CNKCW19GSfFww0b4TCvLjRhjqQIkn4JJJmjjAkzksDoykbuTyxCkHox/4LkGYtzLMkvcDkiGc7hZ+23viSUbqRsteTrYixAN8DEzQrQq5TaUd4IQyz/QZ6kEJdA/HVytBwBAWssDjWeDe4mVT+UgkwggoKelue3U29rD0jhxlGLhFsGnd4E4zdJSq3FchRlqZAtVShGS4uJh4RY6FtZmfnY+rl+bKm3CrR2SubYlbM1f32EdbLeZ63kNvM+sUfhJx/K9ItA440owYhKQfoCGvHksQ7MPYAQsrncrS9vv/jQH2g3gKgU4PxdRpQO2ylKjL5sp+LxmK62v9xs5jPvQPFSs/uc6G+H4/QRG7y8PMvLiy/03Q18Y2d0tjmpmVrDAunX1l+uBcO4LyemBqmQZK96rOtHOkFKOn9xS6CB5NCnBYhgNCK0SkcpJJ+YCDn5myR93WWfMC+W5XmpZK9pfNOvJo0R4jz6UbCn8/6RLmgE9K0MjzkxO6/4uBWF+agHgpA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3b1ab8f-176e-43f4-1179-08da003bb452 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:25.6256 (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: NT4MPo+I0N5/Tyd+V9BvAODSF5M8i4/Kbsau2I/Doau8J20F58+IO4o6xlvi0pA2XqK8ysVvMjDx8cE+kbyCYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR10MB5608 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-ORIG-GUID: WRvoojmf3qZl4J-qQ4qCXH_rCS66AzfU X-Proofpoint-GUID: WRvoojmf3qZl4J-qQ4qCXH_rCS66AzfU 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 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 05a81ed..0b432e8 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 dd02909..59665f7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3927,6 +3927,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 aee0e40..ba61d83 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 Mon Mar 7 13:08:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602171 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=at69laCl; 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=pGdfYgS1; 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 4KBzW572pkz9sFr for ; Tue, 8 Mar 2022 00:16:33 +1100 (AEDT) Received: from localhost ([::1]:36084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRDDy-0004js-VR for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:16:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7g-0007T3-Uz; Mon, 07 Mar 2022 08:10:01 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:62896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7b-0000TB-3s; Mon, 07 Mar 2022 08:10:00 -0500 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 227BjMsu009281; Mon, 7 Mar 2022 13:09:33 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=xdu1Oqe6VRSGnVt1qtHIxwnuomzMTWXK2d9rSfc5B8E=; b=at69laCl94WtdVGkI6RHkNMxn9avFANTixBYERpcy0kCjGVoYE91o0hooUc0mlp42xEB QsPzvTAHY0XjxeMuzI6Z6IxwnXeClMYrDTR0Vmvo7zhLmme8bnSV0YP2KUJvTZBVB08y 3ZuwqnuxQquZhwD4v7FWiJMcd6V2y9ZpLltfGFoRJTAuDZxIASblVDeP/hgyDq5OVKzm 1TEYDeHARwhhh5JA8ikTUV0TWTKv4OMbQBgGZL/m9nXUES9ztjVOcUPt7ZjBhzmzpLxF mRU2SlUZBaRY1TyiJqgbPW1Kt0QC4lteX31z45OTT/vd/FZ2PId66wLO2mqrKmFPaBZq Bg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekxf0ktf3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:33 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D56qS070195; Mon, 7 Mar 2022 13:09:32 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by aserp3020.oracle.com with ESMTP id 3ekyp15pcq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bH00EnJzD6vmFSl4oYopodgkjODl4Ai+pTZtsDADIw3fgIjklE4L4sh3UY93TA7pcO4rCgeQk0JKrGzif7e9Zo14lcl2jIC9+n3Za/gR0pkNSPCl53YU6ud2vqwcrEpPPwLPOikAIYYtYjFc3o1yLBf41i+uDeRmbLTYrumpQuhx3DNPgUjbZLYrzHPkzAnFHRZ0mTp0VyFMdTKqKhuwKm/6cg1uhri6fiMpXXEjVHZf38FHuEKPhwaLfg+JL6NI7AFdMXqT8lJPRm9MxKFj0TENcfKArX//bWGVvQ6vfLHrCACHWmfqWMpJ2zhMPMv7nDLRW6/ko93iIC8kQJ/FPA== 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=xdu1Oqe6VRSGnVt1qtHIxwnuomzMTWXK2d9rSfc5B8E=; b=ITA1+CWKrpV8XJ9pUL/ssYSR+rkayjQDUj0CEcDZ714VKaUgNE62qqH6FF4Wu0TzwBALrSFr0EtMcE6ePUwdQ+qAgagrmTvaY6P7G4xuY2xD6Jga2AbD9nC6TXtvJHToUFeNG3pPydDPC8scrq+0mbWRS10xktrITP8Il92r2iU00+LEJZF3rShdy5qEhLnO73C0MGPfTJiNWqs9R/xdb0+CG/QNHUjGT62IL097eKsMOtnZs2lrBmEuw7JJHTlCxy/dO2Tp5IpyU9eQIz3f8QUBFc2wqGP8C4BLQIRtsGZ03b/JhPpaiBTjukR8Umd4KqstLQyycB/9d1xSHxXvsg== 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=xdu1Oqe6VRSGnVt1qtHIxwnuomzMTWXK2d9rSfc5B8E=; b=pGdfYgS1DxfOspxv6kcb0BfxeGNzxytwswMF+wyUYNwMKSDPT9KpsymDSyiAjUsX4XyK+fbzC37JM6/QGyP437OXlvc52pNJPOFq+ltCB3YAs60JWHReS9/sL9z9nZYP6alEbYDYpP9FbDUzJvVei0758YGgBq85Rl0DIJ0I79A= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by SN4PR10MB5608.namprd10.prod.outlook.com (2603:10b6:806:20b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:29 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:28 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 5/8] qmp: decode feature & status bits in virtio-status Date: Mon, 7 Mar 2022 08:08:38 -0500 Message-Id: <1646658521-31652-6-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: 6491f072-9ca0-4b32-b8b7-08da003bb638 X-MS-TrafficTypeDiagnostic: SN4PR10MB5608: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: uaA5t2g55k9el2+MS+dSRWwByUY8z2AUDXrZv5rcJVi3A/iO/0fUqu7xIYtQaKQoahEFOGb3bfc2aURO7ngBCOSwwr2/fpZnaMfW47IWYdqwVRTvwBcI+TmpdBKVU5geoopbACXE5ZNjEosbgpzZkZR8KGNRYtivKP53esH+Kjgtmh2n3p03XASxOJO4highcRmvGAskR0vgATURALfpeE1dwAwXgux3msCreNGtUphiXHJPhHojctn6Mi3eqT9UhskiQ2PbL13UIZlbQsFvp7CFsyZIOUrkEXveRE33BeURhb6zi3UXivluBgKY1iiT5xEc0bKSsTKKB4zL4ZKqdCke+s8ekJJf/WQLDCEhGXobQk/KoGbFaPfNnY3imT1h2wI51Eflnhcf0bWMwxU05Bt4GLzlja5+UNmHvarwOxOPfH15SRfdCMItGMZIqgalHvJDWEWLOdGp5LajCzo7/Nhleci9aQ2NswfH4n/iEM4z3jMVf34uQ6VdlphQjbjPM3lMt/ZCh4F5EJZJiC/LuZXe9Tggq1zqmUJwMRAL9aY/Qpy8j0DILaQ5iV0MkHzm2Z+ooeBn2jl/0eFKITlC22k2Y6/756bkRblhcdYv4gY1nW8Y83DPSAZ7s4mUxRfB2gyJ1zeJndnPO+/GJ0pcExuF/3dbmVRDEybgkpdTz3NCuFFHCY53xlXdjiyGNPe3 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)(83380400001)(44832011)(30864003)(86362001)(26005)(186003)(38100700002)(6916009)(316002)(38350700002)(2906002)(8676002)(66946007)(4326008)(66476007)(66556008)(8936002)(5660300002)(7416002)(6666004)(6506007)(6512007)(52116002)(6486002)(36756003)(508600001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5G+7L0TCt0VqXyAxO6illNvd/6cYDmBe7oSmPx2WJ5ChbsMfhFDVIiYIU0p3Jp4A6VMIuyfy/+qiWVSnhTnQFuFOErChswmGl2KqXTeMmI/9n/UlVYrPzAdkpcW9AM7F1We5PLq2bwge2ikjrwB8Q5qAYm4etYqUV30GASvlCVaLxAVhmWDja6xOQ6w3QUBGfzZOnOXwUPJiCrMZteMhSFuXZGr4ZOWqmUELi/itxV2MBnYPExqhyEXFdndSqQ+0PEuu5VlbVi5oR4YZlWCzPIAbNy6xoxZjUYxs+P8JfI+0xd9aysGKCMlz0fyQxP5r9Kf+9Izyb4Ky+Z2i3i0V7Hg/9/3fhlB0sdAenEfFXstqlb4zR0xKU3aVtvCQHh805c++2AessC+7KmmlfJJujdpCeKTQKhgRbZGQESBTwxngZTCqo8atD5FeO80yRcIMwjj6xfR41Rbu5tcNi73TiF1ombhLdgr3Q75MRL2Pfmhi9tj2tOpRFs6/J9wrY0DuEMcSpWWMfAaBPL70cc5BrQ8rij+a+9AT+dRiToLU3DA3afxhNWGigh6PM/UuN9EfOOjDgcQnm2ugyVWTccsZtdsL2iWsom3P2AiIlo4CbgcZa6z/0oZ/i5lm/RTjPAE0WlRn6r7lxOSWflxxY3v3FO3Lg3AiiuDENvh82agxVXtH92RCNHZ9iF+MZ2IOfgBDJrEPl4VOegdXWE0rIrB9lG0peHZpTbGI2BKM1aHP1J56Sz/BELLOaISHKLvh6uLoRJHLtyi9Vx181yqeNoJwnh6b0uB8pWiMydc4a9ksVyCe5g9lu8MFE8C85d3pOt8McxCExMA4GVAsY2n9mghJhnf7hqRM+46C20X6Dd/BiRVZqww9D2+AdvamnOdciAmuvxDipddztgknyye3eUbO68UkMkNPikINSFjn2+RuvzK9YxS9RKRyFA4xE5W18LBGYD5AYCqoX9izgDf6W/I6ZQYsFxXpiOE8f/OTx2DGqgXzNRZHp3JDmCt+KHVqO2yVv88MGrSUGe2fGBFkk+zcOnVV+oeGCtcyfX3ftZVNnGQ4aQZp67Pv9Yd0EghjqE2q6QVh57g6qXGBD8xfV99nbNQq8X3En+6hWAKpnjh3g+Y7COwagj6OuDI8LY1EUjv2SPqJ+TdlIhBMiNxBzR42Ui0KQqjuDXR2IBR1JcrbIhiUnH5l0PflK8628OMtg29ur+8QZC6NxZRBc7ZLmC2AY9Z2lqlDJWpqhjEbPfdooexwBykYYxtXQxu9o+bOojfJUiimuI66cgHnb68Mg8PW0UcwMz0T/L4qQ7I7TPzeEeX7xFMwZlFOoW2nlP951g9C2ZIL/eqTt/SyRm0wCi4P47hHrEWSDMlCrIwY6UruvNeV39afW15h2iWJyGYvDvHTTkKMwDuGeDGLwRAvC+iugj87W7q2oDpkdXW9pOJfoMQ2gZ0eNnB7onvmqfw58k5mY+VNcLe9gSFqqRBG6jGWgSwMVP8OcKz6Yb4cuQasHn8ldeRMWZ3GTy/djhUlSUdnHmdAfL2g7XpjPj5jNg6yIKVrjXjlPCNZtBFvriymcE3EpuOE+O6P/o9wkxky00AmeMZS64fkc7Kn0hgdt+oGQUw9BuC2OMOSSD+ap2F+tCI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6491f072-9ca0-4b32-b8b7-08da003bb638 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:28.8618 (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: WfqjLItiJwb/hK/mXg7Kmygh9NfpUVaRyaqfBmW6eb9lpRBGns2mBINBudtkrH08Obftb68KFNjD8lr2EbuiKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR10MB5608 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-ORIG-GUID: plbEwUlPraw_qluMtm5LkWhetBsy9pn6 X-Proofpoint-GUID: plbEwUlPraw_qluMtm5LkWhetBsy9pn6 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-base.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-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 | 297 +++++++++++++++++++++++++++++++++++++++-- include/hw/virtio/vhost.h | 3 + include/hw/virtio/virtio.h | 18 +++ qapi/virtio.json | 156 +++++++++++++++++++--- 16 files changed, 646 insertions(+), 29 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 27c71ad..f104603 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 9f19fd0..9de2575 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-base.c b/hw/display/virtio-gpu-base.c index 8ba5da4..796786a 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -12,13 +12,29 @@ */ #include "qemu/osdep.h" - +#include "standard-headers/linux/vhost_types.h" #include "hw/virtio/virtio-gpu.h" #include "migration/blocker.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/error-report.h" #include "trace.h" +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), +#undef FEATURE_ENTRY +#define FEATURE_ENTRY(name) \ + { VHOST_F_##name, #name } + FEATURE_ENTRY(LOG_ALL), +#undef FEATURE_ENTRY + { -1, "" } +}; + void virtio_gpu_base_reset(VirtIOGPUBase *g) { diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index 5b5398b..fe0ed6d 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 21328dc..db3d4a0 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 2a6141d..9ca8faa 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 e513e4f..096cc07 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-vsock-common.c b/hw/virtio/vhost-vsock-common.c index 416daf8..047ebb7 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 c9cdadc..63d4d27 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 7d63b8c..b938bd8 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 15b3fa0..bbb7382 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -25,6 +25,7 @@ #include "hw/virtio/virtio.h" #include "sysemu/kvm.h" #include "qapi/error.h" +#include "qapi/qapi-visit-virtio.h" #include "qemu/error-report.h" #include "trace.h" @@ -40,6 +41,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; GTree *mappings; diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 465a996..31e7af8 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 59665f7..ccb5e2b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -34,11 +34,100 @@ #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 * which don't provide a means for the guest to tell the host the alignment. @@ -3963,6 +4052,191 @@ 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 + /* 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_I2C_ADAPTER: + 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; @@ -3978,9 +4252,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: @@ -3995,7 +4272,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; @@ -4018,10 +4295,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 58a73e7..4aaa21f 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 8f4e4c1..183d431 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -71,6 +71,24 @@ 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[]; + enum virtio_device_endian { VIRTIO_DEVICE_ENDIAN_UNKNOWN, VIRTIO_DEVICE_ENDIAN_LITTLE, diff --git a/qapi/virtio.json b/qapi/virtio.json index ba61d83..474a8bd 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 Mon Mar 7 13:08:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602173 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=Kqm5ZVhX; 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=WIpqLOFz; 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 4KBzhB4nhWz9sFr for ; Tue, 8 Mar 2022 00:24:26 +1100 (AEDT) Received: from localhost ([::1]:47906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRDLc-0004c1-OG for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:24:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7g-0007Ss-Sc; Mon, 07 Mar 2022 08:10:01 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:55716) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7b-0000TD-FX; Mon, 07 Mar 2022 08:09:58 -0500 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 227C3J4Z010119; Mon, 7 Mar 2022 13:09:36 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=sqLOkoAz9PLSjiTgvW6DexwmElDvxl0n2Zsg1OxtpJk=; b=Kqm5ZVhXTjK+uE4MeGbkq+mAxovoKOWehjD8xJxQUmhXzIbCkNjkjyUc9i0E9iHk8sBh iPE36dp5H34BAxGVKcWuyaLTBXTZny9AzkXafGtbRJZVUbC22oj8nae77jQVycDW7UYz nXwSq8Ru3PUJnW2WM03a51xmxqpsuyZYvzFEUHFVwyjJZ8p2gVKSnfphLuAKvQcylwOf 4ydRpMcHjAB20+1BcQYjBpOmLj1GzVu1/CgZF7NSWB0maN0zECxGuxB3dcgSLqyG2vzC EZRwi3tMpc6NcgYkxj7IXWJ7XtSavxPpF78ChDZaOqG8kt6gPXDzPWNXFfwxy1kRJPZx yw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekx9cbpyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:35 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D6Jn9145484; Mon, 7 Mar 2022 13:09:34 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by userp3030.oracle.com with ESMTP id 3ekvyth2ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PXKQBMvE1VUwp9c+h3T8+Cf3mXt+nz0yua/1DUcW8UH650wFyTD+ON+8WfVtfW+jbhhL3j9f2Kv399X6dYo2uoYKf57Fcizz7VzZcO59nqxW8gRpoFODnheYGcwNplc3W2wibcP79QIhMY4flnlxJncBhSJ0+KqQ5eyR740l7pL37SqjJdBTYQUeTmfkskhnQBiPIldInHxvCYk/+5N4Nw5dJLX0tzi3RP4+ZID8YhuXQbha7KvvJ3Et/1pWF8LDygIWr622FCe9fbIgVx3AR2lapLWohjFvgEUgrfwGzlkOVgw1fMSsoQFAxtt9z1jcw5fVAZpGbOmoXPffERjikg== 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=sqLOkoAz9PLSjiTgvW6DexwmElDvxl0n2Zsg1OxtpJk=; b=CzFEIjYGo76EMkzqlikieGOyBr6zcJ1fF0TFTR/sfX8Nod5O8T4YbEb1Q8Xeze+4tnouY8XMEJymZUcTXnkp3qdvbo1RUEXiLykdjewlW2fmQd3Firks6TfoORYUiPIIQ7ymlItFmtp9czgLFFq5WbZNtIPkrPt4HSt+M8xz81FcIboXtqxiHi5srXrPAm8xvFifqLVczudIWjyiLER4SCj88MT5ZPhQAmUDRMT0mdgI3cfVAsaZIqAFZLOgltvayoSsEvd1/iuT1xJkRXlvWbfwV08rwLZ2uVx5/Qx3TO7oGscN3zek38rnof6hsNxIYvNjbb4aKsLWjX1yDlNZDQ== 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=sqLOkoAz9PLSjiTgvW6DexwmElDvxl0n2Zsg1OxtpJk=; b=WIpqLOFzBEF9nzMiCoYUs1Z6kmGNuC9STfLsDOA3nvy70IFjFeKjBv4DsDxcnLJSSLwpA3qnU6YV6C29Zrh/jRQaS6Jtys2tHXfocbjAJyA45CdmFsO/Pl2v4PGCzqF/d2PlfhMsh5LhbkJNHoKTA+P/XBLI14OgKA0XLLoyfww= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by SN4PR10MB5608.namprd10.prod.outlook.com (2603:10b6:806:20b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:31 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:31 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 6/8] qmp: add QMP commands for virtio/vhost queue-status Date: Mon, 7 Mar 2022 08:08:39 -0500 Message-Id: <1646658521-31652-7-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: 15954ba6-3c9a-4129-d869-08da003bb7fd X-MS-TrafficTypeDiagnostic: SN4PR10MB5608: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: fWiqyF8SVVC7DvCiABOTqdy6JBYQOml7EMGpQi+XrG0iHXlp1WD3pqgQLNKMZrrg08ESAos7m6XN2MlO7z0j839Vl1Je/MDQGk1vVN9HnXGpqV4r4V5ZLYCneIbXGe2BtSZuBA9fRNR4nTCedlUYZCW/vjQ556YoA7yM5ZtOhW7tD07lTkQN11Q0Gf//nzEPbDg8MhXg44Iz+xG193Xw81cV1MW8lq5oGOlTjpmpw446YYkU8T7qWXAfORw8+3B+I4NGbRnC5w4sO1JXVr6JxFQsAixzfj8eQSjESiHdKeXnztui1RUrRekpuEFuijLWYrujC+xHJeIS/n+ygqiZivEW53ZwTV74ltY0YZKvVj2t7vLYDEsBYwq8mKoug4AiZ2ZEKuUgVIFVdWfBkYyEjYtOKotzCSx971UHuPjGGz7Y/l9LpKjtaBwZyi6tMFd9HoZcitsXmXRzxnkcD5o16ky4HT67yR0zcYRCM1iP5zAAM1O4qXahgk/dGjiLMQadC7biqDojldembGed1zIPOXK0+1L0n0jLjjUW70LT0iLm+ZUrMjqFAyHlDNpQ6tlZVnccwNdrmx5c+O68kOhdUu+WjPc5Wu/Z1FSdLYCalw1Aw9iV93XighiagQtJr7v7+4398TMwLEQxqIN2STfCcLBuWb0Dt0E9fj0xGKayo9edvJWck+fYF+K9XlbTh7LW 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)(44832011)(30864003)(86362001)(26005)(186003)(38100700002)(6916009)(316002)(38350700002)(2906002)(8676002)(66946007)(4326008)(66476007)(66556008)(8936002)(5660300002)(7416002)(6506007)(6512007)(52116002)(6486002)(36756003)(508600001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9pNnj2vKeMy9fun3yHuTuFGgz4HFeVJ6rXT0S88xmJAaYklpAowb5iAiWxTWE5Cdm7KBdlVgWdZfL9GBYZgf3DQo6iJER0ayNtaYzSzDM4zBrj5brU35dKF+jBYnPPMJZ+jKM2F/Hh3UHQFKm2XDgzrU5VsJmdGmqEfePIuQHnl9TQcd+/9VT7m6Qv0Ig6CrcI5ZhmohIYzZzc0pXee0LwCIw9OBn8JNgzlR/UX61nBCnL8+271ZrCuqNp6RzLdUtrFAATdFZGWy2EPfpeLJJdhlTq7WNQV3j73Ri3XGDNw7Iqoi70WggVPkrVawDyvyaPvPYnb8L+B1v1u/Wrb/GvSppR10jNL5kuP/wApBK6BqIBDsDQoRW0Zb1x/zf5eXPn3vqECgV/t7jzSSAcfqyL7bl4cfrTzd7JuqBJGsKzFgAGO7XSp6X4fYYRkKiR/NflkiJJB+CrzBvDMd499VhZRUYi6LmAEiwYVtPuGb1NhB3JqDDKnwDItrVwxY5wfCsXigyTSaJ/MMsUN4ojhA9FVD7/SLCfAG1uOf7+vJpJs4TNi/xxWsIF5/bXeRP7jLJlH9a3sB5IcHWzVRRzGU3jNXyWwNwa5A6WZje48cjowBidktBe4BjF1FN26fkApCVpKOGPl5kg4i7W9DId0ykGTli/XpF2LBLeGEpKqU1Z1btjnfPRcofZnCQUqzsLLVBNqJV2NB6nzrf9FZR3RuSJdr6iMqMpGQATTHbTaeVtGt8SGhiDifwqEMwms4o8WURvsa/CZ/tkG9OTbWmtrWsgllowtqw9isqlad8Pbt7kHQZ1dokpYFCRrTdlPlglgOR7snUzWcVzdyOSkbYTqcLpTFnIMQtm1fy2Dxh3QPuoz5Ey/zfBYIaYeF/sWlm5/JlW6V/iwRmFq7W2eilk1VZIad4+hJTaOhtkgQyZTYapobSRT2lpdfcUJv3Evssr7yjIbN0FEg8dSfbF1fu8o+PphVZ1aPBaeawgn1MiUdT7knF1U9Ijehv5VTgZ6GRmS+gvjdJg4VZ0KYgOAJTaKd3RHgmIBi3EEt2YYRQgenFi7CHGuCQm/OztFMO/1lDaSwzsU42wpx3asw6Tq5t9nGTYZ8R+LejagxQG5XS/mssC8XbSwd7qrrlWQwOtcYDz/mD6bGrwELAmVpfG5r33MwfZn+lyzwNN7YmSND9oi0toTvf/hXP1v5Dvljx7o7YbZ5EnP40Gcbf5sEvlB8LJtrZpc8WR1KlNRK/Rj7UTV0qrBz9qhhLlgMTuBbEkyqWSviTqoPWYwWBbBANFeCgOOnwlVDG6k5TVyEniAWzOCy4WrNBGL2Kvp5XS6PIf2BOR+5VjjD7ad1PSjey739UnZoWX2TAvFE7cyiaX4Bn2NHb0fEwnkSyLoabPUj2u3eQ5SlWsQn9IbYGyJl75f8gdrbJyJnKwhsHJdSOagFJOgA3AOM+/lBMCFNlc51tV5gBzvC6xN52pKG17VvESEh3dodlWBAapskBzd7ccLWYFRYIVWzavEEIUqtItO8t9K4LWNZ3LNR9qWVXuVk+MK71Um99QT6GHw87bO0rlyDjZYdrzZEDcfxg/47a48y0RE3TJy7Hh7b9aMq2vWBKjgdVtJBw4LcTMhTt26a0A/zxSED9lc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15954ba6-3c9a-4129-d869-08da003bb7fd X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:31.7701 (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: a+10gBCZHqwZ1MjSFt1wsRCCuHBfe49yGiw50nJEiHadSAlA0VNPIpGrtyrJF71svyLa8cJLsAanvfY/Kv2e9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR10MB5608 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-ORIG-GUID: 9gZTJla0ThRWOYEfKj_NNFNgxhGN7xqJ X-Proofpoint-GUID: 9gZTJla0ThRWOYEfKj_NNFNgxhGN7xqJ 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 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 0b432e8..13e5f93 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 ccb5e2b..8723a53 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4312,6 +4312,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 = (uint64_t)(unsigned long)hdev->vqs[queue].desc; + status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail; + status->used = (uint64_t)(unsigned long)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 474a8bd..44cc05c 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 Mon Mar 7 13:08:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602176 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=y03W38dE; 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=c4LMNcnN; 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 4KBzmC5THMz9sFr for ; Tue, 8 Mar 2022 00:27:54 +1100 (AEDT) Received: from localhost ([::1]:54252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRDOw-0000VC-PZ for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:27:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7i-0007Uo-VK; Mon, 07 Mar 2022 08:10:03 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:9416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7d-0000Tg-4p; Mon, 07 Mar 2022 08:10:00 -0500 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 227C3Ert009954; Mon, 7 Mar 2022 13:09:39 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=hTbMIhzgjziEEPk1Affun57zuvtGTjdTHq76al7jlqI=; b=y03W38dEpP8lmjTVg81sCd6DqD1Q8wgdM4NRd6mhb3HjAS8N3S0OxBb7kg7LfYufVcI0 ezLJsbABjHmDvUyAz9wKg/1zjvabdlstTnU68KFmL17yINqtYU2hizy+PRtoS19mXJal q9lNF1i0gtK1rKsoPD/fMXZzr47+xgzM30ps9YZADiQrV16XeHzQvWnuDYQodi4Iaps9 GsgmF3oyoPL5sOA5fyIOfujGaO9nxICc5uJ3fJTxIKREeYySnQVvz/jQYmNHRpXKBcmF yIW4EQQ5aCQEROQigvt9J6hIMgF4nxhbj9MTRZwQhUnrDPEOgGugQKYDO3Ux5BsgryBH jA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyraknmx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:39 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D7FhC063397; Mon, 7 Mar 2022 13:09:37 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2043.outbound.protection.outlook.com [104.47.66.43]) by userp3020.oracle.com with ESMTP id 3em1ahyv0v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ktAxbTzsAgkj/hJDZQW8KKrLrhhsxc1QrPHTDl3iruGpgJr/jqz19SnEpJy01yet0IlzL84lBFqfV2sLo789SNN6+oLYZYORrslef6mBq5Sm/kVQhdauAZFciwhBXWj+f9kwIHBkqZNwQqUtSsLMWUJQEmnVRZ6w8RpDaRG7k9uMfrotAkambKKqpmTsxlVSS0hE7iSQHjJA7xBn7NZq/TVECcGj/JI0W3sTrPmlxW6dJjT8rDv3ZqLK90REUaIHHAfgO2+Y4USprPsGMNrE9r0zIqgYb23CrVwNT/nXo9Z8Db2mxc+EwdRGR934lHxKCAQw4PrXjklBg3aLdC/zyw== 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=hTbMIhzgjziEEPk1Affun57zuvtGTjdTHq76al7jlqI=; b=bHrZsJ6gvQN9+9CjbSj39okKjYh2r21UeWmD0LcWaFNibNFIEJ9upX/8aJbwOM6prDCtXrO/9ArEpGdiBWkDdeXZDbe8JO5qHgfUih0JQ6hWVHv1pgUWo+J54LOHQmnRvfZxs9oFNWdBnhM8wj9vU57vvrWMfujFgfHL9WgvfGwcEqDmLAvtyjn5dcY/zWYj9OSrFebQS2x7YLXREFYTz977HIdadUcPXyqpV9niynjQstrzuENk4/Q4DjNq+pga4g1FNRJoJW1tvzenTQkEjd12GZhncZ2EhK0Qnu1NS3mAxExWDrRlGlRfTxrjAvx5EF64HqfUNXfnHkiu/p9O9g== 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=hTbMIhzgjziEEPk1Affun57zuvtGTjdTHq76al7jlqI=; b=c4LMNcnNc35WFXw/9HxRsZkV1BFn/+OjG4nYQ8/TGQWuJOMSGynuz+4KNnfuQAFajIMaSknuwx6jB08NkYYIGvk1iuCZBJ2Z3FqbQsNpLD7wry7WsjnOtK9/K9+KoCkc5CS4Oq73RsatX0TkdooA8RpF+A3uLxqDtvhL4Q/wqfU= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by SN4PR10MB5608.namprd10.prod.outlook.com (2603:10b6:806:20b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:34 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:34 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 7/8] qmp: add QMP command x-query-virtio-queue-element Date: Mon, 7 Mar 2022 08:08:40 -0500 Message-Id: <1646658521-31652-8-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: 8dce7e8f-a24d-401e-5847-08da003bb9c5 X-MS-TrafficTypeDiagnostic: SN4PR10MB5608: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: 4xiqY5Rt1EoLulVQ79UYq8pGpbQt6cokkqTI5Ve8dNITZMhVjjSsj8ENsxPsfWLQadEqQ5gRWlUJQ8aBAf04b9JKiLsXjZ3VOIGZnOcRIKV/JiuOTWtV8xJpNflJGh2sxzSrGImNBk4ZXXT8NLj4NsVefm0TZd9UY8LjBuKM2aThHAY1iZ6LVIA5pFqJxKvz0OcZ+pRQCNtTtmRAxl6UlV7rj5KDpbWFC6XATwJyJYVoxkXzhy2XjAYQheT8xc3l/FoXdyAr1zP0R0c+p4Q9e/ZCzP6YB/KbBRTjOs97ils1vUkCkKiRz4JNovTFNV3g4xlkG5wWFE6EDoead/1bwKZxt/dUwXLEwzfEPBuCzRgyrJm1Y469HfY5ACenhPZY8R0YyMxUEnC0q3RqbwzHd8xpe/T1FODqyir0kpMeSaPOFrLgYG+nr/deTjPoDJmgi4rH4qo8yw6Ztp09YJN0QJqwvoVtiiJvdSs226A0jZ1UvGnVJX17aJZekSZmFbRugdBLc2fJ/dIOs24oemq/HqDgtMQ1rwJ8jfHlxhxWKs+nT7QVHWjhULNx3TjMQARekRCiH2lQ89KUa3fuw8z/PrD5zWlGruOXBrd8ykwvE12Dozm7Dfz5vr4OeS6hM8CglQZv6lbawi0jj3Hrea6ESkfH0LMLm76D6/IopRlGyeQ/VdRhL9oFIzL7M2H4rW07543i6DEav45wGzaPRkQySg== 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)(83380400001)(44832011)(86362001)(26005)(186003)(38100700002)(6916009)(316002)(38350700002)(2906002)(8676002)(66946007)(4326008)(66476007)(66556008)(8936002)(5660300002)(7416002)(6666004)(6506007)(6512007)(52116002)(6486002)(36756003)(508600001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Hlo835RQ/1Zjs5gIXa6OIFOcNiz/Qvl50wFs4VrKimCyXo+AFiC/7gblPrBLk5pknavArAGVY/qWl7Wp7xbkgZAojWJ0s4FWjE340yh6xIKKw3lcsUwUKnpO3WUBh2N/LCKt+odJiquuDwNM2gBTAEKxrepWUMb4pd+CzkmNmpgim3FdskKXMkplXT29OCbd8fdqrTasqFgJlZC4nMw0/BV4oRTBSj6GnI0I9LaRyUITfN8DrtPxWvHmc8SypPFPrOOFFCtPDhnqCoHhigIeYOLEBA1FXAm5a54FeWgumlBlLGQVehRVsUOz53TtG4J+cvgIKrUTzBBo1WkAr3iGPbtMqcTz8mkMjqOKjQQgxsqAU49Fv+n1PhQyJA+faYeBuZ5JfkHxHnUMwT465j9wA0xBNVRQHPtp4YGEXMKzmAMla27ubv0KXLWhYGQJSLFLaF6WzE+fb2YsEoFd7956Fbm6kC8uXdujGkdLyxAr66h9lQHYvm8VRtaUfBTs+ycRctuUANk6fO+Qcd9r5iTAdnKr3fh7uqG9SF+Sk0SChSb09ylMt2gsvLS7u6fBQc3MxemUAeWfEebRsDfhbu5NAn/cN8l2LGGecJA3wVugnC2A1IhoMNr46ZeXobgvv1gWDaWpffYairwDqLnfVkWT1NNY3fJm3rE+qPexQpadZJ71HRFWn21Bzg5QFTLo5UrGeegm9SzDSGBWOG//hUQWhdX5DsDI8akzrIITZg0IoYazLHmS0uG0jcG+Q3eywreHN/ymQRjChklS0636Dy3DuWdGxml/gvojwOHf8GBw/Rm/8f7vhENE3s0RrVqyg5JCBX2x/C6LLJ28yOviE5+qHGOVCV/jcvIrtnWmfwp6vrB7L5JzE9njCv4ruJpN1J2cXTqlGyoOx/4taCRja59ogLk3pNvLXa4uf7Ub1uEi2T1J5vInLixVVcLksxwRTSJRu1Kz1u/PLZYS/doeCkIqpKux1RtiUmkJfxOlfqpAzc+SxLWIGPa0+2t9ijLAPUsg0T3soRicxFYCm6coyT3Wj6ql1F2orHzkslta/Z8Vp3BPrUwF9F5TryvdMh4NLzBf995b2gxXTiUdGOOVZCS3CKX8PQUJDQpUa3fSgon3n1dOiRLZ4a3jpy0rQ02kHZXJ3KZFu32MjH3GLO8KLMkmp3KHuUhB87q1DfgpvOyGZ0ZkAirpPwJslZV3zfU64EWZIf5PLjW9o1A+OnTT8u4DX3xQ59OnpdbeVjkjbD34xABHH/eAT4vASdRaSAt+/JOVuJahAH6LyxPsgMqMxVcMoSurAix3FX/PTYqZPLfMtUEFgcsCKdIoYeycw2/J90PPbnGVBD7msvS7woA3/p88cUlZ3ZaP6lNfskwzge4/WV28IJNinY62mRZqDpprHdQo8iBd28qIlhW3hHBOTelpVp7oqYj1BLeD0Wsx/GtbHBl2hBk2dz6Oak60JQ2fvxnqirDusY46rHWzNNLHs2f6iZXKJt+gGvfKu/pYecFs9NuWzwn8iV+UNdqX68Idenk//f7SB5MT6IVlt5Y9mhNLdYQa/mkyVlzC7e6zwLos8oO7hbBlP9Mc7Na/apEfRdckPWvyRRQHiOymAVY20Jq6I7y/809Sxn+kvfe2yBF41jE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dce7e8f-a24d-401e-5847-08da003bb9c5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:34.7384 (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: wQqnAHmTU/eOpDG/F9miixUkKjbI3209GWtt3L5DsBOth39NcYCOS3vDPRFU1Zn4/j1ksmh2N1RUYFMXEg6tlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR10MB5608 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-GUID: lTto94oDzdFdL7i8Rn6eSTUEWM1u6cYE X-Proofpoint-ORIG-GUID: lTto94oDzdFdL7i8Rn6eSTUEWM1u6cYE 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 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 13e5f93..7ddb22c 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 8723a53..d45b8dd 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) { @@ -4415,6 +4428,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 44cc05c..99b9064 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 Mon Mar 7 13:08:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonah Palmer X-Patchwork-Id: 1602177 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=EYws1TOF; 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=PKjuUCzU; 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 4KBzpT1TBzz9sFr for ; Tue, 8 Mar 2022 00:29:53 +1100 (AEDT) Received: from localhost ([::1]:57502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRDQs-0002iJ-Mu for incoming@patchwork.ozlabs.org; Mon, 07 Mar 2022 08:29:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7j-0007Vh-Aq; Mon, 07 Mar 2022 08:10:04 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:15504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRD7f-0000UV-BU; Mon, 07 Mar 2022 08:10:02 -0500 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 227BtvLn028756; Mon, 7 Mar 2022 13:09:42 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=b6cRhgofTg3110J4mbquae/fhanGaPcQ+PGh5VyVeO4=; b=EYws1TOFFyGRL2yqV4CM3ooSw5GS5XyFWMYEDYJLLum/23qX4929bHwmX6WB+V42+P5x ABM+OTArKxQOGVSIMOgsolOaj3qLwxgb4YYRezL3vTgmCyWKbkmlPBFTPbGKJ6+8JTA7 WQmmZ0lEugyjz6etaXiXpi5irxrz1zM4xQBa5EsytdP188QVFTYDFJyX828D47Nj/PYZ CdhZak3aS3aQp24wJXrzEbcWUltR3SLjVIg88JXM2X6hN7FIkxFtDxGQPVSCbj9G5sK7 fvFTR6uzCgezFvqxBxA/roht0PcsWfAdK4aSfuRO3wVPgG/HzmGugpWOXo33qcVj+mYZ Ug== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyfsbpgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:41 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 227D6OFP145635; Mon, 7 Mar 2022 13:09:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by userp3030.oracle.com with ESMTP id 3ekvyth2c4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Mar 2022 13:09:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C+NT8hjJ1znfUBjCZIJOpCS66KpslMLnBliYLstPYIQTjrWPIweqYiqtFFXw5g41L4NqtIKcbA8S34YOgM/tKqtdIw2JoGc6dP3V+JBtgAaa6UZyVXBhMwCvKu17vZlPD8tCVvEO1InQoM6+YmsSaYGPnTT226Ig1cUfZIsJ6ASVDJ7bTDfu1MKSkrwbzmlLUcidtd8uaKusYQ1wP1CkWDJANyza7eIWAK6wo8dakwdMN7ZSuey0e1Ab+RLB3uU3+2SApAstNwm8mfkXZmyGCRQX0TgLrU8b34ronw9FsZD43TJzfRKD4C64aR+6YuASDsygGK1InoaN3ZU22kqcvA== 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=b6cRhgofTg3110J4mbquae/fhanGaPcQ+PGh5VyVeO4=; b=M3SzSUQzwn/ntGc7B8ikKDWP5OV0HsOevzWoFdj8CcvcARyquCvlSbkt+1C2VsS6AgGEwB47jGvoxK9R6JPAh3+rf0hsH0gKgeWdXBvxUm5ZYhyRoshmErls5lHdwokRefq5sA2lK3J0ZFayujrekN1BaPNDtWQ/ucRY+ij7aK50q9ygnTan+1Y6MXrdSTAM9izwFOJVWIoI3E3SmA8ebEbcLBXYXAa+u8QoiMpDxgKsvwF7RO3hpRRB0HWRiAW0wvFacMNd9NJX0b/+8w4UUFYjgxc64f9Ul4nlHpfz33Q7ufPdDe/uBJgrawyKxlhlkUHRYgbK0W3x9UkFrjxEbg== 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=b6cRhgofTg3110J4mbquae/fhanGaPcQ+PGh5VyVeO4=; b=PKjuUCzUS0/0yggJccDajwStFPwSBUp9IIOwf2+6fCG8mwVgLiRwpqrl7loadbJB9oodZMvR4voS8AyWp0FD6kLCPbiWo88Oz6AC88GKx/6wSOqc71bZVLAVeMJTk7WyMsJfCXskoHjyqxdEFSv6gT6axCXwu+tDA6VF8wPT/fc= Received: from PH0PR10MB4664.namprd10.prod.outlook.com (2603:10b6:510:41::11) by SN4PR10MB5608.namprd10.prod.outlook.com (2603:10b6:806:20b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 13:09:37 +0000 Received: from PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85]) by PH0PR10MB4664.namprd10.prod.outlook.com ([fe80::500d:126d:b54c:cc85%7]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 13:09:37 +0000 From: Jonah Palmer To: qemu-devel@nongnu.org Subject: [PATCH v13 8/8] hmp: add virtio commands Date: Mon, 7 Mar 2022 08:08:41 -0500 Message-Id: <1646658521-31652-9-git-send-email-jonah.palmer@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> References: <1646658521-31652-1-git-send-email-jonah.palmer@oracle.com> X-ClientProxiedBy: SN4PR0701CA0034.namprd07.prod.outlook.com (2603:10b6:803:2d::15) 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: d70f5480-e2ce-4fbf-c366-08da003bbb79 X-MS-TrafficTypeDiagnostic: SN4PR10MB5608: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: id8PPUMucPGiwGYTgayKwoeCwJybIs/Y9+d81vrxReEmn3ex6rC+UFcKJ5b3wULNAYWp2dRlO5KqmMiOn/KRrF8YD8dZfRI28QjcdG/8lKtE9AUWKuJOopPecVByd0I3Kq1admRt9dcjQpPzVmEsJI8gLGT/xgMdwNMxEPKhEcI8DKnLwEgPG2wo7Olto/OWqUTiraEd5xdlM/1rXpkolpUMpNYJVzl9pD0h5tw29Y/ilEW4IuTwSkkqTc5FNmqhRFEkV6Fm0YBsCxXj5ohYTB2V0Xf065dygl8A8ggr+GtOXDDSJpZY8qmrCHtKI0wef34CtQuc2BwmHfy2ESM4d/TWZs3+eFqnipehvyZrLszy4KAoT1wJsumPzn3GsaMqQKqn63bx4FWX0Q9Vq8i3FMuIcS1oCOlj0XpfiNbNgLgAApklfmrj+/miWezVy1ywTcX0gWTdausNHR6M+bG61DQpkhRDXGq/MA+CFSkX+MlHkeFiJq71KEVlyZEQFuZMUW0R+EBSY8124NU3NIHiDKnVuAO72FcEvYtfo0viDmScsp/2+pjHe/8S1GMku81wzPHS4+qnYq4LuBCNqG8IZz11dF0Hw4Dao06xiEmT78p0mMatTe8VEmRodCWnxR0Ld0hFVjADyHAlzVSXaA8ndu8VnAHzpAoLwYH82krkQMwmnNUNgdiUI5vGXRjjmRUiW7DVpdkPKImVDd7bEL5m7w== 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)(83380400001)(44832011)(30864003)(86362001)(26005)(186003)(38100700002)(6916009)(316002)(38350700002)(2906002)(8676002)(66946007)(4326008)(66476007)(66556008)(8936002)(5660300002)(7416002)(6666004)(6506007)(6512007)(52116002)(6486002)(36756003)(508600001)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FC3EGs+v0dgm8I6Ppbq7yi06nyPF5uSdjisu6rfnEo8paBEuLv9c9GRcvqp5hCTIaCJvcT8OG9jCINim1zrjaPu7XO/2SlisxmJpleKgOuKSqSq8LpeRa9Es8fI7jAnUnvElVPn/US+IQaNUdvH3mKQCZnpuVSCTdSyX71BURReVx9PMtsPLpiNVOHBQsvXoWnaLHp5kC/8+v/3BmybGtacua98b2UgNHT5BbYLGTj+D9ewz6O9S9E0PXSptsTZA+tpWeRsvv4rhzsVsW79ENRcK5ur12LM2gYP8as5h0OIRqrmrAEBxF3WPAlENh0M1xgBdQmEtM/fiaRfmhGjs9BzxqlNGpVVT/4lkp9MtoaN7kJqFFsmu4Gmazc42ileKgexT4DCx0Rq6cgTMac6abvAhgKypOS43/chyPADPcLi3jRVkw4MO6r76Ik52DQ9PGlJMwfAcbobkURZq/YRJf0n9gN/KJlZ3bSBZLeL6rJkHqvT2ZfsINmTVIwgXmump8c8vUINgC82LkV0og3t/clFC4RfSrYkC7iZuDq39TmV0bsBi0734wM78xQdkA1t0BpZFIuaxHhDgH8aPElFElI4gFYWtWPROr0KIVDmmREzhknSO7X2mXG8LqLqSQF0gDIVXPqgGTGPxkQ7wih/iWy7XXiwpht17dVzDdumUP0sxAgqYY6G5P9x53Rqbng+qgZDJllKqCzIm66yEdXV+RVyBL5nGGHWEvoMdwiL59XvKU9ZAdO6uYaiH5fqdWt5oC8i/hD8uwh0gwGmpBdzE+j5OhteGuU+fuFzrqyZdOl2i1gLDpqPh2dW7xixjcwUiTSmnviFyacYo347xAWHMUQ2iMm9k14aCrkRdp67v8A+3HBkshq6kUJVpDk8PJevENu0esBuXvmKqee4UCulL9S7yjayfQWDCZtZs9OZrMV36Nq+znPlNLBlqU/bRqNj8SwDfqeIc29VT6MWRj8xGBMpgvw80/5Qehsg+bwmS8yYYfwtz2XheZnQUq0oQ5ATJqkiHVitGLvxqyYJj4a0pRGPrwGodIiRG79C9ryilCG1mnyM358zrAHBnz2sEkx8kEPEg2aTADd0kdTB4/JQUFNHxyu0tjSz+GgZ/iOQFTAL4trFkB45AxfURgaKWsVizQ54TAMQkbbwY34mnd70s0pfgFNlHoXUGrla3c4GCTyp3sVOAOMMgn95d78Bun75fwUtek8Y2XdLTXai7CO8Q+1VqQqibVOqrG1M4CPlq/i6x59dKbz+jKLqDvNXP+jCChmSroFQRuiAMp05LPlW1SYpUIoqQxxaPDt5H7L9BXCm7jfa+cpvo5LZtudT7gLNqMyM6VstYII8EaXqj+zINEDClClVPDQF9FT5UmtDp22nJxp8kI6C+BFJ3AnniQ5o63UoKW9QSiEU7RZLiyig5NUn7N8BR9z1GCgWCCk6cCiC06IyINWyoNZolapbDxNxEBVKabZxcC1XQAAt6CYG3YNHGDb65TLx9IUSRj8hDimdjtoHyWrNJdZ32prTAc1bYZA5WBNLzFsCKfB6PQIfeDrtKkU5dnEAZke9qbtD2IP37i+YlW6PcKPd3BX3bP2eScaS/DVVduCzh6dz328V/28+Y0nFnFVV3CwqqLHRKNL0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d70f5480-e2ce-4fbf-c366-08da003bbb79 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB4664.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 13:09:37.6454 (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: anv+iCdC/H+QPnFf1AH2CXxfXjYvvLaAeCJbxp5yveXFXo/eNV6bWRwW0A1Mg8hodo5ltRVzVR5KcdkCM8aJJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR10MB5608 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10278 signatures=690470 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203070076 X-Proofpoint-GUID: NNkk8dxUNLqUULcnWBB91twkAEKfDzTz X-Proofpoint-ORIG-GUID: NNkk8dxUNLqUULcnWBB91twkAEKfDzTz 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 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 e90f20a..9bd1ba5 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -879,3 +879,73 @@ SRST ``info sgx`` Show intel SGX information. 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 96d0148..47446d8 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 6349684..2689aca 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); +}