Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp511663pxb; Tue, 3 Nov 2020 05:38:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1wxVcb7M1tkIIQqReeXTkikL5wC8zjaBk5CYZaDKb/SWqUwQWLW8DEF0by9D7DjETqO6h X-Received: by 2002:aa7:cd56:: with SMTP id v22mr22477703edw.245.1604410730784; Tue, 03 Nov 2020 05:38:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604410730; cv=none; d=google.com; s=arc-20160816; b=Iby9fJlV50YYs1qeNZsIyo9n/pGJH9VSSnS/5o6G2rlscY8Rr3TS6E4EqQp63usg/w 6RuApM994ypQ7V2ZHAteDEklskBa9x9Nq5Rp5eVA1joB0ThClkhzlxmYpoqa/Iifrkr9 GCY29/+EcyOr4IoS9fL3Yt5D2kLKunLOo7YenkVY1XHW3YGAt0SwAMpQltazY+59D6qS rqK2c1l5OOcGh2nz/XKy80c7ftUalEb5Du6PZHCwZ0monVRTUdm7/f33xxoZFl6HRr6k uMe0Bt2MwDkpye0ezR+6t98gHC6GK73Jd3BQa2aeICAMTLl4K9NmsdFd6d/jXxojmqTl NHjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=nSg7w2Ivm/9wN+JWkBxwcrBDmAbCmV+3rjs8r/RSePQ=; b=oSAIyDjlTkA/+n6tRiSg8zkIuhqN5rcTv2xGDSaNeWIpeHfTIbJxEm1sV/kcVHoSMg 3b9JC0WLH5gPCAM9sCSTvAJ+n91UVOE4qOa5PImioGxgvtKe7cYMfC7ZVW7lkI5qGqH8 TaEZH2bBbYIFsMZakLm2+5SzZ1iy5ceI/c2dEP49JxoSohfuCErKjhixf8ndo+W+LgW0 J9hbsQ9O1sb1baCuWptwCJeOpQS2wTs7eqFKQF7yj92SPal3IJ0FYUWPNM4CYp4011pd WfBaTME24cLMzRmlRVb02lJqkbKafCKlHhb2BufFllKVUmVOI9iwXWdpCZdEnFHMzw1W igeA== 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 t2si13722754edj.427.2020.11.03.05.38.26; Tue, 03 Nov 2020 05:38:50 -0800 (PST) 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 S1729133AbgKCNfx (ORCPT + 99 others); Tue, 3 Nov 2020 08:35:53 -0500 Received: from 8bytes.org ([81.169.241.247]:39136 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727883AbgKCNfw (ORCPT ); Tue, 3 Nov 2020 08:35:52 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 7FD9A433; Tue, 3 Nov 2020 14:35:51 +0100 (CET) Date: Tue, 3 Nov 2020 14:35:50 +0100 From: Joerg Roedel To: Suravee Suthikulpanit Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Jon.Grimm@amd.com, brijesh.singh@amd.com Subject: Re: [PATCH] iommu/amd: Enforce 4k mapping for certain IOMMU data structures Message-ID: <20201103133549.GI22888@8bytes.org> References: <20201028231824.56504-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201028231824.56504-1-suravee.suthikulpanit@amd.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Suravee, On Wed, Oct 28, 2020 at 11:18:24PM +0000, Suravee Suthikulpanit wrote: > AMD IOMMU requires 4k-aligned pages for the event log, the PPR log, > and the completion wait write-back regions. However, when allocating > the pages, they could be part of large mapping (e.g. 2M) page. > This causes #PF due to the SNP RMP hardware enforces the check based > on the page level for these data structures. > > So, fix by calling set_memory_4k() on the allocated pages. > > Fixes: commit c69d89aff393 ("iommu/amd: Use 4K page for completion wait write-back semaphore") > Cc: Brijesh Singh > Signed-off-by: Suravee Suthikulpanit > --- > drivers/iommu/amd/init.c | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) > > diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c > index 82e4af8f09bb..75dc30226a7c 100644 > --- a/drivers/iommu/amd/init.c > +++ b/drivers/iommu/amd/init.c > @@ -29,6 +29,7 @@ > #include > #include > #include > +#include > > #include > > @@ -672,11 +673,22 @@ static void __init free_command_buffer(struct amd_iommu *iommu) > free_pages((unsigned long)iommu->cmd_buf, get_order(CMD_BUFFER_SIZE)); > } > > +static void *__init iommu_alloc_4k_pages(gfp_t gfp, size_t size) > +{ > + void *buf; > + int order = get_order(size); > + > + buf = (void *)__get_free_pages(gfp, order); > + if (!buf) > + return buf; > + return set_memory_4k((unsigned long)buf, (1 << order)) ? NULL : buf; > +} > + Please make the 4k split only if SNP is actually enabled in the system. Regards, Joerg