Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp745263imu; Tue, 20 Nov 2018 06:22:19 -0800 (PST) X-Google-Smtp-Source: AJdET5dWFzQhQe6mqEISf+HxoPaf+JNvJojMYOKT4ZPbieRveDdkj1i/CIgTBlOPRVuanuq2W7Ri X-Received: by 2002:a62:4d82:: with SMTP id a124-v6mr2372040pfb.113.1542723739735; Tue, 20 Nov 2018 06:22:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542723739; cv=none; d=google.com; s=arc-20160816; b=uQkB+CqPeGYPuzJw62hvms5cnBWvgC5kyl083KNrcT5zzmIZFNGML2JM3awhWy+upw m186Ao5XtvnXzGCW/Ao55IK4BWKGGCE+lpJtrT0lDXSzV3wWWOwEMnbuE9N9XIYofhuZ ivyNBopuBUABV+ABzm4+98vWQqjJC8lWKJkG4eHOc1irleWiezak8a3Xtex9LLemZbTM sjQyPlvloW8IsUuuinpvMQpeJYcSvsjvpwuTi6NBck71mPig4T8wsAZhPTOCySi615tp 1LwcMvMLTN5RjdnSMV97qBx5k5IsGTuiCMXm2AIHx8Ov2qpdNne/UqEZV2jDiBnjmCQF 5GMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=PiEAniZdMH+DWJkT1CRwaKEpV7WcEgErwR0Zy+awvM4=; b=bbCVTvIritW5zi4FIeyovuvJ1LbxPW2iDTHQBrOWuofLpvYzVtLYpRT0B29wEW6Lvk wLFdVYM9Fg55lBA0Xi4i/QmL2VFsHpMt732CXlKa95dhGTXtOw//uJ9jvKnswxT9nUfP QWZjSVxyr60YRiPPXFzgTSplD/HejC9l45BGYKVSB7h8E/inxgi73XJc+8Da5sgjGlP0 bmUKZSNMgMv09O4Yr2XZBb7xYM1RbxXcBXM3F+krkWsZ00/aVOC8Kdlc9scDvIx+RZuQ gvad4ATXwwtchq/1HMMsI/R4iz3/N+UYrH1w0Trhat/S4RN7Od64/3IYCpfIjmeG9CYD 5e5w== ARC-Authentication-Results: i=1; mx.google.com; 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 y3-v6si42736409pfe.42.2018.11.20.06.22.04; Tue, 20 Nov 2018 06:22:19 -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; 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 S1729704AbeKUAu0 (ORCPT + 99 others); Tue, 20 Nov 2018 19:50:26 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:40331 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725995AbeKUAuZ (ORCPT ); Tue, 20 Nov 2018 19:50:25 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 34E5575C12150; Tue, 20 Nov 2018 22:21:00 +0800 (CST) Received: from localhost.localdomain (10.175.124.28) by smtp.huawei.com (10.3.19.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 20 Nov 2018 22:20:53 +0800 From: Gao Xiang To: Greg Kroah-Hartman , CC: LKML , , "Chao Yu" , Miao Xie , , Gao Xiang Subject: [PATCH 04/10] staging: erofs: fix `erofs_workgroup_{try_to_freeze, unfreeze}' Date: Tue, 20 Nov 2018 22:34:19 +0800 Message-ID: <20181120143425.43637-5-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181120143425.43637-1-gaoxiang25@huawei.com> References: <20181120143425.43637-1-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two minor issues in the current freeze interface: 1) Freeze interfaces have not related with CONFIG_DEBUG_SPINLOCK, therefore fix the incorrect conditions; 2) For SMP platforms, it should also disable preemption before doing atomic_cmpxchg in case that some high priority tasks preempt between atomic_cmpxchg and disable_preempt, then spin on the locked refcount later. Reviewed-by: Chao Yu Signed-off-by: Gao Xiang --- drivers/staging/erofs/internal.h | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h index eb80ba44d072..2e0ef92c138b 100644 --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -194,40 +194,49 @@ struct erofs_workgroup { #define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL) -static inline bool erofs_workgroup_try_to_freeze( - struct erofs_workgroup *grp, int v) +#if defined(CONFIG_SMP) +static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp, + int val) { -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) - if (v != atomic_cmpxchg(&grp->refcount, - v, EROFS_LOCKED_MAGIC)) - return false; preempt_disable(); -#else - preempt_disable(); - if (atomic_read(&grp->refcount) != v) { + if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) { preempt_enable(); return false; } -#endif return true; } -static inline void erofs_workgroup_unfreeze( - struct erofs_workgroup *grp, int v) +static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp, + int orig_val) { -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) - atomic_set(&grp->refcount, v); -#endif + atomic_set(&grp->refcount, orig_val); 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 bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp, + int val) +{ + preempt_disable(); + /* no need to spin on UP platforms, let's just disable preemption. */ + if (val != atomic_read(&grp->refcount)) { + preempt_enable(); + return false; + } + return true; +} + +static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp, + int orig_val) +{ + preempt_enable(); +} + static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) { int v = atomic_read(&grp->refcount); -- 2.14.4