From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13EE4C433EF for ; Fri, 10 Dec 2021 18:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245160AbhLJSQv (ORCPT ); Fri, 10 Dec 2021 13:16:51 -0500 Received: from foss.arm.com ([217.140.110.172]:45808 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238333AbhLJSQu (ORCPT ); Fri, 10 Dec 2021 13:16:50 -0500 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 70F0212FC; Fri, 10 Dec 2021 10:13:15 -0800 (PST) Received: from [10.57.34.58] (unknown [10.57.34.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3668E3F73D; Fri, 10 Dec 2021 10:13:14 -0800 (PST) Message-ID: <80145652-b9ca-57b5-ad95-ca12d6a25eea@arm.com> Date: Fri, 10 Dec 2021 18:13:09 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH v2 01/11] iommu/iova: Fix race between FQ timeout and teardown Content-Language: en-GB To: John Garry , joro@8bytes.org, will@kernel.org Cc: linux-kernel@vger.kernel.org, willy@infradead.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Xiongfeng Wang References: <03cbd9c4-0f11-895b-8eb5-1b75bb74d37c@huawei.com> From: Robin Murphy In-Reply-To: <03cbd9c4-0f11-895b-8eb5-1b75bb74d37c@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-12-10 18:04, John Garry via iommu wrote: > On 10/12/2021 17:54, Robin Murphy wrote: >> From: Xiongfeng Wang >> >> It turns out to be possible for hotplugging out a device to reach the >> stage of tearing down the device's group and default domain before the >> domain's flush queue has drained naturally. At this point, it is then >> possible for the timeout to expire just*before*  the del_timer() call > > super nit: "just*before*  the" - needs a whitespace before "before" :) Weird... the original patch file here and the copy received by lore via linux-iommu look fine, gremlins in your MUA or delivery path perhaps? >> from free_iova_flush_queue(), such that we then proceed to free the FQ >> resources while fq_flush_timeout() is still accessing them on another >> CPU. Crashes due to this have been observed in the wild while removing >> NVMe devices. >> >> Close the race window by using del_timer_sync() to safely wait for any >> active timeout handler to finish before we start to free things. We >> already avoid any locking in free_iova_flush_queue() since the FQ is >> supposed to be inactive anyway, so the potential deadlock scenario does >> not apply. >> >> Fixes: 9a005a800ae8 ("iommu/iova: Add flush timer") >> Signed-off-by: Xiongfeng Wang >> [ rm: rewrite commit message ] >> Signed-off-by: Robin Murphy > > FWIW, > > Reviewed-by: John Garry Thanks John! Robin. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3F10C433F5 for ; Fri, 10 Dec 2021 18:13:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 59C5742557; Fri, 10 Dec 2021 18:13:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wHXb_-UmMd-j; Fri, 10 Dec 2021 18:13:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 44D7D42519; Fri, 10 Dec 2021 18:13:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0AF53C001E; Fri, 10 Dec 2021 18:13:18 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id D076CC0012 for ; Fri, 10 Dec 2021 18:13:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B79C1614B4 for ; Fri, 10 Dec 2021 18:13:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w19ONdTo6Ifk for ; Fri, 10 Dec 2021 18:13:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp3.osuosl.org (Postfix) with ESMTP id 1C1F16147D for ; Fri, 10 Dec 2021 18:13:15 +0000 (UTC) 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 70F0212FC; Fri, 10 Dec 2021 10:13:15 -0800 (PST) Received: from [10.57.34.58] (unknown [10.57.34.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3668E3F73D; Fri, 10 Dec 2021 10:13:14 -0800 (PST) Message-ID: <80145652-b9ca-57b5-ad95-ca12d6a25eea@arm.com> Date: Fri, 10 Dec 2021 18:13:09 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH v2 01/11] iommu/iova: Fix race between FQ timeout and teardown Content-Language: en-GB To: John Garry , joro@8bytes.org, will@kernel.org References: <03cbd9c4-0f11-895b-8eb5-1b75bb74d37c@huawei.com> From: Robin Murphy In-Reply-To: <03cbd9c4-0f11-895b-8eb5-1b75bb74d37c@huawei.com> Cc: linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, Xiongfeng Wang X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: base64 Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" T24gMjAyMS0xMi0xMCAxODowNCwgSm9obiBHYXJyeSB2aWEgaW9tbXUgd3JvdGU6Cj4gT24gMTAv MTIvMjAyMSAxNzo1NCwgUm9iaW4gTXVycGh5IHdyb3RlOgo+PiBGcm9tOiBYaW9uZ2ZlbmcgV2Fu Zzx3YW5neGlvbmdmZW5nMkBodWF3ZWkuY29tPgo+Pgo+PiBJdCB0dXJucyBvdXQgdG8gYmUgcG9z c2libGUgZm9yIGhvdHBsdWdnaW5nIG91dCBhIGRldmljZSB0byByZWFjaCB0aGUKPj4gc3RhZ2Ug b2YgdGVhcmluZyBkb3duIHRoZSBkZXZpY2UncyBncm91cCBhbmQgZGVmYXVsdCBkb21haW4gYmVm b3JlIHRoZQo+PiBkb21haW4ncyBmbHVzaCBxdWV1ZSBoYXMgZHJhaW5lZCBuYXR1cmFsbHkuIEF0 IHRoaXMgcG9pbnQsIGl0IGlzIHRoZW4KPj4gcG9zc2libGUgZm9yIHRoZSB0aW1lb3V0IHRvIGV4 cGlyZSBqdXN0KmJlZm9yZSrCoCB0aGUgZGVsX3RpbWVyKCkgY2FsbAo+IAo+IHN1cGVyIG5pdDog Imp1c3QqYmVmb3JlKsKgIHRoZSIgLSBuZWVkcyBhI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