Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1546732imu; Tue, 11 Dec 2018 23:20:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wb5M12LH4jL4m/kFlDY65xjeEJaQn3oYq7bo1bmhvRtwoLOpeWLc5dpPL3e1JJb1Q6fWIt X-Received: by 2002:a65:4142:: with SMTP id x2mr16921147pgp.356.1544599248637; Tue, 11 Dec 2018 23:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544599248; cv=none; d=google.com; s=arc-20160816; b=BEmkDY+NbqgE2jSNb9Njdxy6t2gaQiTvo35dT/IvWcnVb/0MG+Byhskphh7NYemktc CUFa5pZfR5HU5UjvdU/YVBsE5CL7GVmj70q2YdfzD5rAvX78PuiE/tb1O7Ckid5DV7zB 09K7XM+O7zdxEyz9qFJVETnIi9BrrvlagF1S/B8Ifl1fbVxi+3hTc1ieOaVPcj5oCbVz bwgyUTbeOPuKNzGOqjFfMab963H8/x0Chgks+7qWjzvBzWbT0GzYnBPK3Nu6j2g215yS NBS3U6t5wP+XQ9/Beq/xSaH/XbAjd57LArjxWzEqNFiTSYBHVc/TZB+3E9Gni9tWziy+ 3Snw== 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:from:references:cc:to:subject; bh=nLxKkxnI6ogVRE5s28u4nPnyEd/DzK74VUi5pRcySL4=; b=PxpwvDP0/nclJCShhr1dFsuRWddX5SqMjh0d0O7wDJi8ey6PioSLQZ3xbJ+HR4PHI8 YOhaPU6qURNBUoT54PnMWiMYXsxulx6cYoArS3n3mPVrrnYyxHmO4T9lqJgC5DLCD6AE KwXlCcQ3sLPg58px3Zxojgu1Y9c9sKRltOF/Z9XMXFAW3eF9fkFU5MdPtga7teGe6R74 xdFp9tvCrFI8CEEdTP0hsotgS+rf+NSXBJaNJh6cIrLwk5n0BuVepcpKc8nC0/IgZ1EL AQ3i7ZEhdBJ6BJd+0XYjuylh7A85Nv9hwzLkyLL8pK1c5od9aUgvw+Eqr0p9R7nRGjJ3 Yb4w== 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 w11si13991367pgp.161.2018.12.11.23.20.30; Tue, 11 Dec 2018 23:20:48 -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 S1726603AbeLLHT0 (ORCPT + 99 others); Wed, 12 Dec 2018 02:19:26 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:15508 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbeLLHT0 (ORCPT ); Wed, 12 Dec 2018 02:19:26 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 43F7V31tlnz9v0fb; Wed, 12 Dec 2018 08:19:23 +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 AiQMlPEefn9W; Wed, 12 Dec 2018 08:19:23 +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 43F7V317xXz9v0fZ; Wed, 12 Dec 2018 08:19:23 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 125CF8B82A; Wed, 12 Dec 2018 08:19:24 +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 r5jEYM3B3tVG; Wed, 12 Dec 2018 08:19:23 +0100 (CET) Received: from PO15451 (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A2BCE8B825; Wed, 12 Dec 2018 08:19:23 +0100 (CET) Subject: Re: [PATCH v3] powerpc: implement CONFIG_DEBUG_VIRTUAL To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <87va3zwq1t.fsf@concordia.ellerman.id.au> From: Christophe Leroy Message-ID: <32b00148-214c-44db-e9cf-fa4caa2547e8@c-s.fr> Date: Wed, 12 Dec 2018 08:19:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: <87va3zwq1t.fsf@concordia.ellerman.id.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 12/12/2018 à 01:23, Michael Ellerman a écrit : > Christophe Leroy writes: > >> This patch implements CONFIG_DEBUG_VIRTUAL to warn about >> incorrect use of virt_to_phys() and page_to_phys() >> >> Below is the result of test_debug_virtual: >> >> [ 1.438746] WARNING: CPU: 0 PID: 1 at ./arch/powerpc/include/asm/io.h:808 test_debug_virtual_init+0x3c/0xd4 >> [ 1.448156] CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc5-00560-g6bfb52e23a00-dirty #532 >> [ 1.457259] NIP: c066c550 LR: c0650ccc CTR: c066c514 >> [ 1.462257] REGS: c900bdb0 TRAP: 0700 Not tainted (4.20.0-rc5-00560-g6bfb52e23a00-dirty) >> [ 1.471184] MSR: 00029032 CR: 48000422 XER: 20000000 >> [ 1.477811] >> [ 1.477811] GPR00: c0650ccc c900be60 c60d0000 00000000 006000c0 c9000000 00009032 c7fa0020 >> [ 1.477811] GPR08: 00002400 00000001 09000000 00000000 c07b5d04 00000000 c00037d8 00000000 >> [ 1.477811] GPR16: 00000000 00000000 00000000 00000000 c0760000 c0740000 00000092 c0685bb0 >> [ 1.477811] GPR24: c065042c c068a734 c0685b8c 00000006 00000000 c0760000 c075c3c0 ffffffff >> [ 1.512711] NIP [c066c550] test_debug_virtual_init+0x3c/0xd4 >> [ 1.518315] LR [c0650ccc] do_one_initcall+0x8c/0x1cc >> [ 1.523163] Call Trace: >> [ 1.525595] [c900be60] [c0567340] 0xc0567340 (unreliable) >> [ 1.530954] [c900be90] [c0650ccc] do_one_initcall+0x8c/0x1cc >> [ 1.536551] [c900bef0] [c0651000] kernel_init_freeable+0x1f4/0x2cc >> [ 1.542658] [c900bf30] [c00037ec] kernel_init+0x14/0x110 >> [ 1.547913] [c900bf40] [c000e1d0] ret_from_kernel_thread+0x14/0x1c >> [ 1.553971] Instruction dump: >> [ 1.556909] 3ca50100 bfa10024 54a5000e 3fa0c076 7c0802a6 3d454000 813dc204 554893be >> [ 1.564566] 7d294010 7d294910 90010034 39290001 <0f090000> 7c3e0b78 955e0008 3fe0c062 >> [ 1.572425] ---[ end trace 6f6984225b280ad6 ]--- >> [ 1.577467] PA: 0x09000000 for VA: 0xc9000000 >> [ 1.581799] PA: 0x061e8f50 for VA: 0xc61e8f50 >> >> Signed-off-by: Christophe Leroy >> --- >> v3: Added missing linux/mm.h >> I realised that a driver may use DMA on stack after checking with virt_addr_valid(), so the new >> verification might induce false positives. I remove it for now, will add it again later in a more >> controled way. > > What is this comment referring to? > > I can't see any difference to v2 except the linux/mm.h include. v2 was: @@ -804,6 +806,11 @@ extern void __iounmap_at(void *ea, unsigned long size); */ static inline unsigned long virt_to_phys(volatile void * address) { + if (IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && + !WARN_ON(IS_ENABLED(CONFIG_HAVE_ARCH_VMAP_STACK) && current->pid && + object_is_on_stack((const void*)address))) + WARN_ON(!virt_addr_valid(address)); + return __pa((unsigned long)address); } v3 is: (same as v1) @@ -804,6 +806,8 @@ extern void __iounmap_at(void *ea, unsigned long size); */ static inline unsigned long virt_to_phys(volatile void * address) { + WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !virt_addr_valid(address)); + return __pa((unsigned long)address); } The idea in v2 was to detect objects on stack used for DMA before activating CONFIG_VMAP_STACK, but if the driver uses virt_addr_valid() to decide if it can DMA map it, then we'll get false positives. So I think this should be added with a dedicated DEBUG CONFIG option, not implicitely. Christophe