Received: by 10.192.165.156 with SMTP id m28csp1176262imm; Wed, 11 Apr 2018 13:57:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx48K6BoSA7fEEXLKQmYwkumuyFRjwIcqsImJ061ru34GNlwvHvnHNIVmmagoB0Fz/r6x+P+o X-Received: by 2002:a17:902:7c0e:: with SMTP id x14-v6mr4676363pll.392.1523480260000; Wed, 11 Apr 2018 13:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523480259; cv=none; d=google.com; s=arc-20160816; b=qnYaGLbfgHkLUcVaYAqENrNegQAH3IKGqMBwT00/+uJfjmw5NKPc/ZzNJvsmes4b2a fVRKf1aN4Hxea+x6tc+luLAe8VhZoqY6iatKjeAzQwPAuGTkR5LMeAIxe+YRd12g2170 T6ddkkHo1KAL0MUlh74KRRsmiDhnJ1A4UaNe57odQTeh9bxFVCucq9kv8ZRXcCXhmyRB Fj0EZFKqDbdoSQPBe++JEt5K1RSldv1ChUWUb4KWNrh85Ffksgl0oY2j400awl8Exw9X OjysSiPt+JV4GMsFgOkJhmP5ENP6MKpsQljP/Aq0D+ZbQ1/23XX5LIGDODavqKB27QDY gAIA== 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=h7aP7L1xvk/qvC04XbWoWLbF3RDl/gDdVcpFnEPaQC0=; b=wEibCZyt/QSEaDtzuYrUyCvWCQg5Xq7qzf/kUw+ICUMCdbE8/fAbBdeBcxxkSjcV4B hWbgI/C2MKPgP++cbQFkiIpGrFqpUqzajihjESUHssY9gGhJpcihyC9a0R4gfKLftErF PxGtPyphweeAH5qLZEdOxi2iPRQJG21sthDVvPWFzUUyXzFIXtt9o1zZ61PQFeA7mUPZ pq0idGKCMOSIGz3jNGQvqK47oFN3MYx+PGZRL3kgps0UDovHoqO0Cy1VsaH9BT4mto/Y BJeUn7DjIMfEOpyUeAYSiOydadxZ4oqKqeF+TZ6LYPa0I+J3o2E9Gk6Wwrk1ryl0c8mh b6uQ== 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 142si1221694pgg.29.2018.04.11.13.57.03; Wed, 11 Apr 2018 13:57:39 -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 S1755581AbeDKSpo (ORCPT + 99 others); Wed, 11 Apr 2018 14:45:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58662 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932321AbeDKSpk (ORCPT ); Wed, 11 Apr 2018 14:45:40 -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 46344CDA; Wed, 11 Apr 2018 18:45:39 +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.4 051/190] powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash Date: Wed, 11 Apr 2018 20:34:57 +0200 Message-Id: <20180411183553.284311483@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183550.114495991@linuxfoundation.org> References: <20180411183550.114495991@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.4-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