Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3436985yba; Tue, 23 Apr 2019 03:56:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0XGRzOoQQgR01hImCAJjbyhJXhqGiYXNqfy6F91zdLomTNuIw6xfzR7JBCe1DyxZRvwp9 X-Received: by 2002:a63:521c:: with SMTP id g28mr23711146pgb.431.1556016985721; Tue, 23 Apr 2019 03:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556016985; cv=none; d=google.com; s=arc-20160816; b=lD7tcFxaHLioR+/cWwYsKbuQDz6/oCarmHvf30JqAi6fpQW50MqCILFwhLIpoH3VW8 76OqYEVFkMs532+8sENgKoGZomYixShErXbQ4pVLaQN7F9y2G1kYDJkqa6N2d5eal8Yl 5tLFOAO79M8yJeuw7zivmOgnPCLY8b7l4nwPiQ1+gAZAUry5GD9FDsaHhI0JAYcW4H8G vF4P6aH04zvp18um5NY9oYqxOFAY+FEVSa6bMfcft/iZM5fBQHKhOMgdQYy37dd5uvoI zqJdL4OqbP1AJMSSyZL/1vVBswdbZ3D0fJdt+ZnU9bVWvpCM/Pz5JM8/QFkQ/CculO1e kbwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=IAjyWEQylBs/2xdF/IsJN8tjzbjCGgIEuGATZwsLY8o=; b=nhoNtzZUR8S5+a5PZ24Oe5S5KRdshfdSKIzvTTTnaegqVDO9FnCCXiI/iDOTxCNHG1 sL05Sdw2KSl0ulWYY1nhXZIpW2Wc8z+0HuMWhbycG4kYw6XlfsHK2ylzuFbepY5pf8Up bKo/l7aoEtr46uCyVMrfnHrIrSpO2tIsgYf/PzOw1n9omhI9fgKCzSJs3IZLWgSW3jWX asIGtooqDUEQW6ui1zFwRk2HlPFSxcGfE7acD8EjXU65hK1qVAFY8GB4146veLYBt3tY AhTxwG+ZbVio+lB/uP2rg5HNj/3fCgmPYAjkUdiNtv965ktDCGn9OaDMMKVMnv9IsCVB NXJQ== 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 s4si10194068pgp.158.2019.04.23.03.56.10; Tue, 23 Apr 2019 03:56:25 -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 S1727566AbfDWKzD (ORCPT + 99 others); Tue, 23 Apr 2019 06:55:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:52946 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726204AbfDWKzC (ORCPT ); Tue, 23 Apr 2019 06:55:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 89A67AE4F; Tue, 23 Apr 2019 10:55:01 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, sstabellini@kernel.org, Juergen Gross , stable@vger.kernel.org Subject: [PATCH 1/3] xen/swiotlb: fix condition for calling xen_destroy_contiguous_region() Date: Tue, 23 Apr 2019 12:54:55 +0200 Message-Id: <20190423105457.17502-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190423105457.17502-1-jgross@suse.com> References: <20190423105457.17502-1-jgross@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The condition in xen_swiotlb_free_coherent() for deciding whether to call xen_destroy_contiguous_region() is wrong: in case the region to be freed is not contiguous calling xen_destroy_contiguous_region() is the wrong thing to do: it would result in inconsistent mappings of multiple PFNs to the same MFN. This will lead to various strange crashes or data corruption. Instead of calling xen_destroy_contiguous_region() in that case a warning should be issued as that situation should never occur. Cc: stable@vger.kernel.org Signed-off-by: Juergen Gross --- drivers/xen/swiotlb-xen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2a94f4..42a3924e6d91 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -360,8 +360,8 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, /* 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)) + if ((dev_addr + size - 1 <= dma_mask) && + !WARN_ON(range_straddles_page_boundary(phys, size))) xen_destroy_contiguous_region(phys, order); xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); -- 2.16.4