Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3777591imu; Tue, 18 Dec 2018 04:07:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8q0KoFy7oT5DvuKk9DL63QyQy95zVczzkloCHMG70tOvtKuZ0OpK+YUnm4GnCXxGMQ2FG X-Received: by 2002:a65:4646:: with SMTP id k6mr15213750pgr.153.1545134849533; Tue, 18 Dec 2018 04:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545134849; cv=none; d=google.com; s=arc-20160816; b=rkxotTncTOg7vCk48xaj62M09pTIBWr1QaY9sTAnN/TdA9VHJ75pRtog9odbU/rEEj UyMWm+IAVXvkNMtHojNEBN8sEAoXhapq7lGOccQGI2sDY4ZmhYGaovDWifEQno8wuBOQ 4IPUW9amgQcVSvEoHQJPr0C2Op6znM2SrordmxlvjiITWqYwE4bF/EMMO3OySKJsVI+G +vG1NzYIZ2nNlwgG21d2vyJBCM1R9xtF/XcoghrfnTFl6ff9WGM0KTMkfZ5+M08zeb4B sc7kd24AmakLctMp2gTCVGEuqgBCXACQ8lhD0IT8kEDKIhWWv4mtGTqrzvvwsT8PAx52 QwGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xgH7tJU86A63ysDva0gHrk1mfC2sisonLET/9h8k1Tc=; b=qdTsWJ4YWOR8dDECwgq+9D6Zf+u1JMO8sRj9dc2d09li7NqJWFAFC+BTG2ovAIO7a1 ZOs0Ggk/I+cJbtBY7ZDCtGgQ+lYo7bn/rJPc7uTjq9xtgAg+kNbYAJL8WBqfqrSHyMLg F05q9HPhXeLu+MaAeD9dFv59E8Al7ZKYnBkeHayBU+SvnNUgpj0vl2VVzb8+V2+IhOFi bWnH9C9FPPt+v72mSmj5H6atvbfnUXCKxVVCNOKIx8dlajjhUIAmMjuyEP2M4kgVA3IV NSahDxoCpTKpdPtZlm43oHasDaDSihpU97WvLw5OGLNV7OvMNDt1Peqeqxjl+MS+76+L jP7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KPVuLGto; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si12803999pgj.208.2018.12.18.04.07.13; Tue, 18 Dec 2018 04:07:29 -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=@gmail.com header.s=20161025 header.b=KPVuLGto; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726570AbeLRMGV (ORCPT + 99 others); Tue, 18 Dec 2018 07:06:21 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41203 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeLRMGV (ORCPT ); Tue, 18 Dec 2018 07:06:21 -0500 Received: by mail-lj1-f195.google.com with SMTP id k15-v6so13969597ljc.8 for ; Tue, 18 Dec 2018 04:06:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xgH7tJU86A63ysDva0gHrk1mfC2sisonLET/9h8k1Tc=; b=KPVuLGtoqVJTgTNdQBThrlDOpS4QJO1KtfxY8D0rUcWVKcmNNwiYzi7U2M1PhBtshc iL/ODWxtvZIEg+D47ChA7mcCGdHLNWNcEaZp7oIadyDNNwlcch9BofU/Rvv89Lig16kw HFhEJ8BjQUcqiSnTZL4mN0JmSJY2G25VfhYB09DPLaJvOc5xkJAtSKDrWphtwsmeNfgu l4J/z79tVc6NUxjmphjPjBGzwmgCvRdhi9sQKuooGLO11keY3/bMybxovVqtBeKE1Owj HhFqdSWrviMpp3oGUww6LbaEBTRK1NDp1Ql+gK2bqBMJum0shPqwPGPtMS2sd8oIY6/n 3HgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xgH7tJU86A63ysDva0gHrk1mfC2sisonLET/9h8k1Tc=; b=jpD2xZczuhL8pthYaAOXCi6i7gnzLTNIMB4hhV2CN3sj/SerPeUnz3RoOIUFA10dBe FJyGcBEGd1W6XaDcoX5HtFVFX4HZ+/OgKxBeVHpLpRpdkTocbagESImRzBakGoicDSDn jQ661M0Cki90loVsBl4ixL8KaOIdUuinpWomMrCK2ekX9Q28CeokRNeSfJjIbcYSlDpS 7p5Mo+tZMZ2Er92PLwo88EnQsk59+lYz+OVYBYy4NMrXmi4xlf8CKaWZ6pkz+T9W669P dA3CDi9UPCAm8OWMH9E2rmF6UYA2VEM+9nE7RYE7BW1iqXoqL3yMBlY1MkagpKv99a2o fWMw== X-Gm-Message-State: AA+aEWY58G+3kpGlmaa0dA6XWD6MdO6kZ8BWxovrS+cn+9a4C58ebx8+ 4MJw1uB5H24+c+yQGkhOjbJ4cXxHMbxNrwPlAU8= X-Received: by 2002:a2e:4601:: with SMTP id t1-v6mr10927299lja.111.1545134777792; Tue, 18 Dec 2018 04:06:17 -0800 (PST) MIME-Version: 1.0 References: <20181217202334.GA11758@jordon-HP-15-Notebook-PC> <20181218095709.GJ26090@n2100.armlinux.org.uk> In-Reply-To: <20181218095709.GJ26090@n2100.armlinux.org.uk> From: Souptick Joarder Date: Tue, 18 Dec 2018 17:36:04 +0530 Message-ID: Subject: Re: [PATCH v4 4/9] drm/rockchip/rockchip_drm_gem.c: Convert to use vm_insert_range To: Russell King - ARM Linux Cc: Andrew Morton , Matthew Wilcox , Michal Hocko , hjc@rock-chips.com, Heiko Stuebner , airlied@linux.ie, Linux-MM , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 18, 2018 at 3:27 PM Russell King - ARM Linux wrote: > > On Tue, Dec 18, 2018 at 01:53:34AM +0530, Souptick Joarder wrote: > > Convert to use vm_insert_range() to map range of kernel > > memory to user vma. > > > > Signed-off-by: Souptick Joarder > > Tested-by: Heiko Stuebner > > Acked-by: Heiko Stuebner > > --- > > drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 19 ++----------------- > > 1 file changed, 2 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c > > index a8db758..8279084 100644 > > --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c > > +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c > > @@ -221,26 +221,11 @@ static int rockchip_drm_gem_object_mmap_iommu(struct drm_gem_object *obj, > > struct vm_area_struct *vma) > > { > > struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj); > > - unsigned int i, count = obj->size >> PAGE_SHIFT; > > unsigned long user_count = vma_pages(vma); > > - unsigned long uaddr = vma->vm_start; > > unsigned long offset = vma->vm_pgoff; > > - unsigned long end = user_count + offset; > > - int ret; > > - > > - if (user_count == 0) > > - return -ENXIO; > > - if (end > count) > > - return -ENXIO; > > > > - for (i = offset; i < end; i++) { > > - ret = vm_insert_page(vma, uaddr, rk_obj->pages[i]); > > - if (ret) > > - return ret; > > - uaddr += PAGE_SIZE; > > - } > > - > > - return 0; > > + return vm_insert_range(vma, vma->vm_start, rk_obj->pages + offset, > > + user_count - offset); > > This looks like a change in behaviour. > > If user_count is zero, and offset is zero, then we pass into > vm_insert_range() a page_count of zero, and vm_insert_range() does > nothing and returns zero. > > However, as we can see from the above code, the original behaviour > was to return -ENXIO in that case. I think these checks are not necessary. I am not sure if we get into mmap handlers of driver with user_count = 0. > > The other thing that I'm wondering is that if (eg) count is 8 (the > object is 8 pages), offset is 2, and the user requests mapping 6 > pages (user_count = 6), then we call vm_insert_range() with a > pages of rk_obj->pages + 2, and a pages_count of 6 - 2 = 4. So we > end up inserting four pages. Considering the scenario, user_count will remain 8 (user_count = vma_pages(vma) ). ? No ? Then we call vm_insert_range() with a pages of rk_obj->pages + 2, and a pages_count of 8 - 2 = 6. So we end up inserting 6 pages. Please correct me if I am wrong. > > The original code would calculate end = 6 + 2 = 8. i would iterate > from 2 through 8, inserting six pages. > > (I hadn't spotted that second issue until I'd gone through the > calculations manually - which is worrying.) > > I don't have patches 5 through 9 to look at, but I'm concerned that > similar issues also exist in those patches. yes, you were not cc'd for 5 - 9. Below are the patchwork links - https://patchwork.kernel.org/patch/10734269/ https://patchwork.kernel.org/patch/10734271/ https://patchwork.kernel.org/patch/10734273/ https://patchwork.kernel.org/patch/10734277/ https://patchwork.kernel.org/patch/10734279/ > > I'm concerned that this series seems to be introducing subtle bugs, > it seems to be unnecessarily difficult to use this function correctly. > I think your existing proposal for vm_insert_range() provides an > interface that is way too easy to get wrong, and, therefore, is the > wrong interface. > > I think it would be way better to have vm_insert_range() take the > object page array without any offset adjustment, and the object > page_count again without any adjustment, and have vm_insert_range() > itself handle the offsetting and VMA size validation. That would > then give a simple interface and probably give a further reduction > in code at each call site. > > Thanks. > > -- > RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ > FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up > According to speedtest.net: 11.9Mbps down 500kbps up