Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3881941ybf; Tue, 3 Mar 2020 14:58:58 -0800 (PST) X-Google-Smtp-Source: ADFU+vsmSkBUG5Nl+TPFS3OEO3p2Kn8E3TP7/vrQ4zstQDI4gK6jxdVY9x1XF2q1qMQUnaFDPetp X-Received: by 2002:a9d:7a96:: with SMTP id l22mr131106otn.217.1583276338057; Tue, 03 Mar 2020 14:58:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583276338; cv=none; d=google.com; s=arc-20160816; b=JCDSU3o05EE05SV5m5kcoqwojei9okIm2rr+BMI1B1dsCAT2j7ogIdkBkJDb/vw+fw 2n4/2kurUzYcDD5qZSR4D6XdKxwd3N2iHSnY4mchO2n9p1vWXzCKRUvCfcSH8yoUKOTL Tx/VQ9JQMnuAyqsGfAJQckZAjQl24oaeQ238kJadlMD+KXCRaITJU+6QIpAK/DF/Wltu 3mNkMv0AQ/pSze9RO55IpkyQtEErwdQHx9xnmNXyamar20RV2iI4r9aWOzDGb+WHLDNe aS9rk4cIXALD11Rr+dCuUCvUjMsZ/P/ScL6aIH2UsMY7kmD5Whl9lKyv0p1dBhfVFGLp kwRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MVFYEvw2qmu2jM88Am2H9EOrofn0f8G79RS7/47Djvw=; b=XHJrAxeSgJglQz7bDldTBIIkXzKJWPY6FuZZhbeIwyEp3W6JGq3pyou+nFQbMqEj/0 YwVHV3fpf0Ju155q5uRSGLaDO8Fe/GVSmAAx0A+jAWp/oB/SbaiuCtXTEy8jHMi75xG4 FegjyOm7TFamuWzK+fXQcKyOy1AE7lkgRjcdgkvLa563axpyDyOLHDYXhd0tVjg1qwaf k3D9Fv5dsp1nhdYZ4PbM8PYl+WoOpfRAZF0SZ3JyfLOlTcu6dGQ0KWTLzvxrNVJbOdI8 Ai7APgnOY0TRzJ3ZiLoaLfsEV4GNuHn8rgExT5Xyb4sErOzJe51rSmBts5u+gzWyF40g Pgcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p35GXZsr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si101816oic.246.2020.03.03.14.58.45; Tue, 03 Mar 2020 14:58:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p35GXZsr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728057AbgCCW6g (ORCPT + 99 others); Tue, 3 Mar 2020 17:58:36 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:42413 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726766AbgCCW6g (ORCPT ); Tue, 3 Mar 2020 17:58:36 -0500 Received: by mail-qt1-f195.google.com with SMTP id r6so4211491qtt.9; Tue, 03 Mar 2020 14:58:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MVFYEvw2qmu2jM88Am2H9EOrofn0f8G79RS7/47Djvw=; b=p35GXZsro4kgDGA4OL3xpE8wVBACG2zcivDJEEmOjk4iBGk0GcUCCKvnQECPEV8cvA VByffr11Tv27u/bWfF3IW/f+SZzmahnrKflrXv6s3gSv6bM/q/yTFPBEJWo+BiUdNPId 09Sp8bH9KmPMrySdX4sVtcLAvUo32k6E4dY9SDL/e5Et0088Fspfa/H4Wu5963I9Ab1N 7c1OKGIbNTfryC2vBxUxvF09ZhggSRchL9yeAfqS0EQMzQidy1hEH+C8SmJmBtJlJydy Rpm3/y5FujPuq8l25YwTn5BwW/Y/YD5GhXBqxMzNHGhSHDVGnK+zmM/Ajs4Bpc2M+jNs l0Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MVFYEvw2qmu2jM88Am2H9EOrofn0f8G79RS7/47Djvw=; b=eQqN6R6m0jD2DG6D2tVmGcAAkGMHkXyi2zMjqdDTdf6Es1GPByRV8O/gl+gP+c2fop Tz2JNxhyG8qqZz2vfC3omLCBs6jejl4qgAjoEsBKoSq+yZBocQfw1/aVy9/62Lps5lWa PVahghMoXXGk9n+jVXqOWrzE2xZ7+wOlxjJk4jXnyFWqFoZotuo73FjRPyLb47krSU8n +FbmXWEhKOxOoXGuZCq3VJeZLp98mbuWqvCSFeoXWtk8SKWympTKwi2UDbqzUMFv5TOj SfK4ruN/DCuzaZlcMt7uPk7FIdg5eBYdFu5NsI9AZjuzyuV19QgpoRnqBvN9VyU/l7Lf 1X5g== X-Gm-Message-State: ANhLgQ12MEWgwd0ZzqUnfouionPmXdf6O9kdUVb/8Htl9ZUlZVrxQbbr /9m2/cM905kXo3aJkg1jZ0EmohJwBv4THfoqRzE= X-Received: by 2002:ac8:4581:: with SMTP id l1mr6512031qtn.59.1583276315171; Tue, 03 Mar 2020 14:58:35 -0800 (PST) MIME-Version: 1.0 References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-8-kpsingh@chromium.org> In-Reply-To: <20200303140950.6355-8-kpsingh@chromium.org> From: Andrii Nakryiko Date: Tue, 3 Mar 2020 14:58:20 -0800 Message-ID: Subject: Re: [PATCH bpf-next 7/7] bpf: Add selftests for BPF_MODIFY_RETURN To: KP Singh Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 3, 2020 at 6:13 AM KP Singh wrote: > > From: KP Singh > > Test for two scenarios: > > * When the fmod_ret program returns 0, the original function should > be called along with fentry and fexit programs. > * When the fmod_ret program returns a non-zero value, the original > function should not be called, no side effect should be observed and > fentry and fexit programs should be called. > > The result from the kernel function call and whether a side-effect is > observed is returned via the retval attr of the BPF_PROG_TEST_RUN (bpf) > syscall. > > Signed-off-by: KP Singh > --- minor nits only Acked-by: Andrii Nakryiko > net/bpf/test_run.c | 23 ++++++- > .../selftests/bpf/prog_tests/modify_return.c | 65 +++++++++++++++++++ > .../selftests/bpf/progs/modify_return.c | 49 ++++++++++++++ > 3 files changed, 135 insertions(+), 2 deletions(-) > create mode 100644 tools/testing/selftests/bpf/prog_tests/modify_return.c > create mode 100644 tools/testing/selftests/bpf/progs/modify_return.c > [...] > > - return 0; > + retval = (u32)side_effect << 16 | ret; uhm, I didn't look up operator priority table, but I'd rather have () around bit shift operation :) > + if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) > + goto out; > > + return 0; > out: > trace_bpf_test_finish(&err); > return err; > diff --git a/tools/testing/selftests/bpf/prog_tests/modify_return.c b/tools/testing/selftests/bpf/prog_tests/modify_return.c > new file mode 100644 > index 000000000000..beab9a37f35c > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/modify_return.c > @@ -0,0 +1,65 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * Copyright 2020 Google LLC. > + */ > + > +#include > +#include "modify_return.skel.h" > + > +#define LOWER(x) (x & 0xffff) > +#define UPPER(x) (x >> 16) pedantic nit: (x) instead of just x > + > + [...]