From patchwork Tue Oct 1 09:55:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 1169808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46jF5T1C1nz9sP7 for ; Tue, 1 Oct 2019 19:55:56 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id CC0E97D0D; Tue, 1 Oct 2019 09:55:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B0D467D0C for ; Tue, 1 Oct 2019 09:55:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C11541FB for ; Tue, 1 Oct 2019 09:55:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D04AA44ACC for ; Tue, 1 Oct 2019 09:55:33 +0000 (UTC) Received: from wsfd-netdev76.ntdv.lab.eng.bos.redhat.com (wsfd-netdev76.ntdv.lab.eng.bos.redhat.com [10.19.188.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE36360603 for ; Tue, 1 Oct 2019 09:55:32 +0000 (UTC) From: Eelco Chaudron To: dev@openvswitch.org Date: Tue, 1 Oct 2019 05:55:28 -0400 Message-Id: <156992372775.27142.6845054406764881385.stgit@wsfd-netdev76.ntdv.lab.eng.bos.redhat.com> User-Agent: StGit/0.19-80-g114b MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 01 Oct 2019 09:55:33 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] netdev-afxdp: add afxdp specific maximum MTU check X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Drivers natively supporting AF_XDP will check that a configured MTU size will not exceed the allowed size for AF_XDP. However, when the skb compatibility mode is used there is no check and any value is accepted. This, for example, is the case when using the TAP interface. This fix adds a check to make sure only AF_XDP valid values are excepted. Signed-off-by: Eelco Chaudron --- lib/netdev-afxdp.c | 17 +++++++++++++++++ lib/netdev-afxdp.h | 1 + lib/netdev-linux.c | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c index 6e0180327..140150f29 100644 --- a/lib/netdev-afxdp.c +++ b/lib/netdev-afxdp.c @@ -1001,6 +1001,23 @@ netdev_afxdp_destruct(struct netdev *netdev) ovs_mutex_destroy(&dev->mutex); } +int +netdev_afxdp_verify_mtu_size(const struct netdev *netdev, int mtu) +{ + /* + * If a device is used in xdpmode skb, no driver-specific MTU size is + * checked and any value is allowed resulting in packet drops. + * This check will verify the maximum supported value based on the + * buffer size allocated and the additional headroom required. + */ + if (netdev == NULL || mtu <= 0 + || mtu > (FRAME_SIZE - OVS_XDP_HEADROOM - XDP_PACKET_HEADROOM)) { + return EINVAL; + } + + return 0; +} + int netdev_afxdp_get_custom_stats(const struct netdev *netdev, struct netdev_custom_stats *custom_stats) diff --git a/lib/netdev-afxdp.h b/lib/netdev-afxdp.h index e2f400b72..ee6939fce 100644 --- a/lib/netdev-afxdp.h +++ b/lib/netdev-afxdp.h @@ -39,6 +39,7 @@ int netdev_afxdp_rxq_construct(struct netdev_rxq *rxq_); void netdev_afxdp_rxq_destruct(struct netdev_rxq *rxq_); int netdev_afxdp_construct(struct netdev *netdev_); void netdev_afxdp_destruct(struct netdev *netdev_); +int netdev_afxdp_verify_mtu_size(const struct netdev *netdev, int mtu); int netdev_afxdp_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch, diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index f48192373..89d0d9a9d 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -1593,6 +1593,15 @@ netdev_linux_set_mtu(struct netdev *netdev_, int mtu) goto exit; } +#ifdef HAVE_AF_XDP + if (!strcmp(netdev_get_type(netdev_), "afxdp")) { + error = netdev_afxdp_verify_mtu_size(netdev_, mtu); + if (error) { + goto exit; + } + } +#endif + if (netdev->cache_valid & VALID_MTU) { error = netdev->netdev_mtu_error; if (error || netdev->mtu == mtu) {