From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C26AEC43381 for ; Thu, 21 Feb 2019 19:11:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EA5B2081B for ; Thu, 21 Feb 2019 19:11:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N41qrcWj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbfBUTLF (ORCPT ); Thu, 21 Feb 2019 14:11:05 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:47485 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbfBUTLE (ORCPT ); Thu, 21 Feb 2019 14:11:04 -0500 Received: by mail-qt1-f202.google.com with SMTP id m34so27527017qtb.14 for ; Thu, 21 Feb 2019 11:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=6aLtBLA8i6O+7ipm+shj7xyc26jvMISxWOQZkIWRoEQ=; b=N41qrcWjCZhtEV3gFuuBWGt/QnrHL7p3iffkWLyWa7GHUUn8vuQtLZSNBfAespYSma LwTvPUAAFWK29P9cNu+RE2bSCHlQfwRLxwtW7UnqFFixgqlygMrEt4eG1RDtSsajggoS 8GZuISarsNseYTP1Mw/M7dI06yUrImbC4uYpOhhPI0XCPI3BsMyOiZp1mHe8uQDbgJaR /oq3IpiXIodJ5dGWVPt4Vjd3+HP2+6vZhKoG7LuxK5kRQYqjbaxbtJ5wZsBdTyXKLUxs p92i1LOaqun9Z0FcVRswjV00m6a/gTduBhKapu6iooLXStYY7AHEj+ADzNqfMPsGjXLl i/nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=6aLtBLA8i6O+7ipm+shj7xyc26jvMISxWOQZkIWRoEQ=; b=JcTlN50OY/vx6/dV3Gt2zAG3pU4or/uqW35DD3TJWG8ClVYjVEfFvBAxT6kbEh9x03 RoFxXIe7GxtJOo0+c5slwulVCm9eW8qOlZOhheQe9/qN34Srq1cCusXr13EdiCCgqTtA mkD4cc2b9hQTZYAj31dQdQqaWdT3tYppMj/9f30omBa4f1gp1UFgfb8ut5/MXSXAVpGH kQ4bxBEHbtwb5mWDg+z2uEIM0r5sAijLHn3tzYedOVoRsKJKJgUMwacDh2nYOGVsSmYL 2EaybHV9m3RwAdPQp+8jS5KuvhyUFmcU7DBLFTyTfoPESO+tgi9LalsuxxH+A+xHf/dH vkkQ== X-Gm-Message-State: AHQUAuZqy8Yie3S04QEqfxhFtm2c8EqX2WnY4xnjDHQBpJqhww2FybxC S+Kowz1QmFdrglVv63Y5hk4bdng6q8tDY2/nHxtGb1x6F6HsUyoqv2PhCVPAiQbRql4DYTV8SKp aJtzZE+73oCRpUJfu6ARUpFBBTZBwiKcDYX5Hsoc+yjbaILYIQzRAlQ== X-Google-Smtp-Source: AHgI3Ibo9HkxBWFwFGmoZXT2sPuv5HZXRSJ5cWenSdgGUMpwLVqqlqOv8NweinLzAZbGNPJ5h2jYpDo= X-Received: by 2002:a0c:bd83:: with SMTP id n3mr37406qvg.5.1550776263538; Thu, 21 Feb 2019 11:11:03 -0800 (PST) Date: Thu, 21 Feb 2019 11:11:00 -0800 Message-Id: <20190221191100.84147-1-sdf@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH bpf-next] selftests/bpf: make sure signal interrupts BPF_PROG_TEST_RUN From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net, Stanislav Fomichev Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Simple test that I used to reproduce the issue in the previous commit: Do BPF_PROG_TEST_RUN with max iterations, each program is 4096 simple move instructions. File alarm in 0.1 second and check that bpf_prog_test_run is interrupted (i.e. test doesn't hang). Note: reposting this for bpf-next to avoid linux-next conflict. In this version I test both BPF_PROG_TYPE_SOCKET_FILTER (which uses generic bpf_test_run implementation) and BPF_PROG_TYPE_FLOW_DISSECTOR (which has it own loop with preempt handling in bpf_prog_test_run_flow_dissector). Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/test_progs.c | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index c52bd90fbb34..c59d2e015d16 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -12,6 +12,7 @@ #include #include #include +#include #include typedef __u16 __sum16; @@ -28,6 +29,7 @@ typedef __u16 __sum16; #include #include #include +#include #include #include #include @@ -2108,6 +2110,46 @@ static void test_map_lock(void) bpf_object__close(obj); } +static void sigalrm_handler(int s) {} +static struct sigaction sigalrm_action = { + .sa_handler = sigalrm_handler, +}; + +static void test_signal_pending(enum bpf_prog_type prog_type) +{ + struct bpf_insn prog[4096]; + struct itimerval timeo = { + .it_value.tv_usec = 100000, /* 100ms */ + }; + __u32 duration, retval; + int prog_fd; + int err; + int i; + + for (i = 0; i < ARRAY_SIZE(prog); i++) + prog[i] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0); + prog[ARRAY_SIZE(prog) - 1] = BPF_EXIT_INSN(); + + prog_fd = bpf_load_program(prog_type, prog, ARRAY_SIZE(prog), + "GPL", 0, NULL, 0); + CHECK(prog_fd < 0, "test-run", "errno %d\n", errno); + + err = sigaction(SIGALRM, &sigalrm_action, NULL); + CHECK(err, "test-run-signal-sigaction", "errno %d\n", errno); + + err = setitimer(ITIMER_REAL, &timeo, NULL); + CHECK(err, "test-run-signal-timer", "errno %d\n", errno); + + err = bpf_prog_test_run(prog_fd, 0xffffffff, &pkt_v4, sizeof(pkt_v4), + NULL, NULL, &retval, &duration); + CHECK(duration > 500000000, /* 500ms */ + "test-run-signal-duration", + "duration %dns > 500ms\n", + duration); + + signal(SIGALRM, SIG_DFL); +} + int main(void) { srand(time(NULL)); @@ -2138,6 +2180,8 @@ int main(void) test_flow_dissector(); test_spinlock(); test_map_lock(); + test_signal_pending(BPF_PROG_TYPE_SOCKET_FILTER); + test_signal_pending(BPF_PROG_TYPE_FLOW_DISSECTOR); printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt); return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS; -- 2.21.0.rc0.258.g878e2cd30e-goog