Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2308072imm; Mon, 28 May 2018 05:49:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpnS8p5nkQpf7g13ja8Xm9iuWjgCcqsayvUd9uUiQae+wimoR7xupt20KCBd0u2VP3X69+j X-Received: by 2002:a17:902:145:: with SMTP id 63-v6mr13591304plb.332.1527511758730; Mon, 28 May 2018 05:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527511758; cv=none; d=google.com; s=arc-20160816; b=O0CWALLiLF3TamSCgceVvLMCEy1bNzdphayzEV7I+CO7mf2AO7+EILkp5r6YCGgjaU a1ssav6PTfyksT0eI7m7xrTkVvpyMz4jKjKJxdz7T3MK8NU/PjBPTYPB9XdvHC4xc7Ys PwQ1nMojQzLgJAa5N4eCw58/5zwsE0VNsGk7LJmZUBCR4nN2yoYwGyPya+tLsJX9ikeM 7UAorK2GK30dXV+ouSFaHdKfnFzI4ZJmM0x27K3dRspA4BIw8tFs1Jy06CJa5oDrLTdq BO54jECjoQv/vX0k2wITt15HUdJ0OtcobRaIKFA/8pr+HrC/igsVcOvt5AIH4dL3foO/ JV0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=F1v7W+SAREZz1EEUFxsuItRYCdopgbS2HGCE4ziBDAA=; b=nVDfxwyxk99I9ZDaIZ0mGIcegyZsOioLJ3EbX6PVV8PlLczuXS3LvPm0Bj4dN3z/ix kDdwNjCgptkVjMdLxkh5Mn2oUttoUTx+NqeeY4q+FUoqLSf1HULt0YVk66jL7qSxcFYJ qlXIq7w9CcjtSckNuCilQ96uzJH046Tddi/xf/g5LCaMNbIjUyPl5AtjATV4hRoa/zf0 Q03O46e3+1/bhsqWikmX3ENffO2IGNnr0qLuPy/nCFSR+k7XufhGQFYdZFPA3qWw7dYN +W2/e9E7yQyn47FYZaMCCgCgla6VPZuc7CZED/5Wj74FCQ+phCNbjW3TVHqviOllyX30 DXnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jjPqTTlC; 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 z19-v6si29508075plo.174.2018.05.28.05.49.04; Mon, 28 May 2018 05:49:18 -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=jjPqTTlC; 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 S938962AbeE1MrI (ORCPT + 99 others); Mon, 28 May 2018 08:47:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:45476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937615AbeE1K5T (ORCPT ); Mon, 28 May 2018 06:57:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 9810A208A3; Mon, 28 May 2018 10:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505039; bh=vfhz3Knf4A+NO+zquM5/9eHOn0K+jQY7BaLzq/JsUCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjPqTTlCEHI7Ms3Wgtfh00UdrUDeG2DUigrK5ZSUxNBCuKuSyzcsyZ/6ujagTJ1yQ vojqaKQGRxWbwkl1t9bWwZ7SlxLgHNwQNBU9ZK5Q+efk7yFNkAoE9lvI8YcMzZsW43 VESy9hLjHAB7ksKJ3+j8rUlp864nHymn8oXGQhGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "David H. Gutteridge" , Joerg Roedel , Thomas Gleixner , Andrea Arcangeli , Andy Lutomirski , Boris Ostrovsky , Borislav Petkov , Brian Gerst , Dave Hansen , David Laight , Denys Vlasenko , Eduardo Valentin , Jiri Kosina , Josh Poimboeuf , Juergen Gross , Linus Torvalds , Pavel Machek , Peter Zijlstra , Waiman Long , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, linux-mm@kvack.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 322/496] x86/pgtable: Dont set huge PUD/PMD on non-leaf entries Date: Mon, 28 May 2018 12:01:47 +0200 Message-Id: <20180528100333.398599532@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joerg Roedel [ Upstream commit e3e288121408c3abeed5af60b87b95c847143845 ] The pmd_set_huge() and pud_set_huge() functions are used from the generic ioremap() code to establish large mappings where this is possible. But the generic ioremap() code does not check whether the PMD/PUD entries are already populated with a non-leaf entry, so that any page-table pages these entries point to will be lost. Further, on x86-32 with SHARED_KERNEL_PMD=0, this causes a BUG_ON() in vmalloc_sync_one() when PMD entries are synced from swapper_pg_dir to the current page-table. This happens because the PMD entry from swapper_pg_dir was promoted to a huge-page entry while the current PGD still contains the non-leaf entry. Because both entries are present and point to a different page, the BUG_ON() triggers. This was actually triggered with pti-x32 enabled in a KVM virtual machine by the graphics driver. A real and better fix for that would be to improve the page-table handling in the generic ioremap() code. But that is out-of-scope for this patch-set and left for later work. Reported-by: David H. Gutteridge Signed-off-by: Joerg Roedel Reviewed-by: Thomas Gleixner Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Boris Ostrovsky Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: David Laight Cc: Denys Vlasenko Cc: Eduardo Valentin Cc: Greg KH Cc: Jiri Kosina Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Pavel Machek Cc: Peter Zijlstra Cc: Waiman Long Cc: Will Deacon Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180411152437.GC15462@8bytes.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pgtable.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -636,6 +637,10 @@ int pud_set_huge(pud_t *pud, phys_addr_t (mtrr != MTRR_TYPE_WRBACK)) return 0; + /* Bail out if we are we on a populated non-leaf entry: */ + if (pud_present(*pud) && !pud_huge(*pud)) + return 0; + prot = pgprot_4k_2_large(prot); set_pte((pte_t *)pud, pfn_pte( @@ -664,6 +669,10 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t return 0; } + /* Bail out if we are we on a populated non-leaf entry: */ + if (pmd_present(*pmd) && !pmd_huge(*pmd)) + return 0; + prot = pgprot_4k_2_large(prot); set_pte((pte_t *)pmd, pfn_pte(