Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2989506imm; Sun, 1 Jul 2018 09:49:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdfnAWTgJu6hJVP9L7cd2e5qxeyegkq1tIvQo9/OEYdyug6N17wBJ17uPzGER+ityVIhxTo X-Received: by 2002:a62:859c:: with SMTP id m28-v6mr22215620pfk.42.1530463762378; Sun, 01 Jul 2018 09:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530463762; cv=none; d=google.com; s=arc-20160816; b=zmAA+AWjpLRnsX7aZRlFU/Uy9X7y40uoDxtJ8xwplDKbx2Jib+cFDlLS3lOkfAXCif mo5/Hj8TF9qqgM46rI3huan6Im4M07h9mFje/wrnuo7Uuy3VUIIjoz3JUWVpfKkFAy35 mJYsr4RAg3oSEIK47inKCukNdQNOIB4Eu07yyFC4Of38l151Gy8FxsYyrWd9U6RGcNNF pSy9rbB3fZlrd84rICunPeg7uTxUvLOb2LbxDjv6hl+K+7kaRhp95i9Fc/UkBbidng6g sezFlXU9YSR+M+nS+NenJ9SU2La9AmX5AQrz9fpgWROteHnqaay009P1xXz7B7Lq15wO zFOw== 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=EA3heWh+nm9ur03VJOF8Ma6maHnNr6GN40uxPogfq5M=; b=HUXzV+sVrImBf4C4BeTvLknLSMkoaP5t2pszp7N2XEbql20PClamRFCtovwsKmD2Uu pMcc/ja4pAs9ioLEyfDiALYHlDsuZlLas0ZlxlrrihNlCXWnHUlnhejAaJImbgwBRRCL PQ6YJKo+Clu5WzeszbYhQVTofDceTnllrePSQNJ4N+l9m1G+KHvVngPuSiSP6kE7rQpI SGGFhidN0LS/xGF/hzrDKCxU+hm87Cj/SiuBXH9BV//qc4eh/Fdjd4zKMxZUZC9M2sZW MEqpdh2lkPizEBkyxtT2ctidyRYFITX02LhFm5rLazoJ9QQ5HqRongnHtw3HeGxoyQak lwtw== 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 e98-v6si14303348plb.150.2018.07.01.09.49.08; Sun, 01 Jul 2018 09:49:22 -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 S1032599AbeGAQrD (ORCPT + 99 others); Sun, 1 Jul 2018 12:47:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38586 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032581AbeGAQq6 (ORCPT ); Sun, 1 Jul 2018 12:46:58 -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 9EC5AA73; Sun, 1 Jul 2018 16:46:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams , Hussam Al-Tayeb , Christoph Hellwig , Andrew Morton , Linus Torvalds Subject: [PATCH 4.17 191/220] mm: fix devmem_is_allowed() for sub-page System RAM intersections Date: Sun, 1 Jul 2018 18:23:35 +0200 Message-Id: <20180701160916.175926902@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@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.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 2bdce74412c249ac01dfe36b6b0043ffd7a5361e upstream. Hussam reports: I was poking around and for no real reason, I did cat /dev/mem and strings /dev/mem. Then I saw the following warning in dmesg. I saved it and rebooted immediately. memremap attempted on mixed range 0x000000000009c000 size: 0x1000 ------------[ cut here ]------------ WARNING: CPU: 0 PID: 11810 at kernel/memremap.c:98 memremap+0x104/0x170 [..] Call Trace: xlate_dev_mem_ptr+0x25/0x40 read_mem+0x89/0x1a0 __vfs_read+0x36/0x170 The memremap() implementation checks for attempts to remap System RAM with MEMREMAP_WB and instead redirects those mapping attempts to the linear map. However, that only works if the physical address range being remapped is page aligned. In low memory we have situations like the following: 00000000-00000fff : Reserved 00001000-0009fbff : System RAM 0009fc00-0009ffff : Reserved ...where System RAM intersects Reserved ranges on a sub-page page granularity. Given that devmem_is_allowed() special cases any attempt to map System RAM in the first 1MB of memory, replace page_is_ram() with the more precise region_intersects() to trap attempts to map disallowed ranges. Link: https://bugzilla.kernel.org/show_bug.cgi?id=199999 Link: http://lkml.kernel.org/r/152856436164.18127.2847888121707136898.stgit@dwillia2-desk3.amr.corp.intel.com Fixes: 92281dee825f ("arch: introduce memremap()") Signed-off-by: Dan Williams Reported-by: Hussam Al-Tayeb Tested-by: Hussam Al-Tayeb Cc: Christoph Hellwig Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -706,7 +706,9 @@ void __init init_mem_mapping(void) */ int devmem_is_allowed(unsigned long pagenr) { - if (page_is_ram(pagenr)) { + if (region_intersects(PFN_PHYS(pagenr), PAGE_SIZE, + IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) + != REGION_DISJOINT) { /* * For disallowed memory regions in the low 1MB range, * request that the page be shown as all zeros.