Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2983066imu; Mon, 19 Nov 2018 08:58:44 -0800 (PST) X-Google-Smtp-Source: AJdET5dbXgK1GD4DKELBTOKwiSqQuF9b9vnjPCUiUnp3Un06tKCV+aUNT6xTjR6MnAnzeJIzmfFb X-Received: by 2002:a62:9712:: with SMTP id n18-v6mr391233pfe.69.1542646724217; Mon, 19 Nov 2018 08:58:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646724; cv=none; d=google.com; s=arc-20160816; b=SUpSH/eNUUSMqqLrLowmnbxo23fsB6VUHh4eYeoL8F6WP+AnyuhVB8u0UYDjGtqfUc oSBRnck0SUMnbJdbeskDFUre3gMw36R0M3HfswUM2jbsESCHi+fv/mcRC9slIdLYMhj5 3D7rzLMax3gGt9HDL28Lt/dZPiA6tkl6Kf/eOMP+cTYcVqRpYBjnod1zukA+8OWqffXw x6av5SFEEXg+EaV9+N3+bmhlit80HdFdQozPI3jyvZOfe+ljIuBc/+nIj6ba4HP4XX4s 8c0mhZUXfbLt7i3d7MG4Ewuak135JfRsa8nLxhVYtfEOFueAbrnC4ncQ155QbL4qFNe1 4rvw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EAl1uydqpkFW0fxHE2kuEmUf7T6Q6d7z9U4V6AUAeos=; b=WZjxMpQxDpaUjcFjnaWMTTly5uRvrFAWjU56dJHDRP6RrfQKGqaeiakrK/xsSit+TZ JGiXHu31lskFpfMezEMUfw8UCK/yhNkv20dMr1uEQEslV9ifz16J9GHIa1hGzqYUg8vc ligmKRImegOInOjnlFfN5m/W2ijtd2T0WDReMjAh2QsaCO4WX+a2G4VW/E3vhSvTWXgc 9x3z+aBgOzzIPxJIGA0fsOG3PDMSW8wvraEY6wk/ktsrfxRDryhkbxRYfQe+jIFLBMj/ NaYAX4JiRABx0LRncbTeHYt9cPGcRPct3gcdcHTiKhHdzXTCsSbk4NW3v8IrPQBsJWRb 20qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gi8J+sXk; 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 p19-v6si40104625plr.124.2018.11.19.08.58.29; Mon, 19 Nov 2018 08:58:44 -0800 (PST) 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=Gi8J+sXk; 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 S2404634AbeKTDWD (ORCPT + 99 others); Mon, 19 Nov 2018 22:22:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:33580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403956AbeKTDWC (ORCPT ); Mon, 19 Nov 2018 22:22:02 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 A538C208E3; Mon, 19 Nov 2018 16:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646667; bh=hELZ/8+XYZYjjPcuZXGOhXnU2Ln2XyP8DhzA8SZRTM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gi8J+sXkjzeCJscDQwmmuHxducbCcc80HieHA5N+UuK2e/i6yXoBhvwlc/BK5FY7B BO5/c93exj2Zcmas7nUbJmxAczcePW7teGWW35xVxf5feLSNiWV7zRp0VR3G5YIww/ m3MdiQjCB75fMMx4dWViAjkzeIZe9+fzIPL2MVNM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joe Jin , Konrad Rzeszutek Wilk , Boris Ostrovsky , Christoph Helwig , Dongli Zhang , John Sobecki Subject: [PATCH 4.4 044/160] xen-swiotlb: use actually allocated size on check physical continuous Date: Mon, 19 Nov 2018 17:28:03 +0100 Message-Id: <20181119162635.691225630@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162630.031306128@linuxfoundation.org> References: <20181119162630.031306128@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joe Jin commit 7250f422da0480d8512b756640f131b9b893ccda upstream. xen_swiotlb_{alloc,free}_coherent() allocate/free memory based on the order of the pages and not size argument (bytes). This is inconsistent with range_straddles_page_boundary and memset which use the 'size' value, which may lead to not exchanging memory with Xen (range_straddles_page_boundary() returned true). And then the call to xen_swiotlb_free_coherent() would actually try to exchange the memory with Xen, leading to the kernel hitting an BUG (as the hypercall returned an error). This patch fixes it by making the 'size' variable be of the same size as the amount of memory allocated. CC: stable@vger.kernel.org Signed-off-by: Joe Jin Cc: Konrad Rzeszutek Wilk Cc: Boris Ostrovsky Cc: Christoph Helwig Cc: Dongli Zhang Cc: John Sobecki Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman --- drivers/xen/swiotlb-xen.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -310,6 +310,9 @@ xen_swiotlb_alloc_coherent(struct device */ flags &= ~(__GFP_DMA | __GFP_HIGHMEM); + /* Convert the size to actually allocated. */ + size = 1UL << (order + XEN_PAGE_SHIFT); + /* On ARM this function returns an ioremap'ped virtual address for * which virt_to_phys doesn't return the corresponding physical * address. In fact on ARM virt_to_phys only works for kernel direct @@ -359,6 +362,9 @@ xen_swiotlb_free_coherent(struct device * physical address */ phys = xen_bus_to_phys(dev_addr); + /* Convert the size to actually allocated. */ + size = 1UL << (order + XEN_PAGE_SHIFT); + if (((dev_addr + size - 1 <= dma_mask)) || range_straddles_page_boundary(phys, size)) xen_destroy_contiguous_region(phys, order);