Received: by 10.192.165.148 with SMTP id m20csp2528119imm; Thu, 26 Apr 2018 12:32:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+cNgYduCdyaVQ01hnDtLNs/5XEnVTeDBlUwUeSAUywrlfpHotW+eKJQrOxBJEuz9fFQpu1 X-Received: by 2002:a17:902:a50f:: with SMTP id s15-v6mr36076004plq.175.1524771170155; Thu, 26 Apr 2018 12:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524771170; cv=none; d=google.com; s=arc-20160816; b=VaOA9zztskG8oC0nOjEW815TSNneuUkzYsckdBbzfldshWFHKqvw0FrqqVAbutANsK ENUQcTc1dkmJpVsx5koMn0PX97P2YX9A/ZtTSWMib2wsew8xF+SLC7eZL6uFCDceRow2 1w6Q+UlrLAzb/vzRMzbT+UQ6KC+rAJRycIAMzh8nPTwVh8OB40ywFza7h3I9CPt33Go6 +KDyRM533qIz27HNwDU19+hLInykIpP0WMtbYmO1EgWXB6K4SGduUhL0lWUEOJ05SzGN 2Pcpub+ui0EVkMM+OTJNH7a3FPXCXInCxt0xsZWmPXWTBohVU+BZiLyANDnu2Fmp/usd p1fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:in-reply-to :message-id:cc:to:from:date:arc-authentication-results; bh=4f7Fvt2nEzHM402BEUpWHzxq+lWrEeYKEJX5lfvMnjM=; b=RiDNvDe8a38ta6Thle+WtFKoY20B5U86Z9MY8t4ZqZuJy4cx93PnfyciQT+y/ofTxQ A4rGhdYc3axSxe4XOMem2VrWuSwiFOY/y3qIiNYbNAIkORB1RJ1uvnAVoOn1hV8pMaBZ bCXgoTwOvlgNxnHIMlCldiqCf5qT1lZBTmB5/GsQFH55cyAI0EDmITaeiW0CZfzW69uv G9QI08IcuA/RJjbKb0K6T9ON6q1kHj0CIjt6UIC7uNo2mHaf4fzKEfvBNwBMuH7H9New sjHuGGMGW/wwMbJ9TIPHXJM9E9iemss8WCTljplebUBuLq/ij/CcrYvNL5z4K48gGD2k JJxQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b123si16264946pgc.14.2018.04.26.12.32.35; Thu, 26 Apr 2018 12:32:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753758AbeDZTb2 (ORCPT + 99 others); Thu, 26 Apr 2018 15:31:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57406 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751269AbeDZTb1 (ORCPT ); Thu, 26 Apr 2018 15:31:27 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 386DF4900F; Thu, 26 Apr 2018 19:31:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11477314EE70; Thu, 26 Apr 2018 19:31:27 +0000 (UTC) Received: from zmail24.collab.prod.int.phx2.redhat.com (zmail24.collab.prod.int.phx2.redhat.com [10.5.83.30]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CD2BB180215F; Thu, 26 Apr 2018 19:31:26 +0000 (UTC) Date: Thu, 26 Apr 2018 15:31:26 -0400 (EDT) From: Dave Anderson To: Linux Kernel Mailing List Cc: mingo@kernel.org, andi@firstfloor.org, keescook@chromium.org Message-ID: <823082096.24861749.1524771086176.JavaMail.zimbra@redhat.com> In-Reply-To: <981100282.24860394.1524770798522.JavaMail.zimbra@redhat.com> Subject: BUG: /proc/kcore does not export direct-mapped memory on arm64 (and presumably some other architectures) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.18.17.201, 10.4.195.19] Thread-Topic: /proc/kcore does not export direct-mapped memory on arm64 (and presumably some other architectures) Thread-Index: PMGTpZ8S7xqiuulvvGn4JbhIGYCG5Q== X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 26 Apr 2018 19:31:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While testing /proc/kcore as the live memory source for the crash utility, it fails on arm64. The failure on arm64 occurs because only the vmalloc/module space segments are exported in PT_LOAD segments, and it's missing all of the PT_LOAD segments for the generic unity-mapped regions of physical memory, as well as their associated vmemmap sections. The mapping of unity-mapped RAM segments in fs/proc/kcore.c is architecture-neutral, and after debugging it, I found this as the problem. For each chunk of physical memory, kcore_update_ram() calls walk_system_ram_range(), passing kclist_add_private() as a callback function to add the chunk to the kclist, and eventually leading to the creation of a PT_LOAD segment. kclist_add_private() does some verification of the memory region, but this one below is bogus for arm64: static int kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg) { ... [ cut ] ... ent->addr = (unsigned long)__va((pfn << PAGE_SHIFT)); ... [ cut ] ... /* Sanity check: Can happen in 32bit arch...maybe */ if (ent->addr < (unsigned long) __va(0)) goto free_out; And that's because __va(0) is a bogus check for arm64. It is checking whether the ent->addr value is less than the lowest possible unity-mapped address. But "0" should not be used as a physical address on arm64; the lowest legitimate physical address for this __va() check would be the arm64 PHYS_OFFSET, or memstart_addr: Here's the arm64 __va() and PHYS_OFFSET: #define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x))) #define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET) | PAGE_OFFSET) extern s64 memstart_addr; /* PHYS_OFFSET - the physical address of the start of memory. */ #define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; }) If PHYS_OFFSET/memstart_addr is anything other than 0 (it is 0x4000000000 on my test system), the __va(0) calculation goes negative and creates a bogus, very large, virtual address. And since the ent->addr virtual address is less than bogus __va(0) address, the test fails, and the memory chunk is rejected. Looking at the kernel sources, it seems that this would affect other architectures as well, i.e., the ones whose __va() is not a simple addition of the physical address with PAGE_OFFSET. Anyway, I don't know what the best approach for an architecture-neutral fix would be in this case. So I figured I'd throw it out to you guys for some ideas. Dave Anderson