Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'Two fixes for test_sockmap'

Zijian Zhang says:

====================
Function msg_verify_data should have context of bytes_cnt and k instead of
assuming they are zero. Otherwise, test_sockmap with data integrity test
will report some errors. I also fix the logic related to size and index j

1/ 6 sockmap::txmsg test passthrough:FAIL
2/ 6 sockmap::txmsg test redirect:FAIL
7/12 sockmap::txmsg test apply:FAIL
10/11 sockmap::txmsg test push_data:FAIL
11/17 sockmap::txmsg test pull-data:FAIL
12/ 9 sockmap::txmsg test pop-data:FAIL
13/ 1 sockmap::txmsg test push/pop data:FAIL
...
Pass: 24 Fail: 52

After fixing msg_verify_data, some of the errors are solved, but for push
pull and pop, we may need more fixes to msg_verify_data, added a TODO

10/11 sockmap::txmsg test push_data:FAIL
11/17 sockmap::txmsg test pull-data:FAIL
12/ 9 sockmap::txmsg test pop-data:FAIL
...
Pass: 37 Fail: 15

Besides, added a custom errno EDATAINTEGRITY for msg_verify_data, we
shall not ignore the error in txmsg_cork case, and fixed the txmsg_redir
in test_txmsg_pull "Test pull + redirect" case.
====================

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

+21 -11
+21 -11
tools/testing/selftests/bpf/test_sockmap.c
··· 56 56 #define BPF_SOCKHASH_FILENAME "test_sockhash_kern.bpf.o" 57 57 #define CG_PATH "/sockmap" 58 58 59 + #define EDATAINTEGRITY 2001 60 + 59 61 /* global sockets */ 60 62 int s1, s2, c1, c2, p1, p2; 61 63 int test_cnt; ··· 512 510 return -ENOMEM; 513 511 } 514 512 515 - static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz) 513 + /* TODO: Add verification logic for push, pull and pop data */ 514 + static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz, 515 + unsigned char *k_p, int *bytes_cnt_p) 516 516 { 517 - int i, j = 0, bytes_cnt = 0; 518 - unsigned char k = 0; 517 + int i, j, bytes_cnt = *bytes_cnt_p; 518 + unsigned char k = *k_p; 519 519 520 - for (i = 0; i < msg->msg_iovlen; i++) { 520 + for (i = 0, j = 0; i < msg->msg_iovlen && size; i++, j = 0) { 521 521 unsigned char *d = msg->msg_iov[i].iov_base; 522 522 523 523 /* Special case test for skb ingress + ktls */ 524 524 if (i == 0 && txmsg_ktls_skb) { 525 525 if (msg->msg_iov[i].iov_len < 4) 526 - return -EIO; 526 + return -EDATAINTEGRITY; 527 527 if (memcmp(d, "PASS", 4) != 0) { 528 528 fprintf(stderr, 529 529 "detected skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n", 530 530 i, 0, d[0], d[1], d[2], d[3]); 531 - return -EIO; 531 + return -EDATAINTEGRITY; 532 532 } 533 533 j = 4; /* advance index past PASS header */ 534 534 } ··· 540 536 fprintf(stderr, 541 537 "detected data corruption @iov[%i]:%i %02x != %02x, %02x ?= %02x\n", 542 538 i, j, d[j], k - 1, d[j+1], k); 543 - return -EIO; 539 + return -EDATAINTEGRITY; 544 540 } 545 541 bytes_cnt++; 546 542 if (bytes_cnt == chunk_sz) { ··· 550 546 size--; 551 547 } 552 548 } 549 + *k_p = k; 550 + *bytes_cnt_p = bytes_cnt; 553 551 return 0; 554 552 } 555 553 ··· 608 602 float total_bytes, txmsg_pop_total; 609 603 int fd_flags = O_NONBLOCK; 610 604 struct timeval timeout; 605 + unsigned char k = 0; 606 + int bytes_cnt = 0; 611 607 fd_set w; 612 608 613 609 fcntl(fd, fd_flags); ··· 704 696 iov_length * cnt : 705 697 iov_length * iov_count; 706 698 707 - errno = msg_verify_data(&msg, recv, chunk_sz); 699 + errno = msg_verify_data(&msg, recv, chunk_sz, &k, &bytes_cnt); 708 700 if (errno) { 709 701 perror("data verify msg failed"); 710 702 goto out_errno; ··· 712 704 if (recvp) { 713 705 errno = msg_verify_data(&msg_peek, 714 706 recvp, 715 - chunk_sz); 707 + chunk_sz, 708 + &k, 709 + &bytes_cnt); 716 710 if (errno) { 717 711 perror("data verify msg_peek failed"); 718 712 goto out_errno; ··· 822 812 s.bytes_sent, sent_Bps, sent_Bps/giga, 823 813 s.bytes_recvd, recvd_Bps, recvd_Bps/giga, 824 814 peek_flag ? "(peek_msg)" : ""); 825 - if (err && txmsg_cork) 815 + if (err && err != -EDATAINTEGRITY && txmsg_cork) 826 816 err = 0; 827 817 exit(err ? 1 : 0); 828 818 } else if (rxpid == -1) { ··· 1606 1596 test_send_large(opt, cgrp); 1607 1597 1608 1598 /* Test pull + redirect */ 1609 - txmsg_redir = 0; 1599 + txmsg_redir = 1; 1610 1600 txmsg_start = 1; 1611 1601 txmsg_end = 2; 1612 1602 test_send(opt, cgrp);