Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp367764ybt; Fri, 26 Jun 2020 01:10:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz/XdS71L/dwgPjyeDaV5ivDcno+lZ5FIjw9SbQgMNnN9dRGOaGotcFD9t0DACb9FFpwnx X-Received: by 2002:a17:906:f752:: with SMTP id jp18mr1498587ejb.538.1593159039961; Fri, 26 Jun 2020 01:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593159039; cv=none; d=google.com; s=arc-20160816; b=enRPSfluxi0C3WzLsbibvZZNPoeXPsBXor2RVyECa/gv+8Yj8z1ToBvlxSDEYz5fjE UBPFE9/iq1KbubsBY+kjTYW9A0fl2v4pEir/XwoauOpu6szpOe15paEadkrTQdDFyhPa pFjoyr3MHc1k+D6TeWv3WsgA0dEPrdFiYexjnfvmjxQc6oSl7eR0TWzieLhjXfJbRX4D kE6fRnsd/DTh/Rh2I9dP2t3MR5AvRDaMtacMJ3TF++TRLHou8i0VrWbtfGQKjUVQVqP3 SpymI7FqjNOGvy8N8GJJr3xsbZXQurHhCkAgDyR8STiEqnQNHiRmT/e3m2nE1q+SzcXv aKtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qNIZyaqaFySnrL3JZhaWeAKsvECdPTQZDbsGwxG0as4=; b=ku4q4rEXoOOv8w6f8unxrLItdhqNwXv99oLQQuzNxsztFV98hCRSbtrHAIZ8lkWhB2 TyCOoYpl21tOspn9E8+YDn1IYG4SKBpGStsihAMG4wtIxnALnAcSYLjw1BqHY/RmaCP+ xAcTsJm9JvIIejsQXhz/JghDzvUUXFUcZsKfpJxhWzxEQbHi8bst1P9ZdYV3V6NPfbGr l5uueoo3w2J9rerc3fxM9KAcTieAMN0unTtser7ST6Jmfg5f8VrUwhFOj6joOti6IHwk Ny1hX6p0EHZ9rjc4CW7rVvWdhyjaYj0SYG8/NyaGyaGPaNiUSyrJukYfUNIw0Rz4XM+p JWRA== 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 a9si6022874ejx.271.2020.06.26.01.10.17; Fri, 26 Jun 2020 01:10:39 -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 S1729589AbgFZIIx (ORCPT + 99 others); Fri, 26 Jun 2020 04:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbgFZIFo (ORCPT ); Fri, 26 Jun 2020 04:05:44 -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 BC42AC08C5C1 for ; Fri, 26 Jun 2020 01:05:44 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id DBB1F3FA; Fri, 26 Jun 2020 10:05:41 +0200 (CEST) Date: Fri, 26 Jun 2020 10:05:40 +0200 From: Joerg Roedel To: Qian Cai Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Joerg Roedel Subject: Re: [PATCH 2/2] iommu/amd: Use 'unsigned long' for domain->pt_root Message-ID: <20200626080539.GP3701@8bytes.org> References: <20200625145227.4159-1-joro@8bytes.org> <20200625145227.4159-3-joro@8bytes.org> <20200625153720.GA1127@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625153720.GA1127@lca.pw> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Qian, On Thu, Jun 25, 2020 at 11:37:20AM -0400, Qian Cai wrote: > On Thu, Jun 25, 2020 at 04:52:27PM +0200, Joerg Roedel wrote: > > - u64 pt_root = atomic64_read(&domain->pt_root); > > + unsigned long pt_root = domain->pt_root; > > The pt_root might be reload later in case of register pressure where the > compiler decides to not store it as a stack variable, so it needs > smp_rmb() here to match to the smp_wmb() in > amd_iommu_domain_set_pt_root() to make the load visiable to all CPUs. > > Then, smp_rmb/wmb() wouldn't be able to deal with data races, so it > needs, > > unsigned long 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 +164,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); > > + domain->pt_root = root; > > WRITE_ONCE(domain->pt_root, root); Thanks for your review. I addressed your comments and will send an updated version shortly. Regards, Joerg