From nobody Wed Nov 19 18:40:20 2025 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=1702661403; cv=none; d=zohomail.com; s=zohoarc; b=cZLThhj0BlRMW7RBx5tYQdwxtMTIPssPl13aejJkwVNZ1+Ovh0IEOKUwYk+xJ1c+vZ0Zp5ADGEfJWnq2KOdhXUvXppHhCPz8jUBhcEaE3zbx2iIqFNgAVEhp5iWBHcVMphSxOhBLYV9ofFk2CByEpijKrQpTWihYr3SAJYYv3ZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661403; 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=PkMN1nPj5A25IeLgCKKxet5TFqX79/Bu0sElCs2MvaEC6j5goy4oXVQLFOovRkiILN+eEwajDLygOH+bNZNKGYFWOhwlqP3Zhbr5TebGtf06tOkczbBYWcYXfdPss3OKktoIm+FF+sfyCIR5sDH14pEjmYsjSWFzDKIElfG4VZ0= 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 170266140355171.16310960225667; Fri, 15 Dec 2023 09:30:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzO-0005wv-Us; Fri, 15 Dec 2023 12:28:42 -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 1rEBzN-0005wh-4h for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:41 -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 1rEBzL-00011H-QK for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:40 -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-17-C037A92VNquM0olNjaQOdw-1; Fri, 15 Dec 2023 12:28:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 9E216185A782; Fri, 15 Dec 2023 17:28:35 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02D4640C6EB9; Fri, 15 Dec 2023 17:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661318; 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=M1TcYtNKo4JOtmUwE+BG218KOLr/c/3ZVSp2+9iIqQqsF92vjehkKKXzPUN2uvahna8E5T clldiS9ZpyH3jeczc0wVWpM8vCtlKjMISL2NzwFWewhwEKghJCuk3LgSlmHaNS5cF+k4uy zTkPLk9xyqjuFOvswLAmlol/IquJgkA= X-MC-Unique: C037A92VNquM0olNjaQOdw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 01/12] vdpa: do not set virtio status bits if unneeded Date: Fri, 15 Dec 2023 18:28:19 +0100 Message-Id: <20231215172830.2540987-2-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661404059100001 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 Acked-by: Jason Wang Tested-by: Lei Yang --- 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 19 18:40:20 2025 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=1702661397; cv=none; d=zohomail.com; s=zohoarc; b=VUdzfiauH7FFLJIwm2EPhjAVBPGEV+BDuzc2glgoiO1G4V6yvKygAjLCq0XsGVsw3PtXmvjc3LGGEWZim1CHYl4Ru0fVTXp/R0fx5ZYdaxdpQADvL6pyc4uH/Lx4aW/N9rxT58fQzRt+Xn6aFaK1n5IzPGdxnlemimrroM/xgoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661397; 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=X18Kn97ZDXfiv+eiHTe6smjqTH9/utcOH794nkaOfBq4Fe4mu6wOU3vg4ng5YxicxsxSpG1sgM+9OQuPCAkOCHsqZh+NHtAF+NoXTV2KCHcXe8tinnbr6NLmJZA23IBbXOrmtc4t28TaMB4Q+cjlzZs/+I9rQ7PFQwzHyC8xu0w= 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 1702661397008658.4156877479681; Fri, 15 Dec 2023 09:29:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzS-0005y6-Sl; Fri, 15 Dec 2023 12:28: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 1rEBzQ-0005xT-PK for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28: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 1rEBzP-00011j-Bd for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:44 -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-636-4CJwaGxNPV2hK98ZoeoDpw-1; Fri, 15 Dec 2023 12:28:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 83D8F101A555; Fri, 15 Dec 2023 17:28:37 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC66F40C6EB9; Fri, 15 Dec 2023 17:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661321; 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=NAKTkDavReJXxJZbooxaZkhlncn+ftGCkX/uq70ixE0/1FNftdjZBANHwmyp9DS89uF+vg Kfj3oP7ISJ2kGeDZ0e5NA/gwJP8s7q7B6m3fsTAE2l6D/lmrBllQTRVsEZo8Y15oABZhgp iLkvgKcarMetrAomMRrEHKcBwnZezEo= X-MC-Unique: 4CJwaGxNPV2hK98ZoeoDpw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 02/12] vdpa: make batch_begin_once early return Date: Fri, 15 Dec 2023 18:28:20 +0100 Message-Id: <20231215172830.2540987-3-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661398150100001 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 Acked-by: Jason Wang Tested-by: Lei Yang --- 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 19 18:40:20 2025 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=1702661472; cv=none; d=zohomail.com; s=zohoarc; b=Te8AxDXByt981nxWnkJbHls/o6oPoLm+ES8hiSIbO62wRZ8cTCRtWCyWdwES4bpCHudjFqwjJIAt1QfNgkTRFai6yBt5tiH3sTCENttQARXNntMGhuoaApspEMPnGnCS3e23CydrYe6PzCb82+R9gpBxWYOEF0QZZkEuBWZk4hM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661472; 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=jOzuhdq9eOtDr6zcKVcTp4cQdpF9P3zqir2gNp0nJ+05pFWL7V4+ap6Z3R+O1dtasE7JZWheMP2Cu+7VjSxH4I2oyKbUSjG3bHzOFjL7nXK9X95pnI+QEFKIXlgHWRvFiU7Xf5ithy56L/cBbflUSp8kGgcHU7T7FpvujjuMw+g= 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 1702661472777210.00404243061598; Fri, 15 Dec 2023 09:31:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBze-00063O-UC; Fri, 15 Dec 2023 12:28:58 -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 1rEBzd-00062f-OK for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:57 -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 1rEBzT-00012I-DR for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:57 -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-680-y0vUjWydPPKpVcdWchzIvA-1; Fri, 15 Dec 2023 12:28:39 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 693C9185A784; Fri, 15 Dec 2023 17:28:39 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2AEC40C6EB9; Fri, 15 Dec 2023 17:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661326; 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=RMtAbOs3v5DSU4MBOfHOWH6f2r76PJSdk3TuV6wIkP2egH0hnxLPpCL4pKQIuOaWTouACZ js3fbTjriEITlsSmewW09Yt4Z79Qh2gUtXzTLodcxbSChKbKR6rXnFH1l9f5juuoQqkjQF sl8HVRHZwRwmyXxtw6Zq4Uz+6qXnSrY= X-MC-Unique: y0vUjWydPPKpVcdWchzIvA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 03/12] vdpa: merge _begin_batch into _batch_begin_once Date: Fri, 15 Dec 2023 18:28:21 +0100 Message-Id: <20231215172830.2540987-4-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661474402100001 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 Acked-by: Jason Wang Tested-by: Lei Yang --- 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 19 18:40:20 2025 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=1702661364; cv=none; d=zohomail.com; s=zohoarc; b=WVG4en0PepWRCb007PkDrau64YHu6iJ/H15HGpJsYAYnBIimYIERenoWHkmRbbZC36kn7E7k/bQjaQCgSnJmWIeUtbI4cIGnGR4FOpFDZOAeIY1DBJgXfwUEc6qhaQBz6IZaEkMvMPOzP71fhJRR9wLPrNKan16j0iB30XHNBPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661364; 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=NXKGioLywC1pAdrjBlsKpgWgDQhnTIPomeyBCT7mxb16bdOocEblxWdCCZlbV3DLeMxOYb68M2vw9Hzdh+hP3uhZVt5lGglStpNGGmAubS05v53o34y5Sijc/u+FvDxwFOKgnwJmq1N8SB12VbhcYQ0ly9TmeU12Rt7rzqVR83k= 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 1702661364644672.4536310049085; Fri, 15 Dec 2023 09:29:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzS-0005y4-Gp; Fri, 15 Dec 2023 12:28: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 1rEBzR-0005xc-Fo for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:45 -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 1rEBzQ-00011x-25 for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28: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-451-PVbof7ltPvGRCHTPRctmxA-1; Fri, 15 Dec 2023 12:28:41 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 4F55286EB20; Fri, 15 Dec 2023 17:28:41 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7C3440C6EB9; Fri, 15 Dec 2023 17:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661323; 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=PqpsDcIROmIdTyroSfjrmekUYxBpL/mwCFafdI1UNV8cvYRHnLPg+fzrGbMhtP8YN7cI0e poWyCGaxxIIEv5wGD/SbnF8ZZpG7MbtPaV1VteGywq7HOrqW4NhmCPgzO9qWckkuDvBC59 PRq++iVgFhlklzf8RMkaAwUY0SBn/00= X-MC-Unique: PVbof7ltPvGRCHTPRctmxA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 04/12] vdpa: extract out _dma_end_batch from _listener_commit Date: Fri, 15 Dec 2023 18:28:22 +0100 Message-Id: <20231215172830.2540987-5-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661365813100001 So we can call out vhost_vdpa_dma_end_batch out of the listener callbacks. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Tested-by: Lei Yang --- 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 19 18:40:20 2025 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=1702661464; cv=none; d=zohomail.com; s=zohoarc; b=ZpO37adKxL6L4+PPeHa/fPj6ZubY51G7XFJ0Hxvl1xyhVriqSmwpf7h2CjPZ8Q1uXG4L42Tt9I8k6VL7HxsEVRq4ZCerShV5pAbQ80yMEHFM7s3+VYt8j+XAToLW3TttR48bfRfrKNn2KP/EeI0+ZyccCyCjreJGixrSkyPvIsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661464; 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=EP5JRIymMoPSdZCKc+rTpnCtDGpG+Et6ONjFJa8cSD49sdj4v7DQ77RpkPu83e7qfTiss1rKLHwZ0mZROLnLjPbWjJYsLV0d2fLi2l4GD6VbSrPjt17Egv8zgZ3Vj6AK2jPVY0XOX5oZST2AodOBDP7tBlSrXwu4of6JKU2NFCU= 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 1702661463995432.10558345412926; Fri, 15 Dec 2023 09:31:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzX-00060o-Pg; Fri, 15 Dec 2023 12:28:51 -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 1rEBzW-00060J-8B for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:50 -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 1rEBzU-00012T-Tx for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:50 -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-335-hbd6RSiPO66HHEHjmgzzyw-1; Fri, 15 Dec 2023 12:28:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 32F5D3C00095; Fri, 15 Dec 2023 17:28:43 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D01340C6EB9; Fri, 15 Dec 2023 17:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661328; 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=OEZie9zeBqC5wlOi1RlqhEZ3+RadD5bUUOfpSwfG8brHMwV3+z2lsV5q7aL+HxIaZFefIn FG177o7hpOPvpvYIUelqJ/D+rnEScvwKiIxju0OpBDJeYAVt7Xy86TO3TZXbqapbM5TGRm L+cYujha9FuOux9IUHp13UMSDOa6pMU= X-MC-Unique: hbd6RSiPO66HHEHjmgzzyw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 05/12] vdpa: factor out stop path of vhost_vdpa_dev_start Date: Fri, 15 Dec 2023 18:28:23 +0100 Message-Id: <20231215172830.2540987-6-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661464403100007 This makes easier to build an error path in next patches. No functional change. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang Tested-by: Lei Yang --- 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 19 18:40:20 2025 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=1702661442; cv=none; d=zohomail.com; s=zohoarc; b=A0lZL0Itp1xB98GV89WjcsB8drJCFJfm641fY5Yr1ty0Ot2zF/rIHUbXI1apk8shOOCXQ7TK2nFC5FpprTfc6Er+SEZ38gBGjYYvAKMJ2NM0BOCGc5dN1ex8DbrXhZtIUAzdEQByrwZrsy02cO7bkxAyJUASpnq3+DNn9nlk7Uo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661442; 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=qQKcPkY6/W3EsLgkAEJ6imao+rgKnctifkMPjHMrgNY=; b=DECbgZN03WRl2f9/vQk9DYpHPz2iIfAe9Mk37N0V/TQCQrW4Hg9h+QG4icIdA7xCXT0B7KdXm3VWAR+2th2Mx3fs9O/+MX8QqdhFU4YBganld55j11jv1nt/93+YXdGUy71tFC4pjZk6s6qEVx4YBuWsdpgTlkAuMDhyJEDTQIc= 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 170266144293844.680113838219995; Fri, 15 Dec 2023 09:30:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzX-00060S-2j; Fri, 15 Dec 2023 12:28:51 -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 1rEBzV-00060A-5n for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:49 -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 1rEBzT-00012M-ST for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:48 -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-140-2mORFIW-PKyBzTgLwEV3pw-1; Fri, 15 Dec 2023 12:28:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 16D891C2B662; Fri, 15 Dec 2023 17:28:45 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70E0640C6EBC; Fri, 15 Dec 2023 17:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661327; 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=qQKcPkY6/W3EsLgkAEJ6imao+rgKnctifkMPjHMrgNY=; b=iKNVUAcnT8pT960fK/f0oD5DbkJEo+lnFOnEKnWtCSM0q2o3VcSaSsFdnGxLbjlkSxtzTc zEAEwb4vt4gv0zwph9s6YZCtekKEQFKjeEZOSchU8hO0dGgkzJnAlZaJl3XE3rDtInmO8J DN18kHPgbqysDAzl6QTIjwcnTTczNr8= X-MC-Unique: 2mORFIW-PKyBzTgLwEV3pw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 06/12] vdpa: check for iova tree initialized at net_client_start Date: Fri, 15 Dec 2023 18:28:24 +0100 Message-Id: <20231215172830.2540987-7-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661444244100003 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 Tested-by: Lei Yang --- 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 3726ee5d67..e11b390466 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 19 18:40:20 2025 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=1702661398; cv=none; d=zohomail.com; s=zohoarc; b=Od3IZvwUOfh9b9SYkuVcPbKtB0ffwN0AHehoVsPrjSkFVRItVOTHIExadUgK5xoqqyRzliSQPuo3Bhb/CcrO+ngh6CgV5o62ywNu4niLB6iYQ6DQxeF+I1qzvSocKfVTqs/HwOk24X+v8LSngmfvRQ4IydpWCsB5q1GWprE593Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661398; 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=mk1dNfnor9hirsn1mzkFUWoBOIQlaGs6Q6Wp1tPqwz9OBn7dBVJKqOxGVkVzQTNx4/Pz9VWRB3wn1umBJHLU6w5U0izLzcv59AP5/HSk+djTqTCjfNL0Y/rMLDjp+JfNSBPRY1U2BRqjv3SM0jTT7TNpxoPj5sjC2lYNg7bp3YU= 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 1702661398293299.9285760052975; Fri, 15 Dec 2023 09:29:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzb-00061c-A2; Fri, 15 Dec 2023 12:28:55 -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 1rEBzZ-000615-RB for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:53 -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 1rEBzY-000138-7d for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:53 -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-403-iAB1zuXvPx-d6JIv57cXCA-1; Fri, 15 Dec 2023 12:28:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 F072683FC22; Fri, 15 Dec 2023 17:28:46 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5521E40C6EB9; Fri, 15 Dec 2023 17:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661331; 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=d+XTq629BzkbPeuBBnnPgimuFNQ3B5TACpNFRiiBJE9Nl5uyloyTDYPkzGbD8b7ydhJ2ji ngh0QxKlMWZI1ckaRl6n9mQbyoufqhyLDQNnVEfztPWUsbqZ9rjrg/aPpxDhaXJaVA4RBt e+Du1KhmMxQHEQWvSGLroQ2xDfi85uY= X-MC-Unique: iAB1zuXvPx-d6JIv57cXCA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 07/12] vdpa: set backend capabilities at vhost_vdpa_init Date: Fri, 15 Dec 2023 18:28:25 +0100 Message-Id: <20231215172830.2540987-8-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661400069100009 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 Tested-by: Lei Yang --- 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 19 18:40:20 2025 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=1702661409; cv=none; d=zohomail.com; s=zohoarc; b=MubPQ469xg+IXZ1mrDACa+IHFCqHl2ZRr0bpAVkBddWFQnMrufGhUULKYSJY05uOWOkff0PY8GH4ChkEnuI3jFdxySP5XjQrcfXN5SL+ob4C6mfYNH9zPk6qkEYJ5/mg9Mp8M+WO3N2KQ2YAMylm2VbvIjbxm1uamokmvyxpSpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661409; 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=+BGT/yzYmzJAONhIt/PjwHin02VEjL/ZDy2J/3Z2IoQ=; b=EUKY96k7/J/WOrFb3/n49BNIFMC3tc8uOSTZrD0cUPrZYrKDSRDG+hevtzCo89NGIZD7jzn/ZGzk4cFxxfqwWBkA67Kag/i2xh1RWhLIrmhM7NI8t8h7ILCZ4LN56PYU3c0aD7rymScxjTRcwfmQgTkDgTG/YFCWyN+dfAEDNEw= 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 1702661409566990.4346553331727; Fri, 15 Dec 2023 09:30:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzb-00061x-NR; Fri, 15 Dec 2023 12:28:55 -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 1rEBzZ-000616-Sz for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:53 -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 1rEBzX-000134-NM for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:53 -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-0BZj4Sk_NxaR5dRR7ni-ng-1; Fri, 15 Dec 2023 12:28:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 D670C83DDE0; Fri, 15 Dec 2023 17:28:48 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A5C640C6EB9; Fri, 15 Dec 2023 17:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661330; 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=+BGT/yzYmzJAONhIt/PjwHin02VEjL/ZDy2J/3Z2IoQ=; b=Djt4lI2M3msXhj8L3ElqLrHsHwik+d/EwIsYj2U9tk6cHhGEIeaDPX9f7gwDgEqRnI+Kyc aFqfTeSqy8YGfoFH1Cq5nyHI7pOmxsU/NDuCCGe2CIF7oWtA+rFPYulOe8iccGBkOEPrYs iytjSVsmS/oLmL7c/QHsu0lcttqmksI= X-MC-Unique: 0BZj4Sk_NxaR5dRR7ni-ng-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 08/12] vdpa: add vhost_vdpa_load_setup Date: Fri, 15 Dec 2023 18:28:26 +0100 Message-Id: <20231215172830.2540987-9-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661410128100001 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. 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 next patches use the switchover_ack method to prevent source to stop until all the memory is mapped at the destination. 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. Signed-off-by: Eugenio P=C3=A9rez Tested-by: Lei Yang --- v1: * Moved all the map thread members to another struct than VhostVDPAShared, so its memory and usage can be free from the moment the thread joins. RFC v2: * Use a dedicated thread for map instead of doing all in .load_setup, blocking QMP etc. Other options considered: * ThreadPool: It is hard to keep the order of the requests in this form. To send the worker thread to threadpool is also nice as the number of qemu threads can be controlled that way, but then vhost_vdpa_dev_map and similar cannot know if they are in the worker thread by checking with pthread_self. We can split the dma_map and similar in two functions, one checking if we can offload to thread map and other without it. Synchronization with qemu_thread_join is also lost. A semaphore, QemuEvent, or plain Mutex + Cond would be needed to synchronize list access, complicating the solution. Maps are heavy enough. Using coroutines have the same result. * QIOTask: This is very nice as it does even have the task cleaner to run in the main thread, and I have a model to follow in dns-resolver.c. However, I still need to check if I'm in the main thread or not. To be able to get rid of qemu_thread_is_self, we could create another set of .dma_map_sync, .dma_unmap_sync, etc, and call the (potentially) async versions from the listener or the 100% sure sync version from the map thread. This makes the code more complex in my opinion. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 28 ++++++ hw/virtio/vhost-vdpa.c | 166 ++++++++++++++++++++++++++++++++- 2 files changed, 193 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 8f54e5edd4..b49286b327 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 /* @@ -30,6 +31,12 @@ typedef struct VhostVDPAHostNotifier { void *addr; } VhostVDPAHostNotifier; =20 +typedef struct VhostVDPAMapThread { + QemuThread thread; + GAsyncQueue *queue; + bool map_thread_enabled; +} VhostVDPAMapThread; + /* Info shared by all vhost_vdpa device models */ typedef struct vhost_vdpa_shared { int device_fd; @@ -43,8 +50,27 @@ 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 with BLQ acquired. This forbids + * QEMU to serve other requests like QMP. + * + * To solve it, offload the first listener operations until the first + * listener commit from the main thread. Once these are served, join = the + * map thread. + */ + VhostVDPAMapThread *map_thread; + 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 +99,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..339e11c58a 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -101,6 +101,16 @@ 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 && s->map_thread->map_thread_enabled && + !qemu_thread_is_self(&s->map_thread->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_thread->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 +141,16 @@ 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 && s->map_thread->map_thread_enabled && + !qemu_thread_is_self(&s->map_thread->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_thread->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 +176,16 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVDP= AShared *s) return; } =20 + if (s->map_thread && s->map_thread->map_thread_enabled && + !qemu_thread_is_self(&s->map_thread->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_thread->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 +210,17 @@ 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 && s->map_thread->map_thread_enabled && + !qemu_thread_is_self(&s->map_thread->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_thread->queue, new_msg); + s->map_thread->map_thread_enabled =3D false; + + 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 +1329,88 @@ static void vhost_vdpa_suspend(struct vhost_dev *dev) vhost_vdpa_reset_device(dev); } =20 +static void *vhost_vdpa_load_map_worker(void *opaque) +{ + VhostVDPAShared *shared =3D opaque; + GPtrArray *ret =3D NULL; + + while (true) { + g_autofree struct vhost_msg_v2 *msg =3D NULL; + int r =3D 0; + + msg =3D g_async_queue_pop(shared->map_thread->queue); + 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); + goto end; + default: + error_report("Invalid IOTLB msg type %d", msg->iotlb.type); + break; + }; + + if (unlikely(r !=3D 0)) { + /* Add to failed iotlbs so we can remove it from iova_tree */ + if (ret =3D=3D NULL) { + ret =3D g_ptr_array_new_full(1, g_free); + } + + g_ptr_array_add(ret, g_steal_pointer(&msg)); + } + } + +end: + return ret; +} + +static void vhost_vdpa_spawn_maps_thread(VhostVDPAShared *shared) +{ + shared->map_thread =3D g_new0(VhostVDPAMapThread, 1); + shared->map_thread->queue =3D g_async_queue_new(); + qemu_thread_create(&shared->map_thread->thread, "vdpa map thread", + vhost_vdpa_load_map_worker, shared, + QEMU_THREAD_JOINABLE); + shared->map_thread->map_thread_enabled =3D true; +} + +static bool vhost_vdpa_join_maps_thread(VhostVDPAShared *shared) +{ + g_autoptr(GPtrArray) failed_iova =3D NULL; + + failed_iova =3D qemu_thread_join(&shared->map_thread->thread); + g_async_queue_unref(shared->map_thread->queue); + g_clear_pointer(&shared->map_thread, g_free); + + 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 +1438,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 +1471,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 +1655,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 && !shared->map_thread->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 19 18:40:20 2025 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=1702661427; cv=none; d=zohomail.com; s=zohoarc; b=HwdBveppnRq7B4asUa2hiOAlPwi4ZsFpR+8LQ1gyvcR8YFnMNXqacnDb1TrINQE8pPIkpVJUvyDoeCYi0tqMekK4AK3HDoBlDpkD0R9u6efsWTrQGes2btRLsU1zSoD6ya5oZVscw1mLljcWJm3Z7ZJqZxxs15890E3edFDGp+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661427; 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=djrPUeyzY1LqStlZltfm/nexviMVFCU+NbuO5MY9L4Y=; b=etKI+j6b/eylANlorEWam6eSegIzS+BoARlO8Bwpfj17NOJzS8JN67aH0T03g0G4vU8o4WJthvn02hsPAmn/y6VgCkoNYWfwarYX4TV9SQAdku/n7LuNXSrht6ef1Od0Xdr/Q5GAp35GSHbYV+3nruj3/YLEomtKWSY5kW1Mbe4= 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 1702661427919536.1272164024432; Fri, 15 Dec 2023 09:30:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzc-00062e-Mx; Fri, 15 Dec 2023 12:28:56 -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 1rEBzb-00061a-5L for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:55 -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 1rEBzZ-00013C-87 for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:54 -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-369--UG4hZ1dMem1rT4vxgZeKQ-1; Fri, 15 Dec 2023 12:28:51 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 BDDB33C025C9; Fri, 15 Dec 2023 17:28:50 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2077D40C6EB9; Fri, 15 Dec 2023 17:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661332; 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=djrPUeyzY1LqStlZltfm/nexviMVFCU+NbuO5MY9L4Y=; b=UgOH8oAhh9MVSwERTIgk6nHf74yDcR6IZM4PFG92jQvy5uYMflpIPOekPtKr7VlOrRGu9G gFo322L8oHpduQPq7janNV9M8HTe6uz4Mq2JHJRHj94j3VVuT0DB+VY8gSL6IsclJyx5+T y6T2kjLZ3tWIUlUkfY3hCrCvdB8XMgQ= X-MC-Unique: -UG4hZ1dMem1rT4vxgZeKQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 09/12] vdpa: approve switchover after memory map in the migration destination Date: Fri, 15 Dec 2023 18:28:27 +0100 Message-Id: <20231215172830.2540987-10-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661428205100001 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. The destination can use switchover_ack to prevent source to stop until all the memory is mapped at the destination. Signed-off-by: Eugenio P=C3=A9rez Tested-by: Lei Yang --- include/hw/virtio/vhost-vdpa.h | 4 ++++ hw/virtio/vhost-vdpa.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index b49286b327..1c7e3fbd24 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -34,6 +34,7 @@ typedef struct VhostVDPAHostNotifier { typedef struct VhostVDPAMapThread { QemuThread thread; GAsyncQueue *queue; + QEMUBH *bh; bool map_thread_enabled; } VhostVDPAMapThread; =20 @@ -60,6 +61,9 @@ typedef struct vhost_vdpa_shared { * To solve it, offload the first listener operations until the first * listener commit from the main thread. Once these are served, join = the * map thread. + * + * This map thread is joined by join_map_thread BH if + * migrate_switchover_ack is supported, or by vhost_vdpa_dev_start if = not. */ VhostVDPAMapThread *map_thread; =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 339e11c58a..7d31f4a30e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -22,6 +22,8 @@ #include "hw/virtio/vhost-vdpa.h" #include "exec/address-spaces.h" #include "migration/blocker.h" +#include "migration/options.h" +#include "migration/savevm.h" #include "qemu/cutils.h" #include "qemu/main-loop.h" #include "trace.h" @@ -1372,13 +1374,26 @@ static void *vhost_vdpa_load_map_worker(void *opaqu= e) } =20 end: + if (shared->map_thread->bh) { + qemu_bh_schedule(shared->map_thread->bh); + } + return ret; } =20 +static void vhost_vdpa_load_map_switchover_ack(void *opaque) +{ + qemu_loadvm_approve_switchover(); +} + static void vhost_vdpa_spawn_maps_thread(VhostVDPAShared *shared) { shared->map_thread =3D g_new0(VhostVDPAMapThread, 1); shared->map_thread->queue =3D g_async_queue_new(); + if (migrate_switchover_ack()) { + shared->map_thread->bh =3D qemu_bh_new(vhost_vdpa_load_map_switcho= ver_ack, + NULL); + } qemu_thread_create(&shared->map_thread->thread, "vdpa map thread", vhost_vdpa_load_map_worker, shared, QEMU_THREAD_JOINABLE); @@ -1390,6 +1405,9 @@ static bool vhost_vdpa_join_maps_thread(VhostVDPAShar= ed *shared) g_autoptr(GPtrArray) failed_iova =3D NULL; =20 failed_iova =3D qemu_thread_join(&shared->map_thread->thread); + if (shared->map_thread->bh) { + qemu_bh_delete(shared->map_thread->bh); + } g_async_queue_unref(shared->map_thread->queue); g_clear_pointer(&shared->map_thread, g_free); =20 --=20 2.39.3 From nobody Wed Nov 19 18:40:20 2025 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=1702661396; cv=none; d=zohomail.com; s=zohoarc; b=AV8BPB8FqxinDCxBp50kQm9lpcYOTT5nlGncyy+DGWzcby6hWheBThMOsnt0f+BH2XVSGQNn/uUqcYL1twZ/wCllaHLM8oUT0UlKniT9cQ3aNudxGWNudEMGHVqFydgqUeiYkrS6PvJIQyfPUKaSFddyodtnPnIaKC0t97NYZR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661396; 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=Tqw/FyexJjxhr7V573lIi8oVZJ1Sk7xeFTx0dhtnqn0=; b=W5mUcxhSv204CeFDolR+kfSDOMi6H4GFiE5qWnajdks6na8iz4I4y/cw286QqL227vKp7tYQcvgSQH/Ftue7q8RlJ3A8WgsiGri4jRWJ63zw96nwBLgdEcYgFOSBGT490dXhN7UKpijUkjthWv3ZpYlmlSM2dtez1HBB+dSS3KM= 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 1702661396600660.208423244514; Fri, 15 Dec 2023 09:29:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzf-00063V-9B; Fri, 15 Dec 2023 12:28:59 -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 1rEBze-00062r-CL for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:58 -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 1rEBzc-00013k-Rj for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:28:58 -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-kCfdJIMKOQmr0w2usnM9qA-1; Fri, 15 Dec 2023 12:28:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 A5D92185A783; Fri, 15 Dec 2023 17:28:52 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 096B740C6EB9; Fri, 15 Dec 2023 17:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661336; 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=Tqw/FyexJjxhr7V573lIi8oVZJ1Sk7xeFTx0dhtnqn0=; b=K3LmVmRL/XeDnssO+JiqKV9wGOzGwKHXUs8HebcSd5HTG+E5h5lXAqmFWOyYjE/g16NVlm 1wM2anuogC/8lf1UjAALw39rBO5M3oDo7Os3brwSKjN4yXmIqCPOggr9xsDWgZBjsEJppZ uap530LNQxfOjN31beAvAw7S6CalF18= X-MC-Unique: kCfdJIMKOQmr0w2usnM9qA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 10/12] vdpa: add vhost_vdpa_net_load_setup NetClient callback Date: Fri, 15 Dec 2023 18:28:28 +0100 Message-Id: <20231215172830.2540987-11-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661398159100002 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 Tested-by: Lei Yang --- 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 e11b390466..7d4a99878e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -406,6 +406,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), @@ -418,6 +449,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 19 18:40:20 2025 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=1702661432; cv=none; d=zohomail.com; s=zohoarc; b=koVUiOIeVG25v5TiszSVkMHbtOTSueyhP6JcTIfvrT0C9JJVJzO65BtPbbbwe2HF3gCnjtiFgWIQD43Vhufpa84sTU5y75CUA0zT5rkE0Ga+BOXLw56FMBqF4orJ+t22vULmSS8XSnvrs7pHa/BsW19EuQPNm15qA4SzYm+xOb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661432; 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=7xu9uAi/L9igDhJPMWJIKSWJK94/KRBv9cgJhMWV0nE=; b=LpmnSidqjBCeYaXPPfpNQi5l1luNxaexOeeKI3qSvzQKiR2dMuLpy2+WuRC5oVVj9XEul6yDjH8X8aJ75THnyBemy1M0yQAcu4+ySbFOi4b+NVOOZB8IrF+orRA6DVa8tfcDjZ0GGfBU5LT1VrAom3HEdoxhUgCgPtSwgk6wytQ= 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 1702661432128805.3025025943681; Fri, 15 Dec 2023 09:30:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzh-00064I-F6; Fri, 15 Dec 2023 12:29:01 -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 1rEBzg-00063r-Ag for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:29:00 -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 1rEBze-00013z-TO for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:29:00 -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-352-rqjG7ErbML66UvTNPqbMkg-1; Fri, 15 Dec 2023 12:28:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 8CEE585A58B; Fri, 15 Dec 2023 17:28:54 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id E554040C6EB9; Fri, 15 Dec 2023 17:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661338; 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=7xu9uAi/L9igDhJPMWJIKSWJK94/KRBv9cgJhMWV0nE=; b=KvPPDGjPy7tXyeSPTWQpfaC/CvfpDQRtLFyakvzXERieGr+CDaCed63zkf38vM3FVA6w4y eiOOJxw2SDY2JCqU8YLdkiwqN384zDmkg9qmTz4AwGz8qmzZlIX4GuehFQ8MQ43Z9PFnkZ Y+JFWjZYWAAq48KAXOb6bCDTwdnp1F4= X-MC-Unique: rqjG7ErbML66UvTNPqbMkg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 11/12] vdpa: add vhost_vdpa_net_switchover_ack_needed Date: Fri, 15 Dec 2023 18:28:29 +0100 Message-Id: <20231215172830.2540987-12-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661434212100003 Use migration switchover ack capability to make sure QEMU has mapped all the guest memory to the device before the source stops the VM and attempts to complete the migration. All net vdpa devices support this early map of guest memory, so return always true. Signed-off-by: Eugenio P=C3=A9rez Tested-by: Lei Yang --- include/net/net.h | 2 ++ net/vhost-vdpa.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 68282dde31..f8c65dcb86 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -73,6 +73,7 @@ typedef bool (NetCheckPeerType)(NetClientState *, ObjectC= lass *, 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 *); +typedef bool (NetMigrationSwichoverAckNeeded)(const NetClientState *); =20 typedef struct NetClientInfo { NetClientDriver type; @@ -104,6 +105,7 @@ typedef struct NetClientInfo { NetCheckPeerType *check_peer_type; NetMigrationLoadSetup *load_setup; NetMigrationLoadCleanup *load_cleanup; + NetMigrationSwichoverAckNeeded *load_switchover_ack_needed; } NetClientInfo; =20 struct NetClientState { diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 7d4a99878e..9aa958c4f1 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -437,12 +437,18 @@ static int vhost_vdpa_net_load_cleanup(NetClientState= *nc, NICState *nic) n->parent_obj.status & VIRTIO_CONFIG_S_DRIVER= _OK); } =20 +static bool vhost_vdpa_net_switchover_ack_needed(const NetClientState *nc) +{ + return true; +} + static NetClientInfo net_vhost_vdpa_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), .receive =3D vhost_vdpa_receive, .start =3D vhost_vdpa_net_data_start, .load =3D vhost_vdpa_net_data_load, + .load_switchover_ack_needed =3D vhost_vdpa_net_switchover_ack_need= ed, .stop =3D vhost_vdpa_net_client_stop, .cleanup =3D vhost_vdpa_cleanup, .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, --=20 2.39.3 From nobody Wed Nov 19 18:40:20 2025 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=1702661411; cv=none; d=zohomail.com; s=zohoarc; b=bOESkHvX2Nuak0azEyElDdOMqGxK/PYcCRC0Dt1tnNF50LX0YJHAmDCz3VwMJ2JtmiTDNpoFfabsc3gCm0fouKY5uOmAMrcQKJBEKnRXv18ttg1qp+07csrYUqjBNBfsNdtadXkF/aNaPMPm1BwnCGRt6NS02ehvLFbi/b3mBzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702661411; 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=EIWPeVAlaPMcGC2YIJQ/xPJo8d7uzO//v4TacCwmalQ=; b=KiLLVtjMDv9bh57uTi5sUhWUU3BKgvW+FN4fxtAZjrd+nXUxfNS4gGMuAYY1zDl8GIm+COyJan2SOnHJcPuUiP1675lejpDqle+ERXyw110zttdDs4Hmt7oIrMRfYzc6T7SukMSM960iaMGpKC+KkzgS12IqyoB5BkhuDvxTIic= 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 17026614119511016.6426727477154; Fri, 15 Dec 2023 09:30:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEBzm-00064h-TX; Fri, 15 Dec 2023 12:29:06 -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 1rEBzl-00064O-L7 for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:29:05 -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 1rEBzk-00015y-3c for qemu-devel@nongnu.org; Fri, 15 Dec 2023 12:29:05 -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-463-6FuzGQL8O9qQNEYcs8uQ7A-1; Fri, 15 Dec 2023 12:28:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 72A6A83DDE2; Fri, 15 Dec 2023 17:28:56 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBF7A40C6EB9; Fri, 15 Dec 2023 17:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702661342; 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=EIWPeVAlaPMcGC2YIJQ/xPJo8d7uzO//v4TacCwmalQ=; b=IOs00WzeOlgsT7b5oLTGzwZ3NvlagXzleycgmLSP7JcNh7c40r0e3YT2L9uZoM1BlDicko CRYLGQP02KFMU7MOGVpJ96dM+apphzj1uKrRAIZHspokCgTI52GX9ObwojpHkZ/G9MctLU ileq9Gs9taXbGfbcbap6p33YnCdPz+0= X-MC-Unique: 6FuzGQL8O9qQNEYcs8uQ7A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , si-wei.liu@oracle.com, Lei Yang , Jason Wang , Dragos Tatulea , Zhu Lingshan , Parav Pandit , Stefano Garzarella , Laurent Vivier Subject: [PATCH for 9.0 12/12] virtio_net: register incremental migration handlers Date: Fri, 15 Dec 2023 18:28:30 +0100 Message-Id: <20231215172830.2540987-13-eperezma@redhat.com> In-Reply-To: <20231215172830.2540987-1-eperezma@redhat.com> References: <20231215172830.2540987-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.2 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: 1702661414130100003 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 Tested-by: Lei Yang --- 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 | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 80c56f0cfc..7dd08c98b6 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,52 @@ 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_queue(n->nic); + + if (nc->peer && 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_queue(n->nic); + + if (nc->peer && nc->peer->info->load_cleanup) { + return nc->peer->info->load_cleanup(nc->peer, n->nic); + } + + return 0; +} + +static bool virtio_net_switchover_ack_needed(void *opaque) +{ + VirtIONet *n =3D opaque; + NetClientState *nc =3D qemu_get_queue(n->nic); + + if (nc->peer && nc->peer->info->load_switchover_ack_needed) { + return nc->peer->info->load_switchover_ack_needed(nc->peer); + } + + return false; +} + +static const SaveVMHandlers savevm_virtio_net_handlers =3D { + .load_setup =3D virtio_net_load_setup, + .load_cleanup =3D virtio_net_load_cleanup, + .switchover_ack_needed =3D virtio_net_switchover_ack_needed, +}; + 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 +3868,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