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 6F7AEC4167B for ; Wed, 29 Nov 2023 20:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234027AbjK2UuI (ORCPT ); Wed, 29 Nov 2023 15:50:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbjK2UuG (ORCPT ); Wed, 29 Nov 2023 15:50:06 -0500 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 240CED69 for ; Wed, 29 Nov 2023 12:50:12 -0800 (PST) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1fa20395185so70188fac.3 for ; Wed, 29 Nov 2023 12:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1701291010; x=1701895810; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Z14ncuPizPQTpz34E/qdK1zleu0e7/OH8lwfu0qFocg=; b=F1EcOt6iBj3aQN+agExfUCk/6FwHrRczkDc9gi5HGDtGGVBgJb4EnxfUHew+kXbVp3 pMMxJYd9hjXsd4HXBksuJAAuBs82etU0bVSeCNi9pzptcOtzWiZrGdcqgh96MDiMqF5E oo3pcNWSAQmHD7aYzQeJExoHKAG+asGv6NmsYusKPuj8lxyOf25tg6nUGRz8/IPqfNF4 kr4KEQP9O1hgZWdT87ce2gnhOxHs0eejEOyNcKUtbtD8y8Rz2MMZIx9pNx2rBxpvcSce n6UR427PMpcEnV6hDui5Q0wjY4TaJ18T0fnuh+oHD3EWKrSTRpLjIjkpjz+m9v977NZe DC+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701291010; x=1701895810; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Z14ncuPizPQTpz34E/qdK1zleu0e7/OH8lwfu0qFocg=; b=ml7GRAZwIglzX8PxyqGqpKJfAgiqVWpclf7NnG5j92gtSkRqxDUtpkndbIJ2sBpAem SalLqb/TAg7SB00LM2qlvHteCBBk+zFAmfLsFaKWM3NJUSRbCvIY3XtGRS0hbTDqe5OA bx+vZ1KmmwhGm63hOr3Curu5HV0Z2UU6Lh+frrOBltOkgEtVOSPVsIYifNq5aPtbHD38 iQNX3n1JA6e1fb9Am1TCfpYygPEq/+Cta6x2XKCK1pE8pPuK4i4PIxFBIh8u2qcTJQuF UkIEAoobAjBnV45YtXluWz3LtqUU5D8GYMmtC2CaFqshqbWEfNZB5TerKLh7kpNw+bbe l2aA== X-Gm-Message-State: AOJu0Yw4YQZvtAWoZtxz8/1wJUkn9Zco+V5f8zcczOUH0DChpgnOUvWf 6NsrnclMLQUsX6HyppWF/OPITw== X-Google-Smtp-Source: AGHT+IGgKdfE8YcFNMWNxw13U7YpCs8rnHcqlluxJCfOn0tU84fkZFp4MzoV02U2Np+AMlZvjw1IBA== X-Received: by 2002:a05:6870:d622:b0:1fa:ca3:7069 with SMTP id a34-20020a056870d62200b001fa0ca37069mr20658402oaq.16.1701291009170; Wed, 29 Nov 2023 12:50:09 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-134-23-187.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.134.23.187]) by smtp.gmail.com with ESMTPSA id yu6-20020a05687c224600b001fa6ba84054sm1349572oab.55.2023.11.29.12.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 12:50:08 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1r8RVX-005pjC-Mb; Wed, 29 Nov 2023 16:50:07 -0400 Date: Wed, 29 Nov 2023 16:50:07 -0400 From: Jason Gunthorpe To: Robin Murphy Cc: Joerg Roedel , Christoph Hellwig , Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org Subject: Re: [PATCH 6/7] iommu/dma: Centralise iommu_setup_dma_ops() Message-ID: <20231129205007.GR1312390@ziepe.ca> References: <7fe5a0d2bc855ac38dff326f3e64ba394bc262d4.1701268753.git.robin.murphy@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7fe5a0d2bc855ac38dff326f3e64ba394bc262d4.1701268753.git.robin.murphy@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 29, 2023 at 05:43:03PM +0000, Robin Murphy wrote: > It's somewhat hard to see, but arm64's arch_setup_dma_ops() should only > ever call iommu_setup_dma_ops() after a successful iommu_probe_device(), > which means there should be no harm in instead running it off the back > of iommu_probe_device() itself, as is currently done for x86 and s390 > with .probe_finalize bodges. Pull it all into the main flow properly. > > Signed-off-by: Robin Murphy > --- > arch/arm64/mm/dma-mapping.c | 2 -- > drivers/iommu/amd/iommu.c | 8 -------- > drivers/iommu/dma-iommu.c | 17 ++++------------- > drivers/iommu/dma-iommu.h | 6 ++++++ > drivers/iommu/intel/iommu.c | 7 ------- > drivers/iommu/iommu.c | 2 ++ > drivers/iommu/s390-iommu.c | 6 ------ > drivers/iommu/virtio-iommu.c | 10 ---------- > include/linux/iommu.h | 7 ------- > 9 files changed, 12 insertions(+), 53 deletions(-) Yes! That probe_finalize() stuff is not nice > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 824989874dee..3a0901165b69 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -589,6 +589,8 @@ int iommu_probe_device(struct device *dev) > if (ret) > return ret; > > + iommu_setup_dma_ops(dev); > + I'm pretty sure this should be inside the group mutex lock. The setting of dev->dma_ops should exactly follow the setting of group->domain, and all transitions, including from the sysfs override file should update it, right? Thus to avoid races agsinst concurrent sysfs this should be locked. I think you can just put this in iommu_setup_default_domain() and it will take care of all the cases? Once in iommu_setup_default_domain() it is easy to call it with the domain argument and it can know the domain type without using iommu_is_dma_domain() which is one of the very last few places checking for the DMA domain type. Jason