From patchwork Thu Jan 7 22:52:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 358838 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7593CC432C3 for ; Thu, 7 Jan 2021 22:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44B3F23602 for ; Thu, 7 Jan 2021 22:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbhAGWx1 (ORCPT ); Thu, 7 Jan 2021 17:53:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728568AbhAGWxW (ORCPT ); Thu, 7 Jan 2021 17:53:22 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB96CC0612F5; Thu, 7 Jan 2021 14:52:41 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id p18so6303792pgm.11; Thu, 07 Jan 2021 14:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q4EKfM/UykAzpJGwavvmFKVMSq591R3UWoZHA7HF3eo=; b=Z3DwANhR/EydQ/pT8/9aBcSh6GI0g0LS9rE/IkN+7em5cd7vpgcEklo0g4tfV0n7Jw fVBfxxQgkeGzIwb4RUDt6MjtVaAftHMa61yIySRheNYNQ+ZDrp91QgDqZ+bk2T00mFwE WWVTeZopWwGJhjwvIqjEwXK1dewIG8rnXEG9wdSwEpeDxpFpC6SF3BoABj70eqT2UDem tqkhPwBsmA2V7+WzW1jit9Wmmx6ImpR3oRAhzO7s5FsyfwmixO1qJmo1srnwHIPDo5ke NEMTnXN5pTPUEpzrqHoBouj8O9AnX93Z/m+1cAc1HzO2mOJfXxDI9uJZXmYfaoYqLZ58 pufA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q4EKfM/UykAzpJGwavvmFKVMSq591R3UWoZHA7HF3eo=; b=Els76OejHSwol3IAJrVWWfOPyzhu60VOM6Se38uBcoxY7e5TW6TX8smjHcrqezK1mV VanGhXChvMczmSRWOvxBOrZXzZlatdmFGxOa5qo6k5XlVMebO65JL7pfgRk2cRsCounB VdgPk8dUsi0pRuySsAIUQQI+5yBrZZ3fro434zt/R1R9hxNbuUpUK7KMFoO+4tM3XhJ4 UKde095duqO4G8O0vXu8zbjhW7e1Ep7kMriDGYjAzZ737HPZmoUlKPppyTGF5T0zATuQ AK8+YQ61n4ny2+uXdA8YwyapL7hdcC7SzMBdwHhNy1erQ/nvJ19unN9c2Wca6IrQ9A+D CkSA== X-Gm-Message-State: AOAM530I+nunZeeB61sR+asQeY5d4WTuQHIjOqy+Uawi4CquVmNqdBPy qGF/dwBjY6ju69W0MMnCQB/o9shoyr4= X-Google-Smtp-Source: ABdhPJz8qjQLbY+x7sWjO9oB3B7vCcgf8+Ul70rcroTlofsq9c7bQOdUhjbzC9Pk3eL2yO5PBqKKtA== X-Received: by 2002:a62:19cb:0:b029:19e:75c2:61ec with SMTP id 194-20020a6219cb0000b029019e75c261ecmr712266pfz.19.1610059960956; Thu, 07 Jan 2021 14:52:40 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a10sm6510603pfi.168.2021.01.07.14.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 14:52:40 -0800 (PST) From: Florian Fainelli To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Andr=C3=A9_Draszik?= , Kieran Bingham , Jan Kiszka , Andrew Morton , Linus Torvalds , Florian Fainelli , Leonard Crestez , Du Changbin Subject: [stable 4.9.y 1/4] scripts/gdb: make lx-dmesg command work (reliably) Date: Thu, 7 Jan 2021 14:52:26 -0800 Message-Id: <20210107225229.1502459-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107225229.1502459-1-f.fainelli@gmail.com> References: <20210107225229.1502459-1-f.fainelli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: André Draszik commit d6c9708737c2107c38bd75f133d14d5801b8d6d5 upstream lx-dmesg needs access to the log_buf symbol from printk.c. Unfortunately, the symbol log_buf also exists in BPF's verifier.c and hence gdb can pick one or the other. If it happens to pick BPF's log_buf, lx-dmesg doesn't work: (gdb) lx-dmesg Python Exception Cannot access memory at address 0x0: Error occurred in Python command: Cannot access memory at address 0x0 (gdb) p log_buf $15 = 0x0 Luckily, GDB has a way to deal with this, see https://sourceware.org/gdb/onlinedocs/gdb/Symbols.html (gdb) info variables ^log_buf$ All variables matching regular expression "^log_buf$": File /kernel/bpf/verifier.c: static char *log_buf; File /kernel/printk/printk.c: static char *log_buf; (gdb) p 'verifier.c'::log_buf $1 = 0x0 (gdb) p 'printk.c'::log_buf $2 = 0x811a6aa0 <__log_buf> "" (gdb) p &log_buf $3 = (char **) 0x8120fe40 (gdb) p &'verifier.c'::log_buf $4 = (char **) 0x8120fe40 (gdb) p &'printk.c'::log_buf $5 = (char **) 0x8048b7d0 By being explicit about the location of the symbol, we can make lx-dmesg work again. While at it, do the same for the other symbols we need from printk.c Link: http://lkml.kernel.org/r/20170526112222.3414-1-git@andred.net Signed-off-by: André Draszik Tested-by: Kieran Bingham Acked-by: Jan Kiszka Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Florian Fainelli --- scripts/gdb/linux/dmesg.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py index f9b92ece7834..5afd1098e33a 100644 --- a/scripts/gdb/linux/dmesg.py +++ b/scripts/gdb/linux/dmesg.py @@ -23,10 +23,11 @@ class LxDmesg(gdb.Command): super(LxDmesg, self).__init__("lx-dmesg", gdb.COMMAND_DATA) def invoke(self, arg, from_tty): - log_buf_addr = int(str(gdb.parse_and_eval("log_buf")).split()[0], 16) - log_first_idx = int(gdb.parse_and_eval("log_first_idx")) - log_next_idx = int(gdb.parse_and_eval("log_next_idx")) - log_buf_len = int(gdb.parse_and_eval("log_buf_len")) + log_buf_addr = int(str(gdb.parse_and_eval( + "'printk.c'::log_buf")).split()[0], 16) + log_first_idx = int(gdb.parse_and_eval("'printk.c'::log_first_idx")) + log_next_idx = int(gdb.parse_and_eval("'printk.c'::log_next_idx")) + log_buf_len = int(gdb.parse_and_eval("'printk.c'::log_buf_len")) inf = gdb.inferiors()[0] start = log_buf_addr + log_first_idx From patchwork Thu Jan 7 22:52:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 358839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13278C43332 for ; Thu, 7 Jan 2021 22:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC56323715 for ; Thu, 7 Jan 2021 22:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728991AbhAGWx2 (ORCPT ); Thu, 7 Jan 2021 17:53:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728575AbhAGWxX (ORCPT ); Thu, 7 Jan 2021 17:53:23 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACE84C0612F6; Thu, 7 Jan 2021 14:52:43 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id i5so6348378pgo.1; Thu, 07 Jan 2021 14:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kkJanOIEtiwTHNCIrofj7wjT/1euAC35OtiXO+rsH/E=; b=Ei2AWvifiZYCkJWJPT/YrvJ7SPQ9DmXUkyPZsf10UwBdcdXPyoVE+NPHlQnK0ul/mr mxAHqS+kkDqHCoGfNUFSq3INr5TOGHI9tvhJicP8nW7HAi3FrW+z7nztuk29wuVmqWCv 1SUKMpcR/n8twiVwFTrjNsQIt8ij8PT/hXw1R7xqJU81hh9EfYUuGHuMW0B2ZXLTSUiF th2JbqpTak31kP4FM/VH1UIAesWvXdIkdRs8sXkQ3sYQZmaZMqCK1LNOIAQXLaw9TSNM XpjhlId5Sc6sUwtK3cX5PCxppMZF6umoPpnltEEhdpPaZWZJrv543rm2eZvXKPRUlrjZ daWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kkJanOIEtiwTHNCIrofj7wjT/1euAC35OtiXO+rsH/E=; b=HkzkJXRWdBRZ3ZaDKU7UV3u4TW6QqzAcDY5xFUxuGYeprPQBWQbdJ9ip+nXRTL0wHA UAx9gKXkakq+tbduQon8Xpw71+8U6HZi6euEicWj+sPK22OW7X5C199yZmIBTCI+RloV YUV7M6d4N8UhgFzUDda7NwcbA36wJgb2HeqOoULUEzg82RrYngsdCEhH+DCZr2FJquPA Ti4/+CA9BS+2gp5l8dCMul46akoVXcyr8t/jYBW0GRXk/c1wHYDacPzvfRms+AU8H/ij MJsZYm1A3rhg8dJuJiVM4XtunhTgHlzZ1gF9u1aIvZBLeh4CGLlbNIojK+AOM/j3etDh 2chg== X-Gm-Message-State: AOAM532FzSdiUaqbpZaUngOCKrMDCjkIiCMI/52UFKFpoJXXEg0Ylb/u 8RZhgcoHouVFJRsNYDxSK+J9KCR7jPo= X-Google-Smtp-Source: ABdhPJyLusqCid8FHWWE34bs/i16qmL4MuvouQT7oKVY/d5gsIShKLLYlnuuo4YbpUicFqtpGLf9PA== X-Received: by 2002:aa7:9625:0:b029:1a4:3b48:a19c with SMTP id r5-20020aa796250000b02901a43b48a19cmr4089524pfg.13.1610059962868; Thu, 07 Jan 2021 14:52:42 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a10sm6510603pfi.168.2021.01.07.14.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 14:52:42 -0800 (PST) From: Florian Fainelli To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leonard Crestez , Jan Kiszka , Jason Wessel , Kieran Bingham , Andrew Morton , Linus Torvalds , Florian Fainelli , Kieran Bingham , =?utf-8?q?Andr=C3=A9_Draszik?= , Du Changbin Subject: [stable 4.9.y 2/4] scripts/gdb: lx-dmesg: cast log_buf to void* for addr fetch Date: Thu, 7 Jan 2021 14:52:27 -0800 Message-Id: <20210107225229.1502459-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107225229.1502459-1-f.fainelli@gmail.com> References: <20210107225229.1502459-1-f.fainelli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Leonard Crestez commit c454756f47277b651ad41a5a163499294529e35d upstream In some cases it is possible for the str() conversion here to throw encoding errors because log_buf might not point to valid ascii. For example: (gdb) python print str(gdb.parse_and_eval("log_buf")) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u0303' in position 24: ordinal not in range(128) Avoid this by explicitly casting to (void *) inside the gdb expression. Link: http://lkml.kernel.org/r/ba6f85dbb02ca980ebd0e2399b0649423399b565.1498481469.git.leonard.crestez@nxp.com Signed-off-by: Leonard Crestez Reviewed-by: Jan Kiszka Cc: Jason Wessel Cc: Kieran Bingham Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Florian Fainelli --- scripts/gdb/linux/dmesg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py index 5afd1098e33a..f5a030333dfd 100644 --- a/scripts/gdb/linux/dmesg.py +++ b/scripts/gdb/linux/dmesg.py @@ -24,7 +24,7 @@ class LxDmesg(gdb.Command): def invoke(self, arg, from_tty): log_buf_addr = int(str(gdb.parse_and_eval( - "'printk.c'::log_buf")).split()[0], 16) + "(void *)'printk.c'::log_buf")).split()[0], 16) log_first_idx = int(gdb.parse_and_eval("'printk.c'::log_first_idx")) log_next_idx = int(gdb.parse_and_eval("'printk.c'::log_next_idx")) log_buf_len = int(gdb.parse_and_eval("'printk.c'::log_buf_len")) From patchwork Thu Jan 7 22:52:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 359660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, URIBL_RED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8A8BC4332B for ; Thu, 7 Jan 2021 22:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B94EB23601 for ; Thu, 7 Jan 2021 22:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729005AbhAGWx2 (ORCPT ); Thu, 7 Jan 2021 17:53:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728500AbhAGWx0 (ORCPT ); Thu, 7 Jan 2021 17:53:26 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF5A5C0612F8; Thu, 7 Jan 2021 14:52:45 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id y8so4622853plp.8; Thu, 07 Jan 2021 14:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ueD+y4HncE6w9jLMFht2hirEsKe0+RLoakKJGnlCRI=; b=F/+dBQ5/TJD3FLQmjpCGt3bHe/bl5YWRtzj81VN8619gn6d0u+7Q9ZQOWi/DCtsHz/ ppKd/DyuvEb3O74Wz0otcsVgQ7DDELs6GiBfIeSUE9Z0rQsLqPAsPRpPBz0tFXzm/3k4 iX6EV8df/KfQlJC0aoPUfGZM5bKvgXHd/so5OpOH5iKxHYYz5pvNiHYiuJFBohVR9OgV 0JoLI7U954HVX3lrLGUXeuipSLwttbkZU3wQVI9EpmPWSDZoE3IX2GHiDnK3l2e2hH0E Keb5XFOKyVOuwhrkkvfjhOvrWEcc6A/gi9Dg0HPcFcnJwIVW0aggaAxA+yaL16pn3YRu uBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2ueD+y4HncE6w9jLMFht2hirEsKe0+RLoakKJGnlCRI=; b=WlWG2z3mqGxIpUU9vZcUN2pwQIxXLUo0CaIrcxVj3N8UaDH212vR6Ethrc7lTSxGeA AQBUO6uN01+wTetaQApkCBdPLgKAc+pOVNpp6/+EzswTyLVf/QBZkGOowxaLZcOSM+H0 vl3P4+RE9ZYgPEeajPilXEEZFA8SfBRTSp1FyC4yP6czeUn98qwbDNcRHGIVhkaP+6xb YmQpl0KSJbQ2MAulByNkTYZcGl8sVo7jfeRTEf8mAQOi233rddGWhSg72W4miHnyjDjD ojR46ITq4sL8oRFKmdiCupU5a9QKZIECjS9E+uPIGnh3kj+kXpleGMQbm3f3Uq1wlOyN K5eg== X-Gm-Message-State: AOAM531JUPwUMiCGiLNWttoV8ua+SpoZyw1Lbht2tv24yXSEzjFDT51G vs5ImHR/795rDO4wiZhl+YgnEcR8+9I= X-Google-Smtp-Source: ABdhPJzOr+Go+X8XB+wHjQaMBDvrPAdLRyYoBhbgEE5L9wbzE/CPXN5rzCwqLy/Bk++sgSPCbCpGFA== X-Received: by 2002:a17:90a:ba88:: with SMTP id t8mr641283pjr.229.1610059964848; Thu, 07 Jan 2021 14:52:44 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a10sm6510603pfi.168.2021.01.07.14.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 14:52:44 -0800 (PST) From: Florian Fainelli To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leonard Crestez , Jan Kiszka , Jason Wessel , Kieran Bingham , Andrew Morton , Linus Torvalds , Florian Fainelli , Kieran Bingham , =?utf-8?q?Andr=C3=A9_Draszik?= , Du Changbin Subject: [stable 4.9.y 3/4] scripts/gdb: lx-dmesg: use explicit encoding=utf8 errors=replace Date: Thu, 7 Jan 2021 14:52:28 -0800 Message-Id: <20210107225229.1502459-4-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107225229.1502459-1-f.fainelli@gmail.com> References: <20210107225229.1502459-1-f.fainelli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Leonard Crestez commit 46d10a094353c05144f3b0530516bdac3ce7c435 upstream Use errors=replace because it is never desirable for lx-dmesg to fail on string decoding errors, not even if the log buffer is corrupt and we show incorrect info. The kernel will sometimes print utf8, for example the copyright symbol from jffs2. In order to make this work specify 'utf8' everywhere because python2 otherwise defaults to 'ascii'. In theory the second errors='replace' is not be required because everything that can be decoded as utf8 should also be encodable back to utf8. But it's better to be extra safe here. It's worth noting that this is definitely not true for encoding='ascii', unknown characters are replaced with U+FFFD REPLACEMENT CHARACTER and they fail to encode back to ascii. Link: http://lkml.kernel.org/r/acee067f3345954ed41efb77b80eebdc038619c6.1498481469.git.leonard.crestez@nxp.com Signed-off-by: Leonard Crestez Acked-by: Jan Kiszka Cc: Jason Wessel Cc: Kieran Bingham Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Florian Fainelli --- scripts/gdb/linux/dmesg.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py index f5a030333dfd..6d2e09a2ad2f 100644 --- a/scripts/gdb/linux/dmesg.py +++ b/scripts/gdb/linux/dmesg.py @@ -12,6 +12,7 @@ # import gdb +import sys from linux import utils @@ -52,13 +53,19 @@ class LxDmesg(gdb.Command): continue text_len = utils.read_u16(log_buf[pos + 10:pos + 12]) - text = log_buf[pos + 16:pos + 16 + text_len].decode() + text = log_buf[pos + 16:pos + 16 + text_len].decode( + encoding='utf8', errors='replace') time_stamp = utils.read_u64(log_buf[pos:pos + 8]) for line in text.splitlines(): - gdb.write("[{time:12.6f}] {line}\n".format( + msg = u"[{time:12.6f}] {line}\n".format( time=time_stamp / 1000000000.0, - line=line)) + line=line) + # With python2 gdb.write will attempt to convert unicode to + # ascii and might fail so pass an utf8-encoded str instead. + if sys.hexversion < 0x03000000: + msg = msg.encode(encoding='utf8', errors='replace') + gdb.write(msg) pos += length From patchwork Thu Jan 7 22:52:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 359659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, URIBL_RED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CD30C43333 for ; Thu, 7 Jan 2021 22:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E81E235FA for ; Thu, 7 Jan 2021 22:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728500AbhAGWxj (ORCPT ); Thu, 7 Jan 2021 17:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728997AbhAGWx2 (ORCPT ); Thu, 7 Jan 2021 17:53:28 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4836C0612F9; Thu, 7 Jan 2021 14:52:47 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id c12so4973971pfo.10; Thu, 07 Jan 2021 14:52:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fLaUUyKZV1n5I1oaAK7wF0mjKoazvM828WYSvM0xN9U=; b=SrpDw5ZL20CJZu2dUwe8XoGxa8GIvJGIQ58RqydQMTU1f/39JUSEcZH59Avzzhr0hw u4OjgOG7Jtu2JOvBtgOe/ryAD9ly94Advoxj8BgXDON7dT/jVzLBlei7310PCPbfxXjf z1RtU3G9tUoz/jPSIvN1w1FXFzdGtQz5jdYzOlLvumk6JKxT8QZ43/m/5/uZ5wsjC0md BL0+pqB26Z4qb/EaMWgIsSFtEXRd2BirdmpGNEztvm1B1Cs0iCWJ+TJcOpj8FlKQVava CxZbDGR4YwqjcXRskkLu2v0UEo13kXAIK3oiuZgzuA6uuNQ5dDml6D0iJnV2nKVtK7Rn 4ZVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fLaUUyKZV1n5I1oaAK7wF0mjKoazvM828WYSvM0xN9U=; b=r2px37+R5G4BTwF/JS7HQYrgzGkX8UcbYDqs28ZEZL9/Rk/e6HjSNbaAWjsVH52LGQ lfhBjhHkekJM/HVGAHwrt06DJYw55+zciSvj+IrHOlfGkugGXEktBsm7EURAkWjYNwd3 rQ/q6Fz7Uzjs29N34eNwchCSmQKJG5ewEjLojBJdvSK00hr1uxWJy/UQWt2C9n0wPzjV ez/UNwMtPW7zfG3GQ6BrwpzflNDD0I+XHG6pYtxEY4gtlNUo7X7zYitGq3NhdJzkPhkz C7EddKB6yg6PQs6aSCaiSJSCub1pTn4qf1uANceAJheeyMfMbm5jNJQvi873MzkAxYAW umFA== X-Gm-Message-State: AOAM530W0RN/wvPesO4Uy897mIouRRh9Cg0bZJShe7F8rZ8WgNOjoB3R nGVslop3Cb1UB1Mv5Rfe8/mpdLFgarM= X-Google-Smtp-Source: ABdhPJwWe0iclf9Bfkbmx4pOC1sWmREK06Dw6UmzdkgvyEB8jD36VH1Z7UB5GxPuQyfdJbrV+MGjAA== X-Received: by 2002:a62:b60c:0:b029:1ae:6d91:4eb6 with SMTP id j12-20020a62b60c0000b02901ae6d914eb6mr2150198pff.33.1610059966794; Thu, 07 Jan 2021 14:52:46 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a10sm6510603pfi.168.2021.01.07.14.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 14:52:45 -0800 (PST) From: Florian Fainelli To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Du Changbin , Kieran Bingham , Jan Kiszka , Jason Wessel , Daniel Thompson , Andrew Morton , Linus Torvalds , Florian Fainelli , Kieran Bingham , Leonard Crestez , =?utf-8?q?Andr=C3=A9_Draszi?= =?utf-8?q?k?= Subject: [stable 4.9.y 4/4] scripts/gdb: fix lx-version string output Date: Thu, 7 Jan 2021 14:52:29 -0800 Message-Id: <20210107225229.1502459-5-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107225229.1502459-1-f.fainelli@gmail.com> References: <20210107225229.1502459-1-f.fainelli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Du Changbin commit b058809bfc8faeb7b7cae047666e23375a060059 upstream A bug is present in GDB which causes early string termination when parsing variables. This has been reported [0], but we should ensure that we can support at least basic printing of the core kernel strings. For current gdb version (has been tested with 7.3 and 8.1), 'lx-version' only prints one character. (gdb) lx-version L(gdb) This can be fixed by casting 'linux_banner' as (char *). (gdb) lx-version Linux version 4.19.0-rc1+ (changbin@acer) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #21 SMP Sat Sep 1 21:43:30 CST 2018 [0] https://sourceware.org/bugzilla/show_bug.cgi?id=20077 [kbingham@kernel.org: add detail to commit message] Link: http://lkml.kernel.org/r/20181111162035.8356-1-kieran.bingham@ideasonboard.com Fixes: 2d061d999424 ("scripts/gdb: add version command") Signed-off-by: Du Changbin Signed-off-by: Kieran Bingham Acked-by: Jan Kiszka Cc: Jan Kiszka Cc: Jason Wessel Cc: Daniel Thompson Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Florian Fainelli --- scripts/gdb/linux/proc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py index 38b1f09d1cd9..822e3767bc05 100644 --- a/scripts/gdb/linux/proc.py +++ b/scripts/gdb/linux/proc.py @@ -40,7 +40,7 @@ class LxVersion(gdb.Command): def invoke(self, arg, from_tty): # linux_banner should contain a newline - gdb.write(gdb.parse_and_eval("linux_banner").string()) + gdb.write(gdb.parse_and_eval("(char *)linux_banner").string()) LxVersion()