Skip to contentSkip to conversation

remoteproc: fix recovery procedure

PATCH Superseded Loic Pallardy 3 participants 13 messages Jan 9, 2019 – Jan 21, 2019 Remote processor (remoteproc)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: fix recovery procedure

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}()")
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/remoteproc/remoteproc_virtio.c +2 -0
index 183fc42a510a..88eade99395c 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw

Hi Loic,
The change just hide the problem, I think. The big issue is:
1.virtio devices aren't destroyed by rpproc_stop
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.

Thanks
Xiang

Quoted 39 lines · Loic Pallardy

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}()")
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/remoteproc/remoteproc_virtio.c +2 -1
index 183fc42a510a..88eade99395c 100644
@@ -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

#2 lore raw

Hi Xiang,

Quoted 10 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 3 lines

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()

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.

Quoted 5 lines

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

Quoted 48 lines

Thanks
Xiang

Quoted 12 lines · Loic Pallardy

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.

Quoted 4 lines

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}()")

Review

Quoted 8 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev,

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev,

int id)

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been previously

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#3 lore raw

Here is my output after apply your patch, the duplication device still exist:

[   48.012300] remoteproc remoteproc0: crash detected in
f9210000.toppwr:tl421-rproc: type watchdog
[   48.023473] remoteproc remoteproc0: handling crash #1 in
f9210000.toppwr:tl421-rproc
[   48.037504] remoteproc remoteproc0: recovering f9210000.toppwr:tl421-rproc
[   48.048837] remoteproc remoteproc0: stopped remote processor
f9210000.toppwr:tl421-rproc
[   48.061969] virtio_rpmsg_bus virtio2: rpmsg host is online
[   48.061976] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr 0x1
[   48.062956] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr 0x2
[   48.063489] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr 0x3
[   48.063815] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064064] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr 0x1
[   48.064080] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064087] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064102] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr 0x1
[   48.064118] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064127] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064139] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr 0x2
[   48.064153] virtio_rpmsg_bus virtio2: channel rpmsg-clk:ffffffff:2
already exist
[   48.064159] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064174] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr 0x3
[   48.064192] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064200] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064213] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064229] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064235] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064286] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr 0x3
[   48.064302] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064306] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064318] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064334] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064339] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064351] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr 0x5
[   48.064773] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr 0x5
[   48.064789] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.064797] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064930] virtio_rpmsg_bus virtio2: creating channel  addr 0x5f7361
[   48.064945] virtio_rpmsg_bus virtio2: rpmsg_find_device failed
[   48.064957] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064973] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064979] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.065015] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr 0x5
[   48.065030] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.065035] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.352150] remoteproc remoteproc0: registered virtio2 (type 7)
[   48.358813] remoteproc remoteproc0: remote processor

f9210000.toppwr:tl421-rproc is now up
do I still miss any additional patch?

Thanks
Xiang

Quoted 102 lines · Loic PALLARDY

Hi Xiang,

Quoted 10 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 3 lines

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()

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.

Quoted 5 lines

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

Quoted 48 lines

Thanks
Xiang

Quoted 12 lines · Loic Pallardy

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.

Quoted 4 lines

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}()")

Review

Quoted 8 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev,

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev,

int id)

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been previously

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#4 lore raw

Hi Xiang,

Quoted 22 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of xiang xiao
Sent: mardi 15 janvier 2019 07:46
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Here is my output after apply your patch, the duplication device still exist:

[   48.012300] remoteproc remoteproc0: crash detected in
f9210000.toppwr:tl421-rproc: type watchdog
[   48.023473] remoteproc remoteproc0: handling crash #1 in
f9210000.toppwr:tl421-rproc
[   48.037504] remoteproc remoteproc0: recovering f9210000.toppwr:tl421-
rproc
[   48.048837] remoteproc remoteproc0: stopped remote processor
f9210000.toppwr:tl421-rproc
[   48.061969] virtio_rpmsg_bus virtio2: rpmsg host is online
[   48.061976] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr
Quoted 1 line

0x1

First rpmsg-ttyADSP announcement

Quoted 6 lines
[   48.062956] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr 0x2
[   48.063489] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr
0x3
[   48.063815] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064064] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr

0x1

Second rpmsg-ttyADSP announcement

Quoted 50 lines
[   48.064080] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064087] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064102] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr
0x1
[   48.064118] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064127] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064139] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr 0x2
[   48.064153] virtio_rpmsg_bus virtio2: channel rpmsg-clk:ffffffff:2
already exist
[   48.064159] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064174] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr
0x3
[   48.064192] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064200] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064213] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064229] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064235] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064286] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr
0x3
[   48.064302] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064306] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064318] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064334] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064339] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064351] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr
0x5
[   48.064773] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr
0x5
[   48.064789] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.064797] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064930] virtio_rpmsg_bus virtio2: creating channel  addr 0x5f7361
[   48.064945] virtio_rpmsg_bus virtio2: rpmsg_find_device failed
[   48.064957] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064973] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064979] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.065015] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr
0x5
[   48.065030] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.065035] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.352150] remoteproc remoteproc0: registered virtio2 (type 7)
[   48.358813] remoteproc remoteproc0: remote processor
Quoted 2 lines

f9210000.toppwr:tl421-rproc is now up do I still miss any additional patch?

In your trace, I can see that your rpmsg device are announced twice and error is on the second announcement which is normal as endpoint ID is already used. virtio_rpmsg_bus virtio2: rpmsg_create_channel failed --> means you can't get the requested idr.

