Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4272616pxa; Mon, 10 Aug 2020 05:33:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5+uHsRJTEUca48SyXiRCLRWe9JkveOhQkEumNh6R0P8f4DYh9Cuxxyhoot/qfWLTqc34V X-Received: by 2002:a17:906:cc4d:: with SMTP id mm13mr20785897ejb.191.1597062826002; Mon, 10 Aug 2020 05:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597062825; cv=none; d=google.com; s=arc-20160816; b=O2ZCN9928u+/ueAgLgGHvMDVn38hG/eW5U/zjswf//sludWfhyStNDm6TswQ6xCJYZ jiawd9bm9oEcHG6a6g10tXxCvP5rORlxofaqn/BL6RJdIxug52xsP8X+gHuf8AtnKI2T Ir16VDpIHeXB72J2oFI2iyV4lCBi8+aWekvgdZBciF1HO2EqO3HQ/FE1aAGCa527NHy5 ibEtqjo3djKmct4ECNalAZ7+cgWmlEbv8dOdELxZazQSuNRoxSdVr8thuhat5Om9FySe RGw+huE+SaLdkirCdfsKUFxKX3ucSLUEIQta7hbK6fZFJcwXKaRwShBJJRXL1iAB07da mwqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature; bh=YATn2IQenXC1AZhlnO1R/hOYwlccU9AexyRTM+qvl5Y=; b=fdXmXKIjD8f6KOgR/gDyD1jZlUiPxqWlHWQIxyaxvYCEIENq1cZitZMB+x/1NFiclw hgH2mPQtNXXAgDHw1hwIADYrFQ8trJ26HWXfiTFdff3tdsS/jfDHbOKrUT7g32cJjIeE DwdmrVnOVKQavG/h9kNS1+q0ZCexFObr/Yks7ZpvopwhRQph0p/uTjAHbMZvp3ZpjRpR SNj6iPAVChEI453rttkazX8zD3cH46NG5aAJDciAOFgCYjWzH/oFCRwg/6HNYyFHlK7/ g7hrRSLviKjP+oapWp3cg6Z56DxZm629ZkHTbwtPpvmaeSroXrfkOIdHuR+cPjWWVCOM gtwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=k3lBQMah; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si10121239edv.257.2020.08.10.05.33.22; Mon, 10 Aug 2020 05:33:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=k3lBQMah; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbgHJMcc (ORCPT + 99 others); Mon, 10 Aug 2020 08:32:32 -0400 Received: from mail29.static.mailgun.info ([104.130.122.29]:61112 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgHJMcb (ORCPT ); Mon, 10 Aug 2020 08:32:31 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1597062750; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=YATn2IQenXC1AZhlnO1R/hOYwlccU9AexyRTM+qvl5Y=; b=k3lBQMahbpo0p8P3wFhF41SFJCshrNNG9XCHIFpA2GNYEEKrYC4ZPyraMd5yA5CFcZXmiO4l 5ApxJ2rOU+Otg6MbHOImfLAXhOqNlQ3qJCeXTwxA1bFjJ3eBK78so7gS+CSe7BRhJ2+pEqpj syuY7BH8EoT0dbD5P9yuuvmVdK8= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n09.prod.us-west-2.postgun.com with SMTP id 5f313e49d96d28d61e297dee (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 10 Aug 2020 12:32:09 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id EEE58C4339C; Mon, 10 Aug 2020 12:32:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,NICE_REPLY_A, SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from [192.168.1.100] (unknown [47.8.236.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: akashast) by smtp.codeaurora.org (Postfix) with ESMTPSA id 04822C433C6; Mon, 10 Aug 2020 12:32:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 04822C433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=akashast@codeaurora.org Subject: Re: [PATCH] serial: qcom_geni_serial: Fix recent kdb hang To: Douglas Anderson , Greg Kroah-Hartman Cc: kgdb-bugreport@lists.sourceforge.net, Mukesh Savaliya , Andy Gross , Bjorn Andersson , Evan Green , Jiri Slaby , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org References: <20200806221904.1.I4455ff86f0ef5281c2a0cd0a4712db614548a5ca@changeid> From: Akash Asthana Message-ID: Date: Mon, 10 Aug 2020 18:01:54 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200806221904.1.I4455ff86f0ef5281c2a0cd0a4712db614548a5ca@changeid> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Doug, On 8/7/2020 10:49 AM, Douglas Anderson wrote: > The commit e42d6c3ec0c7 ("serial: qcom_geni_serial: Make kgdb work > even if UART isn't console") worked pretty well and I've been doing a > lot of debugging with it. However, recently I typed "dmesg" in kdb > and then held the space key down to scroll through the pagination. My > device hung. This was repeatable and I found that it was introduced > with the aforementioned commit. > > It turns out that there are some strange boundary cases in geni where > in some weird situations it will signal RX_LAST but then will put 0 in > RX_LAST_BYTE. This means that the entire last FIFO entry is valid. IMO that means we received a word in RX_FIFO and it is the last word hence RX_LAST bit is set. RX_LAST_BYTE is 0 means none of the bytes are valid in the last word. In such scenario we should just read RX_FIFO buffer (to empty it), discard the word and return NO_POLL_CHAR. Something like below. ---------------------------------------------------------------------------------------------------------------------------------------------------------                 else                         private_data->poll_cached_bytes_cnt = 4;                 private_data->poll_cached_bytes =                         readl(uport->membase + SE_GENI_RX_FIFOn);         } +        if (!private_data->poll_cached_bytes_cnt) +              return NO_POLL_CHAR;         private_data->poll_cached_bytes_cnt--;         ret = private_data->poll_cached_bytes & 0xff; ------------------------------------------------------------------------------------------------------------------------------------------------------------- Please let me know whether above code helps. I am not sure about what all scenario can leads to this behavior from hardware, I will try to get an answer from hardware team. Any error bit was set for SE_GENI_S_IRQ_STATUS & SE_GENI_M_IRQ_STATUS registers? I guess the hang was seen because *poll_cached_bytes_cnt* is unsigned int and it's value was 0, when it's decremented by 1 it's value become '4294967295' (very large) and dummy RX (0x00) would happen that many times before reading any actual RX transfers/bytes. Regards, Akash > This weird corner case is handled in qcom_geni_serial_handle_rx() > where you can see that we only honor RX_LAST_BYTE if RX_LAST is set > _and_ RX_LAST_BYTE is non-zero. If either of these is not true we use > BYTES_PER_FIFO_WORD (4) for the size of the last FIFO word. > > Let's fix kgdb. While at it, also use the proper #define for 4. > > Fixes: e42d6c3ec0c7 ("serial: qcom_geni_serial: Make kgdb work even if UART isn't console") > Signed-off-by: Douglas Anderson > --- > > drivers/tty/serial/qcom_geni_serial.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c > index 07b7b6b05b8b..e27077656939 100644 > --- a/drivers/tty/serial/qcom_geni_serial.c > +++ b/drivers/tty/serial/qcom_geni_serial.c > @@ -361,11 +361,16 @@ static int qcom_geni_serial_get_char(struct uart_port *uport) > return NO_POLL_CHAR; > > if (word_cnt == 1 && (status & RX_LAST)) > + /* > + * NOTE: If RX_LAST_BYTE_VALID is 0 it needs to be > + * treated as if it was BYTES_PER_FIFO_WORD. > + */ > private_data->poll_cached_bytes_cnt = > (status & RX_LAST_BYTE_VALID_MSK) >> > RX_LAST_BYTE_VALID_SHFT; > - else > - private_data->poll_cached_bytes_cnt = 4; > + > + if (private_data->poll_cached_bytes_cnt == 0) > + private_data->poll_cached_bytes_cnt = BYTES_PER_FIFO_WORD; > > private_data->poll_cached_bytes = > readl(uport->membase + SE_GENI_RX_FIFOn); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project