Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1727665lqg; Mon, 4 Mar 2024 01:39:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVX42vlEWJytYxFvPAi+hgu1S42bV4CfUSlnienVO404u++GE6MVYkviH8OIHj1z+PsG0QSyix9EDuzjb/v6xI/RCCMcTb72QjaJZR40Q== X-Google-Smtp-Source: AGHT+IEHbmnAbGtsfsgdG1tz0Qu5i2HlCFCmIJBfvdf5FRDHKwyVSp1+izJ4g7jqi6p7O90OvVgM X-Received: by 2002:a05:6808:3a09:b0:3c1:8412:e9d1 with SMTP id gr9-20020a0568083a0900b003c18412e9d1mr12768142oib.31.1709545156364; Mon, 04 Mar 2024 01:39:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709545156; cv=pass; d=google.com; s=arc-20160816; b=roNdM1Ta8tELKSgA6/Iae+6LXi3TiHK+S7es/BILBGObgzFhBo/bHoM3RgTRVbUtAd vnaCNwJ2Hb9ZJGY5R+HMkNKhew1NfHfkT1gNf4ibXmpWcQLtxrutgkEqL4BEdU+IhNqi Ajr2j6XnX1gFc8SBRe7EONfJ0gLNsq686xOdqYE5k8ntgXG+BPBnbe+rk0qn2cWWxZmS Z5qiV975RMvDKRKEOWdLDNMIklYjHbvCzYj0jBVqoWqKiAk83wly1qAwrfAgRvJDMycp PrMRcn11spSk30nACdk0qxrcBdhueJ+kdCBfcqtX1aSEqFeSijVrP85RUaRjWoSZfEku cbGw== 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=Sf5ydK13LiH5i+0Xv/+j841s1PZpOvlXU+5sEiPweTE=; fh=0sytPK7UE4uOKw79i7j7Hu1zQGyv0/+63WV5KVQjwWo=; b=Ot8z03TfBkdyHj7Tft4yg3ujG+Fvz27Sa1OC5VSgMX0JxopfFawacp7jm8cRhkRpMP VqTWMwX2sG7ALaiRKCGhHjC++QfkZ4a5g1olDd3i5rHRir9dgrYbzQUjaYsSoX4U2+ys rI+/cSULCuRNKQFVXD+mrKtuJnDcWeXGEkVrhwUls8qXvWJ4LGVsMKhcyjWN+dVqysrP H8/SGqcKFX2f6f3VxpewgXTEpuwDYqsyIgl2zT5xbTgu7fRqdDr1AgPJj8eqLtydUMnm d5AkfGydy2OpnhU1jZjrD0ONjbYIwDDSaC5h1mlkfdcVuZ7s3A1mV91MUo0Bk5zg5HLk 6Rfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hd1u5h0Y; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90333-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90333-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id le4-20020a056a004fc400b006e61fc3f66bsi1720336pfb.221.2024.03.04.01.39.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 01:39:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90333-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hd1u5h0Y; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90333-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90333-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F081F2824B6 for ; Mon, 4 Mar 2024 09:39:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 916651A731; Mon, 4 Mar 2024 09:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hd1u5h0Y" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 223191BC3D for ; Mon, 4 Mar 2024 09:39:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709545149; cv=none; b=SH3CRR4lThlo64LEKa3H7+V4WXIZWimxNpgQO5IzaKfR2cgYJ4TnRGJt/mDCP9pQ4Dn4y9FyVJ7Mbig2l6Pv30QDs2uWQ9qpZoeco6+Iiq2BaMM/uX+We5dQSjSzE79EFrLKSshOuNo7KxLd73mWzqHpkyn1OeRdlMBZVxXYjgY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709545149; c=relaxed/simple; bh=zw1bKc+mpb3Eq0EH3dsgVKb7A+Jz5grqECA/b0F7Vl0=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=hBmTs9zgiN7p0oksEiWH1/h2fLRglCSMprQ2YuKO6daN2lp9+GQyMe3ilP2mjpFQHPVJv8Ed5Y0BNqxfBeyw/VBConi4tRxO+bl3nw/1KfH8hpqDJrPlZiL0Ft7REb8pUCDErN87wxvxwa2zi5fCFTp3Wis8A1CWqfj3r3hpbfk= 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=hd1u5h0Y; arc=none smtp.client-ip=192.198.163.8 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=1709545148; x=1741081148; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=zw1bKc+mpb3Eq0EH3dsgVKb7A+Jz5grqECA/b0F7Vl0=; b=hd1u5h0YIuJ1JRwH4eKRAzeM/TGb56ZZoWr3QNXCOdu1/Hd+FwfDILo8 ZP4SEj0vlAvXdq6GwTWHU6W3i20DDb3i7w8lbRTmMDMK9v6NAvCIeEFWY wOVRvP6K+2C7uVJYa0o1RjsgN59Bb/G9OyLv+ofjeCiBNfP6GxK1NADSJ RTsMyE8xfGspzGCrlp/JzY/ZPh0Kjp0CHm2K8H3aUBIH/3jNi4jw4C6NJ MywMg5tcaJg0wZBCE5YDRJH//+HOzZjMqvYlSqGqH9VUJaHtjBiadtQEO klz245xg5xnauQslwg2q00424RwQikOFTH7OTGXp9NPDVzxTNGOOKv+eF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="21562712" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="21562712" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 01:39:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="13495049" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.254.211.18]) ([10.254.211.18]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 01:39:05 -0800 Message-ID: <4fadb386-e441-4464-9af1-0d369aed717e@linux.intel.com> Date: Mon, 4 Mar 2024 17:39:03 +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, "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 2/2] iommu/vt-d: Fix NULL domain on device release Content-Language: en-US To: "Tian, Kevin" , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , "Badger, Eric" References: <20240229094613.121575-1-baolu.lu@linux.intel.com> <20240229094613.121575-3-baolu.lu@linux.intel.com> <2cc53838-c88f-43a0-b974-c5acb6f27849@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/3/4 16:59, Tian, Kevin wrote: >> From: Baolu Lu >> Sent: Monday, March 4, 2024 4:07 PM >> >> On 2024/3/4 15:36, Tian, Kevin wrote: >>>> From: Lu Baolu >>>> Sent: Thursday, February 29, 2024 5:46 PM >>>> >>>> + >>>> +/* >>>> + * Cache invalidation for changes to a scalable-mode context table >>>> + * entry. >>>> + * >>>> + * Section 6.5.3.3 of the VT-d spec: >>>> + * - Device-selective context-cache invalidation; >>>> + * - Domain-selective PASID-cache invalidation to affected domains >>>> + * (can be skipped if all PASID entries were not-present); >>>> + * - Domain-selective IOTLB invalidation to affected domains; >>> >>> the spec talks about domain-selective but the code actually does >>> global invalidation. >> >> I should have included the following comments below: >> >> /* Given that we have no idea about which domain IDs and PASIDs were >> * used in the pasid table, upgrade them to global PASID and IOTLB >> * cache invalidation. This doesn't impact the performance significantly >> * as the clearing context entry is not a critical path. >> */ >> > > but then it affects all other perf-critical paths which rely on the cache > for other devices... You are right. Good consideration. > > It's preferable to restrict overhead to this release path only e.g. walking > the PASID table to identify affected DIDs and PASIDs instead of expanding > the impact to system wide. The sm_context_flush_caches() could be used in two different paths: - Deferred attachment case; - Normal device release path. For the formal case, we have to use global cache invalidation; but the the latter case, it's fine to skip these cache invalidation. The new helper probably looks like below. /* * Cache invalidation for changes to a scalable-mode context table * entry. * * Section 6.5.3.3 of the VT-d spec: * - Device-selective context-cache invalidation; * - Domain-selective PASID-cache invalidation to affected domains * (can be skipped if all PASID entries were not-present); * - Domain-selective IOTLB invalidation to affected domains; * - Global Device-TLB invalidation to affected functions. * * For kdump cases, old valid entries may be cached due to the in-flight * DMA and copied pgtable, but there is no unmapping behaviour for them, * thus we need explicit cache flushes for all affected domain IDs and * PASIDs used in the copied PASID table. Given that we have no idea about * which domain IDs and PASIDs were used in the copied tables, upgrade * them to global PASID and IOTLB cache invalidation. * * For normal case, the iommu has been parked in blocking state. All PASID * entries are in non-present now. Skip PASID and IOTLB cache invalidation. */ static void sm_context_flush_caches(struct device *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; iommu->flush.flush_context(iommu, 0, PCI_DEVID(info->bus, info->devfn), DMA_CCMD_MASK_NOBIT, DMA_CCMD_DEVICE_INVL); if (context_copied(iommu, info->bus, info->devfn)) { qi_flush_pasid_cache(iommu, 0, QI_PC_GLOBAL, 0); iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH); } devtlb_invalidation_with_pasid(iommu, dev, IOMMU_NO_PASID); } Does it look good for you? Best regards, baolu