Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp43960imm; Thu, 7 Jun 2018 13:29:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK7/MO8iPeRrsr4EyCtkNKOCOztc1nemzrRGK6yvR18/fGkADzaw9e1cqEd2VPVb2h4CmwC X-Received: by 2002:a62:a6dd:: with SMTP id r90-v6mr3104726pfl.60.1528403377078; Thu, 07 Jun 2018 13:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528403377; cv=none; d=google.com; s=arc-20160816; b=VWQoxKw+WVo0yjNUaapFoiAbAiy/FHi0CP1VtxuJEQzSThejRoMD+MVW1X9unRT5Pn iEj7IawPXOa65WwznYNol9hqzr580e/PNgbKrsWAtPHo0nqhU7svtXV4zPoHvRK9ufzO /5rjub3a8GSYs1+EBIo/ASvVbawQ5sd8GRJbb7zGFKFdxVxck7EUbTcRotoexEAtz4UK NRM+mz2leUp4JlVBNDJVl101cPdpAdYYC7C0rn/PB2oJIp2U50gBOO6nkO4yDTqz0ju2 q7gwOgwmrJaPYjk01ZhCayCd5PKo/sqx56cV+cw1ropV02M1pUFQWGIGLJu94LK7TpBr 6Vqg== 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 :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=I8VdZPf6h2WkRqnidPKkDjw1vZQOclA4PSHs+8tXdjc=; b=dZQxIyR+tOA2olKMFV+YZYuRsqAZT1U4fnAL1hR8hHhUZtKgCWi4vsrPutZXAOZ5Gi V8srq41Fq3ga2Z2xab+RzCKN9fmu8RSHoIOIK2b+K1yfIkvr1qeCgXVJfN7LG4ecB/79 N4KNmCD7QkjUxKylj14Fo1K39DwwgfSCDKrqy9F3YQstqKHBTB2FbvsBGx7tNZB3qwnY gCI8DwEDdxoLyaEh0l8pmWmZbZNXuwheDEa0dk2xUi3T8EdQEpOd5yt7HhANWj67K+AV g0i+TZwRHSZ2sPc13jZ5zbL+wLL0plKkD2sUmol2VvyJW/BDnlKwF+9isTxG7C5pXzfC Yw/A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13-v6si4517643plp.51.2018.06.07.13.29.22; Thu, 07 Jun 2018 13:29:37 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932418AbeFGU2r (ORCPT + 99 others); Thu, 7 Jun 2018 16:28:47 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:40462 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932323AbeFGU2q (ORCPT ); Thu, 7 Jun 2018 16:28:46 -0400 Received: from [148.252.241.226] (helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1fR1WW-000445-04; Thu, 07 Jun 2018 21:28:44 +0100 Message-ID: <1528403323.2289.84.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 010/268] xen-swiotlb: fix the check condition for xen_swiotlb_free_coherent From: Ben Hutchings To: Joe Jin , John Sobecki , Rzeszutek Wilk Cc: stable@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Date: Thu, 07 Jun 2018 21:28:43 +0100 In-Reply-To: <20180528100203.277622038@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> <20180528100203.277622038@linuxfoundation.org> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-05-28 at 11:59 +0200, Greg Kroah-Hartman wrote: > 4.4-stable review patch.  If anyone has any objections, please let me know. > > ------------------ > > From: Joe Jin > > commit 4855c92dbb7b3b85c23e88ab7ca04f99b9677b41 upstream. > > When run raidconfig from Dom0 we found that the Xen DMA heap is reduced, > but Dom Heap is increased by the same size. Tracing raidconfig we found > that the related ioctl() in megaraid_sas will call dma_alloc_coherent() > to apply memory. If the memory allocated by Dom0 is not in the DMA area, > it will exchange memory with Xen to meet the requiment. Later drivers > call dma_free_coherent() to free the memory, on xen_swiotlb_free_coherent() > the check condition (dev_addr + size - 1 <= dma_mask) is always false, I think this was meant to say (dev_addr + size - 1 > dma_mask), i.e. the condition that is replaced by this commit. If that's always false, the new condition (the logical inverse) must always be true. [...] > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -359,7 +359,7 @@ xen_swiotlb_free_coherent(struct device >    * physical address */ >   phys = xen_bus_to_phys(dev_addr); >   > - if (((dev_addr + size - 1 > dma_mask)) || > + if (((dev_addr + size - 1 <= dma_mask)) || >       range_straddles_page_boundary(phys, size)) >   xen_destroy_contiguous_region(phys, order); >   So now we will always call xen_destroy_contiguous_region(), whether or not xen_create_contiguous_region() was called during allocation. Is that really the intent? If so, the entire condition could be removed to make this clear. Alternately, if the commit message is correct, the condition could be simplified to range_straddles_page_boundary(...). But I'm not at all convinced that either of these is correct. It seems like you need to either find a way of distinguishing between memory allocated with or without the use of xen_create_contiguous_region(), or to use it unconditionally. Ben. -- Ben Hutchings, Software Developer   Codethink Ltd https://www.codethink.co.uk/ Dale House, 35 Dale Street Manchester, M1 2HF, United Kingdom