Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2986693yba; Mon, 22 Apr 2019 17:13:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAZOVcRvt5qSboBGdFHnyL/6ooa1iJkXK8XlPgDNtj9bMrcAkFjNWqC6ClkSNRBYm0GRy3 X-Received: by 2002:a62:1795:: with SMTP id 143mr23268826pfx.104.1555978426401; Mon, 22 Apr 2019 17:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555978426; cv=none; d=google.com; s=arc-20160816; b=iAgt5t1xjyEFTbHLjqNEYMdWAWLFNHJoJ6hnH9Lk+1w+/UE8FKmRYIDL6S8MHA/nOo UvJaBgrjfSaLzcrRKJ1RnVDITkIZjOeWJuKyZWOzg6qjOnQw4qUnVLPEBFnMikVx3L9c TdTJxGVJ30dJU6w/YQkLR6Mf7yu0L5jca68TEjEOw+W/JUtBmRM1ohCkmdzcCX3OLTcc O/VZ+SgsN0gwpB388M2+R6ApyHQPPbmkP/q4SMvtvBpeAB4WHDwX11n7rjN0NLqpyXsv uhxt4kTyA39Dtg6jv2uAcZQ4x2HW5SFjfEoPQE0EMZ1ZjNsgdRBPka+q+g3M1YM99gmS ZwNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BUqTmsF0PLZIHnG4hYltASWqvS7pu13Tockm8BVqUME=; b=Uumd6lys0Sl5BZhK6g9y1gR8LfW8h7eDlgK2rnzU5W2AoV1urCeLSn1U7Fvnyxo0vj MAut62/pdYFo1vnGeW031ZVwp6iFLNhC9b9H//p3L9KzjvR1JQi95XDdlZzskYs54j4t pFWljA5Y4li+1LtnIJ+ZHgVUwrL6zQo9ea1okmmjzZYdgV/CpdyqmvNsy6xFq1KabSm/ D7L1JjRi6XloN32e1A+RZJLaUDVF56PTEtb/KM+9gDA72UJwEyF4XxpypxNceb9oAg6q mrz3iPz6zs//on0BcBGxPrWHP9jSKocFAoHpEwlebzi2Js4Z00bNRN+erHja2kwDin2k hF9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iCmPbVZj; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si14647393pfa.163.2019.04.22.17.13.30; Mon, 22 Apr 2019 17:13:46 -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=@kernel.org header.s=default header.b=iCmPbVZj; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732107AbfDVUDX (ORCPT + 99 others); Mon, 22 Apr 2019 16:03:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:48012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729049AbfDVTqA (ORCPT ); Mon, 22 Apr 2019 15:46:00 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A8E1218D9; Mon, 22 Apr 2019 19:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962359; bh=L1aehz1EFWzPIIRniZGjnB9/I8mVEb7GpixGNpjL9aA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iCmPbVZj5FBnm5PTZZNbN7efRDx0qTUdwmdhjpUVThmWkOxnydb9ceb2VsRNSQWOl 9O3PvKU+hQCzgOPdE96gP3Y6Mq+eq9sFUH4T8rn5Pm9/Y83EST6xbQdt2hZBnASXDh PzMktfML0ksx1UhNs0x0bZwIQmCbWLMXOM8uxRck= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Guido Kiener , Guido Kiener , Felipe Balbi , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 22/68] usb: gadget: net2280: Fix overrun of OUT messages Date: Mon, 22 Apr 2019 15:44:30 -0400 Message-Id: <20190422194516.11634-22-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guido Kiener [ Upstream commit 9d6a54c1430647355a5e23434881b2ca3d192b48 ] The OUT endpoint normally blocks (NAK) subsequent packets when a short packet was received and returns an incomplete queue entry to the gadget driver. Thereby the gadget driver can detect a short packet when reading queue entries with a length that is not equal to a multiple of packet size. The start_queue() function enables receiving OUT packets regardless of the content of the OUT FIFO. This results in a race: With the current code, it's possible that the "!ep->is_in && (readl(&ep->regs->ep_stat) & BIT(NAK_OUT_PACKETS))" test in start_dma() will fail, then a short packet will be received, and then start_queue() will call stop_out_naking(). That's what we don't want (OUT naking gets turned off while there is data in the FIFO) because then the next driver request might receive a mixture of old and new packets. With the patch, this race can't occur because the FIFO's state is tested after we know that OUT naking is already turned on, and OUT naking is stopped only when both of the conditions are met. This ensures that all received data is delivered to the gadget driver, which can detect a short packet now before new packets are appended to the last short packet. Acked-by: Alan Stern Signed-off-by: Guido Kiener Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin (Microsoft) --- drivers/usb/gadget/udc/net2280.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index b02ab2a8d927..c57046b1da0e 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -866,9 +866,6 @@ static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma) (void) readl(&ep->dev->pci->pcimstctl); writel(BIT(DMA_START), &dma->dmastat); - - if (!ep->is_in) - stop_out_naking(ep); } static void start_dma(struct net2280_ep *ep, struct net2280_request *req) @@ -907,6 +904,7 @@ static void start_dma(struct net2280_ep *ep, struct net2280_request *req) writel(BIT(DMA_START), &dma->dmastat); return; } + stop_out_naking(ep); } tmp = dmactl_default; -- 2.19.1