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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73A16C77B73 for ; Wed, 31 May 2023 08:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234758AbjEaIhS (ORCPT ); Wed, 31 May 2023 04:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234693AbjEaIhL (ORCPT ); Wed, 31 May 2023 04:37:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E428185 for ; Wed, 31 May 2023 01:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685522162; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D2ZwdaLGqkNgpQd/gtgsXYogAn46nzSogOGGTIXtoVA=; b=HkNBGHhYAPjS8y/E37NU2RmMrgffeRY/Ztcy27DJMQGyh2VBAuw2BXC52Nd29EaO2TO1Dj /kkdt6iYtSry/7dS8J2DMx5wF2fLei2UA8MiaZ5AzVwxQHFWK+33UbX9Fc5oJnKp3XHWTc jCskUYdmN1stRJiqINvuCURn+weKObc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-477-akBoGxAJNLKPo3Ap7wG4_g-1; Wed, 31 May 2023 04:35:59 -0400 X-MC-Unique: akBoGxAJNLKPo3Ap7wG4_g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0837B800159; Wed, 31 May 2023 08:35:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32053112132C; Wed, 31 May 2023 08:35:53 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <20230526214142.958751-1-dhowells@redhat.com> <20230526214142.958751-2-dhowells@redhat.com> To: David Hildenbrand Cc: dhowells@redhat.com, Christoph Hellwig , Lorenzo Stoakes , Jens Axboe , Al Viro , Matthew Wilcox , Jan Kara , Jeff Layton , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH v4 1/3] mm: Don't pin ZERO_PAGE in pin_user_pages() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <510964.1685522152.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 31 May 2023 09:35:52 +0100 Message-ID: <510965.1685522152@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org David Hildenbrand wrote: > > Make pin_user_pages*() leave a ZERO_PAGE unpinned if it extracts a poi= nter > > to it from the page tables and make unpin_user_page*() correspondingly > > ignore a ZERO_PAGE when unpinning. We don't want to risk overrunning = a > > zero page's refcount as we're only allowed ~2 million pins on it - > > something that userspace can conceivably trigger. > = > 2 millions pins (FOLL_PIN, which increments the refcount by 1024) or 2 m= illion > references ? Definitely pins. It's tricky because we've been using "pinned" to mean he= ld by a refcount or held by a flag too. 2 million pins on the zero page is in the realms of possibility. It only takes 32768 64-page DIO writes. > > @@ -3079,6 +3096,9 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast); > > * > > * FOLL_PIN means that the pages must be released via unpin_user_pag= e(). Please > > * see Documentation/core-api/pin_user_pages.rst for further details= . > > + * > > + * Note that if a zero_page is amongst the returned pages, it will no= t have > > + * pins in it and unpin_user_page() will not remove pins from it. > > */ > = > "it will not have pins in it" sounds fairly weird to a non-native speake= r. Oh, I know. The problem is that "pin" is now really ambiguous. Can we ch= ange "FOLL_PIN" to "FOLL_NAIL"? Or maybe "FOLL_SCREW" - your pages are screwed= if you use DIO and fork at the same time. > "Note that the refcount of any zero_pages returned among the pinned page= s will > not be incremented, and unpin_user_page() will similarly not decrement i= t." That's not really right (although it happens to be true), because we're talking primarily about the pin counter, not the refcount - and they may b= e separate. David