From patchwork Fri Apr 25 15:28:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 884386 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp4027006wrs; Fri, 25 Apr 2025 08:34:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUyeTVhEcKtZP2Dum4y8UHWesnQtZYnEHpz/n2+f7ODartfM/Zrvb6h60oPSO0SVYYj2s2Pyg==@linaro.org X-Google-Smtp-Source: AGHT+IGtOKCEdhur+kzMQ4A38FMPjG2Kt+zzgeYuYNjNkKv9RHOgXksWAK0EL7/Uc9Ixh8dnZ/pQ X-Received: by 2002:a05:6214:768:b0:6ec:edf9:4658 with SMTP id 6a1803df08f44-6f4cb9d218emr54576126d6.18.1745595247155; Fri, 25 Apr 2025 08:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1745595247; cv=none; d=google.com; s=arc-20240605; b=T84eU6sT6IK2T96L/Kv03HjwFEIB+kVf16MEAmG2HZlSh2rxgkCWXCN2WFv/sV8dyw HlG6000UpB2M1YKcsp2fpUSzq5o8FP/jMae+zXocoFJqb8LL/+1ghhEp49z0oHFIOumx kcvDhqT2nIVOYsBjGHaCvrCSz6KbivE4WQMEEShLbRL/Yk+8Y5SjqSF1Io3IhGajHvs+ GlMzogpE4kOsagrqfyOF/l8e/9QQGXHyjQeOULuuliWOXDHXXXom5w14cZ6no2RW8XjR pEETX02SK0GFU16gNpSasWBl/sazMhR9GX18s6RYVDvHIZ/KuiXd6+tiR4D/3pU7rb/T GrNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5L0VRZfPFZCVjC2nBfKXHPmUNh0r0Sy/642Ifkd7GzA=; fh=XFr5VEWnexyeyL31SttPR8eP70bUFi12UNF9+gSdaQ4=; b=fF4JbhsZ23vPOijwbfXdTNl2Fougx7tkhZb21CrBdLroExppUvXhFw1JdXrC8fjBYT oc1hE/a7IoNzH+3LS2nrYk7a68STne8VhH5tzk1h9py34D94RL71s4Ez6cEhY2SunLx+ xeHhj929bkVIqxDFXD3JG26ZcaoUBdQSq3O3V+PKbg/FKi5nhU64qW4PWkNkWl4Xg7t9 uzsaEdXgsUFazbdEC2Nrfec9HojDtfyCM5opgU9WS5FiTw6LfBKk8YaRCqaQsonqVlvH rh4okK1YgHMJOA3B18uv6h1jhBDbMurdA+rhq0tFujGkw3sj7KZOHdjRsfq2GQU6ugJ/ FnGQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=adbHjS71; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6f4c0acb1cesi38840336d6.262.2025.04.25.08.34.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Apr 2025 08:34:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=adbHjS71; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8L1L-0003IG-62; Fri, 25 Apr 2025 11:31:19 -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 1u8L1A-0002W6-CP for qemu-devel@nongnu.org; Fri, 25 Apr 2025 11:31:08 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u8L18-00041Q-EE for qemu-devel@nongnu.org; Fri, 25 Apr 2025 11:31:08 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-39129fc51f8so1925999f8f.0 for ; Fri, 25 Apr 2025 08:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745595064; x=1746199864; darn=nongnu.org; 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=5L0VRZfPFZCVjC2nBfKXHPmUNh0r0Sy/642Ifkd7GzA=; b=adbHjS71pIBqBJUZN00GGbMCiY9O0W25nmUaGR7AN/+/seb6scO2WeO+HYN+CxhBI1 L/a+nGWU2/JYa9cRX7EJtXV4ptvwyrux9yAedbMQAKHehIi/Yh5Fsi++NhRJVQrDreJd G2qKbPlotTFCvww+JwqGgWuIYQthUyNoJJ25WN2EbL5xzX7QY2GMk5Oanup42k38XRR/ BRRH6wiFf6cVkPvF4mJ6LJTOD68vlKnpTDX/DhexbbZjN7gzQ3YnZZallTwC77RigeTx F5/yvi0CMWE2xCrjh94Tycz3R52drIyjicLWSHhlySVz7tTEBbZLvkqLY+y75w5UF6fR nbqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745595064; x=1746199864; 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=5L0VRZfPFZCVjC2nBfKXHPmUNh0r0Sy/642Ifkd7GzA=; b=LyjELxenHpA6+MtGFZExLkYuzsY0fWhV8Xl/ykoYrbxIeQYEmn6GJ0RQeBl4HuklqR SVKJh2PFn97CuqQQes81bHh0heCUdExaqESyvV3YzzZ9NZp80AkD86JTLM4abSA8o59r pjqvhoYoZF9x4+pN5dRngK9k4ghmWsCiIndcnJTnvFU4BFJ+YywUiqcet6xYk56Yltud Z/47mMZGIwNqI/WvLdildV8j9/lvgtXPsW7rGd7WHVL1LtC/PKR0KfYrfRV0UDTvr0FV OJ4oJgsCWrF5qUnfKl5bbGOxrx0FA1rHfreStbJ9ZIjvjtT3BL7eOd1rlBJ4MKseK53F +iDA== X-Gm-Message-State: AOJu0Yw3lVpE3bV6xVfKf0pS74Pdjq3a+yPkm2bDdoJ4WjMJ5jcZPx2F H4aYWoR789ogyVu91dSJWbbIWZZAXIp1TySjuoS4wnCGppGltGQ8G90euZZ9PIhFHGgRNGVQlxX u X-Gm-Gg: ASbGncsX6a3eLBHStOQ75V3fty6LW1NvJ7G9+2hi37l4ubAkcw5I5d9whxwsXcEAygm 3nLuN2rfgzDb/Tg9e5GecdxGKcTQtLMIn+tsC+OzolJpY8aqXbG2kowfjzkOA7sAoXuQsN/u98S 96k9BXw5pd0SltXJkcKEXnJk1N8BRfaAPImm1mkRyPqkliuUJ9cEDH9+dMEdmV/LcryqjqtOyx4 xtwt/Resreplfa74exAba2pOp3uLgiKcukFNvNUUT/Oqu6s0Lzsx7lAFa14CEm3HiH0XbmhqxjK jv8uYTbSJdfbuXYE1gCHqOAaWF/Q3zP+qx1Dn5sxTa7/MgpiRsdF0ZQW5S1X9680lxA9umzExRM mLnIBTrT69bH2xKI= X-Received: by 2002:a05:6000:2505:b0:38b:d7d2:12f6 with SMTP id ffacd0b85a97d-3a074e147a9mr2115676f8f.2.1745595064267; Fri, 25 Apr 2025 08:31:04 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a073c8cc81sm2699639f8f.19.2025.04.25.08.31.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 25 Apr 2025 08:31:03 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PULL 28/58] hw/usb/hcd-xhci: Unmap canceled packet Date: Fri, 25 Apr 2025 17:28:12 +0200 Message-ID: <20250425152843.69638-29-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250425152843.69638-1-philmd@linaro.org> References: <20250425152843.69638-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philmd@linaro.org; helo=mail-wr1-x42f.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki When the Stop Endpoint Command is received, packets running asynchronously are canceled and then all packets are cleaned up. Packets running asynchronously hold the DMA mapping so cleaning the packets leak the mapping. Remove the mapping after canceling packets to fix the leak. Fixes: 62c6ae04cf43 ("xhci: Initial xHCI implementation") Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250418-xhc-v1-1-bb32dab6a67e@daynix.com> Signed-off-by: Philippe Mathieu-Daudé --- hw/usb/hcd-xhci.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index b3785b8ba6c..292c378bfc9 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1187,6 +1187,12 @@ static void xhci_ep_free_xfer(XHCITransfer *xfer) g_free(xfer); } +static void xhci_xfer_unmap(XHCITransfer *xfer) +{ + usb_packet_unmap(&xfer->packet, &xfer->sgl); + qemu_sglist_destroy(&xfer->sgl); +} + static int xhci_ep_nuke_one_xfer(XHCITransfer *t, TRBCCode report) { int killed = 0; @@ -1198,6 +1204,7 @@ static int xhci_ep_nuke_one_xfer(XHCITransfer *t, TRBCCode report) if (t->running_async) { usb_cancel_packet(&t->packet); + xhci_xfer_unmap(t); t->running_async = 0; killed = 1; } @@ -1480,12 +1487,6 @@ err: return -1; } -static void xhci_xfer_unmap(XHCITransfer *xfer) -{ - usb_packet_unmap(&xfer->packet, &xfer->sgl); - qemu_sglist_destroy(&xfer->sgl); -} - static void xhci_xfer_report(XHCITransfer *xfer) { uint32_t edtla = 0;