From patchwork Sat Nov 12 00:44:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 9423837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C9C46047D for ; Sat, 12 Nov 2016 00:47:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E3C129AB9 for ; Sat, 12 Nov 2016 00:47:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0060D290F2; Sat, 12 Nov 2016 00:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D003290F2 for ; Sat, 12 Nov 2016 00:47:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c5MRc-0004Y8-Fx; Sat, 12 Nov 2016 00:45:20 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c5MRZ-0003qT-2B for linux-arm-kernel@lists.infradead.org; Sat, 12 Nov 2016 00:45:18 +0000 Received: by mail-pf0-x243.google.com with SMTP id i88so3048380pfk.2 for ; Fri, 11 Nov 2016 16:44:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=oOtvcdbtceCIlm8QeCOdTlzwJKSSqv1epg/VZvt7egM=; b=oW0DVcY21IyKZy0x+Py8EMf0J813CksSi1KLketzTJSUHmk0YqJzbDIT5OX92rAyJR dlZuVX6fNvW4eh7VNZShxlxCQIvUL6YNYuv+1o7teJegQ+JWWIo+cRs8oswwMEu/o0E7 2BKlXbMa5XIfQxQ6tQkovHHdbvOMWaiGI3wDvJz8NYKZ+mxSLmxCGyF0vlqm/ltbuAF2 KL5WwXfdBjY3ZsaK/fH35T0o4VjHSRMkIy/V/gO2Dmg5psjpEMSVXPkS0D+SChYB1USa 9fzjeFXIl/jrGzJmNfqTJDlgMFzkaZH0wmbRQCAFRgo28PihsrSYhz4aZFL6odUfhauQ tWIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oOtvcdbtceCIlm8QeCOdTlzwJKSSqv1epg/VZvt7egM=; b=Um4d5/us9wmR3Cl4HHcJNt+VPzwPvhB6RZURb0jrnd74JOVQD62nfzJ6J5uPpEPBVx j4Jn1Y196o/QhMhrWYLt86Yvump2e1bbIMQohi0HxLXjpacMOT80GcSpYPjnRELlsaAr sSTOkwzFzOBlmwxQfE4zfqb7EM1bdgC2kYgVbcTT4KcdKU73QU+1t7hoWhULZSPXE7sD CSKecYrMudgU3jb6G6DYhuxv+NcNHjFaMNdfG5dxQucXMMkLzqY9Voae+PJksJioQrEo uoCN17a3ZYwgM9HDxmxhYLylhjxkVYt8vALbZXwX0SfvOeOax8K3M3DZcaUy9tIuxHtL WvQQ== X-Gm-Message-State: ABUngvcXf2z7XboQuQaEWvfBIL1S6Dw3z8QTRY0Z32t4Ej5dZkXwcxJk99CcwyW1wID1tQ== X-Received: by 10.99.147.6 with SMTP id b6mr9145969pge.22.1478911495818; Fri, 11 Nov 2016 16:44:55 -0800 (PST) Received: from fainelli-desktop.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id d29sm1339130pfk.78.2016.11.11.16.44.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 16:44:55 -0800 (PST) From: Florian Fainelli To: linux-kernel@vger.kernel.org Subject: [PATCH RFC] mm: Add debug_virt_to_phys() Date: Fri, 11 Nov 2016 16:44:43 -0800 Message-Id: <20161112004449.30566-1-f.fainelli@gmail.com> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161111_164517_235511_F9677675 X-CRM114-Status: GOOD ( 12.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Pitre , Mark Rutland , Michal Hocko , Catalin Marinas , Will Deacon , "open list:MEMORY MANAGEMENT" , Chris Brandt , Pratyush Anand , Florian Fainelli , Jerome Marchand , Russell King , Vlastimil Babka , Laura Abbott , Neeraj Upadhyay , "open list:GENERIC INCLUDE/ASM HEADER FILES" , Arnd Bergmann , Joonsoo Kim , Konstantin Khlebnikov , "moderated list:ARM PORT" , Ard Biesheuvel , James Morse , Andrew Morton , "Kirill A. Shutemov" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When CONFIG_DEBUG_VM is turned on, virt_to_phys() maps to debug_virt_to_phys() which helps catch vmalloc space addresses being passed. This is helpful in debugging bogus drivers that just assume linear mappings all over the place. For ARM, ARM64, Unicore32 and Microblaze, the architectures define __virt_to_phys() as being the functional implementation of the address translation, so we special case the debug stub to call into __virt_to_phys directly. Signed-off-by: Florian Fainelli --- arch/arm/include/asm/memory.h | 4 ++++ arch/arm64/include/asm/memory.h | 4 ++++ include/asm-generic/memory_model.h | 4 ++++ mm/debug.c | 15 +++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h index 76cbd9c674df..448dec9b8b00 100644 --- a/arch/arm/include/asm/memory.h +++ b/arch/arm/include/asm/memory.h @@ -260,11 +260,15 @@ static inline unsigned long __phys_to_virt(phys_addr_t x) * translation for translating DMA addresses. Use the driver * DMA support - see dma-mapping.h. */ +#ifndef CONFIG_DEBUG_VM #define virt_to_phys virt_to_phys static inline phys_addr_t virt_to_phys(const volatile void *x) { return __virt_to_phys((unsigned long)(x)); } +#else +#define virt_to_phys debug_virt_to_phys +#endif #define phys_to_virt phys_to_virt static inline void *phys_to_virt(phys_addr_t x) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index b71086d25195..c9e436b28523 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -186,11 +186,15 @@ extern u64 kimage_voffset; * translation for translating DMA addresses. Use the driver * DMA support - see dma-mapping.h. */ +#ifndef CONFIG_DEBUG_VM #define virt_to_phys virt_to_phys static inline phys_addr_t virt_to_phys(const volatile void *x) { return __virt_to_phys((unsigned long)(x)); } +#else +#define virt_to_phys debug_virt_to_phys +#endif #define phys_to_virt phys_to_virt static inline void *phys_to_virt(phys_addr_t x) diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h index 5148150cc80b..426085757258 100644 --- a/include/asm-generic/memory_model.h +++ b/include/asm-generic/memory_model.h @@ -80,6 +80,10 @@ #define page_to_pfn __page_to_pfn #define pfn_to_page __pfn_to_page +#ifdef CONFIG_DEBUG_VM +unsigned long debug_virt_to_phys(volatile void *address); +#endif /* CONFIG_DEBUG_VM */ + #endif /* __ASSEMBLY__ */ #endif diff --git a/mm/debug.c b/mm/debug.c index 9feb699c5d25..72b2ca9b11f4 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -161,4 +161,19 @@ void dump_mm(const struct mm_struct *mm) ); } +#include +#include + +unsigned long debug_virt_to_phys(volatile void *address) +{ + BUG_ON(is_vmalloc_addr((const void *)address)); +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_UNICORE32) || \ + defined(CONFIG_MICROBLAZE) + return __virt_to_phys(address); +#else + return virt_to_phys(address); +#endif +} +EXPORT_SYMBOL(debug_virt_to_phys); + #endif /* CONFIG_DEBUG_VM */