iommu/core: pass user-provided token when handling faults
PATCH 1/1 iommu/core: pass user-provided token when handling faults
Sometimes a single IOMMU user may have to deal with several different IOMMU devices (e.g. remoteproc).
When an IOMMU fault happens, such users have to regain their context in order to deal with the fault.
Users can't use the private fields of either the iommu_domain or the IOMMU device, because those are already used by the IOMMU core and low level driver (respectively).
This patch just simply allow users to pass a private token (most notably their own context pointer) to iommu_set_fault_handler(), and then makes sure it is provided back to the users whenever IOMMU faults happen.
--- drivers/iommu/iommu.c | 5 ++++- include/linux/iommu.h | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/iommu/iommu.c +4 -1
@@ -119,6 +119,7 @@ EXPORT_SYMBOL_GPL(iommu_present);* iommu_set_fault_handler() - set a fault handler for an iommu domain * @domain: iommu domain * @handler: fault handler +* @token: user data, will be passed back to the fault handler * * This function should be used by IOMMU users which want to be notified * whenever an IOMMU fault happens.
@@ -127,11 +128,13 @@ EXPORT_SYMBOL_GPL(iommu_present);* error code otherwise. */ void iommu_set_fault_handler (struct iommu_domain *domain, -iommu_fault_handler_t handler) +iommu_fault_handler_t handler, +void *token) {BUG_ON (!domain); domain->handler = handler; + domain->handler_token = token; }EXPORT_SYMBOL_GPL (iommu_set_fault_handler);
include/linux/iommu.h +5 -3
@@ -35,12 +35,13 @@ struct iommu_domain;#define IOMMU_FAULT_WRITE 0x1typedef int (*iommu_fault_handler_t )(struct iommu_domain *, -struct device *,unsigned long ,int ); +struct device *,unsigned long ,int ,void *);struct iommu_domain {struct iommu_ops *ops;void *priv;iommu_fault_handler_t handler; +void *handler_token; };#define IOMMU_CAP_CACHE_COHERENCY 0x1
@@ -95,7 +96,7 @@ extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,extern int iommu_domain_has_cap (struct iommu_domain *domain,unsigned long cap);extern void iommu_set_fault_handler (struct iommu_domain *domain, -iommu_fault_handler_t handler); +iommu_fault_handler_t handler,void *token);extern int iommu_device_group (struct device *dev,unsigned int *groupid);/**
@@ -132,7 +133,8 @@ static inline int report_iommu_fault(struct iommu_domain *domain,* invoke it. */ if (domain->handler) - ret = domain->handler (domain, dev, iova, flags); + ret = domain->handler (domain, dev, iova, flags, + domain->handler_token);return ret; }
Signature · 1 line
1.7.5.4
A message that is not in the archive (sent off-list or not yet received): 1337505311-25697-1-git-send-email-ohad-Ix1uc/[email protected]
Quoted 10 lines · Ohad Ben-Cohen
Sometimes a single IOMMU user may have to deal with several different IOMMU devices (e.g. remoteproc).
When an IOMMU fault happens, such users have to regain their context in order to deal with the fault.
Users can't use the private fields of either the
iommu_domainor the IOMMU device, because those are already used by the IOMMU core and low level driver (respectively).
Quoted 6 lines
This patch just simply allow users to pass a private token (most notably their own context pointer) to
iommu_set_fault_handler(), and then makes sure it is provided back to the users whenever IOMMU faults happen.Signed-off-by Ohad Ben-Cohen <ohad-Ix1uc/[email protected]>
May break compilation for !CONFIG_IOMMU_API. Where is remoteproc changed? As far as I can see this is the only user of iommu_set_fault_handler().
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · Joerg Roedel
May break compilation for !CONFIG_IOMMU_API.
Good point. I'll squash this in:
include/linux/iommu.h +1 -1
@@ -193,7 +193,7 @@ static inline int domain_has_cap(struct iommu_domain *domain }static inline void iommu_set_fault_handler (struct iommu_domain *domain, -iommu_fault_handler_t handler) +iommu_fault_handler_t handler,void *token) { }
Or did you have something else in mind?
Quoted 1 line
Where is remoteproc changed?
In a subsequent patch set coming from Fernando (cc'ed). Fernando will also carry this patch with him, and will cc you when the patch set is submitted (should be very soon). I wanted your general opinion before we start relying on this patch (sorry, should have mentioned it earlier).
Thanks for your feedback!
Ohad.