From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 147E0C49ED7 for ; Fri, 13 Sep 2019 15:11:49 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DDCE320640 for ; Fri, 13 Sep 2019 15:11:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="PHvftAxc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDCE320640 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lists.linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4E067C79; Fri, 13 Sep 2019 15:11:36 +0000 (UTC) Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 50B0C1000 for ; Fri, 13 Sep 2019 14:43:24 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id EF00283A for ; Fri, 13 Sep 2019 14:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1568385803; x=1599921803; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=dAPRT0+SGf/sdIMgQty1xpCF61uDMg145/u2nilLrYw=; b=PHvftAxcTMHd6CTpUwBwIsCfGMdx16tU5QP5FlviKU+rSQlz4+GGA8Kn TTpa4VXaKTmn0So7eLTkqWBup/GGYb1ZvSBDui0EJJ2PEIYc4TFIezlNc n1EHDpa5o/qfIU4EAD7wpcwvqe/xupSB26ityCHs4i2YnrG1loEtQ+Mdz 4=; X-IronPort-AV: E=Sophos;i="5.64,501,1559520000"; d="scan'208";a="831626034" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2b-a7fdc47a.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 13 Sep 2019 14:42:42 +0000 Received: from u793be3441f0353.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2b-a7fdc47a.us-west-2.amazon.com (Postfix) with ESMTPS id 85CF7C57F4; Fri, 13 Sep 2019 14:42:41 +0000 (UTC) Received: from u793be3441f0353.ant.amazon.com (localhost [127.0.0.1]) by u793be3441f0353.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTPS id x8DEgdaw021480 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 13 Sep 2019 16:42:39 +0200 Received: (from adulea@localhost) by u793be3441f0353.ant.amazon.com (8.15.2/8.15.2/Submit) id x8DEgd3W021479; Fri, 13 Sep 2019 16:42:39 +0200 To: Joerg Roedel Subject: [PATCH 2/4] iommu/amd: Fix downgrading default page-sizes in alloc_pte() Date: Fri, 13 Sep 2019 16:42:29 +0200 Message-Id: <20190913144231.21382-3-adulea@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190913144231.21382-1-adulea@amazon.de> References: <20190913144231.21382-1-adulea@amazon.de> X-Mailman-Approved-At: Fri, 13 Sep 2019 15:11:34 +0000 Cc: iommu@lists.linux-foundation.org, =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= , Andrei Dulea X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrei Dulea via iommu Reply-To: Andrei Dulea MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: iommu-bounces@lists.linux-foundation.org Errors-To: iommu-bounces@lists.linux-foundation.org Downgrading an existing large mapping to a mapping using smaller page-sizes works only for the mappings created with page-mode 7 (i.e. non-default page size). Treat large mappings created with page-mode 0 (i.e. default page size) like a non-present mapping and allow to overwrite it in alloc_pte(). While around, make sure that we flush the TLB only if we change an existing mapping, otherwise we might end up acting on garbage PTEs. Signed-off-by: Andrei Dulea --- drivers/iommu/amd_iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 138547446345..c7e28a8d25d1 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1490,6 +1490,7 @@ static u64 *alloc_pte(struct protection_domain *domain, pte_level = PM_PTE_LEVEL(__pte); if (!IOMMU_PTE_PRESENT(__pte) || + pte_level == PAGE_MODE_NONE || pte_level == PAGE_MODE_7_LEVEL) { page = (u64 *)get_zeroed_page(gfp); if (!page) @@ -1500,7 +1501,7 @@ static u64 *alloc_pte(struct protection_domain *domain, /* pte could have been changed somewhere. */ if (cmpxchg64(pte, __pte, __npte) != __pte) free_page((unsigned long)page); - else if (pte_level == PAGE_MODE_7_LEVEL) + else if (IOMMU_PTE_PRESENT(__pte)) domain->updated = true; continue; -- 2.17.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu