Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9974401rwd; Wed, 21 Jun 2023 14:32:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bw7fcX0ajOmh8Mk+ziGb2+JmYP84uZ+Y/MU0n3+tKQm3NUubrsLLV6QKeR1ECNXfE19Mi X-Received: by 2002:a17:90b:3687:b0:25e:aeaa:521d with SMTP id mj7-20020a17090b368700b0025eaeaa521dmr13176941pjb.15.1687383175187; Wed, 21 Jun 2023 14:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687383175; cv=none; d=google.com; s=arc-20160816; b=zBZj8R7nyAPZm9Q/V1CNJC7ahlB37J9AUP1rAGLUFNX2eYkfODh7Dpe5Duux7qzfZi E5gGcKAc0SoSwDz52F10BztJcTh/a+5YxoJDp+NGCPUgDw51BAxJ3+cnRpOoY2mQ0UV9 Gzz6hwmiC8pqZIvQgM3ucO0kFsWHbOhUv/7DoAH22IKzfxmWBK9j8Jj7fmDmuaVNvAOM RBW6FjCW55ChPhtrJsqNvR/IAPj6z22jl6e5ZhUIBtDqrWNpiZl4kTJZbclM+vjjy5TU ZVn1i3+doWKx5p0PknSA33PiurwPPDiW+PHb7lumD2QU1/HOMo7xGJkdEsT7D8uaY7ej ZQhQ== 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=V44RqPbP8wHrEah5T1NMbuSIOKSafbt+x+I0fno1bdY=; b=Xvt3usOLtDv4pVQq/SmYKpaD/M7txVXfab+bdU+UPoDI2MVJBPLxhj1dY7HduA6dTG /j3kWNpC5VTw1Psj5xiLN2a1QAaC7b7/eMdAXTCNXKYqO8fR6tvAj14n5Akcen8LQ56S 61HfSdSbx7lukpm+JKCiLrEJQZXhPlophfsOYoK1TKjYnE8ysGTzMSXrw6EVPLaUMt4z 7aNjTnye33WjIAPMq8hHAoVMusDemKpSrSjqkXXixKfnSrtYrqGVSJTe1Cw7FbBI6YxP lXwQ+nhj9R5zFAV4lQ1cpzcSD1GaShcMYcJcXrHTAoYd1ZqIK3PTM3Ejw4BIPiN+aoQ9 lBdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="jsD8/5DM"; 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 n6-20020a63b446000000b00553b54585eesi4797266pgu.245.2023.06.21.14.32.42; Wed, 21 Jun 2023 14:32: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="jsD8/5DM"; 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 S230326AbjFUUzW (ORCPT + 99 others); Wed, 21 Jun 2023 16:55:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbjFUUzL (ORCPT ); Wed, 21 Jun 2023 16:55:11 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 547481726; Wed, 21 Jun 2023 13:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687380910; x=1718916910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mm0RBRlxNTWUVWGSjZmJqXmc9M/wdroaapVIA3ESeqk=; b=jsD8/5DM0Cp7F4alo4nLh+MH6l0XIoysES4JgETtBGc5uqZU7pFYpfgR Ym9Ym6L9n3IktJBmB60BWdgWawIGDk9UiPlwe4ftjlMv36AK3u59AlYJg IkhSawkt6XVJAdnQ4+AQuniCGcIByR8GTZifmBPKPmD8WcSUc2KLai926 6EjQQhJR8kt11UnBVndqkfK3Y3oRvd0EjnLhDYpK0Dtu/8/WQB3nX9t3A 4Dqc5ZGbRqriWMoKFXnzJFQuu3Ptwutl3wIiblPPsJDKo3zRn7jlVtLbv T0zIP4obzdJxdg07K61w7GLGT6sCn4hAGFA7Q2VIXR6UlCTe9LG1GZxUY Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="359168936" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="359168936" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 13:55:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="827597919" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="827597919" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by fmsmga002.fm.intel.com with ESMTP; 21 Jun 2023 13:55:07 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, Jason Gunthorpe , "Lu Baolu" , Joerg Roedel , "Robin Murphy" , Jean-Philippe Brucker , dmaengine@vger.kernel.org, vkoul@kernel.org Cc: "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , rex.zhang@intel.com, xiaochen.shen@intel.com, narayan.ranganathan@intel.com, Jacob Pan Subject: [PATCH v9 4/7] iommu/vt-d: Remove pasid_mutex Date: Wed, 21 Jun 2023 13:59:44 -0700 Message-Id: <20230621205947.1327094-5-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230621205947.1327094-1-jacob.jun.pan@linux.intel.com> References: <20230621205947.1327094-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,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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. Reviewed-by: Jacob Pan Signed-off-by: Lu Baolu --- 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