Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2506902rwd; Fri, 16 Jun 2023 04:49:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eeGZCMK4kO5aoyaW2SW+oQh2BtGRY+Hwb4I6wF00QrkQQr07PuOoa+I8uwH+KciQEgzIM X-Received: by 2002:a17:90a:55c6:b0:259:bdb:6956 with SMTP id o6-20020a17090a55c600b002590bdb6956mr1322298pjm.7.1686916150460; Fri, 16 Jun 2023 04:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686916150; cv=none; d=google.com; s=arc-20160816; b=Hr+DP9sw7azhKM7FnCak7NB6qbXSxeVsYjC+o+MXkm7GRrgPSxPQgVxEIZVv2v5KWu B7sMSV9eUgIh7R3GylajaGVVy0ZHa2Wn9nGPdp2b+6ZZmit3vRBY4Z5nu/nxw5BCOd+o ztIDxTbihurkqkbdRnRIGq+Qb6ezrvL9/TY8oKHbkNpwSf22BA2HMUl+mm7C1bbsvCxE jrogyu4oLGP/CWJalKWjO6x9rPCVgPUVHXPc6I87+72GdsgE6H7rzCzHZD9SaFvtMlvu PTHLDy65S6UFA5/GqJ6y7ne6EK8tGsCUO4oSmCIhWGhWIbLCo/LbB40D6rDzwhu9HB9Y vImQ== 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=2nuyRQlcqUJ1I+sHmU3UQhaVpsWzNHbMeXA40SLBfto=; b=q04liKQSrj035kSHtEyN9u2BCkCcjRDwTk7KmDMIS5neSyM9zjCn0JvZcNlDaeUC4S v9oKhoc8jW6cqAWr25rlMkbtYE1mxswzlL5I0vhk9emtBPPMQtplipblZaBVEmIKwlnF oXVUGbGujaZXbRmzS3Ci3vC1eYTOk/tPHyF4/gctjSQVkukv7p4RiCppZlgHzlLKLsxW nzFhp52q+kH4oDMgdjVfAFQZZw0RAU4WL5kOpNe3c1hohPlqyHhKipLSD6M7grUPFF5J joNrNwD6uE2NUVSYsI35H8gOBPQD3iuTZaPO9I/AB4GHy9jD5RDP+Nypefw09YFD/q+1 tPww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DH5R7s1y; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a17090aac0a00b00258cb09c4a8si1460805pjq.71.2023.06.16.04.48.58; Fri, 16 Jun 2023 04:49:10 -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=@linaro.org header.s=google header.b=DH5R7s1y; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244486AbjFPLcg (ORCPT + 99 others); Fri, 16 Jun 2023 07:32:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235378AbjFPLce (ORCPT ); Fri, 16 Jun 2023 07:32:34 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F3F02720 for ; Fri, 16 Jun 2023 04:32:32 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f61b45ee0dso761053e87.0 for ; Fri, 16 Jun 2023 04:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686915151; x=1689507151; 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=2nuyRQlcqUJ1I+sHmU3UQhaVpsWzNHbMeXA40SLBfto=; b=DH5R7s1yTiVsAJI1g99s6OalFVFW9cM5DAnNDqJJfwlRotOUA96IF3DT5skABPinz5 E4IcsKOQ3I0Rl1kStGkLFAxRCwwg624eQLqtopcQdxXR3xBLUA2PpbggQ7ZzEgEqRcbe zLF4TFVCygtMwuugGFfMrYnwW9LYL8yD4irsAG/DyJmz0CufETPyYE1jSdmH8wJwQ6tx vSjOiWjZxCKLbz+1fw0d11obwbqVVFSHTsLjqc7E95c4rZrMb4MBr8n0fUJ+UFj2gDls a5bE+ElDJi7ADNbMc9uGiuwj+Q1wcaJHUu12vHRDhSs8Nb7M2gleCC8WcLdhD9mV7s2o YiUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686915151; x=1689507151; 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=2nuyRQlcqUJ1I+sHmU3UQhaVpsWzNHbMeXA40SLBfto=; b=NRQOa5Vvb8XaYm9G80avAejKTYf3N/g4KLuTnYZPiL6quljyOSLFboA/kmJ0HX2GX4 rp8iqwRxVVicGKMSlfsbw5jI8UYFarLituyCigRvA4KtS5uHSkMsdn9oeMfpsTEG7zhE bdrJYtjmhK1SgdlFn4AUs6G3tWHWpum9knJMwIVLkFQ6LKlypTB0+n29GbtID1bbS9CI +SaD6fGu6Ob0B+lCABQg+GzZTiS3P2DhA3JEl8OsJREsPvkqd2p4J40LVkDlScvV3j9i TEHBVXmG6dUWpUrT/9TSbMgQm2Qp2O6FWZuUGNG5W38Nxbg2XQKWWuDAw6r60nRkQTmC i8lg== X-Gm-Message-State: AC+VfDw9GrkmJV2Y4bRtS7t3Or8RZ2WE09YmuWDEIquj8ErAPBQpQGne hh1DiXy6zliCwTG830QSBYbUvg== X-Received: by 2002:a19:4409:0:b0:4f3:b07e:7eb8 with SMTP id r9-20020a194409000000b004f3b07e7eb8mr1138136lfa.29.1686915150597; Fri, 16 Jun 2023 04:32:30 -0700 (PDT) Received: from myrica (5750a5b3.skybroadband.com. [87.80.165.179]) by smtp.gmail.com with ESMTPSA id w21-20020a1cf615000000b003f8126bcf34sm1879491wmc.48.2023.06.16.04.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 04:32:29 -0700 (PDT) Date: Fri, 16 Jun 2023 12:32:32 +0100 From: Jean-Philippe Brucker To: Lu Baolu Cc: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Nicolin Chen , 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: <20230616113232.GA84678@myrica> 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: <20230530053724.232765-1-baolu.lu@linux.intel.com> 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,URIBL_BLOCKED autolearn=unavailable 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 Baolu, On Tue, May 30, 2023 at 01:37:07PM +0800, Lu Baolu wrote: > - The timeout value for the pending page fault messages. Ideally we > should determine the timeout value from the device configuration, but > I failed to find any statement in the PCI specification (version 6.x). > A default 100 milliseconds is selected in the implementation, but it > leave the room for grow the code for per-device setting. If it helps we had some discussions about this timeout [1]. It's useful to print out a warning for debugging, but I don't think completing the fault on timeout is correct, we should leave the fault pending. Given that the PCI spec does not indicate a timeout, the guest can wait as long as it wants to complete the fault (and 100ms may even be reasonable on an emulator, who knows how many layers and context switches the fault has to go through). Another outstanding issue was what to do for PASID stop. When the guest device driver stops using a PASID it issues a PASID stop request to the device (a device-specific mechanism). If the device is not using PRI stop markers it waits for pending PRs to complete and we're fine. Otherwise it sends a stop marker which is flushed to the PRI queue, but does not wait for pending PRs. Handling stop markers is annoying. If the device issues one, then the PRI queue contains stale faults, a stop marker, followed by valid faults for the next address space bound to this PASID. The next address space will get all the spurious faults because the fault handler doesn't know that there is a stop marker coming. Linux is probably alright with spurious faults, though maybe not in all cases, and other guests may not support them at all. We might need to revisit supporting stop markers: request that each device driver declares whether their device uses stop markers on unbind() ("This mechanism must indicate that a Stop Marker Message will be generated." says the spec, but doesn't say if the function always uses one or the other mechanism so it's per-unbind). Then we still have to synchronize unbind() with the fault handler to deal with the pending stop marker, which might have already gone through or be generated later. Currently we ignore all that and just flush the PRI queue, followed by the IOPF queue, to get rid of any stale fault before reassigning the PASID. A guest however would also need to first flush the HW PRI queue, but doesn't have a direct way to do that. If we want to support guests that don't deal with stop markers, the host needs to flush the PRI queue when a PASID is detached. I guess on Intel detaching the PASID goes through the host which can flush the host queue. On Arm we'll probably need to flush the queue when receiving a PASID cache invalidation, which the guest issues after clearing a PASID table entry. Thanks, Jean [1] https://lore.kernel.org/linux-iommu/20180423153622.GC38106@ostrya.localdomain/ Also unregistration, not sure if relevant here https://lore.kernel.org/linux-iommu/20190605154553.0d00ad8d@jacob-builder/