Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
Merge branch 'Two fixes for test_sockmap'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin KaFai Lau committed Oct 16, 2024
2 parents 4a6f05d + b29e231 commit 9115825
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tools/testing/selftests/bpf/test_sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ static void running_handler(int a);
#define BPF_SOCKHASH_FILENAME "test_sockhash_kern.bpf.o"
#define CG_PATH "/sockmap"

#define EDATAINTEGRITY 2001

/* global sockets */
int s1, s2, c1, c2, p1, p2;
int test_cnt;
Expand Down Expand Up @@ -510,23 +512,25 @@ static int msg_alloc_iov(struct msghdr *msg,
return -ENOMEM;
}

static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz)
/* TODO: Add verification logic for push, pull and pop data */
static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz,
unsigned char *k_p, int *bytes_cnt_p)
{
int i, j = 0, bytes_cnt = 0;
unsigned char k = 0;
int i, j, bytes_cnt = *bytes_cnt_p;
unsigned char k = *k_p;

for (i = 0; i < msg->msg_iovlen; i++) {
for (i = 0, j = 0; i < msg->msg_iovlen && size; i++, j = 0) {
unsigned char *d = msg->msg_iov[i].iov_base;

/* Special case test for skb ingress + ktls */
if (i == 0 && txmsg_ktls_skb) {
if (msg->msg_iov[i].iov_len < 4)
return -EIO;
return -EDATAINTEGRITY;
if (memcmp(d, "PASS", 4) != 0) {
fprintf(stderr,
"detected skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n",
i, 0, d[0], d[1], d[2], d[3]);
return -EIO;
return -EDATAINTEGRITY;
}
j = 4; /* advance index past PASS header */
}
Expand All @@ -536,7 +540,7 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz)
fprintf(stderr,
"detected data corruption @iov[%i]:%i %02x != %02x, %02x ?= %02x\n",
i, j, d[j], k - 1, d[j+1], k);
return -EIO;
return -EDATAINTEGRITY;
}
bytes_cnt++;
if (bytes_cnt == chunk_sz) {
Expand All @@ -546,6 +550,8 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz)
size--;
}
}
*k_p = k;
*bytes_cnt_p = bytes_cnt;
return 0;
}

Expand Down Expand Up @@ -602,6 +608,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
float total_bytes, txmsg_pop_total;
int fd_flags = O_NONBLOCK;
struct timeval timeout;
unsigned char k = 0;
int bytes_cnt = 0;
fd_set w;

fcntl(fd, fd_flags);
Expand Down Expand Up @@ -696,15 +704,17 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
iov_length * cnt :
iov_length * iov_count;

errno = msg_verify_data(&msg, recv, chunk_sz);
errno = msg_verify_data(&msg, recv, chunk_sz, &k, &bytes_cnt);
if (errno) {
perror("data verify msg failed");
goto out_errno;
}
if (recvp) {
errno = msg_verify_data(&msg_peek,
recvp,
chunk_sz);
chunk_sz,
&k,
&bytes_cnt);
if (errno) {
perror("data verify msg_peek failed");
goto out_errno;
Expand Down Expand Up @@ -812,7 +822,7 @@ static int sendmsg_test(struct sockmap_options *opt)
s.bytes_sent, sent_Bps, sent_Bps/giga,
s.bytes_recvd, recvd_Bps, recvd_Bps/giga,
peek_flag ? "(peek_msg)" : "");
if (err && txmsg_cork)
if (err && err != -EDATAINTEGRITY && txmsg_cork)
err = 0;
exit(err ? 1 : 0);
} else if (rxpid == -1) {
Expand Down Expand Up @@ -1596,7 +1606,7 @@ static void test_txmsg_pull(int cgrp, struct sockmap_options *opt)
test_send_large(opt, cgrp);

/* Test pull + redirect */
txmsg_redir = 0;
txmsg_redir = 1;
txmsg_start = 1;
txmsg_end = 2;
test_send(opt, cgrp);
Expand Down

0 comments on commit 9115825

Please sign in to comment.