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=-7.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED 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 E4F50C43381 for ; Sat, 23 Feb 2019 07:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B8B0206B6 for ; Sat, 23 Feb 2019 07:31:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="m/UMG+LE"; dkim=pass (1024-bit key) header.d=fb.onmicrosoft.com header.i=@fb.onmicrosoft.com header.b="A5n6vcwy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725881AbfBWHbD (ORCPT ); Sat, 23 Feb 2019 02:31:03 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:36778 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725785AbfBWHbC (ORCPT ); Sat, 23 Feb 2019 02:31:02 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x1N7S2xp001459; Fri, 22 Feb 2019 23:30:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=hYajj+I/YH0tXuBNoiXzTqGEVePZzKIjHMq9uQrBZjM=; b=m/UMG+LElyJqxbUr6eInZLvo2HjKyXkXWdsmeiPT4Hbr7BR1Df/xUI5CnszOoGgEz+MI vnekhSuWl3+9SfDCxfwBgvlNALERqRtuFh25JqTmLpQVBaRM+Yzny/tKbi0yG77blwyG qfVv3nlV9sNdBTh5FJXV2L1C12oevr46fFg= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0001303.ppops.net with ESMTP id 2qtupd0q6x-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 22 Feb 2019 23:30:42 -0800 Received: from frc-hub01.TheFacebook.com (2620:10d:c021:18::171) by frc-hub03.TheFacebook.com (2620:10d:c021:18::173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1531.3; Fri, 22 Feb 2019 23:30:37 -0800 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1531.3 via Frontend Transport; Fri, 22 Feb 2019 23:30:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hYajj+I/YH0tXuBNoiXzTqGEVePZzKIjHMq9uQrBZjM=; b=A5n6vcwyV1lrbXk2KcoHV9n0DhEBu/6yNu3xcV4C1WpzXBN3/eAPqvBfBnUACGyzYW1lpRbDPRz9l3r3nG2YRDyrP7AS/RxywFr5g6UYwZDU7JCJaS3YOBVltBkL3X83b1wkEePf7FCPMtUctfWm6gJ6df+mLZLt0DS02nxFQlY= Received: from MWHPR15MB1790.namprd15.prod.outlook.com (10.174.255.19) by MWHPR15MB1744.namprd15.prod.outlook.com (10.174.255.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1643.14; Sat, 23 Feb 2019 07:30:35 +0000 Received: from MWHPR15MB1790.namprd15.prod.outlook.com ([fe80::ac2f:bf87:54e:48a2]) by MWHPR15MB1790.namprd15.prod.outlook.com ([fe80::ac2f:bf87:54e:48a2%12]) with mapi id 15.20.1643.019; Sat, 23 Feb 2019 07:30:35 +0000 From: Martin Lau To: Daniel Borkmann CC: Lawrence Brakmo , netdev , "Alexei Starovoitov" , Eric Dumazet , Kernel Team Subject: Re: [PATCH v2 bpf-next 4/9] bpf: add bpf helper bpf_skb_ecn_set_ce Thread-Topic: [PATCH v2 bpf-next 4/9] bpf: add bpf helper bpf_skb_ecn_set_ce Thread-Index: AQHUyxQy8ZalxRuLfUisxe6xL4P546XslBMAgABpFIA= Date: Sat, 23 Feb 2019 07:30:35 +0000 Message-ID: <20190223073031.utnow4seviqyfqta@kafai-mbp.dhcp.thefacebook.com> References: <20190223010703.678070-1-brakmo@fb.com> <20190223010703.678070-5-brakmo@fb.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR01CA0025.prod.exchangelabs.com (2603:10b6:a02:80::38) To MWHPR15MB1790.namprd15.prod.outlook.com (2603:10b6:301:4e::19) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2620:10d:c090:180::1:c970] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bc8a1da8-ba5e-444e-6ffc-08d69960cc47 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600110)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:MWHPR15MB1744; x-ms-traffictypediagnostic: MWHPR15MB1744: x-microsoft-exchange-diagnostics: 1;MWHPR15MB1744;20:1lEcsIWM+durv/5vn/V+xBypU6GDJ0WfvJrxPzxcvdmfNNojXfkoGDrOMghZNxNBnY2dXCUk8ns/R2dinzO3hhkMBfWkXIqs8d9uhernZsIIbShtHJQIROBQLcI2cv6VmYD31F1Oe+CkIRi7NbKbhPTx/2Z8utLOuQo/Yqb/FMo= x-microsoft-antispam-prvs: x-forefront-prvs: 0957AD37A0 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39860400002)(346002)(136003)(396003)(376002)(199004)(189003)(68736007)(186003)(53546011)(53936002)(1076003)(7736002)(99286004)(486006)(229853002)(102836004)(54906003)(316002)(386003)(6506007)(2906002)(81166006)(81156014)(8676002)(6512007)(9686003)(106356001)(8936002)(6486002)(476003)(6116002)(14454004)(256004)(97736004)(11346002)(14444005)(5024004)(4326008)(46003)(446003)(6246003)(478600001)(105586002)(25786009)(76176011)(6916009)(86362001)(305945005)(71200400001)(71190400001)(6436002)(52116002)(5660300002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1744;H:MWHPR15MB1790.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: fb.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: UgWB55rdLhrVM4TaVWcVmzJAFQIbvf9vo+oVeRVzdkNF4hQOLx8RHMufRIDq1SJ0OCJcTasHuRMUfQPzKHLTjltLn2z4lvxna2BSdaNN4xQ68qDySGej8/0Ytt2infm1Le5jEF4xpD5pUU4C1qu/ZfuwQmYZOR+AjsS1q0fYAMd8YxQIlUicBsKF7S80VFq4N5Oc7JsCh0r7o251o57xJrHBuIVTNzpSC7vgBkMbUeRsJ2Fh68MELfq+T5zD9RtsR0/V4GF7A+a/AD/hSSlSP/DyQq0syO9Do24a85eR7rfyu8KWDf2pYLOm0KS5Spkfnsh/mJbv+jsj5AoXvGa1Ata6rRJkUbG5CD1O9OfR7etN5zZm1IeCYFYgqK/G6OP/rtQmxioKKOmho9t5cbcrvqTXCf+6c+iViTsBCFsrhdE= Content-Type: text/plain; charset="us-ascii" Content-ID: <07C11161858F1F488AA8E35F3D8D7C0F@namprd15.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: bc8a1da8-ba5e-444e-6ffc-08d69960cc47 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Feb 2019 07:30:33.6712 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1744 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-23_06:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sat, Feb 23, 2019 at 02:14:26AM +0100, Daniel Borkmann wrote: > On 02/23/2019 02:06 AM, brakmo wrote: > > This patch adds a new bpf helper BPF_FUNC_skb_ecn_set_ce > > "int bpf_skb_ecn_set_ce(struct sk_buff *skb)". It is added to > > BPF_PROG_TYPE_CGROUP_SKB typed bpf_prog which currently can > > be attached to the ingress and egress path. The helper is needed > > because his type of bpf_prog cannot modify the skb directly. > >=20 > > This helper is used to set the ECN field of ECN capable IP packets to c= e > > (congestion encountered) in the IPv6 or IPv4 header of the skb. It can = be > > used by a bpf_prog to manage egress or ingress network bandwdith limit > > per cgroupv2 by inducing an ECN response in the TCP sender. > > This works best when using DCTCP. > >=20 > > Signed-off-by: Lawrence Brakmo > > --- > > include/uapi/linux/bpf.h | 10 +++++++++- > > net/core/filter.c | 14 ++++++++++++++ > > 2 files changed, 23 insertions(+), 1 deletion(-) > >=20 > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > index 95b5058fa945..fc646f3eaf9b 100644 > > --- a/include/uapi/linux/bpf.h > > +++ b/include/uapi/linux/bpf.h > > @@ -2365,6 +2365,13 @@ union bpf_attr { > > * Make a tcp_sock enter CWR state. > > * Return > > * 0 on success, or a negative error in case of failure. > > + * > > + * int bpf_skb_ecn_set_ce(struct sk_buf *skb) > > + * Description > > + * Sets ECN of IP header to ce (congestion encountered) if > > + * current value is ect (ECN capable). Works with IPv6 and IPv4. > > + * Return > > + * 1 if set, 0 if not set. > > */ > > #define __BPF_FUNC_MAPPER(FN) \ > > FN(unspec), \ > > @@ -2464,7 +2471,8 @@ union bpf_attr { > > FN(spin_unlock), \ > > FN(sk_fullsock), \ > > FN(tcp_sock), \ > > - FN(tcp_enter_cwr), > > + FN(tcp_enter_cwr), \ > > + FN(skb_ecn_set_ce), > > =20 > > /* integer value in 'imm' field of BPF_CALL instruction selects which = helper > > * function eBPF program intends to call > > diff --git a/net/core/filter.c b/net/core/filter.c > > index ca57ef25279c..955369c6ed30 100644 > > --- a/net/core/filter.c > > +++ b/net/core/filter.c > > @@ -5444,6 +5444,18 @@ static const struct bpf_func_proto bpf_tcp_enter= _cwr_proto =3D { > > .ret_type =3D RET_INTEGER, > > .arg1_type =3D ARG_PTR_TO_TCP_SOCK, > > }; > > + > > +BPF_CALL_1(bpf_skb_ecn_set_ce, struct sk_buff *, skb) > > +{ > > + return INET_ECN_set_ce(skb); >=20 > Hm, but as mentioned last time, don't we have to ensure here that skb > is writable (aka skb->data private to us before writing into it)? INET_ECN_set_ce(skb) is also called from a few net/sched/sch_*.c but I don't see how they ensure if a skb is writable. May be I have missed something there that can also be borrowed and reused here? Thanks, Martin >=20 > > +} > > + > > +static const struct bpf_func_proto bpf_skb_ecn_set_ce_proto =3D { > > + .func =3D bpf_skb_ecn_set_ce, > > + .gpl_only =3D false, > > + .ret_type =3D RET_INTEGER, > > + .arg1_type =3D ARG_PTR_TO_CTX, > > +}; > > #endif /* CONFIG_INET */ > > =20 > > bool bpf_helper_changes_pkt_data(void *func) > > @@ -5610,6 +5622,8 @@ cg_skb_func_proto(enum bpf_func_id func_id, struc= t bpf_prog *prog) > > } else { > > return NULL; > > } > > + case BPF_FUNC_skb_ecn_set_ce: > > + return &bpf_skb_ecn_set_ce_proto; > > #endif > > default: > > return sk_filter_func_proto(func_id, prog); > >=20 >=20 > Thanks, > Daniel