Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2077184ybp; Thu, 10 Oct 2019 01:46:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMFm76a9GyYIxrXFV+lMI3mb5NkSt6SSQKuv7Bdhjz8ifnRbZW+AxQZL67/5cG9DUH46CH X-Received: by 2002:a17:906:9487:: with SMTP id t7mr6971225ejx.231.1570697197851; Thu, 10 Oct 2019 01:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697197; cv=none; d=google.com; s=arc-20160816; b=0dvfJBOVNwXt4qVZKVD29kfxo7Q3jdaFAeLlO9VS894ZXZMJk4aU03tiqfh5qEAt0L wBCA46wVqYtcWedU8oNTBmtENAUBERGrAYf6rsXOAG9ZFZpBViBktm3gy6oqKXQew+Rd BvDe5CRLdg0yubYcE09uw+whDLgqYli7h7PwUdJ6eBOzL9uC0hdOObebIs8BQLMNdvCF YkzeYhtSTsCy18aLjxM9dkm9t3YaeAL2FYv6CV3Af8OEMHcrx39foT6kczuF2LN9HZLu 2FvUwpKR03jFV/E9ekPIBl1GS/YHux2bD+ck9uM07VtFwcYvoMjCY0NAcvU6Ofcr5dse rvKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cpVtuIzE+6SsbW1hkJ72hMJRpjeqoJ1i1VEHseR5mnw=; b=MSjH7wR6z3i2XHme3H6DXMVQO26RSC1KbWV/j4w8L4pM48j84CTn62C0UH4q9jNIX1 Ml2brSN7a5p1XPtFN/CvtrSI/I7HZPnt4lr57yW++w/1mS3+SwIdSIC/aLMpQQamEEmB wlVp1K4ifAEZFzUTlRyOk/s6RZcF4sBy/fP6QAvvfylmgP9iCl6rdmTctfeDb/G7VG+u CFdl3/9AApQCaAIfj0zbPC8zrfFEI/2k4X3cVfmE3anHke7b8mwdjlxk7bNPnak0J+CP rnvRIyhYqzwltL3GVRd5LwSvoFJ2ApteriJMKcgRzTexWAUOIIkRJMZnzeZ4DJ86XU7Z rcRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u7p1bUdH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si2994698ede.268.2019.10.10.01.46.14; Thu, 10 Oct 2019 01:46:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u7p1bUdH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388605AbfJJImn (ORCPT + 99 others); Thu, 10 Oct 2019 04:42:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:47312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388593AbfJJIml (ORCPT ); Thu, 10 Oct 2019 04:42:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 91B6C2054F; Thu, 10 Oct 2019 08:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696961; bh=iWYDgRkJIH2M1HsFbcNkn3aCB9lB+OjRA7emx/q8cHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u7p1bUdHCh2jod6pOaXdQ4TEm6AW4KUp3PD9HCEUQVhPo/BepAed9qdnT3pR3srfu vYAdBl6xJL+3+Prl8GKmb6UHstWn2w51Q5ytykoZKmNkfpwMCiZ9i8vhkuOJI2je5Y BYAUzORliAQO1nhXoGfKz1dw2JNIxycnycLJLlEw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrei Dulea , Sasha Levin Subject: [PATCH 5.3 115/148] iommu/amd: Fix downgrading default page-sizes in alloc_pte() Date: Thu, 10 Oct 2019 10:36:16 +0200 Message-Id: <20191010083618.068607397@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Dulea [ Upstream commit 6ccb72f8374e17d60b58a7bfd5570496332c54e2 ] 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. Fixes: 6d568ef9a622 ("iommu/amd: Allow downgrading page-sizes in alloc_pte()") Signed-off-by: Andrei Dulea Signed-off-by: Sasha Levin --- 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 e1259429ded2f..3b1d7ae6f75e0 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.20.1