Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp549991rwd; Wed, 31 May 2023 02:00:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5no0rP4G0R7ylaDV3bpHcM6dHvNNX4KTpX3ojFwYaMnaBNHeQcJnwsS2cTeZb3yBWyy/QE X-Received: by 2002:a05:6870:e606:b0:192:7320:ce with SMTP id q6-20020a056870e60600b00192732000cemr2583642oag.40.1685523622328; Wed, 31 May 2023 02:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685523622; cv=none; d=google.com; s=arc-20160816; b=Z0KzA7OSC2hKu5zimEZvJgjfVwkVEtlKKiqBvOXRTR4aUaxVgo5AakfJ8bAyBMUCCD ArioOLFNwRJUYOhg5ak36VF+6EluS0H8SP964reEsgvuAMVMMoN6LVqQ3tLbrOgorlu6 VIObEuE/eWJC4YBnKsse8DsbIW8S2e2glyNAlOcIW3Rg9Hh74dDSzDWtndmSOEbXu7/d KCWSner8SL+T4WmMie1IcS+ZJ833/+cGr1rcOQUF0ggbstpySUX9d9bph/JFEk/6B3QV Av35BDOxEOonAcWAT7/gmyjLk7RMXZGiUvypbEe68sqx+Q4WuTpGTTEgtO/e9U6zbkTN AXOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=Nx2y8OB2aLxSFND9I+Qn5cRQvjq0n5CCY38YbkEtKAw=; b=Iphwz4jF5lBDCzcQBM0dZgkB4IN4LqpkEP+Tj9ZLTo2IGyqhuo/dLWnCZFLkVEdLpt I1SVPT1m2ahNguxPSR7jdDiSls2JjQRX6vYROx0lWwtPlWa5Uit2o/8qZqywGhbhasx+ 4Bun2eo+v+BD2SB7LKyQvrwhXBDna2UQ56djaKxId2UziqDSCgUoUgHf4Cf7EmvbS39Z pC0npJrHmBm/N3g/Tosw5VBUTaRrnBxcalNQMHTmI1AtmyeSBayo0TJuqntwmvSiua/B UF4NfF7/6xO/j1cKdNHZS27ZRsVLvkI1SZsTYvpAm/b3PZ5pkM6Jn1iTOpmgWNGH0Xiq oAEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ixlNjoWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i124-20020a625482000000b0064d48b75c5asi3192184pfb.357.2023.05.31.02.00.10; Wed, 31 May 2023 02:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ixlNjoWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235220AbjEaIsM (ORCPT + 99 others); Wed, 31 May 2023 04:48:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235072AbjEaIre (ORCPT ); Wed, 31 May 2023 04:47:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 485BEE42 for ; Wed, 31 May 2023 01:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685522796; 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=Nx2y8OB2aLxSFND9I+Qn5cRQvjq0n5CCY38YbkEtKAw=; b=ixlNjoWAXFVeavpP36sE8jWEe0LZaRUPwXtlCoVthyzyPrGmmavX3Qcr0qeVH56Tsl72As CCZyMZxNTl6Fd6eymywCzn0UT3B/JKEBc/rOv9ndLYBAEL7KP4iVK4D0I+br/c7ajeoUv+ finzqsz4rq9DoyitoRwW5J3QjKAMAss= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-DQv-zdoNPoSQ1QXlQoTVqw-1; Wed, 31 May 2023 04:46:33 -0400 X-MC-Unique: DQv-zdoNPoSQ1QXlQoTVqw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f613f5d290so91146905e9.2 for ; Wed, 31 May 2023 01:46:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685522792; x=1688114792; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nx2y8OB2aLxSFND9I+Qn5cRQvjq0n5CCY38YbkEtKAw=; b=dYYd6bS0ahZyp/y77WHJa8s/fDRwmrWHrHNpo6gZqAEc8IPoZgXWXXgRRdQb0KRyJL z3EkkJVRWD/+uJtNmY5OXIf32fg5fUVeR/UjoHc4Z3lKVzMEq2uNDafAg2alWUHyPZ7D uBA+UORJ/m1OX/bbO1gWbiPSlsLqIMcCkGtAzxwR6GSxhmY0/QNbM+e9uBZe32Z3Eqkw gGEq9XLTjG89DbxM+8yYI0DfozLT2Cr2zcrbfjaoHHzgFDIsf6+ITnwd1YZqkce6EJy6 QDEkCNub3BRz028miomH8BDGKDHhIjO9AfsQt1k+Xk34hUdFxBrdcI0n+f2rDUvIya9d 2eOA== X-Gm-Message-State: AC+VfDwm6+n4P0g0JV1O/gIMZMy19y+onQMrWSTo/alEzmcfLgVj6AFQ zMB+R5z8OHx9GkpmdMr1uMQCuD4aBp3RgFONjDr10xJWK0B79tgXW2WJj8msPtq5I7mMzu+xSP2 wYKG5+4Blwk++XtSLdA68cW+G X-Received: by 2002:a1c:ed14:0:b0:3f5:ffe2:91c0 with SMTP id l20-20020a1ced14000000b003f5ffe291c0mr3840030wmh.0.1685522792111; Wed, 31 May 2023 01:46:32 -0700 (PDT) X-Received: by 2002:a1c:ed14:0:b0:3f5:ffe2:91c0 with SMTP id l20-20020a1ced14000000b003f5ffe291c0mr3840011wmh.0.1685522791768; Wed, 31 May 2023 01:46:31 -0700 (PDT) Received: from ?IPV6:2003:cb:c749:cb00:fc9f:d303:d4cc:9f26? (p200300cbc749cb00fc9fd303d4cc9f26.dip0.t-ipconnect.de. [2003:cb:c749:cb00:fc9f:d303:d4cc:9f26]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c231100b003f31d44f0cbsm23714702wmo.29.2023.05.31.01.46.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 May 2023 01:46:31 -0700 (PDT) Message-ID: <492558dc-1377-fc4b-126f-c358bb000ff7@redhat.com> Date: Wed, 31 May 2023 10:46:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: David Howells Cc: 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 References: <20230526214142.958751-1-dhowells@redhat.com> <20230526214142.958751-2-dhowells@redhat.com> <510965.1685522152@warthog.procyon.org.uk> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v4 1/3] mm: Don't pin ZERO_PAGE in pin_user_pages() In-Reply-To: <510965.1685522152@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31.05.23 10:35, David Howells wrote: > David Hildenbrand wrote: > >>> Make pin_user_pages*() leave a ZERO_PAGE unpinned if it extracts a pointer >>> 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 million >> references ? > > Definitely pins. It's tricky because we've been using "pinned" to mean held > by a refcount or held by a flag too. > Yes, it would be clearer if we would be using "pinned" now only for FOLL_PIN and everything else is simply "taking a temporary reference on the page". > 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_page(). 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 not 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 speaker. > > Oh, I know. The problem is that "pin" is now really ambiguous. Can we change > "FOLL_PIN" to "FOLL_NAIL"? Or maybe "FOLL_SCREW" - your pages are screwed if > you use DIO and fork at the same time. > I'm hoping that "pinning" will be "FOLL_PIN" (intention to access page content) and everything else is simply "taking a temporary page reference". >> "Note that the refcount of any zero_pages returned among the pinned pages will >> not be incremented, and unpin_user_page() will similarly not decrement it." > > 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 be > separate. In any case (FOLL_PIN/FOLL_GET) you increment/decrement the refcount. If we have a separate pincount, we increment/decrement the refcount by 1 when (un)pinning. Sure, if we'd have a separate pincount we'd also not be modifying it. -- Thanks, David / dhildenb