Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp30258rwb; Mon, 26 Sep 2022 08:56:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6sD2WH1yoTtPHZIYnguSKg0sfjlPe6QfzfeOVwdAW0KHjJTa4I4xmkUuMt/0XovJCSYoSZ X-Received: by 2002:a17:90b:1a91:b0:203:c2:7102 with SMTP id ng17-20020a17090b1a9100b0020300c27102mr26248720pjb.154.1664207775733; Mon, 26 Sep 2022 08:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664207775; cv=none; d=google.com; s=arc-20160816; b=UVzKXVsJod4IpT3k/PeafoWF9ccWBKKWWt2jOvaryNt8LU5l+D3EzwqXAnUklLEbov WnAmpo8JuwQOaBjNzI4eRekG0Uhc+9gLYSoG9y661mD9XONFlhRLXS7sNTI95phg0L6L 6lXnnvnhJBEiCLsYwGLxYtngWndP5t9v5I8FVpDEJk14KoP4E8tWHDEsom3UjQhP4hwD fMUPOaI8+LmdlCzNOFCYiDbnXmESJSONGKVhC/PVwrk+MKa1hp0MEbPCMYBJI8C8s2T1 SgHye4U95TsqHhSR5fbepR/aXVYrpLNHjrr4J6JY/8BEYuLYS04GofgJuesM1RCNwsqy fvcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=wZ7mbwj+DEHYqlCMeVhDbwi0zz1pLcHzRXAZl3GYD0Q=; b=Xn52ret0G69DZC5CbF/t8wR/mDubL3NOp2e/R6t3rNtwMPqXTOJDWGA4vin6+tDBcJ Ug/Q8nxnODlAhvVMGs1CMGZmTwXq00Nfs0TcReHiAyAZFcl7E2e1vySQSGCsxjGcAAC5 CQRRNGABPnYSiUXzEb7eBugJFh5TrwiZfvBjOCyaIDhs7iS/xndDnpQTsjVKfLzrIdpG /DXuYUUn0pP2qpa3A2XvtUwQsnRGi9yz0ua98adGD0aZhfWNdnD16YauAYJRAFBmC08m ow28tOxaS5h24ihvUmNr0SuZJoNT6dKe9ngz4MP7APgIT133ENVGYKlIt3EBzX7CICF8 9NnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=RifdWi9a; 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=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h69-20020a638348000000b0043cc90bd90fsi1684639pge.254.2022.09.26.08.56.02; Mon, 26 Sep 2022 08:56:15 -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=@linux.org.uk header.s=zeniv-20220401 header.b=RifdWi9a; 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=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234537AbiIZO4D (ORCPT + 99 others); Mon, 26 Sep 2022 10:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235064AbiIZOyw (ORCPT ); Mon, 26 Sep 2022 10:54:52 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB104CFE; Mon, 26 Sep 2022 06:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=wZ7mbwj+DEHYqlCMeVhDbwi0zz1pLcHzRXAZl3GYD0Q=; b=RifdWi9ao0Te+Zy9Sqnw+4Sp1m vtWp92ykZNxYv4HSrD1eKaqE91qsY2CbnMox4IO8LccWEeMc/ecqWbyXvNoNUuIodClfdHO18GiNs FAXHg+Egzykr9ME2la0UcSJnB3nab+AEwdhlBho0iLpUfKGSrLL4pitmr5r66AhzxN7Qo1m7khRXw shK0DHi1ugQlOPh5Lubk48j9l4BrwvKDd8TOAiXU6uHsMUbMAPRL2vFeqCGjDrEiPuY5tCvCmAQkd QsHZ2LL7WKybaK4CuB87UY947Pjdg6JkpDDTYqV0ZJXM8FLH7nNOUp7dte5Z/nsGCN9QGtH2D5yAq AekLe20A==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oco5U-0040Q0-2J; Mon, 26 Sep 2022 13:23:56 +0000 Date: Mon, 26 Sep 2022 14:23:56 +0100 From: Al Viro To: Deming Wang Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfio: Use filp instead of fd Message-ID: References: <20220926065407.2389-1-wangdeming@inspur.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220926065407.2389-1-wangdeming@inspur.com> Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 Mon, Sep 26, 2022 at 02:54:07AM -0400, Deming Wang wrote: > The function of kvm_vfio_group_set_spapr_tce and kvm_vfio_group_del > use fd indirectly.But,it only be used for fd.file. So,we can directly > use the struct of file instead. > > Signed-off-by: Deming Wang NAK. fget() is for the cases when we must keep the reference across the syscall boundary/pass to another thread/etc. If fdget() is applicable, it's a better alternative. And I would suggest you to look at the generated code - it pretty much turns into struct file *file; int need_fput; r = __fdget(fd); need_fput = r & 3; r &= ~3; file = (struct file *)r; .... if (unlikely(need_fput)) fput(file); Note that we are *not* actually passing a structure out of a function, etc. - fdget() is inlined and out-of-line part returns unsigned long. Lower two bits carry flags, the rest - file pointer. Rearrangement into struct fd is done in the caller and compiler manages to dissolve that struct into a couple of local variables. Incidentally, pretty much the only thing in struct fd besides struct file pointer is that "have we failed to skip bumping the reference count?" flag. Between fdget() and fdput() only the file pointer is used - in all users. fdput() uses the flag to decide whether it needs to bother with refcount at all.