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 3129DC4829A for ; Tue, 13 Feb 2024 15:45:56 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XWk9KMtXJPCwfbMy2fVqaLwQg9GxdP7JIGGogq2WxyY=; b=Q9ryQgaTuU1HOY HO30VwYcytM5/2eZh8/t/rFO5mw2Ibm8+O0OmDur5RtxxiBtPDNSp0lM5+XMeip2/yoFYY252JkOF ZNg/zeWbscCMqMh6vqqTDhqsxV1s0plqs8X8egOPFMG7BydWNhoL9m3Qx0GVNApWOGy4Rbnso0cLy bX3voGiEt6v6k+5OCYA4W/LcxY2NAyTllSYBmjsAtQWf5Y7jncIAKiFx+oEAqHLPat5hxjqWiVs4l 6kFBz5Eg5MHOCAJ3JahLrdnJYNpQ7LdSyPKSKS0H0VvS+tj0zca6TiImk5VzWyuVZ8Rr+vN4yJKDo titpFxmO8yg5ZQM5uMFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZuyf-00000009onN-3arT; Tue, 13 Feb 2024 15:45:45 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZuyd-00000009okD-1Kz7 for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2024 15:45:44 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40f0218476aso57145e9.1 for ; Tue, 13 Feb 2024 07:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707839139; x=1708443939; darn=lists.infradead.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=fdE8AsRwFb0gP05F4tbQ9BZCrEG5/tGeZG6PUCDuRyU=; b=H6XMX8vSOBMZQdSQHIzPHlS6NSETDL5XDS0Eedm5WSGxJt/9uHv6Gz+/g9tYRKprcl k38+77tBhQVNbx7NVGTxVlvWOjvn3qCBFBjbwkedPyx9qi6lEw+cnP5JNIGInf+7F6nm AikoWpToRp+5k8rWYtUN20v085eHo9NQAMHmdFm+1hCAqZ/63TVwJYo0paGG6YoKTwuR qk7rJ1IBNB5elmKPRh/3u+uLBmwUOzgjDRPoWLJapen44rtpv8FGLTJze0XHMsdzvyNf otfCAat3Rj4wtjwy2QnObETvAipM/ZLvDzxXoENfTUGYm+7i0qtIzKeF4pLNjLbuVVHH XmGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707839139; x=1708443939; 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=fdE8AsRwFb0gP05F4tbQ9BZCrEG5/tGeZG6PUCDuRyU=; b=K9UAoURnhcKPGD0kVG3Hcho7YAJNhdjQnRrnZ4dG/VeJ9pRJL1SkK6Q4QJPCCkBzsk /UFaOwN2vFyrTTEZi97OrTU4UZ8xYX2yu88C8zlhobFXgAFbLwx4oPO/OZ8wMWG8pqNH Ze2s24adTQUiDRCxIjo0IgqnePlrjIu+x6b02L5nwaRRMyNVFJC3C4kmMY5+SvSIGuWS +bs8ht3KKs/8cRhi9hcWgrCVUBY3Gm7zmTec8PT2G3XO0NwU00xfZutZat4oNR2Hwm4k lHu6RhY/hLs6EHhvwcDY1aTy14Udvbau7v3k8zwf6nSJuafVJ5nf89mIpLkFSBCGzIEQ qvbA== X-Forwarded-Encrypted: i=1; AJvYcCUBrN6oCfdnFSoWSHuUuXyc1peQWzayIPTaElACJrzO5BShv0q0Esor1SxiqUQEXHW+qWT6X/rHflQSGvcS8JzrAUvJINWjP4gkFC0G82gfxdAUuZ8= X-Gm-Message-State: AOJu0Yy4Xr0r1DuqrABgb+SsyhNXx1lmIGU23hcGal9tcUx7+pk9OLe8 VJLoy4Pd2RdV6q7jwtjl1gWx3lM8+UXO0MyKJjZbfyii/cv5QTtCKCtiN9xfdg== X-Google-Smtp-Source: AGHT+IFxoeKa3OTAxaNsO+mmDDhMChpjiPQgXcTp+v8Z1ZiHvEuYhFO4mFCriNtZobQmR1RZo+pMvg== X-Received: by 2002:a05:600c:a3a3:b0:411:62c:b4ae with SMTP id hn35-20020a05600ca3a300b00411062cb4aemr128735wmb.7.1707839138912; Tue, 13 Feb 2024 07:45:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVV96b9s5qGlG18E562U0K/jhVyBjfPg5wT9KEFgL0gRX6FSk6j4vi3fPaYopubvQONtIsbPZ7fF0orfMLNb24rvHrdrvAOWQSrd1tklmwISXfmhn+1n21TphfjAuOVbZYJpAt8D4iNEC2bwtW0BwaZC5RHMCTTmAehDkMIpkX7Wd9o8oWPlVVekkUywEVd1xUcYlsKFt7Q4Jp0v37ul7mUZC8kjXv1jumZIzG6A72y6RGn23u36407QhjWjC5GAcfcrBMblbAnItJtRfzoOTo67sTDGTftxZbr7DAiJrz1Ra8o1/Yb8vGmOxm+DTavufbPpp8yidp/PGuXadXmUMgaMmj6fTwWx7Pavjp0FANWhlgYOrNeoMW3g1c11Q/CUq1ar87hYzEP2PcuwIiITqjdWCdmDr72BivQ1teCuEo8KcNPodf3TM3kES0DFwmWpBNUI6n0PTC7NHG3LpyyLC9YX6dYG4+WTCD35h5yaPE1YPANaV3u0Q== Received: from google.com (185.83.140.34.bc.googleusercontent.com. [34.140.83.185]) by smtp.gmail.com with ESMTPSA id fc9-20020a05600c524900b00410727c315fsm12036539wmb.16.2024.02.13.07.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 07:45:38 -0800 (PST) Date: Tue, 13 Feb 2024 15:45:34 +0000 From: Mostafa Saleh To: Jason Gunthorpe Cc: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon , Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum , Zhangfei Gao Subject: Re: [PATCH v5 11/17] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Message-ID: References: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> <11-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <11-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240213_074543_431851_9AC6132B X-CRM114-Status: GOOD ( 28.11 ) 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Jason, On Tue, Feb 06, 2024 at 11:12:48AM -0400, Jason Gunthorpe wrote: > Introducing global statics which are of type struct iommu_domain, not > struct arm_smmu_domain makes it difficult to retain > arm_smmu_master->domain, as it can no longer point to an IDENTITY or > BLOCKED domain. > > The only place that uses the value is arm_smmu_detach_dev(). Change things > to work like other drivers and call iommu_get_domain_for_dev() to obtain > the current domain. > > The master->domain is subtly protecting the domain_head against being > unused, change the domain_head to be INIT'd when the master is not > attached to a domain instead of garbage/zero. I don't this the problem here, neither the reason for initialising the domain_head, can you please clarify the issue? > Tested-by: Shameer Kolothum > Tested-by: Nicolin Chen > Tested-by: Moritz Fischer > Reviewed-by: Nicolin Chen > Signed-off-by: Jason Gunthorpe > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 ++++++++------------- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - > 2 files changed, 10 insertions(+), 17 deletions(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 133f13f33df124..a98707cd1efccb 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -2560,19 +2560,20 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) > > static void arm_smmu_detach_dev(struct arm_smmu_master *master) > { > + struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev); > + struct arm_smmu_domain *smmu_domain; > unsigned long flags; > - struct arm_smmu_domain *smmu_domain = master->domain; > > - if (!smmu_domain) > + if (!domain) > return; > > + smmu_domain = to_smmu_domain(domain); > arm_smmu_disable_ats(master, smmu_domain); > > spin_lock_irqsave(&smmu_domain->devices_lock, flags); > - list_del(&master->domain_head); > + list_del_init(&master->domain_head); > spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); > > - master->domain = NULL; > master->ats_enabled = false; > } > > @@ -2626,8 +2627,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > > arm_smmu_detach_dev(master); > > - master->domain = smmu_domain; > - > /* > * The SMMU does not support enabling ATS with bypass. When the STE is > * in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests and > @@ -2646,10 +2645,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > case ARM_SMMU_DOMAIN_S1: > if (!master->cd_table.cdtab) { > ret = arm_smmu_alloc_cd_tables(master); > - if (ret) { > - master->domain = NULL; > + if (ret) > goto out_list_del; > - } > } else { > /* > * arm_smmu_write_ctx_desc() relies on the entry being > @@ -2657,17 +2654,13 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > */ > ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, > NULL); > - if (ret) { > - master->domain = NULL; > + if (ret) > goto out_list_del; > - } > } > > ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, &smmu_domain->cd); > - if (ret) { > - master->domain = NULL; > + if (ret) > goto out_list_del; > - } > > arm_smmu_make_cdtable_ste(&target, master); > arm_smmu_install_ste_for_dev(master, &target); > @@ -2693,7 +2686,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > > out_list_del: > spin_lock_irqsave(&smmu_domain->devices_lock, flags); > - list_del(&master->domain_head); > + list_del_init(&master->domain_head); > spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); > > out_unlock: > @@ -2894,6 +2887,7 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) > master->dev = dev; > master->smmu = smmu; > INIT_LIST_HEAD(&master->bonds); > + INIT_LIST_HEAD(&master->domain_head); > dev_iommu_priv_set(dev, master); > > ret = arm_smmu_insert_master(smmu, master); > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > index cbf4b57719b7b9..587f99701ad30f 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > @@ -696,7 +696,6 @@ struct arm_smmu_stream { > struct arm_smmu_master { > struct arm_smmu_device *smmu; > struct device *dev; > - struct arm_smmu_domain *domain; > struct list_head domain_head; > struct arm_smmu_stream *streams; > /* Locked by the iommu core using the group mutex */ > -- > 2.43.0 > Thanks, Mostafa _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel