From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571825511; cv=none; d=zoho.com; s=zohoarc; b=Tai5gmmRIBXwnmpFpYJsmSNwEPv2m+1FNnua9yFO72BpqTp/IdvbXCE0Kz7HxMnETa43kATyqDhP5EaAec6sjRBliIrLUCqPVga/7b/+MPzjbtt+8Fx90XxEnFfY5A9tDiB4Gt2Dy4cPqTKMK8mXHd9HekT0ju0oFTAJSYwNlSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571825511; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KplCgtoUX18u/KqaA+dv9ZMhPI8gImaSkBohz9iZAQc=; b=AZtkRRfLbbyfhRE6OY91bNrYy5OTADqt9bzxDdmK49QcpGdPFfeznwq/xyEJ5yk3CriuRCWFAuB6EhrXZWzblhGSLyaNb2R7JQxnJZaMJwlRGofXCWD62wtXReO6tMhO8WmhSKb2le6/SzClqtMFv1bLfS5Tc5IZR4kkhtxZfjM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571825511508931.1905528100266; Wed, 23 Oct 2019 03:11:51 -0700 (PDT) Received: from localhost ([::1]:59786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDcH-000752-D3 for importer@patchew.org; Wed, 23 Oct 2019 06:11:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40022) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWd-0004J3-NX for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWc-0002Fo-3W for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:55 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:37210 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWb-0001ar-Ur for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:54 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-1YLClgQhPs6IwtrjbxQPUA-1; Wed, 23 Oct 2019 06:04:54 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9EE201005500; Wed, 23 Oct 2019 10:04:50 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF1531001B33; Wed, 23 Oct 2019 10:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KplCgtoUX18u/KqaA+dv9ZMhPI8gImaSkBohz9iZAQc=; b=FxhnoL0fTceZd9dnkBoyZNm0hfLpoDKUfbnAO5VP3r5XHdfBDty6InrZ9ddCun0aNxA/6T r1b9Kx5vUtfYWQa+VoyNirGmTDgNChaAP9Vn78AFrpA6MLav0eK9OYKUoDbOw6QizrVyiM acMjzRunpMhkTPQ8lC4eDGlVJrig/AU= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 01/16] tests/virtio-blk-test: read config space after feature negotiation Date: Wed, 23 Oct 2019 11:04:10 +0100 Message-Id: <20191023100425.12168-2-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 1YLClgQhPs6IwtrjbxQPUA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The VIRTIO Configuration Space cannot be accessed before device feature bits have been read because a driver doesn't know the endianness until it has checked VIRTIO_F_VERSION_1. Fix this problem in preparation for VIRTIO 1.0 support. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth --- tests/virtio-blk-test.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index ed13167392..f6674fb233 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -125,10 +125,6 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloc= ator *alloc, char *data; QTestState *qts =3D global_qtest; =20 - capacity =3D qvirtio_config_readq(dev, 0); - - g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); - features =3D qvirtio_get_features(dev); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) | @@ -136,6 +132,9 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloca= tor *alloc, (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(dev, features); =20 + capacity =3D qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); + qvirtio_set_driver_ok(dev); =20 /* Write and read with 3 descriptor layout */ @@ -359,9 +358,6 @@ static void indirect(void *obj, void *u_data, QGuestAll= ocator *t_alloc) char *data; QTestState *qts =3D global_qtest; =20 - capacity =3D qvirtio_config_readq(dev, 0); - g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); - features =3D qvirtio_get_features(dev); g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=3D, = 0); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | @@ -369,6 +365,9 @@ static void indirect(void *obj, void *u_data, QGuestAll= ocator *t_alloc) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(dev, features); =20 + capacity =3D qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); qvirtio_set_driver_ok(dev); =20 @@ -434,8 +433,16 @@ static void config(void *obj, void *data, QGuestAlloca= tor *t_alloc) QVirtioBlk *blk_if =3D obj; QVirtioDevice *dev =3D blk_if->vdev; int n_size =3D TEST_IMAGE_SIZE / 2; + uint64_t features; uint64_t capacity; =20 + features =3D qvirtio_get_features(dev); + features =3D features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX) | + (1u << VIRTIO_BLK_F_SCSI)); + qvirtio_set_features(dev, features); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); =20 @@ -475,9 +482,6 @@ static void msix(void *obj, void *u_data, QGuestAllocat= or *t_alloc) qpci_msix_enable(pdev->pdev); qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); =20 - capacity =3D qvirtio_config_readq(dev, 0); - g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); - features =3D qvirtio_get_features(dev); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) | @@ -485,6 +489,9 @@ static void msix(void *obj, void *u_data, QGuestAllocat= or *t_alloc) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(dev, features); =20 + capacity =3D qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); =20 @@ -584,9 +591,6 @@ static void idx(void *obj, void *u_data, QGuestAllocato= r *t_alloc) qpci_msix_enable(pdev->pdev); qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); =20 - capacity =3D qvirtio_config_readq(dev, 0); - g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); - features =3D qvirtio_get_features(dev); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) | @@ -594,6 +598,9 @@ static void idx(void *obj, void *u_data, QGuestAllocato= r *t_alloc) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(dev, features); =20 + capacity =3D qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); =20 --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571825674; cv=none; d=zoho.com; s=zohoarc; b=nlytIlQx5WS5AmYES5uWRgLxnCCZixjVm5P03upwAYqu6HkdslHjjOtKF/iRO4U8YmErie6pDXGAPBB36fl/qPVitz1njZZhBV/VZqJR+wpDQ/lYHEY67KVgPW+yVShiES2jIn6rGKdtPijCM9FRynTosSNI5CxJnfODnEAfJhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571825674; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aYsc5mum1o4gRIE85H0CUa+0yJfvF3Wza19cnnM7g3k=; b=ESOVBbfkuiJz8VQMTtp4ag2FmxeHlNCdMhxMajGdtQrgOMZ3r/BmO5joQ7o4LXsPNbKxb5yNcHaSUlo6NirZq9VmYyKkoVC/2OE48prMQT0fiaSafLlUZOfeEhdNnyJ1P9Mb3XhCkuo6k7oxnv6tMvWTomsM/0L8ybvblHiyGno= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571825674842812.309271039047; Wed, 23 Oct 2019 03:14:34 -0700 (PDT) Received: from localhost ([::1]:59838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDez-0000mQ-H7 for importer@patchew.org; Wed, 23 Oct 2019 06:14:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39948) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWb-0004Hl-QH for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWa-0002D1-Il for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:22757 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWa-0001hU-FW for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-X2Qeca0LPraN5xqF66CnDg-1; Wed, 23 Oct 2019 06:05:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 031761800D6B; Wed, 23 Oct 2019 10:05:06 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id E66455DC1E; Wed, 23 Oct 2019 10:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aYsc5mum1o4gRIE85H0CUa+0yJfvF3Wza19cnnM7g3k=; b=hRC3S/PQzutNLiK2pWEqfVS/oVZLAGrHbqE6j1RXU3gcdPUESWnPVQc9f5X77GIbSgWzkB iF657uCwc8wW4XHtbokSPLeAYsDAhyWqasbxEJxA1JQC2WhVw4/HdDa9wbANcUPKqVHw6C 3dtesKSh17UwxhDe6LLmJy/PxXxpQzQ= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 02/16] libqos: read QVIRTIO_MMIO_VERSION register Date: Wed, 23 Oct 2019 11:04:11 +0100 Message-Id: <20191023100425.12168-3-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: X2Qeca0LPraN5xqF66CnDg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There was no real virtio-mmio ABI change between Legacy and VIRTIO 1.0 except that the Version field was incremented from 1 to 2. However, QEMU does not allow Legacy drivers to perform VIRTIO 1.0 operations like accessing 64-bit feature bits. Since we will introduce 64-bit feature bit support we need a way to differentiate between virtio-mmio Version 1 and 2 to avoid upsetting QEMU when we operate in Legacy mode. Stash away the Version field so later patches can change behavior depending on the version. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth --- tests/libqos/virtio-mmio.h | 1 + tests/libqos/virtio-mmio.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/libqos/virtio-mmio.h b/tests/libqos/virtio-mmio.h index 17a17141c3..0e45778b07 100644 --- a/tests/libqos/virtio-mmio.h +++ b/tests/libqos/virtio-mmio.h @@ -40,6 +40,7 @@ typedef struct QVirtioMMIODevice { uint64_t addr; uint32_t page_size; uint32_t features; /* As it cannot be read later, save it */ + uint32_t version; } QVirtioMMIODevice; =20 extern const QVirtioBus qvirtio_mmio; diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index d0047876a8..7154b03c1d 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -223,6 +223,9 @@ void qvirtio_mmio_init_device(QVirtioMMIODevice *dev, Q= TestState *qts, magic =3D qtest_readl(qts, addr + QVIRTIO_MMIO_MAGIC_VALUE); g_assert(magic =3D=3D ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)); =20 + dev->version =3D qtest_readl(qts, addr + QVIRTIO_MMIO_VERSION); + g_assert(dev->version =3D=3D 1 || dev->version =3D=3D 2); + dev->qts =3D qts; dev->addr =3D addr; dev->page_size =3D page_size; --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571826278; cv=none; d=zoho.com; s=zohoarc; b=ZbpiMeD0v69SJgp7d5lbU7CHfe5Ds2R6lOM8uEs62uevlcsDUGg0mXC2vZvS9vGxtrA67sh0QrFzIQohMzQiIs/qHQo6rCGUStIp+5/ZSfg0XL7TfDx354Y+l5s6QJZ5zPeztiMO3WND5zd+/u60eJo7814NmFs3iOgKn3XoAJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571826278; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uDAf/lhMZhR1n4KRYhD/wn+oD6KKdbWtEwZje7sPGyE=; b=Jaq7bf5rpMByrFnC56i/PhLdMgI4woQchHfh//8hg7NRGrBcHUb4ttvwg88SrgP2Qcf67Puf4c0r44f91PODWsPTRZkaE8RY0Kb2kHMoTm9CXlbyO5hOvMBqpiM/dn9ECTmzYpV/W7msdJtCpoQj93F4ygpdfiaZlDI6/5IsK7o= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571826278339761.6089619839425; Wed, 23 Oct 2019 03:24:38 -0700 (PDT) Received: from localhost ([::1]:59946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDoi-0007vr-Lv for importer@patchew.org; Wed, 23 Oct 2019 06:24:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40032) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWe-0004JP-3U for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWb-0002Fb-WB for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:55 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38473 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWb-0001sl-Rn for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-4--Ku_vsafO-ObuGqHGkTMQA-1; Wed, 23 Oct 2019 06:05:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5189F47B; Wed, 23 Oct 2019 10:05:19 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 646371001B09; Wed, 23 Oct 2019 10:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uDAf/lhMZhR1n4KRYhD/wn+oD6KKdbWtEwZje7sPGyE=; b=e+bXTYPKDG4XU9m+3mMFSaH1cFsGvU8pCi2oiFPRFwtebcBvUEUJh3ZbemN9BvMErPqDh6 +dIA9wFh3UjFkMixENZWu+ACS4wrko986umNXTpL7lr8Szpn4IuZS3vze/zUNAYqNt1uGl tA6OKyyNXwM6FgRmZTNCUtm8qJ9tTa4= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 03/16] libqos: extend feature bits to 64-bit Date: Wed, 23 Oct 2019 11:04:12 +0100 Message-Id: <20191023100425.12168-4-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: -Ku_vsafO-ObuGqHGkTMQA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In VIRTIO 1.0 feature bits changed from 32-bit to 64-bit. (In fact, the transports allow even more feature bits but nothing uses more than 64 bits today.) Add 64-bit feature bit support to virtio-mmio and virtio-pci. This will be necessary for VIRTIO 1.0 support. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/libqos/virtio.h | 12 ++++++------ tests/libqos/virtio-mmio.c | 28 ++++++++++++++++++++++------ tests/libqos/virtio-net.c | 6 +++--- tests/libqos/virtio-pci.c | 12 ++++++------ tests/libqos/virtio.c | 4 ++-- tests/virtio-blk-test.c | 8 ++++---- 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 2cb2448f46..a5c99fb3c9 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -13,7 +13,7 @@ #include "libqos/malloc.h" #include "standard-headers/linux/virtio_ring.h" =20 -#define QVIRTIO_F_BAD_FEATURE 0x40000000 +#define QVIRTIO_F_BAD_FEATURE 0x40000000ull =20 typedef struct QVirtioBus QVirtioBus; =20 @@ -52,13 +52,13 @@ struct QVirtioBus { uint64_t (*config_readq)(QVirtioDevice *d, uint64_t addr); =20 /* Get features of the device */ - uint32_t (*get_features)(QVirtioDevice *d); + uint64_t (*get_features)(QVirtioDevice *d); =20 /* Set features of the device */ - void (*set_features)(QVirtioDevice *d, uint32_t features); + void (*set_features)(QVirtioDevice *d, uint64_t features); =20 /* Get features of the guest */ - uint32_t (*get_guest_features)(QVirtioDevice *d); + uint64_t (*get_guest_features)(QVirtioDevice *d); =20 /* Get status of the device */ uint8_t (*get_status)(QVirtioDevice *d); @@ -103,8 +103,8 @@ uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t= addr); uint16_t qvirtio_config_readw(QVirtioDevice *d, uint64_t addr); uint32_t qvirtio_config_readl(QVirtioDevice *d, uint64_t addr); uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_t addr); -uint32_t qvirtio_get_features(QVirtioDevice *d); -void qvirtio_set_features(QVirtioDevice *d, uint32_t features); +uint64_t qvirtio_get_features(QVirtioDevice *d); +void qvirtio_set_features(QVirtioDevice *d, uint64_t features); bool qvirtio_is_big_endian(QVirtioDevice *d); =20 void qvirtio_reset(QVirtioDevice *d); diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index 7154b03c1d..78066e6e05 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -40,22 +40,38 @@ static uint64_t qvirtio_mmio_config_readq(QVirtioDevice= *d, uint64_t off) return qtest_readq(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC = + off); } =20 -static uint32_t qvirtio_mmio_get_features(QVirtioDevice *d) +static uint64_t qvirtio_mmio_get_features(QVirtioDevice *d) { QVirtioMMIODevice *dev =3D container_of(d, QVirtioMMIODevice, vdev); + uint64_t lo; + uint64_t hi =3D 0; + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL, 0); - return qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURES); + lo =3D qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURES); + + if (dev->version >=3D 2) { + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL,= 1); + hi =3D qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURE= S); + } + + return (hi << 32) | lo; } =20 -static void qvirtio_mmio_set_features(QVirtioDevice *d, uint32_t features) +static void qvirtio_mmio_set_features(QVirtioDevice *d, uint64_t features) { QVirtioMMIODevice *dev =3D container_of(d, QVirtioMMIODevice, vdev); dev->features =3D features; qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_GUEST_FEATURES_SEL, 0); qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_GUEST_FEATURES, featur= es); + + if (dev->version >=3D 2) { + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_GUEST_FEATURES_SEL= , 1); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_GUEST_FEATURES, + features >> 32); + } } =20 -static uint32_t qvirtio_mmio_get_guest_features(QVirtioDevice *d) +static uint64_t qvirtio_mmio_get_guest_features(QVirtioDevice *d) { QVirtioMMIODevice *dev =3D container_of(d, QVirtioMMIODevice, vdev); return dev->features; @@ -149,8 +165,8 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtio= Device *d, vq->free_head =3D 0; vq->num_free =3D vq->size; vq->align =3D dev->page_size; - vq->indirect =3D (dev->features & (1u << VIRTIO_RING_F_INDIRECT_DESC))= !=3D 0; - vq->event =3D (dev->features & (1u << VIRTIO_RING_F_EVENT_IDX)) !=3D 0; + vq->indirect =3D dev->features & (1ull << VIRTIO_RING_F_INDIRECT_DESC); + vq->event =3D dev->features & (1ull << VIRTIO_RING_F_EVENT_IDX); =20 qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_NUM, vq->size); =20 diff --git a/tests/libqos/virtio-net.c b/tests/libqos/virtio-net.c index 6567beb553..710d440c3d 100644 --- a/tests/libqos/virtio-net.c +++ b/tests/libqos/virtio-net.c @@ -44,11 +44,11 @@ static void virtio_net_setup(QVirtioNet *interface) =20 features =3D qvirtio_get_features(vdev); features &=3D ~(QVIRTIO_F_BAD_FEATURE | - (1u << VIRTIO_RING_F_INDIRECT_DESC) | - (1u << VIRTIO_RING_F_EVENT_IDX)); + (1ull << VIRTIO_RING_F_INDIRECT_DESC) | + (1ull << VIRTIO_RING_F_EVENT_IDX)); qvirtio_set_features(vdev, features); =20 - if (features & (1u << VIRTIO_NET_F_MQ)) { + if (features & (1ull << VIRTIO_NET_F_MQ)) { interface->n_queues =3D qvirtio_config_readw(vdev, 8) * 2; } else { interface->n_queues =3D 2; diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 50499e75ef..1b6b760fc6 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -96,19 +96,19 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice = *d, uint64_t off) return val; } =20 -static uint32_t qvirtio_pci_get_features(QVirtioDevice *d) +static uint64_t qvirtio_pci_get_features(QVirtioDevice *d) { QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readl(dev->pdev, dev->bar, VIRTIO_PCI_HOST_FEATURES); } =20 -static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features) +static void qvirtio_pci_set_features(QVirtioDevice *d, uint64_t features) { QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); qpci_io_writel(dev->pdev, dev->bar, VIRTIO_PCI_GUEST_FEATURES, feature= s); } =20 -static uint32_t qvirtio_pci_get_guest_features(QVirtioDevice *d) +static uint64_t qvirtio_pci_get_guest_features(QVirtioDevice *d) { QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readl(dev->pdev, dev->bar, VIRTIO_PCI_GUEST_FEATURES); @@ -208,7 +208,7 @@ static void qvirtio_pci_set_queue_address(QVirtioDevice= *d, uint32_t pfn) static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, QGuestAllocator *alloc, uint16_t i= ndex) { - uint32_t feat; + uint64_t feat; uint64_t addr; QVirtQueuePCI *vqpci; QVirtioPCIDevice *qvpcidev =3D container_of(d, QVirtioPCIDevice, vdev); @@ -222,8 +222,8 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioD= evice *d, vqpci->vq.free_head =3D 0; vqpci->vq.num_free =3D vqpci->vq.size; vqpci->vq.align =3D VIRTIO_PCI_VRING_ALIGN; - vqpci->vq.indirect =3D (feat & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != =3D 0; - vqpci->vq.event =3D (feat & (1u << VIRTIO_RING_F_EVENT_IDX)) !=3D 0; + vqpci->vq.indirect =3D feat & (1ull << VIRTIO_RING_F_INDIRECT_DESC); + vqpci->vq.event =3D feat & (1ull << VIRTIO_RING_F_EVENT_IDX); =20 vqpci->msix_entry =3D -1; vqpci->msix_addr =3D 0; diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 0ae9956fc8..4f7e6bb8a1 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -33,12 +33,12 @@ uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_= t addr) return d->bus->config_readq(d, addr); } =20 -uint32_t qvirtio_get_features(QVirtioDevice *d) +uint64_t qvirtio_get_features(QVirtioDevice *d) { return d->bus->get_features(d); } =20 -void qvirtio_set_features(QVirtioDevice *d, uint32_t features) +void qvirtio_set_features(QVirtioDevice *d, uint64_t features) { d->features =3D features; d->bus->set_features(d, features); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index f6674fb233..31680cc159 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -119,7 +119,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloca= tor *alloc, QVirtioBlkReq req; uint64_t req_addr; uint64_t capacity; - uint32_t features; + uint64_t features; uint32_t free_head; uint8_t status; char *data; @@ -352,7 +352,7 @@ static void indirect(void *obj, void *u_data, QGuestAll= ocator *t_alloc) QVRingIndirectDesc *indirect; uint64_t req_addr; uint64_t capacity; - uint32_t features; + uint64_t features; uint32_t free_head; uint8_t status; char *data; @@ -467,7 +467,7 @@ static void msix(void *obj, void *u_data, QGuestAllocat= or *t_alloc) int n_size =3D TEST_IMAGE_SIZE / 2; uint64_t req_addr; uint64_t capacity; - uint32_t features; + uint64_t features; uint32_t free_head; uint8_t status; char *data; @@ -574,7 +574,7 @@ static void idx(void *obj, void *u_data, QGuestAllocato= r *t_alloc) QVirtioBlkReq req; uint64_t req_addr; uint64_t capacity; - uint32_t features; + uint64_t features; uint32_t free_head; uint32_t write_head; uint32_t desc_idx; --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571825487; cv=none; d=zoho.com; s=zohoarc; b=aWNjoJ9xmRvjgzGq6Zu1rOyJ+PKD99gfMqbwZQVrfm1g3zUd6wvDtVvaSi5VlzWaVd1dR22crFbPQfMYJVMIQk2WeIcXo4YQriaggCn1TL3cTLOTj1kQsfk5JLttRBo8nbl4ODagSwVBSbh9/NMTxF0DXyZ3ARyjT2kpCJqUTk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571825487; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B5KzSIxiecHCvl5ctY9GrjtfvWnST80K49H0MHB8Pcs=; b=Duwsqi/myfVR93XijsOKIg1yWanVdz7CPGeYjqkX7fVHHC6zYd7ufZQHY3MV4ZYzY9a/sfiecr/rmGY6dMxtWDoTIg9AKr99qZbcFz8Lt1CcIsMBsE6eqLNeGjPre2WtOc421F406vI5wj8j6geN2eF04EMkshraJ3dvZE244D8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571825487680737.1238059176103; Wed, 23 Oct 2019 03:11:27 -0700 (PDT) Received: from localhost ([::1]:59754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDbu-0006dB-IT for importer@patchew.org; Wed, 23 Oct 2019 06:11:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39978) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWc-0004Hv-F8 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWb-0002E0-8D for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24810 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWb-00022M-3T for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-UiNrvFj8Mqqbd-RCEuDClg-1; Wed, 23 Oct 2019 06:05:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 931241800D6B; Wed, 23 Oct 2019 10:05:31 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF2E85DC1E; Wed, 23 Oct 2019 10:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B5KzSIxiecHCvl5ctY9GrjtfvWnST80K49H0MHB8Pcs=; b=Q160q0ihQ7Ab52I+7MyokAT0LAEkS1kFb5ThdCK5nannGmREKxPRoFEdarjl2bI8o3QwiB fiK8ZlYpanoHp17bhZzaklCCaSNFB/DXmHAEqJqGNqdNaU6Igqg981gZMSGaEwaOR+8A64 wwpZqELSJkDEcndoArMzQVm8A5XUVlU= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 04/16] virtio-scsi-test: add missing feature negotiation Date: Wed, 23 Oct 2019 11:04:13 +0100 Message-Id: <20191023100425.12168-5-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: UiNrvFj8Mqqbd-RCEuDClg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" VIRTIO Device Initialization requires feature negotiation. Currently virtio-scsi-test.c is non-compliant. libqos tests acknowledge all feature bits advertised by the device, except VIRTIO_F_BAD_FEATURE (which devices use to detect broken drivers!) and VIRTIO_RING_F_EVENT_IDX (which is not implemented in libqos and accepting it would break notifications). Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth" --- tests/virtio-scsi-test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 7c8f9b27f8..0415e75876 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -123,10 +123,16 @@ static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDe= vice *dev) QVirtioSCSIQueues *vs; const uint8_t test_unit_ready_cdb[VIRTIO_SCSI_CDB_SIZE] =3D {}; struct virtio_scsi_cmd_resp resp; + uint64_t features; int i; =20 vs =3D g_new0(QVirtioSCSIQueues, 1); vs->dev =3D dev; + + features =3D qvirtio_get_features(dev); + features &=3D ~(QVIRTIO_F_BAD_FEATURE | (1ull << VIRTIO_RING_F_EVENT_I= DX)); + qvirtio_set_features(dev, features); + vs->num_queues =3D qvirtio_config_readl(dev, 0); =20 g_assert_cmpint(vs->num_queues, <, MAX_NUM_QUEUES); @@ -135,6 +141,8 @@ static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDevi= ce *dev) vs->vq[i] =3D qvirtqueue_setup(dev, alloc, i); } =20 + qvirtio_set_driver_ok(dev); + /* Clear the POWER ON OCCURRED unit attention */ g_assert_cmpint(virtio_scsi_do_command(vs, test_unit_ready_cdb, NULL, 0, NULL, 0, &resp), --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571825895; cv=none; d=zoho.com; s=zohoarc; b=e492b7Xhtkv/BTZbYQrMs5nidtf/YYfdZy94mDvsZMp7b8xxq/jhPY9t7OsQCCH7awdltzeGNSyk06FXbCWC/j3hdcn5UktftjLNa4FRplyoQgEKJtUDyHhZqdUlqHvoyTCO+7f3kbA11jfDRZI8cdlHnyWjWgN8+ntI0J4wQ/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571825895; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TgnIp6Vzl6+oiH4t/k6zREBHFuWNo0ZBz0CUc04Pots=; b=iClIfIryLoLI9yBhfTSmZlFPbrT+qsheNPfvdjcs85l0b2Eko5wQc4b2Z2vsi3hyxHw/ZuQLc3Sl+Tv0a668elc9gairtIc6c6iAHhnin9fNEIX3kdOYK0gIPxRTTZsaukcX/7IUIk4bppPBo0/iOYn7VGfGjOHohQoo7Gr9QFo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571825895913900.1726428619845; Wed, 23 Oct 2019 03:18:15 -0700 (PDT) Received: from localhost ([::1]:59864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDiY-0003Kp-82 for importer@patchew.org; Wed, 23 Oct 2019 06:18:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39980) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWc-0004Hw-Ex for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWb-0002Da-4H for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:54 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:46783 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWa-00029R-VU for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:05:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-scP6e1UlMz2dtDatncfSWw-1; Wed, 23 Oct 2019 06:05:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D38DE47B; Wed, 23 Oct 2019 10:05:42 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 019A05D6C8; Wed, 23 Oct 2019 10:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TgnIp6Vzl6+oiH4t/k6zREBHFuWNo0ZBz0CUc04Pots=; b=gZsL0/6/eNJQ0jGWKaB+io+O6+VDKBaoVcxqGF0CsyhA/eTGVcjzOI0PXLce2Srd/CR9Uj /GkRDGqAq91mmWdse8NQq5DiWShbe1Vw+a99ojD/CNa7+vbBTs0Zb+t7PUEuVvsrVmaRoL FebNpu5Yr56v3ZloOZ/OAE6mMB4iKRQ= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 05/16] tests/virtio-blk-test: set up virtqueue after feature negotiation Date: Wed, 23 Oct 2019 11:04:14 +0100 Message-Id: <20191023100425.12168-6-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: scP6e1UlMz2dtDatncfSWw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" VIRTIO Device Initialization requires that feature negotiation has completed before virtqueues are set up. This makes sense because the driver must know whether it is operating in Legacy or VIRTIO 1.0 mode before it can access vring fields with the correct endianness. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth --- tests/virtio-blk-test.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 31680cc159..fe0dc4a896 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -113,8 +113,8 @@ static uint64_t virtio_blk_request(QGuestAllocator *all= oc, QVirtioDevice *d, return addr; } =20 -static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc, - QVirtQueue *vq) +/* Returns the request virtqueue so the caller can perform further tests */ +static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc) { QVirtioBlkReq req; uint64_t req_addr; @@ -124,6 +124,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloca= tor *alloc, uint8_t status; char *data; QTestState *qts =3D global_qtest; + QVirtQueue *vq; =20 features =3D qvirtio_get_features(dev); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | @@ -135,6 +136,8 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloca= tor *alloc, capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); =20 + vq =3D qvirtqueue_setup(dev, alloc, 0); + qvirtio_set_driver_ok(dev); =20 /* Write and read with 3 descriptor layout */ @@ -331,14 +334,16 @@ static void test_basic(QVirtioDevice *dev, QGuestAllo= cator *alloc, =20 guest_free(alloc, req_addr); } + + return vq; } =20 static void basic(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtioBlk *blk_if =3D obj; QVirtQueue *vq; - vq =3D qvirtqueue_setup(blk_if->vdev, t_alloc, 0); - test_basic(blk_if->vdev, t_alloc, vq); + + vq =3D test_basic(blk_if->vdev, t_alloc); qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); =20 } @@ -746,9 +751,7 @@ static void resize(void *obj, void *data, QGuestAllocat= or *t_alloc) QVirtQueue *vq; QTestState *qts =3D global_qtest; =20 - vq =3D qvirtqueue_setup(dev, t_alloc, 0); - - test_basic(dev, t_alloc, vq); + vq =3D test_basic(dev, t_alloc); =20 qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571825891; cv=none; d=zoho.com; s=zohoarc; b=XeC+McnX4II5B+WdjNT0XSliatJwSXN2+g3h9Mu5V5iEl/aFWq8zI7HE+enjmfd2ve3sXKKEKiUCSQavNsFwe7Bb8ft//N5ISwnSmU3hesc1hNsCaXttvfneq3sB94s4QSlp8w1JAtNuNsfKZ+YyYa+xjnZaip8hqiHc5m8wMnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571825891; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kNGzs6XBfUuX9h6V7eDmm96BCP+yvOpdjBrhtPUVLls=; b=Y+fJeGPeCTd0BNITM0YmvPSvEHsbKjJfEAg+NIQ/yJKM9gEiXCM22r8F/0Q0PTI0LzX4ajfl48XMsnGP+OB+QFhGTEf8L0x6xgHYz1RTlmZRKmHWzPnHYPj3/A4goytI/5oJqvqJBEdWHYFNXD3lsknUvsk3tyOBL3PmJ8FbZ7U= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571825891892481.65394195036527; Wed, 23 Oct 2019 03:18:11 -0700 (PDT) Received: from localhost ([::1]:59862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDiU-0003Fq-KI for importer@patchew.org; Wed, 23 Oct 2019 06:18:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40166) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWv-0004OL-S2 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWt-0002SA-E9 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31439 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWk-0002My-N3 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-302-FVzT1ULeMkKffdmnER5QhA-1; Wed, 23 Oct 2019 06:05:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBE37107AD33; Wed, 23 Oct 2019 10:05:56 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 108C35C1B2; Wed, 23 Oct 2019 10:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kNGzs6XBfUuX9h6V7eDmm96BCP+yvOpdjBrhtPUVLls=; b=bgA3jtf//4Q8BkmlAIHnGhZ4Nk2AhmzImJxtAHZWo4wIIHU+vtbuSNGLokaugWLsvuttMl siTGROZQ+NUP1JTFodHoW6QKZqbKSpM6JArdA0bIKlqS1gPk1BUwruE8FacsIxZWXrzBo6 7GfPeADi6ETacQ/9XmzJGXH0k+xtHpw= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 06/16] libqos: add missing virtio-9p feature negotiation Date: Wed, 23 Oct 2019 11:04:15 +0100 Message-Id: <20191023100425.12168-7-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: FVzT1ULeMkKffdmnER5QhA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" VIRTIO Device Initialization requires feature negotiation. The libqos virtio-9p driver lacks feature negotiation and is therefore non-compliant. libqos tests acknowledge all feature bits advertised by the device, except VIRTIO_F_BAD_FEATURE (which devices use to detect broken drivers!) and VIRTIO_RING_F_EVENT_IDX (which is not implemented in libqos and accepting it would break notifications). Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth" --- tests/libqos/virtio-9p.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/libqos/virtio-9p.c b/tests/libqos/virtio-9p.c index 8c9efce3e1..77dbfb62ad 100644 --- a/tests/libqos/virtio-9p.c +++ b/tests/libqos/virtio-9p.c @@ -32,6 +32,12 @@ static void virtio_9p_cleanup(QVirtio9P *interface) =20 static void virtio_9p_setup(QVirtio9P *interface) { + uint64_t features; + + features =3D qvirtio_get_features(interface->vdev); + features &=3D ~(QVIRTIO_F_BAD_FEATURE | (1ull << VIRTIO_RING_F_EVENT_I= DX)); + qvirtio_set_features(interface->vdev, features); + interface->vq =3D qvirtqueue_setup(interface->vdev, alloc, 0); qvirtio_set_driver_ok(interface->vdev); } --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571826230; cv=none; d=zoho.com; s=zohoarc; b=Kn1ZrCMAuMf7TiZthgSAC21mD5Z8ucN05wstXuj09DH1cTuHCoaULgy3MI6CGPeeW5nfOIBadJClJeIwl+yiyh7/KBx9fUsRZpOOsc1ux5M/JoG8nORUdpH1l1p+71ybnVvyvpCM89BuXGtpPx+7grhS7rP5Ma5s7ez/AXPIHUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571826230; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o1ZWAZET2aCYr6F3lk3hGVyaMah3+lLXcCNuqtgSeG0=; b=NPJG2BdoIXV8y0xCoXBo2dzeGETxAGnWDKBEZDSINThqzu1Kw6lUnIwi8l54lmc0tr26U5V1/+X9wI4vV5X42/efUFPRG2bK0xtiSzP7cxmjOGLm+VaQNqaewuBCXzm6UpgEuhjlKjp4LY4QBUao3sy/hOL7p5y46snNapj+oCE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571826230965869.0800013349789; Wed, 23 Oct 2019 03:23:50 -0700 (PDT) Received: from localhost ([::1]:59934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDnx-0007JG-4U for importer@patchew.org; Wed, 23 Oct 2019 06:23:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40189) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDWz-0004R6-1A for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDWw-0002VN-Lm for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:16 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42254 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDWw-0002Ua-IL for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-RBN4SAoMMrKpRGUTfQPEcA-1; Wed, 23 Oct 2019 06:06:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA66647B; Wed, 23 Oct 2019 10:06:09 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 492556061E; Wed, 23 Oct 2019 10:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o1ZWAZET2aCYr6F3lk3hGVyaMah3+lLXcCNuqtgSeG0=; b=dHeHkTA/cP0kqaLelhGd6GnyLhnSiQfQvMuYwPfVLD3nc7+jYDExTeZk9Mtz+PpSRD/FJk vtXfn2/uIYyXuB1MKJgkeHXSdh6ZZGydqJ0+USUejERh4TQoOeiuJ+0Mw6wbnL9W0la1ki 3P5c3DFCmYn6JxUackBBEShHB3XgmXY= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 07/16] libqos: enforce Device Initialization order Date: Wed, 23 Oct 2019 11:04:16 +0100 Message-Id: <20191023100425.12168-8-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: RBN4SAoMMrKpRGUTfQPEcA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" According to VIRTIO 1.1 "3.1.1 Driver Requirements: Device Initialization", configuration space and virtqueues cannot be accessed before features have been negotiated. Enforce this requirement. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth --- v4: * Introduce bool d->features_negotiated so that tests can negotiate a 0 feature bit set in Legacy mode [Thomas] --- tests/libqos/virtio.h | 1 + tests/libqos/virtio.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index a5c99fb3c9..0e8f823c7b 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -23,6 +23,7 @@ typedef struct QVirtioDevice { uint16_t device_type; uint64_t features; bool big_endian; + bool features_negotiated; } QVirtioDevice; =20 typedef struct QVirtQueue { diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 4f7e6bb8a1..6049ff3b3e 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -15,21 +15,25 @@ =20 uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr) { + g_assert_true(d->features_negotiated); return d->bus->config_readb(d, addr); } =20 uint16_t qvirtio_config_readw(QVirtioDevice *d, uint64_t addr) { + g_assert_true(d->features_negotiated); return d->bus->config_readw(d, addr); } =20 uint32_t qvirtio_config_readl(QVirtioDevice *d, uint64_t addr) { + g_assert_true(d->features_negotiated); return d->bus->config_readl(d, addr); } =20 uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_t addr) { + g_assert_true(d->features_negotiated); return d->bus->config_readq(d, addr); } =20 @@ -42,11 +46,13 @@ void qvirtio_set_features(QVirtioDevice *d, uint64_t fe= atures) { d->features =3D features; d->bus->set_features(d, features); + d->features_negotiated =3D true; } =20 QVirtQueue *qvirtqueue_setup(QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index) { + g_assert_true(d->features_negotiated); return d->bus->virtqueue_setup(d, alloc, index); } =20 @@ -60,6 +66,7 @@ void qvirtio_reset(QVirtioDevice *d) { d->bus->set_status(d, 0); g_assert_cmphex(d->bus->get_status(d), =3D=3D, 0); + d->features_negotiated =3D false; } =20 void qvirtio_set_acknowledge(QVirtioDevice *d) --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571826604; cv=none; d=zoho.com; s=zohoarc; b=BYlVmskE92jr98PZiKbglrKMMOhxOfFlFtoX9C1G9y2u1DgvbDvgdtdM3nk6Kw9kqeEFCn5fjjF31JgDy3zgRBOa5MiDWpR08+e03jUXuK6DTgsDSLAEJcfzUTAQOmV8yInxIO/ghFU260j+h132NJvw7w9qrodl9h+yT0yuM/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571826604; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eT/N/Nw1XOIrzstfsg+SR6TEiO5KTJAzYYzr1nmBXvs=; b=nPnMLQ3r/6v2gMCWs3MBhowJ6a3Cv1hrB4+zNHg6TIWjz8qV0XeLWJjpfgUlZp9Ft7xfJKcIOWTOSwVU02rCtVzFttmLKpo2HmJOyGq8TkOtIAJUELkMgg4VkScoWbLx7jLmXDdMQYq9+Q5fIs3l6AoDpaf/ldnJGZhR91Rk75E= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571826604230111.7668020434138; Wed, 23 Oct 2019 03:30:04 -0700 (PDT) Received: from localhost ([::1]:59984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDty-0003K5-4W for importer@patchew.org; Wed, 23 Oct 2019 06:30:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40252) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDXC-0004mL-VN for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDX8-0002dt-26 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:29 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24543 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDX7-0002dQ-U4 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-73r6N6bOOjGOEuVfACYZ_A-1; Wed, 23 Oct 2019 06:06:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 298C01005509; Wed, 23 Oct 2019 10:06:21 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17ED91001E75; Wed, 23 Oct 2019 10:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eT/N/Nw1XOIrzstfsg+SR6TEiO5KTJAzYYzr1nmBXvs=; b=YgP8BNWHrodA+RXgWaSiS2FWSokSJBQ5IoUIm44Fqw8x6ojzPw6IPAwn6T/0qZFEI8cBba we3FHZpbjdNcRuitUFJQE9Rb0xtDZFd33lIPHr5Jxpo0gI/cbfJ5ddZZZzHS/bIzcd4ZCt M5QGpIVi+SJS8uJcUmGpZeZyT+zdhqk= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 08/16] libqos: implement VIRTIO 1.0 FEATURES_OK step Date: Wed, 23 Oct 2019 11:04:17 +0100 Message-Id: <20191023100425.12168-9-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 73r6N6bOOjGOEuVfACYZ_A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Device initialization has an extra step in VIRTIO 1.0. The FEATURES_OK status bit is set to indicate that feature negotiation has completed. The driver then reads the status register again to check that the device agrees with the final features. Implement this step as part of qvirtio_set_features() instead of introducing a separate function. This way all existing code works without modifications. The check in qvirtio_set_driver_ok() needs to be updated because FEATURES_OK will be set for VIRTIO 1.0 devices. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth" --- v4: * Make FEATURES_OK change in qvirtio_set_driver_ok() clearer and mention it in the commit description [Thomas] --- tests/libqos/virtio.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 6049ff3b3e..fa597c2481 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -46,6 +46,20 @@ void qvirtio_set_features(QVirtioDevice *d, uint64_t fea= tures) { d->features =3D features; d->bus->set_features(d, features); + + /* + * This could be a separate function for drivers that want to access + * configuration space before setting FEATURES_OK, but no existing use= rs + * need that and it's less code for callers if this is done implicitly. + */ + if (features & (1ull << VIRTIO_F_VERSION_1)) { + uint8_t status =3D d->bus->get_status(d) | + VIRTIO_CONFIG_S_FEATURES_OK; + + d->bus->set_status(d, status); + g_assert_cmphex(d->bus->get_status(d), =3D=3D, status); + } + d->features_negotiated =3D true; } =20 @@ -86,7 +100,9 @@ void qvirtio_set_driver_ok(QVirtioDevice *d) { d->bus->set_status(d, d->bus->get_status(d) | VIRTIO_CONFIG_S_DRIVER_O= K); g_assert_cmphex(d->bus->get_status(d), =3D=3D, VIRTIO_CONFIG_S_DRIVER_= OK | - VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_ACKNOWLEDGE); + VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_ACKNOWLEDGE | + (d->features & (1ull << VIRTIO_F_VERSION_1) ? + VIRTIO_CONFIG_S_FEATURES_OK : 0)); } =20 void qvirtio_wait_queue_isr(QTestState *qts, QVirtioDevice *d, --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571826294; cv=none; d=zoho.com; s=zohoarc; b=TXFuofugJ8TvcYncxpZ8JDpuV5Elg2WSKcPwZfbT0JUxSj6xRiMPZCTM57Bas+qYnRCPvJ7jrLJgdjX4N+M4lzqMFPVWrNRMtIgrgJvInkbc4HK/bU+WJKsfXZuQSuNlFTOSc+o4OeMdjozXdF4VKilnPCvrFKzadQzRXez92yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571826294; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ay8Xk9vHbXHVk376AF3psjrFYQZNzF3S6nDtzMuJIHA=; b=RZjsK8XQUMzIASBSqusw5mSjaXcRMoC9W/5IbD4K5Qq4qXU2HswUK6D58ZerMwes2PdY03PXfMLnlRRy9E4MxVl1YJS722OslMo9C3cUN5weQE6Dt7pOAq+yD9lRh+TIf5WqZbJJN70Z650ZdQwbbmU6unVYRofPsBu0zdtIXMg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571826294175703.7147068088184; Wed, 23 Oct 2019 03:24:54 -0700 (PDT) Received: from localhost ([::1]:59948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDoy-0008Fo-Re for importer@patchew.org; Wed, 23 Oct 2019 06:24:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40355) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDXf-0005Bi-Tx for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDXc-0002yj-Ir for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:59 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:42244 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDXc-0002lw-CT for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-135-DdqSDYPrOced9ekW1x8GGg-1; Wed, 23 Oct 2019 06:06:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D56A11005509; Wed, 23 Oct 2019 10:06:33 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A7A85DD78; Wed, 23 Oct 2019 10:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ay8Xk9vHbXHVk376AF3psjrFYQZNzF3S6nDtzMuJIHA=; b=ZZ8B06fvwVZciSF/fVkk/W8r9G8PEydep+y5LRVhu/uFJ1MPNmtm3uWfaVaZsyBswunQ2z jPTyURKPFsh8xfiPu8EbBXlVqc9rSX1sg8A9sE7CFUZsXov+FiA7M7dus50jeEL5NY1EHY jRGqrcFoWJrU+sCj8GY4vjD05+JMPrU= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 09/16] libqos: access VIRTIO 1.0 vring in little-endian Date: Wed, 23 Oct 2019 11:04:18 +0100 Message-Id: <20191023100425.12168-10-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: DdqSDYPrOced9ekW1x8GGg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" VIRTIO 1.0 uses little-endian for the vring. Legacy VIRTIO uses guest endianness. Adjust the code to handle both. Note that qvirtio_readq() is not defined because it has no users. All the other accessors are really needed. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth --- v4: * Fixed indentation in qvring_init() [Thomas] --- tests/libqos/virtio.h | 4 +- tests/libqos/virtio-mmio.c | 1 + tests/libqos/virtio-pci.c | 1 + tests/libqos/virtio.c | 131 +++++++++++++++++++++++++++---------- tests/virtio-blk-test.c | 8 +-- 5 files changed, 106 insertions(+), 39 deletions(-) diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 0e8f823c7b..ebbff5193b 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -27,6 +27,7 @@ typedef struct QVirtioDevice { } QVirtioDevice; =20 typedef struct QVirtQueue { + QVirtioDevice *vdev; uint64_t desc; /* This points to an array of struct vring_desc */ uint64_t avail; /* This points to a struct vring_avail */ uint64_t used; /* This points to a struct vring_used */ @@ -135,7 +136,8 @@ void qvring_init(QTestState *qts, const QGuestAllocator= *alloc, QVirtQueue *vq, QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevi= ce *d, QGuestAllocator *alloc, uint16_t elem); -void qvring_indirect_desc_add(QTestState *qts, QVRingIndirectDesc *indirec= t, +void qvring_indirect_desc_add(QVirtioDevice *d, QTestState *qts, + QVRingIndirectDesc *indirect, uint64_t data, uint32_t len, bool write); uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *vq, uint64_t data, uint32_t len, bool write, bool next); diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index 78066e6e05..4db1f1b8bc 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -157,6 +157,7 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtio= Device *d, uint64_t addr; =20 vq =3D g_malloc0(sizeof(*vq)); + vq->vdev =3D d; qvirtio_mmio_queue_select(d, index); qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_ALIGN, dev->page= _size); =20 diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 1b6b760fc6..7ecf5d0a52 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -217,6 +217,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioD= evice *d, feat =3D qvirtio_pci_get_guest_features(d); =20 qvirtio_pci_queue_select(d, index); + vqpci->vq.vdev =3D d; vqpci->vq.index =3D index; vqpci->vq.size =3D qvirtio_pci_get_queue_size(d); vqpci->vq.free_head =3D 0; diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index fa597c2481..9aa360620c 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -8,11 +8,68 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "libqtest.h" #include "libqos/virtio.h" #include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" =20 +/* + * qtest_readX/writeX() functions transfer host endian from/to guest endia= n. + * This works great for Legacy VIRTIO devices where we need guest endian + * accesses. For VIRTIO 1.0 the vring is little-endian so the automatic g= uest + * endianness conversion is not wanted. + * + * The following qvirtio_readX/writeX() functions handle Legacy and VIRTIO= 1.0 + * accesses seamlessly. + */ +static uint16_t qvirtio_readw(QVirtioDevice *d, QTestState *qts, uint64_t = addr) +{ + uint16_t val =3D qtest_readw(qts, addr); + + if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts= )) { + val =3D bswap16(val); + } + return val; +} + +static uint32_t qvirtio_readl(QVirtioDevice *d, QTestState *qts, uint64_t = addr) +{ + uint32_t val =3D qtest_readl(qts, addr); + + if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts= )) { + val =3D bswap32(val); + } + return val; +} + +static void qvirtio_writew(QVirtioDevice *d, QTestState *qts, + uint64_t addr, uint16_t val) +{ + if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts= )) { + val =3D bswap16(val); + } + qtest_writew(qts, addr, val); +} + +static void qvirtio_writel(QVirtioDevice *d, QTestState *qts, + uint64_t addr, uint32_t val) +{ + if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts= )) { + val =3D bswap32(val); + } + qtest_writel(qts, addr, val); +} + +static void qvirtio_writeq(QVirtioDevice *d, QTestState *qts, + uint64_t addr, uint64_t val) +{ + if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts= )) { + val =3D bswap64(val); + } + qtest_writeq(qts, addr, val); +} + uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr) { g_assert_true(d->features_negotiated); @@ -189,23 +246,23 @@ void qvring_init(QTestState *qts, const QGuestAllocat= or *alloc, QVirtQueue *vq, =20 for (i =3D 0; i < vq->size - 1; i++) { /* vq->desc[i].addr */ - qtest_writeq(qts, vq->desc + (16 * i), 0); + qvirtio_writeq(vq->vdev, qts, vq->desc + (16 * i), 0); /* vq->desc[i].next */ - qtest_writew(qts, vq->desc + (16 * i) + 14, i + 1); + qvirtio_writew(vq->vdev, qts, vq->desc + (16 * i) + 14, i + 1); } =20 /* vq->avail->flags */ - qtest_writew(qts, vq->avail, 0); + qvirtio_writew(vq->vdev, qts, vq->avail, 0); /* vq->avail->idx */ - qtest_writew(qts, vq->avail + 2, 0); + qvirtio_writew(vq->vdev, qts, vq->avail + 2, 0); /* vq->avail->used_event */ - qtest_writew(qts, vq->avail + 4 + (2 * vq->size), 0); + qvirtio_writew(vq->vdev, qts, vq->avail + 4 + (2 * vq->size), 0); =20 /* vq->used->flags */ - qtest_writew(qts, vq->used, 0); + qvirtio_writew(vq->vdev, qts, vq->used, 0); /* vq->used->avail_event */ - qtest_writew(qts, vq->used + 2 + sizeof(struct vring_used_elem) * vq->= size, - 0); + qvirtio_writew(vq->vdev, qts, vq->used + 2 + + sizeof(struct vring_used_elem) * vq->size, 0); } =20 QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevi= ce *d, @@ -221,35 +278,39 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QTestS= tate *qs, QVirtioDevice *d, =20 for (i =3D 0; i < elem - 1; ++i) { /* indirect->desc[i].addr */ - qtest_writeq(qs, indirect->desc + (16 * i), 0); + qvirtio_writeq(d, qs, indirect->desc + (16 * i), 0); /* indirect->desc[i].flags */ - qtest_writew(qs, indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT= ); + qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12, + VRING_DESC_F_NEXT); /* indirect->desc[i].next */ - qtest_writew(qs, indirect->desc + (16 * i) + 14, i + 1); + qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, i + 1); } =20 return indirect; } =20 -void qvring_indirect_desc_add(QTestState *qts, QVRingIndirectDesc *indirec= t, +void qvring_indirect_desc_add(QVirtioDevice *d, QTestState *qts, + QVRingIndirectDesc *indirect, uint64_t data, uint32_t len, bool write) { uint16_t flags; =20 g_assert_cmpint(indirect->index, <, indirect->elem); =20 - flags =3D qtest_readw(qts, indirect->desc + (16 * indirect->index) + 1= 2); + flags =3D qvirtio_readw(d, qts, indirect->desc + + (16 * indirect->index) + 12); =20 if (write) { flags |=3D VRING_DESC_F_WRITE; } =20 /* indirect->desc[indirect->index].addr */ - qtest_writeq(qts, indirect->desc + (16 * indirect->index), data); + qvirtio_writeq(d, qts, indirect->desc + (16 * indirect->index), data); /* indirect->desc[indirect->index].len */ - qtest_writel(qts, indirect->desc + (16 * indirect->index) + 8, len); + qvirtio_writel(d, qts, indirect->desc + (16 * indirect->index) + 8, le= n); /* indirect->desc[indirect->index].flags */ - qtest_writew(qts, indirect->desc + (16 * indirect->index) + 12, flags); + qvirtio_writew(d, qts, indirect->desc + (16 * indirect->index) + 12, + flags); =20 indirect->index++; } @@ -269,11 +330,11 @@ uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *= vq, uint64_t data, } =20 /* vq->desc[vq->free_head].addr */ - qtest_writeq(qts, vq->desc + (16 * vq->free_head), data); + qvirtio_writeq(vq->vdev, qts, vq->desc + (16 * vq->free_head), data); /* vq->desc[vq->free_head].len */ - qtest_writel(qts, vq->desc + (16 * vq->free_head) + 8, len); + qvirtio_writel(vq->vdev, qts, vq->desc + (16 * vq->free_head) + 8, len= ); /* vq->desc[vq->free_head].flags */ - qtest_writew(qts, vq->desc + (16 * vq->free_head) + 12, flags); + qvirtio_writew(vq->vdev, qts, vq->desc + (16 * vq->free_head) + 12, fl= ags); =20 return vq->free_head++; /* Return and increase, in this order */ } @@ -288,13 +349,14 @@ uint32_t qvirtqueue_add_indirect(QTestState *qts, QVi= rtQueue *vq, vq->num_free--; =20 /* vq->desc[vq->free_head].addr */ - qtest_writeq(qts, vq->desc + (16 * vq->free_head), indirect->desc); + qvirtio_writeq(vq->vdev, qts, vq->desc + (16 * vq->free_head), + indirect->desc); /* vq->desc[vq->free_head].len */ - qtest_writel(qts, vq->desc + (16 * vq->free_head) + 8, - sizeof(struct vring_desc) * indirect->elem); + qvirtio_writel(vq->vdev, qts, vq->desc + (16 * vq->free_head) + 8, + sizeof(struct vring_desc) * indirect->elem); /* vq->desc[vq->free_head].flags */ - qtest_writew(qts, vq->desc + (16 * vq->free_head) + 12, - VRING_DESC_F_INDIRECT); + qvirtio_writew(vq->vdev, qts, vq->desc + (16 * vq->free_head) + 12, + VRING_DESC_F_INDIRECT); =20 return vq->free_head++; /* Return and increase, in this order */ } @@ -303,21 +365,21 @@ void qvirtqueue_kick(QTestState *qts, QVirtioDevice *= d, QVirtQueue *vq, uint32_t free_head) { /* vq->avail->idx */ - uint16_t idx =3D qtest_readw(qts, vq->avail + 2); + uint16_t idx =3D qvirtio_readw(d, qts, vq->avail + 2); /* vq->used->flags */ uint16_t flags; /* vq->used->avail_event */ uint16_t avail_event; =20 /* vq->avail->ring[idx % vq->size] */ - qtest_writew(qts, vq->avail + 4 + (2 * (idx % vq->size)), free_head); + qvirtio_writew(d, qts, vq->avail + 4 + (2 * (idx % vq->size)), free_he= ad); /* vq->avail->idx */ - qtest_writew(qts, vq->avail + 2, idx + 1); + qvirtio_writew(d, qts, vq->avail + 2, idx + 1); =20 /* Must read after idx is updated */ - flags =3D qtest_readw(qts, vq->avail); - avail_event =3D qtest_readw(qts, vq->used + 4 + - sizeof(struct vring_used_elem) * vq->si= ze); + flags =3D qvirtio_readw(d, qts, vq->avail); + avail_event =3D qvirtio_readw(d, qts, vq->used + 4 + + sizeof(struct vring_used_elem) * vq->size); =20 /* < 1 because we add elements to avail queue one by one */ if ((flags & VRING_USED_F_NO_NOTIFY) =3D=3D 0 && @@ -342,7 +404,8 @@ bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *vq= , uint32_t *desc_idx, uint16_t idx; uint64_t elem_addr, addr; =20 - idx =3D qtest_readw(qts, vq->used + offsetof(struct vring_used, idx)); + idx =3D qvirtio_readw(vq->vdev, qts, + vq->used + offsetof(struct vring_used, idx)); if (idx =3D=3D vq->last_used_idx) { return false; } @@ -354,12 +417,12 @@ bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *= vq, uint32_t *desc_idx, =20 if (desc_idx) { addr =3D elem_addr + offsetof(struct vring_used_elem, id); - *desc_idx =3D qtest_readl(qts, addr); + *desc_idx =3D qvirtio_readl(vq->vdev, qts, addr); } =20 if (len) { addr =3D elem_addr + offsetof(struct vring_used_elem, len); - *len =3D qtest_readw(qts, addr); + *len =3D qvirtio_readw(vq->vdev, qts, addr); } =20 vq->last_used_idx++; @@ -371,7 +434,7 @@ void qvirtqueue_set_used_event(QTestState *qts, QVirtQu= eue *vq, uint16_t idx) g_assert(vq->event); =20 /* vq->avail->used_event */ - qtest_writew(qts, vq->avail + 4 + (2 * vq->size), idx); + qvirtio_writew(vq->vdev, qts, vq->avail + 4 + (2 * vq->size), idx); } =20 void qvirtio_start_device(QVirtioDevice *vdev) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index fe0dc4a896..2a23698211 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -388,8 +388,8 @@ static void indirect(void *obj, void *u_data, QGuestAll= ocator *t_alloc) g_free(req.data); =20 indirect =3D qvring_indirect_desc_setup(qts, dev, t_alloc, 2); - qvring_indirect_desc_add(qts, indirect, req_addr, 528, false); - qvring_indirect_desc_add(qts, indirect, req_addr + 528, 1, true); + qvring_indirect_desc_add(dev, qts, indirect, req_addr, 528, false); + qvring_indirect_desc_add(dev, qts, indirect, req_addr + 528, 1, true); free_head =3D qvirtqueue_add_indirect(qts, vq, indirect); qvirtqueue_kick(qts, dev, vq, free_head); =20 @@ -413,8 +413,8 @@ static void indirect(void *obj, void *u_data, QGuestAll= ocator *t_alloc) g_free(req.data); =20 indirect =3D qvring_indirect_desc_setup(qts, dev, t_alloc, 2); - qvring_indirect_desc_add(qts, indirect, req_addr, 16, false); - qvring_indirect_desc_add(qts, indirect, req_addr + 16, 513, true); + qvring_indirect_desc_add(dev, qts, indirect, req_addr, 16, false); + qvring_indirect_desc_add(dev, qts, indirect, req_addr + 16, 513, true); free_head =3D qvirtqueue_add_indirect(qts, vq, indirect); qvirtqueue_kick(qts, dev, vq, free_head); =20 --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571826630; cv=none; d=zoho.com; s=zohoarc; b=KJzu1Filw2aqS5cQfu4T/D8fO3erfm2FrB3AnNreelNQO+ANEZZF8ak78lPDGARjlzj/moFtgJ5xB+IeUT0e2Qh7ScEc+HLLXKLPrIHbDqlk8oh9q100AAqyNG7G7ZxJgalT18fNdOvrvocn1Ee2od32lnRMTqhuh7Qg5ZaVGcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571826630; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I08VkzUsgrtyia93/HmDZ76VepZd8lI7Z6RdTDxbgFU=; b=nWGoBcRwE9WrIpKRruaqvY4j3uOpO9j84YA9SDQaam4LHKpoV6oiWbDgq6gZZ8hm46RBoQG4G04C+5DIYgH3ho8/MnR/P6nqxw7jQnzWS07Z0DSPhpHjktgUMRrzHArtHKj2EXzXtW0w81F13x+XxTlQaXTyoepmtBh8v0W64M4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571826630612438.7657005962684; Wed, 23 Oct 2019 03:30:30 -0700 (PDT) Received: from localhost ([::1]:59986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDuP-0003cP-Dj for importer@patchew.org; Wed, 23 Oct 2019 06:30:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40359) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDXf-0005Bp-Uu for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDXc-0002yt-Kl for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29890 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDXc-0002v6-GM for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:06:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-BJcQctWxPkmGZfzXumwSAQ-1; Wed, 23 Oct 2019 06:06:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5687A107AD31; Wed, 23 Oct 2019 10:06:46 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 680DE1001E75; Wed, 23 Oct 2019 10:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I08VkzUsgrtyia93/HmDZ76VepZd8lI7Z6RdTDxbgFU=; b=Y1fVGwd97pSdo8UHlwG+ylMohXg8ml0UvbA8pwe99wLUM0kCxH9EWPnWA9NFHsATaXdhlL y4rICzVIqHedA08xc18TJiuqpV+APfBKABs4MhK/JKj9f3vKqowHZ+8fs/embuJvAszNcq NBmUU4WhM157+xZTaP47Nw8gt6RgKso= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 10/16] libqos: add iteration support to qpci_find_capability() Date: Wed, 23 Oct 2019 11:04:19 +0100 Message-Id: <20191023100425.12168-11-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: BJcQctWxPkmGZfzXumwSAQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" VIRTIO 1.0 PCI devices have multiple PCI_CAP_ID_VNDR capabilities so we need a way to iterate over them. Extend qpci_find_capability() to take the last address. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth -- v3: * Document qpci_find_capability() --- tests/libqos/pci.h | 2 +- tests/libqos/pci.c | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index a5389a5845..590c175190 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -86,7 +86,7 @@ bool qpci_has_buggy_msi(QPCIDevice *dev); bool qpci_check_buggy_msi(QPCIDevice *dev); =20 void qpci_device_enable(QPCIDevice *dev); -uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id); +uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id, uint8_t start_ad= dr); void qpci_msix_enable(QPCIDevice *dev); void qpci_msix_disable(QPCIDevice *dev); bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry); diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 662ee7a517..2309a724e4 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -115,10 +115,28 @@ void qpci_device_enable(QPCIDevice *dev) g_assert_cmphex(cmd & PCI_COMMAND_MASTER, =3D=3D, PCI_COMMAND_MASTER); } =20 -uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id) +/** + * qpci_find_capability: + * @dev: the PCI device + * @id: the PCI Capability ID (PCI_CAP_ID_*) + * @start_addr: 0 to begin iteration or the last return value to continue + * iteration + * + * Iterate over the PCI Capabilities List. + * + * Returns: PCI Configuration Space offset of the capabililty structure or + * 0 if no further matching capability is found + */ +uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id, uint8_t start_ad= dr) { uint8_t cap; - uint8_t addr =3D qpci_config_readb(dev, PCI_CAPABILITY_LIST); + uint8_t addr; + + if (start_addr) { + addr =3D qpci_config_readb(dev, start_addr + PCI_CAP_LIST_NEXT); + } else { + addr =3D qpci_config_readb(dev, PCI_CAPABILITY_LIST); + } =20 do { cap =3D qpci_config_readb(dev, addr); @@ -138,7 +156,7 @@ void qpci_msix_enable(QPCIDevice *dev) uint8_t bir_table; uint8_t bir_pba; =20 - addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX); + addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0); g_assert_cmphex(addr, !=3D, 0); =20 val =3D qpci_config_readw(dev, addr + PCI_MSIX_FLAGS); @@ -167,7 +185,7 @@ void qpci_msix_disable(QPCIDevice *dev) uint16_t val; =20 g_assert(dev->msix_enabled); - addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX); + addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0); g_assert_cmphex(addr, !=3D, 0); val =3D qpci_config_readw(dev, addr + PCI_MSIX_FLAGS); qpci_config_writew(dev, addr + PCI_MSIX_FLAGS, @@ -203,7 +221,7 @@ bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry) uint64_t vector_off =3D dev->msix_table_off + entry * PCI_MSIX_ENTRY_S= IZE; =20 g_assert(dev->msix_enabled); - addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX); + addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0); g_assert_cmphex(addr, !=3D, 0); val =3D qpci_config_readw(dev, addr + PCI_MSIX_FLAGS); =20 @@ -221,7 +239,7 @@ uint16_t qpci_msix_table_size(QPCIDevice *dev) uint8_t addr; uint16_t control; =20 - addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX); + addr =3D qpci_find_capability(dev, PCI_CAP_ID_MSIX, 0); g_assert_cmphex(addr, !=3D, 0); =20 control =3D qpci_config_readw(dev, addr + PCI_MSIX_FLAGS); --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571827041; cv=none; d=zoho.com; s=zohoarc; b=f0Fey5FyUsdL2oPH4lxnUXAMRsj+yJg5R2HO/LFdKQiFKpJsI6DYg4rqE2WbZsKRwJA66Uk2cLkkEwRb25fM2xkxgDB2+acE82kNO6rBB429dDhZWZr93U8AKuJmm0YjCEBEA3zUdJPZSazAK1RRTi2aN4AtLKm2FsWOaxAw8fk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571827041; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=b1+p4tcQY08BVFyjCo72mvhJJ+wYreWjS/AeXVIm/U0=; b=odn5/y2RftUhh9OLOFggXF0UuWfBd1+iH5LsTtwe21etioo1Nr8PM0uMO1WXIn2lsm2nsKPqTUkq3ONVgkxZZZjlJSq0PZHprZbFKKkfHLxCN1o9Ub6Dyftnt/rS6nWkXb064K7SGS4T1Vt0WrIyx+l1DLoHlL+Si6pKJ9NElaM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571827041091970.3169748411575; Wed, 23 Oct 2019 03:37:21 -0700 (PDT) Received: from localhost ([::1]:60064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNE11-0007tv-Jj for importer@patchew.org; Wed, 23 Oct 2019 06:37:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40425) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDXo-0005Lm-U3 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDXn-00037g-Nn for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:08 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:22708 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDXn-00036I-Hj for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-aql1H7JMNE-mMvMUVgS2Gw-1; Wed, 23 Oct 2019 06:07:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE9BB80183D; Wed, 23 Oct 2019 10:07:01 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8D6860629; Wed, 23 Oct 2019 10:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b1+p4tcQY08BVFyjCo72mvhJJ+wYreWjS/AeXVIm/U0=; b=B7arMzukbeiSkrUPUKweRSnmRg+HT7lJzbvirHE0GeCX63dK+3RwUp5M9QsyB87fYSghil ngTcS2kBj+rqXh+Dtbmu1GyddiYTXkC1oE5OImlmvWw7qTveUrHGb8v+lD0HfJstg99RI0 S/WhY01sRDW2D4x22XgGgtdnZmOj1qc= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 11/16] libqos: pass full QVirtQueue to set_queue_address() Date: Wed, 23 Oct 2019 11:04:20 +0100 Message-Id: <20191023100425.12168-12-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: aql1H7JMNE-mMvMUVgS2Gw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of just passing the vring page frame number, pass the full QVirtQueue. This will allow the VIRTIO 1.0 transport to program the fine-grained vring address registers in the future. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/libqos/virtio.h | 2 +- tests/libqos/virtio-mmio.c | 6 ++++-- tests/libqos/virtio-pci.c | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index ebbff5193b..529ef7555a 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -81,7 +81,7 @@ struct QVirtioBus { uint16_t (*get_queue_size)(QVirtioDevice *d); =20 /* Set the address of the selected queue */ - void (*set_queue_address)(QVirtioDevice *d, uint32_t pfn); + void (*set_queue_address)(QVirtioDevice *d, QVirtQueue *vq); =20 /* Setup the virtqueue specified by index */ QVirtQueue *(*virtqueue_setup)(QVirtioDevice *d, QGuestAllocator *allo= c, diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index 4db1f1b8bc..e0a2bd7bc6 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -143,9 +143,11 @@ static uint16_t qvirtio_mmio_get_queue_size(QVirtioDev= ice *d) return (uint16_t)qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_= NUM_MAX); } =20 -static void qvirtio_mmio_set_queue_address(QVirtioDevice *d, uint32_t pfn) +static void qvirtio_mmio_set_queue_address(QVirtioDevice *d, QVirtQueue *v= q) { QVirtioMMIODevice *dev =3D container_of(d, QVirtioMMIODevice, vdev); + uint64_t pfn =3D vq->desc / dev->page_size; + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_PFN, pfn); } =20 @@ -179,7 +181,7 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtio= Device *d, =20 addr =3D guest_alloc(alloc, qvring_size(vq->size, dev->page_size)); qvring_init(dev->qts, alloc, vq, addr); - qvirtio_mmio_set_queue_address(d, vq->desc / dev->page_size); + qvirtio_mmio_set_queue_address(d, vq); =20 return vq; } diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 7ecf5d0a52..e4fa318dcc 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -199,9 +199,11 @@ static uint16_t qvirtio_pci_get_queue_size(QVirtioDevi= ce *d) return qpci_io_readw(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_NUM); } =20 -static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn) +static void qvirtio_pci_set_queue_address(QVirtioDevice *d, QVirtQueue *vq) { QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + uint64_t pfn =3D vq->desc / VIRTIO_PCI_VRING_ALIGN; + qpci_io_writel(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_PFN, pfn); } =20 @@ -239,7 +241,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioD= evice *d, addr =3D guest_alloc(alloc, qvring_size(vqpci->vq.size, VIRTIO_PCI_VRING_ALIGN)); qvring_init(qvpcidev->pdev->bus->qts, alloc, &vqpci->vq, addr); - qvirtio_pci_set_queue_address(d, vqpci->vq.desc / VIRTIO_PCI_VRING_ALI= GN); + qvirtio_pci_set_queue_address(d, &vqpci->vq); =20 return &vqpci->vq; } --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571826687; cv=none; d=zoho.com; s=zohoarc; b=GE2/DFXZUAuR58MatCCBwlXxc0L8rxF6S7pvc1hqNGyuMFHEox105xhQONSapCWZcvgIG3cqfe+GdCtvXHO47AsIdige3K2yj1vA1wPj6U8+vqmhHuUzXrpZQgREJBqD1cLOJoQSYjyCZeCWSlV5BROS0TiNgSC22Bq1L4R5Eco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571826687; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tqLry4Ki6u2h7xn3uagKAxOS0sqBOly9DaQ+AXZ+604=; b=DhOjWs3WyyAYVlcCednm2/Pr00OmClsrb8JClJE6g2Xg1mor3BIcxdGkOYlqXq01Q+fCCRARMgYCqowgRgFI4aByDalc16U2Ktnevi+UVDhhOVvICYQt9JRBhZBD7gpIEGbDwQ+M/3Frk9IK5gSu3ZvMje5mK3bDyKYBjlIHuqs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571826687868892.4735437548536; Wed, 23 Oct 2019 03:31:27 -0700 (PDT) Received: from localhost ([::1]:59994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDvK-00040b-4c for importer@patchew.org; Wed, 23 Oct 2019 06:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40487) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDY2-0005Qr-EH for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDY0-0003FK-3c for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:22 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46203 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDXz-0003Di-Vm for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-lk7PHi-YMcepJdRpEHNjpw-1; Wed, 23 Oct 2019 06:07:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6ACE5107AD31; Wed, 23 Oct 2019 10:07:15 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D1FA1001B08; Wed, 23 Oct 2019 10:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tqLry4Ki6u2h7xn3uagKAxOS0sqBOly9DaQ+AXZ+604=; b=gzldFOKxmiahIT1+Zl9EBal7nWmnFTK0XLlTK4WifVsta2h1xyPZIa4WF+Q8RBpHkC6YKQ DlDvtJYtM/dvyroTN4cRP1ZJ/kxsaV2lMXAxDULncqYIZSf8qAJKzpbIc56PKAGuoLC8ZI MrjyrBq0tlnjTjWhRH+0AGMFF/260fo= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 12/16] libqos: add MSI-X callbacks to QVirtioPCIDevice Date: Wed, 23 Oct 2019 11:04:21 +0100 Message-Id: <20191023100425.12168-13-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: lk7PHi-YMcepJdRpEHNjpw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The MSI-X vectors are programmed differently in the VIRTIO 1.0 and Legacy interfaces. Introduce callbacks so different implementations can be used depending on the interface version. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth --- tests/libqos/virtio-pci.h | 12 ++++++++++++ tests/libqos/virtio-pci.c | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 728b4715f1..4299efc023 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -14,16 +14,28 @@ #include "libqos/pci.h" #include "libqos/qgraph.h" =20 +typedef struct QVirtioPCIMSIXOps QVirtioPCIMSIXOps; + typedef struct QVirtioPCIDevice { QOSGraphObject obj; QVirtioDevice vdev; QPCIDevice *pdev; QPCIBar bar; + const QVirtioPCIMSIXOps *msix_ops; uint16_t config_msix_entry; uint64_t config_msix_addr; uint32_t config_msix_data; } QVirtioPCIDevice; =20 +struct QVirtioPCIMSIXOps { + /* Set the Configuration Vector for MSI-X */ + void (*set_config_vector)(QVirtioPCIDevice *d, uint16_t entry); + + /* Set the Queue Vector for MSI-X */ + void (*set_queue_vector)(QVirtioPCIDevice *d, uint16_t vq_idx, + uint16_t entry); +}; + typedef struct QVirtQueuePCI { QVirtQueue vq; uint16_t msix_entry; diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index e4fa318dcc..0725777a8d 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -281,6 +281,31 @@ const QVirtioBus qvirtio_pci =3D { .virtqueue_kick =3D qvirtio_pci_virtqueue_kick, }; =20 +static void qvirtio_pci_set_config_vector(QVirtioPCIDevice *d, uint16_t en= try) +{ + uint16_t vector; + + qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR, entry); + vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR); + g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); +} + +static void qvirtio_pci_set_queue_vector(QVirtioPCIDevice *d, uint16_t vq_= idx, + uint16_t entry) +{ + uint16_t vector; + + qvirtio_pci_queue_select(&d->vdev, vq_idx); + qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR, entry); + vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR); + g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); +} + +static const QVirtioPCIMSIXOps qvirtio_pci_msix_ops_legacy =3D { + .set_config_vector =3D qvirtio_pci_set_config_vector, + .set_queue_vector =3D qvirtio_pci_set_queue_vector, +}; + void qvirtio_pci_device_enable(QVirtioPCIDevice *d) { qpci_device_enable(d->pdev); @@ -295,7 +320,6 @@ void qvirtio_pci_device_disable(QVirtioPCIDevice *d) void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, QGuestAllocator *alloc, uint16_t e= ntry) { - uint16_t vector; uint32_t control; uint64_t off; =20 @@ -321,16 +345,12 @@ void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, Q= VirtQueuePCI *vqpci, off + PCI_MSIX_ENTRY_VECTOR_CTRL, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT); =20 - qvirtio_pci_queue_select(&d->vdev, vqpci->vq.index); - qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR, entry); - vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR); - g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); + d->msix_ops->set_queue_vector(d, vqpci->vq.index, entry); } =20 void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, QGuestAllocator *alloc, uint16_t e= ntry) { - uint16_t vector; uint32_t control; uint64_t off; =20 @@ -358,9 +378,7 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioP= CIDevice *d, off + PCI_MSIX_ENTRY_VECTOR_CTRL, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT); =20 - qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR, entry); - vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR); - g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); + d->msix_ops->set_config_vector(d, entry); } =20 void qvirtio_pci_destructor(QOSGraphObject *obj) @@ -383,6 +401,7 @@ static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevi= ce *dev, QPCIDevice *pci_ dev->vdev.device_type =3D qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); =20 dev->config_msix_entry =3D -1; + dev->msix_ops =3D &qvirtio_pci_msix_ops_legacy; =20 dev->vdev.bus =3D &qvirtio_pci; dev->vdev.big_endian =3D qvirtio_pci_is_big_endian(dev); --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571827391; cv=none; d=zoho.com; s=zohoarc; b=bYR+VhgTsalToYPkZqMxsqIi8rkIY8ZezInxO09CzUUBOvfpB8E2mGsL6zctcp7gbjE05e82U4De1UhbMt3U2n6a6DBG8h/wz3EcqdJg6exf0FO6E/0ylfV+3b4RBkZ5UtactJEtYS0cZpuTsHdtVppVRLJZc+4XJpVb4jOk3eU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571827391; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LIN/DOYgg9BTqPmKA47VXqPwcbwf4Up/hhPqrBSgpn8=; b=aDkopSYRyvSNp1eOkeN38T4G9enHgGZJQTuRXysr2DjydjRFXjajAHtFtQurmemzQBxfInrnclDjOXxUQbb8sUn5396p7lnW7OAeSXSgcI3OLbg48m1IJ/XiE1Z5W+jZK09yH+MLAJzok21Sn6sZOzaHbcpeVHg37+2KZbqRp8o= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571827391405351.35663267604605; Wed, 23 Oct 2019 03:43:11 -0700 (PDT) Received: from localhost ([::1]:60124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNE6f-0004j8-2A for importer@patchew.org; Wed, 23 Oct 2019 06:43:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40531) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDYG-0005V1-Fk for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDYC-0003MD-8O for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:36 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:52454 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDYC-0003La-3e for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-uRI-Jxy9ODaBzPx1cVxgvQ-1; Wed, 23 Oct 2019 06:07:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A8781800D6B; Wed, 23 Oct 2019 10:07:27 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD43860F8C; Wed, 23 Oct 2019 10:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LIN/DOYgg9BTqPmKA47VXqPwcbwf4Up/hhPqrBSgpn8=; b=Eh76H5ajggaGVFWGbC41oNbonwhra9r6zWte19ahZJv8/TPYGHp0ITyRQwTAPnWQwlqOPE 8E8OzPOogfjPzhXoHrO+7kSAmGxArEE1BlhPMxaO6NGBMLVaFYUfXiX5zHCZIXGYPeve9f hH/AylJ3YC+GUny6YKMlCTN9Tag2QO0= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 13/16] libqos: expose common virtqueue setup/cleanup functions Date: Wed, 23 Oct 2019 11:04:22 +0100 Message-Id: <20191023100425.12168-14-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: uRI-Jxy9ODaBzPx1cVxgvQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The VIRTIO 1.0 code will need to perform additional steps but it will reuse the common virtqueue setup/cleanup code. Make these functions public. Make sure to invoke callbacks via QVirtioBus instead of directly calling the virtio-pci Legacy versions of these functions. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth --- tests/libqos/virtio-pci.h | 8 ++++++++ tests/libqos/virtio-pci.c | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 4299efc023..0e4a8b7b00 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -65,4 +65,12 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPC= IDevice *d, QGuestAllocator *alloc, uint16_t e= ntry); void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, QGuestAllocator *alloc, uint16_t e= ntry); + +/* Used by Legacy and Modern virtio-pci code */ +QVirtQueue *qvirtio_pci_virtqueue_setup_common(QVirtioDevice *d, + QGuestAllocator *alloc, + uint16_t index); +void qvirtio_pci_virtqueue_cleanup_common(QVirtQueue *vq, + QGuestAllocator *alloc); + #endif diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 0725777a8d..c900742f96 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -207,8 +207,9 @@ static void qvirtio_pci_set_queue_address(QVirtioDevice= *d, QVirtQueue *vq) qpci_io_writel(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_PFN, pfn); } =20 -static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, - QGuestAllocator *alloc, uint16_t i= ndex) +QVirtQueue *qvirtio_pci_virtqueue_setup_common(QVirtioDevice *d, + QGuestAllocator *alloc, + uint16_t index) { uint64_t feat; uint64_t addr; @@ -216,12 +217,12 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirti= oDevice *d, QVirtioPCIDevice *qvpcidev =3D container_of(d, QVirtioPCIDevice, vdev); =20 vqpci =3D g_malloc0(sizeof(*vqpci)); - feat =3D qvirtio_pci_get_guest_features(d); + feat =3D d->bus->get_guest_features(d); =20 - qvirtio_pci_queue_select(d, index); + d->bus->queue_select(d, index); vqpci->vq.vdev =3D d; vqpci->vq.index =3D index; - vqpci->vq.size =3D qvirtio_pci_get_queue_size(d); + vqpci->vq.size =3D d->bus->get_queue_size(d); vqpci->vq.free_head =3D 0; vqpci->vq.num_free =3D vqpci->vq.size; vqpci->vq.align =3D VIRTIO_PCI_VRING_ALIGN; @@ -241,12 +242,12 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirti= oDevice *d, addr =3D guest_alloc(alloc, qvring_size(vqpci->vq.size, VIRTIO_PCI_VRING_ALIGN)); qvring_init(qvpcidev->pdev->bus->qts, alloc, &vqpci->vq, addr); - qvirtio_pci_set_queue_address(d, &vqpci->vq); + d->bus->set_queue_address(d, &vqpci->vq); =20 return &vqpci->vq; } =20 -static void qvirtio_pci_virtqueue_cleanup(QVirtQueue *vq, +void qvirtio_pci_virtqueue_cleanup_common(QVirtQueue *vq, QGuestAllocator *alloc) { QVirtQueuePCI *vqpci =3D container_of(vq, QVirtQueuePCI, vq); @@ -276,8 +277,8 @@ const QVirtioBus qvirtio_pci =3D { .queue_select =3D qvirtio_pci_queue_select, .get_queue_size =3D qvirtio_pci_get_queue_size, .set_queue_address =3D qvirtio_pci_set_queue_address, - .virtqueue_setup =3D qvirtio_pci_virtqueue_setup, - .virtqueue_cleanup =3D qvirtio_pci_virtqueue_cleanup, + .virtqueue_setup =3D qvirtio_pci_virtqueue_setup_common, + .virtqueue_cleanup =3D qvirtio_pci_virtqueue_cleanup_common, .virtqueue_kick =3D qvirtio_pci_virtqueue_kick, }; =20 --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571827088; cv=none; d=zoho.com; s=zohoarc; b=NZTlogjGdtggfdqZ6zTVbRwlCK21SzP40BF49twHKdy/sIVHejj4lc7Gwh3PmJIZhrwxAdBS/JSOfBdC4Z6nNpSkklgxarbxmGRnGIDSYgXVzeZprp0QtO2c++DD5XBZPsaWBQmk7l4HkZoIBJgAMmZ3eJuIluYuOKQVpkntKEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571827088; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=372NNTcYnSIQBMgZ5qLgMiK1FMNHd9cWDMz+HfJfX38=; b=FM0xu9ZZcpXMxPlHiGWDACM968lJ7pE7JYl9zUKEH37O5kL2qIsATpDQbLfgTEX+jFZvImOEZMppLqIOfxTfMFYSEygeQiw6iQ/JcHYg1PCssOgHL5FF9sr0VUBZah+3u8QqVvupPqaQgZmCE+vN2fG1FZLsAbgdz3u75RhtEfQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571827088315380.2705453084574; Wed, 23 Oct 2019 03:38:08 -0700 (PDT) Received: from localhost ([::1]:60072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNE1m-0008S8-QS for importer@patchew.org; Wed, 23 Oct 2019 06:38:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40596) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDYV-0005cW-De for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDYQ-0003VO-Pn for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:33010 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDYO-0003S6-JF for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:07:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-76-tmfB42kUNLCS01B_CPvpXA-1; Wed, 23 Oct 2019 06:07:42 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08E0047B; Wed, 23 Oct 2019 10:07:41 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DC7D1001E75; Wed, 23 Oct 2019 10:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=372NNTcYnSIQBMgZ5qLgMiK1FMNHd9cWDMz+HfJfX38=; b=baVmfWePoKv+K5NaAezBlUcndLnhECBFWXxBh6RVfZr8wl3LU11PffjNtfpoxajvktyPqJ tbs1s1+teOdywQAvPRizDP9XSwiYPhHASb+sff/nF+yQrLecOH1i1/EPb0lsofOCXd7na4 GKUt/nGxMPzGrFSGJ5vDdo66CEue280= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 14/16] libqos: make the virtio-pci BAR index configurable Date: Wed, 23 Oct 2019 11:04:23 +0100 Message-Id: <20191023100425.12168-15-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: tmfB42kUNLCS01B_CPvpXA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The Legacy virtio-pci interface always uses BAR 0. VIRTIO 1.0 may need to use a different BAR index, so make it configurable. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v3: * Change uint8_t bar_idx to int [Thomas] --- tests/libqos/virtio-pci.h | 2 ++ tests/libqos/virtio-pci.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 0e4a8b7b00..78a1c15c2a 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -25,6 +25,8 @@ typedef struct QVirtioPCIDevice { uint16_t config_msix_entry; uint64_t config_msix_addr; uint32_t config_msix_data; + + int bar_idx; } QVirtioPCIDevice; =20 struct QVirtioPCIMSIXOps { diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index c900742f96..e9595603f5 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -310,7 +310,7 @@ static const QVirtioPCIMSIXOps qvirtio_pci_msix_ops_leg= acy =3D { void qvirtio_pci_device_enable(QVirtioPCIDevice *d) { qpci_device_enable(d->pdev); - d->bar =3D qpci_iomap(d->pdev, 0, NULL); + d->bar =3D qpci_iomap(d->pdev, d->bar_idx, NULL); } =20 void qvirtio_pci_device_disable(QVirtioPCIDevice *d) @@ -400,6 +400,7 @@ static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevi= ce *dev, QPCIDevice *pci_ { dev->pdev =3D pci_dev; dev->vdev.device_type =3D qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); + dev->bar_idx =3D 0; =20 dev->config_msix_entry =3D -1; dev->msix_ops =3D &qvirtio_pci_msix_ops_legacy; --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571825894; cv=none; d=zoho.com; s=zohoarc; b=HgOdPhQrf7aXLv6Qdxkss91ohIwvzbUZsbKiz8qcv81ae2I7Nc8gR6Jd6L1EJJEkVrBBfUPEFkoUTY+IYeEL1fq8l7VUaOIrgTUZNnQ9aQI8tNQj8BPga4/J0whwq7smRPyj8wZw67xVqs06z3wuYRnlrq+Bcy0E1RQQpgpPP5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571825894; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VGXsySC3CD9/9kCq/1CSF79CJqClIPOWzVhKaZ/m5T0=; b=Ukn7d4fI0idlSwH9aej5BRWRv7hzfJoGzA1oJOrt7rCg1QGkOhDfzOq5U1qwoL17s52wBHGFLUSCyJmSGVv9ceH4lUnNJhaCN+k53z4eokfPM0BHdBPztqhUwGUbpryL7/twxymw1ushXkFmCYqlTks+iu0G6uZKrQyola4MSBY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571825894536861.6538213474767; Wed, 23 Oct 2019 03:18:14 -0700 (PDT) Received: from localhost ([::1]:59860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDiW-0003Fg-5A for importer@patchew.org; Wed, 23 Oct 2019 06:18:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40633) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDYi-0005em-F0 for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:08:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDYg-0003d3-DX for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:08:04 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:32992 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDYg-0003bV-8y for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:08:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-CyDo1OtQNbCOsOMelTkPWQ-1; Wed, 23 Oct 2019 06:07:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B0F8107AD31; Wed, 23 Oct 2019 10:07:55 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BB5660BE1; Wed, 23 Oct 2019 10:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGXsySC3CD9/9kCq/1CSF79CJqClIPOWzVhKaZ/m5T0=; b=DAm98BDNkrtAcNBBsZXNBqqC8t5syFV64JqbSdS7JrD6GsSwyeSyo+YEcwtUgiC8Ob3S0F yqxEBaBWmWAZM+4rEzX2XElqS0geWdqPuTHPy7Sxu0KGv3H+CGDtsv4iBfQQGXLNrpJGry PpkgGiRkocrVbOT/oq0zN0pWr38LG9w= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 15/16] libqos: extract Legacy virtio-pci.c code Date: Wed, 23 Oct 2019 11:04:24 +0100 Message-Id: <20191023100425.12168-16-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: CyDo1OtQNbCOsOMelTkPWQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The current libqos virtio-pci.c code implements the VIRTIO Legacy interface. Extract existing code in preparation for VIRTIO 1.0 support. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/libqos/virtio-pci.h | 2 -- tests/libqos/virtio-pci.c | 29 ++++++++++++----------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 78a1c15c2a..6b3a385b06 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -45,8 +45,6 @@ typedef struct QVirtQueuePCI { uint32_t msix_data; } QVirtQueuePCI; =20 -extern const QVirtioBus qvirtio_pci; - void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * ad= dr); QVirtioPCIDevice *virtio_pci_new(QPCIBus *bus, QPCIAddress * addr); =20 diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index e9595603f5..11866f7772 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -35,14 +35,6 @@ * original qvirtio_pci_destructor and qvirtio_pci_start_hw. */ =20 -static inline bool qvirtio_pci_is_big_endian(QVirtioPCIDevice *dev) -{ - QPCIBus *bus =3D dev->pdev->bus; - - /* FIXME: virtio 1.0 is always little-endian */ - return qtest_big_endian(bus->qts); -} - #define CONFIG_BASE(dev) (VIRTIO_PCI_CONFIG_OFF((dev)->pdev->msix_enabled)) =20 static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off) @@ -55,8 +47,7 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d,= uint64_t off) * but virtio ( < 1.0) is in guest order * so with a big-endian guest the order has been reversed, * reverse it again - * virtio-1.0 is always little-endian, like PCI, but this - * case will be managed inside qvirtio_pci_is_big_endian() + * virtio-1.0 is always little-endian, like PCI */ =20 static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t off) @@ -262,7 +253,7 @@ static void qvirtio_pci_virtqueue_kick(QVirtioDevice *d= , QVirtQueue *vq) qpci_io_writew(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_NOTIFY, vq->index= ); } =20 -const QVirtioBus qvirtio_pci =3D { +static const QVirtioBus qvirtio_pci_legacy =3D { .config_readb =3D qvirtio_pci_config_readb, .config_readw =3D qvirtio_pci_config_readw, .config_readl =3D qvirtio_pci_config_readl, @@ -396,17 +387,21 @@ void qvirtio_pci_start_hw(QOSGraphObject *obj) qvirtio_start_device(&dev->vdev); } =20 +static void qvirtio_pci_init_legacy(QVirtioPCIDevice *dev) +{ + dev->vdev.device_type =3D qpci_config_readw(dev->pdev, PCI_SUBSYSTEM_I= D); + dev->bar_idx =3D 0; + dev->vdev.bus =3D &qvirtio_pci_legacy; + dev->msix_ops =3D &qvirtio_pci_msix_ops_legacy; + dev->vdev.big_endian =3D qtest_big_endian(dev->pdev->bus->qts); +} + static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevice *dev, QPCIDevice= *pci_dev) { dev->pdev =3D pci_dev; - dev->vdev.device_type =3D qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); - dev->bar_idx =3D 0; - dev->config_msix_entry =3D -1; - dev->msix_ops =3D &qvirtio_pci_msix_ops_legacy; =20 - dev->vdev.bus =3D &qvirtio_pci; - dev->vdev.big_endian =3D qvirtio_pci_is_big_endian(dev); + qvirtio_pci_init_legacy(dev); =20 /* each virtio-xxx-pci device should override at least this function */ dev->obj.get_driver =3D NULL; --=20 2.21.0 From nobody Wed May 8 00:45:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571827412; cv=none; d=zoho.com; s=zohoarc; b=CfZnz9hxbGabDvbA02/T4qa/SSCr11xBi/Smn1hpBazREK2OAVhLfZwtaxNpYWkuaz88lxtNFolXYKVdoAlSl9aF5qjHHUgtRQLmdQ0Yy61wFQH8O9mADLUACjRtmF2uUeriP1XnN4enUmBmLGHZFd45QikUNXo07lCsms0OoJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571827412; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lQz9Ln+XJFkmTn6T9v3I/jYf9tXweXv6lQuvrs73is8=; b=Jtz9B2uWJUTba4oBLQ0Xw9cbgkt2/iUyFpzj/AJLfpDxmhB9GHFubvtqmb9c6B7RsR5TGldz2LpTj9Q108HO/00NTcsOExFGrqZ6ZhVlNRZvjJUX+iqt/mqvE445wziRIcFEPLhwBpKUnn7AaE1UoxlyUu45bnc+fjgBLDWQgH4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571827412113106.83083863731838; Wed, 23 Oct 2019 03:43:32 -0700 (PDT) Received: from localhost ([::1]:60128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNE6z-0005gL-GB for importer@patchew.org; Wed, 23 Oct 2019 06:43:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40666) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNDYt-0005ra-9F for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:08:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNDYq-0003hd-Of for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:08:15 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47472 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNDYq-0003hT-JY for qemu-devel@nongnu.org; Wed, 23 Oct 2019 06:08:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-93-MBugGOlHPiaIOMzuuL-35w-1; Wed, 23 Oct 2019 06:08:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D98441800D6B; Wed, 23 Oct 2019 10:08:07 +0000 (UTC) Received: from localhost (unknown [10.36.118.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF5BA6061E; Wed, 23 Oct 2019 10:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571825292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQz9Ln+XJFkmTn6T9v3I/jYf9tXweXv6lQuvrs73is8=; b=P2qDztOeo1SEbXyQ7SxJ9cmuXYnZrazERFXdfZV8mJj2ujjoJPel6hRp8Bpf+ctnkAzBKv WAqdFFkMIvss9OF7aQKDs8QHFevQYeNF2bCVx6n8vIBufRnXus/LcTprAc/VFhO+gIGuhV sf6dfedocOi5QdrK0TM/BbCXCbIFQ2c= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 16/16] libqos: add VIRTIO PCI 1.0 support Date: Wed, 23 Oct 2019 11:04:25 +0100 Message-Id: <20191023100425.12168-17-stefanha@redhat.com> In-Reply-To: <20191023100425.12168-1-stefanha@redhat.com> References: <20191023100425.12168-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: MBugGOlHPiaIOMzuuL-35w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, slp@redhat.com, "Michael S. Tsirkin" , Cornelia Huck , Stefan Hajnoczi , Christophe de Dinechin , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Implement the VIRTIO 1.0 virtio-pci interface. The main change here is that the register layout is no longer a fixed layout in BAR 0. Instead we have to iterate of PCI Capabilities to find descriptions of where various registers are located. The vring registers are also more fine-grained, allowing for more flexible vring layouts, but we don't take advantage of that. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Acked-by: Thomas Huth --- tests/Makefile.include | 1 + tests/libqos/virtio-pci-modern.h | 17 ++ tests/libqos/virtio-pci.h | 10 + tests/libqos/virtio-pci-modern.c | 443 +++++++++++++++++++++++++++++++ tests/libqos/virtio-pci.c | 6 +- 5 files changed, 476 insertions(+), 1 deletion(-) create mode 100644 tests/libqos/virtio-pci-modern.h create mode 100644 tests/libqos/virtio-pci-modern.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 3543451ed3..3f633c8313 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -715,6 +715,7 @@ qos-test-obj-y +=3D tests/libqos/virtio-blk.o qos-test-obj-y +=3D tests/libqos/virtio-mmio.o qos-test-obj-y +=3D tests/libqos/virtio-net.o qos-test-obj-y +=3D tests/libqos/virtio-pci.o +qos-test-obj-y +=3D tests/libqos/virtio-pci-modern.o qos-test-obj-y +=3D tests/libqos/virtio-rng.o qos-test-obj-y +=3D tests/libqos/virtio-scsi.o qos-test-obj-y +=3D tests/libqos/virtio-serial.o diff --git a/tests/libqos/virtio-pci-modern.h b/tests/libqos/virtio-pci-mod= ern.h new file mode 100644 index 0000000000..6bf2b207c3 --- /dev/null +++ b/tests/libqos/virtio-pci-modern.h @@ -0,0 +1,17 @@ +/* + * libqos virtio PCI VIRTIO 1.0 definitions + * + * Copyright (c) 2019 Red Hat, Inc + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef LIBQOS_VIRTIO_PCI_MODERN_H +#define LIBQOS_VIRTIO_PCI_MODERN_H + +#include "virtio-pci.h" + +bool qvirtio_pci_init_virtio_1(QVirtioPCIDevice *dev); + +#endif /* LIBQOS_VIRTIO_PCI_MODERN_H */ diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 6b3a385b06..294d5567ee 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -27,6 +27,13 @@ typedef struct QVirtioPCIDevice { uint32_t config_msix_data; =20 int bar_idx; + + /* VIRTIO 1.0 */ + uint32_t common_cfg_offset; + uint32_t notify_cfg_offset; + uint32_t notify_off_multiplier; + uint32_t isr_cfg_offset; + uint32_t device_cfg_offset; } QVirtioPCIDevice; =20 struct QVirtioPCIMSIXOps { @@ -43,6 +50,9 @@ typedef struct QVirtQueuePCI { uint16_t msix_entry; uint64_t msix_addr; uint32_t msix_data; + + /* VIRTIO 1.0 */ + uint64_t notify_offset; } QVirtQueuePCI; =20 void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * ad= dr); diff --git a/tests/libqos/virtio-pci-modern.c b/tests/libqos/virtio-pci-mod= ern.c new file mode 100644 index 0000000000..18d118866f --- /dev/null +++ b/tests/libqos/virtio-pci-modern.c @@ -0,0 +1,443 @@ +/* + * libqos VIRTIO 1.0 PCI driver + * + * Copyright (c) 2019 Red Hat, Inc + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "standard-headers/linux/pci_regs.h" +#include "standard-headers/linux/virtio_pci.h" +#include "standard-headers/linux/virtio_config.h" +#include "virtio-pci-modern.h" + +static uint8_t config_readb(QVirtioDevice *d, uint64_t addr) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + return qpci_io_readb(dev->pdev, dev->bar, dev->device_cfg_offset + add= r); +} + +static uint16_t config_readw(QVirtioDevice *d, uint64_t addr) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + return qpci_io_readw(dev->pdev, dev->bar, dev->device_cfg_offset + add= r); +} + +static uint32_t config_readl(QVirtioDevice *d, uint64_t addr) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + return qpci_io_readl(dev->pdev, dev->bar, dev->device_cfg_offset + add= r); +} + +static uint64_t config_readq(QVirtioDevice *d, uint64_t addr) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + return qpci_io_readq(dev->pdev, dev->bar, dev->device_cfg_offset + add= r); +} + +static uint64_t get_features(QVirtioDevice *d) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + uint64_t lo, hi; + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + device_feature_select), + 0); + lo =3D qpci_io_readl(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, device_featu= re)); + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + device_feature_select), + 1); + hi =3D qpci_io_readl(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, device_featu= re)); + + return (hi << 32) | lo; +} + +static void set_features(QVirtioDevice *d, uint64_t features) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + /* Drivers must enable VIRTIO 1.0 or else use the Legacy interface */ + g_assert_cmphex(features & (1ull << VIRTIO_F_VERSION_1), !=3D, 0); + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + guest_feature_select), + 0); + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + guest_feature), + features); + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + guest_feature_select), + 1); + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + guest_feature), + features >> 32); +} + +static uint64_t get_guest_features(QVirtioDevice *d) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + uint64_t lo, hi; + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + guest_feature_select), + 0); + lo =3D qpci_io_readl(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, guest_featur= e)); + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + guest_feature_select), + 1); + hi =3D qpci_io_readl(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, guest_featur= e)); + + return (hi << 32) | lo; +} + +static uint8_t get_status(QVirtioDevice *d) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + return qpci_io_readb(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + device_status)); +} + +static void set_status(QVirtioDevice *d, uint8_t status) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + return qpci_io_writeb(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + device_status), + status); +} + +static bool get_msix_status(QVirtioPCIDevice *dev, uint32_t msix_entry, + uint32_t msix_addr, uint32_t msix_data) +{ + uint32_t data; + + g_assert_cmpint(msix_entry, !=3D, -1); + if (qpci_msix_masked(dev->pdev, msix_entry)) { + /* No ISR checking should be done if masked, but read anyway */ + return qpci_msix_pending(dev->pdev, msix_entry); + } + + data =3D qtest_readl(dev->pdev->bus->qts, msix_addr); + if (data =3D=3D msix_data) { + qtest_writel(dev->pdev->bus->qts, msix_addr, 0); + return true; + } else { + return false; + } +} + +static bool get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + if (dev->pdev->msix_enabled) { + QVirtQueuePCI *vqpci =3D container_of(vq, QVirtQueuePCI, vq); + + return get_msix_status(dev, vqpci->msix_entry, vqpci->msix_addr, + vqpci->msix_data); + } + + return qpci_io_readb(dev->pdev, dev->bar, dev->isr_cfg_offset) & 1; +} + +static bool get_config_isr_status(QVirtioDevice *d) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + if (dev->pdev->msix_enabled) { + return get_msix_status(dev, dev->config_msix_entry, + dev->config_msix_addr, dev->config_msix_dat= a); + } + + return qpci_io_readb(dev->pdev, dev->bar, dev->isr_cfg_offset) & 2; +} + +static void wait_config_isr_status(QVirtioDevice *d, gint64 timeout_us) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + gint64 start_time =3D g_get_monotonic_time(); + + do { + g_assert(g_get_monotonic_time() - start_time <=3D timeout_us); + qtest_clock_step(dev->pdev->bus->qts, 100); + } while (!get_config_isr_status(d)); +} + +static void queue_select(QVirtioDevice *d, uint16_t index) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + qpci_io_writew(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_select), + index); +} + +static uint16_t get_queue_size(QVirtioDevice *d) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + return qpci_io_readw(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_size= )); +} + +static void set_queue_address(QVirtioDevice *d, QVirtQueue *vq) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_desc_lo), + vq->desc); + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_desc_hi), + vq->desc >> 32); + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_avail_lo), + vq->avail); + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_avail_hi), + vq->avail >> 32); + + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_used_lo), + vq->used); + qpci_io_writel(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_used_hi), + vq->used >> 32); +} + +static QVirtQueue *virtqueue_setup(QVirtioDevice *d, QGuestAllocator *allo= c, + uint16_t index) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + QVirtQueue *vq; + QVirtQueuePCI *vqpci; + uint16_t notify_off; + + vq =3D qvirtio_pci_virtqueue_setup_common(d, alloc, index); + vqpci =3D container_of(vq, QVirtQueuePCI, vq); + + notify_off =3D qpci_io_readw(dev->pdev, dev->bar, dev->common_cfg_offs= et + + offsetof(struct virtio_pci_common_cfg, + queue_notify_off)); + + vqpci->notify_offset =3D dev->notify_cfg_offset + + notify_off * dev->notify_off_multiplier; + + qpci_io_writew(dev->pdev, dev->bar, dev->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_enable), 1= ); + + return vq; +} + +static void virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) +{ + QVirtioPCIDevice *dev =3D container_of(d, QVirtioPCIDevice, vdev); + QVirtQueuePCI *vqpci =3D container_of(vq, QVirtQueuePCI, vq); + + qpci_io_writew(dev->pdev, dev->bar, vqpci->notify_offset, vq->index); +} + +static const QVirtioBus qvirtio_pci_virtio_1 =3D { + .config_readb =3D config_readb, + .config_readw =3D config_readw, + .config_readl =3D config_readl, + .config_readq =3D config_readq, + .get_features =3D get_features, + .set_features =3D set_features, + .get_guest_features =3D get_guest_features, + .get_status =3D get_status, + .set_status =3D set_status, + .get_queue_isr_status =3D get_queue_isr_status, + .wait_config_isr_status =3D wait_config_isr_status, + .queue_select =3D queue_select, + .get_queue_size =3D get_queue_size, + .set_queue_address =3D set_queue_address, + .virtqueue_setup =3D virtqueue_setup, + .virtqueue_cleanup =3D qvirtio_pci_virtqueue_cleanup_common, + .virtqueue_kick =3D virtqueue_kick, +}; + +static void set_config_vector(QVirtioPCIDevice *d, uint16_t entry) +{ + uint16_t vector; + + qpci_io_writew(d->pdev, d->bar, d->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, msix_config), en= try); + vector =3D qpci_io_readw(d->pdev, d->bar, d->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + msix_config)); + g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); +} + +static void set_queue_vector(QVirtioPCIDevice *d, uint16_t vq_idx, + uint16_t entry) +{ + uint16_t vector; + + queue_select(&d->vdev, vq_idx); + qpci_io_writew(d->pdev, d->bar, d->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, queue_msix_vecto= r), + entry); + vector =3D qpci_io_readw(d->pdev, d->bar, d->common_cfg_offset + + offsetof(struct virtio_pci_common_cfg, + queue_msix_vector)); + g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); +} + +static const QVirtioPCIMSIXOps qvirtio_pci_msix_ops_virtio_1 =3D { + .set_config_vector =3D set_config_vector, + .set_queue_vector =3D set_queue_vector, +}; + +static bool probe_device_type(QVirtioPCIDevice *dev) +{ + uint16_t vendor_id; + uint16_t device_id; + + /* "Drivers MUST match devices with the PCI Vendor ID 0x1AF4" */ + vendor_id =3D qpci_config_readw(dev->pdev, PCI_VENDOR_ID); + if (vendor_id !=3D 0x1af4) { + return false; + } + + /* + * "Any PCI device with ... PCI Device ID 0x1000 through 0x107F inclus= ive + * is a virtio device" + */ + device_id =3D qpci_config_readw(dev->pdev, PCI_DEVICE_ID); + if (device_id < 0x1000 || device_id > 0x107f) { + return false; + } + + /* + * "Devices MAY utilize a Transitional PCI Device ID range, 0x1000 to + * 0x103F depending on the device type" + */ + if (device_id < 0x1040) { + /* + * "Transitional devices MUST have the PCI Subsystem Device ID mat= ching + * the Virtio Device ID" + */ + dev->vdev.device_type =3D qpci_config_readw(dev->pdev, PCI_SUBSYST= EM_ID); + } else { + /* + * "The PCI Device ID is calculated by adding 0x1040 to the Virtio + * Device ID" + */ + dev->vdev.device_type =3D device_id - 0x1040; + } + + return true; +} + +/* Find the first VIRTIO 1.0 PCI structure for a given type */ +static bool find_structure(QVirtioPCIDevice *dev, uint8_t cfg_type, + uint8_t *bar, uint32_t *offset, uint32_t *lengt= h, + uint8_t *cfg_addr) +{ + uint8_t addr =3D 0; + + while ((addr =3D qpci_find_capability(dev->pdev, PCI_CAP_ID_VNDR, + addr)) !=3D 0) { + uint8_t type; + + type =3D qpci_config_readb(dev->pdev, + addr + offsetof(struct virtio_pci_cap, cfg_type)); + if (type !=3D cfg_type) { + continue; + } + + *bar =3D qpci_config_readb(dev->pdev, + addr + offsetof(struct virtio_pci_cap, bar)); + *offset =3D qpci_config_readl(dev->pdev, + addr + offsetof(struct virtio_pci_cap, offset)); + *length =3D qpci_config_readl(dev->pdev, + addr + offsetof(struct virtio_pci_cap, length)); + if (cfg_addr) { + *cfg_addr =3D addr; + } + + return true; + } + + return false; +} + +static bool probe_device_layout(QVirtioPCIDevice *dev) +{ + uint8_t bar; + uint8_t cfg_addr; + uint32_t length; + + /* + * Due to the qpci_iomap() API we only support devices that put all + * structures in the same PCI BAR. Luckily this is true with QEMU. + */ + + if (!find_structure(dev, VIRTIO_PCI_CAP_COMMON_CFG, &bar, + &dev->common_cfg_offset, &length, NULL)) { + return false; + } + dev->bar_idx =3D bar; + + if (!find_structure(dev, VIRTIO_PCI_CAP_NOTIFY_CFG, &bar, + &dev->notify_cfg_offset, &length, &cfg_addr)) { + return false; + } + g_assert_cmphex(bar, =3D=3D, dev->bar_idx); + + dev->notify_off_multiplier =3D qpci_config_readl(dev->pdev, + cfg_addr + offsetof(struct virtio_pci_notify_cap, + notify_off_multiplier)); + + if (!find_structure(dev, VIRTIO_PCI_CAP_ISR_CFG, &bar, + &dev->isr_cfg_offset, &length, NULL)) { + return false; + } + g_assert_cmphex(bar, =3D=3D, dev->bar_idx); + + if (!find_structure(dev, VIRTIO_PCI_CAP_DEVICE_CFG, &bar, + &dev->device_cfg_offset, &length, NULL)) { + return false; + } + g_assert_cmphex(bar, =3D=3D, dev->bar_idx); + + return true; +} + +/* Probe a VIRTIO 1.0 device */ +bool qvirtio_pci_init_virtio_1(QVirtioPCIDevice *dev) +{ + if (!probe_device_type(dev)) { + return false; + } + + if (!probe_device_layout(dev)) { + return false; + } + + dev->vdev.bus =3D &qvirtio_pci_virtio_1; + dev->msix_ops =3D &qvirtio_pci_msix_ops_virtio_1; + dev->vdev.big_endian =3D false; + return true; +} diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 11866f7772..62851c29bb 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -22,6 +22,8 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_regs.h" =20 +#include "virtio-pci-modern.h" + /* virtio-pci is a superclass of all virtio-xxx-pci devices; * the relation between virtio-pci and virtio-xxx-pci is implicit, * and therefore virtio-pci does not produce virtio and is not @@ -401,7 +403,9 @@ static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevi= ce *dev, QPCIDevice *pci_ dev->pdev =3D pci_dev; dev->config_msix_entry =3D -1; =20 - qvirtio_pci_init_legacy(dev); + if (!qvirtio_pci_init_virtio_1(dev)) { + qvirtio_pci_init_legacy(dev); + } =20 /* each virtio-xxx-pci device should override at least this function */ dev->obj.get_driver =3D NULL; --=20 2.21.0