Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp642823ybm; Thu, 28 May 2020 11:28:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTX69eLSdpEeoacFkO02TqUoZ85JoSIML40rvEVZjHZgoLwCxDWMf5Sfe5mOJT4kIjHM+Q X-Received: by 2002:a17:906:49da:: with SMTP id w26mr4174482ejv.548.1590690516840; Thu, 28 May 2020 11:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590690516; cv=none; d=google.com; s=arc-20160816; b=ezgesuZpoaop4dFI5LS6mc7N52Q+hSc80DVNgKoeQQvScVpPIvLn5NG5PHGQkC/nyW cWqjIcPerlSDmZGKRpzpvbn8a77YAPevjzoG8byRkvs64y00sEDpbOIWw3yOoSFX0Yto w0/4cYsYJYv1t4DA+kpSmVTFnX5c6x2nunCA1bOiNH2Oh/fSTYVZHX10mw5zif+qeRkT gsKFo/oIDptpSPSYHBj5Vvgv0+j/RPlx07bRIDyVg0XdWl7wEje3mnZImPe2ROU192yd 0njf5bNJYSNy3KePE3OwF3aUAr/ObRvUwZzePgYRFRLf99QdOk24oY7NYx2kITSlioRe FJTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uL3WL3wjiZS/WqaVMZN+pC1EDFb5Gzm+8f1ZDs/CoM8=; b=YrWVgumyvg/hobs4MLnPy5HDN+vj2UuZjl6r+SaZRPg/qgqgfQ3YYG2x5pFTaCQ16z zGChORUyOHtiDE5mEf1o3/A5hk+AFQ39sr59ZltMCkcgHYEW7msElCvgS0Y58yk7NSAv igrGWC5nf1IzzIjKZRYjSJBEYXBtHlR9nEQEnnIRSnA2AVCguHt32nSIA4sEjs9RsNyb aXMfLFtKiBeiFh4szBvgTrptrqFYqPwfYzkvYjsvIcOM6lfSURqht7kJZVyuoaf5AHeE OZdUQ/pVPLuI3c1G0OED/nir62W925vqWsQKBHFWsB/KrLI2w4pVXq+cMOIbN/vbqMvA j0Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jUoiY6Lw; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fy14si4294666ejb.628.2020.05.28.11.27.54; Thu, 28 May 2020 11:28:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jUoiY6Lw; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405779AbgE1S05 (ORCPT + 99 others); Thu, 28 May 2020 14:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405770AbgE1S0y (ORCPT ); Thu, 28 May 2020 14:26:54 -0400 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 717C3C08C5C7 for ; Thu, 28 May 2020 11:26:54 -0700 (PDT) Received: by mail-vs1-xe43.google.com with SMTP id u7so16338354vsp.7 for ; Thu, 28 May 2020 11:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uL3WL3wjiZS/WqaVMZN+pC1EDFb5Gzm+8f1ZDs/CoM8=; b=jUoiY6LwAn07lRdvLrd7+LZ7B/jHbDcfvdN0Ne3nGHXtGE8ltaz1br+6TuczOyb0EM 6PVc1y9DTOLiZH/DTqEJd/ph2qQvzaSL1LFK16lCvD6rCVKstqKERnU7vy/kO0Y6U6ub 1TChCOSrsNHthGlfltW/Aw6cnWWm1DEMjSSe4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uL3WL3wjiZS/WqaVMZN+pC1EDFb5Gzm+8f1ZDs/CoM8=; b=Ij6UXOKFxVLklnM+JhkjP8ySPDyqe8kZD/9A7VjZ+bYrLB149DHdScAodrm6L/ktkH IaRok0U4RiWXdjicO/K9Opd7twHqqiBN+fYUhL6AzlZ0e+YWxkHNLD6Eyb6i7VxpwigB bAhD3vTzxprFVgJrJja2XW706gRVjtlF/GFahtJFpTMX7BQ8g/duG/8Ufr1dSpRPMfN+ tvVDntLnCCGYVGdZAxes/Yqvm5G5YrH3LwCdt/Xz7CpV74+kGvaHmFnbqP/txRpnGf3L f/NJH68zYZ6V7ioQg0pO0jlzS/5jLfy4gJhmYyabHcC2liL43tM6VjKnjLk+nx1zksVK OmYw== X-Gm-Message-State: AOAM530bCHQoVd/x7Fm5wjChnP0hGhh7XWw5/nTcudZJxAzw+glLMeQM c88mr6w/A0A9QDY2fW3VggQbhLCY+BI/rIVb/OZ7Rg== X-Received: by 2002:a67:d119:: with SMTP id u25mr3001502vsi.96.1590690413360; Thu, 28 May 2020 11:26:53 -0700 (PDT) MIME-Version: 1.0 References: <1590550627-24618-1-git-send-email-zijuhu@codeaurora.org> In-Reply-To: From: Abhishek Pandit-Subedi Date: Thu, 28 May 2020 11:26:40 -0700 Message-ID: Subject: Re: [PATCH v2] bluetooth: hci_qca: Fix QCA6390 memdump failure To: Zijun Hu Cc: Marcel Holtmann , Johan Hedberg , LKML , Bluez mailing list , linux-arm-msm@vger.kernel.org, bgodavar@codeaurora.org, c-hbandi@codeaurora.org, hemantg@codeaurora.org, Matthias Kaehlcke , rjliao@codeaurora.org Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi, On Wed, May 27, 2020 at 11:19 PM Zijun Hu wrote: > > > > On 5/28/2020 11:42 AM, Abhishek Pandit-Subedi wrote: > > Hi Zijun, > > > > On Tue, May 26, 2020 at 8:37 PM Zijun Hu wrote: > >> > >> QCA6390 memdump VSE sometimes come to bluetooth driver > >> with wrong sequence number as illustrated as follows: > >> frame # in DEC: frame data in HEX > >> 1396: ff fd 01 08 74 05 00 37 8f 14 > >> 1397: ff fd 01 08 75 05 00 ff bf 38 > >> 1414: ff fd 01 08 86 05 00 fb 5e 4b > >> 1399: ff fd 01 08 77 05 00 f3 44 0a > >> 1400: ff fd 01 08 78 05 00 ca f7 41 > >> it is mistook for controller missing packets, so results > >> in page fault after overwriting memdump buffer allocated. > >> > >> it is fixed by ignoring QCA6390 sequence number error > >> and checking buffer space before writing. > >> > >> Signed-off-by: Zijun Hu > >> --- > >> drivers/bluetooth/hci_qca.c | 45 ++++++++++++++++++++++++++++++++++++++------- > >> 1 file changed, 38 insertions(+), 7 deletions(-) > >> > >> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c > >> index e4a6823..388fe01b 100644 > >> --- a/drivers/bluetooth/hci_qca.c > >> +++ b/drivers/bluetooth/hci_qca.c > >> @@ -114,6 +114,7 @@ struct qca_memdump_data { > >> char *memdump_buf_tail; > >> u32 current_seq_no; > >> u32 received_dump; > >> + u32 ram_dump_size; > >> }; > >> > >> struct qca_memdump_event_hdr { > >> @@ -976,6 +977,8 @@ static void qca_controller_memdump(struct work_struct *work) > >> char nullBuff[QCA_DUMP_PACKET_SIZE] = { 0 }; > >> u16 seq_no; > >> u32 dump_size; > >> + u32 rx_size; > >> + enum qca_btsoc_type soc_type = qca_soc_type(hu); > >> > >> while ((skb = skb_dequeue(&qca->rx_memdump_q))) { > >> > >> @@ -1029,6 +1032,7 @@ static void qca_controller_memdump(struct work_struct *work) > >> > >> skb_pull(skb, sizeof(dump_size)); > >> memdump_buf = vmalloc(dump_size); > >> + qca_memdump->ram_dump_size = dump_size; > >> qca_memdump->memdump_buf_head = memdump_buf; > >> qca_memdump->memdump_buf_tail = memdump_buf; > >> } > >> @@ -1052,25 +1056,52 @@ static void qca_controller_memdump(struct work_struct *work) > >> * packets in the buffer. > >> */ > >> while ((seq_no > qca_memdump->current_seq_no + 1) && > >> + (soc_type != QCA_QCA6390) && > > > > This probably shouldn't be SOC specific. > > > make sense. but this logic block should be skipped for QCA6390 > the present logic to fix controller missing packets for the other products > is not suitable for QCA6390. for QCA6390, it doesn't miss packet and sequence > number field of the packet maybe have data error, but serdev driver doesn't propagate > these error info detected by UART driver to bluetooth driver. so the sequence number > extracted from packet received is not reliable. Ok -- then I think it would be clearer to just set seq_no = qca_memdump->current_seq_no for QCA6390 and leave a comment about it. > > >> seq_no != QCA_LAST_SEQUENCE_NUM) { > >> bt_dev_err(hu->hdev, "QCA controller missed packet:%d", > >> qca_memdump->current_seq_no); > >> + rx_size = qca_memdump->received_dump; > >> + rx_size += QCA_DUMP_PACKET_SIZE; > >> + if (rx_size > qca_memdump->ram_dump_size) { > >> + bt_dev_err(hu->hdev, > >> + "QCA memdump received %d, no space for missed packet", > >> + qca_memdump->received_dump); > >> + break; > >> + } > >> memcpy(memdump_buf, nullBuff, QCA_DUMP_PACKET_SIZE); > >> memdump_buf = memdump_buf + QCA_DUMP_PACKET_SIZE; > >> qca_memdump->received_dump += QCA_DUMP_PACKET_SIZE; > >> qca_memdump->current_seq_no++; > >> } > > > > You can replace this loop with a memset(memdump_buf, 0, (seq_no - > > qca_memdump->current_seq_no) * QCA_DUMP_PACKET_SIZE). This simplifies > > the ram_dump_size check as well because it won't zero fill until the > > end anymore (meaning a single bad seq_no doesn't make the rest of the > > dump incorrect). > > > i don't think so > as explained above, the sequence number is not reliable, so we can't memset buffer > area calculated from seqence number. i just dump all the packets we received without > any handling for QCA6390. I suggest the following: /* For QCA6390, ignore the seq_no and always assume packets are in order */ if (soc_type == QCA_QCA6390 && seq_no != QCA_LAST_SEQUENCE_NUM) { seq_no = qca_memdump->current_seq_no; } else if (seq_no > qca_memdump->current_seq_no && seq_no != QCA_LAST_SEQUENCE_NUM) { /* For bounds checking, add the sizes of the current pkt + the number of missing pkts. * If the given seq_no exceeds the allocated size of the dump, assume the seq_no is * wrong. */ rx_size = (seq_no - qca_memdump->current_seq_no) * QCA_DUMP_PACKET_SIZE; if (rx_size + skb->len <= (qca_memdump->ram_dump_size - qca_memdump->received_dump)) { memset(memdump_buf, 0, rx_size); memdump_buf += rx_size; qca_memdump->received_dump += rx_size; qca_memdump->current_seq_no = seq_no; } else { seq_no = qca_memdump->current_seq_no; } } > >> > >> - memcpy(memdump_buf, (unsigned char *) skb->data, skb->len); > >> - memdump_buf = memdump_buf + skb->len; > >> - qca_memdump->memdump_buf_tail = memdump_buf; > >> - qca_memdump->current_seq_no = seq_no + 1; > >> - qca_memdump->received_dump += skb->len; > >> + rx_size = qca_memdump->received_dump + skb->len; > >> + if (rx_size <= qca_memdump->ram_dump_size) { > >> + if ((seq_no != QCA_LAST_SEQUENCE_NUM) && > >> + (seq_no != qca_memdump->current_seq_no)) > >> + bt_dev_err(hu->hdev, > >> + "QCA memdump unexpected packet %d", > >> + seq_no); This message doesn't make sense here anymore and should be removed. > >> + bt_dev_dbg(hu->hdev, > >> + "QCA memdump packet %d with length %d", > >> + seq_no, skb->len); > >> + memcpy(memdump_buf, (unsigned char *)skb->data, > >> + skb->len); > >> + memdump_buf = memdump_buf + skb->len; > >> + qca_memdump->memdump_buf_tail = memdump_buf; > >> + qca_memdump->current_seq_no = seq_no + 1; > >> + qca_memdump->received_dump += skb->len; > >> + } else { > >> + bt_dev_err(hu->hdev, > >> + "QCA memdump received %d, no space for packet %d", > >> + qca_memdump->received_dump, seq_no); > >> + } > >> qca->qca_memdump = qca_memdump; > >> kfree_skb(skb); > >> if (seq_no == QCA_LAST_SEQUENCE_NUM) { > >> - bt_dev_info(hu->hdev, "QCA writing crash dump of size %d bytes", > >> - qca_memdump->received_dump); > >> + bt_dev_info(hu->hdev, > >> + "QCA memdump Done, received %d, total %d", > >> + qca_memdump->received_dump, > >> + qca_memdump->ram_dump_size); > >> memdump_buf = qca_memdump->memdump_buf_head; > >> dev_coredumpv(&hu->serdev->dev, memdump_buf, > >> qca_memdump->received_dump, GFP_KERNEL); > >> -- > >> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project > >> > > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project