Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp264783ybi; Thu, 13 Jun 2019 15:39:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0nE5AkOWblQvZfO+8GqAXpD5hmefyhlQVEkBmgaHAHbYzw4iioFmjbLQLwmgu9plpOif0 X-Received: by 2002:a63:5d25:: with SMTP id r37mr31793163pgb.449.1560465590319; Thu, 13 Jun 2019 15:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560465590; cv=none; d=google.com; s=arc-20160816; b=Bj0EQeXE4FqUvUJ19tLo5Nvy5B/+9uc8MXkll1K0zLbmSSKTJ8YjA+6UcO8cPPkecA SoakT6wWdI3QNgZ85ZqPObJJ4ruevZ8+40glyCCiXnNxL1onJ1zCq89JdLWFHlxUkvyk nL3MxZet5YTWYYMtowVlizEB+XpIVG3ZDbcQhyBdtMi/vCEUYDEClbLuV1Qaca1MG7TH N4XWZkI3NS6AsuDBGVu2adfhWwNpclK1E5c1W5giSEAyP53oqx663pzwOJ6RhO8aHUFt gvvoz2l1ltIB8EgWwyKxJHughbkN+1m+YHCQ9nHyggOmiTDnH6XpyfhePhwsXwbAkTux 9FHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8su+LTkJ3gu2cKId6zqNGdio1nz4zdi4nwIHQT6LW2c=; b=Zl3ygR45ozYmu+VwZ20lZqGxVjzwK/nTKn9ri8Pvvb7l4CZS35V9S21bMLpZ+NwmJS NXPLE5i1dssIGbDFw8/SHK4kvU3+YsjiVF4BnimQ2XYb9ZwRUs31rTuHhdJaYccJvl7D 9X6JXBDU2C/ywti4F0NwphajzsywAaTke5OuOg4RAt6BXAgMG21H3Glt8eddcDc4tWCA H8VAr6eGLfLASr04SR56uH8fgaM5sQN7B0IlaHpJEVlnwknCQv9tqOEtlZo3fmkyqwjY F3J0z1MCFLhQqytb5+yuo3WIDdV6fT+gJA640v2rsypgHcSjDDV+oZhIduZ1cUakKn8g SWGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tcd-ie.20150623.gappssmtp.com header.s=20150623 header.b=JS+r5933; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i94si603646plb.255.2019.06.13.15.39.35; Thu, 13 Jun 2019 15:39:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@tcd-ie.20150623.gappssmtp.com header.s=20150623 header.b=JS+r5933; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727065AbfFMWjY (ORCPT + 99 others); Thu, 13 Jun 2019 18:39:24 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:42959 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfFMWjX (ORCPT ); Thu, 13 Jun 2019 18:39:23 -0400 Received: by mail-ed1-f68.google.com with SMTP id z25so481791edq.9 for ; Thu, 13 Jun 2019 15:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8su+LTkJ3gu2cKId6zqNGdio1nz4zdi4nwIHQT6LW2c=; b=JS+r5933+fWnWQ/iL9KFp6vvmc39vjWY4aRQgEQUu1LHWyJrIRUXht606UlZxnurzI KAZLXBy3sIe36V/9BqMsC+vFbmjMnVY97ZzJCtRgYx8mdzAE7wVffMFLBO6UqxUWabJz 0Hz+OFHE49MVr7p7JzNgIvA7ge1zMROlXfBGhix+41c3+QmSSkVaLXEUSaz7w2Anb43A p7ZG1gGsFVDTPk6FbKEwSNEUZ12beSwqVxE0k6szS1Aw+RC1JWhFHl1yrwzCSOaWKO0U RhQWM8WCkxOXdm2nnnmop1AtPe0bhW1GtbPyhmT0+gh/oNrPgb0xrnAUDwg81BqDyFwo RLVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8su+LTkJ3gu2cKId6zqNGdio1nz4zdi4nwIHQT6LW2c=; b=Mgd7CLj1mKUw/r3St73veHc5IME37YPGURgXCBYB1uIolGoc7z9US1hGx0K68XB3AG OTQ8c8N93m5m++OS2VOlRoOMg+++e8LATFgfBtSxR7ciyF3q+2v+e8wsLVrJQo/Xrt1m NTQ1qGMvAedty2pGm+l0TMVuQCM28WLiC8kztvGDYGfy0g4Wme11pHp7J2IBCsY/bbll 5j9vAPhVexrj02LdLQU7ChqvxI4MtBXFxYD4PIgmuqzuhJi+3zIxaNAbZtKdxeOtGwI+ zCaDdUgx+f+ZQOZAFojV1JFc5Ys27aY/dAzjYjwbmW/jDO35ax4bBb2WWNcmz7kdTkux ACCg== X-Gm-Message-State: APjAAAWxby5eo19dSipJuwTkMRKtaXmPWJXxy3CZxiA/1kkBjelMIB11 hKVflgx3BNMkUXG6MnyYOeDFVA== X-Received: by 2002:a17:906:32d2:: with SMTP id k18mr20071313ejk.232.1560465562018; Thu, 13 Jun 2019 15:39:22 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:a0:bc00:8042:d435:a754:1f22]) by smtp.googlemail.com with ESMTPSA id s16sm216522eji.27.2019.06.13.15.39.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 13 Jun 2019 15:39:21 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Cc: Tom Murphy , Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Andy Gross , David Brown , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer , Thierry Reding , Jonathan Hunter , Jean-Philippe Brucker , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 1/5] iommu/amd: Remove unnecessary locking from AMD iommu driver Date: Thu, 13 Jun 2019 23:38:56 +0100 Message-Id: <20190613223901.9523-2-murphyt7@tcd.ie> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190613223901.9523-1-murphyt7@tcd.ie> References: <20190613223901.9523-1-murphyt7@tcd.ie> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can remove the mutex lock from amd_iommu_map and amd_iommu_unmap. iommu_map doesn’t lock while mapping and so no two calls should touch the same iova range. The AMD driver already handles the page table page allocations without locks so we can safely remove the locks. Signed-off-by: Tom Murphy --- drivers/iommu/amd_iommu.c | 10 +--------- drivers/iommu/amd_iommu_types.h | 1 - 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 73740b969e62..065639e090fe 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2858,7 +2858,6 @@ static void protection_domain_free(struct protection_domain *domain) static int protection_domain_init(struct protection_domain *domain) { spin_lock_init(&domain->lock); - mutex_init(&domain->api_lock); domain->id = domain_id_alloc(); if (!domain->id) return -ENOMEM; @@ -3045,9 +3044,7 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, if (iommu_prot & IOMMU_WRITE) prot |= IOMMU_PROT_IW; - mutex_lock(&domain->api_lock); ret = iommu_map_page(domain, iova, paddr, page_size, prot, GFP_KERNEL); - mutex_unlock(&domain->api_lock); domain_flush_np_cache(domain, iova, page_size); @@ -3058,16 +3055,11 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, size_t page_size) { struct protection_domain *domain = to_pdomain(dom); - size_t unmap_size; if (domain->mode == PAGE_MODE_NONE) return 0; - mutex_lock(&domain->api_lock); - unmap_size = iommu_unmap_page(domain, iova, page_size); - mutex_unlock(&domain->api_lock); - - return unmap_size; + return iommu_unmap_page(domain, iova, page_size); } static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom, diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 52c35d557fad..5d5f5d009b19 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -461,7 +461,6 @@ struct protection_domain { struct iommu_domain domain; /* generic domain handle used by iommu core code */ spinlock_t lock; /* mostly used to lock the page table*/ - struct mutex api_lock; /* protect page tables in the iommu-api path */ u16 id; /* the domain id written to the device table */ int mode; /* paging mode (0-6 levels) */ u64 *pt_root; /* page table root pointer */ -- 2.20.1