Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1248997rwd; Thu, 25 May 2023 09:55:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uXEqsEmkcrJYHmyaRwOPzFGrJGXTQQkPN+doRhe4H6Oxt1eZH72k1vubkL45P9aqL1U/G X-Received: by 2002:a17:903:6c3:b0:1a6:f93a:a135 with SMTP id kj3-20020a17090306c300b001a6f93aa135mr2124777plb.61.1685033734361; Thu, 25 May 2023 09:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685033734; cv=none; d=google.com; s=arc-20160816; b=fKVuTZIFCiVOE/zXEX0KumFVoyvKsa1xBgwf5jmnT8qVINcTTZNEDIqQo3/NQHJQnx iOLL7KgNaHUMsJpjYVUu1Z/Ic8vA/P5aGviy99EL3eTQQox/Hton5FdDv+N0DTv7s4LI ji+JfKEBJHaES4s25skUS0QYevlUqzwlJEh2NHBiZPA0aM1nq912C5L6u02N4vzgyku3 EiOtMmyR+HEn4hAidrlshDU7k1ItObim9Uhu0+hqagQNtes7LCJ2pF4m0FJ1VH+Abk1n V5WFo5bKClpsdKg4MM2CwmZ8JXvLzTuMclNs8fnfHGMztVMrdwN/kv+pT2UA8YhvZD0a 1Fvw== 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 :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=dkhHTV4yWf72EQW+jJcHV7CXxI+jmEVf1Ed42wfSOPk=; b=fDoiIL9TDZ/8q/l95Yr8/fTElGzZA44nzc5KdGcSxYzPi0TUhWk4l+AQK/BmFxRR0F 1ac/Xsknnm5TZoub0lg7NvgAIDg5AFX20kiI9x0alK/6JWgNya+OvfwKiZknA80H59kR yV+0LRZETRSnlF65lVz5l1qOJBkgPpAUkp7BK4/kJHWjXgkQ3FV9xqeG0pTN9RINP3Ib 4pGZro5QQoMXkxQJX9L9o6MNfG+gYzIroae8c1g/yBataXw+bBvZw/+Yn1magLRSLsBk /fpnIc8NKLd+Tw7+aRjoQpB6GLdHm6MErLRaaDoGSQBzVPjVTQAckVjcCMPfxkf4hZNk WPzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WaF8xPR1; 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 k3-20020a170902c40300b001a647aadbe0si2006231plk.568.2023.05.25.09.55.19; Thu, 25 May 2023 09:55:34 -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=WaF8xPR1; 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 S239157AbjEYQsu (ORCPT + 99 others); Thu, 25 May 2023 12:48:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbjEYQsk (ORCPT ); Thu, 25 May 2023 12:48:40 -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 600D6197 for ; Thu, 25 May 2023 09:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685033277; 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=dkhHTV4yWf72EQW+jJcHV7CXxI+jmEVf1Ed42wfSOPk=; b=WaF8xPR1lvpTp2woEH13cl6poE2DWKBxMZF263M3bBj3RhjEQTAyBiQ69U+M2wecyaf9It x4MeaXSd7ID8A/OBqptVXepCQ6TI2RPlcvlxljbpxfesNZQ9f7MzK39XD6+JNSOlcGAKOc 1OGojcsaqGKxWq39kdCVrV2jDUzYkpE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-hVhqOnHfNhWtTnTmJYDdSA-1; Thu, 25 May 2023 12:47:56 -0400 X-MC-Unique: hVhqOnHfNhWtTnTmJYDdSA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f6038dc351so3429875e9.3 for ; Thu, 25 May 2023 09:47:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685033275; x=1687625275; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dkhHTV4yWf72EQW+jJcHV7CXxI+jmEVf1Ed42wfSOPk=; b=JmeLBjXJ93i+2kkaNSN9bNpmYzH494W2ZpJ5HOgjNKu7uF1JQIj/B6rlFEM8YYJtvo zAQb2fJ8+BjMtpboliJwfZiocYJmlR/pMlEKBv1rNsADCNrYRdpbXgZ4KEJkJRCerPzR XokHA2x9YZFGd1uq9O+BdNExOO0iW5PpCs/l52xv3Xv9PjCoOsNyfe4DY5XBnwdwFrgh ns9n/OFtRe6lRKhcXbPklHT6w1vYxw4xzE4/AawZgiS6NcrHap6P1cqwTmH2S+q010hK Q30uvDwO/42rwjel6F+k77fCRQ8ggZV9kfm+NXniH2G566XduBM6/Zk+PSphWwz7L8P+ jj8A== X-Gm-Message-State: AC+VfDwYP9jagyepm/2QV/m817qoixu/s01a2mbPLOX5EaxN4oO30tuG i6yPzvrf6BZEAER5k8hzkCnphcfIndIkAxmkG0iaSBl3xEejEsy7Ps7dDTCwCRzBTprl/6iVopQ sB0B0iPcx0yaYQzqcUkImT+tc X-Received: by 2002:a1c:4c0e:0:b0:3f6:d2f:27f7 with SMTP id z14-20020a1c4c0e000000b003f60d2f27f7mr2643838wmf.17.1685033275006; Thu, 25 May 2023 09:47:55 -0700 (PDT) X-Received: by 2002:a1c:4c0e:0:b0:3f6:d2f:27f7 with SMTP id z14-20020a1c4c0e000000b003f60d2f27f7mr2643817wmf.17.1685033274602; Thu, 25 May 2023 09:47:54 -0700 (PDT) Received: from ?IPV6:2003:cb:c709:600:4306:6a2b:57d5:2da1? (p200300cbc709060043066a2b57d52da1.dip0.t-ipconnect.de. [2003:cb:c709:600:4306:6a2b:57d5:2da1]) by smtp.gmail.com with ESMTPSA id b5-20020a5d45c5000000b002fda1b12a0bsm2397513wrs.2.2023.05.25.09.47.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 May 2023 09:47:53 -0700 (PDT) Message-ID: <97970ae6-e912-912a-1755-8d7bbb1131d0@redhat.com> Date: Thu, 25 May 2023 18:47:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [RFC PATCH 1/3] mm: Don't pin ZERO_PAGE in pin_user_pages() Content-Language: en-US To: David Howells , Christoph Hellwig Cc: 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: <20230525155102.87353-1-dhowells@redhat.com> <20230525155102.87353-2-dhowells@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230525155102.87353-2-dhowells@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 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 25.05.23 17:51, David Howells wrote: > Make pin_user_pages*() leave the ZERO_PAGE unpinned if it extracts a > pointer to it from the page tables and make unpin_user_page*() > correspondingly ignore the ZERO_PAGE when unpinning. We don't want to risk > overrunning the zero page's refcount as we're only allowed ~2 million pins > on it - something that userspace can conceivably trigger. > As Linus raised, the ZERO_PAGE(0) checks should probably be is_zero_pfn(page_to_pfn(page)). > Signed-off-by: David Howells > cc: Christoph Hellwig > cc: David Hildenbrand > cc: Andrew Morton > cc: Jens Axboe > cc: Al Viro > cc: Matthew Wilcox > cc: Jan Kara > cc: Jeff Layton > cc: Jason Gunthorpe > cc: Logan Gunthorpe > cc: Hillf Danton > cc: Christian Brauner > cc: Linus Torvalds > cc: linux-fsdevel@vger.kernel.org > cc: linux-block@vger.kernel.org > cc: linux-kernel@vger.kernel.org > cc: linux-mm@kvack.org > --- > mm/gup.c | 25 ++++++++++++++++++++++++- > 1 file changed, 24 insertions(+), 1 deletion(-) > > diff --git a/mm/gup.c b/mm/gup.c > index bbe416236593..d2662aa8cf01 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -51,7 +51,8 @@ static inline void sanity_check_pinned_pages(struct page **pages, > struct page *page = *pages; > struct folio *folio = page_folio(page); > > - if (!folio_test_anon(folio)) > + if (page == ZERO_PAGE(0) || > + !folio_test_anon(folio)) > continue; > if (!folio_test_large(folio) || folio_test_hugetlb(folio)) > VM_BUG_ON_PAGE(!PageAnonExclusive(&folio->page), page); > @@ -131,6 +132,13 @@ struct folio *try_grab_folio(struct page *page, int refs, unsigned int flags) > else if (flags & FOLL_PIN) { > struct folio *folio; > > + /* > + * Don't take a pin on the zero page - it's not going anywhere > + * and it is used in a *lot* of places. > + */ > + if (page == ZERO_PAGE(0)) > + return page_folio(ZERO_PAGE(0)); With the fixed check, this should be return page_folio(page); I guess. -- Thanks, David / dhildenb