From patchwork Fri Jan 22 14:12:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 368663 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1762046jam; Fri, 22 Jan 2021 10:44:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzShNIDgNwbrbXg5HFVCCNBIYfNnidwzBk5c7bmvHDGVqHU9GyfayrfDU7+pEK9jQ9V8AJ/ X-Received: by 2002:a17:906:6449:: with SMTP id l9mr4153233ejn.320.1611341063809; Fri, 22 Jan 2021 10:44:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611341063; cv=none; d=google.com; s=arc-20160816; b=v3g5ay3qEqnv227K9YcaV/Hm6xYLa1tbv+03GsTsaIo/In+wObuq6LsPMjZSNVDqfZ YjNUXZ3ZfxAvAgSEE0Xzra3MFx3R7qsbi/uUBx3tafXfMD3HBsTeUluw4J7Pw1YU9o5D usLqLM1TIL/iASG3fFIno7inCMyImx9RVP/d4ZEQiz4T3naFicisNjWhTl0hGLZXpzdU bj3aBIQmQAVDCiLUVCu5BwB9fzrd8jGfA4qYn/g7PbtyYPYMEe6KbINdEf861KYyWUYn HEVLo7pWKUYXZN6uM37rkmaN4f8AEzoHr8G7TOjk33BoDLoO66akY2ccq+kwbcuGAB7z SKiA== 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=/KXrFaP3iGU5SzpdlekvuPltywVRPiSTqVztZmOoDXc=; b=NuTKu4/CAuHihAqpt26Z9UI9DlGEbasnEAW4cEpMrFzLVVwaa5QRYJ+dZjcArmatIT Dn2eb44u+FdNlM3pmMVIPiekaAlO62F+uzA7TXc5q4cQZZW1oC3GEEG6nZTfj3MbLKcx gJIIOdRwW/48Se5/r2luGd8YADNq+upyhdzMrJpN493gjfQGt1YuUOK5pXSXadADZRss I0RofQuLzeXzfyV4UCE4qe0OvG9h7nI39PAuLn+VdVZ/gMgAfcfNIooR046KYDpq3ISv jl3vpZuxY0UU3mzazCkr7VtWGK8Pfh1s5V/Oe7AL4n6Oyb/F/wTvvxb+mmhvm6xCzuob dB4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1SxPx4m9; 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 ia3si3164114ejc.39.2021.01.22.10.44.23; Fri, 22 Jan 2021 10:44:23 -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=1SxPx4m9; 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 S1730082AbhAVSnc (ORCPT + 13 others); Fri, 22 Jan 2021 13:43:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:40034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728547AbhAVOWa (ORCPT ); Fri, 22 Jan 2021 09:22:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B374523AC6; Fri, 22 Jan 2021 14:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611324957; bh=BrWeadbQTGKW4EE0yna3UJEivh1FJIrvof/dXYfm84U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1SxPx4m9EsHOovWKNO/dhftAsehpHrSAB5zz+Zf0iYUFhV71p+SMpWEV5oOPQ02lT W+puzzuGwRfO9xGmV+ONIihYK3Sg70TLunzV7e3H5Vr4rcqn09s3Im/M+YS8+KAVmK BkKn8kbQDyL2H5GnVob/ZZSaMjkvFbtOxa792Fbs= 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.19 19/22] net: introduce skb_list_walk_safe for skb segment walking Date: Fri, 22 Jan 2021 15:12:37 +0100 Message-Id: <20210122135732.673336891@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122135731.921636245@linuxfoundation.org> References: <20210122135731.921636245@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 @@ -1363,6 +1363,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);