From patchwork Thu Nov 5 04:50:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 320585 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp153159ilc; Wed, 4 Nov 2020 20:50:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwe5+IF/QcZlrLOhxDhgpC2yH9M0SACGqWxEQ1Xll4GnsILbonUuiZXNYAEk8dV/vUpQRBr X-Received: by 2002:aa7:d992:: with SMTP id u18mr747195eds.284.1604551834038; Wed, 04 Nov 2020 20:50:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604551834; cv=none; d=google.com; s=arc-20160816; b=W3S3XO1QZw6fR0Md68eq9teqoFVxEa39Q8coSgdS4LgsJou3UW0jiwy8brSmqT/mMs +Wf/soPbAzCscQXucinTxeXgBuErb2gVkd+XHPDS3hl+IygbaQ3NZ2rNhen+y1HxKm7a rzK4mF/tHD4IkUTZuviGENtIjlwtRTMOZYbUwHeCbxUdF/zAsdiLB70mpdEy8WNnRLbL YzwoS5ca8FlTtJVZJpZw/Qxq2VbvMuySAJCO2/UV/BppfLhuZ6uxxOgxMuxTq3CQbCRn wqxrTlUwQI6HMDuE3Zb9BmdLe9FuISigA4Gvz1evnM6QhFfFt2JgsRpnbXzWxlC+Ng20 p7ww== 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=FvjwOA4E4EU4uWdZHjmur5yZGUS7qBISeC6b1M+D3zM=; b=X3YXPYY/82tE9gIpbCKgd0yT9GmzgubwZtJpI47naVKwsg9DVy8XWfvRGHwEWG5dJi V1e9x71OxG2vocmByConncFahF3zWeEE3dUL23cxmGHtQntJXBMEiF1efjfhfg4cUgoA QO0wCNqCs+s7J5M1TMtavtuA/NtLNqmlTDREnIL22NY2Lp6Dos/irqC1akYcmDYsDJhY jNaU99PoTjB25E/lXKBWEKK7WVFpXjwSxOL2ndICSd9ZmImtHeAf9ha/0DEjGAF8SQEn TfnKTEDc0oQcHES6XMlg4IUvMN4Kf/4xh1279dPNxarXfWrghjwAZZ/tF5O/17xiB7A/ Iu8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tiU9APlP; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 e4si348426edr.585.2020.11.04.20.50.33; Wed, 04 Nov 2020 20:50:34 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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=tiU9APlP; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1730370AbgKEEuc (ORCPT + 15 others); Wed, 4 Nov 2020 23:50:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbgKEEuc (ORCPT ); Wed, 4 Nov 2020 23:50:32 -0500 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DA2CC061A4A for ; Wed, 4 Nov 2020 20:50:32 -0800 (PST) Received: by mail-ot1-x344.google.com with SMTP id g19so255332otp.13 for ; Wed, 04 Nov 2020 20:50:32 -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=FvjwOA4E4EU4uWdZHjmur5yZGUS7qBISeC6b1M+D3zM=; b=tiU9APlPLOoAxUJp76XWPjX0w6Bzx0nGeeJFMUVVCicmATSCu0ouGOStpsm7KH2jwB K7hHvMnRwOoRvfihBotW5GprFltQEStY9Jfm7q+4st4EWnGOTU73Jx2M75hpCfe5Hr6L MF83qfpHNGdRLhGlFU2btE7KJchSHqtEQa3AjnqgjvJB3lQJ/zMbDsXJahAIUwoGiciE Ht1H91HmQnTJG7/5Vos+NVVvdPLXNllP3efOkrwybSR/pIyClUEMvO6FANa7IFG0sKWz 60dlWyzlKq+eLg2Wbu4oJqMqTyOdVtDlFW3Pdc/Dsc5Y6Golc1qyTigYMINObZ1xh4fq WFHA== 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=FvjwOA4E4EU4uWdZHjmur5yZGUS7qBISeC6b1M+D3zM=; b=CYNIhK07BHESlNVd6/toDd5s53I7NOCoF0XX0fuJUOmP3dom0oHa/gE2UlMOgTW2W+ ZTGykJ5XquyQsQLc5B4v+uDoVrxFkJZhJCQRnvhJOzpTUkEoKmJjCYaLbrLeyLrfyDj0 4aRatZjFa737Z8ch9DhFKdLaZGtjnmoKB5GJGrE72ob+UZrtcxVwd40rGDsL7tfLyo+j /gzX604lmDcz8evC8BgTfZFttJeDQoeZNLP8xrm+BELF8tHOE2BFo34E2TueIJbEbl+V hnS5W3WFTbL9rVo9YmiMpS58pF1/eIx43RBwEeXg183Vta/ejzvLrAa3Fr50yui8gqqV yKNw== X-Gm-Message-State: AOAM533+wYpNsHPxigFLkMsAwlPIYewBYP4rrNSmTNLi4o/bo0edBzZ9 WZGDTwW5nP9y1PIRzCAs8YUwHg14s4tBjg== X-Received: by 2002:a9d:60d:: with SMTP id 13mr468308otn.366.1604551831750; Wed, 04 Nov 2020 20:50:31 -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 k13sm100553ooi.41.2020.11.04.20.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 20:50:31 -0800 (PST) From: Bjorn Andersson To: Andy Gross , Bjorn Andersson , Ohad Ben-Cohen , Siddharth Gupta , Sibi Sankar Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/4] remoteproc: sysmon: Ensure remote notification ordering Date: Wed, 4 Nov 2020 20:50:48 -0800 Message-Id: <20201105045051.1365780-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201105045051.1365780-1-bjorn.andersson@linaro.org> References: <20201105045051.1365780-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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 v1: - Reduced the locking to be per sysmon instance - Dropped unused local "rproc" variable in sysmon_notify() drivers/remoteproc/qcom_sysmon.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) -- 2.28.0 diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c index 9eb2f6bccea6..38f63c968fa8 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,22 +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); return 0; } @@ -500,7 +509,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 +533,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 +549,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 +605,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");