From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2E65C004D4 for ; Thu, 19 Jan 2023 11:17:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B0AE6B0072; Thu, 19 Jan 2023 06:17:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 060D66B0073; Thu, 19 Jan 2023 06:17:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6AEB6B0074; Thu, 19 Jan 2023 06:17:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D3DC46B0072 for ; Thu, 19 Jan 2023 06:17:47 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A66CA1A023A for ; Thu, 19 Jan 2023 11:17:47 +0000 (UTC) X-FDA: 80371298574.22.9E1EF41 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 215DA100011 for ; Thu, 19 Jan 2023 11:17:45 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bJA+c0az; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674127066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GGtvmOi7utR7ohcsapzjMsFAAOBKArDiNLs/UoDdLrA=; b=FUf2ElabfeJLU4bQcJf+67N1n1/QaCSKAh5eKaWlanhJJs6Pl5w/ni1bWnQFCna1l7uiRh Bx8pIYnvYS4UYGcVXbv17GydYSxDxEPLJG6KvJ8SNyAfH05EzUhw5tul4iA1ClHVzswhGb esBhHL8IoKuoQjuoFWVqBpLSTvENHco= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bJA+c0az; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674127066; a=rsa-sha256; cv=none; b=txgYjfKeis52JPD1Hf+d/7hJP0FBXP1Z0yHPGk6xNjUVoV9+hl2ylqbiOToKLIUG9mGZoM V+T/CucOgp1ovmvE+yFctU6RxVbfCG7+QgqwvrDRjStavSjzGD+EfxY+3Oan85WrkJIIzv 63VSjI6evzhQ49hvV5pVhLk1DzJ1AhA= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 16CAE61AC8; Thu, 19 Jan 2023 11:17:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27695C433D2; Thu, 19 Jan 2023 11:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674127064; bh=nRwpHBvhB9HKLQp2Klt0Edk/XQHZNODTdmzqVbTKFJs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bJA+c0az4R6t9mysQyYbkzVLgH13Te2r6JN+8bTiQorMXEHybtqS+MCaIXMIX9I96 hdL0KEKFywBh9NsRKvFXRDWZZFRQNB8Uir2X7e0HaPzTqqB8TBqOZgyKwdU8rkttMF jCuwZFsVPYrYoIr9Os5Q9mRXES9VCYGQoVY88Dwqhe5+tuvB5jUFe1nS+Xa6pnBWdP 8qfLk68v+3VB6l7kitG5WDxVxSobiJS6T6VHi7QUh0p31Y4P7Y5f+6OqXYdXV2SVbS Lw7OVIeTbhgLvfPV3Ouq3ihpOy+B6bNAs/7o441gukDe1yYUL+GdsTzbQ3RTQMXkSU +Ecz68hYOmhDQ== Date: Thu, 19 Jan 2023 13:17:32 +0200 From: Mike Rapoport To: Jason Gunthorpe Cc: Alistair Popple , John Hubbard , linux-mm@kvack.org Subject: Re: [PATCH 3/8] mm/gup: simplify the external interface functions and consolidate invariants Message-ID: References: <0-v1-dd94f8f0d5ad+716-gup_tidy_jgg@nvidia.com> <3-v1-dd94f8f0d5ad+716-gup_tidy_jgg@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3-v1-dd94f8f0d5ad+716-gup_tidy_jgg@nvidia.com> X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: jzoebqxukoh4syuxdow34fhnrsjt68ht X-Rspamd-Queue-Id: 215DA100011 X-HE-Tag: 1674127065-285984 X-HE-Meta: U2FsdGVkX18hfa4A3ngOYXoB5g1cRRUd3NeUV666qzHjTxWYGKoey1ywK+VLoSvNsa6nepIXMKPdAEw04I+prh/o12p7v0P34ix9IjyVBovJtdRMonpolXAY+uFJW+4ZnGUNuq8/+6izqG+ymVME1CKkrFGfKyDesRFtx8m4LYWIJiDQvMMlqBDuKzDXHBYOokX9Z3CFKbiyFlij9N6o9cC7dsAP/3tYfoVVpkPPrg3Umv+oQ/vXOegB1XAYte2LP3GXmKJfO/r2PGBdk4SfGTTdUY9IBjxLQP3Ce9nTH3WtxbXPdqvoCmxHOMQhMDIsTwj0VmEwZ/aENdK6W+9moqHFD18SG2Db/f80qwGyDEzdjR9z7/RcqUoC/aE0uXwQyJ5Tqp3qbu4TlsiUnOQH8J84ok5Q5pUYqIkGIOpKYcXdtdBuXtGQP5YE4894J5VxVqOkmuYU4u9bWBkVPi51YS0hnPhYTKv1fW+nDWaXGENl0dcwN5t7wUM4Xwt3V+2aVU93bsyJKwCourFwxbmbREhXAPLFfPzy+yYUa05IS/JtPNpaFjMCrrbUfoOL/Me8+7dDwgfAX3O7h1VZ//O+taqDU2vuevlsiMKYaLjhNLcdjsTo9QFrtmj3p09Z1e+RWQ0HtsBcr8WJJQ6pTiRZoWuxdfXzc6VW1PL/8fzniW1HM6RCR3zYPhYuCFLWvfNHHKAd0ifRacmrXgBPXpXSxtsZQj/hQqhwxz3Gf7WVxI49mmKTan1z5nhFyDOJ7gbJKgiLOKv8rxCD/AliRolPAOXreI5FchDy5CAsDot0MaXWUIl/trK5ZQvigL1hvTA2JYorMkkY+KeRLH3Z7p0wU7VZxThfyKNkqDHHe0QvLmOff6/NxOs6VQFEeawkVeKm7rJvs02i+JCtcH+S3PbwaRrpcbN7+SY45z73WHN2pszLu5+77GTmCQISUEXFGZkmt+P+C/FTP8NcUdg2zgn RjD9vKlR onfWd+YXBgtaXaguvag0Wg2JexZlU5hLyZCA1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jan 17, 2023 at 11:58:34AM -0400, Jason Gunthorpe wrote: > The GUP family of functions have a complex, but fairly well defined, set > of invariants for their arguments. Currently these are sprinkled about, > sometimes in duplicate through many functions. > > Internally we don't follow all the invariants that the external interface > has to follow, so place these checks directly at the exported > interface. This ensures the internal functions never reach a violated > invariant. > > Remove the duplicated invariant checks. > > The end result is to make these functions fully internal: > __get_user_pages_locked() > internal_get_user_pages_fast() > __gup_longterm_locked() > > And all the other functions call directly into one of these. > > Suggested-by: John Hubbard > Signed-off-by: Jason Gunthorpe > --- > mm/gup.c | 150 +++++++++++++++++++++++------------------------ > mm/huge_memory.c | 10 ---- > 2 files changed, 75 insertions(+), 85 deletions(-) > > diff --git a/mm/gup.c b/mm/gup.c > index 2c833f862d0354..9e332e3f6ea8e2 100644 > --- a/mm/gup.c > +++ b/mm/gup.c ... > -static bool is_valid_gup_flags(unsigned int gup_flags) > +/* > + * Check that the given flags are valid for the exported gup/pup interface, and > + * update them with the required flags that the caller must have set. > + */ > +static bool is_valid_gup_args(struct page **pages, struct vm_area_struct **vmas, > + int *locked, unsigned int *gup_flags_p, > + unsigned int to_set) > { > + unsigned int gup_flags = *gup_flags_p; > + > /* > - * FOLL_PIN must only be set internally by the pin_user_pages*() APIs, > - * never directly by the caller, so enforce that with an assertion: > + * These flags not allowed to be specified externally to the gup > + * interfaces: > + * - FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY is internal only ^ are? > + * - FOLL_REMOTE is internal only and used on follow_page() > */ > - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) > + if (WARN_ON_ONCE(gup_flags & (FOLL_PIN | FOLL_TRIED | > + FOLL_REMOTE | FOLL_FAST_ONLY))) > return false; > + > + gup_flags |= to_set; > + > + /* FOLL_GET and FOLL_PIN are mutually exclusive. */ > + if (WARN_ON_ONCE((gup_flags & (FOLL_PIN | FOLL_GET)) == > + (FOLL_PIN | FOLL_GET))) > + return false; > + -- Sincerely yours, Mike.