From patchwork Mon May 28 10:02:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 10430717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77443601BE for ; Mon, 28 May 2018 10:21:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AEC728C64 for ; Mon, 28 May 2018 10:21:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6934E28C7B; Mon, 28 May 2018 10:21:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDA3F28CA7 for ; Mon, 28 May 2018 10:21:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1400B6B0005; Mon, 28 May 2018 06:21:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 116086B0006; Mon, 28 May 2018 06:21:12 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02DE86B0007; Mon, 28 May 2018 06:21:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id B9B286B0005 for ; Mon, 28 May 2018 06:21:11 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id x21-v6so7130638pfn.23 for ; Mon, 28 May 2018 03:21:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:user-agent:mime-version; bh=vGWqpLdcEyD6hH1DQM8HaYuHlxl4VLr+fdjCPIRfVpk=; b=tHgyaqts9G5jjaxdK6ZKeUziwo6BDADGzWzFBiBgqhRbZoMU5sdQGjTosqPYIUoFSD fNWVdlEV4RC0ItylkkHHXhJmhH+ahwus+xnhYc8ty86gsEYo70QUlTEWixZ0n9G59V0L L0vgU+leAesIe1EZFV+1cwxIdmbbo2tT6ighlqBhaRYdeanOKKni/LgmKanQjjHsz4IY FSlsGWSDZ4ia3ZncyMd/P9wfiAhcoYZZJMiu/NYv4RKm3aofiKj4WPsIfCX+s1rNKy4K LWlcxsZ3zKIu3gdk74q3jKL+YWZAif4LBoc5M7jEhnzzqNUHJTwZ+lkbhFNxBTsuZdsX YE/A== X-Gm-Message-State: ALKqPwfDlU/7IdS/+/4oFi/pyna/mLPXqyAC8M67asXb8dnCa4GQWqIF A0zrbNB+9JR0YFr4zes5gd5A8ZBpwaSOzAvKHaJTAL94B16J1iJR9+pzRcrxcJEmurrY5nVr7Pc JcpBCvBvRlNH1T2kZSbcqdqz/lnQzlaZzrgVPpEbY9qjOAalbrzIN7y/VtBiZ21U= X-Received: by 2002:a63:b145:: with SMTP id g5-v6mr5384559pgp.164.1527502871410; Mon, 28 May 2018 03:21:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIg88pbrN1Ft4qzCEXRT5X/wJ6DQo7xGWalUJzc/6I/g7mSyIPa2dphVY53tlRJ91RP5M89 X-Received: by 2002:a63:b145:: with SMTP id g5-v6mr5384516pgp.164.1527502870461; Mon, 28 May 2018 03:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527502870; cv=none; d=google.com; s=arc-20160816; b=hQtBPO4zjPMP288tqtKJ/ttVpjK4B0GMX9PLRTXn4lWWQ8OZBx27STyXY9Fs6F7SLR c6iYj03aW6OzVd+f8wE6fRDK7BxoqvPjNKGdSc8TdauIdV4iUrXplkEvmZNULUnT11T2 6I91zPLQKrcoUD7aPD5+dUhFGcdjWQHcvf2dWslP90mQNrvgbfszHyyB3B1aUoptSeEh 52YoaJNdxJ+BnYpHHc7q5+i4rK2E+YOtGncLXKKgVUjHNPKnxkhJ3e625ljujXRmaKSn Whv1GeBUk2crHn06AEBQyO+3ub6T9JBMMHuu9V/WIL1HZVhcsz2JRjQym8Za+ZSH9uDK ULaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vGWqpLdcEyD6hH1DQM8HaYuHlxl4VLr+fdjCPIRfVpk=; b=nnpYwzIRdXXqMj1031DYHNc7m6wb3BewBddB2Z2YKWHGAzwtyHQDsQtzeSl3HZWMmV yo2h9chhS59nMGEnQTNsr7jF+7AUMX2PbvmtjWcFREyXgXPSPgzhtSb4JUJOOC0QXKtI TqbIVgGE72QG9//gZwZrE50qdsund4ZnrYCUhLKM99DopDC6/hkn1QHKElTIyieTWN+3 sOt5jcOYxIeeAHrKHob8o/q0jNzFC0h1LVGZRcgQoAiLSEmjZrQH+tZ1d9i1sD2bHT0n DMweVxZJLVPl1ePol8QMxTAHC+XwnCRrlcGGS62IU6jklg+SYZo9o+WxKHz7CDPW3LK7 cuPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JWaWvR83; spf=pass (google.com: domain of srs0=wbis=ip=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=SRS0=WbIs=IP=linuxfoundation.org=gregkh@kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id i62-v6si30081296pfg.218.2018.05.28.03.21.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 03:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of srs0=wbis=ip=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JWaWvR83; spf=pass (google.com: domain of srs0=wbis=ip=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=SRS0=WbIs=IP=linuxfoundation.org=gregkh@kernel.org 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 73FEF20843; Mon, 28 May 2018 10:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502870; bh=9Maw54E6GZEAzme/2V6NtCo85nVflZrcokR3Fslckc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWaWvR83Td6paJfGhF01rMTNZXRdzgMjtSS3+zzMcUVdaQIy+kQQTGgx81/6XJGud xo08V6NZ4x3Bq7mXlio1qs8f5wKZT5cU33NFTnh3ak/i5yb7OczXw+LIfWR/J88fqK Lf82mk8a+/AfsfFaZnfzCd2kKbDAUoATHu9MA95Y= 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.4 159/268] x86/pgtable: Dont set huge PUD/PMD on non-leaf entries Date: Mon, 28 May 2018 12:02:13 +0200 Message-Id: <20180528100220.420763245@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 4.4-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,5 +1,6 @@ #include #include +#include #include #include #include @@ -600,6 +601,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( @@ -628,6 +633,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(