Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp37398689rwd; Tue, 11 Jul 2023 13:47:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlFOx58bNkFXsk4/5ZnYLa/4u9++dR3DzXFhFQtLTcZrgJkIDecivHNSVza+zQq90xLm+QWg X-Received: by 2002:a05:6a20:442a:b0:11b:3e33:d2ce with SMTP id ce42-20020a056a20442a00b0011b3e33d2cemr22929075pzb.1.1689108462344; Tue, 11 Jul 2023 13:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689108462; cv=none; d=google.com; s=arc-20160816; b=HOhTi2hH0ufqO+1bOqmRWRMqNaT7KHlFpXlcUYQzndmaPC/kkMlzgXN0ilim65Y4iq g8mnuL8R8VRxUn3f/JT5T4kxUplsQ8qnV5myiE6dFKWKPT9/tcLvIOI8MK+Khcoz4yRN cDwf87aYnbsgVnBUBp6wbw83GyGihROFmdE3tU92bTs4/cHk/bYbfgNJ4fom61/c+QYy U7kovjevL0yoq6rLVdP4YuykXnGa1T390ueB+z8EbwS8m32aGMAEKFGX2nOV+LrTVUNA OMOfVw6igOBlP1MCDp17JV9GrpZ12++7ISgKZPrxZLiFEzdfwdksllZgMohBrGJi/5El R9og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=lUtoYvKhw/95RgFsNPyULQnOgrvPg4/Vk42QOdKqiVk=; fh=T3hsfVJPbkGZjAKpCMpVklpqYuS0pcKYuCePzJS1qN8=; b=Q2AfEF2HnerTp8uaWnprMa/dHiH3NcDtCLmsAxQ8a8zubuBRI4THU2angWXMvedNLq Lg0kwbgprdb4rCLGUzOeklcE4sBQs2JL0Mbq0XKVIvwipcKqvgZVp8dQL4AAaRbVaUfg Vh1cR9ZQlDLUTqDuUxgLtnS0De6pSjEiYbcpJ0a1XNViebFDhgarrVG28grjjgLpvbhX wJEMiAmkpXrN8xIjqrTcUuZlIr4sJQdrbQYf+x1A/J14Pas1y48wyKVyPl3wn+z5fF9D c+/zGhRRf90olR4Lv/tb7dfZDSHWCxio2Ea8vooKi0n8XEsslo/JgRlbL2/jjUwEFBin OWAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kpsTmJDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t12-20020a6549cc000000b005536fc5187asi1916988pgs.47.2023.07.11.13.47.29; Tue, 11 Jul 2023 13:47:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kpsTmJDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230180AbjGKUqo (ORCPT + 99 others); Tue, 11 Jul 2023 16:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbjGKUqm (ORCPT ); Tue, 11 Jul 2023 16:46:42 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76538171E; Tue, 11 Jul 2023 13:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689108388; x=1720644388; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bMf3zpaNUsB0eGTK5cLexWrhss7IZThtcdQyprXDLXU=; b=kpsTmJDJ0GJGSMUZ97El+ynsVAXXls06j7afk7pEKWouHUS91mzLe6R0 PUGC3OYFBjLelwNdf6idNtZX7HrPODZ1qvj1qA/TfOZD5WF1S5jvjABkm Q6QF3FF8hyX5kwcrxNaqSRmYd0YVOZOpSD5WLia70K0KT2Xl4qr8VsNnq Oqpfduo/HhjA6cc7SWuCgl7dmWu0Iw4D0tl2kUkPyQbxBsDLAQfZac6Um AOzGzxMwtu2i5Crj/PWzfyl4p6Lttojmbr8XeYH3kLHsCdX4MzL7YDjaF PD2I0fEGH5FYRKoVCjQB7eFXU8Fo9rWISLdZXlFcfiYlukJFys4VNTT7R g==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354631873" X-IronPort-AV: E=Sophos;i="6.01,197,1684825200"; d="scan'208";a="354631873" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 13:46:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="811343747" X-IronPort-AV: E=Sophos;i="6.01,197,1684825200"; d="scan'208";a="811343747" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.24.100.114]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 13:46:00 -0700 Date: Tue, 11 Jul 2023 13:50:56 -0700 From: Jacob Pan To: Lu Baolu Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, jacob.jun.pan@linux.intel.com Subject: Re: [PATCH 3/9] iommu: Add common code to handle IO page faults Message-ID: <20230711135056.4b1fd94a@jacob-builder> In-Reply-To: <20230711010642.19707-4-baolu.lu@linux.intel.com> References: <20230711010642.19707-1-baolu.lu@linux.intel.com> <20230711010642.19707-4-baolu.lu@linux.intel.com> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lu, On Tue, 11 Jul 2023 09:06:36 +0800, Lu Baolu wrote: > The individual iommu drivers report iommu faults by calling > iommu_report_device_fault(), where a pre-registered device fault handler > is called to route the fault to another fault handler installed on the > corresponding iommu domain. > > The pre-registered device fault handler is static and won't be dynamic > as the fault handler is eventually per iommu domain. Replace the device > fault handler with a static common code to avoid unnecessary code. > > Signed-off-by: Lu Baolu > --- > drivers/iommu/iommu.c | 24 +++++++++++++++++++++++- > 1 file changed, 23 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index da340f11c5f5..41328f03e8b4 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -1278,6 +1278,28 @@ int iommu_unregister_device_fault_handler(struct > device *dev) } > EXPORT_SYMBOL_GPL(iommu_unregister_device_fault_handler); > > +static int iommu_handle_io_pgfault(struct device *dev, > + struct iommu_fault *fault) > +{ > + struct iommu_domain *domain; > + > + if (fault->type != IOMMU_FAULT_PAGE_REQ) > + return -EINVAL; > + > + if (fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) > + domain = iommu_get_domain_for_dev_pasid(dev, > fault->prm.pasid, 0); > + else > + domain = iommu_get_domain_for_dev(dev); we don't support IOPF w/o PASID yet, right? > + > + if (!domain || !domain->iopf_handler) > + return -ENODEV; > + > + if (domain->iopf_handler == iommu_sva_handle_iopf) > + return iommu_queue_iopf(fault, dev); Just wondering why have a special treatment for SVA domain. Can iommu_queue_iopf() be used as SVA domain->iopf_handler? > + > + return domain->iopf_handler(fault, dev, domain->fault_data); > +} > + > /** > * iommu_report_device_fault() - Report fault event to device driver > * @dev: the device > @@ -1320,7 +1342,7 @@ int iommu_report_device_fault(struct device *dev, > struct iommu_fault_event *evt) mutex_unlock(&fparam->lock); > } > > - ret = fparam->handler(&evt->fault, fparam->data); > + ret = iommu_handle_io_pgfault(dev, &evt->fault); > if (ret && evt_pending) { > mutex_lock(&fparam->lock); > list_del(&evt_pending->list); Thanks, Jacob