Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3433528imu; Sun, 11 Nov 2018 15:01:13 -0800 (PST) X-Google-Smtp-Source: AJdET5dRYuEwg+Qp8zOrFtBFQ3gFX28F4gI/Siq2Ir7ub+GiqEh+T7zyE8AUwTLZM5czrnpMZmrn X-Received: by 2002:a17:902:6a4:: with SMTP id 33-v6mr18009277plh.268.1541977273682; Sun, 11 Nov 2018 15:01:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977273; cv=none; d=google.com; s=arc-20160816; b=r2Ky5fQN1ZaWzBu9dNhwfnAUe2e/pgfQCqehaV/tP8nPEr9aedFhA3uho4nMharrXh Yqu65pq5mPHOSuZVaqkqO24Knr03X1wSwyNHTAmKt/26Zut+QnzblCrbbDUx0hRVPg3H g0++9ZhIof8HYuOVWNbZq76WN8v3/pGUQuvY8hi3SYC4MaIxjOpiZdws4fkfdHYu/Fx8 sJSJwRTyih9OHqBu71qc5EPdMLvP0lbvVFrJh5+qMI/+fq24uqKJ1rXnE7PVy+wGKcIW oqD1geEY583OwvuUDXB6VFq/f0ienD9+3Ceg3Ffa4yRtC9r2JOWBedNbQSc4sy+tqJSy l1yA== 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=Se8bEVCVeEDoFqkPEdopHRgUlCZCiWk9LIuZ7hdyLOY=; b=0VWcEiim0MeO/dIXPPZ/ea+q/6P+CxiAy4ct3iSOa3+wGxlohQADYCC8qzoZQ3VYR2 g8o5P6F//NGsTifa0HBmQ6mOY5idPkNTadTEAcvfuwH8waz3lQzpLlSpZFhj5szTRSOc kbpM3e6o4IsEvHweOXCgFs1x5A2CLGo4Yow83g4WhFcM8zCt7xA4rLDJKdBcXQ+jiVal AQW4yTdafq36MRKrB0gUK6qa+ubB9qv/UscXfAGxJaMgNHlWLToZ5rmwQR5UU+2uXiRa zVDmrrHkPMzGDNMxwHSuYcVQRNagbD58abtNfqysMqvWvaRG0UrDy7BIvmnHt7TECMQl Rv+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ztghxqOA; 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 i33-v6si15174042pld.433.2018.11.11.15.00.58; Sun, 11 Nov 2018 15:01:13 -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=ztghxqOA; 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 S2390797AbeKLIWi (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:53628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390740AbeKLIWg (ORCPT ); Mon, 12 Nov 2018 03:22:36 -0500 Received: from localhost (unknown [206.108.79.134]) (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 B02F122443; Sun, 11 Nov 2018 22:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975558; bh=J6n5/AJjTX3FW39fn/fdNcuZ498ivOZKzgtqdukDYZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ztghxqOAINDqLip0u+mZcO2mkIx1YgI0EHM8OCE1ARNCqSSG/ZKd+Jpk/dP8F6iWq iu5N33HqeVqDIB9zzR4yw2EQ1ZSyJQ9HYAdAB3lEXNgUME8kkUd8hEU/TeSxEDTiQ/ bPXQitwqw/tonQpyLZ2yWrn5aoQTa5ashTmL9mi0= 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.14 116/222] xen-swiotlb: use actually allocated size on check physical continuous Date: Sun, 11 Nov 2018 14:23:33 -0800 Message-Id: <20181111221658.135131620@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -317,6 +317,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 @@ -365,6 +368,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);