Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4397740rwb; Mon, 31 Jul 2023 06:24:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlGqp0oCPE1sKRBDHStK/B/vaju5DM0gku9yjTEAn1urQX0dB6r4qh4ZFp2mBWqWwoJGbp37 X-Received: by 2002:a17:902:9b89:b0:1b8:b47e:a881 with SMTP id y9-20020a1709029b8900b001b8b47ea881mr7495666plp.49.1690809848242; Mon, 31 Jul 2023 06:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690809848; cv=none; d=google.com; s=arc-20160816; b=GbJtum6CDnH82mohMCQboAPYxFc+B7IsBzP/zps2gjfbDhBeGpl6RLsDV7CcnI2l/C BLT1QBR/vjiur9tHvvFQ3yAt3rOmzRWtLtGBA8fLwnasxnr/GpWu//hItQ/w8ur7CwDV 3Tz5ZqjEHkzXrSAMBsTprsw1MFiFVx3U7zKC66GL+yyBtvtJaFohVVgqEYoWHLZwSN7n eJFaWO8Yx2vaIjYO4dniOOeiTkN/7tVbNjgj6Z2ZsZMowKvtue8yGZ+dK7UIRNLxVygz 3P1qZAKnWskG/wSWHZnTJ6JqTg2fwb0fwtPRzJbYLRH69OHDzDlAntOdOBONHvhs7sKC dEDQ== 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=DacMFZOBu07wKbvtoMxQrUI7MItsaS5hi2kwnsJgjX4=; fh=xgcj4UHTMhxU7RD0GOlXsEAvNmiuSJOqnnl1C4uYxpA=; b=oKWdBTRx37Se5DtTigICZ/xBhDrOjA/h9nZO0dcQcNoKv8wwCfMVDLJ7JitEFKkzh2 c12uBjaypde4jIjSAVc86wipUE9924+9+HqV+1nqHFEF7UL4GGqyCQ7lau2V4K9GnzW/ 1IWiHlJakx7x0mNPt6+7sJ26bN9+jel7uH3Qp62l4R/Cjz5+/YHZye8GSZtyLPeh4ki1 DlGx1Yup6i70tWTJ5EmYeNy9e9yNOy+kzdUXKervEOJ1j0Ppx1xP369Yk1dVbbj2axf5 kHBv63CbVa2dKTyPARy3XnOYJ8Z7T5Qx0ltFcRShh/lv+PjL/aRVgBJNIaiIUNeztdWl AGEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T67Z5ZQ9; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a170902c94300b001b8b4371af8si7390312pla.648.2023.07.31.06.23.56; Mon, 31 Jul 2023 06:24:08 -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=@linuxfoundation.org header.s=korg header.b=T67Z5ZQ9; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232178AbjGaMDU (ORCPT + 99 others); Mon, 31 Jul 2023 08:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232605AbjGaMDJ (ORCPT ); Mon, 31 Jul 2023 08:03:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E237C119; Mon, 31 Jul 2023 05:03:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6F3C56105A; Mon, 31 Jul 2023 12:03:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 032D8C433C8; Mon, 31 Jul 2023 12:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1690804984; bh=TtJhPqRQlajaW9Ul53sJZlLR70A30mmQNrdXLgduGeY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T67Z5ZQ9m8brhGwe96qXE+V+KHAb39u6KyKtiWKwEAYCI1tyXX9XShvxgOps3Dbwj 0Q2fgBFQtqyPSsIJgm6iyYAYEvnF1C5/pq+kydCiB3stV7WbWwOiUvloVWyMWn3XtH +8T0HX6x+LDWk68iF26AvX+8Y5ZV38wROJpU6zNs= Date: Mon, 31 Jul 2023 14:02:59 +0200 From: Greg KH To: Dmitry Torokhov Cc: Paolo Bonzini , Sean Christopherson , Roxana Bradescu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kvm/vfio: ensure kvg instance stays around in kvm_vfio_group_add() Message-ID: <2023073144-whimsical-liberty-4b4f@gregkh> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Mon, Jul 10, 2023 at 03:20:31PM -0700, Dmitry Torokhov wrote: > kvm_vfio_group_add() creates kvg instance, links it to kv->group_list, > and calls kvm_vfio_file_set_kvm() with kvg->file as an argument after > dropping kv->lock. If we race group addition and deletion calls, kvg > instance may get freed by the time we get around to calling > kvm_vfio_file_set_kvm(). > > Fix this by moving call to kvm_vfio_file_set_kvm() under the protection > of kv->lock. We already call it while holding the same lock when vfio > group is being deleted, so it should be safe here as well. > > Fixes: ba70a89f3c2a ("vfio: Change vfio_group_set_kvm() to vfio_file_set_kvm()") > Cc: stable@vger.kernel.org > Signed-off-by: Dmitry Torokhov > --- > virt/kvm/vfio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c > index 9584eb57e0ed..cd46d7ef98d6 100644 > --- a/virt/kvm/vfio.c > +++ b/virt/kvm/vfio.c > @@ -179,10 +179,10 @@ static int kvm_vfio_group_add(struct kvm_device *dev, unsigned int fd) > list_add_tail(&kvg->node, &kv->group_list); > > kvm_arch_start_assignment(dev->kvm); > + kvm_vfio_file_set_kvm(kvg->file, dev->kvm); > > mutex_unlock(&kv->lock); > > - kvm_vfio_file_set_kvm(kvg->file, dev->kvm); > kvm_vfio_update_coherency(dev); > > return 0; > -- > 2.41.0.255.g8b1d071c50-goog What ever happened to this change? Did it end up in a KVM tree somewhere? thanks, greg k-h