In code you pointing in [1] I can see that you are using optimized version of rpmsg, having zero copy features and maybe others coming from rpmsg-lite. On my side I'm testing with official release from OpenAMP and I have no modification on Linux rpmsg (on the top of kernel 5.0-rc0). Could you check content of the shared memory after recovery sequence? Maybe previous messages are still present leading to double announcement. Could you please retry on a mainline kernel without rpmsg optimization ?

On my side I tried the rpmsg_tty driver you pointed in [1] (I just add some stubs for zero copy) and I succeed to recover on my platform with it, so no issue on rpmsg client implementation side.

Regards,
Loic

[1] https://github.com/thesofproject/linux/pull/177

Quoted 129 lines

Thanks
Xiang

Quoted 10 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 7 lines
Quoted 6 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

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.

Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 2 lines

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty device 1

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW shutdown

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 8 lines
[  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.

Quoted 7 lines
Quoted 6 lines

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.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc->power

and so to be silent from rproc user pov.

Quoted 8 lines

Regards,
Loic

Quoted 5 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify recovery

path

Quoted 22 lines
Quoted 22 lines
Quoted 10 lines

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.

Quoted 4 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 13 lines
Quoted 13 lines

int id)

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been previously

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#5 lore raw
Quoted 89 lines · Loic PALLARDY

Hi Xiang,

Quoted 22 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of xiang xiao
Sent: mardi 15 janvier 2019 07:46
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Here is my output after apply your patch, the duplication device still exist:

[   48.012300] remoteproc remoteproc0: crash detected in
f9210000.toppwr:tl421-rproc: type watchdog
[   48.023473] remoteproc remoteproc0: handling crash #1 in
f9210000.toppwr:tl421-rproc
[   48.037504] remoteproc remoteproc0: recovering f9210000.toppwr:tl421-
rproc
[   48.048837] remoteproc remoteproc0: stopped remote processor
f9210000.toppwr:tl421-rproc
[   48.061969] virtio_rpmsg_bus virtio2: rpmsg host is online
[   48.061976] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr
Quoted 1 line

0x1

First rpmsg-ttyADSP announcement

Quoted 6 lines
[   48.062956] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr 0x2
[   48.063489] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr
0x3
[   48.063815] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064064] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr

0x1

Second rpmsg-ttyADSP announcement

Quoted 50 lines
[   48.064080] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064087] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064102] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP addr
0x1
[   48.064118] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064127] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064139] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr 0x2
[   48.064153] virtio_rpmsg_bus virtio2: channel rpmsg-clk:ffffffff:2
already exist
[   48.064159] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064174] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr
0x3
[   48.064192] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064200] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064213] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064229] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064235] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064286] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog addr
0x3
[   48.064302] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064306] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064318] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064334] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064339] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064351] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr
0x5
[   48.064773] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr
0x5
[   48.064789] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.064797] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064930] virtio_rpmsg_bus virtio2: creating channel  addr 0x5f7361
[   48.064945] virtio_rpmsg_bus virtio2: rpmsg_find_device failed
[   48.064957] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr 0x4
[   48.064973] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064979] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.065015] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs addr
0x5
[   48.065030] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.065035] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.352150] remoteproc remoteproc0: registered virtio2 (type 7)
[   48.358813] remoteproc remoteproc0: remote processor
Quoted 2 lines

f9210000.toppwr:tl421-rproc is now up do I still miss any additional patch?

Quoted 5 lines

In your trace, I can see that your rpmsg device are announced twice and error is on the second announcement which is normal as endpoint ID is already used. virtio_rpmsg_bus virtio2: rpmsg_create_channel failed --> means you can't get the requested idr.

In code you pointing in [1] I can see that you are using optimized version of rpmsg, having zero copy features and maybe others coming from rpmsg-lite. On my side I'm testing with official release from OpenAMP and I have no modification on Linux rpmsg (on the top of kernel 5.0-rc0).

I use OpenAMP too, but bring back zero copy features which was removed by the recent code change.

Quoted 3 lines

Could you check content of the shared memory after recovery sequence? Maybe previous messages are still present leading to double announcement. Could you please retry on a mainline kernel without rpmsg optimization ?

Yes, you are right, the duplicated issue get resolved by the following change:

