Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3035135pxj; Mon, 17 May 2021 16:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrcBBof8i9n8h8T68X5DNYStfaoS5vxpIjBIU3x7TXjOiGlO9i3mIMsXdXT/24PK66iL28 X-Received: by 2002:a17:906:3e97:: with SMTP id a23mr2531765ejj.440.1621292807305; Mon, 17 May 2021 16:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621292807; cv=none; d=google.com; s=arc-20160816; b=qfPhnohFRSlOVBad6RaIUYDp+0Wp2mW3vLYoSC0plSDs1pEDADZx13ugYT8PRSHWj+ Aqgszw2Rn7gFNETCXfphiJJweduA5ejEQNPV3jkrm7f7FHy2cx0vEpeIAnc+QUZxlxjS uF8qvSIg8Js2GtSzFn+utQwVd237/fpzvdyRZuACDqmMsyCKV8u82lqOIpNT7QtedVF0 WOFVnjtZdOGtJ0WqGOaZX8I5HnTCAqYpfi0duqYzxSd+hVOiCTQ2Rl7YQZ8RJTYE1nkx f1hebC3sYlUPnM7OtdK7Tfmj+k5MgeR3ebEydHU7C1yQE4y64bsmzUnit4ab11tTzMBa yj/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VGSTFpTQ/4R6qZXhCUrd3VyIn2lUJKA53jntbasPxTc=; b=PXOiuE0WuwYGOdYKJqU2A3iHi9SeSF4MVIMZn9+MYLKIlSZxAGJ63exnHqryrqvPak 7xgXLsfNldkIQ3hejfi2I/iGOv05BUHl+9pGAxQ3huFmJ/zlCf9SlHgjkEw9SpkZdFhD SuEoxDfDSKyutF743ram18FEkqMruMBMTAsKOu0V8rcGsozny0XQUfMcB3HOZAbVm6Bk kS6k7eD75u+xdZksuL14r6AJNwjR83IvNjA/gUOtCYTH9UMy1o2UsdVuZ3o4Gax6KSfU ehsw5Z92l3eaS2DvUXnul2LsYSlwKvhp4c8ANlXRMpLihI/cVbZiA2mRj2BY3uYHNj9C ItOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dov4wqld; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs16si15538400ejc.156.2021.05.17.16.06.24; Mon, 17 May 2021 16:06:47 -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=pass header.i=@linuxfoundation.org header.s=korg header.b=Dov4wqld; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237052AbhEQOUa (ORCPT + 99 others); Mon, 17 May 2021 10:20:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:58640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238726AbhEQORD (ORCPT ); Mon, 17 May 2021 10:17:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7E3860698; Mon, 17 May 2021 14:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260603; bh=xLutIPXd40xSoRJUslveawDzG4kGbUS0s7SQymDKaeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dov4wqldE1dPz0V95nqIwTZvOJeVB7qqbpAlP9TvRiJ9XT8Z/B13b8VbGFuzExPH4 U0TQRzgKR8u2zKcSx9Spk6YmhmhknA3FBo0X4c/y0WxgbAxCULBmNXwkATw5QGFcPe 8OMrRq+eTTFmAfhvtF6CmMempHcnijrFnMPvr9Pc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Poirier , Vignesh Raghavendra , Suman Anna , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.12 157/363] remoteproc: pru: Fix and cleanup firmware interrupt mapping logic Date: Mon, 17 May 2021 16:00:23 +0200 Message-Id: <20210517140307.916543961@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suman Anna [ Upstream commit 880a66e026fbe6a17cd59fe0ee942bbad62a6c26 ] The PRU firmware interrupt mappings are configured and unconfigured in .start() and .stop() callbacks respectively using the variables 'evt_count' and a 'mapped_irq' pointer. These variables are modified only during these callbacks but are not re-initialized/reset properly during unwind or failure paths. These stale values caused a kernel crash while stopping a PRU remoteproc running a different firmware with no events on a subsequent run after a previous run that was running a firmware with events. Fix this crash by ensuring that the evt_count is 0 and the mapped_irq pointer is set to NULL in pru_dispose_irq_mapping(). Also, reset these variables properly during any failures in the .start() callback. While at this, the pru_dispose_irq_mapping() callsites are all made to look the same, moving any conditional logic to inside the function. Reviewed-by: Mathieu Poirier Fixes: c75c9fdac66e ("remoteproc: pru: Add support for PRU specific interrupt configuration") Reported-by: Vignesh Raghavendra Signed-off-by: Suman Anna Link: https://lore.kernel.org/r/20210407155641.5501-4-s-anna@ti.com Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/remoteproc/pru_rproc.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c index dcd5ea0d1f37..549ed3fed625 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -266,12 +266,17 @@ static void pru_rproc_create_debug_entries(struct rproc *rproc) static void pru_dispose_irq_mapping(struct pru_rproc *pru) { - while (pru->evt_count--) { + if (!pru->mapped_irq) + return; + + while (pru->evt_count) { + pru->evt_count--; if (pru->mapped_irq[pru->evt_count] > 0) irq_dispose_mapping(pru->mapped_irq[pru->evt_count]); } kfree(pru->mapped_irq); + pru->mapped_irq = NULL; } /* @@ -307,8 +312,10 @@ static int pru_handle_intrmap(struct rproc *rproc) pru->evt_count = rsc->num_evts; pru->mapped_irq = kcalloc(pru->evt_count, sizeof(unsigned int), GFP_KERNEL); - if (!pru->mapped_irq) + if (!pru->mapped_irq) { + pru->evt_count = 0; return -ENOMEM; + } /* * parse and fill in system event to interrupt channel and @@ -317,13 +324,19 @@ static int pru_handle_intrmap(struct rproc *rproc) * corresponding sibling PRUSS INTC node. */ parent = of_get_parent(dev_of_node(pru->dev)); - if (!parent) + if (!parent) { + kfree(pru->mapped_irq); + pru->mapped_irq = NULL; + pru->evt_count = 0; return -ENODEV; + } irq_parent = of_get_child_by_name(parent, "interrupt-controller"); of_node_put(parent); if (!irq_parent) { kfree(pru->mapped_irq); + pru->mapped_irq = NULL; + pru->evt_count = 0; return -ENODEV; } @@ -398,8 +411,7 @@ static int pru_rproc_stop(struct rproc *rproc) pru_control_write_reg(pru, PRU_CTRL_CTRL, val); /* dispose irq mapping - new firmware can provide new mapping */ - if (pru->mapped_irq) - pru_dispose_irq_mapping(pru); + pru_dispose_irq_mapping(pru); return 0; } -- 2.30.2