Received: by 10.192.165.148 with SMTP id m20csp4145255imm; Mon, 30 Apr 2018 12:36:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq/1L0C6bTE87cf8sLKt5/33NDYT6LIB7xz1EzDouBGgpBAVVoiwWihPLv/1H5L95SXV8EU X-Received: by 10.98.5.129 with SMTP id 123mr138963pff.38.1525116978304; Mon, 30 Apr 2018 12:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525116978; cv=none; d=google.com; s=arc-20160816; b=YmDYP56o+2BgqBWgFERytrSfc87rRjwlKWCQXqhzVYAiniSumBu4CRDMDP1gGqcWns vRnuG6VFoau6hIeCmkruvxjKeWERXoFdH0IF6JUsWEZpn19C2m+1TJzLyboZZOvlzANG hZ+wA3EbEFThQVj2oCyCPKRbM/Ceiyp+O7I5xtOyU9gfY255iNRu/HFrTq063t2VN/Ll LkS1p5ALyCxKOTfelRidFAzgVEfN2WY+FBy7kJMy+D75jcez4lNYF5IA8V4IwrghQfpy MY57z2m+G19snlgxqCtONN/OYzuUeJ4AMVQxdxIWhJHrqeAPqh1QzXLJPuWhqRtrrhTw GptQ== 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:dmarc-filter :arc-authentication-results; bh=Py2KYQo0HeD73qIhkmfrTO8S/6rQFEkXmiCDitE8WJ4=; b=FSv5C5AidPM3wRkVJACi5AeSlRoN338bH11bmvB9KnRIZem7mZxd5srf1nG6HJZDW4 jU+E6BbgZ6Y//4Hi8zXCMxKJWSlbLLzodnZt5OPzW097I97Z8y0b+pyFuc63q97wsd1u hom6busPSL9L/8LpRPOMQWm5JEa/k5wb1ouKdhrcbdkk5UTdHspIqxqpjn56aekahfpW 0ilpSCTC+1db6Q8PRQWbuBqyoyM6uwRl6ifQcC++DBEvT5ixIqTLpOguqy1jOkYuOPyy 1wK+XKUM9scXXzkUxmMvfkpyiue5b1p/ZlQVsu66yUx5QqNQQWvd3y4zaRCLp0z6SJbF cX0Q== 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 i198-v6si6465823pgc.340.2018.04.30.12.36.03; Mon, 30 Apr 2018 12:36:18 -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 S1755448AbeD3T2y (ORCPT + 99 others); Mon, 30 Apr 2018 15:28:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:36668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756406AbeD3T2o (ORCPT ); Mon, 30 Apr 2018 15:28:44 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A07C822DC1; Mon, 30 Apr 2018 19:28:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A07C822DC1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eloy Coto Pereiro , Hans de Goede Subject: [PATCH 4.16 092/113] virt: vbox: Use __get_free_pages instead of kmalloc for DMA32 memory Date: Mon, 30 Apr 2018 12:25:03 -0700 Message-Id: <20180430184019.089903150@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hans de Goede commit faf6a2a44164c0fb2c2a82692ab9051917514bce upstream. It is not possible to get DMA32 zone memory through kmalloc, causing the vboxguest driver to malfunction due to getting memory above 4G which the PCI device cannot handle. This commit changes the kmalloc calls where the 4G limit matters to using __get_free_pages() fixing vboxguest not working on x86_64 guests with more then 4G RAM. Cc: stable@vger.kernel.org Reported-by: Eloy Coto Pereiro Signed-off-by: Hans de Goede Signed-off-by: Greg Kroah-Hartman --- drivers/virt/vboxguest/vboxguest_linux.c | 19 ++++++++++++++++--- drivers/virt/vboxguest/vboxguest_utils.c | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) --- a/drivers/virt/vboxguest/vboxguest_linux.c +++ b/drivers/virt/vboxguest/vboxguest_linux.c @@ -87,6 +87,7 @@ static long vbg_misc_device_ioctl(struct struct vbg_session *session = filp->private_data; size_t returned_size, size; struct vbg_ioctl_hdr hdr; + bool is_vmmdev_req; int ret = 0; void *buf; @@ -106,8 +107,17 @@ static long vbg_misc_device_ioctl(struct if (size > SZ_16M) return -E2BIG; - /* __GFP_DMA32 because IOCTL_VMMDEV_REQUEST passes this to the host */ - buf = kmalloc(size, GFP_KERNEL | __GFP_DMA32); + /* + * IOCTL_VMMDEV_REQUEST needs the buffer to be below 4G to avoid + * the need for a bounce-buffer and another copy later on. + */ + is_vmmdev_req = (req & ~IOCSIZE_MASK) == VBG_IOCTL_VMMDEV_REQUEST(0) || + req == VBG_IOCTL_VMMDEV_REQUEST_BIG; + + if (is_vmmdev_req) + buf = vbg_req_alloc(size, VBG_IOCTL_HDR_TYPE_DEFAULT); + else + buf = kmalloc(size, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -132,7 +142,10 @@ static long vbg_misc_device_ioctl(struct ret = -EFAULT; out: - kfree(buf); + if (is_vmmdev_req) + vbg_req_free(buf, size); + else + kfree(buf); return ret; } --- a/drivers/virt/vboxguest/vboxguest_utils.c +++ b/drivers/virt/vboxguest/vboxguest_utils.c @@ -65,8 +65,9 @@ VBG_LOG(vbg_debug, pr_debug); void *vbg_req_alloc(size_t len, enum vmmdev_request_type req_type) { struct vmmdev_request_header *req; + int order = get_order(PAGE_ALIGN(len)); - req = kmalloc(len, GFP_KERNEL | __GFP_DMA32); + req = (void *)__get_free_pages(GFP_KERNEL | GFP_DMA32, order); if (!req) return NULL; @@ -87,7 +88,7 @@ void vbg_req_free(void *req, size_t len) if (!req) return; - kfree(req); + free_pages((unsigned long)req, get_order(PAGE_ALIGN(len))); } /* Note this function returns a VBox status code, not a negative errno!! */