(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c
index 9d4f459..1e51ce2 100644

drivers/remoteproc/remoteproc_virtio.c +7 -1
@@ -300,7 +300,13 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
        struct rproc *rproc = rvdev->rproc;
        struct device *dev = &rproc->dev;
        struct virtio_device *vdev = &rvdev->vdev;
-       int ret;
+       int i, ret;
+
+       for (i = 0; i < RVDEV_NUM_VRINGS; i++) {
+               struct rproc_vring *rvring = &rvdev->vring[i];
+
+               memset(rvring->va, 0, vring_size(rvring->len, rvring->align));
+       }
 
Quoted 137 lines

On my side I tried the rpmsg_tty driver you pointed in [1] (I just add some stubs for zero copy) and I succeed to recover on my platform with it, so no issue on rpmsg client implementation side.

Regards,
Loic

[1] https://github.com/thesofproject/linux/pull/177

Quoted 129 lines

Thanks
Xiang

Quoted 10 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 7 lines
Quoted 6 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

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.

Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 2 lines

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty device 1

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW shutdown

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 8 lines
[  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.

Quoted 7 lines
Quoted 6 lines

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.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc->power

and so to be silent from rproc user pov.

Quoted 8 lines

Regards,
Loic

Quoted 5 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify recovery

path

Quoted 22 lines
Quoted 22 lines
Quoted 10 lines

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.

Quoted 4 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 13 lines
Quoted 13 lines

int id)

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev · line 335

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been previously

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#6 lore raw
Quoted 147 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: lundi 21 janvier 2019 13:45
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 11 lines · Loic PALLARDY

Hi Xiang,

Quoted 8 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of xiang xiao
Sent: mardi 15 janvier 2019 07:46
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 9 lines
Quoted 9 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Here is my output after apply your patch, the duplication device still exist:

[   48.012300] remoteproc remoteproc0: crash detected in
f9210000.toppwr:tl421-rproc: type watchdog
[   48.023473] remoteproc remoteproc0: handling crash #1 in
f9210000.toppwr:tl421-rproc
[   48.037504] remoteproc remoteproc0: recovering

f9210000.toppwr:tl421-

Quoted 5 lines
Quoted 5 lines

rproc

[   48.048837] remoteproc remoteproc0: stopped remote processor
f9210000.toppwr:tl421-rproc
[   48.061969] virtio_rpmsg_bus virtio2: rpmsg host is online
[   48.061976] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP

addr

Quoted 4 lines
Quoted 1 line

0x1

First rpmsg-ttyADSP announcement

Quoted 1 line
[   48.062956] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr

0x2

Quoted 1 line
Quoted 1 line
[   48.063489] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog

addr

Quoted 2 lines
Quoted 2 lines

0x3

[   48.063815] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 1 line
Quoted 1 line
[   48.064064] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP

addr

Quoted 7 lines
Quoted 1 line

0x1

Second rpmsg-ttyADSP announcement

Quoted 4 lines
[   48.064080] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064087] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064102] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP

addr

Quoted 5 lines
Quoted 5 lines

0x1

[   48.064118] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064127] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064139] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr

0x2

Quoted 4 lines
Quoted 4 lines
[   48.064153] virtio_rpmsg_bus virtio2: channel rpmsg-clk:ffffffff:2
already exist
[   48.064159] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064174] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog

addr

Quoted 5 lines
Quoted 5 lines

0x3

[   48.064192] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064200] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064213] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 4 lines
Quoted 4 lines
[   48.064229] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064235] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064286] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog

addr

Quoted 5 lines
Quoted 5 lines

0x3

[   48.064302] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064306] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064318] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 4 lines
Quoted 4 lines
[   48.064334] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064339] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064351] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs

addr

Quoted 2 lines
Quoted 2 lines

0x5

[   48.064773] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs

addr

Quoted 7 lines
Quoted 7 lines

0x5

[   48.064789] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.064797] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064930] virtio_rpmsg_bus virtio2: creating channel  addr 0x5f7361
[   48.064945] virtio_rpmsg_bus virtio2: rpmsg_find_device failed
[   48.064957] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 4 lines
Quoted 4 lines
[   48.064973] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064979] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.065015] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs

addr

Quoted 10 lines
Quoted 8 lines

0x5

[   48.065030] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.065035] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.352150] remoteproc remoteproc0: registered virtio2 (type 7)
[   48.358813] remoteproc remoteproc0: remote processor

f9210000.toppwr:tl421-rproc is now up do I still miss any additional patch?

In your trace, I can see that your rpmsg device are announced twice and

error is on the second announcement which is normal as endpoint ID is already used.

Quoted 1 line

virtio_rpmsg_bus virtio2: rpmsg_create_channel failed --> means you can't

get the requested idr.

Quoted 2 lines

In code you pointing in [1] I can see that you are using optimized version of

rpmsg, having zero copy features and maybe others coming from rpmsg-lite.

Quoted 1 line

On my side I'm testing with official release from OpenAMP and I have no

modification on Linux rpmsg (on the top of kernel 5.0-rc0).

I use OpenAMP too, but bring back zero copy features which was removed by the recent code change.

Quoted 1 line

Could you check content of the shared memory after recovery sequence?

Maybe previous messages are still present leading to double announcement.

Quoted 2 lines

Could you please retry on a mainline kernel without rpmsg optimization ?

Yes, you are right, the duplicated issue get resolved by the following change:

drivers/remoteproc/remoteproc_virtio.c +0 -0
index 9d4f459..1e51ce2 100644
@@ -300,7 +300,13 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev,
 int id)
        struct rproc *rproc = rvdev->rproc;
        struct device *dev = &rproc->dev;

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, · line 311

Quoted 10 lines
drivers/remoteproc/remoteproc_virtio.c +7 -1
        struct virtio_device *vdev = &rvdev->vdev;
-       int ret;
+       int i, ret;
+
+       for (i = 0; i < RVDEV_NUM_VRINGS; i++) {
+               struct rproc_vring *rvring = &rvdev->vring[i];
+
+               memset(rvring->va, 0, vring_size(rvring->len, rvring->align));
+       }
 

That's not remoteproc responsibility to force to zero vrings. Vrings should be correctly reinitialized by virtio_rpmsg and virtio when virtio_rpmsg is probe. Regards,
Loic

Quoted 155 lines
Quoted 1 line

On my side I tried the rpmsg_tty driver you pointed in [1] (I just add some

stubs for zero copy) and I succeed to recover on my platform with it, so no issue on rpmsg client implementation side.

