Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2231734imu; Thu, 17 Jan 2019 10:30:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN6uPG1F/ZBXloulDb0eMJMw9Vz0PVu3xZ3uqJKn2x8OafzhkvUsJnQbAqOjg0Moa41CzWPz X-Received: by 2002:a63:bf0b:: with SMTP id v11mr14708878pgf.302.1547749857520; Thu, 17 Jan 2019 10:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547749857; cv=none; d=google.com; s=arc-20160816; b=DnQp3EfgpYvFMSYDQxPLom88o0U4dVl4fIh3IhtXYEKjydAm8Lxyx8a4zzZYTPxTt8 6F8trd/Virez2Qt8TXlTQp4l4hoIiWRsLDEimSk1AWyC7tk0rmex8/K8vwvQWpe6b7+F M+16cmroMcNdkyoVuMSOE+yO9d4aE5pEeQX1wLtKJ9FaDvnkihVuNk11D3M7bg73Hgh3 B/Dpe8vbJZpE8u7hbOedWDGZu4gMcPQ1wBfppU7RSIlZEYQ6lysyV2auX91+WLyVVEWA nFSH1NDfgjr0u+dnxjMvS8qAAqm4xs5PzhRa9zwmDzT/quyMN2MlO6kdYzMZRHUsIMLo W0dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JYwxidj+UlC9J8m7R8E8uZr+X7AneZl9KiO0sSarm0w=; b=DiJyW7bckzu3SOjKL+K58+ZKLFNizAv7R5ApH2Zj6829Iu8Aucg7azWzMb+GEXi9i1 YEaKZaS3fDTY/iK7ibos6btAYomZH3qXs/wiCc938ShJrzax0Nta5ppAHxUeEP6DlyZt Qd5BIMVIJ98/kmaErN3CPl5ZbID9i/7heO1Y5Jnf5tcOrqTS9mgyVqPt50y9s6BM3Btw Slmh5mg4gfg/2POqs4Atm1rA/xY/hpUENWv4Ov8ogF2S66YHtl2wPZ2M+FIdbkSvyWeK DwxLp1wkZypLoMcAtwDml/OEXCk9URqEEsuBQexcBtgXsXOW/7hfiQhF2IqruyEK355o uMFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PBK6T36z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b12si2188578pls.32.2019.01.17.10.30.41; Thu, 17 Jan 2019 10:30:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PBK6T36z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727777AbfAQSAM (ORCPT + 99 others); Thu, 17 Jan 2019 13:00:12 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34422 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbfAQSAM (ORCPT ); Thu, 17 Jan 2019 13:00:12 -0500 Received: by mail-pg1-f196.google.com with SMTP id j10so4782115pga.1 for ; Thu, 17 Jan 2019 10:00:11 -0800 (PST) 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:user-agent; bh=JYwxidj+UlC9J8m7R8E8uZr+X7AneZl9KiO0sSarm0w=; b=PBK6T36zWujzaNSnM7l6vEMDi0/KwlbOcZV6QJZWzTWq3nCYiodzeV0fCWBigW9YJz 3FIvLeyVAue1B8ruMB20QMlCin3rzVMBQw8jGhACOfb/dnKkZP5pwha4ldanI1W1rjIy kwXLn6knDMZonZ/sxobUr0RUJ3FhUzDnmEFdg= 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:user-agent; bh=JYwxidj+UlC9J8m7R8E8uZr+X7AneZl9KiO0sSarm0w=; b=XFbvD/nyg0Iu0RyOJA9XKf7fXBkAOJSUNTwrrRPsywhf14K6fmIxNBMJbtiibyceXM hvruPFQSFy6LAhE6O10luTBVpFqP44FihfeWomd309JVQqLoyYGxk9bVvyqerKm2F+5d TtYCC+EhDzAtdkmwmDFFd+VrPKU56HMHjZsKJR+SR63CWSCbVdIzzboEDsNC2cx7+j8L BIPmzwfe9gP6H3qg8nTMIyuWQCLGz21ZZNibKVr1HE3gCx7xpbUapXMPNxhVVG8yO1fm X0Dd1arxvC3+jHOtTMHRw8WOyFghX0CkoVmDueTTGwIbnjLsPWmaeBJ63sHQ1gumRot0 KzDA== X-Gm-Message-State: AJcUukcpQqnDMaVwTxzmgNDzQdkapRg236qSJaGnUse7W97xOQsfA+h+ zujvSaeQf/gWeZXB1SwAfJa5EA== X-Received: by 2002:a65:5387:: with SMTP id x7mr14427393pgq.412.1547748010797; Thu, 17 Jan 2019 10:00:10 -0800 (PST) Received: from minitux (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id b202sm5351959pfb.88.2019.01.17.10.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 10:00:10 -0800 (PST) Date: Thu, 17 Jan 2019 10:00:07 -0800 From: Bjorn Andersson To: Loic PALLARDY Cc: xiang xiao , "ohad@wizery.com" , "linux-remoteproc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Arnaud POULIQUEN , "benjamin.gaignard@linaro.org" , "s-anna@ti.com" Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure Message-ID: <20190117180007.GX9278@minitux> References: <1547031403-34535-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 14 Jan 12:23 PST 2019, Loic PALLARDY wrote: > Hi Xiang, > > > -----Original Message----- > > From: xiang xiao > > Sent: samedi 12 janvier 2019 19:29 > > To: Loic PALLARDY > > Cc: bjorn.andersson@linaro.org; ohad@wizery.com; linux- > > remoteproc@vger.kernel.org; linux-kernel@vger.kernel.org; Arnaud > > POULIQUEN ; benjamin.gaignard@linaro.org; s- > > anna@ti.com > > Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure > > Thanks Loic for picking this up again. > > Hi Loic, > > The change just hide the problem, I think. The big issue is: > > 1.virtio devices aren't destroyed by rpproc_stop > Virtio devices are destroyed by rproc_stop() as vdev is registered as rproc sub device. > rproc_stop() is calling rproc_stop_subdevices() which is in charge of removing virtio device and associated children. > rproc_vdev_do_stop() --> rproc_remove_virtio_dev() --> unregister_virtio_device() > Xiang is right, unregister_virtio_device() ends up decrementing the refcount of device and might free it, but it's not guaranteed. So I think we need to decouple the rproc_vdev and virtio_device, to allow the latter to potentially outlive the prior. > Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are removed and re-inserted correctly > root@stm32mp1:~# ls /dev/ttyRPMSG* > /dev/ttyRPMSG0 /dev/ttyRPMSG1 > root@stm32mp1:~# [ 154.832523] remoteproc remoteproc0: crash detected in m4: type watchdog > [ 154.837725] remoteproc remoteproc0: handling crash #2 in m4 > [ 154.843319] remoteproc remoteproc0: recovering m4 > [ 154.849185] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: rpmsg tty device 0 is removed > [ 154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty device 1 is removed > [ 155.382327] remoteproc remoteproc0: warning: remote FW shutdown without ack > [ 155.387857] remoteproc remoteproc0: stopped remote processor m4 > [ 155.398988] m4@0#vdev0buffer: assigned reserved memory node vdev0buffer@10044000 > [ 155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel addr 0x0 > [ 155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel: 0x400 -> 0x0 : ttyRPMSG0 > [ 155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel addr 0x1 > [ 155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel: 0x401 -> 0x1 : ttyRPMSG1 > [ 155.437338] virtio_rpmsg_bus virtio0: rpmsg host is online > [ 155.442401] m4@0#vdev0buffer: registered virtio0 (type 7) > [ 155.461154] remoteproc remoteproc0: remote processor m4 is now up > ls /dev/ttyRPMSG* > /dev/ttyRPMSG0 /dev/ttyRPMSG1 > root@stm32mp1:~# > > As vdev is including in a larger struct allocated by rproc, it is safe > to set it to 0 before initializing virtio device while rproc subdevice > sequence is respected. > It's likely that this works in most use cases, but if for some reason there's additional references held those will operate on the object past your clearing of it. Regards, Bjorn > > 2.and then rpmsg child devices aren't destroyed too > > Then, when the remote start and create rpmsg channel again, the > > duplicated channel will appear in kernel. > > To fix this problem, we need go through rpproc_shutdown/rproc_boot to > > destroy all devices(virtio and rpmsg) and create them again. > Rproc_shutdown/rproc_boot is solving the issue too, except if rproc_boot() was called several times and so rproc->power atomic not equal to 1. > Using only rproc_stop() and rproc_start() allows to preserve rproc->power and so to be silent from rproc user pov. > > Regards, > Loic > > > > Thanks > > Xiang > > > > On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy wrote: > > > > > > Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify recovery path > > > to use rproc_{start,stop}()") replaces rproc_{shutdown,boot}() with > > > rproc_{stop,start}(), which skips destroy the virtio device at stop > > > but re-initializes it again at start. > > > > > > Issue is that struct virtio_dev is not correctly reinitialized like done > > > at initial allocation thanks to kzalloc() and kobject is considered as > > > already initialized by kernel. That is due to the fact struct virtio_dev > > > is allocated and released at vdev resource handling level managed and > > > virtio device is registered and unregistered at rproc subdevices level. > > > > > > This patch initializes struct virtio_dev to 0 before using it and > > > registering it. > > > > > > Fixes: 7e83cab824a8 ("remoteproc: Modify recovery path to use > > rproc_{start,stop}()") > > > > > > Reported-by: Xiang Xiao > > > Signed-off-by: Loic Pallardy > > > --- > > > drivers/remoteproc/remoteproc_virtio.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/remoteproc/remoteproc_virtio.c > > b/drivers/remoteproc/remoteproc_virtio.c > > > index 183fc42a510a..88eade99395c 100644 > > > --- a/drivers/remoteproc/remoteproc_virtio.c > > > +++ b/drivers/remoteproc/remoteproc_virtio.c > > > @@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, > > int id) > > > struct virtio_device *vdev = &rvdev->vdev; > > > int ret; > > > > > > + /* Reset vdev struct as you don't know how it has been previously > > used */ > > > + memset(vdev, 0, sizeof(struct virtio_device)); > > > vdev->id.device = id, > > > vdev->config = &rproc_virtio_config_ops, > > > vdev->dev.parent = dev; > > > -- > > > 2.7.4 > > >