Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1551815pxj; Sat, 29 May 2021 18:21:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhsdbTjGgF3WfhPI/coucVDKuPLHlFZTw3+5DtVQHNRj6/dllGaawGxc9zL1erZV/QNJ1R X-Received: by 2002:a17:906:eb10:: with SMTP id mb16mr16137448ejb.209.1622337676910; Sat, 29 May 2021 18:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622337676; cv=none; d=google.com; s=arc-20160816; b=xQudhXQCs4JfqrKkrIewA/3tWEjXuGXhFquAWS1RXF2b86LICHvrOIsy3mIkA4OSrh 7ziimj5xqoMrLhZ+PvMsyXVqc6yCTH/lSCw37kcUYXV78ql4xgzsv9Kjc0/UFWMBh1ky SbtO6P3ixWdyoozirAq4b+nkGuKjJITbQ0JvXBxGpS6iuV6TQZFI/R/O4KpxnEVqdA7c SSpD5mBRhk4XkglEH45yCkhxwt/4rG2Yt04qgqYhhYbCGEWu0bDPxs4Wu/PQKMoroL0F lqt7xn9S7SRMLpTe4HY4TcimBBLvdtJZH1Dr2uJl8tkTnftXTMDkJm2BuurSP7m0TRjb +YDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EShTowP+tcGQc64UEUm7RFR1I6QAAde0tBd7WGQUDHU=; b=s43ey3wycE218niNSDeD5G04zfzGhANqQ9Sr9gTSpci7KYBpJ+23H4UNEvq5MsvQUF EwozMn4SLwIHAQy1kpXDVtZ9etnqcWSh+O3pbLKpzxtG6vka8L2fyfX/Ad56P+CraiLw SZGzlO3dL0hZTyJ2cui6gZ8gLHsAmXYqow1/ambPl1bQ36dZ/osbQamnbZTGj29uKdd6 8MnkfpXmVf+oxBhHMUibyXUGTWo0jOPTCYIhScdwsRTgXkRNZvjgHhfyeypwC1PCpIJ/ nKFHOCsDYdLC0iioWygr5Fs8kg7NjADRnNUSkef1U55Orv2Kcst2SYRAS6xXI1OtK7XI 9CxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bERr68h3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id 8si3326092ejx.753.2021.05.29.18.20.43; Sat, 29 May 2021 18:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bERr68h3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229599AbhE3BTR (ORCPT + 99 others); Sat, 29 May 2021 21:19:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbhE3BTQ (ORCPT ); Sat, 29 May 2021 21:19:16 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47879C061574; Sat, 29 May 2021 18:17:38 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id e10so11176922ybb.7; Sat, 29 May 2021 18:17:38 -0700 (PDT) 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=EShTowP+tcGQc64UEUm7RFR1I6QAAde0tBd7WGQUDHU=; b=bERr68h3M1lPtCuT5MqAaBxQYaj08o9pQFt4J8fsdTic10ZQzbEILATI1iDVmWaeMF XlvkfDNQmyVgKZEJd9JWTmswBHhJaM20+uziII9fA7B0RQIK8zhI0nieFZeHuLPHPfiP Fbs5l8E898go62Ldlb+nkOqzXrR/vU0oInsEnpPTsje/NJ6HQIxNHBt56n2UCHh1zqqZ m/512POl1kzr2xXPX1xNCPI4lWNaGecXFhEJPWT9ebYW3tAFmnFmk6T/USK7hs+CEXvc cxwWSI6nDjjHjfqMDXRwm6SoLlria2Yxps7vTNAcmVQ5u1JXee5h99LVl9Ai4WDNaWzS UHzA== 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=EShTowP+tcGQc64UEUm7RFR1I6QAAde0tBd7WGQUDHU=; b=TyYCMJZn1UTfyiLyaVRzI2ilE1Om0Ohm+I+5BVnEmp1vYa5kdgoWXrTsHJpMq0ueH0 ulIY2+5Qqz7R/eyh7rUIJnGYch2a1TLi/9rTJJ25YdR9hd21/v6oWO9I3Q2s1WtZ1anK iO797nywPGYnkk/4Yy5h1t0K8nFMTZ9IVrMW9CNj5VCyD3Ki3zTnhpamHdWKZakvBU6+ KT2ZOVRiGrEoTj2/j4trigD9H9VAb3tNQwKa+HL3K/TbArhkKsRKJvWploYgaI875Ewu 7HjqWQR4G0basLNJQC84BiglQAjChPY4ffnQ+LS6N+1WZFfShmUx+ZNizWeNWZXRSO8O 0uig== X-Gm-Message-State: AOAM532ttnm8EgsyUGRB+aPrKojLVin+VovXz8C84InKgqsMcUeJVvzc iJhxzX2yIrYGkr6/Q80/8zQKuplJdXvqvv64cm8= X-Received: by 2002:a25:ba06:: with SMTP id t6mr20910655ybg.459.1622337457232; Sat, 29 May 2021 18:17:37 -0700 (PDT) MIME-Version: 1.0 References: <20210528090758.1108464-1-yukuai3@huawei.com> In-Reply-To: From: Andrii Nakryiko Date: Sat, 29 May 2021 18:17:26 -0700 Message-ID: Subject: Re: [PATCH] selftests/bpf: Fix return value check in attach_bpf() To: "yukuai (C)" Cc: Daniel Borkmann , Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , "open list:KERNEL SELFTEST FRAMEWORK" , Networking , bpf , open list , yi.zhang@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 28, 2021 at 6:25 PM yukuai (C) wrote: > > On 2021/05/29 4:46, Daniel Borkmann wrote: > > On 5/28/21 11:07 AM, Yu Kuai wrote: > >> use libbpf_get_error() to check the return value of > >> bpf_program__attach(). > >> > >> Reported-by: Hulk Robot > >> Signed-off-by: Yu Kuai > >> --- > >> tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/tools/testing/selftests/bpf/benchs/bench_rename.c > >> b/tools/testing/selftests/bpf/benchs/bench_rename.c > >> index c7ec114eca56..b7d4a1d74fca 100644 > >> --- a/tools/testing/selftests/bpf/benchs/bench_rename.c > >> +++ b/tools/testing/selftests/bpf/benchs/bench_rename.c > >> @@ -65,7 +65,7 @@ static void attach_bpf(struct bpf_program *prog) > >> struct bpf_link *link; > >> link = bpf_program__attach(prog); > >> - if (!link) { > >> + if (libbpf_get_error(link)) { > >> fprintf(stderr, "failed to attach program!\n"); > >> exit(1); > >> } > > > > Could you explain the rationale of this patch? bad2e478af3b > > ("selftests/bpf: Turn > > on libbpf 1.0 mode and fix all IS_ERR checks") explains: 'Fix all the > > explicit > > IS_ERR checks that now will be broken because libbpf returns NULL on > > error (and > > sets errno).' So the !link check looks totally reasonable to me. > > Converting to > > libbpf_get_error() is not wrong in itself, but given you don't make any > > use of > > the err code, there is also no point in this diff here. > Hi, > > I was thinking that bpf_program__attach() can return error code > theoretically(for example -ESRCH), and such case need to be handled. > I explicitly changed to NULL check + libbpf 1.0 error reporting mode because I don't care about specific error in benchmarks. So as Daniel and John pointed out, existing code is correct and doesn't need adjustment. You are right, though, that error code is indeed returned, but you can check errno directly (but need to enable libbpf 1.0 mode) or use libbpf_get_error() (which will get deprecated some time before libbpf 1.0) if you don't know which mode your code will be run in. > Thanks, > Yu Kuai > > > > Thanks, > > Daniel > > . > >