From patchwork Fri Sep 9 10:14:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 9322845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D10B60231 for ; Fri, 9 Sep 2016 10:15:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F74F29D1A for ; Fri, 9 Sep 2016 10:15:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83C5029CAA; Fri, 9 Sep 2016 10:15:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC8EC29CAA for ; Fri, 9 Sep 2016 10:15:12 +0000 (UTC) Received: from localhost ([::1]:56944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIq0-0004mi-06 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Sep 2016 06:15:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIpY-0004lp-Gc for qemu-devel@nongnu.org; Fri, 09 Sep 2016 06:14:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biIpT-0000LB-FZ for qemu-devel@nongnu.org; Fri, 09 Sep 2016 06:14:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biIpT-0000Kv-Ac; Fri, 09 Sep 2016 06:14:39 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0103E4FC; Fri, 9 Sep 2016 10:14:39 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-4-133.ams2.redhat.com [10.36.4.133]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u89AEYA8003785; Fri, 9 Sep 2016 06:14:37 -0400 From: Maxime Coquelin To: mst@redhat.com, qemu-devel@nongnu.org Date: Fri, 9 Sep 2016 12:14:31 +0200 Message-Id: <1473416072-7063-2-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1473416072-7063-1-git-send-email-maxime.coquelin@redhat.com> References: <1473416072-7063-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 09 Sep 2016 10:14:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] virtio: Add backend feature testing functionnality X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcel@redhat.com, vkaplans@redhat.com, Maxime Coquelin , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds virtio_test_backend_feature() function to enable checking a backend feature before the negociation takes place. It may be used, for example, to check whether the backend supports VIRTIO_F_VERSION_1 before enabling modern capabilities. Cc: Marcel Apfelbaum Cc: Michael S. Tsirkin Cc: qemu-stable@nongnu.org Signed-off-by: Maxime Coquelin --- hw/virtio/virtio.c | 14 ++++++++++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 74c085c..7ab91a1 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1481,6 +1481,20 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) virtio_save(VIRTIO_DEVICE(opaque), f); } +bool virtio_test_backend_feature(VirtIODevice *vdev, + unsigned int fbit, Error **errp) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint64_t feature; + + virtio_add_feature(&feature, fbit); + + assert(k->get_features != NULL); + feature = k->get_features(vdev, feature, errp); + + return virtio_has_feature(feature, fbit); +} + static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val) { VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index d2490c1..5fb74c8 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -235,6 +235,8 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val); void virtio_reset(void *opaque); void virtio_update_irq(VirtIODevice *vdev); int virtio_set_features(VirtIODevice *vdev, uint64_t val); +bool virtio_test_backend_feature(VirtIODevice *vdev, + unsigned int fbit, Error **errp); /* Base devices. */ typedef struct VirtIOBlkConf VirtIOBlkConf;