From: Steven Smith Subject: [PATCH] Make netback optionally return TX responses out-of-order Date: Tue, 26 May 2009 16:25:50 +0100 Message-ID: <20090526152550.GA27906@weybridge.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1316162189==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1316162189== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bp/iNruPH9dso1Pn" Content-Disposition: inline --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Add a mode to netback in which it tries to return TX responses in a slightly less predictable order. This can make some otherwise hardware-specific frontend bugs reproduce much more easily, which is obviously rather useful when trying to fix them. It'd also be quite useful for making sure they didn't happen in the first place. Randomisation is only done if a module parameter is set, and defaults to off. It certainly isn't something you'd ever want to run with in production, but it might be useful for other people developing frontend drivers. I don't know if that's considered an adequate reason to apply it, but, if anyone wants it, here it is. Should apply cleanly to the current linux-2.6.18 tree. Signed-off-by: Steven Smith diff -r eba6fe6d8d53 drivers/xen/netback/netback.c --- a/drivers/xen/netback/netback.c Tue May 26 11:23:16 2009 +0100 +++ b/drivers/xen/netback/netback.c Tue May 26 16:08:44 2009 +0100 @@ -142,6 +142,9 @@ static int MODPARM_copy_skb =3D 1; module_param_named(copy_skb, MODPARM_copy_skb, bool, 0); MODULE_PARM_DESC(copy_skb, "Copy data received from netfront without netlo= op"); +static int MODPARM_permute_returns =3D 0; +module_param_named(permute_returns, MODPARM_permute_returns, bool, S_IRUSR= |S_IWUSR); +MODULE_PARM_DESC(permute_returns, "Randomly permute the order in which TX = responses are sent to the frontend"); =20 int netbk_copy_skb_mode; =20 @@ -866,6 +869,25 @@ &mmap_pages[pending_idx]); } =20 +static void permute_dealloc_ring(PEND_RING_IDX dc, PEND_RING_IDX dp) +{ + static unsigned random_src =3D 0x12345678; + unsigned dst_offset; + PEND_RING_IDX dest; + u16 tmp; + + while (dc !=3D dp) { + dst_offset =3D (random_src / 256) % (dp - dc); + dest =3D dc + dst_offset; + tmp =3D dealloc_ring[MASK_PEND_IDX(dest)]; + dealloc_ring[MASK_PEND_IDX(dest)] =3D + dealloc_ring[MASK_PEND_IDX(dc)]; + dealloc_ring[MASK_PEND_IDX(dc)] =3D tmp; + dc++; + random_src *=3D 68389; + } +} + inline static void net_tx_action_dealloc(void) { struct netbk_tx_pending_inuse *inuse, *n; @@ -887,6 +909,9 @@ =20 /* Ensure we see all indices enqueued by netif_idx_release(). */ smp_rmb(); + + if (MODPARM_permute_returns) + permute_dealloc_ring(dc, dp); =20 while (dc !=3D dp) { unsigned long pfn; --bp/iNruPH9dso1Pn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFKHAn+vAgSWYI3DVMRAmzZAKCmPY4nqUzKahnGp86C8QgMCH1YVwCgxLzG 6OxAq+BEX34PQw12+gWSnKU= =YtTj -----END PGP SIGNATURE----- --bp/iNruPH9dso1Pn-- --===============1316162189== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1316162189==--