From nobody Wed May 15 19:03:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1687770818; cv=none; d=zohomail.com; s=zohoarc; b=OQFGNDGTscUtH6ClRJMw6yunES36frL/aR+BjtgkcPOcg2Xd2eT9CX3HbmfaZiwuwNHoWYM4VPvl+XVbcFLOifmvGmLQy2OGL8YCqWgrKBWFgzJo8IHiM6m8Xl1y8lhUxZU23I1wUt/xyINeMoDhaR8d1f19fMp7XEnpwGy06o8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687770818; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=65D9pazVGNczpCkR9CBdv0sj2pWpFpF69/C0zCu5CI8=; b=nYq3ubDgyrjORnXpm41yOJATjXGo3sJWM2TLm3kP+rSJdt4ywpggy6HOHz0PgCuzgcrn+9Ot+ZGRQruJQsHiGc9O7elttpxzfJlE3sg5Bg+nm4t2dYjNbv1lMShpM1kLCcD11H5iEy8CLnGnzLXBJQTCvO4PqQmPCf6N29ySmQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687770818665408.2231726967743; Mon, 26 Jun 2023 02:13:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDiHi-0002Ea-Ns; Mon, 26 Jun 2023 05:13:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDiHZ-0002D3-Hv for qemu-devel@nongnu.org; Mon, 26 Jun 2023 05:13:14 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qDiHX-0006A6-Dt for qemu-devel@nongnu.org; Mon, 26 Jun 2023 05:13:13 -0400 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-51d80c5c834so3266313a12.1 for ; Mon, 26 Jun 2023 02:13:09 -0700 (PDT) Received: from localhost.localdomain.cc ([62.4.35.38]) by smtp.gmail.com with ESMTPSA id i23-20020a50fc17000000b0051c7b5692easm2597693edr.7.2023.06.26.02.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 02:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1687770789; x=1690362789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=65D9pazVGNczpCkR9CBdv0sj2pWpFpF69/C0zCu5CI8=; b=h4UqSeHsJWnMGy4TXB0ayW1TI5HPZcYujGcUS3se2K5hUz3FOr0wbRSAYBI8++Yp5o o8nshl5u8R4Fyb5Iwfg/VWujO43cbDjaE9/V4Vh4TOAiyC3RzWs6Ks+4QtX7oZJXX9bi DC3+je5Ux4Er+wpUMsJfrHxKnJBE2orGCjsptYhPBDdexFhVgBdWgInrB+4Ub7SywyoV JEl9Ai3Vea5jsHe5FDb7xXuqy7NpS712CFkzZrW+ZcPpYz0y0Cn4YhA76GXFpGFeP5IZ 66W8JTPsYF2PO5PdPWXga8NC3CpG2TVHB2CoIYLavwbW4sOOET13V3BmuNqiE01XAioK gVqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687770789; x=1690362789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=65D9pazVGNczpCkR9CBdv0sj2pWpFpF69/C0zCu5CI8=; b=dtn6imajwcMbGh9dhHFtHpdFbSDxBbTVdplsFuFtUHW6G1ZBvlLHns0Al/jLyCD3pw cCTuPjcOvgh0F+AHYY1kADyD2ihlfbmHeSHRqlyqTJmIZwq4QbxqL7zNYIaEX6zyAo7z faAelBN4hS6UGk9GU4aauKz3bPxcKOAZCCt195IksVwbrlQqXkNKtE21HqU/U1ziXo2e mGDD5op13mXFv/uC4/tbiB87W1YlncNc54uaG9j4/RBe/4Jw4q2Mt1Rj8+cFrOkkJ1w+ nuM1jZie17bydqMZNsfDE3tQ06Dabmog9w/QBb2q8Gfyv2GimSeQyr25tpOaNxfq6ocE jykg== X-Gm-Message-State: AC+VfDz0vXoXWfI6qjqSvGf/KcN2AqWYVwxcD/UskwkGyyeWEVkSHsXU 6UG1SR/BnWB+fU4G/KBWgVZVWw== X-Google-Smtp-Source: ACHHUZ65v69Gl+CVc1ylg9r0sksEOv1dg+OQafM120nj3A/IfU9k1ZjElZbT9kpcPZ8n1F3DzGnDEg== X-Received: by 2002:a05:6402:50cd:b0:516:a1d5:846f with SMTP id h13-20020a05640250cd00b00516a1d5846fmr30843688edb.1.1687770788847; Mon, 26 Jun 2023 02:13:08 -0700 (PDT) From: Viktor Prutyanov To: mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, yan@daynix.com, yuri.benditovich@daynix.com, Viktor Prutyanov Subject: [PATCH v5 1/2] vhost: register and change IOMMU flag depending on Device-TLB state Date: Mon, 26 Jun 2023 12:12:57 +0300 Message-Id: <20230626091258.24453-2-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230626091258.24453-1-viktor@daynix.com> References: <20230626091258.24453-1-viktor@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::52c; envelope-from=viktor@daynix.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1687770820712100005 Content-Type: text/plain; charset="utf-8" The guest can disable or never enable Device-TLB. In these cases, it can't be used even if enabled in QEMU. So, check Device-TLB state before registering IOMMU notifier and select unmap flag depending on that. Also, implement a way to change IOMMU notifier flag if Device-TLB state is changed. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D2001312 Signed-off-by: Viktor Prutyanov Acked-by: Jason Wang --- hw/virtio/vhost-stub.c | 4 ++++ hw/virtio/vhost.c | 38 ++++++++++++++++++++++++++------------ include/hw/virtio/vhost.h | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost-stub.c b/hw/virtio/vhost-stub.c index c175148fce..aa858ef3fb 100644 --- a/hw/virtio/vhost-stub.c +++ b/hw/virtio/vhost-stub.c @@ -15,3 +15,7 @@ bool vhost_user_init(VhostUserState *user, CharBackend *c= hr, Error **errp) void vhost_user_cleanup(VhostUserState *user) { } + +void vhost_toggle_device_iotlb(VirtIODevice *vdev) +{ +} diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 23da579ce2..e48507b5a1 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -781,7 +781,6 @@ static void vhost_iommu_region_add(MemoryListener *list= ener, Int128 end; int iommu_idx; IOMMUMemoryRegion *iommu_mr; - int ret; =20 if (!memory_region_is_iommu(section->mr)) { return; @@ -796,7 +795,9 @@ static void vhost_iommu_region_add(MemoryListener *list= ener, iommu_idx =3D memory_region_iommu_attrs_to_index(iommu_mr, MEMTXATTRS_UNSPECIFIED); iommu_notifier_init(&iommu->n, vhost_iommu_unmap_notify, - IOMMU_NOTIFIER_DEVIOTLB_UNMAP, + dev->vdev->device_iotlb_enabled ? + IOMMU_NOTIFIER_DEVIOTLB_UNMAP : + IOMMU_NOTIFIER_UNMAP, section->offset_within_region, int128_get64(end), iommu_idx); @@ -804,16 +805,8 @@ static void vhost_iommu_region_add(MemoryListener *lis= tener, iommu->iommu_offset =3D section->offset_within_address_space - section->offset_within_region; iommu->hdev =3D dev; - ret =3D memory_region_register_iommu_notifier(section->mr, &iommu->n, = NULL); - if (ret) { - /* - * Some vIOMMUs do not support dev-iotlb yet. If so, try to use t= he - * UNMAP legacy message - */ - iommu->n.notifier_flags =3D IOMMU_NOTIFIER_UNMAP; - memory_region_register_iommu_notifier(section->mr, &iommu->n, - &error_fatal); - } + memory_region_register_iommu_notifier(section->mr, &iommu->n, + &error_fatal); QLIST_INSERT_HEAD(&dev->iommu_list, iommu, iommu_next); /* TODO: can replay help performance here? */ } @@ -841,6 +834,27 @@ static void vhost_iommu_region_del(MemoryListener *lis= tener, } } =20 +void vhost_toggle_device_iotlb(VirtIODevice *vdev) +{ + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *dev; + struct vhost_iommu *iommu; + + if (vdev->vhost_started) { + dev =3D vdc->get_vhost(vdev); + } else { + return; + } + + QLIST_FOREACH(iommu, &dev->iommu_list, iommu_next) { + memory_region_unregister_iommu_notifier(iommu->mr, &iommu->n); + iommu->n.notifier_flags =3D vdev->device_iotlb_enabled ? + IOMMU_NOTIFIER_DEVIOTLB_UNMAP : IOMMU_NOTIFIER_UNMAP; + memory_region_register_iommu_notifier(iommu->mr, &iommu->n, + &error_fatal); + } +} + static int vhost_virtqueue_set_addr(struct vhost_dev *dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index f7f10c8fb7..6a173cb9fa 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -320,6 +320,7 @@ bool vhost_has_free_slot(void); int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); =20 +void vhost_toggle_device_iotlb(VirtIODevice *vdev); int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int writ= e); =20 int vhost_virtqueue_start(struct vhost_dev *dev, struct VirtIODevice *vdev, --=20 2.21.0 From nobody Wed May 15 19:03:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1687770818; cv=none; d=zohomail.com; s=zohoarc; b=ksEck1Kkd5S0GxfQtmTBgm3nGFgoB1d8tyc3Udk5ahVqnF82omX4TKMVqT3FE8Qp05AUWzeee+8zOgjH2ibksoL0cTp55IL/nOHgvvUBUb0ewl8Qx9XZqu/y6QsOGoFzKBezD0kDgVyxXBfV4ySEDFVRxvkKzEsmT6qwqmKAtyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687770818; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CIcO5U8ojcl1qIugLnuh0W+nIgo2jy6fb1R5j5z42L4=; b=Lse9WveLz/0ZF7gUdDYcWVHxN86wAUADatZM7q5i14GZVT6aklDTbSxkffkeU3OxSvq+mjMs+EEJkeceH8gXf0XADSvPLJGT5jHX0XUOoKtcjhDAMx9AhA2DQi+WDy+bFSkbB3aqqovgC84OL9xmRKuMMyY0dgRM6+i3OczkcGo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687770818215371.0697618274502; Mon, 26 Jun 2023 02:13:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDiHh-0002Db-6N; Mon, 26 Jun 2023 05:13:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDiHZ-0002D1-6z for qemu-devel@nongnu.org; Mon, 26 Jun 2023 05:13:13 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qDiHX-0006AE-Iw for qemu-devel@nongnu.org; Mon, 26 Jun 2023 05:13:12 -0400 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-51cb40f13f6so3399660a12.2 for ; Mon, 26 Jun 2023 02:13:11 -0700 (PDT) Received: from localhost.localdomain.cc ([62.4.35.38]) by smtp.gmail.com with ESMTPSA id i23-20020a50fc17000000b0051c7b5692easm2597693edr.7.2023.06.26.02.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 02:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1687770790; x=1690362790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CIcO5U8ojcl1qIugLnuh0W+nIgo2jy6fb1R5j5z42L4=; b=5qRLUwSTnkn3mtIOoxElfwCiHtC9mFu+BqsQIuVhoNf0nVb/ibBg4+qMvvem4srScc lKSuVHh3s4aU7voLW/gAw1KtG5vz7xcP3j2DVeyd1oQLtqdP+5I8FaTm1JNb9OmzERbW 5/Te4eeN7mYE5iyjF0iNY2LKgqQXM50IV8f7oacuolGOrJLlQAJGN7RZz9QzCdtqvaZW mbx2KSw6Qj6N4u+IBWUx7SowJU8jaWyTU7wKSgtbPFiMmF+j0r8xpf+O5a0fz3nNdjEf ZRZdpvObysgggCvfKok2Ce6mdXH7amXNKM0oMs9h57f3QIWhvCrCGdMsLShYYPb6d5Uv oX5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687770790; x=1690362790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CIcO5U8ojcl1qIugLnuh0W+nIgo2jy6fb1R5j5z42L4=; b=ivuaTyTYb77sfnduEwyDySN9ADT/eqo9lRDydCmFyxLcv8IDxsym/lt3kGYqMSwHuy T1jnkxwTh23CYmhwXMxrwM6YwPli4q3RME2W3KQzmJVP0U7fa+ia66o0Xj1Unse45zNs YJfBRosqqPGuXaMkq0blav7y3O2r+0e8++hNviDKFTWcEcgqhNO4Ys6C5ThJkN7bbdDr /Sew+p95FHz+GzSUGTD2wQeban+PMX0vkW9l1LObp4gM5HrNrItHMuKgMYTO9Z4njTqF +fL2wqw6UN1sD4zKvpmQxTHsJGJrVpLRThCpacxStYyryoS75Mf+tB8EQafKOo8/5OlX AAkw== X-Gm-Message-State: AC+VfDxHsaUw9TE9ubiSzb1P384Jk3CwvFJXQiFstZLFznvD3aTe/1cj 2xuTekiQjV5qnr+EwRvFFHIzUQ== X-Google-Smtp-Source: ACHHUZ5QXIRcLrPUjp6bh0dX7rJkrBabmO8hHqmI16DYZHANcRs3s0MpEO6GvAq5UVdVA326rg9aZA== X-Received: by 2002:aa7:d058:0:b0:51d:9f6b:1b96 with SMTP id n24-20020aa7d058000000b0051d9f6b1b96mr556314edo.40.1687770789871; Mon, 26 Jun 2023 02:13:09 -0700 (PDT) From: Viktor Prutyanov To: mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, yan@daynix.com, yuri.benditovich@daynix.com, Viktor Prutyanov Subject: [PATCH v5 2/2] virtio-net: pass Device-TLB enable/disable events to vhost Date: Mon, 26 Jun 2023 12:12:58 +0300 Message-Id: <20230626091258.24453-3-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230626091258.24453-1-viktor@daynix.com> References: <20230626091258.24453-1-viktor@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::536; envelope-from=viktor@daynix.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1687770819009100001 Content-Type: text/plain; charset="utf-8" If vhost is enabled for virtio-net, Device-TLB enable/disable events must be passed to vhost for proper IOMMU unmap flag selection. Signed-off-by: Viktor Prutyanov Acked-by: Jason Wang --- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6df6b7329d..30497c00b5 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3951,6 +3951,7 @@ static void virtio_net_class_init(ObjectClass *klass,= void *data) vdc->vmsd =3D &vmstate_virtio_net_device; vdc->primary_unplug_pending =3D primary_unplug_pending; vdc->get_vhost =3D virtio_net_get_vhost; + vdc->toggle_device_iotlb =3D vhost_toggle_device_iotlb; } =20 static const TypeInfo virtio_net_info =3D { --=20 2.21.0