Quoted 31 lines

Regards,
Loic

[1] https://github.com/thesofproject/linux/pull/177

Quoted 24 lines

Thanks
Xiang

Quoted 10 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 7 lines
Quoted 6 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

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

Quoted 7 lines
Quoted 7 lines

sub device.

Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 2 lines

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

Quoted 8 lines
Quoted 8 lines

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 2 lines
Quoted 2 lines

is removed

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty

device 1

Quoted 2 lines
Quoted 2 lines

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW

shutdown

Quoted 5 lines
Quoted 5 lines

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 4 lines
Quoted 4 lines

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 6 lines
Quoted 6 lines

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 3 lines
[  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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 1 line
Quoted 1 line

before initializing virtio device while rproc subdevice sequence is

respected.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

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

Quoted 15 lines
Quoted 2 lines

to 1.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc-

power

Quoted 12 lines

and so to be silent from rproc user pov.

Quoted 8 lines

Regards,
Loic

Quoted 5 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify

recovery

Quoted 9 lines
Quoted 9 lines

path

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

virtio device is registered and unregistered at rproc subdevices

level.

Quoted 20 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been

previously

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#7 lore raw
Quoted 154 lines · Loic PALLARDY
Quoted 154 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: lundi 21 janvier 2019 13:45
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 11 lines · Loic PALLARDY

Hi Xiang,

Quoted 8 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of xiang xiao
Sent: mardi 15 janvier 2019 07:46
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 9 lines
Quoted 9 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Here is my output after apply your patch, the duplication device still exist:

[   48.012300] remoteproc remoteproc0: crash detected in
f9210000.toppwr:tl421-rproc: type watchdog
[   48.023473] remoteproc remoteproc0: handling crash #1 in
f9210000.toppwr:tl421-rproc
[   48.037504] remoteproc remoteproc0: recovering

f9210000.toppwr:tl421-

Quoted 5 lines
Quoted 5 lines

rproc

[   48.048837] remoteproc remoteproc0: stopped remote processor
f9210000.toppwr:tl421-rproc
[   48.061969] virtio_rpmsg_bus virtio2: rpmsg host is online
[   48.061976] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP

addr

Quoted 4 lines
Quoted 1 line

0x1

First rpmsg-ttyADSP announcement

Quoted 1 line
[   48.062956] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr

0x2

Quoted 1 line
Quoted 1 line
[   48.063489] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog

addr

Quoted 2 lines
Quoted 2 lines

0x3

[   48.063815] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 1 line
Quoted 1 line
[   48.064064] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP

addr

Quoted 7 lines
Quoted 1 line

0x1

Second rpmsg-ttyADSP announcement

Quoted 4 lines
[   48.064080] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064087] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064102] virtio_rpmsg_bus virtio2: creating channel rpmsg-ttyADSP

addr

Quoted 5 lines
Quoted 5 lines

0x1

[   48.064118] virtio_rpmsg_bus virtio2: channel
rpmsg-ttyADSP:ffffffff:1 already exist
[   48.064127] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064139] virtio_rpmsg_bus virtio2: creating channel rpmsg-clk addr

0x2

Quoted 4 lines
Quoted 4 lines
[   48.064153] virtio_rpmsg_bus virtio2: channel rpmsg-clk:ffffffff:2
already exist
[   48.064159] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064174] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog

addr

Quoted 5 lines
Quoted 5 lines

0x3

[   48.064192] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064200] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064213] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 4 lines
Quoted 4 lines
[   48.064229] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064235] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064286] virtio_rpmsg_bus virtio2: creating channel rpmsg-syslog

addr

Quoted 5 lines
Quoted 5 lines

0x3

[   48.064302] virtio_rpmsg_bus virtio2: channel
rpmsg-syslog:ffffffff:3 already exist
[   48.064306] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064318] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 4 lines
Quoted 4 lines
[   48.064334] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064339] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064351] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs

addr

Quoted 2 lines
Quoted 2 lines

0x5

[   48.064773] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs

addr

Quoted 7 lines
Quoted 7 lines

0x5

[   48.064789] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.064797] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.064930] virtio_rpmsg_bus virtio2: creating channel  addr 0x5f7361
[   48.064945] virtio_rpmsg_bus virtio2: rpmsg_find_device failed
[   48.064957] virtio_rpmsg_bus virtio2: creating channel rpmsg-rtc addr

0x4

Quoted 4 lines
Quoted 4 lines
[   48.064973] virtio_rpmsg_bus virtio2: channel rpmsg-rtc:ffffffff:4
already exist
[   48.064979] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.065015] virtio_rpmsg_bus virtio2: creating channel rpmsg-hostfs

addr

Quoted 10 lines
Quoted 8 lines

0x5

[   48.065030] virtio_rpmsg_bus virtio2: channel
rpmsg-hostfs:ffffffff:5 already exist
[   48.065035] virtio_rpmsg_bus virtio2: rpmsg_create_channel failed
[   48.352150] remoteproc remoteproc0: registered virtio2 (type 7)
[   48.358813] remoteproc remoteproc0: remote processor

f9210000.toppwr:tl421-rproc is now up do I still miss any additional patch?

In your trace, I can see that your rpmsg device are announced twice and

error is on the second announcement which is normal as endpoint ID is already used.

Quoted 1 line

virtio_rpmsg_bus virtio2: rpmsg_create_channel failed --> means you can't

