Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp514384pxb; Fri, 28 Jan 2022 04:20:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLpuxbR8ehC3UougJdNsT0FfXcw10BATcxENsmktx4GnyDHRk8rKq52ZAKFk8AXqQtA1B6 X-Received: by 2002:a17:907:1c0f:: with SMTP id nc15mr6573164ejc.673.1643372423691; Fri, 28 Jan 2022 04:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643372423; cv=none; d=google.com; s=arc-20160816; b=wiHXEEHosZIlXuMYOobcUB8hayB1vfhqsVTbCM9J2W/cEjUdJcDqaMrusduO6w+N+s NgWAAjmhL6QuWCg7altSopUNbyL97nYQdZ5WXv4FRnLkAfTXShaZFVLFDZj/bTpX97vQ PKEnz1t/vSJ7TCnzrM+tV6EGJ5RxZ9SJm7OtThKJrUxr5ImMP7Dkz7HehkwWIOHINeXk o74g58/td/jxbcp5WYlgTDdUKipLEPnisVrfyZLAFfYCMJS4VBd+hXNX2Guk+2tJaZK6 YQDa6HWRtN6d3/bSJ+gnJbeijc/yy7jwUJEWVh11vmzCKyxikjQmwDh6roSSgLTTy8qE CK8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to:subject :cc:to:from:user-agent:references:dkim-signature; bh=Xawp1TwtSo/uo/1tbPqTEzWBuDJ4Y6t+ZX2/4mqpc+o=; b=sul1Ktgok3cVgnCiucR1yQlkf7XHVyKEjxE9py47XRJdkXd5AE8oW+987rBPLEyd25 gFgIGTLszdwfqsQTiAEYnh1tphpFXI36EFqCvmo9xwPZP1pG4e2MYgRpRv3VDSiovVxk aF2A91kJnfG+cpjUOS8AMKZ/hNsr6UZrAp1bvuPwVi3K1Y3ry7E9Ym4au5tWtfJrDVSO sEiRlPLVL01RB4ME4QD4WvnWOEhqgAcbCHwLG0jyI+nIWW+2RHRZSnvuWxo7uYTlrcpd KWUWOwPp8+Hpi9lvDKuFly64pGekCuqi7fyzTiep8zDsmu9VcqFMGoIxm/ITVmVZbHcv /U2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=tvJb51SK; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b10si3380437ejj.216.2022.01.28.04.19.59; Fri, 28 Jan 2022 04:20:23 -0800 (PST) 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=@cloudflare.com header.s=google header.b=tvJb51SK; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244635AbiA0Rbx (ORCPT + 99 others); Thu, 27 Jan 2022 12:31:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244622AbiA0Rbx (ORCPT ); Thu, 27 Jan 2022 12:31:53 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BB2EC061747 for ; Thu, 27 Jan 2022 09:31:52 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id u6so6728754lfm.10 for ; Thu, 27 Jan 2022 09:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=Xawp1TwtSo/uo/1tbPqTEzWBuDJ4Y6t+ZX2/4mqpc+o=; b=tvJb51SK9pl9ihres+CxFmedKvEw9bFtuhVR5WdFnCRdDOTuIEMwabJE1kAZ5hmw9k TY28PIoWYpejGKA2zB6kDzlh6wFuzsVoFcRWRbXhVTVQpUv2RpezpOw6Qi8k28/x3LhM 1bZMx1x/Kw8Ieybgn5Lyl7NsR1ymit5pUoq6I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=Xawp1TwtSo/uo/1tbPqTEzWBuDJ4Y6t+ZX2/4mqpc+o=; b=IwpijtzdnFHD7jgIglFae0a3NRqqzS7ea0N+VC1OkdBPkRs01v/RfEYfTizLzeUxp3 +zW3Y8f67ur0E1tvA+NpzAwhuVyzqB2XcCn5vWUwbfB1Bvcqkwjyp75HfaX+JGEBcVFH /nkSSiZskBbMNnWLAAc6E0HKq15YpUYVw/wLRRDOwEoYWvxCXJRpBANbdR00AqO8XkO/ t6daERN7lZ5LEF+wuKVkrDtcdwwsUwoHsfdLiyFvgxAATTmFWKtXCkz79LwU5IbhPdNe 184DydI7K9J6ACe6z/rZ2MBKCbTVY9cIIWxN3ku5MNIIKC6T5pALP90SBS017stgy8ux 6e3Q== X-Gm-Message-State: AOAM532+kaXv8jpu9UGY5T3fvshZLiJ4C1roikazxNd2A4mUkcsLNPDY u/zj0gAu7rHwjaKsnDURSKJr2g== X-Received: by 2002:a05:6512:3408:: with SMTP id i8mr3356039lfr.17.1643304710661; Thu, 27 Jan 2022 09:31:50 -0800 (PST) Received: from cloudflare.com ([2a01:110f:4809:d800::e00]) by smtp.gmail.com with ESMTPSA id i1sm958936ljn.39.2022.01.27.09.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 09:31:49 -0800 (PST) References: <20220113070245.791577-1-imagedong@tencent.com> <87sftbobys.fsf@cloudflare.com> <20220125224524.fkodqvknsluihw74@kafai-mbp.dhcp.thefacebook.com> <20220125235320.fx775qsdtqon272v@kafai-mbp.dhcp.thefacebook.com> User-agent: mu4e 1.1.0; emacs 27.2 From: Jakub Sitnicki To: Martin KaFai Lau Cc: Alexei Starovoitov , Menglong Dong , Alexei Starovoitov , "Daniel Borkmann" , Andrii Nakryiko , "Song Liu" , Yonghong Song , John Fastabend , KP Singh , "Network Development" , bpf , LKML , Mengen Sun , flyingpeng@tencent.com, mungerjiang@tencent.com, Menglong Dong Subject: Re: [PATCH bpf-next] bpf: Add document for 'dst_port' of 'struct bpf_sock' In-reply-to: <20220125235320.fx775qsdtqon272v@kafai-mbp.dhcp.thefacebook.com> Date: Thu, 27 Jan 2022 18:31:48 +0100 Message-ID: <8735l9rsor.fsf@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 26, 2022 at 12:53 AM CET, Martin KaFai Lau wrote: > On Tue, Jan 25, 2022 at 03:02:37PM -0800, Alexei Starovoitov wrote: >> On Tue, Jan 25, 2022 at 2:45 PM Martin KaFai Lau wrote: >> > >> > On Tue, Jan 25, 2022 at 08:24:27PM +0100, Jakub Sitnicki wrote: >> > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h >> > > > index b0383d371b9a..891a182a749a 100644 >> > > > --- a/include/uapi/linux/bpf.h >> > > > +++ b/include/uapi/linux/bpf.h >> > > > @@ -5500,7 +5500,11 @@ struct bpf_sock { >> > > > __u32 src_ip4; >> > > > __u32 src_ip6[4]; >> > > > __u32 src_port; /* host byte order */ >> > > > - __u32 dst_port; /* network byte order */ >> > > > + __u32 dst_port; /* low 16-bits are in network byte order, >> > > > + * and high 16-bits are filled by 0. >> > > > + * So the real port in host byte order is >> > > > + * bpf_ntohs((__u16)dst_port). >> > > > + */ >> > > > __u32 dst_ip4; >> > > > __u32 dst_ip6[4]; >> > > > __u32 state; >> > > >> > > I'm probably missing something obvious, but is there anything stopping >> > > us from splitting the field, so that dst_ports is 16-bit wide? >> > > >> > > I gave a quick check to the change below and it seems to pass verifier >> > > checks and sock_field tests. >> > > >> > > IDK, just an idea. Didn't give it a deeper thought. >> > > >> > > --8<-- >> > > >> > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h >> > > index 4a2f7041ebae..344d62ccafba 100644 >> > > --- a/include/uapi/linux/bpf.h >> > > +++ b/include/uapi/linux/bpf.h >> > > @@ -5574,7 +5574,8 @@ struct bpf_sock { >> > > __u32 src_ip4; >> > > __u32 src_ip6[4]; >> > > __u32 src_port; /* host byte order */ >> > > - __u32 dst_port; /* network byte order */ >> > > + __u16 unused; >> > > + __u16 dst_port; /* network byte order */ >> > This will break the existing bpf prog. >> >> I think Jakub's idea is partially expressed: >> + case offsetof(struct bpf_sock, dst_port): >> + bpf_ctx_record_field_size(info, sizeof(__u16)); >> + return bpf_ctx_narrow_access_ok(off, size, sizeof(__u16)); >> >> Either 'unused' needs to be after dst_port or >> bpf_sock_is_valid_access() needs to allow offset at 'unused' >> and at 'dst_port'. >> And allow u32 access though the size is actually u16. >> Then the existing bpf progs (without recompiling) should work? > Yes, I think that should work with the existing bpf progs. > I suspect putting 'dst_port' first and then followed by 'unused' > may be easier. That will also serve as a natural doc for the > current behavior (the value is in the lower 16 bits). You're right. I can't count. Now fixed in [1]. > > It can be extended to bpf_sk_lookup? bpf_sk_lookup can read at any > offset of these 4 bytes, so may need to read 0 during > convert_ctx_accesses? Let's see what the feedback to [1] will be. [1] https://lore.kernel.org/bpf/20220127172448.155686-1-jakub@cloudflare.com/T/#t