Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7327794rwr; Tue, 2 May 2023 12:59:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7iwrS3wI5jOUyj6UzOPJOcWwBYKesePEOzBOTYokMD/OcWXG5CFDM5Wy7eBjg5FbOoxVMh X-Received: by 2002:a17:90a:bd02:b0:23d:1143:c664 with SMTP id y2-20020a17090abd0200b0023d1143c664mr19048653pjr.31.1683057543994; Tue, 02 May 2023 12:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683057543; cv=none; d=google.com; s=arc-20160816; b=XkvQpZHdQDNRaNUS33yxKsmsYSadS8Re0RAPwTU8/pCMk0m6dnVYi+WBx+EHtAclHt 9ORnOLKgngb6i7QY5WDJDWE6BDS1qaogd+N0GKkUSEzoSGlJhQvIJYDvJ3sSnVOfDDZ1 zFFZDMQquKin5fdLlnn09ZreGfQqPYAFSzVemSWcBLSw3lNz/yEhNUqQ+vUN8YLuEdVD Soi9g7HHwDpj85gw2FtUr7Kv9r8AEc101b95eI8Hac7DNBJa7a1LuI+lt3tZSZl9TQ4G I7rpu0ZyayfkkyGAqwp3+82FPjUrcr/1m4gPebdv/d+UqhayeiGtdywHw5oCTgnOOdwg 8n4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WEozocFtC1MF/eLKX6k60Tc4cyy/cZXp+rUuv759qKQ=; b=u2UuKmtxSOLLsiCojefgLhd4x/JfOZ2YZrp9XkjhHuR4mSC/oOrvSK9VvURaKhzYap jJBGMWMWeYWEIsqH6ZN7sKpz849ucZivlQTyDoHBkuOufafDqdz37r/ecCkJBCd3WOKu Ok1DHGwzi6nxcAImbY7MdQzF0qVBBKUahqOWPc+7vfVJ5RC55JvdN6ksMtgo2XvmZIoB 8+aLkBOn+g/+TsIZJ+ZV7Tf6AzmnZTeq4cWf3M0NSkvgflp1GEOW4FI4PV/h1rhYpeW2 vQL7FZV8UJj/C7DrRWdoMHFC7YIoPNPnkp/q6aMN7FLRgp7fVdXbUvHLcN1YtQg15If+ Qa/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=KZxln+oq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a170903024d00b001a64fa4eb27si33524221plh.230.2023.05.02.12.58.46; Tue, 02 May 2023 12:59:03 -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=@gmail.com header.s=20221208 header.b=KZxln+oq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjEBTp3 (ORCPT + 99 others); Tue, 2 May 2023 15:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbjEBTp1 (ORCPT ); Tue, 2 May 2023 15:45:27 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EAFA11B; Tue, 2 May 2023 12:45:25 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3062d764455so1899863f8f.3; Tue, 02 May 2023 12:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683056724; x=1685648724; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WEozocFtC1MF/eLKX6k60Tc4cyy/cZXp+rUuv759qKQ=; b=KZxln+oq3LImf+LRQFD0qCtu0AGSzG9KubXRD4Q1Gt470PKWTvPO46MkvYdANnDfot WMCQBXBgzJOU5SuTc0nXZDekxwER2q70iXjYkDIft41htRddfCiBrbeyPJhS9KTxbxhm Rw1Wh6X34LNKhiCODiYNzteLUt8HJSjqzkU6H9SHuTZDm0yVtMmfXC8bMbsq8LyYtWZT TISJEBgqXIO/tUfJtqG4tbXbKetuph1sJqI+cL2fLt3oid5sjpVht6WM6UImaT915aIp BiokOY1tlqo1e1QRqTXlcNaiNx3EfCN0++cfyFZLy42mdPJqiMo20waAOZISMRNpvhQ9 2lXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683056724; x=1685648724; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WEozocFtC1MF/eLKX6k60Tc4cyy/cZXp+rUuv759qKQ=; b=hvL/7UVvnG7rJPQL9zS7+Ib5CcmImNWe7A9ArnAr99aK11wLSwwUyovGd/kqMwpJ87 dU83Ac23Z/JD3Q2oeVFfP9dkqRk6oWSqeHViqBrVeKJe3Ki05ngR6Yw1icmUzt1SibCe yTnM6TbvLrswlEtpFqb0iboR5IWZ4apgAILZFsnuLxbcG5WuPThgR8542BrEa7AFXCnK rcz2qnd3PnqDrqLj8O20GTUY6enuMJjYG5wOs/sA4KM0/a0jIHqe4dtuRwbNHu6mH0Ve r4r6ETt5LM8JUnVtJdGb8baLiuKukX+f0eTFtfSxmJ5lQSgj6+8GhlddDzDbBTt/CD7W bpsg== X-Gm-Message-State: AC+VfDyvgbS5niHkIQIZq0MswM4fMzxlNDJdjU+qnLEE/TFVAMwoKeMh YCqCRaPxSFvPImA/HUS51aE= X-Received: by 2002:a5d:5384:0:b0:2fe:562c:c0dc with SMTP id d4-20020a5d5384000000b002fe562cc0dcmr13408438wrv.40.1683056723727; Tue, 02 May 2023 12:45:23 -0700 (PDT) Received: from localhost (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.gmail.com with ESMTPSA id bl13-20020adfe24d000000b003062d3daf79sm6288950wrb.107.2023.05.02.12.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 12:45:23 -0700 (PDT) Date: Tue, 2 May 2023 20:45:22 +0100 From: Lorenzo Stoakes To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jason Gunthorpe , Jens Axboe , Matthew Wilcox , Dennis Dalessandro , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner , Richard Cochran , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Oleg Nesterov , Jason Gunthorpe , John Hubbard , Jan Kara , "Kirill A . Shutemov" , Pavel Begunkov , Mika Penttila , Dave Chinner , Theodore Ts'o , Peter Xu , Matthew Rosato , "Paul E . McKenney" , Christian Borntraeger Subject: Re: [PATCH v7 3/3] mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings Message-ID: References: <505b7df8-bb60-7564-af28-b99875eea12a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <505b7df8-bb60-7564-af28-b99875eea12a@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Tue, May 02, 2023 at 09:17:53PM +0200, David Hildenbrand wrote: > > +static bool folio_longterm_write_pin_allowed(struct folio *folio) > > +{ > > + struct address_space *mapping; > > + > > + /* > > + * GUP-fast disables IRQs - this prevents IPIs from causing page tables > > + * to disappear from under us, as well as preventing RCU grace periods > > + * from making progress (i.e. implying rcu_read_lock()). > > + * > > + * This means we can rely on the folio remaining stable for all > > + * architectures, both those that set CONFIG_MMU_GATHER_RCU_TABLE_FREE > > + * and those that do not. > > + * > > + * We get the added benefit that given inodes, and thus address_space, > > + * objects are RCU freed, we can rely on the mapping remaining stable > > + * here with no risk of a truncation or similar race. > > + */ > > + lockdep_assert_irqs_disabled(); > > + > > + /* > > + * If no mapping can be found, this implies an anonymous or otherwise > > + * non-file backed folio so in this instance we permit the pin. > > + * > > + * shmem and hugetlb mappings do not require dirty-tracking so we > > + * explicitly whitelist these. > > + * > > + * Other non dirty-tracked folios will be picked up on the slow path. > > + */ > > + mapping = folio_mapping(folio); > > + return !mapping || shmem_mapping(mapping) || folio_test_hugetlb(folio); > > +} > > BTW, try_grab_folio() is also called from follow_hugetlb_page(), which is > ordinary GUP and has interrupts enabled if I am not wrong. It does hold the PTL though, so can't fiddle with the entry. But that does suggest folio_test_hugetlb() should be put _before_ the irq disabled assertion then :) > > -- > Thanks, > > David / dhildenb >