Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3755535rwo; Mon, 24 Jul 2023 16:34:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlEA0ZTL/tswb1P0BwmGYfDh8dy7w8Scq/qnol5PKOcsOJrhOBxPTxX/3x4mfdHaamO98VlD X-Received: by 2002:a05:6808:1506:b0:3a3:7ee9:8f17 with SMTP id u6-20020a056808150600b003a37ee98f17mr13667621oiw.39.1690241695439; Mon, 24 Jul 2023 16:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690241695; cv=none; d=google.com; s=arc-20160816; b=a2ozSX014WgyyNJaIesKFeW0RqrC74hOmzp0Gom02+3Qa8UiCAaLG1LUpyi+u/aVzp qRFAwABlPYLGepl3f60ZXSpQH0RITr8N61iuPLZRJsOPx5/QfSYbJ4YGxEkCv2b2i1YZ ciTM+0gD5ZLR2A78y0PyP/F6BarzXysxxfU/ptBxrzqOxjdMd6MKnyGaGA1Kjiz/CoLc rhP8p292362XEkdOKvfxC6IHNFGQcoO4fnCmp0R87Tt16nAtjp1XmfKUV0bAdEWmXT6V RR/hN2VHqZwU22Qkb8JgVBs7Yc9497Tniw4dSbAtKC1rpMJOdsbfsRkXHwrFyf9xMFmk rZAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qH2g5/e7oI1QeOps6v0RKPDNRTx+3usdU82fpepupgc=; fh=bGo/Q4ro8pFaOByjLYWhYmu9zFeFMbnTLIEA0/9l4hc=; b=XVt7tg4ocyMF6S5eafNFYuXr4+juvaoyAhydkwCZf43NnhPgWo9QCtg4vq/l4o7876 HU21te7ro8c7Ut+xxEl2F0BGEpx5cLAh8ySRgd0J9vaG7tZGZdVWruUp10D0u3ABlbUH M5c4vh3d3IcoJevomFthZWDYAWQxjouF3Ek0vUXJIRl02HsEFTvFIpXeXB9KBhRc+MCZ vzcbKWJQ8CeZz2MSuq24jWDv5mfEs4dD97FW2GTnzRRbih/njSf0ZfrRR5t/ChYcOQoU YP/31lCmIMqi8kMNLXOGoZKj5FRIysCwu8GMoA9NokElXCDhaOoWrWy4mu/hrmj6U6h1 DOtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g8ALePV+; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a63954d000000b0055b2c94e7b1si9729291pgn.190.2023.07.24.16.34.43; Mon, 24 Jul 2023 16:34:55 -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=@intel.com header.s=Intel header.b=g8ALePV+; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231454AbjGXWUz (ORCPT + 99 others); Mon, 24 Jul 2023 18:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231391AbjGXWUn (ORCPT ); Mon, 24 Jul 2023 18:20:43 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D76F1725 for ; Mon, 24 Jul 2023 15:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690237242; x=1721773242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tvap/bP4frIrjwhw5ezK85sfojLa+kIMDMriKn0x2mM=; b=g8ALePV+6LpPuwH7J3jGVqsSSfVxvF3DRuUgnLeNf20GR2k6KYFNOQAw UeCMifjcitHDy1yHpPWPGRUhGdc1/LoGP7zVtSTD5s/2kZBxgorFzq3Ve uTiwm9AhqxD9Y8hU+ujz/85zxf6vxmyL4970gBn+THoLKtPB0k0318Vct FOtprStUd+27Bp/zYps/rZy2X+RLG6xXpCmei80U29KGx8NuVFHkBqS2H J/RCh8Ji9513QSfzD4N/CqyajbF8SuIhGjls9gFbtQ+lMo74MQYJBJlK6 vZ2SODfNrsO1SDfvUvbTYEFsw4LhyerIT9pzhaqV1/0uzw9XCRB37A0rK w==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="398476712" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="398476712" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 15:20:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="899675504" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="899675504" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by orsmga005.jf.intel.com with ESMTP; 24 Jul 2023 15:20:40 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, "Lu Baolu" , Joerg Roedel , Jean-Philippe Brucker , "Robin Murphy" Cc: Jason Gunthorpe , "Will Deacon" , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Tony Luck , Jacob Pan Subject: [PATCH v11 4/8] iommu/vt-d: Remove pasid_mutex Date: Mon, 24 Jul 2023 15:25:34 -0700 Message-Id: <20230724222538.3902553-5-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724222538.3902553-1-jacob.jun.pan@linux.intel.com> References: <20230724222538.3902553-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 From: Lu Baolu The pasid_mutex was used to protect the paths of set/remove_dev_pasid(). It's duplicate with iommu_sva_lock. Remove it to avoid duplicate code. Signed-off-by: Lu Baolu Reviewed-by: Jacob Pan Reviewed-by: Kevin Tian --- drivers/iommu/intel/svm.c | 45 +++++---------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index e95b339e9cdc..2a82864e9d57 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -259,8 +259,6 @@ static const struct mmu_notifier_ops intel_mmuops = { .invalidate_range = intel_invalidate_range, }; -static DEFINE_MUTEX(pasid_mutex); - static int pasid_to_svm_sdev(struct device *dev, unsigned int pasid, struct intel_svm **rsvm, struct intel_svm_dev **rsdev) @@ -268,10 +266,6 @@ static int pasid_to_svm_sdev(struct device *dev, unsigned int pasid, struct intel_svm_dev *sdev = NULL; struct intel_svm *svm; - /* The caller should hold the pasid_mutex lock */ - if (WARN_ON(!mutex_is_locked(&pasid_mutex))) - return -EINVAL; - if (pasid == IOMMU_PASID_INVALID || pasid >= PASID_MAX) return -EINVAL; @@ -371,22 +365,19 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev, return ret; } -/* Caller must hold pasid_mutex */ -static int intel_svm_unbind_mm(struct device *dev, u32 pasid) +void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid) { struct intel_svm_dev *sdev; struct intel_iommu *iommu; struct intel_svm *svm; struct mm_struct *mm; - int ret = -EINVAL; iommu = device_to_iommu(dev, NULL, NULL); if (!iommu) - goto out; + return; - ret = pasid_to_svm_sdev(dev, pasid, &svm, &sdev); - if (ret) - goto out; + if (pasid_to_svm_sdev(dev, pasid, &svm, &sdev)) + return; mm = svm->mm; if (sdev) { @@ -418,8 +409,6 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid) kfree(svm); } } -out: - return ret; } /* Page request queue descriptor */ @@ -520,19 +509,7 @@ static void intel_svm_drain_prq(struct device *dev, u32 pasid) goto prq_retry; } - /* - * A work in IO page fault workqueue may try to lock pasid_mutex now. - * Holding pasid_mutex while waiting in iopf_queue_flush_dev() for - * all works in the workqueue to finish may cause deadlock. - * - * It's unnecessary to hold pasid_mutex in iopf_queue_flush_dev(). - * Unlock it to allow the works to be handled while waiting for - * them to finish. - */ - lockdep_assert_held(&pasid_mutex); - mutex_unlock(&pasid_mutex); iopf_queue_flush_dev(dev); - mutex_lock(&pasid_mutex); /* * Perform steps described in VT-d spec CH7.10 to drain page @@ -827,26 +804,14 @@ int intel_svm_page_response(struct device *dev, return ret; } -void intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid) -{ - mutex_lock(&pasid_mutex); - intel_svm_unbind_mm(dev, pasid); - mutex_unlock(&pasid_mutex); -} - static int intel_svm_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; struct mm_struct *mm = domain->mm; - int ret; - mutex_lock(&pasid_mutex); - ret = intel_svm_bind_mm(iommu, dev, mm); - mutex_unlock(&pasid_mutex); - - return ret; + return intel_svm_bind_mm(iommu, dev, mm); } static void intel_svm_domain_free(struct iommu_domain *domain) -- 2.25.1