get the requested idr.

Quoted 2 lines

In code you pointing in [1] I can see that you are using optimized version of

rpmsg, having zero copy features and maybe others coming from rpmsg-lite.

Quoted 1 line

On my side I'm testing with official release from OpenAMP and I have no

modification on Linux rpmsg (on the top of kernel 5.0-rc0).

I use OpenAMP too, but bring back zero copy features which was removed by the recent code change.

Quoted 1 line

Could you check content of the shared memory after recovery sequence?

Maybe previous messages are still present leading to double announcement.

Quoted 2 lines

Could you please retry on a mainline kernel without rpmsg optimization ?

Yes, you are right, the duplicated issue get resolved by the following change:

drivers/remoteproc/remoteproc_virtio.c +4 -1
index 9d4f459..1e51ce2 100644
@@ -300,7 +300,13 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev,
 int id)
        struct rproc *rproc = rvdev->rproc;
        struct device *dev = &rproc->dev;
        struct virtio_device *vdev = &rvdev->vdev;
-       int ret;
+       int i, ret;
+
+       for (i = 0; i < RVDEV_NUM_VRINGS; i++) {
+               struct rproc_vring *rvring = &rvdev->vring[i];
Quoted 9 lines

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) · line 310

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +3 -0
+
+               memset(rvring->va, 0, vring_size(rvring->len, rvring->align));
+       }
 

That's not remoteproc responsibility to force to zero vrings. Vrings should be correctly reinitialized by virtio_rpmsg and virtio when virtio_rpmsg is probe. Regards,
Loic

Yes, it's an ad-hoc location to see what happen after zero vring region. The best place is:
__vring_new_virtqueue(drivers/virtio/virtio_ring.c) which initialize many vring fields, but forget to zero out avail and used fields.

Quoted 155 lines
Quoted 155 lines
Quoted 1 line

On my side I tried the rpmsg_tty driver you pointed in [1] (I just add some

stubs for zero copy) and I succeed to recover on my platform with it, so no issue on rpmsg client implementation side.

Quoted 31 lines

Regards,
Loic

[1] https://github.com/thesofproject/linux/pull/177

Quoted 24 lines

Thanks
Xiang

Quoted 10 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 7 lines
Quoted 6 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

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

Quoted 7 lines
Quoted 7 lines

sub device.

Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 2 lines

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

Quoted 8 lines
Quoted 8 lines

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 2 lines
Quoted 2 lines

is removed

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty

device 1

Quoted 2 lines
Quoted 2 lines

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW

shutdown

Quoted 5 lines
Quoted 5 lines

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 4 lines
Quoted 4 lines

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 6 lines
Quoted 6 lines

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 3 lines
[  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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 1 line
Quoted 1 line

before initializing virtio device while rproc subdevice sequence is

respected.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

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

Quoted 15 lines
Quoted 2 lines

to 1.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc-

power

Quoted 12 lines

and so to be silent from rproc user pov.

Quoted 8 lines

Regards,
Loic

Quoted 5 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify

recovery

Quoted 9 lines
Quoted 9 lines

path

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

virtio device is registered and unregistered at rproc subdevices

level.

Quoted 20 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been

previously

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#8 lore raw
In reply to Loic PALLARDY
Quoted 12 lines · Loic PALLARDY

Hi Xiang,

Quoted 10 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Thanks Loic for picking this up again.

Quoted 7 lines
Quoted 3 lines

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.

Quoted 22 lines

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:~#
Quoted 4 lines

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

Quoted 58 lines
Quoted 5 lines

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

Quoted 48 lines

Thanks
Xiang

Quoted 12 lines · Loic Pallardy

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.

Quoted 4 lines

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}()")

Review

Quoted 8 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev,

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev,

int id)

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been previously

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#9 lore raw

Hi Bjorn,

Quoted 33 lines

-----Original Message-----
From: Bjorn Andersson <[email protected]>
Sent: jeudi 17 janvier 2019 19:00
To: Loic PALLARDY <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 9 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 3 lines
Quoted 3 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Thanks Loic for picking this up again.

Quoted 4 lines
Quoted 3 lines

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.

Quoted 8 lines
Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 1 line

Xiang is right, unregister_virtio_device() ends up decrementing the refcount of device and might free it, but it's not guaranteed.

But it that case calling rproc_shutdown() doesn't guarantee devices are free, it is the same.
The only difference will be that rproc_vdev will be released by rproc and then reallocated. So virtio device allocation is restarting with a virgin memory buffer. But you will have some ghost devices and restart may failed too. I post a fix [1] last summer to be sure virtio device won't be released while still registered or registering... So there is still potential issue.

Quoted 4 lines

So I think we need to decouple the rproc_vdev and virtio_device, to allow the latter to potentially outlive the prior.

I checked how to decouple at least the allocation because one issue here. The main issue is that all references are done based on container_of(). I look for a fix having the less impacts on the current code, but still possible to create cross pointer references between rproc_vdev and virtio device. It will clean up the memory allocation procedure, but the problem is still there if sub virtio devices not well release.
We need to not be able to restart remote processor if at least one sub device was not correctly release...

