Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1616263rdh; Mon, 25 Sep 2023 20:10:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH55rFxo2a0qVHvoepuEz8Qjv6tC3kE8JbMNSDKaQtnotT91lF3Eq6w1eDNUtKTNVT3F2Ho X-Received: by 2002:a05:6a20:244a:b0:137:e595:830f with SMTP id t10-20020a056a20244a00b00137e595830fmr7396377pzc.57.1695697837120; Mon, 25 Sep 2023 20:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695697837; cv=none; d=google.com; s=arc-20160816; b=AfTNKmuNQEtng1OFi5sDTxbjEojcPanWSD06Ub+gryhSWHS9jcXYEBeAqmNkPv6llq o/P6Dy0Ii9AzQOgcfXMb8zWXcNANrAZk74QiJDyn38bg/IHPV0DHfZwgQGannB6kLJTo EtjtY6FlNqS82/00C99eRRPijpuNlGSmkJDdgnJdKuTwd6AABkFTndYiGKyKiuAI20bk EB5qnmh/2OjiUvab1OC4KyzyUqOvgOMwZEaFqIfYN1JzKZRjo/qK+pkzhA9AVgt9sIcZ VQjKev3NN42oiASnTqqWnYlh07WKV/JDsU8d5nFcVjorIPN6HIDjFsXA5+0HtsLHU/Iy i3uw== 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 :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=MfEsn5TvCs8HcKYD0mE/hsEXR9xwhU4ALqaBxnoO7eQ=; fh=4v6zqE/6yGNg4q8bfEg2ZbFdI13yFLzHn63mmcbxmHw=; b=jerXOUs59gzWlLFI9qODGjCTT0G6xa2JAlsnsvd1tj7Lr1WHbxB+CTXsyeO8hrB15E Ikdn1cg2ab+X7+c1Y52NiK4LjAmgffhUK3QqXpl9s2+bhQZDNADLRMnC0B8jBmWSCICj WmJ0FrCKhqRJ3MtKUUAxblIBqQKrKVyiPf3mylTvOReKIUdk9JD+z0yqEB4Ch2rlhS/B 5U/UB409BfwhzGEEnpcRNyodHohB2LYpUJbNjDKlUFe9P1q3wxv0NxMC6SoeTEA9bEgQ GFYTCnZv80qmr3f15/X+sJQH9FP36htNjULjhSDvJd31MYw0Hc2zzpYudUSvC1Mz2s3X EP5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B3hKsVBG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n12-20020a170902d2cc00b001b69ede5b79si70926plc.470.2023.09.25.20.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 20:10:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B3hKsVBG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 89A388069F0C; Mon, 25 Sep 2023 18:52:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231130AbjIZBwh (ORCPT + 99 others); Mon, 25 Sep 2023 21:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjIZBwh (ORCPT ); Mon, 25 Sep 2023 21:52:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B195410C; Mon, 25 Sep 2023 18:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695693150; x=1727229150; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=1lzgIf5/5JMxamee7JJyJ354tZveRK0X+4si66acC4k=; b=B3hKsVBGGw85GMDmTi/uNqN31ORClqcy6qm5eizceDGQaASkEDRRzS80 vXaQ8h1+6izlZrC4cHUoqF+WbZkp2782dV/VsfnVHax8ZWgdg5vhcSvMf 2hdK0iqufnQ8su5fB+TtmJvf/Qi6X4r+QncQ1XRrLjZXCeA5TcVgDolfN M1xrxaf/fDfqsgVPJDcb3tQgmigqejGe6B9hxND8Pe327ttk2VlqD8+Gn +1xTWdq1SJ9apI7xnNntYsw5NsFZQXXxQifCwfWkXbPqDgo0oS87X4B1E wi9iu9CcXwk6obTTQesTGFGt3TnpmR9wmzQnYEnpizvk9D+6/fqRe64L6 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="380324777" X-IronPort-AV: E=Sophos;i="6.03,176,1694761200"; d="scan'208";a="380324777" 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 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 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 18:52:49 -0700 (PDT) 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