Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4805704rwr; Sun, 23 Apr 2023 13:51:51 -0700 (PDT) X-Google-Smtp-Source: AKy350YymvOPywbSVZ9pgKsxJ/wSWNBfm4V2dPNXCm7GrxQPdEmpzqQiqZ40z2GgV5HzklmDaHEb X-Received: by 2002:a17:903:124a:b0:1a5:27d2:b6de with SMTP id u10-20020a170903124a00b001a527d2b6demr19492741plh.3.1682283111103; Sun, 23 Apr 2023 13:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682283111; cv=none; d=google.com; s=arc-20160816; b=YX6YGJ1IuvT+mM1Naruy8TpcrUc6WudOVF9PSpz7I8VfAYWstn7lwG2D6oTWY86WrN giq4PjmCwLjGdYTsdUJRKCOPs+XSWPbGHPQJymLxNIPtNUUiSCBiOTTMFwBrAlnCAwub l9jSi5suL3vnI5X582iRtVkP1J02XGqqIzJC2xPHrVBTaMt6W5hYdaYQ534sbBQwx8V7 4vF6IkCNlXmBIRP4vecbMrd6hNGIvlca7l6Z3Di1VHQz676eqsvZ5bDDHs+aWqkGXrog SwgIIQ95DIsa5B5fbxD9trLHibIt7qGHNua/9g9QBARF5ngw+Q4KWjheDPl2ZXeb4ECO gEag== 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=9DaWjR3sBt/MB4A/BsoBVVrHZIqBShz9wV60JqEIpNw=; b=mSQ52+DAiQcG3FBsq4NO1sfy7Y6KQDAfuvmh0gJu1EUFn7ul6lDbv6LMb5yjQ1T9lS NCYmwqloaShTqDuuZWatxTWH9bSr/LaRAXTuRFMwFLNlH9YMS8j3sjrCTqS1uyuzH7w9 9YPa0EUmI2NKw8UHjwa10kog3ua5RxUgYGt58atEt7GLlHEqB3oJUNKqAF66eIL6ONXy ybaVUhUBUlIjzAmcyIe3ymEtQjWA2aMYtKN+WB+bMDJsyNs1Z2qt9nDHqoCyL8W210vn qpIKbDHadWR8zEoJGx8YsujEXh7H/Ni52qOZ6rQY1fGcqewjUj/FUHfdzaMH+ulY7UVa 6XbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OTvbplYF; 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 ls4-20020a17090b350400b0024988ecf25bsi13602728pjb.86.2023.04.23.13.51.28; Sun, 23 Apr 2023 13:51:51 -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=OTvbplYF; 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 S229660AbjDWTlD (ORCPT + 99 others); Sun, 23 Apr 2023 15:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjDWTlC (ORCPT ); Sun, 23 Apr 2023 15:41:02 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C254F1; Sun, 23 Apr 2023 12:41:00 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-2fe3fb8e25fso2128440f8f.0; Sun, 23 Apr 2023 12:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682278859; x=1684870859; 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=9DaWjR3sBt/MB4A/BsoBVVrHZIqBShz9wV60JqEIpNw=; b=OTvbplYFel6puUd9xiVtcmdFcIopxiUAKTZ3clqSvTurQ7cm0qEwdzp46/cpNTJzQU aMeUhMsxKMMw4vogrT72mv362gDPONVE/mW4rAONfsNiswuEm4G8NQ9TQr/4mhzqxthc EPtYvANUtrimsfAe+QxnhtiiIICjlKgvKLypNhfcqDWM4QskqliaM3fpcA4XH5L8Gxs5 UtGT85QM5CHQDBzQ32Ua5Q0yJTPLApaAubXw4+qeT3fR28WAa3Eiw2I77HMyt4R0HaPm XImq/wiODepque1bHxqzsttdrXm0FZ8jlLGdO+rECHQp/nWkgeHUU3cug2joDC8CStjT QnFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682278859; x=1684870859; 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=9DaWjR3sBt/MB4A/BsoBVVrHZIqBShz9wV60JqEIpNw=; b=Kzc9kZLkmDea3ZdXGvY4VhAmjXUlwmN5cRAeBuf5BIePsJuUmjGPdNALyKcnMvkzps PziVp1Bm8VMiP2OMmiKzTrgvMH5lg1u8qILHg9S7FNRRRgpxnUhHKjQFXWuABALGNg9Z C5TT0+cmnlvjdrXj0sVQpg1AgVmkhLgFZNxDXbvlxuFO7FM/APLiKpXObNEB6N4jrQYS 44HGo/TcrggZUmJHnQWR4UXnBcVzJh/aBvD8tSTx3iworrbqOub+QZUQCSwbA1BW02FZ bWA6F4AjPsBkPjXVYDPSJMR2zrRjGkRSVsyLXOA6qLnWe3HvNT5iXmlF54NQB5ppM/Vm p1vw== X-Gm-Message-State: AAQBX9dFxOOoTb8X6iwaha7cPU0xf5WY1irWauMz4iu4iAMzjAUixLdx xn07uVEw7pl1diPUPDPiQ10= X-Received: by 2002:adf:eb4d:0:b0:2f4:d4f2:e2dd with SMTP id u13-20020adfeb4d000000b002f4d4f2e2ddmr8457564wrn.41.1682278858573; Sun, 23 Apr 2023 12:40:58 -0700 (PDT) Received: from localhost ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.gmail.com with ESMTPSA id d13-20020adfe88d000000b002e55cc69169sm9223073wrm.38.2023.04.23.12.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 12:40:57 -0700 (PDT) Date: Sun, 23 Apr 2023 20:40:53 +0100 From: Lorenzo Stoakes To: Simon Horman 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 Subject: Re: [PATCH] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Sun, Apr 23, 2023 at 09:32:01PM +0200, Simon Horman wrote: > On Sat, Apr 22, 2023 at 02:37:05PM +0100, Lorenzo Stoakes wrote: > > It isn't safe to write to file-backed mappings as GUP does not ensure that > > the semantics associated with such a write are performed correctly, for > > instance filesystems which rely upon write-notify will not be correctly > > notified. > > > > There are exceptions to this - shmem and hugetlb mappings are (in effect) > > anonymous mappings by other names so we do permit this operation in these > > cases. > > > > In addition, if no pinning takes place (neither FOLL_GET nor FOLL_PIN is > > specified and neither flags gets implicitly set) then no writing can occur > > so we do not perform the check in this instance. > > > > This is an important exception, as populate_vma_page_range() invokes > > __get_user_pages() in this way (and thus so does __mm_populate(), used by > > MAP_POPULATE mmap() and mlock() invocations). > > > > There are GUP users within the kernel that do nevertheless rely upon this > > behaviour, so we introduce the FOLL_ALLOW_BROKEN_FILE_MAPPING flag to > > explicitly permit this kind of GUP access. > > > > This is required in order to not break userspace in instances where the > > uAPI might permit file-mapped addresses - a number of RDMA users require > > this for instance, as do the process_vm_[read/write]v() system calls, > > /proc/$pid/mem, ptrace and SDT uprobes. Each of these callers have been > > updated to use this flag. > > > > Making this change is an important step towards a more reliable GUP, and > > explicitly indicates which callers might encouter issues moving forward. > > nit: s/encouter/encounter/ > Ack, I always seem to leave at least one or two easter egg spelling mistakes in :) Will fix up on next respin (in unlikely event of no further review, hopefully Andrew would pick up!)