Return-Path: Received: from mail-sn1nam01on0132.outbound.protection.outlook.com ([104.47.32.132]:57184 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932647AbeARVGZ (ORCPT ); Thu, 18 Jan 2018 16:06:25 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: "William A. Kennington III" , Michael Ellerman , Sasha Levin Subject: [added to the 4.1 stable tree] powerpc/opal: Fix EBUSY bug in acquiring tokens Date: Thu, 18 Jan 2018 21:01:43 +0000 Message-ID: <20180118205908.3220-259-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: "William A. Kennington III" This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 71e24d7731a2903b1ae2bba2b2971c654d9c2aa6 ] The current code checks the completion map to look for the first token that is complete. In some cases, a completion can come in but the token can still be on lease to the caller processing the completion. If this completed but unreleased token is the first token found in the bitmap by another tasks trying to acquire a token, then the __test_and_set_bit call will fail since the token will still be on lease. The acquisition will then fail with an EBUSY. This patch reorganizes the acquisition code to look at the opal_async_token_map for an unleased token. If the token has no lease it must have no outstanding completions so we should never see an EBUSY, unless we have leased out too many tokens. Since opal_async_get_token_inrerruptible is protected by a semaphore, we will practically never see EBUSY anymore. Fixes: 8d7248232208 ("powerpc/powernv: Infrastructure to support OPAL async= completion") Signed-off-by: William A. Kennington III Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/platforms/powernv/opal-async.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal-async.c b/arch/powerpc/pla= tforms/powernv/opal-async.c index 693b6cdac691..3fcaa9ef447b 100644 --- a/arch/powerpc/platforms/powernv/opal-async.c +++ b/arch/powerpc/platforms/powernv/opal-async.c @@ -39,18 +39,18 @@ int __opal_async_get_token(void) int token; =20 spin_lock_irqsave(&opal_async_comp_lock, flags); - token =3D find_first_bit(opal_async_complete_map, opal_max_async_tokens); + token =3D find_first_zero_bit(opal_async_token_map, opal_max_async_tokens= ); if (token >=3D opal_max_async_tokens) { token =3D -EBUSY; goto out; } =20 - if (__test_and_set_bit(token, opal_async_token_map)) { + if (!__test_and_clear_bit(token, opal_async_complete_map)) { token =3D -EBUSY; goto out; } =20 - __clear_bit(token, opal_async_complete_map); + __set_bit(token, opal_async_token_map); =20 out: spin_unlock_irqrestore(&opal_async_comp_lock, flags); --=20 2.11.0