From nobody Mon Feb 9 09:34:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1629800922; cv=none; d=zohomail.com; s=zohoarc; b=HiPV9toBDBaaE8mgPVHxceYWVmHwIBef5wbjqcPbeNgk47l0vd6ncaep876/Ati+gufKcnQAA3ngeM1sELh06drfE8eQ/BNQDh8klpj/xE/V8ls0XE9ZeJKbaztoaYKEZwlSIllxaRi3akrDth7zG/qFcDInO1uDYsJ5vwm8WLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629800922; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dRfHDlbGvJX0Rh3aH0nd0i0HxQzYtne2EnV2YC+Etxk=; b=dprVTkWsvpjz8XkbLClHcutCrMZj/LTpIrJ8jFKr0YXOu2TQ6FGgm9L0IQLAU9PCpb4IqhpIR+6U2ZaqIRL8fLwAiFKTPo+EHGv5iFW+sfamttIAOgivONAM4tKN/e9BkY+/P1RXIWl3wf0ot8AZ6AFqbwd4RzCzxKXltIe5UuA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1629800922225342.6021907568895; Tue, 24 Aug 2021 03:28:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.170858.311856 (Exim 4.92) (envelope-from ) id 1mITfQ-0004L3-7N; Tue, 24 Aug 2021 10:28:28 +0000 Received: by outflank-mailman (output) from mailman id 170858.311856; Tue, 24 Aug 2021 10:28:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mITfQ-0004Ku-2u; Tue, 24 Aug 2021 10:28:28 +0000 Received: by outflank-mailman (input) for mailman id 170858; Tue, 24 Aug 2021 10:28:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mITfO-00031l-3n for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 10:28:26 +0000 Received: from smtp-out2.suse.de (unknown [195.135.220.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 84f74615-da8a-4f51-8b77-82161ad5c47f; Tue, 24 Aug 2021 10:28:15 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4AF9E20050; Tue, 24 Aug 2021 10:28:14 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 048EE136DD; Tue, 24 Aug 2021 10:28:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id aKYuO73JJGG8DwAAGKfGzw (envelope-from ); Tue, 24 Aug 2021 10:28:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 84f74615-da8a-4f51-8b77-82161ad5c47f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1629800894; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dRfHDlbGvJX0Rh3aH0nd0i0HxQzYtne2EnV2YC+Etxk=; b=WA3W65tQDCGvZ6HWHIGUJZAQZYk/ziLqp7BG4E0U2Kn9UPepZzumKpmbZ0uW+XGqsGRDGm hc3woFMVOqUqQY8GKTWR9k337NFfSSOWEWki45zkGpCXg4Tdq40AaS6+pew3yTMN51P8xQ BAUavhaDsivS2qpG2Z9jGgMWI7k70rk= From: Juergen Gross To: xen-devel@lists.xenproject.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , "David S. Miller" , Jakub Kicinski Subject: [PATCH v2 3/4] xen/netfront: disentangle tx_skb_freelist Date: Tue, 24 Aug 2021 12:28:08 +0200 Message-Id: <20210824102809.26370-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210824102809.26370-1-jgross@suse.com> References: <20210824102809.26370-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1629800924249100002 Content-Type: text/plain; charset="utf-8" The tx_skb_freelist elements are in a single linked list with the request id used as link reference. The per element link field is in a union with the skb pointer of an in use request. Move the link reference out of the union in order to enable a later reuse of it for requests which need a populated skb pointer. Rename add_id_to_freelist() and get_id_from_freelist() to add_id_to_list() and get_id_from_list() in order to prepare using those for other lists as well. Define ~0 as value to indicate the end of a list and place that value into the link for a request not being on the list. When freeing a skb zero the skb pointer in the request. Use a NULL value of the skb pointer instead of skb_entry_is_link() for deciding whether a request has a skb linked to it. Remove skb_entry_set_link() and open code it instead as it is really trivial now. Signed-off-by: Juergen Gross --- V2: - new patch --- drivers/net/xen-netfront.c | 61 ++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 714fe9d2c534..956e1266bd1a 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -126,17 +126,11 @@ struct netfront_queue { =20 /* * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries - * are linked from tx_skb_freelist through skb_entry.link. - * - * NB. Freelist index entries are always going to be less than - * PAGE_OFFSET, whereas pointers to skbs will always be equal or - * greater than PAGE_OFFSET: we use this property to distinguish - * them. + * are linked from tx_skb_freelist through tx_link. */ - union skb_entry { - struct sk_buff *skb; - unsigned long link; - } tx_skbs[NET_TX_RING_SIZE]; + struct sk_buff *tx_skbs[NET_TX_RING_SIZE]; + unsigned short tx_link[NET_TX_RING_SIZE]; +#define TX_LINK_NONE 0xffff grant_ref_t gref_tx_head; grant_ref_t grant_tx_ref[NET_TX_RING_SIZE]; struct page *grant_tx_page[NET_TX_RING_SIZE]; @@ -181,33 +175,25 @@ struct netfront_rx_info { struct xen_netif_extra_info extras[XEN_NETIF_EXTRA_TYPE_MAX - 1]; }; =20 -static void skb_entry_set_link(union skb_entry *list, unsigned short id) -{ - list->link =3D id; -} - -static int skb_entry_is_link(const union skb_entry *list) -{ - BUILD_BUG_ON(sizeof(list->skb) !=3D sizeof(list->link)); - return (unsigned long)list->skb < PAGE_OFFSET; -} - /* * Access macros for acquiring freeing slots in tx_skbs[]. */ =20 -static void add_id_to_freelist(unsigned *head, union skb_entry *list, - unsigned short id) +static void add_id_to_list(unsigned *head, unsigned short *list, + unsigned short id) { - skb_entry_set_link(&list[id], *head); + list[id] =3D *head; *head =3D id; } =20 -static unsigned short get_id_from_freelist(unsigned *head, - union skb_entry *list) +static unsigned short get_id_from_list(unsigned *head, unsigned short *lis= t) { unsigned int id =3D *head; - *head =3D list[id].link; + + if (id !=3D TX_LINK_NONE) { + *head =3D list[id]; + list[id] =3D TX_LINK_NONE; + } return id; } =20 @@ -406,7 +392,8 @@ static void xennet_tx_buf_gc(struct netfront_queue *que= ue) continue; =20 id =3D txrsp.id; - skb =3D queue->tx_skbs[id].skb; + skb =3D queue->tx_skbs[id]; + queue->tx_skbs[id] =3D NULL; if (unlikely(gnttab_query_foreign_access( queue->grant_tx_ref[id]) !=3D 0)) { pr_alert("%s: warning -- grant still in use by backend domain\n", @@ -419,7 +406,7 @@ static void xennet_tx_buf_gc(struct netfront_queue *que= ue) &queue->gref_tx_head, queue->grant_tx_ref[id]); queue->grant_tx_ref[id] =3D GRANT_INVALID_REF; queue->grant_tx_page[id] =3D NULL; - add_id_to_freelist(&queue->tx_skb_freelist, queue->tx_skbs, id); + add_id_to_list(&queue->tx_skb_freelist, queue->tx_link, id); dev_kfree_skb_irq(skb); } =20 @@ -452,7 +439,7 @@ static void xennet_tx_setup_grant(unsigned long gfn, un= signed int offset, struct netfront_queue *queue =3D info->queue; struct sk_buff *skb =3D info->skb; =20 - id =3D get_id_from_freelist(&queue->tx_skb_freelist, queue->tx_skbs); + id =3D get_id_from_list(&queue->tx_skb_freelist, queue->tx_link); tx =3D RING_GET_REQUEST(&queue->tx, queue->tx.req_prod_pvt++); ref =3D gnttab_claim_grant_reference(&queue->gref_tx_head); WARN_ON_ONCE(IS_ERR_VALUE((unsigned long)(int)ref)); @@ -460,7 +447,7 @@ static void xennet_tx_setup_grant(unsigned long gfn, un= signed int offset, gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id, gfn, GNTMAP_readonly); =20 - queue->tx_skbs[id].skb =3D skb; + queue->tx_skbs[id] =3D skb; queue->grant_tx_page[id] =3D page; queue->grant_tx_ref[id] =3D ref; =20 @@ -1284,17 +1271,18 @@ static void xennet_release_tx_bufs(struct netfront_= queue *queue) =20 for (i =3D 0; i < NET_TX_RING_SIZE; i++) { /* Skip over entries which are actually freelist references */ - if (skb_entry_is_link(&queue->tx_skbs[i])) + if (!queue->tx_skbs[i]) continue; =20 - skb =3D queue->tx_skbs[i].skb; + skb =3D queue->tx_skbs[i]; + queue->tx_skbs[i] =3D NULL; get_page(queue->grant_tx_page[i]); gnttab_end_foreign_access(queue->grant_tx_ref[i], GNTMAP_readonly, (unsigned long)page_address(queue->grant_tx_page[i])); queue->grant_tx_page[i] =3D NULL; queue->grant_tx_ref[i] =3D GRANT_INVALID_REF; - add_id_to_freelist(&queue->tx_skb_freelist, queue->tx_skbs, i); + add_id_to_list(&queue->tx_skb_freelist, queue->tx_link, i); dev_kfree_skb_irq(skb); } } @@ -1851,13 +1839,14 @@ static int xennet_init_queue(struct netfront_queue = *queue) snprintf(queue->name, sizeof(queue->name), "vif%s-q%u", devid, queue->id); =20 - /* Initialise tx_skbs as a free chain containing every entry. */ + /* Initialise tx_skb_freelist as a free chain containing every entry. */ queue->tx_skb_freelist =3D 0; for (i =3D 0; i < NET_TX_RING_SIZE; i++) { - skb_entry_set_link(&queue->tx_skbs[i], i+1); + queue->tx_link[i] =3D i + 1; queue->grant_tx_ref[i] =3D GRANT_INVALID_REF; queue->grant_tx_page[i] =3D NULL; } + queue->tx_link[NET_TX_RING_SIZE - 1] =3D TX_LINK_NONE; =20 /* Clear out rx_skbs */ for (i =3D 0; i < NET_RX_RING_SIZE; i++) { --=20 2.26.2