• Waiman Long's avatar
    locking/rwsem: Guard against making count negative · a15ea1a3
    Waiman Long authored
    The upper bits of the count field is used as reader count. When
    sufficient number of active readers are present, the most significant
    bit will be set and the count becomes negative. If the number of active
    readers keep on piling up, we may eventually overflow the reader counts.
    This is not likely to happen unless the number of bits reserved for
    reader count is reduced because those bits are need for other purpose.
    
    To prevent this count overflow from happening, the most significant
    bit is now treated as a guard bit (RWSEM_FLAG_READFAIL). Read-lock
    attempts will now fail for both the fast and slow paths whenever this
    bit is set. So all those extra readers will be put to sleep in the wait
    list. Wakeup will not happen until the reader count reaches 0.
    Signed-off-by: default avatarWaiman Long <longman@redhat.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Tim Chen <tim.c.chen@linux.intel.com>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: huang ying <huang.ying.caritas@gmail.com>
    Link: https://lkml.kernel.org/r/20190520205918.22251-17-longman@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    a15ea1a3
rwsem.c 45.5 KB