From patchwork Fri Mar 17 14:55:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 13179137 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 A0BD7C74A5B for ; Fri, 17 Mar 2023 14:56:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdBUx-0000Pz-0k; Fri, 17 Mar 2023 10:56:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBUr-0000OY-3V for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:55:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBUo-0007Jx-Rf for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:55:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064954; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X3nK4ZpQgMUN43K3mekqrzfFLQ5w2ZvOSOOq3BPDe50=; b=SjpnqiQ88bJaNCc8XkOwFg+YglFdrhA7JtE8cs7TBeCwysjQ7UtjyaaU6A/Kk5ghWIDMDn tvjlRB/cwiItQUQqN6jcMwQvRzvgDHWFab9vqtXVB4bSD55PtKC7/ovLUlpGDMSSqRBMmE lqvyuydR8OaLZd0il0LznB+JHVI6I9c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-425-P7c4QFVNN46tjVd6pyNBQw-1; Fri, 17 Mar 2023 10:55:50 -0400 X-MC-Unique: P7c4QFVNN46tjVd6pyNBQw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 68684884EC0; Fri, 17 Mar 2023 14:55:49 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA13543FBE; Fri, 17 Mar 2023 14:55:46 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: alvaro.karsz@solid-run.com, Laurent Vivier , Gautam Dawar , Jason Wang , Harpreet Singh Anand , Zhu Lingshan , "Gonglei (Arei)" , "Michael S. Tsirkin" , Eli Cohen , si-wei.liu@oracle.com, Stefano Garzarella , longpeng2@huawei.com, Cindy Lu , Parav Pandit , Liuxiangdong , Shannon Nelson , Lei Yang Subject: [RFC PATCH for 8.1 1/6] vdpa: Remove status in reset tracing Date: Fri, 17 Mar 2023 15:55:37 +0100 Message-Id: <20230317145542.347368-2-eperezma@redhat.com> In-Reply-To: <20230317145542.347368-1-eperezma@redhat.com> References: <20230317145542.347368-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It is always 0 and it is not useful to route call through file descriptor. Signed-off-by: Eugenio Pérez Reviewed-by: Stefano Garzarella --- hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index bc6bad23d5..bbabea18f3 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -716,7 +716,7 @@ static int vhost_vdpa_reset_device(struct vhost_dev *dev) uint8_t status = 0; ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); - trace_vhost_vdpa_reset_device(dev, status); + trace_vhost_vdpa_reset_device(dev); v->suspended = false; return ret; } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 8f8d05cf9b..6265231683 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -44,7 +44,7 @@ vhost_vdpa_set_mem_table(void *dev, uint32_t nregions, uint32_t padding) "dev: % vhost_vdpa_dump_regions(void *dev, int i, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, uint64_t flags_padding) "dev: %p %d: guest_phys_addr: 0x%"PRIx64" memory_size: 0x%"PRIx64" userspace_addr: 0x%"PRIx64" flags_padding: 0x%"PRIx64 vhost_vdpa_set_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64 vhost_vdpa_get_device_id(void *dev, uint32_t device_id) "dev: %p device_id %"PRIu32 -vhost_vdpa_reset_device(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 +vhost_vdpa_reset_device(void *dev) "dev: %p" vhost_vdpa_get_vq_index(void *dev, int idx, int vq_idx) "dev: %p idx: %d vq idx: %d" vhost_vdpa_set_vring_ready(void *dev) "dev: %p" vhost_vdpa_dump_config(void *dev, const char *line) "dev: %p %s" From patchwork Fri Mar 17 14:55:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 13179135 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 03B11C76195 for ; Fri, 17 Mar 2023 14:56:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdBV7-0000R5-Es; Fri, 17 Mar 2023 10:56:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV6-0000QQ-3U for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBUr-0007KF-EE for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:55:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064956; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V6G854HLuZuQfow/C6K0fkFxQ0GSyQoJl9oDAp5MsxI=; b=EY/5Iz+2Y03qlV4GU9BEPVgIduaf2cW1m6ZzDVMPPhNWI8gmDGJSiaOWoi2/OQEBL/BlnC H352eqsN6i+RNhaz3zmLMAV+3vf7xkHhVGonbfIkTELV/YClNJc1jlps6QTmVDvlUcGNZZ IY+jxayanmeKG0D/4TjaiZSttdHU6H8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-553-nmgaRIB-P-eSy50x1hGh1w-1; Fri, 17 Mar 2023 10:55:53 -0400 X-MC-Unique: nmgaRIB-P-eSy50x1hGh1w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4EA2188B7B4; Fri, 17 Mar 2023 14:55:52 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id A56A443FBE; Fri, 17 Mar 2023 14:55:49 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: alvaro.karsz@solid-run.com, Laurent Vivier , Gautam Dawar , Jason Wang , Harpreet Singh Anand , Zhu Lingshan , "Gonglei (Arei)" , "Michael S. Tsirkin" , Eli Cohen , si-wei.liu@oracle.com, Stefano Garzarella , longpeng2@huawei.com, Cindy Lu , Parav Pandit , Liuxiangdong , Shannon Nelson , Lei Yang Subject: [RFC PATCH for 8.1 2/6] vdpa: add vhost_vdpa_reset_status_fd Date: Fri, 17 Mar 2023 15:55:38 +0100 Message-Id: <20230317145542.347368-3-eperezma@redhat.com> In-Reply-To: <20230317145542.347368-1-eperezma@redhat.com> References: <20230317145542.347368-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This allows to reset a vhost-vdpa device from external subsystems like vhost-net. It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation. Signed-off-by: Eugenio Pérez --- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 58 +++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index c278a2a8de..28de7da91e 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -54,6 +54,7 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; +void vhost_vdpa_reset_status_fd(int fd); int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index bbabea18f3..7a2053b8d9 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -335,38 +335,45 @@ static const MemoryListener vhost_vdpa_memory_listener = { .region_del = vhost_vdpa_listener_region_del, }; -static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int request, - void *arg) +static int vhost_vdpa_dev_fd(const struct vhost_dev *dev) { struct vhost_vdpa *v = dev->opaque; - int fd = v->device_fd; - int ret; assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA); + return v->device_fd; +} + +static int vhost_vdpa_call_fd(int fd, unsigned long int request, void *arg) +{ + int ret = ioctl(fd, request, arg); - ret = ioctl(fd, request, arg); return ret < 0 ? -errno : ret; } -static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) +static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int request, + void *arg) +{ + return vhost_vdpa_call_fd(vhost_vdpa_dev_fd(dev), request, arg); +} + +static int vhost_vdpa_add_status_fd(int fd, uint8_t status) { uint8_t s; int ret; - trace_vhost_vdpa_add_status(dev, status); - ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s); + ret = vhost_vdpa_call_fd(fd, VHOST_VDPA_GET_STATUS, &s); if (ret < 0) { return ret; } s |= status; - ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); + ret = vhost_vdpa_call_fd(fd, VHOST_VDPA_SET_STATUS, &s); if (ret < 0) { return ret; } - ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s); + ret = vhost_vdpa_call_fd(fd, VHOST_VDPA_GET_STATUS, &s); if (ret < 0) { return ret; } @@ -378,6 +385,12 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) return 0; } +static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) +{ + trace_vhost_vdpa_add_status(dev, status); + return vhost_vdpa_add_status_fd(vhost_vdpa_dev_fd(dev), status); +} + int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range) { int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); @@ -709,16 +722,20 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev, return ret; } +static int vhost_vdpa_reset_device_fd(int fd) +{ + uint8_t status = 0; + + return vhost_vdpa_call_fd(fd, VHOST_VDPA_SET_STATUS, &status); +} + static int vhost_vdpa_reset_device(struct vhost_dev *dev) { struct vhost_vdpa *v = dev->opaque; - int ret; - uint8_t status = 0; - ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); - trace_vhost_vdpa_reset_device(dev); v->suspended = false; - return ret; + trace_vhost_vdpa_reset_device(dev); + return vhost_vdpa_reset_device_fd(vhost_vdpa_dev_fd(dev)); } static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) @@ -1170,6 +1187,13 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) return 0; } +void vhost_vdpa_reset_status_fd(int fd) +{ + vhost_vdpa_reset_device_fd(fd); + vhost_vdpa_add_status_fd(fd, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); +} + static void vhost_vdpa_reset_status(struct vhost_dev *dev) { struct vhost_vdpa *v = dev->opaque; @@ -1178,9 +1202,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev) return; } - vhost_vdpa_reset_device(dev); - vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | - VIRTIO_CONFIG_S_DRIVER); + vhost_vdpa_reset_status_fd(vhost_vdpa_dev_fd(dev)); memory_listener_unregister(&v->listener); } From patchwork Fri Mar 17 14:55:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 13179136 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 03ADDC7618E for ; Fri, 17 Mar 2023 14:56:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdBVA-0000SF-Fg; Fri, 17 Mar 2023 10:56:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV7-0000R3-H2 for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV1-0007Kj-Rw for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064959; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpmyuWBcYlh2Hd+XeU5GfmO3PD9opnGLJrAwHvLGNp0=; b=ehA2nuqlLu5Sst2vYpcPZVKsBhiLFhBOr6HXteaGgb3dHPPSNWzfhS5bJytUSwk6+0MR4t VzWnhFZ1vNNstA4eUlzfu91DXYw/qsE+HKtZDa6ue0xGUji7X21TxA5/XSzRIrw5qJJfi/ qd0ygFM/Pbd2dYTO53CwiXqTFxpLOXQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-h_taBTzoM36OJNqe6LfmUQ-1; Fri, 17 Mar 2023 10:55:55 -0400 X-MC-Unique: h_taBTzoM36OJNqe6LfmUQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38D9718E530C; Fri, 17 Mar 2023 14:55:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CA2643FBE; Fri, 17 Mar 2023 14:55:52 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: alvaro.karsz@solid-run.com, Laurent Vivier , Gautam Dawar , Jason Wang , Harpreet Singh Anand , Zhu Lingshan , "Gonglei (Arei)" , "Michael S. Tsirkin" , Eli Cohen , si-wei.liu@oracle.com, Stefano Garzarella , longpeng2@huawei.com, Cindy Lu , Parav Pandit , Liuxiangdong , Shannon Nelson , Lei Yang Subject: [RFC PATCH for 8.1 3/6] vdpa: add vhost_vdpa_set_dev_features_fd Date: Fri, 17 Mar 2023 15:55:39 +0100 Message-Id: <20230317145542.347368-4-eperezma@redhat.com> In-Reply-To: <20230317145542.347368-1-eperezma@redhat.com> References: <20230317145542.347368-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This allows to set the features of a vhost-vdpa device from external subsystems like vhost-net. It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation. Signed-off-by: Eugenio Pérez Reviewed-by: Stefano Garzarella --- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 28de7da91e..a9cb6f3a32 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -55,6 +55,7 @@ typedef struct vhost_vdpa { } VhostVDPA; void vhost_vdpa_reset_status_fd(int fd); +int vhost_vdpa_set_dev_features_fd(int fd, uint64_t features); int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7a2053b8d9..acd5be46a9 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -651,11 +651,22 @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, return 0; } +int vhost_vdpa_set_dev_features_fd(int fd, uint64_t features) +{ + int ret; + + ret = vhost_vdpa_call_fd(fd, VHOST_SET_FEATURES, &features); + if (ret) { + return ret; + } + + return vhost_vdpa_add_status_fd(fd, VIRTIO_CONFIG_S_FEATURES_OK); +} + static int vhost_vdpa_set_features(struct vhost_dev *dev, uint64_t features) { struct vhost_vdpa *v = dev->opaque; - int ret; if (!vhost_vdpa_first_dev(dev)) { return 0; @@ -678,12 +689,7 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev, } trace_vhost_vdpa_set_features(dev, features); - ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); - if (ret) { - return ret; - } - - return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); + return vhost_vdpa_set_dev_features_fd(vhost_vdpa_dev_fd(dev), features); } static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) From patchwork Fri Mar 17 14:55:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 13179139 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 81674C74A5B for ; Fri, 17 Mar 2023 14:57:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdBVA-0000S1-6T; Fri, 17 Mar 2023 10:56:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV7-0000R4-Iq for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV5-0007L2-7K for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064962; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F1cnkhgtsZ7wT+NckoMu50SXggVHBW0DZRluBDN1IOc=; b=GmWIW5nvB3l/Gs2f1bn3hkluovPKstKDnTZVBOw/1/Zx2Zhwp618hQQbwGb2Ft7AABmVoL 0uabGHMGhs1YwrTk6uWvQIXZexb//fQa3S+bE2nZFSd18nQaaoNZXzxR9Yh6Y2Se9RYlAN uYvX1PDzWLONp20nd0GtOgTjB64q5fc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-tUg2bhmuPN6_aknyJnHwfA-1; Fri, 17 Mar 2023 10:55:58 -0400 X-MC-Unique: tUg2bhmuPN6_aknyJnHwfA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 21AD038221CF; Fri, 17 Mar 2023 14:55:58 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 777C843FBE; Fri, 17 Mar 2023 14:55:55 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: alvaro.karsz@solid-run.com, Laurent Vivier , Gautam Dawar , Jason Wang , Harpreet Singh Anand , Zhu Lingshan , "Gonglei (Arei)" , "Michael S. Tsirkin" , Eli Cohen , si-wei.liu@oracle.com, Stefano Garzarella , longpeng2@huawei.com, Cindy Lu , Parav Pandit , Liuxiangdong , Shannon Nelson , Lei Yang Subject: [RFC PATCH for 8.1 4/6] vdpa: return errno in vhost_vdpa_get_vring_group error Date: Fri, 17 Mar 2023 15:55:40 +0100 Message-Id: <20230317145542.347368-5-eperezma@redhat.com> In-Reply-To: <20230317145542.347368-1-eperezma@redhat.com> References: <20230317145542.347368-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We need to tell in the caller, as some errors are expected in a normal workflow. In particular, parent drivers in recent kernels with VHOST_BACKEND_F_IOTLB_ASID may not support vring groups. In that case, -ENOTSUP is returned. This is the case of vp_vdpa in Linux 6.2. Next patches in this series will use that information to know if it must abort or not. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 99904a0da7..4397c0d4b3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -361,6 +361,14 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +/** + * Get vring virtqueue group + * + * @device_fd vdpa device fd + * @vq_index Virtqueue index + * + * Return -errno in case of error, or vq group if success. + */ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index) { struct vhost_vring_state state = { @@ -369,6 +377,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index) int r = ioctl(device_fd, VHOST_VDPA_GET_VRING_GROUP, &state); if (unlikely(r < 0)) { + r = -errno; error_report("Cannot get VQ %u group: %s", vq_index, g_strerror(errno)); return r; From patchwork Fri Mar 17 14:55:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 13179140 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 1FF6BC6FD1D for ; Fri, 17 Mar 2023 14:57:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdBVA-0000S4-A0; Fri, 17 Mar 2023 10:56:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV9-0000Rj-71 for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV5-0007LK-Rz for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064965; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aEm2sa/IUANDIUmIsl5MKxfqBl79LRB9lF8pvMUWj+I=; b=UzyyA8P2lF6lQ3/ZKZbsON55DWP2mHeKmpZVoVc2A0+QloLj/y16EMgxLuX8LuLLwVS6Gh 2kC0Sp25AYGWHwoxDAW5Ar7iPBvbHW69Q5jU6jFkrAYeaHp7kVOQ61jUh59nToW+el+0Hf iL5DmMbjBaL+C16d3Y+YzBOgPzSJDME= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663--spWs4TYP4yTfm3509CdqA-1; Fri, 17 Mar 2023 10:56:03 -0400 X-MC-Unique: -spWs4TYP4yTfm3509CdqA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E8D496DCAB; Fri, 17 Mar 2023 14:56:01 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F15483B9F; Fri, 17 Mar 2023 14:55:58 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: alvaro.karsz@solid-run.com, Laurent Vivier , Gautam Dawar , Jason Wang , Harpreet Singh Anand , Zhu Lingshan , "Gonglei (Arei)" , "Michael S. Tsirkin" , Eli Cohen , si-wei.liu@oracle.com, Stefano Garzarella , longpeng2@huawei.com, Cindy Lu , Parav Pandit , Liuxiangdong , Shannon Nelson , Lei Yang Subject: [RFC PATCH for 8.1 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa Date: Fri, 17 Mar 2023 15:55:41 +0100 Message-Id: <20230317145542.347368-6-eperezma@redhat.com> In-Reply-To: <20230317145542.347368-1-eperezma@redhat.com> References: <20230317145542.347368-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers. Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 200 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 157 insertions(+), 43 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 4397c0d4b3..818a24fb0e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -43,6 +43,13 @@ typedef struct VhostVDPAState { /* The device always have SVQ enabled */ bool always_svq; + + /* The device can isolate CVQ in its own ASID if MQ is negotiated */ + bool cvq_isolated_mq; + + /* The device can isolate CVQ in its own ASID if MQ is not negotiated */ + bool cvq_isolated; + bool started; } VhostVDPAState; @@ -361,15 +368,8 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; -/** - * Get vring virtqueue group - * - * @device_fd vdpa device fd - * @vq_index Virtqueue index - * - * Return -errno in case of error, or vq group if success. - */ -static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index) +static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index, + Error **errp) { struct vhost_vring_state state = { .index = vq_index, @@ -378,8 +378,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index) if (unlikely(r < 0)) { r = -errno; - error_report("Cannot get VQ %u group: %s", vq_index, - g_strerror(errno)); + error_setg_errno(errp, errno, "Cannot get VQ %u group", vq_index); return r; } @@ -479,9 +478,9 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) { VhostVDPAState *s, *s0; struct vhost_vdpa *v; - uint64_t backend_features; int64_t cvq_group; - int cvq_index, r; + int r; + Error *err = NULL; assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -501,42 +500,29 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) /* * If we early return in these cases SVQ will not be enabled. The migration * will be blocked as long as vhost-vdpa backends will not offer _F_LOG. - * - * Calling VHOST_GET_BACKEND_FEATURES as they are not available in v->dev - * yet. */ - r = ioctl(v->device_fd, VHOST_GET_BACKEND_FEATURES, &backend_features); - if (unlikely(r < 0)) { - error_report("Cannot get vdpa backend_features: %s(%d)", - g_strerror(errno), errno); - return -1; - } - if (!(backend_features & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) || - !vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { + if (!vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { return 0; } - /* - * Check if all the virtqueues of the virtio device are in a different vq - * than the last vq. VQ group of last group passed in cvq_group. - */ - cvq_index = v->dev->vq_index_end - 1; - cvq_group = vhost_vdpa_get_vring_group(v->device_fd, cvq_index); - if (unlikely(cvq_group < 0)) { - return cvq_group; - } - for (int i = 0; i < cvq_index; ++i) { - int64_t group = vhost_vdpa_get_vring_group(v->device_fd, i); - - if (unlikely(group < 0)) { - return group; + if (v->dev->features & BIT_ULL(VIRTIO_NET_F_MQ)) { + if (!s->cvq_isolated_mq) { + return 0; } - - if (group == cvq_group) { + } else { + if (!s->cvq_isolated) { return 0; } } + cvq_group = vhost_vdpa_get_vring_group(v->device_fd, + v->dev->vq_index_end - 1, + &err); + if (unlikely(cvq_group < 0)) { + error_report_err(err); + return cvq_group; + } + r = vhost_vdpa_set_address_space_id(v, cvq_group, VHOST_VDPA_NET_CVQ_ASID); if (unlikely(r < 0)) { return r; @@ -798,6 +784,122 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { .avail_handler = vhost_vdpa_net_handle_ctrl_avail, }; +/** + * Probe the device to check control virtqueue is isolated. + * + * @device_fd vhost-vdpa file descriptor + * @features features to negotiate + * @cvq_index Control vq index + * + * Returns -1 in case of error, 0 if false and 1 if true + */ +static int vhost_vdpa_cvq_is_isolated(int device_fd, uint64_t features, + unsigned cvq_index, Error **errp) +{ + int64_t cvq_group; + int r; + + vhost_vdpa_reset_status_fd(device_fd); + r = vhost_vdpa_set_dev_features_fd(device_fd, features); + if (unlikely(r < 0)) { + error_setg_errno(errp, -r, "Cannot set device features"); + return r; + } + + cvq_group = vhost_vdpa_get_vring_group(device_fd, cvq_index, errp); + if (unlikely(cvq_group < 0)) { + r = cvq_group; + goto out; + } + + for (int i = 0; i < cvq_index; ++i) { + int64_t group = vhost_vdpa_get_vring_group(device_fd, i, errp); + + if (unlikely(group < 0)) { + r = group; + goto out; + } + + if (group == (int64_t)cvq_group) { + r = 0; + goto out; + } + } + + return 1; + +out: + vhost_vdpa_reset_status_fd(device_fd); + return r; +} + +/** + * Probe if CVQ is isolated when the device is MQ and when it is not MQ + * + * @device_fd The vdpa device fd + * @features Features offered by the device. + * @cvq_index The control vq index if mq is negotiated. Ignored + * otherwise. + * @cvq_isolated It'll be set to true if cvq is isolated if mq is not + * negotiated. + * @cvq_isolated_mq It'll be set to true if cvq is isolated if mq is + * negotiated. + * + * Returns -1 in case of failure + */ +static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, + int cvq_index, bool *cvq_isolated, + bool *cvq_isolated_mq, Error **errp) +{ + uint64_t backend_features; + int r; + + ERRP_GUARD(); + + *cvq_isolated = false; + *cvq_isolated_mq = false; + r = ioctl(device_fd, VHOST_GET_BACKEND_FEATURES, &backend_features); + if (unlikely(r < 0)) { + error_setg_errno(errp, errno, "Cannot get vdpa backend_features"); + return r; + } + + if (!(backend_features & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID))) { + return 0; + } + + r = vhost_vdpa_cvq_is_isolated(device_fd, + features & ~BIT_ULL(VIRTIO_NET_F_MQ), 2, + errp); + if (unlikely(r < 0)) { + if (r == -ENOTSUP) { + /* + * The kernel report VHOST_BACKEND_F_IOTLB_ASID if the vdpa + * frontend support ASID but the parent driver does not. The CVQ + * cannot be isolated in this case. + */ + error_free(*errp); + *errp = NULL; + return 0; + } + + return r; + } + + *cvq_isolated = r == 1; + if (!(features & BIT_ULL(VIRTIO_NET_F_MQ))) { + return 0; + } + + r = vhost_vdpa_cvq_is_isolated(device_fd, features, cvq_index * 2, errp); + if (unlikely(r < 0)) { + return r; + } + + *cvq_isolated_mq = r == 1; + return 0; +} + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -807,16 +909,26 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, bool is_datapath, bool svq, struct vhost_vdpa_iova_range iova_range, - uint64_t features) + uint64_t features, + Error **errp) { NetClientState *nc = NULL; VhostVDPAState *s; int ret = 0; assert(name); + bool cvq_isolated, cvq_isolated_mq; + if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); } else { + ret = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features, + queue_pair_index, &cvq_isolated, + &cvq_isolated_mq, errp); + if (unlikely(ret)) { + return NULL; + } + nc = qemu_new_net_control_client(&net_vhost_vdpa_cvq_info, peer, device, name); } @@ -843,6 +955,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; + s->cvq_isolated = cvq_isolated; + s->cvq_isolated_mq = cvq_isolated_mq; /* * TODO: We cannot migrate devices with CVQ as there is no way to set @@ -971,7 +1085,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, for (i = 0; i < queue_pairs; i++) { ncs[i] = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 2, true, opts->x_svq, - iova_range, features); + iova_range, features, errp); if (!ncs[i]) goto err; } @@ -979,7 +1093,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, if (has_cvq) { nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 1, false, - opts->x_svq, iova_range, features); + opts->x_svq, iova_range, features, errp); if (!nc) goto err; } From patchwork Fri Mar 17 14:55:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 13179138 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 2EFDCC74A5B for ; Fri, 17 Mar 2023 14:57:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdBVB-0000T4-N6; Fri, 17 Mar 2023 10:56:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV9-0000Ri-6I for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdBV6-0007LY-Ut for qemu-devel@nongnu.org; Fri, 17 Mar 2023 10:56:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064971; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KFHn4XW+UavDoe4jloqdSWbaWn9IBPuMyjVQ0mDdSGY=; b=BbTJXrWpqTAzWYcjg4neP3+ojfJORZ/o+4jhGWsAb54S9HW5p+T7FQH38CMPZQhwxG8MTk 8VsZm1tJBW45ernxgf7/2wEAqskZ+XpHuScJN0DdYAGy374Xy6Bzzwq60J7X/b7feHnAt9 3nF5LDNmNBZo4sSST5tjnk8V4L/OS+w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-478-5s2Ejd16N7uZaMNsR_nWHw-1; Fri, 17 Mar 2023 10:56:05 -0400 X-MC-Unique: 5s2Ejd16N7uZaMNsR_nWHw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC5F080A209; Fri, 17 Mar 2023 14:56:03 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B8D243FBE; Fri, 17 Mar 2023 14:56:01 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: alvaro.karsz@solid-run.com, Laurent Vivier , Gautam Dawar , Jason Wang , Harpreet Singh Anand , Zhu Lingshan , "Gonglei (Arei)" , "Michael S. Tsirkin" , Eli Cohen , si-wei.liu@oracle.com, Stefano Garzarella , longpeng2@huawei.com, Cindy Lu , Parav Pandit , Liuxiangdong , Shannon Nelson , Lei Yang Subject: [RFC PATCH for 8.1 6/6] vdpa: Cache cvq group in VhostVDPAState Date: Fri, 17 Mar 2023 15:55:42 +0100 Message-Id: <20230317145542.347368-7-eperezma@redhat.com> In-Reply-To: <20230317145542.347368-1-eperezma@redhat.com> References: <20230317145542.347368-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Continue the move of code that interacts with the device from control virtqueue start to control virtqueue init. As with previous patches, it reduces the number of ioctls in the migration, reducing failure possibilities. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 818a24fb0e..fe0ec62060 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -41,6 +41,12 @@ typedef struct VhostVDPAState { void *cvq_cmd_out_buffer; virtio_net_ctrl_ack *status; + /* CVQ group if cvq_isolated_mq */ + uint32_t cvq_group_mq; + + /* CVQ group if cvq_isolated */ + uint32_t cvq_group; + /* The device always have SVQ enabled */ bool always_svq; @@ -480,7 +486,6 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) struct vhost_vdpa *v; int64_t cvq_group; int r; - Error *err = NULL; assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -509,18 +514,14 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) if (!s->cvq_isolated_mq) { return 0; } + + cvq_group = s->cvq_group_mq; } else { if (!s->cvq_isolated) { return 0; } - } - cvq_group = vhost_vdpa_get_vring_group(v->device_fd, - v->dev->vq_index_end - 1, - &err); - if (unlikely(cvq_group < 0)) { - error_report_err(err); - return cvq_group; + cvq_group = s->cvq_group; } r = vhost_vdpa_set_address_space_id(v, cvq_group, VHOST_VDPA_NET_CVQ_ASID); @@ -790,11 +791,13 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { * @device_fd vhost-vdpa file descriptor * @features features to negotiate * @cvq_index Control vq index + * @pcvq_group: Returns CVQ group if cvq is isolated. * * Returns -1 in case of error, 0 if false and 1 if true */ static int vhost_vdpa_cvq_is_isolated(int device_fd, uint64_t features, - unsigned cvq_index, Error **errp) + unsigned cvq_index, uint32_t *pcvq_group, + Error **errp) { int64_t cvq_group; int r; @@ -812,6 +815,7 @@ static int vhost_vdpa_cvq_is_isolated(int device_fd, uint64_t features, goto out; } + *pcvq_group = (uint32_t)cvq_group; for (int i = 0; i < cvq_index; ++i) { int64_t group = vhost_vdpa_get_vring_group(device_fd, i, errp); @@ -844,12 +848,15 @@ out: * negotiated. * @cvq_isolated_mq It'll be set to true if cvq is isolated if mq is * negotiated. + * @cvq_group CVQ group if MQ is not negotiated. + * @cvq_group_mq CVQ group if MQ is negotiated. * * Returns -1 in case of failure */ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, int cvq_index, bool *cvq_isolated, - bool *cvq_isolated_mq, Error **errp) + bool *cvq_isolated_mq, uint32_t *cvq_group, + uint32_t *cvq_group_mq, Error **errp) { uint64_t backend_features; int r; @@ -858,6 +865,8 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, *cvq_isolated = false; *cvq_isolated_mq = false; + *cvq_group = 0; + *cvq_group_mq = 0; r = ioctl(device_fd, VHOST_GET_BACKEND_FEATURES, &backend_features); if (unlikely(r < 0)) { error_setg_errno(errp, errno, "Cannot get vdpa backend_features"); @@ -870,7 +879,7 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, r = vhost_vdpa_cvq_is_isolated(device_fd, features & ~BIT_ULL(VIRTIO_NET_F_MQ), 2, - errp); + cvq_group, errp); if (unlikely(r < 0)) { if (r == -ENOTSUP) { /* @@ -891,7 +900,8 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, return 0; } - r = vhost_vdpa_cvq_is_isolated(device_fd, features, cvq_index * 2, errp); + r = vhost_vdpa_cvq_is_isolated(device_fd, features, cvq_index * 2, + cvq_group_mq, errp); if (unlikely(r < 0)) { return r; } @@ -917,6 +927,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, int ret = 0; assert(name); bool cvq_isolated, cvq_isolated_mq; + uint32_t cvq_group, cvq_group_mq; if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, @@ -924,7 +935,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, } else { ret = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features, queue_pair_index, &cvq_isolated, - &cvq_isolated_mq, errp); + &cvq_isolated_mq, &cvq_group, + &cvq_group_mq, errp); if (unlikely(ret)) { return NULL; } @@ -957,6 +969,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops_opaque = s; s->cvq_isolated = cvq_isolated; s->cvq_isolated_mq = cvq_isolated_mq; + s->cvq_group = cvq_group; + s->cvq_group_mq = cvq_group_mq; /* * TODO: We cannot migrate devices with CVQ as there is no way to set