Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4918768imc; Mon, 25 Feb 2019 13:37:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IYgLz3RcPRlecc2h9mJvFsJzMOQFdx1JawgdRMqvSJ9R4gUi9IcRB5328gLayhcZS+GcZTZ X-Received: by 2002:a17:902:2e03:: with SMTP id q3mr23060902plb.330.1551130653995; Mon, 25 Feb 2019 13:37:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130653; cv=none; d=google.com; s=arc-20160816; b=cBuEZ5JhehBduH8tRfSTtfmb+xBz2uxqtF1Q2OhCbQrWsiytyYZXEYVfv70vdMr9+n dBeCW7PpvXH4epX2vHmj5iYxur3e12WSaW1qWK6GYnofy7wxUtJQcLgAyvLmcUfe5Gua dIfhMWHbCzkRCaauv01yP474rTwfpGWVc6Dut5YOQ6IRKE+wt81iqMeo15cn+xN5Q9w+ 9un6S1wjHTVrYX/k06bCEZBhCPEvTXvTQU1AdN4aDOwbugiH568qZBwjX2TISJeIKdSh wfrG4Hv3GUcE3qJstJpzH8bnHT67uWu0t8/JIyEpm94ImLO83rTP4ib6T/tzaYOEKbb5 wVKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kKK2c2L/bRl67YKSKjcrJsTyxnNCgzSxZOPMakQC/2w=; b=b+jXsjeke7CkOFOhbC3+dZymnEBvoW6mseIj7coL3USSlPdfDuz93YXLC5tL6JBMV8 MEqd7LglBm5KRLhgIi7lJJ2nP8jxBeuVkGZf8X3cNCIhp03EOV07RUhAn8PSVG0W9HvM Q78zpkOkv7saHsse0wvfVEOE8fU5YLMnerk2C9T/xlp2uc/Eal54WFRL787JWVNZhIFJ NamQAcSuelZHsjoaPQsTscwFM5M4E1ZK1CQkR+WMAUquRXQB/E8lDTOgxuDw+iIAtdrH aP4XXaCWmHiaASW4suAVemekevWIgf9b2P5fgrk8Zn8XutKZy5D2isN3AI0GGtR8NYrO PtRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lhhs2ctn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b38si6993505plb.249.2019.02.25.13.37.19; Mon, 25 Feb 2019 13:37:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lhhs2ctn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732799AbfBYVgo (ORCPT + 99 others); Mon, 25 Feb 2019 16:36:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:43832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733212AbfBYVgk (ORCPT ); Mon, 25 Feb 2019 16:36:40 -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 BD48021850; Mon, 25 Feb 2019 21:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130599; bh=Sv3PCBzc4h+qeUjUv8Ha4P6iNjBWC4IrVaYPK/gskfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lhhs2ctn5WqW+/KMFSytE8z5TxQamk3JLOomYbjzYvjU+eMoZukikn2UckHsMGzDw S2R7N3jPJFFM1QAypFDMm8NqxEU84d6UaDxPKYLxsP3+A94FfGK1Y/CdC9chG2SpCB mUM/jU3VRaLKSKixXwKhaoOxKrcJEMRQwPbAwWRc= 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.20 171/183] staging: erofs: atomic_cond_read_relaxed on ref-locked workgroup Date: Mon, 25 Feb 2019 22:12:24 +0100 Message-Id: <20190225195123.961705410@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@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.20-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 @@ -221,23 +221,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;