From patchwork Tue Apr 9 05:18:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13621832 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C26A433C8; Tue, 9 Apr 2024 05:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712639941; cv=none; b=cO7Kiu6PjvEkcC5rbwvjiPpYx/XEQM1wm9MxeovX/pkX0gWh2M535uI+WZkqjIZh3Ls+I8qDjS7y/msGwpluOThEhyPWiL7ymiiHIavJrVwesyQEw0qoezgpspJ6F1M6MrOk4sp/jtN5EeiZQYWiFcY3EWNLkefis9iGKm5UGtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712639941; c=relaxed/simple; bh=kyRs5Dn9q/PNdmhzLdwShhMh1tHoLcJ0NKrgF3iBslc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FCaQbodeSS4szT3nfP20CdXEBKr24ydXD3Z2eKGtKu/QQiLId5Pvw5ZV3PI5Nv3FnWWM12KPFaa50+tnLMYJNkL9h0uhhNZlWfIw9IRlaslVmLpTml8rHTvZ4O3D3F7P/vFih+Xv4jCRVI79Z6dSgZeZW4Kg7igOta+nYKNRnZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j4zxdDrb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j4zxdDrb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABDA7C433B1; Tue, 9 Apr 2024 05:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712639940; bh=kyRs5Dn9q/PNdmhzLdwShhMh1tHoLcJ0NKrgF3iBslc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j4zxdDrb30t/BfTJVbH/HEn8hNk5nibvtpXUGI+P5yR6Hm0QRU/0UrD6ebiaV0tnO NZR384P0Wx1bJ3gjmNK/fKI5D7/awuA/C7my1N6rkKZYfWTM6+PesjHS3obW4GwBxW X4GS6auxGe6THmsHf9Q3QZMVCA7rZKL+reYn4FEd8/3JLqYSgnw0bRlbbWBaexxz2x tf3crndEKn7IZB8DiB6coCOUdIxH7no8nRqlVDfSqYQv3ioZUKarplMVcgF5edSMdN s53HYHVH1xcIeTLtFJszC1YzTmV5Wbv0GTSbWNNnpJDpwXJtGlRfK2JdsPjxnkg4rK jTfb5ayxORjQw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jakub Sitnicki Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [PATCH bpf v4 1/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap Date: Tue, 9 Apr 2024 13:18:39 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Incorrect arguments are passed to fcntl() in test_sockmap.c when invoking it to set file status flags. If O_NONBLOCK is used as 2nd argument and passed into fcntl, -EINVAL will be returned (See do_fcntl() in fs/fcntl.c). The correct approach is to use F_SETFL as 2nd argument, and O_NONBLOCK as 3rd one. In nonblock mode, if EWOULDBLOCK is received, continue receiving, otherwise some subtests of test_sockmap fail. Fixes: 16962b2404ac ("bpf: sockmap, add selftests") Signed-off-by: Geliang Tang Acked-by: Yonghong Song --- tools/testing/selftests/bpf/test_sockmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 024a0faafb3b..4feed253fca2 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -603,7 +603,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, struct timeval timeout; fd_set w; - fcntl(fd, fd_flags); + if (fcntl(fd, F_SETFL, fd_flags)) + goto out_errno; + /* Account for pop bytes noting each iteration of apply will * call msg_pop_data helper so we need to account for this * by calculating the number of apply iterations. Note user @@ -678,6 +680,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, perror("recv failed()"); goto out_errno; } + continue; } s->bytes_recvd += recv;