From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 2B239637 for ; Tue, 26 Sep 2023 01:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695693151; x=1727229151; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=1lzgIf5/5JMxamee7JJyJ354tZveRK0X+4si66acC4k=; b=G2GuVwW3Poo9siXVc9rXLdfrvydIN1VRiGcfxo5/J0/gF0jSjkryxKE/ 8njW5b5MPohf1o2DcTsaUhTRnKM5BGED8cmgprF4mKuh1zaiiWwkQLOEP 65iLX/hwI2raXUneOPlSwYxQcTdytAnCEeQGAW1UlJbS8ttxcJArRa0kl 0mAVAnR23SdgCUMKFXTIJ3B3lmeNJ1oCcGpVUmT+dM4EmsFnVltkjcgVI e0xoVqID9hcQuJyDOsdKDcncyp0D9svmRoXwpm5IoMsJ7Lon9SPxjSXoM FyixJE1nyKnEF+UeLzlsGfPEVc6+xqQBjM3QidA+9KbjxQlgMXs4B13Fb w==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="380324778" X-IronPort-AV: E=Sophos;i="6.03,176,1694761200"; d="scan'208";a="380324778" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 18:52:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995629793" X-IronPort-AV: E=Sophos;i="6.03,176,1694761200"; d="scan'208";a="995629793" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by fmsmga006.fm.intel.com with ESMTP; 25 Sep 2023 18:52:26 -0700 Message-ID: Date: Tue, 26 Sep 2023 09:49:10 +0800 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Cc: baolu.lu@linux.intel.com, "Liu, Yi L" , Jacob Pan , "iommu@lists.linux.dev" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v5 12/12] iommu: Improve iopf_queue_flush_dev() Content-Language: en-US To: "Tian, Kevin" , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Jean-Philippe Brucker , Nicolin Chen References: <20230914085638.17307-1-baolu.lu@linux.intel.com> <20230914085638.17307-13-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 9/25/23 3:00 PM, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Thursday, September 14, 2023 4:57 PM >> @@ -300,6 +299,7 @@ EXPORT_SYMBOL_GPL(iommu_page_response); >> /** >> * iopf_queue_flush_dev - Ensure that all queued faults have been >> processed >> * @dev: the endpoint whose faults need to be flushed. >> + * @pasid: the PASID of the endpoint. >> * >> * The IOMMU driver calls this before releasing a PASID, to ensure that all >> * pending faults for this PASID have been handled, and won't hit the >> address > > the comment should be updated too. Yes. ... pending faults for this PASID have been handled or dropped ... > >> @@ -309,17 +309,53 @@ EXPORT_SYMBOL_GPL(iommu_page_response); >> * >> * Return: 0 on success and <0 on error. >> */ >> -int iopf_queue_flush_dev(struct device *dev) >> +int iopf_queue_flush_dev(struct device *dev, ioasid_t pasid) > > iopf_queue_flush_dev_pasid()? > >> { >> struct iommu_fault_param *iopf_param = >> iopf_get_dev_fault_param(dev); >> + const struct iommu_ops *ops = dev_iommu_ops(dev); >> + struct iommu_page_response resp; >> + struct iopf_fault *iopf, *next; >> + int ret = 0; >> >> if (!iopf_param) >> return -ENODEV; >> >> flush_workqueue(iopf_param->queue->wq); >> + >> + mutex_lock(&iopf_param->lock); >> + list_for_each_entry_safe(iopf, next, &iopf_param->partial, list) { >> + if (!(iopf->fault.prm.flags & >> IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) || >> + iopf->fault.prm.pasid != pasid) >> + break; >> + >> + list_del(&iopf->list); >> + kfree(iopf); >> + } >> + >> + list_for_each_entry_safe(iopf, next, &iopf_param->faults, list) { >> + if (!(iopf->fault.prm.flags & >> IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) || >> + iopf->fault.prm.pasid != pasid) >> + continue; >> + >> + memset(&resp, 0, sizeof(struct iommu_page_response)); >> + resp.pasid = iopf->fault.prm.pasid; >> + resp.grpid = iopf->fault.prm.grpid; >> + resp.code = IOMMU_PAGE_RESP_INVALID; >> + >> + if (iopf->fault.prm.flags & >> IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID) >> + resp.flags = IOMMU_PAGE_RESP_PASID_VALID; >> + >> + ret = ops->page_response(dev, iopf, &resp); >> + if (ret) >> + break; >> + >> + list_del(&iopf->list); >> + kfree(iopf); >> + } >> + mutex_unlock(&iopf_param->lock); >> iopf_put_dev_fault_param(iopf_param); >> >> - return 0; >> + return ret; >> } > > Is it more accurate to call this function as iopf_queue_drop_dev_pasid()? > The added logic essentially implies that the caller doesn't care about > responses and all the in-fly states are either flushed (request) or > abandoned (response). > > A normal flush() helper usually means just the flush action. If there is > a need to wait for responses after flush then we could add a > flush_dev_pasid_wait_timeout() later when there is a demand... Fair enough. As my understanding, "flush" means "handling the pending i/o page faults immediately and wait until everything is done". Here what the caller wants is "I have completed using this pasid, discard all the pending requests by responding an INVALID result so that this PASID could be reused". If this holds, how about iopf_queue_discard_dev_pasid()? It matches the existing iopf_queue_discard_partial(). Best regards, baolu