• Artem Bityutskiy's avatar
    UBI: fix races in I/O debugging checks · ffb6b7e4
    Artem Bityutskiy authored
    When paranoid checs are enabled, the 'io_paral' test from the
    'mtd-utils' package fails. The symptoms are:
    
    UBI error: paranoid_check_all_ff: flash region at PEB 3973:512, length 15872 does not contain all 0xFF bytes
    UBI error: paranoid_check_all_ff: paranoid check failed for PEB 3973
    UBI: hex dump of the 512-16384 region
    
    It turned out to be a bug in the checking function. Suppose there
    are 2 tasks - A and B. Task A is the wear-levelling working
    ('wear_leveling_worker()'). It is reading the VID header to find
    which LEB this PEB belongs to. Say, task A is reading header
    of PEB X. Suppose PEB X is unmapped, and has no VID header.
    Task B is trying to write to PEB X.
    
    Task A: in 'ubi_io_read_vid_hdr()': reads the VID header from PEB X.
            The read data contain all 0xFF bytes.
    Task B: writes VID header and some data to PEB X
    Task A: assumes PEB X is empty, calls 'paranoid_check_all_ff()', which
            fails.
    
    The solution for this problem is to make 'paranoid_check_all_ff()'
    re-read the VID header, re-check it, and only if it is not there,
    check the rest. This now implemented by the 'paranoid_check_empty()'
    function.
    Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
    ffb6b7e4
io.c 40.2 KB