6.18.52-rc1 review
Greg Kroah-Hartman
maintainerPATCH 881/1518 selftests/mm: ksm_tests: use kselftest framework
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Rapoport (Microsoft) <[email protected]>
[ Upstream commit 4cc68d5f52de9614e2db70f43c52f012d1ebb5ad ]
Convert ksm_tests to use kselftest framework for reporting and tracking successful and failing runs.
Stable-dep-of: 15828a150c58 ("selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes")
--- tools/testing/selftests/mm/ksm_tests.c | 180 +++++++++++-------------- 1 file changed, 81 insertions(+), 99 deletions(-)
tools/testing/selftests/mm/ksm_tests.c +81 -99
@@ -175,12 +175,12 @@ static void *allocate_memory(void *ptr, int prot, int mapping, char data, size_void *map_ptr =mmap (ptr, map_size,PROT_WRITE , mapping,-1 ,0 );if (!map_ptr) { -perror ("mmap" ); +ksft_perror ("mmap" );return NULL ; }memset (map_ptr, data, map_size);if (mprotect (map_ptr, map_size, prot)) { -perror ("mprotect" ); +ksft_perror ("mprotect" );munmap (map_ptr, map_size);return NULL ; }
@@ -201,11 +201,11 @@ static int ksm_do_scan(int scan_count, struct timespec start_time, int timeout)if (ksm_read_sysfs (KSM_FP ("full_scans" ), &cur_scan))return 1 ;if (clock_gettime (CLOCK_MONOTONIC_RAW , &cur_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return 1 ; }if ((cur_time.tv_sec - start_time.tv_sec) > timeout) { -printf ("Scan time limit exceeded\n" ); +ksft_print_msg ("Scan time limit exceeded\n" );return 1 ; } }
@@ -218,12 +218,12 @@ static int ksm_merge_pages(int merge_type, void *addr, size_t size, {if (merge_type ==KSM_MERGE_MADVISE ) {if (madvise (addr, size,MADV_MERGEABLE )) { -perror ("madvise" ); +ksft_perror ("madvise" );return 1 ; } }else if (merge_type ==KSM_MERGE_PRCTL ) {if (prctl (PR_SET_MEMORY_MERGE ,1 ,0 ,0 ,0 )) { -perror ("prctl" ); +ksft_perror ("prctl" );return 1 ; } }
@@ -242,7 +242,7 @@ static int ksm_unmerge_pages(void *addr, size_t size, struct timespec start_time, int timeout) { if (madvise(addr, size, MADV_UNMERGEABLE)) { -perror ("madvise" ); +ksft_perror ("madvise" );return 1 ; }return 0 ;
@@ -324,7 +324,7 @@ static int check_ksm_merge(int merge_type, int mapping, int prot,struct timespec start_time;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return KSFT_FAIL ; }
@@ -338,7 +338,6 @@ static int check_ksm_merge(int merge_type, int mapping, int prot,/* verify that the right number of pages are merged */ if (assert_ksm_pages_count (page_count)) { -printf ("OK\n" );munmap (map_ptr, page_size * page_count);if (merge_type ==KSM_MERGE_PRCTL )prctl (PR_SET_MEMORY_MERGE ,0 ,0 ,0 ,0 );
@@ -346,7 +345,6 @@ static int check_ksm_merge(int merge_type, int mapping, int prot, } err_out: -printf ("Not OK\n" );munmap (map_ptr, page_size * page_count);return KSFT_FAIL ; }
@@ -358,7 +356,7 @@ static int check_ksm_unmerge(int merge_type, int mapping, int prot, int timeout,int page_count =2 ;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return KSFT_FAIL ; }
@@ -380,13 +378,11 @@ static int check_ksm_unmerge(int merge_type, int mapping, int prot, int timeout,/* check that unmerging was successful and 0 pages are currently merged */ if (assert_ksm_pages_count (0 )) { -printf ("OK\n" );munmap (map_ptr, page_size * page_count);return KSFT_PASS ; } err_out: -printf ("Not OK\n" );munmap (map_ptr, page_size * page_count);return KSFT_FAIL ; }
@@ -398,7 +394,7 @@ static int check_ksm_zero_page_merge(int merge_type, int mapping, int prot, longstruct timespec start_time;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return KSFT_FAIL ; }
@@ -425,12 +421,10 @@ static int check_ksm_zero_page_merge(int merge_type, int mapping, int prot, longelse if (!use_zero_pages && !assert_ksm_pages_count (page_count)) goto err_out; -printf ("OK\n" );munmap (map_ptr, page_size * page_count);return KSFT_PASS ; err_out: -printf ("Not OK\n" );munmap (map_ptr, page_size * page_count);return KSFT_FAIL ; }
@@ -465,16 +459,16 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeoint first_node;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return KSFT_FAIL ; }if (numa_available () <0 ) { -perror ("NUMA support not enabled" ); +ksft_print_msg ("NUMA support not enabled\n" );return KSFT_SKIP ; }if (numa_num_configured_nodes () <=1 ) { -printf ("At least 2 NUMA nodes must be available\n" ); +ksft_print_msg ("At least 2 NUMA nodes must be available\n" );return KSFT_SKIP ; }if (ksm_write_sysfs (KSM_FP ("merge_across_nodes" ), merge_across_nodes))
@@ -485,7 +479,7 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeo numa1_map_ptr =numa_alloc_onnode (page_size, first_node); numa2_map_ptr =numa_alloc_onnode (page_size,get_next_mem_node (first_node));if (!numa1_map_ptr || !numa2_map_ptr) { -perror ("numa_alloc_onnode" ); +ksft_perror ("numa_alloc_onnode" );return KSFT_FAIL ; }
@@ -510,13 +504,11 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeonuma_free (numa1_map_ptr, page_size);numa_free (numa2_map_ptr, page_size); -printf ("OK\n" );return KSFT_PASS ; err_out:numa_free (numa1_map_ptr, page_size);numa_free (numa2_map_ptr, page_size); -printf ("Not OK\n" );return KSFT_FAIL ; }
@@ -529,7 +521,7 @@ static int ksm_merge_hugepages_time(int merge_type, int mapping, int prot,int pagemap_fd, n_normal_pages, n_huge_pages;if (!thp_is_enabled ()) { -printf ("Transparent Hugepages not available\n" ); +ksft_print_msg ("Transparent Hugepages not available\n" );return KSFT_SKIP ; }
@@ -559,36 +551,35 @@ static int ksm_merge_hugepages_time(int merge_type, int mapping, int prot,else n_huge_pages++; } -printf ("Number of normal pages: %d\n" , n_normal_pages); -printf ("Number of huge pages: %d\n" , n_huge_pages); +ksft_print_msg ("Number of normal pages: %d\n" , n_normal_pages); +ksft_print_msg ("Number of huge pages: %d\n" , n_huge_pages);memset (map_ptr,'*' , len);if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; }if (ksm_merge_pages (merge_type, map_ptr, map_size, start_time, timeout)) goto err_out;if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; } scan_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); -printf ("Total size: %lu MiB\n" , map_size /MB ); -printf ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , +ksft_print_msg ("Total size: %lu MiB\n" , map_size /MB ); +ksft_print_msg ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , scan_time_ns %NSEC_PER_SEC ); -printf ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / +ksft_print_msg ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / ((double )scan_time_ns /NSEC_PER_SEC ));munmap (map_ptr_orig, len +HPAGE_SIZE );return KSFT_PASS ; err_out: -printf ("Not OK\n" );munmap (map_ptr_orig, len +HPAGE_SIZE );return KSFT_FAIL ; }
@@ -606,30 +597,29 @@ static int ksm_merge_time(int merge_type, int mapping, int prot, int timeout, sireturn KSFT_FAIL ;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; }if (ksm_merge_pages (merge_type, map_ptr, map_size, start_time, timeout)) goto err_out;if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; } scan_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); -printf ("Total size: %lu MiB\n" , map_size /MB ); -printf ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , +ksft_print_msg ("Total size: %lu MiB\n" , map_size /MB ); +ksft_print_msg ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , scan_time_ns %NSEC_PER_SEC ); -printf ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / +ksft_print_msg ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / ((double )scan_time_ns /NSEC_PER_SEC ));munmap (map_ptr, map_size);return KSFT_PASS ; err_out: -printf ("Not OK\n" );munmap (map_ptr, map_size);return KSFT_FAIL ; }
@@ -646,37 +636,36 @@ static int ksm_unmerge_time(int merge_type, int mapping, int prot, int timeout,if (!map_ptr)return KSFT_FAIL ;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; }if (ksm_merge_pages (merge_type, map_ptr, map_size, start_time, timeout)) goto err_out;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; }if (ksm_unmerge_pages (map_ptr, map_size, start_time, timeout)) goto err_out;if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; } scan_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); -printf ("Total size: %lu MiB\n" , map_size /MB ); -printf ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , +ksft_print_msg ("Total size: %lu MiB\n" , map_size /MB ); +ksft_print_msg ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , scan_time_ns %NSEC_PER_SEC ); -printf ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / +ksft_print_msg ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / ((double )scan_time_ns /NSEC_PER_SEC ));munmap (map_ptr, map_size);return KSFT_PASS ; err_out: -printf ("Not OK\n" );munmap (map_ptr, map_size);return KSFT_FAIL ; }
@@ -695,24 +684,24 @@ static int ksm_cow_time(int merge_type, int mapping, int prot, int timeout, sizereturn KSFT_FAIL ;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return KSFT_FAIL ; }for (size_t i =0 ; i < page_count -1 ; i = i +2 )memset (map_ptr + page_size * i,'-' ,1 );if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" );return KSFT_FAIL ; } cow_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); -printf ("Total size: %lu MiB\n\n" , (page_size * page_count) /MB ); -printf ("Not merged pages:\n" ); -printf ("Total time: %ld.%09ld s\n" , cow_time_ns /NSEC_PER_SEC , +ksft_print_msg ("Total size: %lu MiB\n\n" , (page_size * page_count) /MB ); +ksft_print_msg ("Not merged pages:\n" ); +ksft_print_msg ("Total time: %ld.%09ld s\n" , cow_time_ns /NSEC_PER_SEC , cow_time_ns %NSEC_PER_SEC ); -printf ("Average speed: %.3f MiB/s\n\n" , ((page_size * (page_count /2 )) /MB ) / +ksft_print_msg ("Average speed: %.3f MiB/s\n\n" , ((page_size * (page_count /2 )) /MB ) / ((double )cow_time_ns /NSEC_PER_SEC ));/* Create 2000 pairs of duplicate pages */
@@ -724,30 +713,29 @@ static int ksm_cow_time(int merge_type, int mapping, int prot, int timeout, size goto err_out;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; }for (size_t i =0 ; i < page_count -1 ; i = i +2 )memset (map_ptr + page_size * i,'-' ,1 );if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { -perror ("clock_gettime" ); +ksft_perror ("clock_gettime" ); goto err_out; } cow_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); -printf ("Merged pages:\n" ); -printf ("Total time: %ld.%09ld s\n" , cow_time_ns /NSEC_PER_SEC , +ksft_print_msg ("Merged pages:\n" ); +ksft_print_msg ("Total time: %ld.%09ld s\n" , cow_time_ns /NSEC_PER_SEC , cow_time_ns %NSEC_PER_SEC ); -printf ("Average speed: %.3f MiB/s\n" , ((page_size * (page_count /2 )) /MB ) / +ksft_print_msg ("Average speed: %.3f MiB/s\n" , ((page_size * (page_count /2 )) /MB ) / ((double )cow_time_ns /NSEC_PER_SEC ));munmap (map_ptr, page_size * page_count);return KSFT_PASS ; err_out: -printf ("Not OK\n" );munmap (map_ptr, page_size * page_count);return KSFT_FAIL ; }
@@ -765,6 +753,10 @@ int main(int argc, char *argv[])bool use_zero_pages =KSM_USE_ZERO_PAGES_DEFAULT ;bool merge_across_nodes =KSM_MERGE_ACROSS_NODES_DEFAULT ;long size_MB =0 ; +const char *test_descr ="KSM merging" ; + +ksft_print_header (); +ksft_set_plan (1 );while ((opt =getopt (argc, argv,"dha:p:l:z:m:s:t:MUZNPCHD" )) !=-1 ) {switch (opt) {
@@ -773,17 +765,13 @@ int main(int argc, char *argv[])break ;case 'p' : page_count =atol (optarg); -if (page_count <=0 ) { -printf ("The number of pages must be greater than 0\n" ); -return KSFT_FAIL ; - } +if (page_count <=0 ) +ksft_exit_fail_msg ("The number of pages must be greater than 0\n" );break ;case 'l' : ksm_scan_limit_sec =atoi (optarg); -if (ksm_scan_limit_sec <=0 ) { -printf ("Timeout value must be greater than 0\n" ); -return KSFT_FAIL ; - } +if (ksm_scan_limit_sec <=0 ) +ksft_exit_fail_msg ("Timeout value must be greater than 0\n" );break ;case 'h' :print_help ();
@@ -805,19 +793,15 @@ int main(int argc, char *argv[])break ;case 's' : size_MB =atoi (optarg); -if (size_MB <=0 ) { -printf ("Size must be greater than 0\n" ); -return KSFT_FAIL ; - } +if (size_MB <=0 ) +ksft_exit_fail_msg ("Size must be greater than 0\n" );break ;case 't' : {int tmp =atoi (optarg); -if (tmp <0 || tmp >KSM_MERGE_LAST ) { -printf ("Invalid merge type\n" ); -return KSFT_FAIL ; - } +if (tmp <0 || tmp >KSM_MERGE_LAST ) +ksft_exit_fail_msg ("Invalid merge type\n" ); merge_type = tmp; }break ;
@@ -845,82 +829,80 @@ int main(int argc, char *argv[]) test_name =KSM_COW_TIME ;break ;default : -return KSFT_FAIL ; +ksft_exit_fail_msg ("Unknown option\n" ); } }if (prot ==0 ) prot =str_to_prot (KSM_PROT_STR_DEFAULT ); -if (access (KSM_SYSFS_PATH ,F_OK )) { -printf ("Config KSM not enabled\n" ); -return KSFT_SKIP ; - } +if (access (KSM_SYSFS_PATH ,F_OK )) +ksft_exit_skip ("Config KSM not enabled\n" ); -if (ksm_save_def (&ksm_sysfs_old)) { -printf ("Cannot save default tunables\n" ); -return KSFT_FAIL ; - } +if (ksm_save_def (&ksm_sysfs_old)) +ksft_exit_fail_msg ("Cannot save default tunables\n" );if (ksm_write_sysfs (KSM_FP ("run" ),2 ) ||ksm_write_sysfs (KSM_FP ("sleep_millisecs" ),0 ) ||numa_available () ?0 :ksm_write_sysfs (KSM_FP ("merge_across_nodes" ),1 ) ||ksm_write_sysfs (KSM_FP ("pages_to_scan" ), page_count)) -return KSFT_FAIL ; +ksft_exit_fail_msg ("Cannot set up KSM tunables\n" );switch (test_name) {case CHECK_KSM_MERGE : + test_descr ="KSM merging" ; ret =check_ksm_merge (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, page_count, ksm_scan_limit_sec, page_size);break ;case CHECK_KSM_UNMERGE : + test_descr ="KSM unmerging" ; ret =check_ksm_unmerge (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, page_size);break ;case CHECK_KSM_ZERO_PAGE_MERGE : + test_descr ="KSM zero page merging" ; ret =check_ksm_zero_page_merge (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, page_count, ksm_scan_limit_sec, use_zero_pages, page_size);break ;case CHECK_KSM_NUMA_MERGE : + test_descr ="KSM NUMA merging" ; ret =check_ksm_numa_merge (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, merge_across_nodes, page_size);break ;case KSM_MERGE_TIME : -if (size_MB ==0 ) { -printf ("Option '-s' is required.\n" ); -return KSFT_FAIL ; - } +if (size_MB ==0 ) +ksft_exit_fail_msg ("Option '-s' is required\n" ); + test_descr ="KSM merge time" ; ret =ksm_merge_time (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, size_MB);break ;case KSM_MERGE_TIME_HUGE_PAGES : -if (size_MB ==0 ) { -printf ("Option '-s' is required.\n" ); -return KSFT_FAIL ; - } +if (size_MB ==0 ) +ksft_exit_fail_msg ("Option '-s' is required\n" ); + test_descr ="KSM merge time with huge pages" ; ret =ksm_merge_hugepages_time (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, size_MB);break ;case KSM_UNMERGE_TIME : -if (size_MB ==0 ) { -printf ("Option '-s' is required.\n" ); -return KSFT_FAIL ; - } +if (size_MB ==0 ) +ksft_exit_fail_msg ("Option '-s' is required\n" ); + test_descr ="KSM unmerge time" ; ret =ksm_unmerge_time (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, size_MB);break ;case KSM_COW_TIME : + test_descr ="KSM COW time" ; ret =ksm_cow_time (merge_type,MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, page_size);break ; } -if (ksm_restore (&ksm_sysfs_old)) { -printf ("Cannot restore default tunables\n" ); -return KSFT_FAIL ; - } +if (ksm_restore (&ksm_sysfs_old)) +ksft_print_msg ("Cannot restore default tunables\n" ); + +ksft_test_result_report (ret,"%s\n" , test_descr); -return ret; +ksft_finished (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 882/1518 selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 15828a150c5806869b7feb9e38ad2c0284fbf18a ]
The KSM NUMA merge test allocates identical pages on different NUMA nodes and verifies KSM behavior with merge_across_nodes enabled and disabled.
On systems with memoryless NUMA nodes, for example:
#numactl -H
available: 2 nodes (0,4)
.....
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
node 0 size: 14825 MB
node 0 free: 1382 MB
node 4 cpus:
node 4 size: 0 MB
node 4 free: 0 MBthe test may attempt to allocate memory on a node without memory, causing numa_alloc_onnode() to fail and resulting in a spurious test failure.
The test currently checks numa_num_configured_nodes() to determine whether sufficient NUMA nodes are available. However, configured nodes do not necessarily have memory.
Reuse the existing get_first_mem_node() and get_next_mem_node() helpers to locate NUMA nodes that actually contain memory, and skip the test when fewer than two such nodes are available.
Before patch:
---------------------------
running ./ksm_tests -N -m 1
---------------------------
mbind: Invalid argument
ok 1 KSM NUMA merging
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 [PASS]
ok 1 ksm_tests -N -m 1
---------------------------
running ./ksm_tests -N -m 0
---------------------------
mbind: Invalid argument
not ok 1 KSM NUMA merging
Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0 [FAIL]
not ok 2 ksm_tests -N -m 0 # exit=1
After patch:
---------------------------
running ./ksm_tests -N -m 1
---------------------------
At least 2 NUMA nodes with memory must be available ok 1
SKIP KSM NUMA merging
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 [PASS]
ok 1 ksm_tests -N -m 1
---------------------------
running ./ksm_tests -N -m 0
---------------------------
At least 2 NUMA nodes with memory must be available ok 1
SKIP KSM NUMA merging
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 [PASS]
ok 2 ksm_tests -N -m 0
--- tools/testing/selftests/mm/ksm_tests.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
tools/testing/selftests/mm/ksm_tests.c +9 -7
@@ -440,9 +440,9 @@ static int get_next_mem_node(int node) mem_node = i % (max_node +1 ); node_size =numa_node_size (mem_node,NULL );if (node_size >0 ) -break ; +return mem_node; } -return mem_node; +return -ENODEV ; }static int get_first_mem_node (void )
@@ -455,8 +455,8 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeo {void *numa1_map_ptr, *numa2_map_ptr;struct timespec start_time; +int first_node, second_node;int page_count =2 ; -int first_node;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) {ksft_perror ("clock_gettime" );
@@ -467,17 +467,19 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeoksft_print_msg ("NUMA support not enabled\n" );return KSFT_SKIP ; } -if (numa_num_configured_nodes () <=1 ) { -ksft_print_msg ("At least 2 NUMA nodes must be available\n" ); + first_node =get_first_mem_node (); + second_node =get_next_mem_node (first_node); + +if (second_node <0 ) { +ksft_print_msg ("At least 2 NUMA nodes with memory must be available\n" );return KSFT_SKIP ; }if (ksm_write_sysfs (KSM_FP ("merge_across_nodes" ), merge_across_nodes))return KSFT_FAIL ;/* allocate 2 pages in 2 different NUMA nodes and fill them with the same data */ - first_node =get_first_mem_node (); numa1_map_ptr =numa_alloc_onnode (page_size, first_node); - numa2_map_ptr =numa_alloc_onnode (page_size,get_next_mem_node (first_node)); + numa2_map_ptr =numa_alloc_onnode (page_size, second_node);if (!numa1_map_ptr || !numa2_map_ptr) {ksft_perror ("numa_alloc_onnode" );return KSFT_FAIL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 883/1518 selftests/mm: fix ternary operator precedence in ksm_tests
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 4e1fbffb3333626682a011db7c4b4e9e40ba96d4 ]
The KSM selftest uses conditional expressions to skip accesses to merge_across_nodes on systems without NUMA support. However, the ternary operator is combined with logical OR without parentheses:
a || numa_available() ? 0 : b || c
Due to operator precedence rules, this is parsed as:
(a || numa_available()) ? 0 : (b || c)
instead of the intended:
a || (numa_available() ? 0 : b) || c
Add parentheses around the conditional expressions to ensure the correct evaluation order.
--- tools/testing/selftests/mm/ksm_tests.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/mm/ksm_tests.c +6 -6
@@ -288,8 +288,8 @@ static bool assert_ksm_pages_count(long dupl_page_count)static int ksm_save_def (struct ksm_sysfs *ksm_sysfs) { if (ksm_read_sysfs(KSM_FP("max_page_sharing"), &ksm_sysfs->max_page_sharing) || - numa_available() ? 0 : - ksm_read_sysfs(KSM_FP("merge_across_nodes"), &ksm_sysfs->merge_across_nodes) || + (numa_available() ? 0 : + ksm_read_sysfs(KSM_FP("merge_across_nodes"), &ksm_sysfs->merge_across_nodes)) || ksm_read_sysfs(KSM_FP("sleep_millisecs"), &ksm_sysfs->sleep_millisecs) || ksm_read_sysfs(KSM_FP("pages_to_scan"), &ksm_sysfs->pages_to_scan) || ksm_read_sysfs(KSM_FP("run"), &ksm_sysfs->run) ||
@@ -304,8 +304,8 @@ static int ksm_save_def(struct ksm_sysfs *ksm_sysfs)static int ksm_restore (struct ksm_sysfs *ksm_sysfs) { if (ksm_write_sysfs(KSM_FP("max_page_sharing"), ksm_sysfs->max_page_sharing) || - numa_available() ? 0 : - ksm_write_sysfs(KSM_FP("merge_across_nodes"), ksm_sysfs->merge_across_nodes) || + (numa_available() ? 0 : + ksm_write_sysfs(KSM_FP("merge_across_nodes"), ksm_sysfs->merge_across_nodes)) || ksm_write_sysfs(KSM_FP("pages_to_scan"), ksm_sysfs->pages_to_scan) || ksm_write_sysfs(KSM_FP("run"), ksm_sysfs->run) || ksm_write_sysfs(KSM_FP("sleep_millisecs"), ksm_sysfs->sleep_millisecs) ||
@@ -846,8 +846,8 @@ int main(int argc, char *argv[])if (ksm_write_sysfs (KSM_FP ("run" ),2 ) ||ksm_write_sysfs (KSM_FP ("sleep_millisecs" ),0 ) || -numa_available () ?0 : -ksm_write_sysfs (KSM_FP ("merge_across_nodes" ),1 ) || + (numa_available () ?0 : +ksm_write_sysfs (KSM_FP ("merge_across_nodes" ),1 )) ||ksm_write_sysfs (KSM_FP ("pages_to_scan" ), page_count))ksft_exit_fail_msg ("Cannot set up KSM tunables\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 884/1518 arm64: dts: qcom: sc8280xp-blackrock: Fix swapped USB QMP PHY vdda-phy/vdda-pll supplies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit ff7155df9a9543af1eb9722563e6dcda33c1a97d ]
The QMP PHY expects the vdda-phy supply to be around 0.88V and the vdda-pll supply to be 1.2V. But these two supplies are swapped for the USB QMP PHYs on this board, feeding 1.2V to vdda-phy and 0.9V to vdda-pll.
Fix it by swapping the two supplies back.
--- arch/arm64/boot/dts/qcom/sc8280xp-microsoft-blackrock.dts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sc8280xp-microsoft-blackrock.dts +4 -4
@@ -1000,8 +1000,8 @@ &usb_0_hsphy { }; &usb_0_qmpphy { - vdda-phy-supply = <&vreg_l4d>; - vdda-pll-supply = <&vreg_l9d>; + vdda-phy-supply = <&vreg_l9d>; + vdda-pll-supply = <&vreg_l4d>; orientation-switch;
@@ -1037,8 +1037,8 @@ &usb_1_hsphy { }; &usb_1_qmpphy { - vdda-phy-supply = <&vreg_l3b>; - vdda-pll-supply = <&vreg_l4b>; + vdda-phy-supply = <&vreg_l4b>; + vdda-pll-supply = <&vreg_l3b>; orientation-switch;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 885/1518 arm64: dts: qcom: qcs8550-aim300: Fix swapped USB QMP PHY vdda-phy/vdda-pll supplies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit c0ea3b6339881c2a5fff0830557b1279d9681036 ]
The QMP PHY expects the vdda-phy supply to be around 0.88V and the vdda-pll supply to be 1.2V. But these two supplies are swapped for the USB QMP PHY on this board, feeding 1.2V to vdda-phy and 0.88V to vdda-pll.
Fix it by swapping the two supplies back.
--- arch/arm64/boot/dts/qcom/qcs8550-aim300.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/qcs8550-aim300.dtsi +2 -2
@@ -396,8 +396,8 @@ &usb_1_hsphy { }; &usb_dp_qmpphy { - vdda-phy-supply = <&vreg_l3e_1p2>; - vdda-pll-supply = <&vreg_l3f_0p88>; + vdda-phy-supply = <&vreg_l3f_0p88>; + vdda-pll-supply = <&vreg_l3e_1p2>; }; &xo_board {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 886/1518 arm64: dts: qcom: sm7225-fairphone-fp4: Fix swapped USB QMP PHY vdda-phy/vdda-pll supplies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit a3b3a060b696d964c769a7d9dc5835c79e4fe964 ]
The QMP PHY expects the vdda-phy supply to be around 0.88V and the vdda-pll supply to be 1.2V. But these two supplies are swapped for the USB QMP PHY on this board, feeding 1.2V to vdda-phy and 0.9V to vdda-pll.
Fix it by swapping the two supplies back.
--- arch/arm64/boot/dts/qcom/sm7225-fairphone-fp4.dts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sm7225-fairphone-fp4.dts +2 -2
@@ -1179,8 +1179,8 @@ &usb_1_hsphy { }; &usb_1_qmpphy { - vdda-phy-supply = <&vreg_l22a>; - vdda-pll-supply = <&vreg_l16a>; + vdda-phy-supply = <&vreg_l16a>; + vdda-pll-supply = <&vreg_l22a>; status = "okay"; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 887/1518 arm64: dts: qcom: sar2130p: Fix swapped USB QMP PHY vdda-phy/vdda-pll supplies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 9d883d21fc12c873eee2f864f706c38a289bef59 ]
The QMP PHY expects the vdda-phy supply to be around 0.88V and the vdda-pll supply to be 1.2V. But these two supplies are swapped for the USB QMP PHY on this board, feeding 1.2V to vdda-phy and 0.9V to vdda-pll.
Fix it by swapping the two supplies back.
--- arch/arm64/boot/dts/qcom/sar2130p-qar2130p.dts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sar2130p-qar2130p.dts +2 -2
@@ -551,8 +551,8 @@ &usb_1_hsphy { }; &usb_dp_qmpphy { - vdda-phy-supply = <&vreg_l3a_1p2>; - vdda-pll-supply = <&vreg_l1a_0p91>; + vdda-phy-supply = <&vreg_l1a_0p91>; + vdda-pll-supply = <&vreg_l3a_1p2>; status = "okay"; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 888/1518 bpf: Check load-acquire src ptr type before the load
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit b87803391baa7e0bef60549d8841f12e549ad057 ]
check_atomic_load() calls check_load_mem() before atomic_ptr_type_ok(). For a load-acquire that fetches into its own source register (dst_reg == src_reg), check_load_mem() overwrites src_reg's type with the type of the loaded value, so the subsequent atomic_ptr_type_ok() no longer sees the source pointer and fails to reject the disallowed types (ctx, pkt, flow_keys, sock).
Since bpf_convert_ctx_accesses() does not rewrite atomic loads, the raw access to the underlying kernel object is left in place. The destination type is taken from the ctx access itself, so a load-acquire of the sk field of struct __sk_buff for example leaves the register typed as PTR_TO_SOCK_COMMON_OR_NULL, which type_is_sk_pointer() does not match either, while it actually holds unconverted struct sk_buff bytes. Once the NULL check has passed this is a type confusion, not just a leak of kernel data.
Validate src_reg with check_reg_arg() and check the source pointer type with atomic_ptr_type_ok() before the load again, mirroring check_atomic_rmw(). Out-of-range register numbers are already rejected earlier by check_and_resolve_insns() (commit 503d21ef8eac ("bpf: Do register range validation early")), and the only exemption there, is_stack_arg_ldx(), requires BPF_LDX | BPF_MEM | BPF_DW and thus never matches a BPF_ATOMIC insn. atomic_ptr_type_ok() can therefore not dereference register state out of bounds, that is, the out-of-bounds read addressed by the Fixes commit below does not reappear (as proven also via selftest).
--- kernel/bpf/verifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +2 -2
@@ -7975,7 +7975,7 @@ static int check_atomic_load(struct bpf_verifier_env *env, {int err; - err =check_load_mem (env, insn, true, false, false,"atomic_load" ); + err =check_reg_arg (env, insn->src_reg,SRC_OP );if (err)return err;
@@ -7986,7 +7986,7 @@ static int check_atomic_load(struct bpf_verifier_env *env,return -EACCES ; } -return 0 ; +return check_load_mem (env, insn, true, false, false,"atomic_load" ); } static int check_atomic_store(struct bpf_verifier_env *env,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 889/1518 intel_idle: Initialize sysfs after cpuidle driver initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Artem Bityutskiy <[email protected]>
[ Upstream commit ff24f314447a25164bac85cb310c382e289afdbe ]
Reorder initialization calls to initialize the internal driver data before sysfs:
Was:intel_idle_sysfs_init();intel_idle_cpuidle_driver_init();
Now:intel_idle_cpuidle_driver_init();intel_idle_sysfs_init();
Follow the general principle that drivers should initialize internal state before registering external interfaces like sysfs, avoiding potential usage before full initialization.
Stable-dep-of: 9eadbed788df ("intel_idle: Avoid using deep idle states during initialization")
--- drivers/idle/intel_idle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +2 -2
@@ -2485,12 +2485,12 @@ static int __init intel_idle_init(void)if (!intel_idle_cpuidle_devices)return -ENOMEM ; +intel_idle_cpuidle_driver_init (&intel_idle_driver); + retval =intel_idle_sysfs_init ();if (retval)pr_warn ("failed to initialized sysfs" ); -intel_idle_cpuidle_driver_init (&intel_idle_driver); - retval =cpuidle_register_driver (&intel_idle_driver);if (retval) {struct cpuidle_driver *drv =cpuidle_get_driver ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 890/1518 intel_idle: Add cmdline option to adjust C-states table
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Artem Bityutskiy <[email protected]>
[ Upstream commit 111f77a233484cf39a6317f4d0306387e9ffda7b ]
Add a new module parameter that allows adjusting the C-states table used by the driver.
Currently, the C-states table is hardcoded in the driver based on the CPU model. The goal is to have good enough defaults for most users.
However, C-state characteristics, such as exit latency and residency, can vary between different variants of the same CPU model and BIOS settings. Moreover, different platform usage models and user preferences may benefit from different C-state target_residency values.
Provide a way for users to adjust the C-states table via a module parameter "table". The general format is:
"state1:latency1:target_residency1,state2:latency2:target_residency2,..."
In other words, represent each C-state by its name, exit latency (in microseconds), and target residency (in microseconds), separated by colons. Separate multiple C-states by commas.
For example, suppose a CPU has 3 C-states with the following characteristics:
C1: exit_latency=1, target_residency=2
C1E: exit_latency=10, target_residency=10
C6: exit_latency=100, target_residency=500
Users can specify a custom C-states table as follows:
1. intel_idle.table="C1:2:2,C1E:5:20,C6:150:600"
Result: C1: exit_latency=2, target_residency=2
C1E: exit_latency=5, target_residency=20
C6: exit_latency=150, target_residency=600
2. intel_idle.table="C6::400"
Result: C1: exit_latency=1, target_residency=2 (unchanged)
C1E: exit_latency=10, target_residency=10 (unchanged)
C6: exit_latency=100, target_residency=400
(only target_residency changed)
Stable-dep-of: 9eadbed788df ("intel_idle: Avoid using deep idle states during initialization")
--- drivers/idle/intel_idle.c | 169 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+)
drivers/idle/intel_idle.c +169 -0
@@ -76,6 +76,10 @@ static unsigned int preferred_states_mask __read_mostly;static bool force_irq_on__read_mostly ;static bool ibrs_off__read_mostly ; +/* The maximum allowed length for the 'table' module parameter */ +#define MAX_CMDLINE_TABLE_LEN 256 +static char cmdline_table_str[MAX_CMDLINE_TABLE_LEN ]__read_mostly ; +static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;static unsigned long auto_demotion_disable_flags;
@@ -107,6 +111,9 @@ static struct device *sysfs_root __initdata;static const struct idle_cpu *icpu__initdata ;static struct cpuidle_state *cpuidle_state_table__initdata ; +/* C-states data from the 'intel_idle.table' cmdline parameter */ +static struct cpuidle_state cmdline_states[CPUIDLE_STATE_MAX ]__initdata ; +static unsigned int mwait_substates__initdata ;/*
@@ -2420,6 +2427,149 @@ static void __init intel_idle_sysfs_uninit(void)put_device (sysfs_root); } +/** +* get_cmdline_field - Get the current field from a cmdline string. +* @args: The cmdline string to get the current field from. +* @field: Pointer to the current field upon return. +* @sep: The fields separator character. +* +* Examples: +* Input: args="C1:1:1,C1E:2:10", sep=':' +* Output: field="C1", return "1:1,C1E:2:10" +* Input: args="C1:1:1,C1E:2:10", sep=',' +* Output: field="C1:1:1", return "C1E:2:10" +* Ipnut: args="::", sep=':' +* Output: field="", return ":" +* +* Return: The continuation of the cmdline string after the field or NULL. +*/ +static char *get_cmdline_field (char *args,char **field,char sep) +{ +unsigned int i; + +for (i =0 ; args[i] && !isspace (args[i]); i++) { +if (args[i] == sep) +break ; + } + + *field = args; + +if (args[i] != sep) +return NULL ; + + args[i] ='\0' ; +return args + i +1 ; +} + +/** +* cmdline_table_adjust - Adjust the C-states table with data from cmdline. +* @drv: cpuidle driver (assumed to point to intel_idle_driver). +* +* Adjust the C-states table with data from the 'intel_idle.table' module +* parameter (if specified). +*/ +static void __init cmdline_table_adjust (struct cpuidle_driver *drv) +{ +char *args = cmdline_table_str; +struct cpuidle_state *state; +int i; + +if (args[0 ] =='\0' ) +/* The 'intel_idle.table' module parameter was not specified */ +return ; + +/* Create a copy of the C-states table */ +for (i =0 ; i < drv->state_count; i++) + cmdline_states[i] = drv->states[i]; + +/* +* Adjust the C-states table copy with data from the 'intel_idle.table' +* module parameter. +*/ +while (args) { +char *fields, *name, *val; + +/* +* Get the next C-state definition, which is expected to be +* '<name>:<latency_us>:<target_residency_us>'. Treat "empty" +* fields as unchanged. For example, +* '<name>::<target_residency_us>' leaves the latency unchanged. +*/ + args =get_cmdline_field (args, &fields,',' ); + +/* name */ + fields =get_cmdline_field (fields, &name,':' ); +if (!fields) + goto error; + +if (!strcmp (name,"POLL" )) { +pr_err ("Cannot adjust POLL\n" ); +continue ; + } + +/* Find the C-state by its name */ + state =NULL ; +for (i =0 ; i < drv->state_count; i++) { +if (!strcmp (name, drv->states[i].name)) { + state = &cmdline_states[i]; +break ; + } + } + +if (!state) { +pr_err ("C-state '%s' was not found\n" , name); +continue ; + } + +/* Latency */ + fields =get_cmdline_field (fields, &val,':' ); +if (!fields) + goto error; + +if (*val) { +if (kstrtouint (val,0 , &state->exit_latency)) + goto error; + } + +/* Target residency */ + fields =get_cmdline_field (fields, &val,':' ); + +if (*val) { +if (kstrtouint (val,0 , &state->target_residency)) + goto error; + } + +/* +* Allow for 3 more fields, but ignore them. Helps to make +* possible future extensions of the cmdline format backward +* compatible. +*/ +for (i =0 ; fields && i <3 ; i++) { + fields =get_cmdline_field (fields, &val,':' ); +if (!fields) +break ; + } + +if (fields) { +pr_err ("Too many fields for C-state '%s'\n" , state->name); + goto error; + } + +pr_info ("C-state from cmdline: name=%s, latency=%u, residency=%u\n" , + state->name, state->exit_latency, state->target_residency); + } + +/* Copy the adjusted C-states table back */ +for (i =1 ; i < drv->state_count; i++) + drv->states[i] = cmdline_states[i]; + +pr_info ("Adjusted C-states with data from 'intel_idle.table'\n" ); +return ; + +error: +pr_info ("Failed to adjust C-states with data from 'intel_idle.table'\n" ); +} +static int __init intel_idle_init (void ) {const struct x86_cpu_id *id;
@@ -2486,6 +2636,7 @@ static int __init intel_idle_init(void)return -ENOMEM ;intel_idle_cpuidle_driver_init (&intel_idle_driver); +cmdline_table_adjust (&intel_idle_driver); retval =intel_idle_sysfs_init ();if (retval)
@@ -2560,3 +2711,21 @@ module_param(force_irq_on, bool, 0444);*/ module_param (ibrs_off, bool,0444 );MODULE_PARM_DESC (ibrs_off,"Disable IBRS when idle" ); + +/* +* Define the C-states table from a user input string. Expected format is +* 'name:latency:residency', where: +* - name: The C-state name. +* - latency: The C-state exit latency in us. +* - residency: The C-state target residency in us. +* +* Multiple C-states can be defined by separating them with commas: +* 'name1:latency1:residency1,name2:latency2:residency2' +* +* Example: intel_idle.table=C1:1:1,C1E:5:10,C6:100:600 +* +* To leave latency or residency unchanged, use an empty field, for example: +* 'C1:1:1,C1E::10' - leaves C1E latency unchanged. +*/ +module_param_string (table, cmdline_table_str,MAX_CMDLINE_TABLE_LEN ,0444 ); +MODULE_PARM_DESC (table,"Build the C-states table from a user input string" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 891/1518 intel_idle: Avoid using deep idle states during initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 9eadbed788df453289b5927327bd22edb542f472 ]
Commit c0f691388992 ("intel_idle: Use subsys_initcall_sync() for initialization") effectively made intel_idle initialize earlier which turns out to interfere with USB EHCI probing on some platforms [1]. Investigation led to the conclusion that this was related to allowing package idle states to be used earlier than before.
Work around that issue by making intel_idle set a CPU latency QoS request to prevent package idle states from being used on all platforms supported by it for the duration of the device_initcall() initialization phase.
--- drivers/idle/intel_idle.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/idle/intel_idle.c +23 -0
@@ -52,6 +52,7 @@#include <linux/notifier.h> #include <linux/cpu.h> #include <linux/moduleparam.h> +#include <linux/pm_qos.h> #include <linux/sysfs.h> #include <asm/cpuid/api.h> #include <asm/cpu_device_id.h>
@@ -2570,6 +2571,9 @@ static void __init cmdline_table_adjust(struct cpuidle_driver *drv)pr_info ("Failed to adjust C-states with data from 'intel_idle.table'\n" ); } +#define INTEL_IDLE_INIT_QOS 20 +static struct pm_qos_request qos_req__initdata ; +static int __init intel_idle_init (void ) {const struct x86_cpu_id *id;
@@ -2642,6 +2646,13 @@ static int __init intel_idle_init(void)if (retval)pr_warn ("failed to initialized sysfs" ); +/* +* Some platforms, in particular the Intel S1200BTL motherboard, have a +* problem with using package idle states too early, so prevent that +* from taking place until the device_initcall() phase is over. +*/ +cpu_latency_qos_add_request (&qos_req,INTEL_IDLE_INIT_QOS ); + retval =cpuidle_register_driver (&intel_idle_driver);if (retval) {struct cpuidle_driver *drv =cpuidle_get_driver ();
@@ -2666,6 +2677,9 @@ static int __init intel_idle_init(void)intel_idle_cpuidle_devices_uninit ();cpuidle_unregister_driver (&intel_idle_driver); init_driver_fail: +if (cpu_latency_qos_request_active ((&qos_req))) +cpu_latency_qos_remove_request (&qos_req); +intel_idle_sysfs_uninit ();free_percpu (intel_idle_cpuidle_devices);return retval;
@@ -2673,6 +2687,15 @@ static int __init intel_idle_init(void) }subsys_initcall_sync (intel_idle_init); +static int __init intel_idle_init_complete (void ) +{ +if (cpu_latency_qos_request_active ((&qos_req))) +cpu_latency_qos_remove_request (&qos_req); + +return 0 ; +} +device_initcall_sync (intel_idle_init_complete); +/* * We are not really modular, but we used to support that. Meaning we also * support "intel_idle.max_cstate=..." at boot and also a read-only export of
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 892/1518 scripts/tags.sh: Prevent binary files appearing in cscope.files
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergei Litvin <[email protected]>
[ Upstream commit a9b93c34625a27bed5dc0f80ee2a359ceb955172 ]
When executing the command make COMPILED_SOURCE=1 cscope, the resulting cscope.files file contains filenames with the extensions *.rlib, *.rmeta, and *.so.
To fix this, modify the regular expression in the all_compiled_sources() function so that only files with the extensions *.h, *.c, *.S, and *.rs are accepted.
The issue has been introduced by commit 4f491bb6ea2a ("scripts/tags.sh:
collect compiled source precisely") which implemented the parsing of compiled sources from *.cmd files instead of using the "find" command.
--- scripts/tags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/tags.sh +1 -1
@@ -100,7 +100,7 @@ all_compiled_sources() { echo include/generated/autoconf.h find $ignore -name "*.cmd" -exec \ - grep -Poh '(?<=^ )\S+|(?<== )\S+[^\\](?=$)' {} \+ | + grep -Poh '(?<=^ )\S+\.([chS]|rs)(?=\s)|(?<== )\S+\.(?1)(?=$)' {} \+ | awk '!a[$0]++' } | xargs realpath -esq $([ -z "$KBUILD_ABS_SRCTREE" ] && echo --relative-to=.) | sort -u
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 893/1518 modpost: prevent leak when early return no suffix .o in read_symbols()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robertus Diawan Chris <[email protected]>
[ Upstream commit 9a5b76027ed91680e10f90111d9cba300f96d1ab ]
The allocation for elf info symsearch and hdr from parse_elf() haven't been released when return because of modname didn't have suffix ".o". And it seems like the suffix ".o" check did not depends on parse_elf() to succeed first. So, move the suffix ".o" check before checking parse_elf() result to prevent resource leak when the modname didn't have suffix ".o" and return early.
This is reported by Coverity Scan as "Resource leak".
--- scripts/mod/modpost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/mod/modpost.c +3 -3
@@ -1570,14 +1570,14 @@ static void read_symbols(const char *modname)struct elf_info info = { };Elf_Sym *sym; -if (!parse_elf (&info, modname)) -return ; -if (!strends (modname,".o" )) {error ("%s: filename must be suffixed with .o\n" , modname);return ; } +if (!parse_elf (&info, modname)) +return ; +/* strip trailing .o */ mod =new_module (modname,strlen (modname) -strlen (".o" ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 894/1518 kbuild: fix modules.builtin(.modinfo) targets in the top-level Makefile
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuntao Wang <[email protected]>
[ Upstream commit 69ef27076d19297c0bf3bd22171fab8d87464a09 ]
Commit 7a342e6c7735 ("kbuild: move modules.builtin(.modinfo) rules to Makefile.vmlinux_o") moved the modules.builtin(.modinfo) rules from link-vmlinux.sh to Makefile.vmlinux_o, and added the corresponding targets to the top-level Makefile.
Commit 39cfd5b12160 ("kbuild: extract modules.builtin.modinfo from vmlinux.unstripped") later moved these rules from Makefile.vmlinux_o to Makefile.vmlinux, but left the corresponding targets in the top-level Makefile unchanged.
These modules.builtin(.modinfo) targets in the top-level Makefile should be moved alongside the vmlinux target, since they are now generated by Makefile.vmlinux.
However, simply removing these trivial targets might be a better choice, as it makes the Makefile cleaner and avoids the need to keep them in sync across multiple files, reducing the chance of future mistakes.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -1252,7 +1252,7 @@ PHONY += vmlinux_o vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o -vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o +vmlinux.o: vmlinux_o @: PHONY += vmlinux
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 895/1518 RDMA/erdma: Hold CQ references when processing EQ events
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Xu <[email protected]>
[ Upstream commit 98df2aee1459ee1c62c70cbe9b370d2a532aea36 ]
EQ handlers look up CQs from dev->cq_xa and invoke CQ completion or error callbacks outside the xarray lock. erdma_destroy_cq() can erase the CQ from the xarray and free its queue buffer and doorbell record while a previously scheduled EQ handler is still using the CQ.
Add a CQ refcount and take a reference under the xarray lock with refcount_inc_not_zero(). Remove the CQ from the xarray before dropping the destroy-path reference, then wait for in-flight EQ users before releasing CQ resources.
--- drivers/infiniband/hw/erdma/erdma_eq.c | 6 ++++-- drivers/infiniband/hw/erdma/erdma_verbs.c | 12 +++++++++-- drivers/infiniband/hw/erdma/erdma_verbs.h | 25 +++++++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-)
drivers/infiniband/hw/erdma/erdma_eq.c +4 -2
@@ -52,7 +52,7 @@ void erdma_aeq_event_handler(struct erdma_dev *dev)if (FIELD_GET (ERDMA_AEQE_HDR_TYPE_MASK ,le32_to_cpu (aeqe->hdr)) ==ERDMA_AE_TYPE_CQ_ERR ) { cqn =le32_to_cpu (aeqe->event_data0); - cq =find_cq_by_cqn (dev, cqn); + cq =erdma_cq_get_by_cqn (dev, cqn);if (!cq)continue ;
@@ -62,6 +62,7 @@ void erdma_aeq_event_handler(struct erdma_dev *dev)if (cq->ibcq.event_handler) cq->ibcq.event_handler (&event, cq->ibcq.cq_context); +erdma_cq_put (cq); }else { qpn =le32_to_cpu (aeqe->event_data0); qp =find_qp_by_qpn (dev, qpn);
@@ -157,7 +158,7 @@ void erdma_ceq_completion_handler(struct erdma_eq_cb *ceq_cb) poll_cnt++; cqn =FIELD_GET (ERDMA_CEQE_HDR_CQN_MASK ,READ_ONCE (*ceqe)); - cq =find_cq_by_cqn (dev, cqn); + cq =erdma_cq_get_by_cqn (dev, cqn);if (!cq)continue ;
@@ -166,6 +167,7 @@ void erdma_ceq_completion_handler(struct erdma_eq_cb *ceq_cb)if (cq->ibcq.comp_handler) cq->ibcq.comp_handler (&cq->ibcq, cq->ibcq.cq_context); +erdma_cq_put (cq); }notify_eq (&ceq_cb->eq);
drivers/infiniband/hw/erdma/erdma_verbs.c +10 -2
@@ -1327,6 +1327,7 @@ int erdma_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)struct erdma_dev *dev =to_edev (ibcq->device);struct erdma_ucontext *ctx =rdma_udata_to_drv_context ( udata, struct erdma_ucontext, ibucontext); +unsigned long flags;int err;struct erdma_cmdq_destroy_cq_req req;
@@ -1341,6 +1342,13 @@ int erdma_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)"failed to destroy CQ %u: %d\n" , cq->cqn, err); +xa_lock_irqsave (&dev->cq_xa, flags); +__xa_erase (&dev->cq_xa, cq->cqn); +xa_unlock_irqrestore (&dev->cq_xa, flags); + +erdma_cq_put (cq); +wait_for_completion (&cq->free); +if (rdma_is_kernel_res (&cq->ibcq.res)) {dma_free_coherent (&dev->pdev->dev, cq->depth <<CQE_SHIFT , cq->kern_cq.qbuf, cq->kern_cq.qbuf_dma_addr);
@@ -1351,8 +1359,6 @@ int erdma_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)put_mtt_entries (dev, &cq->user_cq.qbuf_mem); } -xa_erase (&dev->cq_xa, cq->cqn); -return 0 ; }
@@ -1981,6 +1987,8 @@ int erdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, cq->ibcq.cqe = depth; cq->depth = depth; cq->assoc_eqn = attr->comp_vector +1 ; +refcount_set (&cq->refcount,1 ); +init_completion (&cq->free); ret = xa_alloc_cyclic(&dev->cq_xa, &cq->cqn, cq, XA_LIMIT(1, dev->attrs.max_cq - 1),
drivers/infiniband/hw/erdma/erdma_verbs.h +23 -2
@@ -7,6 +7,9 @@#ifndef __ERDMA_VERBS_H__#define __ERDMA_VERBS_H__ +#include <linux/completion.h> +#include <linux/refcount.h> +#include "erdma.h" /* RDMA Capability. */
@@ -341,6 +344,8 @@ struct erdma_cq {u32 depth;u32 assoc_eqn; +refcount_t refcount; +struct completion free;union {struct erdma_kcq_info kern_cq;
@@ -355,9 +360,25 @@ static inline struct erdma_qp *find_qp_by_qpn(struct erdma_dev *dev, int id)return (struct erdma_qp *)xa_load (&dev->qp_xa, id); } -static inline struct erdma_cq *find_cq_by_cqn (struct erdma_dev *dev,int id) +static inline struct erdma_cq *erdma_cq_get_by_cqn (struct erdma_dev *dev, +int id) +{ +struct erdma_cq *cq; +unsigned long flags; + +xa_lock_irqsave (&dev->cq_xa, flags); + cq =xa_load (&dev->cq_xa, id); +if (cq && !refcount_inc_not_zero (&cq->refcount)) + cq =NULL ; +xa_unlock_irqrestore (&dev->cq_xa, flags); + +return cq; +} + +static inline void erdma_cq_put (struct erdma_cq *cq) { -return (struct erdma_cq *)xa_load (&dev->cq_xa, id); +if (refcount_dec_and_test (&cq->refcount)) +complete (&cq->free); }void erdma_qp_get (struct erdma_qp *qp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 896/1518 RDMA/erdma: Hold QP references for AE and CM processing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Xu <[email protected]>
[ Upstream commit a52eeff32024f190b3bdc99088c7becccd4fa60b ]
AE QP fatal events and iWARP CM paths load QPs from dev->qp_xa and then use or reference them outside the xarray lock. erdma_destroy_qp() can drop the destroy-path reference and free QP resources while such a lookup is in flight.
Add erdma_qp_get_by_qpn() to acquire a kref under the xarray lock with kref_get_unless_zero(). Remove the QP from the xarray before dropping the destroy-path reference so no new lookup can acquire it while destruction waits for existing users.
--- drivers/infiniband/hw/erdma/erdma_cm.c | 6 ++---- drivers/infiniband/hw/erdma/erdma_eq.c | 3 ++- drivers/infiniband/hw/erdma/erdma_verbs.c | 6 +++++- drivers/infiniband/hw/erdma/erdma_verbs.h | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-)
drivers/infiniband/hw/erdma/erdma_cm.c +2 -4
@@ -1021,10 +1021,9 @@ int erdma_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params)if (laddr->sa_family !=AF_INET || raddr->sa_family !=AF_INET )return -EAFNOSUPPORT ; - qp =find_qp_by_qpn (dev, params->qpn); + qp =erdma_qp_get_by_qpn (dev, params->qpn);if (!qp)return -ENOENT ; -erdma_qp_get (qp); ret =sock_create (AF_INET ,SOCK_STREAM ,IPPROTO_TCP , &s);if (ret <0 )
@@ -1154,10 +1153,9 @@ int erdma_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)return -ECONNRESET ; } - qp =find_qp_by_qpn (dev, params->qpn); + qp =erdma_qp_get_by_qpn (dev, params->qpn);if (!qp)return -ENOENT ; -erdma_qp_get (qp);down_write (&qp->state_lock);if (qp->attrs.iwarp.state >ERDMA_QPS_IWARP_RTR ) {
drivers/infiniband/hw/erdma/erdma_eq.c +2 -1
@@ -65,7 +65,7 @@ void erdma_aeq_event_handler(struct erdma_dev *dev)erdma_cq_put (cq); }else { qpn =le32_to_cpu (aeqe->event_data0); - qp =find_qp_by_qpn (dev, qpn); + qp =erdma_qp_get_by_qpn (dev, qpn);if (!qp)continue ;
@@ -75,6 +75,7 @@ void erdma_aeq_event_handler(struct erdma_dev *dev)if (qp->ibqp.event_handler) qp->ibqp.event_handler (&event, qp->ibqp.qp_context); +erdma_qp_put (qp); } }
drivers/infiniband/hw/erdma/erdma_verbs.c +5 -1
@@ -1370,6 +1370,7 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) udata, struct erdma_ucontext, ibucontext);struct erdma_cmdq_destroy_qp_req req;union erdma_mod_qp_params params; +unsigned long flags;int err;down_write (&qp->state_lock);
@@ -1397,6 +1398,10 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)"failed to destroy QP %u: %d\n" , QP_ID(qp), err); +xa_lock_irqsave (&dev->qp_xa, flags); +__xa_erase (&dev->qp_xa,QP_ID (qp)); +xa_unlock_irqrestore (&dev->qp_xa, flags); +erdma_qp_put (qp);wait_for_completion (&qp->safe_free);
@@ -1410,7 +1415,6 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)if (qp->cep)erdma_cep_put (qp->cep); -xa_erase (&dev->qp_xa,QP_ID (qp));return 0 ; }
drivers/infiniband/hw/erdma/erdma_verbs.h +15 -0
@@ -360,6 +360,21 @@ static inline struct erdma_qp *find_qp_by_qpn(struct erdma_dev *dev, int id)return (struct erdma_qp *)xa_load (&dev->qp_xa, id); } +static inline struct erdma_qp *erdma_qp_get_by_qpn (struct erdma_dev *dev, +int id) +{ +struct erdma_qp *qp; +unsigned long flags; + +xa_lock_irqsave (&dev->qp_xa, flags); + qp =xa_load (&dev->qp_xa, id); +if (qp && !kref_get_unless_zero (&qp->ref)) + qp =NULL ; +xa_unlock_irqrestore (&dev->qp_xa, flags); + +return qp; +} +static inline struct erdma_cq *erdma_cq_get_by_cqn (struct erdma_dev *dev,int id) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 897/1518 RDMA/srp: fix heap information leak on a truncated SRP_CRED_REQ
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit 961ac0f0c5e414abdd6b33fae84b311d9fde0bd0 ]
srp_recv_done() passes wc->byte_len to srp_process_rsp(). It passes nothing to srp_process_cred_req() and srp_process_aer_req(), which read fixed-size fields from the receive buffer without checking that those fields were received.
The buffer size is max_ti_iu_len, which comes from the login response and is not validated. A target that advertises 8 and then sends an 8-byte SRP_CRED_REQ makes the initiator read req->tag from beyond the end of the buffer. req->tag is copied into the SRP_CRED_RSP and sent back, so those bytes reach the target. SRP_AER_REQ behaves the same way and also reads req->lun.
The leak is 8 bytes per response. max_ti_iu_len also decides which slab cache the buffer comes from. With 8 the buffer is a kmalloc-8 object and the read is entirely outside it:
BUG: KASAN: slab-out-of-bounds in srp_recv_done+0x172b/0x1aa0 Read of size 8 at addr ffff888104714da8 by task kworker/u8:3/50 which belongs to the cache kmalloc-8 of size 8 The buggy address is located 0 bytes to the right of allocated 8-byte region [ffff888104714da0, ffff888104714da8)
Without KASAN the returned bytes are whatever is next in the slab. One run returned ".strtab".
rsp->data[3] in srp_process_rsp() has the same problem: only resp_data_len is checked before it is read.
Drop a request that is shorter than the structure being parsed, and check byte_len before the tsk_mgmt read.
--- drivers/infiniband/ulp/srp/ib_srp.c | 45 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +30 -15
@@ -1943,7 +1943,8 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp, ch->req_lim +=be32_to_cpu (rsp->req_lim_delta);if (rsp->tag == ch->tsk_mgmt_tag) { ch->tsk_mgmt_status =-1 ; -if (be32_to_cpu (rsp->resp_data_len) >=4 ) +if (be32_to_cpu (rsp->resp_data_len) >=4 && + byte_len >=sizeof (*rsp) +4 ) ch->tsk_mgmt_status = rsp->data[3 ];complete (&ch->tsk_mgmt_done); }else {
@@ -2043,13 +2044,20 @@ static int srp_response_common(struct srp_rdma_ch *ch, s32 req_delta, }static void srp_process_cred_req (struct srp_rdma_ch *ch, -struct srp_cred_req *req) +struct srp_cred_req *req,u32 byte_len) { -struct srp_cred_rsp rsp = { - .opcode =SRP_CRED_RSP , - .tag = req->tag, - }; -s32 delta =be32_to_cpu (req->req_lim_delta); +struct srp_cred_rsp rsp = { .opcode =SRP_CRED_RSP }; +s32 delta; + +if (byte_len <sizeof (*req)) { +shost_printk (KERN_ERR , ch->target->scsi_host,PFX +"dropping truncated SRP_CRED_REQ (%u bytes received, %zu expected)\n" , + byte_len,sizeof (*req)); +return ; + } + + rsp.tag = req->tag; + delta =be32_to_cpu (req->req_lim_delta);if (srp_response_common (ch, delta, &rsp,sizeof (rsp))) shost_printk(KERN_ERR, ch->target->scsi_host, PFX
@@ -2057,14 +2065,21 @@ static void srp_process_cred_req(struct srp_rdma_ch *ch, }static void srp_process_aer_req (struct srp_rdma_ch *ch, -struct srp_aer_req *req) +struct srp_aer_req *req,u32 byte_len) {struct srp_target_port *target = ch->target; -struct srp_aer_rsp rsp = { - .opcode =SRP_AER_RSP , - .tag = req->tag, - }; -s32 delta =be32_to_cpu (req->req_lim_delta); +struct srp_aer_rsp rsp = { .opcode =SRP_AER_RSP }; +s32 delta; + +if (byte_len <sizeof (*req)) { +shost_printk (KERN_ERR , target->scsi_host,PFX +"dropping truncated SRP_AER_REQ (%u bytes received, %zu expected)\n" , + byte_len,sizeof (*req)); +return ; + } + + rsp.tag = req->tag; + delta =be32_to_cpu (req->req_lim_delta);shost_printk (KERN_ERR , target->scsi_host,PFX "ignoring AER for LUN %llu\n" ,scsilun_to_int (&req->lun));
@@ -2106,11 +2121,11 @@ static void srp_recv_done(struct ib_cq *cq, struct ib_wc *wc)break ;case SRP_CRED_REQ : -srp_process_cred_req (ch, iu->buf); +srp_process_cred_req (ch, iu->buf, wc->byte_len);break ;case SRP_AER_REQ : -srp_process_aer_req (ch, iu->buf); +srp_process_aer_req (ch, iu->buf, wc->byte_len);break ;case SRP_T_LOGOUT :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 898/1518 ARM: 9481/2: breakpoint: CFI breakpoints only on demand
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 8ed9bff906cf8036531d1559f10e82733a52b41f ]
This removes the stub hw_breakpoint_cfi_handler() from ARM, making it not steal breakpoint type 0x03 (ARM_ENTRY_CFI_BREAKPOINT) unless CFI is actively used in the kernel.
When not instrumenting with CFI, or when a breakpoint is issued in userspace, we fall through to return 1 from hw_breakpoint_pending() "unhandled fault" so userspace can make use of this breakpoint.
Tested with LKDTM and this command line:
echo CFI_FORWARD_PROTO > /sys/kernel/debug/provoke-crash/DIRECT still works as expected.
--- arch/arm/kernel/hw_breakpoint.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/arm/kernel/hw_breakpoint.c +6 -5
@@ -929,10 +929,6 @@ static void hw_breakpoint_cfi_handler(struct pt_regs *regs) break; } } -#else -static void hw_breakpoint_cfi_handler (struct pt_regs *regs) -{ -}#endif /*
@@ -964,9 +960,14 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,case ARM_ENTRY_SYNC_WATCHPOINT :watchpoint_handler (addr, fsr, regs);break ; +#ifdef CONFIG_CFI case ARM_ENTRY_CFI_BREAKPOINT : -hw_breakpoint_cfi_handler (regs); +if (user_mode (regs)) + ret =1 ;/* Don't handle userspace BKPT */ +else +hw_breakpoint_cfi_handler (regs);break ; +#endif default : ret =1 ;/* Unhandled fault. */ }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 899/1518 ARM: 9485/1: mm: acquire mmap write lock around show_pte() for user faults
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xie Yuanbin <[email protected]>
[ Upstream commit 1039bffd6ae9c75b42b7d148d6c1106134107b66 ]
When CONFIG_DEBUG_USER=y, and cmdline "user_debug=31" is set, a user fault may trigger show_pte() without any lock.
If another thread in the same process concurrently calls munmap(), the page table pages may be freed while show_pte() is still traversing them, causing a use-after-free in show_pte().
If CONFIG_ARM_LPAE=y, this may cause a kernel panic if the pages table of PMD are freed when show_pte() is running.
Acquire mmap_write_lock() around show_pte() for user faults to fix the contention.
For user faults, additionally restrict that show_pte() is called only when the addr is a user-space address (addr < TASK_SIZE). This is because the lock of tsk->mm only protects the virtual memory of user address space, furthermore, dumping the page tables of a kernel-space address for user faults is unnecessary and may have security implications.
Keep everything unchanged for kernel faults, because the kernel is already in the "oops" state, acquiring a lock may risk a deadlock.
--- arch/arm/mm/fault.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
arch/arm/mm/fault.c +14 -2
@@ -204,7 +204,11 @@ __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,pr_err ("8<--- cut here ---\n" );pr_err ("%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n" , tsk->comm, sig, addr, fsr); -show_pte (KERN_ERR , tsk->mm, addr); +if (likely (addr <TASK_SIZE )) { +mmap_write_lock (tsk->mm); +show_pte (KERN_ERR , tsk->mm, addr); +mmap_write_unlock (tsk->mm); + } show_regs(regs); }#endif
@@ -648,7 +652,15 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)pr_alert ("8<--- cut here ---\n" );pr_alert ("Unhandled fault: %s (0x%03x) at 0x%08lx\n" , inf->name, fsr, addr); -show_pte (KERN_ALERT , current->mm, addr); +if (likely (user_mode (regs))) { +if (addr <TASK_SIZE ) { +mmap_write_lock (current->mm); +show_pte (KERN_ALERT , current->mm, addr); +mmap_write_unlock (current->mm); + } + }else { +show_pte (KERN_ALERT , current->mm, addr); + }arm_notify_die ("" , regs, inf->sig, inf->code, (void __user *)addr, fsr,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 900/1518 perf libbfd: Validate BPF prog info arrays before pointer cast
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 01765b456f850aed7475b37111f1c50bf76aaf51 ]
symbol__disassemble_bpf_libbfd() casts info_linear->info.jited_prog_insns and info_linear->info.jited_ksyms to pointers without checking whether bpil_offs_to_addr() actually converted the file offsets. A crafted perf.data with PERF_BPIL_* bits unset but non-zero counts causes raw file offsets to be dereferenced as pointers.
Add bitmask checks for PERF_BPIL_JITED_INSNS and PERF_BPIL_JITED_KSYMS before the casts, matching the validation added to bpf-event.c call sites.
--- tools/perf/util/libbfd.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/perf/util/libbfd.c +11 -0
@@ -552,6 +552,11 @@ int symbol__disassemble_bpf_libbfd(struct symbol *sym __maybe_unused, info_linear = info_node->info_linear; sub_id =dso__bpf_prog (dso)->sub_id; +/* jited_prog_insns is only valid if bpil_offs_to_addr() converted it */ +if (!(info_linear->arrays & (1UL <<PERF_BPIL_JITED_INSNS ))) { + ret =SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF ; + goto out; + } info.buffer = (void *)(uintptr_t )(info_linear->info.jited_prog_insns); info.buffer_length = info_linear->info.jited_prog_len;
@@ -581,6 +586,12 @@ int symbol__disassemble_bpf_libbfd(struct symbol *sym __maybe_unused,if (disassemble ==NULL )abort (); +/* jited_ksyms is only valid if bpil_offs_to_addr() converted it */ +if (!(info_linear->arrays & (1UL <<PERF_BPIL_JITED_KSYMS ))) { + ret =SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF ; + goto out; + } +fflush (s); do { const struct bpf_line_info *linfo = NULL;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 901/1518 perf bpf: Add PROG_TAGS to required arrays in __bpf_event__print_bpf_prog_info()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 38ba525335c4399b15c9be0f81de304e94ccb462 ]
synthesize_bpf_prog_name() unconditionally dereferences prog_tags[sub_id] (line: u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(uintptr_t)(info->prog_tags)) but __bpf_event__print_bpf_prog_info() only requires JITED_KSYMS and JITED_FUNC_LENS in its required_arrays bitmask.
If a crafted perf.data has the PROG_TAGS bit cleared (or the array was invalidated by bpil_offs_to_addr() bounds checking), info->prog_tags contains either zero or a raw file offset. Dereferencing it causes a NULL pointer dereference or an arbitrary memory read.
Add PERF_BPIL_PROG_TAGS to required_arrays so the function returns early when prog_tags was not present or failed validation.
--- tools/perf/util/bpf-event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/bpf-event.c +2 -1
@@ -969,7 +969,8 @@ void __bpf_event__print_bpf_prog_info(struct perf_bpil *info_linear, {struct bpf_prog_info *info = &info_linear->info;__u64 required_arrays = (1UL <<PERF_BPIL_JITED_KSYMS ) | - (1UL <<PERF_BPIL_JITED_FUNC_LENS ); + (1UL <<PERF_BPIL_JITED_FUNC_LENS ) | + (1UL <<PERF_BPIL_PROG_TAGS );__u32 *prog_lens;__u64 *prog_addrs;char name[KSYM_NAME_LEN ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 902/1518 perf libbfd: Fix memory leaks and NULL fclose in BPF disassembly
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit fe3ab00d55aa56b4d55cbc1150448f0aadd6732c ]
symbol__disassemble_bpf_libbfd() has four resource management bugs:
1. free(prog_linfo) leaks internal arrays. bpf_prog_linfo contains raw_linfo, raw_jited_linfo, nr_jited_linfo_per_func, and jited_linfo_func_idx pointers that are only freed by the proper destructor bpf_prog_linfo__free().
2. open_memstream(&buf, &buf_size) allocates a dynamic buffer that the caller must free after fclose(). The function calls fclose(s) but never free(buf), leaking the stream buffer on every call.
3. args->line = strdup(srcline) is immediately consumed by disasm_line__new(args) which internally calls strdup(args->line) again via annotation_line__init(). The first strdup result is then overwritten by args->line = buf + prev_buf_size without being freed.
4. If open_memstream() fails, the error path jumps to 'out:' which calls fclose(s) with s == NULL — undefined behavior.
Fix by using bpf_prog_linfo__free(), initializing buf to NULL, adding free(buf) after fclose(s), guarding fclose() against NULL, and removing the redundant strdup since annotation_line__init() makes its own copy.
--- tools/perf/util/libbfd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/perf/util/libbfd.c +8 -4
@@ -15,6 +15,7 @@#ifdef HAVE_LIBBPF_SUPPORT #include <bpf/bpf.h> #include <bpf/btf.h> +#include <bpf/libbpf.h> #endif #include <fcntl.h> #include <stdio.h>
@@ -510,7 +511,7 @@ int symbol__disassemble_bpf_libbfd(struct symbol *sym __maybe_unused,char tpath[PATH_MAX ];size_t buf_size;int nr_skip =0 ; -char *buf; +char *buf =NULL ;bfd *bfdf;int ret;FILE *s;
@@ -620,7 +621,7 @@ int symbol__disassemble_bpf_libbfd(struct symbol *sym __maybe_unused,if (!annotate_opts.hide_src_code && srcline) { args->offset =-1 ; - args->line =strdup (srcline); + args->line = (char *)srcline; args->line_nr =0 ; args->fileloc =NULL ; args->ms->sym = sym;
@@ -645,9 +646,12 @@ int symbol__disassemble_bpf_libbfd(struct symbol *sym __maybe_unused, ret =0 ; out: -free (prog_linfo); +bpf_prog_linfo__free (prog_linfo);btf__free (btf); -fclose (s); +if (s) { +fclose (s); +free (buf); + }bfd_close (bfdf);return ret;#else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 903/1518 ocfs2: synchronize heartbeat callbacks with o2net teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 3e326f3bf16506873777444608e8b715aab74a7a ]
Patch series "ocfs2: harden heartbeat teardown races".
This series fixes two OCFS2 heartbeat/o2net teardown races found by KASAN.
This patch (of 2):
Heartbeat callbacks stay registered while configfs local-node teardown enters o2net_stop_listening(). A node-down event can still run through o2net_disconnect_node() and o2net_set_nn_state() while teardown is destroying o2net_wq, so the later queue/flush operations can hit a dead workqueue. KASAN has caught this as a slab-use-after-free in __queue_work() with the call chain:
KASAN slab-use-after-free in __queue_work+0x56/0xa90
Read of size 4 Call trace: dump_stack_lvl+0x66/0xa0 print_report+0xce/0x630 __queue_work+0x56/0xa90 srso_alias_return_thunk+0x5/0xfbef5 __virt_addr_valid+0x19f/0x330 kasan_report+0xe0/0x110 __queue_delayed_work+0x58/0x1e0 queue_delayed_work_on+0xb4/0xc0 o2net_set_nn_state+0x467/0x840 o2net_disconnect_node+0x7b/0xe0 o2net_hb_node_down_cb+0x54/0x60 o2hb_run_event_list+0x236/0x2d0 o2hb_check_slot+0xad4/0xbc0 lock_release+0xc8/0x290 o2hb_check_slot+0x9ea/0xbc0 trace_hardirqs_on+0x18/0x130 o2hb_do_disk_heartbeat+0x646/0xb30 (fs/ocfs2/cluster/heartbeat.c:1079) __lock_acquire+0x466/0x2260 lockdep_hardirqs_on_prepare+0xea/0x1a0 ktime_get_with_offset+0xe9/0x230 o2hb_thread+0x14e/0x770 kthread+0x1ad/0x1f0 ret_from_fork+0x3c9/0x540 __switch_to+0x2e9/0x730 ret_from_fork_asm+0x1a/0x30 Allocated by task stack: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_noprof+0x292/0x760 __alloc_workqueue+0x736/0xc60 alloc_workqueue_noprof+0xb1/0x110 o2net_start_listening+0xe5/0x430 o2nm_node_local_store+0x184/0x310 configfs_write_iter+0x18a/0x210 vfs_write+0x469/0x810 ksys_write+0xd2/0x170 do_syscall_64+0x115/0x6a0 (arch/x86/entry/syscall_64.c:87) entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task stack: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x313/0x590 rcu_core+0x4f4/0x1320 handle_softirqs+0x156/0x660
queue_delayed_work_ono2net_set_nn_stateo2net_disconnect_nodeo2net_hb_node_down_cbo2hb_run_event_list
Keep heartbeat callbacks registered so quorum state still tracks node state, but stop them from driving o2net reconnect/disconnect work once local teardown starts. Mark the transport offline before destroying o2net_wq, wait for any in-flight heartbeat callback to finish, and delay bring-up replay until the new local node is published through o2nm_this_node().
The replay also has to stay serialized with heartbeat callback delivery. Otherwise a live-node snapshot can be copied, a real hb_down callback can install -ENOTCONN for a peer, and the stale replay can call o2net_hb_node_up() for that same peer and queue reconnect work even though heartbeat is already down.
The buggy scenario involves two paths, with each column showing the order within that path:
local-node teardown: heartbeat node-down callback:
1. configfs local-off enters 1. o2hb_run_event_list() invokes
o2net_stop_listening(). o2net_hb_node_down_cb().
2. teardown heads for 2. the callback reaches
destroy_workqueue(o2net_wq). o2net_disconnect_node() and
o2net_set_nn_state().
3. teardown destroys and NULLs 3. the callback flushes or queues
o2net_wq. work through o2net_wq.
--- fs/ocfs2/cluster/heartbeat.c | 43 ++++++++++++++---- fs/ocfs2/cluster/heartbeat.h | 5 ++ fs/ocfs2/cluster/nodemanager.c | 4 ++ fs/ocfs2/cluster/tcp.c | 83 +++++++++++++++++++++++++++------- fs/ocfs2/cluster/tcp.h | 1 + 5 files changed, 109 insertions(+), 27 deletions(-)
fs/ocfs2/cluster/heartbeat.c +33 -10
@@ -1477,13 +1477,38 @@ void o2hb_init(void)o2hb_debug_init (); } -/* if we're already in a callback then we're already serialized by the sem */ -static void o2hb_fill_node_map_from_callback (unsigned long *map, -unsigned int bits) +static void __o2hb_fill_node_map (unsigned long *map,unsigned int bits) {bitmap_copy (map, o2hb_live_node_bitmap, bits); } +void o2hb_callback_read_lock (void ) +{ +down_read (&o2hb_callback_sem); +} + +void o2hb_callback_read_unlock (void ) +{ +up_read (&o2hb_callback_sem); +} + +void o2hb_synchronize_callbacks (void ) +{ +down_write (&o2hb_callback_sem); +up_write (&o2hb_callback_sem); +} + +/* +* Callers must already hold o2hb_callback_sem for read or write so the copy +* stays serialized with callback delivery. +*/ +void o2hb_fill_node_map_locked (unsigned long *map,unsigned int bits) +{ +spin_lock (&o2hb_live_lock); +__o2hb_fill_node_map (map, bits); +spin_unlock (&o2hb_live_lock); +} +/* * get a map of all nodes that are heartbeating in any regions */
@@ -1491,11 +1516,9 @@ void o2hb_fill_node_map(unsigned long *map, unsigned int bits) {/* callers want to serialize this map and callbacks so that they * can trust that they don't miss nodes coming to the party */ -down_read (&o2hb_callback_sem); -spin_lock (&o2hb_live_lock); -o2hb_fill_node_map_from_callback (map, bits); -spin_unlock (&o2hb_live_lock); -up_read (&o2hb_callback_sem); +o2hb_callback_read_lock (); +o2hb_fill_node_map_locked (map, bits); +o2hb_callback_read_unlock (); }EXPORT_SYMBOL_GPL (o2hb_fill_node_map);
@@ -2567,7 +2590,7 @@ int o2hb_check_node_heartbeating_no_sem(u8 node_num)unsigned long testing_map[BITS_TO_LONGS (O2NM_MAX_NODES )];spin_lock (&o2hb_live_lock); -o2hb_fill_node_map_from_callback (testing_map,O2NM_MAX_NODES ); +__o2hb_fill_node_map (testing_map,O2NM_MAX_NODES );spin_unlock (&o2hb_live_lock);if (!test_bit (node_num, testing_map)) { mlog(ML_HEARTBEAT,
@@ -2584,7 +2607,7 @@ int o2hb_check_node_heartbeating_from_callback(u8 node_num) {unsigned long testing_map[BITS_TO_LONGS (O2NM_MAX_NODES )]; -o2hb_fill_node_map_from_callback (testing_map,O2NM_MAX_NODES ); +o2hb_fill_node_map_locked (testing_map,O2NM_MAX_NODES );if (!test_bit (node_num, testing_map)) { mlog(ML_HEARTBEAT, "node (%u) does not have heartbeating enabled.\n",
fs/ocfs2/cluster/heartbeat.h +5 -0
@@ -58,6 +58,11 @@ int o2hb_register_callback(const char *region_uuid, struct o2hb_callback_func *hc);void o2hb_unregister_callback (const char *region_uuid,struct o2hb_callback_func *hc); +void o2hb_callback_read_lock (void ); +void o2hb_callback_read_unlock (void ); +void o2hb_synchronize_callbacks (void ); +void o2hb_fill_node_map_locked (unsigned long *map, +unsigned int bits);void o2hb_fill_node_map (unsigned long *map,unsigned int bits);void o2hb_exit (void );
fs/ocfs2/cluster/nodemanager.c +4 -0
@@ -325,6 +325,7 @@ static ssize_t o2nm_node_local_store(struct config_item *item, const char *page,struct o2nm_node *node =to_o2nm_node (item);struct o2nm_cluster *cluster;unsigned long tmp; +bool starting = false;char *p = (char *)page;ssize_t ret;
@@ -361,6 +362,7 @@ static ssize_t o2nm_node_local_store(struct config_item *item, const char *page, ret =o2net_start_listening (node);if (ret) goto out; + starting = true; } if (!tmp && cluster->cl_has_local &&
@@ -374,6 +376,8 @@ static ssize_t o2nm_node_local_store(struct config_item *item, const char *page,if (node->nd_local) { cluster->cl_has_local = tmp; cluster->cl_local_node = node->nd_num; +if (starting) +o2net_complete_start_listening (node); } ret = count;
fs/ocfs2/cluster/tcp.c +66 -17
137 lines not on this page · raw message
fs/ocfs2/cluster/tcp.h +1 -0
@@ -96,6 +96,7 @@ struct o2nm_node;int o2net_register_hb_callbacks (void );void o2net_unregister_hb_callbacks (void );int o2net_start_listening (struct o2nm_node *node); +void o2net_complete_start_listening (struct o2nm_node *node);void o2net_stop_listening (struct o2nm_node *node);void o2net_disconnect_node (struct o2nm_node *node);int o2net_num_connected_peers (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 904/1518 clk: rockchip: rk3576: fix source muxes for SPI0..SPI4
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
[ Upstream commit 586ff159ec02533c17dd928641529cb0b52e9c62 ]
The TRM defines available source muxes for SPI0..SPI4 as
- b00: clk_gpll_div6_src
- b01: clk_gpll_div8_src
- b10: clk_cpll_div10_src
- b11: clk_xin_osc0_func
Which doesn't match what the current clock driver implements, making it impossible to derive some SPI clock rates such as 37.125 MHz (which requires clk_gpll_div8_src as the source mux).
Add a correct mux definition per TRM and point SPI0..SPI4 clocks at it.
--- drivers/clk/rockchip/clk-rk3576.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/clk/rockchip/clk-rk3576.c +6 -5
@@ -315,6 +315,7 @@ PNAME(mux_100m_24m_lclk0_p) = { "clk_cpll_div10", "xin24m", "lclk_asrc_src_0" }PNAME (mux_100m_24m_lclk1_p) = {"clk_cpll_div10" ,"xin24m" ,"lclk_asrc_src_1" };PNAME (mux_150m_100m_50m_24m_p) = {"clk_gpll_div8" ,"clk_cpll_div10" ,"clk_cpll_div20" ,"xin24m" };PNAME (mux_200m_100m_50m_24m_p) = {"clk_gpll_div6" ,"clk_cpll_div10" ,"clk_cpll_div20" ,"xin24m" }; +PNAME (mux_200m_150m_100m_24m_p) = {"clk_gpll_div6" ,"clk_gpll_div8" ,"clk_cpll_div10" ,"xin24m" };PNAME (mux_400m_200m_100m_24m_p) = {"clk_gpll_div3" ,"clk_gpll_div6" ,"clk_cpll_div10" ,"xin24m" };PNAME (mux_500m_250m_100m_24m_p) = {"clk_cpll_div2" ,"clk_cpll_div4" ,"clk_cpll_div10" ,"xin24m" };PNAME (mux_600m_400m_300m_24m_p) = {"clk_gpll_div2" ,"clk_gpll_div3" ,"clk_gpll_div4" ,"xin24m" };
@@ -706,19 +707,19 @@ static struct rockchip_clk_branch rk3576_clk_branches[] __initdata = { RK3576_CLKGATE_CON(16), 0, GFLAGS),GATE (PCLK_SPI4 ,"pclk_spi4" ,"pclk_bus_root" ,0 ,RK3576_CLKGATE_CON (16 ),1 ,GFLAGS ), -COMPOSITE_NODIV (CLK_SPI0 ,"clk_spi0" , mux_200m_100m_50m_24m_p,0 , +COMPOSITE_NODIV (CLK_SPI0 ,"clk_spi0" , mux_200m_150m_100m_24m_p,0 ,RK3576_CLKSEL_CON (70 ),13 ,2 ,MFLAGS ,RK3576_CLKGATE_CON (16 ),2 ,GFLAGS ), -COMPOSITE_NODIV (CLK_SPI1 ,"clk_spi1" , mux_200m_100m_50m_24m_p,0 , +COMPOSITE_NODIV (CLK_SPI1 ,"clk_spi1" , mux_200m_150m_100m_24m_p,0 ,RK3576_CLKSEL_CON (71 ),0 ,2 ,MFLAGS ,RK3576_CLKGATE_CON (16 ),3 ,GFLAGS ), -COMPOSITE_NODIV (CLK_SPI2 ,"clk_spi2" , mux_200m_100m_50m_24m_p,0 , +COMPOSITE_NODIV (CLK_SPI2 ,"clk_spi2" , mux_200m_150m_100m_24m_p,0 ,RK3576_CLKSEL_CON (71 ),2 ,2 ,MFLAGS ,RK3576_CLKGATE_CON (16 ),4 ,GFLAGS ), -COMPOSITE_NODIV (CLK_SPI3 ,"clk_spi3" , mux_200m_100m_50m_24m_p,0 , +COMPOSITE_NODIV (CLK_SPI3 ,"clk_spi3" , mux_200m_150m_100m_24m_p,0 ,RK3576_CLKSEL_CON (71 ),4 ,2 ,MFLAGS ,RK3576_CLKGATE_CON (16 ),5 ,GFLAGS ), -COMPOSITE_NODIV (CLK_SPI4 ,"clk_spi4" , mux_200m_100m_50m_24m_p,0 , +COMPOSITE_NODIV (CLK_SPI4 ,"clk_spi4" , mux_200m_150m_100m_24m_p,0 ,RK3576_CLKSEL_CON (71 ),6 ,2 ,MFLAGS ,RK3576_CLKGATE_CON (16 ),6 ,GFLAGS ), GATE(PCLK_WDT0, "pclk_wdt0", "pclk_bus_root", 0,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 905/1518 perf c2c: Add annotation support to perf c2c report
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianyou Li <[email protected]>
[ Upstream commit cd3466cd2639783da563253f1f9e3fb2ba936317 ]
Perf c2c report currently specified the code address and source:line information in the cacheline browser, while it is lack of annotation support like perf report to directly show the disassembly code for the particular symbol shared that same cacheline. This patches add a key 'a' binding to the cacheline browser which reuse the annotation browser to show the disassembly view for easier analysis of cacheline contentions.
Stable-dep-of: f53f5c2437c1 ("perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()")
--- tools/perf/Documentation/perf-c2c.txt | 7 ++ tools/perf/builtin-c2c.c | 155 +++++++++++++++++++++++++- 2 files changed, 157 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-c2c.txt +7 -0
@@ -143,6 +143,13 @@ REPORT OPTIONS feature, which causes cacheline sharing to behave like the cacheline size is doubled. +-M:: +--disassembler-style=:: + Set disassembler style for objdump. + +--objdump=<path>:: + Path to objdump binary. + C2C RECORD ---------- The perf c2c record command setup options related to HITM cacheline analysis
tools/perf/builtin-c2c.c +150 -5
259 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 906/1518 perf report: Fix histogram entry collapsing for -F option
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namhyung Kim <[email protected]>
[ Upstream commit 5d35d829bb0b19ee51be9732e3b5f81abc7ef3bb ]
Users can use -F/--fields option to set output fields and sort keys together.
But it missed to set perf_hpp_list->need_collapse for sort entries that have se_collapse callbacks.
So it ends up with having duplicated entries separately.
For example, let's run this command first.
$ perf mem record -t load -U -- perf test -w datasym
This will record samples for memory access (load) to struct 'buf' and a loop condition ('sig_atomic_t') types.
So the following two commands should have identical output.
$ perf report -s type --stdio --percent-limit=1 -q
87.80% perf buf
12.17% perf sig_atomic_tBut using -F option didn't collapse the entries based on types so the result looked like below:
$ perf report -F overhead,type --stdio --percent-limit=1 -q
23.31% perf buf
22.84% perf buf
21.26% perf buf
20.39% perf buf
12.17% perf sig_atomic_tStable-dep-of: f53f5c2437c1 ("perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()")
--- tools/perf/util/sort.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/sort.c +3 -0
@@ -3585,6 +3585,9 @@ static int __sort_dimension__add_output(struct perf_hpp_list *list,if (__sort_dimension__add_hpp_output (sd, list, level) <0 )return -1 ; +if (sd->entry->se_collapse) + list->need_collapse =1 ; + sd->taken =1 ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 907/1518 perf report: Update sort key state from -F option
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namhyung Kim <[email protected]>
[ Upstream commit cbd41c6d4c26c161a2b0e70ad411d3885ff13507 ]
Factor out __sort_dimension__update() so that it can be called from -s and -F option parsing logics. Otherwise the following command cannot go into the annotation mode.
$ perf report -F overhead,type,sym
Warning: Annotation is only available for symbolic views, include "sym*" in --sort to use it.
Stable-dep-of: f53f5c2437c1 ("perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()")
--- tools/perf/util/sort.c | 100 ++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 46 deletions(-)
tools/perf/util/sort.c +54 -46
@@ -3538,6 +3538,56 @@ static int add_dynamic_entry(struct evlist *evlist, const char *tok,return ret; } +static int __sort_dimension__update (struct sort_dimension *sd, +struct perf_hpp_list *list) +{ +if (sd->entry == &sort_parent && parent_pattern) { +int ret =regcomp (&parent_regex, parent_pattern,REG_EXTENDED ); +if (ret) { +char err[BUFSIZ ]; + +regerror (ret, &parent_regex, err,sizeof (err)); +pr_err ("Invalid regex: %s\n%s" , parent_pattern, err); +return -EINVAL ; + } + list->parent =1 ; + }else if (sd->entry == &sort_sym) { + list->sym =1 ; +/* +* perf diff displays the performance difference amongst +* two or more perf.data files. Those files could come +* from different binaries. So we should not compare +* their ips, but the name of symbol. +*/ +if (sort__mode ==SORT_MODE__DIFF ) + sd->entry->se_collapse = sort__sym_sort; + + }else if (sd->entry == &sort_sym_offset) { + list->sym =1 ; + }else if (sd->entry == &sort_dso) { + list->dso =1 ; + }else if (sd->entry == &sort_socket) { + list->socket =1 ; + }else if (sd->entry == &sort_thread) { + list->thread =1 ; + }else if (sd->entry == &sort_comm) { + list->comm =1 ; + }else if (sd->entry == &sort_type_offset) { + symbol_conf.annotate_data_member = true; + }else if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to) { + list->sym =1 ; + }else if (sd->entry == &sort_mem_dcacheline &&cacheline_size () ==0 ) { +return -EINVAL ; + }else if (sd->entry == &sort_mem_daddr_sym) { + list->sym =1 ; + } + +if (sd->entry->se_collapse) + list->need_collapse =1 ; + +return 0 ; +} +static int __sort_dimension__add (struct sort_dimension *sd,struct perf_hpp_list *list,int level)
@@ -3548,8 +3598,8 @@ static int __sort_dimension__add(struct sort_dimension *sd,if (__sort_dimension__add_hpp_sort (sd, list, level) <0 )return -1 ; -if (sd->entry->se_collapse) - list->need_collapse =1 ; +if (__sort_dimension__update (sd, list) <0 ) +return -1 ; sd->taken =1 ;
@@ -3585,8 +3635,8 @@ static int __sort_dimension__add_output(struct perf_hpp_list *list,if (__sort_dimension__add_hpp_output (sd, list, level) <0 )return -1 ; -if (sd->entry->se_collapse) - list->need_collapse =1 ; +if (__sort_dimension__update (sd, list) <0 ) +return -1 ; sd->taken =1 ;return 0 ;
@@ -3651,39 +3701,6 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,sort_dimension_add_dynamic_header (sd, env); } -if (sd->entry == &sort_parent && parent_pattern) { -int ret =regcomp (&parent_regex, parent_pattern,REG_EXTENDED ); -if (ret) { -char err[BUFSIZ ]; - -regerror (ret, &parent_regex, err,sizeof (err)); -pr_err ("Invalid regex: %s\n%s" , parent_pattern, err); -return -EINVAL ; - } - list->parent =1 ; - }else if (sd->entry == &sort_sym) { - list->sym =1 ; -/* -* perf diff displays the performance difference amongst -* two or more perf.data files. Those files could come -* from different binaries. So we should not compare -* their ips, but the name of symbol. -*/ -if (sort__mode ==SORT_MODE__DIFF ) - sd->entry->se_collapse = sort__sym_sort; - - }else if (sd->entry == &sort_dso) { - list->dso =1 ; - }else if (sd->entry == &sort_socket) { - list->socket =1 ; - }else if (sd->entry == &sort_thread) { - list->thread =1 ; - }else if (sd->entry == &sort_comm) { - list->comm =1 ; - }else if (sd->entry == &sort_type_offset) { - symbol_conf.annotate_data_member = true; - } -return __sort_dimension__add (sd, list, level); }
@@ -3702,9 +3719,6 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok, strlen(tok)))return -EINVAL ; -if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to) - list->sym =1 ; -__sort_dimension__add (sd, list, level);return 0 ; }
@@ -3718,12 +3732,6 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,if (sort__mode !=SORT_MODE__MEMORY )return -EINVAL ; -if (sd->entry == &sort_mem_dcacheline &&cacheline_size () ==0 ) -return -EINVAL ; - -if (sd->entry == &sort_mem_daddr_sym) - list->sym =1 ; -__sort_dimension__add (sd, list, level);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 908/1518 perf c2c: Use perf_env e_machine rather than arch
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 70b3c4f734bbfd5664cd6e4eb007c108bf2b1c43 ]
Use the e_machine rather than arch string matching for AARCH64.
Add include of dwarf-regs.h in case the EM_AARCH64 isn't defined, sort the headers given this include.
Stable-dep-of: f53f5c2437c1 ("perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()")
--- tools/perf/builtin-c2c.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)
tools/perf/builtin-c2c.c +22 -18
@@ -12,41 +12,45 @@*/ #include <errno.h> #include <inttypes.h> + +#include <asm/bug.h> #include <linux/compiler.h> #include <linux/err.h> #include <linux/kernel.h> #include <linux/stringify.h> #include <linux/zalloc.h> -#include <asm/bug.h> #include <sys/param.h> -#include "debug.h" -#include "builtin.h" + +#include <dwarf-regs.h> #include <perf/cpumap.h> #include <subcmd/pager.h> #include <subcmd/parse-options.h> -#include "map_symbol.h" -#include "mem-events.h" -#include "session.h" -#include "hist.h" -#include "sort.h" -#include "tool.h" + +#include "builtin.h" #include "cacheline.h" #include "data.h" +#include "debug.h" #include "event.h" #include "evlist.h" #include "evsel.h" -#include "ui/browsers/hists.h" -#include "thread.h" -#include "mem2node.h" +#include "hist.h" +#include "map_symbol.h" +#include "mem-events.h" #include "mem-info.h" -#include "symbol.h" -#include "ui/ui.h" -#include "ui/progress.h" +#include "mem2node.h" #include "pmus.h" +#include "session.h" +#include "sort.h" #include "string2.h" -#include "util/util.h" -#include "util/symbol.h" +#include "symbol.h" +#include "thread.h" +#include "tool.h" +#include "ui/browsers/hists.h" +#include "ui/progress.h" +#include "ui/ui.h" #include "util/annotate.h" +#include "util/symbol.h" +#include "util/util.h" struct c2c_hists {struct hists hists;
@@ -3225,7 +3229,7 @@ static int perf_c2c__report(int argc, const char **argv)* default display type. */ if (!display) { -if (!strcmp (perf_env__arch (env),"arm64" )) +if (perf_env__e_machine (env,/*e_flags=*/ NULL ) ==EM_AARCH64 ) display ="peer" ;else display ="tot" ;
Signature · 1 line
2.53.0
Re: [PATCH 6.18 0908/1518] perf c2c: Use perf_env e_machine rather than arch
Hi,
Quoted 23 lines
6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit
70b3c4f734bbfd5664cd6e4eb007c108bf2b1c43]Use the
e_machinerather than arch string matching for AARCH64.Add include of
dwarf-regs.hin case theEM_AARCH64isn't defined, sort the headers given this include.Signed-off-by Ian Rogers <[email protected]>Acked-by Namhyung Kim <[email protected]>Cc Alexander Gordeev <[email protected]>Cc Heiko Carstens <[email protected]>Cc Honglei Wang <[email protected]>Cc Jan Polensky <[email protected]>Cc Sumanth Korikkar <[email protected]>Cc Thomas Richter <[email protected]>Cc Vasily Gorbik <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Quoted 5 lines
Stable-dep-of:
f53f5c2437c1("perf c2c: Fix error masking, OOM, and unchecked caller errors inhpp_list__parse()")Signed-off-by Sasha Levin <[email protected]>--- tools/perf/builtin-c2c.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)
Please drop this patch for 6.18.y because of build failure.
builtin-c2c.c:3277:21: warning: implicit declaration of function 'perf_env__e_machine'; did you mean 'thread__e_machine'? [-Wimplicit-function-declaration]
3277 | if (perf_env__e_machine(env, /*e_flags=*/NULL) == EM_AARCH64)
| ^~~~~~~~~~~~~~~~~~~
| thread__e_machineBest Regards
Wang Yugui ([email protected])
2026/09/13
Sasha Levin
maintainerRe: [PATCH 6.18 0908/1518] perf c2c: Use perf_env e_machine rather than arch
Quoted 3 lines
Please drop this patch for 6.18.y because of build failure.
builtin-c2c.c:3277:21: warning: implicit declaration of function '
perf_env__e_machine'; did you mean 'thread__e_machine'? [-Wimplicit-function-declaration]
Dropped from the 6.18 queue along with the following two dependent patches:
- "perf c2c: Fix error masking, OOM, and unchecked caller errors in
hpp_list__parse()"
- "perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure"
Thanks for the report.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 909/1518 perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit f53f5c2437c1bd76fc0063a30a069a5207de8802 ]
hpp_list__parse() has three bugs:
1. The PARSE_LIST macro resets ret = 0 at the start of each invocation, so an error from output parsing is silently overwritten when the sort parsing block runs. The function returns success with partially initialized state.
2. When the caller passes a non-NULL output_ or sort_ string, but strdup() returns NULL due to OOM, NULL is passed to PARSE_LIST which treats it as empty input (the "if (!_list) break" branch). No error is returned.
3. When the called _fn function fails and returns something other than -ESRCH or -EINVAL (-ENOMEM, for instance) it was not bailing out of the strtok loop.
Fix them by checking strdup() return values before proceeding and adding a cleanup label so that ret from each PARSE_LIST call is checked before the next runs, preserving the first error.
The early exits now skip perf_hpp__setup_output_field(), which means c2c_hists__reinit() can return a non-zero value in cases that previously always succeeded silently. Both callers discarded its return:resort_cl_cb() continued into hists__collapse_resort() on a broken list, and perf_c2c__report() proceeded with uninitialised hists. Fix the full
chain: check and propagate the error in resort_cl_cb() -- hists__iterate_cb() already stops iteration and returns the callback error -- and check both c2c_hists__reinit() and hists__iterate_cb() in perf_c2c__report().
Also turn PARSE_LIST into a function, using a switch to catch other errors, converting the called functions to return an appropriate errno instead of -1 on failure.
Also make the two callers that iterate sort_dimension__add() and output_field_add() handle the newly propagated errors: setup_sort_list() and setup_output_list() only checked for -EINVAL and -ESRCH, so an -ENOMEM from a failed allocation was silently overwritten by the next loop iteration. Break out of the loop and propagate any other error.
The hpp_list__parse() fixes were developed with AI assistance from Claude:claude-sonnet-4.6, and the setup_sort_list()/setup_output_list() caller fixes with AI assistance from Opencode:mimo-v2.5-free and Opencode:DeepSeek-V4-Flash-free.
--- tools/perf/builtin-c2c.c | 85 ++++++++++++++++++++++++++++------------ tools/perf/util/sort.c | 76 +++++++++++++++++++++++------------ 2 files changed, 112 insertions(+), 49 deletions(-)
tools/perf/builtin-c2c.c +60 -25
@@ -12,11 +12,14 @@*/ #include <errno.h> #include <inttypes.h> +#include <stdlib.h> +#include <string.h> #include <asm/bug.h> #include <linux/compiler.h> #include <linux/err.h> #include <linux/kernel.h> +#include <linux/string.h> #include <linux/stringify.h> #include <linux/zalloc.h> #include <sys/param.h>
@@ -2068,26 +2071,38 @@ static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name, strureturn 0 ; } -#define PARSE_LIST (_list, _fn) \ - do { \ - char *tmp, *tok; \ - ret = 0; \ - \ - if (!_list) \ - break; \ - \ - for (tok = strtok_r((char *)_list, ", ", &tmp); \ - tok; tok = strtok_r(NULL, ", ", &tmp)) { \ - ret = _fn(hpp_list, tok, env); \ - if (ret == -EINVAL) { \ - pr_err("Invalid --fields key: `%s'", tok); \ - break; \ - } else if (ret == -ESRCH) { \ - pr_err("Unknown --fields key: `%s'", tok); \ - break; \ - } \ - } \ - } while (0) +static int __hpp_list__parse (struct perf_hpp_list *hpp_list,char *_list,struct perf_env *env, +int (*_fn)(struct perf_hpp_list *hpp_list,char *name,struct perf_env *env)) +{ +char *tmp, *tok; +int ret =0 ; + +if (!_list) +return 0 ; + +for (tok =strtok_r (_list,", " , &tmp); tok; tok =strtok_r (NULL ,", " , &tmp)) { + ret =_fn (hpp_list, tok, env); +switch (ret) { +case 0 : +continue ; +case -EINVAL : +pr_err ("Invalid --fields key: `%s'" , tok); + goto out; +case -ESRCH : +pr_err ("Unknown --fields key: `%s'" , tok); + goto out; +default : { +char buf[STRERR_BUFSIZE ]; + +pr_err ("%s for --fields key: `%s'" , +str_error_r (-ret, buf,sizeof (buf)), tok); + goto out; + } + } + } +out: +return ret; +} static int hpp_list__parse(struct perf_hpp_list *hpp_list, const char *output_,
@@ -2098,8 +2113,18 @@ static int hpp_list__parse(struct perf_hpp_list *hpp_list,char *sort = sort_ ?strdup (sort_) :NULL ;int ret; -PARSE_LIST (output, c2c_hists__init_output); -PARSE_LIST (sort, c2c_hists__init_sort); +/* strdup() returns NULL on OOM, don't silently treat as empty */ +if ((output_ && !output) || (sort_ && !sort)) { + ret = -ENOMEM ; + goto out; + } + + ret =__hpp_list__parse (hpp_list, output, env, c2c_hists__init_output); +if (ret) + goto out; + ret =__hpp_list__parse (hpp_list, sort, env, c2c_hists__init_sort); +if (ret) + goto out;/* copy sort keys to output fields */ perf_hpp__setup_output_field (hpp_list);
@@ -2116,6 +2141,7 @@ static int hpp_list__parse(struct perf_hpp_list *hpp_list,perf_hpp__append_sort_keys (&hists->list);#endif +out:free (output);free (sort);return ret;
@@ -2286,6 +2312,7 @@ static int resort_cl_cb(struct hist_entry *he, void *arg)struct c2c_hist_entry *c2c_he;struct c2c_hists *c2c_hists;bool display =he__display (he, &c2c.shared_clines_stats); +int ret; c2c_he = container_of(he, struct c2c_hist_entry, he); c2c_hists = c2c_he->hists;
@@ -2296,7 +2323,9 @@ static int resort_cl_cb(struct hist_entry *he, void *arg) c2c_he->cacheline_idx = idx++;calc_width (c2c_he); -c2c_hists__reinit (c2c_hists, c2c.cl_output, c2c.cl_resort, env); + ret =c2c_hists__reinit (c2c_hists, c2c.cl_output, c2c.cl_resort, env); +if (ret) +return ret;hists__collapse_resort (&c2c_hists->hists,NULL );hists__output_resort_cb (&c2c_hists->hists,NULL , filter_cb);
@@ -3356,13 +3385,19 @@ static int perf_c2c__report(int argc, const char **argv)else if (c2c.display ==DISPLAY_SNP_PEER ) sort_str ="tot_peer" ; -c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session)); + err =c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session)); +if (err) { +pr_err ("Failed to reinitialize hists\n" ); + goto out_mem2node; + }ui_progress__init (&prog, c2c.hists.hists.nr_entries,"Sorting..." );hists__collapse_resort (&c2c.hists.hists,NULL );hists__output_resort_cb (&c2c.hists.hists, &prog, resort_shared_cl_cb); -hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session)); + err =hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session)); +if (err) + goto out_mem2node;ui_progress__finish ();
tools/perf/util/sort.c +52 -24
160 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 910/1518 perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 6d421f609bba7b0b1a11741ec4b19feadfd27051 ]
When c2c_hists__init() or c2c_hists__reinit() calls hpp_list__parse() and it fails partway through, format structures registered via perf_hpp_list__column_register() and perf_hpp_list__register_sort_field() are left on the hpp_list.
In c2c_hists__init(), only one of the callers, c2c_he__alloc_hists(), handled this with perf_hpp__reset_output_field(), while perf_c2c_report() did not, leaking the partially registered entries.
In c2c_hists__reinit(), neither perf_c2c_report() nor resort_cl_cb() clean up on failure.
Fix by adding cleanup inside both functions themselves, so all callers are protected, and remove the now redundant reset in c2c_he__alloc_hists().
--- tools/perf/builtin-c2c.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
tools/perf/builtin-c2c.c +18 -2
@@ -2152,6 +2152,8 @@ static int c2c_hists__init(struct c2c_hists *hists,int nr_header_lines, struct perf_env *env) { + int ret; +__hists__init (&hists->hists, &hists->list);/*
@@ -2164,7 +2166,13 @@ static int c2c_hists__init(struct c2c_hists *hists,/* Overload number of header lines.*/ hists->list.nr_header_lines = nr_header_lines; -return hpp_list__parse (&hists->list,/*output=*/ NULL , sort, env); + ret =hpp_list__parse (&hists->list,/*output=*/ NULL , sort, env); + +/* Unregister any formats added before the failure point */ +if (ret) +perf_hpp__reset_output_field (&hists->list); + +return ret; } static int c2c_hists__reinit(struct c2c_hists *c2c_hists,
@@ -2172,8 +2180,16 @@ static int c2c_hists__reinit(struct c2c_hists *c2c_hists,const char *sort, struct perf_env *env) { + int ret; +perf_hpp__reset_output_field (&c2c_hists->list); -return hpp_list__parse (&c2c_hists->list, output, sort, env); + ret =hpp_list__parse (&c2c_hists->list, output, sort, env); + +/* Unregister any formats added before the failure point */ +if (ret) +perf_hpp__reset_output_field (&c2c_hists->list); + +return ret; }#define DISPLAY_LINE_LIMIT 0.001
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 911/1518 drm/sun4i: vi scaler: Fix coefficient selection
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit 5c31990b21f0b535732deb2b658b78b07464f56c ]
Currently, vertical coefficients are selected based on horizontal scaling, which is wrong. Additionally, chroma coefficients should be selected based on format subsampling.
Fix all that.
--- drivers/gpu/drm/sun4i/sun8i_vi_scaler.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/gpu/drm/sun4i/sun8i_vi_scaler.c +12 -6
@@ -893,20 +893,26 @@ static void sun8i_vi_scaler_set_coeff(struct regmap *map, u32 base, lan3coefftab32_left[offset + i]);regmap_write (map,SUN8I_SCALER_VSU_YHCOEFF1 (base, i), lan3coefftab32_right[offset + i]); + } + offset =sun8i_vi_scaler_coef_index (vstep) * +SUN8I_VI_SCALER_COEFF_COUNT ; +for (i =0 ; i <SUN8I_VI_SCALER_COEFF_COUNT ; i++) +regmap_write (map,SUN8I_SCALER_VSU_YVCOEFF (base, i), + lan2coefftab32[offset + i]); + + offset =sun8i_vi_scaler_coef_index (hstep / format->hsub) * +SUN8I_VI_SCALER_COEFF_COUNT ; +for (i =0 ; i <SUN8I_VI_SCALER_COEFF_COUNT ; i++) {regmap_write (map,SUN8I_SCALER_VSU_CHCOEFF0 (base, i), ch_left[offset + i]);regmap_write (map,SUN8I_SCALER_VSU_CHCOEFF1 (base, i), ch_right[offset + i]); } - - offset =sun8i_vi_scaler_coef_index (hstep) * + offset =sun8i_vi_scaler_coef_index (vstep / format->vsub) *SUN8I_VI_SCALER_COEFF_COUNT ; -for (i =0 ; i <SUN8I_VI_SCALER_COEFF_COUNT ; i++) { -regmap_write (map,SUN8I_SCALER_VSU_YVCOEFF (base, i), - lan2coefftab32[offset + i]); +for (i =0 ; i <SUN8I_VI_SCALER_COEFF_COUNT ; i++)regmap_write (map,SUN8I_SCALER_VSU_CVCOEFF (base, i), cy[offset + i]); - } }void sun8i_vi_scaler_enable (struct sun8i_mixer *mixer,int layer,bool enable)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 912/1518 drm/sun4i: tcon: Set output mux for DSI and LVDS
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit 9c90199b39637ad94253c4fd8e7b1333ca1d3e0d ]
DSI and LVDS skip output mux setup, so TCON TOP cannot route the selected mixer. Configure them like other channel 0 outputs.
In practice this matters for D1, where channel 0 TCONs are fed through TCON TOP. The remaining set_mux implementations only handle TMDS and return an error for other encoder types, as before.
--- drivers/gpu/drm/sun4i/sun4i_tcon.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/sun4i/sun4i_tcon.c +2 -0
@@ -717,9 +717,11 @@ void sun4i_tcon_mode_set(struct sun4i_tcon *tcon,case DRM_MODE_ENCODER_DSI :/* DSI is tied to special case of CPU interface */ sun4i_tcon0_mode_set_cpu (tcon, encoder, mode); +sun4i_tcon_set_mux (tcon,0 , encoder);break ;case DRM_MODE_ENCODER_LVDS :sun4i_tcon0_mode_set_lvds (tcon, encoder, mode); +sun4i_tcon_set_mux (tcon,0 , encoder);break ;case DRM_MODE_ENCODER_NONE :sun4i_tcon0_mode_set_rgb (tcon, encoder, mode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 913/1518 drm/sun4i: tcon: Drop TCON TOP device reference
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit 8208832a38ff3d2560eb8a77a9d7a2f17d8ebcdc ]
of_find_device_by_node() takes a device reference. Drop it after mux configuration succeeds.
--- drivers/gpu/drm/sun4i/sun4i_tcon.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/sun4i/sun4i_tcon.c +9 -10
@@ -1409,7 +1409,7 @@ static int sun8i_r40_tcon_tv_set_mux(struct sun4i_tcon *tcon, {struct device_node *port, *remote;struct platform_device *pdev; -int id, ret; +int id, ret =0 ;/* find TCON TOP platform device and TCON id */
@@ -1432,21 +1432,20 @@ static int sun8i_r40_tcon_tv_set_mux(struct sun4i_tcon *tcon,if (IS_ENABLED (CONFIG_DRM_SUN8I_TCON_TOP ) && encoder->encoder_type ==DRM_MODE_ENCODER_TMDS ) { ret =sun8i_tcon_top_set_hdmi_src (&pdev->dev, id); -if (ret) { -put_device (&pdev->dev); -return ret; - } +if (ret) + goto out_put_device; }if (IS_ENABLED (CONFIG_DRM_SUN8I_TCON_TOP )) { ret =sun8i_tcon_top_de_config (&pdev->dev, tcon->id, id); -if (ret) { -put_device (&pdev->dev); -return ret; - } +if (ret) + goto out_put_device; } -return 0 ; +out_put_device: +put_device (&pdev->dev); + +return ret; }static const struct sun4i_tcon_quirks sun4i_a10_quirks = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 914/1518 drm/sun4i: hdmi: Dont leak sync polarity bits into packet control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit f5c3b1b0d228624786d22973a20c908c84e1a576 ]
sun4i_hdmi_enable() keeps using the same variable after it programmed the video timing polarity register with it. The leftover TX_CLK, HSYNC and VSYNC bits are then ORed into the packet control register, where each nibble selects the packet type sent in one slot.
As a result, slot 0 selects packet type 3 instead of the AVI infoframe whenever the mode has positive HSYNC polarity, and the TX_CLK bits set nibbles which the driver never programs.
Assign the packet types instead of ORing them into the stale value.
--- drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +1 -1
@@ -146,7 +146,7 @@ static void sun4i_hdmi_enable(struct drm_encoder *encoder,drm_atomic_helper_connector_hdmi_update_infoframes (connector, state); - val |=SUN4I_HDMI_PKT_CTRL_TYPE (0 ,SUN4I_HDMI_PKT_AVI ); + val =SUN4I_HDMI_PKT_CTRL_TYPE (0 ,SUN4I_HDMI_PKT_AVI ); val |=SUN4I_HDMI_PKT_CTRL_TYPE (1 ,SUN4I_HDMI_PKT_END );writel (val, hdmi->base +SUN4I_HDMI_PKT_CTRL_REG (0 ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 915/1518 drm/sun4i: crtc: Propagate layer initialization error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit 7061ff05ed4a3cf16e83f7e3ad09cbd212508a32 ]
sun4i_crtc_init() returns plain NULL when layer initialization fails, while all its other error paths return an error pointer. The only caller, sun4i_tcon_bind(), checks the result with IS_ERR() and happily continues with tcon->crtc set to NULL. sun4i_rgb_init() and sun4i_lvds_init() then dereference it in drm_crtc_mask(), which oopses.
Return the error pointer instead.
--- drivers/gpu/drm/sun4i/sun4i_crtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/sun4i/sun4i_crtc.c +1 -1
@@ -208,7 +208,7 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm, planes =sunxi_engine_layers_init (drm, engine);if (IS_ERR (planes)) {dev_err (drm->dev,"Couldn't create the planes\n" ); -return NULL ; +return ERR_CAST (planes); }/* find primary and cursor planes for drm_crtc_init_with_planes */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 916/1518 drm/sun4i: tcon: Drop remote endpoint reference
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit 3f77e4072630e2301efdbe521e7fca10311043ec ]
sun4i_tcon_of_get_id_from_port() never drops the reference taken by of_graph_get_remote_endpoint(). The function is not only called during bind, but also on every mode set through sun8i_r40_tcon_tv_set_mux(), so the leak accumulates.
--- drivers/gpu/drm/sun4i/sun4i_tcon.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/sun4i/sun4i_tcon.c +1 -0
@@ -972,6 +972,7 @@ static int sun4i_tcon_of_get_id_from_port(struct device_node *port)continue ; ret =of_property_read_u32 (remote,"reg" , ®); +of_node_put (remote);if (ret)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 917/1518 drm/sun4i: dw-hdmi: Drop TCON TOP port reference
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit d2a242e5688a17b79c89cd966cd31820c5096d80 ]
When the HDMI controller is fed by TCON TOP, the port node used to enumerate the possible CRTCs is never released.
--- drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c +2 -0
@@ -83,6 +83,8 @@ static u32 sun8i_dw_hdmi_find_possible_crtcs(struct drm_device *drm,of_node_put (remote_port); } } + +of_node_put (port); }else { crtcs =drm_of_find_possible_crtcs (drm, node); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 918/1518 drm/sun4i: hdmi-phy: Fix H6 8-bit MPLL config at 594 MHz
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jernej Skrabec <[email protected]>
[ Upstream commit 0ba6deddaae74f0539c0303bfb5f860adbe1a68b ]
The 8-bit entry of the last MPLL row (594 MHz) doesn't lock reliably on H6. 4K@60 RGB/YUV444, which is the mode that reaches this entry, doesn't come up.
Align the value with the vendor driver. Other entries are left alone, they are used by lower pixel clocks which work fine.
Tested with 4K@60 on a LG TV.
--- drivers/gpu/drm/sun4i/sun8i_hdmi_phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/sun4i/sun8i_hdmi_phy.c +1 -1
@@ -91,7 +91,7 @@ static const struct dw_hdmi_mpll_config sun50i_h6_mpll_cfg[] = { }, }, { 594000000, { - { 0x1a40, 0x0003 }, + { 0x1a7c, 0x0003 }, { 0x3b4c, 0x0003 }, { 0x5a64, 0x0003 }, },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 919/1518 rust: cpufreq: Add CPUFREQ_TABLE_END as last table entry in TableBuilder::to_table
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Priya Bala Govindasamy <[email protected]>
[ Upstream commit b5e4771f20a37fdf19eac0824bf062dffb4e291f ]
The TableBuilder::to_table function adds Hertz(c_ulong::MAX).as_khz() as the last frequency entry in the frequency table.
But the C API expects the last entry to have frequency set to CPUFREQ_TABLE_END which is ~1u as per include/linux/cpufreq.h.
Fix this by setting the last frequency entry to CPUFREQ_TABLE_END instead of Hertz(c_ulong::MAX).as_khz().
--- rust/kernel/cpufreq.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
rust/kernel/cpufreq.rs +9 -4
@@ -361,23 +361,28 @@ impl TableBuilder { } } -/// Adds a new entry to the table. -pub fn add (&mut self, freq:Hertz , flags:u32 , driver_data:u32 ) ->Result { +/// Adds a raw frequency-table entry. +fn push (&mut self, frequency:u32 , flags:u32 , driver_data:u32 ) ->Result {// Adds the new entry at the end of the vector. Ok (self.entries.push ( bindings::cpufreq_frequency_table { flags, driver_data, - frequency: freq.as_khz ()as u32 , + frequency, },GFP_KERNEL , )?) } +/// Adds a new entry to the table. +pub fn add (&mut self, freq:Hertz , flags:u32 , driver_data:u32 ) ->Result { + self.push (freq.as_khz ()as u32 , flags, driver_data) + } +/// Consumes the [`TableBuilder`] and returns [`TableBox`]. pub fn to_table (mut self) ->Result <TableBox > {// Add last entry to the table. - self.add (Hertz (c_ulong::MAX ),0 ,0 )?; + self.push (bindings::CPUFREQ_TABLE_END as u32 ,0 ,0 )?;TableBox ::new (self.entries) }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 920/1518 rust: cpufreq: Fix temporary write in Registration::bios_limit_callback
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Priya Bala Govindasamy <[email protected]>
[ Upstream commit 19c76bdd3fc02475c73c8576f6f4a55ff07886f1 ]
In Registration::bios_limit_callback, the expression &mut (unsafe { *limit }) creates a reference to a temporary copy of the value pointed to by limit on the stack. Therefore, writes made by T::bios_limit go to this temporary instead of the memory location pointed to by limit.
Additionally, limit may be uninitialized, such as when Registration::bios_limit_callback is invoked by show_bios_limit in drivers/cpufreq/cpufreq.c. Therefore creating a reference to limit is unsound.
Fix this by changing the signature of T::bios_limit to return the limit value.Registration::bios_limit_callback can then update limit directly.
--- rust/kernel/cpufreq.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
rust/kernel/cpufreq.rs +8 -3
@@ -821,7 +821,9 @@ pub trait Driver { }/// Driver's `bios_limit` callback. -fn bios_limit (_policy: &mut Policy , _limit: &mut u32 ) ->Result { +/// +/// Returns HW/BIOS max frequency limitations for the CPU. +fn bios_limit (_policy: &mut Policy ) ->Result <u32 > {build_error! (VTABLE_DEFAULT_ERROR ) }
@@ -1356,9 +1358,12 @@ impl<T: Driver> Registration<T> {from_result (|| {let mut policy =PolicyCpu ::from_cpu (cpu_id)?; - +let val =T ::bios_limit (&mut policy)?;// SAFETY: `limit` is guaranteed by the C code to be valid. -T ::bios_limit (&mut policy, &mut (unsafe { *limit })).map (|()|0 ) +unsafe { + *limit = val; + } +Ok (0 ) }) }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 921/1518 cpufreq: imx6q: fix devres accumulation across driver rebind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 22c23c72c3b21fa3ec3db5070dfc0582794e0ef9 ]
imx6_soc_volt is allocated with devm_kcalloc(cpu_dev, ...), where cpu_dev is the CPU device from get_cpu_device(0). That device is never unbound, so its devres list is never released, and imx6q_cpufreq_remove() does not free the array either. Every probe therefore adds an allocation that stays for the lifetime of the system.
Allocate against the platform device instead. Its devres is released when the driver is unbound, which is exactly the lifetime the array wants:imx6q_set_target() reads it, and nothing may reach that after cpufreq_unregister_driver().
That makes the array actually go away on unbind, so also clear the file-scope pointer in remove and on the failed-probe path, rather than leave it pointing at memory devres is about to release.
Tested by rebinding the driver on qemu's mcimx6ul-evk.
--- drivers/cpufreq/imx6q-cpufreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/imx6q-cpufreq.c +3 -1
@@ -400,7 +400,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev) }/* Make imx6_soc_volt array's size same as arm opp number */ - imx6_soc_volt =devm_kcalloc (cpu_dev, num,sizeof (*imx6_soc_volt), + imx6_soc_volt =devm_kcalloc (&pdev->dev, num,sizeof (*imx6_soc_volt),GFP_KERNEL );if (imx6_soc_volt ==NULL ) { ret = -ENOMEM ;
@@ -485,6 +485,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)return 0 ; free_freq_table: + imx6_soc_volt =NULL ;dev_pm_opp_free_cpufreq_table (cpu_dev, &freq_table); out_free_opp:dev_pm_opp_of_remove_table (cpu_dev);
@@ -506,6 +507,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)static void imx6q_cpufreq_remove (struct platform_device *pdev) {cpufreq_unregister_driver (&imx6q_cpufreq_driver); + imx6_soc_volt =NULL ;dev_pm_opp_free_cpufreq_table (cpu_dev, &freq_table);dev_pm_opp_of_remove_table (cpu_dev);regulator_put (arm_reg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 922/1518 cpufreq: imx6q: fix out-of-bounds write when probed more than once
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 8c3afcf27fa4582c1ab912503dc8a4ebb8dc0f82 ]
imx6_soc_volt is allocated fresh on every probe, sized to the number of ARM OPPs:
imx6_soc_volt = devm_kcalloc(cpu_dev, num, sizeof(*imx6_soc_volt), GFP_KERNEL);
but it is filled through soc_opp_count, which has static storage and is never reset. A second bind after an unbind keeps indexing from where the first one stopped, and writes past the end of the new array.
Unbinding and rebinding the driver on qemu's mcimx6ul-evk, under KASAN:
BUG: KASAN: slab-out-of-bounds in imx6q_cpufreq_probe+0x3b0/0xa34 Write of size 4 at addr c5e90480 by task binder/73 imx6q_cpufreq_probe from platform_probe+0x88/0xe4 platform_probe from really_probe+0x108/0x384 bind_store from kernfs_fop_write_iter+0x1b4/0x28c
The write lands one u32 past the end of the allocation.
soc_opp_count is only read a few lines below the loop that fills it, so it never needed static storage. Make it a local.
--- drivers/cpufreq/imx6q-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/imx6q-cpufreq.c +1 -1
@@ -55,7 +55,6 @@ static unsigned int max_freq;static unsigned int transition_latency;static u32 *imx6_soc_volt; -static u32 soc_opp_count;static int imx6q_set_target (struct cpufreq_policy *policy,unsigned int index) {
@@ -330,6 +329,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)const struct property *prop;const __be32 *val;u32 nr, i, j; +u32 soc_opp_count =0 ; cpu_dev =get_cpu_device (0 );if (!cpu_dev) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 923/1518 IB/isert: delay the final Login Response until the session is registered
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit 464f5afa92d071a226f88424803b0fcf88093ede ]
isert_put_login_tx() puts the final Login Response on the wire before __transport_register_session(), which iscsi_post_login_handler() reaches only after iscsi_target_do_login() returns. An initiator that issues a SCSI command as soon as it sees that response can have it executed against an se_session whose se_tpg is still NULL, and the ib-comp-wq worker oopses on the NULL dereference.
Oops: general protection fault, probably for non-canonical address 0xdffffc000000000f: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000078-0x000000000000007f] CPU: 0 UID: 0 PID: 178 Comm: kworker/0:1H Not tainted 7.2.0-rc5-V2CTL-gf5098b6bae76 #10 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: ib-comp-wq ib_cq_poll_work RIP: 0010:target_submit+0xbe/0x390 Code: fa 48 c1 ea 03 80 3c 02 00 0f 85 89 02 00 00 48 b8 00 00 00 00 00 fc ff df 4d 8b 64 24 18 49 8d 7c 24 78 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 5a 02 00 00 48 8d 7b 78 4d 8b 6c 24 78 48 b8 00 RSP: 0018:ffff8881058cfa78 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: ffff88810c78c6f0 RCX: ffffffff964bb363 RDX: 000000000000000f RSI: 00000000fffffe00 RDI: 0000000000000078 RBP: 1ffff11020b19f52 R08: 0000000000000001 R09: ffffed1020b19f52 R10: 0000000000000003 R11: ffff88810596c000 R12: 0000000000000000 R13: ffff88810c61b000 R14: ffff88810c6a3400 R15: ffff88810c61b044 FS: 0000000000000000(0000) GS:ffff8881822b2000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f1f1b83c000 CR3: 000000006fe72001 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: <TASK> ? __pfx__raw_spin_lock_bh+0x10/0x10 ? __pfx_target_submit+0x10/0x10 ? mutex_lock+0x81/0xe0 ? __pfx_mutex_lock+0x10/0x10 ? iscsit_execute_cmd+0x650/0x850 iscsit_sequence_cmd+0x186/0x3d0 iscsit_process_scsi_cmd+0x87/0x300 isert_recv_done+0x1002/0x2390 ? __pfx_isert_recv_done+0x10/0x10 ? rxe_poll_cq+0x253/0x3d0 ? finish_task_switch.isra.0+0x1dc/0xa70 __ib_process_cq+0xe1/0x390 ib_cq_poll_work+0x46/0x150 process_one_work+0x633/0x1030 ? assign_work+0x11d/0x370 worker_thread+0x45b/0xd10 ? __pfx_worker_thread+0x10/0x10 ? __pfx_worker_thread+0x10/0x10 kthread+0x2c6/0x3b0 ? recalc_sigpending+0x15c/0x1e0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x36e/0x5a0 ? __pfx_ret_from_fork+0x10/0x10 ? __switch_to+0x572/0xdd0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]---
Delay the final Login Response instead. isert_get_rx_pdu() runs from iscsi_target_rx_thread() after conn->rx_login_comp, completed by iscsi_post_login_handler() after __transport_register_session(); iscsi-TCP and cxgbit already take PDUs from that thread, isert alone does not. The buffers are still posted first, so the initiator's first command does not meet an empty receive queue and nothing depends on RNR flow control, and the header and payload live in isert_conn, not in the struct iscsi_login that iscsi_target_nego_release() frees first.
Over rxe, 400 login cycles per run, the oops appeared in 10 of 20 unpatched runs and in none of 20 runs with this patch. An initiator that never waits is handled by the next patch.
Not tested: iWARP, discovery sessions over iSER, and real HCAs.
--- drivers/infiniband/ulp/isert/ib_isert.c | 20 ++++++++++++++++++-- drivers/infiniband/ulp/isert/ib_isert.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +18 -2
@@ -59,6 +59,8 @@ static void isert_recv_done(struct ib_cq *cq, struct ib_wc *wc);static void isert_send_done (struct ib_cq *cq,struct ib_wc *wc);static void isert_login_recv_done (struct ib_cq *cq,struct ib_wc *wc);static void isert_login_send_done (struct ib_cq *cq,struct ib_wc *wc); +static void isert_unmap_tx_desc (struct iser_tx_desc *tx_desc, +struct ib_device *ib_dev);static int isert_sg_tablesize_set (const char *val,const struct kernel_param *kp) {
@@ -498,6 +500,8 @@ isert_connect_release(struct isert_conn *isert_conn)if (isert_conn->qp)isert_destroy_qp (isert_conn); +isert_unmap_tx_desc (&isert_conn->login_tx_desc, device->ib_device); +if (isert_conn->login_desc)isert_free_login_buf (isert_conn);
@@ -958,14 +962,17 @@ isert_put_login_tx(struct iscsit_conn *conn, struct iscsi_login *login,mutex_lock (&isert_conn->mutex); isert_conn->state =ISER_CONN_FULL_FEATURE ;mutex_unlock (&isert_conn->mutex); - goto post_send; + +/* Sent from isert_get_rx_pdu() after registration. */ + isert_conn->login_rsp_pending = true; +return 0 ; } ret =isert_login_post_recv (isert_conn);if (ret)return ret; } -post_send: + ret =isert_login_post_send (isert_conn, tx_desc);if (ret)return ret;
@@ -2625,8 +2632,17 @@ static void isert_free_conn(struct iscsit_conn *conn)static void isert_get_rx_pdu (struct iscsit_conn *conn) { +struct isert_conn *isert_conn = conn->context;struct completion comp; +/* The session is registered by now; see isert_put_login_tx(). */ +if (isert_conn->login_rsp_pending) { + isert_conn->login_rsp_pending = false; +if (isert_login_post_send (isert_conn, + &isert_conn->login_tx_desc)) +return ; + } +init_completion (&comp);wait_for_completion_interruptible (&comp);
drivers/infiniband/ulp/isert/ib_isert.h +1 -0
@@ -178,6 +178,7 @@ struct isert_conn {struct completion login_comp;struct completion login_req_comp;struct iser_tx_desc login_tx_desc; +bool login_rsp_pending;struct rdma_cm_id *cm_id;struct ib_qp *qp;struct ib_cq *cq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 924/1518 IB/isert: post the full-feature receive buffers after session registration
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit 5247dde9daac7e107853b6fea043f7f47be033f7 ]
isert_put_login_tx() posts the full-feature receive buffers before __transport_register_session() runs, so an initiator that does not wait for the final Login Response can still have a SCSI command executed against an se_session whose se_tpg is NULL - the same oops as the previous patch, at target_submit+0xbe.
Post them from isert_get_rx_pdu(), which the previous patch already uses to send that response, and post them before that send: the receive queue is filled at the moment the initiator is told it may use it. Allocating there keeps the existing property that a memory allocation failure cannot happen once the final Login Response is on the wire.
The receive queue is already empty between the final Login Request and isert_post_recvm(); this moves the second point later, from a median of 92 us to 172 us over 1200 logins. Only an initiator that sends before it has been told to can reach that window, and on IB and RoCE its send is retried there until the buffers appear - isert_rdma_accept() asks for rnr_retry_count = 7. iWARP has no RNR flow control, so there the same send terminates the connection instead.
Measured over rxe, 400 login cycles per run, with an initiator that does not wait: an instrumented build counted no entries to isert_recv_done() before the buffers are posted in 10 runs, where that initiator oopsed 8 of 10 unpatched runs and 5 of 10 with only the previous patch.
Not tested: iWARP, discovery sessions over iSER, and real HCAs.
--- drivers/infiniband/ulp/isert/ib_isert.c | 41 ++++++++++++------------- 1 file changed, 20 insertions(+), 21 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +20 -21
@@ -949,21 +949,7 @@ isert_put_login_tx(struct iscsit_conn *conn, struct iscsi_login *login, }if (!login->login_failed) {if (login->login_complete) { - ret =isert_alloc_rx_descriptors (isert_conn); -if (ret) -return ret; - - ret =isert_post_recvm (isert_conn, -ISERT_QP_MAX_RECV_DTOS ); -if (ret) -return ret; - -/* Now we are in FULL_FEATURE phase */ -mutex_lock (&isert_conn->mutex); - isert_conn->state =ISER_CONN_FULL_FEATURE ; -mutex_unlock (&isert_conn->mutex); - -/* Sent from isert_get_rx_pdu() after registration. */ +/* Posted and sent from isert_get_rx_pdu(). */ isert_conn->login_rsp_pending = true;return 0 ; }
@@ -2635,13 +2621,26 @@ static void isert_get_rx_pdu(struct iscsit_conn *conn)struct isert_conn *isert_conn = conn->context;struct completion comp; +/* The login timeout timer can fail the login after isert_put_login_tx(). */ +if (!isert_conn->login_rsp_pending) +return ; + + isert_conn->login_rsp_pending = false; +/* The session is registered by now; see isert_put_login_tx(). */ -if (isert_conn->login_rsp_pending) { - isert_conn->login_rsp_pending = false; -if (isert_login_post_send (isert_conn, - &isert_conn->login_tx_desc)) -return ; - } +if (isert_alloc_rx_descriptors (isert_conn)) +return ; + +if (isert_post_recvm (isert_conn,ISERT_QP_MAX_RECV_DTOS )) +return ; + +/* Now we are in FULL_FEATURE phase */ +mutex_lock (&isert_conn->mutex); + isert_conn->state =ISER_CONN_FULL_FEATURE ; +mutex_unlock (&isert_conn->mutex); + +if (isert_login_post_send (isert_conn, &isert_conn->login_tx_desc)) +return ;init_completion (&comp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 925/1518 RDMA/siw: Fix use-after-free in siw_accept()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
[ Upstream commit a9394971825933074032794a5feee5211509c774 ]
siw_accept() looks up the QP supplied by userspace. If that QP is already in RTS, the function jumps to error cleanup before associating the incoming CEP with it.
The cleanup tests whether qp->cep is non-NULL and assumes the current call installed the association. However, qp->cep can point to the CEP of an existing connection. The cleanup then drops a reference from the incoming cep, not qp->cep. Once the incoming endpoint loses its remaining references, this can free it before the subsequent cep->qp store, causing a use-after-free. It also clears the existing QP association.
Only release the association reference when qp->cep is the incoming CEP. This preserves an existing association and avoids accessing the freed endpoint.
--- drivers/infiniband/sw/siw/siw_cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_cm.c +1 -1
@@ -1701,7 +1701,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params) cep->state =SIW_EPSTATE_CLOSED ;siw_free_cm_id (cep); -if (qp->cep) { +if (qp->cep == cep) {siw_cep_put (cep); qp->cep =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 926/1518 module: replace use of system_wq with system_dfl_wq
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Crivellari <[email protected]>
[ Upstream commit 581ac2d4a58b81669cc6abf645a558bce5cf14ab ]
Currently if a user enqueues a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistency cannot be addressed without refactoring the API.
This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
Switch to using system_dfl_wq, the new unbound workqueue, because the users do not benefit from a per-cpu workqueue.
Stable-dep-of: 5eecb11b543f ("module/dups: Fix use-after-free in kmod_dup_req lifetime handling")
--- kernel/module/dups.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/module/dups.c +2 -2
@@ -113,7 +113,7 @@ static void kmod_dup_request_complete(struct work_struct *work)* let this linger forever as this is just a boot optimization for * possible abuses of vmalloc() incurred by finit_module() thrashing. */ -queue_delayed_work (system_wq, &kmod_req->delete_work,60 *HZ ); +queue_delayed_work (system_dfl_wq, &kmod_req->delete_work,60 *HZ ); }bool kmod_dup_request_exists_wait (char *module_name,bool wait,int *dup_ret)
@@ -240,7 +240,7 @@ void kmod_dup_request_announce(char *module_name, int ret)* There is no rush. But we also don't want to hold the * caller up forever or introduce any boot delays. */ -queue_work (system_wq, &kmod_req->complete_work); +queue_work (system_dfl_wq, &kmod_req->complete_work); out:mutex_unlock (&kmod_dup_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 927/1518 module: use strscpy() to copy module names in stats and dup tracking
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naveen Kumar Chaudhary <[email protected]>
[ Upstream commit 93c29ebd1622fb0670701e1c1b3a978a5cac08b7 ]
Both try_add_failed_module() and kmod_dup_request_exists_wait() use memcpy() with strlen() to copy module names into fixed-size char[MODULE_NAME_LEN] buffers. Neither performs a bounds check on the copy. Current callers always pass names originating from mod->name (itself char[MODULE_NAME_LEN]), so this is not exploitable today. However both functions accept a plain const char * with no documented length contract, making them latent buffer overflows if a future caller passes a longer string.
Replace memcpy() with strscpy() in both sites, which bounds the copy to MODULE_NAME_LEN and always NUL-terminates.
Stable-dep-of: 5eecb11b543f ("module/dups: Fix use-after-free in kmod_dup_req lifetime handling")
--- kernel/module/dups.c | 2 +- kernel/module/stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/module/dups.c +1 -1
@@ -129,7 +129,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)if (!new_kmod_req)return false; -memcpy (new_kmod_req->name, module_name,strlen (module_name)); +strscpy (new_kmod_req->name, module_name);INIT_WORK (&new_kmod_req->complete_work, kmod_dup_request_complete);INIT_DELAYED_WORK (&new_kmod_req->delete_work, kmod_dup_request_delete);init_completion (&new_kmod_req->first_req_done);
kernel/module/stats.c +1 -1
@@ -253,7 +253,7 @@ int try_add_failed_module(const char *name, enum fail_dup_mod_reason reason) mod_fail =kzalloc (sizeof (*mod_fail),GFP_KERNEL );if (!mod_fail)return -ENOMEM ; -memcpy (mod_fail->name, name,strlen (name)); +strscpy (mod_fail->name, name);__set_bit (reason, &mod_fail->dup_fail_mask);atomic_long_inc (&mod_fail->count);list_add_rcu (&mod_fail->list, &dup_failed_modules);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 928/1518 module/dups: Inform duplicate requests about the result directly
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Pavlu <[email protected]>
[ Upstream commit d258ed8a86bb46bbbbc84fb914478259a1e694a4 ]
When kmod_dup_request_announce() announces the completion of a request_module() call to duplicate waiters, it queues a work item to invoke kmod_dup_request_complete(), and only that function calls complete_all().
This adds an arbitrary delay that is unnecessary and provides little benefit. Call complete_all() directly from kmod_dup_request_announce() instead.
Stable-dep-of: 5eecb11b543f ("module/dups: Fix use-after-free in kmod_dup_req lifetime handling")
--- kernel/module/dups.c | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-)
kernel/module/dups.c +9 -34
@@ -48,7 +48,6 @@ struct kmod_dup_req {struct list_head list;char name[MODULE_NAME_LEN ];struct completion first_req_done; -struct work_struct complete_work;struct delayed_work delete_work;int dup_ret; };
@@ -93,29 +92,6 @@ static void kmod_dup_request_delete(struct work_struct *work)kfree (kmod_req); } -static void kmod_dup_request_complete (struct work_struct *work) -{ -struct kmod_dup_req *kmod_req; - - kmod_req = container_of(work, struct kmod_dup_req, complete_work); - -/* -* This will ensure that the kernel will let all the waiters get -* informed its time to check the return value. It's time to -* go home. -*/ -complete_all (&kmod_req->first_req_done); - -/* -* Now that we have allowed prior request_module() calls to go on -* with life, let's schedule deleting this entry. We don't have -* to do it right away, but we *eventually* want to do it so to not -* let this linger forever as this is just a boot optimization for -* possible abuses of vmalloc() incurred by finit_module() thrashing. -*/ -queue_delayed_work (system_dfl_wq, &kmod_req->delete_work,60 *HZ ); -} -bool kmod_dup_request_exists_wait (char *module_name,bool wait,int *dup_ret) {struct kmod_dup_req *kmod_req, *new_kmod_req;
@@ -130,7 +106,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)return false;strscpy (new_kmod_req->name, module_name); -INIT_WORK (&new_kmod_req->complete_work, kmod_dup_request_complete);INIT_DELAYED_WORK (&new_kmod_req->delete_work, kmod_dup_request_delete);init_completion (&new_kmod_req->first_req_done);
@@ -230,17 +205,17 @@ void kmod_dup_request_announce(char *module_name, int ret) kmod_req->dup_ret = ret; +/* Inform all duplicate waiters to check the return value. */ +complete_all (&kmod_req->first_req_done); +/* -* If we complete() here we may allow duplicate threads -* to continue before the first one that submitted the -* request. We're in no rush also, given that each and -* every bounce back to userspace is slow we avoid that -* with a slight delay here. So queueue up the completion -* and let duplicates suffer, just wait a tad bit longer. -* There is no rush. But we also don't want to hold the -* caller up forever or introduce any boot delays. +* Now that we have allowed prior request_module() calls to go on +* with life, let's schedule deleting this entry. We don't have +* to do it right away, but we *eventually* want to do it so to not +* let this linger forever as this is just a boot optimization for +* possible abuses of vmalloc() incurred by finit_module() thrashing. */ -queue_work (system_dfl_wq, &kmod_req->complete_work); +queue_delayed_work (system_dfl_wq, &kmod_req->delete_work,60 *HZ ); out:mutex_unlock (&kmod_dup_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 929/1518 module/dups: Fix use-after-free in kmod_dup_req lifetime handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Pavlu <[email protected]>
[ Upstream commit 5eecb11b543f9f417bcf0dea239ff99c6af65dbd ]
The kmod dups code uses RCU to ensure that a kmod_dup_req instance is freed only after it is no longer referenced. When releasing an instance, the kmod_dup_request_delete() function removes the kmod_dup_req from the dup_kmod_reqs list, waits via synchronize_rcu() and finally frees it. However, this doesn't work correctly because parallel users referencing the instance in kmod_dup_request_exists_wait() don't enter an RCU read-side critical section. This can result in a use-after-free.
The kmod_dup_request_exists_wait() function may need to hold a valid reference to a kmod_dup_req instance across a blocking wait until the corresponding modprobe command completes. This makes it unsuitable for RCU.
Fix the issue by changing the lifecycle management of kmod_dup_req to use reference counting.
--- kernel/module/dups.c | 56 +++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 16 deletions(-)
kernel/module/dups.c +40 -16
@@ -30,6 +30,7 @@#include <linux/ptrace.h> #include <linux/async.h> #include <linux/uaccess.h> +#include <linux/refcount.h> #include "internal.h"
@@ -38,13 +39,12 @@static bool enable_dups_trace =IS_ENABLED (CONFIG_MODULE_DEBUG_AUTOLOAD_DUPS_TRACE );module_param (enable_dups_trace, bool_enable_only,0644 ); -/* -* Protects dup_kmod_reqs list, adds / removals with RCU. -*/ +/* A mutex-protected list of active kmod requests. */ static DEFINE_MUTEX (kmod_dup_mutex);static LIST_HEAD (dup_kmod_reqs);struct kmod_dup_req { +refcount_t refcount;struct list_head list;char name[MODULE_NAME_LEN ];struct completion first_req_done;
@@ -52,12 +52,24 @@ struct kmod_dup_req {int dup_ret; }; +static void get_kmod_req (struct kmod_dup_req *kmod_req) +{ +refcount_inc (&kmod_req->refcount); +} + +static void put_kmod_req (struct kmod_dup_req *kmod_req) +{ +if (refcount_dec_and_test (&kmod_req->refcount)) +kfree (kmod_req); +} +static struct kmod_dup_req *kmod_dup_request_lookup (char *module_name) {struct kmod_dup_req *kmod_req; -list_for_each_entry_rcu (kmod_req, &dup_kmod_reqs, list, -lockdep_is_held (&kmod_dup_mutex)) { +lockdep_assert_held (&kmod_dup_mutex); + +list_for_each_entry (kmod_req, &dup_kmod_reqs, list) {if (strlen (kmod_req->name) ==strlen (module_name) && !memcmp (kmod_req->name, module_name,strlen (module_name))) {return kmod_req;
@@ -86,10 +98,10 @@ static void kmod_dup_request_delete(struct work_struct *work)* just returning 0. */ mutex_lock (&kmod_dup_mutex); -list_del_rcu (&kmod_req->list); -synchronize_rcu (); +list_del (&kmod_req->list);mutex_unlock (&kmod_dup_mutex); -kfree (kmod_req); + +put_kmod_req (kmod_req); }bool kmod_dup_request_exists_wait (char *module_name,bool wait,int *dup_ret)
@@ -105,6 +117,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)if (!new_kmod_req)return false; +refcount_set (&new_kmod_req->refcount,1 );strscpy (new_kmod_req->name, module_name);INIT_DELAYED_WORK (&new_kmod_req->delete_work, kmod_dup_request_delete);init_completion (&new_kmod_req->first_req_done);
@@ -136,10 +149,12 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)* keep tab on duplicates later. */ pr_debug ("New request_module() for %s\n" , module_name); -list_add_rcu (&new_kmod_req->list, &dup_kmod_reqs); +list_add (&new_kmod_req->list, &dup_kmod_reqs);mutex_unlock (&kmod_dup_mutex);return false; } + +get_kmod_req (kmod_req);mutex_unlock (&kmod_dup_mutex);/* We are dealing with a duplicate request now */
@@ -169,7 +184,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)* calls bail out right away. */ *dup_ret =0 ; -return true; + goto out; }/*
@@ -184,12 +199,14 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) TASK_KILLABLE);if (ret) { *dup_ret = ret; -return true; + goto out; }/* Now the duplicate request has the same exact return value as the first request */ *dup_ret = kmod_req->dup_ret; +out: +put_kmod_req (kmod_req);return true; }
@@ -199,15 +216,25 @@ void kmod_dup_request_announce(char *module_name, int ret)mutex_lock (&kmod_dup_mutex); +/* +* Look for a kmod_dup_req previously added in +* kmod_dup_request_exists_wait(). Note that a request_module_nowait() +* without its own kmod_dup_req entry can announce a result of +* a concurrent request_module() call. +*/ kmod_req =kmod_dup_request_lookup (module_name); -if (!kmod_req) - goto out; +if (!kmod_req ||completion_done (&kmod_req->first_req_done)) { +mutex_unlock (&kmod_dup_mutex); +return ; + } kmod_req->dup_ret = ret;/* Inform all duplicate waiters to check the return value. */ complete_all (&kmod_req->first_req_done); +mutex_unlock (&kmod_dup_mutex); +/* * Now that we have allowed prior request_module() calls to go on * with life, let's schedule deleting this entry. We don't have
@@ -216,7 +243,4 @@ void kmod_dup_request_announce(char *module_name, int ret)* possible abuses of vmalloc() incurred by finit_module() thrashing. */ queue_delayed_work (system_dfl_wq, &kmod_req->delete_work,60 *HZ ); - -out: -mutex_unlock (&kmod_dup_mutex); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 930/1518 RDMA/erdma: restrict the driver to little-endian systems
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit a12d9145145b21c50531afb6e3f711b1f34e1465 ]
The eRDMA device interface requires explicit byte ordering, but several DMA-visible values that should be little-endian remain native-endian. Command request payloads are copied verbatim, data-path SQE headers are written without cpu_to_le64(), and kernel doorbell records are assigned plain u64 values. The command completion path also reads a little-endian SQE header without conversion.
These paths are byte-swapped on big-endian kernels and can break command processing during probe. Since complete big-endian support requires converting every device-visible structure, depend on !CPU_BIG_ENDIAN.
--- drivers/infiniband/hw/erdma/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/erdma/Kconfig +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config INFINIBAND_ERDMA tristate "Alibaba Elastic RDMA Adapter (ERDMA) support" - depends on PCI_MSI && 64BIT + depends on PCI_MSI && 64BIT && !CPU_BIG_ENDIAN depends on INFINIBAND_ADDR_TRANS depends on INFINIBAND_USER_ACCESS help
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 931/1518 wifi: mac80211: skip default WMM setup for AP_VLAN links
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 4d8cfff012aaa971d50b01823b1015c1073c3ff6 ]
AP_VLAN interfaces are never passed to the driver, so setting default WMM parameters on their links trips the check-sdata-in-driver warning in drv_conf_tx(), as well as in the BSS_CHANGED_QOS link info notification. Skip it, matching the existing AP_VLAN handling in this function.
--- net/mac80211/link.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mac80211/link.c +2 -1
@@ -343,7 +343,8 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata, link = links[link_id];ieee80211_link_init (sdata, link_id, &link->data, &link->conf);ieee80211_link_setup (&link->data); -ieee80211_set_wmm_default (&link->data, true, non_sta); +if (sdata->vif.type !=NL80211_IFTYPE_AP_VLAN ) +ieee80211_set_wmm_default (&link->data, true, non_sta); }if (new_links ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 932/1518 arm64: hibernate: mask DAIF before restoring hibernated kernel
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ada Couprie Diaz <[email protected]>
[ Upstream commit 684bde100117931f4c51c644a95f42f2dab041bc ]
The arm64 hibernate code manages the exception masking in an unsound way, leading to potential crashes and/or warnings during resume.
When a hibernation image is saved in swsusp_arch_suspend(), all DAIF exceptions are masked (by virtue of local_daif_save()), and the suspended image is saved assuming that all DAIF exceptions will remain masked when the image is restored.
When a hibernation image is resumed by swsusp_arch_resume(), only interrupts are masked (by virtue of local_irq_disable() in resume_target_kernel()). When pseudo-NMI is enabled the DAIF.IF bits will be clear, and regardless of pseudo-NMI the DAIF.DA bits will be clear.
This means that there are two problems:
(1) It is possible to take Debug, SError, or pseudo-NMI exceptions during the resume process. This is unsafe, as during the resume process both the old ane new kernels will tranisently be in an inconsistent state, and swsusp_arch_suspend_exit() won't retain an executable mapping of any exception vectors.
Any exception taken here will be fatal and silent.
(2) When re-entering the resumed kernel, some DAIF bits will be clear unexpectedly. This permits Debug, SError, or pseudo-NMI exceptions to be taken for a short period while the resumed kernel is not yet in a consistent state.
This is detected by CONFIG_ARM64_DEBUG_PRIORITY_MASKING.
Avoid these issues by masking all DAIF exceptions during resume.
--- arch/arm64/kernel/hibernate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm64/kernel/hibernate.c +12 -0
@@ -465,9 +465,21 @@ int __nocfi swsusp_arch_resume(void)if (el2_reset_needed ())__hyp_set_vectors (el2_vectors); +/* +* It is necessary to mask all DAIF exceptions here as: +* +* - The copy of swsusp_arch_suspend_exit() in the hibernation +* text cannot handle taking any exceptions. +* +* - The suspended kernel masked all DAIF exceptions in +* swsusp_arch_resume(), and expects to be re-entered in the +* same state : with all DAIF exceptions masked. +*/ +local_daif_save ();hibernate_exit (virt_to_phys (tmp_pg_dir), resume_hdr.ttbr1_el1, resume_hdr.reenter_kernel, restore_pblist, resume_hdr.__hyp_stub_vectors,virt_to_phys (zero_page)); +unreachable ();return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 933/1518 arm64: hibernate: Restore DAIF state on error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Murzin <[email protected]>
[ Upstream commit 541549827889d0380fd73f8aacb5de6ef7a5a1ac ]
Sashiko AI has reported that if swsusp_mte_save_tags() for some reason fails we return from swsusp_arch_suspend() with DAIF being masked - that is not what we'd expect. Restore the saved DAIF state before returning from the error path.
--- arch/arm64/kernel/hibernate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kernel/hibernate.c +3 -1
@@ -348,8 +348,10 @@ int swsusp_arch_suspend(void)crash_prepare_suspend (); ret =swsusp_mte_save_tags (); -if (ret) +if (ret) { +local_daif_restore (flags);return ret; + } sleep_cpu =smp_processor_id (); ret =swsusp_save ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 934/1518 mfd: rave-sp: validate received frame payload lengths
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 0be718b5451bd83865d6e2a8d750ca7886c4772a ]
A received RAVE-SP frame contains protocol data followed by a variant-specific one- or two-byte checksum. rave_sp_receive_frame() derives a checksum pointer before proving that the frame contains the checksum, then passes the checksum-inclusive length to handlers that index the command, acknowledgment ID and event-data bytes or derive a reply payload length.
Name those protocol field offsets, prove the checksum extent before deriving the protocol-data length, pass only that data length to the handlers, and require the complete event or reply prefix before consuming it.
--- drivers/mfd/rave-sp.c | 64 +++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 20 deletions(-)
drivers/mfd/rave-sp.c +44 -20
@@ -63,6 +63,12 @@#define RAVE_SP_TX_BUFFER_SIZE \ (RAVE_SP_STX_ETX_SIZE + 2 * RAVE_SP_RX_BUFFER_SIZE) +enum rave_sp_frame_offset { +RAVE_SP_FRAME_CODE_OFFSET , +RAVE_SP_FRAME_ACK_ID_OFFSET , +RAVE_SP_FRAME_DATA_OFFSET , +}; +/** * enum rave_sp_deframer_state - Possible state for de-framer *
@@ -352,7 +358,7 @@ int rave_sp_exec(struct rave_sp *sp,int command, ret =0 ;u8 ackid; - command = sp->variant->cmd.translate (data[0 ]); + command = sp->variant->cmd.translate (data[RAVE_SP_FRAME_CODE_OFFSET ]);if (command <0 )return command;
@@ -366,8 +372,8 @@ int rave_sp_exec(struct rave_sp *sp, sp->reply = &reply;mutex_unlock (&sp->reply_lock); - data[0 ] = command; - data[1 ] = ackid; + data[RAVE_SP_FRAME_CODE_OFFSET ] = command; + data[RAVE_SP_FRAME_ACK_ID_OFFSET ] = ackid;rave_sp_write (sp, data, data_size);
@@ -388,16 +394,23 @@ EXPORT_SYMBOL_GPL(rave_sp_exec);static void rave_sp_receive_event (struct rave_sp *sp,const unsigned char *data,size_t length) { -u8 cmd[] = { - [0 ] =rave_sp_reply_code (data[0 ]), - [1 ] = data[1 ], - }; +unsigned long action; +u8 cmd[RAVE_SP_FRAME_DATA_OFFSET ]; + +if (length <RAVE_SP_FRAME_DATA_OFFSET +1 ) { +dev_warn (&sp->serdev->dev,"Dropping short event frame\n" ); +return ; + } + + cmd[RAVE_SP_FRAME_CODE_OFFSET ] = +rave_sp_reply_code (data[RAVE_SP_FRAME_CODE_OFFSET ]); + cmd[RAVE_SP_FRAME_ACK_ID_OFFSET ] = data[RAVE_SP_FRAME_ACK_ID_OFFSET ];rave_sp_write (sp, cmd,sizeof (cmd)); -blocking_notifier_call_chain (&sp->event_notifier_list, -rave_sp_action_pack (data[0 ], data[2 ]), -NULL ); + action =rave_sp_action_pack (data[RAVE_SP_FRAME_CODE_OFFSET ], + data[RAVE_SP_FRAME_DATA_OFFSET ]); +blocking_notifier_call_chain (&sp->event_notifier_list, action,NULL ); } static void rave_sp_receive_reply(struct rave_sp *sp,
@@ -405,27 +418,35 @@ static void rave_sp_receive_reply(struct rave_sp *sp, {struct device *dev = &sp->serdev->dev;struct rave_sp_reply *reply; -const size_t payload_length = length -2 ; +size_t payload_length; + +if (length <RAVE_SP_FRAME_DATA_OFFSET ) { +dev_warn (dev,"Dropping short reply frame\n" ); +return ; + } + payload_length = length -RAVE_SP_FRAME_DATA_OFFSET ;mutex_lock (&sp->reply_lock); reply = sp->reply;if (reply) { -if (reply->code == data[0 ] && reply->ackid == data[1 ] && +if (reply->code == data[RAVE_SP_FRAME_CODE_OFFSET ] && + reply->ackid == data[RAVE_SP_FRAME_ACK_ID_OFFSET ] && payload_length >= reply->length) {/* * We are relying on memcpy(dst, src, 0) to be a no-op * when handling commands that have a no-payload reply */ -memcpy (reply->data, &data[2 ], reply->length); +memcpy (reply->data, &data[RAVE_SP_FRAME_DATA_OFFSET ], + reply->length);complete (&reply->received); sp->reply =NULL ; }else {dev_err (dev,"Ignoring incorrect reply\n" );dev_dbg (dev,"Code: expected = 0x%08x received = 0x%08x\n" , - reply->code, data[0 ]); + reply->code, data[RAVE_SP_FRAME_CODE_OFFSET ]);dev_dbg (dev,"ACK ID: expected = 0x%08x received = 0x%08x\n" , - reply->ackid, data[1 ]); + reply->ackid, data[RAVE_SP_FRAME_ACK_ID_OFFSET ]);dev_dbg (dev,"Length: expected = %zu received = %zu\n" , reply->length, payload_length); }
@@ -439,10 +460,10 @@ static void rave_sp_receive_frame(struct rave_sp *sp, size_t length) {const size_t checksum_length = sp->variant->checksum->length; -const size_t payload_length = length - checksum_length; -const u8 *crc_reported = &data[payload_length];struct device *dev = &sp->serdev->dev;u8 crc_calculated[RAVE_SP_CHECKSUM_SIZE ]; +const u8 *crc_reported; +size_t payload_length;if (unlikely (checksum_length >sizeof (crc_calculated))) {dev_warn (dev,"Checksum too long, dropping\n" );
@@ -457,6 +478,9 @@ static void rave_sp_receive_frame(struct rave_sp *sp,return ; } + payload_length = length - checksum_length; + crc_reported = &data[payload_length]; + sp->variant->checksum->subroutine (data, payload_length, crc_calculated);
@@ -465,10 +489,10 @@ static void rave_sp_receive_frame(struct rave_sp *sp,return ; } -if (rave_sp_id_is_event (data[0 ])) -rave_sp_receive_event (sp, data, length); +if (rave_sp_id_is_event (data[RAVE_SP_FRAME_CODE_OFFSET ])) +rave_sp_receive_event (sp, data, payload_length);else -rave_sp_receive_reply (sp, data, length); +rave_sp_receive_reply (sp, data, payload_length); } static size_t rave_sp_receive_buf(struct serdev_device *serdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 935/1518 mfd: iqs62x: Reject zero-length firmware records
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 08ea045e0b82cbcadb7a2efc43a23561489a00f2 ]
struct iqs62x_fw_rec includes the first data byte in its fixed-size header, so the parser advances by len - 1 bytes after that header. A zero len makes the size_t cursor update move back by one byte, so the next record overlaps the current record instead of following a valid declared extent.
Reject zero-length records and express the remaining-size check without an offset addition.
--- drivers/mfd/iqs62x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/iqs62x.c +1 -1
@@ -237,7 +237,7 @@ static int iqs62x_firmware_parse(struct iqs62x_core *iqs62x, fw_rec = (struct iqs62x_fw_rec *)(fw->data + pos); pos +=sizeof (*fw_rec); -if (pos + fw_rec->len -1 > fw->size) { +if (!fw_rec->len || fw_rec->len -1 > fw->size - pos) { ret = -EINVAL ;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 936/1518 mfd: macsmc: Fix key count endianness annotation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Peter <[email protected]>
[ Upstream commit 0a29aa605286bcd01632eb6b61f59b9053312347 ]
SMC firmware returns the value of the #KEY key in big-endian unlike most other keys. Reading it through apple_smc_read_u32() into a plain u32 and then converting with be32_to_cpu() makes sparse complain:
drivers/mfd/macsmc.c:462:26: sparse: cast to restricted __be32
Read the raw value into a __be32 using apple_smc_read() instead.
--- drivers/mfd/macsmc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/mfd/macsmc.c +5 -3
@@ -406,7 +406,7 @@ static int apple_smc_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct apple_smc *smc; -u32 count; +__be32 count;int ret; smc =devm_kzalloc (dev,sizeof (*smc),GFP_KERNEL );
@@ -457,8 +457,10 @@ static int apple_smc_probe(struct platform_device *pdev)dev_set_drvdata (&pdev->dev, smc);BLOCKING_INIT_NOTIFIER_HEAD (&smc->event_handlers); - ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count); -if (ret) + ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count)); +if (ret >=0 && ret !=sizeof (count)) + ret = -EINVAL ; +if (ret <0 )return dev_err_probe (smc->dev, ret,"Failed to get key count" ); smc->key_count =be32_to_cpu (count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 937/1518 gpiolib: move legacy interface into linux/gpio/legacy.h
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit bfdc854ba63bc815cf710701f889544a9d27df83 ]
Split the old contents from gpio.h for clarity. Ideally any driver that still includes linux/gpio.h can now be ported over to use either linux/gpio/legacy.h or linux/gpio/consumer.h, with the original file getting removed once that is complete.
No functional changes intended for now.
Stable-dep-of: 942901eeda93 ("leds: gpio: Clear error pointers for skipped LEDs")
--- include/linux/gpio.h | 162 +-------------------------------- include/linux/gpio/legacy.h | 173 ++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 158 deletions(-) create mode 100644 include/linux/gpio/legacy.h
include/linux/gpio.h +4 -158
@@ -2,13 +2,11 @@/* * NOTE: This header *must not* be included. * -* This is the LEGACY GPIO bulk include file, including legacy APIs. It is -* used for GPIO drivers still referencing the global GPIO numberspace, -* and should not be included in new code. -* * If you're implementing a GPIO driver, only include <linux/gpio/driver.h> * If you're implementing a GPIO consumer, only include <linux/gpio/consumer.h> +* If you're using the legacy interfaces, include <linux/gpio/legacy.h> */ +#ifndef __LINUX_GPIO_H#define __LINUX_GPIO_H
@@ -18,159 +16,7 @@#endif #ifdef CONFIG_GPIOLIB_LEGACY - -struct device ; - -/* make these flag values available regardless of GPIO kconfig options */ -#define GPIOF_IN ((1 << 0)) -#define GPIOF_OUT_INIT_LOW ((0 << 0) | (0 << 1)) -#define GPIOF_OUT_INIT_HIGH ((0 << 0) | (1 << 1)) - -#ifdef CONFIG_GPIOLIB -/* -* "valid" GPIO numbers are nonnegative and may be passed to -* setup routines like gpio_request(). Only some valid numbers -* can successfully be requested and used. -* -* Invalid GPIO numbers are useful for indicating no-such-GPIO in -* platform data and other tables. -*/ -static inline bool gpio_is_valid (int number) -{ -/* only non-negative numbers are valid */ -return number >=0 ; -} - -/* -* Platforms may implement their GPIO interface with library code, -* at a small performance cost for non-inlined operations and some -* extra memory (for code and for per-GPIO table entries). -*/ - -/* Always use the library code for GPIO management calls, -* or when sleeping may be involved. -*/ -int gpio_request (unsigned gpio,const char *label); -void gpio_free (unsigned gpio); - -static inline int gpio_direction_input (unsigned gpio) -{ -return gpiod_direction_input (gpio_to_desc (gpio)); -} -static inline int gpio_direction_output (unsigned gpio,int value) -{ -return gpiod_direction_output_raw (gpio_to_desc (gpio), value); -} - -static inline int gpio_get_value_cansleep (unsigned gpio) -{ -return gpiod_get_raw_value_cansleep (gpio_to_desc (gpio)); -} -static inline void gpio_set_value_cansleep (unsigned gpio,int value) -{ -gpiod_set_raw_value_cansleep (gpio_to_desc (gpio), value); -} - -static inline int gpio_get_value (unsigned gpio) -{ -return gpiod_get_raw_value (gpio_to_desc (gpio)); -} -static inline void gpio_set_value (unsigned gpio,int value) -{ -gpiod_set_raw_value (gpio_to_desc (gpio), value); -} - -static inline int gpio_to_irq (unsigned gpio) -{ -return gpiod_to_irq (gpio_to_desc (gpio)); -} - -int gpio_request_one (unsigned gpio,unsigned long flags,const char *label); - -int devm_gpio_request_one (struct device *dev,unsigned gpio, -unsigned long flags,const char *label); - -#else /* ! CONFIG_GPIOLIB */ - -#include <linux/kernel.h> - -#include <asm/bug.h> -#include <asm/errno.h> - -static inline bool gpio_is_valid (int number) -{ -return false; -} - -static inline int gpio_request (unsigned gpio,const char *label) -{ -return -ENOSYS ; -} - -static inline int gpio_request_one (unsigned gpio, -unsigned long flags,const char *label) -{ -return -ENOSYS ; -} - -static inline void gpio_free (unsigned gpio) -{ -might_sleep (); - -/* GPIO can never have been requested */ -WARN_ON (1 ); -} - -static inline int gpio_direction_input (unsigned gpio) -{ -return -ENOSYS ; -} - -static inline int gpio_direction_output (unsigned gpio,int value) -{ -return -ENOSYS ; -} - -static inline int gpio_get_value (unsigned gpio) -{ -/* GPIO can never have been requested or set as {in,out}put */ -WARN_ON (1 ); -return 0 ; -} - -static inline void gpio_set_value (unsigned gpio,int value) -{ -/* GPIO can never have been requested or set as output */ -WARN_ON (1 ); -} - -static inline int gpio_get_value_cansleep (unsigned gpio) -{ -/* GPIO can never have been requested or set as {in,out}put */ -WARN_ON (1 ); -return 0 ; -} - -static inline void gpio_set_value_cansleep (unsigned gpio,int value) -{ -/* GPIO can never have been requested or set as output */ -WARN_ON (1 ); -} - -static inline int gpio_to_irq (unsigned gpio) -{ -/* GPIO can never have been requested or set as input */ -WARN_ON (1 ); -return -EINVAL ; -} - -static inline int devm_gpio_request_one (struct device *dev,unsigned gpio, -unsigned long flags,const char *label) -{ -WARN_ON (1 ); -return -EINVAL ; -} - -#endif /* ! CONFIG_GPIOLIB */ +#include <linux/gpio/legacy.h> #endif /* CONFIG_GPIOLIB_LEGACY */ +#endif /* __LINUX_GPIO_H */
include/linux/gpio/legacy.h new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 6.18 0937/1518] gpiolib: move legacy interface into linux/gpio/legacy.h
Quoted 8 lines · Greg Kroah-Hartman
6.18-stable review patch. If anyone has any objections, please let me know.
Signed-off-by Arnd Bergmann <[email protected]>Signed-off-by Bartosz Golaszewski<[email protected]>
Stable-dep-of:942901eeda93("leds: gpio: Clear error pointers for skipped LEDs")
Quoted 6 lines
Signed-off-by Sasha Levin <[email protected]>--- include/linux/gpio.h | 162 +-------------------------------- include/linux/gpio/legacy.h | 173 ++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 158 deletions(-) create mode 100644 include/linux/gpio/legacy.h
I don't see how this would related to 942901eeda93, this only moves code around that is not touched by that patch.
Arnd
Greg Kroah-Hartman
maintainerRe: [PATCH 6.18 0937/1518] gpiolib: move legacy interface into linux/gpio/legacy.h
Quoted 16 lines · Arnd Bergmann
Quoted 8 lines · Greg Kroah-Hartman
6.18-stable review patch. If anyone has any objections, please let me know.
Signed-off-by Arnd Bergmann <[email protected]>Signed-off-by Bartosz Golaszewski<[email protected]>
Stable-dep-of:942901eeda93("leds: gpio: Clear error pointers for skipped LEDs")Quoted 6 lines
Signed-off-by Sasha Levin <[email protected]>--- include/linux/gpio.h | 162 +-------------------------------- include/linux/gpio/legacy.h | 173 ++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 158 deletions(-) create mode 100644 include/linux/gpio/legacy.h
Quoted 2 lines
I don't see how this would related to
942901eeda93, this only moves code around that is not touched by that patch.
Odd, yeah, that's not needed, now dropped, thanks!
greg k-h
Greg Kroah-Hartman
maintainerPATCH 938/1518 leds: gpio: Make legacy gpiolib interface optional
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit 98c5c7b0d4269ecabfc86b8b49ffcfa47979e99d ]
There are still a handful of ancient mips/armv5/sh boards that use the gpio_led:gpio member to pass an old-style gpio number, but all modern users have been converted to gpio descriptors.
While the CONFIG_GPIOLIB_LEGACY option that guards devm_gpio_request_one() and related helpers is currently turned on in all kernel builds, the plan is to only enable it on the few platforms that actually pass gpio numbers in any platform_data.
Split out the legacy portion of the platform_data handling into a custom helper function that is guarded with in #ifdef block, to allow the the leds-gpio driver to compile cleanly when CONFIG_GPIOLIB_LEGACY gets turned off. Once the last user is converted, this function can be removed.
Stable-dep-of: 942901eeda93 ("leds: gpio: Clear error pointers for skipped LEDs")
--- drivers/leds/leds-gpio.c | 52 +++++++++++++++++++++++++++------------- include/linux/leds.h | 2 ++ 2 files changed, 37 insertions(+), 17 deletions(-)
drivers/leds/leds-gpio.c +35 -17
@@ -9,8 +9,8 @@#include <linux/container_of.h> #include <linux/device.h> #include <linux/err.h> -#include <linux/gpio.h> #include <linux/gpio/consumer.h> +#include <linux/gpio/legacy.h> #include <linux/leds.h> #include <linux/mod_devicetable.h> #include <linux/module.h>
@@ -212,7 +212,6 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, const struct gpio_led *template) {struct gpio_desc *gpiod; -int ret;/* * This means the LED does not come from the device tree
@@ -223,16 +222,29 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, gpiod =devm_gpiod_get_index_optional (dev,NULL , idx,GPIOD_OUT_LOW );if (IS_ERR (gpiod))return gpiod; -if (gpiod) { -gpiod_set_consumer_name (gpiod, template->name); -return gpiod; - } -/* -* This is the legacy code path for platform code that -* still uses GPIO numbers. Ultimately we would like to get -* rid of this block completely. -*/ +gpiod_set_consumer_name (gpiod, template->name); +return gpiod; +} + +#ifdef CONFIG_GPIOLIB_LEGACY +/* +* This is the legacy code path for platform code that still uses +* GPIO numbers, mainly MIPS and SuperH board files. +* Ultimately we would like to get rid of this block completely. +* +* ppc44x-warp sets the template->gpiod directly instead of +* adding a lookup table or device properties. This is not +* much better. +*/ +static struct gpio_desc *gpio_led_get_legacy_gpiod (struct device *dev,int idx, +const struct gpio_led *template) +{ +struct gpio_desc *gpiod; +int ret; + +if (template->gpiod) +return template->gpiod;/* skip leds that aren't available */ if (!gpio_is_valid (template->gpio))
@@ -252,6 +264,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, return gpiod; } +#else +static struct gpio_desc *gpio_led_get_legacy_gpiod (struct device *dev,int idx, +const struct gpio_led *template) +{ +return template->gpiod ?:ERR_PTR (-ENOENT ); +} +#endif static int gpio_led_probe (struct platform_device *pdev) {
@@ -270,14 +289,13 @@ static int gpio_led_probe(struct platform_device *pdev)const struct gpio_led *template = &pdata->leds[i];struct gpio_led_data *led_dat = &priv->leds[i]; -if (template->gpiod) - led_dat->gpiod = template->gpiod; -else + led_dat->gpiod =gpio_led_get_gpiod (dev, i, template); +if (!led_dat->gpiod) led_dat->gpiod = -gpio_led_get_gpiod (dev, i, template); +gpio_led_get_legacy_gpiod (dev, i, template);if (IS_ERR (led_dat->gpiod)) { -dev_info (dev,"Skipping unavailable LED gpio %d (%s)\n" , - template->gpio, template->name); +dev_info (dev,"Skipping unavailable LED gpio %s\n" , + template->name);continue ; }
include/linux/leds.h +2 -0
@@ -676,8 +676,10 @@ typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state,struct gpio_led {const char *name;const char *default_trigger; +#ifdef CONFIG_GPIOLIB_LEGACY unsigned gpio;unsigned active_low :1 ; +#endif unsigned retain_state_suspended :1 ;unsigned panic_indicator :1 ;unsigned default_state :2 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 939/1518 leds: gpio: Clear error pointers for skipped LEDs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steve Dunnagan <[email protected]>
[ Upstream commit 942901eeda934f1bebf2605a781155e9d6bc7f6e ]
gpio_led_get_gpiod() returns an error pointer when a platform-data LED's GPIO is unavailable. gpio_led_probe() skips registration in that case, but leaves the error pointer in led_dat->gpiod.
The skipped entry remains included in priv->num_leds. During shutdown, gpio_led_shutdown() walks those entries and passes the error pointer to gpio_led_set(), producing:
gpiod_set_value: invalid GPIO (errorpointer: -ENOENT)
Clear led_dat->gpiod before skipping the LED so skipped entries do not retain error-valued descriptors.
--- drivers/leds/leds-gpio.c | 1 + 1 file changed, 1 insertion(+)
drivers/leds/leds-gpio.c +1 -0
@@ -296,6 +296,7 @@ static int gpio_led_probe(struct platform_device *pdev)if (IS_ERR (led_dat->gpiod)) {dev_info (dev,"Skipping unavailable LED gpio %s\n" , template->name); + led_dat->gpiod =NULL ;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 940/1518 drm/amdgpu/gfx6: Fixup emit_cntxcntl()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 1edb323406aaf05739804d2faa2561f2d43bcd09 ]
Set bits on dword 2 like GFX7-8 except load_global_uconfig which doesn't exist on GFX6.
Emit VS_PARTIAL_FLUSH before VGT_FLUSH like GFX7-8.
For reference see old PAL which explains the bit fields in this register and that load_global_uconfig doesn't exist on GFX6 and also see gfx_v7_ring_emit_cntxcntl() for the GFX7 code which this commit follows.
--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +21 -7
@@ -1881,11 +1881,13 @@ static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)return r; } -static void gfx_v6_0_ring_emit_vgt_flush (struct amdgpu_ring *ring) +static void gfx_v6_0_ring_emit_event_write (struct amdgpu_ring *ring, +uint32_t event_type, +uint32_t event_index) {amdgpu_ring_write (ring,PACKET3 (PACKET3_EVENT_WRITE ,0 )); -amdgpu_ring_write (ring,EVENT_TYPE (VGT_FLUSH ) | -EVENT_INDEX (0 )); +amdgpu_ring_write (ring,EVENT_TYPE (event_type) | +EVENT_INDEX (event_index)); } static void gfx_v6_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr,
@@ -2998,10 +3000,22 @@ static uint64_t gfx_v6_0_get_gpu_clock_counter(struct amdgpu_device *adev)static void gfx_v6_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) { -if (flags &AMDGPU_HAVE_CTX_SWITCH ) -gfx_v6_0_ring_emit_vgt_flush (ring); +u32 dw2 =0x80000000 ;/* set load_enable otherwise this package is just NOPs */ + +if (flags &AMDGPU_HAVE_CTX_SWITCH ) { +gfx_v6_0_ring_emit_event_write (ring,VS_PARTIAL_FLUSH ,4 ); +gfx_v6_0_ring_emit_event_write (ring,VGT_FLUSH ,0 ); + +/* set load_global_config (load_global_uconfig doesn't exist on GFX6) */ + dw2 |=0x1 ; +/* set load_cs_sh_regs */ + dw2 |=0x01000000 ; +/* set load_per_context_state & load_gfx_sh_regs */ + dw2 |=0x10002 ; + } +amdgpu_ring_write (ring,PACKET3 (PACKET3_CONTEXT_CONTROL ,1 )); -amdgpu_ring_write (ring,0x80000000 ); +amdgpu_ring_write (ring, dw2);amdgpu_ring_write (ring,0 ); }
@@ -3529,7 +3543,7 @@ static const struct amdgpu_ring_funcs gfx_v6_0_ring_funcs_gfx = {14 +14 +14 +/* gfx_v6_0_ring_emit_fence x3 for user fence, vm fence */ 7 +4 +/* gfx_v6_0_ring_emit_pipeline_sync */ SI_FLUSH_GPU_TLB_NUM_WREG *5 +7 +6 +/* gfx_v6_0_ring_emit_vm_flush */ -3 +2 +/* gfx_v6_ring_emit_cntxcntl including vgt flush */ +3 +2 +2 +/* gfx_v6_ring_emit_cntxcntl including VGT flush */ 5, /* SURFACE_SYNC */ .emit_ib_size = 6, /* gfx_v6_0_ring_emit_ib */ .emit_ib = gfx_v6_0_ring_emit_ib,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 941/1518 ext4: fix spurious message about orphan cleanup on RO fs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
[ Upstream commit 5aa98f874c013bcce9bb84ffded2f0ef886e4e33 ]
When orphan_file feature is enabled, ext4_orphan_cleanup() was always walking through the orphan file looking for orphan inodes. This is mostly harmless but for read-only filesystem it results in spurious "orphan cleanup on readonly fs" message and in other cornercases it could result in similar somewhat misleading messages. Skip orphan cleanup if the orphan file is empty to avoid confusing messages.
--- fs/ext4/orphan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/orphan.c +1 -1
@@ -388,7 +388,7 @@ void ext4_orphan_cleanup(struct super_block *sb, struct ext4_super_block *es)struct ext4_orphan_info *oi = &EXT4_SB (sb)->s_orphan_info;int inodes_per_ob =ext4_inodes_per_orphan_block (sb); -if (!es->s_last_orphan && !oi->of_blocks) { +if (!es->s_last_orphan &&ext4_orphan_file_empty (sb)) {ext4_debug ("no orphan inodes to clean up\n" );return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 942/1518 arm64: dts: ti: k3-am64: Fix MDIO clock reference for ICSSG0 node
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Meghana Malladi <[email protected]>
[ Upstream commit 197df050a10fe216971b45a79f07195c86a02236 ]
MDIO clock index changed from 62:3 to 81:0 to match proper clock definition in the SoC device tree. Clock Id 81:0 belongs to ICSSG0 core clock, where as 62 belongs to EQEP2 device.
See: https://software-dl.ti.com/tisci/esd/latest/5_soc_doc/am64x/clocks.html
--- arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am64-main.dtsi +1 -1
@@ -1401,7 +1401,7 @@ tx_pru0_1: txpru@c000 { icssg0_mdio: mdio@32400 { compatible = "ti,davinci_mdio"; reg = <0x32400 0x100>; - clocks = <&k3_clks 62 3>; + clocks = <&k3_clks 81 0>; clock-names = "fck"; #address-cells = <1>; #size-cells = <0>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 943/1518 phy: renesas: rcar-gen3-usb2: Factor out VBUS control logic
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tommaso Merciai <[email protected]>
[ Upstream commit d6db3b3af74a26b65d1ec1e86f9738c784e7ae29 ]
Refactor the VBUS control logic into a new helper function to improve code clarity and reduce duplication. This makes it easier to handle different VBUS control register cases and aids future maintenance.
Stable-dep-of: 49c9b71b4508 ("phy: renesas: phy-rcar-gen3-usb2: Fix devm action registration for disabled VBUS regulator")
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 34 +++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +22 -12
@@ -203,28 +203,38 @@ static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm)writel (val, usb2_base +USB2_LINECTRL1 ); } -static void rcar_gen3_enable_vbus_ctrl (struct rcar_gen3_chan *ch,int vbus) +static void rcar_gen3_phy_usb2_set_vbus (struct rcar_gen3_chan *ch, +u32 vbus_ctrl_reg, +u32 vbus_ctrl_val, +bool enable) {void __iomem *usb2_base = ch->base; -u32 vbus_ctrl_reg =USB2_ADPCTRL ; -u32 vbus_ctrl_val =USB2_ADPCTRL_DRVVBUS ;u32 val; + val =readl (usb2_base + vbus_ctrl_reg); +if (enable) + val |= vbus_ctrl_val; +else + val &= ~vbus_ctrl_val; +writel (val, usb2_base + vbus_ctrl_reg); + +dev_vdbg (ch->dev,"%s: reg=0x%08x, val=%08x, enable=%d\n" , + __func__, vbus_ctrl_reg, val, enable); +} + +static void rcar_gen3_enable_vbus_ctrl (struct rcar_gen3_chan *ch,int vbus) +{if (ch->phy_data->no_adp_ctrl || ch->phy_data->vblvl_ctrl) {if (ch->vbus)regulator_hardware_enable (ch->vbus, vbus); - vbus_ctrl_reg =USB2_VBCTRL ; - vbus_ctrl_val =USB2_VBCTRL_VBOUT ; +rcar_gen3_phy_usb2_set_vbus (ch,USB2_VBCTRL , +USB2_VBCTRL_VBOUT , vbus); +return ; } - val =readl (usb2_base + vbus_ctrl_reg); -if (vbus) - val |= vbus_ctrl_val; -else - val &= ~vbus_ctrl_val; -dev_vdbg (ch->dev,"%s: %08x, %d\n" , __func__, val, vbus); -writel (val, usb2_base + vbus_ctrl_reg); +rcar_gen3_phy_usb2_set_vbus (ch,USB2_ADPCTRL , +USB2_ADPCTRL_DRVVBUS , vbus); }static void rcar_gen3_control_otg_irq (struct rcar_gen3_chan *ch,int enable)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 944/1518 phy: renesas: rcar-gen3-usb2: Add regulator for OTG VBUS control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tommaso Merciai <[email protected]>
[ Upstream commit b6d7dd157763e0c8937f60241fb4af9eb546a7fb ]
Enable OTG VBUS control on R-Car Gen3 USB2 PHY by registering a regulator driver that manages the VBOUT line. This change allows the controller to handle VBUS output for OTG ports using the regulator framework when the platform requires hardware-based VBUS control.
Without this, some platforms cannot properly manage VBUS power on OTG- capable ports, leading to potential USB functionality issues.
Stable-dep-of: 49c9b71b4508 ("phy: renesas: phy-rcar-gen3-usb2: Fix devm action registration for disabled VBUS regulator")
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 142 ++++++++++++++++++++++- 1 file changed, 137 insertions(+), 5 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +137 -5
@@ -22,6 +22,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <linux/regulator/driver.h> #include <linux/reset.h> #include <linux/string.h> #include <linux/usb/of.h>
@@ -140,6 +141,7 @@ struct rcar_gen3_chan {bool extcon_host;bool is_otg_channel;bool uses_otg_pins; +bool otg_internal_reg; };struct rcar_gen3_phy_drv_data {
@@ -224,6 +226,11 @@ static void rcar_gen3_phy_usb2_set_vbus(struct rcar_gen3_chan *ch,static void rcar_gen3_enable_vbus_ctrl (struct rcar_gen3_chan *ch,int vbus) { +if (ch->otg_internal_reg) { +regulator_hardware_enable (ch->vbus, vbus); +return ; + } +if (ch->phy_data->no_adp_ctrl || ch->phy_data->vblvl_ctrl) {if (ch->vbus)regulator_hardware_enable (ch->vbus, vbus);
@@ -592,7 +599,7 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)u32 val;int ret =0 ; -if (channel->vbus) { +if (channel->vbus && !channel->otg_internal_reg) { ret =regulator_enable (channel->vbus);if (ret)return ret;
@@ -633,7 +640,7 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) } } -if (channel->vbus) +if (channel->vbus && !channel->otg_internal_reg) ret =regulator_disable (channel->vbus);return ret;
@@ -819,6 +826,128 @@ static int rcar_gen3_phy_usb2_init_bus(struct rcar_gen3_chan *channel)return ret; } +static int rcar_gen3_phy_usb2_regulator_endisable (struct regulator_dev *rdev, +bool enable) +{ +struct rcar_gen3_chan *channel =rdev_get_drvdata (rdev); +struct device *dev = channel->dev; +int ret; + + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) { +dev_warn (dev,"pm_runtime_get failed: %i\n" , ret); +return ret; + } + +rcar_gen3_phy_usb2_set_vbus (channel,USB2_VBCTRL , +USB2_VBCTRL_VBOUT , enable); +pm_runtime_put_noidle (dev); + +return ret; +} + +static int rcar_gen3_phy_usb2_regulator_enable (struct regulator_dev *rdev) +{ +return rcar_gen3_phy_usb2_regulator_endisable (rdev, true); +} + +static int rcar_gen3_phy_usb2_regulator_disable (struct regulator_dev *rdev) +{ +return rcar_gen3_phy_usb2_regulator_endisable (rdev, false); +} + +static int rcar_gen3_phy_usb2_regulator_is_enabled (struct regulator_dev *rdev) +{ +struct rcar_gen3_chan *channel =rdev_get_drvdata (rdev); +void __iomem *usb2_base = channel->base; +struct device *dev = channel->dev; +u32 vbus_ctrl_reg =USB2_VBCTRL ; +u32 val; +int ret; + + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) { +dev_warn (dev,"pm_runtime_get failed: %i\n" , ret); +return ret; + } + + val =readl (usb2_base + vbus_ctrl_reg); + +pm_runtime_put_noidle (dev); +dev_dbg (channel->dev,"%s: %08x\n" , __func__, val); + +return (val &USB2_VBCTRL_VBOUT ) ?1 :0 ; +} + +static const struct regulator_ops rcar_gen3_phy_usb2_regulator_ops = { + .enable = rcar_gen3_phy_usb2_regulator_enable, + .disable = rcar_gen3_phy_usb2_regulator_disable, + .is_enabled = rcar_gen3_phy_usb2_regulator_is_enabled, +}; + +static const struct regulator_desc rcar_gen3_phy_usb2_regulator = { + .name ="otg-vbus-regulator" , + .of_match =of_match_ptr ("vbus-regulator" ), + .ops = &rcar_gen3_phy_usb2_regulator_ops, + .type =REGULATOR_VOLTAGE , + .owner =THIS_MODULE , + .fixed_uV =5000000 , + .n_voltages =1 , +}; + +static void rcar_gen3_phy_usb2_vbus_disable_action (void *data) +{ +struct regulator *vbus = data; + +regulator_disable (vbus); +} + +static int rcar_gen3_phy_usb2_vbus_regulator_get_exclusive_enable (struct rcar_gen3_chan *channel, +bool enable) +{ +struct device *dev = channel->dev; +int ret; + + channel->vbus =devm_regulator_get_exclusive (dev,"vbus" ); +if (IS_ERR (channel->vbus)) +return PTR_ERR (channel->vbus); + +if (!enable) +return 0 ; + + ret =regulator_enable (channel->vbus); +if (ret) +return ret; + +return devm_add_action_or_reset (dev, rcar_gen3_phy_usb2_vbus_disable_action, + channel->vbus); +} + +static int rcar_gen3_phy_usb2_vbus_regulator_register (struct rcar_gen3_chan *channel) +{ +struct device *dev = channel->dev; +struct regulator_config rcfg = { .dev = dev, }; +struct regulator_dev *rdev; +bool enable = false; + + rcfg.of_node =of_get_available_child_by_name (dev->of_node, +"vbus-regulator" ); +if (rcfg.of_node) { + rcfg.driver_data = channel; + rdev =devm_regulator_register (dev, &rcar_gen3_phy_usb2_regulator, + &rcfg); +of_node_put (rcfg.of_node); +if (IS_ERR (rdev)) +return dev_err_probe (dev,PTR_ERR (rdev), +"Failed to create vbus-regulator\n" ); + + channel->otg_internal_reg = true; + enable = true; + } + +return rcar_gen3_phy_usb2_vbus_regulator_get_exclusive_enable (channel, enable); +} +static int rcar_gen3_phy_usb2_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -891,10 +1020,13 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)phy_set_drvdata (channel->rphys[i].phy, &channel->rphys[i]); } -if (channel->phy_data->no_adp_ctrl && channel->is_otg_channel) - channel->vbus =devm_regulator_get_exclusive (dev,"vbus" ); -else +if (channel->phy_data->no_adp_ctrl && channel->is_otg_channel) { + ret =rcar_gen3_phy_usb2_vbus_regulator_register (channel); +if (ret) +return ret; + }else { channel->vbus =devm_regulator_get_optional (dev,"vbus" ); + }if (IS_ERR (channel->vbus)) {if (PTR_ERR (channel->vbus) == -EPROBE_DEFER ) { ret =PTR_ERR (channel->vbus);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 945/1518 phy: renesas: phy-rcar-gen3-usb2: Fix devm action registration for disabled VBUS regulator
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Biju Das <[email protected]>
[ Upstream commit 49c9b71b45081e5e5eeb507a2d6edb80d332dc59 ]
devm_regulator_get_exclusive() initialises the regulator with enable_count = 1, requiring the consumer to disable it before release.
The devm disable action was previously only registered when the caller explicitly requested enable, so when the regulator was left in its initial enabled state without an explicit enable call, the cleanup path skipped decrementing enable_count, triggering a WARN_ON during regulator release on device removal.
Fix this by always registering the devm disable action based on the actual enabled state via regulator_is_enabled(), regardless of whether the caller requested an explicit enable. This covers both the explicitly enabled case and the initial state set by devm_regulator_get_exclusive().
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +9 -7
@@ -912,15 +912,17 @@ static int rcar_gen3_phy_usb2_vbus_regulator_get_exclusive_enable(struct rcar_geif (IS_ERR (channel->vbus))return PTR_ERR (channel->vbus); -if (!enable) -return 0 ; +if (enable) { + ret =regulator_enable (channel->vbus); +if (ret) +return ret; + } - ret =regulator_enable (channel->vbus); -if (ret) -return ret; +if (regulator_is_enabled (channel->vbus)) +return devm_add_action_or_reset (dev, rcar_gen3_phy_usb2_vbus_disable_action, + channel->vbus); -return devm_add_action_or_reset (dev, rcar_gen3_phy_usb2_vbus_disable_action, - channel->vbus); +return 0 ; }static int rcar_gen3_phy_usb2_vbus_regulator_register (struct rcar_gen3_chan *channel)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 946/1518 phy: sunplus: fix error handling in sp_uphy_init()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit 8b2683bc4cc18c581b7cd24f227cbe61abca7f4d ]
Fix the error paths of sp_uphy_init() to undo exactly what each stage
did: return directly if clk_prepare_enable() fails, release only the clock if reset_control_deassert() fails, and jump to err_reset if update_disc_vol() fails so the clock and reset are not leaked.
--- drivers/phy/sunplus/phy-sunplus-usb2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/phy/sunplus/phy-sunplus-usb2.c +3 -3
@@ -116,11 +116,11 @@ static int sp_uphy_init(struct phy *phy) ret =clk_prepare_enable (usbphy->phy_clk);if (ret) - goto err_clk; +return ret; ret =reset_control_deassert (usbphy->rstc);if (ret) - goto err_reset; + goto err_clk;/* Default value modification */ writel (HIGH_MASK_BITS |0x4002 , usbphy->moon4_regs +UPHY_CONTROL0 );
@@ -129,7 +129,7 @@ static int sp_uphy_init(struct phy *phy)/* disconnect voltage */ ret =update_disc_vol (usbphy);if (ret <0 ) -return ret; + goto err_reset;/* board uphy 0 internal register modification for tid certification */ val =readl (usbphy->phy_regs +CONFIG9 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 947/1518 phy: rockchip: phy-rockchip-inno-csidphy: fix rk1808 hsfreq table
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gerald Loacker <[email protected]>
[ Upstream commit 4fae43e33a7c10951fbdc6baf409d51bd66aaefb ]
The rk1808 hsfreq table capped at 2499 Mbps, preventing a data rate of exactly 2500 Mbps. Extend the final entry to 2500 Mbps to support this rate.
This is essential for RK3588 reusing this array and fully supporting rates up to 2500 Mbps.
--- drivers/phy/rockchip/phy-rockchip-inno-csidphy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/rockchip/phy-rockchip-inno-csidphy.c +1 -1
@@ -170,7 +170,7 @@ static const struct hsfreq_range rk1808_mipidphy_hsfreq_ranges[] = { { 299, 0x06}, { 399, 0x08}, { 499, 0x0b}, { 599, 0x0e}, { 699, 0x10}, { 799, 0x12}, { 999, 0x16}, {1199, 0x1e}, {1399, 0x23}, {1599, 0x2d}, {1799, 0x32}, {1999, 0x37}, - {2199, 0x3c}, {2399, 0x41}, {2499, 0x46} + {2199, 0x3c}, {2399, 0x41}, {2500, 0x46} }; static const struct hsfreq_range rk3326_mipidphy_hsfreq_ranges[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 948/1518 perf trace-event: Fix buffer overflow in read_string()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tanushree Shah <[email protected]>
[ Upstream commit 1121a7af1833f8b5723f1e32685b461614353d5d ]
read_string() writes into buf[BUFSIZ] one byte at a time without checking 'size' against the buffer bound before each write. A string longer than BUFSIZ in the input overflows the stack buffer.
Add a bounds check before each write to prevent overflow. On overflow the function returns NULL, matching its other error paths.
--- tools/perf/util/trace-event-read.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/util/trace-event-read.c +5 -0
@@ -127,6 +127,11 @@ static char *read_string(void) } } +if (size >= (int )sizeof (buf) -1 ) { +pr_debug ("string too long (max %zu bytes)" ,sizeof (buf) -1 ); + goto out; + } + buf[size++] = c;if (!c)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 949/1518 drm/amdgpu/gfx6: Fixup emitting SWITCH_BUFFER packets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 7aac4242a11991d530eee3e141d6e445d5f11c22 ]
Implement the emit_switch_buffer() function instead of emitting them duing emit_ib, emit_pipeline_sync and emit_vm_flush.
Note that it isn't necessary to emit these in both emit_pipeline_sync() and emit_vm_flush() because amdgpu_vm_flush() already calls these when calling either of those functions.
--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 38 ++++++++++----------------- 1 file changed, 14 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +14 -24
@@ -1926,12 +1926,6 @@ static void gfx_v6_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);u32 header, control =0 ; -/* insert SWITCH_BUFFER packet before first IB in the ring frame */ -if (flags &AMDGPU_HAVE_CTX_SWITCH ) { -amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 )); -amdgpu_ring_write (ring,0 ); - } -if (ib->flags &AMDGPU_IB_FLAG_CE ) header =PACKET3 (PACKET3_INDIRECT_BUFFER_CONST ,2 );else
@@ -2366,14 +2360,6 @@ static void gfx_v6_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring, seq);amdgpu_ring_write (ring,0xffffffff );amdgpu_ring_write (ring,4 );/* poll interval */ - -if (usepfp) { -/* synce CE with ME to prevent CE fetch CEIB before context switch done */ -amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 )); -amdgpu_ring_write (ring,0 ); -amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 )); -amdgpu_ring_write (ring,0 ); - } } static void gfx_v6_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
@@ -2397,12 +2383,6 @@ static void gfx_v6_0_ring_emit_vm_flush(struct amdgpu_ring *ring,/* sync PFP to ME, otherwise we might get invalid PFP reads */ amdgpu_ring_write (ring,PACKET3 (PACKET3_PFP_SYNC_ME ,0 ));amdgpu_ring_write (ring,0x0 ); - -/* synce CE with ME to prevent CE fetch CEIB before context switch done */ -amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 )); -amdgpu_ring_write (ring,0 ); -amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 )); -amdgpu_ring_write (ring,0 ); } }
@@ -2998,6 +2978,12 @@ static uint64_t gfx_v6_0_get_gpu_clock_counter(struct amdgpu_device *adev)return clock; } +static void gfx_v6_0_ring_emit_sb (struct amdgpu_ring *ring) +{ +amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 )); +amdgpu_ring_write (ring,0 ); +} +static void gfx_v6_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) {u32 dw2 =0x80000000 ;/* set load_enable otherwise this package is just NOPs */
@@ -3541,11 +3527,12 @@ static const struct amdgpu_ring_funcs gfx_v6_0_ring_funcs_gfx = { .emit_frame_size =5 +5 +/* hdp flush / invalidate */ 14 +14 +14 +/* gfx_v6_0_ring_emit_fence x3 for user fence, vm fence */ -7 +4 +/* gfx_v6_0_ring_emit_pipeline_sync */ -SI_FLUSH_GPU_TLB_NUM_WREG *5 +7 +6 +/* gfx_v6_0_ring_emit_vm_flush */ +7 +/* gfx_v6_0_ring_emit_pipeline_sync */ +SI_FLUSH_GPU_TLB_NUM_WREG *5 +7 +2 +/* gfx_v6_0_ring_emit_vm_flush */ +3 *2 +/* gfx_v6_0_ring_emit_sb x3 (from amdgpu_vm_flush, amdgpu_ib_schedule) */ 3 +2 +2 +/* gfx_v6_ring_emit_cntxcntl including VGT flush */ 5, /* SURFACE_SYNC */ - .emit_ib_size = 6, /* gfx_v6_0_ring_emit_ib */ + .emit_ib_size = 4, /* gfx_v6_0_ring_emit_ib */ .emit_ib = gfx_v6_0_ring_emit_ib, .emit_fence = gfx_v6_0_ring_emit_fence, .emit_pipeline_sync = gfx_v6_0_ring_emit_pipeline_sync,
@@ -3553,6 +3540,7 @@ static const struct amdgpu_ring_funcs gfx_v6_0_ring_funcs_gfx = { .test_ring = gfx_v6_0_ring_test_ring, .test_ib = gfx_v6_0_ring_test_ib, .insert_nop = amdgpu_ring_insert_nop, + .emit_switch_buffer = gfx_v6_0_ring_emit_sb, .emit_cntxcntl = gfx_v6_ring_emit_cntxcntl, .emit_wreg = gfx_v6_0_ring_emit_wreg, .emit_mem_sync = gfx_v6_0_emit_mem_sync,
@@ -3570,8 +3558,9 @@ static const struct amdgpu_ring_funcs gfx_v6_0_ring_funcs_compute = {7 +/* gfx_v6_0_ring_emit_pipeline_sync */ SI_FLUSH_GPU_TLB_NUM_WREG *5 +7 +/* gfx_v6_0_ring_emit_vm_flush */ 14 +14 +14 +/* gfx_v6_0_ring_emit_fence x3 for user fence, vm fence */ +3 *2 +/* gfx_v6_0_ring_emit_sb x3 (from amdgpu_vm_flush, amdgpu_ib_schedule) */ 5, /* SURFACE_SYNC */ - .emit_ib_size = 6, /* gfx_v6_0_ring_emit_ib */ + .emit_ib_size = 4, /* gfx_v6_0_ring_emit_ib */ .emit_ib = gfx_v6_0_ring_emit_ib, .emit_fence = gfx_v6_0_ring_emit_fence, .emit_pipeline_sync = gfx_v6_0_ring_emit_pipeline_sync,
@@ -3579,6 +3568,7 @@ static const struct amdgpu_ring_funcs gfx_v6_0_ring_funcs_compute = { .test_ring = gfx_v6_0_ring_test_ring, .test_ib = gfx_v6_0_ring_test_ib, .insert_nop = amdgpu_ring_insert_nop, + .emit_switch_buffer = gfx_v6_0_ring_emit_sb, .emit_wreg = gfx_v6_0_ring_emit_wreg, .emit_mem_sync = gfx_v6_0_emit_mem_sync, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 950/1518 drm/amdgpu/gfx6: Use PFP on the compute queues too
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 60f20946cd318518ddc2c0da12103c666b2b9564 ]
On GFX6, the compute rings use the same CP path as the graphics ring. The only difference is that they don't support draw commands. (As opposed to GFX7 and newer which have a separate command parser that is called MEC for compute queues.)
This means that we have to take into consideration that the PFP also exists on compute queues on GFX6:
Use PFP for register writes on both graphics and compute queues.
In the pipeline sync, use the PFP to wait for the previous fence (and not the ME) to prevent the PFP from starting to execute the next submission while the ME is still in the previous submission.
After a VM flush, emit PFP_SYNC_ME on compute queues as well.
--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +4 -4
@@ -2347,7 +2347,7 @@ static int gfx_v6_0_cp_resume(struct amdgpu_device *adev)static void gfx_v6_0_ring_emit_pipeline_sync (struct amdgpu_ring *ring) { -int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX ); +int usepfp =1 ;uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr;
@@ -2365,7 +2365,7 @@ static void gfx_v6_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)static void gfx_v6_0_ring_emit_vm_flush (struct amdgpu_ring *ring,unsigned vmid,uint64_t pd_addr) { -int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX ); +int usepfp =1 ;amdgpu_gmc_emit_flush_gpu_tlb (ring, vmid, pd_addr);
@@ -2389,7 +2389,7 @@ static void gfx_v6_0_ring_emit_vm_flush(struct amdgpu_ring *ring,static void gfx_v6_0_ring_emit_wreg (struct amdgpu_ring *ring,uint32_t reg,uint32_t val) { -int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX ); +int usepfp =1 ;amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
@@ -3556,7 +3556,7 @@ static const struct amdgpu_ring_funcs gfx_v6_0_ring_funcs_compute = { .emit_frame_size =5 +5 +/* hdp flush / invalidate */ 7 +/* gfx_v6_0_ring_emit_pipeline_sync */ -SI_FLUSH_GPU_TLB_NUM_WREG *5 +7 +/* gfx_v6_0_ring_emit_vm_flush */ +SI_FLUSH_GPU_TLB_NUM_WREG *5 +7 +2 +/* gfx_v6_0_ring_emit_vm_flush */ 14 +14 +14 +/* gfx_v6_0_ring_emit_fence x3 for user fence, vm fence */ 3 *2 +/* gfx_v6_0_ring_emit_sb x3 (from amdgpu_vm_flush, amdgpu_ib_schedule) */ 5, /* SURFACE_SYNC */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 951/1518 scsi: qla2xxx: Remove redundant VPD flash read in sysfs read path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manish Rangankar <[email protected]>
[ Upstream commit 5cbc49d5c4cd20c18041e86958103045216d2190 ]
qla2x00_sysfs_read_vpd() called ha->isp_ops->read_optrom() a second time after releasing optrom_mutex. The repeated read is redundant and, unlike the first, runs without optrom_mutex held, exposing flash access to concurrent optrom operations. Drop the duplicate call.
--- drivers/scsi/qla2xxx/qla_attr.c | 1 - 1 file changed, 1 deletion(-)
drivers/scsi/qla2xxx/qla_attr.c +0 -1
@@ -580,7 +580,6 @@ qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj, ha->isp_ops->read_optrom (vha, ha->vpd, faddr, ha->vpd_size);mutex_unlock (&ha->optrom_mutex); - ha->isp_ops->read_optrom (vha, ha->vpd, faddr, ha->vpd_size); skip:return memory_read_from_buffer (buf, count, &off, ha->vpd, ha->vpd_size); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 952/1518 firmware_loader: do not queue completed sysfs fallback requests
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit b48373c901951fad1a26bd7c33ad91172b3945b5 ]
fw_load_sysfs_fallback() calls device_add() before adding the fw_priv to pending_fw_head. device_add() publishes the fallback loading interface, so a userspace helper which discovers the device by scanning sysfs can write 0 to the loading attribute and complete the request before it is queued as pending.
In that interleaving firmware_loading_store() calls fw_state_done() while pending_list still points to itself, so it cannot remove an entry from pending_fw_head. The subsequent unconditional list_add() then queues an already-completed fw_priv. Once the request is released, pending_fw_head can retain a pointer to freed memory and the next fallback request can fault while validating the list.
Only in-flight fallback requests need suspend or reboot abort handling. If the request is already DONE after device_add(), return success from the fallback path without sending another uevent, waiting again, or queueing it as pending. This preserves the invariant that pending_fw_head contains only active fallback requests.
--- drivers/base/firmware_loader/fallback.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/base/firmware_loader/fallback.c +10 -0
@@ -95,6 +95,16 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout) retval = -EINTR ; goto out; } + +/* +* device_add() exposes the loading interface before pending_list is +* linked into pending_fw_head, so fw_state_done() may run first. +*/ +if (fw_state_is_done (fw_priv)) { +mutex_unlock (&fw_lock); + goto out; + } +list_add (&fw_priv->pending_list, &pending_fw_head);mutex_unlock (&fw_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 953/1518 pinctrl: rockchip: Reset the pin count when recalculating SoC data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Simon Glass <[email protected]>
[ Upstream commit 5b695c191cc85f0fd62eec885b55d01468dc9f2c ]
rockchip_pinctrl_get_soc_data() mutates the static per-SoC data. The iomux and drive offsets are recalculated idempotently, since a rerun anchors at the values calculated before, but the total pin count only
accumulates: each run adds every bank's pins again. When the probe is deferred and runs a second time, nr_pins doubles and every bank's pin_base shifts, so later pin lookups resolve to the wrong bank and the wrong registers.
Reset the pin count at the start of the calculation, so that a rerun produces the same values.
This is verified on a Luckfox Pico Mini B (RV1103, with the pending RV1106 series applied) by forcing the probe to defer once: without this patch the second probe calculates nr_pins=304 instead of 152 and no GPIO bank comes up; with it the recalculation matches the first run and all banks work.
--- drivers/pinctrl/pinctrl-rockchip.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/pinctrl/pinctrl-rockchip.c +10 -0
@@ -3675,6 +3675,16 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data( pmu_offs = ctrl->pmu_mux_offset; drv_pmu_offs = ctrl->pmu_drv_offset; drv_grf_offs = ctrl->grf_drv_offset; + +/* +* This function mutates the static per-SoC data. Most of it is +* idempotent: recalculated iomux and drv offsets anchor at the +* values calculated by a previous run. The pin count is not, so +* reset it here; otherwise it accumulates when the probe runs +* again after a probe deferral, shifting every bank's pin_base. +*/ + ctrl->nr_pins =0 ; + bank = ctrl->pin_banks;for (i =0 ; i < ctrl->nr_banks; ++i, ++bank) {int bank_pins =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 954/1518 hugetlbfs: release subpool on fill_super failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
[ Upstream commit 308ab73e97c87bd0e142b11758faab7f88d82854 ]
hugetlbfs_fill_super() allocates a hugepage subpool when size or min_size mount options are specified. hugepage_new_subpool() may also reserve huge pages for min_size.
If root dentry creation fails after the subpool is created, the failure path frees the subpool with kfree(). This bypasses hugepage_put_subpool() and can leave min_size reservations charged.
Use hugepage_put_subpool() on the failure path, matching the normal put_super path.
--- fs/hugetlbfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/hugetlbfs/inode.c +2 -1
@@ -1433,7 +1433,8 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc) goto out_free;return 0 ; out_free: -kfree (sbinfo->spool); +if (sbinfo->spool) +hugepage_put_subpool (sbinfo->spool);kfree (sbinfo);return -ENOMEM ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 955/1518 soc: fsl: qe: check platform_driver_register() in qe_ic_of_init()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit fbdba2a67fa7c0e7570bcbf9f28b782d6100270d ]
qe_ic_of_init() ignored the return value of platform_driver_register() and always returned success. Propagate the error to the initcall.
--- drivers/soc/fsl/qe/qe_ic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/soc/fsl/qe/qe_ic.c +1 -2
@@ -473,7 +473,6 @@ static struct platform_driver qe_ic_driver =static int __init qe_ic_of_init (void ) { -platform_driver_register (&qe_ic_driver); -return 0 ; +return platform_driver_register (&qe_ic_driver); }subsys_initcall (qe_ic_of_init);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 956/1518 phy: qcom-sgmii-eth: relax order of .power_on() vs .set_mode*()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Russell King (Oracle) <[email protected]>
[ Upstream commit ebe8b48b88ad012cf6067226e184e9173b7ea9d6 ]
Allow any order of the .power_on() and .set_mode*() methods as per the recent discussion. This means phy_power_on() with this SerDes will now restore the previous setup without requiring a subsequent phy_set_mode*() call.
Stable-dep-of: 4f81684a1d10 ("phy: qcom: sgmii-eth: vote for both voltage rails with correct current loads")
--- drivers/phy/qualcomm/phy-qcom-sgmii-eth.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/qualcomm/phy-qcom-sgmii-eth.c +13 -1
@@ -267,8 +267,17 @@ static int qcom_dwmac_sgmii_phy_calibrate(struct phy *phy)static int qcom_dwmac_sgmii_phy_power_on (struct phy *phy) {struct qcom_dwmac_sgmii_phy_data *data =phy_get_drvdata (phy); +int ret; -return clk_prepare_enable (data->refclk); + ret =clk_prepare_enable (data->refclk); +if (ret <0 ) +return ret; + + ret =qcom_dwmac_sgmii_phy_calibrate (phy); +if (ret <0 ) +clk_disable_unprepare (data->refclk); + +return ret; }static int qcom_dwmac_sgmii_phy_power_off (struct phy *phy)
@@ -293,6 +302,9 @@ static int qcom_dwmac_sgmii_phy_set_speed(struct phy *phy, int speed)if (speed != data->speed) data->speed = speed; +if (phy->power_count ==0 ) +return 0 ; +return qcom_dwmac_sgmii_phy_calibrate (phy); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 957/1518 phy: qcom: sgmii-eth: vote for both voltage rails with correct current loads
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohd Ayaan Anwar <[email protected]>
[ Upstream commit 4f81684a1d1018d7d0e5579f08d95e7701279358 ]
The SerDes PHY has two voltage supply rails, vdda-0p9 and vdda-1p2, that must both be enabled for calibration to succeed. Without them:
qcom-dwmac-sgmii-phy 8909000.phy: QSERDES_COM_C_READY_STATUS timed-out qcom-ethqos 23040000.ethernet eth0: __stmmac_open: Serdes powerup failed
The driver relied solely on the PHY framework's implicit enable of 'phy-supply', which only voted for a single rail and set no current load. Use devm_regulator_bulk_get_const() to acquire both supplies and set the peak current loads (46 mA for vdda-0p9, 15 mA for vdda-1p2) as required by the hardware.
--- drivers/phy/qualcomm/phy-qcom-sgmii-eth.c | 37 ++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-sgmii-eth.c +33 -4
@@ -10,6 +10,7 @@#include <linux/phy/phy.h> #include <linux/platform_device.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include "phy-qcom-qmp-pcs-sgmii.h" #include "phy-qcom-qmp-qserdes-com-v5.h"
@@ -25,7 +26,15 @@#define QSERDES_PCS_SGMIIPHY_READY BIT(7)#define QSERDES_COM_C_PLL_LOCKED BIT(1) +static const struct regulator_bulk_data qcom_dwmac_sgmii_phy_vregs[] = { + { .supply ="vdda-0p9" , .init_load_uA =46000 }, + { .supply ="vdda-1p2" , .init_load_uA =15000 }, +}; + +#define QCOM_SGMII_NUM_SUPPLIES ARRAY_SIZE(qcom_dwmac_sgmii_phy_vregs) +struct qcom_dwmac_sgmii_phy_data { +struct regulator_bulk_data *vregs;struct regmap *regmap;struct clk *refclk;int speed;
@@ -269,13 +278,24 @@ static int qcom_dwmac_sgmii_phy_power_on(struct phy *phy)struct qcom_dwmac_sgmii_phy_data *data =phy_get_drvdata (phy);int ret; - ret =clk_prepare_enable (data->refclk); -if (ret <0 ) + ret =regulator_bulk_enable (QCOM_SGMII_NUM_SUPPLIES , data->vregs); +if (ret)return ret; + ret =clk_prepare_enable (data->refclk); +if (ret) + goto err_disable_regulators; + ret =qcom_dwmac_sgmii_phy_calibrate (phy); -if (ret <0 ) -clk_disable_unprepare (data->refclk); +if (ret) + goto err_disable_clk; + +return 0 ; + +err_disable_clk: +clk_disable_unprepare (data->refclk); +err_disable_regulators: +regulator_bulk_disable (QCOM_SGMII_NUM_SUPPLIES , data->vregs);return ret; }
@@ -292,6 +312,8 @@ static int qcom_dwmac_sgmii_phy_power_off(struct phy *phy)clk_disable_unprepare (data->refclk); +regulator_bulk_disable (QCOM_SGMII_NUM_SUPPLIES , data->vregs); +return 0 ; }
@@ -331,6 +353,7 @@ static int qcom_dwmac_sgmii_phy_probe(struct platform_device *pdev)struct phy_provider *provider;void __iomem *base;struct phy *phy; +int ret; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL );if (!data)
@@ -355,6 +378,12 @@ static int qcom_dwmac_sgmii_phy_probe(struct platform_device *pdev)if (IS_ERR (data->refclk))return PTR_ERR (data->refclk); + ret =devm_regulator_bulk_get_const (dev,QCOM_SGMII_NUM_SUPPLIES , + qcom_dwmac_sgmii_phy_vregs, + &data->vregs); +if (ret) +return ret; + provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate);if (IS_ERR (provider))return PTR_ERR (provider);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 958/1518 phy: qcom: qmp-usb-legacy: Fix possible NULL-deref on early runtime suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Loic Poulain <[email protected]>
[ Upstream commit 8e3687f7e18fe84372e86875709d56c37e7525a8 ]
There is a small window where the runtime suspend callback may run after pm_runtime_enable() and before pm_runtime_forbid(). In this case, a crash occurs because runtime suspend/resume dereferences qmp->phy pointer, which is not yet initialized:
`if (!qmp->phy->init_count) {`This can also happen if user re-enables runtime-pm via the sysfs attribute before qmp phy is initialized.
Similarly to other qcom phy drivers, introduce a qmp->phy_initialized variable that can be used to avoid relying on the possibly uninitialized phy pointer.
--- drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c +10 -2
@@ -542,6 +542,8 @@ struct qmp_usb {enum phy_mode mode; +bool phy_initialized; +struct phy *phy;struct clk_fixed_rate pipe_clk_fixed;
@@ -895,6 +897,7 @@ static int qmp_usb_legacy_power_off(struct phy *phy)static int qmp_usb_legacy_enable (struct phy *phy) { +struct qmp_usb *qmp =phy_get_drvdata (phy);int ret; ret =qmp_usb_legacy_init (phy);
@@ -904,14 +907,19 @@ static int qmp_usb_legacy_enable(struct phy *phy) ret =qmp_usb_legacy_power_on (phy);if (ret)qmp_usb_legacy_exit (phy); +else + qmp->phy_initialized = true;return ret; }static int qmp_usb_legacy_disable (struct phy *phy) { +struct qmp_usb *qmp =phy_get_drvdata (phy);int ret; + qmp->phy_initialized = false; + ret =qmp_usb_legacy_power_off (phy);if (ret)return ret;
@@ -988,7 +996,7 @@ static int __maybe_unused qmp_usb_legacy_runtime_suspend(struct device *dev)dev_vdbg (dev,"Suspending QMP phy, mode:%d\n" , qmp->mode); -if (!qmp->phy->init_count) { +if (!qmp->phy_initialized) {dev_vdbg (dev,"PHY not initialized, bailing out\n" );return 0 ; }
@@ -1009,7 +1017,7 @@ static int __maybe_unused qmp_usb_legacy_runtime_resume(struct device *dev)dev_vdbg (dev,"Resuming QMP phy, mode:%d\n" , qmp->mode); -if (!qmp->phy->init_count) { +if (!qmp->phy_initialized) {dev_vdbg (dev,"PHY not initialized, bailing out\n" );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 959/1518 phy: qcom: snps-femto-v2: Fix possible NULL-deref on early runtime suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Loic Poulain <[email protected]>
[ Upstream commit c271a6926ea7d3c9566b033d63fd4e8c488dc860 ]
Runtime PM must be enabled before creating the PHY, since phy_create() only enables runtime PM on the PHY device if it is already enabled on this parent device. However, the runtime PM callbacks dereference the hsphy instance, which is not yet ready, leaving a window where a suspend callback may trigger a NULL pointer dereference.
Take a runtime PM usage reference with pm_runtime_get_noresume() before enabling runtime PM and release it once the PHY has been created, so that no runtime suspend can run before the PHY is ready. This also prevents a short window where an unnecessary runtime suspend can occur.
Use the devres-managed version to ensure PM runtime is symmetrically disabled during driver removal for proper cleanup.
--- drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +20 -6
@@ -599,8 +599,18 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)return dev_err_probe (dev, ret,"failed to get regulator supplies\n" ); +/* +* Enable runtime PM before creating the PHY, phy_create() only enables +* it on the PHY device if already enabled on the parent. Hold a usage +* reference so callbacks cannot run before the PHY is ready. +*/ +pm_runtime_get_noresume (dev);pm_runtime_set_active (dev); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) { +pm_runtime_put_noidle (dev); +return ret; + }/* * Prevent runtime pm from being ON by default. Users can enable * it using power/control in sysfs.
@@ -611,6 +621,7 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)if (IS_ERR (generic_phy)) { ret =PTR_ERR (generic_phy);dev_err (dev,"failed to create phy, %d\n" , ret); +pm_runtime_put_noidle (dev);return ret; } hsphy->phy = generic_phy;
@@ -620,12 +631,15 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)qcom_snps_hsphy_read_override_param_seq (dev); phy_provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); -if (!IS_ERR (phy_provider)) -dev_dbg (dev,"Registered Qcom-SNPS HS phy\n" ); -else -pm_runtime_disable (dev); +if (IS_ERR (phy_provider)) { +pm_runtime_put_noidle (dev); +return PTR_ERR (phy_provider); + } -return PTR_ERR_OR_ZERO (phy_provider); +dev_dbg (dev,"Registered Qcom-SNPS HS phy\n" ); +pm_runtime_put (dev); + +return 0 ; }static struct platform_driver qcom_snps_hsphy_driver = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 960/1518 phy: qcom: qmp-usb: Fix possible NULL-deref on early runtime suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Loic Poulain <[email protected]>
[ Upstream commit 142c5593379273264474f31d5956b1a0065cd576 ]
There is a small window where the runtime suspend callback may run after pm_runtime_enable() and before pm_runtime_forbid(). In this case, a crash occurs because runtime suspend/resume dereferences qmp->phy pointer, which is not yet initialized:
`if (!qmp->phy->init_count) {`This can also happen if user re-enables runtime-pm via the sysfs attribute before qmp phy is initialized.
Similarly to other qcom phy drivers, introduce a qmp->phy_initialized variable that can be used to avoid relying on the possibly uninitialized phy pointer.
--- drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +10 -2
@@ -1300,6 +1300,8 @@ struct qmp_usb {enum phy_mode mode; +bool phy_initialized; +struct phy *phy;struct clk_fixed_rate pipe_clk_fixed;
@@ -1848,6 +1850,7 @@ static int qmp_usb_power_off(struct phy *phy)static int qmp_usb_enable (struct phy *phy) { +struct qmp_usb *qmp =phy_get_drvdata (phy);int ret; ret =qmp_usb_init (phy);
@@ -1857,14 +1860,19 @@ static int qmp_usb_enable(struct phy *phy) ret =qmp_usb_power_on (phy);if (ret)qmp_usb_exit (phy); +else + qmp->phy_initialized = true;return ret; }static int qmp_usb_disable (struct phy *phy) { +struct qmp_usb *qmp =phy_get_drvdata (phy);int ret; + qmp->phy_initialized = false; + ret =qmp_usb_power_off (phy);if (ret)return ret;
@@ -1940,7 +1948,7 @@ static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)dev_vdbg (dev,"Suspending QMP phy, mode:%d\n" , qmp->mode); -if (!qmp->phy->init_count) { +if (!qmp->phy_initialized) {dev_vdbg (dev,"PHY not initialized, bailing out\n" );return 0 ; }
@@ -1960,7 +1968,7 @@ static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)dev_vdbg (dev,"Resuming QMP phy, mode:%d\n" , qmp->mode); -if (!qmp->phy->init_count) { +if (!qmp->phy_initialized) {dev_vdbg (dev,"PHY not initialized, bailing out\n" );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 961/1518 phy: qcom: qmp-pcie: Add pcs_lane1 offset to V5 offsets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esteban Urrutia <[email protected]>
[ Upstream commit f8b4493d5e7e19682abcf538a9faad012b5ef69e ]
Some SoCs such as SM8475 write data to registers using this offset, specifically SW_CTRL2 and MX_CTRL2.
Add pcs_lane1 offset to V5 offsets to support this.
--- drivers/phy/qualcomm/phy-qcom-qmp-pcie.c | 1 + 1 file changed, 1 insertion(+)
drivers/phy/qualcomm/phy-qcom-qmp-pcie.c +1 -0
@@ -3288,6 +3288,7 @@ static const struct qmp_pcie_offsets qmp_pcie_offsets_v5 = { .pcs_misc = 0x0600, .tx = 0x0e00, .rx = 0x1000, + .pcs_lane1 = 0x1400, .tx2 = 0x1600, .rx2 = 0x1800, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 962/1518 md/raid5: round bitmap stripes with sector division
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Kuai <[email protected]>
[ Upstream commit 17ea021ae74987d6064c8195c4922fa025753892 ]
raid5_bitmap_sector_map() aligns the array range to full RAID5 stripe widths before converting it to component sectors. That width is chunk_sectors multiplied by the number of data disks, and it is not always a power of two.
Reproduce with a 4-disk RAID5, 1024-sector chunks, and three data disks. The full-stripe width is 3072 sectors. For a one-sector write at array sector 3072, correct rounding gives array range [3072, 6144), which maps to component range [1024, 2048). The old round_down()/round_up() logic instead gives [1024, 4096), which maps to [0, 1024).
Use sector_div() based arithmetic so the rounded range is aligned to the actual RAID5 stripe width.
The deterministic mapper test now reports the fixed component range as [1024, 2048), while the old mask-based range was [0, 1024).
--- drivers/md/raid5.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/md/raid5.c +9 -4
@@ -5922,8 +5922,11 @@ static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset, sectors_per_chunk = conf->chunk_sectors * (conf->raid_disks - conf->max_degraded); - start =round_down (start, sectors_per_chunk); - end =round_up (end, sectors_per_chunk); +sector_div (start, sectors_per_chunk); + start *= sectors_per_chunk; +if (sector_div (end, sectors_per_chunk)) + end++; + end *= sectors_per_chunk; start =raid5_compute_sector (conf, start,0 , &dd_idx,NULL ); end =raid5_compute_sector (conf, end,0 , &dd_idx,NULL );
@@ -5941,8 +5944,10 @@ static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset, sectors_per_chunk = conf->prev_chunk_sectors * (conf->previous_raid_disks - conf->max_degraded); - prev_start =round_down (prev_start, sectors_per_chunk); - prev_end =round_down (prev_end, sectors_per_chunk); +sector_div (prev_start, sectors_per_chunk); + prev_start *= sectors_per_chunk; +sector_div (prev_end, sectors_per_chunk); + prev_end *= sectors_per_chunk; prev_start =raid5_compute_sector (conf, prev_start,1 , &dd_idx,NULL ); prev_end =raid5_compute_sector (conf, prev_end,1 , &dd_idx,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 963/1518 md: wait for behind writes before destroying bitmap
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Kuai <[email protected]>
[ Upstream commit 2a79365b2278f16e163e4024086105693b421601 ]
__md_stop() destroyed the bitmap before calling mddev_detach(). That made mddev_detach() skip bitmap_ops->wait_behind_writes(), because the bitmap was already disconnected from mddev.
This was still safe for the legacy bitmap because bitmap_destroy() waits for behind writes itself. llbitmap keeps that wait in its ->wait_behind_writes() operation instead, while ->destroy() tears down the llbitmap storage. With the old ordering, RAID1 behind-write completions could still run after llbitmap storage had been freed.
Call mddev_detach() before md_bitmap_destroy() so the common detach path can wait for behind writes while the bitmap is still alive. Only destroy the bitmap after those users are gone.
--- drivers/md/md.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md.c +1 -1
@@ -6957,8 +6957,8 @@ static void __md_stop(struct mddev *mddev) {struct md_personality *pers = mddev->pers; -md_bitmap_destroy (mddev);mddev_detach (mddev); +md_bitmap_destroy (mddev);spin_lock (&mddev->lock); mddev->pers =NULL ;spin_unlock (&mddev->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 964/1518 md: avoid stale clone I/O accounting timestamps
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Kuai <[email protected]>
[ Upstream commit 45102fc8330525d35675b1c193242bba101df5ee ]
md_clone_bio() always allocates the clone from mddev->io_clone_set, even when queue I/O stats are disabled. In that case it does not call bio_start_io_acct(), but it also left md_io_clone->start_time untouched.
The clone private data comes from a mempool and can contain data from a previous user. md_end_clone_io() checks start_time to decide whether it needs to call bio_end_io_acct(), so a stale non-zero value can make the completion path end accounting that was never started for this bio.
Set start_time to 0 in the no-stats branch. This keeps the end path tied to whether bio_start_io_acct() actually ran.
--- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/md.c +2 -0
@@ -9313,6 +9313,8 @@ static void md_clone_bio(struct mddev *mddev, struct bio **bio) md_io_clone->mddev = mddev;if (blk_queue_io_stat (bdev->bd_disk->queue)) md_io_clone->start_time =bio_start_io_acct (*bio); +else + md_io_clone->start_time =0 ;if (bio_data_dir (*bio) ==WRITE &&md_bitmap_enabled (mddev, false)) { md_io_clone->offset = (*bio)->bi_iter.bi_sector;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 965/1518 md/md-llbitmap: prevent create failure bitmap UAF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Kuai <[email protected]>
[ Upstream commit 2116c2f0a0e547615886900e2ed8c529c016499b ]
llbitmap_create() publishes mddev->bitmap before reading the bitmap superblock. This is needed because llbitmap_read_sb() can initialize a new bitmap and flush it through helpers that use mddev->bitmap.
If llbitmap_read_sb() fails, the old cleanup dropped bitmap_info.mutex and freed llbitmap before clearing mddev->bitmap. Readers such as /proc/mdstat rely on bitmap_info.mutex to keep the bitmap pointer stable while collecting bitmap stats, so they could observe the stale pointer after the failed create path released the mutex.
Clear mddev->bitmap while still holding bitmap_info.mutex, then free the failed llbitmap after dropping the mutex. This makes mutex-protected readers see either a live bitmap or no bitmap.
--- drivers/md/md-llbitmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md-llbitmap.c +2 -1
@@ -999,10 +999,11 @@ static int llbitmap_create(struct mddev *mddev)mutex_lock (&mddev->bitmap_info.mutex); mddev->bitmap = llbitmap; ret =llbitmap_read_sb (llbitmap); +if (ret) + mddev->bitmap =NULL ;mutex_unlock (&mddev->bitmap_info.mutex);if (ret) {kfree (llbitmap); - mddev->bitmap =NULL ; }return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 966/1518 md/md-llbitmap: stop daemon timer rearm on destroy
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Kuai <[email protected]>
[ Upstream commit 5553d64e01d9a995be6c3de38501c6dd4ceede3b ]
llbitmap_destroy() deletes pending_timer before flushing md_llbitmap_io_wq. However, daemon_work can still be queued or running after the timer has been deleted, and the daemon path can arm pending_timer again when it finds dirty chunks that are not ready to flush yet.
If that happens during teardown, pending_timer can remain armed after llbitmap is freed and later dereference freed memory.
Add a BITMAP_SHUTDOWN bit to llbitmap->flags, set it before deleting the timer, and make the timer and daemon paths stop queueing or rearming work once teardown starts. Cancel daemon_work before flushing the shared workqueue so no already queued daemon instance can race with the free. Use timer_shutdown_sync() so a daemon instance that passed the shutdown check before teardown cannot rearm the timer afterward.
BITMAP_SHUTDOWN is a runtime-only state. Mask it out when reading and updating the llbitmap superblock so the shutdown state is never loaded from disk or persisted to disk.
--- drivers/md/md-bitmap.h | 1 + drivers/md/md-llbitmap.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
drivers/md/md-bitmap.h +1 -0
@@ -29,6 +29,7 @@ enum bitmap_state {BITMAP_FIRST_USE =3 ,/* llbitmap is just created */ BITMAP_CLEAN =4 ,/* llbitmap is created with assume_clean */ BITMAP_DAEMON_BUSY =5 ,/* llbitmap daemon is not finished after daemon_sleep */ +BITMAP_SHUTDOWN =6 ,/* llbitmap is being destroyed */ BITMAP_HOSTENDIAN =15, };
drivers/md/md-llbitmap.c +13 -4
@@ -662,6 +662,7 @@ static enum llbitmap_state llbitmap_state_machine(struct llbitmap *llbitmap,if (state == BitNeedSync) need_resync = !mddev->degraded;else if (state == BitDirty && + !test_bit (BITMAP_SHUTDOWN , &llbitmap->flags) && !timer_pending (&llbitmap->pending_timer))mod_timer (&llbitmap->pending_timer, jiffies + mddev->bitmap_info.daemon_sleep *HZ );
@@ -854,7 +855,7 @@ static int llbitmap_read_sb(struct llbitmap *llbitmap)else mddev->bitmap_info.space = mddev->bitmap_info.default_space; } - llbitmap->flags =le32_to_cpu (sb->state); + llbitmap->flags =le32_to_cpu (sb->state) & ~BIT (BITMAP_SHUTDOWN );if (test_and_clear_bit (BITMAP_FIRST_USE , &llbitmap->flags)) { ret =llbitmap_init (llbitmap); goto out_put_page;
@@ -910,6 +911,9 @@ static void llbitmap_pending_timer_fn(struct timer_list *pending_timer)struct llbitmap *llbitmap = container_of(pending_timer, struct llbitmap, pending_timer); +if (test_bit (BITMAP_SHUTDOWN , &llbitmap->flags)) +return ; +if (work_busy (&llbitmap->daemon_work)) { pr_warn("md/llbitmap: %s daemon_work not finished in %lu seconds\n", mdname(llbitmap->mddev),
@@ -930,6 +934,9 @@ static void md_llbitmap_daemon_fn(struct work_struct *work)bool restart;int idx; +if (test_bit (BITMAP_SHUTDOWN , &llbitmap->flags)) +return ; +if (llbitmap->mddev->degraded)return ; retry:
@@ -969,7 +976,7 @@ static void md_llbitmap_daemon_fn(struct work_struct *work) goto retry;/* If some page is dirty but not expired, setup timer again */ -if (restart) +if (restart && !test_bit (BITMAP_SHUTDOWN , &llbitmap->flags))mod_timer (&llbitmap->pending_timer, jiffies + llbitmap->mddev->bitmap_info.daemon_sleep *HZ ); }
@@ -1052,7 +1059,9 @@ static void llbitmap_destroy(struct mddev *mddev)mutex_lock (&mddev->bitmap_info.mutex); -timer_delete_sync (&llbitmap->pending_timer); +set_bit (BITMAP_SHUTDOWN , &llbitmap->flags); +timer_shutdown_sync (&llbitmap->pending_timer); +cancel_work_sync (&llbitmap->daemon_work);flush_workqueue (md_llbitmap_io_wq);flush_workqueue (md_llbitmap_unplug_wq);
@@ -1376,7 +1385,7 @@ static void llbitmap_update_sb(void *data) sb =kmap_local_page (sb_page); sb->events =cpu_to_le64 (mddev->events); - sb->state =cpu_to_le32 (llbitmap->flags); + sb->state =cpu_to_le32 (llbitmap->flags & ~BIT (BITMAP_SHUTDOWN )); sb->chunksize =cpu_to_le32 (llbitmap->chunksize); sb->sync_size =cpu_to_le64 (mddev->resync_max_sectors); sb->events_cleared =cpu_to_le64 (llbitmap->events_cleared);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 967/1518 md/raid1: dont set array_frozen in raid1_takeover()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bruce Johnston <[email protected]>
[ Upstream commit dc386aa0ac0a3ec06c9a3ea9b064b073fb72a916 ]
raid1_takeover() sets conf->array_frozen = 1 on the newly-allocated r1conf and nothing ever clears it, so every I/O to the array stalls permanently once _wait_barrier() sees it stuck at 1.
This used to be harmless: level_store() called mddev_resume() right after pers->run(), which called raid1_quiesce(mddev, 0) and cleared array_frozen back to 0 regardless of what raid1_takeover() set. Commit b39f35ebe86d ("md: don't quiesce in mddev_suspend()") removed that quiesce(mddev, 0) call, so the pre-set now sticks.
setup_conf() already zero-initializes the new r1conf via kzalloc, so just don't set array_frozen here.
Same class of bug as commit 892da88d1cd9 ("md/raid10: fix a 'conf->barrier' leakage in raid10_takeover()"), also triggered by b39f35ebe86d.
--- drivers/md/raid1.c | 2 -- 1 file changed, 2 deletions(-)
drivers/md/raid1.c +0 -2
@@ -3480,8 +3480,6 @@ static void *raid1_takeover(struct mddev *mddev) mddev->new_chunk_sectors =0 ; conf =setup_conf (mddev);if (!IS_ERR (conf)) { -/* Array must appear to be quiesced */ - conf->array_frozen =1 ;mddev_clear_unsupported_flags (mddev,UNSUPPORTED_MDDEV_FLAGS ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 968/1518 coresight: etm4x: fix wrong check of etm4x_sspcicrn_present()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 0e1cd4270b42a257c139165622091e1e8c7104a7 ]
According to Embedded Trace Macrocell Architecture Specification ETMv4.0 to ETM4.6 [0], TRCSSPCICR<n> is present only if all of the following are true:
- TRCIDR4.NUMSSCC > n.
- TRCIDR4.NUMPC > 0b0000.
- TRCSSCSR<n>.PC == 0b1.
Comment for etm4x_sspcicrn_present() is align with the specification. However, the check should use drvdata->nr_pe_cmp to check TRCIDR4.NUMPC not nr_pe.
--- drivers/hwtracing/coresight/coresight-etm4x-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -1
@@ -92,7 +92,7 @@ static int etm4_probe_cpu(unsigned int cpu);static bool etm4x_sspcicrn_present (struct etmv4_drvdata *drvdata,int n) {return (n < drvdata->nr_ss_cmp) && - drvdata->nr_pe && + drvdata->nr_pe_cmp && (drvdata->config.ss_status[n] & TRCSSCSRn_PC); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 969/1518 coresight: Change syncfreq to be a u8
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 10d4dbdc8fbce586b17be07b8138e025381453dd ]
TRCSYNCPR.PERIOD is the only functional part of TRCSYNCPR and it only has 5 valid bits so it can be stored in a u8.
Stable-dep-of: 1674d9bff807 ("coresight: etm4x: fix underflow for usage of (nrseqstate - 1)")
--- drivers/hwtracing/coresight/coresight-etm4x.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-etm4x.h +1 -1
@@ -825,7 +825,6 @@ struct etmv4_config {u32 eventctrl1;u32 stall_ctrl;u32 ts_ctrl; -u32 syncfreq;u32 ccctlr;u32 bb_ctrl;u32 vinst_ctrl;
@@ -833,6 +832,7 @@ struct etmv4_config {u32 vissctlr;u32 vipcssctlr;u8 seq_idx; +u8 syncfreq;u32 seq_ctrl[ETM_MAX_SEQ_STATES ];u32 seq_rst;u32 seq_state;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 970/1518 coresight: etm4x: fix underflow for usage of (nrseqstate - 1)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 1674d9bff8073bdee5dbc200f56fc3caa28d0566 ]
According to IHI006H Embedded Trace Macrocell Architecture Specification[0], TRCSEQEVR<n> is implemented only when TRCIDR5.NUMSEQSTATE is 0b100, in which case n ranges from 0 to 2; otherwise, TRCIDR5.NUMSEQSTATE is 0b000.
IOW, the number of usage in the initialisation or setting TRCSEQEVR<n> with drvdata->nrseqstate - 1 in the loop could make underflow issue when TRCIDR5.NUMSEQSTATE is 0b000.
Therefore, introduce nr_seq_ctrls field and untie it from nrseqstate. As part of this introduce ETM_MAX_SEQ_TRANSITIONS macro and apply nr_seq_ctrls and above macro to TRCSEQEVR<n> relevant fields setup.
--- drivers/hwtracing/coresight/coresight-etm4x-cfg.c | 2 +- drivers/hwtracing/coresight/coresight-etm4x-core.c | 9 ++++++--- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 6 ++++-- drivers/hwtracing/coresight/coresight-etm4x.h | 7 +++++-- 4 files changed, 16 insertions(+), 8 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-cfg.c +1 -1
@@ -76,7 +76,7 @@ static int etm4_cfg_map_reg_offset(struct etmv4_drvdata *drvdata, }else if ((offset &GENMASK (11 ,4 )) ==TRCSEQEVRn (0 )) {/* sequencer state control registers */ idx = (offset &GENMASK (3 ,0 )) /4 ; -if (idx <ETM_MAX_SEQ_STATES ) { +if (idx <ETM_MAX_SEQ_TRANSITIONS ) { reg_csdev->driver_regval = &drvcfg->seq_ctrl[idx]; err =0 ; }
drivers/hwtracing/coresight/coresight-etm4x-core.c +6 -3
@@ -541,7 +541,8 @@ static int etm4_enable_hw(struct etmv4_drvdata *drvdata)etm4x_relaxed_write32 (csa, config->vissctlr,TRCVISSCTLR );if (drvdata->nr_pe_cmp)etm4x_relaxed_write32 (csa, config->vipcssctlr,TRCVIPCSSCTLR ); -for (i =0 ; i < drvdata->nrseqstate -1 ; i++) + +for (i =0 ; i < drvdata->nr_seq_ctrls; i++)etm4x_relaxed_write32 (csa, config->seq_ctrl[i],TRCSEQEVRn (i));if (drvdata->nrseqstate) {etm4x_relaxed_write32 (csa, config->seq_rst,TRCSEQRSTEVR );
@@ -1476,6 +1477,8 @@ static void etm4_init_arch_data(void *info) drvdata->lpoverride = (etmidr5 &TRCIDR5_LPOVERRIDE ) && (!drvdata->skip_power_up);/* NUMSEQSTATE, bits[27:25] number of sequencer states implemented */ drvdata->nrseqstate =FIELD_GET (TRCIDR5_NUMSEQSTATE_MASK , etmidr5); +if (drvdata->nrseqstate) + drvdata->nr_seq_ctrls =ETM_MAX_SEQ_TRANSITIONS ;/* NUMCNTR, bits[30:28] number of counters available for tracing */ drvdata->nr_cntr =FIELD_GET (TRCIDR5_NUMCNTR_MASK , etmidr5);
@@ -1889,7 +1892,7 @@ static int __etm4_cpu_save(struct etmv4_drvdata *drvdata)if (drvdata->nr_pe_cmp) state->trcvipcssctlr =etm4x_read32 (csa,TRCVIPCSSCTLR ); -for (i =0 ; i < drvdata->nrseqstate -1 ; i++) +for (i =0 ; i < drvdata->nr_seq_ctrls; i++) state->trcseqevr[i] =etm4x_read32 (csa,TRCSEQEVRn (i));if (drvdata->nrseqstate) {
@@ -2020,7 +2023,7 @@ static void __etm4_cpu_restore(struct etmv4_drvdata *drvdata)if (drvdata->nr_pe_cmp)etm4x_relaxed_write32 (csa, state->trcvipcssctlr,TRCVIPCSSCTLR ); -for (i =0 ; i < drvdata->nrseqstate -1 ; i++) +for (i =0 ; i < drvdata->nr_seq_ctrls; i++)etm4x_relaxed_write32 (csa, state->trcseqevr[i],TRCSEQEVRn (i));if (drvdata->nrseqstate) {
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +4 -2
@@ -223,7 +223,7 @@ static ssize_t reset_store(struct device *dev, config->vipcssctlr =0x0 ;/* Disable seq events */ -for (i =0 ; i < drvdata->nrseqstate-1 ; i++) +for (i =0 ; i < drvdata->nr_seq_ctrls; i++) config->seq_ctrl[i] =0x0 ; config->seq_rst =0x0 ; config->seq_state =0x0 ;
@@ -1395,9 +1395,11 @@ static ssize_t seq_idx_store(struct device *dev,struct etmv4_drvdata *drvdata =dev_get_drvdata (dev->parent);struct etmv4_config *config = &drvdata->config; +if (!drvdata->nr_seq_ctrls) +return -ENOTSUPP ;if (kstrtoul (buf,16 , &val))return -EINVAL ; -if (val >= drvdata->nrseqstate -1 ) +if (val >= drvdata->nr_seq_ctrls)return -EINVAL ;/*
drivers/hwtracing/coresight/coresight-etm4x.h +5 -2
@@ -570,6 +570,7 @@#define ETM_MAX_NR_PE 8#define ETMv4_MAX_CNTR 4#define ETM_MAX_SEQ_STATES 4 +#define ETM_MAX_SEQ_TRANSITIONS 3#define ETM_MAX_EXT_INP_SEL 4#define ETM_MAX_EXT_INP 256#define ETM_MAX_EXT_OUT 4
@@ -833,7 +834,7 @@ struct etmv4_config {u32 vipcssctlr;u8 seq_idx;u8 syncfreq; -u32 seq_ctrl[ETM_MAX_SEQ_STATES ]; +u32 seq_ctrl[ETM_MAX_SEQ_TRANSITIONS ];u32 seq_rst;u32 seq_state;u8 cntr_idx;
@@ -884,7 +885,7 @@ struct etmv4_save_state {u32 trcvissctlr;u32 trcvipcssctlr; -u32 trcseqevr[ETM_MAX_SEQ_STATES ]; +u32 trcseqevr[ETM_MAX_SEQ_TRANSITIONS ];u32 trcseqrstevr;u32 trcseqstr;u32 trcextinselr;
@@ -937,6 +938,7 @@ struct etmv4_save_state {* @numcidc: Number of contextID comparators. * @numvmidc: Number of VMID comparators. * @nrseqstate: The number of sequencer states that are implemented. +* @nr_seq_ctrls: The number of sequence state transition control registers. * @nr_event: Indicates how many events the trace unit support. * @nr_resource:The number of resource selection pairs available for tracing. * @nr_ss_cmp: Number of single-shot comparator controls that are available.
@@ -1002,6 +1004,7 @@ struct etmv4_drvdata {u8 numextinsel;u8 numvmidc;u8 nrseqstate; +u8 nr_seq_ctrls;u8 nr_event;u8 nr_resource;u8 nr_ss_cmp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 971/1518 coresight: etm4x: fix leaked trace id
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 467e5862ccb0eed907002f4c6d3badfe34360940 ]
If etm4_enable_sysfs() fails in cscfg_csdev_enable_active_config(), the trace ID may be leaked because it is not released.
To address this, call etm4_release_trace_id() when etm4_enable_sysfs() fails in cscfg_csdev_enable_active_config().
--- drivers/hwtracing/coresight/coresight-etm4x-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -1
@@ -880,8 +880,10 @@ static int etm4_enable_sysfs(struct coresight_device *csdev, struct coresight_pacscfg_config_sysfs_get_active_cfg (&cfg_hash, &preset);if (cfg_hash) { ret =cscfg_csdev_enable_active_config (csdev, cfg_hash, preset); -if (ret) +if (ret) { +etm4_release_trace_id (drvdata);return ret; + } }raw_spin_lock (&drvdata->spinlock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 972/1518 coresight: Refactor etm4_config_timestamp_event()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit b02450de6ba6309c66e2e056ccfbfce4bd3b0352 ]
Remove some of the magic numbers and try to clarify some of the documentation so it's clearer how this sets up the timestamp interval.
Return errors directly instead of jumping to out and returning ret, nothing needs to be cleaned up at the end and it only obscures the flow and return value.
Add utilities for programming resource selectors that do compile time checks for constants or WARN_ONs for non-constant values. FIELD_PREP includes compile time checks so we only need to add an additional BUILD_BUG_ON for resource == 0 in pair mode.
Stable-dep-of: 0a47f0be6557 ("coresight: etm4x: missing cscfg_csdev_disable_active_config() in perf enable")
--- .../coresight/coresight-etm4x-core.c | 96 ++++++++++++------- drivers/hwtracing/coresight/coresight-etm4x.h | 54 ++++++++++- 2 files changed, 112 insertions(+), 38 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +63 -33
@@ -641,18 +641,33 @@ static void etm4_enable_sysfs_smp_call(void *info)* TRCRSCTLR1 (always true) used to get the counter to decrement. From * there a resource selector is configured with the counter and the * timestamp control register to use the resource selector to trigger the -* event that will insert a timestamp packet in the stream. +* event that will insert a timestamp packet in the stream: +* +* +--------------+ +* | Resource 1 | fixed "always-true" resource +* +--------------+ +* | +* +------v-------+ +* | Counter x | (reload to 1 on underflow) +* +--------------+ +* | +* +------v--------------+ +* | Resource Selector y | (trigger on counter x == 0) +* +---------------------+ +* | +* +------v---------------+ +* | Timestamp Generator | (timestamp on resource y) +* +----------------------+ */ static int etm4_config_timestamp_event (struct etmv4_drvdata *drvdata) { -int ctridx, ret = -EINVAL ; -int counter, rselector; -u32 val =0 ; +int ctridx; +int rselector;struct etmv4_config *config = &drvdata->config;/* No point in trying if we don't have at least one counter */ if (!drvdata->nr_cntr) - goto out; +return -EINVAL ;/* Find a counter that hasn't been initialised */ for (ctridx =0 ; ctridx < drvdata->nr_cntr; ctridx++)
@@ -662,15 +677,19 @@ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata)/* All the counters have been configured already, bail out */ if (ctridx == drvdata->nr_cntr) {pr_debug ("%s: no available counter found\n" , __func__); - ret = -ENOSPC ; - goto out; +return -ENOSPC ; }/* -* Searching for an available resource selector to use, starting at -* '2' since every implementation has at least 2 resource selector. -* ETMIDR4 gives the number of resource selector _pairs_, -* hence multiply by 2. +* Searching for an available resource selector to use, starting at '2' +* since resource 0 is the fixed 'always returns false' resource and 1 +* is the fixed 'always returns true' resource. See IHI0064H_b '7.3.64 +* TRCRSCTLRn, Resource Selection Control Registers, n=2-31'. If there +* are no resources, there would also be no counters so wouldn't get +* here. +* +* ETMIDR4 gives the number of resource selector _pairs_, hence multiply +* by 2. */ for (rselector =2 ; rselector < drvdata->nr_resource *2 ; rselector++)if (!config->res_ctrl[rselector])
@@ -679,13 +698,9 @@ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata)if (rselector == drvdata->nr_resource *2 ) {pr_debug ("%s: no available resource selector found\n" , __func__); - ret = -ENOSPC ; - goto out; +return -ENOSPC ; } -/* Remember what counter we used */ - counter =1 << ctridx; -/* * Initialise original and reload counter value to the smallest * possible value in order to get as much precision as we can.
@@ -693,26 +708,41 @@ static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) config->cntr_val[ctridx] =1 ; config->cntrldvr[ctridx] =1 ; -/* Set the trace counter control register */ - val =0x1 <<16 |/* Bit 16, reload counter automatically */ -0x0 <<7 |/* Select single resource selector */ -0x1 ;/* Resource selector 1, i.e always true */ - - config->cntr_ctrl[ctridx] = val; - - val =0x2 <<16 |/* Group 0b0010 - Counter and sequencers */ - counter <<0 ;/* Counter to use */ - - config->res_ctrl[rselector] = val; +/* +* Trace Counter Control Register TRCCNTCTLRn +* +* CNTCHAIN = 0, don't reload on the previous counter +* RLDSELF = true, reload counter automatically on underflow +* RLDEVENT = RES_SEL_FALSE (0), reload on single false resource (never reload) +* CNTEVENT = RES_SEL_TRUE (1), count single fixed 'always true' resource (always decrement) +*/ + config->cntr_ctrl[ctridx] = TRCCNTCTLRn_RLDSELF | +FIELD_PREP (TRCCNTCTLRn_RLDEVENT_MASK, +etm4_res_sel_single (ETM4_RES_SEL_FALSE )) | +FIELD_PREP (TRCCNTCTLRn_CNTEVENT_MASK, +etm4_res_sel_single (ETM4_RES_SEL_TRUE )); - val =0x0 <<7 |/* Select single resource selector */ - rselector;/* Resource selector */ +/* +* Resource Selection Control Register TRCRSCTLRn +* +* PAIRINV = 0, INV = 0, don't invert +* GROUP = 2, SELECT = ctridx, trigger when counter 'ctridx' reaches 0 +* +* Multiple counters can be selected, and each bit signifies a counter, +* so set bit 'ctridx' to select our counter. +*/ + config->res_ctrl[rselector] =FIELD_PREP (TRCRSCTLRn_GROUP_MASK,2 ) | +FIELD_PREP (TRCRSCTLRn_SELECT_MASK,1 << ctridx); - config->ts_ctrl = val; +/* +* Global Timestamp Control Register TRCTSCTLR +* +* EVENT = generate timestamp on single resource 'rselector' +*/ + config->ts_ctrl =FIELD_PREP (TRCTSCTLR_EVENT_MASK , +etm4_res_sel_single (rselector)); - ret =0 ; -out: -return ret; +return 0 ; } static int etm4_parse_event_config(struct coresight_device *csdev,
drivers/hwtracing/coresight/coresight-etm4x.h +49 -5
73 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 973/1518 perf: arm_pmuv3: Zero initialize hw_id branch stack field
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 7c3b63386c27bed8d59a4b4c283d02860420eb0a ]
PERF_SAMPLE_BRANCH_HW_INDEX is supported by BRBE so hw_id is passed to userspace, but it's never set by the BRBE driver. Zero initialize it as it should be according to the docs:
* For the architectures whose raw branch records are
* already stored in age order, the hw_idx should be 0.
It's probably too risky to remove PERF_SAMPLE_BRANCH_HW_INDEX from BRBE now in case anyone is setting it and reading the value, but zero initializing the whole struct also protects against the same issue with new fields that are added in the future.
--- drivers/perf/arm_pmuv3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/arm_pmuv3.c +1 -1
@@ -1351,7 +1351,7 @@ static int branch_records_alloc(struct arm_pmu *armpmu)struct pmu_hw_events *events_cpu; events_cpu =per_cpu_ptr (armpmu->hw_events, cpu); - events_cpu->branch_stack =kmalloc (size,GFP_KERNEL ); + events_cpu->branch_stack =kzalloc (size,GFP_KERNEL );if (!events_cpu->branch_stack)return -ENOMEM ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 974/1518 bpf: Reject load-acquire from pointers requiring fault protection
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 7db0a00445f1a40bacfe9b747405c11cb5f10fc9 ]
A BPF_LOAD_ACQ is not rewritten to a BPF_PROBE_MEM load by the verifier, unlike a regular BPF_LDX, so the JIT emits a plain load with no exception table entry and a fault panics the kernel instead of being handled.
Reject the source pointer types that a BPF_LDX would have had that fault protection applied to, i.e. the ones bpf_convert_ctx_accesses() turns into BPF_PROBE_MEM: a bare PTR_TO_BTF_ID, PTR_TO_BTF_ID | PTR_UNTRUSTED, PTR_TO_BTF_ID | MEM_ALLOC | PTR_UNTRUSTED and PTR_TO_MEM | MEM_RDONLY | PTR_UNTRUSTED.
This is reachable e.g. by loading ->mm out of a trusted task_struct yields an untrusted pointer to mm_struct, and it is NULL for a kernel thread:
[...]
SEC("tp_btf/sched_switch")
int BPF_PROG(demo, bool preempt, struct task_struct *prev,
struct task_struct *next)
{
struct mm_struct *mm = next->mm; /* untrusted */
out_ldx = (__u64)mm->pgd; /* BPF_LDX */
out_acq = load_acquire(&mm->pgd); /* BPF_LOAD_ACQ */
return 0; }
[...]
Both dereference the same pointer, but only the BPF_LDX is protected (x86-64 JIT, jump targets shown prog-relative):
[...]
; out_ldx = (__u64)mm->pgd;
17: movq $-10485760, %r10 1e: movq %rsi, %r11 21: addq $184, %r11 28: subq %r10, %r11 2b: movabsq $140737498841088, %r10 35: cmpq %r10, %r11 38: ja 0x3e <-- kernel addr? 3a: xorl %edi, %edi <-- no: dst = 0, skip the load 3c: jmp 0x45 3e: movq 184(%rsi), %rdi <-- yes: load + extable entry
[...]
; load_acquire(&mm->pgd)
53: movq %rsi, %rdi
56: movq 184(%rdi), %rax <-- no check, no extable entry
[...]
Note that BPF_PROBE_MEM is not visible in a bpftool xlated dump, as bpf_insn_prepare_dump() rewrites it back to BPF_MEM.
A PTR_TRUSTED pointer is deliberately not on the list. Such a load is not converted either, but it does not need to be, since the pointer is guaranteed live, so load-acquire from it stays allowed.
The check is gated on BPF_LOAD_ACQ so that atomic RMW and store-release error messages are unchanged; writes (RMW / store-release) to such pointers are already rejected elsewhere, so only load-acquire needs this.
--- kernel/bpf/verifier.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +26 -1
@@ -6385,6 +6385,30 @@ static bool is_arena_reg(struct bpf_verifier_env *env, int regno)return reg->type ==PTR_TO_ARENA ; } +static bool is_load_acq_unsafe (struct bpf_verifier_env *env,int regno, +struct bpf_insn *insn) +{ +const struct bpf_reg_state *reg =reg_state (env, regno); + +/* +* A BPF_LOAD_ACQ is not rewritten to a BPF_PROBE_MEM load by the +* verifier, unlike a regular BPF_LDX. The JIT would emit a plain load +* with no exception table entry, so a fault (e.g. NULL deref) crashes +* the kernel instead of being handled. +* +* Reject the source pointer types that a BPF_LDX would have had that +* fault protection applied to, i.e. the ones bpf_convert_ctx_accesses() +* turns into BPF_PROBE_MEM: a bare PTR_TO_BTF_ID and any PTR_UNTRUSTED +* pointer (untrusted btf ids, untrusted MEM_ALLOC, rdonly untrusted +* memory). A PTR_TRUSTED pointer is not among them, is not converted, +* and stays allowed. Same for the other flagged PTR_TO_BTF_ID variants +* (MEM_ALLOC, MEM_RCU, ...), hence the exact match on the base type. +*/ +return insn->imm ==BPF_LOAD_ACQ && + (reg->type ==PTR_TO_BTF_ID || + (type_flag (reg->type) &PTR_UNTRUSTED )); +} +/* Return false if @regno contains a pointer whose type isn't supported for * atomic instruction @insn. */
@@ -6401,7 +6425,8 @@ static bool atomic_ptr_type_ok(struct bpf_verifier_env *env, int regno,return false;if (is_arena_reg (env, regno))return bpf_jit_supports_insn (insn, true); - +if (is_load_acq_unsafe (env, regno, insn)) +return false;return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 975/1518 bpf, riscv: Add and use bpf_atomic_is_load_acq() helper
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit e2577cd62060be91a3d7d11a56e5a61faae4b7f7 ]
A load-acquire is the only BPF_STX class instruction that reads from src_reg into dst_reg, that is, it has the operand roles of a BPF_LDX. JIT code which tells loads from stores apart by instruction class alone has to special case it, for example when deciding which register holds the faulting address and which one to clear from an exception handler.
riscv64 already does so, open coded as a bare insn->imm test. Add a bpf_atomic_is_load_acq() helper and convert riscv64 over to it, so that the x86-64 and arm64 JITs can use the same helper in subsequent patches.
Unlike bpf_atomic_is_load_store(), which presumes that its argument is already known to be a BPF_ATOMIC instruction, the new helper is called from code which still sees all instruction classes, so it checks class and mode itself.
Also, move bpf_atomic_is_load_store() to filter.h next to BPF_ATOMIC_OP, so that both helpers stay together. No functional change intended.
Stable-dep-of: 4cf8def58b77 ("bpf, x86: Fix exception table metadata for arena load-acquire")
--- arch/riscv/net/bpf_jit_comp64.c | 2 +- include/linux/bpf.h | 15 --------------- include/linux/filter.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 16 deletions(-)
arch/riscv/net/bpf_jit_comp64.c +1 -1
@@ -1928,7 +1928,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,/* ret can be 1 (skip-zext); extable entry still needs to be added */ if (ret >=0 ) ret =add_exception_handler (insn, - insn->imm ==BPF_LOAD_ACQ ? rd :REG_DONT_CLEAR_MARKER , +bpf_atomic_is_load_acq (insn) ? rd :REG_DONT_CLEAR_MARKER , ctx) ?: ret;if (ret)
include/linux/bpf.h +0 -15
@@ -1044,21 +1044,6 @@ static inline bool bpf_pseudo_func(const struct bpf_insn *insn)return bpf_is_ldimm64 (insn) && insn->src_reg ==BPF_PSEUDO_FUNC ; } -/* Given a BPF_ATOMIC instruction @atomic_insn, return true if it is an -* atomic load or store, and false if it is a read-modify-write instruction. -*/ -static inline bool -bpf_atomic_is_load_store (const struct bpf_insn *atomic_insn) -{ -switch (atomic_insn->imm) { -case BPF_LOAD_ACQ : -case BPF_STORE_REL : -return true; -default : -return false; - } -} -struct bpf_prog_ops {int (*test_run)(struct bpf_prog *prog,const union bpf_attr *kattr,union bpf_attr __user *uattr);
include/linux/filter.h +31 -0
@@ -383,6 +383,37 @@ static inline bool insn_is_cast_user(const struct bpf_insn *insn)/* Legacy alias */ #define BPF_STX_XADD (SIZE ,DST ,SRC ,OFF ) BPF_ATOMIC_OP(SIZE, BPF_ADD, DST, SRC, OFF) +/* +* Given a BPF_ATOMIC instruction @atomic_insn, return true if it is an +* atomic load or store, and false if it is a read-modify-write instruction. +*/ +static inline bool +bpf_atomic_is_load_store (const struct bpf_insn *atomic_insn) +{ +switch (atomic_insn->imm) { +case BPF_LOAD_ACQ : +case BPF_STORE_REL : +return true; +default : +return false; + } +} + +/* +* A load-acquire is the only BPF_STX class instruction that reads into +* dst_reg from src_reg + off16, i.e. it has the operand roles of a BPF_LDX. +* Unlike bpf_atomic_is_load_store(), @insn is not assumed to be a BPF_ATOMIC +* instruction here, so that callers which walk all instruction classes can +* use this directly. +*/ +static inline bool bpf_atomic_is_load_acq (const struct bpf_insn *insn) +{ +return BPF_CLASS (insn->code) ==BPF_STX && + (BPF_MODE (insn->code) ==BPF_ATOMIC || +BPF_MODE (insn->code) ==BPF_PROBE_ATOMIC ) && + insn->imm ==BPF_LOAD_ACQ ; +} +/* Memory store, *(uint *) (dst_reg + off16) = imm32 */ #define BPF_ST_MEM (SIZE ,DST ,OFF ,IMM ) \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 976/1518 bpf, x86: Fix exception table metadata for arena load-acquire
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 4cf8def58b779ad2827f81760837b7a844d6c7d6 ]
A load-acquire from an arena pointer is converted to BPF_PROBE_ATOMIC and gets an exception table entry, but the entry is filled in as if it were a store, since populate_extable() decides based on instruction class alone and a load-acquire is of BPF_STX class:
if (BPF_CLASS(insn->code) == BPF_LDX) {
arena_reg = reg2pt_regs[src_reg];
fixup_reg = reg2pt_regs[dst_reg];
} else {
arena_reg = reg2pt_regs[dst_reg];
fixup_reg = DONT_CLEAR;
}For a load-acquire dst_reg holds the loaded value and src_reg holds the address, so both assignments in the else branch are wrong. On a fault over an unmapped arena page ex_handler_bpf() then:
- computes the reported address from the value register instead of the address register
- reports the access as a WRITE, since it derives the direction
from fixup_reg == DONT_CLEAR
- leaves dst_reg untouched, so the program continues with a stale value instead of the 0 that BPF_PROBE_* loads deliver
The access itself is emitted correctly, emit_atomic_ld_st_index() uses src_reg as the address, so this is a broken probe contract and a wrong diagnostic rather than a memory safety issue.
Use bpf_atomic_is_load_acq() helper so a load-acquire takes the load path.
--- arch/x86/net/bpf_jit_comp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/net/bpf_jit_comp.c +6 -1
@@ -2175,8 +2175,13 @@ st: if (is_imm8(insn->off))* BPF_PROBE_ATOMIC) before being used for the memory access. Pass * the reg holding the unmodified 32-bit address to * ex_handler_bpf(). +* +* A load-acquire is of BPF_STX class, but reads from src_reg +* into dst_reg like a BPF_LDX does, hence it must not be +* treated as a store here. */ -if (BPF_CLASS (insn->code) ==BPF_LDX ) { +if (BPF_CLASS (insn->code) ==BPF_LDX || +bpf_atomic_is_load_acq (insn)) { arena_reg = reg2pt_regs[src_reg]; fixup_reg = reg2pt_regs[dst_reg]; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 977/1518 bpf, arm64: Fix exception table metadata for arena load-acquire
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit af22d273aa1f61fb86ec712b3ed785da73c3296e ]
Same problem as on x86-64: add_exception_handler() decides whether an instruction is a load by its class, and a load-acquire is of BPF_STX class even though it reads from src_reg into dst_reg. As a result ...
if (BPF_CLASS(insn->code) != BPF_LDX)
dst_reg = DONT_CLEAR;... drops the register to clear, and ...
if (BPF_CLASS(insn->code) == BPF_LDX)
arena_reg = bpf2a64[insn->src_reg];
else
arena_reg = bpf2a64[insn->dst_reg];... hands ex_handler_bpf() the value register instead of the address register. A load-acquire from an arena pointer that faults on an unmapped page is therefore reported as a WRITE at a bogus address, and dst_reg keeps its previous value instead of being cleared to 0.
Note that emit_atomic_ld_st() already picks src_reg as the address for BPF_LOAD_ACQ, so only the exception table metadata was out of sync with the emitted access.
Same as on x86-64, use bpf_atomic_is_load_acq() so a load-acquire takes the load path.
--- arch/arm64/net/bpf_jit_comp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm64/net/bpf_jit_comp.c +7 -2
@@ -1168,7 +1168,12 @@ static int add_exception_handler(const struct bpf_insn *insn, ex->insn = ins_offset; -if (BPF_CLASS (insn->code) !=BPF_LDX ) +/* +* A load-acquire is of BPF_STX class, but reads from src_reg into +* dst_reg like a BPF_LDX does, hence it must not be treated as a store +* here. +*/ +if (BPF_CLASS (insn->code) !=BPF_LDX && !bpf_atomic_is_load_acq (insn)) dst_reg =DONT_CLEAR ; ex->fixup =FIELD_PREP (BPF_FIXUP_REG_MASK , dst_reg);
@@ -1183,7 +1188,7 @@ static int add_exception_handler(const struct bpf_insn *insn,* memory access. Pass the reg holding the unmodified 32-bit address to * ex_handler_bpf. */ -if (BPF_CLASS (insn->code) ==BPF_LDX ) +if (BPF_CLASS (insn->code) ==BPF_LDX ||bpf_atomic_is_load_acq (insn)) arena_reg = bpf2a64[insn->src_reg];else arena_reg = bpf2a64[insn->dst_reg];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 978/1518 regulator: qcom-rpmh: Fix PMIC5 BOB bypass mode handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kamal Wadhwa <[email protected]>
[ Upstream commit abd14bebb87e0fa2749371272c8b31d6ee5f0a36 ]
Currently, when rpmh_regulator_set_mode_bypass() helper function is called to set bypass mode, it sends PMIC4's BOB bypass mode value for even if its a PMIC5 BOB.
To fix this, introduce new hw_data parameterpmic_bypass_mode to store bypass mode value. Use it to send correct PMIC bypass mode value that corresponds to PMIC4/5 BOB regulators from the helper function.
--- drivers/regulator/qcom-rpmh-regulator.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/regulator/qcom-rpmh-regulator.c +5 -1
@@ -77,6 +77,7 @@ enum rpmh_regulator_type {* @hpm_min_load_uA: Minimum load current in microamps that requires * high power mode (HPM) operation. This is used * for LDO hardware type regulators only. +* @pmic_bypass_mode: The PMIC bypass mode value. * @pmic_mode_map: Array indexed by regulator framework mode * containing PMIC hardware modes. Must be large * enough to index all framework modes supported
@@ -91,6 +92,7 @@ struct rpmh_vreg_hw_data {int n_linear_ranges;int n_voltages;int hpm_min_load_uA; +int pmic_bypass_mode;const int *pmic_mode_map;unsigned int (*of_map_mode)(unsigned int mode); };
@@ -277,7 +279,7 @@ static int rpmh_regulator_vrm_set_mode_bypass(struct rpmh_vreg *vreg,return pmic_mode;if (bypassed) - cmd.data =PMIC4_BOB_MODE_PASS ; + cmd.data = vreg->hw_data->pmic_bypass_mode;else cmd.data = pmic_mode;
@@ -692,6 +694,7 @@ static const struct rpmh_vreg_hw_data pmic4_bob = { }, .n_linear_ranges = 1, .n_voltages = 84, + .pmic_bypass_mode = PMIC4_BOB_MODE_PASS, .pmic_mode_map = pmic_mode_map_pmic4_bob, .of_map_mode = rpmh_regulator_pmic4_bob_of_map_mode, };
@@ -900,6 +903,7 @@ static const struct rpmh_vreg_hw_data pmic5_bob = { }, .n_linear_ranges = 1, .n_voltages = 32, + .pmic_bypass_mode = PMIC5_BOB_MODE_PASS, .pmic_mode_map = pmic_mode_map_pmic5_bob, .of_map_mode = rpmh_regulator_pmic4_bob_of_map_mode, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 979/1518 ACPI: video: Release PCI device reference after lookup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 3d7ed9b8ef47b8bcae1fc3e12f7590a217862a89 ]
video_detect_portege_r100() uses pci_get_device() only as a boolean check for the Trident CyberBlade XP4m32 device. pci_get_device() takes a reference on a matching PCI device, but the callback returns without releasing it.
Drop the reference after selecting the vendor backlight quirk so the PCI device can be released normally.
--- drivers/acpi/video_detect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/video_detect.c +3 -1
@@ -137,8 +137,10 @@ static int video_detect_portege_r100(const struct dmi_system_id *d)struct pci_dev *dev;/* Search for Trident CyberBlade XP4m32 to confirm Portégé R100 */ dev =pci_get_device (PCI_VENDOR_ID_TRIDENT ,0x2100 ,NULL ); -if (dev) +if (dev) { acpi_backlight_dmi = acpi_backlight_vendor; +pci_dev_put (dev); + }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 980/1518 perf/x86/intel/pt: Factor out pt_config_enable()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit c6df517796189723ffbdd7679206c97d3642c2ef ]
pt_config() enables tracing by allowing NMIs and pause/resume, issuing the necessary barriers, and calling pt_config_start(). A later change needs to re-enable tracing on a (re-)start path without repeating the full pt_config() setup (filters, RTIT_CTL, buffer configuration).
Factor that enabling sequence out into a new helper, pt_config_enable(), so it can be called on its own.
No functional change intended.
Stable-dep-of: 2e17bf3a469a ("perf/x86/intel/pt: Fix stop/start with no update")
--- arch/x86/events/intel/pt.c | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-)
arch/x86/events/intel/pt.c +24 -17
@@ -501,6 +501,29 @@ static u64 pt_config_filters(struct perf_event *event)return rtit_ctl; } +static void pt_config_enable (struct perf_event *event) +{ +struct pt *pt =this_cpu_ptr (&pt_ctx); + +/* +* Allow resume before starting so as not to overwrite a value set by a +* PMI. +*/ +barrier (); +WRITE_ONCE (pt->resume_allowed,1 ); +/* Configuration is complete, it is now OK to handle an NMI */ +barrier (); +WRITE_ONCE (pt->handle_nmi,1 ); +barrier (); +pt_config_start (event); +barrier (); +/* +* Allow pause after starting so its pt_config_stop() doesn't race with +* pt_config_start(). +*/ +WRITE_ONCE (pt->pause_allowed,1 ); +} +static void pt_config (struct perf_event *event) {struct pt *pt =this_cpu_ptr (&pt_ctx);
@@ -540,23 +563,7 @@ static void pt_config(struct perf_event *event) event->hw.aux_config = reg; -/* -* Allow resume before starting so as not to overwrite a value set by a -* PMI. -*/ -barrier (); -WRITE_ONCE (pt->resume_allowed,1 ); -/* Configuration is complete, it is now OK to handle an NMI */ -barrier (); -WRITE_ONCE (pt->handle_nmi,1 ); -barrier (); -pt_config_start (event); -barrier (); -/* -* Allow pause after starting so its pt_config_stop() doesn't race with -* pt_config_start(). -*/ -WRITE_ONCE (pt->pause_allowed,1 ); +pt_config_enable (event); }static void pt_config_stop (struct perf_event *event)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 981/1518 perf/x86/intel/pt: Use bitwise access for PERF_HES_STOPPED
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 265bb4ef75fa657f4957d72087a6a246b89d5f0d ]
The Intel PT driver reads and writes event->hw.state as a whole value, assuming it is either 0 or PERF_HES_STOPPED. That is true today, but a subsequent fix needs to also track an open AUX output buffer using the PERF_HES_UPTODATE bit of the same field.
When more than one bit can be set, whole-value assignments would overwrite the other bits and whole-value comparisons would fail to match.
Convert all accesses to set, clear and test the PERF_HES_STOPPED bit individually, in preparation for that change.
No functional change intended: event->hw.state currently only ever holds 0 or PERF_HES_STOPPED, so the bitwise forms are equivalent.
Stable-dep-of: 2e17bf3a469a ("perf/x86/intel/pt: Fix stop/start with no update")
--- arch/x86/events/intel/pt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/events/intel/pt.c +8 -8
@@ -1539,12 +1539,12 @@ void intel_pt_interrupt(void)perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 )); -if (!event->hw.state) { +if (!(event->hw.state &PERF_HES_STOPPED )) {int ret; buf =perf_aux_output_begin (&pt->handle, event);if (!buf) { - event->hw.state =PERF_HES_STOPPED ; + event->hw.state |=PERF_HES_STOPPED ;WRITE_ONCE (pt->resume_allowed,0 );return ; }
@@ -1639,7 +1639,7 @@ static void pt_event_start(struct perf_event *event, int mode) goto fail_end_stop; } - hwc->state =0 ; + hwc->state &= ~PERF_HES_STOPPED ;pt_config_buffer (buf);pt_config (event);
@@ -1649,7 +1649,7 @@ static void pt_event_start(struct perf_event *event, int mode) fail_end_stop:perf_aux_output_end (&pt->handle,0 ); fail_stop: - hwc->state =PERF_HES_STOPPED ; + hwc->state |=PERF_HES_STOPPED ; }static void pt_event_stop (struct perf_event *event,int mode)
@@ -1680,10 +1680,10 @@ static void pt_event_stop(struct perf_event *event, int mode)pt_config_stop (event); -if (event->hw.state ==PERF_HES_STOPPED ) +if (event->hw.state &PERF_HES_STOPPED )return ; - event->hw.state =PERF_HES_STOPPED ; + event->hw.state |=PERF_HES_STOPPED ;if (mode &PERF_EF_UPDATE ) {struct pt_buffer *buf =perf_get_aux (&pt->handle);
@@ -1778,10 +1778,10 @@ static int pt_event_add(struct perf_event *event, int mode)if (mode &PERF_EF_START ) {pt_event_start (event,0 ); ret = -EINVAL ; -if (hwc->state ==PERF_HES_STOPPED ) +if (hwc->state &PERF_HES_STOPPED ) goto fail; }else { - hwc->state =PERF_HES_STOPPED ; + hwc->state |=PERF_HES_STOPPED ; } ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 982/1518 perf/x86/intel/pt: Fix stop/start with no update
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 2e17bf3a469a41457a3bc31b1f8fd66b6ce94a6d ]
If pt_event_stop() is called without PERF_EF_UPDATE flag, then perf_aux_output_end() is not called. A subsequent call to pt_event_start() will call perf_aux_output_begin() again which violates the rule against nesting and triggers a WARNING in perf_aux_output_begin().
Originally, pt_event_stop() was never called without PERF_EF_UPDATE, because the only code paths to do so are from event overflow, and Intel PT does not do that.
However the introduction of group throttling by commit 9734e25fbf5ae ("perf: Fix the throttle logic for a group") meant that an Intel PT event could be throttled if it was part of a group. Throttling calls PMU
->stop() / ->start() callbacks without flags.
An example is when AUX area sampling is used. The following commands hit the issue:
echo 10000 > /proc/sys/kernel/perf_event_max_sample_rate
perf record -F32000 --aux-sample -e '{intel_pt//u,cycles:u}' \
-- bash -c 'for i in `seq 1 100000` ; do true ; done'Use PERF_HES_UPTODATE to track whether perf_aux_output_begin() and perf_aux_output_end() are balanced. A cleared PERF_HES_UPTODATE bit indicates that an AUX output context is still open.
Amend pt_event_start() / pt_event_stop() accordingly so that begin/end stay balanced:
- In non-snapshot mode, stop() always closes the buffer (the buffer may have run out of space, and that accounting is done by the update), so a following start() opens a fresh one as before.
- In snapshot/overwrite mode, stop() without PERF_EF_UPDATE leaves the buffer open so that pt_event_snapshot_aux() can still copy from it, and start() then only re-enables tracing instead of calling perf_aux_output_begin() again.
Note that pt_event_del() calls pt_event_stop() with PERF_EF_UPDATE flag set (as is required by the documentation), so a final call to perf_aux_output_end() is assured.
--- arch/x86/events/intel/pt.c | 45 ++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-)
arch/x86/events/intel/pt.c +36 -9
@@ -1539,6 +1539,8 @@ void intel_pt_interrupt(void)perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 )); + event->hw.state |=PERF_HES_UPTODATE ; +if (!(event->hw.state &PERF_HES_STOPPED )) {int ret;
@@ -1560,6 +1562,8 @@ void intel_pt_interrupt(void)pt_config_buffer (buf);pt_config_start (event); + + event->hw.state &= ~PERF_HES_UPTODATE ; } }
@@ -1629,6 +1633,18 @@ static void pt_event_start(struct perf_event *event, int mode)return ; } +/* +* Re-start subsequent to a call to pt_event_stop() without the +* PERF_EF_UPDATE flag. Absence of PERF_HES_UPTODATE indicates that +* perf_aux_output_begin() has already been called. This path can +* come about only in snapshot/overwrite mode - see pt_event_stop(). +*/ +if (!(hwc->state &PERF_HES_UPTODATE )) { + hwc->state &= ~PERF_HES_STOPPED ; +pt_config_enable (event); +return ; + } + buf =perf_aux_output_begin (&pt->handle, event);if (!buf) goto fail_stop;
@@ -1639,7 +1655,7 @@ static void pt_event_start(struct perf_event *event, int mode) goto fail_end_stop; } - hwc->state &= ~PERF_HES_STOPPED ; + hwc->state &= ~(PERF_HES_STOPPED |PERF_HES_UPTODATE );pt_config_buffer (buf);pt_config (event);
@@ -1649,12 +1665,13 @@ static void pt_event_start(struct perf_event *event, int mode) fail_end_stop:perf_aux_output_end (&pt->handle,0 ); fail_stop: - hwc->state |=PERF_HES_STOPPED ; + hwc->state |=PERF_HES_STOPPED |PERF_HES_UPTODATE ; }static void pt_event_stop (struct perf_event *event,int mode) {struct pt *pt =this_cpu_ptr (&pt_ctx); +struct pt_buffer *buf;if (mode &PERF_EF_PAUSE ) {if (READ_ONCE (pt->pause_allowed))
@@ -1680,17 +1697,24 @@ static void pt_event_stop(struct perf_event *event, int mode)pt_config_stop (event); -if (event->hw.state &PERF_HES_STOPPED ) -return ; - event->hw.state |=PERF_HES_STOPPED ; -if (mode &PERF_EF_UPDATE ) { -struct pt_buffer *buf =perf_get_aux (&pt->handle); +if (event->hw.state &PERF_HES_UPTODATE ) +return ; -if (!buf) -return ; + buf =perf_get_aux (&pt->handle); +if (!buf) +return ; +/* +* When not in snapshot/overwrite mode, there is a possibility that the +* buffer has run out of space. The accounting for that is handled by +* the update, so always update in that case. Snapshot/overwrite mode is +* treated differently to allow for pt_event_snapshot_aux() which can +* still get called if the AUX-sampling event is not stopped until after +* PT is stopped. +*/ +if ((mode &PERF_EF_UPDATE ) || !buf->snapshot) {if (WARN_ON_ONCE (pt->handle.event != event))return ;
@@ -1705,6 +1729,7 @@ static void pt_event_stop(struct perf_event *event, int mode)local_xchg (&buf->data_size, buf->nr_pages <<PAGE_SHIFT );perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 )); + event->hw.state |=PERF_HES_UPTODATE ; } }
@@ -1775,6 +1800,8 @@ static int pt_event_add(struct perf_event *event, int mode)if (pt->handle.event) goto fail; + event->hw.state |=PERF_HES_UPTODATE ; +if (mode &PERF_EF_START ) {pt_event_start (event,0 ); ret = -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 983/1518 sched/fair: Also gate overloaded status update for SD_ASYM_CPUCAPACITY
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Neri <[email protected]>
[ Upstream commit 6060d61d13a10da8c90da4eadf4a421825149883 ]
The argument sg_overloaded of update_sg_lb_stats() is only consumed when balancing at the root domain. It only makes sense to update it in such a case. Commit 3229adbe7875 ("sched/fair: Do not compute overloaded status unnecessarily during lb") updated the logic accordingly but missed the case in which the root domain has the SD_ASYM_CPUCAPACITY flag. Fix this.
--- kernel/sched/fair.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/fair.c +3 -1
@@ -10680,7 +10680,9 @@ static inline void update_sg_lb_stats(struct lb_env *env,/* Check for a misfit task on the cpu */ if (sgs->group_misfit_task_load < rq->misfit_task_load) { sgs->group_misfit_task_load = rq->misfit_task_load; - *sg_overloaded =1 ; + +if (balancing_at_rd) + *sg_overloaded =1 ; } }else if (env->idle &&sched_reduced_capacity (rq, env->sd)) {/* Check for a task running on a CPU with reduced capacity */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 984/1518 sched/fair: Check CPU capacity before comparing group types during load balance
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Neri <[email protected]>
[ Upstream commit 50b101f6e586b4417d060a976fd831cd87e86e2b ]
update_sd_pick_busiest() may incorrectly select a fully_busy group as the busiest group when its per-CPU capacity exceeds that of the destination CPU. This happens because the type of busiest group is initialized to group_has_spare and allows the fully_busy group to win the type comparison.
update_sd_pick_busiest() should not choose a candidate scheduling group with at most one runnable task if its per-CPU capacity is greater than that of the destination CPU. Such a check already exists, but it is done too
late: after the type comparison, preventing a subsequent fully_busy group of equal per-CPU capacity from being correctly selected.
Move this check to occur before comparing group types.
--- kernel/sched/fair.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
kernel/sched/fair.c +11 -11
@@ -10748,6 +10748,17 @@ static bool update_sd_pick_busiest(struct lb_env *env, sds->local_stat.group_type != group_has_spare))return false; +/* +* Candidate sg has no more than one task per CPU and has higher +* per-CPU capacity. Migrating tasks to less capable CPUs may harm +* throughput. Maximize throughput, power/energy consequences are not +* considered. +*/ +if ((env->sd->flags &SD_ASYM_CPUCAPACITY ) && + (sgs->group_type <= group_fully_busy) && + (capacity_greater (sg->sgc->min_capacity,capacity_of (env->dst_cpu)))) +return false; +if (sgs->group_type > busiest->group_type)return true;
@@ -10850,17 +10861,6 @@ static bool update_sd_pick_busiest(struct lb_env *env,break ; } -/* -* Candidate sg has no more than one task per CPU and has higher -* per-CPU capacity. Migrating tasks to less capable CPUs may harm -* throughput. Maximize throughput, power/energy consequences are not -* considered. -*/ -if ((env->sd->flags &SD_ASYM_CPUCAPACITY ) && - (sgs->group_type <= group_fully_busy) && - (capacity_greater (sg->sgc->min_capacity,capacity_of (env->dst_cpu)))) -return false; -return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 985/1518 Bluetooth: btqca: Fix qca_set_bdaddr() waiting for wrong HCI event
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijun Hu <[email protected]>
[ Upstream commit cf81f0a3db2a5c34ee6e4ea379c631fab6d13e01 ]
qca_set_bdaddr() waits for HCI_EV_VENDOR when sending EDL_WRITE_BD_ADDR_OPCODE (0xFC14), but the controller responds with Command Complete event as confirmed by btmon on WCN7850:
< HCI Command: Vendor (0x3f|0x0014) plen 6 #3 [hci0]
11 22 33 44 55 66
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #4 [hci0]
Vendor (0x3f|0x0014) ncmd 1
Status: Success (0x00)Fix by passing 0 as the event parameter to __hci_cmd_sync_ev() to wait for the command complete event instead.
--- drivers/bluetooth/btqca.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/bluetooth/btqca.c +1 -2
@@ -1014,8 +1014,7 @@ int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)baswap (&bdaddr_swapped, bdaddr); skb =__hci_cmd_sync_ev (hdev,EDL_WRITE_BD_ADDR_OPCODE ,6 , - &bdaddr_swapped,HCI_EV_VENDOR , -HCI_INIT_TIMEOUT ); + &bdaddr_swapped,0 ,HCI_INIT_TIMEOUT );if (IS_ERR (skb)) { err =PTR_ERR (skb);bt_dev_err (hdev,"QCA Change address cmd failed (%d)" , err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 986/1518 Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijun Hu <[email protected]>
[ Upstream commit d0b15d812688d3f0f3fe1c4426e12814d0c294dc ]
btusb_set_bdaddr_wcn6855() sends the address without swapping byte order for VSC 0xFC14, but the command expects the address in reversed byte order compared to other HCI commands like HCI_Create_Connection, resulting in a wrong BD_ADDR being set.
btmon log on WCN6855 shows VSC 0xFC14 is sent with swapped bytes 11 22 33 44 55 66, and Read BD ADDR returns the expected address 11:22:33:44:55:66:
< HCI Command: Vendor (0x3f|0x0014) plen 6 #3 [hci0]
11 22 33 44 55 66
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #4 [hci0]
Vendor (0x3f|0x0014) ncmd 1
Status: Success (0x00)< HCI Command: Read BD ADDR (0x04|0x0009) plen 0 #11 [hci0]
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 10 #12 [hci0]
Read BD ADDR (0x04|0x0009) ncmd 1
Status: Success (0x00)
Address: 11:22:33:44:55:66 (OUI 11-22-33)Fix by swapping the input address before issuing the command.
--- drivers/bluetooth/btusb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/bluetooth/btusb.c +5 -4
@@ -3006,14 +3006,15 @@ static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,static int btusb_set_bdaddr_wcn6855 (struct hci_dev *hdev,const bdaddr_t *bdaddr) { +bdaddr_t bdaddr_swapped;struct sk_buff *skb; -u8 buf[6 ];long ret; -memcpy (buf, bdaddr,sizeof (bdaddr_t)); +baswap (&bdaddr_swapped, bdaddr); - skb =__hci_cmd_sync_ev (hdev,0xfc14 ,sizeof (buf), buf, -HCI_EV_CMD_COMPLETE ,HCI_INIT_TIMEOUT ); + skb =__hci_cmd_sync_ev (hdev,0xfc14 ,sizeof (bdaddr_swapped), + &bdaddr_swapped,HCI_EV_CMD_COMPLETE , +HCI_INIT_TIMEOUT );if (IS_ERR (skb)) { ret =PTR_ERR (skb);bt_dev_err (hdev,"Change address command failed (%ld)" , ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 987/1518 Bluetooth: btusb: refactor endpoint lookup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 5c31aaa05624b54dc18c9e313bcee5a88c025593 ]
Use the common USB helper for looking up bulk and interrupt endpoints instead of open coding.
Stable-dep-of: 33c6a8d01889 ("Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices")
--- drivers/bluetooth/btusb.c | 51 ++++++--------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-)
drivers/bluetooth/btusb.c +8 -43
@@ -3658,31 +3658,14 @@ static inline int __set_diag_interface(struct hci_dev *hdev) {struct btusb_data *data =hci_get_drvdata (hdev);struct usb_interface *intf = data->diag; -int i; +int ret;if (!data->diag)return -ENODEV ; - data->diag_tx_ep =NULL ; - data->diag_rx_ep =NULL ; - -for (i =0 ; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { -struct usb_endpoint_descriptor *ep_desc; - - ep_desc = &intf->cur_altsetting->endpoint[i].desc; - -if (!data->diag_tx_ep &&usb_endpoint_is_bulk_out (ep_desc)) { - data->diag_tx_ep = ep_desc; -continue ; - } - -if (!data->diag_rx_ep &&usb_endpoint_is_bulk_in (ep_desc)) { - data->diag_rx_ep = ep_desc; -continue ; - } - } - -if (!data->diag_tx_ep || !data->diag_rx_ep) { + ret =usb_find_common_endpoints (intf->cur_altsetting, &data->diag_rx_ep, + &data->diag_tx_ep,NULL ,NULL ); +if (ret) {bt_dev_err (hdev,"invalid diagnostic descriptors" );return -ENODEV ; }
@@ -4013,12 +3996,11 @@ static struct hci_drv btusb_hci_drv = {static int btusb_probe (struct usb_interface *intf,const struct usb_device_id *id) { -struct usb_endpoint_descriptor *ep_desc;struct gpio_desc *reset_gpio;struct btusb_data *data;struct hci_dev *hdev;unsigned ifnum_base; -int i, err, priv_size; +int err, priv_size;BT_DBG ("intf %p id %p" , intf, id);
@@ -4055,26 +4037,9 @@ static int btusb_probe(struct usb_interface *intf,if (!data)return -ENOMEM ; -for (i =0 ; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { - ep_desc = &intf->cur_altsetting->endpoint[i].desc; - -if (!data->intr_ep &&usb_endpoint_is_int_in (ep_desc)) { - data->intr_ep = ep_desc; -continue ; - } - -if (!data->bulk_tx_ep &&usb_endpoint_is_bulk_out (ep_desc)) { - data->bulk_tx_ep = ep_desc; -continue ; - } - -if (!data->bulk_rx_ep &&usb_endpoint_is_bulk_in (ep_desc)) { - data->bulk_rx_ep = ep_desc; -continue ; - } - } - -if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) { + err =usb_find_common_endpoints (intf->cur_altsetting, &data->bulk_rx_ep, + &data->bulk_tx_ep, &data->intr_ep,NULL ); +if (err) {kfree (data);return -ENODEV ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 988/1518 Bluetooth: btusb: Record matched usb_device_id into btusb_data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijun Hu <[email protected]>
[ Upstream commit ff50db7a522e7bd3bd1c4db6da715e4bdb53af97 ]
Add @match_id to btusb_data to record the matched usb_device_id which will be used later.
Stable-dep-of: 33c6a8d01889 ("Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices")
--- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bluetooth/btusb.c +2 -0
@@ -976,6 +976,7 @@ struct btusb_data {bool usb_alt6_packet_flow;int isoc_altsetting;int suspend_count; +const struct usb_device_id *match_id;int (*recv_event)(struct hci_dev *hdev,struct sk_buff *skb);int (*recv_acl)(struct hci_dev *hdev,struct sk_buff *skb);
@@ -4037,6 +4038,7 @@ static int btusb_probe(struct usb_interface *intf,if (!data)return -ENOMEM ; + data->match_id = id; err =usb_find_common_endpoints (intf->cur_altsetting, &data->bulk_rx_ep, &data->bulk_tx_ep, &data->intr_ep,NULL );if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 989/1518 Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijun Hu <[email protected]>
[ Upstream commit 33c6a8d01889a84cc773c0c20c8323bce84af27d ]
Devcoredump is not enabled for ATH3012 or QCA_ROME, but they unconditionally populate devcoredump fields in btusb_setup_qca().
Fix by populating devcoredump fields only when BTUSB_QCA_WCN6855 is set, which marks the first generation of QCA BT SoCs for which devcoredump is enabled.
--- drivers/bluetooth/btusb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bluetooth/btusb.c +4 -2
@@ -3631,8 +3631,10 @@ static int btusb_setup_qca(struct hci_dev *hdev)if (err)return err; - btdata->qca_dump.fw_version =le32_to_cpu (ver.patch_version); - btdata->qca_dump.controller_id =le32_to_cpu (ver.rom_version); +if (btdata->match_id->driver_info &BTUSB_QCA_WCN6855 ) { + btdata->qca_dump.fw_version =le32_to_cpu (ver.patch_version); + btdata->qca_dump.controller_id =le32_to_cpu (ver.rom_version); + }if (!(status &QCA_SYSCFG_UPDATED )) { err =btusb_setup_qca_load_nvm (hdev, &ver, info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 990/1518 perf trace-event: Fix integer truncation in do_read() and skip()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tanushree Shah <[email protected]>
[ Upstream commit c108c1391be0826920991d24532fbae8f6373ddc ]
The do_read() and skip() functions use 'int' for size parameters, truncating 64-bit sizes from callers. This causes two issues:
1. Uninitialized memory dump: do_read() reads fewer bytes than allocated, leaving uninitialized heap memory that gets written to output files.
2. Out-of-bounds read: Parsing functions process the full 64-bit size while only partial data was read into the buffer.
Change do_read(), __do_read(), and skip() to use size_t for size parameters and ssize_t for return values (where applicable), matching read()/write() system calls.
Update callers to use ssize_t for storing return values.
--- tools/perf/util/trace-event-read.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
tools/perf/util/trace-event-read.c +14 -14
@@ -25,18 +25,18 @@ static int input_fd;static ssize_t trace_data_size;static bool repipe; -static int __do_read (int fd,void *buf,int size) +static ssize_t __do_read (int fd,void *buf,size_t size) { -int rsize = size; +size_t rsize = size;while (size) { -int ret =read (fd, buf, size); +ssize_t ret =read (fd, buf, size);if (ret <=0 )return -1 ;if (repipe) { -int retw =write (STDOUT_FILENO , buf, ret); +ssize_t retw =write (STDOUT_FILENO , buf, ret);if (retw <=0 || retw != ret) {pr_debug ("repiping input file" );
@@ -51,13 +51,13 @@ static int __do_read(int fd, void *buf, int size)return rsize; } -static int do_read (void *data,int size) +static ssize_t do_read (void *data,size_t size) { -int r; +ssize_t r; r =__do_read (input_fd, data, size);if (r <=0 ) { -pr_debug ("reading input file (size expected=%d received=%d)" , +pr_debug ("reading input file (size expected=%zu received=%zd)" , size, r);return -1 ; }
@@ -68,10 +68,10 @@ static int do_read(void *data, int size) }/* If it fails, the next read will report it */ -static void skip (int size) +static void skip (size_t size) {char buf[BUFSIZ ]; -int r; +size_t r;while (size) { r = size >BUFSIZ ?BUFSIZ : size;
@@ -202,7 +202,7 @@ static int read_header_files(struct tep_handle *pevent)unsigned long long size;char *header_page;char buf[BUFSIZ ]; -int ret =0 ; +ssize_t ret =0 ;if (do_read (buf,12 ) <0 )return -1 ;
@@ -250,7 +250,7 @@ static int read_header_files(struct tep_handle *pevent)static int read_ftrace_file (struct tep_handle *pevent,unsigned long long size) { -int ret; +ssize_t ret;char *buf; buf =malloc (size);
@@ -276,7 +276,7 @@ static int read_ftrace_file(struct tep_handle *pevent, unsigned long long size)static int read_event_file (struct tep_handle *pevent,char *sys,unsigned long long size) { -int ret; +ssize_t ret;char *buf; buf =malloc (size);
@@ -322,7 +322,7 @@ static int read_event_files(struct tep_handle *pevent)int systems;int count;int i,x; -int ret; +ssize_t ret; systems =read4 (pevent);
@@ -350,7 +350,7 @@ static int read_saved_cmdline(struct tep_handle *pevent) {unsigned long long size;char *buf; -int ret; +ssize_t ret;/* it can have 0 size */ size =read8 (pevent);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 991/1518 scsi: core: Pass a struct scsi_driver to scsi_{,un}register_driver()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 7d42bcea57ae139e2ed754425cc5fc44e260c890 ]
This aligns with what other subsystems do, reduces boilerplate a bit for device drivers and is less error prone.
Stable-dep-of: bb31844d88b7 ("scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails")
--- drivers/scsi/ch.c | 4 ++-- drivers/scsi/scsi_sysfs.c | 4 +++- drivers/scsi/sd.c | 4 ++-- drivers/scsi/ses.c | 4 ++-- drivers/scsi/sr.c | 4 ++-- drivers/scsi/st.c | 4 ++-- drivers/ufs/core/ufshcd.c | 4 ++-- include/scsi/scsi_driver.h | 4 ++-- 8 files changed, 17 insertions(+), 15 deletions(-)
drivers/scsi/ch.c +2 -2
@@ -1014,7 +1014,7 @@ static int __init init_ch_module(void) SCSI_CHANGER_MAJOR); goto fail1; } - rc =scsi_register_driver (&ch_template.gendrv); + rc =scsi_register_driver (&ch_template);if (rc <0 ) goto fail2;return 0 ;
@@ -1028,7 +1028,7 @@ static int __init init_ch_module(void) static void __exit exit_ch_module(void) { -scsi_unregister_driver (&ch_template.gendrv); +scsi_unregister_driver (&ch_template);unregister_chrdev (SCSI_CHANGER_MAJOR ,"ch" );class_unregister (&ch_sysfs_class);idr_destroy (&ch_index_idr);
drivers/scsi/scsi_sysfs.c +3 -1
@@ -1609,8 +1609,10 @@ void scsi_remove_target(struct device *dev) }EXPORT_SYMBOL (scsi_remove_target); -int __scsi_register_driver (struct device_driver *drv,struct module *owner) +int __scsi_register_driver (struct scsi_driver *sdrv,struct module *owner) { +struct device_driver *drv = &sdrv->gendrv; + drv->bus = &scsi_bus_type; drv->owner = owner;
drivers/scsi/sd.c +2 -2
@@ -4375,7 +4375,7 @@ static int __init init_sd(void) goto err_out_class; } - err =scsi_register_driver (&sd_template.gendrv); + err =scsi_register_driver (&sd_template);if (err) goto err_out_driver;
@@ -4402,7 +4402,7 @@ static void __exit exit_sd(void)SCSI_LOG_HLQUEUE (3 ,printk ("exit_sd: exiting sd driver\n" )); -scsi_unregister_driver (&sd_template.gendrv); +scsi_unregister_driver (&sd_template);mempool_destroy (sd_page_pool);class_unregister (&sd_disk_class);
drivers/scsi/ses.c +2 -2
@@ -920,7 +920,7 @@ static int __init ses_init(void)if (err)return err; - err =scsi_register_driver (&ses_template.gendrv); + err =scsi_register_driver (&ses_template);if (err) goto out_unreg;
@@ -933,7 +933,7 @@ static int __init ses_init(void) static void __exit ses_exit(void) { -scsi_unregister_driver (&ses_template.gendrv); +scsi_unregister_driver (&ses_template);scsi_unregister_interface (&ses_interface); }
drivers/scsi/sr.c +2 -2
@@ -994,7 +994,7 @@ static int __init init_sr(void) rc =register_blkdev (SCSI_CDROM_MAJOR ,"sr" );if (rc)return rc; - rc =scsi_register_driver (&sr_template.gendrv); + rc =scsi_register_driver (&sr_template);if (rc)unregister_blkdev (SCSI_CDROM_MAJOR ,"sr" );
@@ -1003,7 +1003,7 @@ static int __init init_sr(void) static void __exit exit_sr(void) { -scsi_unregister_driver (&sr_template.gendrv); +scsi_unregister_driver (&sr_template);unregister_blkdev (SCSI_CDROM_MAJOR ,"sr" ); }
drivers/scsi/st.c +2 -2
@@ -4533,7 +4533,7 @@ static int __init init_st(void) goto err_class; } - err =scsi_register_driver (&st_template.gendrv); + err =scsi_register_driver (&st_template);if (err) goto err_chrdev;
@@ -4549,7 +4549,7 @@ static int __init init_st(void) static void __exit exit_st(void) { -scsi_unregister_driver (&st_template.gendrv); +scsi_unregister_driver (&st_template);unregister_chrdev_region (MKDEV (SCSI_TAPE_MAJOR ,0 ),ST_MAX_TAPE_ENTRIES );class_unregister (&st_sysfs_class);
drivers/ufs/core/ufshcd.c +2 -2
@@ -11090,7 +11090,7 @@ static int __init ufshcd_core_init(void)ufs_debugfs_init (); - ret =scsi_register_driver (&ufs_dev_wlun_template.gendrv); + ret =scsi_register_driver (&ufs_dev_wlun_template);if (ret)ufs_debugfs_exit ();return ret;
@@ -11099,7 +11099,7 @@ static int __init ufshcd_core_init(void) static void __exit ufshcd_core_exit(void) {ufs_debugfs_exit (); -scsi_unregister_driver (&ufs_dev_wlun_template.gendrv); +scsi_unregister_driver (&ufs_dev_wlun_template); }module_init (ufshcd_core_init);
include/scsi/scsi_driver.h +2 -2
@@ -25,9 +25,9 @@ struct scsi_driver {#define scsi_register_driver (drv) \ __scsi_register_driver(drv, THIS_MODULE) -int __scsi_register_driver (struct device_driver *,struct module *); +int __scsi_register_driver (struct scsi_driver *,struct module *);#define scsi_unregister_driver (drv) \ - driver_unregister(drv); + driver_unregister(&(drv)->gendrv);extern int scsi_register_interface (struct class_interface *);#define scsi_unregister_interface (intf) \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 992/1518 scsi: core: sysfs: Make use of bus callbacks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit f7d4f1bf5724e52de049c619beddd53c62206624 ]
Introduce a bus-specific probe, remove and shutdown function. For now this only allows to get rid of a cast of the generic device to a SCSI device in the drivers and changes the remove prototype to return void---a non-zero return value is ignored anyhow.
The objective is to get rid of users of struct device_driver callbacks .probe(), .remove() and .shutdown() to eventually remove these. Until all SCSI drivers are converted, this results in a runtime warning about the drivers needing an update because there is a bus probe function and a driver probe function. The in-tree drivers are fixed by the following commits.
Stable-dep-of: bb31844d88b7 ("scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails")
--- drivers/scsi/scsi_sysfs.c | 73 ++++++++++++++++++++++++++++++++++++-- include/scsi/scsi_driver.h | 3 ++ 2 files changed, 74 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +71 -2
@@ -554,10 +554,48 @@ static int scsi_bus_uevent(const struct device *dev, struct kobj_uevent_env *envreturn 0 ; } +static int scsi_bus_probe (struct device *dev) +{ +struct scsi_device *sdp =to_scsi_device (dev); +struct scsi_driver *drv =to_scsi_driver (dev->driver); + +if (drv->probe) +return drv->probe (sdp); +else +return 0 ; +} + +static void scsi_bus_remove (struct device *dev) +{ +struct scsi_device *sdp =to_scsi_device (dev); +struct scsi_driver *drv =to_scsi_driver (dev->driver); + +if (drv->remove) + drv->remove (sdp); +} + +static void scsi_bus_shutdown (struct device *dev) +{ +struct scsi_device *sdp =to_scsi_device (dev); +struct scsi_driver *drv; + +if (!dev->driver) +return ; + + drv =to_scsi_driver (dev->driver); + +if (drv->shutdown) + drv->shutdown (sdp); +} + +const struct bus_type scsi_bus_type = { - .name ="scsi" , - .match = scsi_bus_match, + .name ="scsi" , + .match = scsi_bus_match, .uevent = scsi_bus_uevent, + .probe = scsi_bus_probe, + .remove = scsi_bus_remove, + .shutdown = scsi_bus_shutdown, #ifdef CONFIG_PM .pm = &scsi_bus_pm_ops, #endif
@@ -1609,6 +1647,30 @@ void scsi_remove_target(struct device *dev) }EXPORT_SYMBOL (scsi_remove_target); +static int scsi_legacy_probe (struct scsi_device *sdp) +{ +struct device *dev = &sdp->sdev_gendev; +struct device_driver *driver = dev->driver; + +return driver->probe (dev); +} + +static void scsi_legacy_remove (struct scsi_device *sdp) +{ +struct device *dev = &sdp->sdev_gendev; +struct device_driver *driver = dev->driver; + + driver->remove (dev); +} + +static void scsi_legacy_shutdown (struct scsi_device *sdp) +{ +struct device *dev = &sdp->sdev_gendev; +struct device_driver *driver = dev->driver; + + driver->shutdown (dev); +} +int __scsi_register_driver (struct scsi_driver *sdrv,struct module *owner) {struct device_driver *drv = &sdrv->gendrv;
@@ -1616,6 +1678,13 @@ int __scsi_register_driver(struct scsi_driver *sdrv, struct module *owner) drv->bus = &scsi_bus_type; drv->owner = owner; +if (!sdrv->probe && drv->probe) + sdrv->probe = scsi_legacy_probe; +if (!sdrv->remove && drv->remove) + sdrv->remove = scsi_legacy_remove; +if (!sdrv->shutdown && drv->shutdown) + sdrv->shutdown = scsi_legacy_shutdown; +return driver_register (drv); }EXPORT_SYMBOL (__scsi_register_driver);
include/scsi/scsi_driver.h +3 -0
@@ -12,6 +12,9 @@ struct request;struct scsi_driver {struct device_driver gendrv; +int (*probe)(struct scsi_device *); +void (*remove)(struct scsi_device *); +void (*shutdown)(struct scsi_device *);int (*resume)(struct device *);void (*rescan)(struct device *);blk_status_t (*init_command)(struct scsi_cmnd *);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 993/1518 scsi: sd: Convert to SCSI bus methods
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 63b541f054e7147f5a19fcd964677c189bad7cff ]
The SCSI subsystem has implemented dedicated callbacks for probe, remove and shutdown. Make use of them. This fixes a runtime warning about the driver needing to be converted to the bus probe method.
Stable-dep-of: bb31844d88b7 ("scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails")
--- drivers/scsi/sd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/scsi/sd.c +13 -12
@@ -108,7 +108,7 @@ static void sd_config_write_same(struct scsi_disk *sdkp, struct queue_limits *lim);static void sd_revalidate_disk (struct gendisk *);static void sd_unlock_native_capacity (struct gendisk *disk); -static void sd_shutdown (struct device *); +static void sd_shutdown (struct scsi_device *);static void scsi_disk_release (struct device *cdev);static DEFINE_IDA (sd_index_ida);
@@ -3894,7 +3894,7 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen)* sd_probe - called during driver initialization and whenever a * new scsi device is attached to the system. It is called once * for each scsi device (not just disks) present. -* @dev: pointer to device object +* @sdp: pointer to device object * * Returns 0 if successful (or not interested in this scsi device * (e.g. scanner)); 1 when there is an error.
@@ -3908,9 +3908,9 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen)* Assume sd_probe is not re-entrant (for time being) * Also think about sd_probe() and sd_remove() running coincidentally. **/ -static int sd_probe (struct device *dev) +static int sd_probe (struct scsi_device *sdp) { -struct scsi_device *sdp =to_scsi_device (dev); +struct device *dev = &sdp->sdev_gendev;struct scsi_disk *sdkp;struct gendisk *gd;int index;
@@ -4051,15 +4051,16 @@ static int sd_probe(struct device *dev)* sd_remove - called whenever a scsi disk (previously recognized by * sd_probe) is detached from the system. It is called (potentially * multiple times) during sd module unload. -* @dev: pointer to device object +* @sdp: pointer to device object * * Note: this function is invoked from the scsi mid-level. * This function potentially frees up a device name (e.g. /dev/sdc) * that could be re-used by a subsequent sd_probe(). * This function is not called when the built-in sd driver is "exit-ed". **/ -static int sd_remove (struct device *dev) +static void sd_remove (struct scsi_device *sdp) { +struct device *dev = &sdp->sdev_gendev;struct scsi_disk *sdkp =dev_get_drvdata (dev);scsi_autopm_get_device (sdkp->device);
@@ -4067,10 +4068,9 @@ static int sd_remove(struct device *dev)device_del (&sdkp->disk_dev);del_gendisk (sdkp->disk);if (!sdkp->suspended) -sd_shutdown (dev); +sd_shutdown (sdp);put_disk (sdkp->disk); -return 0 ; }static void scsi_disk_release (struct device *dev)
@@ -4157,8 +4157,9 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)* the normal SCSI command structure. Wait for the command to * complete. */ -static void sd_shutdown (struct device *dev) +static void sd_shutdown (struct scsi_device *sdp) { +struct device *dev = &sdp->sdev_gendev;struct scsi_disk *sdkp =dev_get_drvdata (dev);if (!sdkp)
@@ -4326,12 +4327,12 @@ static const struct dev_pm_ops sd_pm_ops = { };static struct scsi_driver sd_template = { + .probe = sd_probe, + .remove = sd_remove, + .shutdown = sd_shutdown, .gendrv = { .name ="sd" , - .probe = sd_probe, .probe_type =PROBE_PREFER_ASYNCHRONOUS , - .remove = sd_remove, - .shutdown = sd_shutdown, .pm = &sd_pm_ops, }, .rescan = sd_rescan,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 994/1518 scsi: sd: Move the sd_remove() function definition
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 4f39a4870a59971797be86fed72423b83b6b4e00 ]
Move the sd_remove() function definition such that the sd_shutdown() forward declaration can be removed.
Stable-dep-of: bb31844d88b7 ("scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails")
--- drivers/scsi/sd.c | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-)
drivers/scsi/sd.c +26 -27
@@ -108,7 +108,6 @@ static void sd_config_write_same(struct scsi_disk *sdkp, struct queue_limits *lim);static void sd_revalidate_disk (struct gendisk *);static void sd_unlock_native_capacity (struct gendisk *disk); -static void sd_shutdown (struct scsi_device *);static void scsi_disk_release (struct device *cdev);static DEFINE_IDA (sd_index_ida);
@@ -4047,32 +4046,6 @@ static int sd_probe(struct scsi_device *sdp)return error; } -/** -* sd_remove - called whenever a scsi disk (previously recognized by -* sd_probe) is detached from the system. It is called (potentially -* multiple times) during sd module unload. -* @sdp: pointer to device object -* -* Note: this function is invoked from the scsi mid-level. -* This function potentially frees up a device name (e.g. /dev/sdc) -* that could be re-used by a subsequent sd_probe(). -* This function is not called when the built-in sd driver is "exit-ed". -**/ -static void sd_remove (struct scsi_device *sdp) -{ -struct device *dev = &sdp->sdev_gendev; -struct scsi_disk *sdkp =dev_get_drvdata (dev); - -scsi_autopm_get_device (sdkp->device); - -device_del (&sdkp->disk_dev); -del_gendisk (sdkp->disk); -if (!sdkp->suspended) -sd_shutdown (sdp); - -put_disk (sdkp->disk); -} -static void scsi_disk_release (struct device *dev) {struct scsi_disk *sdkp =to_scsi_disk (dev);
@@ -4184,6 +4157,32 @@ static void sd_shutdown(struct scsi_device *sdp) } } +/** +* sd_remove - called whenever a scsi disk (previously recognized by +* sd_probe) is detached from the system. It is called (potentially +* multiple times) during sd module unload. +* @sdp: pointer to device object +* +* Note: this function is invoked from the scsi mid-level. +* This function potentially frees up a device name (e.g. /dev/sdc) +* that could be re-used by a subsequent sd_probe(). +* This function is not called when the built-in sd driver is "exit-ed". +**/ +static void sd_remove (struct scsi_device *sdp) +{ +struct device *dev = &sdp->sdev_gendev; +struct scsi_disk *sdkp =dev_get_drvdata (dev); + +scsi_autopm_get_device (sdkp->device); + +device_del (&sdkp->disk_dev); +del_gendisk (sdkp->disk); +if (!sdkp->suspended) +sd_shutdown (sdp); + +put_disk (sdkp->disk); +} +static inline bool sd_do_start_stop (struct scsi_device *sdev,bool runtime) { return (sdev->manage_system_start_stop && !runtime) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 995/1518 scsi: sd: Move the sd_config_discard() function definition
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit c0daf4836114fcbdf64bf817cab00b75ce712945 ]
Move the sd_config_discard() function definition such that its forward declaration can be removed.
Stable-dep-of: bb31844d88b7 ("scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails")
--- drivers/scsi/sd.c | 114 +++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 58 deletions(-)
drivers/scsi/sd.c +56 -58
@@ -102,8 +102,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);#define SD_MINORS 16 -static void sd_config_discard (struct scsi_disk *sdkp,struct queue_limits *lim, -unsigned int mode);static void sd_config_write_same (struct scsi_disk *sdkp,struct queue_limits *lim);static void sd_revalidate_disk (struct gendisk *);
@@ -120,6 +118,62 @@ static const char *sd_cache_types[] = {"write back, no read (daft)" }; +static void sd_disable_discard (struct scsi_disk *sdkp) +{ + sdkp->provisioning_mode =SD_LBP_DISABLE ; +blk_queue_disable_discard (sdkp->disk->queue); +} + +static void sd_config_discard (struct scsi_disk *sdkp,struct queue_limits *lim, +unsigned int mode) +{ +unsigned int logical_block_size = sdkp->device->sector_size; +unsigned int max_blocks =0 ; + + lim->discard_alignment = sdkp->unmap_alignment * logical_block_size; + lim->discard_granularity =max (sdkp->physical_block_size, + sdkp->unmap_granularity * logical_block_size); + sdkp->provisioning_mode = mode; + +switch (mode) { + +case SD_LBP_FULL : +case SD_LBP_DISABLE : +break ; + +case SD_LBP_UNMAP : + max_blocks =min_not_zero (sdkp->max_unmap_blocks, + (u32 )SD_MAX_WS16_BLOCKS ); +break ; + +case SD_LBP_WS16 : +if (sdkp->device->unmap_limit_for_ws) + max_blocks = sdkp->max_unmap_blocks; +else + max_blocks = sdkp->max_ws_blocks; + + max_blocks =min_not_zero (max_blocks, (u32 )SD_MAX_WS16_BLOCKS ); +break ; + +case SD_LBP_WS10 : +if (sdkp->device->unmap_limit_for_ws) + max_blocks = sdkp->max_unmap_blocks; +else + max_blocks = sdkp->max_ws_blocks; + + max_blocks =min_not_zero (max_blocks, (u32 )SD_MAX_WS10_BLOCKS ); +break ; + +case SD_LBP_ZERO : + max_blocks =min_not_zero (sdkp->max_ws_blocks, + (u32 )SD_MAX_WS10_BLOCKS ); +break ; + } + + lim->max_hw_discard_sectors = max_blocks * + (logical_block_size >>SECTOR_SHIFT ); +} +static void sd_set_flush_flag (struct scsi_disk *sdkp,struct queue_limits *lim) {
@@ -835,62 +889,6 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,return protect; } -static void sd_disable_discard (struct scsi_disk *sdkp) -{ - sdkp->provisioning_mode =SD_LBP_DISABLE ; -blk_queue_disable_discard (sdkp->disk->queue); -} - -static void sd_config_discard (struct scsi_disk *sdkp,struct queue_limits *lim, -unsigned int mode) -{ -unsigned int logical_block_size = sdkp->device->sector_size; -unsigned int max_blocks =0 ; - - lim->discard_alignment = sdkp->unmap_alignment * logical_block_size; - lim->discard_granularity =max (sdkp->physical_block_size, - sdkp->unmap_granularity * logical_block_size); - sdkp->provisioning_mode = mode; - -switch (mode) { - -case SD_LBP_FULL : -case SD_LBP_DISABLE : -break ; - -case SD_LBP_UNMAP : - max_blocks =min_not_zero (sdkp->max_unmap_blocks, - (u32 )SD_MAX_WS16_BLOCKS ); -break ; - -case SD_LBP_WS16 : -if (sdkp->device->unmap_limit_for_ws) - max_blocks = sdkp->max_unmap_blocks; -else - max_blocks = sdkp->max_ws_blocks; - - max_blocks =min_not_zero (max_blocks, (u32 )SD_MAX_WS16_BLOCKS ); -break ; - -case SD_LBP_WS10 : -if (sdkp->device->unmap_limit_for_ws) - max_blocks = sdkp->max_unmap_blocks; -else - max_blocks = sdkp->max_ws_blocks; - - max_blocks =min_not_zero (max_blocks, (u32 )SD_MAX_WS10_BLOCKS ); -break ; - -case SD_LBP_ZERO : - max_blocks =min_not_zero (sdkp->max_ws_blocks, - (u32 )SD_MAX_WS10_BLOCKS ); -break ; - } - - lim->max_hw_discard_sectors = max_blocks * - (logical_block_size >>SECTOR_SHIFT ); -} -static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) {struct page *page;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 996/1518 scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Swarna Prabhu <[email protected]>
[ Upstream commit 7179e626b76eb42f2529c6f6dd6ba88ea2445372 ]
The WRITE SAME(16) and WRITE SAME(10) SCSI commands use a page from a dedicated mempool (sd_page_pool) for their payload. This pool was initialized to allocate single pages, which was sufficient as long as the device sector size did not exceed the PAGE_SIZE.
Given that block layer now supports block size upto 64KB, i.e. beyond PAGE_SIZE, initialize a large page pool in sd_probe() if a higher sector device is attached, ensuring atomicity. Adapt sd_set_special_bvec() to use large page pool when a higher sector size device is attached. Hence enable sector sizes > PAGE_SIZE in SCSI sd driver.
Stable-dep-of: bb31844d88b7 ("scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails")
--- drivers/scsi/sd.c | 80 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 12 deletions(-)
drivers/scsi/sd.c +68 -12
@@ -109,8 +109,11 @@ static void sd_unlock_native_capacity(struct gendisk *disk);static void scsi_disk_release (struct device *cdev);static DEFINE_IDA (sd_index_ida); +static DEFINE_MUTEX (sd_mutex_lock);static mempool_t *sd_page_pool; +static mempool_t *sd_large_page_pool; +static atomic_t sd_large_page_pool_users =ATOMIC_INIT (0 );static struct lock_class_key sd_bio_compl_lkclass;static const char *sd_cache_types[] = {
@@ -118,6 +121,33 @@ static const char *sd_cache_types[] = {"write back, no read (daft)" }; +static int sd_large_pool_create (void ) +{ +mutex_lock (&sd_mutex_lock); +if (!sd_large_page_pool) { + sd_large_page_pool =mempool_create_page_pool ( +SD_MEMPOOL_SIZE ,get_order (BLK_MAX_BLOCK_SIZE )); +if (!sd_large_page_pool) { +printk (KERN_ERR "sd: can't create large page mempool\n" ); +mutex_unlock (&sd_mutex_lock); +return -ENOMEM ; + } + } +atomic_inc (&sd_large_page_pool_users); +mutex_unlock (&sd_mutex_lock); +return 0 ; +} + +static void sd_large_pool_destroy (void ) +{ +mutex_lock (&sd_mutex_lock); +if (atomic_dec_and_test (&sd_large_page_pool_users)) { +mempool_destroy (sd_large_page_pool); + sd_large_page_pool =NULL ; + } +mutex_unlock (&sd_mutex_lock); +} +static void sd_disable_discard (struct scsi_disk *sdkp) { sdkp->provisioning_mode =SD_LBP_DISABLE ;
@@ -889,14 +919,24 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,return protect; } -static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) +static void *sd_set_special_bvec (struct scsi_cmnd *cmd,unsigned int data_len) {struct page *page; +struct request *rq =scsi_cmd_to_rq (cmd); +struct scsi_device *sdp = cmd->device; +unsigned sector_size = sdp->sector_size; +unsigned int nr_pages =DIV_ROUND_UP (sector_size,PAGE_SIZE ); +int n; - page =mempool_alloc (sd_page_pool,GFP_ATOMIC ); +if (sector_size >PAGE_SIZE ) + page =mempool_alloc (sd_large_page_pool,GFP_ATOMIC ); +else + page =mempool_alloc (sd_page_pool,GFP_ATOMIC );if (!page)return NULL ; -clear_highpage (page); + +for (n =0 ; n < nr_pages; n++) +clear_highpage (page + n);bvec_set_page (&rq->special_vec, page, data_len,0 ); rq->rq_flags |=RQF_SPECIAL_PAYLOAD ;return bvec_virt (&rq->special_vec);
@@ -912,7 +952,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)unsigned int data_len =24 ;char *buf; - buf =sd_set_special_bvec (rq, data_len); + buf =sd_set_special_bvec (cmd, data_len);if (!buf)return BLK_STS_RESOURCE ;
@@ -1001,7 +1041,7 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; -if (!sd_set_special_bvec (rq, data_len)) +if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ; cmd->cmd_len =16 ;
@@ -1028,7 +1068,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; -if (!sd_set_special_bvec (rq, data_len)) +if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ; cmd->cmd_len =10 ;
@@ -1474,9 +1514,15 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd)static void sd_uninit_command (struct scsi_cmnd *SCpnt) {struct request *rq =scsi_cmd_to_rq (SCpnt); +struct scsi_device *sdp = SCpnt->device; +unsigned sector_size = sdp->sector_size; -if (rq->rq_flags &RQF_SPECIAL_PAYLOAD ) -mempool_free (rq->special_vec.bv_page, sd_page_pool); +if (rq->rq_flags &RQF_SPECIAL_PAYLOAD ) { +if (sector_size >PAGE_SIZE ) +mempool_free (rq->special_vec.bv_page, sd_large_page_pool); +else +mempool_free (rq->special_vec.bv_page, sd_page_pool); + } }static bool sd_need_revalidate (struct gendisk *disk,struct scsi_disk *sdkp)
@@ -2876,10 +2922,7 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim, "assuming 512.\n"); } -if (sector_size !=512 && - sector_size !=1024 && - sector_size !=2048 && - sector_size !=4096 ) { +if (blk_validate_block_size (sector_size)) {sd_printk (KERN_NOTICE , sdkp,"Unsupported sector size %d.\n" , sector_size);/*
@@ -4001,6 +4044,12 @@ static int sd_probe(struct scsi_device *sdp) sdkp->max_medium_access_timeouts =SD_MAX_MEDIUM_TIMEOUTS ;sd_revalidate_disk (gd); +if (sdp->sector_size >PAGE_SIZE ) { +if (sd_large_pool_create ()) { + error = -ENOMEM ; + goto out_free_index; + } + }if (sdp->removable) { gd->flags |=GENHD_FL_REMOVABLE ;
@@ -4018,6 +4067,8 @@ static int sd_probe(struct scsi_device *sdp)if (error) {device_unregister (&sdkp->disk_dev);put_disk (gd); +if (sdp->sector_size >PAGE_SIZE ) +sd_large_pool_destroy (); goto out; }
@@ -4179,6 +4230,9 @@ static void sd_remove(struct scsi_device *sdp)sd_shutdown (sdp);put_disk (sdkp->disk); + +if (sdp->sector_size >PAGE_SIZE ) +sd_large_pool_destroy (); }static inline bool sd_do_start_stop (struct scsi_device *sdev,bool runtime)
@@ -4402,6 +4456,8 @@ static void __exit exit_sd(void)scsi_unregister_driver (&sd_template);mempool_destroy (sd_page_pool); +if (sd_large_page_pool) +mempool_destroy (sd_large_page_pool);class_unregister (&sd_disk_class);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 997/1518 scsi: sd: Fix special_vec mempool leak when scsi_alloc_sgtables() fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit bb31844d88b77138b67aa20c3600203baff40140 ]
sd_set_special_bvec() allocates a special payload page for UNMAP and WRITE SAME commands. If scsi_alloc_sgtables() fails afterward in sd_setup_unmap_cmnd() or sd_setup_write_same{10,16}_cmnd(), the SCSI midlayer does not call uninit_command() because RQF_DONTPREP is not set yet, leaking the page.
Call sd_uninit_command() on error, and clear RQF_SPECIAL_PAYLOAD after freeing the page.
--- drivers/scsi/sd.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-)
drivers/scsi/sd.c +30 -17
@@ -919,6 +919,21 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,return protect; } +static void sd_uninit_command (struct scsi_cmnd *cmd) +{ +struct request *rq =scsi_cmd_to_rq (cmd); +struct scsi_device *sdp = cmd->device; + +if (!(rq->rq_flags &RQF_SPECIAL_PAYLOAD )) +return ; + +if (sdp->sector_size >PAGE_SIZE ) +mempool_free (rq->special_vec.bv_page, sd_large_page_pool); +else +mempool_free (rq->special_vec.bv_page, sd_page_pool); + rq->rq_flags &= ~RQF_SPECIAL_PAYLOAD ; +} +static void *sd_set_special_bvec (struct scsi_cmnd *cmd,unsigned int data_len) {struct page *page;
@@ -951,6 +966,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));unsigned int data_len =24 ;char *buf; +blk_status_t ret; buf =sd_set_special_bvec (cmd, data_len);if (!buf)
@@ -969,7 +985,10 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) cmd->transfersize = data_len; rq->timeout =SD_TIMEOUT ; -return scsi_alloc_sgtables (cmd); + ret =scsi_alloc_sgtables (cmd); +if (ret !=BLK_STS_OK ) +sd_uninit_command (cmd); +return ret; }static void sd_config_atomic (struct scsi_disk *sdkp,struct queue_limits *lim)
@@ -1040,6 +1059,7 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,u64 lba =sectors_to_logical (sdp,blk_rq_pos (rq));u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; +blk_status_t ret;if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ;
@@ -1055,7 +1075,10 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, cmd->transfersize = data_len; rq->timeout = unmap ?SD_TIMEOUT :SD_WRITE_SAME_TIMEOUT ; -return scsi_alloc_sgtables (cmd); + ret =scsi_alloc_sgtables (cmd); +if (ret !=BLK_STS_OK ) +sd_uninit_command (cmd); +return ret; } static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
@@ -1067,6 +1090,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,u64 lba =sectors_to_logical (sdp,blk_rq_pos (rq));u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; +blk_status_t ret;if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ;
@@ -1082,7 +1106,10 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->transfersize = data_len; rq->timeout = unmap ?SD_TIMEOUT :SD_WRITE_SAME_TIMEOUT ; -return scsi_alloc_sgtables (cmd); + ret =scsi_alloc_sgtables (cmd); +if (ret !=BLK_STS_OK ) +sd_uninit_command (cmd); +return ret; }static blk_status_t sd_setup_write_zeroes_cmnd (struct scsi_cmnd *cmd)
@@ -1511,20 +1538,6 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd) } } -static void sd_uninit_command (struct scsi_cmnd *SCpnt) -{ -struct request *rq =scsi_cmd_to_rq (SCpnt); -struct scsi_device *sdp = SCpnt->device; -unsigned sector_size = sdp->sector_size; - -if (rq->rq_flags &RQF_SPECIAL_PAYLOAD ) { -if (sector_size >PAGE_SIZE ) -mempool_free (rq->special_vec.bv_page, sd_large_page_pool); -else -mempool_free (rq->special_vec.bv_page, sd_page_pool); - } -} -static bool sd_need_revalidate (struct gendisk *disk,struct scsi_disk *sdkp) {if (sdkp->device->removable || sdkp->write_prot) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 998/1518 scsi: sd: Fix sd_done() sense handling condition
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit a640d4546b11be5709a82bdc63d7dafd8ddc6c9e ]
Only enter the sense_key switch when the command returned CHECK CONDITION with valid, non-deferred sense. The old condition let deferred or invalid sense fall through and mis-handle the I/O.
--- drivers/scsi/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/sd.c +2 -2
@@ -2384,8 +2384,8 @@ static int sd_done(struct scsi_cmnd *SCpnt) } sdkp->medium_access_timed_out =0 ; -if (!scsi_status_is_check_condition (result) && - (!sense_valid || sense_deferred)) +if (!scsi_status_is_check_condition (result) || + !sense_valid || sense_deferred) goto out;switch (sshdr.sense_key) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 999/1518 btrfs: defrag: fix deadlock between defrag and delalloc space reservation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit ba02eab28041f9a4bbe9fc90c7249644fef6de0f ]
While running fsstress with autodefrag and flushoncommit, hit a deadlock due to the fact that defrag reserves delalloc space while it's holding dirty and locked folios, besides the extent range lock. The stack traces are the following:
[958.624] task:kworker/u50:3 state:D stack:0 pid:20365 tgid:20365 ppid:2 task_flags:0x4208060 flags:0x00080000 [958.626] Workqueue: events_unbound btrfs_async_reclaim_metadata_space [btrfs] [958.627] Call Trace: [958.628] <TASK> [958.628] __schedule+0x4be/0x10f0 [958.629] ? preempt_count_add+0x69/0xa0 [958.630] schedule+0x26/0xd0 [958.631] wait_current_trans+0x102/0x160 [btrfs] [958.632] ? __pfx_autoremove_wake_function+0x10/0x10 [958.633] start_transaction+0x374/0x900 [btrfs] [958.634] btrfs_commit_current_transaction+0x1d/0x70 [btrfs] [958.635] flush_space+0xca/0x5e0 [btrfs] [958.636] ? _raw_spin_unlock+0x15/0x30 [958.637] ? btrfs_reduce_alloc_profile+0x8c/0x190 [btrfs] [958.639] ? _raw_spin_unlock+0x15/0x30 [958.640] ? calc_available_free_space.isra.0+0x6f/0x110 [btrfs] [958.641] do_async_reclaim_metadata_space+0x84/0x190 [btrfs] [958.642] btrfs_async_reclaim_metadata_space+0x64/0x80 [btrfs] [958.644] process_one_work+0x19d/0x3a0 [958.644] worker_thread+0x1c4/0x330 [958.645] ? __pfx_worker_thread+0x10/0x10 [958.646] kthread+0xfc/0x130 [958.647] ? __pfx_kthread+0x10/0x10 [958.648] ret_from_fork+0x1f7/0x2c0 [958.648] ? __pfx_kthread+0x10/0x10 [958.649] ret_from_fork_asm+0x1a/0x30 [958.650] </TASK> [958.651] task:kworker/u49:7 state:D stack:0 pid:52990 tgid:52990 ppid:2 task_flags:0x4208060 flags:0x00080000 [958.653] Workqueue: writeback wb_workfn (flush-btrfs-334) [958.655] Call Trace: [958.655] <TASK> [958.656] __schedule+0x4be/0x10f0 [958.657] ? __blk_flush_plug+0xe9/0x140 [958.658] schedule+0x26/0xd0 [958.658] io_schedule+0x42/0x70 [958.659] folio_wait_bit_common+0x12b/0x330 [958.660] ? folio_wait_bit_common+0x100/0x330 [958.662] ? __pfx_wake_page_function+0x10/0x10 [958.663] extent_write_cache_pages+0x599/0x830 [btrfs] [958.664] ? acpi_fwnode_get_reference_args+0x1fa/0x270 [958.665] btrfs_writepages+0x77/0x130 [btrfs] [958.666] ? __pfx_end_bbio_data_write+0x10/0x10 [btrfs] [958.667] do_writepages+0xc6/0x160 [958.668] __writeback_single_inode+0x42/0x310 [958.669] writeback_sb_inodes+0x231/0x570 [958.670] wb_writeback+0x8a/0x340 [958.671] wb_workfn+0xbf/0x450 [958.672] ? finish_task_switch.isra.0+0xc1/0x350 [958.673] process_one_work+0x19d/0x3a0 [958.673] worker_thread+0x1c4/0x330 [958.674] ? __pfx_worker_thread+0x10/0x10 [958.675] kthread+0xfc/0x130 [958.676] ? __pfx_kthread+0x10/0x10 [958.676] ret_from_fork+0x1f7/0x2c0 [958.677] ? __pfx_kthread+0x10/0x10 [958.678] ret_from_fork_asm+0x1a/0x30 [958.679] </TASK> [958.679] task:btrfs-cleaner state:D stack:0 pid:296750 tgid:296750 ppid:2 task_flags:0x208040 flags:0x00080000 [958.681] Call Trace: [958.682] <TASK> [958.682] __schedule+0x4be/0x10f0 [958.683] schedule+0x26/0xd0 [958.684] handle_reserve_ticket+0x1b9/0x2c0 [btrfs] [958.685] ? __pfx_autoremove_wake_function+0x10/0x10 [958.686] reserve_bytes+0x283/0x4c0 [btrfs] [958.687] btrfs_reserve_metadata_bytes+0x18/0xb0 [btrfs] [958.688] btrfs_delalloc_reserve_metadata+0x121/0x320 [btrfs] [958.690] btrfs_delalloc_reserve_space+0x46/0xb0 [btrfs] [958.691] btrfs_defrag_file+0x903/0x1110 [btrfs] [958.692] btrfs_run_defrag_inodes+0x334/0x430 [btrfs] [958.694] cleaner_kthread+0x97/0x1c0 [btrfs] [958.694] ? __pfx_cleaner_kthread+0x10/0x10 [btrfs] [958.696] kthread+0xfc/0x130 [958.696] ? __pfx_kthread+0x10/0x10 [958.697] ret_from_fork+0x1f7/0x2c0 [958.698] ? __pfx_kthread+0x10/0x10 [958.699] ret_from_fork_asm+0x1a/0x30 [958.700] </TASK> [958.716] task:fsstress state:D stack:0 pid:296769 tgid:296769 ppid:296768 task_flags:0x400140 flags:0x00080000 [958.718] Call Trace: [958.719] <TASK> [958.719] __schedule+0x4be/0x10f0 [958.720] ? preempt_count_add+0x69/0xa0 [958.721] schedule+0x26/0xd0 [958.722] wb_wait_for_completion+0x79/0xc0 [958.723] ? __pfx_autoremove_wake_function+0x10/0x10 [958.724] __writeback_inodes_sb_nr+0xc5/0xf0 [958.725] try_to_writeback_inodes_sb+0x55/0x70 [958.726] btrfs_commit_transaction+0x19d/0xeb0 [btrfs] [958.727] ? start_transaction+0x343/0x900 [btrfs] [958.728] btrfs_mksubvol+0x28b/0x4e0 [btrfs] [958.729] btrfs_mksnapshot+0x74/0xa0 [btrfs] [958.730] __btrfs_ioctl_snap_create+0x194/0x210 [btrfs] [958.732] btrfs_ioctl_snap_create_v2+0xef/0x150 [btrfs] [958.733] btrfs_ioctl+0x7ec/0x2a70 [btrfs] [958.734] ? __virt_addr_valid+0xe4/0x180 [958.735] ? __check_object_size+0x1cd/0x1f0 [958.736] ? kmem_cache_free+0x146/0x380 [958.737] ? _raw_spin_unlock+0x15/0x30 [958.738] ? do_sys_openat2+0x83/0xd0 [958.739] __x64_sys_ioctl+0x92/0xe0 [958.740] do_syscall_64+0x60/0x590 [958.741] ? clear_bhb_loop+0x60/0xb0 [958.742] entry_SYSCALL_64_after_hwframe+0x76/0x7e [958.743] RIP: 0033:0x7f4431e108db [958.744] RSP: 002b:00007ffcd147db20 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [958.746] RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f4431e108db [958.747] RDX: 00007ffcd147eb90 RSI: 0000000050009417 RDI: 0000000000000005 [958.749] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 [958.751] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffcd147fbf0 [958.752] R13: 00007ffcd147eb90 R14: 0000000000000005 R15: 0000000000000003 [958.754] </TASK>
What happens is the following:
1) The cleaner kthread is running autodefrag, and in defrag_one_range() it acquired all the folios for the range and locked them.
Then it locked the extent range in the inode's iotree.
It got two subranges from defrag_collect_targets(), the first one with folio A and the second one with folio B.
After it defragged the first subrange, folio A remains locked and dirty - it's only unlocked when defrag_one_range() returns.
When it attempts to defrag the second subrange (containing folio B), btrfs_delalloc_reserve_space() creates a space reservation ticket, due to lack of free metadata space and blocks waiting for the async metadata reclaim task to free space and wake it up;
2) The async reclaim metadata task attempts to commit the current transaction, but it blocks because there is another task that started the commit first;
3) A task creating a snapshot is committing the transaction and because the fs was mounted with flushoncommit, it calls try_to_writeback_inodes_sb(), which spawns a task to flush delalloc and waits for it to complete;
4) The task flushing delalloc (kworker/u49:7), finds that folio A for the inode being defragged is dirty, so it tries to lock it...
But it blocks because folio A is locked by the defrag task (the cleaner kthread) which is blocked waiting for the reservation ticket to be served, but the async reclaim metadata task is blocked waiting for the transaction commit, which in turn is blocked waiting for the delalloc flush task, which is trying to lock folio A, resulting in a deadlock.
The same type of problem can happen if the async reclaim task starts to flush delalloc, as that requires both locking the folio and the extent range in the inode's io tree, and in this case we don't need the fs to be mounted with flushoncommit. This type of problem has ocurred several times in the past with reflinks for example, where we had a dirty folio while holding the extent range locked and then starting a transaction blocked waiting for the async reclaim task due to lack of free metadata space.
So fix this by reserving delalloc space before locking folios and locking the extent range in the inode's iotree. We can not simply unlock the folios for each subrange given by defrag_collect_targets() after we defrag it because the same folio may be present too in the next subrange (due to large folios).
--- fs/btrfs/defrag.c | 50 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-)
fs/btrfs/defrag.c +33 -17
@@ -1150,20 +1150,15 @@ static_assert(PAGE_ALIGNED(CLUSTER_SIZE));* * - Extent bits are locked */ -static int defrag_one_locked_target (struct btrfs_inode *inode, -struct defrag_target_range *target, -struct folio **folios,int nr_pages, -struct extent_state **cached_state) +static void defrag_one_locked_target (struct btrfs_inode *inode, +struct defrag_target_range *target, +struct folio **folios,int nr_pages, +struct extent_state **cached_state) {struct btrfs_fs_info *fs_info = inode->root->fs_info; -struct extent_changeset *data_reserved =NULL ;const u64 start = target->start;const u64 len = target->len; -int ret =0 ; - ret =btrfs_delalloc_reserve_space (inode, &data_reserved, start, len); -if (ret <0 ) -return ret;btrfs_clear_extent_bit (&inode->io_tree, start, start + len -1 ,EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING |EXTENT_DEFRAG , cached_state);
@@ -1184,10 +1179,6 @@ static int defrag_one_locked_target(struct btrfs_inode *inode,btrfs_folio_clamp_clear_checked (fs_info, folio, start, len);btrfs_folio_clamp_set_dirty (fs_info, folio, start, len); } -btrfs_delalloc_release_extents (inode, len); -extent_changeset_free (data_reserved); - -return ret; } static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
@@ -1203,6 +1194,8 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,u64 cur = start;const unsigned int nr_pages = ((start + len -1 ) >>PAGE_SHIFT ) - (start >>PAGE_SHIFT ) +1 ; +struct extent_changeset *data_reserved =NULL ; +u64 last_defrag_end = start;int ret =0 ;ASSERT (nr_pages <=CLUSTER_SIZE /PAGE_SIZE );
@@ -1212,6 +1205,22 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,if (!folios)return -ENOMEM ; +/* +* Reserve delalloc space before locking the range and before locking +* and dirtying any folios - otherwise we could deadlock, for example +* after defrag of one range we dirty folios and keep them locked when +* we move to the next range, so reserving delalloc space right before +* each range could trigger flushing of delalloc and deadlock on the +* extent lock or trigger a transaction commit with flushoncommit, which +* can either deadlock on the lock of a folio made dirty in the previous +* range or the extent lock. +*/ + ret =btrfs_delalloc_reserve_space (inode, &data_reserved, start, len); +if (ret <0 ) { +kfree (folios); +return ret; + } +/* Prepare all pages */ for (int i =0 ; cur < start + len && i < nr_pages; i++) { folios[i] =defrag_prepare_one_folio (inode, cur >>PAGE_SHIFT );
@@ -1246,10 +1255,11 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len, goto unlock_extent;list_for_each_entry (entry, &target_list, list) { - ret =defrag_one_locked_target (inode, entry, folios, nr_pages, - &cached_state); -if (ret <0 ) -break ; +defrag_one_locked_target (inode, entry, folios, nr_pages, &cached_state); +if (entry->start > last_defrag_end) +btrfs_delalloc_release_space (inode, data_reserved, last_defrag_end, + entry->start - last_defrag_end, true); + last_defrag_end = entry->start + entry->len; }list_for_each_entry_safe (entry, tmp, &target_list, list) {
@@ -1266,6 +1276,12 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,folio_put (folios[i]); }kfree (folios); +btrfs_delalloc_release_extents (inode, len); +if (last_defrag_end < start + len) +btrfs_delalloc_release_space (inode, data_reserved, last_defrag_end, + start + len - last_defrag_end, true); +extent_changeset_free (data_reserved); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1000/1518 btrfs: make btrfs_repair_io_failure() handle bs > ps cases without large folios
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 2574e9011018a1d6d3da8d03d0bfc4e2675dee2a ]
Currently btrfs_repair_io_failure() only accept a single @paddr parameter, and for bs > ps cases it's required that @paddr is backed by a large folio.
That assumption has quite some limitations, preventing us from utilizing true zero-copy direct-io and encoded read/writes.
To address the problem, enhance btrfs_repair_io_failure() by:
- Accept an array of paddrs, up to 64K / PAGE_SIZE entries This kind of acts like a bio_vec, but with very limited entries, as the function is only utilized to repair one fs data block, or a tree block.
Both have an upper size limit (BTRFS_MAX_BLOCK_SIZE, i.e. 64K), so we don't need the full bio_vec thing to handle it.
- Allocate a bio with multiple slots
Previously even for bs > ps cases, we only passed in a contiguous physical address range, thus a single slot will be enough.
But not anymore, so we have to allocate a bio structure, other than using the on-stack one.
- Use on-stack memory to allocate @paddrs array
It's at most 16 pages (4K page size, 64K block size), will take up at most 128 bytes.
I think the on-stack cost is still acceptable.
- Add one extra check to make sure the repair bio is exactly one block
- Utilize btrfs_repair_io_failure() to submit a single bio for metadata This should improve the read-repair performance for metadata, as now we submit a node sized bio then wait, other than submit each block of the metadata and wait for each submitted block.
- Add one extra parameter indicating the step
This is due to the fact that metadata step can be as large as nodesize, instead of sectorsize.
So we need a way to distinguish metadata and data repair.
- Reduce the width of @length parameter of btrfs_repair_io_failure() Since we only call btrfs_repair_io_failure() on a single data or metadata block, u64 is overkilled.
Use u32 instead and add one extra ASSERT()s to make sure the length never exceed BTRFS_MAX_BLOCK_SIZE.
Stable-dep-of: ec78575dde99 ("btrfs: always wait for ordered extents to avoid OE races")
--- fs/btrfs/bio.c | 68 ++++++++++++++++++++++++++++++++++++---------- fs/btrfs/bio.h | 5 ++-- fs/btrfs/disk-io.c | 31 +++++++++++++-------- 3 files changed, 76 insertions(+), 28 deletions(-)
fs/btrfs/bio.c +54 -14
@@ -172,7 +172,21 @@ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio,struct btrfs_inode *inode = repair_bbio->inode;struct btrfs_fs_info *fs_info = inode->root->fs_info;struct bio_vec *bv =bio_first_bvec_all (&repair_bbio->bio); +/* +* We can not move forward the saved_iter, as it will be later +* utilized by repair_bbio again. +*/ +struct bvec_iter saved_iter = repair_bbio->saved_iter; +const u32 step =min (fs_info->sectorsize,PAGE_SIZE ); +const u64 logical = repair_bbio->saved_iter.bi_sector <<SECTOR_SHIFT ; +const u32 nr_steps = repair_bbio->saved_iter.bi_size / step;int mirror = repair_bbio->mirror_num; +phys_addr_t paddrs[BTRFS_MAX_BLOCKSIZE /PAGE_SIZE ]; +phys_addr_t paddr; +unsigned int slot =0 ; + +/* Repair bbio should be eaxctly one block sized. */ +ASSERT (repair_bbio->saved_iter.bi_size == fs_info->sectorsize);if (repair_bbio->bio.bi_status || !btrfs_data_csum_ok (repair_bbio, dev,0 ,bvec_phys (bv))) {
@@ -190,12 +204,17 @@ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio,return ; } +btrfs_bio_for_each_block (paddr, &repair_bbio->bio, &saved_iter, step) { +ASSERT (slot < nr_steps); + paddrs[slot] = paddr; + slot++; + } +do { mirror =prev_repair_mirror (fbio, mirror);btrfs_repair_io_failure (fs_info,btrfs_ino (inode), repair_bbio->file_offset, fs_info->sectorsize, - repair_bbio->saved_iter.bi_sector <<SECTOR_SHIFT , -bvec_phys (bv), mirror); + logical, paddrs, step, mirror); }while (mirror != fbio->bbio->mirror_num); done:
@@ -865,18 +884,36 @@ void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num)* * The I/O is issued synchronously to block the repair read completion from * freeing the bio. +* +* @ino: Offending inode number +* @fileoff: File offset inside the inode +* @length: Length of the repair write +* @logical: Logical address of the range +* @paddrs: Physical address array of the content +* @step: Length of for each paddrs +* @mirror_num: Mirror number to write to. Must not be zero */ -int btrfs_repair_io_failure (struct btrfs_fs_info *fs_info,u64 ino,u64 start, -u64 length,u64 logical,phys_addr_t paddr,int mirror_num) +int btrfs_repair_io_failure (struct btrfs_fs_info *fs_info,u64 ino,u64 fileoff, +u32 length,u64 logical,const phys_addr_t paddrs[], +unsigned int step,int mirror_num) { +const u32 nr_steps =DIV_ROUND_UP_POW2 (length, step);struct btrfs_io_stripe smap = {0 }; -struct bio_vec bvec; -struct bio bio; +struct bio *bio =NULL ;int ret =0 ;ASSERT (!(fs_info->sb->s_flags &SB_RDONLY ));BUG_ON (!mirror_num); +/* Basic alignment checks. */ +ASSERT (IS_ALIGNED (logical, fs_info->sectorsize)); +ASSERT (IS_ALIGNED (length, fs_info->sectorsize)); +ASSERT (IS_ALIGNED (fileoff, fs_info->sectorsize)); +/* Either it's a single data or metadata block. */ +ASSERT (length <=BTRFS_MAX_BLOCKSIZE ); +ASSERT (step <= length); +ASSERT (is_power_of_2 (step)); +if (btrfs_repair_one_zone (fs_info, logical))return 0 ;
@@ -896,24 +933,27 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, goto out_counter_dec; } -bio_init (&bio, smap.dev->bdev, &bvec,1 ,REQ_OP_WRITE |REQ_SYNC ); - bio.bi_iter.bi_sector = smap.physical >>SECTOR_SHIFT ; -__bio_add_page (&bio,phys_to_page (paddr), length,offset_in_page (paddr)); - ret =submit_bio_wait (&bio); + bio =bio_alloc (smap.dev->bdev, nr_steps,REQ_OP_WRITE |REQ_SYNC ,GFP_NOFS ); + bio->bi_iter.bi_sector = smap.physical >>SECTOR_SHIFT ; +for (int i =0 ; i < nr_steps; i++) { + ret =bio_add_page (bio,phys_to_page (paddrs[i]), step,offset_in_page (paddrs[i])); +/* We should have allocated enough slots to contain all the different pages. */ +ASSERT (ret == step); + } + ret =submit_bio_wait (bio); +bio_put (bio);if (ret) {/* try to remap that extent elsewhere? */ btrfs_dev_stat_inc_and_print (smap.dev,BTRFS_DEV_STAT_WRITE_ERRS ); - goto out_bio_uninit; + goto out_counter_dec; }btrfs_info_rl (fs_info,"read error corrected: ino %llu off %llu (dev %s sector %llu)" , - ino, start,btrfs_dev_name (smap.dev), + ino, fileoff,btrfs_dev_name (smap.dev), smap.physical >>SECTOR_SHIFT ); ret =0 ; -out_bio_uninit: -bio_uninit (&bio); out_counter_dec:btrfs_bio_counter_dec (fs_info);return ret;
fs/btrfs/bio.h +3 -2
@@ -127,7 +127,8 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);void btrfs_submit_bbio (struct btrfs_bio *bbio,int mirror_num);void btrfs_submit_repair_write (struct btrfs_bio *bbio,int mirror_num,bool dev_replace); -int btrfs_repair_io_failure (struct btrfs_fs_info *fs_info,u64 ino,u64 start, -u64 length,u64 logical,phys_addr_t paddr,int mirror_num); +int btrfs_repair_io_failure (struct btrfs_fs_info *fs_info,u64 ino,u64 fileoff, +u32 length,u64 logical,const phys_addr_t paddrs[], +unsigned int step,int mirror_num);#endif
fs/btrfs/disk-io.c +19 -12
@@ -183,26 +183,33 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num) {struct btrfs_fs_info *fs_info = eb->fs_info; +const u32 step =min (fs_info->nodesize,PAGE_SIZE ); +const u32 nr_steps = eb->len / step; +phys_addr_t paddrs[BTRFS_MAX_BLOCKSIZE /PAGE_SIZE ];int ret =0 ;if (sb_rdonly (fs_info->sb))return -EROFS ; -for (int i =0 ; i <num_extent_folios (eb); i++) { +for (int i =0 ; i <num_extent_pages (eb); i++) {struct folio *folio = eb->folios[i]; -u64 start =max_t (u64, eb->start,folio_pos (folio)); -u64 end =min_t (u64, eb->start + eb->len, -folio_pos (folio) + eb->folio_size); -u32 len = end - start; -phys_addr_t paddr =PFN_PHYS (folio_pfn (folio)) + -offset_in_folio (folio, start); - - ret =btrfs_repair_io_failure (fs_info,0 , start, len, start, - paddr, mirror_num); -if (ret) -break ; + +/* No large folio support yet. */ +ASSERT (folio_order (folio) ==0 ); +ASSERT (i < nr_steps); + +/* +* For nodesize < page size, there is just one paddr, with some +* offset inside the page. +* +* For nodesize >= page size, it's one or more paddrs, and eb->start +* must be aligned to page boundary. +*/ + paddrs[i] =page_to_phys (&folio->page) +offset_in_page (eb->start); } + ret =btrfs_repair_io_failure (fs_info,0 , eb->start, eb->len, eb->start, + paddrs, step, mirror_num);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1001/1518 btrfs: merge setting ret and return ret
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Sterba <[email protected]>
[ Upstream commit 4b117be65ff41efae3694df449b9badb4e9d142e ]
In many places we have pattern:
ret = ...; return ret;
This can be simplified to a direct return, removing 'ret' if not otherwise needed. The places in self tests are not converted so we can add more test cases without changing surrounding code (extent-map-tests.c:test_case_4()).
Stable-dep-of: ec78575dde99 ("btrfs: always wait for ordered extents to avoid OE races")
--- fs/btrfs/block-group.c | 3 +-- fs/btrfs/ctree.c | 3 +-- fs/btrfs/delayed-inode.c | 4 ++-- fs/btrfs/disk-io.c | 13 +++++-------- fs/btrfs/extent-io-tree.c | 7 ++----- fs/btrfs/extent-tree.c | 10 +++------- fs/btrfs/file.c | 3 +-- fs/btrfs/free-space-tree.c | 4 +--- fs/btrfs/inode-item.c | 7 +++---- fs/btrfs/inode.c | 13 ++++--------- fs/btrfs/qgroup.c | 14 ++++---------- fs/btrfs/relocation.c | 5 ++--- fs/btrfs/volumes.c | 9 +++------ 13 files changed, 32 insertions(+), 63 deletions(-)
fs/btrfs/block-group.c +1 -2
@@ -1057,8 +1057,7 @@ static int remove_block_group_item(struct btrfs_trans_handle *trans,if (ret <0 )return ret; - ret =btrfs_del_item (trans, root, path); -return ret; +return btrfs_del_item (trans, root, path); } int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
fs/btrfs/ctree.c +1 -2
@@ -3990,8 +3990,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,if (ret)return ret; - ret =split_item (trans, path, new_key, split_offset); -return ret; +return split_item (trans, path, new_key, split_offset); }/*
fs/btrfs/delayed-inode.c +2 -2
@@ -1140,8 +1140,8 @@ __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, ret =btrfs_record_root_in_trans (trans, node->root);if (ret)return ret; - ret =btrfs_update_delayed_inode (trans, node->root, path, node); -return ret; + +return btrfs_update_delayed_inode (trans, node->root, path, node); }/*
fs/btrfs/disk-io.c +5 -8
@@ -186,7 +186,6 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,const u32 step =min (fs_info->nodesize,PAGE_SIZE );const u32 nr_steps = eb->len / step;phys_addr_t paddrs[BTRFS_MAX_BLOCKSIZE /PAGE_SIZE ]; -int ret =0 ;if (sb_rdonly (fs_info->sb))return -EROFS ;
@@ -208,9 +207,8 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, paddrs[i] =page_to_phys (&folio->page) +offset_in_page (eb->start); } - ret =btrfs_repair_io_failure (fs_info,0 , eb->start, eb->len, eb->start, - paddrs, step, mirror_num); -return ret; +return btrfs_repair_io_failure (fs_info,0 , eb->start, eb->len, + eb->start, paddrs, step, mirror_num); }/*
@@ -2190,11 +2188,10 @@ static int load_global_roots(struct btrfs_root *tree_root)return ret;if (!btrfs_fs_compat_ro (tree_root->fs_info,FREE_SPACE_TREE ))return ret; - ret =load_global_roots_objectid (tree_root, path, -BTRFS_FREE_SPACE_TREE_OBJECTID , -"free space" ); -return ret; +return load_global_roots_objectid (tree_root, path, +BTRFS_FREE_SPACE_TREE_OBJECTID , +"free space" ); }static int btrfs_read_roots (struct btrfs_fs_info *fs_info)
fs/btrfs/extent-io-tree.c +2 -5
@@ -187,8 +187,6 @@ static int add_extent_changeset(struct extent_state *state, u32 bits, struct extent_changeset *changeset, int set) { - int ret; -if (!changeset)return 0 ;if (set && (state->state & bits) == bits)
@@ -196,9 +194,8 @@ static int add_extent_changeset(struct extent_state *state, u32 bits,if (!set && (state->state & bits) ==0 )return 0 ; changeset->bytes_changed += state->end - state->start +1 ; - ret =ulist_add (&changeset->range_changed, state->start, state->end, -GFP_ATOMIC ); -return ret; + +return ulist_add (&changeset->range_changed, state->start, state->end,GFP_ATOMIC ); }static inline struct extent_state *next_state (struct extent_state *state)
fs/btrfs/extent-tree.c +3 -7
@@ -2557,7 +2557,6 @@ static u64 get_alloc_profile_by_root(struct btrfs_root *root, int data) {struct btrfs_fs_info *fs_info = root->fs_info;u64 flags; -u64 ret;if (data) flags =BTRFS_BLOCK_GROUP_DATA ;
@@ -2566,8 +2565,7 @@ static u64 get_alloc_profile_by_root(struct btrfs_root *root, int data)else flags =BTRFS_BLOCK_GROUP_METADATA ; - ret =btrfs_get_alloc_profile (fs_info, flags); -return ret; +return btrfs_get_alloc_profile (fs_info, flags); }static u64 first_logical_byte (struct btrfs_fs_info *fs_info)
@@ -4192,10 +4190,8 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,else trans =btrfs_join_transaction (root); -if (IS_ERR (trans)) { - ret =PTR_ERR (trans); -return ret; - } +if (IS_ERR (trans)) +return PTR_ERR (trans); ret =btrfs_chunk_alloc (trans, space_info, ffe_ctl->flags,CHUNK_ALLOC_FORCE_FOR_EXTENT );
fs/btrfs/file.c +1 -2
@@ -1267,8 +1267,7 @@ static int copy_one_range(struct btrfs_inode *inode, struct iov_iter *iter,btrfs_delalloc_release_extents (inode, reserved_len);release_space (inode, *data_reserved, reserved_start, reserved_len, only_release_metadata); - ret = extents_locked; -return ret; +return extents_locked; } copied = copy_folio_from_iter_atomic(folio, offset_in_folio(folio, start),
fs/btrfs/free-space-tree.c +1 -3
@@ -1533,9 +1533,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,btrfs_release_path (path); } - ret =0 ; - -return ret; +return 0 ; } static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
fs/btrfs/inode-item.c +3 -4
@@ -371,14 +371,13 @@ int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, struct btrfs_path *path, u64 objectid) {struct btrfs_key key; -int ret; + key.objectid = objectid; key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; - ret =btrfs_insert_empty_item (trans, root, path, &key, -sizeof (struct btrfs_inode_item )); -return ret; +return btrfs_insert_empty_item (trans, root, path, &key, +sizeof (struct btrfs_inode_item )); } int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
fs/btrfs/inode.c +4 -9
@@ -2348,7 +2348,6 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct folio *locked_fol u64 start, u64 end, struct writeback_control *wbc) { const bool zoned = btrfs_is_zoned(inode->root->fs_info); -int ret;/* * The range must cover part of the @locked_folio, or a return of 1
@@ -2356,10 +2355,8 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct folio *locked_fol*/ ASSERT (!(end <=folio_pos (locked_folio) || start >=folio_end (locked_folio))); -if (should_nocow (inode, start, end)) { - ret =run_delalloc_nocow (inode, locked_folio, start, end); -return ret; - } +if (should_nocow (inode, start, end)) +return run_delalloc_nocow (inode, locked_folio, start, end); if (btrfs_inode_can_compress(inode) && inode_need_compress(inode, start, end) &&
@@ -2367,11 +2364,9 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct folio *locked_folreturn 1 ;if (zoned) - ret =run_delalloc_cow (inode, locked_folio, start, end, wbc, - true); +return run_delalloc_cow (inode, locked_folio, start, end, wbc, true);else - ret =cow_file_range (inode, locked_folio, start, end,NULL ,0 ); -return ret; +return cow_file_range (inode, locked_folio, start, end,NULL ,0 ); } void btrfs_split_delalloc_extent(struct btrfs_inode *inode,
fs/btrfs/qgroup.c +4 -10
@@ -694,7 +694,6 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info)static int add_qgroup_relation_item (struct btrfs_trans_handle *trans,u64 src,u64 dst) { -int ret;struct btrfs_root *quota_root = trans->fs_info->quota_root;BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key;
@@ -707,8 +706,7 @@ static int add_qgroup_relation_item(struct btrfs_trans_handle *trans, u64 src, key.type =BTRFS_QGROUP_RELATION_KEY ; key.offset = dst; - ret =btrfs_insert_empty_item (trans, quota_root, path, &key,0 ); -return ret; +return btrfs_insert_empty_item (trans, quota_root, path, &key,0 ); } static int del_qgroup_relation_item(struct btrfs_trans_handle *trans, u64 src,
@@ -833,9 +831,7 @@ static int del_qgroup_item(struct btrfs_trans_handle *trans, u64 qgroupid)if (ret >0 )return -ENOENT ; - ret =btrfs_del_item (trans, quota_root, path); - -return ret; +return btrfs_del_item (trans, quota_root, path); } static int update_qgroup_limit_item(struct btrfs_trans_handle *trans,
@@ -2682,10 +2678,8 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,return ret; } -if (root_level ==0 ) { - ret =btrfs_qgroup_trace_leaf_items (trans, root_eb); -return ret; - } +if (root_level ==0 ) +return btrfs_qgroup_trace_leaf_items (trans, root_eb); path =btrfs_alloc_path ();if (!path)
fs/btrfs/relocation.c +2 -3
@@ -3266,7 +3266,6 @@ static int delete_v1_space_cache(struct extent_buffer *leaf,struct btrfs_key key;bool found = false;int i; -int ret;if (btrfs_header_owner (leaf) !=BTRFS_ROOT_TREE_OBJECTID )return 0 ;
@@ -3290,8 +3289,8 @@ static int delete_v1_space_cache(struct extent_buffer *leaf, }if (!found)return -ENOENT ; - ret =delete_block_group_cache (block_group,NULL , space_cache_ino); -return ret; + +return delete_block_group_cache (block_group,NULL , space_cache_ino); }/*
fs/btrfs/volumes.c +3 -6
@@ -2456,9 +2456,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,free_fs_devices (cur_devices); } - ret =btrfs_commit_transaction (trans); - -return ret; +return btrfs_commit_transaction (trans); error_undo:if (test_bit (BTRFS_DEV_STATE_WRITEABLE , &device->dev_state)) {
@@ -7347,7 +7345,6 @@ static int read_one_dev(struct extent_buffer *leaf,struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;struct btrfs_device *device;u64 devid; -int ret;u8 fs_uuid[BTRFS_FSID_SIZE ];u8 dev_uuid[BTRFS_UUID_SIZE ];
@@ -7446,8 +7443,8 @@ static int read_one_dev(struct extent_buffer *leaf,atomic64_add (device->total_bytes - device->bytes_used, &fs_info->free_chunk_space); } - ret =0 ; -return ret; + +return 0 ; }int btrfs_read_sys_array (struct btrfs_fs_info *fs_info)
Signature · 1 line
2.53.0