Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4393516yba; Tue, 9 Apr 2019 18:21:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqze129PhX0iWBulSJ58jDI+jdVLzD3VDkVJwmVVuXCPa6nC6jY2wHmecIn/mtzpdsTGrFTJ X-Received: by 2002:a63:530e:: with SMTP id h14mr2540830pgb.136.1554859301996; Tue, 09 Apr 2019 18:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554859301; cv=none; d=google.com; s=arc-20160816; b=mDZwOzh3ZVaBenKPfFMQEirnu9VQgUf0jWIcyUVxO80PoIGKYIpzI+OgSOJM04nwHq CQu43DgHW8abAYvKuiw2UbIaQb1+kDeAq4nBgUoLzcfg/eFSeUczlFgt2YTdc5YICe+k /dktdyUKzJ4xdx3RNOto+Iag6gcpLpEwz3+ICOLJTzQ64Umh57+Db2ZCKuQ+p/t5TZf0 J445CQ61+rajXvjqRdKa4tjkUXKHkjATHQFED74kPu2HqA+iUH8fIdie+BkJvoA06q5F n6Q5yfNDGfj9wKr2nLa0gFQuhhyVwKFqO9B6+BjrRhDehix1YcmmcX9n6tzC2GkbBwHp WVvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :content-disposition; bh=GcuAOHRiKIFSZeRnIegs+sx9nR6bVTMEV5kQiFAX6gE=; b=l9bGsjWYwBzAjWtBXVPoCbJtrqcIAs0Eokt5EbKeSPfnIW5fTvOgLZQghQGnDbdx9E g//Z2lPf8pp345HbzhNuA6PfkDPwQolxfZidhZv0IH2RCGdkZ2Sj6v9WGe0Qx3K3Ceso Y1CDIAXFPpek9Ds0v6JTgRpypYBIcDOpIUxD3rt8qPsdypzvVSSdKdWOTI/GQl+twFXx RzZAK2zaBqmfNUgSc+EltSCs+sxy2bb/lqIuYeurIr5kSynwUEQQjkeDva56FU6BCnHT NaduGjMuz+WqUZtoX/9zEVTJl709iMVnX60cOoGk8etG/FraLW+bkpi9D0cIj/qj0iY2 cBuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@iluvatar.ai header.s=key_2018 header.b=O+XctjsQ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=iluvatar.ai Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 137si11672899pge.63.2019.04.09.18.21.26; Tue, 09 Apr 2019 18:21:41 -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; dkim=pass header.i=@iluvatar.ai header.s=key_2018 header.b=O+XctjsQ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=iluvatar.ai Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726774AbfDJBUl (ORCPT + 99 others); Tue, 9 Apr 2019 21:20:41 -0400 Received: from owa.iluvatar.ai ([103.91.158.24]:5258 "EHLO smg.iluvatar.ai" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726532AbfDJBUl (ORCPT ); Tue, 9 Apr 2019 21:20:41 -0400 X-AuditID: 0a650161-773ff700000078a3-da-5cad44e6e592 Received: from owa.iluvatar.ai (s-10-101-1-102.iluvatar.local [10.101.1.102]) by smg.iluvatar.ai (Symantec Messaging Gateway) with SMTP id AB.C4.30883.6E44DAC5; Wed, 10 Apr 2019 09:20:38 +0800 (HKT) Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline DKIM-Signature: v=1; a=rsa-sha256; d=iluvatar.ai; s=key_2018; c=relaxed/relaxed; t=1554859237; h=from:subject:to:date:message-id; bh=GcuAOHRiKIFSZeRnIegs+sx9nR6bVTMEV5kQiFAX6gE=; b=O+XctjsQKh9LHjxwrPveCyJsIuMjwXVgEkBmPe5T004HJ/7DIvdDJwozzctACuW2oZIMZIdoJEA p7t+SS5TB1u7iiIW3H/T4pp4DGjCwIa9iw57crF8B/IsNPXhFtxU9c39eWaaY09CKwBP8QN5FRIty YuRvoWuzFD4uXczpBRU= Received: from hsj-Precision-5520 (10.101.199.253) by S-10-101-1-102.iluvatar.local (10.101.1.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1415.2; Wed, 10 Apr 2019 09:20:37 +0800 Date: Wed, 10 Apr 2019 09:20:36 +0800 From: Huang Shijie To: "Weiny, Ira" CC: Matthew Wilcox , "akpm@linux-foundation.org" , "william.kucharski@oracle.com" , "palmer@sifive.com" , "axboe@kernel.dk" , "keescook@chromium.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 1/2] mm/gup.c: fix the wrong comments Message-ID: <20190410012034.GB3640@hsj-Precision-5520> References: <20190408023746.16916-1-sjhuang@iluvatar.ai> <20190408141313.GU22763@bombadil.infradead.org> <20190409010832.GA28081@hsj-Precision-5520> <20190409024929.GW22763@bombadil.infradead.org> <20190409030417.GA3324@hsj-Precision-5520> <20190409111905.GY22763@bombadil.infradead.org> <2807E5FD2F6FDA4886F6618EAC48510E79CA51BA@CRSMSX101.amr.corp.intel.com> MIME-Version: 1.0 In-Reply-To: <2807E5FD2F6FDA4886F6618EAC48510E79CA51BA@CRSMSX101.amr.corp.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [10.101.199.253] X-ClientProxiedBy: S-10-101-1-102.iluvatar.local (10.101.1.102) To S-10-101-1-102.iluvatar.local (10.101.1.102) X-Brightmail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ulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 09, 2019 at 02:55:31PM +0000, Weiny, Ira wrote: > > On Tue, Apr 09, 2019 at 11:04:18AM +0800, Huang Shijie wrote: > > > On Mon, Apr 08, 2019 at 07:49:29PM -0700, Matthew Wilcox wrote: > > > > On Tue, Apr 09, 2019 at 09:08:33AM +0800, Huang Shijie wrote: > > > > > On Mon, Apr 08, 2019 at 07:13:13AM -0700, Matthew Wilcox wrote: > > > > > > On Mon, Apr 08, 2019 at 10:37:45AM +0800, Huang Shijie wrote: > > > > > > > The root cause is that sg_alloc_table_from_pages() requires > > > > > > > the page order to keep the same as it used in the user space, > > > > > > > but > > > > > > > get_user_pages_fast() will mess it up. > > > > > > > > > > > > I don't understand how get_user_pages_fast() can return the > > > > > > pages in a different order in the array from the order they appear in > > userspace. > > > > > > Can you explain? > > > > > Please see the code in gup.c: > > > > > > > > > > int get_user_pages_fast(unsigned long start, int nr_pages, > > > > > unsigned int gup_flags, struct page **pages) > > > > > { > > > > > ....... > > > > > if (gup_fast_permitted(start, nr_pages)) { > > > > > local_irq_disable(); > > > > > gup_pgd_range(addr, end, gup_flags, pages, &nr); > > // The @pages array maybe filled at the first time. > > > > > > > > Right ... but if it's not filled entirely, it will be filled > > > > part-way, and then we stop. > > > > > > > > > local_irq_enable(); > > > > > ret = nr; > > > > > } > > > > > ....... > > > > > if (nr < nr_pages) { > > > > > /* Try to get the remaining pages with > > get_user_pages */ > > > > > start += nr << PAGE_SHIFT; > > > > > pages += nr; // The > > @pages is moved forward. > > > > > > > > Yes, to the point where gup_pgd_range() stopped. > > > > > > > > > if (gup_flags & FOLL_LONGTERM) { > > > > > down_read(¤t->mm->mmap_sem); > > > > > ret = __gup_longterm_locked(current, > > current->mm, // The @pages maybe filled at the second time > > > > > > > > Right. > > > > > > > > > /* > > > > > * retain FAULT_FOLL_ALLOW_RETRY > > optimization if > > > > > * possible > > > > > */ > > > > > ret = get_user_pages_unlocked(start, > > nr_pages - nr, // The @pages maybe filled at the second time. > > > > > pages, gup_flags); > > > > > > > > Yes. But they'll be in the same order. > > > > > > > > > BTW, I do not know why we mess up the page order. It maybe used in > > some special case. > > > > > > > > I'm not discounting the possibility that you've found a bug. > > > > But documenting that a bug exists is not the solution; the solution > > > > is fixing the bug. > > > I do not think it is a bug :) > > > > > > If we use the get_user_pages_unlocked(), DMA is okay, such as: > > > .... > > > get_user_pages_unlocked() > > > sg_alloc_table_from_pages() > > > ..... > > > > > > I think the comment is not accurate enough. So just add more comments, > > > and tell the driver users how to use the GUPs. > > > > gup_fast() and gup_unlocked() should return the pages in the same order. > > If they do not, then it is a bug. > > Is there a reproducer for this? Or do you have some debug output which shows this problem? Is Matthew right? " gup_fast() and gup_unlocked() should return the pages in the same order. If they do not, then it is a bug." If Matthew is right, I need more time to debug the DMA issue... Thanks Huang Shijie > > Ira >