Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp901667pxf; Wed, 7 Apr 2021 14:35:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxldwsW2IiCVPIn/28Upn2a+Qn6tma33jr9Exgb+e/inQiwKEMzuxFJ5BSf15bXQndrlB0M X-Received: by 2002:a05:6402:11c9:: with SMTP id j9mr6990936edw.348.1617831320670; Wed, 07 Apr 2021 14:35:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617831320; cv=none; d=google.com; s=arc-20160816; b=HVVKvLFfa6W1AIjhmpdPD9rNqV1ugPkvzbtK61yV/ja/Gms5Bo1cqisIN755XEUNXc l40LWVdKuXGo/JEtnFlzq3H33fpsQuvXZfpXuEDv5ghTRnU3afQKPxFCSlYD+8NF5eKz LkWCWXnrBnMvpNbCZ3T7oGAy36Nlj8Lzm7C+H71xMgkcW+1nT25bRJJBhDCoBmEEyQYZ UPZcEoiSctSmsa1vxd+LGebfOFDzlEptdFRYxA7SECNgnoUi1MQhbT9lHLsS+StZHrNN xk7rhSqu8yJN1btlDPg7SZrcQMzHFpXzxIshMr1FAxfnIfCMNnaoeNAyfrxlXsFkYl4V Q1LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DiVOnoRaOKWzvOjowAkfK5gmTOofYlhr3RJ2hit0GwM=; b=m6hmj7TRa0dr/tDoEkD1ndlhpKeHdA0uA2EezTKj1Nhr/OhxypZrYl70VAEEl5MF2G eIK8NY8wNiMhnS2FayFAdz7WIsRJzl1ap3xJ+A58Qqz+SKiLmOjXwBZsZ11TIHxBOLVQ MVqPIrhP3F+p/rzMryu5cE192c7cVanOG7GN5vBmAOEf7do2CrocrmtYC2hH1iV2C6ay 7M/hMXItOfvlrGPmAEwzmeD+vKnzUOsBXhaOHHqa58ab2OH4zwvd3PEQgZ9ssjROw+4M 3iovvjV9wTaG3FYuADxf16JXxQgu7sNBOBry5Gwhy9ni6if8I55ZvRr0TO3dt3/FPNDo yG4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="m6AJkn/r"; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si7399256edd.369.2021.04.07.14.34.57; Wed, 07 Apr 2021 14:35:20 -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=@linaro.org header.s=google header.b="m6AJkn/r"; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236600AbhDGQLN (ORCPT + 99 others); Wed, 7 Apr 2021 12:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236529AbhDGQLL (ORCPT ); Wed, 7 Apr 2021 12:11:11 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D726C06175F for ; Wed, 7 Apr 2021 09:11:01 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d124so4406119pfa.13 for ; Wed, 07 Apr 2021 09:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DiVOnoRaOKWzvOjowAkfK5gmTOofYlhr3RJ2hit0GwM=; b=m6AJkn/rVeDyMIthqlgy8KQvKd3h+thfr5PHrr2NxQ7yoFq/nwmn8amXFL4OlD3i4X b4sUW79MlVz2GxS59lNlvqJUMMVdVKpV8JCJHu0pEsaia2VRVGPgKbfSRAJZ96vOQJo1 zWvqWycS5RcdPA4/xRdi6vyFgtj+5CMYEgYqIUASdOJPdcUIFR0n2UiQ31WSor1XjN2R KXVLuVwwSKFQyFImJ+YOoVibjCPABKxSuYvuVVTijpkKwsFwve8z/5XfItsgtcVeQjrK XPdIPTIxii3FJVutW7I/heAvz7/6mf0RSfNbsbrdPd28kBQyFrN6x+8tMqXrgpVKG+uR b1xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DiVOnoRaOKWzvOjowAkfK5gmTOofYlhr3RJ2hit0GwM=; b=a37BB2NMQ8w34AUAQN8JBV5yXyl0ZbzRUNkYtpd5D2TwOHlbw4kj3HckuQryEQvfO4 U2XVpSyJ6r0+a2oS0sS/MCK3wiUA8Oj/xmP1lSsb6RIe96yfNXqZVPmt4bB/6oeJyY+V Udajxzf9Fpozd9Ue94IkJSEUhWr1mEdgvJGr981tgDu6dEpnHORGXkk3oi5UmlZA0vyg QcNfqXEloL4sOKwOecdtqZt+K/KiX+rNmSJoqVyvrkOUrxpBcvWO6DOI5jyH7b6dGtiw 1HNy3Iw5HpX5oSXOQbhKm/d5yIctscXlQ2WezlPhR85uoS57MEmSS51n4+S8iuVtWtGP djjQ== X-Gm-Message-State: AOAM531Vwuz22RxsosB1PSTcbJWmb4vf9q5mVOhiJLJEXJEGBL3odCkP 4piGJhCT8a1qgrN3jt4KhOHsmw== X-Received: by 2002:aa7:9804:0:b029:1f1:5340:77c1 with SMTP id e4-20020aa798040000b02901f1534077c1mr3584600pfl.72.1617811860852; Wed, 07 Apr 2021 09:11:00 -0700 (PDT) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id q19sm22379844pff.91.2021.04.07.09.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 09:11:00 -0700 (PDT) Date: Wed, 7 Apr 2021 10:10:58 -0600 From: Mathieu Poirier To: Suman Anna Cc: Bjorn Andersson , Grzegorz Jaszczyk , Jan Kiszka , Vignesh Raghavendra , Lokesh Vutla , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/3] remoteproc: pru: Fix and cleanup firmware interrupt mapping logic Message-ID: <20210407161058.GA418374@xps15> References: <20210407155641.5501-1-s-anna@ti.com> <20210407155641.5501-4-s-anna@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210407155641.5501-4-s-anna@ti.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 07, 2021 at 10:56:41AM -0500, Suman Anna wrote: > 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. > > Fixes: c75c9fdac66e ("remoteproc: pru: Add support for PRU specific interrupt configuration") > Reported-by: Vignesh Raghavendra > Signed-off-by: Suman Anna > --- > v2: > - Fixed two additional cleanup paths in pru_handle_intrmap() > addressing Mathieu's review comment > v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210323223839.17464-4-s-anna@ti.com/ > > drivers/remoteproc/pru_rproc.c | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) > Reviewed-by: Mathieu Poirier > diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c > index 87b43976c51b..04863bf23db8 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.1 >