Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2115510rdb; Tue, 20 Feb 2024 18:49:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUh4CNpQJyK+adShiQrQr8jDp/jOHXmW45p3csVtg9IyF0uRTduunxbaZc8TiH3Y2syvrhW7G56AF2e+pG32IY26HPGuHUxZVitJ2eRzg== X-Google-Smtp-Source: AGHT+IHxqZrge7C6p5fFqdLKP8KW47MmTQERrThu36+laSBOR+HGwmyroTxkiofaSpupoT500MEM X-Received: by 2002:a05:6358:7e04:b0:176:9bfd:d092 with SMTP id o4-20020a0563587e0400b001769bfdd092mr19887387rwm.18.1708483792304; Tue, 20 Feb 2024 18:49:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708483792; cv=pass; d=google.com; s=arc-20160816; b=DMmmzqckpOHWpJA6eFYwbrP1/atMc5jm3/Y4vmfn3NMjchDcBnU/0y4A6M7TV9lmXS uf0FpyGLfoDVaBGC4p5zBCoY/SAe4iFwH1qG4L08W0HMk5JeOaWMFn6Kud1RxnBnfOpF jIPW4WQLRDKDwt3I13JgI2ye3ZceuidRymG9rZ977JaqbmkAFQebizBMSxUIQ47b2CdY Arj8FEUa3iFO2Db5Xr0fcOgbOZbQi86OD7pjcTn+8UKVGrKw+cRdj48i9E2BEbjFsiDC g0lgCrBtB0NoWWevnnDdUSGQpl+sKww5NK5pf3FUIh8zDu0Ow7PJnae1tQFxQS3IRroV 9C5Q== 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=lxtvdPikO0D3wFK3zR7keTqhktStBJy3OKU49D/C2cg=; fh=FlGbG/4p+p/dbM/Gz8LEjJvTVbHRc/I3EhxPiAUKkcc=; b=TvFXz4F4pSbyvTUz7QFW0t312vumCJF0/n9sVYukZcCphH1p7xIAfV3VVvWdHVCo0W ejL5W3VrnRuf2JPwowxOW0MVQ63r+1ZA9UDAia8Hd7NJsuozqcEDd7XImAaqCPcv0oX7 lL7BA5L/KN+qeLiiKq7q82LVbO16elRKzCknQA145A+mXJSURdB3V1b+dM9YUJoFThRF 6bFB1GThYuFh5l46aWvyoarnDyRjfL+ITpCC8KUqTH/WWhMU467c99FRT0kTBzOo+wiJ WR3mzbmU1kogHh3xAnAUF+Uj9YOSWh1pD7ChZVgmkBzIIja4qZjBLPiy7TySwPHogOg+ nSdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qv+gMPbE; 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-73974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73974-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. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s189-20020a635ec6000000b005dc4b0e5f57si6990623pgb.804.2024.02.20.18.49.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 18:49:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qv+gMPbE; 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-73974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73974-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 96010B23165 for ; Wed, 21 Feb 2024 02:45:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9CBE2836A; Wed, 21 Feb 2024 02:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="qv+gMPbE" 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 010D9273FE for ; Wed, 21 Feb 2024 02:45:13 +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=1708483515; cv=none; b=URlUpggJDK8eJrXzpFvaRjGEKUTMig+/ds0qRqOk6+R7earlBVOlK3RmFkg4s0CqxUJoYmWFvzpmktogqpuflKsUrvFR+l2NfzbwwkGQMIGJQ/JQIW6fG6PLdhn/1oOAx88z34/h5DIczFk15GXsSJRLuiBqJFqAuUMm9DvBNTo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708483515; c=relaxed/simple; bh=p4WjEooW4ErxBw+WqcK/RzKhb/ec6O5a1jY5Hxvm4JY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=reMvRIpB2eZc6b3UjSRgoslIH/wR8NaI9Y5BDrgBoBANmAiIZ1P7e059tjaRal2IqKMdpKn3vn0lsHDe59qOQJZkKKlQr61TwIxj92LrkWPqVEUsfgfhYUexKm9GAYbyFVcq4mOuFZLwXgjoy7/hM2qKZEXBN8Pnc7z3crB9w70= 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=qv+gMPbE; 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-2d109e82bd0so81679861fa.3 for ; Tue, 20 Feb 2024 18:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708483512; x=1709088312; 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=lxtvdPikO0D3wFK3zR7keTqhktStBJy3OKU49D/C2cg=; b=qv+gMPbEPgYgrCrGwR0ApI7qDZmqXbQcMuMOpngryKtor07jCD+yLSmJNgr+MQT1aQ QY0VEzg1OPld0xUuxoGU94vsfl2/6GBERCxsmjdLeZQvFKeBlOAU07yqGJCOgFexEFLp CGmKfPgZUCfxkMAxlSlMHqX5/XYAE+X9a1D8hGjtUzDw5cgtqzj0pUvrXqwksIZ83sw7 HfJkoZPZqDIAvVl2ZyJyJvQ2QDAr215vkZ1JbXctHCeN7DijW4QuSWO1gov9UOT5kGKW cS4dDu2kb/6oU+5+52saA532tGwQeRm8/l2jjSCavjeGG6kQFAvoWb/vOyj+ST4rn/7C aSVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708483512; x=1709088312; 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=lxtvdPikO0D3wFK3zR7keTqhktStBJy3OKU49D/C2cg=; b=rYHU9GwCk741KnAICGGsWYzWFM5dYI1J6L3IqadDe46TaTnRZ+8XFeOTZpCRdSRrH5 TOUCro1EzP2vAnkaFpknl2vIduvCJISJLhcT0HDj9p5MLxWozuSxvq+Q/eXivX4V/ILE exdUIk8fvm8WMQIaDJzWsviVS6/t0UdQnZrSkLHI1VMEGNPhz1XgNTvKmA6tsOivr0dg jFUt0LvJy7Ii3Vy3K4bl/A9BZAqeLx+ymGOSP2p1Hptf030+MLfFoB84jK1Ej1pUirxd YlNvfwDKn30MiDJ6qTR6pnuwOIUh6DSlAZXwl5VlQGMGO6sb9RW+B8UBYGbp1T+IlJ3F OdPw== X-Forwarded-Encrypted: i=1; AJvYcCXYHhWjllKcPRO8SY7iDnoIxbjc9iLkhXGQ83u8eHOJUwFlYEM/+AMk+3U14MWvfRAz42GPdn1L31jt42sFsWTw8S90c88dJLYz9vvV X-Gm-Message-State: AOJu0Yw2kajbSjGuE+Roqq1TjKDZlMX37juZqHpTBV4ZfxR7a448QKau AeC/sM3iPsbbm7OoTqWopMo+NV1BiwBgMLgFtiZtpjBY7DJvgPWDAI3XH4a2/PD+juYEl7TBkga PC4B3Ry+wPnOJwFbNQwgQYeCrVISUj9vngkY2wA== X-Received: by 2002:a05:651c:1a26:b0:2d2:4450:92 with SMTP id by38-20020a05651c1a2600b002d244500092mr4283969ljb.20.1708483512158; Tue, 20 Feb 2024 18:45:12 -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 10:45:00 +0800 Message-ID: Subject: Re: [PATCH v10 5/6] iommu: Support mm PASID 1:n with sva domains To: Baolu Lu Cc: "Zhang, Tina" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , David Woodhouse , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , "Tian, Kevin" , Nicolin Chen , Michael Shavit , Vasant Hegde , Jason Gunthorpe , Jean-Philippe Brucker , Hao Fang Content-Type: text/plain; charset="UTF-8" On Wed, 21 Feb 2024 at 10:06, Baolu Lu wrote: > > On 2024/2/21 9:28, Zhangfei Gao wrote: > > 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. > > Is there any real use case to bind an mm to the pasid of a device > multiple times? If there are cases, is it better to handle this in the > uacce driver? Yes, it is required for multi-thread, the device can provide multi-queue to speed up. > > From iommu core's perspective, it doesn't make sense to attach the same > domain to the same device (or pasid) multiple times. But is it the refcount domain->user++ used for? Is there any reason not doing this. Thanks