From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168293; cv=none; d=zohomail.com; s=zohoarc; b=PME/EYazTFxRCm65/jHWTPS7AdBJwwm14SP6DqM0wmHq8usvMILaDrO6ALn3iOHeRgp4S1/DygixL/hgj/RUAJqBB6lynyGxdCWswsbl++z9aAY/Gu7Iq/B8jSC46NXmFi6xowJzmMycRaSuXLZ4DRZm5WJuAfdWWP4z8+I4oxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168293; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VlbL1HFd0cOmdquKv/xWNmr/CPE5aCshT232rfU4Gmk=; b=DUaenzoUir2M3ae899/NcDSl9kZJuKbogz/u3XbmNdYNK3nc8ckdxaPC1N0jjSwV4TnN2ChzICESoE3xZQqJM8urqhAzyvBVkrvn44elRuD+IjdxBDlRMzvHTlH0YcALT9iRb3HLz9tKVDwygG587brq6d9tctRDJsDaoBV7hFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168293848766.086166590359; Tue, 28 Nov 2023 02:44:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vYm-0006jz-Oc; Tue, 28 Nov 2023 05:43:20 -0500 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 1r7vYk-0006jW-Vl for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:18 -0500 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 1r7vYj-0005dq-Ig for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:18 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-VigptARGM4-l-eOpI6UVpg-1; Tue, 28 Nov 2023 05:43:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5952A811E7B; Tue, 28 Nov 2023 10:43:10 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25EED20268D8; Tue, 28 Nov 2023 10:43:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168195; 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=VlbL1HFd0cOmdquKv/xWNmr/CPE5aCshT232rfU4Gmk=; b=O9Qzdct5SqPSwNkGe1qDYjKZHuW5W1badgipI82Fp1zWIlmAYmWWyI00wJ7kMy3D0roRxr O3UQGWvdKShsEDgn0doQYXYjAAQmG4SxYXhuerPAieTTL6GGv5EVFSqkxnzN8T2T0KwCzh zYgs0bzM/4p0YUveAgwDHrg9xkCruRE= X-MC-Unique: VigptARGM4-l-eOpI6UVpg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 01/10] vdpa: do not set virtio status bits if unneeded Date: Tue, 28 Nov 2023 11:42:54 +0100 Message-Id: <20231128104303.3314000-2-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168295418000003 Next commits will set DRIVER and ACKNOWLEDGE flags repeatedly in the case of a migration destination. Let's save ioctls with this. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7500c2fc82..cc252fc2d8 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -510,6 +510,10 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev= , uint8_t status) if (ret < 0) { return ret; } + if ((s & status) =3D=3D status) { + /* Don't set bits already set */ + return 0; + } =20 s |=3D status; =20 --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168243; cv=none; d=zohomail.com; s=zohoarc; b=D3wa/SCAbpUBUnDEOGq9vfmaw50YcZ23iN4cYZCp2WM4bxK0zUWL6cWdN2jyKENG0KoGc+JJKQScRNwLWrLwGK5Vc4UTHJGeRUAdpTPx4Od80qcpFJLxaJb64//3Ns+xj1ntsZWsMYkqD5xM6oZihH1+UHeIt+GthGNYTne8i3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168243; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jiCsDaivPOvgkYPv1nwn65nD5kYXp+LU4DCyQMQzLN4=; b=cQFUC3X29qxB77kbVnlV3JF1ci3uVO5zpvEmNiwWbiDtl6bE17Zv984kZRq0OjNd3B6PVNWRZl59eQwDwu6/y2GHjZeeOOnAJvYcF0Zuj9a55YzuYha/M+grBWAXELa7lgq9VzlbeNlvPJw3Oc7SOiMMLyVW7z/pSqQmX/pUe8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168243021204.46122449089887; Tue, 28 Nov 2023 02:44:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vYm-0006k1-Vt; Tue, 28 Nov 2023 05:43:21 -0500 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 1r7vYm-0006jr-4m for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:20 -0500 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 1r7vYj-0005e7-Ja for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:19 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-hE13P9OkM-KnaogtQDKufQ-1; Tue, 28 Nov 2023 05:43:13 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D43391C0512B; Tue, 28 Nov 2023 10:43:12 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9483220268D7; Tue, 28 Nov 2023 10:43:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168196; 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=jiCsDaivPOvgkYPv1nwn65nD5kYXp+LU4DCyQMQzLN4=; b=MroIS/Ar0pbF7fPKHx1QOL1hUbvRgdVPOXuEHCg58Xgdqu0M2ISoUx64NlI0lqMiZ1yC7V jeT8A7UQ8fdC6gg5M04zjEDCp+gxL3TYMvTQJbXpcEYKHl/gIFwaqAiza4qNjy59GW7EnN o8Otrb/HHsoKhW8gked0jYoe/Kzs8cw= X-MC-Unique: hE13P9OkM-KnaogtQDKufQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 02/10] vdpa: make batch_begin_once early return Date: Tue, 28 Nov 2023 11:42:55 +0100 Message-Id: <20231128104303.3314000-3-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168245664000005 Prefer early return so it is easier to merge vhost_vdpa_listener_begin_batch here and make iotlb baches begin and end symmetrical. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index cc252fc2d8..bf9771870a 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -160,11 +160,12 @@ static void vhost_vdpa_listener_begin_batch(VhostVDPA= Shared *s) =20 static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) { - if (s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && - !s->iotlb_batch_begin_sent) { - vhost_vdpa_listener_begin_batch(s); + if (!(s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH)) || + s->iotlb_batch_begin_sent) { + return; } =20 + vhost_vdpa_listener_begin_batch(s); s->iotlb_batch_begin_sent =3D true; } =20 --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168271; cv=none; d=zohomail.com; s=zohoarc; b=Tri72HFZJ6AoArkSa9/xc8lxE2UuqGfrKtIxQzYp2SulmU0oBNFViG3Yn8gvuWbFfjfVKcQhG9IJztfwGFCVET2tRtHRW/9Y09oFRubH6nf0aFul1UseHCrD6fqBTBJQjkRcGTcIPA2gO12axuYUbRO0t8spwScLJ6YVugTzzvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168271; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6D5rlfw7G1yLNiSv7CgLqkOdOD7ElVEtb3VUVH2sVwA=; b=BH7QqGUZyBS9qT9gfWFQq4PHeFyQx78LMkjmgih+YWszZCtfVM4fiNZnITU62VG+rnXaDWLt6Jm4f62CNsUDWcLBP28PJ916W1ngWsu2Lo+9x5ScuqkG3Gf6Y7XjblRvH2/ilznxRW09pVH0hTwOMT2Ko4Hu8+/no3HtmjSEHRk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168271845731.7599939165154; Tue, 28 Nov 2023 02:44:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vYs-0006lu-MV; Tue, 28 Nov 2023 05:43:26 -0500 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 1r7vYr-0006l5-8B for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:25 -0500 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 1r7vYo-0005f0-SQ for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:24 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-y85cGbMBN0CnvmCWgQlIUA-1; Tue, 28 Nov 2023 05:43:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F54B1C0512B; Tue, 28 Nov 2023 10:43:15 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DCD320268D7; Tue, 28 Nov 2023 10:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168201; 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=6D5rlfw7G1yLNiSv7CgLqkOdOD7ElVEtb3VUVH2sVwA=; b=WPc2DBjcBiSxkjeqmQYOikD9HP/JXaCm0D9UMdy8HnU76QyH88RJebhQU2eiCjpLB2A88t B57waV/18TUVmf/26Ka4pok08CehDd9E+4/qjJlKZBgzlJwVF7KYNWNZurBRm0r8iEDO3t 6V19Rqe+mJ0yNajDn65eH7b3z6wX/5g= X-MC-Unique: y85cGbMBN0CnvmCWgQlIUA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 03/10] vdpa: merge _begin_batch into _batch_begin_once Date: Tue, 28 Nov 2023 11:42:56 +0100 Message-Id: <20231128104303.3314000-4-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168273329000001 There was only one call. This way we can make the begin and end of the batch symmetrical. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index bf9771870a..a533fc5bc7 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -143,7 +143,7 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t a= sid, hwaddr iova, return ret; } =20 -static void vhost_vdpa_listener_begin_batch(VhostVDPAShared *s) +static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) { int fd =3D s->device_fd; struct vhost_msg_v2 msg =3D { @@ -151,21 +151,16 @@ static void vhost_vdpa_listener_begin_batch(VhostVDPA= Shared *s) .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, }; =20 - trace_vhost_vdpa_listener_begin_batch(s, fd, msg.type, msg.iotlb.type); - if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { - error_report("failed to write, fd=3D%d, errno=3D%d (%s)", - fd, errno, strerror(errno)); - } -} - -static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) -{ if (!(s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH)) || s->iotlb_batch_begin_sent) { return; } =20 - vhost_vdpa_listener_begin_batch(s); + trace_vhost_vdpa_listener_begin_batch(s, fd, msg.type, msg.iotlb.type); + if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { + error_report("failed to write, fd=3D%d, errno=3D%d (%s)", + fd, errno, strerror(errno)); + } s->iotlb_batch_begin_sent =3D true; } =20 --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168317; cv=none; d=zohomail.com; s=zohoarc; b=BuVFnaTgSZmFOSs6S8KFoYaMwFg/JElyqSSY4hpcVHC6u90RsqBVLJ0rC0uJECHsr2oiMm2dJXXq1jrWu+i3joyZoL69BSX4PQ8vRdkqaRZNRZ4yYRtkeMjCv9MplaJNFuyT9DroMLVHoQ20cyASR8a9tz/lfL+3CvSwRU++Fcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168317; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=czRuS48Nn1k6ylS+U5+ONFWw9urqtIfLEQqVSIBrLjc=; b=U0RbciYMP0rtDQGHhvUxQjALmQYxHRai60bv5wdDpdkstPiR3d9a5jskk61Ms3PAaatFI3856GWb0HVYNxI5lmSzZWYCZ6y27AbYEghcUmDXp/MbKaQ4i+tf7Zhr/TjsnTIXmd4Uyoguex9MKtpimLmg2P3nn2vT5IeINHpFvfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168317484513.6535925266994; Tue, 28 Nov 2023 02:45:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vYs-0006lL-5I; Tue, 28 Nov 2023 05:43:26 -0500 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 1r7vYp-0006kr-TN for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:23 -0500 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 1r7vYo-0005f1-GU for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:23 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-xNYNfw_wM3Gbg4qw7e26OQ-1; Tue, 28 Nov 2023 05:43:18 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D0B1A84AC62; Tue, 28 Nov 2023 10:43:17 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF9F20268D7; Tue, 28 Nov 2023 10:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168201; 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=czRuS48Nn1k6ylS+U5+ONFWw9urqtIfLEQqVSIBrLjc=; b=i108wtazkOoE/8ccsj9pkJKonrUMmayrxQq1W+IMChPz53ng0LbY/EpM7KUrTnC3IPPwRu 8FHLOv+jflzCcVFuIRDh3XPorxK7VmKKxs7cvJYQzTwTHiYW70sPDetrnB3lNic9IUzkVx 9E5C3RAvSu2YMPmMPbsEvg4D1oQov1A= X-MC-Unique: xNYNfw_wM3Gbg4qw7e26OQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 04/10] vdpa: extract out _dma_end_batch from _listener_commit Date: Tue, 28 Nov 2023 11:42:57 +0100 Message-Id: <20231128104303.3314000-5-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168320323000003 So we can call out vhost_vdpa_dma_end_batch out of the listener callbacks. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index a533fc5bc7..57a8043cd4 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -164,9 +164,8 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPA= Shared *s) s->iotlb_batch_begin_sent =3D true; } =20 -static void vhost_vdpa_listener_commit(MemoryListener *listener) +static void vhost_vdpa_dma_end_batch(VhostVDPAShared *s) { - VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); struct vhost_msg_v2 msg =3D {}; int fd =3D s->device_fd; =20 @@ -190,6 +189,13 @@ static void vhost_vdpa_listener_commit(MemoryListener = *listener) s->iotlb_batch_begin_sent =3D false; } =20 +static void vhost_vdpa_listener_commit(MemoryListener *listener) +{ + VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); + + vhost_vdpa_dma_end_batch(s); +} + static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *i= otlb) { struct vdpa_iommu *iommu =3D container_of(n, struct vdpa_iommu, n); --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168266; cv=none; d=zohomail.com; s=zohoarc; b=Vww9igv8D1wjf/T0vkU/b3j/teS5DFTCkVly/bn3P+HBP+uF+qoeWnjkfIELgxLwEf0VF7l5ELYdQCbem4T1SGSrX0nERMjlPrpnSrIFJkUDCRH7CZqtjMEcYKPbZD1MtjemCtstcEsVLbuEk3vH1F4JhflbBCgxeZpaPmqE0Vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168266; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A8WueJS/E1fA/bzQAcF/yF24VB8sgCLQokVl1j8eJtk=; b=XZNryw2iaxLI2eyOABeMIzvnjoYQSNICXqmRCjxn4/e1zRFwMDlvDgHtZCrVu3fBKWUbICHieW0+gVVDkUAVrHsCs9Kk4/MlXtupvt20um56k2CLY+PnfGnkxaFFQu9frMD+9ypfkoAPX2H/IDo2x5YQzSwysvFy2BPWno3rmiE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168266007605.3063666878129; Tue, 28 Nov 2023 02:44:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vYw-0006mb-BH; Tue, 28 Nov 2023 05:43:30 -0500 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 1r7vYu-0006m8-P9 for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:28 -0500 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 1r7vYt-0005fx-7r for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:28 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-SCCtnt-qNxyXh-zAz7r-8Q-1; Tue, 28 Nov 2023 05:43:20 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F14481D873; Tue, 28 Nov 2023 10:43:20 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B35220268D7; Tue, 28 Nov 2023 10:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168205; 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=A8WueJS/E1fA/bzQAcF/yF24VB8sgCLQokVl1j8eJtk=; b=IxH/d0BAymxKWcLqwfuE/Ra4rIPX6oqcYqaPZkVnT8ju7NT75cGAsdLulM3YKSEeesW+iG E3CAvLr201SJ7gwgjiQPMfDI7GuwiTmQL8iRlQuQ2doX4l8DUI+iVT3+P5nKlvM19sn3Mj W8crxXv+3YeQXWH+apMKtM+Mofal9kM= X-MC-Unique: SCCtnt-qNxyXh-zAz7r-8Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 05/10] vdpa: factor out stop path of vhost_vdpa_dev_start Date: Tue, 28 Nov 2023 11:42:58 +0100 Message-Id: <20231128104303.3314000-6-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168267238000001 This makes easier to build an error path in next patches. No functional change. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 57a8043cd4..449c3794b2 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1302,7 +1302,7 @@ static void vhost_vdpa_suspend(struct vhost_dev *dev) static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; - bool ok; + bool ok =3D true; trace_vhost_vdpa_dev_start(dev, started); =20 if (started) { @@ -1313,8 +1313,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev= , bool started) } } else { vhost_vdpa_suspend(dev); - vhost_vdpa_svqs_stop(dev); - vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); + goto out_stop; } =20 if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { @@ -1333,6 +1332,11 @@ static int vhost_vdpa_dev_start(struct vhost_dev *de= v, bool started) } =20 return 0; + +out_stop: + vhost_vdpa_svqs_stop(dev); + vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); + return ok ? 0 : -1; } =20 static void vhost_vdpa_reset_status(struct vhost_dev *dev) --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168243; cv=none; d=zohomail.com; s=zohoarc; b=lrd690+EojkCZjuthz4K+5oGrlaZBo/y6dKleLM8TJrHaJ2gZOJ5BdKrsYr9gVIOV9A2kvvQElOEbCl/3K7PKsX1ia9izGH4NtusrCqfQKul3W4ywgD0GkTcLFhxnluF35QwF107oZqjG+1nLzBAbICCQByPecbddEP30AIh/gQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168243; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9X3lY7EwesmvNy+U/t0ivD5sWmuCNHr3WZysO4tIJ8U=; b=IBSV8l/FPLmI/WTrsDLAN07wMQbtzq/Dc3rsWlFF1c0ClFqid2MWAcn4rjFr5GmUXdONAX7I3RmY7aQYuYI0I4bVQLE42QRg3doTl7+a0hmM+zY5HYbHW0seCz8klhNU8Yt1JyexgbwCw4SDD9qec7LqFkv4xJ0rnm2dj9AoIaE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168243171264.0494249394126; Tue, 28 Nov 2023 02:44:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vZ0-0006mv-Oh; Tue, 28 Nov 2023 05:43:34 -0500 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 1r7vYz-0006md-55 for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:33 -0500 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 1r7vYu-0005gN-K9 for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:32 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-467-fE16MYqpPDuLOzbJx1LwwQ-1; Tue, 28 Nov 2023 05:43:23 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFD2B280BC43; Tue, 28 Nov 2023 10:43:22 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C77720268D7; Tue, 28 Nov 2023 10:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168207; 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=9X3lY7EwesmvNy+U/t0ivD5sWmuCNHr3WZysO4tIJ8U=; b=cFUTmXM3mFVIkIMUYisWqmxUWCl2YHWm61CGZpoFxRlJWU9iY6PIXauN5/toRk709ttdR+ tUTC2KpOAFzqo3ceKlBwftQ4/YxRrgMyCz5v6C4oxZQOFydUXN6Aoo7eG69T8Rw0sdyhex RMsKHEVORtXZIrQ6k9kcHxHRw+BvLGY= X-MC-Unique: fE16MYqpPDuLOzbJx1LwwQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 06/10] vdpa: check for iova tree initialized at net_client_start Date: Tue, 28 Nov 2023 11:42:59 +0100 Message-Id: <20231128104303.3314000-7-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168245671000006 To map the guest memory while it is migrating we need to create the iova_tree, as long as the destination uses x-svq=3Don. Checking to not override it. The function vhost_vdpa_net_client_stop clear it if the device is stopped. If the guest starts the device again, the iova tree is recreated by vhost_vdpa_net_data_start_first or vhost_vdpa_net_cvq_start if needed, so old behavior is kept. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 3fb209cd35..a37de7860e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -341,7 +341,9 @@ static void vhost_vdpa_net_data_start_first(VhostVDPASt= ate *s) =20 migration_add_notifier(&s->migration_state, vdpa_net_migration_state_notifier); - if (v->shadow_vqs_enabled) { + + /* iova_tree may be initialized by vhost_vdpa_net_load_setup */ + if (v->shadow_vqs_enabled && !v->shared->iova_tree) { v->shared->iova_tree =3D vhost_iova_tree_new(v->shared->iova_range= .first, v->shared->iova_range.l= ast); } --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168248; cv=none; d=zohomail.com; s=zohoarc; b=hq0y8q8EBqXXobTFONRVnxd4L0HF+U2PLGjiJIGMdCdssNXgFvDJoDWtIEw1AkOev3HOlPg1O3bej79eJ0E0MQPLD1uEFcbiOFtvmvW03wDvb6QeO3kMhMgEnH8S3AKxq8HnNGBdG6fWDx2fHhOYr2rqrY8ER0E8SpjWwKBwChc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168248; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dEVdqJdWKralGQPtSdv/lMX0iMS7IIhcmIcBa2iN+lk=; b=bZkKf2m9T66HMt3Z3wcpC+Kcp3u5+mHNf01RSIXv35xRkx+sZv+dX+RNcyMNVKtGLYXzknmbcOaKJ2tHmVEjtzhCLkh3pj9xuFn7XpQkjkt4Yo2Gin5xzx/ugyj4ViSVVjzSxp9e4u7Zn1RpFh+FoCDiEWpNaDkoAtxQBpgr2VA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168248912651.0980743486258; Tue, 28 Nov 2023 02:44:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vZ9-0006nZ-Pb; Tue, 28 Nov 2023 05:43:43 -0500 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 1r7vZ8-0006nI-Oz for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:42 -0500 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 1r7vYv-0005gb-Tk for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:34 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-YHpmpDUBNSOhoCdiePKT2A-1; Tue, 28 Nov 2023 05:43:25 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43D541C294A3; Tue, 28 Nov 2023 10:43:25 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A7B320268D7; Tue, 28 Nov 2023 10:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168209; 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=dEVdqJdWKralGQPtSdv/lMX0iMS7IIhcmIcBa2iN+lk=; b=F2kN+iL0/xsaq8BXayD+PhkO3oUbiLLGqBaxZOQc9WCb7SqdxyomHcWiT4ZgQOv/i0awB7 PfXmtxdIxp83tXZ+wGxym2E7e/foSSRZPPLCL7TnT4SvUcL7xxSXdd5375BbWerH7BaOi8 sMsGrjne4kqPQN3phHOYKebOHgGxwmY= X-MC-Unique: YHpmpDUBNSOhoCdiePKT2A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 07/10] vdpa: set backend capabilities at vhost_vdpa_init Date: Tue, 28 Nov 2023 11:43:00 +0100 Message-Id: <20231128104303.3314000-8-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168249395000003 The backend does not reset them until the vdpa file descriptor is closed so there is no harm in doing it only once. This allows the destination of a live migration to premap memory in batches, using VHOST_BACKEND_F_IOTLB_BATCH. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 50 ++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 449c3794b2..43f7c382b1 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -587,11 +587,25 @@ static int vhost_vdpa_init(struct vhost_dev *dev, voi= d *opaque, Error **errp) struct vhost_vdpa *v =3D opaque; assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); trace_vhost_vdpa_init(dev, v->shared, opaque); + uint64_t backend_features; + uint64_t qemu_backend_features =3D 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG= _V2 | + 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH= | + 0x1ULL << VHOST_BACKEND_F_IOTLB_ASID | + 0x1ULL << VHOST_BACKEND_F_SUSPEND; int ret; =20 v->dev =3D dev; dev->opaque =3D opaque ; v->shared->listener =3D vhost_vdpa_memory_listener; + + if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &backend_features= )) { + return -EFAULT; + } + + backend_features &=3D qemu_backend_features; + + dev->backend_cap =3D backend_features; + v->shared->backend_cap =3D backend_features; vhost_vdpa_init_svq(dev, v); =20 error_propagate(&dev->migration_blocker, v->migration_blocker); @@ -599,6 +613,11 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque, Error **errp) return 0; } =20 + ret =3D vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &backend_feat= ures); + if (ret) { + return -EFAULT; + } + /* * If dev->shadow_vqs_enabled at initialization that means the device = has * been started with x-svq=3Don, so don't block migration @@ -829,36 +848,6 @@ static int vhost_vdpa_set_features(struct vhost_dev *d= ev, return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } =20 -static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) -{ - struct vhost_vdpa *v =3D dev->opaque; - - uint64_t features; - uint64_t f =3D 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | - 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH | - 0x1ULL << VHOST_BACKEND_F_IOTLB_ASID | - 0x1ULL << VHOST_BACKEND_F_SUSPEND; - int r; - - if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { - return -EFAULT; - } - - features &=3D f; - - if (vhost_vdpa_first_dev(dev)) { - r =3D vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &features); - if (r) { - return -EFAULT; - } - } - - dev->backend_cap =3D features; - v->shared->backend_cap =3D features; - - return 0; -} - static int vhost_vdpa_get_device_id(struct vhost_dev *dev, uint32_t *device_id) { @@ -1512,7 +1501,6 @@ const VhostOps vdpa_ops =3D { .vhost_set_vring_kick =3D vhost_vdpa_set_vring_kick, .vhost_set_vring_call =3D vhost_vdpa_set_vring_call, .vhost_get_features =3D vhost_vdpa_get_features, - .vhost_set_backend_cap =3D vhost_vdpa_set_backend_cap, .vhost_set_owner =3D vhost_vdpa_set_owner, .vhost_set_vring_endian =3D NULL, .vhost_backend_memslots_limit =3D vhost_vdpa_memslots_limit, --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168263; cv=none; d=zohomail.com; s=zohoarc; b=LQvcjd5uzwp3wXR70e8RECoAQNgoFXOLgFO9S+2hEZlLHOLnw+SrMzHTCj7YZjBQk8RpGIL5CAS75AZWqV3TAiCZY/GGw43BiUbgs3QR32HI5TQLkJfJRJ/+Z2I3yegEVCt3uO4oOoXPOAHPtVh7L53i+U4mUJ/6gvKC1xjJIEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168263; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IMGBqBxHbDIzPYVYBCJ4kY+zoFlcXenNG6ZZ68h3Q48=; b=aLfQkgEFoFv1Ib1xGJGzc8OlTpOFbluAVwLCe+vNDObTpBfz+xpzA4ZrWOJZ1kM8sASncQL9TBL5Xnldl4HT1O8mEShX7dFrzyT6/CHwybNj8QfWvEFWFRRWXTMWXVRi/Ab9EPjGH+2RLBOZHShaAWbQlPAxpT/uvKDmp9jHFVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168263062328.6554906921093; Tue, 28 Nov 2023 02:44:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vZ9-0006nY-Kd; Tue, 28 Nov 2023 05:43:43 -0500 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 1r7vZ8-0006nJ-P5 for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:42 -0500 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 1r7vYz-0005gl-15 for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:34 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-k8rMvenXNIS1U4xt27kKgA-1; Tue, 28 Nov 2023 05:43:28 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5780185A782; Tue, 28 Nov 2023 10:43:27 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 809FF20268D7; Tue, 28 Nov 2023 10:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168212; 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=IMGBqBxHbDIzPYVYBCJ4kY+zoFlcXenNG6ZZ68h3Q48=; b=cM4i2fA8qZge4cKhf0ZsOoMVBDWHVlpG1dMOcB7XHz9UtAuStLmG6clD8bon4hU5oueL5S H1je9XPxmbmphlnhewBYdmj/VUqK+aiZtqyVYDB078dUans3MJwDVto6P8OMXp0MdH9Y67 nkKDrAXyr6mZWqsW6eRgZA082c6UUro= X-MC-Unique: k8rMvenXNIS1U4xt27kKgA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 08/10] vdpa: add vhost_vdpa_load_setup Date: Tue, 28 Nov 2023 11:43:01 +0100 Message-Id: <20231128104303.3314000-9-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168263257000001 Callers can use this function to setup the incoming migration thread. This thread is able to map the guest memory while the migration is ongoing, without blocking QMP or other important tasks. While this allows the destination QEMU not to block, it expands the mapping time during migration instead of making it pre-migration. This thread joins at vdpa backend device start, so it could happen that the guest memory is so large that we still have guest memory to map before this time. This can be improved in later iterations, when the destination device can inform QEMU that it is not ready to complete the migration. If the device is not started, the clean of the mapped memory is done at .load_cleanup. This is far from ideal, as the destination machine has mapped all the guest ram for nothing, and now it needs to unmap it. However, we don't have information about the state of the device so its the best we can do. Once iterative migration is supported, this will be improved as we know the virtio state of the device. TODO RFC: if the VM migrates before finishing all the maps, the source will stop but the destination is still not ready to continue, and it will wait until all guest RAM is mapped. It is still an improvement over doing all the map when the migration finish, but it should be easy to forbid the guest to stop until a condition is met. TODO RFC: The memory unmapping if the device is not started is weird too, as ideally nothing would be mapped. This can be fixed when we migrate the device state iteratively, and we know for sure if the device is started or not. At this moment we don't have such information so there is no better alternative. Other options considered: * Coroutines: Overkill? What thread can I assign them, as vdpa does not have any dedicated iothread for the moment? * QemuEvent or Mutex + Cond: Need to synchronize list access then, complicating the synchronization. As maps ops are heavier enough, it is not worth. Signed-off-by: Eugenio P=C3=A9rez --- RFC v2: * Use a dedicated thread for map instead of doing all in .load_setup, blocking QMP etc. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 25 +++++ hw/virtio/vhost-vdpa.c | 167 ++++++++++++++++++++++++++++++++- 2 files changed, 191 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 8f54e5edd4..6533ad211c 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -17,6 +17,7 @@ #include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/virtio.h" +#include "qemu/thread.h" #include "standard-headers/linux/vhost_types.h" =20 /* @@ -43,8 +44,30 @@ typedef struct vhost_vdpa_shared { /* Copy of backend features */ uint64_t backend_cap; =20 + /* + * Thread to map memory in QEMU incoming migration. + * + * Incoming migration calls devices ->load_setup in the main thread, b= ut + * map operations can take a long time. This forbids the main thread = to + * serve other requests like QMP. + * + * It works by fetching jobs from map_queue until it receives + * VhostVDPAShared, signalling the end of thread job. From that point, + * thread is joined and maps requests are synchronous again. These new + * maps are not served from main thread, so there is no danger there. + */ + QemuThread map_thread; + GAsyncQueue *map_queue; + bool map_thread_enabled; + bool iotlb_batch_begin_sent; =20 + /* + * The memory listener has been registered, so DMA maps have been sent= to + * the device. + */ + bool listener_registered; + /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ bool shadow_data; } VhostVDPAShared; @@ -73,6 +96,8 @@ int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid,= hwaddr iova, hwaddr size, void *vaddr, bool readonly); int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size); +int vhost_vdpa_load_setup(VhostVDPAShared *s, AddressSpace *dma_as); +int vhost_vdpa_load_cleanup(VhostVDPAShared *s, bool vhost_will_start); =20 typedef struct vdpa_iommu { VhostVDPAShared *dev_shared; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 43f7c382b1..24844b5dfa 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -101,6 +101,15 @@ int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t as= id, hwaddr iova, msg.iotlb.perm =3D readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; msg.iotlb.type =3D VHOST_IOTLB_UPDATE; =20 + if (s->map_thread_enabled && !qemu_thread_is_self(&s->map_thread)) { + struct vhost_msg_v2 *new_msg =3D g_new(struct vhost_msg_v2, 1); + + *new_msg =3D msg; + g_async_queue_push(s->map_queue, new_msg); + + return 0; + } + trace_vhost_vdpa_dma_map(s, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.pe= rm, msg.iotlb.type); @@ -131,6 +140,15 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t = asid, hwaddr iova, msg.iotlb.size =3D size; msg.iotlb.type =3D VHOST_IOTLB_INVALIDATE; =20 + if (s->map_thread_enabled && !qemu_thread_is_self(&s->map_thread)) { + struct vhost_msg_v2 *new_msg =3D g_new(struct vhost_msg_v2, 1); + + *new_msg =3D msg; + g_async_queue_push(s->map_queue, new_msg); + + return 0; + } + trace_vhost_vdpa_dma_unmap(s, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.type); =20 @@ -156,6 +174,15 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDP= AShared *s) return; } =20 + if (s->map_thread_enabled && !qemu_thread_is_self(&s->map_thread)) { + struct vhost_msg_v2 *new_msg =3D g_new(struct vhost_msg_v2, 1); + + *new_msg =3D msg; + g_async_queue_push(s->map_queue, new_msg); + + return; + } + trace_vhost_vdpa_listener_begin_batch(s, fd, msg.type, msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", @@ -180,6 +207,15 @@ static void vhost_vdpa_dma_end_batch(VhostVDPAShared *= s) msg.type =3D VHOST_IOTLB_MSG_V2; msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; =20 + if (s->map_thread_enabled && !qemu_thread_is_self(&s->map_thread)) { + struct vhost_msg_v2 *new_msg =3D g_new(struct vhost_msg_v2, 1); + + *new_msg =3D msg; + g_async_queue_push(s->map_queue, new_msg); + + return; + } + trace_vhost_vdpa_listener_commit(s, fd, msg.type, msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", @@ -1288,6 +1324,94 @@ static void vhost_vdpa_suspend(struct vhost_dev *dev) vhost_vdpa_reset_device(dev); } =20 +static void *vhost_vdpa_load_map(void *opaque) +{ + VhostVDPAShared *shared =3D opaque; + GPtrArray *ret =3D NULL; + + while (true) { + g_autofree struct vhost_msg_v2 *msg =3D NULL; + void *job =3D g_async_queue_pop(shared->map_queue); + int r =3D 0; + + if (job =3D=3D shared) { + /* exit signal */ + break; + } + + msg =3D job; + switch (msg->iotlb.type) { + case VHOST_IOTLB_UPDATE: + r =3D vhost_vdpa_dma_map(shared, msg->asid, msg->iotlb.iova, + msg->iotlb.size, + (void *)(uintptr_t)msg->iotlb.uaddr, + msg->iotlb.perm =3D=3D VHOST_ACCESS_RO); + break; + case VHOST_IOTLB_INVALIDATE: + r =3D vhost_vdpa_dma_unmap(shared, msg->asid, msg->iotlb.iova, + msg->iotlb.size); + break; + case VHOST_IOTLB_BATCH_BEGIN: + vhost_vdpa_iotlb_batch_begin_once(shared); + break; + case VHOST_IOTLB_BATCH_END: + vhost_vdpa_dma_end_batch(shared); + break; + default: + error_report("Invalid IOTLB msg type %d", msg->iotlb.type); + break; + }; + + if (unlikely(r !=3D 0)) { + /* Add to return value so we can remove it from iova_tree */ + if (ret =3D=3D NULL) { + ret =3D g_ptr_array_new_full(0, g_free); + } + + g_ptr_array_add(ret, g_steal_pointer(&msg)); + } + } + + return ret; +} + +static void vhost_vdpa_spawn_maps_thread(VhostVDPAShared *shared) +{ + shared->map_queue =3D g_async_queue_new(); + qemu_thread_create(&shared->map_thread, "vdpa map thread", + vhost_vdpa_load_map, shared, QEMU_THREAD_JOINABLE); + shared->map_thread_enabled =3D true; +} + +static bool vhost_vdpa_join_maps_thread(VhostVDPAShared *shared) +{ + g_autoptr(GPtrArray) failed_iova =3D NULL; + + /* Signal end of offloading maps */ + g_async_queue_push(shared->map_queue, shared); + failed_iova =3D qemu_thread_join(&shared->map_thread); + g_async_queue_unref(shared->map_queue); + + shared->map_thread_enabled =3D false; + + if (likely(!failed_iova)) { + return true; + } + + /* If it is a failed IOVA, abort starting */ + for (size_t i =3D 0; failed_iova->len; ++i) { + struct vhost_msg_v2 *msg =3D g_ptr_array_index(failed_iova, i); + DMAMap mem_region =3D { + .iova =3D msg->iotlb.iova, + .size =3D msg->iotlb.size - 1, /* Inclusive */ + }; + + vhost_iova_tree_remove(shared->iova_tree, mem_region); + } + + return false; +} + static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; @@ -1315,7 +1439,15 @@ static int vhost_vdpa_dev_start(struct vhost_dev *de= v, bool started) "IOMMU and try again"); return -1; } - memory_listener_register(&v->shared->listener, dev->vdev->dma_as); + if (!v->shared->listener_registered) { + memory_listener_register(&v->shared->listener, dev->vdev->dma_= as); + v->shared->listener_registered =3D true; + } else { + ok =3D vhost_vdpa_join_maps_thread(v->shared); + if (unlikely(!ok)) { + goto out_stop; + } + } =20 return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); } @@ -1340,6 +1472,8 @@ static void vhost_vdpa_reset_status(struct vhost_dev = *dev) vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); memory_listener_unregister(&v->shared->listener); + v->shared->listener_registered =3D false; + } =20 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, @@ -1522,3 +1656,34 @@ const VhostOps vdpa_ops =3D { .vhost_set_config_call =3D vhost_vdpa_set_config_call, .vhost_reset_status =3D vhost_vdpa_reset_status, }; + +int vhost_vdpa_load_setup(VhostVDPAShared *shared, AddressSpace *dma_as) +{ + uint8_t s =3D VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; + int r =3D ioctl(shared->device_fd, VHOST_VDPA_SET_STATUS, &s); + if (unlikely(r < 0)) { + return r; + } + + vhost_vdpa_spawn_maps_thread(shared); + memory_listener_register(&shared->listener, dma_as); + shared->listener_registered =3D true; + return 0; +} + +int vhost_vdpa_load_cleanup(VhostVDPAShared *shared, bool vhost_will_start) +{ + if (!shared->map_thread_enabled) { + return 0; + } + + if (vhost_will_start) { + /* + * Delegate the join of map thread to vhost_vdpa_dev_start, as it = runs + * out of main qemu lock. + */ + return 0; + } + + return vhost_vdpa_join_maps_thread(shared) ? 0 : -1; +} --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168281; cv=none; d=zohomail.com; s=zohoarc; b=CjVVI8SXhn2PvJfobyfVCa6OsaSCSi3UtbfM5FrC19ITj9irBBRjd24z+oPyWyJLcBV2e9IKqnxrPVxrk7tMFzU49wnppe333e2ZwPrk6uoArdX6rFg2sS4iPGq2VUcA0wWMUNw4HevBU/7V1uwfyIG6gLG4fq0VkzFBN48jIOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168281; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Xzdm5YKmAcApcYJb/8xg+e8LPU0ALlufPyzIkHlXIls=; b=cDLfTdLGpVlidK0fwuWSY/GXg1yYmZAmarjK4ix1suMzMRQyoFdrWtxhFw1mGGNXXlkjTXWeCxTqJQJcQYmdCr3csYobkjG/CrZmfyxRqW6+9bGhURePF3mDsx9yXYJQ3Qg+zypCSAHLtqOdUeip9fDbrNXbNJWoETIf/qPSzDQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701168281692970.424404283506; Tue, 28 Nov 2023 02:44:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vZC-0006or-PA; Tue, 28 Nov 2023 05:43:46 -0500 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 1r7vZB-0006oP-Fr for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:45 -0500 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 1r7vZ8-0005hE-HN for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:45 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-542-TWrBiRRdPC6xv7FHK5ke8w-1; Tue, 28 Nov 2023 05:43:30 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34F1D8309A3; Tue, 28 Nov 2023 10:43:30 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0096420268D8; Tue, 28 Nov 2023 10:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168215; 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=Xzdm5YKmAcApcYJb/8xg+e8LPU0ALlufPyzIkHlXIls=; b=BCafkelNHgcWfgJv5P0uZupH+eHrb3qL5wlSAn55E3NjtOYeBJ1DAEHahNU8NldGy+AXtt 2rZS3iYcXZoiZaEkz/I5F3Patryfk0FCqPjhu61F14UAsHDXw56s16G9DsxxCP+qH+sU+H Dpuh7BoTA+Ucm+CH6Ir03nQPdTBnG8Q= X-MC-Unique: TWrBiRRdPC6xv7FHK5ke8w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 09/10] vdpa: add vhost_vdpa_net_load_setup NetClient callback Date: Tue, 28 Nov 2023 11:43:02 +0100 Message-Id: <20231128104303.3314000-10-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168283402000003 So the vDPA backend knows when a migration incoming starts. NicState argument is needed so we can get the dma address space. Signed-off-by: Eugenio P=C3=A9rez --- RFC v2: * Solve git conflict with .set_steering_ebpf * Fix x-svq=3Don use case which did not allocated iova_tree. --- include/net/net.h | 6 ++++++ net/vhost-vdpa.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index ffbd2c8d56..68282dde31 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -42,6 +42,7 @@ typedef struct NICConf { =20 /* Net clients */ =20 +struct NICState; typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); typedef int (NetStart)(NetClientState *); @@ -69,6 +70,9 @@ typedef void (SocketReadStateFinalize)(SocketReadState *r= s); typedef void (NetAnnounce)(NetClientState *); typedef bool (SetSteeringEBPF)(NetClientState *, int); typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **); +/* This can be called before start & pair, so get also the peer */ +typedef int (NetMigrationLoadSetup)(NetClientState *, struct NICState *); +typedef int (NetMigrationLoadCleanup)(NetClientState *, struct NICState *); =20 typedef struct NetClientInfo { NetClientDriver type; @@ -98,6 +102,8 @@ typedef struct NetClientInfo { NetAnnounce *announce; SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; + NetMigrationLoadSetup *load_setup; + NetMigrationLoadCleanup *load_cleanup; } NetClientInfo; =20 struct NetClientState { diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index a37de7860e..90f41280d2 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -407,6 +407,37 @@ static void vhost_vdpa_net_client_stop(NetClientState = *nc) } } =20 +static int vhost_vdpa_net_load_setup(NetClientState *nc, NICState *nic) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + VirtIONet *n =3D qemu_get_nic_opaque(&nic->ncs[0]); + VhostVDPAShared *shared =3D s->vhost_vdpa.shared; + int r; + + if (s->always_svq) { + /* iova tree is needed because of SVQ */ + shared->iova_tree =3D vhost_iova_tree_new(shared->iova_range.first, + shared->iova_range.last); + } + + r =3D vhost_vdpa_load_setup(shared, n->parent_obj.dma_as); + if (unlikely(r < 0)) { + g_clear_pointer(&s->vhost_vdpa.shared->iova_tree, + vhost_iova_tree_delete); + } + + return r; +} + +static int vhost_vdpa_net_load_cleanup(NetClientState *nc, NICState *nic) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + VirtIONet *n =3D qemu_get_nic_opaque(&nic->ncs[0]); + + return vhost_vdpa_load_cleanup(s->vhost_vdpa.shared, + n->parent_obj.status & VIRTIO_CONFIG_S_DRIVER= _OK); +} + static NetClientInfo net_vhost_vdpa_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), @@ -419,6 +450,8 @@ static NetClientInfo net_vhost_vdpa_info =3D { .has_ufo =3D vhost_vdpa_has_ufo, .check_peer_type =3D vhost_vdpa_check_peer_type, .set_steering_ebpf =3D vhost_vdpa_set_steering_ebpf, + .load_setup =3D vhost_vdpa_net_load_setup, + .load_cleanup =3D vhost_vdpa_net_load_cleanup, }; =20 static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index, --=20 2.39.3 From nobody Wed Nov 27 02:29:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1701168290; cv=none; d=zohomail.com; s=zohoarc; b=n38ewCKjQm8LwCaSaCqmvk661OgncjRnShDiQn5KIbu5sd4sa1nsagpH64F7B0EhSjv9/8JGzCl6qtyAXfQZoPH6Edox3XNDzLzmUyEYImlUIYs/kimLQbVAMPOG9BN6vueuN6g4X/rgvicN4GhYKf5e5wsuL0BoXZO9BiLzQEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701168290; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Wj2KOCSd3gkqmbd2ClDeaOLOq55F9jaRkAO+a/H8Y0M=; b=RM6XIVEPjUkmIRcbEzZV+RJi6HdxCfWcXb52sCIJKd85eeox1Y1zY4dz/S32DITYKQmOi5VFisJevG7oltMQZ0sCULoCbEchoDbEk6AizuvNJrZ01wk5nyf7ljSyp2HZN7889rGrm3BrmkB7BcBc603ARUDsq1gPFC7RLZHKub0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170116829023337.085958701191544; Tue, 28 Nov 2023 02:44:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7vZC-0006om-6Y; Tue, 28 Nov 2023 05:43:46 -0500 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 1r7vZA-0006nb-3H for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:44 -0500 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 1r7vZ7-0005hA-En for qemu-devel@nongnu.org; Tue, 28 Nov 2023 05:43:43 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-KUyxP7KWMa26lB9DH_zD5w-1; Tue, 28 Nov 2023 05:43:33 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A559481D871; Tue, 28 Nov 2023 10:43:32 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70FFE20268D7; Tue, 28 Nov 2023 10:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701168214; 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=Wj2KOCSd3gkqmbd2ClDeaOLOq55F9jaRkAO+a/H8Y0M=; b=QQQIOYOUtdGr0o7ptCRwlXVzp02reWtPAZnw5VmwsBBTuTsB3LPsy+mNjSK65M5VclWFG1 v1xQ+/ofCwdM/wCaX3h37rtLcbyqc4XW0vdDt7yg7yAlXGicrZqHnpLZCBQ0w3Mygc5K45 drXwq1b4vlxi2b7FSZXgE9fbTucKDLc= X-MC-Unique: KUyxP7KWMa26lB9DH_zD5w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Jason Wang , Zhu Lingshan , yin31149@gmail.com, Shannon Nelson , "Michael S. Tsirkin" , Dragos Tatulea , Yajun Wu , Juan Quintela , Laurent Vivier , Stefano Garzarella , Parav Pandit , Lei Yang , si-wei.liu@oracle.com Subject: [RFC PATCH v2 10/10] virtio_net: register incremental migration handlers Date: Tue, 28 Nov 2023 11:43:03 +0100 Message-Id: <20231128104303.3314000-11-eperezma@redhat.com> In-Reply-To: <20231128104303.3314000-1-eperezma@redhat.com> References: <20231128104303.3314000-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1701168291395000001 This way VirtIONet can detect when the incoming migration starts. While registering in the backend (nc->peer) seems more logical, we need nic dma address space, and we cannot get it from the backend. Signed-off-by: Eugenio P=C3=A9rez --- This could be done in vhost_vdpa or VirtIODevice struct, but future series will add state restore through CVQ so it's easier to start in VirtIONet directly. If we need to make this more generic, we can move to VirtIODevice and expose callbacks from VirtIONet class. Also, the pointer may not be the best id, but there are not a lot of things initialized in n. --- hw/net/virtio-net.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 80c56f0cfc..374d0b4ec8 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -38,6 +38,7 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/register.h" #include "standard-headers/linux/ethtool.h" #include "sysemu/sysemu.h" #include "trace.h" @@ -3810,9 +3811,39 @@ static void virtio_net_device_unrealize(DeviceState = *dev) virtio_cleanup(vdev); } =20 +static int virtio_net_load_setup(QEMUFile *f, void *opaque) +{ + VirtIONet *n =3D opaque; + NetClientState *nc =3D qemu_get_subqueue(n->nic, 0); + + if (nc->peer->info->load_setup) { + return nc->peer->info->load_setup(nc->peer, n->nic); + } + + return 0; +} + +static int virtio_net_load_cleanup(void *opaque) +{ + VirtIONet *n =3D opaque; + NetClientState *nc =3D qemu_get_subqueue(n->nic, 0); + + if (nc->peer->info->load_cleanup) { + return nc->peer->info->load_cleanup(nc->peer, n->nic); + } + + return 0; +} + +static const SaveVMHandlers savevm_virtio_net_handlers =3D { + .load_setup =3D virtio_net_load_setup, + .load_cleanup =3D virtio_net_load_cleanup, +}; + static void virtio_net_instance_init(Object *obj) { VirtIONet *n =3D VIRTIO_NET(obj); + g_autoptr(GString) id =3D g_string_new(NULL); =20 /* * The default config_size is sizeof(struct virtio_net_config). @@ -3824,6 +3855,10 @@ static void virtio_net_instance_init(Object *obj) DEVICE(n)); =20 ebpf_rss_init(&n->ebpf_rss); + + g_string_printf(id, "%p", n); + register_savevm_live(id->str, VMSTATE_INSTANCE_ID_ANY, 1, + &savevm_virtio_net_handlers, n); } =20 static int virtio_net_pre_save(void *opaque) --=20 2.39.3