From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E106C10F11 for ; Mon, 22 Apr 2019 19:52:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 555FD204EC for ; Mon, 22 Apr 2019 19:52:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962724; bh=4p1ViJP7nWF7GWckE1LCukqQ2Ye/qP7N7i4nnAQ8E2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=b9fssHq4zZnNI6yYlJxRsX29v74c+3jc/qIAwfjIWa73+8qI9TcPSM8OlAdr/BakS gp2bqz3ITSTh51B55m/IkKj/gd4wuP+uW52RwtGkrbIdofWWxtuKx/sb0J7HEeeT9Y P0tRsJ1zQ2D55glYJxA2L2nGgIRacoqNjTFtFzbY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731109AbfDVTub (ORCPT ); Mon, 22 Apr 2019 15:50:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:54458 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730420AbfDVTu1 (ORCPT ); Mon, 22 Apr 2019 15:50:27 -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 F0413204EC; Mon, 22 Apr 2019 19:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962626; bh=4p1ViJP7nWF7GWckE1LCukqQ2Ye/qP7N7i4nnAQ8E2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wR1dTadDnUlwVE7+14zkCUxx4NpSSotvOzw1rFjxExek2lffez6uEgPpH3eRZ6cpZ Eg9Tq7Tb6d9yWANQjNOAs/BwDOnse+HnJ1XEyhJBuAHWaI1oNmBNLqXNELzqcA4p/w ealkl1c0hFtwxFfvGdsEAJ4cnnrZeyJvFDPBs9/I= 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 3.18 02/15] usb: gadget: net2280: Fix overrun of OUT messages Date: Mon, 22 Apr 2019 15:50:09 -0400 Message-Id: <20190422195022.13760-2-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422195022.13760-1-sashal@kernel.org> References: <20190422195022.13760-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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 8d13337e2dde..931765208286 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -800,9 +800,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) @@ -841,6 +838,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