Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2138093rdb; Thu, 7 Dec 2023 21:52:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQ9p+UTysHYwQXnn0LwPEZO/kdoK+p+MegNW4KNpw2sGNPFGg3bnW//X6qhke76Tc4ZIH4 X-Received: by 2002:a05:6a21:a596:b0:18c:c37:35fb with SMTP id gd22-20020a056a21a59600b0018c0c3735fbmr4014443pzc.40.1702014761227; Thu, 07 Dec 2023 21:52:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702014761; cv=none; d=google.com; s=arc-20160816; b=sEG4AW0lymnbE3lzMZ1DYOSPZHOHSbFWqU/gGIiBUjqH091UZp2fPiSoJIhczUs6Mn oi0GtOL13/bt0ePP/FdEWTQdHUjxqyDRNRJvUfyQknvWxYzLdzgUZVI1uo/o9o8S7bPQ 0mLz0c0Pa59GBe7G0vRQwArKWxyywjbzzBuDqi1oYQ+cI7DtGxu5pl3VYHOX08RmKgHu Dnim3I2GaLLs5N0DIESLAMOJhFKiliDNu4YegZM0eIpwX7zj476dDFcMSSy/91U0ny8z /j3SK0iWtqQgoP4qhOxGY0ScRo6svVTGKkb+NwRkckZuA5rjMBdCHcC2BfHLgBm5N/oi zPNg== 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 :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=4XArd8sewYCbaSv+iyy71fdl7qLOdt9BsSzjFgdzXN8=; fh=Ty013/s3USjgaq0vt1KcS0o922FZrcN+/Crpr5TAzGM=; b=CFf4fC92vwAlJEl6SZSpM93peeeqh3EllURwCcKPO48N2cFw6W0SLAe9fKJqn+3tFB dBFjgpv5nxF9jyJl+cialUHGyWCwETiZkDxCnIifRws+apVG05wORyTtz0SOR+JSe2Wf Xg1LsfyG7Y6NIPRjqiFWhSY1JUE3nyREf9R2br4/X2NktPCnKxXapgfQJRBD2rGJUvFk 0wic9gNBa2wSEGBsSC2Y2n5DTXzqYlSpt0WtJ3JyeJWYXUK9T48kg5hP2TMVY2d/hzvP xNTT2kkv7B1RlcaMOoaZ81tf9I5acezeoRdze3S1Qrba1sORNMfH32uNiKmAQFnFYGwE 9PCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FJ9pODvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id w93-20020a17090a6be600b0028a18d957desi1438790pjj.183.2023.12.07.21.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 21:52:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FJ9pODvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7F1B28108BE9; Thu, 7 Dec 2023 21:52:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573169AbjLHFwM (ORCPT + 99 others); Fri, 8 Dec 2023 00:52:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjLHFwK (ORCPT ); Fri, 8 Dec 2023 00:52:10 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76AD9171F; Thu, 7 Dec 2023 21:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702014737; x=1733550737; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=2CgvhfqEe7oPS8iAqYFe0ARHhvX5HhGtxuEy7yZmrms=; b=FJ9pODvJGSndZ85yMXUM1yZHYqKCRB3XjCOIEfQxtwLF3hYD6WBDkech oUtZqtPO3FQeh2d5stT7K8o0qhS2OfwWgTIq+OEfVZBbIBJEGsPEHmkQ1 d814zGM3ddUKV56qt/Wmuo5/YAOMCQV2lNfLGCf9lma9aNM2Rrf3Hr6c0 eX2BtLgXoHAUvq2OT4sfO50tO7dARDVOskqJKkxTVvLdHSCPSP2Q10Vwq BFVdr7Bl4ZjWiJVay1mYRcDWCUvM3LV7bBmKYOsmX3Hxh6iwCOrKtlfwT 5QLTdRZy1zHAqqBnUp4IpJYFySXQf77PGrhrfILyClXJKTDGXhrMnNc47 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="7685672" X-IronPort-AV: E=Sophos;i="6.04,259,1695711600"; d="scan'208";a="7685672" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 21:52:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="838016425" X-IronPort-AV: E=Sophos;i="6.04,259,1695711600"; d="scan'208";a="838016425" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by fmsmga008.fm.intel.com with ESMTP; 07 Dec 2023 21:52:12 -0800 Message-ID: Date: Fri, 8 Dec 2023 13:47:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , 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: [PATCH v2 4/6] iommufd: Deliver fault messages to user space Content-Language: en-US To: Jason Gunthorpe , Joel Granados References: <20231026024930.382898-1-baolu.lu@linux.intel.com> <20231026024930.382898-5-baolu.lu@linux.intel.com> <20231207163410.ap3w4faii6wkgwed@localhost> <20231207171742.GU1489931@ziepe.ca> From: Baolu Lu In-Reply-To: <20231207171742.GU1489931@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 07 Dec 2023 21:52:27 -0800 (PST) On 12/8/23 1:17 AM, Jason Gunthorpe wrote: > On Thu, Dec 07, 2023 at 05:34:10PM +0100, Joel Granados wrote: >>> @@ -58,6 +255,8 @@ static void hw_pagetable_fault_free(struct hw_pgtable_fault *fault) >>> WARN_ON(!list_empty(&fault->deliver)); >>> WARN_ON(!list_empty(&fault->response)); >>> >>> + fput(fault->fault_file); >>> + put_unused_fd(fault->fault_fd); >> I have resolved this in a naive way by just not calling the >> put_unused_fd function. > That is correct. > > put_unused_fd() should only be called on error paths prior to the > syscall return. > > The design of a FD must follow this pattern > > syscall(): > fdno = get_unused_fd_flags(O_CLOEXEC); > filep = [..] > > // syscall MUST succeed after this statement: > fd_install(fdno, filep); > return 0; > > err: > put_unused_fd(fdno) > return -ERRNO Yes. Agreed. > > Also the refcounting looks a little strange, the filep reference is > consumed by fd_install, so what is that fput pairing with in fault_free? fput() pairs with get_unused_fd_flags()? fd_install() does not seem to increase any reference. Best regards, baolu