Quoted 32 lines
Quoted 1 line

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty device 1

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW shutdown

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 7 lines
[  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:~#

Quoted 8 lines
Quoted 4 lines

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.

In fact, as the memory is free/kzalloc, virtio device fields are not all at 0 as during boot sequence. As mentioned below issue is coming from kobject state_initialized field which is not in a correct state. This field is only set by kobject_init().
I think normal way of working is to release memory when a device is no more used.
But another solution could be to reset it in kobject_cleanup() or kobject_del() in order to have a symmetrical procedure.

Regards,
Loic
[1] https://patchwork.kernel.org/patch/10544757/

Quoted 68 lines

Regards,
Bjorn

Quoted 6 lines
Quoted 5 lines

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.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc->power

and so to be silent from rproc user pov.

Quoted 8 lines

Regards,
Loic

Quoted 5 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify recovery

path

Quoted 22 lines
Quoted 22 lines
Quoted 10 lines

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.

Quoted 4 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 13 lines
Quoted 13 lines

int id)

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been previously

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#10 lore raw
Quoted 124 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Loic PALLARDY
Sent: jeudi 17 janvier 2019 21:52
To: Bjorn Andersson <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: RE: [PATCH 1/1] remoteproc: fix recovery procedure

Hi Bjorn,

Quoted 7 lines

-----Original Message-----
From: Bjorn Andersson <[email protected]>
Sent: jeudi 17 janvier 2019 19:00
To: Loic PALLARDY <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected];

s-

Quoted 26 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 9 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 3 lines
Quoted 3 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Thanks Loic for picking this up again.

Quoted 4 lines
Quoted 3 lines

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.

Quoted 8 lines
Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 1 line

Xiang is right, unregister_virtio_device() ends up decrementing the refcount of device and might free it, but it's not guaranteed.

But it that case calling rproc_shutdown() doesn't guarantee devices are free, it is the same.
The only difference will be that rproc_vdev will be released by rproc and then reallocated. So virtio device allocation is restarting with a virgin memory buffer. But you will have some ghost devices and restart may failed too. I post a fix [1] last summer to be sure virtio device won't be released while still registered or registering... So there is still potential issue.

Quoted 4 lines

So I think we need to decouple the rproc_vdev and virtio_device, to allow the latter to potentially outlive the prior.

I checked how to decouple at least the allocation because one issue here. The main issue is that all references are done based on container_of(). I look for a fix having the less impacts on the current code, but still possible to create cross pointer references between rproc_vdev and virtio device. It will clean up the memory allocation procedure, but the problem is still there if sub virtio devices not well release.
We need to not be able to restart remote processor if at least one sub device was not correctly release...

Quoted 9 lines
Quoted 1 line

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 2 lines

is removed

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty device

1

Quoted 7 lines

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW shutdown

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 4 lines

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 10 lines

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 7 lines
[  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:~#

Quoted 8 lines
Quoted 4 lines

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.

Quoted 9 lines

In fact, as the memory is free/kzalloc, virtio device fields are not all at 0 as during boot sequence.
As mentioned below issue is coming from kobject state_initialized field which is not in a correct state.
This field is only set by kobject_init().
I think normal way of working is to release memory when a device is no more used.
But another solution could be to reset it in kobject_cleanup() or kobject_del() in order to have a symmetrical procedure.

Reading some literature, it is a bad idea.
Having a look to device_initialize () function description, it is clearly mention device struct must be 0 (except fields provided by user) before. (Same in kobject documentation)

Extract drivers/base/core.c [1]
* All fields in @dev must be initialized by the caller to 0, except
* for those explicitly set to some other value. The simplest
* approach is to use kzalloc() to allocate the structure containing
* @dev.

So memset or kfree/kzalloc of virtio_device manadatory.

Regards,
Loic

[1]: https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L1482

Quoted 78 lines

Regards,
Loic
[1] https://patchwork.kernel.org/patch/10544757/

Quoted 8 lines

Regards,
Bjorn

Quoted 4 lines
Quoted 4 lines

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

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

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

Quoted 8 lines

to 1.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc-

power
and so to be silent from rproc user pov.

Quoted 4 lines

Regards,
Loic

Quoted 1 line
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify recovery

path

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 5 lines
Quoted 5 lines

int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been

previously

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#11 lore raw
Quoted 138 lines · Loic PALLARDY
Quoted 125 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Loic PALLARDY
Sent: jeudi 17 janvier 2019 21:52
To: Bjorn Andersson <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: RE: [PATCH 1/1] remoteproc: fix recovery procedure

Hi Bjorn,

Quoted 7 lines

-----Original Message-----
From: Bjorn Andersson <[email protected]>
Sent: jeudi 17 janvier 2019 19:00
To: Loic PALLARDY <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected];

s-

Quoted 26 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 9 lines · Loic PALLARDY

Hi Xiang,

Quoted 7 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 3 lines
Quoted 3 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Thanks Loic for picking this up again.

Quoted 4 lines
Quoted 3 lines

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.

Quoted 8 lines
Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 1 line

Xiang is right, unregister_virtio_device() ends up decrementing the refcount of device and might free it, but it's not guaranteed.

But it that case calling rproc_shutdown() doesn't guarantee devices are free, it is the same.
The only difference will be that rproc_vdev will be released by rproc and then reallocated. So virtio device allocation is restarting with a virgin memory buffer. But you will have some ghost devices and restart may failed too. I post a fix [1] last summer to be sure virtio device won't be released while still registered or registering... So there is still potential issue.

Quoted 4 lines

So I think we need to decouple the rproc_vdev and virtio_device, to allow the latter to potentially outlive the prior.

