Skip to content

Commit 73f5c66

Browse files
Gao Xianggregkh
authored andcommitted
staging: erofs: fix `erofs_workgroup_{try_to_freeze, unfreeze}'
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 <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent df134b8 commit 73f5c66

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

drivers/staging/erofs/internal.h

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,40 +194,49 @@ struct erofs_workgroup {
194194

195195
#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
196196

197-
static inline bool erofs_workgroup_try_to_freeze(
198-
struct erofs_workgroup *grp, int v)
197+
#if defined(CONFIG_SMP)
198+
static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
199+
int val)
199200
{
200-
#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
201-
if (v != atomic_cmpxchg(&grp->refcount,
202-
v, EROFS_LOCKED_MAGIC))
203-
return false;
204201
preempt_disable();
205-
#else
206-
preempt_disable();
207-
if (atomic_read(&grp->refcount) != v) {
202+
if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
208203
preempt_enable();
209204
return false;
210205
}
211-
#endif
212206
return true;
213207
}
214208

215-
static inline void erofs_workgroup_unfreeze(
216-
struct erofs_workgroup *grp, int v)
209+
static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
210+
int orig_val)
217211
{
218-
#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
219-
atomic_set(&grp->refcount, v);
220-
#endif
212+
atomic_set(&grp->refcount, orig_val);
221213
preempt_enable();
222214
}
223215

224-
#if defined(CONFIG_SMP)
225216
static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
226217
{
227218
return atomic_cond_read_relaxed(&grp->refcount,
228219
VAL != EROFS_LOCKED_MAGIC);
229220
}
230221
#else
222+
static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
223+
int val)
224+
{
225+
preempt_disable();
226+
/* no need to spin on UP platforms, let's just disable preemption. */
227+
if (val != atomic_read(&grp->refcount)) {
228+
preempt_enable();
229+
return false;
230+
}
231+
return true;
232+
}
233+
234+
static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
235+
int orig_val)
236+
{
237+
preempt_enable();
238+
}
239+
231240
static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
232241
{
233242
int v = atomic_read(&grp->refcount);

0 commit comments

Comments
 (0)