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: 13051301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC1ECC433FE for ; Mon, 21 Nov 2022 15:29:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C987110E300; Mon, 21 Nov 2022 15:29:19 +0000 (UTC) Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 574B410E16B for ; Fri, 11 Nov 2022 00:22:30 +0000 (UTC) Received: by mail-pf1-x44a.google.com with SMTP id m6-20020aa79006000000b0056bc283f477so1808261pfo.19 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=ZQlQTCuGVYxeSEyxO6Gar9fUl2Cd61mpG9f4SOhNd7Eh6skGDpsXzzqRm5RJIJHoCA DDBwZWBi7LVDtaBtjA9xygCyWpMcTDjkMCE3XSCGCh8Ivmi4sBaGRgfmIfVi9cHYLGfo wYc/1JVKObZ19eAgFuJsQp88twwIJK93O6yvUG3YV1aRhdfFz8pcLzl4blil1s6R/KaH FsGD4lB78ALdkvpceeM1nw5iLuoEhPqtaQv0QhvyLwMEKDkdDgcPuyKN60q+yJ1xd3ya LDJbrqQz/lr3CvzZnlazYBSN6ETGb5zLAvx4W0fmTeHsfA4dt0Viz3OZ6duzh2xOyrA1 8c3w== X-Gm-Message-State: ACrzQf0/RBiwml1rHBYsk9K0QUE0xwIDh9vHKIiI3noe5+8fSI3TdWH4 bJzWWhsP/Gee/QB1PBpfBOVCLlCBFT4= X-Google-Smtp-Source: AMsMyM7iJ8xUv6oGaaWJB9TjFOHAMhWthcMv2slpXsAbeSOdSGcqg31xUyPwviIZlQaEysgjStUI+jeH2IM= 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) 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> From: Sean Christopherson To: Zhenyu Wang , Zhi Wang X-Mailman-Approved-At: Mon, 21 Nov 2022 15:26:23 +0000 Subject: [Intel-gfx] [PATCH 1/2] drm/i915/gvt: Get reference to KVM iff attachment to VM is successful X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Cc: Sean Christopherson , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 --- 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); From patchwork Fri Nov 11 00:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13051275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27C4EC433FE for ; Mon, 21 Nov 2022 15:27:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B34B010E307; Mon, 21 Nov 2022 15:26:33 +0000 (UTC) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8BDDB10E16B for ; Fri, 11 Nov 2022 00:22:32 +0000 (UTC) Received: by mail-pf1-x449.google.com with SMTP id t10-20020aa7946a000000b0057193a6891eso726473pfq.0 for ; Thu, 10 Nov 2022 16:22:32 -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=n36J7s+0ilM0Tsn5slAdsXyaRWJfxWCAeT/6FWqeTp8=; b=TZiKdFTbv7ULH977/XXkoaKwCBWIUXcZgjj3kk67qk6G/7NTnWl7f9ErIfa3sgs6Iu PIE2j9lVQnRevVhSmgy5ghpMaowZSmo/JvV26NB/u5XUxIGVX2T3kGhGEB+GX40/BH+e dMm5i34zN0Ep9bgjqiptCmyqKJTPz98+Gc5Erv/2Hk0eC6sx/JrEjrvIb4L//JadZb+D yyrZCQmeoRcq14GM/aKC8IJAyy66Zz5B57Ex00OXo4YACUPRLXDVs9TboavE9uxTi60O H5HIhz1q4T4MEoC0qbI3gIAqHaqRVBYY+wU9Sv6jmDDDGplg8ezaO+Oydl1V1nV+l4ZE GG4Q== 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=n36J7s+0ilM0Tsn5slAdsXyaRWJfxWCAeT/6FWqeTp8=; b=fTJlouNNi9NGJF/5ifqQWEyU6kdav2CPBBsWISTguhIbR4S0epuVgkoHWwfzmSPte/ iqhVmPhlfJ2KPw+lioXQkPZsLGwf9NFdWVHySkfvSjU7ao2kLmbrtseFG/sXYgqKzwhs tG/qcTxDcGRjmmtlT6PhTiEzhWCrvTp7fpJiJkIBD/VoCLjj6TugHdu7HlRbm7vNE65h j3oPm60eaOi4jcdd7rOv2Z5e7xgYwLGnPWY6VN1c53BknL/lUT5uhcctOF5ILwC0TiYv KlkVS46cqu/4d6u5OYuOeUzCtZGgi6GmsQRDaGnKZ0H1qvbArYcDSQs5CHj82GSvsrdW tahA== X-Gm-Message-State: ANoB5pmCua0+Epo+pcE2qBqOHm1gAuMVHuwiLj6IopuX4tIZ8hE2PA71 80raeDCtP/4ermKxbu3VEw+Ym2G9uE4= X-Google-Smtp-Source: AA0mqf59PK1ce8OQvm+mdu5I4wtiwB4LZ1gWqBvwwJnwlP7+YuZxp1WsB+ro/Om0CHqF+A4TMJj0VFzo6aE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:dac4:b0:186:5f54:18cf with SMTP id q4-20020a170902dac400b001865f5418cfmr4884plx.141.1668126151578; Thu, 10 Nov 2022 16:22:31 -0800 (PST) Date: Fri, 11 Nov 2022 00:22:25 +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-3-seanjc@google.com> From: Sean Christopherson To: Zhenyu Wang , Zhi Wang X-Mailman-Approved-At: Mon, 21 Nov 2022 15:26:23 +0000 Subject: [Intel-gfx] [PATCH 2/2] drm/i915/gvt: Unconditionally put reference to KVM when detaching vGPU X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Cc: Sean Christopherson , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Always put the KVM reference when closing a vCPU device, as intel_vgpu_open_device() succeeds if and only if the KVM pointer is valid and a reference to KVM is acquired. And if that doesn't hold true, the call to kvm_page_track_unregister_notifier() a few lines earlier is doomed. Signed-off-by: Sean Christopherson --- drivers/gpu/drm/i915/gvt/kvmgt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index e67d5267fde0..714221f9a131 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -714,15 +714,14 @@ static void intel_vgpu_close_device(struct vfio_device *vfio_dev) kvm_page_track_unregister_notifier(vgpu->vfio_device.kvm, &vgpu->track_node); + kvm_put_kvm(vgpu->vfio_device.kvm); + kvmgt_protect_table_destroy(vgpu); gvt_cache_destroy(vgpu); intel_vgpu_release_msi_eventfd_ctx(vgpu); vgpu->attached = false; - - if (vgpu->vfio_device.kvm) - kvm_put_kvm(vgpu->vfio_device.kvm); } static u64 intel_vgpu_get_bar_addr(struct intel_vgpu *vgpu, int bar)