Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2217260pxp; Mon, 21 Mar 2022 14:07:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKljRyvr4Jkk7o931gghDSGKbFQUUfZAZIKe+FvMYX3orAGnz31T+IV2Ckl+bu2y9UW++j X-Received: by 2002:a17:902:7b95:b0:153:34e6:7e38 with SMTP id w21-20020a1709027b9500b0015334e67e38mr14593790pll.62.1647896871453; Mon, 21 Mar 2022 14:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647896871; cv=none; d=google.com; s=arc-20160816; b=lW7s4OZEKGMClMIgvcPvNGBgsPJwjI7Ty4146FB/rAm7yiAHepjfBDIeQShUlkbuGH AG0k/6uw6ZGbkXw0VcC27yQvCqRAZ7Aj12XNeTKhSkB5+UZSVFjbayeBELuL/cxbupYP euGlRfIlt2G8jgI/bOol3uU+JgfB96Kw2sl6g3MhRbGh+54EUqTYvWH01uqRxpxrrS3G sqUtsn1LkzYv2in51D0eI/DUfupuaozgKjsOrJL7E19pg88DUTp5Qkp90XOKNphNEMbF +v5i5X7FLPZ+feVfKLShkTfINbpx7sy8dmdoCyRRifVlI600SD0XPOnmTPYCIEyIWRR/ y+hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZVAnw0RzZRCIiVPUEetPfW2YkVPetMxKA7nBTzr+HIw=; b=JzPu80ec1M7AUbpLfv/4JzhEN00CPgVh9z97k6ixFwUUIf2NvMHEZXi3ljzQThBda1 E7frwDcG/NxUAFjjCWUIUmwBSQ4tsK4ttbdqB0mAFJXDO+6nqMZXKqgq4uw8xek+Utgu xHEpGDQvl7NR24ORqjN1t6X4RN9G/kbWM7ighoInqwQkOSEK7qIvxLjLrr/ZCsbCkX9O +yyle9+N5Qr/ArUAhYKsFEZwVSupcd41SgSHxuMA7HzQJvexnGHosUM9CmyrgnwlDBIe eBM7XmDPIQ+Cc4egBYOPGXSdPAc3w7a3I/Tcl5j/ak9LvaA2FxUrit17e3B0AuoP+QSM wHfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uZLSsmc7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 4-20020a170902c14400b00153b2d16578si10981381plj.384.2022.03.21.14.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 14:07:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uZLSsmc7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9B2961B6082; Mon, 21 Mar 2022 14:01:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346782AbiCULhb (ORCPT + 99 others); Mon, 21 Mar 2022 07:37:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234145AbiCULha (ORCPT ); Mon, 21 Mar 2022 07:37:30 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5ECF93998 for ; Mon, 21 Mar 2022 04:36:04 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so8193531wmp.5 for ; Mon, 21 Mar 2022 04:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZVAnw0RzZRCIiVPUEetPfW2YkVPetMxKA7nBTzr+HIw=; b=uZLSsmc74Q5/B8CA/4kxhdheuai2ZCTIeNLvbrI84RUpUGdkpG9Cz3bh6BwiqiFrGc abtmrsOH9fwm5vPy639n2ou6PTw8ZFqIW64RTcPm98lu0L/zed0WmpJviwfCca8+Unk3 C9EXmtDr+t01W6DRvP5hL0eZu2UW2nk0/yCPPCd9jKrYkNzq0TLEPZAmrEqNCkIiCi7p 3lESvWrDt63NMoEKakueosHmptoJJP4QrnSRayS0dFTlfvXq07Q4CeNS9zfCoxNwB3pM jl3pheGxMCrUUNTbhcscnRc8DiwTdFAHPu87eokMvgsxJEcKz2Qvo/3U21Wle6Ylwsig WYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZVAnw0RzZRCIiVPUEetPfW2YkVPetMxKA7nBTzr+HIw=; b=lbZA5cM0YNEjwrez9pff1kiue9C2W+7cO6ejDJoZv/2IXKqL4w6GdZyEW4RKh84RAT Y1aWlviMq98V28DtygR8zZmBwVprJaEm0jIpuHbt6rSN62h7p5/dUEo6JCABRmFhGfwh PpERSmyp85Wh5zpHQUhoEQFIcg2FNFOOPmqoysPAiRSvO5CY8JevbMrz3aTVJbjgtP4u Y7PVWN+wlGqIsSE48ci9LJmMyumyjS3hW2hgk83lvH/YwOiRf/RHvGEP5i0taby3rKL4 JpO3rGe4GUtUj8cFRCpRkv7ALxIdlPSvo1Cnu6jFEt5nNCc4GaM+UY7serGHCdVvXXEp 9KGw== X-Gm-Message-State: AOAM532balkQUPYptd/aj2MEtEDxkFfAeUbYcMXhILImtRD7H5IoQRWP 8nfeqwXGN8vz0+OQulCt1LWMRA== X-Received: by 2002:a05:600c:2e4c:b0:38c:7088:afd0 with SMTP id q12-20020a05600c2e4c00b0038c7088afd0mr21171537wmf.70.1647862563546; Mon, 21 Mar 2022 04:36:03 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id w7-20020a1cf607000000b00389a5390180sm13530707wmc.25.2022.03.21.04.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 04:36:03 -0700 (PDT) Date: Mon, 21 Mar 2022 11:35:38 +0000 From: Jean-Philippe Brucker To: Lu Baolu Cc: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC 08/11] iommu: Handle IO page faults directly Message-ID: References: <20220320064030.2936936-1-baolu.lu@linux.intel.com> <20220320064030.2936936-9-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220320064030.2936936-9-baolu.lu@linux.intel.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sun, Mar 20, 2022 at 02:40:27PM +0800, Lu Baolu wrote: > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index c0966fc9b686..4f90b71c6f6e 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -27,6 +27,8 @@ > #include > #include > > +#include "iommu-sva-lib.h" > + > static struct kset *iommu_group_kset; > static DEFINE_IDA(iommu_group_ida); > > @@ -1177,10 +1179,9 @@ int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt) > if (!param || !evt) > return -EINVAL; > > - /* we only report device fault if there is a handler registered */ > mutex_lock(¶m->lock); > fparam = param->fault_param; > - if (!fparam || !fparam->handler) { > + if (!fparam) { > ret = -EINVAL; > goto done_unlock; > } > @@ -1198,7 +1199,11 @@ int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt) > mutex_unlock(&fparam->lock); > } > > - ret = fparam->handler(&evt->fault, fparam->data); > + if (fparam->handler) > + ret = fparam->handler(&evt->fault, fparam->data); > + else > + ret = iommu_queue_iopf(&evt->fault, fparam->data); > + I like the change, but we'll need to consolidate this, because now if the driver registers a fault handler it disables IOPF. We could instead prevent registration if an IOPF param is present. We could also just merge fparam->handler but eventually I'd like to make IOPF fall back to the fault handler registered by device driver, in case of invalid page faults. I have a couple patches for this but am still missing some bits. Thanks, Jean > if (ret && evt_pending) { > mutex_lock(&fparam->lock); > list_del(&evt_pending->list); > -- > 2.25.1 >