From nobody Sun May 5 11:29:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153204764594586.06608560331881; Thu, 19 Jul 2018 17:47:25 -0700 (PDT) Received: from localhost ([::1]:45921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgJZs-0008Fe-ST for importer@patchew.org; Thu, 19 Jul 2018 20:47:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgJYA-0007Q1-KK for qemu-devel@nongnu.org; Thu, 19 Jul 2018 20:45:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgJY9-0003dt-LT for qemu-devel@nongnu.org; Thu, 19 Jul 2018 20:45:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43986 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgJY9-0003dh-F2 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 20:45:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 034F240778BB; Fri, 20 Jul 2018 00:45:37 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-42.pek2.redhat.com [10.72.12.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFDB6111E40B; Fri, 20 Jul 2018 00:45:34 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 20 Jul 2018 08:45:28 +0800 Message-Id: <1532047529-17961-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1532047529-17961-1-git-send-email-jasowang@redhat.com> References: <1532047529-17961-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 20 Jul 2018 00:45:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 20 Jul 2018 00:45:37 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 1/2] e1000e: Prevent MSI/MSI-X storms X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jan Kiszka Only signal MSI/MSI-X events on rising edges. So far we re-triggered the interrupt sources even if the guest did no consumed the pending one, easily causing interrupt storms. Issue was observable with Linux 4.16 e1000e driver when MSI-X was used. Vector 2 was causing interrupt storms after the driver activated the device. Signed-off-by: Jan Kiszka Signed-off-by: Jason Wang --- hw/net/e1000e_core.c | 11 +++++++++++ hw/net/e1000e_core.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 9504891..2a221c2 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -2023,6 +2023,7 @@ e1000e_msix_notify_one(E1000ECore *core, uint32_t cau= se, uint32_t int_cfg) effective_eiac =3D core->mac[EIAC] & cause; =20 core->mac[ICR] &=3D ~effective_eiac; + core->msi_causes_pending &=3D ~effective_eiac; =20 if (!(core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) { core->mac[IMS] &=3D ~effective_eiac; @@ -2119,6 +2120,13 @@ e1000e_send_msi(E1000ECore *core, bool msix) { uint32_t causes =3D core->mac[ICR] & core->mac[IMS] & ~E1000_ICR_ASSER= TED; =20 + core->msi_causes_pending &=3D causes; + causes ^=3D core->msi_causes_pending; + if (causes =3D=3D 0) { + return; + } + core->msi_causes_pending |=3D causes; + if (msix) { e1000e_msix_notify(core, causes); } else { @@ -2156,6 +2164,9 @@ e1000e_update_interrupt_state(E1000ECore *core) core->mac[ICS] =3D core->mac[ICR]; =20 interrupts_pending =3D (core->mac[IMS] & core->mac[ICR]) ? true : fals= e; + if (!interrupts_pending) { + core->msi_causes_pending =3D 0; + } =20 trace_e1000e_irq_pending_interrupts(core->mac[ICR] & core->mac[IMS], core->mac[ICR], core->mac[IMS]); diff --git a/hw/net/e1000e_core.h b/hw/net/e1000e_core.h index 7d8ff41..63a1551 100644 --- a/hw/net/e1000e_core.h +++ b/hw/net/e1000e_core.h @@ -109,6 +109,8 @@ struct E1000Core { NICState *owner_nic; PCIDevice *owner; void (*owner_start_recv)(PCIDevice *d); + + uint32_t msi_causes_pending; }; =20 void --=20 2.7.4 From nobody Sun May 5 11:29:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532047660304676.4783486166117; Thu, 19 Jul 2018 17:47:40 -0700 (PDT) Received: from localhost ([::1]:45922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgJa7-0008JE-30 for importer@patchew.org; Thu, 19 Jul 2018 20:47:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgJYD-0007RS-VW for qemu-devel@nongnu.org; Thu, 19 Jul 2018 20:45:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgJYC-0003gM-UH for qemu-devel@nongnu.org; Thu, 19 Jul 2018 20:45:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36350 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgJYC-0003g8-On; Thu, 19 Jul 2018 20:45:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 409CD81A88DE; Fri, 20 Jul 2018 00:45:40 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-42.pek2.redhat.com [10.72.12.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FC3C111E40B; Fri, 20 Jul 2018 00:45:37 +0000 (UTC) From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 20 Jul 2018 08:45:29 +0800 Message-Id: <1532047529-17961-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1532047529-17961-1-git-send-email-jasowang@redhat.com> References: <1532047529-17961-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 20 Jul 2018 00:45:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 20 Jul 2018 00:45:40 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 2/2] tap: fix memory leak on success to create a tap device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Yunjian Wang , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yunjian Wang The memory leak on success to create a tap device. And the nfds and nvhosts may not be the same and need to be processed separately. Fixes: 07825977 ("tap: fix memory leak on failure to create a multiqueue ta= p device") Fixes: 264986e2 ("tap: multiqueue support") Cc: qemu-stable@nongnu.org Signed-off-by: Yunjian Wang Signed-off-by: Jason Wang --- net/tap.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2126f48..cc8525f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -805,7 +805,8 @@ int net_init_tap(const Netdev *netdev, const char *name, } else if (tap->has_fds) { char **fds; char **vhost_fds; - int nfds, nvhosts; + int nfds =3D 0, nvhosts =3D 0; + int ret =3D 0; =20 if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || @@ -825,6 +826,7 @@ int net_init_tap(const Netdev *netdev, const char *name, if (nfds !=3D nvhosts) { error_setg(errp, "The number of fds passed does not match " "the number of vhostfds passed"); + ret =3D -1; goto free_fail; } } @@ -833,6 +835,7 @@ int net_init_tap(const Netdev *netdev, const char *name, fd =3D monitor_fd_param(cur_mon, fds[i], &err); if (fd =3D=3D -1) { error_propagate(errp, err); + ret =3D -1; goto free_fail; } =20 @@ -843,6 +846,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd)) { error_setg(errp, "vnet_hdr not consistent across given tap fds"); + ret =3D -1; goto free_fail; } =20 @@ -852,21 +856,21 @@ int net_init_tap(const Netdev *netdev, const char *na= me, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); + ret =3D -1; goto free_fail; } } - g_free(fds); - g_free(vhost_fds); - return 0; =20 free_fail: + for (i =3D 0; i < nvhosts; i++) { + g_free(vhost_fds[i]); + } for (i =3D 0; i < nfds; i++) { g_free(fds[i]); - g_free(vhost_fds[i]); } g_free(fds); g_free(vhost_fds); - return -1; + return ret; } else if (tap->has_helper) { if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) { --=20 2.7.4