Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1721626lqg; Mon, 4 Mar 2024 01:27:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVhB0jqkNDJXKlACaZ45iDNeiER1kRNJrbed/9oB5+aKe9ynYDGfISOtyTUYF37qPXUzqk7NjOEcqtZmBM7x+G54GMJfMEynBJa+BwH8A== X-Google-Smtp-Source: AGHT+IEAkp1b9ur0i1QNvirLQAeqZJB5SYXuKYP8iV+i7G0P2tWpihBp8D8Q4/WwL++WFs9OrYPF X-Received: by 2002:a17:902:f705:b0:1db:df16:2660 with SMTP id h5-20020a170902f70500b001dbdf162660mr12565869plo.12.1709544421106; Mon, 04 Mar 2024 01:27:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709544421; cv=pass; d=google.com; s=arc-20160816; b=l33SIAIEO6nwHBFUxiLGIvGouRgMIt/i5R6oS/oXmD5yz+mOvfvwsAfyvylRpbO322 HVTFqktBQWaJ8wDciKXLVtyOIe0FgVjx8DskHc8Za0dpxgHhBTFviSQUuf9JBNxv2iX9 I/dePzz+cuFaY5MgCBkT9xNfOgCm7KTBah274I3IVD0W+FyuvAuLxGOg5CQFvT5XYGnt Y73QJJlRog4M4isxlDxEGK58TKDLdWYvNziaACZ+dQFOxIuC4ujMl9wY41Un2LW2QzQW 1Ix9fpJg5iFhZ9c+UHzXaqFlsacYZlNVPa5y7AiJYvuJpdy+5v8qnCNzDifoQLzjlVKa gO4Q== 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=2TJ8aGged9/kVA4y7ged+9SIn4iJiELgd5tqh2aMSwY=; fh=0sytPK7UE4uOKw79i7j7Hu1zQGyv0/+63WV5KVQjwWo=; b=wG3nS1o5oOcePfbSf9aIY7Iwkbc/IBPPvFGp1enMEP8z7Ew1BHH3KHF9i0P4xdthuf CBnX4HEdv/nj/IrMNOYlYKeHNe/qgWDatX57bQ46F6Mh0+0UHWj8zeEf26+VoKiz5iWk vse0UfEHJmUlHcc20QAHpoX2/2s8VM+G7pY9hBjZRmBn3BHLS9D7m2gH1KDvCXwRMJY3 ACo2kdeZOl5vKlXDNhgs8xhARkxx4xZ66jNZeai/vK9vboyY2PPjkIRIJ/f4gF9r2lWc NJvVk0iqJYukrIz0RGph48lI8BJsoU3jVU4vRqF+/xsZguvAj/StdgFecUuVPLs4zwYq bs6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RNItvujE; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90165-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90165-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 jk8-20020a170903330800b001d9859103e0si7620653plb.153.2024.03.04.01.27.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 01:27:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90165-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=RNItvujE; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90165-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90165-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 7E85A281E5F for ; Mon, 4 Mar 2024 08:07:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8B88171A8; Mon, 4 Mar 2024 08:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RNItvujE" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 92CEC168CD for ; Mon, 4 Mar 2024 08:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709539647; cv=none; b=USQZ2wCPNOfh7qI8HY2llOGUCQ4H1IXSX/KI8hqbRq7+vntNKTqLFvZ/2Ex88QGl85aW2LWmsY7FvXVx00z1mAScZbhKo/Z69WdyIfND/VihCijBiFuI2UDl6ptZJHASTyslJxwEyRBfnvf9Gm0UyMdRrH39MvPfJ11//2EvOOE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709539647; c=relaxed/simple; bh=dMRTbw4iZl7sJrSFYrv3ms++N6+JBz9tv6hN222A2Ik=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=NIXpKrtJa2r0k4XH3db89cTSEmPkKF1ml0dlfbstLrFvB8bONzAjDPr+pmA22niO8vDIk987+KAkNRh7hz9nNQCP4bPoHeXh934TuUaec2p7Ryf/lTRJ9ih5i16YctYhe9+HgSp8KlcERTi7ckq2xz9TmKyJs3xYosuYGtdVHJo= 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=RNItvujE; arc=none smtp.client-ip=198.175.65.15 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=1709539646; x=1741075646; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=dMRTbw4iZl7sJrSFYrv3ms++N6+JBz9tv6hN222A2Ik=; b=RNItvujEy8x9ZkRdEoHY1OH4hQXkLEILjaHv717j/B8vXnpOYTxQVRQq wGVBrnKeLk2sYFuYBxDs7lT2gF/npHFbFs9YUPa/0bpuDXZzGEkC8sRpZ CUQHSgwEqKz9ruNHjlXidkw3MklfKMNxhSuLhOGnpxGNF6R/dEZ8iKgxI pFzzpcYN24oZpaGClsDpAufXqayE6uY0sSYTikgsZZfO6G6mHx5eWmnz2 XKvpXjNIMQPD1xkhmGyKaSev2cFqx1NPI416FLG56h/hpjMyDuJbu8uZX tYFsWEIejI8aLVc76OKwdeyOqbgLVcPeKkiR/IsbWY+EtCzOAGqbskryr A==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="7835006" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="7835006" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 00:07:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="8846492" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.254.211.18]) ([10.254.211.18]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 00:07:23 -0800 Message-ID: <2cc53838-c88f-43a0-b974-c5acb6f27849@linux.intel.com> Date: Mon, 4 Mar 2024 16:07:20 +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> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. */ > >> + * - Global Device-TLB invalidation to affected functions. >> + * >> + * Note that RWBF (Required Write-Buffer Flushing) capability has >> + * been deprecated for scable mode. Section 11.4.2 of the VT-d spec: >> + * >> + * HRWBF: Hardware implementations reporting Scalable Mode Translation >> + * Support (SMTS) as Set also report this field as Clear. > > RWBF info is a bit weird given existing code doesn't touch it Yes. I will remove above note. > >> + */ >> +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); >> + 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); >> +} >> + >> +static void context_entry_teardown_pasid_table(struct intel_iommu >> *iommu, >> + struct context_entry *context) >> +{ >> + context_clear_entry(context); >> + if (!ecap_coherent(iommu->ecap)) >> + clflush_cache_range(context, sizeof(*context)); > > this is __iommu_flush_cache(). You can use it throughout this and > the 2nd series. Yes. > >> + >> +void intel_pasid_teardown_sm_context(struct device *dev) >> +{ > > it's clearer to call it just intel_teardown_sm_context. pasid_table > is one field in the context entry. Having pasid leading is slightly > confusing. I used the intel_pasid prefix because this helper function is located in the pasid.c file. Best regards, baolu