From patchwork Tue Feb 19 05:38:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Brakmo X-Patchwork-Id: 1044440 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="pRx70GGK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443V002PJkz9s21 for ; Tue, 19 Feb 2019 16:38:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbfBSFii (ORCPT ); Tue, 19 Feb 2019 00:38:38 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:51326 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725763AbfBSFii (ORCPT ); Tue, 19 Feb 2019 00:38:38 -0500 Received: from pps.filterd (m0001255.ppops.net [127.0.0.1]) by mx0b-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1J5bGrQ007282 for ; Mon, 18 Feb 2019 21:38:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=kR46L8UsfkDjPuJxy77NaoAbCoTS7FTFTFBxFIGu9Gs=; b=pRx70GGKXCzvnNfbCj3viwCg07BI1ToBK+hL708iBNpIbKTgsMHDoCFjnK5a1E9ce3GC R2nrIxq3Y5hhbTa2VFxAaK/nZhxTTULWhoy9MgeNcvYJHb8QxKufim6P8BhlfG30PXHO D6iL55y2cp9c2lNsMkLawsw7i0g222o8PAM= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0b-00082601.pphosted.com with ESMTP id 2qr9gdr95f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 18 Feb 2019 21:38:36 -0800 Received: from mx-out.facebook.com (2620:10d:c0a1:3::13) by mail.thefacebook.com (2620:10d:c021:18::175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1531.3; Mon, 18 Feb 2019 21:38:35 -0800 Received: by devbig009.ftw2.facebook.com (Postfix, from userid 10340) id 070865AE1EBC; Mon, 18 Feb 2019 21:38:33 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: brakmo Smtp-Origin-Hostname: devbig009.ftw2.facebook.com To: netdev CC: Martin Lau , Alexei Starovoitov , Daniel Borkmann --cc=Kernel Team <"daniel@iogearbox.netKernel-team"@fb.com> Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next 4/9] bpf: Add bpf helper bpf_tcp_check_probe_timer Date: Mon, 18 Feb 2019 21:38:33 -0800 Message-ID: <20190219053833.2086766-1-brakmo@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-19_03:, , 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 This patch adds a new bpf helper BPF_FUNC_tcp_check_probe_timer "int bpf_check_tcp_probe_timer(struct tcp_bpf_sock *tp, u32 when_us)". It is added to BPF_PROG_TYPE_CGROUP_SKB typed bpf_prog which currently can be attached to the ingress and egress path. The function forces when_us to be at least TCP_TIMEOUT_MIN (currently 2 jiffies) and no more than TCP_RTO_MIN (currently 200ms). When using a bpf_prog to limit the egress bandwidth of a cgroup, it can happen that we drop a packet of a connection that has no packets out. In this case, the connection may not retry sending the packet until the probe timer fires. Since the default value of the probe timer is at least 200ms, this can introduce link underutiliation (i.e. the cgroup egress bandwidth being smaller than the specified rate) thus increased tail latency. This helper function allows for setting a smaller probe timer. Signed-off-by: Lawrence Brakmo --- include/uapi/linux/bpf.h | 12 +++++++++++- net/core/filter.c | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 5daf404511f7..a78936acccae 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -2372,6 +2372,15 @@ union bpf_attr { * val should be one of 0, 1, 2, 3. * Return * -EINVAL on error (e.g. val > 3), 0 otherwise. + * + * int bpf_tcp_check_probe_timer(struct bpf_tcp_sock *tp, int when_us) + * Description + * Checks that there are no packets out and there is no pending + * timer. If both of these are true, it bounds when_us by + * TCP_TIMEOUT_MIN (2 jiffies) or TCP_RTO_MIN (200ms) and + * sets the probe timer. + * Return + * 0 */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -2472,7 +2481,8 @@ union bpf_attr { FN(sk_fullsock), \ FN(tcp_sock), \ FN(tcp_enter_cwr), \ - FN(skb_set_ecn), + FN(skb_set_ecn), \ + FN(tcp_check_probe_timer), /* 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 275acfb2117d..2b975e651a04 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5465,6 +5465,31 @@ static const struct bpf_func_proto bpf_skb_set_ecn_proto = { .arg1_type = ARG_PTR_TO_CTX, .arg2_type = ARG_ANYTHING, }; + +BPF_CALL_2(bpf_tcp_check_probe_timer, struct tcp_sock *, tp, u32, when_us) +{ + struct sock *sk = (struct sock *) tp; + unsigned long when = usecs_to_jiffies(when_us); + + if (!tp->packets_out && !inet_csk(sk)->icsk_pending) { + if (when < TCP_TIMEOUT_MIN) + when = TCP_TIMEOUT_MIN; + else if (when > TCP_RTO_MIN) + when = TCP_RTO_MIN; + + inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, + when, TCP_RTO_MAX); + } + return 0; +} + +static const struct bpf_func_proto bpf_tcp_check_probe_timer_proto = { + .func = bpf_tcp_check_probe_timer, + .gpl_only = false, + .ret_type = RET_INTEGER, + .arg1_type = ARG_PTR_TO_TCP_SOCK, + .arg2_type = ARG_ANYTHING, +}; #endif /* CONFIG_INET */ bool bpf_helper_changes_pkt_data(void *func) @@ -5628,6 +5653,8 @@ cg_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_tcp_enter_cwr_proto; case BPF_FUNC_skb_set_ecn: return &bpf_skb_set_ecn_proto; + case BPF_FUNC_tcp_check_probe_timer: + return &bpf_tcp_check_probe_timer_proto; #endif default: return sk_filter_func_proto(func_id, prog);