From patchwork Thu May 5 09:13:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladi Prosek X-Patchwork-Id: 9022151 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3EE25BF29F for ; Thu, 5 May 2016 09:14:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9ADEA203FB for ; Thu, 5 May 2016 09:14:29 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id DB8D7203C1 for ; Thu, 5 May 2016 09:14:28 +0000 (UTC) Received: from localhost ([::1]:52775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayFMW-0001gJ-HL for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 May 2016 05:14:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayFMK-0001Rt-JR for qemu-devel@nongnu.org; Thu, 05 May 2016 05:14:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayFM9-0004LP-0N for qemu-devel@nongnu.org; Thu, 05 May 2016 05:14:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayFM8-0004ID-Qv for qemu-devel@nongnu.org; Thu, 05 May 2016 05:14:00 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 7D47F8E3DA for ; Thu, 5 May 2016 09:13:48 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (dhcp-1-127.brq.redhat.com [10.34.1.127]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u459DkjC030792; Thu, 5 May 2016 05:13:47 -0400 From: Ladi Prosek To: qemu-devel@nongnu.org Date: Thu, 5 May 2016 11:13:37 +0200 Message-Id: <1462439617-11387-1-git-send-email-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 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] [RFC PATCH] virtio: set ISR status when delivering queue MSI 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: lprosek@redhat.com, vrozenfe@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability. Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest. With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ. While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers. This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path. Signed-off-by: Ladi Prosek --- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 08275a9..4053313 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) } trace_virtio_notify(vdev, vq); - vdev->isr |= 0x01; + vdev->isr |= 0x01; // <= here we set ISR status even if we don't raise IRQ virtio_notify_vector(vdev, vq->vector); } @@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd(EventNotifier *n) +{ + VirtQueue *vq = container_of(n, VirtQueue, guest_notifier); + if (event_notifier_test_and_clear(n)) { + vq->vdev->isr |= 0x01; + } +} + void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, bool with_irqfd) { - if (assign && !with_irqfd) { + if (assign) { event_notifier_set_handler(&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); } else { event_notifier_set_handler(&vq->guest_notifier, NULL); - } - if (!assign) { + /* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read(&vq->guest_notifier);