All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: baolu.lu@linux.intel.com, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>,
	Nicolin Chen <nicolinc@nvidia.com>, Yi Liu <yi.l.liu@intel.com>,
	iommu@lists.linux.dev, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/9] iommu: Add common code to handle IO page faults
Date: Wed, 12 Jul 2023 10:37:03 +0800	[thread overview]
Message-ID: <0438aba6-650b-9b9f-21d1-dc355759fd65@linux.intel.com> (raw)
In-Reply-To: <20230711135056.4b1fd94a@jacob-builder>

On 2023/7/12 4:50, Jacob Pan wrote:
> Hi Lu,
> 
> On Tue, 11 Jul 2023 09:06:36 +0800, Lu Baolu <baolu.lu@linux.intel.com>
> wrote:
> 
>> The individual iommu drivers report iommu faults by calling
>> iommu_report_device_fault(), where a pre-registered device fault handler
>> is called to route the fault to another fault handler installed on the
>> corresponding iommu domain.
>>
>> The pre-registered device fault handler is static and won't be dynamic
>> as the fault handler is eventually per iommu domain. Replace the device
>> fault handler with a static common code to avoid unnecessary code.
>>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>>   drivers/iommu/iommu.c | 24 +++++++++++++++++++++++-
>>   1 file changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index da340f11c5f5..41328f03e8b4 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -1278,6 +1278,28 @@ int iommu_unregister_device_fault_handler(struct
>> device *dev) }
>>   EXPORT_SYMBOL_GPL(iommu_unregister_device_fault_handler);
>>   
>> +static int iommu_handle_io_pgfault(struct device *dev,
>> +				   struct iommu_fault *fault)
>> +{
>> +	struct iommu_domain *domain;
>> +
>> +	if (fault->type != IOMMU_FAULT_PAGE_REQ)
>> +		return -EINVAL;
>> +
>> +	if (fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID)
>> +		domain = iommu_get_domain_for_dev_pasid(dev,
>> fault->prm.pasid, 0);
>> +	else
>> +		domain = iommu_get_domain_for_dev(dev);
> we don't support IOPF w/o PASID yet, right?

It's the individual driver that decides whether iopf w/o pasid is
supported or not. The iommu core doesn't need to make such assumption.

> 
>> +
>> +	if (!domain || !domain->iopf_handler)
>> +		return -ENODEV;
>> +
>> +	if (domain->iopf_handler == iommu_sva_handle_iopf)
>> +		return iommu_queue_iopf(fault, dev);
> Just wondering why have a special treatment for SVA domain. Can
> iommu_queue_iopf() be used as SVA domain->iopf_handler?

Yes. I will make this change according to Kevin's suggestion in this
thread.

> 
>> +
>> +	return domain->iopf_handler(fault, dev, domain->fault_data);
>> +}
>> +
>>   /**
>>    * iommu_report_device_fault() - Report fault event to device driver
>>    * @dev: the device
>> @@ -1320,7 +1342,7 @@ int iommu_report_device_fault(struct device *dev,
>> struct iommu_fault_event *evt) mutex_unlock(&fparam->lock);
>>   	}
>>   
>> -	ret = fparam->handler(&evt->fault, fparam->data);
>> +	ret = iommu_handle_io_pgfault(dev, &evt->fault);
>>   	if (ret && evt_pending) {
>>   		mutex_lock(&fparam->lock);
>>   		list_del(&evt_pending->list);
> 
> 
> Thanks,
> 
> Jacob
> 

Best regards,
baolu

  reply	other threads:[~2023-07-12  2:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11  1:06 [PATCH 0/9] iommu: Prepare to deliver page faults to user space Lu Baolu
2023-07-11  1:06 ` [PATCH 1/9] iommu: Move iommu fault data to linux/iommu.h Lu Baolu
2023-07-11  6:05   ` Tian, Kevin
2023-07-12  2:07     ` Baolu Lu
2023-07-12  9:33       ` Jean-Philippe Brucker
2023-07-13  3:22         ` Tian, Kevin
2023-07-13  3:48           ` Baolu Lu
2023-07-11  1:06 ` [PATCH 2/9] iommu: Add device parameter to iopf handler Lu Baolu
2023-07-11 17:26   ` Jacob Pan
2023-07-12  2:16     ` Baolu Lu
2023-07-12  5:46       ` Jacob Pan
2023-07-11  1:06 ` [PATCH 3/9] iommu: Add common code to handle IO page faults Lu Baolu
2023-07-11  6:12   ` Tian, Kevin
2023-07-12  2:32     ` Baolu Lu
2023-07-12  9:45       ` Jean-Philippe Brucker
2023-07-13  4:02         ` Baolu Lu
2023-07-11 20:50   ` Jacob Pan
2023-07-12  2:37     ` Baolu Lu [this message]
2023-07-11  1:06 ` [PATCH 4/9] iommu: Change the return value of dev_iommu_get() Lu Baolu
2023-07-11 21:05   ` Jacob Pan
2023-07-11  1:06 ` [PATCH 5/9] iommu: Make fault_param generic Lu Baolu
2023-07-11  6:14   ` Tian, Kevin
2023-07-12  2:43     ` Baolu Lu
2023-07-11 21:31   ` Jacob Pan
2023-07-12  3:02     ` Baolu Lu
2023-07-11  1:06 ` [PATCH 6/9] iommu: Remove iommu_[un]register_device_fault_handler() Lu Baolu
2023-07-11  1:06 ` [PATCH 7/9] iommu: Add helper to set iopf handler for domain Lu Baolu
2023-07-11  1:06 ` [PATCH 8/9] iommu: Add iommu page fault cookie helpers Lu Baolu
2023-07-11  1:06 ` [PATCH 9/9] iommu: Use fault cookie to store iopf_param Lu Baolu
2023-07-11  6:26   ` Tian, Kevin
2023-07-12  3:09     ` Baolu Lu
2023-07-11 22:02   ` Jacob Pan
2023-07-12  3:13     ` Baolu Lu
2023-07-13  3:24       ` Tian, Kevin
2023-07-13  3:43         ` Baolu Lu
2023-07-13  8:01           ` Tian, Kevin
2023-07-14  2:49             ` Baolu Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0438aba6-650b-9b9f-21d1-dc355759fd65@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=jean-philippe@linaro.org \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    --cc=yi.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.