All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Arjan Mels <arjan.mels@gmx.net>,
	Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>,
	Max Vozeler <max@vozeler.com>
Subject: [14/74] staging: usbip: bugfix for isochronous packets and optimization
Date: Wed, 13 Apr 2011 08:50:38 -0700	[thread overview]
Message-ID: <20110413155144.460745207@clark.kroah.org> (raw)
In-Reply-To: <20110413155406.GA22568@kroah.com>

2.6.32-longterm review patch.  If anyone has any objections, please let us know.

------------------

From: Arjan Mels <arjan.mels@gmx.net>

commit 28276a28d8b3cd19f4449991faad4945fe557656 upstream.

For isochronous packets the actual_length is the sum of the actual
length of each of the packets, however between the packets might be
padding, so it is not sufficient to just send the first actual_length
bytes of the buffer. To fix this and simultanesouly optimize the
bandwidth the content of the isochronous packets are send without the
padding, the padding is restored on the receiving end.

Signed-off-by: Arjan Mels <arjan.mels@gmx.net>
Cc: Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>
Cc: Max Vozeler <max@vozeler.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/usbip/stub_tx.c      |   74 ++++++++++++++++++++++++++++-------
 drivers/staging/usbip/usbip_common.c |   57 ++++++++++++++++++++++++++
 drivers/staging/usbip/usbip_common.h |    2 
 drivers/staging/usbip/vhci_rx.c      |    3 +
 4 files changed, 122 insertions(+), 14 deletions(-)

--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -167,7 +167,6 @@ static int stub_send_ret_submit(struct s
 	struct stub_priv *priv, *tmp;
 
 	struct msghdr msg;
-	struct kvec iov[3];
 	size_t txsize;
 
 	size_t total_size = 0;
@@ -177,28 +176,73 @@ static int stub_send_ret_submit(struct s
 		struct urb *urb = priv->urb;
 		struct usbip_header pdu_header;
 		void *iso_buffer = NULL;
+		struct kvec *iov = NULL;
+		int iovnum = 0;
 
 		txsize = 0;
 		memset(&pdu_header, 0, sizeof(pdu_header));
 		memset(&msg, 0, sizeof(msg));
-		memset(&iov, 0, sizeof(iov));
 
-		usbip_dbg_stub_tx("setup txdata urb %p\n", urb);
+		if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
+			iovnum = 2 + urb->number_of_packets;
+		else
+			iovnum = 2;
 
+		iov = kzalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);
+
+		if (!iov) {
+			usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_MALLOC);
+			return -1;
+		}
+
+		iovnum = 0;
 
 		/* 1. setup usbip_header */
 		setup_ret_submit_pdu(&pdu_header, urb);
+		usbip_dbg_stub_tx("setup txdata seqnum: %d urb: %p\n",
+						pdu_header.base.seqnum, urb);
+		/*usbip_dump_header(pdu_header);*/
 		usbip_header_correct_endian(&pdu_header, 1);
 
-		iov[0].iov_base = &pdu_header;
-		iov[0].iov_len  = sizeof(pdu_header);
+		iov[iovnum].iov_base = &pdu_header;
+		iov[iovnum].iov_len  = sizeof(pdu_header);
+		iovnum++;
 		txsize += sizeof(pdu_header);
 
 		/* 2. setup transfer buffer */
