Skip to content

Commit de0e062

Browse files
committed
RAS/CEC: Check count_threshold unconditionally
The count_threshold should be checked unconditionally, after insertion too, so that a count_threshold value of 1 can cause an immediate offlining. I.e., offline the page on the *first* error encountered. Add comments to make it clear what cec_add_elem() does, while at it. Reported-by: WANG Chao <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: Tony Luck <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 6d8e294 commit de0e062

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

drivers/ras/cec.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ int cec_add_elem(u64 pfn)
294294

295295
ca->ces_entered++;
296296

297+
/* Array full, free the LRU slot. */
297298
if (ca->n == MAX_ELEMS)
298299
WARN_ON(!del_lru_elem_unlocked(ca));
299300

@@ -306,24 +307,17 @@ int cec_add_elem(u64 pfn)
306307
(void *)&ca->array[to],
307308
(ca->n - to) * sizeof(u64));
308309

309-
ca->array[to] = (pfn << PAGE_SHIFT) |
310-
(DECAY_MASK << COUNT_BITS) | 1;
311-
310+
ca->array[to] = pfn << PAGE_SHIFT;
312311
ca->n++;
313-
314-
ret = 0;
315-
316-
goto decay;
317312
}
318313

319-
count = COUNT(ca->array[to]);
320-
321-
if (count < count_threshold) {
322-
ca->array[to] |= (DECAY_MASK << COUNT_BITS);
323-
ca->array[to]++;
314+
/* Add/refresh element generation and increment count */
315+
ca->array[to] |= DECAY_MASK << COUNT_BITS;
316+
ca->array[to]++;
324317

325-
ret = 0;
326-
} else {
318+
/* Check action threshold and soft-offline, if reached. */
319+
count = COUNT(ca->array[to]);
320+
if (count >= count_threshold) {
327321
u64 pfn = ca->array[to] >> PAGE_SHIFT;
328322

329323
if (!pfn_valid(pfn)) {
@@ -338,15 +332,14 @@ int cec_add_elem(u64 pfn)
338332
del_elem(ca, to);
339333

340334
/*
341-
* Return a >0 value to denote that we've reached the offlining
342-
* threshold.
335+
* Return a >0 value to callers, to denote that we've reached
336+
* the offlining threshold.
343337
*/
344338
ret = 1;
345339

346340
goto unlock;
347341
}
348342

349-
decay:
350343
ca->decay_count++;
351344

352345
if (ca->decay_count >= CLEAN_ELEMS)

0 commit comments

Comments
 (0)