Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5926368ybe; Tue, 10 Sep 2019 10:52:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsnZjRt7C5phg8cmTxVNxzEwuLKI4oVCKq+G6cwQWMAPfZhWx3qJZq3bCH4dWCS7Y5tWI5 X-Received: by 2002:a50:e701:: with SMTP id a1mr26129479edn.108.1568137966627; Tue, 10 Sep 2019 10:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568137966; cv=none; d=google.com; s=arc-20160816; b=sZUwMxqcSQ3AwcUrocg3WLrBV4NqTY54OJkcawuzWpqtWlWiDMfOqGatzuuQbP9PDm VKpF1S0dFaETChelr6hGWr+WMG1DBsc31L5EdETsU0fl1Sx2q1Gnp1jS8LGrTLkdE1Ji vh9pOsy8NmpZHtQBTWAhiYw2PRSxxnyFWpbMYBJ9IxPR57Z+4ZJZeUb2x6JEvgQ6B6F6 t+1IbZNdk312WfH25bxXRgl3GpLRM3WWcEjk1ABivPvyGbRiGCzM1lFGbtgY1aTFS4/w AsCBBlbGmQF0BjVbeiAlPmlXO5ycYcyjiGZC6OrEI/UkiwZ0lk1+ycXF+ET2f8eyRUm9 HMrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=mJRW8lKwbthmLc8gotnL669qFNsjqI2ujReZHQn2tbQ=; b=wGBV2+emWIbUdnVOt4OswV4qOrPdbdr0pqEhBX8Lj2dYImgnR1Gt9ZmwIedF+AFFj9 Z1u10rPbkFxMlNmEEz/74e9LgAAxxRvWwh40NBTBm02BdTeuIPfyIW0dihVfbloWijxC x3Tttwe1Hu1o+8JwNlSuNz32AXj+FOjfYcvx3lwZdIqwDh1/ngKSGONmq0J7NIJwRBRJ BX/J+z5pXt6088mW8TEZ92dVZ9ZrFXoNIY3w58ALsWCi/oRMz+8nK2gQkzoxmrPICyBa evLQRmrWDNvKy/Svo4wPqOFIO4VL2Lh5CJ3v3G+f37ovFhoE9PzhXM/f9Kf3ORRnx9ax QD1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=DoXnPZpN; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a11si10156828edh.91.2019.09.10.10.52.22; Tue, 10 Sep 2019 10:52:46 -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=@amazon.de header.s=amazon201209 header.b=DoXnPZpN; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437222AbfIJRuI (ORCPT + 99 others); Tue, 10 Sep 2019 13:50:08 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:2144 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437206AbfIJRuH (ORCPT ); Tue, 10 Sep 2019 13:50:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1568137807; x=1599673807; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=mJRW8lKwbthmLc8gotnL669qFNsjqI2ujReZHQn2tbQ=; b=DoXnPZpNIxMywwVrYkhaMNy4d0RYKG92Ucsnfb8V4EBVu/0pYVQdILOu B8d1EWyOpqXFT6A0vgT7XzDbfp5ndlc9TdwJMEo3kPYmrT3L8IujbhESy CwI+7/c8az9dp8uPmLRb1XvrPdTC0b43r2YYDJBqmy+ufz6d7u8atjDHv 0=; X-IronPort-AV: E=Sophos;i="5.64,490,1559520000"; d="scan'208";a="701858197" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 10 Sep 2019 17:49:51 +0000 Received: from uf8b156e456a5587c9af4.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id 87B94A1EC9; Tue, 10 Sep 2019 17:49:48 +0000 (UTC) Received: from uf8b156e456a5587c9af4.ant.amazon.com (localhost [127.0.0.1]) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id x8AHnk7Z023845; Tue, 10 Sep 2019 19:49:46 +0200 Received: (from sironi@localhost) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Submit) id x8AHnkE6023839; Tue, 10 Sep 2019 19:49:46 +0200 From: Filippo Sironi To: sironi@amazon.de, joro@8bytes.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: Wei Wang Subject: [PATCH 5/5] iommu/amd: Hold the domain lock when calling domain_flush_tlb[_pde] Date: Tue, 10 Sep 2019 19:49:25 +0200 Message-Id: <1568137765-20278-6-git-send-email-sironi@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1568137765-20278-1-git-send-email-sironi@amazon.de> References: <1568137765-20278-1-git-send-email-sironi@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei Wang domain_flush_tlb[_pde] traverses the device list, which is protected by the domain lock. Signed-off-by: Wei Wang Signed-off-by: Filippo Sironi --- drivers/iommu/amd_iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 3714ae5ded31..f5df23acd1c7 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1806,7 +1806,11 @@ static void free_gcr3_table(struct protection_domain *domain) static void dma_ops_domain_flush_tlb(struct dma_ops_domain *dom) { + unsigned long flags; + + spin_lock_irqsave(&dom->domain.lock, flags); domain_flush_tlb(&dom->domain); + spin_unlock_irqrestore(&dom->domain.lock, flags); domain_flush_complete(&dom->domain); } @@ -2167,7 +2171,9 @@ static int attach_device(struct device *dev, * left the caches in the IOMMU dirty. So we have to flush * here to evict all dirty stuff. */ + spin_lock_irqsave(&domain->lock, flags); domain_flush_tlb_pde(domain); + spin_unlock_irqrestore(&domain->lock, flags); domain_flush_complete(domain); @@ -3245,8 +3251,11 @@ static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain, static void amd_iommu_flush_iotlb_all(struct iommu_domain *domain) { struct protection_domain *dom = to_pdomain(domain); + unsigned long flags; + spin_lock_irqsave(&dom->lock, flags); domain_flush_tlb_pde(dom); + spin_unlock_irqrestore(&dom->lock, flags); domain_flush_complete(dom); } -- 2.7.4