From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753063AbdCTHB7 (ORCPT ); Mon, 20 Mar 2017 03:01:59 -0400 Received: from mga09.intel.com ([134.134.136.24]:8797 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752827AbdCTHB5 (ORCPT ); Mon, 20 Mar 2017 03:01:57 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,193,1486454400"; d="scan'208";a="1110234477" Message-ID: <58CF7D7E.6010006@intel.com> Date: Mon, 20 Mar 2017 14:58:06 +0800 From: Jike Song User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Alex Williamson CC: intel-gvt-dev@lists.freedesktop.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , stable@vger.kernel.org#v4.10, Paolo Bonzini , Zhi Wang Subject: Re: [PATCH] kvmgt: Hold struct kvm reference References: <20170320023814.18566.36538.stgit@gimli.home> In-Reply-To: <20170320023814.18566.36538.stgit@gimli.home> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/20/2017 10:38 AM, Alex Williamson wrote: > The kvmgt code keeps a pointer to the struct kvm associated with the > device, but doesn't actually hold a reference to it. If we do unclean > shutdown testing (ie. killing the user process), then we can see the > kvm association to the device unset, which causes kvmgt to trigger a > device release via a work queue. Naturally we cannot guarantee that > the cached struct kvm pointer is still valid at this point without > holding a reference. The observed failure in this case is a stuck > cpu trying to acquire the spinlock from the invalid reference, but > other failure modes are clearly possible. Hold a reference to avoid > this. > > Signed-off-by: Alex Williamson > Cc: stable@vger.kernel.org #v4.10 > Cc: Jike Song > Cc: Paolo Bonzini > Cc: Zhenyu Wang > Cc: Zhi Wang > --- Reviewed-by: Jike Song Thanks for the fix! -- Thanks, Jike > drivers/gpu/drm/i915/gvt/kvmgt.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c > index 84d801638ede..142b8bd4ba6b 100644 > --- a/drivers/gpu/drm/i915/gvt/kvmgt.c > +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c > @@ -1324,6 +1324,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev) > vgpu->handle = (unsigned long)info; > info->vgpu = vgpu; > info->kvm = kvm; > + kvm_get_kvm(info->kvm); > > kvmgt_protect_table_init(info); > gvt_cache_init(vgpu); > @@ -1343,6 +1344,7 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info) > } > > kvm_page_track_unregister_notifier(info->kvm, &info->track_node); > + kvm_put_kvm(info->kvm); > kvmgt_protect_table_destroy(info); > gvt_cache_destroy(info->vgpu); > vfree(info); >