Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1313995pxu; Mon, 23 Nov 2020 18:08:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXqorWfiJaNWu/YQciNXCal09MzRzXGpHI26WehgGwVjcShLUEBQihZo3TQzwCMJoNhTwJ X-Received: by 2002:a50:a40a:: with SMTP id u10mr1933923edb.16.1606183685136; Mon, 23 Nov 2020 18:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606183685; cv=none; d=google.com; s=arc-20160816; b=G6Y5rpWRd7A0sjL3+8UlKmU6ogCj4mEygmuvef+M+ZPJ/ExATENPISlhvSLfDHHviY d0H30wWYxcgA7lx2kg8Q9G/+OQVJeC7PrqMw4GazopnwIlp7Yp2hae/aEs+3Kpa9wFxU jRUZzwhCPAMKFpgzZXKCiDzMeJ+4f3rv5OJkgxZ+f6yhGYnz3P2X+j9OsyXW8uCNUVae z58IXBhwE26SVgIk75NE+jC//QUgjrRv3a413cSKOyPAuFHoQ1nryjUcrtl7wE+bq3I9 cILcialjUWPpVoCBEX+3EPMDVxLyt9zOivaL5yhMMUL9//10nAj4ffjpaOXI4zYqnFQx t7CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WfJhnfj39FhjjsTo0ZOOVketvPcyJ+dBXioLKkSFqD0=; b=cQcWbiZs/v07k6RuogWfbpPMHxuUdvA4UZ8+Tbxy14GQk3eMq0BDQDpA6DVi43x5mL gfLC3fnroXHU1p9Px84hFCVmZCUjtijZd7keQ7SLfUEXm3gCz9KIgn/h1mzAau9Q/PhC b35QQLHGpsCj/P812PXG7JVfaUVNSYPWQoQt8zr0yHdw+wYlxTObp+3jbjWw3GYQYYnS O+ry6hISwGCQV/ynschpoOmeSgFE1Zrhc9RGWhUiKrm43a7+mRq+PXH+2FvTWvkRvVIe DCOYc2kEeExKGiyp1S6TqlIKMZuuapnHb5yQZgr4uI7GBAFEQvbJxoalmX+sSayErlmk ejvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="E/IRnT0v"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si3610213ejx.124.2020.11.23.18.07.42; Mon, 23 Nov 2020 18:08:05 -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=@linuxfoundation.org header.s=korg header.b="E/IRnT0v"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732863AbgKWNHm (ORCPT + 99 others); Mon, 23 Nov 2020 08:07:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:33888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730930AbgKWMtI (ORCPT ); Mon, 23 Nov 2020 07:49:08 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B672C208C3; Mon, 23 Nov 2020 12:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135733; bh=RXU4H0CDypkczO1YozbRulrRctyn8Yk3HjDP1voUK8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E/IRnT0vGNTuEfOMNoh4BM/cJvgxt7LQywKunnz33DenEQcwve6hjvWX8vyjmlgaf ZvWndbR/y+JsF8NP51ErDI+Cfpw/mjqPDif4ITFsJjUlxStLz9hZafNkz9MMtMzbv5 uzSCwtUK5s8rUXwIuY+sQsSfrT/dX/61KTDGl9dQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Fastabend , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.9 174/252] bpf, sockmap: On receive programs try to fast track SK_PASS ingress Date: Mon, 23 Nov 2020 13:22:04 +0100 Message-Id: <20201123121843.989114063@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121835.580259631@linuxfoundation.org> References: <20201123121835.580259631@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Fastabend [ Upstream commit 9ecbfb06a078c4911fb444203e8e41d93d22f886 ] When we receive an skb and the ingress skb verdict program returns SK_PASS we currently set the ingress flag and put it on the workqueue so it can be turned into a sk_msg and put on the sk_msg ingress queue. Then finally telling userspace with data_ready hook. Here we observe that if the workqueue is empty then we can try to convert into a sk_msg type and call data_ready directly without bouncing through a workqueue. Its a common pattern to have a recv verdict program for visibility that always returns SK_PASS. In this case unless there is an ENOMEM error or we overrun the socket we can avoid the workqueue completely only using it when we fall back to error cases caused by memory pressure. By doing this we eliminate another case where data may be dropped if errors occur on memory limits in workqueue. Fixes: 51199405f9672 ("bpf: skb_verdict, support SK_PASS on RX BPF path") Signed-off-by: John Fastabend Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/160226859704.5692.12929678876744977669.stgit@john-Precision-5820-Tower Signed-off-by: Sasha Levin --- net/core/skmsg.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index aa78784292a7e..eaf9c90389517 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -764,6 +764,7 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, { struct tcp_skb_cb *tcp; struct sock *sk_other; + int err = -EIO; switch (verdict) { case __SK_PASS: @@ -775,8 +776,20 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, tcp = TCP_SKB_CB(skb); tcp->bpf.flags |= BPF_F_INGRESS; - skb_queue_tail(&psock->ingress_skb, skb); - schedule_work(&psock->work); + + /* If the queue is empty then we can submit directly + * into the msg queue. If its not empty we have to + * queue work otherwise we may get OOO data. Otherwise, + * if sk_psock_skb_ingress errors will be handled by + * retrying later from workqueue. + */ + if (skb_queue_empty(&psock->ingress_skb)) { + err = sk_psock_skb_ingress(psock, skb); + } + if (err < 0) { + skb_queue_tail(&psock->ingress_skb, skb); + schedule_work(&psock->work); + } break; case __SK_REDIRECT: sk_psock_skb_redirect(skb); -- 2.27.0