Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5985981rdb; Thu, 14 Dec 2023 05:34:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbRPqhkT+d+kgwazhwFLrFQeRKaVV94sACnRMmNfMwx89r8T4rJfO7PS3DS703VIyZXEtF X-Received: by 2002:a17:903:24e:b0:1d0:4759:bb60 with SMTP id j14-20020a170903024e00b001d04759bb60mr13984321plh.26.1702560846339; Thu, 14 Dec 2023 05:34:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560846; cv=none; d=google.com; s=arc-20160816; b=krPorW+UzbhU19wr7hGYiiVrnrAYO9TsLm0m2kXyfy3cX8NqpBj5gMqdEoILTD0hIx eFXU4q5Zt46Mm7DGYnTmAzNSBPGmnFpLqhNdsUobx9Xzh4XFtDX1tdbD+TIQGnggydYV /4IxYE6xUAHAHuRz1MeOY8CPZ4/Ue5+Jv+dnL2rLff8XSEboR6OYPqdvOuWmVyPOi1mI BgCK8HEOldBD97ZOW3VybusGXDFB3ba7GhxF9lZQZ8bDVnpSp+qqM1dvRSSPobtJQMlK Sg8GYQyt9tHIYLgF7S4PpPSicEzt5YUpkIEAOnOtEEx0q8r3CAXFKLiMwxbEAQ/1lX59 my8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:to:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=CMyee2NqZ4h6CT/nnOmmP9aFhDf6QV069oti2kpZUO0=; fh=piCh8yzwHxIDyz2mi/l1BKwhNQXWZkUwkg6l/E/QqhM=; b=A7MAlQKHj7ffeegz+4vysizG7Nn8vaty+AMi/Xf6QfZAF1iMlp3wi/sjxYfB+BXpkL sSehSsUsGknEk/N8hee4XrVpS04enM3fgYdx141NvVa2QTgR485x8YKVQRPtrT3oeTF9 85HPBl622mlcDI6Ua/zqFD6bZK69l04/1WVPUC+YavOdNe4Z0iJE+PrcnCRa6cHADdFM fuWrBa30dI5Pxv+VWiKquPibFpXkHqX+i38fo4kT5HWL3Zybp2quz0E4QFgvYEOmsqOB U4afVcPsvKKjGC+ALQzHyrsHWJSS5zHFMHkj8ULnBWOcDylxBKI2oRDzU16dt9F7+w/T EVxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fN6tqZiw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id r9-20020a63ec49000000b005c662c8da8asi11759738pgj.203.2023.12.14.05.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:34:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fN6tqZiw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AD92282069C4; Thu, 14 Dec 2023 05:34:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573324AbjLNNdt (ORCPT + 99 others); Thu, 14 Dec 2023 08:33:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573304AbjLNNds (ORCPT ); Thu, 14 Dec 2023 08:33:48 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F401114; Thu, 14 Dec 2023 05:33:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702560834; x=1734096834; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=soBBTcL3N0Z5TyqqPy+iCs++Nwlxmcs4HlCzpCK+Ozw=; b=fN6tqZiwNcL/+l9lCwbG/GJFNQswxjj+zYaHGJLzfqqbAvWPdQuxKFTF DKAT515nZSkSVIIhIxerilnmI9tbNwZi2GR8ZHB5b5wC7oA0ZZlLXqiSy E6OxiwTyMJPLbYbbwFgSwXdTgGy3AEetT3gJRyYq8T3E+xNcqVYidkKfj wrnfA+vZosa5rdsVYULWZtCbBmxRAyTiHFeROFp96YgIpg2P61c3NF7Tl piTd2rklxO0a3+Wg2ppl93eEwf+WsoQC9NkJNIETTG6tUKBtqENiiR0ZM 6/eiTcy1RfZeqlAEOPCsxX8cxZx0HnW55aRozEY+BHFb8JRkt7oZ7xtCZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="375274190" X-IronPort-AV: E=Sophos;i="6.04,275,1695711600"; d="scan'208";a="375274190" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 05:33:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="892469482" X-IronPort-AV: E=Sophos;i="6.04,275,1695711600"; d="scan'208";a="892469482" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.254.210.30]) ([10.254.210.30]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 05:33:48 -0800 Message-ID: <4e08dc77-82ce-40ce-8a0c-ac9016186c23@linux.intel.com> Date: Thu, 14 Dec 2023 21:33:46 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, robin.murphy@arm.com, kevin.tian@intel.com, jgg@nvidia.com, alex.williamson@redhat.com, joro@8bytes.org, 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, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com, yan.y.zhao@intel.com Subject: Re: [PATCH 8/8] iommu/vt-d: Add set_dev_pasid callback for nested domain To: "Yang, Weijiang" , Yi Liu References: <20231127063428.127436-1-yi.l.liu@intel.com> <20231127063428.127436-9-yi.l.liu@intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:34:03 -0800 (PST) On 2023/12/14 10:55, Yang, Weijiang wrote: > On 11/27/2023 2:34 PM, Yi Liu wrote: >> From: Lu Baolu >> >> This allows the upper layers to set a nested type domain to a PASID of a >> device if the PASID feature is supported by the IOMMU hardware. >> >> The set_dev_pasid callback for non-nest domain has already be there, so >> this only needs to add it for nested domains. >> >> Signed-off-by: Lu Baolu >> Signed-off-by: Yi Liu >> --- >>   drivers/iommu/intel/nested.c | 47 ++++++++++++++++++++++++++++++++++++ >>   1 file changed, 47 insertions(+) >> >> diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c >> index 44ad48db7ea0..f6f687750104 100644 >> --- a/drivers/iommu/intel/nested.c >> +++ b/drivers/iommu/intel/nested.c >> @@ -68,6 +68,52 @@ static int intel_nested_attach_dev(struct >> iommu_domain *domain, >>       return 0; >>   } >> +static int intel_nested_set_dev_pasid(struct iommu_domain *domain, >> +                      struct device *dev, ioasid_t pasid) >> +{ >> +    struct device_domain_info *info = dev_iommu_priv_get(dev); >> +    struct dmar_domain *dmar_domain = to_dmar_domain(domain); >> +    struct intel_iommu *iommu = info->iommu; >> +    struct dev_pasid_info *dev_pasid; >> +    unsigned long flags; >> +    int ret = 0; >> + >> +    if (!pasid_supported(iommu)) >> +        return -EOPNOTSUPP; >> + >> +    if (iommu->agaw < dmar_domain->s2_domain->agaw) >> +        return -EINVAL; >> + >> +    ret = >> prepare_domain_attach_device(&dmar_domain->s2_domain->domain, dev); >> +    if (ret) >> +        return ret; >> + >> +    dev_pasid = kzalloc(sizeof(*dev_pasid), GFP_KERNEL); >> +    if (!dev_pasid) >> +        return -ENOMEM; >> + >> +    ret = domain_attach_iommu(dmar_domain, iommu); >> +    if (ret) >> +        goto err_free; >> + >> +    ret = intel_pasid_setup_nested(iommu, dev, pasid, dmar_domain); >> +    if (ret) >> +        goto err_detach_iommu; >> + >> +    dev_pasid->dev = dev; >> +    dev_pasid->pasid = pasid; >> +    spin_lock_irqsave(&dmar_domain->lock, flags); >> +    list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids); >> +    spin_unlock_irqrestore(&dmar_domain->lock, flags); > > ---> list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids); > > dev_pasid is linked at later time, this leads to > domain->has_iotlb_device is not correctly set, which finally results > into a missing of device iotlb flush in iommu_flush_dev_iotlb()when it's > called. > Check this call path: > domain_attach_iommu()->domain_update_iommu_cap()->domain_update_iotlb()->domain->has_iotlb_device = has_iotlb_device; The ugly fixup is to call domain_update_iommu_cap() or domain_update_iotlb() here again before return. > The similar issue is in intel_iommu_set_dev_pasid() and > intel_nested_attach_dev(). Yes, domain->has_iotlb_device must be updated whenever a domain is attached to (or removed from) a RID or PASID. I would be grateful if you could post some patches to fix the set_device_pasid and nested_attach_dev paths. I assume Yi can fix this series in the next version. Best regards, baolu