From patchwork Tue Apr 25 06:19:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 9697545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9AF4E60249 for ; Tue, 25 Apr 2017 06:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86FDA28698 for ; Tue, 25 Apr 2017 06:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 643D12861A; Tue, 25 Apr 2017 06:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5098628630 for ; Tue, 25 Apr 2017 06:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S980605AbdDYGUF (ORCPT ); Tue, 25 Apr 2017 02:20:05 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:33752 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S980587AbdDYGUE (ORCPT ); Tue, 25 Apr 2017 02:20:04 -0400 Received: by mail-pf0-f179.google.com with SMTP id a188so22244847pfa.0 for ; Mon, 24 Apr 2017 23:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=H5Hl30+oo7pucdzSRwZhsCk+JIGW51RxbUaIXNyiWPs=; b=mIf6o2bwaseTLMLVOB642kAlHX4fWgJuLLwxD4Y5jj7toAA5m3qZ+gRAIgUmrz0bHD bf7P7c//+xevkGNkQCgYjPSrZtrk6NNVGspM+oHNWEoxiOz0bxK2NRf+aIBaLzEKaTvH Oh6XwTIxe2ZxMJzYOE5G8mQGk8LUa4pvTR1Yc= 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; bh=H5Hl30+oo7pucdzSRwZhsCk+JIGW51RxbUaIXNyiWPs=; b=SjklV9XTzpnd8R4yi2euyzRN0UqLyNS8ly+gmfueoWUokYbfQqWkJ21SzmCgzifEuD P0NhB03A7vJWPPy6xBp91gRZMUhx2/vAOtX+8iITaW/yD1Jif1xeSpm0+oln60JnXWQ+ RvIv37S/FjJ1mN1CDuHTPTjwFNUF6BhPDUl3IIy0VaiWhy+HXu2QQKUQonXXqkDdkmmO oE0YICv1bnZITtSs+7HNozMZOmZMtgHUh7NjsTEb+HpACkV8SwRJMxc22PcJupwvTp1V GeZMkoF/FofjBckSgQji41FxKXocJLPdr4wmp7Irl+YUjlgmcKBuHg+1AM6raDDCvbd2 Xilw== X-Gm-Message-State: AN3rC/6bhZzWIyK/9dziwNec7MmB2aBbahl4BFiuSrI0oHKjtXZa7gUv QFtqoIiD7FLVnpGU X-Received: by 10.99.55.78 with SMTP id g14mr27468940pgn.191.1493101203613; Mon, 24 Apr 2017 23:20:03 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([100.103.2.117]) by smtp.gmail.com with ESMTPSA id r73sm34017887pfa.65.2017.04.24.23.20.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Apr 2017 23:20:03 -0700 (PDT) From: Alexandre Courbot To: Andrzej Pietrasiewicz , Jacek Anaszewski , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot Subject: [PATCH] [media] s5p-jpeg: fix recursive spinlock acquisition Date: Tue, 25 Apr 2017 15:19:43 +0900 Message-Id: <20170425061943.717-1-acourbot@chromium.org> X-Mailer: git-send-email 2.13.0.rc0.306.g87b477812d-goog Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP v4l2_m2m_job_finish(), which is called from the interrupt handler with slock acquired, can call the device_run() hook immediately if another context was in the queue. This hook also acquires slock, resulting in a deadlock for this scenario. Fix this by releasing slock right before calling v4l2_m2m_job_finish(). This is safe to do as the state of the hardware cannot change before v4l2_m2m_job_finish() is called anyway. Signed-off-by: Alexandre Courbot Acked-by: Jacek Anaszewski --- drivers/media/platform/s5p-jpeg/jpeg-core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c index 52dc7941db65..223b4379929e 100644 --- a/drivers/media/platform/s5p-jpeg/jpeg-core.c +++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c @@ -2642,13 +2642,13 @@ static irqreturn_t s5p_jpeg_irq(int irq, void *dev_id) if (curr_ctx->mode == S5P_JPEG_ENCODE) vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size); v4l2_m2m_buf_done(dst_buf, state); - v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); curr_ctx->subsampling = s5p_jpeg_get_subsampling_mode(jpeg->regs); spin_unlock(&jpeg->slock); s5p_jpeg_clear_int(jpeg->regs); + v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); return IRQ_HANDLED; } @@ -2707,11 +2707,12 @@ static irqreturn_t exynos4_jpeg_irq(int irq, void *priv) v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_ERROR); } - v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); if (jpeg->variant->version == SJPEG_EXYNOS4) curr_ctx->subsampling = exynos4_jpeg_get_frame_fmt(jpeg->regs); spin_unlock(&jpeg->slock); + + v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); return IRQ_HANDLED; } @@ -2770,10 +2771,15 @@ static irqreturn_t exynos3250_jpeg_irq(int irq, void *dev_id) if (curr_ctx->mode == S5P_JPEG_ENCODE) vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size); v4l2_m2m_buf_done(dst_buf, state); - v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); curr_ctx->subsampling = exynos3250_jpeg_get_subsampling_mode(jpeg->regs); + + spin_unlock(&jpeg->slock); + + v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); + return IRQ_HANDLED; + exit_unlock: spin_unlock(&jpeg->slock); return IRQ_HANDLED;