From patchwork Fri Nov 11 00:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 18351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp454047wru; Thu, 10 Nov 2022 16:28:04 -0800 (PST) X-Google-Smtp-Source: AMsMyM6q4L2xW5IC9vNhTAhDiUolB6GDlAW8sM6jU21EWOLNKj6YxT7edeor0CUagJT0gilaXdgZ X-Received: by 2002:a17:90b:2392:b0:20b:a5e:5c40 with SMTP id mr18-20020a17090b239200b0020b0a5e5c40mr2756207pjb.185.1668126483874; Thu, 10 Nov 2022 16:28:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668126483; cv=none; d=google.com; s=arc-20160816; b=dh3c+SDxUjdUTXTrfZ3juvzESJl2kQ6oF8qk6fmhzUKQBy5wJ+w9e6wG+huIJg9ApE nj6bDey4VrSiAH4hCo7G4qnlKRKJqrjpwxKeikhkWiyf3NY+2leSZmPAXB6fF58DRYwa ETIUDqcpLF6xW5TIacFXacQS5LETp08SioE6V1N02ATBhx5tuveDptOJf47GEObGNaMC fx0TVpvanzTNNilHADmCGeaM/WeG9MSnIgI88l2396Ai0+WuRhFMwplrQ0kdHXcBG2YQ SYNiuz8S7UoKmuo8AHdQGYRc5waBh8OZBOajWZWQcQui/IUlwioaPsGHaUu0ROrV0yZi SMDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=/Qtct265AUs3mCRq4YXmCFT3mbV9fW5IFtDc5J2z2zs=; b=Ko8OH7GUI2w4yy7ARrrRZJOCJyyzZiNn3P2A+arvZIRoIFeerc7cwLrszLD3sosv3I MMTp7O0uwLD5+rk/qt0b43GHfjFno0hkv3AVsTfQoNcne4isTopOgf5zxVw7hTokqOxY 2gxPej/UjAP89WFGPNBhx1SOFFToLBRHaQKB7cLQg1xCUOsI7Njwkzrabk6r3jRNYTPP 3O5k5PY018AX/1mCvfqX7dvzWeFxLWmdEvCmYQ0PWl3QXikoZcWSR4umSxuIgecidBEZ UHNxe5DdL2qioe/B5ldMEArxCsNFphNJ5eH5p4D9KHUnMfQV8s+BAjbOANGfma9bzjCn /5qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FBR88osY; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w186-20020a6382c3000000b0046f4d395e6dsi665054pgd.573.2022.11.10.16.27.46; Thu, 10 Nov 2022 16:28:03 -0800 (PST) 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=@google.com header.s=20210112 header.b=FBR88osY; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231260AbiKKAWf (ORCPT + 99 others); Thu, 10 Nov 2022 19:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbiKKAWb (ORCPT ); Thu, 10 Nov 2022 19:22:31 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C04E1F61E for ; Thu, 10 Nov 2022 16:22:30 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id y15-20020aa7804f000000b0056c9b4a58d3so1815404pfm.18 for ; Thu, 10 Nov 2022 16:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=/Qtct265AUs3mCRq4YXmCFT3mbV9fW5IFtDc5J2z2zs=; b=FBR88osY8fIlZLbRznAOCa2Xf7BHDJaHVBD3PLmB9KlLJqRyRDDLI3zyzsZcD0Rn5m 5oCwjogt2zecTA7RiD9yeOlvc55mEqbD8BgDuCuDPhgkuTUGCTX+PZfFw8d63rpWQhSP 4YkKHAyfDPUatmW5/skfXM0hFEJa+6kp7KfEuEWXg7E4DNB1ZzIThCPt1PM0BzD8Xdhq A/EPbIV3ybXi65UzJTKQ8T8FJMvIkmMoPVo3GTuq4UapPDYeRJRzaqoquBxRN2AYC9KA A/DU8ldikEieGp5BDIr3DGthufNFJEG9FQ/iYXTHPCiQh1sE8mL3YkDDK1B4aUDeO2MN Z8Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/Qtct265AUs3mCRq4YXmCFT3mbV9fW5IFtDc5J2z2zs=; b=Q2GPEKqRyYfpm0CtV7yZGcd9IdtIepRJcLdbP83ANdJzwWXPEHV6MaobOQxqp/fVkf W+Kh3gFW16jIca69r94Et6po/u354iSYluEUDrUb/bwM6JmGkiS6l2b5ETu5ePNL5vvJ UqONifhGym6HGbEdWdmclA/zqCVQWsrXle3tlPxrRY49ZVabOIJmVJaUTBwyiEMceNqn MvG8F9A2uQf6YxDRapudwtdXECP/IkJEpDJf6sNmZYbX2f08/9kqCQ3Jv/xnOLFQ9ZBn g18EC20U5n+zE7iRtwlTnF7ohFVTIbHCCsqCAfe1PcTD+u5xUMe4o/EzVq/cMl6yBds7 mzxQ== X-Gm-Message-State: ACrzQf2N/tk4Q9QGjRfUXYyuTqZYEqrR4MrevgQjq3ar7KQsVTc1behQ l9yvh+WMk6IW6irFPmeBSWJ9S6COd1c= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:703:b0:56c:e37d:ec12 with SMTP id 3-20020a056a00070300b0056ce37dec12mr4208245pfl.80.1668126149761; Thu, 10 Nov 2022 16:22:29 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 11 Nov 2022 00:22:24 +0000 In-Reply-To: <20221111002225.2418386-1-seanjc@google.com> Mime-Version: 1.0 References: <20221111002225.2418386-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221111002225.2418386-2-seanjc@google.com> Subject: [PATCH 1/2] drm/i915/gvt: Get reference to KVM iff attachment to VM is successful From: Sean Christopherson To: Zhenyu Wang , Zhi Wang Cc: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sean Christopherson X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749157395968871766?= X-GMAIL-MSGID: =?utf-8?q?1749157395968871766?= Get a reference to KVM if and only if a vGPU is successfully attached to the VM to avoid leaking a reference if there's no available vGPU. On open_device() failure, vfio_device_open() doesn't invoke close_device(). Fixes: 421cfe6596f6 ("vfio: remove VFIO_GROUP_NOTIFY_SET_KVM") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Reviewed-by: Kevin Tian --- drivers/gpu/drm/i915/gvt/kvmgt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 7a45e5360caf..e67d5267fde0 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -664,8 +664,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) return -ESRCH; } - kvm_get_kvm(vgpu->vfio_device.kvm); - if (__kvmgt_vgpu_exist(vgpu)) return -EEXIST; @@ -676,6 +674,7 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) vgpu->track_node.track_write = kvmgt_page_track_write; vgpu->track_node.track_flush_slot = kvmgt_page_track_flush_slot; + kvm_get_kvm(vgpu->vfio_device.kvm); kvm_page_track_register_notifier(vgpu->vfio_device.kvm, &vgpu->track_node);