From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40C81C433FE for ; Thu, 6 Jan 2022 13:21:13 +0000 (UTC) Received: from localhost ([::1]:52300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Shc-0007uM-8O for qemu-devel@archiver.kernel.org; Thu, 06 Jan 2022 08:21:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5SdL-00044x-Sj for qemu-devel@nongnu.org; Thu, 06 Jan 2022 08:16:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57535) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5SdK-0000oj-01 for qemu-devel@nongnu.org; Thu, 06 Jan 2022 08:16:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641475005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ETB+n0NhBVWLTVk31iuRnbCsPO0dzdop/Y6jcjDWEjk=; b=FXVLQOm45T40k84dZgsUgt9OtPI7Y3b9qt3iRG7PZPbEA2EuN4zK0IHuByqZq7GCUYc90L eS/KeZsR9XAQk5pZoTc2tejyi6ocwaIOBD9LbSKXTHezC4VB9jCyq9ZiQdts/AvBmxTaqB j/KnoY3AjNK8IAKMTCUO+dPUGOEEqxY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-141-dvaVktDGPYKl1HbGOcUZHg-1; Thu, 06 Jan 2022 08:16:44 -0500 X-MC-Unique: dvaVktDGPYKl1HbGOcUZHg-1 Received: by mail-wr1-f72.google.com with SMTP id v14-20020adfa1ce000000b001a49d6587ceso1181237wrv.21 for ; Thu, 06 Jan 2022 05:16:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ETB+n0NhBVWLTVk31iuRnbCsPO0dzdop/Y6jcjDWEjk=; b=7EvrVizNMHSzL6tjrY/ZAuAJb0RUHK3lyZJJUyGqJaFIu3+PvTIqtzJPmqZQXjjLj0 MAVOImq3Zp6H7YZQORWtPp+T9yYfPrmSE9gqxMmFzZbNnhlStloWg0kmEoT1wN7CKvnQ Est5MZ1UmUpJnaPnZwyrUCWDZVgVWzhQDfp7A72pnNLBUHI5Fz86Bc+7a8psAW8knpd4 2oLuTqeh9RG3/c6+BkkB0jejkT5P4NLJojBMkTHlbNHTrOkt4aQCNwnYuZTQFU6Kg5gN s5YPFymnv4EWjVhVUlPk4tVxUffSAeorvbflkTEsG56H3dslQWMj85nDfEKSxC9HCB54 Wc6Q== X-Gm-Message-State: AOAM533XyDqZMd1sJ4W0w99zZCZpFCZLMAcucXSjEPxzy0VPb62IGIBj 8rBZK1DK4JBXIbNRCoOcwla+Hfx+sxzZoFocCVUL/8w+fzlPM3OKzNs/fGjEQ812ncPI/cR1psx n7PkMMz0c4I8C6dXPaVtGgrT8/Yg8jbv0fTQ4z0K6TWNeEgWfVzZu96pr5VNM X-Received: by 2002:adf:ea4a:: with SMTP id j10mr3668867wrn.275.1641475002300; Thu, 06 Jan 2022 05:16:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcCOKY6Owkxz6J3JFzYqoAd6HIt4+241OFgjEdgxlC/CGzhX48j3+ujN24XEvkeI32J4613w== X-Received: by 2002:adf:ea4a:: with SMTP id j10mr3668847wrn.275.1641475002067; Thu, 06 Jan 2022 05:16:42 -0800 (PST) Received: from redhat.com ([2a03:c5c0:207e:991b:6857:5652:b903:a63b]) by smtp.gmail.com with ESMTPSA id u16sm1990171wrn.24.2022.01.06.05.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 05:16:41 -0800 (PST) Date: Thu, 6 Jan 2022 08:16:39 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 09/52] vhost: add support for configure interrupt Message-ID: <20220106131534.423671-10-mst@redhat.com> References: <20220106131534.423671-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20220106131534.423671-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.372, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cindy Lu Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu Add functions to support configure interrupt. The configure interrupt process will start in vhost_dev_start and stop in vhost_dev_stop. Also add the functions to support vhost_config_pending and vhost_config_mask, for masked_config_notifier, we only use the notifier saved in vq 0. Signed-off-by: Cindy Lu Message-Id: <20211104164827.21911-8-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 4 +++ hw/virtio/vhost.c | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 58a73e7b7a..b0f3b78987 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -29,6 +29,7 @@ struct vhost_virtqueue { unsigned long long used_phys; unsigned used_size; EventNotifier masked_notifier; + EventNotifier masked_config_notifier; struct vhost_dev *dev; }; @@ -37,6 +38,7 @@ typedef unsigned long vhost_log_chunk_t; #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t)) #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS) #define VHOST_INVALID_FEATURE_BIT (0xff) +#define VHOST_QUEUE_NUM_CONFIG_INR 0 struct vhost_log { unsigned long long size; @@ -116,6 +118,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); +bool vhost_config_pending(struct vhost_dev *hdev); +void vhost_config_mask(struct vhost_dev *hdev, VirtIODevice *vdev, bool mask); /* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 20913cf8fb..98a4b0a0df 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1561,6 +1561,67 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, } } +bool vhost_config_pending(struct vhost_dev *hdev) +{ + assert(hdev->vhost_ops); + if ((hdev->started == false) || + (hdev->vhost_ops->vhost_set_config_call == NULL)) { + return false; + } + + EventNotifier *notifier = + &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier; + return event_notifier_test_and_clear(notifier); +} + +void vhost_config_mask(struct vhost_dev *hdev, VirtIODevice *vdev, bool mask) +{ + int fd; + int r; + EventNotifier *notifier = + &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier; + EventNotifier *config_notifier = &vdev->config_notifier; + assert(hdev->vhost_ops); + + if ((hdev->started == false) || + (hdev->vhost_ops->vhost_set_config_call == NULL)) { + return; + } + if (mask) { + assert(vdev->use_guest_notifier_mask); + fd = event_notifier_get_fd(notifier); + } else { + fd = event_notifier_get_fd(config_notifier); + } + r = hdev->vhost_ops->vhost_set_config_call(hdev, fd); + if (r < 0) { + VHOST_OPS_DEBUG("vhost_set_config_call failed"); + } +} + +static void vhost_stop_config_intr(struct vhost_dev *dev) +{ + int fd = -1; + assert(dev->vhost_ops); + if (dev->vhost_ops->vhost_set_config_call) { + dev->vhost_ops->vhost_set_config_call(dev, fd); + } +} + +static void vhost_start_config_intr(struct vhost_dev *dev) +{ + int r; + + assert(dev->vhost_ops); + int fd = event_notifier_get_fd(&dev->vdev->config_notifier); + if (dev->vhost_ops->vhost_set_config_call) { + r = dev->vhost_ops->vhost_set_config_call(dev, fd); + if (!r) { + event_notifier_set(&dev->vdev->config_notifier); + } + } +} + uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features) { @@ -1773,6 +1834,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } + r = event_notifier_init( + &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier, 0); + if (r < 0) { + return r; + } + event_notifier_test_and_clear( + &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier); + if (!vdev->use_guest_notifier_mask) { + vhost_config_mask(hdev, vdev, true); + } if (hdev->log_enabled) { uint64_t log_base; @@ -1806,6 +1877,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) vhost_device_iotlb_miss(hdev, vq->used_phys, true); } } + vhost_start_config_intr(hdev); return 0; fail_log: vhost_log_put(hdev, false); @@ -1831,6 +1903,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) /* should only be called after backend is connected */ assert(hdev->vhost_ops); + event_notifier_test_and_clear( + &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier); + event_notifier_test_and_clear(&vdev->config_notifier); if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); @@ -1848,6 +1923,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) } memory_listener_unregister(&hdev->iommu_listener); } + vhost_stop_config_intr(hdev); vhost_log_put(hdev, true); hdev->started = false; hdev->vdev = NULL; -- MST