From patchwork Tue Nov 22 09:20:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 697603 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tNKk83v6dz9snk for ; Tue, 22 Nov 2016 20:22:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dI8zKRjF"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tNKk82ZCnzDvmr for ; Tue, 22 Nov 2016 20:22:24 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dI8zKRjF"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pg0-x242.google.com (mail-pg0-x242.google.com [IPv6:2607:f8b0:400e:c05::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tNKh41G0KzDvmk for ; Tue, 22 Nov 2016 20:20:35 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dI8zKRjF"; dkim-atps=neutral Received: by mail-pg0-x242.google.com with SMTP id p66so1597389pga.2 for ; Tue, 22 Nov 2016 01:20:35 -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:in-reply-to:references; bh=zEkwxeMCEtzbdfuGjp6QsYLujyGBIAU4twLHaM01PcM=; b=dI8zKRjF4dgQBFAp5j3jjx6v7/5PwjMsFs8F+L756IWs07n70jT/k8K70M41RFbHWK n33Wk3zxqjJJ6occfAOtUHUm8T+RS+vmz4hh/JSxx7O0nrn/ZKzCmmD+sBgtZKVQzNWb A5HwtmSKKDvtNGVLv79OfdBxMPrIitI73QuQ6AjgtqqAtymVWg7I0UocufY3/+Un6jt6 tk06mk2eIoAsqEknVFkzkVMQni2tIOSjGfDfjjfETOX3ZHdMS+syLRlumo8DEW4kooq8 2bYByBFNV0dfYAUxhu/qJKzOrpvsCRqQX/JH54jkiXMkyR2xmihss7ovuNGQ9IF4IG+0 ooJQ== 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:in-reply-to :references; bh=zEkwxeMCEtzbdfuGjp6QsYLujyGBIAU4twLHaM01PcM=; b=NCQi6Y9FdUrydIqJ1PI2kdz8w48nbldXpLrn7hWbt4Bpas2yoAGZRW9Xlme+AFiM0b Qq49osNYY6ZYrKt0ACOhxYiX8Xt8zh6x71dpum5S1EjoJtoyWsIukQX7Rv/knKGcqLZb Jlh6Cto0cOrhI/WLMZHa8yPBJn0+9u5pNLRoPcyyzs3pwnVTXYBAtmsUDT8wxkaaSwZ8 fTQ9KlBWnEtT3rMpqNFLrpF9RW20cT9DyoXxqcSP2n5vbQIATcBKLZS0Q3i1c0xxCBvf 0oSAh3CYXpIteN7RzKQBtF1D3r5m3s42c/7I86wds3uQ1kPH2VTSzrq7rmonPHDjooaU IkLA== X-Gm-Message-State: AKaTC00gP2efKE0uOTFvlqkBLHHs4Vjh+O5wVfx+kSjEwqea4kyihehakGzs+T7Kh+zlqQ== X-Received: by 10.98.155.146 with SMTP id e18mr24527560pfk.45.1479806433644; Tue, 22 Nov 2016 01:20:33 -0800 (PST) Received: from localhost ([45.32.128.109]) by smtp.gmail.com with ESMTPSA id y134sm43445701pfg.81.2016.11.22.01.20.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Nov 2016 01:20:32 -0800 (PST) From: Boqun Feng To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [RFC v2] powerpc: xmon: Add address lookup for percpu symbols Date: Tue, 22 Nov 2016 17:20:09 +0800 Message-Id: <20161122092033.7869-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161117094051.21606-1-boqun.feng@gmail.com> References: <20161117094051.21606-1-boqun.feng@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Douglas Miller , Boqun Feng , Rashmica Gupta , Paul Mackerras , "Aneesh Kumar K.V" , Andrew Donnellan Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Currently, in xmon, there is no obvious way to get an address for a percpu symbol for a particular cpu. Having such an ability would be good for debugging the system when percpu variables got involved. Therefore, this patch introduces a new xmon command "lp" to lookup the address for percpu symbols. Usage of "lp" is similar to "ls", except that we could add a cpu number to choose the variable of which cpu we want to lookup. If no cpu number is given, lookup for current cpu. Signed-off-by: Boqun Feng --- v1 --> v2: o Using per_cpu_ptr() and this_cpu_ptr() instead of per_cpu_offset() and my_cpu_offset, because the latter are undefined on !SMP kernel. o Only print the address of percpu symbols, i.e. symbols in [__per_cpu_start, __per_cpu_end) arch/powerpc/xmon/xmon.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index 760545519a0b..2747c94400a2 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -49,6 +49,7 @@ #include #include +#include #ifdef CONFIG_PPC64 #include @@ -229,6 +230,7 @@ Commands:\n\ f flush cache\n\ la lookup symbol+offset of specified address\n\ ls lookup address of specified symbol\n\ + lp s [#] lookup address of percpu symbol s for current cpu, or cpu #\n\ m examine/change memory\n\ mm move a block of memory\n\ ms set a block of memory\n\ @@ -2943,7 +2945,8 @@ static void symbol_lookup(void) { int type = inchar(); - unsigned long addr; + unsigned long addr, cpu; + void __percpu *ptr = NULL; static char tmp[64]; switch (type) { @@ -2967,6 +2970,36 @@ symbol_lookup(void) catch_memory_errors = 0; termch = 0; break; + case 'p': + getstring(tmp, 64); + if (setjmp(bus_error_jmp) == 0) { + catch_memory_errors = 1; + sync(); + ptr = (void __percpu *)kallsyms_lookup_name(tmp); + sync(); + } + + if (ptr && ptr >= (void __percpu *)__per_cpu_start + && ptr < (void __percpu *)__per_cpu_end) { + + if (scanhex(&cpu) && cpu < num_possible_cpus()) + addr = (unsigned long)per_cpu_ptr(ptr, cpu); + else { + cpu = raw_smp_processor_id(); + addr = (unsigned long)this_cpu_ptr(ptr); + } + + printf("%s for cpu 0x%lx: %lx\n", tmp, cpu, addr); + + } else { + printf("Percpu symbol '%s' not found.\n", tmp); + } + + + + catch_memory_errors = 0; + termch = 0; + break; } }