From patchwork Fri May 22 10:56:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 187147 Delivered-To: patches@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2384961ilb; Fri, 22 May 2020 03:57:12 -0700 (PDT) X-Received: by 2002:a63:1a11:: with SMTP id a17mr13315367pga.227.1590145032637; Fri, 22 May 2020 03:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590145032; cv=none; d=google.com; s=arc-20160816; b=JUeoqrs8y/r9BW+A1839CIm2w1o2FHBGtFXIXkFlMM+IYdBV+xTsEWhhkdBk3BsnwH foecmo3o3Ya4seUaHeDyHcNu8USiIfJF829nr7XDJ/E+8GwnjoTnivE0q4bst9DhQQbL wO6GRmZ9LwDxmYqCwMWenwivlq4RkVHwecQ9dGcHwLYqw+i8xVVtjhjKHd1+JtyWZdsl aWizzVu9zHwj6TvBTGsj/bX0wk1zP2jaxCuPMv29pxgtfBDPm8V6VWpA3jgkxB4Imn8g c5hRGVUhI6HekyTvz8Q/XZ7THCTwKmfTQpl1V0frJTUyBsGz//Idf3gOq/EcU4JWrq3U 1Shw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=XbAbqhq+unVwIg9uKq66qARtp8J8Upab6bqriejYl48=; b=xLRTPaG86SB4RLStBWHUynbcBsRyXWXZAmIlo8lpF9Ag17zQBQpYrmeRt4Y/zVeUdT 2pUnpjV0/r4H+b3RG0DQ8rhrHvCybkOMNshcSTmEmdnzVZSoopFYjTZ33BKRKEQUtvTO tYCGA/J/iUP7K2TOi+8piqxaNGhVew4BuBAMYnNfqQKHCvFAlJCI6dCcaNAm0gA4kLBn VR5Hfex+K+upJbwI7K9zBhnCwsSpM1yyVvJsGnJoBzytnhALyeSKygnk/d+PFBwm6erI EyvswgWNwnrCz5vqRj+4eQxDjqrCeGkNTKzdTtzGQur0QQe/1Vp1wbY2hAMXRyNof9Zy 5jdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mmYbCwnw; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a19sor10917008pfg.41.2020.05.22.03.57.12 for (Google Transport Security); Fri, 22 May 2020 03:57:12 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mmYbCwnw; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=XbAbqhq+unVwIg9uKq66qARtp8J8Upab6bqriejYl48=; b=mmYbCwnwOJLKkKIBFIPNakjsF94R59hgIoFop4hCWVckf8E95Ryqpl5LrI17hmLx9b VrazunkoQNXEohpcvBihmgW918qpFt5lsQI56ohGsvQ3TZO/KIzpXPIdAe17wnOU4z4s v58qAe0sED2I4ywCtfka91LQHaO2YU/aIhLEBNceh9Nc+cDuc0Kwk9ebIEBEYDNOQcRS Bnuhaq8ph2Up8uuSbWTrit0CSLnqyjsUfFcD9T79h+0+8ks4Pv7LIULVFsfT8M+P3uQc cn8Go3R/yR4kJFK+Te27NlG+xlHcnm2tY8VKwLmqBlqdFFmrB4rtIRj0Bw4aBO4tpwZK abng== 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; bh=XbAbqhq+unVwIg9uKq66qARtp8J8Upab6bqriejYl48=; b=mgpD924xcUeTn3FNeD3/0jm3IMMEAMm2duttQJiNpF/Um/bi7lgz3bXOR9vRhMy2+J b9VCRt39DVcEHxpUBXMYtCm+8H15vwEANF9w2kQ96cMXAqBXWMPGM0Z43Nvjptfa7Xka mP8UCUZtCgfg6vnQrIBHJbuZWy6frka/y4dLaIXtuXEv2lGubzH3qSt7ikc0uxrVY4c7 4owomDECC4Gc34LeNkwGxRzT31IywLFZaaH3XB9vYDBo6iTMF219lYbhQAZo1acmX7g9 2pAOzUwGkNrMjDAcMYjntTwFvdMahNoDcGM3AjNOlavzc/mwFPM2k3evtf5hVaiimv6z z0bA== X-Gm-Message-State: AOAM532e4AhM3bYxmfg66zmnsfFsEgAnHcUOmmtbcp947lMxpRtY7UhI OPK/W7wsIjwHB/5mAh2kc1LL4AF3 X-Google-Smtp-Source: ABdhPJxRTwAJ6Gx6+odbTPNeYK6pOxiwrZ++PP7hX3MuGGowatOBvIS5qthJJt7vr51e6TEIBu47Bw== X-Received: by 2002:a62:2cd7:: with SMTP id s206mr3191373pfs.183.1590145032153; Fri, 22 May 2020 03:57:12 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.252.68.136]) by smtp.gmail.com with ESMTPSA id j24sm6168726pga.51.2020.05.22.03.57.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 May 2020 03:57:11 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [INTERNAL REVIEW] kdb: Switch kdb_printf to use safer console poll APIs Date: Fri, 22 May 2020 16:26:46 +0530 Message-Id: <1590145006-15823-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In kgdb NMI context, polling driver APIs are more safer to use instead of console APIs since the polling drivers know they will execute from all sorts of crazy places. And for the most common use cases this would also result in no console handler ever being called. So switch to use polling driver APIs in case a particular console supports polling mode. Suggested-by: Daniel Thompson Signed-off-by: Sumit Garg --- Please confirm if this is as per your suggestion and all kgdb modes should work fine. If yes, then I will post this patch in upstream. kernel/debug/kdb/kdb_io.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index e32ece6..86cc416 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "kdb_private.h" #define CMD_BUFLEN 256 @@ -699,11 +700,26 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) } } for_each_console(c) { + int line; + struct tty_driver *p; + if (!(c->flags & CON_ENABLED)) continue; - bust_spinlocks(1); - c->write(c, cp, retlen - (cp - kdb_buffer)); - bust_spinlocks(0); + + p = c->device ? c->device(c, &line) : NULL; + if (p && p->ops && p->ops->poll_init && + !p->ops->poll_init(p, line, NULL)) { + len = retlen - (cp - kdb_buffer); + cp2 = cp; + while (len--) { + p->ops->poll_put_char(p, line, *cp2); + cp2++; + } + } else { + bust_spinlocks(1); + c->write(c, cp, retlen - (cp - kdb_buffer)); + bust_spinlocks(0); + } touch_nmi_watchdog(); } } @@ -765,11 +781,25 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) } } for_each_console(c) { + int line; + struct tty_driver *p; + if (!(c->flags & CON_ENABLED)) continue; - bust_spinlocks(1); - c->write(c, moreprompt, strlen(moreprompt)); - bust_spinlocks(0); + p = c->device ? c->device(c, &line) : NULL; + if (p && p->ops && p->ops->poll_init && + !p->ops->poll_init(p, line, NULL)) { + len = strlen(moreprompt); + cp = moreprompt; + while (len--) { + p->ops->poll_put_char(p, line, *cp); + cp++; + } + } else { + bust_spinlocks(1); + c->write(c, moreprompt, strlen(moreprompt)); + bust_spinlocks(0); + } touch_nmi_watchdog(); }