-		if (usb_pipein(urb->pipe) && urb->actual_length > 0) {
-			iov[1].iov_base = urb->transfer_buffer;
-			iov[1].iov_len  = urb->actual_length;
+		if (usb_pipein(urb->pipe) &&
+				usb_pipetype(urb->pipe) != PIPE_ISOCHRONOUS &&
+					urb->actual_length > 0) {
+			iov[iovnum].iov_base = urb->transfer_buffer;
+			iov[iovnum].iov_len  = urb->actual_length;
+			iovnum++;
 			txsize += urb->actual_length;
+		} else if (usb_pipein(urb->pipe) &&
+				usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
+			/*
+			 * For isochronous packets: actual length is the sum of
+			 * the actual length of the individual, packets, but as
+			 * the packet offsets are not changed there will be
+			 * padding between the packets. To optimally use the
+			 * bandwidth the padding is not transmitted.
+			 */
+
+			int i;
+			for (i = 0; i < urb->number_of_packets; i++) {
+				iov[iovnum].iov_base = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
+				iov[iovnum].iov_len = urb->iso_frame_desc[i].actual_length;
+				iovnum++;
+				txsize += urb->iso_frame_desc[i].actual_length;
+			}
+
+			if (txsize != sizeof(pdu_header) + urb->actual_length) {
+				dev_err(&sdev->interface->dev,
+					"actual length of urb (%d) does not match iso packet sizes (%d)\n",
+					urb->actual_length, txsize-sizeof(pdu_header));
+				kfree(iov);
+				usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_TCP);
+			   return -1;
+			}
 		}
 
 		/* 3. setup iso_packet_descriptor */
@@ -209,32 +253,34 @@ static int stub_send_ret_submit(struct s
 			if (!iso_buffer) {
 				usbip_event_add(&sdev->ud,
 						SDEV_EVENT_ERROR_MALLOC);
+				kfree(iov);
 				return -1;
 			}
 
-			iov[2].iov_base = iso_buffer;
-			iov[2].iov_len  = len;
+			iov[iovnum].iov_base = iso_buffer;
+			iov[iovnum].iov_len  = len;
 			txsize += len;
+			iovnum++;
 		}
 
-		ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg, iov,
-				     3, txsize);
+		ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg,
+						iov,  iovnum, txsize);
 		if (ret != txsize) {
 			dev_err(&sdev->interface->dev,
 				"sendmsg failed!, retval %d for %zd\n",
 				ret, txsize);
+			kfree(iov);
 			kfree(iso_buffer);
 			usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_TCP);
 			return -1;
 		}
 
+		kfree(iov);
 		kfree(iso_buffer);
-		usbip_dbg_stub_tx("send txdata\n");
 
 		total_size += txsize;
 	}
 
-
 	spin_lock_irqsave(&sdev->priv_lock, flags);
 
 	list_for_each_entry_safe(priv, tmp, &sdev->priv_free, list) {
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -896,6 +896,7 @@ int usbip_recv_iso(struct usbip_device *
 	int size = np * sizeof(*iso);
 	int i;
 	int ret;
+	int total_length = 0;
 
 	if (!usb_pipeisoc(urb->pipe))
 		return 0;
@@ -925,19 +926,75 @@ int usbip_recv_iso(struct usbip_device *
 		return -EPIPE;
 	}
 
+
 	for (i = 0; i < np; i++) {
 		iso = buff + (i * sizeof(*iso));
 
 		usbip_iso_pakcet_correct_endian(iso, 0);
 		usbip_pack_iso(iso, &urb->iso_frame_desc[i], 0);
+		total_length += urb->iso_frame_desc[i].actual_length;
 	}
 
 	kfree(buff);
 
+	if (total_length != urb->actual_length) {
+		dev_err(&urb->dev->dev,
+		  "total length of iso packets (%d) not equal to actual length of buffer (%d)\n",
+		  total_length, urb->actual_length);
+
+		if (ud->side == USBIP_STUB)
+			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
+		else
+			usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
+
+		return -EPIPE;
+	}
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(usbip_recv_iso);
 
+/*
+ * This functions restores the padding which was removed for optimizing
+ * the bandwidth during transfer over tcp/ip
+ *
+ * buffer and iso packets need to be stored and be in propeper endian in urb
+ * before calling this function
+ */
+int usbip_pad_iso(struct usbip_device *ud, struct urb *urb)
+{
+	int np = urb->number_of_packets;
+	int i;
+	int ret;
+	int actualoffset = urb->actual_length;
+
+	if (!usb_pipeisoc(urb->pipe))
+		return 0;
+
+	/* if no packets or length of data is 0, then nothing to unpack */
+	if (np == 0 || urb->actual_length == 0)
+		return 0;
+
+	/*
+	 * if actual_length is transfer_buffer_length then no padding is
+	 * present.
+	*/
+	if (urb->actual_length == urb->transfer_buffer_length)
+		return 0;
+
+	/*
+	 * loop over all packets from last to first (to prevent overwritting
+	 * memory when padding) and move them into the proper place
+	 */
+	for (i = np-1; i > 0; i--) {
+		actualoffset -= urb->iso_frame_desc[i].actual_length;
+		memmove(urb->transfer_buffer + urb->iso_frame_desc[i].offset,
+				  urb->transfer_buffer + actualoffset,
+				  urb->iso_frame_desc[i].actual_length);
+	}
+	return ret;
+}
+EXPORT_SYMBOL_GPL(usbip_pad_iso);
 
 /* some members of urb must be substituted before. */
 int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb)
--- a/drivers/staging/usbip/usbip_common.h
+++ b/drivers/staging/usbip/usbip_common.h
@@ -393,6 +393,8 @@ void usbip_header_correct_endian(struct
 int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb);
 /* some members of urb must be substituted before. */
 int usbip_recv_iso(struct usbip_device *ud, struct urb *urb);
+/* some members of urb must be substituted before. */
+int usbip_pad_iso(struct usbip_device *ud, struct urb *urb);
 void *usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen);
 
 
