Re: [PATCH] powerpc/nvram: Fix an incorrect partition merge

From: xinhui
Date: Fri Dec 11 2015 - 00:44:11 EST


Hi, all
I do some tests *without* my fix patch. after reboot, I saw logs below.

[ 0.271236] WARNING: nvram partition checksum was 58, should be 24!
[ 0.271239] Terminating nvram partition scan

If I do tests *with* my fix patch, logs are:

[ 0.291419] --------NVRAM Partitions---------
[ 0.291422] indx sig chks len name
[ 0.291425] 0 51 15 512 ibm,CPU0log
[ 0.291428] 8192 51 94 128 ibm,CPU1log
[ 0.291431] 10240 70 fc 256 common
[ 0.291434] 14336 a0 b5 131 ibm,rtas-log
[ 0.291437] 16432 a0 4f 251 lnx,oops-log
[ 0.291440] 20448 7f 26 2818 wwwwwwwwwwww


HOW TO REPRODUCE this warning?:
root@ubuntu:/home/pp/host# ./a.out 0 xinhui 4096
root@ubuntu:/home/pp/host# ./a.out 0 xinhui2 4096
root@ubuntu:/home/pp/host# ./a.out 0 xinhui3 4096
root@ubuntu:/home/pp/host# ./a.out 1 xinhui2
root@ubuntu:/home/pp/host# ./a.out 1 xinhui3
root@ubuntu:/home/pp/host# ./a.out 1 xinhui

then logs from dmesg are:
[ 844.205337] XINHUI: dev_nvram_ioctl, [xinhui],[0]
[ 844.205449] --------NVRAM Partitions---------
[ 844.205482] indx sig chks len name
[ 844.205510] 0 51 15 512 ibm,CPU0log
[ 844.205541] 8192 51 94 128 ibm,CPU1log
[ 844.205573] 10240 70 fc 256 common
[ 844.205604] 14336 a0 b5 131 ibm,rtas-log
[ 844.205636] 16432 a0 4f 251 lnx,oops-log
[ 844.205667] 20448 7f 5e 2818 free space
[ 851.636438] XINHUI: dev_nvram_ioctl, [xinhui],[4096]
[ 851.636534] --------NVRAM Partitions---------
[ 851.636573] indx sig chks len name
[ 851.636614] 0 51 15 512 ibm,CPU0log
[ 851.636651] 8192 51 94 128 ibm,CPU1log
[ 851.636688] 10240 70 fc 256 common
[ 851.636725] 14336 a0 b5 131 ibm,rtas-log
[ 851.636762] 16432 a0 4f 251 lnx,oops-log
[ 851.636798] 20448 ef 89 257 xinhui
[ 851.636836] 24560 7f 5c 2561 free space
[ 855.354409] XINHUI: dev_nvram_ioctl, [xinhui2],[4096]
[ 855.354600] --------NVRAM Partitions---------
[ 855.354639] indx sig chks len name
[ 855.354671] 0 51 15 512 ibm,CPU0log
[ 855.354708] 8192 51 94 128 ibm,CPU1log
[ 855.355499] 10240 70 fc 256 common
[ 855.356186] 14336 a0 b5 131 ibm,rtas-log
[ 855.356816] 16432 a0 4f 251 lnx,oops-log
[ 855.357429] 20448 ef 89 257 xinhui
[ 855.357966] 24560 ef bb 257 xinhui2
[ 855.358466] 28672 7f 5a 2304 free space
[ 857.866574] XINHUI: dev_nvram_ioctl, [xinhui3],[4096]
[ 857.867449] --------NVRAM Partitions---------
[ 857.868250] indx sig chks len name
[ 857.869082] 0 51 15 512 ibm,CPU0log
[ 857.869901] 8192 51 94 128 ibm,CPU1log
[ 857.870727] 10240 70 fc 256 common
[ 857.871569] 14336 a0 b5 131 ibm,rtas-log
[ 857.872392] 16432 a0 4f 251 lnx,oops-log
[ 857.873202] 20448 ef 89 257 xinhui
[ 857.874019] 24560 ef bb 257 xinhui2
[ 857.874811] 28672 ef bc 257 xinhui3
[ 857.875568] 32784 7f 58 2047 free space
[ 1015.661796] XINHUI: dev_nvram_ioctl, [xinhui2],[16383]
[ 1015.662670] --------NVRAM Partitions---------
[ 1015.663457] indx sig chks len name
[ 1015.664150] 0 51 15 512 ibm,CPU0log
[ 1015.664788] 8192 51 94 128 ibm,CPU1log
[ 1015.665396] 10240 70 fc 256 common
[ 1015.665948] 14336 a0 b5 131 ibm,rtas-log
[ 1015.666470] 16432 a0 4f 251 lnx,oops-log
[ 1015.666977] 20448 ef 89 257 xinhui
[ 1015.667455] 24560 7f 1b 257 wwwwwwwwwwww
[ 1015.667914] 28672 ef bc 257 xinhui3
[ 1015.668359] 32784 7f 58 2047 free space
[ 1017.452055] XINHUI: dev_nvram_ioctl, [xinhui3],[16383]
[ 1017.452902] --------NVRAM Partitions---------
[ 1017.453731] indx sig chks len name
[ 1017.454531] 0 51 15 512 ibm,CPU0log
[ 1017.455341] 8192 51 94 128 ibm,CPU1log
[ 1017.456121] 10240 70 fc 256 common
[ 1017.456916] 14336 a0 b5 131 ibm,rtas-log
[ 1017.457705] 16432 a0 4f 251 lnx,oops-log
[ 1017.458473] 20448 ef 89 257 xinhui
[ 1017.459256] 24560 7f 58 2561 wwwwwwwwwwww
[ 1020.871652] XINHUI: dev_nvram_ioctl, [xinhui],[16383]
[ 1020.872141] --------NVRAM Partitions---------
[ 1020.872584] indx sig chks len name
[ 1020.873021] 0 51 15 512 ibm,CPU0log
[ 1020.873475] 8192 51 94 128 ibm,CPU1log
[ 1020.873907] 10240 70 fc 256 common
[ 1020.874339] 14336 a0 b5 131 ibm,rtas-log
[ 1020.874777] 16432 a0 4f 251 lnx,oops-log
[ 1020.875205] 20448 7f 24 2818 wwwwwwwwwwww

the we reboot system, we would see warning logs, it means nvram partition is corrupted!

WHY IT CORRUPTED?:
when we combine two continuous partitions, current codes do wrong merge!
see my fix patch codes below:
@@ -1017,8 +1017,8 @@ int nvram_remove_partition(const char *name, int sig,
}
if (prev) {
prev->header.length += part->header.length;
- prev->header.checksum = nvram_checksum(&part->header);
[XINHUI]: we update prev->header.length, then we need re-calculate it's checksum, not part's!
- rc = nvram_write_header(part);
[XINHUI]: we update prev->header, so we need write prev's header to nvram. not part's!
+ prev->header.checksum = nvram_checksum(&prev->header);
+ rc = nvram_write_header(prev);
[XINHUI]: this is the correct code.
if (rc <= 0) {
printk(KERN_ERR "nvram_remove_partition: nvram_write failed (%d)\n", rc);
return rc;

these two partitions looks like
before merge:
------ ----------- --------- -------
other| | prev | | part | | other...
------ ---------- --------- -------
after merge:
------ ---------------------- -------
other| | prev(updated) | | other...
------ ---------------------- -------

NOW let me share the *debug* patch and the user-space codes, they are :