Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp326256ybj; Thu, 19 Sep 2019 15:07:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9lPVXT2agRtuAnL0RKEwTWPmbAw88Kk1lJNJBZ+j1q2L3Q4dkm99UALqaoyJF6/pOdNxx X-Received: by 2002:a17:907:4242:: with SMTP id np2mr16517121ejb.102.1568930857697; Thu, 19 Sep 2019 15:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568930857; cv=none; d=google.com; s=arc-20160816; b=pnOp+li2Prkp/WPtNhRUuhCVlGv+Gp/MSahnMypjoAITXn7EEZsBYurw8RfV4j4lEP 8vPNr1HD2OrdvS6yozTuxJfSYfdolw/czfmN2n24ifPq2ChGFd2rwR2qt0UjorKwlSgv EPYHkFlxDeUtryvZTvpH1oWGFxM7Cchq1fn/qHQT8yvGjzZAVeY18gWx295D1YNGr5En l0sGwNWurqqnsv1JFadq1IaIUZOycFrnKWaIG+oJ0tjZpk9gH4fQr7XeEnOtI0+kXUC/ 8We3skA2rCfoP2bLm5kzsx+rfZRvAikuoFEdlIiHfd346bRcFCrpMT8pyA38jGFd28dm mn1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=oUQUKfGGLyoufGiv0FoEyuW3RCfv5lyXYP4LRA9yUnI=; b=mxE6cYpbMe+wtciW9JwY9HeHW3k95mpRGm3WSYFdEZLrYMLc6DkiQMrmtnQ4GNyhqp 2GtRIk93pCF7bJxNBH6Na82ZZ/2hFGBYlmaeFY5Sp01oxqHME/5ephOT/EbIra9oGlrl KMy/2M4USJGXF4SoLaHdFGxK8sq7618bR353sbhqBHtld3/CL+Z7+g+Kp/pSapPSE5fq SwklpIQeiwaInKoUeVCQaph5ElJJSThXyGckheamTP1oC1OjrfBAeQkwWdhL0Lxyk6Ja YWOyitMa0Vnt5ZZLYnJgWlCrJR0pkw+2tPXKkueF1vsrLoJ4vXmXGoq6bLoYkJ2hWUaJ XEQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sm1kYe9P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si51719edq.239.2019.09.19.15.07.14; Thu, 19 Sep 2019 15:07:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sm1kYe9P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403755AbfISPGi (ORCPT + 99 others); Thu, 19 Sep 2019 11:06:38 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:42340 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390897AbfISPGi (ORCPT ); Thu, 19 Sep 2019 11:06:38 -0400 Received: by mail-ed1-f68.google.com with SMTP id y91so3495788ede.9 for ; Thu, 19 Sep 2019 08:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=oUQUKfGGLyoufGiv0FoEyuW3RCfv5lyXYP4LRA9yUnI=; b=sm1kYe9P5pTViCKFjNk/d6ebqMWyJNooZxf91TSUePYb/5i7/VaEYPsMPIc2wfZVi8 P/ooqN0dZaXdOGopagPyYfk47lN5uurdLwK5TuwLmyhYW1FITstvFCYOZDjE+2XBbEGs DVxBofb6ZPhP/lrm+qE4xpNtlFMAcMZAd1Ca6mP8mwuQVxEQi5Rsqjk+fTKinMoccU00 yhhDKLGlRrtw55fnv6F+DBvplwGlSB8NUvnA7oH0UD9rik/SsDa/qisHAdtFxMcNHJ5E poqcqtsjOyIKhSbiF+IAS/z0wbnfXeBUqDE1jU6R7i186QYsRgMIkQLl1pqPo1r1IhhB MT4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=oUQUKfGGLyoufGiv0FoEyuW3RCfv5lyXYP4LRA9yUnI=; b=rdptH/W3iAaHWIFG/Js+UN6s4Rv7Xc2oCkBUFltexMaVSAYNEl0UwGYyJ2eUuXlQUQ 7duPu8L8Cef7YGadlM6J2GiAssLRxJ2K8xK5bxmoFb7Jdvnv2aSgZK7JyWmHXrol0+5N eWtl7OikbN3zsHVTgTf1KJcjNyEgALWg7FbrSdZ6Yg4XhnVZkzLPdc4myk9BsW1aSOqY Cj+wuGuFRjSIMlOua/70fVFv1Vxcy1bPs2SLxYyXGXp3E9UEf1B1dFuLuMU6Yzc532S0 8XoftKtnmcQektcTCw7DqKRa8RNWhcGR12ljBevMNAIF3WG3zG13zLl4+KbHpeYV8ZAe fjtA== X-Gm-Message-State: APjAAAUgCIkoKRYXuGlbaPXPJJ/DSsmnGotdL0ktpFlsv/1oitxNOuMS 5dcuNH0NnnpidvjQMYMoIxFbcA== X-Received: by 2002:aa7:d295:: with SMTP id w21mr9488517edq.302.1568905596363; Thu, 19 Sep 2019 08:06:36 -0700 (PDT) Received: from lophozonia ([85.195.192.192]) by smtp.gmail.com with ESMTPSA id a19sm1374424edy.37.2019.09.19.08.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 08:06:35 -0700 (PDT) Date: Thu, 19 Sep 2019 17:06:34 +0200 From: Jean-Philippe Brucker To: Will Deacon Cc: Jean-Philippe Brucker , joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, robin.murphy@arm.com, jacob.jun.pan@linux.intel.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eric.auger@redhat.com Subject: Re: [PATCH 6/8] iommu/arm-smmu-v3: Support auxiliary domains Message-ID: <20190919150634.GE1013538@lophozonia> References: <20190610184714.6786-1-jean-philippe.brucker@arm.com> <20190610184714.6786-7-jean-philippe.brucker@arm.com> <20190626175959.ubxvb2qn4taclact@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190626175959.ubxvb2qn4taclact@willie-the-truck> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 26, 2019 at 06:59:59PM +0100, Will Deacon wrote: > > @@ -666,8 +668,14 @@ struct arm_smmu_domain { > > > > struct iommu_domain domain; > > > > + /* Unused in aux domains */ > > struct list_head devices; > > spinlock_t devices_lock; > > + > > + /* Auxiliary domain stuff */ > > + struct arm_smmu_domain *parent; > > + ioasid_t ssid; > > + unsigned long aux_nr_devs; > > Maybe use a union to avoid comments about what is used/unused? OK > > +static void arm_smmu_aux_detach_dev(struct iommu_domain *domain, struct device *dev) > > +{ > > + struct iommu_domain *parent_domain; > > + struct arm_smmu_domain *parent_smmu_domain; > > + struct arm_smmu_master *master = dev_to_master(dev); > > + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); > > + > > + if (!arm_smmu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX)) > > + return; > > + > > + parent_domain = iommu_get_domain_for_dev(dev); > > + if (!parent_domain) > > + return; > > + parent_smmu_domain = to_smmu_domain(parent_domain); > > + > > + mutex_lock(&smmu_domain->init_mutex); > > + if (!smmu_domain->aux_nr_devs) > > + goto out_unlock; > > + > > + if (!--smmu_domain->aux_nr_devs) { > > + arm_smmu_write_ctx_desc(parent_smmu_domain, smmu_domain->ssid, > > + NULL); > > + /* > > + * TLB doesn't need invalidation since accesses from the device > > + * can't use this domain's ASID once the CD is clear. > > + * > > + * Sadly that doesn't apply to ATCs, which are PASID tagged. > > + * Invalidate all other devices as well, because even though > > + * they weren't 'officially' attached to the auxiliary domain, > > + * they could have formed ATC entries. > > + */ > > + arm_smmu_atc_inv_domain(smmu_domain, 0, 0); > > I've been struggling to understand the locking here, since both > arm_smmu_write_ctx_desc and arm_smmu_atc_inv_domain take and release the > devices_lock for the domain. Is there not a problem with devices coming and > going in-between the two calls? Yes, I need to think about this more. I bet there are plenty more issues like this. For example I don't think I currently prevent the parent domain from disappearing while auxiliary domains are attached. > > static struct iommu_ops arm_smmu_ops = { > > .capable = arm_smmu_capable, > > .domain_alloc = arm_smmu_domain_alloc, > > @@ -2539,6 +2772,13 @@ static struct iommu_ops arm_smmu_ops = { > > .of_xlate = arm_smmu_of_xlate, > > .get_resv_regions = arm_smmu_get_resv_regions, > > .put_resv_regions = arm_smmu_put_resv_regions, > > + .dev_has_feat = arm_smmu_dev_has_feature, > > + .dev_feat_enabled = arm_smmu_dev_feature_enabled, > > + .dev_enable_feat = arm_smmu_dev_enable_feature, > > + .dev_disable_feat = arm_smmu_dev_disable_feature, > > Why can't we use the existing ->capable and ->dev_{get,set}_attr callbacks > for this? ->capable isn't very useful because it applies to all SMMUs in the system. The existing ->{get,set}_attr callbacks apply to an iommu_domain. I think the main reason for doing it on endpoints was that it would be tedious to keep track of capabilities when attaching and detaching devices to a domain, especially for drivers that allow multiple IOMMUs per domain [1]. There were more discussions, and in the end we agreed on this API for device attributes [2]. Thanks, Jean [1] https://lore.kernel.org/lkml/aa1ff748-c2ec-acc0-f1d9-cdff2b131e58@linux.intel.com/ [2] https://lore.kernel.org/linux-iommu/20181207102926.GM16835@8bytes.org/