From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226RKymAS46r9QOWIqFFNKFN9UPGIATYky3uAJeuxu3O0DkIxLNtaDDM9K66+B/32smJI8zJ ARC-Seal: i=1; a=rsa-sha256; t=1516737597; cv=none; d=google.com; s=arc-20160816; b=ydJr73em6c93E8gpuvhVhO6+OkMNp6ixvbOf95KI59F0+i0Pj8rAObeopGpCDJxHTj Py5t9wM4DlGMVaa5g15gspFIitP0sDvavl+3veG4GiYLnyCtX9OKr6TBKiy8Ap4vbgnk AycyR876nbWnR609hUc392ndOHaClxdjTIWr7JFkaLCmAR5u/n+kWl5kQpO2QnnmuLmN aFD8Sz6armKa8EJ3zSasXk3BHDX77f5ar5y3EpwWQOHDoAlCLvja5b8MWWu1mDPs2P6e bAQg7n6dOLbL5+NlscxMi1ijuWauu2CyCUjNJf6kYk68mY/0HE+EMKHejk39IWXdct1p S1aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=jkFw+PBNJ7lvHKtMA8aQV+7WNyUhVpzWg3FkCfV2/hc=; b=ZyyApi+ABX0xMKYSNvM7ywmjyzdrmEkDb904hduq6vV7ses1jehgEDQPipYG3pbOEM C+0e1wTPiClC0GYZSeRUYcnVQ/yjWjr3AOStzMrkAniF1XXTyFk8eXb8z9xLuqcN4hgt dsPpN+T1kDS3lh6GqXtnKhSLhEvX/BoevvaQMQH6uQGm7qYRtBo+84liEzp9B9SGv3ek OnjNsXU02+jegFYULuo5Txxrll+djKMz9SQiPxtdLxtVMehfY3qlBhwhF+2iTPA3QaSh 1JEoBrQL2vFKdPN29ahCHKFmqOL/DZB1K0yUNBJzJZ1CebNimHwhF7zBBAfIPzUMzv1z 5pLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of jacob.jun.pan@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=jacob.jun.pan@linux.intel.com Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of jacob.jun.pan@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=jacob.jun.pan@linux.intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,403,1511856000"; d="scan'208";a="168567266" Date: Tue, 23 Jan 2018 12:01:38 -0800 From: Jacob Pan To: Jean-Philippe Brucker Cc: "iommu@lists.linux-foundation.org" , LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Rafael Wysocki , Alex Williamson , Lan Tianyu , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH v3 10/16] iommu: introduce device fault report API Message-ID: <20180123120138.787d1f81@jacob-builder> In-Reply-To: <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> <6eea3b27-d0ca-8021-325f-fdc876ebf113@arm.com> Organization: OTC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1584340513594467122?= X-GMAIL-MSGID: =?utf-8?q?1590414643392805063?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On Thu, 18 Jan 2018 19:24:52 +0000 Jean-Philippe Brucker wrote: > 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)". > good catch, thanks, > > + 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. > */ > agreed. thanks. sorry about the delay. > Thanks, > Jean [Jacob Pan]