--- a/drivers/staging/usbip/vhci_rx.c
+++ b/drivers/staging/usbip/vhci_rx.c
@@ -97,6 +97,9 @@ static void vhci_recv_ret_submit(struct
 	if (usbip_recv_iso(ud, urb) < 0)
 		return;
 
+	/* restore the padding in iso packets */
+	if (usbip_pad_iso(ud, urb) < 0)
+		return;
 
 	if (usbip_dbg_flag_vhci_rx)
 		usbip_dump_urb(urb);



  parent reply	other threads:[~2011-04-13 16:11 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-13 15:54 [00/74] 2.6.32.37-longterm review Greg KH
2011-04-13 15:50 ` [01/74] ALSA: hda - Fix SPDIF out regression on ALC889 Greg KH
2011-04-13 15:50 ` [02/74] ALSA: Fix yet another race in disconnection Greg KH
2011-04-13 15:50 ` [03/74] perf: Better fit max unprivileged mlock pages for tools needs Greg KH
2011-04-13 15:50 ` [04/74] myri10ge: fix rmmod crash Greg KH
2011-04-13 15:50 ` [05/74] cciss: fix lost command issue Greg KH
2011-04-13 15:50 ` [06/74] sound/oss/opl3: validate voice and channel indexes Greg KH
2011-04-13 15:50 ` [07/74] mac80211: initialize sta->last_rx in sta_info_alloc Greg KH
2011-04-13 15:50 ` [08/74] [SCSI] ses: show devices for enclosures with no page 7 Greg KH
2011-04-13 15:50 ` [09/74] [SCSI] ses: Avoid kernel panic when lun 0 is not mapped Greg KH
2011-04-13 15:50 ` [10/74] eCryptfs: Unlock page in write_begin error path Greg KH
2011-04-13 15:50 ` [11/74] eCryptfs: ecryptfs_keyring_auth_tok_for_sig() bug fix Greg KH
2011-04-13 15:50 ` [12/74] staging: usbip: bugfixes related to kthread conversion Greg KH
2011-04-17 20:15   ` Arnd Bergmann
2011-04-18  6:02     ` Greg KH
2011-04-18  8:50       ` Arjan Mels
2011-04-13 15:50 ` [13/74] staging: usbip: bugfix add number of packets for isochronous frames Greg KH
2011-04-13 15:50 ` Greg KH [this message]
2011-04-13 15:50 ` [15/74] staging: hv: Fix GARP not sent after Quick Migration Greg KH
2011-04-13 15:50 ` [16/74] staging: hv: use sync_bitops when interacting with the hypervisor Greg KH
2011-04-13 15:50 ` [17/74] Relax si_code check in rt_sigqueueinfo and rt_tgsigqueueinfo Greg KH
2011-04-13 15:50 ` [18/74] xfs: prevent leaking uninitialized stack memory in FSGEOMETRY_V1 Greg KH
2011-04-14  2:54   ` [Stable-review] " Ben Hutchings
2011-04-14 18:27     ` [stable] " Greg KH
2011-04-13 15:50 ` [19/74] irda: validate peer name and attribute lengths Greg KH
2011-04-13 15:50 ` [20/74] irda: prevent heap corruption on invalid nickname Greg KH
2011-04-13 15:50 ` [21/74] nilfs2: fix data loss in mmap page write for hole blocks Greg KH
2011-04-13 15:50 ` [22/74] ASoC: Explicitly say registerless widgets have no register Greg KH
2011-04-13 15:50 ` [23/74] ALSA: ens1371: fix Creative Ectiva support Greg KH
2011-04-13 15:50 ` [24/74] ROSE: prevent heap corruption with bad facilities Greg KH
2011-04-13 15:50 ` [25/74] Btrfs: Fix uninitialized root flags for subvolumes Greg KH
2011-04-13 15:50 ` [26/74] x86, mtrr, pat: Fix one cpu getting out of sync during resume Greg KH
2011-04-13 15:50 ` [27/74] ath9k: fix a chip wakeup related crash in ath9k_start Greg KH
2011-04-13 15:50 ` [28/74] UBIFS: do not read flash unnecessarily Greg KH
2011-04-13 15:50 ` [29/74] UBIFS: fix oops on error path in read_pnode Greg KH
2011-04-13 15:50 ` [30/74] UBIFS: fix debugging failure in dbg_check_space_info Greg KH
2011-04-13 15:50 ` [31/74] quota: Dont write quota info in dquot_commit() Greg KH
2011-04-14  3:09   ` [Stable-review] " Ben Hutchings
2011-04-14  8:48     ` Jan Kara
2011-04-13 15:50 ` [32/74] mm: avoid wrapping vm_pgoff in mremap() Greg KH
2011-04-13 15:50 ` [33/74] p54usb: IDs for two new devices Greg KH
2011-04-13 15:50 ` [34/74] b43: allocate receive buffers big enough for max frame len + offset Greg KH
2011-04-13 15:50 ` [35/74] Bluetooth: sco: fix information leak to userspace Greg KH
2011-04-13 15:51 ` [36/74] bridge: netfilter: fix information leak Greg KH
2011-04-13 15:51 ` [37/74] Bluetooth: bnep: fix buffer overflow Greg KH
2011-04-13 15:51 ` [38/74] Bluetooth: add support for Apple MacBook Pro 8,2 Greg KH
2011-04-13 15:51 ` [39/74] Treat writes as new when holes span across page boundaries Greg KH
2011-04-13 15:51 ` [40/74] char/tpm: Fix unitialized usage of data buffer Greg KH
2011-04-13 15:51 ` [41/74] netfilter: ip_tables: fix infoleak to userspace Greg KH
2011-04-13 15:51 ` [42/74] netfilter: arp_tables: " Greg KH
2011-04-13 15:51 ` [43/74] netfilter: ipt_CLUSTERIP: fix buffer overflow Greg KH
2011-04-13 15:51 ` [44/74] ipv6: netfilter: ip6_tables: fix infoleak to userspace Greg KH
2011-04-13 15:51 ` [45/74] mfd: ab3100: world-writable debugfs *_priv files Greg KH
2011-04-13 15:51 ` [46/74] drivers/rtc/rtc-ds1511.c: world-writable sysfs nvram file Greg KH
2011-04-13 15:51 ` [47/74] drivers/misc/ep93xx_pwm.c: world-writable sysfs files Greg KH
2011-04-13 15:51 ` [48/74] econet: 4 byte infoleak to the network Greg KH
2011-04-13 15:51 ` [49/74] netfilter: h323: bug in parsing of ASN1 SEQOF field Greg KH
2011-04-13 16:03   ` Patrick McHardy
2011-04-13 16:17     ` Greg KH
2011-04-13 15:51 ` [50/74] sound/oss: remove offset from load_patch callbacks Greg KH
2011-04-13 15:51 ` [51/74] sound: oss: midi_synth: check get_user() return value Greg KH
2011-04-13 15:51 ` [52/74] repair gdbstub to match the gdbserial protocol specification Greg KH
2011-04-13 15:51 ` [53/74] gro: Reset dev pointer on reuse Greg KH
2011-04-13 15:51 ` [54/74] gro: reset skb_iif " Greg KH
2011-04-13 15:51 ` [55/74] x86, amd-ucode: Remove needless log messages Greg KH
2011-04-13 15:51 ` [56/74] x86, microcode, AMD: Extend ucode size verification Greg KH
2011-04-14  3:37   ` [Stable-review] " Ben Hutchings
2011-04-14  7:41     ` Borislav Petkov
2011-04-14  8:18       ` Borislav Petkov
2011-04-15 23:22       ` Henrique de Moraes Holschuh
2011-06-18 21:04     ` [tip:x86/microcode] x86, microcode, AMD: Fix section header size check tip-bot for Borislav Petkov
2011-04-13 15:51 ` [57/74] powerpc/kexec: Add ifdef CONFIG_PPC_STD_MMU_64 to PPC64 code Greg KH
2011-04-13 15:51 ` [58/74] powerpc: Fix default_machine_crash_shutdown #ifdef botch Greg KH
2011-04-13 15:51 ` [59/74] [PATCH] Revert "x86: Cleanup highmap after brk is concluded" Greg KH
2011-04-13 15:51 ` [60/74] Squashfs: handle corruption of directory structure Greg KH
2011-04-13 15:51 ` [61/74] sctp: fix to calc the INIT/INIT-ACK chunk length correctly is set Greg KH
2011-04-13 15:51 ` [62/74] atm/solos-pci: Dont include frame pseudo-header on transmit hex-dump Greg KH
2011-04-13 15:51 ` [63/74] net: ax25: fix information leak to userland Greg KH
2011-04-13 15:51 ` [64/74] net: packet: " Greg KH
2011-04-13 15:51 ` [65/74] ext4: fix credits computing for indirect mapped files Greg KH
2011-04-13 15:51 ` [66/74] nfsd: fix auth_domain reference leak on nlm operations Greg KH
2011-04-13 15:51 ` [67/74] net: tipc: fix information leak to userland Greg KH
2011-04-13 15:51 ` [68/74] inet_diag: Make sure we actually run the same bytecode we audited Greg KH
2011-06-20 19:05   ` [stable] " Paul Gortmaker
2011-04-13 15:51 ` [69/74] econet: Fix crash in aun_incoming() Greg KH
2011-04-13 15:51 ` [70/74] irda: prevent integer underflow in IRLMP_ENUMDEVICES Greg KH
2011-04-13 15:51 ` [71/74] CAN: Use inode instead of kernel address for /proc file Greg KH
2011-04-13 15:51 ` [72/74] exec: make argv/envp memory visible to oom-killer Greg KH
2011-04-13 15:51 ` [73/74] exec: copy-and-paste the fixes into compat_do_execve() paths Greg KH
2011-04-13 15:51 ` [74/74] net: fix rds_iovec page count overflow Greg KH
2011-04-15 16:53   ` [stable] " Paul Gortmaker
2011-04-15 17:10   ` Linus Torvalds
2011-04-15 17:26     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110413155144.460745207@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arjan.mels@gmx.net \
    --cc=hirofuchi@users.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=max@vozeler.com \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.