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 727AFC77B7A for ; Wed, 31 May 2023 08:36:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E315A8E0001; Wed, 31 May 2023 04:36:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE15E6B0074; Wed, 31 May 2023 04:36:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C81AC8E0001; Wed, 31 May 2023 04:36:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B5F9D6B0072 for ; Wed, 31 May 2023 04:36:03 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6C171402D1 for ; Wed, 31 May 2023 08:36:03 +0000 (UTC) X-FDA: 80849892606.30.819B122 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 7D22F40017 for ; Wed, 31 May 2023 08:36:01 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aYblUXwi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685522161; a=rsa-sha256; cv=none; b=4ihGELQQI49LqfKJ6NqOdXI3tluqvp1euZ4EIQAxz2UMGznOqL7mCVet495SR0qUtRfIpC o7WXHVzIfYXes2HpWuSmjiZgEnnAhsgH1GE8+8PRjcybbTmhGsgHYx1ZdY+Euetba20v3Q kEWQk0Y+fdjGTMOsj0pDrT7ub1UcuGc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aYblUXwi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685522161; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D2ZwdaLGqkNgpQd/gtgsXYogAn46nzSogOGGTIXtoVA=; b=zAYwDbHyEtAu64iHNbPJbMDTVkRAAA+5gpjI4JdDRz9hdVq97xHdnfhmhBFhI0kZUkLjPb gl7ihev4Dw/xrd9nNzq4tVgzReRn+6b7tzcQsfgIXUMpIOX9vrumWUdxq6GGVcMGRhTvJt SsXvvULmk0AeRPrv+8L32FUN1UfVm2M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685522160; 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=aYblUXwizfKgiQQoVuNJ6fLIw92ujLoftgMZtuzChUFzJCbtxweXEGt206LSSLKb5qPghd nosxmvMWFz6/WpI72nEcWRisXubcSM5HB7XXWtHbSFrt/hYR3LT3NJQ1lIAwdOfP9BYLVF wcFJMKA1hTR644OD0FlosWtXCkL2ueg= 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 X-Rspam-User: X-Rspamd-Server: rsp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a+WqGu V7aW/1DtnCsEtA2gsFJlLuUFbMmI0zuSge57yeqP8ZxXN0UoP8h31idrBsoVcFrU/9lSzMUz1MuCpH8ImtzSLS+t0YvLQCG31iOJde9jTTiu3Amr2MHzZp1Ld0myGead68Hd+thfF7Z62gfz3c/S7FhH5+ubVlxBo5C8gf0/yNcXYRxLfFrUOgi0GXBcJMr2JuPEpAe+uen6VqrEjlcLSc4Ff4fbqHioSEHRz 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: 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