From patchwork Tue Jun 7 17:02:33 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: 12872169 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 02265C433EF for ; Tue, 7 Jun 2022 17:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345379AbiFGRDy (ORCPT ); Tue, 7 Jun 2022 13:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345406AbiFGRDq (ORCPT ); Tue, 7 Jun 2022 13:03:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A3CD1021F0 for ; Tue, 7 Jun 2022 10:03:42 -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 5BB771515; Tue, 7 Jun 2022 10:03:42 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EADD53F66F; Tue, 7 Jun 2022 10:03:40 -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, sasha.levin@oracle.com, jean-philippe@linaro.org Subject: [PATCH kvmtool 18/24] virtio: Extract init_vq() for PCI and MMIO Date: Tue, 7 Jun 2022 18:02:33 +0100 Message-Id: <20220607170239.120084-19-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607170239.120084-1-jean-philippe.brucker@arm.com> References: <20220607170239.120084-1-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Modern virtio will need to reuse this code when initializing a virtqueue. It's not much, but still nicer to have next to exit_vq(). Signed-off-by: Jean-Philippe Brucker --- virtio/mmio.c | 19 +++++++++++++++---- virtio/pci.c | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/virtio/mmio.c b/virtio/mmio.c index 268a4391..2a96e0e3 100644 --- a/virtio/mmio.c +++ b/virtio/mmio.c @@ -79,6 +79,20 @@ int virtio_mmio_signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq) return 0; } +static int virtio_mmio_init_vq(struct kvm *kvm, struct virtio_device *vdev, + int vq) +{ + int ret; + struct virtio_mmio *vmmio = vdev->virtio; + + ret = virtio_mmio_init_ioeventfd(vmmio->kvm, vdev, vq); + if (ret) { + pr_err("couldn't add ioeventfd for vq %d: %d", vq, ret); + return ret; + } + return vdev->ops->init_vq(vmmio->kvm, vmmio->dev, vq); +} + static void virtio_mmio_exit_vq(struct kvm *kvm, struct virtio_device *vdev, int vq) { @@ -200,10 +214,7 @@ static void virtio_mmio_config_out(struct kvm_cpu *vcpu, .align = vmmio->hdr.queue_align, .pgsize = vmmio->hdr.guest_page_size, }; - virtio_mmio_init_ioeventfd(vmmio->kvm, vdev, - vmmio->hdr.queue_sel); - vdev->ops->init_vq(vmmio->kvm, vmmio->dev, - vmmio->hdr.queue_sel); + virtio_mmio_init_vq(kvm, vdev, vmmio->hdr.queue_sel); } else { virtio_mmio_exit_vq(kvm, vdev, vmmio->hdr.queue_sel); } diff --git a/virtio/pci.c b/virtio/pci.c index 9b710852..f0459925 100644 --- a/virtio/pci.c +++ b/virtio/pci.c @@ -128,6 +128,20 @@ free_ioport_evt: return r; } +static int virtio_pci_init_vq(struct kvm *kvm, struct virtio_device *vdev, + int vq) +{ + int ret; + struct virtio_pci *vpci = vdev->virtio; + + ret = virtio_pci__init_ioeventfd(kvm, vdev, vq); + if (ret) { + pr_err("couldn't add ioeventfd for vq %d: %d", vq, ret); + return ret; + } + return vdev->ops->init_vq(kvm, vpci->dev, vq); +} + static void virtio_pci_exit_vq(struct kvm *kvm, struct virtio_device *vdev, int vq) { @@ -314,10 +328,7 @@ static bool virtio_pci__data_out(struct kvm_cpu *vcpu, struct virtio_device *vde .align = VIRTIO_PCI_VRING_ALIGN, .pgsize = 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT, }; - virtio_pci__init_ioeventfd(kvm, vdev, - vpci->queue_selector); - vdev->ops->init_vq(kvm, vpci->dev, - vpci->queue_selector); + virtio_pci_init_vq(kvm, vdev, vpci->queue_selector); } else { virtio_pci_exit_vq(kvm, vdev, vpci->queue_selector); }