From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDE8D603A for ; Wed, 6 Jul 2022 01:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657071585; x=1688607585; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=fJxV3N/r8RRwYOaYdoJK639dTHZ5BBDCFg7PkYP7v3w=; b=cTYBlLL6lIry7NYEoVTGdTxGiUOBL1GQ//oKN4e7iIHFjjDNSgVu8ZYT HzRGPhvKPoX6EJWwuVqTmlZnScUjXWH7nQxVLuMqNmmZWQKKbtxpar79/ yQ5X6zpXcV05TeXmf2gzlyqBiNJeTHxYnLtOPd6QEiWUkiMdZakXFOW/u D5WkXg3QtC8BkN7b7xoH+t3ZAfPUjO1AI+osBcUy6rFUIUPRm3Sq7U8GH zJwA0PSsck7KMvQaLBMWvEzL07fsvuPsleJTpcoNdsB8n1HwvoOL7OjO2 p9eK+zHSAFVihHBsWfjfdI6IvJzl/PhOVOC0d0HQKBXwbJPydkdDmwbk5 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="309158752" X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="309158752" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 18:39:45 -0700 X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="650429732" Received: from zhuoliu-mobl1.ccr.corp.intel.com (HELO [10.249.174.206]) ([10.249.174.206]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 18:39:42 -0700 Message-ID: <032937a0-ffef-221c-4faf-4680fa09b2af@linux.intel.com> Date: Wed, 6 Jul 2022 09:39:40 +0800 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cc: baolu.lu@linux.intel.com, will@kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, suravee.suthikulpanit@amd.com, vasant.hegde@amd.com, mjrosato@linux.ibm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 01/15] iommu/vt-d: Handle race between registration and device probe Content-Language: en-US To: Robin Murphy , joro@8bytes.org References: <894db0ccae854b35c73814485569b634237b5538.1657034828.git.robin.murphy@arm.com> From: Baolu Lu In-Reply-To: <894db0ccae854b35c73814485569b634237b5538.1657034828.git.robin.murphy@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2022/7/6 01:08, Robin Murphy wrote: > Currently we rely on registering all our instances before initially > allowing any .probe_device calls via bus_set_iommu(). In preparation for > phasing out the latter, make sure we won't inadvertently return success > for a device associated with a known but not yet registered instance, > otherwise we'll run straight into iommu_group_get_for_dev() trying to > use NULL ops. > > That also highlights an issue with intel_iommu_get_resv_regions() taking > dmar_global_lock from within a section where intel_iommu_init() already > holds it, which already exists via probe_acpi_namespace_devices() when > an ANDD device is probed, but gets more obvious with the upcoming change > to iommu_device_register(). Since they are both read locks it manages > not to deadlock in practice, so I'm leaving it here for someone with > more confidence to tackle a larger rework of the locking. Thanks for highlighting this. I will look into it later. Best regards, baolu > > Signed-off-by: Robin Murphy > --- > > v3: New > > drivers/iommu/intel/iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index 44016594831d..3e02c08802a0 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -4600,7 +4600,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) > u8 bus, devfn; > > iommu = device_to_iommu(dev, &bus, &devfn); > - if (!iommu) > + if (!iommu || !iommu->iommu.ops) > return ERR_PTR(-ENODEV); > > info = kzalloc(sizeof(*info), GFP_KERNEL); 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 42A31C433EF for ; Wed, 6 Jul 2022 01:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:To:Subject:Cc: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9q++osjXbVLP4rUJY7EJ0fjIYO0JFPV2HPc+lDWcd3Q=; b=hapHfNX8WwTNc/ jPY/NvHr6L4kt7SdM16PmhMup+F7spbF6SodM0WzZtqhjTzG22WVjSGkYKa3xt2bTvYGmqUA+VMjV gjxXAkFubiFAaz7TyqqSFpbnpACHDbJQgE0gHyh3hFdnJL/egSp+iD8P0s+LL0KKm2M2jC86arWoC W4GLP5Jlxovb8xwMC2iSqQw2q0f0hulbCpKs2WlQfUANRPzPQjdfSFA57IKg6AzdpcVSyOFyRiGVu 1oOyw2qubtU+KYDw75CF5ulOmievZ0zKZoxJ+Q0XKiieOKIcx8m7Ky9CpY8VANPBsz/hBnweLI56d 6DkKJABo6RKd0Tm0GpUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8u18-005EsG-6B; Wed, 06 Jul 2022 01:39:50 +0000 Received: from mga04.intel.com ([192.55.52.120]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8u14-005ErM-LM for linux-arm-kernel@lists.infradead.org; Wed, 06 Jul 2022 01:39:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657071586; x=1688607586; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=fJxV3N/r8RRwYOaYdoJK639dTHZ5BBDCFg7PkYP7v3w=; b=lbXJAQxDfxhD1w882Ictfvz7ygWl71c5M81frTpPQeViNUCHPyamrPhD Vh+9AiqaHHZiG/nSVdClNpXVO/fqzh/CUkka7FFEDdnI268w7gK+Nq/pl cSiMKXOo4zHTzZF6CT4kPAsxstrjOO+Lu3wqihqZ/KmVRhs3juWTXVMhl ziBO5F4GdueL7L+gTvEQW2mOPxLVD4lB8smgvZGBxmeUkhk+LF46qVeTT rCHigDOVCYGrKAixXg7vwdD0IDKyY/1Xa7OY2fv+12O+j0nGS0+znK7i7 zTftLGvzMLSqCGX26lMs5dy2Y+ya+JVxnvCemFjMYDra9sEL0rwnIA0IN A==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="282365427" X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="282365427" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 18:39:45 -0700 X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="650429732" Received: from zhuoliu-mobl1.ccr.corp.intel.com (HELO [10.249.174.206]) ([10.249.174.206]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 18:39:42 -0700 Message-ID: <032937a0-ffef-221c-4faf-4680fa09b2af@linux.intel.com> Date: Wed, 6 Jul 2022 09:39:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cc: baolu.lu@linux.intel.com, will@kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, suravee.suthikulpanit@amd.com, vasant.hegde@amd.com, mjrosato@linux.ibm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 01/15] iommu/vt-d: Handle race between registration and device probe Content-Language: en-US To: Robin Murphy , joro@8bytes.org References: <894db0ccae854b35c73814485569b634237b5538.1657034828.git.robin.murphy@arm.com> From: Baolu Lu In-Reply-To: <894db0ccae854b35c73814485569b634237b5538.1657034828.git.robin.murphy@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220705_183946_761420_B7008E50 X-CRM114-Status: GOOD ( 19.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2022/7/6 01:08, Robin Murphy wrote: > Currently we rely on registering all our instances before initially > allowing any .probe_device calls via bus_set_iommu(). In preparation for > phasing out the latter, make sure we won't inadvertently return success > for a device associated with a known but not yet registered instance, > otherwise we'll run straight into iommu_group_get_for_dev() trying to > use NULL ops. > > That also highlights an issue with intel_iommu_get_resv_regions() taking > dmar_global_lock from within a section where intel_iommu_init() already > holds it, which already exists via probe_acpi_namespace_devices() when > an ANDD device is probed, but gets more obvious with the upcoming change > to iommu_device_register(). Since they are both read locks it manages > not to deadlock in practice, so I'm leaving it here for someone with > more confidence to tackle a larger rework of the locking. Thanks for highlighting this. I will look into it later. Best regards, baolu > > Signed-off-by: Robin Murphy > --- > > v3: New > > drivers/iommu/intel/iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index 44016594831d..3e02c08802a0 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -4600,7 +4600,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) > u8 bus, devfn; > > iommu = device_to_iommu(dev, &bus, &devfn); > - if (!iommu) > + if (!iommu || !iommu->iommu.ops) > return ERR_PTR(-ENODEV); > > info = kzalloc(sizeof(*info), GFP_KERNEL); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel