Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp17935rda; Fri, 20 Oct 2023 18:30:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8s1wBWQp6qcfj5qUTbclQ2FDQB+jyXdPymezRPU+BwqzE04O44XAp2oISSgrOMczzOCno X-Received: by 2002:a05:6214:622:b0:66d:33c8:b83e with SMTP id a2-20020a056214062200b0066d33c8b83emr4148945qvx.26.1697851826127; Fri, 20 Oct 2023 18:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697851826; cv=none; d=google.com; s=arc-20160816; b=WfC8DBqhPaofVZoLjQoThPUEqm1Ucvx9mFZn5BaiGmEHuF0Wyc2hI2onKLuqdomlWl wK3vxStkGHrhOYfGs3y/KVU4p2dobDXNW+bfTHeaamk1xA99hFbwrXRk7vgnEhw5zvoU wH8zqT04DFea4x4OhZcV3aVuZ//Q+kcC8+DmqwL2Mga3PXugVFUeU7rj6+R8ueS67psr ILSZVkpd1jgFKZPe1hwoGnjjJlDwY2ajVIKye7XbyqHgIQLrDBUGuACfkx5l4vtnRiJH WVPnMo586J/FsrohOESNddiKBz+mdkcq1KkWJBnGzZPxjhkHLJt37hs9h30SiX19+P2z 04Tw== 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=J328geP9hjje++g7lVteVPY03ptcMOChHDDLBcmrTVw=; fh=w1swM85JoIQrU31VH/c2tqUCi9ZEtnDnJpIizkQvSnU=; b=1KSbQHtCyQh0+gWRJ17zZhj+0vJXIn4GMLfCiig42VQLhsdp60M/Md9jrt3YzOpCo/ aDL4BxPXSxjA7ihwKhvBxBVHlgl1jhyRJEEHanh2oeaG5qaNzcApALpIiYBQe2MmNlhJ iVlV0+WlStQ8qNX+eouqE1/zfn6YXQSSFWIQOifFv2KRFPknZNjbVPFah1nKoS93Ddht y9JaGIdwuNFoaEMFsltj742tK7B7L8bpNnLGVcgzW56FPB0UcqHmDJK04qT01g9miO1n ji9fnt9SjiJzDsw4rq6izi4+UUDP3AddwOsbfRZaMDymcQKMzRlsaEVFlokSQ3aDJkG+ k9fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JNHk2Yqu; 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 bm35-20020a05620a19a300b00775b23dc394si2304316qkb.287.2023.10.20.18.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 18:30:26 -0700 (PDT) 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=JNHk2Yqu; 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 5E0E383D5995; Fri, 20 Oct 2023 18:30:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbjJUBZd (ORCPT + 99 others); Fri, 20 Oct 2023 21:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjJUBZc (ORCPT ); Fri, 20 Oct 2023 21:25:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3829CD6A for ; Fri, 20 Oct 2023 18:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697851524; x=1729387524; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=zLh2pwlSFXDc8f1T4HvmKnsr4cUsTKT+TV1gVp5dCqM=; b=JNHk2YquRcw9WrfxnSgd9ro56ijSWEFG68qq8f7YULqSUtnSyErgC4+x 9wE8VcETLiCQJF+rrre80+nnQHX1UaXJixORfppkUTbSPWi04n2+hPjqV /uCTz9nuf2O85snfszwgq/pO76WXUzzOgwQ12vnrvEIQPaQBVGUXvU4+H NtN7fA1E4NGW/8CNnsmSVEFo2PbTm9jLrHDqTRC1rvEBWL5OtVbNxdgK3 cy63dTlSprvmkyulX9Vek1ZbWD7EjPxEkut+34NjuGpTepmuTHdXTJv61 mPWt40EgpS8voRx4sO51GxxSizdRDJdCs9SnoOX8g91eEzmJu53WvNrwP g==; X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="376978665" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="376978665" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 18:25:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="5268878" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.255.30.224]) ([10.255.30.224]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 18:24:09 -0700 Message-ID: Date: Sat, 21 Oct 2023 09:25:18 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, yi.l.liu@intel.com Subject: Re: [PATCH 1/2] iommufd/device: Drop enforce_cache_coherency in iommufd_device_do_replace To: Nicolin Chen , jgg@nvidia.com, kevin.tian@intel.com References: <5593200da9015fee7b2e8195c2998f36148d83de.1697848510.git.nicolinc@nvidia.com> Content-Language: en-US From: Baolu Lu In-Reply-To: <5593200da9015fee7b2e8195c2998f36148d83de.1697848510.git.nicolinc@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 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]); Fri, 20 Oct 2023 18:30:10 -0700 (PDT) On 2023/10/21 8:37, Nicolin Chen wrote: > According to the conversion in the following link: > https://lore.kernel.org/linux-iommu/20231020135501.GG3952@nvidia.com/ > > The enforce_cache_coherency should be set/enforced in the hwpt allocation > routine. The iommu driver in its attach_dev() op should decide whether to > reject or not a device that doesn't match with the configuration of cache > coherency. Drop the enforce_cache_coherency piece in replace(). Also move > the remaining "num_devices++" piece closer to the refcount that uses this > num_devices. > > Cc: stable@vger.kernel.org > Fixes: e88d4ec154a8 ("iommufd: Add iommufd_device_replace()") > Suggested-by: Tian, Kevin > Signed-off-by: Nicolin Chen > --- > drivers/iommu/iommufd/device.c | 12 ++---------- > 1 file changed, 2 insertions(+), 10 deletions(-) > > diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c > index e88fa73a45e6..c93f3478f808 100644 > --- a/drivers/iommu/iommufd/device.c > +++ b/drivers/iommu/iommufd/device.c > @@ -429,16 +429,6 @@ iommufd_device_do_replace(struct iommufd_device *idev, > return NULL; > } > > - /* Try to upgrade the domain we have */ > - list_for_each_entry(cur, &igroup->device_list, group_item) { > - num_devices++; > - if (cur->enforce_cache_coherency) { > - rc = iommufd_hw_pagetable_enforce_cc(hwpt); > - if (rc) > - goto err_unlock; > - } > - } > - > old_hwpt = igroup->hwpt; > if (hwpt->ioas != old_hwpt->ioas) { > list_for_each_entry(cur, &igroup->device_list, group_item) { > @@ -465,6 +455,8 @@ iommufd_device_do_replace(struct iommufd_device *idev, > > igroup->hwpt = hwpt; > > + list_for_each_entry(cur, &igroup->device_list, group_item) > + num_devices++; Minor: How about using list_count_nodes()? > /* > * Move the refcounts held by the device_list to the new hwpt. Retain a > * refcount for this thread as the caller will free it. Either way, Reviewed-by: Lu Baolu Best regards, baolu