Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3479946imu; Sun, 11 Nov 2018 16:03:46 -0800 (PST) X-Google-Smtp-Source: AJdET5ca0lzkW1LECHdc1nVDSkrFxD4YZjj4PJ6SrfgAyi+IfjmKV9h8I2LVH2ijms/7neMWz3MN X-Received: by 2002:a63:5442:: with SMTP id e2-v6mr15672603pgm.316.1541981026797; Sun, 11 Nov 2018 16:03:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981026; cv=none; d=google.com; s=arc-20160816; b=09X+BC3s0DtWwuNXOZxwAJyupqctv076x3xJG19mQ578W76MqpYdz/Q+3lLXhHZYIz ajubh1r05109iidJT/RmTu4q6u/sAAO3YomI7St8r0GKZ9R1TV0Tb9RqymipHBCsyKqo i8Tlohpna203ZUGuAJU2QfdOYGxVhsgBKVOY9If5OpUXIT1vMHhgIq5bTtuAh4n1+6fb y7kDKTI1a76nlhvrfRBC+NtvbHajygcDRvK4z+N/2cW4ppBEodzTIKCrlRtQJ6kHq3QG vPLzuZcMvRhanoxXXZ2oQVCV8Xg1h5Ws2atFZ1WkyIIrF832il8iaYBDcp2JujCOk4qT xTmg== 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=PSHgsU0FbonN11TojbZ5b+SUz28VP7Z1Vrn0LnwPYGY=; b=fMSdLgjoug10gHnzLk5vDjji3tQg8VMvQhci8cIyofC89TcqCRGV8xOZoEQPeIjunT S5u6z4Wx88T/b5OUsJU1V4dJQpPEVpVls5yyTgG12CanOTGpdzhXKII9joQYox6tHABj hHXPPeKodspl2FARnMjvJqpQvoNeSDqxeBRXhVkzJFdQOvMk/Uvi0rOkjxe/LLTAVB7y LRnViXHSYnktdO1HMmqOAUDEqgCCp5XAf6eXbd4nsM8EMLglIM6TWuIbR1mCQDy2lDO9 JYZUO/fDTcr8RsLbI4zOAna/qA9wuB8FH4iNGXPvNx8Gmod3YycLCfMZVNPhOHd+LVYS 386w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JYe9LIBO; 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 31-v6si15866927plz.181.2018.11.11.16.03.31; Sun, 11 Nov 2018 16:03:46 -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=JYe9LIBO; 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 S1732336AbeKLJwL (ORCPT + 99 others); Mon, 12 Nov 2018 04:52:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:34210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732196AbeKLIR4 (ORCPT ); Mon, 12 Nov 2018 03:17:56 -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 64C1D22353; Sun, 11 Nov 2018 22:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975280; bh=lbJtcTDz0lJd8i+fz1Fe4HGvZF+jbMCKM5ckmYytD1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYe9LIBO9ut8xgGOyIAyxosxRxsmrDK8ZHpZVKs8idp1264l+cSpEMJmQNlsFu0Gu cp5inzcl2b9HkMqBzrjnZAg18ADxYG0g+bpZWcS14V1LVTFuuwVSs96iWLmzLCMeXv em8duzLYYP+gwZYnokpDFfnqblEY6VYRiFS6Q0sU= 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.19 199/361] xen-swiotlb: use actually allocated size on check physical continuous Date: Sun, 11 Nov 2018 14:19:06 -0800 Message-Id: <20181111221648.307309340@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -303,6 +303,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 @@ -351,6 +354,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);