netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@kernel.org>
To: shaozhengchao <shaozhengchao@huawei.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"ast@kernel.org" <ast@kernel.org>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"hawk@kernel.org" <hawk@kernel.org>,
	"john.fastabend@gmail.com" <john.fastabend@gmail.com>,
	"andrii@kernel.org" <andrii@kernel.org>,
	"kafai@fb.com" <kafai@fb.com>,
	"songliubraving@fb.com" <songliubraving@fb.com>,
	"yhs@fb.com" <yhs@fb.com>,
	"kpsingh@kernel.org" <kpsingh@kernel.org>
Cc: "weiyongjun (A)" <weiyongjun1@huawei.com>,
	yuehaibing <yuehaibing@huawei.com>
Subject: Re: 答复: [PATCH v5,bpf-next] samples/bpf: check detach prog exist or not in xdp_fwd
Date: Thu, 02 Jun 2022 12:16:16 +0200	[thread overview]
Message-ID: <87leufs74f.fsf@toke.dk> (raw)
In-Reply-To: <f7e88b843e964632919c8efe16368786@huawei.com>

shaozhengchao <shaozhengchao@huawei.com> writes:

> -----邮件原件-----
> 发件人: Toke Høiland-Jørgensen [mailto:toke@kernel.org] 
> 发送时间: 2022年6月2日 16:55
> 收件人: shaozhengchao <shaozhengchao@huawei.com>; bpf@vger.kernel.org; netdev@vger.kernel.org; linux-kernel@vger.kernel.org; ast@kernel.org; daniel@iogearbox.net; davem@davemloft.net; kuba@kernel.org; hawk@kernel.org; john.fastabend@gmail.com; andrii@kernel.org; kafai@fb.com; songliubraving@fb.com; yhs@fb.com; kpsingh@kernel.org
> 抄送: weiyongjun (A) <weiyongjun1@huawei.com>; shaozhengchao <shaozhengchao@huawei.com>; yuehaibing <yuehaibing@huawei.com>
> 主题: Re: [PATCH v5,bpf-next] samples/bpf: check detach prog exist or not in xdp_fwd
>
> Zhengchao Shao <shaozhengchao@huawei.com> writes:
>
>> Before detach the prog, we should check detach prog exist or not.
>>
>> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
>
> You missed one 'return errno', see below:
>
>> ---
>>  samples/bpf/xdp_fwd_user.c | 55 
>> +++++++++++++++++++++++++++++++++-----
>>  1 file changed, 49 insertions(+), 6 deletions(-)
>>
>> diff --git a/samples/bpf/xdp_fwd_user.c b/samples/bpf/xdp_fwd_user.c 
>> index 1828487bae9a..d321e6aa9364 100644
>> --- a/samples/bpf/xdp_fwd_user.c
>> +++ b/samples/bpf/xdp_fwd_user.c
>> @@ -47,17 +47,60 @@ static int do_attach(int idx, int prog_fd, int map_fd, const char *name)
>>  	return err;
>>  }
>>  
>> -static int do_detach(int idx, const char *name)
>> +static int do_detach(int ifindex, const char *ifname, const char 
>> +*app_name)
>>  {
>> -	int err;
>> +	LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
>> +	struct bpf_prog_info prog_info = {};
>> +	char prog_name[BPF_OBJ_NAME_LEN];
>> +	__u32 info_len, curr_prog_id;
>> +	int prog_fd;
>> +	int err = 1;
>> +
>> +	if (bpf_xdp_query_id(ifindex, xdp_flags, &curr_prog_id)) {
>> +		printf("ERROR: bpf_xdp_query_id failed (%s)\n",
>> +		       strerror(errno));
>> +		return err;
>> +	}
>>  
>> -	err = bpf_xdp_detach(idx, xdp_flags, NULL);
>> -	if (err < 0)
>> -		printf("ERROR: failed to detach program from %s\n", name);
>> +	if (!curr_prog_id) {
>> +		printf("ERROR: flags(0x%x) xdp prog is not attached to %s\n",
>> +		       xdp_flags, ifname);
>> +		return err;
>> +	}
>>  
>> +	info_len = sizeof(prog_info);
>> +	prog_fd = bpf_prog_get_fd_by_id(curr_prog_id);
>> +	if (prog_fd < 0) {
>> +		printf("ERROR: bpf_prog_get_fd_by_id failed (%s)\n",
>> +		       strerror(errno));
>> +		return errno;
>
> This should just be ' return prog_fd ' to propagate the error...
>
> -Toke
>
>
> Hi Toke:
> 	Use 'return prog_fd' instead of 'return errno' first. And Which
> position missed one 'return errno'?

Ah, no, that's the one I was talking about; I meant "missed one" as in
"missed removing one of them", not "a return errno was missing but
should be there"; so just changing that one to 'return prog_fd' should
and I think we should be good :)

-Toke

      reply	other threads:[~2022-06-02 10:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02  1:19 [PATCH v5,bpf-next] samples/bpf: check detach prog exist or not in xdp_fwd Zhengchao Shao
2022-06-02  8:55 ` Toke Høiland-Jørgensen
2022-06-02  9:59   ` 答复: " shaozhengchao
2022-06-02 10:16     ` Toke Høiland-Jørgensen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87leufs74f.fsf@toke.dk \
    --to=toke@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shaozhengchao@huawei.com \
    --cc=songliubraving@fb.com \
    --cc=weiyongjun1@huawei.com \
    --cc=yhs@fb.com \
    --cc=yuehaibing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).