From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60F9837E2FF for ; Fri, 22 May 2026 12:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779452092; cv=none; b=ajO2/ZBdG58YREESdV8MJVpvPKrCrEZyBi+Y8YCr0Yqd5XmzaYS2QxVyG6PUo+PeubLujFZ/LiNT8Y+Csa468KMaztKYGFx5bUUluPvUu90wgOlTQwVk1I5OudXYBmyKn1pCPPy5LygxYE4ag+NqgDvWA7Tj6ZkvBDHPJqdazLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779452092; c=relaxed/simple; bh=Z7WYvrDcaqVs+7anYHSzDEo0GveQb9WfUn9Sv2ufkrU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jArLyjEm3HsTXBCpW5BL8xt/+RDqO78WtRzSF8YU/Zf50WG6oGAsJ77Prdx9InAdF1UGRjSJDUKtWs8QadAZF7Qi7HyBiNK4LDkp0bXUCf0/nGzNOc0igV5HVG41r3RpqfyW7Ro7K7N9okAaQzK4Yf4WaGiUv+DhjJty/33VmeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=m0Fsud1G; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="m0Fsud1G" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-43d7e23defbso4098586f8f.0 for ; Fri, 22 May 2026 05:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779452089; x=1780056889; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=90y7x6sel2hIxCCCCElmz6nzXLa/RsMCG0kg8p2DOaI=; b=m0Fsud1Gxp0A8SkTR5C0pRKApqBj6JUPahFYoDWh2ptUal5BCx/UXuw2RUloFw91gf q3JN5vRkU3sjFH96HQWK5i47SG4xsiaXIzrboaBJvLeXxqDgbV17aA4XwmZf8P25OlzG mugxOEsLwPsvFz41oMp7hXimqM9Gta1TNm33zmhkGhjWN4Jl/XbLtuZ8sTALwmqRpMbr WfOc0oTzYvEozAusYkjQZBR7uNbNvwUy9/E5ZhQLSLwzpKoz2TVxDYWt2p/QCeCYQeAN GaylET7RT/8qNeI0QEY3dbf3FFdGznURXuppwfsrZK1nWaF7cOvU5JYYd5/4oyBU4ad8 eoqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779452089; x=1780056889; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=90y7x6sel2hIxCCCCElmz6nzXLa/RsMCG0kg8p2DOaI=; b=D2y8TJK/OLDrl9AAtjJef1SZ7GY9m1LmAsYjOJ7FbuLrhfXXbjih3z7uqKZZfAY6Pv hhJK+HwLKKV+iLDid2jrxNxKYHb0MZtp31l/8BeLaT0Hgf5pDXuxiAzaD5IZxFh/mPcT erIRSf6KnKa6HBCk6a2MGl70ZCyeDTDcp5Lzx5UBj0Jd0owtuyapQwbMNjPqOVeKbJsF v6kpahO4g+sEPM1ljhAYn8HCR1jqdkzNHDBwnE0XXowa/uGDvuJXeWKlHRSlBO0qM8qU AR832fjKUvxxyHOz9zfFzjNHgEx/xBZSviwCH8fMKgTc/M95tO8HzAGxi5YUGqPA0e3F Gq6A== X-Forwarded-Encrypted: i=1; AFNElJ9xgx7mW3OBflGzCdV+6YIZ1NJgdss4C7HnDRcLp+RFvMizOEZE2BqDpfKXKVVDx1eC4wNsQxHsPdyVVds=@vger.kernel.org X-Gm-Message-State: AOJu0YxpyKvtQDfBFUVn+ykf5PX8dwNJNeEZ9Ad9XjC+jwbPOC7WKK3z vpJyzkXh1spAedrevm9dbc8xG67/s3+dLo+lQN67HMZ7iVmdfz1Qe4QcpC3XsgQG6qs= X-Gm-Gg: Acq92OERPcRH2bljtl3eNRrdTS6Swk9xHvJYwHRpz45MsHkxt3LDjdSFy7vxsKPuMOO HrBLwTglGMX3edJ3gqi8wz9584nSD1sYmUzzYa1tIqc1zgQQGcNElzYqMHj8Q+IItFlF/njIRVj HiGwGYML5wIWbBedwrP8W/7hYLQHv3ZpFn9KcMRwII8y4Tm/Jr+rNFp+7bVaarLDabcunmVsUdc Jvy6laBNybLI9ceChqIk+GaIcuhEUYiX9hmeSMz4vA1cfGQaXXehzdW0Fy7ExISx7o6sjjc7K4e sj+yur8l8dMKkFQAMpAu2Zqd7ZlilAmlvw+dB/0VKciNKSrhrt4M8IbNEPWmYpYREpkd6FIr5+X ou83pGO3FPb8qeOc1KJxMkun9yw3yU6rfdcWJ8F1Y1XR6tCNdAdN7P1S4N5vhkQUzdQD3VHZ3hL BseXyB3OLbRsNnPCAWrEr7d+qZi37S X-Received: by 2002:a05:600c:4ecc:b0:488:a824:fdff with SMTP id 5b1f17b1804b1-490426d190cmr45585095e9.22.1779452088697; Fri, 22 May 2026 05:14:48 -0700 (PDT) Received: from linaro.org ([77.64.147.221]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4904527526dsm43297775e9.4.2026.05.22.05.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 05:14:48 -0700 (PDT) Date: Fri, 22 May 2026 14:14:46 +0200 From: Stephan Gerhold To: Jingyi Wang Cc: Bjorn Andersson , Mathieu Poirier , aiqun.yu@oss.qualcomm.com, tingwei.zhang@oss.qualcomm.com, trilok.soni@oss.qualcomm.com, yijie.yang@oss.qualcomm.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] remoteproc: core: Check subdev start status in rproc_stop() Message-ID: References: <20260519-rproc-attach-issue-v2-0-caa1eaf75081@oss.qualcomm.com> <20260519-rproc-attach-issue-v2-2-caa1eaf75081@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260519-rproc-attach-issue-v2-2-caa1eaf75081@oss.qualcomm.com> On Tue, May 19, 2026 at 12:20:03AM -0700, Jingyi Wang wrote: > For rproc that doing attach, rproc_start_subdevices() is called only when > attach successfully. If rproc_report_crash() is called in the attach > function, rproc_boot_recovery()->rproc_stop()->rproc_stop_subdevices()-> > glink_subdev_stop() could be called and cause NULL pointer dereference: > > Unable to handle kernel NULL pointer dereference at virtual address 0000000000000300 > Mem abort info: > ... > pc : qcom_glink_smem_unregister+0x14/0x48 [qcom_glink_smem] > lr : glink_subdev_stop+0x1c/0x30 [qcom_common] > ... > Call trace: > qcom_glink_smem_unregister+0x14/0x48 [qcom_glink_smem] (P) > glink_subdev_stop+0x1c/0x30 [qcom_common] > rproc_stop+0x58/0x17c > rproc_trigger_recovery+0xb0/0x150 > rproc_crash_handler_work+0xa4/0xc4 > process_scheduled_works+0x18c/0x2d8 > worker_thread+0x144/0x280 > kthread+0x124/0x138 > ret_from_fork+0x10/0x20 > Code: a9be7bfd 910003fd a90153f3 aa0003f3 (b9430000) > ---[ end trace 0000000000000000 ]--- > > Introduce "subdevs_started" flag to indicate rproc_start_subdevices() has > been called successfully. Ensure subdevices are only stopped if they have > been started. > > Signed-off-by: Jingyi Wang > --- > drivers/remoteproc/remoteproc_core.c | 4 +++- > include/linux/remoteproc.h | 2 ++ > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index f02db1113fae..6e23cb11e515 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1308,6 +1308,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) > goto stop_rproc; > } > > + rproc->subdevs_started = true; > rproc->state = RPROC_RUNNING; > > dev_info(dev, "remote processor %s is now up\n", rproc->name); > @@ -1712,7 +1713,8 @@ static int rproc_stop(struct rproc *rproc, bool crashed) > return -EINVAL; > > /* Stop any subdevices for the remote processor */ > - rproc_stop_subdevices(rproc, crashed); > + if (rproc->subdevs_started) > + rproc_stop_subdevices(rproc, crashed); Thanks, this approach looks better. But where do we clear this flag? Shouldn't we do that here? In addition, I think we also need to set subdevs_started = true if attach succeeds. And clear it when detaching a remoteproc. I think you just need to update all the callers of rproc_stop_subdevices() and rproc_start_subdevices(). Or, which is probably simpler, just make the check directly inside these two functions to cover all users. Thanks, Stephan