Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1827389imm; Mon, 3 Sep 2018 10:27:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYMBhoTZhMUkauIdYdtwdsjIscH0OQs+PUG5ELqB6y5/v4VqQiAGbegLhAOu2zKfj+pllkq X-Received: by 2002:a17:902:2ac3:: with SMTP id j61-v6mr29488526plb.172.1535995657768; Mon, 03 Sep 2018 10:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995657; cv=none; d=google.com; s=arc-20160816; b=ItoHvLuuENmtsP8jf73+jDJu5GG8ZEhDEykoYBQwU/l/uxo0EJpRhP0/vIKdXb6g/e CMbNl0MaHUqTMcjbIA8USmiZPaSDsaHCNR/tWV1TOyAzd/3HRaUBc2rG3WZfyuu/wQ5c hf9+5Av4NHqF9qVD45mNUWeUij6ftnBhU0p4tzDlvoBmAcQr0SQd7h1q9gNVzXYmG2x/ eZVe0JUvY0OJJZC7C3pLdKfl1G1cS72380rdFbWSY2jsT85W+5F3oUhxidRG6CJhcFB6 Ur2gxzTqBYY8DVkQr4cFyGlQ6AfqbLnD+UmEggSgHJEVPNQRe/Hdg+VC2Sdk5hhZegbS QrlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ti3qaa+w+R/chPU6Ld4/rXBtqpUud+1Hq7WZRcXg2so=; b=AhNyGJ1FCShKsdKBcCJ3F2x32fbv8JXgfegXJ0mW5ftJNGDdnl41gP1HIjaf7Ga1x8 Ew4Awq9Y0HY6N1hBnSq5mBQbB7r5cNy40thKeFrTeTF7Mzjrx6yXSBf1+bsEoYAhCG// T7MmSEqgnIi7IuNwhIu720T30Aw9ByAlGn5yQUg9H0V3QXraoR/kPbuQ4fCuS0dXNcU3 N6d8vwe8TwdpNup9O1UCLQ0DNEvCDbXgC6UVFjc70k3+hM6Pxp8kD88Jsk6GrJwvzFNK i76umzk1XDdDSNX/D+aZ+PTfcvHEZoFpPbCrFn++JUUa4MZ8u8WbojH7LK0oJxdrNbL2 AUUg== 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 w20-v6si17872663pgf.434.2018.09.03.10.27.22; Mon, 03 Sep 2018 10:27:37 -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 S1730739AbeICVrC (ORCPT + 99 others); Mon, 3 Sep 2018 17:47:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45832 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728380AbeICVrB (ORCPT ); Mon, 3 Sep 2018 17:47:01 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E8677D36; Mon, 3 Sep 2018 17:25:53 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Dave Airlie Subject: [PATCH 4.14 126/165] udl-kms: handle allocation failure Date: Mon, 3 Sep 2018 18:56:52 +0200 Message-Id: <20180903165701.896318994@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit 542bb9788a1f485eb1a2229178f665d8ea166156 upstream. Allocations larger than PAGE_ALLOC_COSTLY_ORDER are unreliable and they may fail anytime. This patch fixes the udl kms driver so that when a large alloactions fails, it tries to do multiple smaller allocations. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Dave Airlie Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/udl/udl_main.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) --- a/drivers/gpu/drm/udl/udl_main.c +++ b/drivers/gpu/drm/udl/udl_main.c @@ -199,17 +199,22 @@ static void udl_free_urb_list(struct drm static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) { struct udl_device *udl = dev->dev_private; - int i = 0; struct urb *urb; struct urb_node *unode; char *buf; + size_t wanted_size = count * size; spin_lock_init(&udl->urbs.lock); +retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list); - while (i < count) { + sema_init(&udl->urbs.limit_sem, 0); + udl->urbs.count = 0; + udl->urbs.available = 0; + + while (udl->urbs.count * size < wanted_size) { unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL); if (!unode) break; @@ -225,11 +230,16 @@ static int udl_alloc_urb_list(struct drm } unode->urb = urb; - buf = usb_alloc_coherent(udl->udev, MAX_TRANSFER, GFP_KERNEL, + buf = usb_alloc_coherent(udl->udev, size, GFP_KERNEL, &urb->transfer_dma); if (!buf) { kfree(unode); usb_free_urb(urb); + if (size > PAGE_SIZE) { + size /= 2; + udl_free_urb_list(dev); + goto retry; + } break; } @@ -240,16 +250,14 @@ static int udl_alloc_urb_list(struct drm list_add_tail(&unode->entry, &udl->urbs.list); - i++; + up(&udl->urbs.limit_sem); + udl->urbs.count++; + udl->urbs.available++; } - sema_init(&udl->urbs.limit_sem, i); - udl->urbs.count = i; - udl->urbs.available = i; - - DRM_DEBUG("allocated %d %d byte urbs\n", i, (int) size); + DRM_DEBUG("allocated %d %d byte urbs\n", udl->urbs.count, (int) size); - return i; + return udl->urbs.count; } struct urb *udl_get_urb(struct drm_device *dev)