From patchwork Fri Jul 1 14:24:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 12903409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7D1FC43334 for ; Fri, 1 Jul 2022 14:31:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233234AbiGAObK (ORCPT ); Fri, 1 Jul 2022 10:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbiGAOak (ORCPT ); Fri, 1 Jul 2022 10:30:40 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1742D7125C for ; Fri, 1 Jul 2022 07:25:51 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 592DB1BF7; Fri, 1 Jul 2022 07:25:28 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BB5A13F792; Fri, 1 Jul 2022 07:25:26 -0700 (PDT) From: Jean-Philippe Brucker To: will@kernel.org Cc: andre.przywara@arm.com, alexandru.elisei@arm.com, kvm@vger.kernel.org, suzuki.poulose@arm.com, sashal@kernel.org, jean-philippe@linaro.org Subject: [PATCH kvmtool v2 05/12] virtio/net: Set vhost backend after queue address Date: Fri, 1 Jul 2022 15:24:27 +0100 Message-Id: <20220701142434.75170-6-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220701142434.75170-1-jean-philippe.brucker@arm.com> References: <20220701142434.75170-1-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We currently call VHOST_SET_BACKEND from notify_vq_gsi(), which can't work with modern virtio because vhost checks that the virtqueue is accessible when handling VHOST_SET_BACKEND, and the modern driver initializes the MSIs before setting up the virtqueue. Move VHOST_SET_BACKEND to init_vq(). Signed-off-by: Jean-Philippe Brucker --- virtio/net.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/virtio/net.c b/virtio/net.c index f8c40d40..dcf9210d 100644 --- a/virtio/net.c +++ b/virtio/net.c @@ -601,6 +601,7 @@ static bool is_ctrl_vq(struct net_dev *ndev, u32 vq) static int init_vq(struct kvm *kvm, void *dev, u32 vq) { struct vhost_vring_state state = { .index = vq }; + struct vhost_vring_file file = { .index = vq }; struct net_dev_queue *net_queue; struct vhost_vring_addr addr; struct net_dev *ndev = dev; @@ -656,6 +657,11 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq) if (r < 0) die_perror("VHOST_SET_VRING_ADDR failed"); + file.fd = ndev->tap_fd; + r = ioctl(ndev->vhost_fd, VHOST_NET_SET_BACKEND, &file); + if (r < 0) + die_perror("VHOST_NET_SET_BACKEND failed"); + return 0; } @@ -713,11 +719,6 @@ static void notify_vq_gsi(struct kvm *kvm, void *dev, u32 vq, u32 gsi) r = ioctl(ndev->vhost_fd, VHOST_SET_VRING_CALL, &file); if (r < 0) die_perror("VHOST_SET_VRING_CALL failed"); - file.fd = ndev->tap_fd; - r = ioctl(ndev->vhost_fd, VHOST_NET_SET_BACKEND, &file); - if (r != 0) - die("VHOST_NET_SET_BACKEND failed %d", errno); - } static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)