From patchwork Mon Nov 6 22:17:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 10044577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BCEC602BF for ; Mon, 6 Nov 2017 22:20:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E19F28E55 for ; Mon, 6 Nov 2017 22:20:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62EAA29E5C; Mon, 6 Nov 2017 22:20:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E4E4D29E50 for ; Mon, 6 Nov 2017 22:20:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBpiY-0003Ku-NJ; Mon, 06 Nov 2017 22:18:06 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBpiW-0003Ko-U0 for xen-devel@lists.xenproject.org; Mon, 06 Nov 2017 22:18:05 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id 35/E8-10698-C9FD00A5; Mon, 06 Nov 2017 22:18:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVybKJssu6s+wx RBvN3qFp83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlXzq1hKZjKWbH5yluWBsZX7F2MXBxCAuuY JM7PWsvUxcjJwSLgIHHg+FTGLkYODkaBGIkHP6xBwowCYRKTLy9hBbHZBAwl/j7ZxAZiiwgoS dxbNRmslVnAU2LlzKnMILawgLfExOZPUCNVJfYveANm8wq4Spx49AWsV0JATuLkscmsExi5Fz AyrGLUKE4tKkst0jW01EsqykzPKMlNzMzRNTQw1stNLS5OTE/NSUwq1kvOz93ECPRuPQMD4w7 G38f9DjFKcjApifJuCGGIEuJLyk+pzEgszogvKs1JLT7EKMPBoSTB63cPKCdYlJqeWpGWmQMM M5i0BAePkgjvobtAad7igsTc4sx0iNQpRkuOY5su/2HieDbzdQMzx7SrrU3MQix5+XmpUuK8e 0HmCYA0ZJTmwY2DxcIlRlkpYV5GBgYGIZ6C1KLczBJU+VeM4hyMSsK8+0Gm8GTmlcBtfQV0EB PQQftDwA4qSURISTUwmizrXPunUPujmNNJ36d7l9rYTki2rcyJ3i9gz6Q79WGrGkvjs4UxDCE KWf6n9t47n3lCQe7Df4MAXqW/ikvqGrfnmr1y32Lc98zzoIDBL01eZfHwhf6xm1ZVvX1t+OLL hVDTNyfMr63WPPDkToDJbJ2k4JuP4go5JP6ntkyK/uCx8jFr/jJ7JZbijERDLeai4kQAzr9zI 4ACAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-7.tower-31.messagelabs.com!1510006681!106207928!1 X-Originating-IP: [198.145.29.99] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29584 invoked from network); 6 Nov 2017 22:18:02 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Nov 2017 22:18:02 -0000 Received: from localhost.localdomain (162-198-228-33.lightspeed.wlfrct.sbcglobal.net [162.198.228.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A697921870; Mon, 6 Nov 2017 22:18:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A697921870 From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Mon, 6 Nov 2017 14:17:59 -0800 Message-Id: <1510006679-6381-1-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 Cc: jgross@suse.com, boris.ostrovsky@oracle.com, sstabellini@kernel.org Subject: [Xen-devel] [PATCH] xen/pvcalls: fix potential endless loop in pvcalls-front.c X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Stefano Stabellini CC: boris.ostrovsky@oracle.com CC: jgross@suse.com Reviewed-by: Boris Ostrovsky --- 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);