Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1517185ybt; Thu, 25 Jun 2020 07:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKkqo5YuPraiVp9ByXsQ5V2UNeiwxDKyQ4Ba4HsrEKFlIOs64KA3X25LqlMTcD3yP3v7P8 X-Received: by 2002:a05:6402:1481:: with SMTP id e1mr32498239edv.113.1593096852872; Thu, 25 Jun 2020 07:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593096852; cv=none; d=google.com; s=arc-20160816; b=TdEk82OkUHPFuxhBQ5H3dwp4It+t4zs0Qib+8a78nNZ+b+4XFp87BRuSMrzUXWYjXN LWqJalTZpC5tVxe9p4hush0yjRo1rUknxfKAOQ2zLOZpiFyG7PWAOMzdoiocd46zxYWZ WU6dSJ2hlUn9UkgW0BFqppQcBtrQ1QPLaNbgT3JCcDqtsg1JWn9/oORnJufRsgcduaMr Rev/KqCYQ9nwkXo61UA6njFVxWGz8w4ks+NeW40sNctEk9cCkmlk2KbpXzbeaCp012TZ W6h9147JHkhMQowRhkU9oU+WjuW/IbDhbACkB244+anK10qTZDa+LQM36DjPF8PQ51Lq 1ykA== 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=0OZYIweTu8XDGCrRWXVgxkikuRlj8zOFvKA3oPLKrl4=; b=ngESHm4M6xif9KcqTI7zupwI7JJYIlc3lg3x6hU8v7xYUCVlHUJi51VrS8wofJgVAh tUyJCh8Jq4iwwKx8XKaQUqT1TtwM11Au4i8djUBcatbmwQsLsHbma5lGuCv8Tj/IUxXx YC7zZ1TdkRUnjaarPaoKNQLCDVZFw2yr4n4v+3Er24qyuBRuwtl/KiwFkyV3iFvM27iZ 3YbY26qImRKPYMJL6p9dQIpmggLnZdZpyyf8lpSMZVH7IPeTIUa2J85dDX33AmVhXGRG jug4QchRdxfPoOIURiwq8rkOCJL1V9TTzq7LqSoNF7Wy6SvL6qqRQbEbXBykS4lTIZq2 bh9w== 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 c9si716885ejb.631.2020.06.25.07.53.49; Thu, 25 Jun 2020 07:54:12 -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 S2405532AbgFYOwf (ORCPT + 99 others); Thu, 25 Jun 2020 10:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405463AbgFYOwb (ORCPT ); Thu, 25 Jun 2020 10:52:31 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43315C08C5DC for ; Thu, 25 Jun 2020 07:52:31 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 68DE8366; Thu, 25 Jun 2020 16:52:28 +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 1/2] iommu/amd: Add helper functions to update domain->pt_root Date: Thu, 25 Jun 2020 16:52:26 +0200 Message-Id: <20200625145227.4159-2-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200625145227.4159-1-joro@8bytes.org> References: <20200625145227.4159-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 Do not call atomic64_set() directly to update the domain page-table root and use two new helper functions. This makes it easier to implement additional work necessary when the page-table is updated. Signed-off-by: Joerg Roedel --- drivers/iommu/amd/iommu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 74cca1757172..5286ddcfc2f9 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -162,7 +162,18 @@ static void amd_iommu_domain_get_pgtable(struct protection_domain *domain, pgtable->mode = pt_root & 7; /* lowest 3 bits encode pgtable mode */ } -static u64 amd_iommu_domain_encode_pgtable(u64 *root, int mode) +static void amd_iommu_domain_set_pt_root(struct protection_domain *domain, u64 root) +{ + atomic64_set(&domain->pt_root, root); +} + +static void amd_iommu_domain_clr_pt_root(struct protection_domain *domain) +{ + amd_iommu_domain_set_pt_root(domain, 0); +} + +static void amd_iommu_domain_set_pgtable(struct protection_domain *domain, + u64 *root, int mode) { u64 pt_root; @@ -170,7 +181,7 @@ static u64 amd_iommu_domain_encode_pgtable(u64 *root, int mode) pt_root = mode & 7; pt_root |= (u64)root; - return pt_root; + amd_iommu_domain_set_pt_root(domain, pt_root); } static struct iommu_dev_data *alloc_dev_data(u16 devid) @@ -1410,7 +1421,7 @@ static bool increase_address_space(struct protection_domain *domain, struct domain_pgtable pgtable; unsigned long flags; bool ret = true; - u64 *pte, root; + u64 *pte; spin_lock_irqsave(&domain->lock, flags); @@ -1438,8 +1449,7 @@ static bool increase_address_space(struct protection_domain *domain, * Device Table needs to be updated and flushed before the new root can * be published. */ - root = amd_iommu_domain_encode_pgtable(pte, pgtable.mode); - atomic64_set(&domain->pt_root, root); + amd_iommu_domain_set_pgtable(domain, pte, pgtable.mode); ret = true; @@ -2319,7 +2329,7 @@ static void protection_domain_free(struct protection_domain *domain) domain_id_free(domain->id); amd_iommu_domain_get_pgtable(domain, &pgtable); - atomic64_set(&domain->pt_root, 0); + amd_iommu_domain_clr_pt_root(domain); free_pagetable(&pgtable); kfree(domain); @@ -2327,7 +2337,7 @@ static void protection_domain_free(struct protection_domain *domain) static int protection_domain_init(struct protection_domain *domain, int mode) { - u64 *pt_root = NULL, root; + u64 *pt_root = NULL; BUG_ON(mode < PAGE_MODE_NONE || mode > PAGE_MODE_6_LEVEL); @@ -2343,8 +2353,7 @@ static int protection_domain_init(struct protection_domain *domain, int mode) return -ENOMEM; } - root = amd_iommu_domain_encode_pgtable(pt_root, mode); - atomic64_set(&domain->pt_root, root); + amd_iommu_domain_set_pgtable(domain, pt_root, mode); return 0; } @@ -2713,8 +2722,8 @@ void amd_iommu_domain_direct_map(struct iommu_domain *dom) /* First save pgtable configuration*/ amd_iommu_domain_get_pgtable(domain, &pgtable); - /* Update data structure */ - atomic64_set(&domain->pt_root, 0); + /* Remove page-table from domain */ + amd_iommu_domain_clr_pt_root(domain); /* Make changes visible to IOMMUs */ update_domain(domain); -- 2.27.0