From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752460AbdHHSfJ (ORCPT ); Tue, 8 Aug 2017 14:35:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:54715 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752430AbdHHSfI (ORCPT ); Tue, 8 Aug 2017 14:35:08 -0400 Date: Tue, 8 Aug 2017 20:35:05 +0200 From: "Luis R. Rodriguez" To: Florian Fainelli Cc: "Luis R. Rodriguez" , Juergen Gross , linux-kernel@vger.kernel.org, ard.biesheuvel@linaro.org, labbott@redhat.com, Andrew Morton , "Paul E. McKenney" , Kees Cook , Ingo Molnar , "David S. Miller" , Peter Zijlstra , Geert Uytterhoeven , Nicholas Piggin , Olof Johansson , "Jason A. Donenfeld" , "Theodore Ts'o" , Thomas Gleixner , Josh Poimboeuf , Andy Shevchenko , Bart Van Assche , Matthew Wilcox , Al Viro , Jiri Pirko , Jeff Layton Subject: Re: [PATCH] lib: Add test module for CONFIG_DEBUG_VIRTUAL Message-ID: <20170808183505.GS27873@wotan.suse.de> References: <20170808164035.26725-1-f.fainelli@gmail.com> <20170808175708.GR27873@wotan.suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 08, 2017 at 11:04:11AM -0700, Florian Fainelli wrote: > On 08/08/2017 10:57 AM, Luis R. Rodriguez wrote: > > On Tue, Aug 08, 2017 at 09:40:26AM -0700, Florian Fainelli wrote: > >> Add a test module that allows testing that CONFIG_DEBUG_VIRTUAL works > >> correctly, at least that it can catch invalid calls to virt_to_phys() > >> against the non-linear kernel virtual address map. > >> > >> Signed-off-by: Florian Fainelli > >> --- > > >> +static int __init test_debug_virtual_init(void) > >> +{ > >> + phys_addr_t pa; > >> + void *va; > >> + > >> + va = (void *)VMALLOC_START; > >> + pa = virt_to_phys(va); > >> + > >> + pr_info("PA: %pa for VA: 0x%lx\n", &pa, (unsigned long)va); > >> + > >> + foo = kzalloc(sizeof(*foo), GFP_KERNEL); > >> + if (!foo) > >> + return -ENOMEM; > >> + > >> + pa = virt_to_phys(foo); > >> + va = foo; > >> + pr_info("PA: %pa for VA: 0x%lx\n", &pa, (unsigned long)va); > > > > Should there be a tests here of some sort? When should this fail, why? > > There is no test per-se, the kernel will produce warning with > CONFIG_DEBUG_VIRTUAL telling you that what you are doing is wrong. > > > There is no docs on this self test, could one be added? > > I suppose I could add one even though that just means pointing out the > code that produces the warning? A /* note */ indicating what you just said above would suffice then but typically tests return back to userspace an error, so another option would be to see if one could get a return value that an error happened and return that back to the module init. Grepping just for warning for an error seems error prone. Luis