Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9856257rwp; Thu, 20 Jul 2023 10:39:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlEx7J9iZ23r6W8jUrc06ZcHwJKTFTrUyuq71awAaeQgamEeElnP7doTsq72Q4XNTutHjQIV X-Received: by 2002:a17:907:86a8:b0:966:1bf2:2af5 with SMTP id qa40-20020a17090786a800b009661bf22af5mr6103610ejc.22.1689874745592; Thu, 20 Jul 2023 10:39:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689874745; cv=none; d=google.com; s=arc-20160816; b=Fble3io3FHpvGVoR/xkA//I8djPv59VyEiSX4V2d6AI22W5IigVeJKQaJ91Qw0cieZ w40wRNCvvCAkMn/ASGe+XnrxeUFlx8ZKyRCCgCp1WVIBeQescu+lw3AfwHhNip0cD5L2 /GzrS3O81CgLuRiO/yTiLbbp8Ra7mZcFHW/G+Z7yu8zRbe+dFQBVTQ4PV9zNQM0+2SMH RddFOkRdBjWvD6JtD5ixu7NaVf7o4shq/HWlEv3xvtfY42SVWGTs3kz0yZjeDcQFVvPs k2idQWvP6t5Z0KW99x1j+re0a55ndfhT3MutcY59qIRXF+Vc/Acg0uUruPw65ZKfzXX8 4PlA== 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=1HxVqm6QdvDEhgAmZIzdUgqN5ps1HBMX/R5gvglFRS0=; fh=7KhqMsEDo7BTfCk6NG+VlByJJo7I6VM4ls4Wj0u9F2k=; b=zzG5zxjTlkJkyWEEqGU8Vs1f0nO5s1w05DoEMx0bioSO+ObDzpC/evvKghtP1dmY0C QpaFFtCCj8Nu+GRHYB8ZRyVvqnyZb//NiXaC7UpkeLs2gHDeaDJh/hnMU2YN5ZsSbL3m RPZ1LbDW+RjRgcC4NziGNAKlf1p6ZHhjfrksRLuNt5dtN2l0x7fVi4ctD/YUQkC3ZbQC cvh7O1ChKrDFb+hi+syUL64tl13PlfX6hEwzPtdDD0Orghnxku3AkLT1nOMaO8sDOfwi Bmpyhg+5IVwfjdCrwRHOEChKa84ZrgWJm3jZPloSv9pLqotSabE+rWkhP8nChf/kgPN7 tx0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="CUnVP2R/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gz24-20020a170906f2d800b00991f3517cbdsi1106840ejb.1.2023.07.20.10.38.41; Thu, 20 Jul 2023 10:39:05 -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=@gmail.com header.s=20221208 header.b="CUnVP2R/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbjGTRKO (ORCPT + 99 others); Thu, 20 Jul 2023 13:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbjGTRKN (ORCPT ); Thu, 20 Jul 2023 13:10:13 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 130B41A8; Thu, 20 Jul 2023 10:10:12 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b8b2b60731so6107815ad.2; Thu, 20 Jul 2023 10:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689873011; x=1690477811; 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=1HxVqm6QdvDEhgAmZIzdUgqN5ps1HBMX/R5gvglFRS0=; b=CUnVP2R/iiwpjbeMsc4i4TDFynfvvkqT6gTKNeBxnlIjD9QVmKFoyQlmCLQSsVgHsx ToJLqSIN90f+DX3Qt3bR9vNgHXq6l+ZMT2IM9wyUzUoq8aybjTGrUfvhEcuShUyb+uOg 6PURexEpO0+W5NAO5EtFyc+oaqPmZj+PBstcoltHr3vmblfLuSx7ywg0iqTcOfw/W+6E 8wUHZBRcgE/pMdncAGE59V8cbSwo0Zhfn9McECy3OsIr9wDqNlOE+e0oNEBYOv8c3ngs XFc9ntZZLaP40fqAWQHEBpHVuWt2zLNcWHZE2mJ4ced4F0mvOmmVQ2ZgYYIgD4+FWCCZ kuSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689873011; x=1690477811; 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=1HxVqm6QdvDEhgAmZIzdUgqN5ps1HBMX/R5gvglFRS0=; b=kmX1xEJYvi2HdDCby/f+SRkpvhew7pXIR2zXuwcLxBvNxRKlurmUpuyh71aVLyAwFM PM1DjN1daUMO7nGwrWxUWlfVfVodavGrQ/nql8MXhQ7o8vW519OzAJ6RufwmVqekVuxC o7t4Z8ms1lsrTDVJBObIGv6TYpGy52GElnX/UVMtd/u+zwnwoIrH1LGHsAZ1Q9K6Zjus zwu6Sj4nG8+zIYNIBidqL5cAtT7V9CS5zBeV8fU5Cj/7lFBmkKqoGHTTR3OOaw0lfvHQ ZjHpctohrlXF1F9n/EDzPzVomZxSowpfK8JHnHDnz6ef/kJITXDDgHbj0U9ausuhiAyd mTiQ== X-Gm-Message-State: ABy/qLa/PyRMl6+ma2dm6aGotLtX1/Oe6y8mPRAwkAWVtTgsWreRFfRV yvElEWMizTZixo5wK6ZVirU= X-Received: by 2002:a17:902:d485:b0:1b2:1b22:196 with SMTP id c5-20020a170902d48500b001b21b220196mr32439plg.48.1689873011077; Thu, 20 Jul 2023 10:10:11 -0700 (PDT) Received: from google.com ([2620:15c:9d:2:e754:74d1:c368:67a2]) by smtp.gmail.com with ESMTPSA id t6-20020a170902a5c600b001b9c5e0393csm1623345plq.225.2023.07.20.10.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 10:10:10 -0700 (PDT) Date: Thu, 20 Jul 2023 10:10:07 -0700 From: Dmitry Torokhov To: "Tian, Kevin" Cc: Paolo Bonzini , Alex Williamson , Greg KH , "Christopherson,, Sean" , "Bradescu, Roxana" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3 2/2] kvm/vfio: avoid bouncing the mutex when adding and deleting groups Message-ID: References: <20230714224538.404793-1-dmitry.torokhov@gmail.com> <20230714224538.404793-2-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FSL_HELO_FAKE, SPF_HELO_NONE,SPF_PASS,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 Thu, Jul 20, 2023 at 02:36:16AM +0000, Tian, Kevin wrote: > > From: Dmitry Torokhov > > Sent: Wednesday, July 19, 2023 2:11 PM > > > > On Wed, Jul 19, 2023 at 05:32:27AM +0000, Tian, Kevin wrote: > > > > From: Dmitry Torokhov > > > > Sent: Saturday, July 15, 2023 6:46 AM > > > > > > > > @@ -165,30 +161,26 @@ static int kvm_vfio_group_add(struct > > kvm_device > > > > *dev, unsigned int fd) > > > > list_for_each_entry(kvg, &kv->group_list, node) { > > > > if (kvg->file == filp) { > > > > ret = -EEXIST; > > > > - goto err_unlock; > > > > + goto out_unlock; > > > > } > > > > } > > > > > > > > kvg = kzalloc(sizeof(*kvg), GFP_KERNEL_ACCOUNT); > > > > if (!kvg) { > > > > ret = -ENOMEM; > > > > - goto err_unlock; > > > > + goto out_unlock; > > > > } > > > > > > > > - kvg->file = filp; > > > > + kvg->file = get_file(filp); > > > > > > Why is another reference required here? > > > > Because the function now has a single exit point and the original > > reference is dropped unconditionally on exit. It looks cleaner than > > checking for non-zero "ret" and deciding whether the reference should be > > dropped or kept. > > > > A comment is appreciated. otherwise, > > Reviewed-by: Kevin Tian Thank you for the review! However I do not think any comment is needed, if one is looking at the final source and not the patch form, the reason for taking another reference is plain to see. Thanks! -- Dmitry