From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6E31C001E0 for ; Fri, 16 Jun 2023 09:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344478AbjFPJks (ORCPT ); Fri, 16 Jun 2023 05:40:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344647AbjFPJkZ (ORCPT ); Fri, 16 Jun 2023 05:40:25 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90A312117; Fri, 16 Jun 2023 02:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686908424; x=1718444424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KhvcWRFOVp5HOcClxatXBklBptaC3+GyTlJbkaThObE=; b=DoZxatimrUKSU483Dg45hxso5S1iaY41CikkVyr+aisBms9q48MN87kt 3wlB4gZr/zm7c5RxpAuDXMUl+IpltcsdUk+B9HHACz7H+6+kFzxtjXESA 1UThfRlZkdioI2CqMXsXgY8O86a1UIwjTsdaK8QT0i2EqlOFHjOL7pkXq obLKaBrZPvptAW+CtqvkRBgiogu6xxFECJHcEbTS2c549zEQSt29c265e kjNYLLCVcr+a3XTvegVFJlC12E1Nxe++sDzZuvXpQ3SCtb1ohWXpMBLAs 7DNYusGRHFsi22oUG0CWqyyEg5IDdizMfA/WchPdOOyWVrwdyD2rCTFx/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="361700403" X-IronPort-AV: E=Sophos;i="6.00,247,1681196400"; d="scan'208";a="361700403" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 02:40:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="715951226" X-IronPort-AV: E=Sophos;i="6.00,247,1681196400"; d="scan'208";a="715951226" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga007.fm.intel.com with ESMTP; 16 Jun 2023 02:40:22 -0700 From: Yi Liu To: alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com Cc: joro@8bytes.org, robin.murphy@arm.com, cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-s390@vger.kernel.org, xudong.hao@intel.com, yan.y.zhao@intel.com, terrence.xu@intel.com, yanting.jiang@intel.com, zhenzhong.duan@intel.com, clegoate@redhat.com Subject: [PATCH v13 16/22] vfio: Move vfio_device_group_unregister() to be the first operation in unregister Date: Fri, 16 Jun 2023 02:39:40 -0700 Message-Id: <20230616093946.68711-17-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230616093946.68711-1-yi.l.liu@intel.com> References: <20230616093946.68711-1-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-s390@vger.kernel.org This avoids endless vfio_device refcount increasement by userspace, which would keep blocking the vfio_unregister_group_dev(). Tested-by: Nicolin Chen Tested-by: Matthew Rosato Tested-by: Yanting Jiang Tested-by: Shameer Kolothum Tested-by: Terrence Xu Signed-off-by: Yi Liu --- drivers/vfio/vfio_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index c71c0d1a079f..6d45caa1f9a0 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -332,6 +332,12 @@ void vfio_unregister_group_dev(struct vfio_device *device) bool interrupted = false; long rc; + /* + * Prevent new device opened by userspace via the + * VFIO_GROUP_GET_DEVICE_FD in the group path. + */ + vfio_device_group_unregister(device); + vfio_device_put_registration(device); rc = try_wait_for_completion(&device->comp); while (rc <= 0) { @@ -355,8 +361,6 @@ void vfio_unregister_group_dev(struct vfio_device *device) } } - vfio_device_group_unregister(device); - /* Balances device_add in register path */ device_del(&device->device); -- 2.34.1