Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7125927ybi; Thu, 13 Jun 2019 10:01:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7ZwuegwSU+yb+9+lQORe8Rh3JrIwaDb61/njtWp620pkFbnh58FVCH4jRvVB6bEsl99Kb X-Received: by 2002:a17:902:b691:: with SMTP id c17mr66226830pls.107.1560445294418; Thu, 13 Jun 2019 10:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560445294; cv=none; d=google.com; s=arc-20160816; b=S7VFlRcws6BnpP5Faobyme9ELCSxOi/jRKB9IAVVabSC0LebrDW6UV+HQSwcEf8VOm EhnvKLYUBzZoOfVq/gfiksN128S+R5rU7nXqtpy2IIzulQfq0oFb55N0/3U4ummI8JSu 7k/89j4eXElDMGRImxe7I4wzaWYzwpYHWG4Q5l8Uxi0JSnozZU+TYqGSGC52kZdOvDrg VSPRoANLB2G8OONVF3xdUjmEscuieLdZpNg6fvrCv3PBCdnVPwvKdDh2n7jr488VmVvr zZSk5v8/T1Qip7q0MF718G+WbMpN0q28DWJK6WAl1b+I+4NYaDvPxLHkWUrIShKqwNjw f6Jw== 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 :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=wq9rAsPaxnT+MWeaQyCG0bTAAecSDhi0iHcA45NgI+k=; b=V+KkR/Tme/kaqDRdqcQApbucMtfN1wTssireUXS4h6R+OQv1MZCoxkH1cpe7dezIgC BYECXtzeXutpwKykrpyrryTjqspJJ2SU0DIFMT8ZfkOgwD9zT5lKaTZqxIAAGLrpCxoi Eol8Jzh2lTijwRwDJWF3w93MuYfekfOFhFTZq+l5U0RDe9x+M/RbRPOp8i45FHVO47+s udDgvf2jLYhbwHLtC86t4DXV/+oR8Hpd0ENI0DCaNreZYpkZsHeu6bVQXhgxPqdQlYi6 k5tPF1hP/j7mMuqkPT/bg9TQWMjYtMEPHWGOuAaRhz/aV8LIkvs0MB6VdhJmHZl7LYUo QwSQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si240911pgu.316.2019.06.13.10.01.19; Thu, 13 Jun 2019 10:01:34 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729753AbfFMRBJ (ORCPT + 99 others); Thu, 13 Jun 2019 13:01:09 -0400 Received: from mga04.intel.com ([192.55.52.120]:15714 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729744AbfFLXtM (ORCPT ); Wed, 12 Jun 2019 19:49:12 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2019 16:49:11 -0700 X-ExtLoop1: 1 Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by orsmga002.jf.intel.com with ESMTP; 12 Jun 2019 16:49:11 -0700 Date: Wed, 12 Jun 2019 16:50:31 -0700 From: Ira Weiny To: Pingfan Liu Cc: "Aneesh Kumar K.V" , "linux-mm@kvack.org" , Andrew Morton , Mike Rapoport , "Williams, Dan J" , Matthew Wilcox , John Hubbard , "Busch, Keith" , Christoph Hellwig , "linux-kernel@vger.kernel.org" Subject: Re: [PATCHv3 1/2] mm/gup: fix omission of check on FOLL_LONGTERM in get_user_pages_fast() Message-ID: <20190612235031.GF14336@iweiny-DESK2.sc.intel.com> References: <1559725820-26138-1-git-send-email-kernelfans@gmail.com> <87tvcwhzdo.fsf@linux.ibm.com> <2807E5FD2F6FDA4886F6618EAC48510E79D8D79B@CRSMSX101.amr.corp.intel.com> <20190612135458.GA19916@dhcp-128-55.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190612135458.GA19916@dhcp-128-55.nay.redhat.com> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 12, 2019 at 09:54:58PM +0800, Pingfan Liu wrote: > On Tue, Jun 11, 2019 at 04:29:11PM +0000, Weiny, Ira wrote: > > > Pingfan Liu writes: > > > > > > > As for FOLL_LONGTERM, it is checked in the slow path > > > > __gup_longterm_unlocked(). But it is not checked in the fast path, > > > > which means a possible leak of CMA page to longterm pinned requirement > > > > through this crack. > > > > > > Shouldn't we disallow FOLL_LONGTERM with get_user_pages fastpath? W.r.t > > > dax check we need vma to ensure whether a long term pin is allowed or not. > > > If FOLL_LONGTERM is specified we should fallback to slow path. > > > > Yes, the fastpath bails to the slowpath if FOLL_LONGTERM _and_ DAX. But it does this while walking the page tables. I missed the CMA case and Pingfan's patch fixes this. We could check for CMA pages while walking the page tables but most agreed that it was not worth it. For DAX we already had checks for *_devmap() so it was easier to put the FOLL_LONGTERM checks there. > > > Then for CMA pages, are you suggesting something like: I'm not suggesting this. Sorry I wrote this prior to seeing the numbers in your other email. Given the numbers it looks like performing the check whilst walking the tables is worth the extra complexity. I was just trying to summarize the thread. I don't think we should disallow FOLL_LONGTERM because it only affects CMA and DAX. Other pages will be fine with FOLL_LONGTERM. Why penalize every call if we don't have to. Also in the case of DAX the use of vma will be going away...[1] Eventually... ;-) Ira [1] https://lkml.org/lkml/2019/6/5/1049 > diff --git a/mm/gup.c b/mm/gup.c > index 42a47c0..8bf3cc3 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2251,6 +2251,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, > if (unlikely(!access_ok((void __user *)start, len))) > return -EFAULT; > > + if (unlikely(gup_flags & FOLL_LONGTERM)) > + goto slow; > if (gup_fast_permitted(start, nr_pages)) { > local_irq_disable(); > gup_pgd_range(addr, end, gup_flags, pages, &nr); > @@ -2258,6 +2260,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, > ret = nr; > } > > +slow: > if (nr < nr_pages) { > /* Try to get the remaining pages with get_user_pages */ > start += nr << PAGE_SHIFT; > > Thanks, > Pingfan