Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14573686rwd; Sat, 24 Jun 2023 23:47:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jo4kS36PLRt9Zyee8+mHi4d1/imTYFJ5h5e40SXfWelEpaNoXqXdAv3eaWFw+SxR9afxM X-Received: by 2002:a92:ce8b:0:b0:345:9269:341e with SMTP id r11-20020a92ce8b000000b003459269341emr2224881ilo.4.1687675664693; Sat, 24 Jun 2023 23:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687675664; cv=none; d=google.com; s=arc-20160816; b=gG4i2Jw/1hw4jy5Cjur8tDRVyeqjsXeTFrFp71Pu7ehiYigSBzaYdG9VP2VxKQ/2m2 jmd9DoR44XBI4M34NqSnvV/jdzZfMqTQ0eZ+qNHPFpnBaJi0d1GQABIX2ciz2iWFJ8li J198BYcjafOtYMWeok1rcCi9jOnAW6NJXB+ojNdgHgtfN2l29fSamVEOB7UIzSeQzIPB nZquDvTchUKNjjkBOj0qu6WW5bec+mOVAHMoRuEUkJSXgQoVaRGn7287INpG5Uc1wZf4 LfKurwtznAXw6vgSzZYxEOWiEZVDQCgcwXBpDWWO5RlKMMEsk9ml2H2EXoR5IMTKeHXa C8qQ== 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=XQ7fvBlBh4qukGt25MDg4MBG7GeoD8B+QSXopQerC/s=; fh=xq4XAJ6ANYNHuXl/POFxn6Nyv0Pr0OBtbgs7eF2HE3Y=; b=j5bwiZb7i8phYRPJuF4eegbTGhx+FC9Qxpm49E0mnkz5jwB9r5IsFbKHZ47dht533p ZvNEsI4/jnvFPEAdm7d78pEdsaVoIAJf5fKIUpDiVihDfRKLndZ4NUE6dxF19djRED/m Ma9qZJ3xeJOatI5I15DrTs54llFR6vOpGeFfBEjmSK2RSGzYjkyhAb/KvwbEc315wnt3 oV3eVAOcd7MWS1MUAtmfOoSNfQH2MYM6K5hrlhzxt+2dLR7F3abyg60k5kG10SclMLaq CDkkX4xR4Fsm5aTKCfgK9YsXNq4iIYmLaVut6D/0LkC5OBFZbGG7YI+s22Pm8l2eIcQh Hu0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZQDJuTZG; 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 h12-20020a056a00230c00b0064d2b749b3csi2669377pfh.71.2023.06.24.23.47.32; Sat, 24 Jun 2023 23:47:44 -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=ZQDJuTZG; 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 S230049AbjFYGa5 (ORCPT + 99 others); Sun, 25 Jun 2023 02:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjFYGaz (ORCPT ); Sun, 25 Jun 2023 02:30:55 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68EF9E46; Sat, 24 Jun 2023 23:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687674654; x=1719210654; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=R7Yhr42fK7gKhO8erEf7BeGzaAEEpOtaMIIdcwtYeU4=; b=ZQDJuTZGtlvftcSznqEa5dfamtLWgc8aQwMsg5sL+qlzCl8oES7Z+vjT YK0gSfB75r4y3V4+HqzPnq0a0M+sMVkBxLblo3T7WRzXVVhIQRQc9ytPU xMEihkwGPkAdHsb6mhZNhFfHlaFc31KIYmdA7aDriGxRatKcW1k2KXavk IcaIemXCAFDD/MOC1FsPtD7XznHOwBnnq1qBekufND2KqfaRSjw13jQlS vSmSPbYeZpO1zGm6uM46Fr9XTrk0O7kvQgoUWIIIh0LCq0vfqEjPyChDF 5c3AsoUGmqw8uY0Xmm3VGRySF4T2dJXum/09IFOaGerGQeT2y98t6JRA9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10751"; a="424708490" X-IronPort-AV: E=Sophos;i="6.01,156,1684825200"; d="scan'208";a="424708490" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2023 23:30:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10751"; a="889912917" X-IronPort-AV: E=Sophos;i="6.01,156,1684825200"; d="scan'208";a="889912917" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.254.208.26]) ([10.254.208.26]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2023 23:30:48 -0700 Message-ID: Date: Sun, 25 Jun 2023 14:30:46 +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, Jason Gunthorpe , 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: Nicolin Chen References: <20230530053724.232765-1-baolu.lu@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_NONE,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/5/31 2:50, Nicolin Chen wrote: > Hi Baolu, > > On Tue, May 30, 2023 at 01:37:07PM +0800, Lu Baolu wrote: > >> This series implements the functionality of delivering IO page faults to >> user space through the IOMMUFD framework. The use case is nested >> translation, where modern IOMMU hardware supports two-stage translation >> tables. The second-stage translation table is managed by the host VMM >> while the first-stage translation table is owned by the user space. >> Hence, any IO page fault that occurs on the first-stage page table >> should be delivered to the user space and handled there. The user space >> should respond the page fault handling result to the device top-down >> through the IOMMUFD response uAPI. >> >> User space indicates its capablity of handling IO page faults by setting >> a user HWPT allocation flag IOMMU_HWPT_ALLOC_FLAGS_IOPF_CAPABLE. IOMMUFD >> will then setup its infrastructure for page fault delivery. Together >> with the iopf-capable flag, user space should also provide an eventfd >> where it will listen on any down-top page fault messages. >> >> On a successful return of the allocation of iopf-capable HWPT, a fault >> fd will be returned. User space can open and read fault messages from it >> once the eventfd is signaled. > > I think that, whether the guest has an IOPF capability or not, > the host should always forward any stage-1 fault/error back to > the guest. Yet, the implementation of this series builds with > the IOPF framework that doesn't report IOMMU_FAULT_DMA_UNRECOV. > > And I have my doubt at the using the IOPF framework with that > IOMMU_PAGE_RESP_ASYNC flag: using the IOPF framework is for > its bottom half workqueue, because a page response could take > a long cycle. But adding that flag feels like we don't really > need the bottom half workqueue, i.e. losing the point of using > the IOPF framework, IMHO. > > Combining the two facts above, I wonder if we really need to > go through the IOPF framework; can't we just register a user > fault handler in the iommufd directly upon a valid event_fd? 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. 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); } Best regards, baolu