Received: by 10.223.164.202 with SMTP id h10csp635950wrb; Wed, 15 Nov 2017 05:39:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMYO8aZXKAbVS2Hbdx7pRI36DmVtAXoST+1zs/mEM+hrWGWDGI8DHtV/uyB1MUqGosMA7knA X-Received: by 10.159.249.73 with SMTP id h9mr5483643pls.6.1510753197516; Wed, 15 Nov 2017 05:39:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510753197; cv=none; d=google.com; s=arc-20160816; b=xnsq422K3ghD10kLmFCDlZkskIjfSpyKRCqSFNe7Ixgeh2aZwdRHCOQembaAEmEEsQ l/Qk56SGFxbug3O4a4EcNn1NJYRo7Oc2RpQUVKmUBNrCgSRFZR/EBUNx3JcISAm2UMrt R9fC1dgrGMW6N8Uyg3R2VSMtFpy+0hYgF53uCP7XUFXPVRKbCLj+exEzamdEK5D8dAwX pk8vGvFqnp7qWYnLJmv3x0umroQHifk5GffT/Uhj3ry3NnoXbvaW4gH5Ie/8wa8LtBZQ yRfwP2otF8f7sozbxLe4XMhUOpF2Q0e6jaO4udGIowK9Or3rWQ9VGf8a70J/GBE8q49M 24vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=NkskGzDM2qD7imSqMi34lQ64fYYo5piYeHsKQHNLlr8=; b=dA9aO+bO0BsBaul7O9ZFFAJgBk5FONfQO9QgiS0EQFWQL8d0QnxrivLeKGJMoz6wSv +KLZE/P4c0yDwUJJ2QvZbNrBmTwmEG5G/WvuhW1+GlM7BSPMs5I4hW5vjDLdzgm0m4pC CfJjKOBeVuwkZoEbatFf5GOFTNbNv+pkJHzh1ZKWBfUKHrYWA1CTpi2TwQMIRSjQHyeD KBo9Z0MVeZCqw8kTRUMWo0BzCHil7W4aQpvb7kyOzHWsEdryVk6JhuNttLPyna+qqKMl VG/yoyZlRT+p6wPGaYLVpd/yCVybh2CrR2Br85BEkcoG6TmmjcFRW/ZR2TRxHua7OTIC /mIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ZkHjiPXi; dkim=pass header.i=@codeaurora.org header.s=default header.b=OPzdY9wR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e32si5917106plb.674.2017.11.15.05.39.45; Wed, 15 Nov 2017 05:39:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@codeaurora.org header.s=default header.b=ZkHjiPXi; dkim=pass header.i=@codeaurora.org header.s=default header.b=OPzdY9wR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932742AbdKONaL (ORCPT + 89 others); Wed, 15 Nov 2017 08:30:11 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:40156 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932291AbdKONaF (ORCPT ); Wed, 15 Nov 2017 08:30:05 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D6C4A60376; Wed, 15 Nov 2017 13:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510752604; bh=Af/tz/gfgdRo/KMej0J5cEtGRe0lgyxA6YhwsR18JJc=; h=From:To:Cc:Subject:Date:From; b=ZkHjiPXi9FttXbYxD82tAif/p4gO3HAkgeEfgsQ/VSinah2Wz0qyTQWavIPg/x+/R pkLAlxhF4xPYuA7Gsvi75dthOzdj3ysqIYgok9YBQPwL9H2cTt9IUEmDesXhzyoFGq UEc7mhRKo6PXK7tzwv0kJjSK73bZRvyHfMKU6JJA= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from chromaggus.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: awallis@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 6B6F560310; Wed, 15 Nov 2017 13:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510752603; bh=Af/tz/gfgdRo/KMej0J5cEtGRe0lgyxA6YhwsR18JJc=; h=From:To:Cc:Subject:Date:From; b=OPzdY9wRzFF3lDDzGShlOpK9aWoQ2+ItmNWriQ67HR6DsuQsdUQ1ZjRb7l35WKJzE 4HjRuDsv/aiCGgYR4fY2+oaqQJuDJuW6sXIliIkaRPeihzhR6Il7VUI/B/+LKJBcvW suJ+xMk467A+qYQqSLAsqFGKNaxwuv8fnt1jn8VE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6B6F560310 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=awallis@codeaurora.org From: Adam Wallis To: linux-arm-kernel@lists.infradead.org, Vinod Koul , Dan Williams , Sinan Kaya , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, shunyong.yang@hxt-semitech.com, rruigrok@codeaurora.org Cc: timur@codeaurora.org Subject: [PATCH v2][for 4.15] dmaengine: dmatest: move callback wait queue to thread context Date: Wed, 15 Nov 2017 08:29:51 -0500 Message-Id: <1510752591-22702-1-git-send-email-awallis@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit adfa543e7314 ("dmatest: don't use set_freezable_with_signal()") introduced a bug (that is in fact documented by the patch commit text) that leaves behind a dangling pointer. Since the done_wait structure is allocated on the stack, future invocations to the DMATEST can produce undesirable results (e.g., corrupted spinlocks). Commit a9df21e34b42 ("dmaengine: dmatest: warn user when dma test times out") attempted to WARN the user that the stack was likely corrupted but did not fix the actual issue. This patch fixes the issue by pushing the wait queue and callback structs into the the thread structure. If a failure occurs due to time, dmaengine_terminate_all will force the callback to safely call wake_up_all() without possibility of using a freed pointer. Cc: stable@vger.kernel.org # 4.13.x: a9df21e: dmatest: Warn User Cc: stable@vger.kernel.org # 4.13.x Cc: stable@vger.kernel.org # 4.14.x Bug: https://bugzilla.kernel.org/show_bug.cgi?id=197605 Reviewed-by: Sinan Kaya Suggested-by: Shunyong Yang Signed-off-by: Adam Wallis --- changes from v1: Added pre-req patches for stable drivers/dma/dmatest.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c index 47edc7f..2573b6c 100644 --- a/drivers/dma/dmatest.c +++ b/drivers/dma/dmatest.c @@ -155,6 +155,12 @@ struct dmatest_params { #define PATTERN_COUNT_MASK 0x1f #define PATTERN_MEMSET_IDX 0x01 +/* poor man's completion - we want to use wait_event_freezable() on it */ +struct dmatest_done { + bool done; + wait_queue_head_t *wait; +}; + struct dmatest_thread { struct list_head node; struct dmatest_info *info; @@ -165,6 +171,8 @@ struct dmatest_thread { u8 **dsts; u8 **udsts; enum dma_transaction_type type; + wait_queue_head_t done_wait; + struct dmatest_done test_done; bool done; }; @@ -342,11 +350,6 @@ static unsigned int dmatest_verify(u8 **bufs, unsigned int start, return error_count; } -/* poor man's completion - we want to use wait_event_freezable() on it */ -struct dmatest_done { - bool done; - wait_queue_head_t *wait; -}; static void dmatest_callback(void *arg) { @@ -424,9 +427,8 @@ static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len) */ static int dmatest_func(void *data) { - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait); struct dmatest_thread *thread = data; - struct dmatest_done done = { .wait = &done_wait }; + struct dmatest_done *done = &thread->test_done; struct dmatest_info *info; struct dmatest_params *params; struct dma_chan *chan; @@ -673,9 +675,9 @@ static int dmatest_func(void *data) continue; } - done.done = false; + done->done = false; tx->callback = dmatest_callback; - tx->callback_param = &done; + tx->callback_param = done; cookie = tx->tx_submit(tx); if (dma_submit_error(cookie)) { @@ -688,21 +690,12 @@ static int dmatest_func(void *data) } dma_async_issue_pending(chan); - wait_event_freezable_timeout(done_wait, done.done, + wait_event_freezable_timeout(thread->done_wait, done->done, msecs_to_jiffies(params->timeout)); status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); - if (!done.done) { - /* - * We're leaving the timed out dma operation with - * dangling pointer to done_wait. To make this - * correct, we'll need to allocate wait_done for - * each test iteration and perform "who's gonna - * free it this time?" dancing. For now, just - * leave it dangling. - */ - WARN(1, "dmatest: Kernel stack may be corrupted!!\n"); + if (!done->done) { dmaengine_unmap_put(um); result("test timed out", total_tests, src_off, dst_off, len, 0); @@ -789,7 +782,7 @@ static int dmatest_func(void *data) dmatest_KBs(runtime, total_len), ret); /* terminate all transfers on specified channels */ - if (ret) + if (ret || failed_tests) dmaengine_terminate_all(chan); thread->done = true; @@ -849,6 +842,8 @@ static int dmatest_add_threads(struct dmatest_info *info, thread->info = info; thread->chan = dtc->chan; thread->type = type; + thread->test_done.wait = &thread->done_wait; + init_waitqueue_head(&thread->done_wait); smp_wmb(); thread->task = kthread_create(dmatest_func, thread, "%s-%s%u", dma_chan_name(chan), op, i); -- Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. From 1583489670814835844@xxx Wed Nov 08 09:30:29 +0000 2017 X-GM-THRID: 1583489605963771438 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread