Received: by 10.192.165.148 with SMTP id m20csp3311232imm; Mon, 23 Apr 2018 04:31:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Ddv/daJQ5Cz+HxwrTAx1DlKPvrzKiuoUu6zj/7xMxIHRmsqtP7Darg23n1x7OdS1/cdsv X-Received: by 10.167.128.81 with SMTP id y17mr19317555pfm.194.1524483111235; Mon, 23 Apr 2018 04:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524483111; cv=none; d=google.com; s=arc-20160816; b=xSdo92tw8V8VL736PxZDZ2jW3MSorpk5DNgqbNZ2nYu7SwX2tEr0YoqWOBozFHBHKe iS7mhwUU/LuntCHS9fZ30w1JSMoaT5+AEDSPk7Pp2hM5J1j565RXK73gLtGr1Aor2svk Jb5u0R+aCFPR8qbyjSDACkh7LQfO7YtTZHJ4CY6+d62aTPn2YnI67FVggRK1AUPXr2xA zuhfa8HtSq4IUPLFf9FC2aRMTzfr2LaYy+p6tmDSB/SHImb9V/J6OQKkyj0LkT+DCgCc i5owp5WNSWt22UdjT5BE8c0YjkqTx1gpP4zPvgi+6atL/Xh8eS8qnBTjQT0ZsnRnR/dc Ln8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Z2gwjkmLndblddYo6dCLj8vdoqHRtVZ9DkRlHc7WaUs=; b=TMnPvGN/Z5QgGvM40cQ++cw3Sn+eIgCCHiwT8halqhNra6wkSzOJP+iaTIzA3Tjr4i Cv61/eFz28aOVDUbBDLGy08tOi865FPMxvAIGUZMm8OhNKhbueDhLI+P0wgpNlMqOv0j 07xTe1nxAKAUwBXWDyqfSKX/vuF478uNoxzt32g8ssKPLnQQcw6qI3IYqYxzmibbQmDa k183DQZ63NBWjwgDPSwtVeFdt7VCtjab4va9a7P3bJV89fqLK0RQAJlKKCwagpcx8d45 ci71MZpNvR04a0j5+zr2Zcy24s/qywQF7PL+k7FOs3eRLedb8swEd+3xALsYYe7+HFl4 yXKw== 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 o11-v6si11755422plk.434.2018.04.23.04.31.36; Mon, 23 Apr 2018 04:31:51 -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 S1754774AbeDWLaY (ORCPT + 99 others); Mon, 23 Apr 2018 07:30:24 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39818 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754624AbeDWLaV (ORCPT ); Mon, 23 Apr 2018 07:30:21 -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 E16911435; Mon, 23 Apr 2018 04:30:20 -0700 (PDT) Received: from ostrya.localdomain (ostrya.cambridge.arm.com [10.1.210.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 89DCB3F4FF; Mon, 23 Apr 2018 04:30:18 -0700 (PDT) Date: Mon, 23 Apr 2018 12:30:13 +0100 From: Jean-Philippe Brucker To: Jacob Pan Cc: "iommu@lists.linux-foundation.org" , LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson , Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Jean Delvare , Christoph Hellwig , Lu Baolu Subject: Re: [PATCH v4 12/22] iommu: introduce device fault report API Message-ID: <20180423113013.GB38106@ostrya.localdomain> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1523915351-54415-13-git-send-email-jacob.jun.pan@linux.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 16, 2018 at 10:49:01PM +0100, 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; > + > + mutex_lock(¶m->lock); > + get_device(dev); > + param->fault_param = > + kzalloc(sizeof(struct iommu_fault_param), GFP_ATOMIC); This can be GFP_KERNEL [...] > +int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt) > +{ > + int ret = 0; > + struct iommu_fault_event *evt_pending; > + struct iommu_fault_param *fparam; > + > + /* iommu_param is allocated when device is added to group */ > + if (!dev->iommu_param | !evt) > + return -EINVAL; > + /* we only report device fault if there is a handler registered */ > + mutex_lock(&dev->iommu_param->lock); > + if (!dev->iommu_param->fault_param || > + !dev->iommu_param->fault_param->handler) { > + ret = -EINVAL; > + goto done_unlock; > + } > + fparam = dev->iommu_param->fault_param; > + if (evt->type == IOMMU_FAULT_PAGE_REQ && evt->last_req) { > + evt_pending = kzalloc(sizeof(*evt_pending), GFP_ATOMIC); We're expecting caller to be a thread at the moment, so this could be GFP_KERNEL too. You could also use kmemdup to remove the memcpy below [...] > +static inline int iommu_register_device_fault_handler(struct device *dev, > + iommu_dev_fault_handler_t handler, > + void *data) > +{ > + return 0; Should return -ENODEV Thanks, Jean