From nobody Wed May 15 18:36:03 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=1683899581; cv=none; d=zohomail.com; s=zohoarc; b=OrKs5QwGN2KcGX1j7sSFhnKl9/7a+8jJDrkJU5bjqvX3FT/WsJB1pqA3gGnxIAM/TFF7TR/85+TtQdIKUr1GXgBAA3ALBuNPGLzIvQLRwkk2tK4XfPn1131OGC2fvRnV7HmQ2CVOKxN2r7Wd68fvq7/SxCbKQ06QVkVb9NAG0DY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683899581; 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=VUbUhFUIT7zvA0dV/gO0XR4/4OQmYfc2bPvzMXOSlZs=; b=VjmnQsapcD9koewN13/7XO6l8vV9eBXWU4Cl1FvZ2pvCyW97ILRaoNgxgvtJDn3SrBJTUadMnpEAUMKhTQ3+yTTnwY5EQEm4tYNe5jlkM44QQhLf27Xuqd436g+Vtf5ZtvOWqe6ThW1/xzHtM2VTGKfFI/S9WWANwVl3eXZve8k= 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 1683899581155529.1755065825116; Fri, 12 May 2023 06:53:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxTBe-00038L-7P; Fri, 12 May 2023 09:51:58 -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 1pxTBb-000369-8q for qemu-devel@nongnu.org; Fri, 12 May 2023 09:51:55 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pxTBZ-0006SQ-JZ for qemu-devel@nongnu.org; Fri, 12 May 2023 09:51:55 -0400 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2ac88d9edf3so96260151fa.0 for ; Fri, 12 May 2023 06:51:52 -0700 (PDT) Received: from vp-pc.. (109-252-115-147.nat.spd-mgts.ru. [109.252.115.147]) by smtp.gmail.com with ESMTPSA id o7-20020a2e90c7000000b002ad994b0b51sm1744283ljg.16.2023.05.12.06.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 06:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1683899511; x=1686491511; 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=VUbUhFUIT7zvA0dV/gO0XR4/4OQmYfc2bPvzMXOSlZs=; b=u/L/umvslmhgC2EsS2jT93ybtE+BfTS4w/I0Oni+VFgzPVDctFfFzCffDkpUORPlm+ Oh4ocTCB3U3Ia2FPB9DunFwXWNGtvxpKUCBgoM1wtZfDHHM/3zSAwmsGVEjTS5EIqu+a 3YZXga5fbJklERu+4Kd9V+8PgvE1NXmX2Ksp/IJ1TBdMMJiCddglQ0dmHZhPKoGmUL4h 3daqJNBeb7FdWQ9wlsN9TQvcHv2ulN/qxpMNsN7stiWvYhVs2zYNB26FEQK7c7jyHxQj NHc+9h5cLZVuRDYDCw0ErFV+8VOvl2NPTdvCYmduYahBvt+P8Bq6b2n2MaYwTE8Qn7zu iTYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683899511; x=1686491511; 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=VUbUhFUIT7zvA0dV/gO0XR4/4OQmYfc2bPvzMXOSlZs=; b=bKEAE1ILebHx8bBZZtm8iYflkd0MY5I4hZjf0g1IjdkYyYJ41X8gzN2ukvBzgDbnCD 7NIT+mbh4mJbfpkee4eFlTyxXk/k4Rv+d2rVC+kkrG1blyjnmgPIqRRzxq+hdrQygIKo OyLh/z5CDyeT86w6xfTu7JKhtl/X646ZMgeFvdh1cZhaJkrWgtgPvCPPwfVylkrVip46 1RLcxRi0WsGZ49ei5h/YZ5I2zvcLVvlsPhEJJcxtmPJm6MXs8UcLnFiOA0m9kSroquDB zuxynzF8lekt1e/rMk1OCZFoJkBAW+zHs4cnc+LIGc8NE0IqhxCYvy7Dw7+GCUoHsFRY 5GCA== X-Gm-Message-State: AC+VfDwYlpIVCGCV4rrtEO8eRqrgTv8yidCR92uY+Dlvdt026yCkAOSd qcSbhqYtgPHn2KR6WXqlx6Es9g== X-Google-Smtp-Source: ACHHUZ4ojP4VxrmyhKC3Gy0SldrXsjd2T0YeE+jn5+UDDooJkzlUyiHXvPz8F1bl8+iQeAU/Nh4EVg== X-Received: by 2002:a2e:7004:0:b0:2ac:e6d4:2c02 with SMTP id l4-20020a2e7004000000b002ace6d42c02mr4549076ljc.27.1683899511718; Fri, 12 May 2023 06:51:51 -0700 (PDT) From: Viktor Prutyanov To: mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, viktor@daynix.com, yan@daynix.com, yuri.benditovich@daynix.com Subject: [PATCH v3 1/3] virtio-pci: add handling of PCI ATS and Device-TLB enable/disable Date: Fri, 12 May 2023 16:51:20 +0300 Message-Id: <20230512135122.70403-2-viktor@daynix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230512135122.70403-1-viktor@daynix.com> References: <20230512135122.70403-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::229; envelope-from=viktor@daynix.com; helo=mail-lj1-x229.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: 1683899582227100003 Content-Type: text/plain; charset="utf-8" According to PCIe Address Translation Services specification 5.1.3., ATS Control Register has Enable bit to enable/disable ATS. Guest may enable/disable PCI ATS and, accordingly, Device-TLB for the VirtIO PCI device. So, raise/lower a flag and call a trigger function to pass this event to a device implementation. Signed-off-by: Viktor Prutyanov Acked-by: Jason Wang --- hw/virtio/virtio-pci.c | 36 ++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 02fb84a8fa..edbc0daa18 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -716,6 +716,38 @@ virtio_address_space_read(VirtIOPCIProxy *proxy, hwadd= r addr, } } =20 +static void virtio_pci_ats_ctrl_trigger(PCIDevice *pci_dev, bool enable) +{ + VirtIOPCIProxy *proxy =3D VIRTIO_PCI(pci_dev); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); + + vdev->device_iotlb_enabled =3D enable; + + if (k->toggle_device_iotlb) { + k->toggle_device_iotlb(vdev); + } +} + +static void pcie_ats_config_write(PCIDevice *dev, uint32_t address, + uint32_t val, int len) +{ + uint32_t off; + uint16_t ats_cap =3D dev->exp.ats_cap; + + if (!ats_cap || address < ats_cap) { + return; + } + off =3D address - ats_cap; + if (off >=3D PCI_EXT_CAP_ATS_SIZEOF) { + return; + } + + if (range_covers_byte(off, len, PCI_ATS_CTRL + 1)) { + virtio_pci_ats_ctrl_trigger(dev, !!(val & PCI_ATS_CTRL_ENABLE)); + } +} + static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val, int len) { @@ -729,6 +761,10 @@ static void virtio_write_config(PCIDevice *pci_dev, ui= nt32_t address, pcie_cap_flr_write_config(pci_dev, address, val, len); } =20 + if (proxy->flags & VIRTIO_PCI_FLAG_ATS) { + pcie_ats_config_write(pci_dev, address, val, len); + } + if (range_covers_byte(address, len, PCI_COMMAND)) { if (!(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { virtio_set_disabled(vdev, true); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index f6b38f7e9c..af86ed7249 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -155,6 +155,7 @@ struct VirtIODevice QLIST_HEAD(, VirtQueue) *vector_queues; QTAILQ_ENTRY(VirtIODevice) next; EventNotifier config_notifier; + bool device_iotlb_enabled; }; =20 struct VirtioDeviceClass { @@ -212,6 +213,7 @@ struct VirtioDeviceClass { const VMStateDescription *vmsd; bool (*primary_unplug_pending)(void *opaque); struct vhost_dev *(*get_vhost)(VirtIODevice *vdev); + void (*toggle_device_iotlb)(VirtIODevice *vdev); }; =20 void virtio_instance_init_common(Object *proxy_obj, void *data, --=20 2.35.1 From nobody Wed May 15 18:36:03 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=1683899606; cv=none; d=zohomail.com; s=zohoarc; b=NPbp0uCzWdnXT2md2wzRIPjgfwELGICXXhefvG86hU6ek4uxkuNAhsWx8H/UlaU5nDaxK/NsUCkcoP4eUe/IMkx0mTjze/rOwcfRIvttJ6vwnxrjT9F8g/HTt9Ct/3fUJTt6Et+4WwyZ/4sNM/YIB6XRKA5E9o2gMYtyR+Yftnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683899606; 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=IksVQBM2UDb2f/oZ2W8mYBornY1QQeR85JYcDBnnKbg=; b=ANrK+YiaKyZofC96elDLfcqw8AOwnVYHDFXhQkHu76Z+6BqfWJEtcNEB9WxQBN2ZQZOJ9x79NcflrFOXprlPOEHW1OF1vGCzDEuBCSGwiwLwzpwZjcT+Ki2iwAB5n8DzRYvSGUjoCHJHy/VwW6MuUrrTf4tDBdlFAuqRZuBo1hk= 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 1683899606485693.2371394424409; Fri, 12 May 2023 06:53:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxTBg-0003CR-MH; Fri, 12 May 2023 09:52:00 -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 1pxTBc-000389-Hl for qemu-devel@nongnu.org; Fri, 12 May 2023 09:51:56 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pxTBa-0006Sk-1d for qemu-devel@nongnu.org; Fri, 12 May 2023 09:51:56 -0400 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2ac82b07eb3so101117691fa.1 for ; Fri, 12 May 2023 06:51:53 -0700 (PDT) Received: from vp-pc.. (109-252-115-147.nat.spd-mgts.ru. [109.252.115.147]) by smtp.gmail.com with ESMTPSA id o7-20020a2e90c7000000b002ad994b0b51sm1744283ljg.16.2023.05.12.06.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 06:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1683899512; x=1686491512; 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=IksVQBM2UDb2f/oZ2W8mYBornY1QQeR85JYcDBnnKbg=; b=zZW/DtTV9XIU4GoTyFQnCotMI78+RKsoFpNcS8hnhZqRnxIjdT73KEKRCaBz/V6gbx kfmBT/zt/YqJglK5mBeJiMV+35VbS12TBkO6JCFmsk1eMIYi56wR3nT0EZDebWkYW21z 64z4Q+2Hdv/WU/grssrVEY6h9U9gwI3xOPXAwByL0+e25v8YlzNCN5jxBxoj/UiqWPZM 2m7+Xt6Wgeor9Sd017KCLZ+pn3Xs6JuojodU5L63uWAlPn8EgrfsWif9Xr4BzX//GeiO RIQAnOOunr/oy+KQlYhlD76G+GBidGIn8t1jc0faqkL2JMMqlWzmBYVogqrVOurKyYSn 0UaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683899512; x=1686491512; 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=IksVQBM2UDb2f/oZ2W8mYBornY1QQeR85JYcDBnnKbg=; b=gSIQu0afpGhQxc0bSPbuEKJfuLsNS8MxAghn9ywqCdqSltB8V5XgihvxpxIuzfLkoS XQ/RvRNRyCGqvkIjHRV90rHMRLe//BMhmKi2G4fekjweX7Uh5qEGILdB7jvKk9Ke+FXo 4ZBjvcabTAAf5g6UGQHV2gVBKNxx1vdjimpiNPvHHq2h05Chjgm+W7bMD8W2e5w32AwZ pt42MhbRNZr/RZkVQ3WqzlENLAIycQouyNEWYylIGqTcOr46zc3gtk6YlN/Z9GfWz0jE X+sGthiOB9XwoJNFoPPF3TiJjv7Y+BT1bAXwHMinKE6Ou0WWiSpkUZfvk8koE3KWp9Pv fK1A== X-Gm-Message-State: AC+VfDwJHzFpo0K/zur/fFyBXVPqEH8IPRFS564/V2TXMkE9NxUCD8uo e+YdbZv5Z3zpP4oIJfToqedA+A== X-Google-Smtp-Source: ACHHUZ4hm69LXBoSvIiz1kqUNrk2S2ZmdPLGQvUNv81LITB9LQaXUAUXtJsn3axLysIE7fgVKCNhnw== X-Received: by 2002:a2e:894c:0:b0:2ad:d6cd:efe0 with SMTP id b12-20020a2e894c000000b002add6cdefe0mr756638ljk.37.1683899512502; Fri, 12 May 2023 06:51:52 -0700 (PDT) From: Viktor Prutyanov To: mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, viktor@daynix.com, yan@daynix.com, yuri.benditovich@daynix.com Subject: [PATCH v3 2/3] vhost: register and change IOMMU flag depending on Device-TLB state Date: Fri, 12 May 2023 16:51:21 +0300 Message-Id: <20230512135122.70403-3-viktor@daynix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230512135122.70403-1-viktor@daynix.com> References: <20230512135122.70403-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::235; envelope-from=viktor@daynix.com; helo=mail-lj1-x235.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: 1683899608466100003 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 --- hw/virtio/vhost-backend.c | 6 ++++++ hw/virtio/vhost.c | 30 ++++++++++++++++++------------ include/hw/virtio/vhost-backend.h | 3 +++ include/hw/virtio/vhost.h | 1 + 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 8e581575c9..d39bfefd2d 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -297,6 +297,11 @@ static void vhost_kernel_set_iotlb_callback(struct vho= st_dev *dev, qemu_set_fd_handler((uintptr_t)dev->opaque, NULL, NULL, NULL); } =20 +static void vhost_kernel_toggle_device_iotlb(struct vhost_dev *dev) +{ + vhost_toggle_device_iotlb(dev); +} + const VhostOps kernel_ops =3D { .backend_type =3D VHOST_BACKEND_TYPE_KERNEL, .vhost_backend_init =3D vhost_kernel_init, @@ -328,6 +333,7 @@ const VhostOps kernel_ops =3D { .vhost_vsock_set_running =3D vhost_kernel_vsock_set_running, .vhost_set_iotlb_callback =3D vhost_kernel_set_iotlb_callback, .vhost_send_device_iotlb_msg =3D vhost_kernel_send_device_iotlb_ms= g, + .vhost_toggle_device_iotlb =3D vhost_kernel_toggle_device_iotlb, }; #endif =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 746d130c74..41c9fbf286 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,19 @@ static void vhost_iommu_region_del(MemoryListener *lis= tener, } } =20 +void vhost_toggle_device_iotlb(struct vhost_dev *dev) +{ + struct vhost_iommu *iommu; + + QLIST_FOREACH(iommu, &dev->iommu_list, iommu_next) { + memory_region_unregister_iommu_notifier(iommu->mr, &iommu->n); + iommu->n.notifier_flags =3D dev->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-backend.h b/include/hw/virtio/vhost-ba= ckend.h index ec3fbae58d..10a3c36b4b 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -133,6 +133,8 @@ typedef int (*vhost_set_config_call_op)(struct vhost_de= v *dev, =20 typedef void (*vhost_reset_status_op)(struct vhost_dev *dev); =20 +typedef void (*vhost_toggle_device_iotlb_op)(struct vhost_dev *dev); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -181,6 +183,7 @@ typedef struct VhostOps { vhost_force_iommu_op vhost_force_iommu; vhost_set_config_call_op vhost_set_config_call; vhost_reset_status_op vhost_reset_status; + vhost_toggle_device_iotlb_op vhost_toggle_device_iotlb; } VhostOps; =20 int vhost_backend_update_device_iotlb(struct vhost_dev *dev, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index a52f273347..785832ed46 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(struct vhost_dev *dev); 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.35.1 From nobody Wed May 15 18:36:03 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=1683899570; cv=none; d=zohomail.com; s=zohoarc; b=bHL71bf7To3s7ByUGaIk3VKkMzpJEosi8lda0rt+E/6VFoi8hb55M9k5TQBEpbw/W8umAsA0+K+mwZybXsvFfhbOQYR+jtB/MeiWJtjbn9Q/QxfEY1XoTmVXYQnbnh+6XzSunfNZtncpF8zXoALAS1crH2F0NnjIRhokmqMU7ag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683899570; 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=GiU1Bp9osy3apaC7ea53hTYiSGjaET77MlLPjFYHdzw=; b=Jch0CYloieu9uj7g0rI7VO0g9IrjNiV+/vzDaO7TfmhC2bLEG5ngMyS1Uv2ooxxZidGhwLlWwGMPfXeyXa9goh/x+Bwk5ZvzEoSxFPFHsSdm3w0VoucP/0rfQx3E8o8HJmibOh3SLHgUQ3L3xCYPPBDAkQsdQnTxaSFSPMwlGws= 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 168389957035136.41587913827607; Fri, 12 May 2023 06:52:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxTBf-00038P-EK; Fri, 12 May 2023 09:52:00 -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 1pxTBc-00037l-7L for qemu-devel@nongnu.org; Fri, 12 May 2023 09:51:56 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pxTBa-0006Sy-HQ for qemu-devel@nongnu.org; Fri, 12 May 2023 09:51:55 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ac785015d6so106025081fa.0 for ; Fri, 12 May 2023 06:51:54 -0700 (PDT) Received: from vp-pc.. (109-252-115-147.nat.spd-mgts.ru. [109.252.115.147]) by smtp.gmail.com with ESMTPSA id o7-20020a2e90c7000000b002ad994b0b51sm1744283ljg.16.2023.05.12.06.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 06:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1683899513; x=1686491513; 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=GiU1Bp9osy3apaC7ea53hTYiSGjaET77MlLPjFYHdzw=; b=X/5UMIhpHQmiakE92CYwcQsCqUwFKFSXZvLSv1pLuGvo3v6YleKcO1yIfPHPMVYro9 uZ02o5LG12683nakfgVG7iDbMbVU9XtaazkeP2brgBPMJ/UQf4ckK9josoXzQY1eCOT/ 5nSUyk9/GtvfFe3UR+TkVq3NNTefUnDgG/xfQnw1I91NrHxKGeZzvtzWz2DhCMBaUK3m ICOL56gvoFzPsRHTzaubF/hezU+93N2WTl3Qefe027EPCC9Nb3+iaBGYSgSwS/PKNv1s OvY3e4+gK2FvJ6NHHu8ThBXbILJTXyUgtkjL3rW7dySiHxAMysF5D9mUrvy9pxPa+Lmu yV8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683899513; x=1686491513; 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=GiU1Bp9osy3apaC7ea53hTYiSGjaET77MlLPjFYHdzw=; b=JgdUCc0OUeeXgSwE8H89a4+B23pB3KL/xDpHDt9V/o5xbuORaZSoH1RrcBVkVRoZPj Lf34AtUVxeg4oMVEglysvxtndTtZ9OltIF0VNIk2TyTZ5OHuHp3NCF0iR8VJQKeSeus4 GjUObKeqStiLEhwAK4+f/Nwscx+t/OxSoVoxPx1kGDEdz4/TQiedxEWlYOnssp8OCbyw RwW1CeKc1d/jfcAH5K8Yyeol6VraR5OjgSBikERypWKI5Aqt4n8VJgw11VrS7rOOKXm1 yQd1WjVyIw7TCO1N62EpogmVJfTaAg0eSfPK1Y8u7zIVINvsP+iVSqd+KtKX4iJvqBQx 9Iaw== X-Gm-Message-State: AC+VfDwYS5URW3di9BLdqwaxFCPwk1+NVQ9BFsXzXtMHYHZB4dMY1GaY 7VFa7B4Uofhbbnt9u+Ca+PT1BQ== X-Google-Smtp-Source: ACHHUZ79eUJK/m9h3Z+oNYuIYFucdSyGXQCHshr8sDuo4yilnBmAaVRFH2svx27MJkzu2jScdYOItQ== X-Received: by 2002:a2e:3314:0:b0:2a8:b27f:b721 with SMTP id d20-20020a2e3314000000b002a8b27fb721mr4077251ljc.29.1683899513187; Fri, 12 May 2023 06:51:53 -0700 (PDT) From: Viktor Prutyanov To: mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, viktor@daynix.com, yan@daynix.com, yuri.benditovich@daynix.com Subject: [PATCH v3 3/3] virtio-net: pass Device-TLB enable/disable events to vhost Date: Fri, 12 May 2023 16:51:22 +0300 Message-Id: <20230512135122.70403-4-viktor@daynix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230512135122.70403-1-viktor@daynix.com> References: <20230512135122.70403-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::233; envelope-from=viktor@daynix.com; helo=mail-lj1-x233.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: 1683899572390100003 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 --- hw/net/vhost_net.c | 11 +++++++++++ hw/net/virtio-net.c | 7 +++++++ include/net/vhost_net.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index c4eecc6f36..df5c312993 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -552,6 +552,17 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t = mtu) return vhost_ops->vhost_net_set_mtu(&net->dev, mtu); } =20 +void vhost_net_toggle_device_iotlb(struct vhost_dev *dev) +{ + const VhostOps *vhost_ops =3D dev->vhost_ops; + + if (!vhost_ops->vhost_toggle_device_iotlb) { + return; + } + + vhost_ops->vhost_toggle_device_iotlb(dev); +} + void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc, int vq_index) { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 447f669921..faba810db1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3844,6 +3844,12 @@ static struct vhost_dev *virtio_net_get_vhost(VirtIO= Device *vdev) return &net->dev; } =20 +static void virtio_net_toggle_device_iotlb(VirtIODevice *vdev) +{ + if (vdev->vhost_started) + vhost_net_toggle_device_iotlb(virtio_net_get_vhost(vdev)); +} + static const VMStateDescription vmstate_virtio_net =3D { .name =3D "virtio-net", .minimum_version_id =3D VIRTIO_NET_VM_VERSION, @@ -3949,6 +3955,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 virtio_net_toggle_device_iotlb; } =20 static const TypeInfo virtio_net_info =3D { diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index c37aba35e6..28d93ea8c5 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -56,4 +56,6 @@ int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetCl= ientState *nc, int vq_index); =20 void vhost_net_save_acked_features(NetClientState *nc); + +void vhost_net_toggle_device_iotlb(struct vhost_dev *dev); #endif --=20 2.35.1