I checked how to decouple at least the allocation because one issue here. The main issue is that all references are done based on container_of(). I look for a fix having the less impacts on the current code, but still possible to create cross pointer references between rproc_vdev and virtio device. It will clean up the memory allocation procedure, but the problem is still there if sub virtio devices not well release.
We need to not be able to restart remote processor if at least one sub device was not correctly release...

Quoted 9 lines
Quoted 1 line

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty are

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 2 lines

is removed

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty device

1

Quoted 7 lines

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW shutdown

without ack

Quoted 2 lines
[  155.387857] remoteproc remoteproc0: stopped remote processor m4
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 4 lines

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 10 lines

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 7 lines
[  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:~#

Quoted 8 lines
Quoted 4 lines

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.

Quoted 9 lines

In fact, as the memory is free/kzalloc, virtio device fields are not all at 0 as during boot sequence.
As mentioned below issue is coming from kobject state_initialized field which is not in a correct state.
This field is only set by kobject_init().
I think normal way of working is to release memory when a device is no more used.
But another solution could be to reset it in kobject_cleanup() or kobject_del() in order to have a symmetrical procedure.

Reading some literature, it is a bad idea.
Having a look to device_initialize () function description, it is clearly mention device struct must be 0 (except fields provided by user) before. (Same in kobject documentation)

Quoted 8 lines

Extract drivers/base/core.c [1]
* All fields in @dev must be initialized by the caller to 0, except
* for those explicitly set to some other value. The simplest
* approach is to use kzalloc() to allocate the structure containing
* @dev.

So memset or kfree/kzalloc of virtio_device manadatory.

As Bjorn note, it's very dangerous to do memset in rproc_vdev_do_probe blindly, since subsystem or userspace may still hold the reference on rpmsg device which will block the release process of virtio device. If we do memset before the release, the later will make a panic mostly like.

Quoted 82 lines

Regards,
Loic

[1]: https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L1482

Quoted 78 lines

Regards,
Loic
[1] https://patchwork.kernel.org/patch/10544757/

Quoted 8 lines

Regards,
Bjorn

Quoted 4 lines
Quoted 4 lines

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

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

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

Quoted 8 lines

to 1.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc-

power
and so to be silent from rproc user pov.

Quoted 4 lines

Regards,
Loic

Quoted 1 line
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify recovery

path

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct rproc_vdev

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct rproc_vdev

*rvdev,

Quoted 5 lines
Quoted 5 lines

int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been

previously

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4

#12 lore raw
Quoted 176 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: lundi 21 janvier 2019 14:22
To: Loic PALLARDY <[email protected]>
Cc: Bjorn Andersson <[email protected]>; [email protected]; [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]; s- [email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 11 lines · Loic PALLARDY
Quoted 11 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Loic PALLARDY
Sent: jeudi 17 janvier 2019 21:52
To: Bjorn Andersson <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 5 lines
Quoted 5 lines

[email protected]
Subject: RE: [PATCH 1/1] remoteproc: fix recovery procedure

Hi Bjorn,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Bjorn Andersson <[email protected]>
Sent: jeudi 17 janvier 2019 19:00
To: Loic PALLARDY <[email protected]>
Cc: xiang xiao <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>;

[email protected];

Quoted 6 lines
Quoted 6 lines

s-

Quoted 5 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

On Mon 14 Jan 12:23 PST 2019, Loic PALLARDY wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Hi Xiang,

Quoted 6 lines

-----Original Message-----
From: xiang xiao <[email protected]>
Sent: samedi 12 janvier 2019 19:29
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected];

Arnaud

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

POULIQUEN <[email protected]>;

[email protected]; s-

Quoted 3 lines
Quoted 3 lines

[email protected]
Subject: Re: [PATCH 1/1] remoteproc: fix recovery procedure

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Thanks Loic for picking this up again.

Quoted 4 lines
Quoted 3 lines

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

Quoted 11 lines
Quoted 11 lines
Quoted 9 lines

sub device.

Quoted 1 line

rproc_stop() is calling rproc_stop_subdevices() which is in charge of

removing virtio device and associated children.

Quoted 1 line

rproc_vdev_do_stop() --> rproc_remove_virtio_dev() -->

unregister_virtio_device()

Quoted 1 line

Xiang is right, unregister_virtio_device() ends up decrementing the refcount of device and might free it, but it's not guaranteed.

But it that case calling rproc_shutdown() doesn't guarantee devices are

free,

Quoted 3 lines
Quoted 3 lines

it is the same.
The only difference will be that rproc_vdev will be released by rproc and then reallocated. So virtio device allocation is restarting with a virgin

memory

Quoted 2 lines
Quoted 2 lines

buffer. But you will have some ghost devices and restart may failed too. I post a fix [1] last summer to be sure virtio device won't be released

while

Quoted 9 lines
Quoted 9 lines

still registered or registering... So there is still potential issue.

Quoted 4 lines

So I think we need to decouple the rproc_vdev and virtio_device, to allow the latter to potentially outlive the prior.

I checked how to decouple at least the allocation because one issue here. The main issue is that all references are done based on container_of(). I look for a fix having the less impacts on the current code, but still

possible to

Quoted 4 lines
Quoted 4 lines

create cross pointer references between rproc_vdev and virtio device. It will clean up the memory allocation procedure, but the problem is still there if sub virtio devices not well release.
We need to not be able to restart remote processor if at least one sub

device

Quoted 3 lines
Quoted 3 lines

was not correctly release...

Quoted 1 line
Quoted 1 line

Please find below trace of a recovery on my ST SOC. My 2 rpmsg tty

are

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

removed and re-inserted correctly

Quoted 3 lines
root@stm32mp1:~# ls /dev/ttyRPMSG*
/dev/ttyRPMSG0  /dev/ttyRPMSG1
root@stm32mp1:~# [  154.832523] remoteproc remoteproc0: crash

detected in m4: type watchdog

Quoted 3 lines
[  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

Quoted 3 lines
Quoted 3 lines

0

Quoted 2 lines

is removed

Quoted 1 line
[  154.857572] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: rpmsg tty

device

Quoted 3 lines
Quoted 3 lines

1

Quoted 2 lines

is removed

Quoted 1 line
[  155.382327] remoteproc remoteproc0: warning: remote FW

shutdown

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

without ack

Quoted 1 line
[  155.387857] remoteproc remoteproc0: stopped remote processor

m4

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
[  155.398988]  m4@0#vdev0buffer: assigned reserved memory node

vdev0buffer@10044000

Quoted 1 line
[  155.405910] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 3 lines

addr 0x0

Quoted 1 line
[  155.413422] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel:

0x400 -> 0x0 : ttyRPMSG0

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
[  155.421038] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-

channel

Quoted 6 lines

addr 0x1

Quoted 1 line
[  155.429088] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel:

0x401 -> 0x1 : ttyRPMSG1

Quoted 3 lines
[  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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

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.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

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.

In fact, as the memory is free/kzalloc, virtio device fields are not all at 0 as during boot sequence.
As mentioned below issue is coming from kobject state_initialized field

which

Quoted 3 lines
Quoted 3 lines

is not in a correct state.
This field is only set by kobject_init().
I think normal way of working is to release memory when a device is no

more

Quoted 6 lines
Quoted 3 lines

used.
But another solution could be to reset it in kobject_cleanup() or kobject_del() in order to have a symmetrical procedure.

Reading some literature, it is a bad idea.
Having a look to device_initialize () function description, it is clearly mention

device struct must be 0 (except fields provided by user) before. (Same in kobject documentation)

Quoted 7 lines

Extract drivers/base/core.c [1]
* All fields in @dev must be initialized by the caller to 0, except
* for those explicitly set to some other value. The simplest
* approach is to use kzalloc() to allocate the structure containing
* @dev.

Quoted 7 lines
Quoted 2 lines

So memset or kfree/kzalloc of virtio_device manadatory.

As Bjorn note, it's very dangerous to do memset in rproc_vdev_do_probe blindly, since subsystem or userspace may still hold the reference on rpmsg device which will block the release process of virtio device. If we do memset before the release, the later will make a panic mostly like.

Hi,

As mentioned in my previous answer, doing a rproc_shutdown() and then a rproc_boot() is not safe at all for the same reason.
The only safe way to proceed is to correlate the 2 devices as they don't have the same life cycle and to rely on device release mechanism to free structure. If a sub device is not correctly clean up, it will stay in the system, but it won't enter in conflict with remoteproc start sequence as a new object will be allocated... It is the responsibility of the customer to release correctly sub devices when a stop is requested.

I'll send a v2 going in that way

Regards,
Loic

Quoted 90 lines
Quoted 5 lines

Regards,
Loic

[1]:

https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L1482

Quoted 6 lines
Quoted 6 lines

Regards,
Loic
[1] https://patchwork.kernel.org/patch/10544757/

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Regards,
Bjorn

Quoted 4 lines
Quoted 4 lines

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

Quoted 13 lines
Quoted 13 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

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

Quoted 8 lines

to 1.

Quoted 1 line

Using only rproc_stop() and rproc_start() allows to preserve rproc-

power
and so to be silent from rproc user pov.

Quoted 4 lines

Regards,
Loic

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Thanks
Xiang

On Wed, Jan 9, 2019 at 6:56 PM Loic Pallardy <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

Commit 7e83cab824a87e83cab824a8 ("remoteproc: Modify

recovery

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

path

Quoted 1 line
Quoted 1 line
Quoted 1 line

to use rproc_{start,stop}()") replaces rproc_{shutdown,boot}()

with

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

is allocated and released at vdev resource handling level managed

and

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

virtio device is registered and unregistered at rproc subdevices

level.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines

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}()")

Quoted 7 lines
---
 drivers/remoteproc/remoteproc_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_virtio.c

drivers/remoteproc/remoteproc_virtio.c int rproc_add_virtio_dev(struct

Quoted 4 lines

index 183fc42a510a..88eade99395c 100644

drivers/remoteproc/remoteproc_virtio.c +0 -0
@@ -332,6 +332,8 @@ int rproc_add_virtio_dev(struct

rproc_vdev

Quoted 15 lines
Quoted 15 lines
Quoted 6 lines

*rvdev,

Quoted 5 lines
Quoted 5 lines

int id)

Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +1 -0
        struct virtio_device *vdev = &rvdev->vdev;
        int ret;
 
+       /* Reset vdev struct as you don't know how it has been

previously

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

used */

Quoted 7 lines
drivers/remoteproc/remoteproc_virtio.c +1 -1
+       memset(vdev, 0, sizeof(struct virtio_device));
        vdev->id.device = id,
        vdev->config = &rproc_virtio_config_ops,
        vdev->dev.parent = dev;
--

2.7.4