From patchwork Tue Feb 4 16:53:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 3577911 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F2D0FC02DD for ; Tue, 4 Feb 2014 16:54:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2DA3D2018B for ; Tue, 4 Feb 2014 16:54:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55539201B9 for ; Tue, 4 Feb 2014 16:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932179AbaBDQyE (ORCPT ); Tue, 4 Feb 2014 11:54:04 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:49548 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932152AbaBDQx6 (ORCPT ); Tue, 4 Feb 2014 11:53:58 -0500 Received: from mudshark.cambridge.arm.com (mudshark.cambridge.arm.com [10.1.203.36]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s14GrXki003308; Tue, 4 Feb 2014 16:53:33 GMT Received: by mudshark.cambridge.arm.com (Postfix, from userid 1000) id 765AFC2A8A; Tue, 4 Feb 2014 16:53:32 +0000 (GMT) From: Will Deacon To: kvm@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, penberg@kernel.org, marc.zyngier@arm.com, arnd@arndb.de Subject: [PATCH 04/17] kvm tools: net: allow a mixture of pci and mmio virtio devices Date: Tue, 4 Feb 2014 16:53:19 +0000 Message-Id: <1391532812-2043-5-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: <1391532812-2043-1-git-send-email-will.deacon@arm.com> References: <1391532812-2043-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When attempting to initialise a mixture of pci and mmio virtio devices, we cannot share an ops structure, otherwise the transport-specific fields (init/exit and signal handling) will be globally set to the transport of the last registered device. This patch dynamically allocates a new ops structure for each instance of a virtio net device. Signed-off-by: Will Deacon --- tools/kvm/virtio/net.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index ae4712c3c550..dbb443124ee1 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -713,13 +713,20 @@ done: static int virtio_net__init_one(struct virtio_net_params *params) { - int i; + int i, err; struct net_dev *ndev; + struct virtio_ops *ops; ndev = calloc(1, sizeof(struct net_dev)); if (ndev == NULL) return -ENOMEM; + ops = malloc(sizeof(*ops)); + if (ops == NULL) { + err = -ENOMEM; + goto err_free_ndev; + } + list_add_tail(&ndev->list, &ndevs); ndev->kvm = params->kvm; @@ -749,12 +756,13 @@ static int virtio_net__init_one(struct virtio_net_params *params) uip_static_init(&ndev->info); } + *ops = net_dev_virtio_ops; if (params->trans && strcmp(params->trans, "mmio") == 0) - virtio_init(params->kvm, ndev, &ndev->vdev, &net_dev_virtio_ops, - VIRTIO_MMIO, PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET); + virtio_init(params->kvm, ndev, &ndev->vdev, ops, VIRTIO_MMIO, + PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET); else - virtio_init(params->kvm, ndev, &ndev->vdev, &net_dev_virtio_ops, - VIRTIO_PCI, PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET); + virtio_init(params->kvm, ndev, &ndev->vdev, ops, VIRTIO_PCI, + PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET); if (params->vhost) virtio_net__vhost_init(params->kvm, ndev); @@ -763,6 +771,10 @@ static int virtio_net__init_one(struct virtio_net_params *params) compat_id = virtio_compat_add_message("virtio-net", "CONFIG_VIRTIO_NET"); return 0; + +err_free_ndev: + free(ndev); + return err; } int virtio_net__init(struct kvm *kvm)