From nobody Tue May 7 15:42:26 2024 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=1679906249; cv=none; d=zohomail.com; s=zohoarc; b=PORPOY44C/4kyr7VFzVsbBcOAB1WSveRXdxsdZkVqN/gSgJt8+UmFAmVIWdvIa+lsINc7GbSHYz6lx/gXjY6mMakBFp4RGyx7IKgfihskqRs9BVSc6XYpZV1y2M1h+3cvamoM4eMwnCY2FgtO+U2xc8ko3K2QXWKNFmWlKbqaxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679906249; 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=fnetXybi04CNdZ9/xLVwXiguyC8aMRuM30o5vuH2Yac=; b=jvqpY24++Mw4XKVTc4Dz8nxA1UhJDS4aEk1VaqNnc2h53wZy6Q5PlM1xR1gmZMltE5LYGuwbdPf91Kc56325I89W7VdzKEPw+01qLNK/Z6o3+RetoiGi2w7ghjOAquOldp5B1CmwmRUKFeHQfsrMkUXViujvkIYT70/nPfDtDso= 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 1679906249750337.0749773429428; Mon, 27 Mar 2023 01:37:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515068.797583 (Exim 4.92) (envelope-from ) id 1pgiLb-00071k-1q; Mon, 27 Mar 2023 08:36:59 +0000 Received: by outflank-mailman (output) from mailman id 515068.797583; Mon, 27 Mar 2023 08:36:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgiLa-00071d-VP; Mon, 27 Mar 2023 08:36:58 +0000 Received: by outflank-mailman (input) for mailman id 515068; Mon, 27 Mar 2023 08:36:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgiLa-00071F-3R for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 08:36:58 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 86c3e9e4-cc7a-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 10:36:54 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 CC0201F8A8; Mon, 27 Mar 2023 08:36:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7DF8B13329; Mon, 27 Mar 2023 08:36:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id I5EqHaZVIWStSAAAMHmgww (envelope-from ); Mon, 27 Mar 2023 08:36:54 +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: 86c3e9e4-cc7a-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1679906214; 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=fnetXybi04CNdZ9/xLVwXiguyC8aMRuM30o5vuH2Yac=; b=GUN+jirZQ5RXcvQG0fEWtMYCkkdmRxzV1X9DFZMTb8Oo7vos8dNhs8farNpDq9/xQWGWMG hQdb6B5nRuZ1zHhXynYWLABX2fQEzMVrt55V226/auqxbx4NrE8xCQi09AO4QOLmyQ4W65 2EIXlCH0Ke5wskB6xPqHcftEoQWoXMo= From: Juergen Gross To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Juergen Gross , Wei Liu , Paul Durrant , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , xen-devel@lists.xenproject.org, stable@vger.kernel.org Subject: [PATCH 1/2] xen/netback: don't do grant copy across page boundary Date: Mon, 27 Mar 2023 10:36:45 +0200 Message-Id: <20230327083646.18690-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230327083646.18690-1-jgross@suse.com> References: <20230327083646.18690-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1679906250685100002 Content-Type: text/plain; charset="utf-8" Fix xenvif_get_requests() not to do grant copy operations across local page boundaries. This requires to double the maximum number of copy operations per queue, as each copy could now be split into 2. Make sure that struct xenvif_tx_cb doesn't grow too large. Cc: stable@vger.kernel.org Fixes: ad7f402ae4f4 ("xen/netback: Ensure protocol headers don't fall in th= e non-linear area") Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant --- drivers/net/xen-netback/common.h | 2 +- drivers/net/xen-netback/netback.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/com= mon.h index 3dbfc8a6924e..1fcbd83f7ff2 100644 --- a/drivers/net/xen-netback/common.h +++ b/drivers/net/xen-netback/common.h @@ -166,7 +166,7 @@ struct xenvif_queue { /* Per-queue data for xenvif */ struct pending_tx_info pending_tx_info[MAX_PENDING_REQS]; grant_handle_t grant_tx_handle[MAX_PENDING_REQS]; =20 - struct gnttab_copy tx_copy_ops[MAX_PENDING_REQS]; + struct gnttab_copy tx_copy_ops[2 * MAX_PENDING_REQS]; struct gnttab_map_grant_ref tx_map_ops[MAX_PENDING_REQS]; struct gnttab_unmap_grant_ref tx_unmap_ops[MAX_PENDING_REQS]; /* passed to gnttab_[un]map_refs with pages under (un)mapping */ diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/ne= tback.c index 1b42676ca141..111c179f161b 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c @@ -334,6 +334,7 @@ static int xenvif_count_requests(struct xenvif_queue *q= ueue, struct xenvif_tx_cb { u16 copy_pending_idx[XEN_NETBK_LEGACY_SLOTS_MAX + 1]; u8 copy_count; + u32 split_mask; }; =20 #define XENVIF_TX_CB(skb) ((struct xenvif_tx_cb *)(skb)->cb) @@ -361,6 +362,8 @@ static inline struct sk_buff *xenvif_alloc_skb(unsigned= int size) struct sk_buff *skb =3D alloc_skb(size + NET_SKB_PAD + NET_IP_ALIGN, GFP_ATOMIC | __GFP_NOWARN); + + BUILD_BUG_ON(sizeof(*XENVIF_TX_CB(skb)) > sizeof(skb->cb)); if (unlikely(skb =3D=3D NULL)) return NULL; =20 @@ -396,11 +399,13 @@ static void xenvif_get_requests(struct xenvif_queue *= queue, nr_slots =3D shinfo->nr_frags + 1; =20 copy_count(skb) =3D 0; + XENVIF_TX_CB(skb)->split_mask =3D 0; =20 /* Create copy ops for exactly data_len bytes into the skb head. */ __skb_put(skb, data_len); while (data_len > 0) { int amount =3D data_len > txp->size ? txp->size : data_len; + bool split =3D false; =20 cop->source.u.ref =3D txp->gref; cop->source.domid =3D queue->vif->domid; @@ -413,6 +418,13 @@ static void xenvif_get_requests(struct xenvif_queue *q= ueue, cop->dest.u.gmfn =3D virt_to_gfn(skb->data + skb_headlen(skb) - data_len); =20 + /* Don't cross local page boundary! */ + if (cop->dest.offset + amount > XEN_PAGE_SIZE) { + amount =3D XEN_PAGE_SIZE - cop->dest.offset; + XENVIF_TX_CB(skb)->split_mask |=3D 1U << copy_count(skb); + split =3D true; + } + cop->len =3D amount; cop->flags =3D GNTCOPY_source_gref; =20 @@ -420,7 +432,8 @@ static void xenvif_get_requests(struct xenvif_queue *qu= eue, pending_idx =3D queue->pending_ring[index]; callback_param(queue, pending_idx).ctx =3D NULL; copy_pending_idx(skb, copy_count(skb)) =3D pending_idx; - copy_count(skb)++; + if (!split) + copy_count(skb)++; =20 cop++; data_len -=3D amount; @@ -441,7 +454,8 @@ static void xenvif_get_requests(struct xenvif_queue *qu= eue, nr_slots--; } else { /* The copy op partially covered the tx_request. - * The remainder will be mapped. + * The remainder will be mapped or copied in the next + * iteration. */ txp->offset +=3D amount; txp->size -=3D amount; @@ -539,6 +553,13 @@ static int xenvif_tx_check_gop(struct xenvif_queue *qu= eue, pending_idx =3D copy_pending_idx(skb, i); =20 newerr =3D (*gopp_copy)->status; + + /* Split copies need to be handled together. */ + if (XENVIF_TX_CB(skb)->split_mask & (1U << i)) { + (*gopp_copy)++; + if (!newerr) + newerr =3D (*gopp_copy)->status; + } if (likely(!newerr)) { /* The first frag might still have this slot mapped */ if (i < copy_count(skb) - 1 || !sharedslot) --=20 2.35.3 From nobody Tue May 7 15:42:26 2024 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=1679906255; cv=none; d=zohomail.com; s=zohoarc; b=BuNdXFmUdsWFbHYvHj+ZjgHoe53a52eBVdp+v0X9v7lRrKhTo6ayNSUCDkJk6MmIdVPkmwvWhyiAf/l+dJ/1arCcFkjwG0MFl5+Htmm8RH7bJOqeUyNYKiR+EaQlnltielprUOtYZuvdkDjPdyFKHxNMLSzJBSpE4vWBfDe7km0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679906255; 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=BYwAGMe1PfAGydSVqlgv0hiTKV8LxJz7Cfr4pQvks4M=; b=auGbMZjPJBOiVCc5tloRJcy0OTfgmYPI/HMmdG+dtQAUIGKW0gMXNz3Q13E/zzEjrU/5Ak5U2+rVrmNw48TLapROzuXljW3YJts5qQ4VOf8vbK+4lkHGVYBK1vrb0qYXS7Pfq0prJNkTQclf3SsXdjw+rmnCJ+3OyLZTR+oBNM4= 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 16799062557131001.7715956856065; Mon, 27 Mar 2023 01:37:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515069.797594 (Exim 4.92) (envelope-from ) id 1pgiLf-0007Is-Ah; Mon, 27 Mar 2023 08:37:03 +0000 Received: by outflank-mailman (output) from mailman id 515069.797594; Mon, 27 Mar 2023 08:37:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgiLf-0007Il-6x; Mon, 27 Mar 2023 08:37:03 +0000 Received: by outflank-mailman (input) for mailman id 515069; Mon, 27 Mar 2023 08:37:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgiLe-00071F-Fd for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 08:37:02 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a2600f9-cc7a-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 10:36:59 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 8FDA81F8A8; Mon, 27 Mar 2023 08:37:00 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3D0B913329; Mon, 27 Mar 2023 08:37:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rNmIDaxVIWS+SAAAMHmgww (envelope-from ); Mon, 27 Mar 2023 08:37:00 +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: 8a2600f9-cc7a-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1679906220; 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=BYwAGMe1PfAGydSVqlgv0hiTKV8LxJz7Cfr4pQvks4M=; b=pnRmRrpElIfOGh45HyDbGyTLv5HE1XJiCA+hgB75qnV0jL4KSVd4BTS/HMLMTgZ6vr5c/q EW2BxF/x9H47o/NyMlbMwkvnqPLcy3SN0f4vddtVKFgShfc+EvOgYvcl9QnYQkD2CuiNrS 8JiD6T2Fu41dFmCAKBsZ2kYeG2PvttU= From: Juergen Gross To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Juergen Gross , Wei Liu , Paul Durrant , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , xen-devel@lists.xenproject.org, Jan Beulich Subject: [PATCH 2/2] xen/netback: remove not needed test in xenvif_tx_build_gops() Date: Mon, 27 Mar 2023 10:36:46 +0200 Message-Id: <20230327083646.18690-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230327083646.18690-1-jgross@suse.com> References: <20230327083646.18690-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1679906256178100001 Content-Type: text/plain; charset="utf-8" The tests for the number of grant mapping or copy operations reaching the array size of the operations buffer at the end of the main loop in xenvif_tx_build_gops() isn't needed. The loop can handle at maximum MAX_PENDING_REQS transfer requests, as XEN_RING_NR_UNCONSUMED_REQUESTS() is taking unsent responses into consideration, too. Remove the tests. Suggested-by: Jan Beulich Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant --- drivers/net/xen-netback/netback.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/ne= tback.c index 111c179f161b..4943be4fd99d 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c @@ -1082,10 +1082,6 @@ static void xenvif_tx_build_gops(struct xenvif_queue= *queue, __skb_queue_tail(&queue->tx_queue, skb); =20 queue->tx.req_cons =3D idx; - - if ((*map_ops >=3D ARRAY_SIZE(queue->tx_map_ops)) || - (*copy_ops >=3D ARRAY_SIZE(queue->tx_copy_ops))) - break; } =20 return; --=20 2.35.3