Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4392459yba; Tue, 9 Apr 2019 18:19:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnwYzI6E5NRLWeY9miOYrWxxSGnzh6KJpqof0fXPRpmQR9L+ppUF74B3WVt6iHawEuJvut X-Received: by 2002:aa7:8e04:: with SMTP id c4mr4645812pfr.48.1554859195298; Tue, 09 Apr 2019 18:19:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554859195; cv=none; d=google.com; s=arc-20160816; b=W5JTtW9lVJoJrGyiQa+c+xnPUxFbPKHTE4XwAxFRb/t3BLdwyv0uIS/1uW5rCYBIv4 RcO0B5RdYQxwx7v3bwXSzMJEj1y7eaUQffySbO+tpCvvKEvIuxNY3ssa0AChErKaPDtz z6LKUz/sfry6J+Jt/GFQKaaVz6HVXnGJPTIxnI2PIDA5fRPNbRbdo1LMF0msp369QX3D yLvmJkm4OzuHmib798eYSgxegfGKm/Tm1Cf6X8JTkKQtJyhrXF6fEtmerxS20S7wF1eO hedkO+0VRxl6Da71LXbwf49i/jyZMshMr3tjLMzkGsHz9c+bRi2BsifSIgOMnfcpDAMd MWXQ== 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=KzP1OXRAGGZZzLvdoLhRN33zXcievyZzFh84tg/kl7U=; b=liwmQcMYHkHfHjhFrj23312W3OcT7BB3PhGe4bEvVNfuR7DZkW2VfTZZ8x+dVo6dM4 3BJw6eDontwj8jLGr5qZO6PSqwPwT8Rq8eUR9lgUdIHQSggSk9AMP45IWV2zz+0naheA e7sbbhj3CCoJDB+RIZSw0p+MqgfFXajTzBd7VbSeuqo/m8XmrhekzRIZNl+4HO5Gx8EE UIESBcTBGsdcb7GzaCjhJHTe03aRo/VwPRD2ZPcM1b5bDFWY7tB+3vxqXXhdRnh+kGuc s3ddF7aLDTpgFFOLMPN8i6x57b423S/MjDq+GvaBCXGMyX2uPjQG+ZiuKtJt5SbAqV3G 6k4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@iluvatar.ai header.s=key_2018 header.b=wgOguPYq; 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 h69si20977282pge.487.2019.04.09.18.19.39; Tue, 09 Apr 2019 18:19:55 -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=wgOguPYq; 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 S1726784AbfDJBS4 (ORCPT + 99 others); Tue, 9 Apr 2019 21:18:56 -0400 Received: from owa.iluvatar.ai ([103.91.158.24]:5254 "EHLO smg.iluvatar.ai" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726532AbfDJBS4 (ORCPT ); Tue, 9 Apr 2019 21:18:56 -0400 X-AuditID: 0a650161-78bff700000078a3-d7-5cad447c2cf4 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 FA.C4.30883.C744DAC5; Wed, 10 Apr 2019 09:18:52 +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=1554859132; h=from:subject:to:date:message-id; bh=KzP1OXRAGGZZzLvdoLhRN33zXcievyZzFh84tg/kl7U=; b=wgOguPYq8mgGYZrxtMGfvsh8vCfDqyl+hENTlfsEjlf96vyXuLw1HiWeL/f1dZncxoi1dCf5Ftj jvoyONwMI3qeM2zmsq0ynXnIsutGhSGZz/zsDRkn9GD1pUJMNMCvrX/jhzVK27GohQSaPZ8dzvjxd 8pTVvvblEhZGyBjQ734= 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:18:51 +0800 Date: Wed, 10 Apr 2019 09:18:50 +0800 From: Huang Shijie To: Ira Weiny CC: Matthew Wilcox , , , , , , , Subject: Re: [PATCH 1/2] mm/gup.c: fix the wrong comments Message-ID: <20190410011850.GA3640@hsj-Precision-5520> References: <20190408023746.16916-1-sjhuang@iluvatar.ai> <20190408141313.GU22763@bombadil.infradead.org> <20190409010832.GA28081@hsj-Precision-5520> <20190409202316.GA22989@iweiny-DESK2.sc.intel.com> MIME-Version: 1.0 In-Reply-To: <20190409202316.GA22989@iweiny-DESK2.sc.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-Tracker: H4sIAAAAAAAAA+NgFprCIsWRmVeSWpSXmKPExsXClcqYplvjsjbG4MY9BYs569ewWay+289m sf/pcxaLM925Fpd3zWGzuLfmP6vF5gkLgMTiLiaL3z/msDlwesxuuMjisXmFlsfiPS+ZPC6f LfXY9GkSu8eJGb9ZPD4+vcXican5OrvH501yAZxRXDYpqTmZZalF+nYJXBk/vneyF7wRr3gx 9SVbA+N0wS5GTg4JAROJCSdXsYPYQgInGCV6P/CA2MwCOhILdn9i62LkALKlJZb/4+hi5OJg EXjLJNHz7QwTiCMk8B2o/utvZpAiFgFVifanQSC9bAIaEnNP3GUGsUUElCVO/7vKBlLPLPCA UWLP2SOMIAlhAUuJdd3HwBbzCphJbPxxD2roWUaJ1f1nGSESghInZz5hAbE5Bewl3m+5DDZV FGjqgW3HmUAWCwkoSLxYqQXxjJLEkr2zmCDsQonvL++yTGAUnoXkn1kI/8xCsmABI/MqRv7i 3HS9zJzSssSSxCK9xMxNjJCoStzBeKPzpd4hRgEORiUe3oDpa2KEWBPLiitzDzFKcDArifB+ fAMU4k1JrKxKLcqPLyrNSS0+xCjNwaIkzls20SRGSCA9sSQ1OzW1ILUIJsvEwSnVwGTwv3L7 m68z/klWW9qp/Jg+/++OKzHH4thb18vP3Fu6IiahVnHurWCh4i1cDyJEpsTslkxoOxqatkZ5 X0Cgv2KiVOprZr4/VZU3jSd+ED5y0EPqvm/z/FiPk/Kn+2WKORYll4mbH7wgUXzorQRz9NFw JZG3ouWODM9m17gET9q2+KYnf+FXdv7Zyy3nptlzstaVej0qm/t0zqIfv9ju6F86/ZfdcLFX 0clMgbf88Ts/3hPpNFz02Vx929lZ7kGS8s9PzvH29L8+++7VT+dk3VZGff+xQt9QseRyxp79 YldZTX7qffxkylsVdGrJWgudzFk2bB86Gpd8+ze5v/HY9g3bdgbsaHFUlebr/P1TvFOJpTgj 0VCLuag4EQDQREnjJwMAAA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 09, 2019 at 01:23:16PM -0700, Ira Weiny 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: > > > > When CONFIG_HAVE_GENERIC_GUP is defined, the kernel will use its own > > > > get_user_pages_fast(). > > > > > > > > In the following scenario, we will may meet the bug in the DMA case: > > > > ..................... > > > > get_user_pages_fast(start,,, pages); > > > > ...... > > > > sg_alloc_table_from_pages(, pages, ...); > > > > ..................... > > > > > > > > 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. > > 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. > > > > 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 > > > > Neither this nor the get_user_pages_unlocked is filling the pages a second The get_user_pages_unlocked() will call the handle_mm_fault which will allocate a new page for the empty PTE, and save the new page into the @pages array. > time. It is adding to the page array having moved start and the page array > forward. Yes. This will mess up the page order. I will read the code again to check if I am wrong :) > > Are you doing a FOLL_LONGTERM GUP? Or are you in the else clause below when > you get this bug? I do not use FOLL_LONGTERM, I just use the FOLL_WRITE. So it seems it runs into the else clause below. Thanks Huang Shijie > > Ira > > > start, nr_pages - nr, > > pages, NULL, gup_flags); > > up_read(¤t->mm->mmap_sem); > > } else { > > /* > > * 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); > > } > > } > > > >