Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2095822rdb; Tue, 20 Feb 2024 17:54:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVMeeYwpJuvi2zvhQzw+JLC8aCPoo1c24T6smjNRC4g7qm52t5/5M7RBEcMOTNScIulxT3w4CzvS5T3NUBnyrIj1qAun8pmSzDpJGNPeA== X-Google-Smtp-Source: AGHT+IHggsqHrwUGGC6ftFrvT8obv+os8sR302WM97yQ+H0LbQe49uD7QVd3A+gdpSkzUDj26K13 X-Received: by 2002:a05:6a20:3e0b:b0:19e:9af8:40e3 with SMTP id m11-20020a056a203e0b00b0019e9af840e3mr11422540pzc.16.1708480442198; Tue, 20 Feb 2024 17:54:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708480442; cv=pass; d=google.com; s=arc-20160816; b=p4EHToY25HPoqu7Mib5+hVbCun72440vxkdYApPWwScbJHLDoSf4LM4OmLoj/XUsQ6 QGSvd/I0ZA1jcWEUb2hbKyx4PyHnY0k0QbWp7xIn499cM3YLoxiEpGpOd6RqzDgZdbGu Sj+2q3vl905D/zKqriopWBWaRYbwbx4iVtePT6sIrmjWENdvZP+kUIAf87N5ZuRyu8pt +xTdijjWQ0X6F+p5h27Ejs3hVUxGKJ2fd8xKYCh01cUpvZTJ8LqoH2ORPXde4BiWqJkd g/DDIuXmiAk/l9gopA8Qzj33AYqAMO6eInYo+1hwXRiJvoi4MiCrjK/nA5M9MI/vTNL8 MeoQ== 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=xNv57wTrROpvBu7D7eRkAMBX/0S6ivveyoxRqXbvKXQ=; fh=fmEGt55gTTYNa6sb6hcZy+SY43Wr0hrrRyzvqHGJNXc=; b=T+ovJhEOntGu2qtfj2s1AsUqSP9i/PkNXjNE9cI4eohQS4SDPdHQMNrbWrPtVPuYXt XuApS260HV78vFbfmxbVNPmPckPqpBgC70aVmtwsp/3yfQ/L+YM6NYDKk/LNLS8g0b2h E/YcEQ5hZ/zOCLXvC60VtCIDq8QZ6l/zQ+eu9bk7UGPDRqyDDRlBOOHFQHZ/ECzj7EmZ QaT8J9TWtgX0mEjrvhdlr9Ac5RcwvERAIgSwZQMO7gnxRpYf+Mzl8ll0KxBjwEC7mePU bHs75Blox83P32ykhVeYnNYj4IIlDCOcqVFirhAgJk4QVIQf14Mn0h2rNGcqcjsCQvXp uGLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p1m1hVpO; 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-73916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e8-20020a170903240800b001dbe81d155csi5157849plo.412.2024.02.20.17.54.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 17:54:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p1m1hVpO; 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-73916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73916-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6E7EAB2371C for ; Wed, 21 Feb 2024 01:53:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01A954C86; Wed, 21 Feb 2024 01:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="p1m1hVpO" Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 31DFE6FAE for ; Wed, 21 Feb 2024 01:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708480430; cv=none; b=p+lFrnt1fCoiMWQ5SCFqufE9ngshqDJSPm43RZ7s3aXj1t3VRd+SGTtiAK+i++rK9ptKfESfIUKtsxb196tkCpvZRqDVQ6DFkITAvcsGKPxIUkpPbfSz1tF5VBaetWc3bt6vN/A/zRndbo9ZUJlnmuwyOWbwMxb6MCvi5WMs02o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708480430; c=relaxed/simple; bh=X7DS4AxqZmwIGaiOTbhL7uSmpzpJXN4zPisSmEhXWzw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Ylo8lfogLL4ptGzw+j4LzQpp/Je3yuPQXI/fTVj3WtlhoL2p3mNlmGjAGJibhwioYhVvGYukorxPAzaLF1fmdRgp16snHyFz6raOZfVRj6sFdm9xAEBqu9SJJtOwAC53mYpuu9HUcGuKvo0vnbh1iy76cdk751XIUg+OTPhQ2qo= 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=p1m1hVpO; arc=none smtp.client-ip=209.85.208.175 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-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d21cdbc85bso1074201fa.2 for ; Tue, 20 Feb 2024 17:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708480426; x=1709085226; 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=xNv57wTrROpvBu7D7eRkAMBX/0S6ivveyoxRqXbvKXQ=; b=p1m1hVpOwX/WbQY1KOCL3TDL7t+jJveS529gwfL5BcYVmp2m9MiXlGX5//upZDhYJ6 2BmYVmhUl/3EE2KPIJQpIxJ4yzi/0/nC9eUzI6yqhQBDWR+1QoUWlfkuWFdIBFFcR56P yBJrW7qWCfHoTPidBUtK93YX9ydV2Ya8yYeGcQfUY+lDs8OBLi71HsNThXcN6aDwAimH IxFef8G6sZ9zCjc/wEn1JkhvWW8BxOS20BIwJlC7PsIYaG6/Xi933r51RS3G/247B+KC OGi0lanGqoKcJXG2AfzF712v1huH37O8RDKOkMEDkMcoGUg3ah8Au4UrZeOsIOwZH0kt nLag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708480426; x=1709085226; 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=xNv57wTrROpvBu7D7eRkAMBX/0S6ivveyoxRqXbvKXQ=; b=XIQZreEF5ygbT6hVJ/ps9CuCibxEhE8A8LC11knG5DLeyju6M5JhNSO4IL5ddlODxr RWQwhr20DOCvMxHwknjXOzZpltsgO7/6cUJvX207+LH6aPnEuaI/9EkRMKneOtg548BL 5TLO0zOGTXw/jSJ8rDKcOEEh64zoMLnozsiMQX0LmuAqjqWviOqwPWj9mJHaQFsWCxNH SkbkXVQnX++QfkfTTu257tSzwxB+rYP4H0q13/g92DJLD6FKF3KzkwGOrgU+cSavRwt0 KdmfOhMdCjbk+PyxVa5nanwmXtNK7l7DCn0f9Nh4oPOVESp8a5JW9ECmyLET+RzqGhzh SA1g== X-Forwarded-Encrypted: i=1; AJvYcCXfdjjeBUAGchv3SMX2bXCAqrxAv3rUk5psu/F3u4H0GzM2eGXKD120hY+G69CFzbywVlykHdIzaiS6cxyhESmzWW7ItgrnCGHMWnk+ X-Gm-Message-State: AOJu0YwknRTyfEzGBlacalYruYSDzRdagbNzfiHUQNjAjdVWh4yl2u5j SVOCjvGnbCcSwbXDjbqzsG/1IXwz6orKGcf9dTbY9dVysMsYwE07pBNtAtAH/PRu7yzNnIjDUNC huTKnbyZPzF2RDo0kdGLDxZDg5hSmbXKx9HZ8oA== X-Received: by 2002:a05:6512:2021:b0:512:b041:d6cc with SMTP id s1-20020a056512202100b00512b041d6ccmr5213332lfs.29.1708480426340; Tue, 20 Feb 2024 17:53:46 -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:53:34 +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" On Wed, 21 Feb 2024 at 09:28, Zhangfei Gao wrote: > > 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. With this diff can solve the issue, what's your suggestion? @@ -88,10 +94,12 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm /* 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); - if (!ret) { + if (!ret || ret == -EBUSY) { domain->users++; goto out; } @@ -141,8 +151,8 @@ void iommu_sva_unbind_device(struct iommu_sva *handle) struct device *dev = handle->dev; mutex_lock(&iommu_sva_lock); - iommu_detach_device_pasid(domain, dev, iommu_mm->pasid); if (--domain->users == 0) { + iommu_detach_device_pasid(domain, dev, iommu_mm->pasid); list_del(&domain->next); iommu_domain_free(domain); } Thanks