Received: by 10.213.65.68 with SMTP id h4csp1886067imn; Mon, 19 Mar 2018 16:23:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELtlof14hiRKIdFTbCtUGn4XAFndWdLIQgZ11vuy/F8GMAC1IRhpo+7gkmT6991y8plZzVwU X-Received: by 10.98.20.143 with SMTP id 137mr131193pfu.78.1521501811747; Mon, 19 Mar 2018 16:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521501811; cv=none; d=google.com; s=arc-20160816; b=DO7xgbQ/8pFvWyhqUn1GRoeOnmqVgCNSOEBgx2LykFDXPNdlpHV46k12rt5RTTtJcR AgewHZ2e+LNGh3NHU4h7pK4Ky8l3DA6pfdjzDb9nsKe7IJpClru0GQ/tP/J3uvfehIHq xnevZ9aXveDVjv5Gk35ledNjxtazeZ5cdNbxssWeGBSEAgKXpt/8VlUJBOCqO7H4dgIh tjRUVHAt3NlclaQvAbyaAiL5moJFg9/KJqqXLsVfaNPF9ewiILMyHWxwurH+AA7HHeJm VL2q9DWFDpBSWHsxFC+oCXGYC2oj6wm9VU9BG9mAL4WegSEXm5a956dBj6VhKTDZalUn eEXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=hfS62gyul6WdcBB++E5YlGeU8tCEHXeeCwU3Nqx8aT8=; b=suc2Fr3of8SwVEfichvP81kqwIIyrGeUHLfs5K83HRpeQXtBgNqWUBQf3xcaQn09UZ rhWCb3ncqyXMKpOiydTwo3Lm6KxbR5XXvIEZyi6Ar6UBaYWPeV3S4tFdv+9vt0LFmUKK dPfHQ87CM65wvJ13lVXJ7CbXHntkotbn/acsrhhSuW/J9ePqG7nF4TBXp0FgONJry1Qd sK0WCkaRIB0v+BOeFjVa64CsM7TzuA/LdxEyKRUO42YrmDjEfgY1Un3NW80qYVIHmG2e 0GWctk1IacR9eC3vdCCqIWQgYP1Sd0+gf3rjDpCWu+NF6m6RN1sA8E/q7FXDxcmrcJdB lMgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=nP6CyGjm; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n7si230186pfj.58.2018.03.19.16.23.16; Mon, 19 Mar 2018 16:23: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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=nP6CyGjm; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966369AbeCSQIx (ORCPT + 99 others); Mon, 19 Mar 2018 12:08:53 -0400 Received: from mail-by2nam01on0120.outbound.protection.outlook.com ([104.47.34.120]:3328 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966289AbeCSQI1 (ORCPT ); Mon, 19 Mar 2018 12:08:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=hfS62gyul6WdcBB++E5YlGeU8tCEHXeeCwU3Nqx8aT8=; b=nP6CyGjm8ZcY8ff5yppG8+AUQ9eTqiRLc3jT4l61Uzo5FVQHNGdt/lG7P31d8+cJ8wu+6c/8QUkbXFBYdIPiuM+EdDLTsp7AX/tInUZLgN8u0xcSWL0qxFkkwsUH3YRvUX7enDK2s2RW90b8ahEUn+1YMeaWUW4at3NC0Gv0rsw= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1094.namprd21.prod.outlook.com (52.132.130.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 16:08:19 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:08:19 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 052/167] powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash Thread-Topic: [PATCH AUTOSEL for 4.4 052/167] powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash Thread-Index: AQHTv5w7aRmllRoGc0q9j8Avm4a2eg== Date: Mon, 19 Mar 2018 16:06:25 +0000 Message-ID: <20180319160513.16384-52-alexander.levin@microsoft.com> References: <20180319160513.16384-1-alexander.levin@microsoft.com> In-Reply-To: <20180319160513.16384-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1094;7:aSqSTqZw62IWcdQbAuLQXrCuWiPvKj5XJWcRTSgBKuouTnveREZx8ba+2ETfAU9Ey4PlnrxMWVg90TZGFd9iP3frJ26WoATkm1EiCxqUPPLcWThfo7Ww0kPoN8w0GR6NQbAju+eDq9fwuj5ygpkehJB9SBqi0D6zzISmS0EnqraayYBIiyiAKXcTA5agnU3ToE9RSdOm4HUUG+HxTLEYJlqJEeKL9aaeEeRBJJl5blCMvd1qsMmhR+VAOiba1GnJ;20:p0N8s7+50qqrXwwDwjXcI1WIeayB1ZgX26k9eMnygJoBcX8gAflxCXHNX+Tj/lawSVO4In8xH5MusDfYi4pm4WKG+yVqFUnNsGFCGQ3KxPImatHccxSQNSHzIJ4pPmhyxB3O0mEygnlDDmG3LQcaYkKiCD/RAzMBtogMbjIRuv8= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 1c1eb90b-6ae4-42ff-4cac-08d58db3a1f3 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1094; x-ms-traffictypediagnostic: DM5PR2101MB1094: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB1094;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1094; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(366004)(396003)(376002)(39380400002)(199004)(189003)(106356001)(10290500003)(110136005)(22452003)(3280700002)(478600001)(6666003)(54906003)(2906002)(2900100001)(2950100002)(10090500001)(186003)(26005)(97736004)(5660300001)(72206003)(66066001)(107886003)(102836004)(53936002)(59450400001)(6506007)(6512007)(316002)(7736002)(305945005)(1076002)(6436002)(36756003)(3846002)(6116002)(6486002)(105586002)(8676002)(8936002)(86612001)(68736007)(3660700001)(86362001)(575784001)(81166006)(81156014)(25786009)(2501003)(4326008)(76176011)(5250100002)(14454004)(99286004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1094;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: uLCYFc++3YYs0VKBsVGjvZMgccm+Mc8VXcmbxnupOwHam1T3tK89DQ1VQSOdNMbyeI5X43GKyJkk8MgkU6ZLuTdoS7fY9w03pvLHw79l4N8LKzJnuXVEvn+DD3E5HTpcgfds/mMJUbdJ60E/CjGD0TEB6+8oMSln9xQ2pNKj8uSIKfT2OWm/vDQIYSlr8P+ukcFzUCK7lkgy6lXE8bnpYIdkt+PTpZ9Paw91PDHbw0zDk48Rr1F6OBTP882EvMrw33NCEicX+JUEB/LFLgUAOHqpI2a6nuwdqCHnLm9hblYxup4UyR/4SwDhbUXdWejfMUP5eBNa8LViUSf8uyEvJQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c1eb90b-6ae4-42ff-4cac-08d58db3a1f3 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:06:25.8614 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1094 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) =3D 0x10000 # Good __pa(0xd000000000010000) =3D 0x10000 # Bad! __pa(0x0000000000010000) =3D 0x10000 # Bad! This started happening after commit bdbc29c19b26 ("powerpc: Work around gcc miscompilation of __pa() on 64-bit") (Aug 2013), where we changed the defin= ition 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 gi= ve 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 regi= on. 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 --- arch/powerpc/include/asm/page.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/pag= e.h index 3140c19c448c..70b379ee6b7e 100644 --- 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 p= assed + * through __pa(), which virt_to_pfn() uses. That means virt_addr_valid() = can + * return true for some vmalloc addresses, which is incorrect. So explicit= ly + * check that the address is in the kernel region. + */ +#define virt_addr_valid(kaddr) (REGION_ID(kaddr) =3D=3D KERNEL_REGION_ID &= & \ + pfn_valid(virt_to_pfn(kaddr))) +#else #define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr)) +#endif =20 /* * On Book-E parts we need __va to parse the device tree and we can't --=20 2.14.1