From patchwork Fri Nov 20 18:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404034 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R4QjhXmk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5K526D9z9sVZ for ; Sat, 21 Nov 2020 05:52:57 +1100 (AEDT) Received: from localhost ([::1]:58742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBWa-00047I-SR for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 13:52:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBVl-00045U-O7 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:51:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35261) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBVZ-0006sY-Cz for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:51:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898295; 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=VF68uyWFilZpHj5bABsThH0akvfjRoVBR9ksieJzwHo=; b=R4QjhXmk3NTOZ5E1hI4nQ0rI7jo+E6TZDmhwBc7LGnGJJz9wQv6riO0NWMERY7lW305SUH CxERRyiEF9wEiuuPh4eeZp2uR7GzwzhqCZxLXGiQ0Meau3DF9tKKZKx+W8Z9LTlOl3JqF0 mq/+Ia3EyAH2be5pGfwUXgHEh1wBZ8k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-125-5oC7RBGnOfe3nRKgW98M6A-1; Fri, 20 Nov 2020 13:51:33 -0500 X-MC-Unique: 5oC7RBGnOfe3nRKgW98M6A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2F0E1842159; Fri, 20 Nov 2020 18:51:30 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 440965C1D5; Fri, 20 Nov 2020 18:51:23 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 01/27] vhost: Add vhost_dev_can_log Date: Fri, 20 Nov 2020 19:50:39 +0100 Message-Id: <20201120185105.279030-2-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Just syntactic sugar. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 614ccc2bcb..2bd8cdf893 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -61,6 +61,11 @@ bool vhost_has_free_slot(void) return slots_limit > used_memslots; } +static bool vhost_dev_can_log(const struct vhost_dev *hdev) +{ + return hdev->features & (0x1ULL << VHOST_F_LOG_ALL); +} + static void vhost_dev_sync_region(struct vhost_dev *dev, MemoryRegionSection *section, uint64_t mfirst, uint64_t mlast, @@ -1347,7 +1352,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, }; if (hdev->migration_blocker == NULL) { - if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) { + if (!vhost_dev_can_log(hdev)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_check()) { From patchwork Fri Nov 20 18:50:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PwIRLYwr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5Y60m2Cz9sTR for ; Sat, 21 Nov 2020 06:03:22 +1100 (AEDT) Received: from localhost ([::1]:55584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBgl-0006MW-VZ for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:03:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBVo-000478-D4 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBVk-0006vi-Vk for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898310; 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=hB04k6BmQFwa3NAoUh0c6SZfxRFuR9AWa1v2aVbfxk4=; b=PwIRLYwrvqHT4UyXpKM8/TF5+veSWLwJUFRKifbdWDurUZQJ079MvHlYSUhvxknQANYIpx n8ByMmt5LXYNX6psf25QvY7+OTIilLtQSLwJDfWbJsIwW6p2oQgGEf5919VSH/nARVIIuw tzWSiorBEwXXy7CxTJNughv07hRz3Ko= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-ZCnzaR28NEuQleuWtg2vfQ-1; Fri, 20 Nov 2020 13:51:46 -0500 X-MC-Unique: ZCnzaR28NEuQleuWtg2vfQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 671DD1842159; Fri, 20 Nov 2020 18:51:43 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26B075C1D5; Fri, 20 Nov 2020 18:51:30 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 02/27] vhost: Add device callback in vhost_migration_log Date: Fri, 20 Nov 2020 19:50:40 +0100 Message-Id: <20201120185105.279030-3-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This allows code to reuse the logic to not to re-enable or re-disable migration mechanisms. Code works the same way as before. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 2bd8cdf893..2adb2718c1 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -862,7 +862,9 @@ err_features: return r; } -static int vhost_migration_log(MemoryListener *listener, bool enable) +static int vhost_migration_log(MemoryListener *listener, + bool enable, + int (*device_cb)(struct vhost_dev *, bool)) { struct vhost_dev *dev = container_of(listener, struct vhost_dev, memory_listener); @@ -877,14 +879,14 @@ static int vhost_migration_log(MemoryListener *listener, bool enable) r = 0; if (!enable) { - r = vhost_dev_set_log(dev, false); + r = device_cb(dev, false); if (r < 0) { goto check_dev_state; } vhost_log_put(dev, false); } else { vhost_dev_log_resize(dev, vhost_get_log_size(dev)); - r = vhost_dev_set_log(dev, true); + r = device_cb(dev, true); if (r < 0) { goto check_dev_state; } @@ -916,7 +918,7 @@ static void vhost_log_global_start(MemoryListener *listener) { int r; - r = vhost_migration_log(listener, true); + r = vhost_migration_log(listener, true, vhost_dev_set_log); if (r < 0) { abort(); } @@ -926,7 +928,7 @@ static void vhost_log_global_stop(MemoryListener *listener) { int r; - r = vhost_migration_log(listener, false); + r = vhost_migration_log(listener, false, vhost_dev_set_log); if (r < 0) { abort(); } From patchwork Fri Nov 20 18:50:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TnUoj5tl; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5KH5Xchz9sVY for ; Sat, 21 Nov 2020 05:53:07 +1100 (AEDT) Received: from localhost ([::1]:58806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBWr-00049J-JI for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 13:53:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBVp-00048L-8u for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBVn-0006wv-B7 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898318; 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=4varrbTkFQFU3BGiSDv77OV+Am6FgvunCFxXqhYibgk=; b=TnUoj5tlsNT0shyl+zdVVBGZ/18D3iyeTOEN8LWCVhHzNSHp8id6wWT0zq73779kJ3AkPZ oemY6TirrHp4RV97AAtIy187A48jnRsZ1WW/ABNyNQU1SG7vdTgmW27QtsjVx7HDNgQYb0 KhzHcyp04YOHLZuvuVYfuj6ezyyuT+o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-icKHBA9mMzOymkuJgqFU_Q-1; Fri, 20 Nov 2020 13:51:55 -0500 X-MC-Unique: icKHBA9mMzOymkuJgqFU_Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA084107AD30; Fri, 20 Nov 2020 18:51:52 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B5435C1D5; Fri, 20 Nov 2020 18:51:43 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 03/27] vhost: Move log resize/put to vhost_dev_set_log Date: Fri, 20 Nov 2020 19:50:41 +0100 Message-Id: <20201120185105.279030-4-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Software assisted live migration does not allocate vhost log. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 2adb2718c1..9cbd52a7f1 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -828,6 +828,10 @@ static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) int r, i, idx; hwaddr addr; + if (enable_log) { + vhost_dev_log_resize(dev, vhost_get_log_size(dev)); + } + r = vhost_dev_set_features(dev, enable_log); if (r < 0) { goto err_features; @@ -850,6 +854,10 @@ static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) goto err_vq; } } + + if (!enable_log) { + vhost_log_put(dev, false); + } return 0; err_vq: for (; i >= 0; --i) { @@ -877,22 +885,8 @@ static int vhost_migration_log(MemoryListener *listener, return 0; } - r = 0; - if (!enable) { - r = device_cb(dev, false); - if (r < 0) { - goto check_dev_state; - } - vhost_log_put(dev, false); - } else { - vhost_dev_log_resize(dev, vhost_get_log_size(dev)); - r = device_cb(dev, true); - if (r < 0) { - goto check_dev_state; - } - } + r = device_cb(dev, enable); -check_dev_state: dev->log_enabled = enable; /* * vhost-user-* devices could change their state during log From patchwork Fri Nov 20 18:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404037 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g54XMXCC; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5PK1nT0z9sVH for ; Sat, 21 Nov 2020 05:56:37 +1100 (AEDT) Received: from localhost ([::1]:37554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBaF-00077l-3L for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 13:56:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBW6-0004Pd-1q for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34998) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBW4-00070H-AT for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898335; 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=f1xuNkaaPUcrhHGAqp8H+FXDGPjhfJDXls907UFvbJo=; b=g54XMXCCRdOh7wxzq8edRmtDXM/MfH/UxkG1FkPv+qHs3qMX+qVCkqfcL3ZedSEHnHmi2l RopbTdT5fFDH++GYZjotreCCN4ULRN023dNRp5fS3MVtulYLqt/oSZrorl9HgO/JRLAh3p THEq89Jrqgl+qJ1x1y9b4HGRT2e57c4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-BqEhkUiMPp2_cG8WPQgPOg-1; Fri, 20 Nov 2020 13:52:13 -0500 X-MC-Unique: BqEhkUiMPp2_cG8WPQgPOg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38DCE8030BC; Fri, 20 Nov 2020 18:52:10 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DEE05C1D5; Fri, 20 Nov 2020 18:51:52 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 04/27] vhost: add vhost_kernel_set_vring_enable Date: Fri, 20 Nov 2020 19:50:42 +0100 Message-Id: <20201120185105.279030-5-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-backend.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 222bbcc62d..317f1f96fa 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -201,6 +201,34 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx) return idx - dev->vq_index; } +static int vhost_kernel_set_vq_enable(struct vhost_dev *dev, unsigned idx, + bool enable) +{ + struct vhost_vring_file file = { + .index = idx, + }; + + if (!enable) { + file.fd = -1; /* Pass -1 to unbind from file. */ + } else { + struct vhost_net *vn_dev = container_of(dev, struct vhost_net, dev); + file.fd = vn_dev->backend; + } + + return vhost_kernel_net_set_backend(dev, &file); +} + +static int vhost_kernel_set_vring_enable(struct vhost_dev *dev, int enable) +{ + int i; + + for (i = 0; i < dev->nvqs; ++i) { + vhost_kernel_set_vq_enable(dev, i, enable); + } + + return 0; +} + #ifdef CONFIG_VHOST_VSOCK static int vhost_kernel_vsock_set_guest_cid(struct vhost_dev *dev, uint64_t guest_cid) @@ -317,6 +345,7 @@ static const VhostOps kernel_ops = { .vhost_set_owner = vhost_kernel_set_owner, .vhost_reset_device = vhost_kernel_reset_device, .vhost_get_vq_index = vhost_kernel_get_vq_index, + .vhost_set_vring_enable = vhost_kernel_set_vring_enable, #ifdef CONFIG_VHOST_VSOCK .vhost_vsock_set_guest_cid = vhost_kernel_vsock_set_guest_cid, .vhost_vsock_set_running = vhost_kernel_vsock_set_running, From patchwork Fri Nov 20 18:50:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SCiB1HEk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5PH726Yz9sTR for ; Sat, 21 Nov 2020 05:56:35 +1100 (AEDT) Received: from localhost ([::1]:37396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBaD-00073X-1v for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 13:56:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBWE-0004Ud-4T for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBWC-00071S-6A for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898341; 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=FBKfLERfSf5dIrOoBodiDDSFxkynaDNC4JNMEvaUCDk=; b=SCiB1HEka9YFy0+h+PBOK8XD5eWwyPmcFGaPN4Nb18MFGJwsyVwLFc1aM6Kp8rRBA2xxt9 Z6X0BdxyiQ2WDtsj4HhbY3trcbKBvnrzWcLDaUwArLqh0jclOIAat7hGYw7QuUalkyK079 EtE5yiVvlJiJuEvD3TCR/42B/dY1SJI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-DQLDp4S1P1eb-cRn3OpcPw-1; Fri, 20 Nov 2020 13:52:19 -0500 X-MC-Unique: DQLDp4S1P1eb-cRn3OpcPw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A853E814418; Fri, 20 Nov 2020 18:52:16 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90D515C1D5; Fri, 20 Nov 2020 18:52:10 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 05/27] vhost: Add hdev->dev.sw_lm_vq_handler Date: Fri, 20 Nov 2020 19:50:43 +0100 Message-Id: <20201120185105.279030-6-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Only virtio-net honors it. Signed-off-by: Eugenio Pérez --- include/hw/virtio/vhost.h | 1 + hw/net/virtio-net.c | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4a8bc75415..b5b7496537 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -83,6 +83,7 @@ struct vhost_dev { bool started; bool log_enabled; uint64_t log_size; + VirtIOHandleOutput sw_lm_vq_handler; Error *migration_blocker; const VhostOps *vhost_ops; void *opaque; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9179013ac4..9a69ae3598 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2628,24 +2628,32 @@ static void virtio_net_tx_bh(void *opaque) } } -static void virtio_net_add_queue(VirtIONet *n, int index) +static void virtio_net_add_queue(VirtIONet *n, int index, + VirtIOHandleOutput custom_handler) { VirtIODevice *vdev = VIRTIO_DEVICE(n); + VirtIOHandleOutput rx_vq_handler = virtio_net_handle_rx; + VirtIOHandleOutput tx_vq_handler; + bool tx_timer = n->net_conf.tx && !strcmp(n->net_conf.tx, "timer"); + + if (custom_handler) { + rx_vq_handler = tx_vq_handler = custom_handler; + } else if (tx_timer) { + tx_vq_handler = virtio_net_handle_tx_timer; + } else { + tx_vq_handler = virtio_net_handle_tx_bh; + } n->vqs[index].rx_vq = virtio_add_queue(vdev, n->net_conf.rx_queue_size, - virtio_net_handle_rx); + rx_vq_handler); + n->vqs[index].tx_vq = virtio_add_queue(vdev, n->net_conf.tx_queue_size, + tx_vq_handler); - if (n->net_conf.tx && !strcmp(n->net_conf.tx, "timer")) { - n->vqs[index].tx_vq = - virtio_add_queue(vdev, n->net_conf.tx_queue_size, - virtio_net_handle_tx_timer); + if (tx_timer) { n->vqs[index].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, virtio_net_tx_timer, &n->vqs[index]); } else { - n->vqs[index].tx_vq = - virtio_add_queue(vdev, n->net_conf.tx_queue_size, - virtio_net_handle_tx_bh); n->vqs[index].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[index]); } @@ -2677,6 +2685,10 @@ static void virtio_net_del_queue(VirtIONet *n, int index) static void virtio_net_change_num_queues(VirtIONet *n, int new_max_queues) { VirtIODevice *vdev = VIRTIO_DEVICE(n); + NetClientState *nc = n->nic->conf->peers.ncs[0]; + struct vhost_net *hdev = get_vhost_net(nc); + VirtIOHandleOutput custom_handler = hdev ? hdev->dev.sw_lm_vq_handler + : NULL; int old_num_queues = virtio_get_num_queues(vdev); int new_num_queues = new_max_queues * 2 + 1; int i; @@ -2702,7 +2714,7 @@ static void virtio_net_change_num_queues(VirtIONet *n, int new_max_queues) for (i = old_num_queues - 1; i < new_num_queues - 1; i += 2) { /* new_num_queues > old_num_queues */ - virtio_net_add_queue(n, i / 2); + virtio_net_add_queue(n, i / 2, custom_handler); } /* add ctrl_vq last */ @@ -3256,6 +3268,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIONet *n = VIRTIO_NET(dev); NetClientState *nc; + struct vhost_net *hdev; + VirtIOHandleOutput custom_handler; int i; if (n->net_conf.mtu) { @@ -3347,8 +3361,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->net_conf.tx_queue_size = MIN(virtio_net_max_tx_queue_size(n), n->net_conf.tx_queue_size); + nc = n->nic_conf.peers.ncs[0]; + hdev = get_vhost_net(nc); + custom_handler = hdev ? hdev->dev.sw_lm_vq_handler : NULL; for (i = 0; i < n->max_queues; i++) { - virtio_net_add_queue(n, i); + virtio_net_add_queue(n, i, custom_handler); } n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl); From patchwork Fri Nov 20 18:50:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=chx1PoKw; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5TJ708Vz9sVH for ; Sat, 21 Nov 2020 06:00:04 +1100 (AEDT) Received: from localhost ([::1]:45864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBda-0002Fo-Ot for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:00:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBWS-0004gd-Do for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46239) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBWP-00078J-Vd for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:52:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898357; 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=Y17EVO/s0xg6tqcxCWG6nhFINdKj1LKpomp8rmt7L8A=; b=chx1PoKwHguedkukAvHrJivJv5Rwt98XLRA7ctOf0oCdpiyw+5LJEWeRcupj1lWtbT33uY AjHibdD8AZ68VGkEk4w2ag518WA7S+Zwd7poqC6n1gnGIRiWSssaVR/2OEJAqXoAOPG3U+ aDY8Jcv/ogccym8TEi93Bq4joN3SJL0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-H2Z1tymUMiSbaQlXOnSUjA-1; Fri, 20 Nov 2020 13:52:35 -0500 X-MC-Unique: H2Z1tymUMiSbaQlXOnSUjA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7889F8144EC; Fri, 20 Nov 2020 18:52:32 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C9F25C1D5; Fri, 20 Nov 2020 18:52:16 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 06/27] virtio: Add virtio_queue_get_used_notify_split Date: Fri, 20 Nov 2020 19:50:44 +0100 Message-Id: <20201120185105.279030-7-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This function is just used for a few commits, so SW LM is developed incrementally, and it is deleted after it is useful. For a few commits, only the events (irqfd, eventfd) are forwarded. This series adds descriptors forwarding on top of that. Signed-off-by: Eugenio Pérez --- include/hw/virtio/virtio.h | 1 + hw/virtio/virtio.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b7ece7a6a8..b9b8497ea0 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -225,6 +225,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id); void virtio_notify_config(VirtIODevice *vdev); +bool virtio_queue_get_used_notify_split(VirtQueue *vq); bool virtio_queue_get_notification(VirtQueue *vq); void virtio_queue_set_notification(VirtQueue *vq, int enable); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ceb58fda6c..3469946538 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -377,6 +377,20 @@ static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val) vq->used_idx = val; } +bool virtio_queue_get_used_notify_split(VirtQueue *vq) +{ + VRingMemoryRegionCaches *caches; + hwaddr pa = offsetof(VRingUsed, flags); + uint16_t flags; + + RCU_READ_LOCK_GUARD(); + + caches = vring_get_region_caches(vq); + assert(caches); + flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); + return !(VRING_USED_F_NO_NOTIFY & flags); +} + /* Called within rcu_read_lock(). */ static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask) { From patchwork Fri Nov 20 18:50:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=alqDTXGf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5Xr6gDcz9sTR for ; Sat, 21 Nov 2020 06:03:08 +1100 (AEDT) Received: from localhost ([::1]:54300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBgY-0005q0-Oi for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:03:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBWr-00050M-7r for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBWh-0007Cn-0f for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898374; 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=PHs7w9gRWn5Mh5hB2N7v2usauab9QEU61xYfrhNJnDI=; b=alqDTXGfrJTpNAPLNvDSicdLpX/hRZXQhDf46ZOg4dRtIngwveUWDTHWMcxEgSX0z9MSAr pfp+fMd/a/sWe3wUu4J0GwKHZionJ1gR3e9GAub1jx9ih+tQ5dracp0FB2yMbqTBCvgBx9 PqJ50GO99si1geZxZSPsV96jcCLR6O4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-GxLlklPmNPC1LNXpQGTGGQ-1; Fri, 20 Nov 2020 13:52:51 -0500 X-MC-Unique: GxLlklPmNPC1LNXpQGTGGQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5249C5B36A; Fri, 20 Nov 2020 18:52:48 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1B785C1D5; Fri, 20 Nov 2020 18:52:32 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 07/27] vhost: Route guest->host notification through qemu Date: Fri, 20 Nov 2020 19:50:45 +0100 Message-Id: <20201120185105.279030-8-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.h | 26 +++++++++ include/hw/virtio/vhost.h | 3 ++ hw/virtio/vhost-sw-lm-ring.c | 60 +++++++++++++++++++++ hw/virtio/vhost.c | 100 +++++++++++++++++++++++++++++++++-- hw/virtio/meson.build | 2 +- 5 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 hw/virtio/vhost-sw-lm-ring.h create mode 100644 hw/virtio/vhost-sw-lm-ring.c diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h new file mode 100644 index 0000000000..86dc081b93 --- /dev/null +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -0,0 +1,26 @@ +/* + * vhost software live migration ring + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2020 + * SPDX-FileContributor: Author: Eugenio Pérez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef VHOST_SW_LM_RING_H +#define VHOST_SW_LM_RING_H + +#include "qemu/osdep.h" + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" + +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + +bool vhost_vring_kick(VhostShadowVirtqueue *vq); + +VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx); + +void vhost_sw_lm_shadow_vq_free(VhostShadowVirtqueue *vq); + +#endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index b5b7496537..93cc3f1ae3 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -54,6 +54,8 @@ struct vhost_iommu { QLIST_ENTRY(vhost_iommu) iommu_next; }; +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + typedef struct VhostDevConfigOps { /* Vhost device config space changed callback */ @@ -83,6 +85,7 @@ struct vhost_dev { bool started; bool log_enabled; uint64_t log_size; + VhostShadowVirtqueue *sw_lm_shadow_vq[2]; VirtIOHandleOutput sw_lm_vq_handler; Error *migration_blocker; const VhostOps *vhost_ops; diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c new file mode 100644 index 0000000000..0192e77831 --- /dev/null +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -0,0 +1,60 @@ +/* + * vhost software live migration ring + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2020 + * SPDX-FileContributor: Author: Eugenio Pérez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "hw/virtio/vhost-sw-lm-ring.h" +#include "hw/virtio/vhost.h" + +#include "standard-headers/linux/vhost_types.h" +#include "standard-headers/linux/virtio_ring.h" + +#include "qemu/event_notifier.h" + +typedef struct VhostShadowVirtqueue { + EventNotifier hdev_notifier; + VirtQueue *vq; +} VhostShadowVirtqueue; + +static inline bool vhost_vring_should_kick(VhostShadowVirtqueue *vq) +{ + return virtio_queue_get_used_notify_split(vq->vq); +} + +bool vhost_vring_kick(VhostShadowVirtqueue *vq) +{ + return vhost_vring_should_kick(vq) ? event_notifier_set(&vq->hdev_notifier) + : true; +} + +VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) +{ + struct vhost_vring_file file = { + .index = idx + }; + VirtQueue *vq = virtio_get_queue(dev->vdev, idx); + VhostShadowVirtqueue *svq; + int r; + + svq = g_new0(VhostShadowVirtqueue, 1); + svq->vq = vq; + + r = event_notifier_init(&svq->hdev_notifier, 0); + assert(r == 0); + + file.fd = event_notifier_get_fd(&svq->hdev_notifier); + r = dev->vhost_ops->vhost_set_vring_kick(dev, &file); + assert(r == 0); + + return svq; +} + +void vhost_sw_lm_shadow_vq_free(VhostShadowVirtqueue *vq) +{ + event_notifier_cleanup(&vq->hdev_notifier); + g_free(vq); +} diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9cbd52a7f1..a55b684b5f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -13,6 +13,8 @@ * GNU GPL, version 2 or (at your option) any later version. */ +#include "hw/virtio/vhost-sw-lm-ring.h" + #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/virtio/vhost.h" @@ -61,6 +63,20 @@ bool vhost_has_free_slot(void) return slots_limit > used_memslots; } +static struct vhost_dev *vhost_dev_from_virtio(const VirtIODevice *vdev) +{ + struct vhost_dev *hdev; + + QLIST_FOREACH(hdev, &vhost_devices, entry) { + if (hdev->vdev == vdev) { + return hdev; + } + } + + assert(hdev); + return NULL; +} + static bool vhost_dev_can_log(const struct vhost_dev *hdev) { return hdev->features & (0x1ULL << VHOST_F_LOG_ALL); @@ -148,6 +164,12 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *dev, return 0; } +static void vhost_log_sync_nop(MemoryListener *listener, + MemoryRegionSection *section) +{ + return; +} + static void vhost_log_sync(MemoryListener *listener, MemoryRegionSection *section) { @@ -928,6 +950,71 @@ static void vhost_log_global_stop(MemoryListener *listener) } } +static void handle_sw_lm_vq(VirtIODevice *vdev, VirtQueue *vq) +{ + struct vhost_dev *hdev = vhost_dev_from_virtio(vdev); + uint16_t idx = virtio_get_queue_index(vq); + + VhostShadowVirtqueue *svq = hdev->sw_lm_shadow_vq[idx]; + + vhost_vring_kick(svq); +} + +static int vhost_sw_live_migration_stop(struct vhost_dev *dev) +{ + int idx; + + vhost_dev_enable_notifiers(dev, dev->vdev); + for (idx = 0; idx < dev->nvqs; ++idx) { + vhost_sw_lm_shadow_vq_free(dev->sw_lm_shadow_vq[idx]); + } + + return 0; +} + +static int vhost_sw_live_migration_start(struct vhost_dev *dev) +{ + int idx; + + for (idx = 0; idx < dev->nvqs; ++idx) { + dev->sw_lm_shadow_vq[idx] = vhost_sw_lm_shadow_vq(dev, idx); + } + + vhost_dev_disable_notifiers(dev, dev->vdev); + + return 0; +} + +static int vhost_sw_live_migration_enable(struct vhost_dev *dev, + bool enable_lm) +{ + if (enable_lm) { + return vhost_sw_live_migration_start(dev); + } else { + return vhost_sw_live_migration_stop(dev); + } +} + +static void vhost_sw_lm_global_start(MemoryListener *listener) +{ + int r; + + r = vhost_migration_log(listener, true, vhost_sw_live_migration_enable); + if (r < 0) { + abort(); + } +} + +static void vhost_sw_lm_global_stop(MemoryListener *listener) +{ + int r; + + r = vhost_migration_log(listener, false, vhost_sw_live_migration_enable); + if (r < 0) { + abort(); + } +} + static void vhost_log_start(MemoryListener *listener, MemoryRegionSection *section, int old, int new) @@ -1334,9 +1421,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, .region_nop = vhost_region_addnop, .log_start = vhost_log_start, .log_stop = vhost_log_stop, - .log_sync = vhost_log_sync, - .log_global_start = vhost_log_global_start, - .log_global_stop = vhost_log_global_stop, + .log_sync = !vhost_dev_can_log(hdev) ? + vhost_log_sync_nop : + vhost_log_sync, + .log_global_start = !vhost_dev_can_log(hdev) ? + vhost_sw_lm_global_start : + vhost_log_global_start, + .log_global_stop = !vhost_dev_can_log(hdev) ? vhost_sw_lm_global_stop : + vhost_log_global_stop, .eventfd_add = vhost_eventfd_add, .eventfd_del = vhost_eventfd_del, .priority = 10 @@ -1364,6 +1456,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, error_free(hdev->migration_blocker); goto fail_busyloop; } + } else { + hdev->sw_lm_vq_handler = handle_sw_lm_vq; } hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions)); diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index fbff9bc9d4..17419cb13e 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-sw-lm-ring.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c')) From patchwork Fri Nov 20 18:50:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=X0UqFWHt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5fb744Hz9s0b for ; Sat, 21 Nov 2020 06:08:07 +1100 (AEDT) Received: from localhost ([::1]:35850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBlN-0001c6-OB for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:08:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBX9-0005Ku-HW for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35708) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBWz-0007Gz-HC for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898392; 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=Qu8CTJiydQcChlxQWTNmkAEwFHT33IJLluEvEtsX/ss=; b=X0UqFWHt5Y5UpnjR+b0lXwVdmCbdlm94xDVTuttICwnEHuseS3etSoJRxZ0qMMX/nhUPHG V9qfpmvprls5onSjJ+PajPwGl9lprPgYuz3aRhAnmIrBQ021BJr12pNFcPNN81eoYnZXDY MHxjGMuW9MyO5B31HkrAlvmwBtk1paA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-458-_JNmgddUNyaRjjXM5pQgFA-1; Fri, 20 Nov 2020 13:53:10 -0500 X-MC-Unique: _JNmgddUNyaRjjXM5pQgFA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10C3C8797E8; Fri, 20 Nov 2020 18:53:08 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAD965C1D5; Fri, 20 Nov 2020 18:52:48 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 08/27] vhost: Add a flag for software assisted Live Migration Date: Fri, 20 Nov 2020 19:50:46 +0100 Message-Id: <20201120185105.279030-9-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- include/hw/virtio/vhost.h | 1 + hw/virtio/vhost.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 93cc3f1ae3..ef920a8076 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -84,6 +84,7 @@ struct vhost_dev { uint64_t backend_cap; bool started; bool log_enabled; + bool sw_lm_enabled; uint64_t log_size; VhostShadowVirtqueue *sw_lm_shadow_vq[2]; VirtIOHandleOutput sw_lm_vq_handler; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a55b684b5f..1d55e26d45 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -988,11 +988,16 @@ static int vhost_sw_live_migration_start(struct vhost_dev *dev) static int vhost_sw_live_migration_enable(struct vhost_dev *dev, bool enable_lm) { + int r; + if (enable_lm) { - return vhost_sw_live_migration_start(dev); + r = vhost_sw_live_migration_start(dev); } else { - return vhost_sw_live_migration_stop(dev); + r = vhost_sw_live_migration_stop(dev); } + + dev->sw_lm_enabled = enable_lm; + return r; } static void vhost_sw_lm_global_start(MemoryListener *listener) @@ -1466,6 +1471,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, hdev->log = NULL; hdev->log_size = 0; hdev->log_enabled = false; + hdev->sw_lm_enabled = false; hdev->started = false; memory_listener_register(&hdev->memory_listener, &address_space_memory); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); @@ -1571,6 +1577,13 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); int i, r; + if (hdev->sw_lm_enabled) { + /* We've been called after migration is completed, so no need to + disable it again + */ + return; + } + for (i = 0; i < hdev->nvqs; ++i) { r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i, false); From patchwork Fri Nov 20 18:50:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ee8D6rCE; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5fH2lLzz9s0b for ; Sat, 21 Nov 2020 06:07:51 +1100 (AEDT) Received: from localhost ([::1]:34710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBl7-00017N-2e for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:07:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBXP-0005P7-2r for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBXK-0007LJ-UH for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898412; 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=u/Ojn4cpi7xAVMskNFT0feT7MkBDEW4NMg9WWPtVNhY=; b=ee8D6rCEOQJnungZiScW+nZ8NWam0KBxqbj8e9H5gFlvVZYB91Vjcawm+DMunipMmS3caQ R1mqqf1DH8YfDuY2Xbe13AY0zObcczSobLExm0bHLvl3FTPIEHFeXvNeG4FX8fBtHDFXDU s875UpWOvYwUGGkqwqftne4FcDneZ8Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-syOVuANoOUy-jKfm_jOXDg-1; Fri, 20 Nov 2020 13:53:27 -0500 X-MC-Unique: syOVuANoOUy-jKfm_jOXDg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EFBC8145E2; Fri, 20 Nov 2020 18:53:24 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66FD25C230; Fri, 20 Nov 2020 18:53:08 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 09/27] vhost: Route host->guest notification through qemu Date: Fri, 20 Nov 2020 19:50:47 +0100 Message-Id: <20201120185105.279030-10-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.c | 3 +++ hw/virtio/vhost.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index 0192e77831..cbf53965cd 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -50,6 +50,9 @@ VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) r = dev->vhost_ops->vhost_set_vring_kick(dev, &file); assert(r == 0); + vhost_virtqueue_mask(dev, dev->vdev, idx, true); + vhost_virtqueue_pending(dev, idx); + return svq; } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1d55e26d45..9352c56bfa 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -960,12 +960,29 @@ static void handle_sw_lm_vq(VirtIODevice *vdev, VirtQueue *vq) vhost_vring_kick(svq); } +static void vhost_handle_call(EventNotifier *n) +{ + struct vhost_virtqueue *hvq = container_of(n, + struct vhost_virtqueue, + masked_notifier); + struct vhost_dev *vdev = hvq->dev; + int idx = vdev->vq_index + (hvq == &vdev->vqs[0] ? 0 : 1); + VirtQueue *vq = virtio_get_queue(vdev->vdev, idx); + + if (event_notifier_test_and_clear(n)) { + virtio_queue_invalidate_signalled_used(vdev->vdev, idx); + virtio_notify_irqfd(vdev->vdev, vq); + } +} + static int vhost_sw_live_migration_stop(struct vhost_dev *dev) { int idx; vhost_dev_enable_notifiers(dev, dev->vdev); for (idx = 0; idx < dev->nvqs; ++idx) { + vhost_virtqueue_mask(dev, dev->vdev, idx, false); + vhost_virtqueue_pending(dev, idx); vhost_sw_lm_shadow_vq_free(dev->sw_lm_shadow_vq[idx]); } @@ -977,7 +994,10 @@ static int vhost_sw_live_migration_start(struct vhost_dev *dev) int idx; for (idx = 0; idx < dev->nvqs; ++idx) { + struct vhost_virtqueue *vq = &dev->vqs[idx]; + dev->sw_lm_shadow_vq[idx] = vhost_sw_lm_shadow_vq(dev, idx); + event_notifier_set_handler(&vq->masked_notifier, vhost_handle_call); } vhost_dev_disable_notifiers(dev, dev->vdev); From patchwork Fri Nov 20 18:50:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=doo1gPHi; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5kj17VCz9sTR for ; Sat, 21 Nov 2020 06:11:41 +1100 (AEDT) Received: from localhost ([::1]:44254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBop-0005Dm-4q for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:11:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBXW-0005Zd-T7 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBXV-0007Nc-16 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:53:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898421; 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=geMra6s2mk7qQGmiDf6FdjeAxAi7bQOlm3m+XgBp7eM=; b=doo1gPHiehCgbvYbC7n4JtUOXU1SKlYIGsMxxgpX762R/iLEILbNqI9kjY8c1bgFiF4fwF +GzH2SO2oJVefAWUhL2bKcJa41ENAj9X6S8wlaLDNZGqlmz/lF8BJZa6C59HJ5wXKALvuT WGkO28UOlo2LVEU2ocwgD49aklphrBE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-O0I0LkrQMrGPImdL7SOirQ-1; Fri, 20 Nov 2020 13:53:39 -0500 X-MC-Unique: O0I0LkrQMrGPImdL7SOirQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 437D1801AF1; Fri, 20 Nov 2020 18:53:36 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97F395C1D5; Fri, 20 Nov 2020 18:53:24 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 10/27] vhost: Allocate shadow vring Date: Fri, 20 Nov 2020 19:50:48 +0100 Message-Id: <20201120185105.279030-11-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index cbf53965cd..cd7b5ba772 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -16,8 +16,11 @@ #include "qemu/event_notifier.h" typedef struct VhostShadowVirtqueue { + struct vring vring; EventNotifier hdev_notifier; VirtQueue *vq; + + vring_desc_t descs[]; } VhostShadowVirtqueue; static inline bool vhost_vring_should_kick(VhostShadowVirtqueue *vq) @@ -37,10 +40,12 @@ VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) .index = idx }; VirtQueue *vq = virtio_get_queue(dev->vdev, idx); + unsigned num = virtio_queue_get_num(dev->vdev, idx); + size_t ring_size = vring_size(num, VRING_DESC_ALIGN_SIZE); VhostShadowVirtqueue *svq; int r; - svq = g_new0(VhostShadowVirtqueue, 1); + svq = g_malloc0(sizeof(*svq) + ring_size); svq->vq = vq; r = event_notifier_init(&svq->hdev_notifier, 0); From patchwork Fri Nov 20 18:50:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Hc3ctVPS; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5Sv4Nb7z9sTR for ; Sat, 21 Nov 2020 05:59:42 +1100 (AEDT) Received: from localhost ([::1]:45318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBdE-00021V-0l for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 13:59:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBXn-0005s8-2N for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:54:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBXl-0007TF-1l for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:54:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898440; 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=GYiokrtmxVGaxHYQFYtHrYcyj4QArcgChV2OGqAzahY=; b=Hc3ctVPSgydSURZY66CjMLPs0tM+la9i9XB0tRnsg+tZd0LGxS2DJ8bseaWfMCGmMtbasA qqB2jXefNJIIAJwlkoW1TWAn2VA22dpwYOPmnAiye3z+wB+0xhoitpJqj5fYywyeQrE2Ml HMSpUrJX2XCxIvKkraO3+Go1ub0Xsrw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-71-Q2QN0RgLOE-Z4tC5OIvHtg-1; Fri, 20 Nov 2020 13:53:58 -0500 X-MC-Unique: Q2QN0RgLOE-Z4tC5OIvHtg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D4232100C605; Fri, 20 Nov 2020 18:53:54 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 721AB5C1D5; Fri, 20 Nov 2020 18:53:36 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 11/27] virtio: const-ify all virtio_tswap* functions Date: Fri, 20 Nov 2020 19:50:49 +0100 Message-Id: <20201120185105.279030-12-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" They do not modify vdev, so these should be const as qemu coding style guideline. Signed-off-by: Eugenio Pérez --- include/hw/virtio/virtio-access.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h index 6818a23a2d..7474f89b5f 100644 --- a/include/hw/virtio/virtio-access.h +++ b/include/hw/virtio/virtio-access.h @@ -24,7 +24,7 @@ #define LEGACY_VIRTIO_IS_BIENDIAN 1 #endif -static inline bool virtio_access_is_big_endian(VirtIODevice *vdev) +static inline bool virtio_access_is_big_endian(const VirtIODevice *vdev) { #if defined(LEGACY_VIRTIO_IS_BIENDIAN) return virtio_is_big_endian(vdev); @@ -147,7 +147,7 @@ static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr) } } -static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s) +static inline uint16_t virtio_tswap16(const VirtIODevice *vdev, uint16_t s) { #ifdef HOST_WORDS_BIGENDIAN return virtio_access_is_big_endian(vdev) ? s : bswap16(s); @@ -213,7 +213,7 @@ static inline void virtio_tswap16s(VirtIODevice *vdev, uint16_t *s) *s = virtio_tswap16(vdev, *s); } -static inline uint32_t virtio_tswap32(VirtIODevice *vdev, uint32_t s) +static inline uint32_t virtio_tswap32(const VirtIODevice *vdev, uint32_t s) { #ifdef HOST_WORDS_BIGENDIAN return virtio_access_is_big_endian(vdev) ? s : bswap32(s); @@ -227,7 +227,7 @@ static inline void virtio_tswap32s(VirtIODevice *vdev, uint32_t *s) *s = virtio_tswap32(vdev, *s); } -static inline uint64_t virtio_tswap64(VirtIODevice *vdev, uint64_t s) +static inline uint64_t virtio_tswap64(const VirtIODevice *vdev, uint64_t s) { #ifdef HOST_WORDS_BIGENDIAN return virtio_access_is_big_endian(vdev) ? s : bswap64(s); From patchwork Fri Nov 20 18:50:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R5zHjq7t; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5kV08m3z9sTR for ; Sat, 21 Nov 2020 06:11:29 +1100 (AEDT) Received: from localhost ([::1]:43088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBod-0004jg-LF for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:11:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBXz-00068k-U3 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:54:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBXx-0007WS-U4 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:54:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898453; 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=P54fNkbLFlDhwRYgmtpG8Llho8C34w4aU/D/fzEYMnA=; b=R5zHjq7tn3D7j+fjx8/YfqB+mxNQXtT7BN3NqhJ5BiyC/g2PaNPXjwsY8wx9gYI1zxkHCg Hp1qHrWio0wTkBF4cbHzqb0UBsSFTEDvJnVuXCNqn5X2BLxI2CwISqpfjon3sO/JkyF6HY YswnYeVOow6bjZEGaShk/zMMFUB88DU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-547-Ibt8zbtuMPKnozMX7xzKtA-1; Fri, 20 Nov 2020 13:54:11 -0500 X-MC-Unique: Ibt8zbtuMPKnozMX7xzKtA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 636981084423; Fri, 20 Nov 2020 18:54:08 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 375E35C1D5; Fri, 20 Nov 2020 18:53:55 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 12/27] virtio: Add virtio_queue_full Date: Fri, 20 Nov 2020 19:50:50 +0100 Message-Id: <20201120185105.279030-13-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- include/hw/virtio/virtio.h | 2 ++ hw/virtio/virtio.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b9b8497ea0..0a7f5cc63e 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -233,6 +233,8 @@ int virtio_queue_ready(VirtQueue *vq); int virtio_queue_empty(VirtQueue *vq); +bool virtio_queue_full(const VirtQueue *vq); + /* Host binding interface. */ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3469946538..77ca5f6b6f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -684,6 +684,17 @@ int virtio_queue_empty(VirtQueue *vq) } } +static bool virtio_queue_full_rcu(const VirtQueue *vq) +{ + return vq->inuse >= vq->vring.num; +} + +bool virtio_queue_full(const VirtQueue *vq) +{ + RCU_READ_LOCK_GUARD(); + return virtio_queue_full_rcu(vq); +} + static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len) { @@ -1453,7 +1464,7 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz) max = vq->vring.num; - if (vq->inuse >= vq->vring.num) { + if (unlikely(virtio_queue_full_rcu(vq))) { virtio_error(vdev, "Virtqueue size exceeded"); goto done; } @@ -1588,7 +1599,7 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz) max = vq->vring.num; - if (vq->inuse >= vq->vring.num) { + if (unlikely(virtio_queue_full_rcu(vq))) { virtio_error(vdev, "Virtqueue size exceeded"); goto done; } From patchwork Fri Nov 20 18:50:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QLgW7Thk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5WY2K8Gz9sTR for ; Sat, 21 Nov 2020 06:02:01 +1100 (AEDT) Received: from localhost ([::1]:50368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBfT-0004Bd-78 for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:01:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBYM-0006Kb-H0 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:54:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBYJ-0007dN-O3 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:54:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898473; 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=DBP6ZYk56FcgCXgaWqpbvzcgYqNFQcFTrZnQ3USZwTQ=; b=QLgW7ThkHg9++LdDA7A4xuZD2t4QbDVsCdYuwFze2SH/swZU6G8R/G1TWnKiHokSKv/9IG b+Kk9KVzl/mYk+elhAaPzolgrWMmv/2eszT3QYuOVBKO4v2E52V+ygGve1jp9O3Bc+8hwk MV5sRFzn7gAZp4t/zRQKlQvR/4rZVAo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-lEeqo5FhPaaoSZsN_h9FbQ-1; Fri, 20 Nov 2020 13:54:31 -0500 X-MC-Unique: lEeqo5FhPaaoSZsN_h9FbQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 64E8B184215F; Fri, 20 Nov 2020 18:54:28 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD0785C1D5; Fri, 20 Nov 2020 18:54:08 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 13/27] vhost: Send buffers to device Date: Fri, 20 Nov 2020 19:50:51 +0100 Message-Id: <20201120185105.279030-14-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.h | 3 + hw/virtio/vhost-sw-lm-ring.c | 134 +++++++++++++++++++++++++++++++++-- hw/virtio/vhost.c | 59 ++++++++++++++- 3 files changed, 189 insertions(+), 7 deletions(-) diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h index 86dc081b93..29d21feaf4 100644 --- a/hw/virtio/vhost-sw-lm-ring.h +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -18,6 +18,9 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; bool vhost_vring_kick(VhostShadowVirtqueue *vq); +int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem); +void vhost_vring_write_addr(const VhostShadowVirtqueue *vq, + struct vhost_vring_addr *addr); VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx); diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index cd7b5ba772..aed005c2d9 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -9,6 +9,7 @@ #include "hw/virtio/vhost-sw-lm-ring.h" #include "hw/virtio/vhost.h" +#include "hw/virtio/virtio-access.h" #include "standard-headers/linux/vhost_types.h" #include "standard-headers/linux/virtio_ring.h" @@ -19,21 +20,140 @@ typedef struct VhostShadowVirtqueue { struct vring vring; EventNotifier hdev_notifier; VirtQueue *vq; + VirtIODevice *vdev; + + /* Map for returning guest's descriptors */ + VirtQueueElement **ring_id_maps; + + /* Next head to expose to device */ + uint16_t avail_idx_shadow; + + /* Number of descriptors added since last notification */ + uint16_t num_added; + + /* Next free descriptor */ + uint16_t free_head; vring_desc_t descs[]; } VhostShadowVirtqueue; -static inline bool vhost_vring_should_kick(VhostShadowVirtqueue *vq) +static bool vhost_vring_should_kick_rcu(VhostShadowVirtqueue *vq) { - return virtio_queue_get_used_notify_split(vq->vq); + VirtIODevice *vdev = vq->vdev; + vq->num_added = 0; + + smp_rmb(); + return !(vq->vring.used->flags + & virtio_tswap16(vdev, VRING_USED_F_NO_NOTIFY)); } +static bool vhost_vring_should_kick(VhostShadowVirtqueue *vq) +{ + RCU_READ_LOCK_GUARD(); + return vhost_vring_should_kick_rcu(vq); +} + + bool vhost_vring_kick(VhostShadowVirtqueue *vq) { return vhost_vring_should_kick(vq) ? event_notifier_set(&vq->hdev_notifier) : true; } +static void vhost_vring_write_descs(VhostShadowVirtqueue *vq, + const struct iovec *iovec, + size_t num, bool more_descs, bool write) +{ + uint16_t i = vq->free_head, last = vq->free_head; + unsigned n; + const VirtIODevice *vdev = vq->vdev; + uint16_t flags = write ? virtio_tswap16(vdev, VRING_DESC_F_WRITE) : 0; + vring_desc_t *descs = vq->vring.desc; + + if (num == 0) { + return; + } + + for (n = 0; n < num; n++) { + if (more_descs || (n + 1 < num)) { + descs[i].flags = flags | virtio_tswap16(vdev, VRING_DESC_F_NEXT); + } else { + descs[i].flags = flags; + } + descs[i].addr = virtio_tswap64(vdev, (hwaddr)iovec[n].iov_base); + descs[i].len = virtio_tswap32(vdev, iovec[n].iov_len); + + last = i; + i = virtio_tswap16(vdev, descs[i].next); + } + + vq->free_head = virtio_tswap16(vdev, descs[last].next); +} + +/* virtqueue_add: + * @vq: The #VirtQueue + * @elem: The #VirtQueueElement + * + * Add an avail element to a virtqueue. + */ +static int vhost_vring_add_split(VhostShadowVirtqueue *vq, + const VirtQueueElement *elem) +{ + int head; + unsigned avail_idx; + const VirtIODevice *vdev; + vring_avail_t *avail; + + RCU_READ_LOCK_GUARD(); + vdev = vq->vdev; + avail = vq->vring.avail; + + head = vq->free_head; + + /* We need some descriptors here */ + assert(elem->out_num || elem->in_num); + + vhost_vring_write_descs(vq, elem->out_sg, elem->out_num, + elem->in_num > 0, false); + vhost_vring_write_descs(vq, elem->in_sg, elem->in_num, false, true); + + /* Put entry in available array (but don't update avail->idx until they + * do sync). */ + avail_idx = vq->avail_idx_shadow & (vq->vring.num - 1); + avail->ring[avail_idx] = virtio_tswap16(vdev, head); + vq->avail_idx_shadow++; + + /* Expose descriptors to device */ + smp_wmb(); + avail->idx = virtio_tswap16(vdev, vq->avail_idx_shadow); + + /* threoretically possible. Kick just in case */ + if (unlikely(vq->num_added++ == (uint16_t)-1)) { + vhost_vring_kick(vq); + } + + return head; +} + +int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem) +{ + int host_head = vhost_vring_add_split(vq, elem); + if (vq->ring_id_maps[host_head]) { + g_free(vq->ring_id_maps[host_head]); + } + + vq->ring_id_maps[host_head] = elem; + return 0; +} + +void vhost_vring_write_addr(const VhostShadowVirtqueue *vq, + struct vhost_vring_addr *addr) +{ + addr->desc_user_addr = (uint64_t)vq->vring.desc; + addr->avail_user_addr = (uint64_t)vq->vring.avail; + addr->used_user_addr = (uint64_t)vq->vring.used; +} + VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) { struct vhost_vring_file file = { @@ -43,9 +163,11 @@ VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) unsigned num = virtio_queue_get_num(dev->vdev, idx); size_t ring_size = vring_size(num, VRING_DESC_ALIGN_SIZE); VhostShadowVirtqueue *svq; - int r; + int r, i; svq = g_malloc0(sizeof(*svq) + ring_size); + svq->ring_id_maps = g_new0(VirtQueueElement *, num); + svq->vdev = dev->vdev; svq->vq = vq; r = event_notifier_init(&svq->hdev_notifier, 0); @@ -55,8 +177,9 @@ VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) r = dev->vhost_ops->vhost_set_vring_kick(dev, &file); assert(r == 0); - vhost_virtqueue_mask(dev, dev->vdev, idx, true); - vhost_virtqueue_pending(dev, idx); + vring_init(&svq->vring, num, svq->descs, VRING_DESC_ALIGN_SIZE); + for (i = 0; i < num - 1; i++) + svq->descs[i].next = virtio_tswap16(dev->vdev, i + 1); return svq; } @@ -64,5 +187,6 @@ VhostShadowVirtqueue *vhost_sw_lm_shadow_vq(struct vhost_dev *dev, int idx) void vhost_sw_lm_shadow_vq_free(VhostShadowVirtqueue *vq) { event_notifier_cleanup(&vq->hdev_notifier); + g_free(vq->ring_id_maps); g_free(vq); } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9352c56bfa..304e0baa61 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -956,8 +956,34 @@ static void handle_sw_lm_vq(VirtIODevice *vdev, VirtQueue *vq) uint16_t idx = virtio_get_queue_index(vq); VhostShadowVirtqueue *svq = hdev->sw_lm_shadow_vq[idx]; + VirtQueueElement *elem; - vhost_vring_kick(svq); + /* + * Make available all buffers as possible. + */ + do { + if (virtio_queue_get_notification(vq)) { + virtio_queue_set_notification(vq, false); + } + + while (true) { + int r; + if (virtio_queue_full(vq)) { + break; + } + + elem = virtqueue_pop(vq, sizeof(*elem)); + if (!elem) { + break; + } + + r = vhost_vring_add(svq, elem); + assert(r >= 0); + vhost_vring_kick(svq); + } + + virtio_queue_set_notification(vq, true); + } while(!virtio_queue_empty(vq)); } static void vhost_handle_call(EventNotifier *n) @@ -975,6 +1001,11 @@ static void vhost_handle_call(EventNotifier *n) } } +static void vhost_virtqueue_stop(struct vhost_dev *dev, + struct VirtIODevice *vdev, + struct vhost_virtqueue *vq, + unsigned idx); + static int vhost_sw_live_migration_stop(struct vhost_dev *dev) { int idx; @@ -991,17 +1022,41 @@ static int vhost_sw_live_migration_stop(struct vhost_dev *dev) static int vhost_sw_live_migration_start(struct vhost_dev *dev) { - int idx; + int idx, r; + + assert(dev->vhost_ops->vhost_set_vring_enable); + dev->vhost_ops->vhost_set_vring_enable(dev, false); for (idx = 0; idx < dev->nvqs; ++idx) { struct vhost_virtqueue *vq = &dev->vqs[idx]; + struct vhost_vring_addr addr = { + .index = idx, + }; + struct vhost_vring_state s = { + .index = idx, + }; + + vhost_virtqueue_stop(dev, dev->vdev, &dev->vqs[idx], idx); dev->sw_lm_shadow_vq[idx] = vhost_sw_lm_shadow_vq(dev, idx); event_notifier_set_handler(&vq->masked_notifier, vhost_handle_call); + + vhost_vring_write_addr(dev->sw_lm_shadow_vq[idx], &addr); + r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr); + assert(r == 0); + + r = dev->vhost_ops->vhost_set_vring_base(dev, &s); + assert(r == 0); } + dev->vhost_ops->vhost_set_vring_enable(dev, true); vhost_dev_disable_notifiers(dev, dev->vdev); + for (idx = 0; idx < dev->nvqs; ++idx) { + vhost_virtqueue_mask(dev, dev->vdev, idx, true); + vhost_virtqueue_pending(dev, idx); + } + return 0; } From patchwork Fri Nov 20 18:50:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OkILHZ1l; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5pf4Gn4z9sVH for ; Sat, 21 Nov 2020 06:15:06 +1100 (AEDT) Received: from localhost ([::1]:51502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBs8-0008BL-En for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:15:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBYl-0006eP-0w for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBYi-0007kA-VY for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898494; 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=y9YecuAZNjK7boQsGuALrrDDzK7DqtNNTDUOzMBa16g=; b=OkILHZ1lh47KN9mPSEjMoZu7opIqgnGF2L9gMJCE62FitmNdeV9l4unHzIyiqxXNUS/rOc 0guRHbOrIAkwhHxyVyEqPD2aDhqqs9tGKR4gFrCG5dsDq4SeS6IjL5MNxOUd5IRs946sO2 bFuF1XjjIHunLqh9kWi0GBX1mWNP14o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-1Z2VrzOYN9q29U6WGS9-vA-1; Fri, 20 Nov 2020 13:54:52 -0500 X-MC-Unique: 1Z2VrzOYN9q29U6WGS9-vA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 027678030AD; Fri, 20 Nov 2020 18:54:49 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD2B65C1D5; Fri, 20 Nov 2020 18:54:28 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 14/27] virtio: Remove virtio_queue_get_used_notify_split Date: Fri, 20 Nov 2020 19:50:52 +0100 Message-Id: <20201120185105.279030-15-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" No more uses beyond this point Signed-off-by: Eugenio Pérez --- include/hw/virtio/virtio.h | 1 - hw/virtio/virtio.c | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 0a7f5cc63e..79212141a6 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -225,7 +225,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id); void virtio_notify_config(VirtIODevice *vdev); -bool virtio_queue_get_used_notify_split(VirtQueue *vq); bool virtio_queue_get_notification(VirtQueue *vq); void virtio_queue_set_notification(VirtQueue *vq, int enable); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 77ca5f6b6f..ad9dc5dfa7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -377,20 +377,6 @@ static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val) vq->used_idx = val; } -bool virtio_queue_get_used_notify_split(VirtQueue *vq) -{ - VRingMemoryRegionCaches *caches; - hwaddr pa = offsetof(VRingUsed, flags); - uint16_t flags; - - RCU_READ_LOCK_GUARD(); - - caches = vring_get_region_caches(vq); - assert(caches); - flags = virtio_lduw_phys_cached(vq->vdev, &caches->used, pa); - return !(VRING_USED_F_NO_NOTIFY & flags); -} - /* Called within rcu_read_lock(). */ static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask) { From patchwork Fri Nov 20 18:50:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OGwTUoY0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5b743Bgz9sTR for ; Sat, 21 Nov 2020 06:05:07 +1100 (AEDT) Received: from localhost ([::1]:58966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBiT-0007k8-HU for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:05:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBYq-0006mj-4J for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49246) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBYn-0007mi-Vl for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898505; 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=4wp9YwTYGJnUKm2v8rubzSiDU/VoJ3Bb1DJ/6lk+2es=; b=OGwTUoY0ZbWHvLDtCRfDAfbzluKzXjFl+sTW/D3U57HC6gjuNIa59+ocRgwhUodCXxQNOI PeNkydEUr2mkKQV2k+PXNBTkL+CVQiRQE5oaAFCTLwGOMeL5Wt24Y0tpat1bgAjX+9SrG7 FSpfojOTUUnbCjoFmdg7M2MA94pdW4o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-vhU3u-tTOGC90Zymqu4hTA-1; Fri, 20 Nov 2020 13:55:01 -0500 X-MC-Unique: vhU3u-tTOGC90Zymqu4hTA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 951ED8030AD; Fri, 20 Nov 2020 18:54:58 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7628E5C1D5; Fri, 20 Nov 2020 18:54:49 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 15/27] vhost: Do not invalidate signalled used Date: Fri, 20 Nov 2020 19:50:53 +0100 Message-Id: <20201120185105.279030-16-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since we are in control of guest' VQ again, we can trust on it. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 304e0baa61..ac2bc14190 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -996,7 +996,6 @@ static void vhost_handle_call(EventNotifier *n) VirtQueue *vq = virtio_get_queue(vdev->vdev, idx); if (event_notifier_test_and_clear(n)) { - virtio_queue_invalidate_signalled_used(vdev->vdev, idx); virtio_notify_irqfd(vdev->vdev, vq); } } From patchwork Fri Nov 20 18:50:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QsFByzEM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5qH5916z9sTR for ; Sat, 21 Nov 2020 06:15:39 +1100 (AEDT) Received: from localhost ([::1]:52660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBsf-0000EZ-Le for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:15:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBZ2-0006rs-L2 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43039) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBZ0-0007sj-2S for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898517; 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=2NtO6niIGV95EKH2ITwzudVB3tBfrLrd6tahFyFqPtU=; b=QsFByzEME5Iqh723uJG8oIS89Qow2A6+5/3qLL1/jrNLFapK7+6KDYVIcPWicYT1V0V7WZ Lua+549CDpuldfbk7C6BDettL53ePUbwjyD12bZuyQV57yozyHIZdJGyp96W75SbHD4ILF zDtxy3EFEvWa7UCRTi+Try6B333FIs4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-zR19Dr3RMGSdd3PWouysKg-1; Fri, 20 Nov 2020 13:55:14 -0500 X-MC-Unique: zR19Dr3RMGSdd3PWouysKg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE8D25B375; Fri, 20 Nov 2020 18:55:11 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0B3E5C1D5; Fri, 20 Nov 2020 18:54:58 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 16/27] virtio: Expose virtqueue_alloc_element Date: Fri, 20 Nov 2020 19:50:54 +0100 Message-Id: <20201120185105.279030-17-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Specify VirtQueueElement * as return type makes no harm at this moment. Signed-off-by: Eugenio Pérez --- include/hw/virtio/virtio.h | 2 ++ hw/virtio/virtio.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 79212141a6..ee8fe96f32 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -196,6 +196,8 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx); void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem); +VirtQueueElement *virtqueue_alloc_element(size_t sz, unsigned out_num, + unsigned in_num); void *virtqueue_pop(VirtQueue *vq, size_t sz); unsigned int virtqueue_drop_all(VirtQueue *vq); void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t sz); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ad9dc5dfa7..a89525f067 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1400,7 +1400,8 @@ void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem) false); } -static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num) +VirtQueueElement *virtqueue_alloc_element(size_t sz, unsigned out_num, + unsigned in_num) { VirtQueueElement *elem; size_t in_addr_ofs = QEMU_ALIGN_UP(sz, __alignof__(elem->in_addr[0])); From patchwork Fri Nov 20 18:50:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404049 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QWM/Vy++; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5dP1rtFz9sVH for ; Sat, 21 Nov 2020 06:07:05 +1100 (AEDT) Received: from localhost ([::1]:33594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBkN-0000ZC-66 for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:07:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBZB-0006wp-Pu for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBZ9-0007y9-Pp for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898525; 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=0UHivzc6s/JNkkNVrXBKkPRfSO+gYprJIEU1Xp+Kgh8=; b=QWM/Vy++egcDcQqlX7DvSZZ9zN/B01vUeA9siEzqXmD4oSyfg0OIFM0eQPocRTvzRNH8AZ fk6k555VehMjef3F16Y5BW7T2yxN3EOSRipU6LCDnNo2KGlTkaPGKrLCO/R8eNVzu6/M5E PLvVxoZhRX83SqhOB+wtHAmgq4NNTM4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-70ESR6YbNbOEQU5MD20vSA-1; Fri, 20 Nov 2020 13:55:23 -0500 X-MC-Unique: 70ESR6YbNbOEQU5MD20vSA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22C821842159; Fri, 20 Nov 2020 18:55:21 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 130455C1D5; Fri, 20 Nov 2020 18:55:11 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 17/27] vhost: add vhost_vring_set_notification_rcu Date: Fri, 20 Nov 2020 19:50:55 +0100 Message-Id: <20201120185105.279030-18-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.h | 4 ++++ hw/virtio/vhost-sw-lm-ring.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h index 29d21feaf4..c537500d9e 100644 --- a/hw/virtio/vhost-sw-lm-ring.h +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -19,6 +19,10 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; bool vhost_vring_kick(VhostShadowVirtqueue *vq); int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem); + +/* Called within rcu_read_lock(). */ +void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable); + void vhost_vring_write_addr(const VhostShadowVirtqueue *vq, struct vhost_vring_addr *addr); diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index aed005c2d9..c3244c550e 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -34,6 +34,9 @@ typedef struct VhostShadowVirtqueue { /* Next free descriptor */ uint16_t free_head; + /* Cache for exposed notification flag */ + bool notification; + vring_desc_t descs[]; } VhostShadowVirtqueue; @@ -60,6 +63,26 @@ bool vhost_vring_kick(VhostShadowVirtqueue *vq) : true; } +void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable) +{ + uint16_t notification_flag; + + if (vq->notification == enable) { + return; + } + + notification_flag = virtio_tswap16(vq->vdev, VRING_AVAIL_F_NO_INTERRUPT); + + vq->notification = enable; + if (enable) { + vq->vring.avail->flags &= ~notification_flag; + } else { + vq->vring.avail->flags |= notification_flag; + } + + smp_mb(); +} + static void vhost_vring_write_descs(VhostShadowVirtqueue *vq, const struct iovec *iovec, size_t num, bool more_descs, bool write) From patchwork Fri Nov 20 18:50:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XsfvQ946; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5kG3LVYz9sVH for ; Sat, 21 Nov 2020 06:11:18 +1100 (AEDT) Received: from localhost ([::1]:41966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBoS-0004By-DV for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:11:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBZN-0007OC-2m for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60075) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBZL-000819-5T for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898538; 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=XrOQ1s9JEtCDaxgd6vNOOY/KU2hMoYwe0eOTlPEs1LA=; b=XsfvQ946fvsuibV8/03b3I3UksPC3LDRzzL/LnPzHRJS45M8G+z7Sb28OWqmHET3iR5Dl/ U2Ddm3TcmEfThfGhPku1kRhbqM+tK9RQJw4+jj5HKTTzjuwScYEMdJ37UpxxarA5dPCauk RVGYEYDqrfRp21Nnycsscnu++Qj67BY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-539-3a8sTKaMN8eKwFoqmbXgCw-1; Fri, 20 Nov 2020 13:55:33 -0500 X-MC-Unique: 3a8sTKaMN8eKwFoqmbXgCw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF8875B365; Fri, 20 Nov 2020 18:55:30 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 798045C1D5; Fri, 20 Nov 2020 18:55:21 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 18/27] vhost: add vhost_vring_poll_rcu Date: Fri, 20 Nov 2020 19:50:56 +0100 Message-Id: <20201120185105.279030-19-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.h | 2 ++ hw/virtio/vhost-sw-lm-ring.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h index c537500d9e..03257d60c1 100644 --- a/hw/virtio/vhost-sw-lm-ring.h +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -22,6 +22,8 @@ int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem); /* Called within rcu_read_lock(). */ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable); +/* Called within rcu_read_lock(). */ +bool vhost_vring_poll_rcu(VhostShadowVirtqueue *vq); void vhost_vring_write_addr(const VhostShadowVirtqueue *vq, struct vhost_vring_addr *addr); diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index c3244c550e..3652889d8e 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -34,6 +34,12 @@ typedef struct VhostShadowVirtqueue { /* Next free descriptor */ uint16_t free_head; + /* Last seen used idx */ + uint16_t shadow_used_idx; + + /* Next head to consume from device */ + uint16_t used_idx; + /* Cache for exposed notification flag */ bool notification; @@ -83,6 +89,18 @@ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable) smp_mb(); } +bool vhost_vring_poll_rcu(VhostShadowVirtqueue *vq) +{ + if (vq->used_idx != vq->shadow_used_idx) { + return true; + } + + smp_rmb(); + vq->shadow_used_idx = virtio_tswap16(vq->vdev, vq->vring.used->idx); + + return vq->used_idx != vq->shadow_used_idx; +} + static void vhost_vring_write_descs(VhostShadowVirtqueue *vq, const struct iovec *iovec, size_t num, bool more_descs, bool write) From patchwork Fri Nov 20 18:50:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NeKpx8RD; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5vc0jY9z9sVH for ; Sat, 21 Nov 2020 06:19:24 +1100 (AEDT) Received: from localhost ([::1]:59950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBwH-0003NT-Vf for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:19:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBZf-0007Rz-Bv for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45921) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBZY-00086K-Ud for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:55:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898551; 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=dZxEbXIS4zyXv2m5LGIw7P1HSVQ2S2HneDTGUSzuoD4=; b=NeKpx8RDCXzDnVnnSzOwCMIQ8c7SFIOlDZcO5QZWV5zm63yJ5FhSfj5feU2fgi6M/unwvz 14kE38Y+iNbaK3/Mqvr6bAk3I9U+UHkSo6/AQGONa+p65hTvK4V+OTH9fiv6VNJy8JY6G2 zI8QWUER6F5hagsRF+QxPfeV+It9FBk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-TAvJhVXkPzytOL7DCgwuCw-1; Fri, 20 Nov 2020 13:55:46 -0500 X-MC-Unique: TAvJhVXkPzytOL7DCgwuCw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A68DA8030A3; Fri, 20 Nov 2020 18:55:43 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 146EB5C1D5; Fri, 20 Nov 2020 18:55:30 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 19/27] vhost: add vhost_vring_get_buf_rcu Date: Fri, 20 Nov 2020 19:50:57 +0100 Message-Id: <20201120185105.279030-20-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.h | 1 + hw/virtio/vhost-sw-lm-ring.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h index 03257d60c1..429a125558 100644 --- a/hw/virtio/vhost-sw-lm-ring.h +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -19,6 +19,7 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; bool vhost_vring_kick(VhostShadowVirtqueue *vq); int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem); +VirtQueueElement *vhost_vring_get_buf_rcu(VhostShadowVirtqueue *vq, size_t sz); /* Called within rcu_read_lock(). */ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable); diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index 3652889d8e..4fafd1b278 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -187,6 +187,35 @@ int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem) return 0; } +VirtQueueElement *vhost_vring_get_buf_rcu(VhostShadowVirtqueue *vq, size_t sz) +{ + const vring_used_t *used = vq->vring.used; + VirtQueueElement *ret; + vring_used_elem_t used_elem; + uint16_t last_used; + + if (!vhost_vring_poll_rcu(vq)) { + return NULL; + } + + last_used = vq->used_idx & (vq->vring.num - 1); + used_elem.id = virtio_tswap32(vq->vdev, used->ring[last_used].id); + used_elem.len = virtio_tswap32(vq->vdev, used->ring[last_used].len); + + if (unlikely(used_elem.id >= vq->vring.num)) { + virtio_error(vq->vdev, "Device says index %u is available", + used_elem.id); + return NULL; + } + + ret = vq->ring_id_maps[used_elem.id]; + ret->len = used_elem.len; + + vq->used_idx++; + + return ret; +} + void vhost_vring_write_addr(const VhostShadowVirtqueue *vq, struct vhost_vring_addr *addr) { From patchwork Fri Nov 20 18:50:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Jf3rZABf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5hk3bRDz9sTR for ; Sat, 21 Nov 2020 06:09:58 +1100 (AEDT) Received: from localhost ([::1]:39306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBnA-000335-D5 for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:09:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBZj-0007T8-Hy for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBZf-0008AU-3R for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898558; 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=DG7n1lY/Hiobxg4WLGYVhL1ajHj2aBFA91adPYMLFP4=; b=Jf3rZABflxeqCx7FJNgc2aQRYnAU+aKiQMk1twWs7rjkO6fv2SYsCOQD/F7lp0r172BBEM BLrxzUjuoqMeZKNykZFQfDXqFsdFjCnz9okuxdZOykx1DycxTTSLunRhF2uMoNi1yBbx4f OSwgFPFbtbITSKxMhx9gaCWggpFusgA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-twp43SyfNR6F-fyrLqtTQA-1; Fri, 20 Nov 2020 13:55:56 -0500 X-MC-Unique: twp43SyfNR6F-fyrLqtTQA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7487C801B1E; Fri, 20 Nov 2020 18:55:53 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B4585C1D5; Fri, 20 Nov 2020 18:55:43 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 20/27] vhost: Return used buffers Date: Fri, 20 Nov 2020 19:50:58 +0100 Message-Id: <20201120185105.279030-21-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- hw/virtio/vhost-sw-lm-ring.h | 3 +++ hw/virtio/vhost-sw-lm-ring.c | 14 +++++++---- hw/virtio/vhost.c | 46 +++++++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h index 429a125558..0c4fa772c7 100644 --- a/hw/virtio/vhost-sw-lm-ring.h +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -17,6 +17,9 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; +VirtIODevice *vhost_vring_vdev(VhostShadowVirtqueue *svq); +VirtQueue *vhost_vring_vdev_vq(VhostShadowVirtqueue *svq); + bool vhost_vring_kick(VhostShadowVirtqueue *vq); int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem); VirtQueueElement *vhost_vring_get_buf_rcu(VhostShadowVirtqueue *vq, size_t sz); diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index 4fafd1b278..244c722910 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -46,6 +46,16 @@ typedef struct VhostShadowVirtqueue { vring_desc_t descs[]; } VhostShadowVirtqueue; +VirtIODevice *vhost_vring_vdev(VhostShadowVirtqueue *svq) +{ + return svq->vdev; +} + +VirtQueue *vhost_vring_vdev_vq(VhostShadowVirtqueue *svq) +{ + return svq->vq; +} + static bool vhost_vring_should_kick_rcu(VhostShadowVirtqueue *vq) { VirtIODevice *vdev = vq->vdev; @@ -179,10 +189,6 @@ static int vhost_vring_add_split(VhostShadowVirtqueue *vq, int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem) { int host_head = vhost_vring_add_split(vq, elem); - if (vq->ring_id_maps[host_head]) { - g_free(vq->ring_id_maps[host_head]); - } - vq->ring_id_maps[host_head] = elem; return 0; } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ac2bc14190..9a3c580dcf 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -986,17 +986,50 @@ static void handle_sw_lm_vq(VirtIODevice *vdev, VirtQueue *vq) } while(!virtio_queue_empty(vq)); } +static void handle_sw_lm_vq_call(struct vhost_dev *hdev, + VhostShadowVirtqueue *svq) +{ + VirtQueueElement *elem; + VirtIODevice *vdev = vhost_vring_vdev(svq); + VirtQueue *vq = vhost_vring_vdev_vq(svq); + uint16_t idx = virtio_get_queue_index(vq); + + RCU_READ_LOCK_GUARD(); + /* + * Make used all buffers as possible. + */ + do { + unsigned i = 0; + + vhost_vring_set_notification_rcu(svq, false); + while (true) { + elem = vhost_vring_get_buf_rcu(svq, sizeof(*elem)); + if (!elem) { + break; + } + + assert(i < virtio_queue_get_num(vdev, idx)); + virtqueue_fill(vq, elem, elem->len, i++); + } + + virtqueue_flush(vq, i); + virtio_notify_irqfd(vdev, vq); + + vhost_vring_set_notification_rcu(svq, true); + } while (vhost_vring_poll_rcu(svq)); +} + static void vhost_handle_call(EventNotifier *n) { struct vhost_virtqueue *hvq = container_of(n, struct vhost_virtqueue, masked_notifier); struct vhost_dev *vdev = hvq->dev; - int idx = vdev->vq_index + (hvq == &vdev->vqs[0] ? 0 : 1); - VirtQueue *vq = virtio_get_queue(vdev->vdev, idx); + int idx = hvq == &vdev->vqs[0] ? 0 : 1; + VhostShadowVirtqueue *vq = vdev->sw_lm_shadow_vq[idx]; if (event_notifier_test_and_clear(n)) { - virtio_notify_irqfd(vdev->vdev, vq); + handle_sw_lm_vq_call(vdev, vq); } } @@ -1028,6 +1061,7 @@ static int vhost_sw_live_migration_start(struct vhost_dev *dev) for (idx = 0; idx < dev->nvqs; ++idx) { struct vhost_virtqueue *vq = &dev->vqs[idx]; + unsigned num = virtio_queue_get_num(dev->vdev, idx); struct vhost_vring_addr addr = { .index = idx, }; @@ -1044,6 +1078,12 @@ static int vhost_sw_live_migration_start(struct vhost_dev *dev) r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr); assert(r == 0); + r = vhost_backend_update_device_iotlb(dev, addr.used_user_addr, + addr.used_user_addr, + sizeof(vring_used_elem_t) * num, + IOMMU_RW); + assert(r == 0); + r = dev->vhost_ops->vhost_set_vring_base(dev, &s); assert(r == 0); } From patchwork Fri Nov 20 18:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R5jQwOeP; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5mg2yjMz9sTR for ; Sat, 21 Nov 2020 06:13:23 +1100 (AEDT) Received: from localhost ([::1]:47626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBqT-0006YU-Bn for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:13:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBa1-0007n2-9T for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24475) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBZz-0008Ez-3z for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898576; 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=VvYPxnElcsRqPRB3x32KT+7TZhu7baplHklcHyJ3ntU=; b=R5jQwOePsG/Z9alAQ1wSiuAFdyiu+2yRgf6WdWIHTHD/g/KoroWA2G1DQbKKvzizQH8EjF qn855O5M4BR9c6Me9gOj8V0kbgfH4Js+EMhEHX71bNyhdrcREVd5l27qMj5348uo+ZHIVe VBn8feger9GZbOYDMxoj1b6QgFwKkWA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-387-mtyRzA7kNwS9vj-lQSG9zQ-1; Fri, 20 Nov 2020 13:56:15 -0500 X-MC-Unique: mtyRzA7kNwS9vj-lQSG9zQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1189184215D; Fri, 20 Nov 2020 18:56:11 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB6785C1D5; Fri, 20 Nov 2020 18:55:53 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 21/27] vhost: Add vhost_virtqueue_memory_unmap Date: Fri, 20 Nov 2020 19:50:59 +0100 Message-Id: <20201120185105.279030-22-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is not a huge gain but helps in later changes. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9a3c580dcf..eafbbaa751 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -812,6 +812,21 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, return 0; } +static void vhost_virtqueue_memory_unmap(struct vhost_dev *dev, + struct vhost_virtqueue *vq, + bool used_is_dirty) +{ + if (vq->used) { + vhost_memory_unmap(dev, vq->used, vq->used_size, used_is_dirty, 0); + } + if (vq->avail) { + vhost_memory_unmap(dev, vq->avail, vq->avail_size, 0, 0); + } + if (vq->desc) { + vhost_memory_unmap(dev, vq->desc, vq->desc_size, 0, 0); + } +} + static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log) { @@ -1301,21 +1316,21 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, vq->desc = vhost_memory_map(dev, a, &l, false); if (!vq->desc || l != s) { r = -ENOMEM; - goto fail_alloc_desc; + goto fail_alloc; } vq->avail_size = s = l = virtio_queue_get_avail_size(vdev, idx); vq->avail_phys = a = virtio_queue_get_avail_addr(vdev, idx); vq->avail = vhost_memory_map(dev, a, &l, false); if (!vq->avail || l != s) { r = -ENOMEM; - goto fail_alloc_avail; + goto fail_alloc; } vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx); vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx); vq->used = vhost_memory_map(dev, a, &l, true); if (!vq->used || l != s) { r = -ENOMEM; - goto fail_alloc_used; + goto fail_alloc; } r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled); @@ -1358,15 +1373,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, fail_vector: fail_kick: fail_alloc: - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx), - 0, 0); -fail_alloc_used: - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, idx), - 0, 0); -fail_alloc_avail: - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx), - 0, 0); -fail_alloc_desc: + vhost_virtqueue_memory_unmap(dev, vq, false); return r; } @@ -1408,12 +1415,7 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev, vhost_vq_index); } - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, idx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx), - 0, virtio_queue_get_desc_size(vdev, idx)); + vhost_virtqueue_memory_unmap(dev, vq, true); } static void vhost_eventfd_add(MemoryListener *listener, From patchwork Fri Nov 20 18:51:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=F9nhvc2I; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5sl5CSKz9sTR for ; Sat, 21 Nov 2020 06:17:47 +1100 (AEDT) Received: from localhost ([::1]:55976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBuj-0001hT-NZ for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:17:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBaQ-00086G-Dd for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBaL-0008MG-Q4 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:56:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898600; 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=PTSVtxwsFfunaFRmsiJCHQSu2dQDXIap/g3V71hKaPI=; b=F9nhvc2IVK05wD3qnCCiNscMOhWYcpb0TqxjNLq+M9/9ZU89g0t597IdbfqkPYy8yGFsyT tsdcm0mEMFJGpw7Ec6mEUT1419A6b25NbefMPitsCxUheD/Hbbjv7kIwuyIHw3Gq5CEla+ j19CGEmZA4/V/olEg0ty3owPsT1Il0Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-xXhwUuTlODSMizKH-YZFMg-1; Fri, 20 Nov 2020 13:56:39 -0500 X-MC-Unique: xXhwUuTlODSMizKH-YZFMg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4524A100C602; Fri, 20 Nov 2020 18:56:36 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A8FF5C1D5; Fri, 20 Nov 2020 18:56:12 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 22/27] vhost: Add vhost_virtqueue_memory_map Date: Fri, 20 Nov 2020 19:51:00 +0100 Message-Id: <20201120185105.279030-23-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" To make it symmetric with _unmap. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 68 ++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index eafbbaa751..f640d4edf0 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -827,6 +827,42 @@ static void vhost_virtqueue_memory_unmap(struct vhost_dev *dev, } } +static int vhost_virtqueue_memory_map(struct vhost_dev *dev, + struct vhost_virtqueue *vq, + unsigned int vhost_vq_index) +{ + int r; + hwaddr a, l, s; + + a = vq->desc_phys; + s = l = vq->desc_size; + vq->desc = vhost_memory_map(dev, a, &l, false); + if (!vq->desc || l != s) { + return -ENOMEM; + } + + a = vq->avail_phys; + s = l = vq->avail_size; + vq->avail = vhost_memory_map(dev, a, &l, false); + if (!vq->avail || l != s) { + return -ENOMEM; + } + + a = vq->used_phys; + s = l = vq->used_size; + vq->used = vhost_memory_map(dev, a, &l, true); + if (!vq->used || l != s) { + return -ENOMEM; + } + + r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled); + if (r < 0) { + return -errno; + } + + return 0; +} + static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log) { @@ -1271,7 +1307,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); - hwaddr s, l, a; + hwaddr a; int r; int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file = { @@ -1311,31 +1347,15 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, } } - vq->desc_size = s = l = virtio_queue_get_desc_size(vdev, idx); + vq->desc_size = virtio_queue_get_desc_size(vdev, idx); vq->desc_phys = a; - vq->desc = vhost_memory_map(dev, a, &l, false); - if (!vq->desc || l != s) { - r = -ENOMEM; - goto fail_alloc; - } - vq->avail_size = s = l = virtio_queue_get_avail_size(vdev, idx); - vq->avail_phys = a = virtio_queue_get_avail_addr(vdev, idx); - vq->avail = vhost_memory_map(dev, a, &l, false); - if (!vq->avail || l != s) { - r = -ENOMEM; - goto fail_alloc; - } - vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx); - vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx); - vq->used = vhost_memory_map(dev, a, &l, true); - if (!vq->used || l != s) { - r = -ENOMEM; - goto fail_alloc; - } + vq->avail_size = virtio_queue_get_avail_size(vdev, idx); + vq->avail_phys = virtio_queue_get_avail_addr(vdev, idx); + vq->used_size = virtio_queue_get_used_size(vdev, idx); + vq->used_phys = virtio_queue_get_used_addr(vdev, idx); - r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled); - if (r < 0) { - r = -errno; + r = vhost_virtqueue_memory_map(dev, vq, vhost_vq_index); + if (r) { goto fail_alloc; } From patchwork Fri Nov 20 18:51:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JODFRAB5; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5xZ5Sl5z9s1l for ; Sat, 21 Nov 2020 06:21:06 +1100 (AEDT) Received: from localhost ([::1]:36182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBxw-0005HN-Mf for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:21:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBam-0008Cl-BL for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBaj-0008Qe-Ro for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898622; 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=CrZ8HzqKH9jvP8Zbz9rlbrynGHpm+xBKQyRidhhC+ks=; b=JODFRAB5AGFUsX6SEnxeUozM0HOQzKVxDixChQuzJZX5zk5ukmdEr/VjOXafDSMY6UbqTW 3qOf+Zht98YDcncGML6Q1tApaRmOJ9qK5hFVR6knNlb2GVugWv6810U3RLbJd53XIF3ExL fJ/w5hOmT41UJrQ2GR0/Ylp+WP+dgeM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-Fp2Ve2KaObiDeZeZtu8-8A-1; Fri, 20 Nov 2020 13:57:00 -0500 X-MC-Unique: Fp2Ve2KaObiDeZeZtu8-8A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5123B10059A4; Fri, 20 Nov 2020 18:56:58 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FE645C1D5; Fri, 20 Nov 2020 18:56:36 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 23/27] vhost: unmap qemu's shadow virtqueues on sw live migration Date: Fri, 20 Nov 2020 19:51:01 +0100 Message-Id: <20201120185105.279030-24-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since vhost does not need to access it, it has no sense to keep it mapped. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index f640d4edf0..eebfac4455 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1124,6 +1124,7 @@ static int vhost_sw_live_migration_start(struct vhost_dev *dev) dev->sw_lm_shadow_vq[idx] = vhost_sw_lm_shadow_vq(dev, idx); event_notifier_set_handler(&vq->masked_notifier, vhost_handle_call); + vhost_virtqueue_memory_unmap(dev, &dev->vqs[idx], true); vhost_vring_write_addr(dev->sw_lm_shadow_vq[idx], &addr); r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr); From patchwork Fri Nov 20 18:51:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H3kjDMtd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd61V5BMPz9s1l for ; Sat, 21 Nov 2020 06:24:30 +1100 (AEDT) Received: from localhost ([::1]:43390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgC1E-0008Hs-NL for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:24:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBb0-0008QI-Dy for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBay-0008UI-OS for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898640; 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=ryEh3kyaXHqK19Bj8UjCon+CnIrYqmewzumtOEVqPsQ=; b=H3kjDMtdWUV1rYRruexbHqgbOsphrs5gegTpkCA3jDr9UmI6h+46lQ92aUxSZUBHC0dcJo iHhDngJ1Dir6s//vijMeZv7dk5tVxZkFDznyWOElxVVACCTGQ8qyXPov8pzVF5Z3BWf9vJ yusqNHEhxwHGpEPZYJebk5PK0m6wJ54= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-434-OefOQcNqNjmjp4PHqy7Kmg-1; Fri, 20 Nov 2020 13:57:17 -0500 X-MC-Unique: OefOQcNqNjmjp4PHqy7Kmg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F365B1084425; Fri, 20 Nov 2020 18:57:13 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id A90BD5C1D5; Fri, 20 Nov 2020 18:56:58 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 24/27] vhost: iommu changes Date: Fri, 20 Nov 2020 19:51:02 +0100 Message-Id: <20201120185105.279030-25-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since vhost is now asking for qemu's VA, iommu needs to be bypassed. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index eebfac4455..cb44b9997f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1109,6 +1109,10 @@ static int vhost_sw_live_migration_start(struct vhost_dev *dev) assert(dev->vhost_ops->vhost_set_vring_enable); dev->vhost_ops->vhost_set_vring_enable(dev, false); + if (vhost_dev_has_iommu(dev)) { + r = vhost_backend_invalidate_device_iotlb(dev, 0, -1ULL); + assert(r == 0); + } for (idx = 0; idx < dev->nvqs; ++idx) { struct vhost_virtqueue *vq = &dev->vqs[idx]; @@ -1269,6 +1273,19 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write) trace_vhost_iotlb_miss(dev, 1); + if (dev->sw_lm_enabled) { + uaddr = iova; + len = 4096; + ret = vhost_backend_update_device_iotlb(dev, iova, uaddr, len, + IOMMU_RW); + if (ret) { + trace_vhost_iotlb_miss(dev, 2); + error_report("Fail to update device iotlb"); + } + + return ret; + } + iotlb = address_space_get_iotlb_entry(dev->vdev->dma_as, iova, write, MEMTXATTRS_UNSPECIFIED); From patchwork Fri Nov 20 18:51:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RT45NiFt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5w705Fbz9s1l for ; Sat, 21 Nov 2020 06:19:51 +1100 (AEDT) Received: from localhost ([::1]:60980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBwj-0003nD-0B for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:19:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBbC-00009J-HW for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBb8-00006K-PE for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898648; 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=7NFTh5Kxb25Zit2Z09Dwayle5qrijF2SdCF72+OTF/8=; b=RT45NiFtEwtJYp6ul1BBomD8AI8Vo3w3Qeeyyxs/lyHAWCLzbRCRogw7h7tDB24dWp2i+a GgqZm52gsb1S7pMGcrolZrF5MDa1G+mNv3zzLR5XVcUxQZFbHktqPRtZeiLUmA+/hFpWyN J2QINy6U0yXMOhoAmPFx2B7TxxtatXE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-111-APAVSU7rNfasUb3rHao7YA-1; Fri, 20 Nov 2020 13:57:26 -0500 X-MC-Unique: APAVSU7rNfasUb3rHao7YA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77F0D801B19; Fri, 20 Nov 2020 18:57:23 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 571CD5C1D5; Fri, 20 Nov 2020 18:57:14 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 25/27] vhost: Do not commit vhost used idx on vhost_virtqueue_stop Date: Fri, 20 Nov 2020 19:51:03 +0100 Message-Id: <20201120185105.279030-26-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" ... if sw lm is enabled Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index cb44b9997f..cf000b979f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1424,17 +1424,22 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev, struct vhost_vring_state state = { .index = vhost_vq_index, }; - int r; + int r = -1; if (virtio_queue_get_desc_addr(vdev, idx) == 0) { /* Don't stop the virtqueue which might have not been started */ return; } - r = dev->vhost_ops->vhost_get_vring_base(dev, &state); - if (r < 0) { - VHOST_OPS_DEBUG("vhost VQ %u ring restore failed: %d", idx, r); - /* Connection to the backend is broken, so let's sync internal + if (!dev->sw_lm_enabled) { + r = dev->vhost_ops->vhost_get_vring_base(dev, &state); + if (r < 0) { + VHOST_OPS_DEBUG("vhost VQ %u ring restore failed: %d", idx, r); + } + } + + if (!dev->sw_lm_enabled || r < 0) { + /* Connection to the backend is unusable, so let's sync internal * last avail idx to the device used idx. */ virtio_queue_restore_last_avail_idx(vdev, idx); From patchwork Fri Nov 20 18:51:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JCfmfHLN; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5p413q3z9sVH for ; Sat, 21 Nov 2020 06:14:36 +1100 (AEDT) Received: from localhost ([::1]:50342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBre-0007it-4I for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:14:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBbW-0000Rd-Vn for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBbP-0000AP-PO for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898664; 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=O+qiriFl30O5ZK13M3dH3aBYCSEg2kw5TfbYjHT/iYc=; b=JCfmfHLNpjpVSyGVWncCnaULYi7398HU2t8nYjCVLQGMvD2vl/iW7Z2TxBk5rKuuhoij8u qltNX6iCSCPJMFpsrq6VhaxmTMziE7A9JuMj7Etndm1Z6t4uGjfK35EYEznMHxLvC5lfJy 1CJl16f8WQubiUlwuUk3LCGRztrE5ZQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320--iW6dT1CPiib-6aLo2w7YA-1; Fri, 20 Nov 2020 13:57:42 -0500 X-MC-Unique: -iW6dT1CPiib-6aLo2w7YA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA5C21084422; Fri, 20 Nov 2020 18:57:38 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDD7B5C1D5; Fri, 20 Nov 2020 18:57:23 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 26/27] vhost: Add vhost_hdev_can_sw_lm Date: Fri, 20 Nov 2020 19:51:04 +0100 Message-Id: <20201120185105.279030-27-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=63.128.21.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This allows a device to migrate if it meet a few requirements. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index cf000b979f..44a51ccf5e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1529,6 +1529,37 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) event_notifier_cleanup(&vq->masked_notifier); } +static bool vhost_hdev_can_sw_lm(struct vhost_dev *hdev) +{ + const char *cause = NULL; + + if (hdev->features & (VIRTIO_F_IOMMU_PLATFORM)) { + cause = "have iommu"; + } else if (hdev->features & VIRTIO_F_RING_PACKED) { + cause = "is packed"; + } else if (hdev->features & VIRTIO_RING_F_EVENT_IDX) { + cause = "Have event idx"; + } else if (hdev->features & VIRTIO_RING_F_INDIRECT_DESC) { + cause = "Supports indirect descriptors"; + } else if (hdev->nvqs != 2) { + cause = "!= 2 #vq supported"; + } else if (!hdev->vhost_ops->vhost_net_set_backend) { + cause = "cannot pause device"; + } + + if (cause) { + if (!hdev->migration_blocker) { + error_setg(&hdev->migration_blocker, + "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature and %s.", + cause); + } + + return false; + } + + return true; +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout) { @@ -1604,7 +1635,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, }; if (hdev->migration_blocker == NULL) { - if (!vhost_dev_can_log(hdev)) { + if (!vhost_dev_can_log(hdev) && !vhost_hdev_can_sw_lm(hdev) + && hdev->migration_blocker == NULL) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_check()) { From patchwork Fri Nov 20 18:51:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1404078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MSI82BlG; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cd5tb5TFGz9sTR for ; Sat, 21 Nov 2020 06:18:31 +1100 (AEDT) Received: from localhost ([::1]:58754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgBvR-0002sl-Km for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2020 14:18:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBbZ-0000Sy-1w for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27984) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgBbT-0000Bm-JQ for qemu-devel@nongnu.org; Fri, 20 Nov 2020 13:57:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605898670; 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=K8v+fo5FJLI5mUneJtRG5p9f1qblLX12fPi1h8UA2TI=; b=MSI82BlGcPb0YkYZsGlgoAbRUOENMW8LR7b5AT46arhLmS+dKLTHF5WoPTHT2KTw0B5hLV JMe98+LWIN3Fh8lezSgD0UWncjsZgIfAbFoUjidPGS6YMzEpnyToLyqf35HrltRGj/DM7P LSp0WnwPyKuk730fAX1tDJs5ej3Q5lg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-461-_2evQM4sOaKGsMBKkPjsGA-1; Fri, 20 Nov 2020 13:57:48 -0500 X-MC-Unique: _2evQM4sOaKGsMBKkPjsGA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48BCB814411; Fri, 20 Nov 2020 18:57:45 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-88.ams2.redhat.com [10.36.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E4555C1D5; Fri, 20 Nov 2020 18:57:39 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 27/27] vhost: forbid vhost devices logging Date: Fri, 20 Nov 2020 19:51:05 +0100 Message-Id: <20201120185105.279030-28-eperezma@redhat.com> In-Reply-To: <20201120185105.279030-1-eperezma@redhat.com> References: <20201120185105.279030-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Received-SPF: pass client-ip=216.205.24.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Daniel Daly , virtualization@lists.linux-foundation.org, Liran Alon , Eli Cohen , Nitin Shrivastav , Alex Barba , Christophe Fontaine , Juan Quintela , Lee Ballard , Lars Ganrot , Rob Miller , Stefano Garzarella , Howard Cai , Parav Pandit , vm , Salil Mehta , Stephen Finucane , Xiao W Wang , Sean Mooney , Stefan Hajnoczi , Jim Harford , Dmytro Kazantsev , Siwei Liu , Harpreet Singh Anand , Michael Lilja , Max Gurtovoy Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is NOT a commit intended for merge, but for test the patchset. Signed-off-by: Eugenio Pérez --- hw/virtio/vhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 44a51ccf5e..069e5c915d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -79,7 +79,7 @@ static struct vhost_dev *vhost_dev_from_virtio(const VirtIODevice *vdev) static bool vhost_dev_can_log(const struct vhost_dev *hdev) { - return hdev->features & (0x1ULL << VHOST_F_LOG_ALL); + return false; } static void vhost_dev_sync_region(struct vhost_dev *dev,