Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1555641lql; Wed, 13 Mar 2024 01:01:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWlD7yv3t4r2Shk5UInGGhf7KR26/7IhHYfn3VjiL+ZVlxyrYLJl34HMEPa7ublAeyw5Z3YPpRS/2SH17o/wPLNGaUwxyQl/EDeTZpBCg== X-Google-Smtp-Source: AGHT+IHkHExXlPJORljL+lzB+ZIivUXMemjKanxrP9mkwb67uQnUHE6SGMXpbHpagyHiu26CLLLT X-Received: by 2002:a17:906:4a0f:b0:a46:4df1:fb3c with SMTP id w15-20020a1709064a0f00b00a464df1fb3cmr1395237eju.10.1710316912454; Wed, 13 Mar 2024 01:01:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710316912; cv=pass; d=google.com; s=arc-20160816; b=osH/wL0f8WaCpwjdrpOUvTH94htmUKryD5f4I0TKPXXkzgFMToNeeKcij6nKf0h1p4 gi9K0rbG73MkhZ9h+x8A/ygLV4h0WDCvsmKJRAcdHV4IFf96XEOXaFCbHRDIJ7a4iBG4 xZKe8b73pIVSof3xrgC6CAOKwDU8Qdoaq4nATZBhBfy9Z7+1gDSKnMEFQu2hll13erlp cxksp82idY83Sm434lrWYECSeHPBrSMkqxTdDrmJ9S3Ax1YNPGCunx6sUEYPnoepaxX1 BGdyaAR+dkm2hXyetPtVsBBsXSVI6uLnui+5EjmUK/Gqzle6nwY8RmLiOpPw27m/txES erWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=2Hl/TSJlAEzSXBobGoJobK3tE6b+oLef5iCjFcejpF8=; fh=4K4PnLuWVtRg+VAEZscM8m7gKbJZZWxaHCZAq66pvtM=; b=mOFESNzcoNbIKNIn5hsCI8F1PvMj+AEPmYp9YIbycz1VbwEqWzW5ij7ab42vpLN63l VyWAJZwP3JWtn78ZiwkuQLd2+mI3PMLEwajGgLgya1vW7h+I8oHPASWd3Y6ZwSMQRJGV UiS5EpWzSyFatetrIxKSEIXlMwOaF16mJSc6Sfxk42OTL+3bYa91x42+BrNSo7rTrsTu qYzXqz+8X05zjvzeI4wFHTdm/l6O0RH77OS7B/yZZ/uVyZcoqwp4OeFLowoI83HBqCIZ semkek5dXcEyFKNwxNNIEEQaODENcqG+srPlgw+R2y+ixeMik2ej4PaihYlZsQbQpxNG DWGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cnZbTn06; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-101066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id by26-20020a170906a2da00b00a45c05cb40bsi4365964ejb.919.2024.03.13.01.01.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 01:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cnZbTn06; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-101066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 CE71C1F23107 for ; Wed, 13 Mar 2024 03:13:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE9D6101C1; Wed, 13 Mar 2024 03:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cnZbTn06" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C65AC13D; Wed, 13 Mar 2024 03:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710299614; cv=none; b=X631Q6WorWqQbNu6+tM7MnnioderjIl5LsKuYAq05XzrB6krmQB1k9Imv2kB7Bf35W1LLz7AOawfXwadPO2fbZlp9KPMKjqNTd8zPnwYQO9WR16entO5jsI4ErWIUQJ6vx8ykFCVzyVs8wO3+CMp8AHAi1KfQsj08pCZbBOuXTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710299614; c=relaxed/simple; bh=n2YjBU/qs6IdWcXohPVlN+e053Y/IEgAwN4JCjsR9HI=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=eEJ8y7xhpZIpmLmOm/RLfgxANrdes/Yh0URfByaTVQwBP4III58vbwvmYqhK7A1YYSm+TnYaoUdyWe9Ou1fR7VyNKazPOq/LLKgjmQ+O5NYsRFN2X38yimqz4W6XXJZG4GYxwwGhnMBGTb5kiWD2WQTXdfdvuYDMYRP/Qs6O9lE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cnZbTn06; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710299613; x=1741835613; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=n2YjBU/qs6IdWcXohPVlN+e053Y/IEgAwN4JCjsR9HI=; b=cnZbTn06j9fL7Uc9GrbEFm46PaPp+4qm5ALIOwpIZqjEqeCU/AH7xvwM Dl6ehvlKNdtbMao3qoZXNLA4wX3VkDP53+60dVORsJhf8rcTTUmN/rVbG 7WaBi8qgHk9ztiijbNvCutRreEy1Nh//UCMGWKyv9thd5b6cowX5iw0Tm wtkpHvVSQfdbaqeYgRWL9g2Dq+iv9yfiu9H0mus0uIf5yJRQeP+spO2/U O+p44Ak39/FpN32yWrhr9WQ5XYb8HgB97CVpKxCfJsC/Ymhp2BKtexbP7 3v9LvUWffu7x+Wf4SO5wbvrHeYujLIHvrhNj9U4+NRN9VAttDHvt7cc3f w==; X-IronPort-AV: E=McAfee;i="6600,9927,11011"; a="15598662" X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="15598662" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 20:13:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="49197836" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.254.214.116]) ([10.254.214.116]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 20:13:26 -0700 Message-ID: <87a2be0d-6a24-4ca8-be30-35287072dda4@linux.intel.com> Date: Wed, 13 Mar 2024 11:13:23 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, "joro@8bytes.org" , "alex.williamson@redhat.com" , "robin.murphy@arm.com" , "cohuck@redhat.com" , "eric.auger@redhat.com" , "nicolinc@nvidia.com" , "kvm@vger.kernel.org" , "mjrosato@linux.ibm.com" , "chao.p.peng@linux.intel.com" , "yi.y.sun@linux.intel.com" , "peterx@redhat.com" , "jasowang@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "lulu@redhat.com" , "suravee.suthikulpanit@amd.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "Duan, Zhenzhong" , "joao.m.martins@oracle.com" , "Zeng, Xin" , "Zhao, Yan Y" Subject: Re: [PATCH 1/8] iommu: Introduce a replace API for device pasid Content-Language: en-US To: Yi Liu , "Tian, Kevin" , Jason Gunthorpe References: <20231127063428.127436-1-yi.l.liu@intel.com> <20231127063428.127436-2-yi.l.liu@intel.com> <20240115171950.GL734935@nvidia.com> <585423de-9173-4c97-b596-71e1564d8b4e@intel.com> From: Baolu Lu In-Reply-To: <585423de-9173-4c97-b596-71e1564d8b4e@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024/3/12 11:07, Yi Liu wrote: > On 2024/3/11 17:26, Tian, Kevin wrote: >>> From: Liu, Yi L >>> Sent: Sunday, March 10, 2024 9:06 PM >>> >>> On 2024/1/16 01:19, Jason Gunthorpe wrote: >>>> On Sun, Nov 26, 2023 at 10:34:21PM -0800, Yi Liu wrote: >>>>> +int iommu_replace_device_pasid(struct iommu_domain *domain, >>>>> +                   struct device *dev, ioasid_t pasid) >>>>> +{ >>>>> +    struct iommu_group *group = dev->iommu_group; >>>>> +    struct iommu_domain *old_domain; >>>>> +    int ret; >>>>> + >>>>> +    if (!domain) >>>>> +        return -EINVAL; >>>>> + >>>>> +    if (!group) >>>>> +        return -ENODEV; >>>>> + >>>>> +    mutex_lock(&group->mutex); >>>>> +    __iommu_remove_group_pasid(group, pasid); >>>> >>>> It is not replace if you do remove first. >>>> >>>> Replace must just call set_dev_pasid and nothing much else.. >>> >>> Seems uneasy to do it so far. The VT-d driver needs to get the old >>> domain >>> first in order to do replacement. However, VT-d driver does not track >>> the >>> attached domains of pasids. It gets domain of a pasid >>> by iommu_get_domain_for_dev_pasid(). Like >>> intel_iommu_remove_dev_pasid) >>> in link [1]. While the iommu layer exchanges the domain in the >>> group->pasid_array before calling into VT-d driver. So when calling into >>> VT-d driver, the domain got by iommu_get_domain_for_dev_pasid() is >>> already >>> the new domain. To solve it, we may need to let VT-d driver have its >>> own tracking on the domains. How about your thoughts? @Jason, @Kevin, >>> @Baoplu? >>> >>> [1] >>> https://github.com/torvalds/linux/blob/master/drivers/iommu/intel/iommu >>> .c#L4621C19-L4621C20 >>> >> >> Jason's point was that the core helper should directly call set_dev_pasid >> and underlying iommu driver decides whether atomic replacement >> can be implemented inside the callback. If you first remove in the core >> then one can never implement a replace semantics. > > yeah, I got Jason's point. I'm raising an open to make the set_dev_pasid > callback to handle domain replacement. The existing intel iommu driver > does not track attached domains for pasid. But it's needed to know the > attached domain of a pasid and find the dev_pasid under the domain, hence > be able to clean up the old attachment and do the new attachment. Existing > code cannot work as I mentioned above. The group->pasid_xarray is updated > before calling set_dev_pasid callback. This means the underlying iommu > driver cannot get the old domain in the set_dev_pasid callback by the > iommu_get_domain_for_dev_pasid() helper. > > As above, I'm considering the possibility to track attached domains for > pasid by an xarray in the struct device_domain_info. Hence, intel iommu > driver could store/retrieve attached domain for pasids. If it's > replacement, the set_dev_pasid callback could find the attached domain and > the dev_pasid instance in the domain. Then be able to do detach and clean > up the tracking structures (e.g. dev_pasid). Maintaining the same data structure in both core and individual iommu drivers seems to be duplicate effort. It appears that what you want here is just to get the currently used domain in the set_dev_pasid path. Is it possible to adjust the core code so that the pasid array is updated after the driver's set_dev_pasid callback returns success? Best regards, baolu