Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5258220rdb; Wed, 13 Dec 2023 03:54:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IElRUQD1Y3pVyq3glQpniPrwyH0ZXxR2vthy/Fz0BrR31r4B3bNE1Nrn+sdDT/JZXJxmrPT X-Received: by 2002:a05:6a20:a107:b0:18f:e2c9:9751 with SMTP id q7-20020a056a20a10700b0018fe2c99751mr11631421pzk.19.1702468458253; Wed, 13 Dec 2023 03:54:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702468458; cv=none; d=google.com; s=arc-20160816; b=sU4UXH+H6+xIlIvc9bOycKoNak1vZZZJhjuBB4yEAIMcy9ODvEZvLVFvxBfU9B0847 yder2AUqzV2x5T91qqTZqB9OuRvE0F+5hpJ6d8ayxIaH+yj3QvkNlCtOANh6/63G5poK ZQMGvZgB5GOUCbaf3ghrHUmVA318WvROHsr4sAPQwArKCE2Bo44J04S4LAErmQ+FigNh o2A1Vgsa9nBA4nIFfXKYWB/qj/oBlFMt1yz87690Cszq5EgtM8ZKaPU4LIaB3MQ62Rg8 RQkotD9TJDPMJZe6mY5Fr9b222Ayc8eE3fDm3LtDnAd3ntYGh2h2JSKECjxRv9pMDhV4 vSug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=JXpJqY35Q/+UagOTkMa7jzWgg5WQIi+DxFdmwi2zZLM=; fh=vOUORdy2KgPXFdd2jH/laN0kScUsV/JfHphyDdtLFYM=; b=Q8bbUYxHS5IlOstdDSP8hL8blPvVSac/rf4nkYJcdStvCbkNs+U4Ott5mYl9+4pavV nxjlMLYZK9tW0h4zJuTRdHpDKLVHzmaMqOzdHT/QOKRsN8ORhkJ2XNEw+P9tBdwADLEZ 7D5F4Op5wn+Ahz4lU5oVBq6SxVnuhfx5HsnHwr+DMSXejv4kQ8HXqfVmMjqYTI/PviyR 6kuPQ81bglPID8BoM7IHR1Hq1cE4vSySN/7flzRYeBWc5++k5XxfkAWIfXZiVGm7AvZ2 1rofBvkSJLGHhvXVJAS3YE9QuQJ2B3ag2B5O8wfQGSwQz7fimwVsg504nAa1X/kucxaw mBhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id l22-20020a656816000000b005c626128e67si9583669pgt.494.2023.12.13.03.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 03:54:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D361F82072E8; Wed, 13 Dec 2023 03:54:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378168AbjLMLyD (ORCPT + 99 others); Wed, 13 Dec 2023 06:54:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377447AbjLMLyC (ORCPT ); Wed, 13 Dec 2023 06:54:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB233B0; Wed, 13 Dec 2023 03:54:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9EB2FFEC; Wed, 13 Dec 2023 03:54:54 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5F46E3F7F4; Wed, 13 Dec 2023 03:54:07 -0800 (PST) Message-ID: <3b7742c4-bbae-4a78-a5a6-30df936a17d4@arm.com> Date: Wed, 13 Dec 2023 11:54:05 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] iommu/vt-d: don's issue devTLB flush request when device is disconnected Content-Language: en-GB To: Lukas Wunner , Ethan Zhao Cc: bhelgaas@google.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, will@kernel.org, linux-pci@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Haorong Ye References: <20231213034637.2603013-1-haifeng.zhao@linux.intel.com> <20231213034637.2603013-3-haifeng.zhao@linux.intel.com> <20231213104417.GA31964@wunner.de> From: Robin Murphy In-Reply-To: <20231213104417.GA31964@wunner.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 03:54:16 -0800 (PST) On 13/12/2023 10:44 am, Lukas Wunner wrote: > On Tue, Dec 12, 2023 at 10:46:37PM -0500, Ethan Zhao wrote: >> For those endpoint devices connect to system via hotplug capable ports, >> users could request a warm reset to the device by flapping device's link >> through setting the slot's link control register, > > Well, users could just *unplug* the device, right? Why is it relevant > that thay could fiddle with registers in config space? > > >> as pciehpt_ist() DLLSC >> interrupt sequence response, pciehp will unload the device driver and >> then power it off. thus cause an IOMMU devTLB flush request for device to >> be sent and a long time completion/timeout waiting in interrupt context. > > A completion timeout should be on the order of usecs or msecs, why does it > cause a hard lockup? The dmesg excerpt you've provided shows a 12 *second* > delay between hot removal and watchdog reaction. The PCIe spec only requires an endpoint to respond to an ATS invalidate within a rather hilarious 90 seconds, so it's primarily a question of how patient the root complex and bridges in between are prepared to be. >> Fix it by checking the device's error_state in >> devtlb_invalidation_with_pasid() to avoid sending meaningless devTLB flush >> request to link down device that is set to pci_channel_io_perm_failure and >> then powered off in > > This doesn't seem to be a proper fix. It will work most of the time > but not always. A user might bring down the slot via sysfs, then yank > the card from the slot just when the iommu flush occurs such that the > pci_dev_is_disconnected(pdev) check returns false but the card is > physically gone immediately afterwards. In other words, you've shrunk > the time window during which the issue may occur, but haven't eliminated > it completely. Yeah, I think we have a subtle but fundamental issue here in that the iommu_release_device() callback is hooked to BUS_NOTIFY_REMOVED_DEVICE, so in general probably shouldn't be assuming it's safe to do anything with the device itself *after* it's already been removed from its bus - this step is primarily about cleaning up any of the IOMMU's own state relating to the given device. I think if we want to ensure ATCs are invalidated on hot-unplug we need an additional pre-removal notifier to take care of that, and that step would then want to distinguish between an orderly removal where cleaning up is somewhat meaningful, and a surprise removal where it definitely isn't. Thanks, Robin.