Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1063272ybi; Fri, 21 Jun 2019 13:05:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4KUixnjn1hh5oPec6OIrRcp6p3MJLCahdbi7TP+8Gs5Ho40HBOYksLHoaqCR5qhoCyAsP X-Received: by 2002:a17:902:3a5:: with SMTP id d34mr48577823pld.239.1561147547061; Fri, 21 Jun 2019 13:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561147547; cv=none; d=google.com; s=arc-20160816; b=eZACs4+jgzGCq3PE1iizi+l2d9X+YN32yhc9bJN3ckJnKAwXjQUrQ28P3C+tYmAXsF HDHuLdfUfuRIU3g/QIXX9l5Xqr9ggmBs0JlLsLOPAYOSDlwLA6Y9akE/LcGG31+olmyv AuU7GRUeGCL99jS3k8RNHbxjU3YpSYubjYcGxP6/n9C42vU9Wo+kUkm2T2srlZUL0d6f CCcstk82A9mY1u9hTMJ1z5nQngNQrDkQf/l1QSt0A/igSKCNzq6ilEDiVU7NRvnX8SSS ITD1edPnbi+MX8tu2RIhYsyQ0fa4T43LckuBbzahO2maipBTxyS3Xtk2avFBJtUCCBvH Zq8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=+75d+qLT34sAOHcUue1J6zTYcdt1fbQExMkZHvt3s50=; b=nv3ANu3BSZN6XTwIIIBwUapKFdGwCTjeKx1uBahGo4PMd+bV4ecHvCzkQXWNyZhAQf Erfx5/Axr9iCqIIrk/Pw4kwygAZxLP17rA4Hj3v6Xrq/2lMrfkLH+3krR5dawht+e/9w tHg08iOvB4HyO/KLnRAmO7RyC5JpVRWzFAyn0sYsGjgjXjQ4tnzO5AGnJya9uysaltnq YGXK8q0T4O6G/s0Aj6sFJdJlXm5VIF3fBSemNi3CmGjxielb/RqXk43QwII/jlG0Pln+ bu6yZrdQKmLV55F51g3F61TJZl6+uBYrPtIp/9QJBPzdxv6gLa+ObnmPJhDpb/hA2IYo NCeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si3422974pjr.109.2019.06.21.13.05.30; Fri, 21 Jun 2019 13:05:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726121AbfFUUFZ (ORCPT + 99 others); Fri, 21 Jun 2019 16:05:25 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:34458 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725985AbfFUUFZ (ORCPT ); Fri, 21 Jun 2019 16:05:25 -0400 Received: (qmail 11223 invoked by uid 2102); 21 Jun 2019 16:05:24 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 21 Jun 2019 16:05:24 -0400 Date: Fri, 21 Jun 2019 16:05:24 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Suwan Kim cc: shuah@kernel.org, , , , Subject: Re: [PATCH 2/2] usbip: Implement SG support to vhci In-Reply-To: <20190621174553.28862-3-suwan.kim027@gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 22 Jun 2019, Suwan Kim wrote: > There are bugs on vhci with usb 3.0 storage device. Originally, vhci > doesn't supported SG. So, USB storage driver on vhci divides SG list > into multiple URBs and it causes buffer overflow on the xhci of the > server. So we need to add SG support to vhci It doesn't cause buffer overflow. The problem was that a transfer got terminated too early because the transfer length for one of the URBs was not divisible by the maxpacket size. > In this patch, vhci basically support SG and it sends each SG list > entry to the stub driver. Then, the stub driver sees total length of > the buffer and allocates SG table and pages according to the total > buffer length calling sgl_alloc(). After the stub driver receives > completed URB, it again sends each SG list entry to the vhci. > > If HCD of server doesn't support SG, the stub driver allocates > big buffer using kmalloc() instead of using sgl_alloc() which > allocates SG list and pages. You might be better off not using kmalloc. It's easier for the kernel to allocate a bunch of small buffers than a single big one. Then you can create a separate URB for each buffer. > Alan fixed vhci bug with the USB 3.0 storage device by modifying > USB storage driver. > ("usb-storage: Set virt_boundary_mask to avoid SG overflows") > But the fundamental solution of it is to add SG support to vhci. > > This patch works well with the USB 3.0 storage devices without Alan's > patch, and we can revert Alan's patch if it causes some troubles. These last two paragraphs don't need to be in the patch description. > Signed-off-by: Suwan Kim > --- I'm not sufficiently familiar with the usbip drivers to review most of this. However... > diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c > index be87c8a63e24..cc93c1a87a3e 100644 > --- a/drivers/usb/usbip/vhci_hcd.c > +++ b/drivers/usb/usbip/vhci_hcd.c > @@ -696,7 +696,8 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag > } > vdev = &vhci_hcd->vdev[portnum-1]; > > - if (!urb->transfer_buffer && urb->transfer_buffer_length) { > + if (!urb->transfer_buffer && !urb->num_sgs && > + urb->transfer_buffer_length) { > dev_dbg(dev, "Null URB transfer buffer\n"); > return -EINVAL; > } > @@ -1142,6 +1143,11 @@ static int vhci_setup(struct usb_hcd *hcd) > hcd->speed = HCD_USB3; > hcd->self.root_hub->speed = USB_SPEED_SUPER; > } > + > + /* support sg */ > + hcd->self.sg_tablesize = ~0; > + hcd->self.no_sg_constraint = 1; You probably shouldn't do this, for two reasons. First, sg_tablesize of the server's HCD may be smaller than ~0. If the client's value is larger than the server's, a transfer could be accepted on the client but then fail on the server because the SG list was too big. Also, you may want to restrict the size of SG transfers even further, so that you don't have to allocate a tremendous amount of memory all at once on the server. An SG transfer can be quite large. I don't know what a reasonable limit would be -- 16 perhaps? Alan Stern