Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16617488rwd; Mon, 26 Jun 2023 12:32:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7etXn8fKc2YtndsRTNSUXVpcyTd2UFl9mytkMZ5t2rwqjV9hZ91tcWYgJFH1GRq+fLw+P0 X-Received: by 2002:a05:6402:b0a:b0:51d:9339:1cd0 with SMTP id bm10-20020a0564020b0a00b0051d93391cd0mr4091123edb.20.1687807932331; Mon, 26 Jun 2023 12:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687807932; cv=none; d=google.com; s=arc-20160816; b=Os1nFLeGmK2FaeOliUzXId4p+UnLz/yKFBiweYLmTz9qQ14BzHdxVh7HfS2u9f4ON6 A/l5pNCLH+9FC5mS4tgQHJainn8g8yEhWwOMz1hbvEDiP9uumOd3ghGuDo2CYFIlzift +o9db/nclwJ3fLbR3Oa9ZBAocZYxio/2zbqKIYKmc72cWsg3I4hJWgbNrFz2CZ6SKQ3K CL+qHPNqIS/+6OHUu6HUKEB3KqFkGO28bYos6SOo7erblKOhkFveLw7hps9jvp1tG/p2 Z5GqOUw2/KRC3Qi49s9iG9HOEiz247xnpCk4hVfPgwYppmlHDeaGhNNZhN+WjLS3BJxO 2eOw== 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=Llh4gIlToO5IIgOre9UJS/YUO0ldCTUXip1sWklWSMQ=; fh=MyIltSyj0MPQ7GtVYJfg7XtqPugZHDtwGpteHah8L8E=; b=rL/4S0nCcAizKpVae/rNrXMvmFx+9fdw/RtbTi5jDa1nmJmoZVjTvL24nyFUd/ziR7 M1JKPD7alyDQsttDh+MuBq2XbeAvzlNcPQp83NBeVzAOBbZ7gvJW3euBbPo/6wCeVPMb +GxfgI8RYXLYhnTadhvx2uuNjrEeWSxbGRBXVZmaqJA7FksZ+B0lQexkdBJcz44S23o/ JCrR/3UJ16Zu2nDYmCSC8J8bVPh8a4GYv9qqjubPJULskAxeiUwtcFlws1UUJ+a4uX8j fvbOnAMsagEUEYosP61/G+owL2R48LromKdFgHWVJGiEx/YRCNxETQQzeKf3EJjZ5NfC Zt3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=JVUAS6Mw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a22-20020aa7cf16000000b0051a2044649bsi2891256edy.223.2023.06.26.12.31.48; Mon, 26 Jun 2023 12:32:12 -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=@ziepe.ca header.s=google header.b=JVUAS6Mw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232265AbjFZSdX (ORCPT + 99 others); Mon, 26 Jun 2023 14:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232248AbjFZSdV (ORCPT ); Mon, 26 Jun 2023 14:33:21 -0400 Received: from mail-vk1-xa2d.google.com (mail-vk1-xa2d.google.com [IPv6:2607:f8b0:4864:20::a2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16B9EDC for ; Mon, 26 Jun 2023 11:33:20 -0700 (PDT) Received: by mail-vk1-xa2d.google.com with SMTP id 71dfb90a1353d-471b3ad20e1so998615e0c.1 for ; Mon, 26 Jun 2023 11:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1687804399; x=1690396399; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Llh4gIlToO5IIgOre9UJS/YUO0ldCTUXip1sWklWSMQ=; b=JVUAS6Mwd4CGVgbTg2A/4nZBcOTwKzPyRt4TC3yOvNM2+tIbS6xPD0y0D61ppUoIqP kZrkBWOA7Ql4ra0BfHP6nORKavSIwwHUciNKkQa/xmCuLHQQU0FKrjqNuDpFFUV2WhAs bj0vBswCZ/jeImDakg37V6RL9mG+1bVuMZuVcmiIwOAR2fw7RzomjAA6nEM2czoRF5T3 UfxPt3ZwyqtBl2AfZC59Q6h21ylliaEpNdI5EVodei9o/wAyUMzWRcPPeO/chWAPw5Vz /ewQOBhvCVgbaU8C2DAN4F+GwhoddBQvjmntOXBFEFx01mMP8Ky6gACQ9gm16ROU2eWf tjRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804399; x=1690396399; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Llh4gIlToO5IIgOre9UJS/YUO0ldCTUXip1sWklWSMQ=; b=SuHbPRHU/F5484FMMKWClf3xM9KjEYwo2Kg5G0uVf39mRfbQtZeUKUwjbg680NYB18 MHC23IYgKhyJVz2lz8bgqyqnb71DuCVkdwU7qdYnFfiy2N8vs1DVS3eDYp8ZsEJ6F/sE JywrqKQZF5Id6GvV/HHgRv9BSKa0UzNUdu4sssTawMSpfz9IDrEVVmrip8MLowxg9qUf IeRq8EIncCb/iqX9qkKq5ige+iG1M0NqHaWCmL4lCPRQCkRWTl0aUefXiweoPML+DasE Enxa/PyJWaNPwzSgLPi2Zyxfrk4S79tj8Qg2peqVxs8+oX9/F/KkTwa4iJpePk7AWqdU YiJA== X-Gm-Message-State: AC+VfDwnHY0vgsAykfN+ISDebjJRl5k3D4j35Mf9r8S9AA0FBUJ6Nezv 1q12MRiBq29IBIVLSVe+4WF+eQ== X-Received: by 2002:a1f:3fca:0:b0:471:5939:f4f2 with SMTP id m193-20020a1f3fca000000b004715939f4f2mr9532857vka.8.1687804399118; Mon, 26 Jun 2023 11:33:19 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-25-194.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.25.194]) by smtp.gmail.com with ESMTPSA id z24-20020ac875d8000000b003fddd8e7bbasm3348807qtq.30.2023.06.26.11.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:33:18 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1qDr1Z-008pJc-JP; Mon, 26 Jun 2023 15:33:17 -0300 Date: Mon, 26 Jun 2023 15:33:17 -0300 From: Jason Gunthorpe To: Baolu Lu Cc: Nicolin Chen , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Yi Liu , Jacob Pan , iommu@lists.linux.dev, linux-kselftest@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCHES 00/17] IOMMUFD: Deliver IO page faults to user space Message-ID: References: <20230530053724.232765-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Sun, Jun 25, 2023 at 02:30:46PM +0800, Baolu Lu wrote: > Agreed. We should avoid workqueue in sva iopf framework. Perhaps we > could go ahead with below code? It will be registered to device with > iommu_register_device_fault_handler() in IOMMU_DEV_FEAT_IOPF enabling > path. Un-registering in the disable path of cause. This maze needs to be undone as well. It makes no sense that all the drivers are calling iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); The driver should RX a PRI fault and deliver it to some core code function, this looks like a good start: > static int io_pgfault_handler(struct iommu_fault *fault, void *cookie) > { > ioasid_t pasid = fault->prm.pasid; > struct device *dev = cookie; > struct iommu_domain *domain; > > if (fault->type != IOMMU_FAULT_PAGE_REQ) > return -EOPNOTSUPP; > > if (fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) > domain = iommu_get_domain_for_dev_pasid(dev, pasid, 0); > else > domain = iommu_get_domain_for_dev(dev); > > if (!domain || !domain->iopf_handler) > return -ENODEV; > > if (domain->type == IOMMU_DOMAIN_SVA) > return iommu_queue_iopf(fault, cookie); > > return domain->iopf_handler(fault, dev, domain->fault_data); Then we find the domain that owns the translation and invoke its domain->ops->iopf_handler() If the driver created a SVA domain then the op should point to some generic 'handle sva fault' function. There shouldn't be weird SVA stuff in the core code. The weird SVA stuff is really just a generic per-device workqueue dispatcher, so if we think that is valuable then it should be integrated into the iommu_domain (domain->ops->use_iopf_workqueue = true for instance). Then it could route the fault through the workqueue and still invoke domain->ops->iopf_handler. The word "SVA" should not appear in any of this. Not sure what iommu_register_device_fault_handler() has to do with all of this.. Setting up the dev_iommu stuff to allow for the workqueue should happen dynamically during domain attach, ideally in the core code before calling to the driver. Also, I can understand there is a need to turn on PRI support really early, and it can make sense to have some IOMMU_DEV_FEAT_IOPF/SVA to ask to turn it on.. But that should really only be needed if the HW cannot turn it on dynamically during domain attach of a PRI enabled domain. It needs cleaning up.. Jason