Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6057106ybi; Wed, 29 May 2019 02:06:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjLjO7fChMAt4bubwMqtW024Auxpy5Lfk0QqsbeyXH43kYzFN8QClu8DYlBAbjz8kud1te X-Received: by 2002:a17:902:2beb:: with SMTP id l98mr136942246plb.290.1559120793438; Wed, 29 May 2019 02:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559120793; cv=none; d=google.com; s=arc-20160816; b=VUqsnfCJmzoEryBMZ+NcFoNS0N51++iEJDTM0rqOPx6hi+fXaxHYzFdBV6znzkWkjD EX+WAJlgnMkEvYTV7QtEeXv2ZZ5oraSJL2db7jfRG7sS/pXXaiEX+f1BQkCnhc4taLfi iFcwy6hYEF5lrFT3QMQpzj7W1YZeRXPS8F9o2wPoxWTolmCqukuMiqKNM/rmkM1YQCkj dGVrNZkybqj+JRk8h8wQM8PxoDSpZkvzQ8a+77zjv+V/srccMt3QaU2UX2K3w2njLj3P Y4lPsMFEAQV0JnprScMOAhT3WhUMauIBKmBH3K+Lf/XPekDCDshFU4HpMzyc2HBp2nS2 Fmfg== 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=66tA1G6QgeiNrNy37eyey0BgRX9fEUzVd1CrxP3P7+Q=; b=BMUcINzTYq+pQ6gnAky9NW7YByl6LeSgfIfnKCKR1f3Js5ebavAe6NnQnEBc5iN9mt rq8bIuG0ysxeURub3NDVLEOfAQKf0acG3vF4RoRJHhsqATd5RO96Cp8tjgLQeCLaVq1n i++rRl1OCE74xx4gvEaLRM0S8QlsQGnW9bc540IdntORg5Tk5pRSRP0JW9f9Ra4GdFv8 +JqL9DaGh1ELHjEuhfNLtr4qeIkUBPH2jLxCobvMVoImwpGfGvaxBqOnYg0yi+OFXN/v yx5DTvlaf+JYEp4MrhOd4AU0oaYxWt2prEVMY8k1wEKKfYEDtWL+sxglF/xyC6BQ2u6B 2tDQ== 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 k14si25420718pfa.206.2019.05.29.02.06.16; Wed, 29 May 2019 02:06:33 -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 S1726254AbfE2JEM (ORCPT + 99 others); Wed, 29 May 2019 05:04:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:46170 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726106AbfE2JEL (ORCPT ); Wed, 29 May 2019 05:04:11 -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 8C518AD5E; Wed, 29 May 2019 09:04:10 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: Juergen Gross , Konrad Rzeszutek Wilk , Boris Ostrovsky , Stefano Stabellini , xen-devel@lists.xenproject.org, stable@vger.kernel.org Subject: [PATCH v2 1/3] xen/swiotlb: fix condition for calling xen_destroy_contiguous_region() Date: Wed, 29 May 2019 11:04:05 +0200 Message-Id: <20190529090407.1225-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190529090407.1225-1-jgross@suse.com> References: <20190529090407.1225-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 Reviewed-by: Boris Ostrovsky --- V2: always issue a warning in case xen_destroy_contiguous_region() isn't called (Jan Beulich) --- 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 5dcb06fe9667..1caadca124b3 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 (!WARN_ON((dev_addr + size - 1 > dma_mask) || + 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