Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp902161rwr; Wed, 3 May 2023 07:41:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5z9VK7uOfQ2cjHLleX+h6F8vVPghlU7C+Ii75HKJXQ+5IZpbz/VHDfHDmmvuX1U/MDCpjd X-Received: by 2002:a05:6a00:a21:b0:63b:5257:6837 with SMTP id p33-20020a056a000a2100b0063b52576837mr7031903pfh.1.1683124875410; Wed, 03 May 2023 07:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683124875; cv=none; d=google.com; s=arc-20160816; b=Q+YfLPTIllXSQfmCILtmO5wQ1kJsbS0tFtC2fRn/WYiuTljIDnbl4SJx7KdOSBf/ei LWp205h+cMIR7BRm1EmHpf4iirYafWXxUT6koBss04idzZ5IUAdLCeSRcbzcIEsObqDg AUjNJ8Cl/YQXJkBuMAy9tZFLTtdPLoTiqGZ71A8j7Uw39kW2gqD7koD163glVuLfQifM dAw2mdc5+TCJ5a/+XM6X+VAX2QmDrVHsPt/veZWh987Olislg9veI1eatBUKwsvQ3N2C ZXGJxxkvibB1hymKUyeQmUucZqVAJVp6yqU964uiP4wME03r/cLgg9i9jfTk/4G194ao roog== 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=nFXd5ix15SvNReqhl4i1pG9MIhuegRONOWBlaLSwSeQ=; b=gvQyuxnQN95+lBgdOpjd2PaYri8/7xFrhcBrdfIfYbr2nu3qvT/pf6pKtqcuypzzUM Yb+oA2arkiYrujUTiQzY5Rt+e0meYxQAZJXArI47+MM+6LIQKvBkF82NYfOBMZj5OpQm hPLxiRfHH919kf6EfPJsNBE08ezT3iw3lQpu1ne54aS7HInKjTBESVM2ZRNni+3/2wWA Qn04gnc6O/3lj8Mzn+fEGAvwkhDxPtNrD+vxsQdo7CsC+AwGyk53htHnV2APi2uo8EHh 652F78p83aHOx5CJgOA5t/DLYrpM39dqml2cA3ZDFVPn2ECC8CxeIbfTy+udcL1+zHPN 4SvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="jOjXn/+Z"; 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 h1-20020aa796c1000000b00635ebd8854esi33776937pfq.173.2023.05.03.07.40.58; Wed, 03 May 2023 07:41:15 -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="jOjXn/+Z"; 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 S230070AbjECOe3 (ORCPT + 99 others); Wed, 3 May 2023 10:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjECOe2 (ORCPT ); Wed, 3 May 2023 10:34:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E2FA6A57 for ; Wed, 3 May 2023 07:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683124387; 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=nFXd5ix15SvNReqhl4i1pG9MIhuegRONOWBlaLSwSeQ=; b=jOjXn/+Ze6v00vPc9Bw5aM91h6OaAspjWeWS9H/Yhpecb7Sy+fv+xMGVn+337aulV21WL9 ELPXoBt2AmnFDxWQUXvHATA+LzQ/L9aBQfe3/l0rMN4s4Kd35ddwOiKS/RQQrpG/TCnkSO TH8+ZIfrZoKgE+59Xatsf8PPTmPgOto= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-27-REs1sQqUNYWD1etgv-ztyA-1; Wed, 03 May 2023 10:33:06 -0400 X-MC-Unique: REs1sQqUNYWD1etgv-ztyA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f171d201afso31911475e9.0 for ; Wed, 03 May 2023 07:33:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683124385; x=1685716385; 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=nFXd5ix15SvNReqhl4i1pG9MIhuegRONOWBlaLSwSeQ=; b=J3ax3Ct6ktVkD4OLu89yVpnFgZuoLyq6hreb7rhKGabNU8xLO7wy65dhLjj8clIobV 6X5Yt+BiiCtsR84+6TGfGpeU623jK0nzQm+8pAOuwkF920PUeXGmFNiZn5BcX5MEd7IE ABQ6I6oqGYT7EdtnQ3QP/fRsM03SN1qg+zqIwhAXkTLjAqlcY3Xm/YiUKP2woUp+WUEi vXw2XvQ2qu8WtuVKEDYrdlhcLjHNYKoqolDM5xTiITZ6T3lDAOPZADrbtBSSSTBT11Vy IMdKmLR4fdBBXxdvlpSbQqCSzXQemZqMjPN319emZioK0ugOhkrTq66M2wf5jhB5MR2G kd/g== X-Gm-Message-State: AC+VfDwUZ495qGvja/oZ+x9XgD0XDsxkKyu/GPbm7OztyW5ydaRqjAbW 7xQHBdibvWz/JgayyW6dmssUGeWDrl9JGSsuxg/1NyFeKtTnejT0IpnBKuJYEL+JuXMUg3YmX4p MJacd4Kt1Ax7uI9aTD8t7ZqJy X-Received: by 2002:a1c:f217:0:b0:3f2:5641:1477 with SMTP id s23-20020a1cf217000000b003f256411477mr15136878wmc.2.1683124384971; Wed, 03 May 2023 07:33:04 -0700 (PDT) X-Received: by 2002:a1c:f217:0:b0:3f2:5641:1477 with SMTP id s23-20020a1cf217000000b003f256411477mr15136833wmc.2.1683124384528; Wed, 03 May 2023 07:33:04 -0700 (PDT) Received: from ?IPV6:2003:cb:c711:6a00:9109:6424:1804:a441? (p200300cbc7116a00910964241804a441.dip0.t-ipconnect.de. [2003:cb:c711:6a00:9109:6424:1804:a441]) by smtp.gmail.com with ESMTPSA id u24-20020a7bc058000000b003f173987ec2sm2063013wmc.22.2023.05.03.07.33.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 May 2023 07:33:03 -0700 (PDT) Message-ID: <052b66e9-eed2-15a4-cecf-fa26f5cc49c9@redhat.com> Date: Wed, 3 May 2023 16:33:01 +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: [PATCH v8 2/3] mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings Content-Language: en-US To: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: 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 References: From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.5 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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 03.05.23 00:51, Lorenzo Stoakes wrote: > Writing to file-backed mappings which require folio dirty tracking using > GUP is a fundamentally broken operation, as kernel write access to GUP > mappings do not adhere to the semantics expected by a file system. > > A GUP caller uses the direct mapping to access the folio, which does not > cause write notify to trigger, nor does it enforce that the caller marks > the folio dirty. > > The problem arises when, after an initial write to the folio, writeback > results in the folio being cleaned and then the caller, via the GUP > interface, writes to the folio again. > > As a result of the use of this secondary, direct, mapping to the folio no > write notify will occur, and if the caller does mark the folio dirty, this > will be done so unexpectedly. > > For example, consider the following scenario:- > > 1. A folio is written to via GUP which write-faults the memory, notifying > the file system and dirtying the folio. > 2. Later, writeback is triggered, resulting in the folio being cleaned and > the PTE being marked read-only. > 3. The GUP caller writes to the folio, as it is mapped read/write via the > direct mapping. > 4. The GUP caller, now done with the page, unpins it and sets it dirty > (though it does not have to). > > This results in both data being written to a folio without writenotify, and > the folio being dirtied unexpectedly (if the caller decides to do so). > > This issue was first reported by Jan Kara [1] in 2018, where the problem > resulted in file system crashes. > > This is only relevant when the mappings are file-backed and the underlying > file system requires folio dirty tracking. File systems which do not, such > as shmem or hugetlb, are not at risk and therefore can be written to > without issue. > > Unfortunately this limitation of GUP has been present for some time and > requires future rework of the GUP API in order to provide correct write > access to such mappings. > > However, for the time being we introduce this check to prevent the most > egregious case of this occurring, use of the FOLL_LONGTERM pin. > > These mappings are considerably more likely to be written to after > folios are cleaned and thus simply must not be permitted to do so. > > This patch changes only the slow-path GUP functions, a following patch > adapts the GUP-fast path along similar lines. > > [1]:https://lore.kernel.org/linux-mm/20180103100430.GE4911@quack2.suse.cz/ > > Suggested-by: Jason Gunthorpe > Signed-off-by: Lorenzo Stoakes > Reviewed-by: John Hubbard > Reviewed-by: Mika Penttilä > Reviewed-by: Jan Kara > Reviewed-by: Jason Gunthorpe > --- Acked-by: David Hildenbrand -- Thanks, David / dhildenb