The patch titled Subject: rapidio: avoid data race between file operation callbacks and mport_cdev_add(). has been added to the -mm tree. Its filename is rapidio-avoid-data-race-between-file-operation-callbacks-and-mport_cdev_add.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/rapidio-avoid-data-race-between-file-operation-callbacks-and-mport_cdev_add.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/rapidio-avoid-data-race-between-file-operation-callbacks-and-mport_cdev_add.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Madhuparna Bhowmik <madhuparnabhowmik10@xxxxxxxxx> Subject: rapidio: avoid data race between file operation callbacks and mport_cdev_add(). Fields of md(mport_dev) are set after cdev_device_add(). However, the file operation callbacks can be called after cdev_device_add() and therefore accesses to fields of md in the callbacks can race with the rest of the mport_cdev_add() function. One such example is INIT_LIST_HEAD(&md->portwrites) in mport_cdev_add(), the list is initialised after cdev_device_add(). This can race with list_add_tail(&pw_filter->md_node,&md->portwrites) in rio_mport_add_pw_filter() which is called by unlocked_ioctl. To avoid such data races use cdev_device_add() after initializing md. Found by Linux Driver Verification project (linuxtesting.org). Link: http://lkml.kernel.org/r/20200426112950.1803-1-madhuparnabhowmik10@xxxxxxxxx Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@xxxxxxxxx> Acked-by: Alexandre Bounine <alex.bou9@xxxxxxxxx> Cc: Matt Porter <mporter@xxxxxxxxxxxxxxxxxxx> Cc: Dan Carpenter <dan.carpenter@xxxxxxxxxx> Cc: Mike Marshall <hubcap@xxxxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Ira Weiny <ira.weiny@xxxxxxxxx> Cc: Allison Randal <allison@xxxxxxxxxxx> Cc: Pavel Andrianov <andrianov@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- drivers/rapidio/devices/rio_mport_cdev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/drivers/rapidio/devices/rio_mport_cdev.c~rapidio-avoid-data-race-between-file-operation-callbacks-and-mport_cdev_add +++ a/drivers/rapidio/devices/rio_mport_cdev.c @@ -2379,13 +2379,6 @@ static struct mport_dev *mport_cdev_add( cdev_init(&md->cdev, &mport_fops); md->cdev.owner = THIS_MODULE; - ret = cdev_device_add(&md->cdev, &md->dev); - if (ret) { - rmcd_error("Failed to register mport %d (err=%d)", - mport->id, ret); - goto err_cdev; - } - INIT_LIST_HEAD(&md->doorbells); spin_lock_init(&md->db_lock); INIT_LIST_HEAD(&md->portwrites); @@ -2405,6 +2398,13 @@ static struct mport_dev *mport_cdev_add( #else md->properties.transfer_mode |= RIO_TRANSFER_MODE_TRANSFER; #endif + + ret = cdev_device_add(&md->cdev, &md->dev); + if (ret) { + rmcd_error("Failed to register mport %d (err=%d)", + mport->id, ret); + goto err_cdev; + } ret = rio_query_mport(mport, &attr); if (!ret) { md->properties.flags = attr.flags; _ Patches currently in -mm which might be from madhuparnabhowmik10@xxxxxxxxx are rapidio-avoid-data-race-between-file-operation-callbacks-and-mport_cdev_add.patch