Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2528030ybd; Mon, 24 Jun 2019 07:59:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvooQUGde5U1bIdpGUwBCJZmSMfycXLYRktSbg6KklHHj8SxoKpm2AeJ4STcqPrKnuZdJO X-Received: by 2002:a17:902:294a:: with SMTP id g68mr151722958plb.169.1561388392874; Mon, 24 Jun 2019 07:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561388392; cv=none; d=google.com; s=arc-20160816; b=RKHePHccNr9BIz1ZKSZ6X8q24uNY0h3D0oeQXPk1F22xk6qgReZ7eqI1Yw/9hZDyDS avffa1o17fvYm8BjsmIvVnnldHLpY9PidgqTD30cu3J463U9fDFmlaFwc8YUdorZR8F5 6I7zaLjTvpLCPKImSLiSzE/cA/qsrG7wBgB2zQZizTSqQuqXeYBZI1n7a4eHddJXFM6q zwDWnYjI6b1ddqxebAGvTHkpA1eHmy1afDlvBZH4Jwczvax6AE5a02yX5SIwf+B2pye4 2juViEUPTBmce3BmTn8E5LrsKDlbtgW6DMmKXEtMLHv5rks3qohZPabu0LlWyAWiQDcG gWmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=TRMTWS0cPEEAhit+uZ2HEz5EhK22AdHx0UBIHnvpe0s=; b=wfiRzCutXxdNvdKl/CIkdz8mY/eR/MyovBHiAKKtAyrYcNCYRmpAZEyeXAYdCMMBxs mq7iMU1857kjpkAr/Ddu4YtGwuolU+5pRtpjh02R4Q5GHMKP9Yj8Mo93x/dQqtLtoDTJ Qt0VQSK8V1qSzQUe5OrH/6PrGNb3rIDt5OVI+oTKG94ipgKswIY8VCGRt4SUiRVL/AbW HLFH8P8EV9p0hi7pbKoerK0nIq5k1MNNeLMJDBj13EdQXB1yy/MJ9wEye6i8dJIAH56t Pqxuafke3gSJyIY14Str0fDcUfcgsYmcOTPEwlgScGxvzGF9KJI/sh6WJVNAJMaehcTy sgNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t+sZ1zdW; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 78si11259222pfz.268.2019.06.24.07.59.37; Mon, 24 Jun 2019 07:59:52 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t+sZ1zdW; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729055AbfFXO67 (ORCPT + 99 others); Mon, 24 Jun 2019 10:58:59 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45752 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfFXO67 (ORCPT ); Mon, 24 Jun 2019 10:58:59 -0400 Received: by mail-pf1-f195.google.com with SMTP id r1so7648824pfq.12; Mon, 24 Jun 2019 07:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TRMTWS0cPEEAhit+uZ2HEz5EhK22AdHx0UBIHnvpe0s=; b=t+sZ1zdWZTip2CFxNZMQXxFxHl02l9mBF1G1GdEBxsOzyEqCjy19IrnvhFVQqG5Jsu HKc5h3UtXpXM2+pZamRlW/35dJTpBaSHcbXGlL2CrAzexBZ7+eDZaqFlGjun6Qwk6TaN 03piFOleKJKbKbJTPESIEpNtZTJNmjg8GRlGw5mhHzjBM4xJtmDbgLUWoVEj8EOVrw9E 5L11cVwmC7RDx7CmojvaxHp9XRW3TjN7sOuiNyaEWlpU9hSNguiCAY3sQFy3Wyuwp7kO gOxJr909vvQHYgrmoWzOd4YMY7KtNcx5a/sNVAWaO2bNOXik954iAjCchuxfoa/xwSGL 9A5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TRMTWS0cPEEAhit+uZ2HEz5EhK22AdHx0UBIHnvpe0s=; b=mUfd010dcYbndt6xQj80Jaavr4xaItyInxgOgG3/Z2wgd6m0G7h00LVxZO/s/5v84H I+hGOKmMLhBc2+nsQSKjIoY2FB+JKZVcK23FJU39YSWmYLfLt+PCjnP4tWfommqTt6mg /gqiz8bXOXtiIlQxfzFBzSf4hcKAgQcl2FdN/D9B2Fz+jEjCG5JGv6NAdJ7b9+2oM71C tyUd75LPBXIXCl2Jj2DUxX+kssrWzdGpZ0RaECJ0q1J8GCsBoxW+RCoveFXmXtMcd5UB qF0rD2dakTM9x/5AKRbp4ufbgTfgXLve47KRh2nVZeemgZv2ZRCp5T295v21XN8KdriG laaw== X-Gm-Message-State: APjAAAXiUFd01xftJCKqcRua1upxbooGmK0rhcZGTL8kAa8eeUsMkVLJ 1XU1h6quBsqQKN0MzknBMyU= X-Received: by 2002:a65:510c:: with SMTP id f12mr32304339pgq.92.1561388338217; Mon, 24 Jun 2019 07:58:58 -0700 (PDT) Received: from localhost.localdomain ([125.142.23.13]) by smtp.gmail.com with ESMTPSA id w16sm15623074pfj.85.2019.06.24.07.58.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 07:58:57 -0700 (PDT) Date: Mon, 24 Jun 2019 23:58:53 +0900 From: Suwan Kim To: Alan Stern Cc: shuah@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] usbip: Implement SG support to vhci Message-ID: <20190624145852.GC7547@localhost.localdomain> References: <20190621174553.28862-3-suwan.kim027@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 21, 2019 at 04:05:24PM -0400, Alan Stern wrote: > 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. Oh.. I misunderstood the problem. I will rewrite the problem situation. > > 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. Ok. I will implement it as usb_sg_init() does and send v2 patch including the logic of submitting separate URBs. > > 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. I will remove these paragraphs in v2 patch. > > 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? Is there any reason why you think that 16 is ok? Or Can I set this value as the smallest value of all HC? I think that sg_tablesize cannot be a variable value because vhci interacts with different machines and all machines has different sg_tablesize value. Regards Suwan Kim