From patchwork Wed Nov 27 14:15:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 180307 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp6179583ilf; Wed, 27 Nov 2019 06:16:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzkXq2r3OyPSa65RIgQ6chTt+av5wXFcvEUZJSqew2WEN2boYGP0vG38T5XaDaEwO04hrnQ X-Received: by 2002:a1c:f00a:: with SMTP id a10mr4470471wmb.167.1574864200633; Wed, 27 Nov 2019 06:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574864200; cv=none; d=google.com; s=arc-20160816; b=xQhA2YLShUlJIXg67divmQjFYpXa38tO9glxwDVMGzuovj+O6IRaO+A6yFYGHog9XW V0SR+YsDvc4GRywqdEb7okh3QXct9OmIt5eeECUUF+vBF3se+hVpMKBlXmgkc0KjhDfn SXjChu+N5e9DEcwV9I1ja27P+2YyiTqQrOoNBQoYWLLpuotpVQMJTspcAY8X6OgDLLp2 fn25tx5vqsPy0hnQXhTgBGWUcE+dT0UnwVczAg66m5hYWFpa1e57s8U31fWQuYuqza4J PgSzCMchLK8QRlWag8WP1gpufq1ooMGhwn9gHFHRrxvyUs8ZTqfBIpaF2oT3RIw5X1/k OwkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CIUhEj1Cxl4mcTC+Hh8o1BVtvNMRQEU53pMe4Z0u5xw=; b=NY045D8AmTTmdzsbUr5qNR/O4U/esr4HFRLZhCIOiCIMgK+kmULzgrqOCuO01TL4pc x313jd6neimqD73LN45+9iqoEIYAEvn/Aa+7ZwRupb4wmFLT5RdbqAxOFPJerTyB4/vg tUZhypKIhPPCkD3tnXnNbPh5dfgBS+7WZfeNgcnyyjrVqe9al8PYm3XSxo47kHK5jLWw s1TGuQYilXicSGuxWJ1RKArm151amkAjKVuYd4t7awXRFDt/3lCge1CdbWdBGd5U/TEV GxwPgVKPmqYzP2LHXfbULkBPK+UV2GqxOcROSz1X4UxnYemR1IcdPBs3+DAjicCRVMu4 sREw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xDtklBSx; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a14si10885844edm.344.2019.11.27.06.16.40; Wed, 27 Nov 2019 06:16:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xDtklBSx; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbfK0OQk (ORCPT + 1 other); Wed, 27 Nov 2019 09:16:40 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:36400 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbfK0OQj (ORCPT ); Wed, 27 Nov 2019 09:16:39 -0500 Received: by mail-yb1-f196.google.com with SMTP id v2so9034823ybo.3 for ; Wed, 27 Nov 2019 06:16:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CIUhEj1Cxl4mcTC+Hh8o1BVtvNMRQEU53pMe4Z0u5xw=; b=xDtklBSxpXCXUM/P4qgJEGo3w98bIz5pGXMkP4B03I3H/9KfBbAJot0wUh1KdzxTEN pxE2oHI6osm1ZQkG3bPbbTLiV8Dew0dg7nLKmFZedMyPR8W3OUTFCW4GvqBpDvKbuDF5 olDE3NFrHm5QpDmOukxyOtmFiGgbRLISKz55cjBh7Njwpj3FQV7LLszpqklMpLAGKWMy 1aArrg6nk/8ND6Ez/LJVOk0HeT+4WE8+lyEMkau4yyuebdZvL/sjiayLmqLU4R01ViXa Leq11dQX1KZdC6zEOAz5V3J8i5ZJpYRHbSFaz+RuzGe3wMwKTCrMn+qvkh8g4lXIH+MF HJzg== 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; bh=CIUhEj1Cxl4mcTC+Hh8o1BVtvNMRQEU53pMe4Z0u5xw=; b=k316ddlfK/NoTcxPJtS7dAnefzu6CsE6Stakv3I6tTGscu7kQflrmbSOEcm/EueTfA Vmm8p5l8Ds6a7CiWtN8ywLgZcQqW51M8pfahIMEjqOE6rhdvkE5hlAckIV2oZs8/Hxvq SLa+N5cLVBVt+wjN7bOQy5OBUKhOUnTPibqGXp6+xUxhprITEX+NawKhpqkqDruGnOf7 lwJLvuJi4FS70qwUChJHIFidvWNb0IpIjKmT66jJtUcfuaB1YZ5LcuvdzKzzGVXT0XmO kJ1a8qXnFDfrKq4E5733LU3xF/Nk0g3OR0KnzJeNeUGrBPNDRnkHXTPN0BLADJ7v7i27 TpoA== X-Gm-Message-State: APjAAAU2EghK04Fsrs1x8mn8KlzICaP7tf7HbSihdBgXVLmH0qW0J2Sc J1bvK4uszsu1xABdM+UDxX429Q== X-Received: by 2002:a25:908d:: with SMTP id t13mr31248482ybl.265.1574864198588; Wed, 27 Nov 2019 06:16:38 -0800 (PST) Received: from localhost.localdomain (li2093-158.members.linode.com. [172.105.159.158]) by smtp.gmail.com with ESMTPSA id u123sm6911115ywd.105.2019.11.27.06.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 06:16:38 -0800 (PST) From: Leo Yan To: Andy Gross , Greg Kroah-Hartman , Jiri Slaby , Bjorn Andersson , Stephen Boyd , Nicolas Dechesne , Jeffrey Hugo , linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v2 1/2] tty: serial: msm_serial: Fix lockup for sysrq and oops Date: Wed, 27 Nov 2019 22:15:43 +0800 Message-Id: <20191127141544.4277-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191127141544.4277-1-leo.yan@linaro.org> References: <20191127141544.4277-1-leo.yan@linaro.org> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org As the commit 677fe555cbfb ("serial: imx: Fix recursive locking bug") has mentioned the uart driver might cause recursive locking between normal printing and the kernel debugging facilities (e.g. sysrq and oops). In the commit it gave out suggestion for fixing recursive locking issue: "The solution is to avoid locking in the sysrq case and trylock in the oops_in_progress case." This patch follows the suggestion (also used the exactly same code with other serial drivers, e.g. amba-pl011.c) to fix the recursive locking issue, this can avoid stuck caused by deadlock and print out log for sysrq and oops. Fixes: 04896a77a97b ("msm_serial: serial driver for MSM7K onboard serial peripheral.") Signed-off-by: Leo Yan --- drivers/tty/serial/msm_serial.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c index 3657a24913fc..889538182e83 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -1576,6 +1576,7 @@ static void __msm_console_write(struct uart_port *port, const char *s, int num_newlines = 0; bool replaced = false; void __iomem *tf; + int locked = 1; if (is_uartdm) tf = port->membase + UARTDM_TF; @@ -1588,7 +1589,13 @@ static void __msm_console_write(struct uart_port *port, const char *s, num_newlines++; count += num_newlines; - spin_lock(&port->lock); + if (port->sysrq) + locked = 0; + else if (oops_in_progress) + locked = spin_trylock(&port->lock); + else + spin_lock(&port->lock); + if (is_uartdm) msm_reset_dm_count(port, count); @@ -1624,7 +1631,9 @@ static void __msm_console_write(struct uart_port *port, const char *s, iowrite32_rep(tf, buf, 1); i += num_chars; } - spin_unlock(&port->lock); + + if (locked) + spin_unlock(&port->lock); } static void msm_console_write(struct console *co, const char *s,