From patchwork Fri Jan 22 14:12:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 368665 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1784781jam; Fri, 22 Jan 2021 11:17:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYsXPDl7Ow73hSyqPzu+FVTz+fdMF3SWM/+DK7wHEa2ALgfTdvJ8F+TPuchIkdNs6Ai/ML X-Received: by 2002:a17:907:96a5:: with SMTP id hd37mr268805ejc.541.1611343069579; Fri, 22 Jan 2021 11:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611343069; cv=none; d=google.com; s=arc-20160816; b=UW31PS8latRUFeAdEFz5eI28VRaQ/IQyVc5F/sNY3CAvuel98im5DaAtbRbm0PrrdX YlGcqct+rntzLybGl//DyHX1Nt9WxpbVm5UP5DuyuMrOg4YHpfJQ/T7s7dUrgHwvuQMO cZQGemt0AipaL4ggQ8XySuf2U0z4OIp1RnCHKeGX5GFVf5gkgaCFXVFsMZS+7P2RM7Jo hODJgiyrFcPXDH+CGAQuB8KfNC+ulT+HltpsKUDWiucV4yjVyf8DnHlbbK11CssOFjqx SY7caChQPDvAVN1V2ptj4Ga3tqEB4+j2HSjA9xyickUgsD1Amr/YelePm/MntkA7LaUa XjjA== 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=HcSxy2DFbyUvAqQ6/dTm6fZW366jYZaukRdGQyCj1UM=; b=GF6T406rkcNe0PMlnlB9pY2Ns20zcwZsOZxYk4tX1w4eqqlgofWvUQZixoq5qaCuNP ot+25lSn9O4H2okDLfxjntIDKxuHOklWa4b7h4WgrvvD+h45HyRsf4Mjf5n2lVwkgluM GO56JfLnvl/FFKYsyc3wXKoWpEF1wZA8PQwWGjU5u9YByF8gId0IRXSv5OpwkMl8I718 NYX4Acz7bdkacvACHqH2f7NJK1Pns/ZECAiSGaDFAk1HlSnokfeVp22odiPxN6Q004tI cyxI+X5O6nPM9MN57d1+58OhoqFvhfyxkOQ7LeqgurjnauxwyhxemzdMRo/LikKCkHSb MapQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R3QPDCL+; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 n17si3339596eji.245.2021.01.22.11.17.49; Fri, 22 Jan 2021 11:17:49 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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=R3QPDCL+; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1729785AbhAVSlH (ORCPT + 13 others); Fri, 22 Jan 2021 13:41:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:37758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728489AbhAVOVB (ORCPT ); Fri, 22 Jan 2021 09:21:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A683023A54; Fri, 22 Jan 2021 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611324895; bh=cGQfnrgoeCJEnL0TN9QJGquA+MO91nPl+N9O1fCN5cI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R3QPDCL+zi7Fu5eACvNUnXPJqTdp3zCH6ClGDfHvvh53tKAKztk2D2S2SmdLKUs7X 2thepnJW/X+BJgvKK1tA363ws7WMVJE5Ye6AeOwR4pwGszrN2UQXwLkonfoztsFNFN zg4OkVW32qyl5d6YUpFbWREVJd/wGgL23+hWSHfU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , "David S. Miller" Subject: [PATCH 4.14 47/50] net: introduce skb_list_walk_safe for skb segment walking Date: Fri, 22 Jan 2021 15:12:28 +0100 Message-Id: <20210122135737.099337340@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122135735.176469491@linuxfoundation.org> References: <20210122135735.176469491@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jason A. Donenfeld commit dcfea72e79b0aa7a057c8f6024169d86a1bbc84b upstream. As part of the continual effort to remove direct usage of skb->next and skb->prev, this patch adds a helper for iterating through the singly-linked variant of skb lists, which are used for lists of GSO packet. The name "skb_list_..." has been chosen to match the existing function, "kfree_skb_list, which also operates on these singly-linked lists, and the "..._walk_safe" part is the same idiom as elsewhere in the kernel. This patch removes the helper from wireguard and puts it into linux/skbuff.h, while making it a bit more robust for general usage. In particular, parenthesis are added around the macro argument usage, and it now accounts for trying to iterate through an already-null skb pointer, which will simply run the iteration zero times. This latter enhancement means it can be used to replace both do { ... } while and while (...) open-coded idioms. This should take care of these three possible usages, which match all current methods of iterations. skb_list_walk_safe(segs, skb, next) { ... } skb_list_walk_safe(skb, skb, next) { ... } skb_list_walk_safe(segs, skb, segs) { ... } Gcc appears to generate efficient code for each of these. Signed-off-by: Jason A. Donenfeld Signed-off-by: David S. Miller [ Just the skbuff.h changes for backporting - gregkh] Signed-off-by: Greg Kroah-Hartman --- include/linux/skbuff.h | 5 +++++ 1 file changed, 5 insertions(+) --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1340,6 +1340,11 @@ static inline void skb_mark_not_on_list( skb->next = NULL; } +/* Iterate through singly-linked GSO fragments of an skb. */ +#define skb_list_walk_safe(first, skb, next) \ + for ((skb) = (first), (next) = (skb) ? (skb)->next : NULL; (skb); \ + (skb) = (next), (next) = (skb) ? (skb)->next : NULL) + static inline void skb_list_del_init(struct sk_buff *skb) { __list_del_entry(&skb->list);