From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD70A9CA60 for ; Thu, 21 Sep 2023 19:03:02 +0000 (UTC) Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6561fc267dbso7154166d6.2 for ; Thu, 21 Sep 2023 12:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1695322981; x=1695927781; darn=lists.linux.dev; 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=swwjAhkLvf2PxtUGkC4GC1yABB8RkqrPI0gAF8T7JK0=; b=jLW6hEJ5ocOTt+8kzNKWmUWheQnOi5tvgRdMRRUpRUH69iZbgjABR80X+vw8PDKGcD lWttXpK51ti5qtj1UE7RRNTiKyn8Ck1d/F1JrMg5SrTpuk4KTnokpquwSahEtSiws8vD ped0ZhZDifl0e+mofbYPe9vO7ioQprCxN9ysXRuM5BN8AF1dfbvFRXr+vSMJ2V6rADSn AitotOxZ890cu3LP4lg+IsBmSDjQCZFcK4vBjeRerGhN0kacSPu6HEyGUrHzEFGaXINk fKU+EP3CeMry684AmlxQWBEHXjq4HY8e1s1siUpPiTNKDpCFCEmU354VKNqRDo8NLvxj TvOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695322981; x=1695927781; 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=swwjAhkLvf2PxtUGkC4GC1yABB8RkqrPI0gAF8T7JK0=; b=ABLwJ2x4Utvw7w3dWAKaJ2mPkUM/9pSY3wuK9S1PSiwntjtw2dRi0+AKtI3Q4oqjdI 4elgQyCjjwnugXVCaJqVhpCaPzDHjR0I0saXyBA0d+rZi9Tj6+PEQG0rGR15lwcCfR1l ut5mZiWLck8ZABNiHLx6VhUp2RogbQnEl5VoNIuJsvgB0lbw498maVuuMiyA9WmAzrNN 854GELiw9oDtOOL1av2Kj2usuMUkgU+swJTBrI+QBnXiH2RieQnhAupN4hIhRZ2169Bx fz3SR+51ksJ7FjTA7Bw6UEQqtMON4cK6rADXS1rChJP2u3o8L1CRTybliLnczhTl7MUe rx3A== X-Gm-Message-State: AOJu0YxCz0KmIY4oGvB4fT9wh5rKb/Rw5oGTAQgSuN7nO7QuCj9DNro+ KveC37ouWHY/Z9MtGpSMvWdwkw== X-Google-Smtp-Source: AGHT+IFdKgSsaiYl9w1PGP+h1hhaanbGtVCH42jDNLS/f9CfseBqiTy8DPrtBfsbOOZy50KPY8kklQ== X-Received: by 2002:a05:6214:5852:b0:655:78f5:bef7 with SMTP id ml18-20020a056214585200b0065578f5bef7mr6344042qvb.21.1695322981562; Thu, 21 Sep 2023 12:03:01 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id h20-20020a0cf414000000b0063f822dae2csm801093qvl.54.2023.09.21.12.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:03:00 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1qjOx1-000TYP-JI; Thu, 21 Sep 2023 16:02:59 -0300 Date: Thu, 21 Sep 2023 16:02:59 -0300 From: Jason Gunthorpe To: Tina Zhang Cc: Kevin Tian , Lu Baolu , Michael Shavit , Vasant Hegde , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 3/6] iommu: Introduce mm_get_pasid() helper function Message-ID: <20230921190259.GZ13795@ziepe.ca> References: <20230912125936.722348-1-tina.zhang@intel.com> <20230912125936.722348-4-tina.zhang@intel.com> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230912125936.722348-4-tina.zhang@intel.com> On Tue, Sep 12, 2023 at 08:59:33PM +0800, Tina Zhang wrote: > Use the helper function mm_get_pasid() to get a mm assigned pasid > value. The motivation is to replace mm->pasid with an iommu private > data structure that is introduced in a later patch. > > Reviewed-by: Lu Baolu > Signed-off-by: Tina Zhang > --- > > Changes in v4: > - Rebase to v6.6-rc1. > > Changes in v2: > - Update commit message. > - Let mm_get_enqcmd_pasid() call mm_get_pasid() to get pasid. > > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 12 ++++++------ > drivers/iommu/iommu-sva.c | 12 ++++++------ > include/linux/iommu.h | 10 +++++++++- > 3 files changed, 21 insertions(+), 13 deletions(-) Michael already has a series to remove this mis-use from the ARM driver like you did for the Intel driver. I think for the interm it is fine to just use mm_get_enqcmd_pasid() and Michael can remove it. It helps point out this is just wrong anyhow and better discourages anyone else from using it. > diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c > index b78671a8a914..0f956ecd0c9b 100644 > --- a/drivers/iommu/iommu-sva.c > +++ b/drivers/iommu/iommu-sva.c > @@ -23,7 +23,7 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, struct device *dev) > mutex_lock(&iommu_sva_lock); > /* Is a PASID already associated with this mm? */ > if (mm_valid_pasid(mm)) { > - if (mm->pasid >= dev->iommu->max_pasids) > + if (mm_get_pasid(mm) >= dev->iommu->max_pasids) > ret = -EOVERFLOW; > > goto out; > } > > @@ -73,7 +73,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm > > mutex_lock(&iommu_sva_lock); > /* Search for an existing domain. */ > - domain = iommu_get_domain_for_dev_pasid(dev, mm->pasid, > + domain = iommu_get_domain_for_dev_pasid(dev, mm_get_pasid(mm), > IOMMU_DOMAIN_SVA); > if (IS_ERR(domain)) { > ret = PTR_ERR(domain); > @@ -92,7 +92,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm > goto out_unlock; > } > > - ret = iommu_attach_device_pasid(domain, dev, mm->pasid); > + ret = iommu_attach_device_pasid(domain, dev, mm_get_pasid(mm)); > if (ret) > goto out_free_domain; > domain->users = 1; These ones are all manipulating the enqcmd_pasid really.. If it wasn't for enqcmd then we'd simply make each device have its own PASID and then we wouldn't have the issue that a valid pasid is incompatible with a certain device. Jason