Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4772164imu; Tue, 18 Dec 2018 23:20:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9UFQzoKgCbm95mc4tY1VuN8S0x11B1U9gxmFslE27qVFJkxXOQKT7gXbB372bbeyOGPQj X-Received: by 2002:a63:fd53:: with SMTP id m19mr2041562pgj.340.1545204008395; Tue, 18 Dec 2018 23:20:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545204008; cv=none; d=google.com; s=arc-20160816; b=rFYRNaLduxnw2wRSCBYLaMT5MfwwesGE28As9yDE4UcRiBf0doiulGNzcqP40swBAm SgyTBa/QFAZe3SG1DsPwuUfFLq23vs8I6d0iVLhZrbrdGUtiznkVUWcOq+Q1S52Og8vc 6UxzrrI+omvtj5afKjBasCoqk151lGOuZx6oNEwJ6Vev6KMXzDj0dirgJN2jepOheJgw J4sRyVYhkxRNcyGQ7zE3BiVPSqsNdujSTW6LxKPkaIqJZKw2lSpZz4j1Eyik2yNdi9Tp KJWrrScHs0RS5hmcxyqoHMH7DvHGNCdh24xX3tHvcU9nMafcJTgAU4l6xqBhWVuCA6Bc xXTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=KdZp7IrDe6UYhdcCwE8X5ou8NawUkW6KE4t6KOysg4U=; b=rhqHia4aihte3ZdVRqNpRuLtxx0pLgdYrAZiS7NsRsIStg7wtV3VFEC9VyRq1Ka63U Q8h5BD3tf1Hm6AF9AsnnxDzq11G1fx4/hfCxV1+I5VyeZ3RjvPsWi9gk5ccE3zu3lHy5 Z0aj0/hEz9DYsL+UM5FYNQ741Vf4T/vc+okiVoxmDyYWN9R1MFpV2Kd4qas6XtL1Eexv NPoKsLyiOQREW0M72cpazcSHwXVzRvRXruZl8PYLSyBmlB4z13yIstmUXNvScbsmSZ29 P8tTfOi0Md7mXae16DsIsMgp814gVRy6BxH/e8E8XqfR6c1tVADpzvg5SAmiRQiyibUa 4yVQ== 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 j191si14553993pgd.31.2018.12.18.23.19.50; Tue, 18 Dec 2018 23:20:08 -0800 (PST) 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 S1728087AbeLSHDg (ORCPT + 99 others); Wed, 19 Dec 2018 02:03:36 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:3629 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725294AbeLSHDf (ORCPT ); Wed, 19 Dec 2018 02:03:35 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 43KQpX6x2nz9v2Rx; Wed, 19 Dec 2018 08:03:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id ZLGtgowk6JAG; Wed, 19 Dec 2018 08:03:32 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 43KQpX6M43z9v2Rw; Wed, 19 Dec 2018 08:03:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BF4F88B85D; Wed, 19 Dec 2018 08:03:33 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id gxj39CXns4St; Wed, 19 Dec 2018 08:03:33 +0100 (CET) Received: from po14163vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8B2D78B754; Wed, 19 Dec 2018 08:03:33 +0100 (CET) Subject: Re: [PATCH v3] powerpc: implement CONFIG_DEBUG_VIRTUAL From: Christophe Leroy To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <87y38nrkto.fsf@concordia.ellerman.id.au> <87a7l2s6p3.fsf@concordia.ellerman.id.au> Message-ID: <5e18c60e-9572-5844-b17d-aa55e7ff4709@c-s.fr> Date: Wed, 19 Dec 2018 07:03:32 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/19/2018 06:57 AM, Christophe Leroy wrote: > > > Le 19/12/2018 à 01:26, Michael Ellerman a écrit : >> Michael Ellerman writes: >>> Christophe Leroy writes: >>> >>>> This patch implements CONFIG_DEBUG_VIRTUAL to warn about >>>> incorrect use of virt_to_phys() and page_to_phys() >>> >>> This commit is breaking my p5020ds booting a 32-bit kernel with: >>> >>>    smp: Bringing up secondary CPUs ... >>>    __ioremap(): phys addr 0x7fef5000 is RAM lr ioremap_coherent >>>    Unable to handle kernel paging request for data at address 0x00000000 >>>    Faulting instruction address: 0xc002e950 >>>    Oops: Kernel access of bad area, sig: 11 [#1] >>>    BE SMP NR_CPUS=24 CoreNet Generic >>>    Modules linked in: >>>    CPU: 0 PID: 1 Comm: swapper/0 Not tainted >>> 4.20.0-rc2-gcc-7.0.1-00138-g9a0380d299e9 #148 >>>    NIP:  c002e950 LR: c002eb20 CTR: 00000001 >>>    REGS: e804bd20 TRAP: 0300   Not tainted >>> (4.20.0-rc2-gcc-7.0.1-00138-g9a0380d299e9) >>>    MSR:  00021002   CR: 28004222  XER: 00000000 >>>    DEAR: 00000000 ESR: 00000000 >>>    GPR00: c002eb20 e804bdd0 e8050000 00000000 00021002 00000000 >>> 00000050 00021002 >>>    GPR08: 2d3f0000 00000001 00000000 00000004 24000842 00000000 >>> c00026d0 00000000 >>>    GPR16: 00000000 00000000 00000000 00000000 00000000 00000000 >>> 00000000 00000001 >>>    GPR24: 00029002 7fef5140 30000000 00000000 00000000 00000040 >>> 00000001 00000000 >>>    NIP [c002e950] smp_85xx_kick_cpu+0x120/0x410 >>>    LR [c002eb20] smp_85xx_kick_cpu+0x2f0/0x410 >>>    Call Trace: >>>    [e804bdd0] [c002eb20] smp_85xx_kick_cpu+0x2f0/0x410 (unreliable) >>>    [e804be20] [c0012e38] __cpu_up+0xc8/0x230 >>>    [e804be50] [c0040b34] bringup_cpu+0x34/0x110 >>>    [e804be70] [c00418a8] cpu_up+0x128/0x250 >>>    [e804beb0] [c0b84b14] smp_init+0xc4/0x10c >>>    [e804bee0] [c0b75c1c] kernel_init_freeable+0xc8/0x250 >>>    [e804bf20] [c00026e8] kernel_init+0x18/0x120 >>>    [e804bf40] [c0011298] ret_from_kernel_thread+0x14/0x1c >>>    Instruction dump: >>>    7fb3e850 57bdd1be 2e1d0000 41d20250 57bd3032 393dffc0 7e6a9b78 >>> 5529d1be >>>    39290001 7d2903a6 60000000 60000000 <7c0050ac> 394a0040 4200fff8 >>> 7c0004ac >>>    ---[ end trace edcab2a1dfd5b38c ]--- >>> >>> >>> Which is obviously this hunk: >>> >>>> diff --git a/arch/powerpc/mm/pgtable_32.c >>>> b/arch/powerpc/mm/pgtable_32.c >>>> index 4fc77a99c9bf..68d204a45cd0 100644 >>>> --- a/arch/powerpc/mm/pgtable_32.c >>>> +++ b/arch/powerpc/mm/pgtable_32.c >>>> @@ -143,7 +143,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long >>>> size, pgprot_t prot, void *call >>>>        * Don't allow anybody to remap normal RAM that we're using. >>>>        * mem_init() sets high_memory so only do the check after that. >>>>        */ >>>> -    if (slab_is_available() && (p < virt_to_phys(high_memory)) && >>>> +    if (slab_is_available() && virt_addr_valid(p) && >>>>           page_is_ram(__phys_to_pfn(p))) { >>>>           printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n", >>>>                  (unsigned long long)p, __builtin_return_address(0)); >>> >>> >>> I'll try and come up with a fix tomorrow. >> >> Actually I think that change is just wrong. virt_addr_valid() takes a >> virtual address, but p is a physical address. >> >> So I'll drop this hunk for now, which makes the patch a no-op when >> DEBUG_VIRTUAL is n which is probably the way it should be. > > The hunk is obviously wrong for sure. Anyway there's a problem, most > likely high_memory is not a valid virtual address, so without this hunk > I get the following warning at every ioremap(): > > [    0.000000] WARNING: CPU: 0 PID: 0 at > ./arch/powerpc/include/asm/io.h:809 __ioremap_caller+0x9c/0x180 > [    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted > 4.20.0-rc6-s3k-dev-00677-g9c98dcab6203-dirty #615 > [    0.000000] NIP:  c000fcd0 LR: c000fc64 CTR: 00000000 > [    0.000000] REGS: c073de50 TRAP: 0700   Not tainted > (4.20.0-rc6-s3k-dev-00677-g9c98dcab6203-dirty) > [    0.000000] MSR:  00021032   CR: 28944422  XER: 0000f940 > [    0.000000] > [    0.000000] GPR00: c000fe04 c073df00 c06e1450 00000001 00004023 > c073df38 c0018f50 00000001 > [    0.000000] GPR08: 00002000 08000000 00002000 00000000 88944224 > 00600000 00000000 07ff9580 > [    0.000000] GPR16: 00000000 07ffb94c 00000000 00000000 00000000 > 00000000 00000000 00000000 > [    0.000000] GPR24: 00000000 c0760000 0000019f ff000000 ff000000 > c000fe04 00004000 c0018f50 > [    0.000000] NIP [c000fcd0] __ioremap_caller+0x9c/0x180 > [    0.000000] LR [c000fc64] __ioremap_caller+0x30/0x180 > [    0.000000] Call Trace: > [    0.000000] [c073df00] [c02fc23c] of_address_to_resource+0x114/0x154 > (unreliable) > [    0.000000] [c073df30] [c000fe04] ioremap_wt+0x20/0x30 > [    0.000000] [c073df40] [c0018f50] mpc8xx_pic_init+0x70/0xf8 > [    0.000000] [c073df80] [c0655b84] mpc8xx_pics_init+0x10/0x6c > [    0.000000] [c073df90] [c0675080] cmpc885_pics_init+0x14/0x118 > [    0.000000] [c073dfa0] [c0652eb0] init_IRQ+0x24/0x38 > [    0.000000] [c073dfb0] [c0650b10] start_kernel+0x2a8/0x3d4 > [    0.000000] [c073dff0] [c0002258] start_here+0x44/0x98 > [    0.000000] Instruction dump: > [    0.000000] 419e00b8 7f83e378 480013fd 7c7d1b79 41820030 576304be > 7c63ea14 80010034 > [    0.000000] bb410018 7c0803a6 38210030 4e800020 <0fe00000> 7f9c4840 > 409cffc4 480000a8 > [    0.000000] random: get_random_bytes called from > print_oops_end_marker+0x60/0x84 with crng_init=0 > [    0.000000] ---[ end trace 25d7f28ce013ad37 ]--- > > I'll try and come with solution during the day. In fact the solution is the following: diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c index 4fc77a99c9bf..60401af2bc8f 100644 --- a/arch/powerpc/mm/pgtable_32.c +++ b/arch/powerpc/mm/pgtable_32.c @@ -143,7 +143,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call * Don't allow anybody to remap normal RAM that we're using. * mem_init() sets high_memory so only do the check after that. */ - if (slab_is_available() && (p < virt_to_phys(high_memory)) && + if (slab_is_available() && (p <= virt_to_phys(high_memory - 1)) && page_is_ram(__phys_to_pfn(p))) { printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n", (unsigned long long)p, __builtin_return_address(0)); I'll send an updated patch in a few minutes. Christophe