Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3054056imm; Sun, 1 Jul 2018 11:09:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ0l1QX76McFYxyNnDwW0rhUDz/wOibjsmEJz5j7wYYsPJ87VDae66FDpB7bYukoY209VaE X-Received: by 2002:a65:6094:: with SMTP id t20-v6mr19494198pgu.264.1530468597328; Sun, 01 Jul 2018 11:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468597; cv=none; d=google.com; s=arc-20160816; b=hGJycetMV5DfNGSqLMlEG9HECbK+MLiyAj8843xlrJSKD1EuNMpmR6coOGF5oS74s5 53UXsjl2+EmDPMJ9L1tV3oRta8SxS0V8xsdf7UjcPAfgbZaVOO9ozu58480oZQ8lOkcZ 6ju0AAHdixP5sXI5oEWfKJlmQNO4Gj/NgPuIsXGOOjDI1sS0caYOh9TWy8Y0Key4cKja TPbsS3S837NWqWhqwu6BCHjCgThkEzVvupiSwnWggHFpETU3s7P03oolfTr7bsbGF/7d viOQlC+WWcp6vB+ZrmDy8zb+6+JMA7MJUXitYimfWisJuE3xdJCUst1JslGC9KjIA2PJ F5Qg== 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=/OacTAUGeSixib2cf5tRjK6H8LyzZMCdyYqWW5DDYX4=; b=riAt6rJepyAcxpfamIvjieO1c3PZNAGranaWG6KKJnzuFPCw1Be7EMh6I/uNqQTF9L GHvcaPT/CCiaNc/NZKJAYsprbam4YOsrvrmFIsktGtL8ZgpFJaZoWbZzCVFiW27XaFC4 rTlcp0fMvA/8pOVSM6zZq8q1L3ne1UJdhXDhq2KUgHbcvh/ly/fcSgffZQMc8PwZ1e1c nJ6dgtjH2Pz1i0lDGAv/XDmdovReMCNAiptznwJpSJEM7J4zZSGfUXfzW+OP9OGJpgDF NJKlCZVZK793384kridOgfDbuYdRLXnIMco7+1HZ9QWZlXf+8tTQeeR9WQDvMLaLHVgk 97nA== 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 n187-v6si13002483pgn.368.2018.07.01.11.09.42; Sun, 01 Jul 2018 11:09:57 -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 S1753595AbeGASIc (ORCPT + 99 others); Sun, 1 Jul 2018 14:08:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34300 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964962AbeGAQ2V (ORCPT ); Sun, 1 Jul 2018 12:28:21 -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 40896ACD; Sun, 1 Jul 2018 16:28:21 +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.9 091/101] mm: fix devmem_is_allowed() for sub-page System RAM intersections Date: Sun, 1 Jul 2018 18:22:17 +0200 Message-Id: <20180701160800.798439352@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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: 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 @@ -653,7 +653,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.