Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751370AbdINHku (ORCPT ); Thu, 14 Sep 2017 03:40:50 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33687 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751252AbdINHkt (ORCPT ); Thu, 14 Sep 2017 03:40:49 -0400 X-Google-Smtp-Source: ADKCNb5u21HW8oXd2iRpaZcb2c7KbZEQTZurSBNz0eH6cF+39i6J6jNQgGPQYga5E1kXd7Ed+yifQQ== Date: Thu, 14 Sep 2017 16:40:44 +0900 From: Sergey Senozhatsky To: Helge Deller Cc: "Luck, Tony" , Sergey Senozhatsky , "linux-kernel@vger.kernel.org" , Sergey Senozhatsky , Petr Mladek , Andrew Morton , "Yu, Fenghua" , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Subject: Re: [PATCH 00/14] Fix wrong %pF and %pS printk format specifier usages Message-ID: <20170914074044.GE599@jagdpanzerIV.localdomain> References: <20170907075653.GA533@jagdpanzerIV.localdomain> <20170907083207.GC533@jagdpanzerIV.localdomain> <667b8849-fb60-a312-2483-505252ff737e@gmx.de> <20170907093631.GD533@jagdpanzerIV.localdomain> <20170907095119.GE533@jagdpanzerIV.localdomain> <0604f27e-24ab-625b-9013-c6c0f4f6acc1@gmx.de> <3908561D78D1C84285E8C5FCA982C28F6136C2ED@ORSMSX114.amr.corp.intel.com> <20170908061830.GA496@jagdpanzerIV.localdomain> <20170908172528.qc2vdtxzqh777k6o@intel.com> <67a0aad8-5412-60f8-6481-562d37995eb2@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67a0aad8-5412-60f8-6481-562d37995eb2@gmx.de> User-Agent: Mutt/1.9.0 (2017-09-02) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3126 Lines: 103 On (09/08/17 20:28), Helge Deller wrote: [..] > I don't like this kind of trying to figure out at runtime at all. > It's too much guessing in here IMHO. well, may be we can avoid any guessing by checking that the pointer belongs to .opd section. for kernel we can add 2 new unsigned longs - __opd_start __opd_end -- and tweak the corresponding arch/${FOO}/kernel/vmlinux.lds.S file to set those two, the same way text, unwinding, etc. are set. .... wait a second. arch/ia64/kernel/vmlinux.lds.S already handles .opd section .opd : AT(ADDR(.opd) - LOAD_OFFSET) { *(.opd) } it just doesn't save start/end addresses. so all we need to to is .opd : AT(ADDR(.opd) - LOAD_OFFSET) { + __opd_start = .; *(.opd) + __opd_end = .; } and tweak symbol dereference static inline void *dereference_function_descriptor(void *ptr) { struct fdesc *desc = ptr; void *p; + if (prt < (void *)__start_opd || (void *)__end_opd < ptr) + return ptr; + if (!probe_kernel_address(&desc->ip, p)) ptr = p; return ptr; now, the modules. module_frob_arch_sections() has the following lines else if (strcmp(".opd", secstrings + s->sh_name) == 0) mod->arch.opd = s; so, once, again, we keep the .opd section info in memory. and we also have the size of that section mod->arch.opd->sh_size = fdescs * sizeof(struct fdesc); so it seems that we've got what we need. need to provide arch callback (same way as we do with dereference_function_descriptor() to properly dereference modules' symbols). so I think we almost have what we need to make ps/pS smart enough on ppc64/ia64/parisc. powerpc and parisc handle kernel .opd section as well: arch/powerpc/kernel/vmlinux.lds.S: .opd arch/parisc/kernel/vmlinux.lds.S: .opd need to check more. > What about this idea: > For %pF we always have pointers to functions, e.g.: > printk("Going to call: %pF\n", gettimeofday); > printk("Going to call: %pF\n", p->func); > > and for %pS most (if not all) usages use some kind of casting > from "unsigned long" to "void *", e.g.: > printk("%s: called from %pS\n", __func__, (void *)_RET_IP_); > printk("%s: called from %pS\n", __func__, (void *)__builtin_return_address(0)); > printk("Faulted at %pS\n", (void *)regs->ip); > > So, what if we for the %pS case simply take the type as it is > (unsigned long) and introduce a new printk-format, e.g. "%luS" ? > The %pS examples above then become: > printk("%s: called from %luS\n", __func__, _RET_IP_); > printk("%s: called from %luS\n", __func__, __builtin_return_address(0)); > printk("Faulted at %luS\n", regs->ip); > > That way we don't need type-casting, gain compile-time type > checks from the compiler, and we could add a checkpatch (or occinelle) > check which checks for the combination of %pF/%pS and "void*" keyword > and suggest to use %luS. > > Opinions? hm. sounds interesting. but I'm afraid people won't be so happy to learn a new printk format specifier. -ss