Skip to content

Commit f96fb2d

Browse files
ubizjakbp3tk0v
authored andcommitted
x86/apic: Fix atomic update of offset in reserve_eilvt_offset()
The detection of atomic update failure in reserve_eilvt_offset() is not correct. The value returned by atomic_cmpxchg() should be compared to the old value from the location to be updated. If these two are the same, then atomic update succeeded and "eilvt_offsets[offset]" location is updated to "new" in an atomic way. Otherwise, the atomic update failed and it should be retried with the value from "eilvt_offsets[offset]" - exactly what atomic_try_cmpxchg() does in a correct and more optimal way. Fixes: a68c439 ("apic, x86: Check if EILVT APIC registers are available (AMD only)") Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5b422b9 commit f96fb2d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/x86/kernel/apic/apic.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,9 @@ static unsigned int reserve_eilvt_offset(int offset, unsigned int new)
422422
if (vector && !eilvt_entry_is_changeable(vector, new))
423423
/* may not change if vectors are different */
424424
return rsvd;
425-
rsvd = atomic_cmpxchg(&eilvt_offsets[offset], rsvd, new);
426-
} while (rsvd != new);
425+
} while (!atomic_try_cmpxchg(&eilvt_offsets[offset], &rsvd, new));
427426

428-
rsvd &= ~APIC_EILVT_MASKED;
427+
rsvd = new & ~APIC_EILVT_MASKED;
429428
if (rsvd && rsvd != vector)
430429
pr_info("LVT offset %d assigned for vector 0x%02x\n",
431430
offset, rsvd);

0 commit comments

Comments
 (0)