Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7786976rwp; Tue, 18 Jul 2023 23:35:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFNQejC/IChix5qv2aTAVIeY7Gj7abAmyMG4GPB7M09xzV1R3xuiKzVUezlAmZWbbxFM4sU X-Received: by 2002:a17:906:7a4a:b0:993:e883:491f with SMTP id i10-20020a1709067a4a00b00993e883491fmr1980910ejo.8.1689748542743; Tue, 18 Jul 2023 23:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689748542; cv=none; d=google.com; s=arc-20160816; b=leZ+WPNe5SM2VWJd29mn3kDpkzC45UmAWTv6PWFgR65OKnuV3X9yizfKbhxEH2FYwU Pdwm8fQkWY5KDKSUBeWBYbJfsfAwjxFlgRjig9R7YGa8VfOHILbEco8cz6/AF6eUOztu G8aV79PFJ+I3bFCOjJwDSHtGnetmDa/JTqlC3YCkcI295n+3IwUUE1Pmsil1GTWFzVFe 4NFnzXflOKENtJbNFQ2yBKwZqKvqqGliRo8Xj7GFGRFDkCRDyDksWGXedvCiY6VkBBjB H1fLyqp8LpgQ0vOyS7e0aHR+eoHuDX8gAfMTknwLTS3I9vbhVhZyKzZePsCYk3jU5Nyt Z1tQ== 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=pU0qdX1zjclqQ1Al6JJUTxVgam+qJOuCC65TIbBSrT4=; fh=7KhqMsEDo7BTfCk6NG+VlByJJo7I6VM4ls4Wj0u9F2k=; b=OU0ZhHnU2dRwSy0WzmbC3+8zjGpJGzma6WWcSQWUnrb/5I41FK4Ejtk6KZsUpNTxjq ENcZB/MK8EFMkbNe+f8qfjONZ0HIPwEoHfdQGw+1mp8sVyYtOM57uxddoKweLsWj4kTV ArNo+SYuWdeO9WkA0z+dMqXYJ82Q2rZlniafH+P6jjMYQTViaw9WtCBUDqxYt/YBOhYg 8GxHTVrPackxUGku55ZYgVNY0gH9ZSojTTj50uE/qTTcNyeOpP+wpjabH+z9kyIJ+eF7 Q+YeK33eXoyQatwWw7KZ9NERNiMSdL39tIBCsaUyMiDezKcsBu3aNnmWYuJlPIGswo+9 RbCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NrZcGaJp; 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 lw3-20020a170906bcc300b0096f65c97148si2360788ejb.714.2023.07.18.23.35.18; Tue, 18 Jul 2023 23:35:42 -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=NrZcGaJp; 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 S229648AbjGSGLG (ORCPT + 99 others); Wed, 19 Jul 2023 02:11:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbjGSGLE (ORCPT ); Wed, 19 Jul 2023 02:11:04 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3C6C1FE7; Tue, 18 Jul 2023 23:10:43 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b89bc52cd1so36767765ad.1; Tue, 18 Jul 2023 23:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689747043; x=1692339043; 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=pU0qdX1zjclqQ1Al6JJUTxVgam+qJOuCC65TIbBSrT4=; b=NrZcGaJpj0rPP53dHrJXfP9oHbhqtB0JXL2v/o6AaAUGaCjZBtpX9+ILoAAPE6j2HA Fnojg/SFcXU8Ju6G9dUA8HbReNapA3Ij6F2q8m+2k5LCOf4dQhSSApOcQ/PDz0PuC/ze +dIo89neaMj3Wle0NlGTW+iQ6DJY3eMV56Aa00tsNe2VqkHjpSXwqTlua/Dao0E0FZ1s G3oVWD100FS9kU6jp4TecfIsaOuZDdRbKCQfFlv+dR8oBaYYc1TeJAtrM6I0kBr1Lnzi /6xPtKY5I/TuJYX+Cc36Zqgra/qqnJuvM26AdhWIQ1DQZzXq0LozBBk1eu9wYuWSP4x+ 18nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689747043; x=1692339043; 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=pU0qdX1zjclqQ1Al6JJUTxVgam+qJOuCC65TIbBSrT4=; b=Bfq1vnYsAlN8DDXAao4PIAC/osnn5mCRflggSjjYsnov582Ig5BsPfXGTeirIZ6w7V /cls8ZEOE96CSpuYFvw1R3PPwN1FtLY1aTduXLEicGnGWMGZ4HIRupoOPJL6o6Jvda32 vAVobpZbHeFftN942YN6TUD/biyXz6N3uzYNUCBycohbl8sYUg9+kHq9jtePW6eiciab xoptR5vSi3cXbHHIjEIpg/uxKNrJG7olI82e17T44lI5dqtAIbBTPDYaJg9cSrku4bmE 0rOaDNZ8Mhtb5maNgcm0YvglhKakr+fXu8uKkLMo1fQnGP2rsuY8wim1UoW0Kdh6nGNG /KkQ== X-Gm-Message-State: ABy/qLZZKqeVYzyzdlHq/9s3tSbgmVcaHNbEVIRYh683GUMygrb0BeyT xg3z1WZPXEQhXMX7NfRQmA4= X-Received: by 2002:a17:902:d382:b0:1b0:f727:bc41 with SMTP id e2-20020a170902d38200b001b0f727bc41mr14917234pld.42.1689747043276; Tue, 18 Jul 2023 23:10:43 -0700 (PDT) Received: from google.com ([2620:15c:9d:2:798:b6f:a67a:7ac1]) by smtp.gmail.com with ESMTPSA id z16-20020a170903019000b001b83dc8649dsm2915121plg.250.2023.07.18.23.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 23:10:42 -0700 (PDT) Date: Tue, 18 Jul 2023 23:10:39 -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, RCVD_IN_DNSWL_NONE,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 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. Thanks. -- Dmitry