Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp367857ybt; Fri, 26 Jun 2020 01:10:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdFJXt0P10c3aoJQjMfILlGXlhPtTvsBoH5tbOhfU/C9tePgyWnXgVIb7wLu7GlA+pkKaE X-Received: by 2002:a17:906:2b52:: with SMTP id b18mr1579488ejg.158.1593159048416; Fri, 26 Jun 2020 01:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593159048; cv=none; d=google.com; s=arc-20160816; b=Ouj62Jol7jXcS2dmsmorjcC3Tyfm7Ktb46Th0NKbmcwRmeVdM2/Z89hXUwjY4/QqYw zFHR1kenVO2SKpNMuezgMS1MIKwS3OaynZt8lnx1v68zLhe7ogYvMc0zSZz5eePsTFcB /lF0xS51OQ/JMvktl4xTEZDQMr/i+wDoD5BDItw32cf3X/lyFSsVn8a3rIN2bQttVFfT Q1H2c7qoqxevTugRcfkpNkY2Z+8gThACNo2yGfU1q1m6FvoF5Pt4TEm6MDn/QYCXkupR CyILEvzf7AD5hH/b0vQhEBrWpMYzu+17LesnabcKh099/DO09vj3A8AAtvB29ELZdcNz KXBA== 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; bh=+KYevLuLr7wx7Ax6SyJh9OWqCmm2lYGASZWW07H6kPs=; b=bdpi+ifRbl4g08B5yRwumZXTYvcRzX8tadaTnQUyJ4wvZJrVdd1uXZpXN0SnO6FJks ymeYGBDPrLLSYQhaHgr3VnhC07Iu3czrDfeYUTDK7usOMIal49zFx/zshx16mcEBisCQ aibi0Q/o038VNUb/93ZQ/wvCiOolq1cHHC70FGNJXbo4KgavbsHG1FxcT0h5lqWrIreV 3a/rzPFg1viOy96iaw1W4NRkXoeAybRSDbQdDOQvRT3/lM8IClWJAkAKntWKchlIFYeZ QSgbAK1eFzATSlG290kglUGOKidatiPajQrvUCyEV1h3DJ7OMO7cCucpIsYTLtl9exfv tdCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si4102329edd.139.2020.06.26.01.10.25; Fri, 26 Jun 2020 01:10:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729556AbgFZIId (ORCPT + 99 others); Fri, 26 Jun 2020 04:08:33 -0400 Received: from 8bytes.org ([81.169.241.247]:50198 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729146AbgFZIFt (ORCPT ); Fri, 26 Jun 2020 04:05:49 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 904D945B; Fri, 26 Jun 2020 10:05:48 +0200 (CEST) From: Joerg Roedel To: Joerg Roedel Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Qian Cai , Joerg Roedel Subject: [PATCH v2 2/2] iommu/amd: Use 'unsigned long' for domain->pt_root Date: Fri, 26 Jun 2020 10:05:47 +0200 Message-Id: <20200626080547.24865-3-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626080547.24865-1-joro@8bytes.org> References: <20200626080547.24865-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Using atomic64_t can be quite expensive, so use unsigned long instead. This is safe because the write becomes visible atomically. Signed-off-by: Joerg Roedel --- drivers/iommu/amd/amd_iommu_types.h | 2 +- drivers/iommu/amd/iommu.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 30a5d412255a..f6f102282dda 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -468,7 +468,7 @@ struct protection_domain { iommu core code */ spinlock_t lock; /* mostly used to lock the page table*/ u16 id; /* the domain id written to the device table */ - atomic64_t pt_root; /* pgtable root and pgtable mode */ + unsigned long pt_root; /* pgtable root and pgtable mode */ int glx; /* Number of levels for GCR3 table */ u64 *gcr3_tbl; /* Guest CR3 table */ unsigned long flags; /* flags to find out type of domain */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 5286ddcfc2f9..aec585f47646 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -156,7 +156,12 @@ static struct protection_domain *to_pdomain(struct iommu_domain *dom) static void amd_iommu_domain_get_pgtable(struct protection_domain *domain, struct domain_pgtable *pgtable) { - u64 pt_root = atomic64_read(&domain->pt_root); + unsigned long pt_root; + + /* Match the barrier in amd_iommu_domain_set_pt_root() */ + smp_rmb(); + + pt_root = READ_ONCE(domain->pt_root); pgtable->root = (u64 *)(pt_root & PAGE_MASK); pgtable->mode = pt_root & 7; /* lowest 3 bits encode pgtable mode */ @@ -164,7 +169,13 @@ static void amd_iommu_domain_get_pgtable(struct protection_domain *domain, static void amd_iommu_domain_set_pt_root(struct protection_domain *domain, u64 root) { - atomic64_set(&domain->pt_root, root); + WRITE_ONCE(domain->pt_root, root); + + /* + * The new value needs to be gobally visible in case pt_root gets + * cleared, so that the page-table can be safely freed. + */ + smp_wmb(); } static void amd_iommu_domain_clr_pt_root(struct protection_domain *domain) -- 2.27.0