Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp32138pxu; Sat, 21 Nov 2020 21:45:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV21xCLD6sau70ShzqFcG1rSdF6MNBQ29xBBG+imD/lwMozLyyJ+qdh0y+7fB11d56zT6c X-Received: by 2002:aa7:da8f:: with SMTP id q15mr16492785eds.229.1606023949122; Sat, 21 Nov 2020 21:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606023949; cv=none; d=google.com; s=arc-20160816; b=bo0WEybzaYCV94BFd40Daftxl9E1IfdQPhcV305e8JNdlR6kWgToV6QNXJoY5ShwO4 +bk41jfDSjUBgNRvXWfD2m8aD5XSCAD9Hz9acwhAhtsmuj5ZWAgVw3VT3QcoLaSkV6Kh N45g0QLo6si3drRSQX1c6YF1lw2smwDL91JYIuwE/Q1vv3YTioTVy6m0YNs2KhX0roeh 0InuhPqSN+5hTmcdfBMwT0eIEjBcBfh8X3K6AyF4QHrDqqgy0vPOMlGP50yyhkyDgo2e eWKwC+9THiwThvx2sqMzf83XtgZK6qBvNAF8c2ALh3HDG8s2OJe78lMNjZJ6cwFQvX90 cB+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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yQvyFDM0JjV69fRQJvQbh4EUUpGYP88ib4fx5c7S58s=; b=x8YvVuOSgRfglE61CgGkd6zlp5LZrflEn17vgGjX9rWmyvyRxU5Y+I64onwhb7Zwh+ gYswe2Egkc2+XrgxL7yu/zr6Eh3hq9HXyx6Ebyr21P6gOjHW+IlGhncX2/gTfZ8xTPrW 7ZPHDuyrHyVKzbZwgMC2RaCA8pIk1xURWiYysGkG9Xg5oxUt39rbdTskQyERROE3jvfi Kj84X9s06NIFpMsinmD9bfEb0UJ/dwOL0Y6YQNhP7KjExHhAVUvDH+cI90UrbykrDGwS u+34ia/PGGoxCs65v9l7nqC8c5xOq7w7o47HM8WeqKSK5MBdJ5v0VPqH8xXidjr0ZDCE k65A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mJBunxM5; 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 hr4si4258398ejc.486.2020.11.21.21.45.26; Sat, 21 Nov 2020 21:45:49 -0800 (PST) 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=mJBunxM5; 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 S1727358AbgKVFlh (ORCPT + 99 others); Sun, 22 Nov 2020 00:41:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbgKVFle (ORCPT ); Sun, 22 Nov 2020 00:41:34 -0500 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFFFBC0613D3 for ; Sat, 21 Nov 2020 21:41:34 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id s18so14678975oih.1 for ; Sat, 21 Nov 2020 21:41:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yQvyFDM0JjV69fRQJvQbh4EUUpGYP88ib4fx5c7S58s=; b=mJBunxM5mgkzBeH2Zqtr83SqxLzRQSI7jClSU564b/d8b94UJKf0ItjyaU8DOysg9q c2qrBo8aHMdfR9hFXUBrTuIndVRUWnODvuOoejC55fXbmlNn/YwzSESZOD/40gvxinXC Wvd3n8E82XsOpQlCJclCsN+Tbf5AAzNUhsp9Qpc9dTYWz9oLvdK+BPp2+S8sI+8Fj4xT AkZJ/sAcKBw4adkSr0cQMyyDeMTuuwYzOes78AZLUJ9otLcg12Rx5f4U8Xs7wNSSENWN ppDjxUS4l2njr6Cm53FAz6F95SPpOhxtr95nOCHLdfngcggTtw3lm2iBNOTZmutjWhDE vTLQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=yQvyFDM0JjV69fRQJvQbh4EUUpGYP88ib4fx5c7S58s=; b=VlgL2kTSEcf6NACapHXdzS4EfWCA+NRuVVnGrBsWY36vPPPO/yU9DsS6Foit/ZFNa8 +LmYPyc1fquXeZG5wEpkjLA+/LmftimzM1vlSqzOTGLrsC4c1Ae1CjwPnxF9mnxNxtGC yJpvknaMK6rNf58fVq4dT3lZlD4F4ay4t608qdySjSLKIh81mEfIvH9EsOLNFOsAGKVl SSA7cUKJ3V4LaUdyFxfJ6l9i63c6aP5fkOfxVf7PigiPa8lRV3bnxYihHAdXT9wMalFf /2UU++PxH3sic5EIwGjMsAPjm2I3EUkj9SmK4Oe7vFEfsUujP+OY19qtgQTUnlqE69lE sPcQ== X-Gm-Message-State: AOAM530mHGknb5kW1EbYXtqPUVAjcmu7rQM7bOTXYfdciqD48HYEIk1J fhKMNjhuciQu3KBcn3GdYeBDhQ== X-Received: by 2002:a54:4608:: with SMTP id p8mr11536251oip.5.1606023694131; Sat, 21 Nov 2020 21:41:34 -0800 (PST) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id s28sm4303132otr.4.2020.11.21.21.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 21:41:33 -0800 (PST) From: Bjorn Andersson To: Andy Gross , Bjorn Andersson , Ohad Ben-Cohen , Siddharth Gupta Cc: Mathieu Poirier , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3 1/4] remoteproc: sysmon: Ensure remote notification ordering Date: Sat, 21 Nov 2020 21:41:32 -0800 Message-Id: <20201122054135.802935-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201122054135.802935-1-bjorn.andersson@linaro.org> References: <20201122054135.802935-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The reliance on the remoteproc's state for determining when to send sysmon notifications to a remote processor is racy with regard to concurrent remoteproc operations. Further more the advertisement of the state of other remote processor to a newly started remote processor might not only send the wrong state, but might result in a stream of state changes that are out of order. Address this by introducing state tracking within the sysmon instances themselves and extend the locking to ensure that the notifications are consistent with this state. Fixes: 1f36ab3f6e3b ("remoteproc: sysmon: Inform current rproc about all active rprocs") Fixes: 1877f54f75ad ("remoteproc: sysmon: Add notifications for events") Fixes: 1fb82ee806d1 ("remoteproc: qcom: Introduce sysmon") Cc: stable@vger.kernel.org Signed-off-by: Bjorn Andersson --- Changes since v2: - Hold sysmon_lock during traversal of sysmons in sysmon_start() drivers/remoteproc/qcom_sysmon.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c index 9eb2f6bccea6..b37b111b15b3 100644 --- a/drivers/remoteproc/qcom_sysmon.c +++ b/drivers/remoteproc/qcom_sysmon.c @@ -22,6 +22,9 @@ struct qcom_sysmon { struct rproc_subdev subdev; struct rproc *rproc; + int state; + struct mutex state_lock; + struct list_head node; const char *name; @@ -448,7 +451,10 @@ static int sysmon_prepare(struct rproc_subdev *subdev) .ssr_event = SSCTL_SSR_EVENT_BEFORE_POWERUP }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_BEFORE_POWERUP; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); return 0; } @@ -472,20 +478,25 @@ static int sysmon_start(struct rproc_subdev *subdev) .ssr_event = SSCTL_SSR_EVENT_AFTER_POWERUP }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_AFTER_POWERUP; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); mutex_lock(&sysmon_lock); list_for_each_entry(target, &sysmon_list, node) { - if (target == sysmon || - target->rproc->state != RPROC_RUNNING) + if (target == sysmon) continue; + mutex_lock(&target->state_lock); event.subsys_name = target->name; + event.ssr_event = target->state; if (sysmon->ssctl_version == 2) ssctl_send_event(sysmon, &event); else if (sysmon->ept) sysmon_send_event(sysmon, &event); + mutex_unlock(&target->state_lock); } mutex_unlock(&sysmon_lock); @@ -500,7 +511,10 @@ static void sysmon_stop(struct rproc_subdev *subdev, bool crashed) .ssr_event = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); /* Don't request graceful shutdown if we've crashed */ if (crashed) @@ -521,7 +535,10 @@ static void sysmon_unprepare(struct rproc_subdev *subdev) .ssr_event = SSCTL_SSR_EVENT_AFTER_SHUTDOWN }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_AFTER_SHUTDOWN; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); } /** @@ -534,11 +551,10 @@ static int sysmon_notify(struct notifier_block *nb, unsigned long event, void *data) { struct qcom_sysmon *sysmon = container_of(nb, struct qcom_sysmon, nb); - struct rproc *rproc = sysmon->rproc; struct sysmon_event *sysmon_event = data; /* Skip non-running rprocs and the originating instance */ - if (rproc->state != RPROC_RUNNING || + if (sysmon->state != SSCTL_SSR_EVENT_AFTER_POWERUP || !strcmp(sysmon_event->subsys_name, sysmon->name)) { dev_dbg(sysmon->dev, "not notifying %s\n", sysmon->name); return NOTIFY_DONE; @@ -591,6 +607,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, init_completion(&sysmon->ind_comp); init_completion(&sysmon->shutdown_comp); mutex_init(&sysmon->lock); + mutex_init(&sysmon->state_lock); sysmon->shutdown_irq = of_irq_get_byname(sysmon->dev->of_node, "shutdown-ack"); -- 2.28.0