From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: ACJfBovcwxM/VUFwpflRtOxIbbUYqgkK8FlId1eqML+HonyV3DQUdYODoCJVzbl3pybwUH6SPisO ARC-Seal: i=1; a=rsa-sha256; t=1516303346; cv=none; d=google.com; s=arc-20160816; b=we4FJcUNVfJqzRzuZirKAXrqtV6GmQRGgdkvpQTcSpqUlcbCI+Xcubq7HTh8QXD8yE q3AyKceV3gugvOPNO8HCjEEuKzEvNRIoRYltK9G6jwf8hMuPr58qxWg8nEENxTNBYZfz GW5ngmpK9dLrVnHi1+a6YTB8Ww3zZnEEKJLCPxn4ElG+avZhAE9tfz//zQnjAMrWBuZO z3PMhBNmfb99ei7V8dEFQgdEKx2iolMPCgsBkNxY9Ms5R0QVNLQXED7FWGtomLoJewKz 2yFIRVVEuUlGqmK/rQ+HURGyTHDATqSDE4sUBsOLu9hOU0aeq/TFFiLN6Xk1FmNPYMpP l9oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=fcc:user-agent:content-language:thread-index:thread-topic :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:arc-authentication-results; bh=9JQZC41dT3LDtrXhpB6ke9kWDISMJycPlz6K5fR9e4U=; b=DU8hL0xJuIG0EbQe+cMMrh9DzuiRrB7GZATV2a3rboO/Lzny2TyB3KdDYXr2i00ovN P1bxa3iTNCTsCMJwbeq4rSjTCr6FL3dLyEaWH4zBQh5xsHXw0U2ZOsgjpU62p8IaV8SO vaW+2kOLbvyP0TrzVfMu/O8u8lEIQ3LeYjVq5YgyETkr78eNQ9V8H7QPHd/HYL18hB1Q yA+92I2cpCuZ7FXKXm42ooKShsxrqAJ0je2J6RhCksPc/U48GNaB3QzMHNisvKVqB3n8 bI6Em6jMULIR2h9OI3957y/MNAkjrun2I7QUp2u88I7cUjDn8bIgHU4EJA5palv4qreH 54pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com Date: Thu, 18 Jan 2018 19:24:52 +0000 From: Jean-Philippe Brucker To: Jacob Pan , "iommu@lists.linux-foundation.org" , LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Rafael Wysocki , Alex Williamson Cc: Lan Tianyu Subject: Re: [PATCH v3 10/16] iommu: introduce device fault report API Message-ID: <6eea3b27-d0ca-8021-325f-fdc876ebf113@arm.com> References: <1510944914-54430-1-git-send-email-jacob.jun.pan@linux.intel.com> <1510944914-54430-11-git-send-email-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1510944914-54430-11-git-send-email-jacob.jun.pan@linux.intel.com> Thread-Topic: [PATCH v3 10/16] iommu: introduce device fault report API Thread-Index: AQHTX9W56s8IHIZQQ06aWpqkFkZOAqN6YNyA X-MS-Exchange-MessageSentRepresentingType: 1 Content-Language: en-US X-MS-Exchange-Organization-RecordReviewCfmType: 0 user-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 fcc: imap://jean-philippe.brucker%40arm.com@outlook.office365.com/Sent x-mozilla-draft-info: internal/draft; vcard=0; receipt=0; DSN=0; uuencode=0; attachmentreminder=0; deliveryformat=4 x-account-key: account1 x-identity-key: id1 x-ms-exchange-imapappendstamp: AM4PR0802MB2369.eurprd08.prod.outlook.com (15.20.0407.000) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1584340513594467122?= X-GMAIL-MSGID: =?utf-8?q?1589959297976707719?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: Hi Jacob, I've got minor comments after working with this patch, sorry for the multiple replies On 17/11/17 18:55, Jacob Pan wrote: [...] > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 829e9e9..97b7990 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -581,6 +581,12 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) > goto err_free_name; > } > > + dev->iommu_param = kzalloc(sizeof(struct iommu_fault_param), GFP_KERNEL); This should be "sizeof(struct iommu_param)" or maybe "sizeof(*dev->iommu_param)". > + if (!dev->iommu_param) { > + ret = -ENOMEM; > + goto err_free_name; > + } > + > kobject_get(group->devices_kobj); > > dev->iommu_group = group; > @@ -657,7 +663,7 @@ void iommu_group_remove_device(struct device *dev) > sysfs_remove_link(&dev->kobj, "iommu_group"); > > trace_remove_device_from_group(group->id, dev); > - > + kfree(dev->iommu_param); > kfree(device->name); > kfree(device); > dev->iommu_group = NULL; > @@ -791,6 +797,61 @@ int iommu_group_unregister_notifier(struct iommu_group *group, > } > EXPORT_SYMBOL_GPL(iommu_group_unregister_notifier); > > +int iommu_register_device_fault_handler(struct device *dev, > + iommu_dev_fault_handler_t handler, > + void *data) > +{ > + struct iommu_param *idata = dev->iommu_param; > + > + /* > + * Device iommu_param should have been allocated when device is > + * added to its iommu_group. > + */ > + if (!idata) > + return -EINVAL; > + /* Only allow one fault handler registered for each device */ > + if (idata->fault_param) > + return -EBUSY; > + get_device(dev); > + idata->fault_param = > + kzalloc(sizeof(struct iommu_fault_param), GFP_KERNEL); > + if (!idata->fault_param) > + return -ENOMEM; > + idata->fault_param->handler = handler; > + idata->fault_param->data = data; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(iommu_register_device_fault_handler); > + > +int iommu_unregister_device_fault_handler(struct device *dev) > +{ > + struct iommu_param *idata = dev->iommu_param; > + > + if (!idata) > + return -EINVAL; > + > + kfree(idata->fault_param); > + idata->fault_param = NULL; > + put_device(dev); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(iommu_unregister_device_fault_handler); We should probably document register() and unregister() functions since they are part of the device driver API. If it helps I came up with: /** * iommu_register_device_fault_handler() - Register a device fault handler * @dev: the device * @handler: the fault handler * @data: private data passed as argument to the handler * * When an IOMMU fault event is received, call this handler with the fault event * and data as argument. The handler should return 0. If the fault is * recoverable (IOMMU_FAULT_PAGE_REQ), the handler must also complete * the fault by calling iommu_page_response() with one of the following * response code: * - IOMMU_PAGE_RESP_SUCCESS: retry the translation * - IOMMU_PAGE_RESP_INVALID: terminate the fault * - IOMMU_PAGE_RESP_FAILURE: terminate the fault and stop reporting * page faults if possible. * * Return 0 if the fault handler was installed successfully, or an error. */ /** * iommu_unregister_device_fault_handler() - Unregister the device fault handler * @dev: the device * * Remove the device fault handler installed with * iommu_register_device_fault_handler(). * * Return 0 on success, or an error. */ Thanks, Jean