Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp547964pxj; Fri, 11 Jun 2021 05:51:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxciXyo8HZasJCkEY5sg+QbFXqDR5hVF4QGsmQbVeEPuKxNAKOzr4pxlbTWEt4mFc0yxMsr X-Received: by 2002:a17:906:c314:: with SMTP id s20mr3524864ejz.355.1623415916827; Fri, 11 Jun 2021 05:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623415916; cv=none; d=google.com; s=arc-20160816; b=bw15z/cn+PTm5u8qGiKSJibN1WsC244yDb9tJTtPPU6FbbuBVXHRFRdaF65gB1UEad UpzclJA6h5Y+DRdNLtH8K79EewE17korDgwtjJRO7j6DHgECF35yM+JE4amft3BY+g4w vhhb5PF9swOxl7ntYKojU7E4ruMbIKwsTNDUSrfxwdLq8Td8VZwB34MyywLOGpZoKApD NcTQnhD+pMfx9QvKk5l6+wm/GFwLRCHVHvTSkTZaG9dEzE+Gk9xOi8DKPm5U1RblM31c MkY8oOEhNBiSfE6IX5/3qlZM225OE+B8MpM/CMSVI+DRnqu+V+H3dN6xEk1cIGLj9747 qh+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=3YNBgcIezhRVjKiXm4HeFUhrCyP7lNswwK1g44VEQu4=; b=syyRMmq9tABEbyj/6Hs5GHbLfG4HmIn9xYgom/rElv006pBrr3Xj8NEcS3wNkW8NpI xr2O/zHdgaqZNH7/6VC3iyvrecz4rlXTGDCnArBrDmuvLO+RaZNjQPwVXwEfnQWbuRad mIdbrKhPdniC4Um9OokXbI9ZwZIz7OjTc8UBzKUlVQntiuq+pUGvsfktQZ+wKfSqE+Fo wwWI/yK07nzIsRT0CktVkaHM3tYCbUfd3xCSYuV6oI5aVvh28H42WwOCVXPQN/JDLjBY Zn6GZze6fvNVTvB9IROr7/emSfh9z7BQSfd/eRmj9ICjZwadzDs+ocxIcCIf9LQEoUBf JFkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n5si4841758edr.505.2021.06.11.05.51.33; Fri, 11 Jun 2021 05:51:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231236AbhFKMvV (ORCPT + 99 others); Fri, 11 Jun 2021 08:51:21 -0400 Received: from foss.arm.com ([217.140.110.172]:57510 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbhFKMvR (ORCPT ); Fri, 11 Jun 2021 08:51:17 -0400 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 35FF5D6E; Fri, 11 Jun 2021 05:49:19 -0700 (PDT) Received: from [10.57.6.115] (unknown [10.57.6.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5EEB23F73D; Fri, 11 Jun 2021 05:49:18 -0700 (PDT) Subject: Re: [PATCH 1/2] iommu: Fix race condition during default domain allocation To: Will Deacon , Ashish Mhetre Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <1623298614-31755-1-git-send-email-amhetre@nvidia.com> <1623298614-31755-2-git-send-email-amhetre@nvidia.com> <20210611104524.GD15274@willie-the-truck> From: Robin Murphy Message-ID: Date: Fri, 11 Jun 2021 13:49:13 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210611104524.GD15274@willie-the-truck> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-11 11:45, Will Deacon wrote: > On Thu, Jun 10, 2021 at 09:46:53AM +0530, Ashish Mhetre wrote: >> Domain is getting created more than once during asynchronous multiple >> display heads(devices) probe. All the display heads share same SID and >> are expected to be in same domain. As iommu_alloc_default_domain() call >> is not protected, the group->default_domain and group->domain are ending >> up with different domains and leading to subsequent IOMMU faults. >> Fix this by protecting iommu_alloc_default_domain() call with group->mutex. > > Can you provide some more information about exactly what the h/w > configuration is, and the callstack which exhibits the race, please? It'll be basically the same as the issue reported long ago with PCI groups in the absence of ACS not being constructed correctly. Triggering the iommu_probe_device() replay in of_iommu_configure() off the back of driver probe is way too late and allows calls to happen in the wrong order, or indeed race in parallel as here. Fixing that is still on my radar, but will not be simple, and will probably go hand-in-hand with phasing out the bus ops (for the multiple-driver-coexistence problem). >> Signed-off-by: Ashish Mhetre >> --- >> drivers/iommu/iommu.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c >> index 808ab70..2700500 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -273,7 +273,9 @@ int iommu_probe_device(struct device *dev) >> * support default domains, so the return value is not yet >> * checked. >> */ >> + mutex_lock(&group->mutex); >> iommu_alloc_default_domain(group, dev); >> + mutex_unlock(&group->mutex); > > It feels wrong to serialise this for everybody just to cater for systems > with aliasing SIDs between devices. If two or more devices are racing at this point then they're already going to be serialised by at least iommu_group_add_device(), so I doubt there would be much impact - only the first device through here will hold the mutex for any appreciable length of time. Every other path which modifies group->domain does so with the mutex held (note the "expected" default domain allocation flow in bus_iommu_probe() in particular), so not holding it here does seem like a straightforward oversight. Robin.