From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 69C433A6409 for ; Tue, 14 Apr 2026 08:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776155263; cv=none; b=Q+xGmnJ32d/SdT52oZygjhKJ+S883WH5xoa6YaPb6pr38u3BTZVEyk1nrOKUwTBmlyNb0rx0utbRwgw9dJrtejHJn+breNdZleuaqGLTdzwrJKujotWshFpYREP+Ck0Cv6D9pNX7AsLqZfKtArd9UoN77yAmRA70M3IrsVytOi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776155263; c=relaxed/simple; bh=seC81ngWogUab0Cv00JdZnlQAdPQmT479POgeSqYkGo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q3mT20qamBagblutFZDCXCq63MZdeecAX3vvy8/nvOx194Aq37MrNe2CJnHaxvxcrdW7iQvx8fqIgJRe2cfbuTeYVcQrdvY37vfs0gqPcvzhY2daU20D74gfKRM3vKrJA3vu+tJKmWI3Bz3//gC6m52vhKJzrTPzw9d8o9yqOW0= 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=OTzDxoIH; arc=none smtp.client-ip=209.85.128.45 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="OTzDxoIH" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso50616615e9.1 for ; Tue, 14 Apr 2026 01:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1776155261; x=1776760061; 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=vAoerfiNNrWz161JIQ3021f9av7AFwKNdNb1czdX2oQ=; b=OTzDxoIHnHjGrJIglReSS+op8d69c7NjA/dUE2vUrftByBUm14vSKtzDXeDcfuBqrQ uZpvg+LgvHIhQ78pBI0BC+d3saDQ73MkVrzbSMiWHh5C2QbNXmgsI2ryD/38hGLob87u AvwG716H2XN/dxBJrUuNB0viLHltyJvL5N3ivM1PN5oMhD6pfJ68g/TDar1PZ026MiSb tYqNBt2z2gjsQdiHsta01bl8X3uV4lYiJzHA/AMxZ5EbEExJaGXzsoMiDZUkPNrnfrP4 bAZqBnnEEd3k4xCSBWh966LktyGiZFaNaKyOM702s2o/iKzT/218SNyPq9uB1vmCzQkk kIXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776155261; x=1776760061; 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=vAoerfiNNrWz161JIQ3021f9av7AFwKNdNb1czdX2oQ=; b=LeOzoLUcA8F6B/U8btCliR+TnsHo15uhazksqvZ82Nuif20GwV2qcfEWRo8VsDfQht jFTib8n4ATU9MMGYS03X4YMF/hhfmeo7CSCS1en7C7TW8Pz4+9BoKQuRMR07bDxUWpFH LKlEkvJN3y4KDJAwj1SdlxW4EVWJMYJQP4ST7idIDixJoBU9n03qQMonqir3Li/ijigg dxjhQoGcG186x0NbM6Cz0oDQQ4ZVLbeo+5cVCwmqKU1AUjlJsKoLyMxmJxf8aRedEcu8 Dqfr3PRBjIkU31V4dKNQjk0QrOE5v8oIFV68QaXdZk6ZWCUBRdwt4atu9Dub3DBYPPOB uMsA== X-Forwarded-Encrypted: i=1; AFNElJ8Rl3ozrI/J8Y3AX4nhqXHCK2ezS0kkzvEFQ1dz4d+Y+Llfsjd5jTZfAy3M/+x+qEidel+CvSOEo4GrfpI=@vger.kernel.org X-Gm-Message-State: AOJu0YzSM8p352VWIgk+AiJsUImR9789H1IaTKVvdCLEI/V7hOS7kC4T wjgKKavfGvH1hu+XLRPYEKpFWaWdVYrEnpXHpgF+ukbMnCy5WHb4APEUfJ0qG/pFyDY= X-Gm-Gg: AeBDieujeyL/nIl1DTAqgZgoNt4Dfxw2YQHEYZT9JnN3ycWKZxuTGy1XdwWb0TK4wc+ ql/T4TULZt4GsEWfzmyW23Uw+PiTgP7m/F0fumZBg2W0YJW7cZJjuNj0+Nm7dCxDiZlmX+zN5BO CfV0872FOYqSkLRrhbCeZS951aE9s/VWK6NnqZliWGohysh9V2xyqPmikoG3Gvwm55iUvMSY1s1 S0NmyCXL98JjJqkOKz5Joswhzy6v/0kInI/7lFUMWWEFsHbGnCHr8Yy0hJghWEebkANV2tA0KxJ +1Dlk5tdMa2+LjKURMCbqmwBrqFMCohcKj0ertETLBGXIe/C/IHS7QwNo3+GfA0V9Q9uGcZtkwg D0LzzIiyzBMI7WAfGyuXvTH15lf8NQnaB0kkEpKxw3dkuq8XDQimE5j1psbvQcTsBYlA1IA8jfY tKnXSKdvLkZKjkl6Z2ICSsSjNM64I= X-Received: by 2002:a05:600c:35c7:b0:483:64b4:79da with SMTP id 5b1f17b1804b1-488d68b27d6mr248949515e9.26.1776155260781; Tue, 14 Apr 2026 01:27:40 -0700 (PDT) Received: from linaro.org ([77.64.147.31]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488eddb9751sm54594395e9.0.2026.04.14.01.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 01:27:40 -0700 (PDT) Date: Tue, 14 Apr 2026 10:27:38 +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, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH 2/2] remoteproc: qcom: Check glink->edge in glink_subdev_stop() Message-ID: References: <20260409-rproc-attach-issue-v1-0-088a1c348e7a@oss.qualcomm.com> <20260409-rproc-attach-issue-v1-2-088a1c348e7a@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: On Tue, Apr 14, 2026 at 11:23:50AM +0800, Jingyi Wang wrote: > On 4/10/2026 10:15 PM, Stephan Gerhold wrote: > > On Thu, Apr 09, 2026 at 01:46:22AM -0700, Jingyi Wang wrote: > > > For rproc that doing attach, glink_subdev_start() is called only when > > > attach successfully. If rproc_report_crash() is called in the attach > > > function, rproc_boot_recovery()->rproc_stop()->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 ]--- > > > > > > Add NULL pointer check in the glink_subdev_stop() to make sure > > > qcom_glink_smem_unregister() will not be called if glink_subdev_start() > > > is not called. > > > > > > > You mention the actual root problem here: Why is glink_subdev_stop() > > called if glink_subdev_start() wasn't called? > > > > The call to rproc_start_subdevices() in __rproc_attach() makes sure that > > all subdevices are in consistent state when exiting the function (either > > prepared+started or stopped+unprepared). Only if all subdevices were > > started successfully, the rproc->state is changed to RPROC_ATTACHED. > > > > In your case, attaching the rproc failed so the rproc->state should be > > still RPROC_DETACHED. All subdevices should be stopped+unprepared. We > > shouldn't stop/unprepare any subdevices again in this state, they all > > might crash like glink does here. > > > > We know that subdevices are already stopped+unprepared in RPROC_DETACHED > > state, so I think you just need to skip rproc_stop_subdevices() and > > rproc_unprepare_subdevices() inside rproc_stop() in this case, see diff > > below. > > > > @@ -1708,8 +1709,9 @@ static int rproc_stop(struct rproc *rproc, bool crashed) > > if (!rproc->ops->stop) > > return -EINVAL; > > - /* Stop any subdevices for the remote processor */ > > - rproc_stop_subdevices(rproc, crashed); > > + /* Stop any subdevices for the remote processor if it was attached */ > > + if (rproc->state != RPROC_DETACHED) > > + rproc_stop_subdevices(rproc, crashed); > > /* the installed resource table is no longer accessible */ > > ret = rproc_reset_rsc_table_on_stop(rproc); > > @@ -1726,7 +1728,8 @@ static int rproc_stop(struct rproc *rproc, bool crashed) > > return ret; > > } > > - rproc_unprepare_subdevices(rproc); > > + if (rproc->state != RPROC_DETACHED) > > + rproc_unprepare_subdevices(rproc); > > rproc->state = RPROC_OFFLINE; > > In this case, rproc_crash_handler_work()->rproc_trigger_recovery()-> > rproc_boot_recovery()->rproc_stop()->glink_subdev_stop() is called, > "rproc->state = RPROC_CRASHED" is set in the rproc_crash_handler_work > before rproc_boot_recovery is called, so checking RPROC_DETACHED can > not work for this case. > You're right, I forgot about that. I think we need a more generic solution for this though. rproc_stop_subdevices() should not be called without a prior call to rproc_start_subdevices(). I think there are a couple of options for this: - Add a bool "subdevs_started" to struct rproc and manage that separately from the rproc->state. - Track the rproc state before the crash separately (something like rproc->state_before_crash) and check that in the stop path. - Add a new state RPROC_CRASHED_DETACHED to make sure the states are unique. - ... Does the same issue also exist in qcom_pas_stop() of "[PATCH v5 4/5] remoteproc: qcom: pas: Add late attach support for subsystems" [1]? There you check for pas->rproc->state != RPROC_ATTACHED, wouldn't this also fail for the RPROC_CRASHED case? Thanks, Stephan [1]: https://lore.kernel.org/linux-arm-msm/20260409-knp-soccp-v5-4-805a492124da@oss.qualcomm.com/