Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20019227rwd; Wed, 28 Jun 2023 18:35:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ75pjdTvUr5j8SMlN/YUDoEiVi/AOZ8rE2RnIuUvZfdyHKKFZplC0zGn/SSi0bkVQ/7U+H3 X-Received: by 2002:a05:6a21:3388:b0:126:1580:36e6 with SMTP id yy8-20020a056a21338800b00126158036e6mr21169382pzb.29.1688002503504; Wed, 28 Jun 2023 18:35:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688002503; cv=none; d=google.com; s=arc-20160816; b=BUmedyxnO1qt4PLvDzoAp60X2HPvXLd4fyxZxHyEiChBJ8h7NNyavXEJcQlpzipMDS gj+wrkM3TJ4tSvXuJ+el6i/NWaTAAzMh13aFdUkXb2t4+F8ZG+R8L9RQfTu9aJAA7kql 83UnJ74KwJu8ZZemUSYc+jCug2tzwdu5jG57IakOxq+meUyOgCJmXVE1ugN0CDkvaeoW gQ54CkpYN+EDk9jkp4v6z01hlaLPyB3IC95q+bn7cT9QGiZfSIxnp1M78Qy/EB0Evd1R GT1Q9u3bV9bJgVFa2gamM4SLVq9QezvR8U583eaGUrOvapuTF9Y/qI3hEErqyTnLgG2A lj/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:to:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=ZxJt0KjI8dBY72MRQB0tKwEbVaknQ6JFisBG3h70iH0=; fh=2CJUNqUMwsxBtPzmnkGlx6WPRHF5ywjJ43ktmkT7ygM=; b=VaMRDoAK/4Hl49Fr1zt9C8JJ3cmuH5NGYf7X8P8NYGLEm2wwD1L9aSRXHiMrmjzoOr 04cYitTcjQH0IduwDBpRGE7PW012jFkmQX9g/gcfDqKAf9TvSxX8AkTLjUa/BugtSvZf 1fU7eb8FngTyz36zNjoKBOOio+gkAF4PZ70CuMp30uQ2U7EqfXMUkCqcVt8t9eCnfxtX UcFvQQppHmVQ+T7UHc/4miJHlU9p43G6qVgNL3qWy/Fva0a8CyX39l06n05oYbdntvXK SI7qo9bCD9CZaF+ygBWXzND9lA7nJ9XRyqUvbVaTvNbbu8qHu5PwFsUBjfL9N2yh6+Ow XLlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dC1jsAjk; 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 v16-20020a63d550000000b0053fee209655si9778911pgi.664.2023.06.28.18.34.50; Wed, 28 Jun 2023 18:35:03 -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=dC1jsAjk; 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 S230314AbjF2BHk (ORCPT + 99 others); Wed, 28 Jun 2023 21:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230099AbjF2BHb (ORCPT ); Wed, 28 Jun 2023 21:07:31 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BBC426A1; Wed, 28 Jun 2023 18:07: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=1688000848; x=1719536848; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=b9GdT6r2b9r4HGFh4jKr0wne/bp8GHgArZMHuUjrA0Y=; b=dC1jsAjkmUmCduFhM8pPJrnCsNmh1av67BkpRhyR7hbhcluZKcQ7p/za Kj1gbOFcEj+VhK53RXCer0k0W3981ZpuQYFLEPYN2l1BIhk92ImvSc8iJ Kx+6YwmhgaZKd0S3A56oDwm9Lm2+ZENvHQmov/Qwurx/liFsmplfJDvmR QzIC9eq7zjFzbuaSz7yEmTcq7wQXOTgM+qFjZBiDTr5HSKrHmxLQRxDG+ KILVDpURkeqfq/N6ZF7EXysiCo1c6/wFMrgPNtLZZ7T3aQE+s7e+aWTFg zTm/6k9zYWq8kE96JxojtdHrK0brl7eL5qHCYsIllepUNBoMrScz1tstL w==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="341581967" X-IronPort-AV: E=Sophos;i="6.01,167,1684825200"; d="scan'208";a="341581967" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 18:07:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="717179669" X-IronPort-AV: E=Sophos;i="6.01,167,1684825200"; d="scan'208";a="717179669" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.252.186.48]) ([10.252.186.48]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 18:07:09 -0700 Message-ID: <7669371f-c529-78ec-1303-9b3a6e23cdce@linux.intel.com> Date: Thu, 29 Jun 2023 09:07:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Cc: baolu.lu@linux.intel.com, 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 To: Jason Gunthorpe References: <20230530053724.232765-1-baolu.lu@linux.intel.com> <26b97776-7ce5-51f6-77b7-0ce837aa7cca@linux.intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,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 2023/6/28 20:49, Jason Gunthorpe wrote: > On Wed, Jun 28, 2023 at 10:00:56AM +0800, Baolu Lu wrote: >>> 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. >> >> Yes. We should make it generic. The domain->use_iopf_workqueue flag >> denotes that the page faults of a fault group should be put together and >> then be handled and responded in a workqueue. Otherwise, the page fault >> is dispatched to domain->iopf_handler directly. > > It might be better to have iopf_handler and > iopf_handler_work function pointers to distinguish to two cases. Both are okay. Let's choose one when we have the code. > >>> 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. >> >> There are two pointers under struct dev_iommu for fault handling. >> >> /** >> * struct dev_iommu - Collection of per-device IOMMU data >> * >> * @fault_param: IOMMU detected device fault reporting data >> * @iopf_param: I/O Page Fault queue and data >> >> [...] >> >> struct dev_iommu { >> struct mutex lock; >> struct iommu_fault_param *fault_param; >> struct iopf_device_param *iopf_param; >> >> My understanding is that @fault_param is a place holder for generic >> things, while @iopf_param is workqueue specific. > > Well, lets look > > struct iommu_fault_param { > iommu_dev_fault_handler_t handler; > void *data; > > These two make no sense now. handler is always iommu_queue_iopf. Given > our domain centric design we want the function pointer in the domain, > not in the device. So delete it. Agreed. > > struct list_head faults; > struct mutex lock; > > Queue of unhandled/unacked faults? Seems sort of reasonable It's the list of faults pending for response. >> @iopf_param could be allocated on demand. (perhaps renaming it to a more >> meaningful one?) It happens before a domain with use_iopf_workqueue flag >> set attaches to a device. iopf_param keeps alive until device_release. > > Yes > > Do this for the iommu_fault_param as well, in fact, probably just put > the two things together in one allocation and allocate if we attach a > PRI using domain. I don't think we need to micro optimze further.. Yeah, let me try this. Best regards, baolu