Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4633124rwb; Mon, 31 Jul 2023 09:42:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHTncGhE7tcjkhrEDQ1hzjiGdrIn1WEOBPJJ+gmRix13Apu2fhVriyRFitXjs7FmnccIYuj X-Received: by 2002:a17:906:3f5b:b0:99b:5abb:8caf with SMTP id f27-20020a1709063f5b00b0099b5abb8cafmr282301ejj.44.1690821758750; Mon, 31 Jul 2023 09:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690821758; cv=none; d=google.com; s=arc-20160816; b=nTIJ7m+r3Ng1xVY5xc9XhVPdFjlxHqNGdXjorbbCXETDp0Q2Dkuaa/OJKcvZaBUScy qXYkbkKr+ZWlnWrm1sGv4EcH7uU7kqqrlobNk+bu3bMOVl/fOnAZ8WdQp9fXb4RFPoNS u77/JPFBuXrXDI5nhsMEEXEBC25deEaga6AWn9cE6uzPNwZwkFkC77/OiaAzqftQxzZr LoA3g2sD0gwmGmZzF3+7sip7pzrUVMDZtAgWSILFVVJHkmJ0Ku1XlI9Ep7+tXUNZvMBd mvS00X8fg+2YHkmN4roFnKpR4vg0udIAORuuE4PJ5RKM7FRWflEiukRSZGucdsOj7QwV negA== 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=yRI4uTVmkcfy2T7ALhUcJFpRNujxrfSpxIRskmxX1Hs=; fh=CMkKPLzNkw1G7MuvBwfGstx6YyOODwCV/A1c0Lbshy4=; b=mFgIBD4mHmJLgx2t3trwEM/Y7vJNFKq14LQJ3rCzJK9pQwaSEmJdu+LhnYAHLCql4s mIjZ3cd0om+LM3tc9fgKDCQs40ST+bMmQ7QUz5Rd887TaU6sACg33sQvLyMx2Q145Ct7 2FGfZdLNC6OgYsCxNGuPJRXM03J7rHlFMP8AuaraFRnaJeXr19NvA7IseDLqfmCuacZd /BUOKPku77L10qoWTWFPXaMqsTo9LcQcbdYeFbaE2XseDY6HO8DLU8N0djXq22xSD+nA to7tVlzXzEK94wCXAQUkssun54HidVxExawFDjpuL2DS43BmY/oWpXS4WHkXUwSGveTa g/yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OXz5Yjyx; 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 i18-20020a170906115200b0099bcb3ad52dsi7109138eja.805.2023.07.31.09.42.13; Mon, 31 Jul 2023 09:42:38 -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=OXz5Yjyx; 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 S232087AbjGaQSF (ORCPT + 99 others); Mon, 31 Jul 2023 12:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232558AbjGaQRy (ORCPT ); Mon, 31 Jul 2023 12:17:54 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1315A7; Mon, 31 Jul 2023 09:17:53 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-686efa1804eso3316940b3a.3; Mon, 31 Jul 2023 09:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690820273; x=1691425073; 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=yRI4uTVmkcfy2T7ALhUcJFpRNujxrfSpxIRskmxX1Hs=; b=OXz5Yjyxv8+pYj6Q6lK/kui71QV75eeVQJbDv+9fxjDonaaAYGbetVhIPHnqLavjs6 PSVN6UFkfGZ7LqMh+amfcUZlX+xKzYd61p+IFx9qHqTHr1c4cOkhL2jYWZJm1xDUVslt PmVBGCutLKz+F+GHaxv1vbTOnWtNHmVXGJCGsprsrwXLyhGakwXPKzJfpG8BomIHll10 /SZgGm/3oxO0dUGDwQ1zQtdjyhTU5E+Q5Ivv/1s1DDHp7u5QhgOCZplzoZa+5qdMmfbO 6BGgFx+Rqlg6zjG1XnQ4ZZDa0RMXsODG2FXEUugcMQTjZ6GHZQ5mLNEsE/BOPKXsAvzc rIcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690820273; x=1691425073; 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=yRI4uTVmkcfy2T7ALhUcJFpRNujxrfSpxIRskmxX1Hs=; b=YqYR5/WxoxMD2ss2UfaYDyZEALl5DeMXcTYqdGxrRW1MjLl8yy9Bg7yhzNrQ/CBl5B 3laIGJ+X3b/W1ACDXdlAKvEQNX39uweZ6VxSzdwBRT8eLSwVFEbhIew0+zzWdd50P48D 3YIi4HsvqhfEKzLf6Yo91pNEE5HyWTnpF2POSPAonZpckThhABcKg2ycYQM66q73arPp R4WOtYM+KV++GMx0QVWvviOWYPqPngfpOV3PVR5DZBFgBZfnw5QQyrLa+myv1Op/xTIB NrqBcEKs/VnAW1XTZhD6/0lLr9nD4zAZaEdIOOF2MwoHgaX5Yn82ahISkGt+M5/UcuLZ nXkA== X-Gm-Message-State: ABy/qLY/YSf5BuYNTmknuEpiT/j5z47xy+muggaMXuRHlqEVXsluMhDf gtmXpWOfvamnzN3V91EsDOE= X-Received: by 2002:a05:6300:8003:b0:13b:9d80:673d with SMTP id an3-20020a056300800300b0013b9d80673dmr9746142pzc.48.1690820273060; Mon, 31 Jul 2023 09:17:53 -0700 (PDT) Received: from google.com ([2620:15c:9d:2:6d25:c0f1:d8d5:201c]) by smtp.gmail.com with ESMTPSA id r4-20020a62e404000000b0064d47cd116esm7726102pfh.161.2023.07.31.09.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 09:17:52 -0700 (PDT) Date: Mon, 31 Jul 2023 09:17:49 -0700 From: Dmitry Torokhov To: Greg KH Cc: Paolo Bonzini , Sean Christopherson , Roxana Bradescu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Williamson Subject: Re: [PATCH] kvm/vfio: ensure kvg instance stays around in kvm_vfio_group_add() Message-ID: References: <2023073144-whimsical-liberty-4b4f@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2023073144-whimsical-liberty-4b4f@gregkh> 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_BLOCKED,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 31, 2023 at 02:02:59PM +0200, Greg KH wrote: > 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? It was posted as: https://lore.kernel.org/all/20230714224538.404793-1-dmitry.torokhov@gmail.com/ and I believe Alex Williamson is planning to take it through VFIO tree. Thanks. -- Dmitry