Received: by 10.192.165.148 with SMTP id m20csp3997781imm; Mon, 30 Apr 2018 09:54:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoyikoCNOzmMNDY0b3B30MgiFz69iILw1VyKsx3SPrgTesB8eLOzBb4QcKvw9LhszJzETez X-Received: by 10.98.222.2 with SMTP id h2mr10736714pfg.205.1525107275558; Mon, 30 Apr 2018 09:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525107275; cv=none; d=google.com; s=arc-20160816; b=hg6czev7rDQZTqgzN+Tg48iqMFs0wY2+VOt9+Euzqvc59wUd2Mgb3tZ/deitJsapAc tZjiGzOsWLHzvCFTNS5du/BGWIC3F+Hc1XzDT+9ZU/DjnKlsltj4LnMHmRns2+R2PWuy euuqh3tKBb7o3JSHKiXMpsngQtIhsUAh+Bx31/+DfFrXrf7y0T2FpsV2FpUeGTgmLxIa QhILvJk4a1OFoAgJraqdOevOie6MKmf/AGZrmpINdqzsRA2XMJyNc3vdMcpTE4+eCiMy 4GheizJ46Wft1K9E/r9rW5TCW1yBKq7e6WuREHv1buHSN+QrwAXF3a5vv/1ilRgfNYI+ dh5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=PI8uWGK6klFUibVAWEK2lggyPwc6ecpcSgHwyBU4vtI=; b=RxIcj48q0merjTtm3qQiy7GPp6GEZWUWwc1OmQPPgiMv/YhIgyK+H2VDDlEXkgauds rDU2YlL5Q7ONlOxxTk6yQvoJ/chWYefTzJksxzl+ctzH7ZnvscK99RUo5TRp2DSSkntM NTtUnmWH09NvAZRYD8Fp7KPN2/P3PrcRFkdhdhc2d5ofl4lD2TeaemAqk9rEucsV6HpI v2ZFbaIAf5UPPhfq8AwAGh4XPNz/aisCWvsYnaNtcdE6K7uW8k0GMWU4QDbN/aadDOTZ rDMNDJ3F+Xf0OjlPf2EgcO2UrqLV4SG8nt8iZeItgTgWGQ3/QusnqDDaZ54GJunJ3JLU mefg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4-v6si6480349pgs.291.2018.04.30.09.54.21; Mon, 30 Apr 2018 09:54:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754938AbeD3QyC (ORCPT + 99 others); Mon, 30 Apr 2018 12:54:02 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39258 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754843AbeD3QyB (ORCPT ); Mon, 30 Apr 2018 12:54:01 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8404AF; Mon, 30 Apr 2018 09:54:00 -0700 (PDT) Received: from [10.1.210.33] (ostrya.cambridge.arm.com [10.1.210.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 442D63F587; Mon, 30 Apr 2018 09:53:58 -0700 (PDT) Subject: Re: [PATCH v4 12/22] iommu: introduce device fault report API To: Jacob Pan , "iommu@lists.linux-foundation.org" , LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson Cc: Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Christoph Hellwig , Lu Baolu References: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> <1523915351-54415-13-git-send-email-jacob.jun.pan@linux.intel.com> From: Jean-Philippe Brucker Message-ID: Date: Mon, 30 Apr 2018 17:53:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1523915351-54415-13-git-send-email-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I noticed a couple issues when testing On 16/04/18 22:49, Jacob Pan wrote: > +int iommu_register_device_fault_handler(struct device *dev, > + iommu_dev_fault_handler_t handler, > + void *data) > +{ > + struct iommu_param *param = dev->iommu_param; > + > + /* > + * Device iommu_param should have been allocated when device is > + * added to its iommu_group. > + */ > + if (!param) > + return -EINVAL; > + > + /* Only allow one fault handler registered for each device */ > + if (param->fault_param) > + return -EBUSY; Should this be inside the param lock? We probably don't expect concurrent register/unregister but it seems cleaner > + > + mutex_lock(¶m->lock); > + get_device(dev); > + param->fault_param = > + kzalloc(sizeof(struct iommu_fault_param), GFP_ATOMIC); > + if (!param->fault_param) { > + put_device(dev); > + mutex_unlock(¶m->lock); > + return -ENOMEM; > + } > + mutex_init(¶m->fault_param->lock); > + param->fault_param->handler = handler; > + param->fault_param->data = data; > + INIT_LIST_HEAD(¶m->fault_param->faults); > + > + mutex_unlock(¶m->lock); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(iommu_register_device_fault_handler); > + > +/** > + * 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. > + */ > +int iommu_unregister_device_fault_handler(struct device *dev) > +{ > + struct iommu_param *param = dev->iommu_param; > + int ret = 0; > + > + if (!param) > + return -EINVAL; > + > + mutex_lock(¶m->lock); We should return EINVAL here, if fault_param is NULL. That way users can call unregister_fault_handler unconditionally in their cleanup paths > + /* we cannot unregister handler if there are pending faults */ > + if (list_empty(¶m->fault_param->faults)) { if (!list_empty(...)) > + ret = -EBUSY; > + goto unlock; > + } > + > + list_del(¶m->fault_param->faults); faults is the list head, no need for list_del > + kfree(param->fault_param); > + param->fault_param = NULL; > + put_device(dev); > + > +unlock: > + mutex_unlock(¶m->lock); > + > + return 0; return ret Thanks, Jean