xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/pvcalls: fix potential endless loop in pvcalls-front.c
@ 2017-11-06 22:17 Stefano Stabellini
  2017-11-06 22:34 ` Boris Ostrovsky
  2017-11-07  5:44 ` Juergen Gross
  0 siblings, 2 replies; 20+ messages in thread
From: Stefano Stabellini @ 2017-11-06 22:17 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, boris.ostrovsky, sstabellini

mutex_trylock() returns 1 if you take the lock and 0 if not. Assume you
take in_mutex on the first try, but you can't take out_mutex. Next times
you call mutex_trylock() in_mutex is going to fail. It's an endless
loop.

Solve the problem by moving the two mutex_trylock calls to two separate
loops.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
CC: boris.ostrovsky@oracle.com
CC: jgross@suse.com
---
 drivers/xen/pvcalls-front.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 0c1ec68..047dce7 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -1048,8 +1048,9 @@ int pvcalls_front_release(struct socket *sock)
 		 * is set to NULL -- we only need to wait for the existing
 		 * waiters to return.
 		 */
-		while (!mutex_trylock(&map->active.in_mutex) ||
-			   !mutex_trylock(&map->active.out_mutex))
+		while (!mutex_trylock(&map->active.in_mutex))
+			cpu_relax();
+		while (!mutex_trylock(&map->active.out_mutex))
 			cpu_relax();
 
 		pvcalls_front_free_map(bedata, map);
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-11-16  5:28 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-06 22:17 [PATCH] xen/pvcalls: fix potential endless loop in pvcalls-front.c Stefano Stabellini
2017-11-06 22:34 ` Boris Ostrovsky
2017-11-06 22:38   ` Stefano Stabellini
2017-11-07  5:44 ` Juergen Gross
2017-11-10 23:57   ` Stefano Stabellini
2017-11-11  2:02     ` Boris Ostrovsky
2017-11-13 18:30       ` Stefano Stabellini
2017-11-13 15:15     ` Juergen Gross
2017-11-13 18:33       ` Stefano Stabellini
2017-11-14  9:11         ` Juergen Gross
2017-11-14 21:46           ` Boris Ostrovsky
2017-11-15  8:14             ` Juergen Gross
2017-11-15 19:09               ` Stefano Stabellini
2017-11-15 19:50                 ` Boris Ostrovsky
2017-11-15 19:53                   ` Boris Ostrovsky
2017-11-15 21:20                   ` Stefano Stabellini
2017-11-15 21:50                     ` Stefano Stabellini
2017-11-15 21:51                       ` Boris Ostrovsky
2017-11-15 21:54                         ` Stefano Stabellini
2017-11-16  5:28                     ` Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).