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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 EC78DC433E1 for ; Thu, 20 Aug 2020 05:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C34432078D for ; Thu, 20 Aug 2020 05:29:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="n6cL5UxP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725823AbgHTF3g (ORCPT ); Thu, 20 Aug 2020 01:29:36 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:12818 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725798AbgHTF3g (ORCPT ); Thu, 20 Aug 2020 01:29:36 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07K5AVpu024701 for ; Wed, 19 Aug 2020 22:29:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=rwpWzKjmFqaruUF4571Q+tKjRQfEAl8lZq07kS6p5wo=; b=n6cL5UxPe0QusLutkW9DAHcufzl7Zqf0x3vVFnIUaxRC3yRXhnqala1sGirJkJQ+V5xg +Tp+LjDEaO5n9NQfjVQ8hpgvIw5360jePVWqJGdiRPXlOKYL0yCwpwcVIXCGHzWfSIG/ uivqAqxqQrvdyLjAj3c9bkUV3+Kpa8PeS+Y= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 331d50h730-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 19 Aug 2020 22:29:35 -0700 Received: from intmgw002.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 19 Aug 2020 22:28:56 -0700 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id BC3E52EC5E9A; Wed, 19 Aug 2020 22:28:53 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Andrii Nakryiko Smtp-Origin-Hostname: devbig012.ftw2.facebook.com To: , , , CC: , , Andrii Nakryiko , Lorenzo Bianconi Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf] bpf: xdp: fix XDP mode when no mode flags specified Date: Wed, 19 Aug 2020 22:28:41 -0700 Message-ID: <20200820052841.1559757-1-andriin@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-19_13:2020-08-19,2020-08-19 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 spamscore=0 malwarescore=0 mlxlogscore=910 priorityscore=1501 impostorscore=0 clxscore=1015 phishscore=0 suspectscore=8 adultscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008200046 X-FB-Internal: deliver Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs in ne= t_device") inadvertently changed which XDP mode is assumed when no mode flags are specified explicitly. Previously, driver mode was preferred, if driver supported it. If not, generic SKB mode was chosen. That commit changed de= fault to SKB mode always. This patch fixes the issue and restores the original logic. Reported-by: Lorenzo Bianconi Fixes: 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF program= s in net_device") Signed-off-by: Andrii Nakryiko --- net/core/dev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index b5d1129d8310..d42c9ea0c3c0 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8742,13 +8742,15 @@ struct bpf_xdp_link { int flags; }; =20 -static enum bpf_xdp_mode dev_xdp_mode(u32 flags) +static enum bpf_xdp_mode dev_xdp_mode(struct net_device *dev, u32 flags) { if (flags & XDP_FLAGS_HW_MODE) return XDP_MODE_HW; if (flags & XDP_FLAGS_DRV_MODE) return XDP_MODE_DRV; - return XDP_MODE_SKB; + if (flags & XDP_FLAGS_SKB_MODE) + return XDP_MODE_SKB; + return dev->netdev_ops->ndo_bpf ? XDP_MODE_DRV : XDP_MODE_SKB; } =20 static bpf_op_t dev_xdp_bpf_op(struct net_device *dev, enum bpf_xdp_mode= mode) @@ -8896,7 +8898,7 @@ static int dev_xdp_attach(struct net_device *dev, s= truct netlink_ext_ack *extack return -EINVAL; } =20 - mode =3D dev_xdp_mode(flags); + mode =3D dev_xdp_mode(dev, flags); /* can't replace attached link */ if (dev_xdp_link(dev, mode)) { NL_SET_ERR_MSG(extack, "Can't replace active BPF XDP link"); @@ -8984,7 +8986,7 @@ static int dev_xdp_detach_link(struct net_device *d= ev, =20 ASSERT_RTNL(); =20 - mode =3D dev_xdp_mode(link->flags); + mode =3D dev_xdp_mode(dev, link->flags); if (dev_xdp_link(dev, mode) !=3D link) return -EINVAL; =20 @@ -9080,7 +9082,7 @@ static int bpf_xdp_link_update(struct bpf_link *lin= k, struct bpf_prog *new_prog, goto out_unlock; } =20 - mode =3D dev_xdp_mode(xdp_link->flags); + mode =3D dev_xdp_mode(xdp_link->dev, xdp_link->flags); bpf_op =3D dev_xdp_bpf_op(xdp_link->dev, mode); err =3D dev_xdp_install(xdp_link->dev, mode, bpf_op, NULL, xdp_link->flags, new_prog); @@ -9164,7 +9166,7 @@ int bpf_xdp_link_attach(const union bpf_attr *attr,= struct bpf_prog *prog) int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *ex= tack, int fd, int expected_fd, u32 flags) { - enum bpf_xdp_mode mode =3D dev_xdp_mode(flags); + enum bpf_xdp_mode mode =3D dev_xdp_mode(dev, flags); struct bpf_prog *new_prog =3D NULL, *old_prog =3D NULL; int err; =20 --=20 2.24.1