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 X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B18B8C433F5 for ; Fri, 24 Sep 2021 13:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F32061076 for ; Fri, 24 Sep 2021 13:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346566AbhIXN7F (ORCPT ); Fri, 24 Sep 2021 09:59:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:56058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbhIXN7E (ORCPT ); Fri, 24 Sep 2021 09:59:04 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 02A8A61050; Fri, 24 Sep 2021 13:57:31 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mTlhf-00CmsD-U6; Fri, 24 Sep 2021 14:57:29 +0100 Date: Fri, 24 Sep 2021 14:57:27 +0100 Message-ID: <87wnn6t6t4.wl-maz@kernel.org> From: Marc Zyngier To: Sven Peter Cc: Joerg Roedel , Will Deacon , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/dart: Clear sid2group entry when a group is freed In-Reply-To: <20210924134502.15589-1-sven@svenpeter.dev> References: <20210924134502.15589-1-sven@svenpeter.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: sven@svenpeter.dev, joro@8bytes.org, will@kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 Sep 2021 14:45:02 +0100, Sven Peter wrote: > > sid2groups keeps track of which stream id combinations belong to a > iommu_group to assign those correctly to devices. > When a iommu_group is freed a stale pointer will however remain in > sid2groups. This prevents devices with the same stream id combination > to ever be attached again (see below). > Fix that by creating a shadow copy of the stream id configuration > when a group is allocated for the first time and clear the sid2group > entry when that group is freed. > > # echo 1 >/sys/bus/pci/devices/0000\:03\:00.0/remove > pci 0000:03:00.0: Removing from iommu group 1 > # echo 1 >/sys/bus/pci/rescan > [...] > pci 0000:03:00.0: BAR 0: assigned [mem 0x6a0000000-0x6a000ffff 64bit pref] > pci 0000:03:00.0: BAR 2: assigned [mem 0x6a0010000-0x6a001ffff 64bit pref] > pci 0000:03:00.0: BAR 6: assigned [mem 0x6c0100000-0x6c01007ff pref] > tg3 0000:03:00.0: Failed to add to iommu group 1: -2 > [...] > > Fixes: 46d1fb072e76b161 ("iommu/dart: Add DART iommu driver") > Reported-by: Marc Zyngier > Signed-off-by: Sven Peter Thanks for posting this. Tested-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.