Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2086795rdb; Tue, 20 Feb 2024 17:28:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUyoSkCzgVoKCAjo0iTFHAwcd01qQhF2WaZ7JjSDT8/Sq/7DcPz9HQUshSpQhw89nKqog6dT/47NqrZex3oPuQXeKe5kCoEiXz/K/U+Bg== X-Google-Smtp-Source: AGHT+IHm28GsKXoP13euXvaqVA7vwRQ0say2BtXDKxuZ21OghEE73KDMiMCoDbNeXerYbDfPTw/Z X-Received: by 2002:a05:6402:1812:b0:564:ab98:35ea with SMTP id g18-20020a056402181200b00564ab9835eamr3848480edy.12.1708478910474; Tue, 20 Feb 2024 17:28:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708478910; cv=pass; d=google.com; s=arc-20160816; b=iArsHNvrXoTiBy7vV19k02qoU/iQbhvty6Qb7eP8U9W+tjWpbe/qUYRJGmdsMpruLk /Vqhwv0rZPykZqT3NOp/N5cjaid6S7zm5VMa7fQ7djZw3OCmiXaOv6cc7v+19RT92Q+G PyKWp/6wRRIIi9zl7INVC973o31iyafnqDBDgYPGAXCO3KUYVw/uKpljKfqdC/LntyUE FQvBRRZjZYUGBUbJbhZWLfyCRFfr1UyE0i0DK8JFH2skWW8kdRk3/dBh7oFTSf3rmzqt U2T5r0+YzNdJGBYbfXqjOnuVJGxxRepWj3nZWDWqodu9tUYV1pvmLLjuG0srWb4cY4av 4vag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=nYNt1GrpQrtFfSNviDmfzHNLw/OwvxTSzUWQXin35bs=; fh=aSUFV2w3/QYIH+kpf3b4f0BkaX3Y2ss0iiuCPPAQsqE=; b=iHCxyKxTqVS/PdeF3PbdwjJwI+y3YJCRYaA8Xw+6cEEuxyu31AnAduUtag8n9zkI0j XKSj0cTgfLydsJdh2lddE5OYh/OO3mQMOWz+DSjo/4+igru1IG/TAHfwL7tgkMWY069T Q2IGauqmA9501VcWAV36ye29Ok4qJOarbBG+yjWTzWcd0tSPYkysFdiD8eJbn/H7AlBb 7dNPi8sdSYOH5413G6UNUXajvX7QFvoEtXN2lQGF+xTMTlSHdxh3KtuKBtz2lkRPHkH7 qY9lvE+3K5XS4kQykIjNGPdg+ZWGQPi8KuxeA9gHdhN/RgZ/aLEu2y3Dljjwr/lSaKaI kVLw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tcN55P1L; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-73906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u19-20020a50a413000000b005644211a4c8si3200225edb.689.2024.02.20.17.28.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 17:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tcN55P1L; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-73906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3E8FC1F24506 for ; Wed, 21 Feb 2024 01:28:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 884614694; Wed, 21 Feb 2024 01:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tcN55P1L" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.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 F0A5C17D5 for ; Wed, 21 Feb 2024 01:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708478902; cv=none; b=IZ/EFeZyECBh8zRuqfot3DNIZKxPCZE7Pmb8v3wRgFbubyjN37zH9v0Dr0mVFTX2s7ZxHgSag+8Sfqhw764g6/3hAv1huyoVZbNrpEe4Oox+ikUDv6cIWrTsPKzhXM6dlrCe33ZApWur+ZuSTCindR5+iwMjdoFyDigPSCrbxmY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708478902; c=relaxed/simple; bh=miuWVSUfiT4bw6c4HADcYw+Oa2GyLFZkBZGaNA1iiHM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=cq3PYLwP0qverrstVK3QwJ9uQ4GoRY0cCEunfz6a7OXjdbWODOjIxqzbULdIXY2lTuD47LpTPzVUI1Bm6rhfMhEYI+Bv06aHjhfunFyeotynXf+3cntWMqpo/Z1t/F3fubzRg1Aq8w9K3RfFaQuhz1QCk9Dm6I87oyVHUjbWzSk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tcN55P1L; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-512be87a0f3so105307e87.3 for ; Tue, 20 Feb 2024 17:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708478899; x=1709083699; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nYNt1GrpQrtFfSNviDmfzHNLw/OwvxTSzUWQXin35bs=; b=tcN55P1LaNtXahXtvZKWe8w936K3Q5xNs5H4EYRpHAQxTwn55g0lvKgLa6C3QLX1k1 7LflE8ytOamO5kfVyLe4P/sKAYsk5BfFUNPuVbksAE6kcXiSTTygqZTpypb3oLn3ZqGz 8010hWfg+DSmMgj4whgfrlbsmXrjRUpK3mhaj5uqyAY0MR0dMy33eUoDsMinAJZf5C8e iZ90HSgM9rNlOVSjhBdqIC6Y/N5BZ8iwlLvEZc+mDDn6IvhStTROTxFwtz9SZJf4R2ps 6RnS5uMzrlmsieuVbcOVEBTvzyS599rhcJIbYNBq1PgrNPqeiGgFvJ/l0mMjmY/9PRUY I3Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708478899; x=1709083699; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nYNt1GrpQrtFfSNviDmfzHNLw/OwvxTSzUWQXin35bs=; b=OoJJHUR7ibkWcofKmKB7ZXEGtChZSq2j5lWAc4Jcf61fuy+D6XF8AsG6ypXWKtZRyU 5m+VPheQSZBJf/bHYRyEeOmEdEF2QQtHH6Y2RtjS0zrBGmljBrGwPcHrDTNqinPc/u5+ gD0EiXJ7IA/qDWj924ECC02KsXd6I6ObfDuz3ckBQ+l9IB0XrbsrKkoJuIB8RESLu80n 9toGJNn844SEsf4ERnracl7l19WMFcJZU64HJKZXFGXIuil1I9fMn4L7XxmEccTyvqBL P6WHXtcPO3XnX5uK75af2rNgW5UO3S/hbKotLw4ve4K605mLFx76vfB7LA8Yv4Q28AQO d9KA== X-Forwarded-Encrypted: i=1; AJvYcCXQgPEmZENIV+qWLmozpB7ykdrVaZ94VowaPtZqsUjHTQ6PbnZhFMyOAx6OFAG/clEuiX3A+iFTiEZCPXMj4hR/sjQ5tkJcH3z8UgxU X-Gm-Message-State: AOJu0YwDfjBjLapr3srQJLJkmyTqUEifsy9zYZ3A5y9dQwr2flIhHbUs 9BgvCGA8Nt99KHmQxbWvoTEi00XT9yWJ2k4da6MZoE3eydYDx83e0mZ6A+FPlEKLrejuy0raaGs NN+TMvS77FlY1Fpzp2rc9IKkMIRDR3GTwXh7JmA== X-Received: by 2002:a05:6512:3e6:b0:512:ba41:51f with SMTP id n6-20020a05651203e600b00512ba41051fmr3710314lfq.50.1708478899197; Tue, 20 Feb 2024 17:28:19 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231027000525.1278806-1-tina.zhang@intel.com> <20231027000525.1278806-6-tina.zhang@intel.com> In-Reply-To: From: Zhangfei Gao Date: Wed, 21 Feb 2024 09:28:07 +0800 Message-ID: Subject: Re: [PATCH v10 5/6] iommu: Support mm PASID 1:n with sva domains To: "Zhang, Tina" Cc: "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , "Tian, Kevin" , Nicolin Chen , Michael Shavit , Vasant Hegde , Jason Gunthorpe Content-Type: text/plain; charset="UTF-8" Hi, Tina On Wed, 21 Feb 2024 at 07:58, Zhang, Tina wrote: > > > struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct > > > mm_struct *mm) { > > > + struct iommu_mm_data *iommu_mm; > > > struct iommu_domain *domain; > > > struct iommu_sva *handle; > > > int ret; > > > > > > + mutex_lock(&iommu_sva_lock); > > > + > > > /* Allocate mm->pasid if necessary. */ > > > - ret = iommu_sva_alloc_pasid(mm, dev); > > > - if (ret) > > > - return ERR_PTR(ret); > > > + iommu_mm = iommu_alloc_mm_data(mm, dev); > > > + if (IS_ERR(iommu_mm)) { > > > + ret = PTR_ERR(iommu_mm); > > > + goto out_unlock; > > > + } > > > > > > handle = kzalloc(sizeof(*handle), GFP_KERNEL); > > > - if (!handle) > > > - return ERR_PTR(-ENOMEM); > > > - > > > - mutex_lock(&iommu_sva_lock); > > > - /* Search for an existing domain. */ > > > - domain = iommu_get_domain_for_dev_pasid(dev, mm->pasid, > > > - IOMMU_DOMAIN_SVA); > > > - if (IS_ERR(domain)) { > > > - ret = PTR_ERR(domain); > > > + if (!handle) { > > > + ret = -ENOMEM; > > > goto out_unlock; > > > } > > > > > > - if (domain) { > > > - domain->users++; > > > - goto out; > > > > Our multi bind test case broke since 6.8-rc1. > > The test case can use same domain & pasid, return different handle, > > 6.7 simply domain->users ++ and return. > > > > > + /* Search for an existing domain. */ > > > + list_for_each_entry(domain, &mm->iommu_mm->sva_domains, next) > > { > > > + ret = iommu_attach_device_pasid(domain, dev, > > > + iommu_mm->pasid); > > > > Now iommu_attach_device_pasid return BUSY since the same pasid. > > And then iommu_sva_bind_device attach ret=-16 > Sounds like the test case tries to bind a device to a same mm multiple times without unbinding the device and the expectation is that it can always return a valid handle to pass the test. Right? Yes The device can bind to the same mm multi-times and return different handle, Since the refcount, no need to unbind and bind sequently, The unbind can happen later with the handle. Thanks