Received: by 10.192.165.156 with SMTP id m28csp1076940imm; Wed, 11 Apr 2018 12:00:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+umx/giuv8du0rdPeIfCHDUlGY3AKIXOP5IIOO4ai648Vj/ehqaP6j/gqBBRUQXfJAHFVM X-Received: by 10.99.119.79 with SMTP id s76mr4199747pgc.291.1523473231577; Wed, 11 Apr 2018 12:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523473231; cv=none; d=google.com; s=arc-20160816; b=jZHndWSsqIqtOflxNToWa1hvoA1bdLfNCnp7oeETwY+sAW5qa9q00KayyhmuVanVaf cbBg2pxrdlkdYUFazNFwjwwJhXtoJ1YE26fZCjTodTPe1cehfhTGk1z0FJ/QXDc5nZA+ waVqXS5+zjF9c0zc52qnzWq9FkN6RTeLnO4M4bhNM4ApPsYnq/186XGQAm7nirnl2GsH Lp3QQxY9E6EENsD23unUIFEy5acapaKChJTaSU1ZtkH/iO2v34qQaMYrnM1mymG7GDfJ aIe6Edy0Wh0tdTBj5u+EoJ62rLrrZh7inyaLRcvCdszg1RigR6eon5u8lXp695I0vhgT XHYw== 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 :arc-authentication-results; bh=66WmHLqORCrwY/H3QC6vvMENFfReDDbHJ+haKQP8VG0=; b=NlFHjHtFXB0wI3TtMMJS+rIO/IxwRH+HVGKNDIJvRILy5me4zBIVg4N8lfY1hw6gmP yQf2Ty7ndTh42MeU7AgeEdNjv2OLq06BoXlOsB2si4R7oeyvERBD7UO7FE3BzXJxeFZ+ xJoJmy1oDiVTUtbYHkHY4/uHuFK7iD5zqRIegGuBTkgpyydBfY86sYO5R5sgFvdPQXfz DK4CvOHWDjIWxMYTlEUK/V193x4su0Sma6rEO/7zEXBdXVtgG+IcVd1MOwqEn+n8i+I9 DLAwTOQ5YOr9Pf2pSD7FoCvuuxtvVaN1M5zHbUKwT1RAesekPLWhOCvXoBipaTMnb1nx pnZA== ARC-Authentication-Results: i=1; mx.google.com; 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 p5-v6si1585116plk.421.2018.04.11.11.59.54; Wed, 11 Apr 2018 12:00:31 -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; 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 S933823AbeDKS4B (ORCPT + 99 others); Wed, 11 Apr 2018 14:56:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35628 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933012AbeDKSz4 (ORCPT ); Wed, 11 Apr 2018 14:55:56 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1BF7FCF7; Wed, 11 Apr 2018 18:55:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Paul Mackerras , Balbir Singh , Breno Leitao , Sasha Levin Subject: [PATCH 4.9 078/310] powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash Date: Wed, 11 Apr 2018 20:33:37 +0200 Message-Id: <20180411183625.658342181@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Ellerman [ Upstream commit e41e53cd4fe331d0d1f06f8e4ed7e2cc63ee2c34 ] virt_addr_valid() is supposed to tell you if it's OK to call virt_to_page() on an address. What this means in practice is that it should only return true for addresses in the linear mapping which are backed by a valid PFN. We are failing to properly check that the address is in the linear mapping, because virt_to_pfn() will return a valid looking PFN for more or less any address. That bug is actually caused by __pa(), used in virt_to_pfn(). eg: __pa(0xc000000000010000) = 0x10000 # Good __pa(0xd000000000010000) = 0x10000 # Bad! __pa(0x0000000000010000) = 0x10000 # Bad! This started happening after commit bdbc29c19b26 ("powerpc: Work around gcc miscompilation of __pa() on 64-bit") (Aug 2013), where we changed the definition of __pa() to work around a GCC bug. Prior to that we subtracted PAGE_OFFSET from the value passed to __pa(), meaning __pa() of a 0xd or 0x0 address would give you something bogus back. Until we can verify if that GCC bug is no longer an issue, or come up with another solution, this commit does the minimal fix to make virt_addr_valid() work, by explicitly checking that the address is in the linear mapping region. Fixes: bdbc29c19b26 ("powerpc: Work around gcc miscompilation of __pa() on 64-bit") Signed-off-by: Michael Ellerman Reviewed-by: Paul Mackerras Reviewed-by: Balbir Singh Tested-by: Breno Leitao Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/include/asm/page.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h @@ -132,7 +132,19 @@ extern long long virt_phys_offset; #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) + +#ifdef CONFIG_PPC_BOOK3S_64 +/* + * On hash the vmalloc and other regions alias to the kernel region when passed + * through __pa(), which virt_to_pfn() uses. That means virt_addr_valid() can + * return true for some vmalloc addresses, which is incorrect. So explicitly + * check that the address is in the kernel region. + */ +#define virt_addr_valid(kaddr) (REGION_ID(kaddr) == KERNEL_REGION_ID && \ + pfn_valid(virt_to_pfn(kaddr))) +#else #define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr)) +#endif /* * On Book-E parts we need __va to parse the device tree and we can't