From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE3D8C43381 for ; Mon, 25 Feb 2019 21:27:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A5CEF213A2 for ; Mon, 25 Feb 2019 21:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130062; bh=UGWJAz3AmEAW7sUxvf2rHk+kCrI/eoFUV3sLUhC/weE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VzEaU4AHWgz6cIntmoiSIHJif6j5Yy1n4Z6REAW06toNi9B7RYznwU7vGIxKcuyza Dbcv/HM3lD75TSvbPWWc+SdEtB4jLgGzhpel7ABnfWDG9eFkfz0+uevNXYMa2WaxS0 7vHvR236PZ8orKOyobNPfB7RRnWA3UBGDn+Ico0w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731782AbfBYV1l (ORCPT ); Mon, 25 Feb 2019 16:27:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:33494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731770AbfBYV1f (ORCPT ); Mon, 25 Feb 2019 16:27:35 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B7A3213A2; Mon, 25 Feb 2019 21:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130054; bh=UGWJAz3AmEAW7sUxvf2rHk+kCrI/eoFUV3sLUhC/weE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lJo1LgBACzvhicHibsSSvlAqNZBKVPatpJaPK67S0qr/ci8Tc9NUpcvlSV4bUQRaJ f4TrK/SiEbm993ggIRI7ZL0iQnpyEBYJTuZ3XrdffL2njACaWNfmxz0B67w3ColXUN AfOGiv2FQdvh/YMLJ9NNf0wIPtb17kpSrvtWwGnM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Gao Xiang Subject: [PATCH 4.19 139/152] staging: erofs: atomic_cond_read_relaxed on ref-locked workgroup Date: Mon, 25 Feb 2019 22:12:11 +0100 Message-Id: <20190225195053.612214053@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195043.645958524@linuxfoundation.org> References: <20190225195043.645958524@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gao Xiang commit df134b8d17b90c1e7720e318d36416b57424ff7a upstream. It's better to use atomic_cond_read_relaxed, which is implemented in hardware instructions to monitor a variable changes currently for ARM64, instead of open-coded busy waiting. Reviewed-by: Chao Yu Signed-off-by: Gao Xiang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/erofs/internal.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -211,23 +211,29 @@ static inline void erofs_workgroup_unfre preempt_enable(); } +#if defined(CONFIG_SMP) +static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) +{ + return atomic_cond_read_relaxed(&grp->refcount, + VAL != EROFS_LOCKED_MAGIC); +} +#else +static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) +{ + int v = atomic_read(&grp->refcount); + + /* workgroup is never freezed on uniprocessor systems */ + DBG_BUGON(v == EROFS_LOCKED_MAGIC); + return v; +} +#endif + static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt) { - const int locked = (int)EROFS_LOCKED_MAGIC; int o; repeat: - o = atomic_read(&grp->refcount); - - /* spin if it is temporarily locked at the reclaim path */ - if (unlikely(o == locked)) { -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) - do - cpu_relax(); - while (atomic_read(&grp->refcount) == locked); -#endif - goto repeat; - } + o = erofs_wait_on_workgroup_freezed(grp); if (unlikely(o <= 0)) return -1;