Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2344035rdb; Fri, 8 Dec 2023 05:41:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbW8dIrjSmG2fPOsqc1fpogvthDL56yNIHZPN3ekt9m90D7mUlmZw8dznJSD7E3QnH1ICl X-Received: by 2002:a17:903:11c5:b0:1d0:6ffd:8367 with SMTP id q5-20020a17090311c500b001d06ffd8367mr20450plh.114.1702042916356; Fri, 08 Dec 2023 05:41:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702042916; cv=none; d=google.com; s=arc-20160816; b=KKmXtvaC4AmGK4/Y9YpZjCqykKObyekaIHIddcCaeqT3ipS4Dw9DcchGJxJ1EZThZq JTSJ8My5xQ4GNkmKUDN2AHdDIhjFRsccPS4uLgmBBva5aHurwhdZqXg5PFPxvTBWqcwc XWY6sH/scPl2imZC08+88KY4exT5pe43g8210+0XWEdoOdk+zjlZE4of5DVxqB3Hvwhb 6utLFrUHmJUCOXgOCOJeXFM48M9iRdqTnwkURDisvGhQjaxwyeg7bbqxdO6yZtfQaNS8 MT5u7Zu+rcIw4m6kh7rqM9MOYFudWc73KXgveZcC51AflCn2gZZ8WlzAsi5NE8eBrfv9 gFcQ== 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=YucZctI9OnES6g1Fy1Wtf0Z1+OcLPgAF9qFfV1szyvI=; fh=QZaIlcKlItoo9luHiAXJgDpuOW5ObuPa7Y19h02OMZM=; b=02NvFpb2nVU4yeCY8tVmAp5MG9606kL3mD2GFJocdsUCRP3vfSj3kFNXeg3JkUGaro Lb0ozyAV9l5JZ4hqd95rqEcTWNZ5ebhyBl9cSjJpWDmTB68moeI1TNWd62jGgeDDgFaZ 9WUyXmwHJunrVxv5+/VfzL8A9lRVtRYKoLQkUpJJmiElynw5v3qrD3MVJgZsXfnxbngF CE6GB4882RC07Ym7Kw1Y8LX6hnr6HgzaoaM2mlVy8LfVi8SE8Pbpwq+iVLzJEt0iR1N2 xpHbYv1f1mAoe4Y3YkJG8s3Np8FJxh0PfyuLoJcHLMVx6uhC8fba+l7MMLjTSjb0ipfk g4ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=UQO4D9uf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x14-20020a170902ec8e00b001cfd0495288si1677595plg.298.2023.12.08.05.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 05:41:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=UQO4D9uf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D5EB1819CC2B; Fri, 8 Dec 2023 05:41:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233684AbjLHNli (ORCPT + 99 others); Fri, 8 Dec 2023 08:41:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235891AbjLHNlg (ORCPT ); Fri, 8 Dec 2023 08:41:36 -0500 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E6291986 for ; Fri, 8 Dec 2023 05:41:41 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-4258423e133so12145061cf.3 for ; Fri, 08 Dec 2023 05:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1702042900; x=1702647700; darn=vger.kernel.org; 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=YucZctI9OnES6g1Fy1Wtf0Z1+OcLPgAF9qFfV1szyvI=; b=UQO4D9ufl/sEF35xxGRzYtk162hQ7fl1RaoDfoS/+9vl4xs3B3qXZlr9UGkNUlpU04 VUqAwEonYfNfHnaDG/DSNPDCkcoPx2WOXMxQISI8l7WbtrG56pnofxLFtrRfVmZbH3bC qq+uB6QQkS2xHkPXxhm1T9Nh/NVcOSbVuq0DcK4eb4eCTOYkJ4i2UBp3g+c3TOmTZOBI kvkR+RRa6idVSYIo0Cp9PjJLNuR1hAj4nxTPR0rEzNS7Yf7vsNgNrhvt0Q8rG8hPrCRe FwKQZJ7Iho98qBcQPJ9ZkquW5dlXifvvFXtHnH07MmqXCI+2udmaTZm2pM4wiSOKeCs/ Y/UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702042900; x=1702647700; 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=YucZctI9OnES6g1Fy1Wtf0Z1+OcLPgAF9qFfV1szyvI=; b=HWoOtqfMI1IvJoHjDln7kk0bWx8cmLeRNYnh7JdQbdC+qoJ+lekevDVAFiZzfvpGHS ePSJD/d7u9wouhOcV0LyRTRxa2/5IJmAwxwzx8aeM7YD3bmCnDN8ZBHJBjw6fiDrV5eo lMO2mpSsUb0jgiyVG86wmX1hpCdzHTBAfy8d4WlvVwzU6MYQ8UljnErswFTnOMA5vCZt f/oXKEJBEzvuuQ0PUKzESb7Ae5iiZTh/G3LDQE9n5lX2Jyo9s+uLlEPTJWtyfPePVkHS SuoY/c4DaRPTCFHvbBG57IseKwbCphKcrdPVdvkLKthkvEwEGkmryWsgLDOryg8eFQvf ZDTw== X-Gm-Message-State: AOJu0YyOqJv8wXRvFq9BXH0IdjzbcA6JXJ8S7uuZtjRQ3m/Ci1opQUBb eql4IgWPmiMOV6gdQ5sd5f3VOA== X-Received: by 2002:a05:622a:1708:b0:425:4043:1d77 with SMTP id h8-20020a05622a170800b0042540431d77mr105008qtk.74.1702042900661; Fri, 08 Dec 2023 05:41:40 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-134-23-187.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.134.23.187]) by smtp.gmail.com with ESMTPSA id cd5-20020a05622a418500b004255fd32eeasm543901qtb.7.2023.12.08.05.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 05:41:40 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rBb6p-00C88X-Fn; Fri, 08 Dec 2023 09:41:39 -0400 Date: Fri, 8 Dec 2023 09:41:39 -0400 From: Jason Gunthorpe To: Baolu Lu Cc: Joel Granados , 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 Message-ID: <20231208134139.GW1489931@ziepe.ca> References: <20231026024930.382898-1-baolu.lu@linux.intel.com> <20231026024930.382898-5-baolu.lu@linux.intel.com> <20231207163410.ap3w4faii6wkgwed@localhost> <20231207171742.GU1489931@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 05:41:54 -0800 (PST) On Fri, Dec 08, 2023 at 01:47:35PM +0800, Baolu Lu wrote: > 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. fd_install() transfers the reference to the fd table and that reference is put back by the close() system call. Notice that instantly after fd_install() a concurrent user can free the filep. Jason