From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422677AbcFMJAA (ORCPT ); Mon, 13 Jun 2016 05:00:00 -0400 Received: from foss.arm.com ([217.140.101.70]:49810 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933300AbcFMI77 (ORCPT ); Mon, 13 Jun 2016 04:59:59 -0400 Subject: Re: [PATCH] coresight: Fix erroneous memset in tmc_read_unprepare_etr To: Greg KH References: <1465204301-24184-1-git-send-email-suzuki.poulose@arm.com> <1465554688-28241-1-git-send-email-suzuki.poulose@arm.com> Cc: Mathieu Poirier , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" From: Suzuki K Poulose Message-ID: <575E760C.9030009@arm.com> Date: Mon, 13 Jun 2016 09:59:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/06/16 22:06, Mathieu Poirier wrote: > On 10 June 2016 at 04:31, Suzuki K Poulose wrote: >> At the end of a trace collection, we try to clear the entire buffer >> and enable the ETR back if it was already enabled. But, we would have >> adjusted the drvdata->buf to point to the beginning of the trace data >> in the trace buffer @drvdata->vaddr. So, the following code which >> clears the buffer is dangerous and can cause crashes, like below : >> >> memset(drvdata->buf, 0, drvdata->size); >> >> Unable to handle kernel paging request at virtual address ffffff800a145000 >> pgd = ffffffc974726000 >> *pgd=00000009f3e91003, *pud=00000009f3e91003, *pmd=0000000000000000 >> PREEMPT SMP >> Modules linked in: >> CPU: 4 PID: 1692 Comm: dd Not tainted 4.7.0-rc2+ #1721 >> Hardware name: ARM Juno development board (r0) (DT) >> task: ffffffc9734a0080 ti: ffffffc974460000 task.ti: ffffffc974460000 >> PC is at __memset+0x1ac/0x200 >> LR is at tmc_read_unprepare_etr+0x144/0x1bc >> pc : [] lr : [] pstate: 200001c5 >> ... >> [] __memset+0x1ac/0x200 >> [] tmc_release+0x90/0x94 >> [] __fput+0xa8/0x1ec >> [] ____fput+0xc/0x14 >> [] task_work_run+0xb0/0xe4 >> [] do_notify_resume+0x64/0x6c >> [] work_pending+0x10/0x14 >> Code: 91010108 54ffff4a 8b040108 cb050042 (d50b7428) >> >> Since we clear the buffer anyway in the following call to >> tmc_etr_enable_hw(), remove the erroneous memset(). >> >> Fixes: commit de5461970b3e9e1 ("coresight: tmc: allocating memory when needed") >> Cc: Mathieu Poirier >> Signed-off-by: Suzuki K Poulose >> --- >> >> Mathieu, >> >> I think this should go to 4.7. Please push it. > > If this [1] didn't make it, this one won't make it either. > applied it to my tree for merging in the 4.8 cycle. I think both should go to 4.7, as these fixes real crashes. Greg, We have two fixes [1],[2] for coresight driver which fixes Kernel crashes. Could you please pick them up ? I could resend them, if you would like. [1] https://patchwork.kernel.org/patch/9144589/ [2] https://patchwork.kernel.org/patch/9169407/ Thanks Suzuki > > Thanks, > Mathieu > > >> >> --- >> drivers/hwtracing/coresight/coresight-tmc-etr.c | 9 +++------ >> 1 file changed, 3 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c >> index 69e104b..24d99ed 100644 >> --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c >> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c >> @@ -306,13 +306,10 @@ int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata) >> if (local_read(&drvdata->mode) == CS_MODE_SYSFS) { >> /* >> * The trace run will continue with the same allocated trace >> - * buffer. As such zero-out the buffer so that we don't end >> - * up with stale data. >> - * >> - * Since the tracer is still enabled drvdata::buf >> - * can't be NULL. >> + * buffer. The trace buffer is cleared in tmc_etr_enable_hw(), >> + * so we don't have to explicitly clear it. Also, since the > > Yes, very good. > >> + * tracer is still enabled drvdata::buf can't be NULL. >> */ >> - memset(drvdata->buf, 0, drvdata->size); >> tmc_etr_enable_hw(drvdata); >> } else { >> /* >> -- >> 1.9.1 >> >