From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDF04C25B07 for ; Wed, 10 Aug 2022 19:40:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 538656B0071; Wed, 10 Aug 2022 15:40:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E8818E0002; Wed, 10 Aug 2022 15:40:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 387DF8E0001; Wed, 10 Aug 2022 15:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 284C66B0071 for ; Wed, 10 Aug 2022 15:40:16 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F39291C6E37 for ; Wed, 10 Aug 2022 19:40:15 +0000 (UTC) X-FDA: 79784699190.29.B3DA5CC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 85D0C8017D for ; Wed, 10 Aug 2022 19:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660160415; 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=ywXwFTTYN19k6bKSmUxoUNC6PPsNakVJx+Pwn8GLIOw=; b=hDq+rCjuEQjavPwZ9yLpBF83hEDX9XpuqMCt/l18kBEnrjBP9wCMXi9DFLQ4wGF4/btnU4 7feCwFBNFbtjnF2dv6OZvLk40i16wspNOUBJrreIc4AXEE8Iq5gkUrfcyoidjlQrmB8eo2 YcQPS55QnuCVyPG32Lv4jn6QAFS+5ps= 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_128_GCM_SHA256) id us-mta-150-oeHr8AqtPvqZqf4wHDzbOw-1; Wed, 10 Aug 2022 15:40:13 -0400 X-MC-Unique: oeHr8AqtPvqZqf4wHDzbOw-1 Received: by mail-wm1-f70.google.com with SMTP id j22-20020a05600c485600b003a50fa6981bso1506418wmo.9 for ; Wed, 10 Aug 2022 12:40:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=ywXwFTTYN19k6bKSmUxoUNC6PPsNakVJx+Pwn8GLIOw=; b=20Q2wkJRkRTwP+LSJSzVb18sOO6S1krf1EI5O9hiJr1Vu9iTaEmFYwDzvdQeQmVUx3 ucAFMHcx1VShKW1zZjL0g0sGoHwL1n01+IMx01sl2LniQj47mizQUHhs99Uon6CA1HhL GG2psVgro/wvUmpo1U/78QYgn3AcStmNyZ6QRaTSwFzwMMoZ2D/t2Xkrh7EydDYkzxoF piLFgfJ9JN/lhIYpFuIBks3cyLge/oMFY+hI7KQqkiyFPAZ+yI5BEGbVirj8VI9mk1PQ 8BFpXnXmWH1++en+n6Q1JuEuQnlAHoMROkzzFpTuorJVTdADjSZsGVakpfqemDUqKxd5 J5nQ== X-Gm-Message-State: ACgBeo3T2KeVR9anHcpqQSALLfM3VLuK9AOe2YnHqEcsUydDR1q9hawP YEumj8bUBMbths7mZncypoECQeCZ9W8oJwktQ42bL6Ahs4Q3SaPCON3CWcHNLUSGff6c41cIL2H m4ZBOcAMBa7Q= X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr16712054wrb.336.1660160412787; Wed, 10 Aug 2022 12:40:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR5m2be9A/VIlIf4mcJpLGYLozKrToHSPpbPQj+VTs1y3MiK44ruwPLfFlxMAccMpfgCzQhKZA== X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr16712049wrb.336.1660160412519; Wed, 10 Aug 2022 12:40:12 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:1600:a3ce:b459:ef57:7b93? (p200300cbc7071600a3ceb459ef577b93.dip0.t-ipconnect.de. [2003:cb:c707:1600:a3ce:b459:ef57:7b93]) by smtp.gmail.com with ESMTPSA id t24-20020a1c7718000000b003a501ad8648sm3192271wmi.40.2022.08.10.12.40.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 12:40:12 -0700 (PDT) Message-ID: Date: Wed, 10 Aug 2022 21:40:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1 2/2] mm/hugetlb: support write-faults in shared mappings To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mike Kravetz , Muchun Song , Peter Feiner , "Kirill A . Shutemov" References: <20220805110329.80540-1-david@redhat.com> <20220805110329.80540-3-david@redhat.com> <4f644ac5-c40b-32d4-3234-c1dac3d09f83@redhat.com> <8b317ac7-f80e-4aab-4ad1-4e19a1a0740f@redhat.com> <12c65d91-5fc0-cb2e-c415-2b3447960b43@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660160415; a=rsa-sha256; cv=none; b=XYNFVI0SR0IaFkGQmmwsUqZXQMHP4k33E1KsVb1H165WNJoqL8/qOv3jt7zwKiogfDL/IW dN/e61fnIcb3UsKdWF9t/NVApwTAGMQ2sQu+Ta+BoVjcccQM/HokIOtLvuvNDXgrV4kldn eW9KC02WPp2Po4Km67AM6geKujoxew4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hDq+rCju; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660160415; h=from:from:sender: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:dkim-signature; bh=ywXwFTTYN19k6bKSmUxoUNC6PPsNakVJx+Pwn8GLIOw=; b=NHb0i/x2pCWvlN1hXkTf94uHgv41Vsn5q0FePJUxtnrS9kPdqEO263/w88mSbAPoZ+mzJz xRIap7pjcHtEUN5Q78VAs4ShXSjzSefjEAttnnmJa3BtLsLF0kimXcZAqZ19gp6d/aNC7z axsvx+B+P7Ab3358l/iKdj+J8INmmkg= X-Stat-Signature: efmn5ymjiji1p3or3is9xmtbtusrzr5w X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 85D0C8017D Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hDq+rCju; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-HE-Tag: 1660160415-101682 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 10.08.22 21:29, Peter Xu wrote: > On Wed, Aug 10, 2022 at 11:37:13AM +0200, David Hildenbrand wrote: >> On 09.08.22 00:08, Peter Xu wrote: >>> On Mon, Aug 08, 2022 at 04:21:39PM -0400, Peter Xu wrote: >>>> On Mon, Aug 08, 2022 at 06:25:21PM +0200, David Hildenbrand wrote: >>>>>>> Relying on VM_SHARED to detect MAP_PRIVATE vs. MAP_SHARED is >>>>>>> unfortunately wrong. >>>>>>> >>>>>>> If you're curious, take a look at f83a275dbc5c ("mm: account for >>>>>>> MAP_SHARED mappings using VM_MAYSHARE and not VM_SHARED in hugetlbfs") >>>>>>> and mmap() code. >>>>>>> >>>>>>> Long story short: if the file is read-only, we only have VM_MAYSHARE but >>>>>>> not VM_SHARED (and consequently also not VM_MAYWRITE). >>>>>> >>>>>> To ask in another way: if file is RO but mapped RW (mmap() will have >>>>>> VM_SHARED cleared but VM_MAYSHARE set), then if we check VM_MAYSHARE here >>>>>> won't we grant write bit errornously while we shouldn't? As the user >>>>>> doesn't really have write permission to the file. >>>>> >>>>> Thus the VM_WRITE check. :) >>>>> >>>>> I wonder if we should just do it cleanly and introduce the maybe_mkwrite >>>>> semantics here as well. Then there is no need for additional VM_WRITE >>>>> checks and hugetlb will work just like !hugetlb. >>>> >>>> Hmm yeah I think the VM_MAYSHARE check is correct, since we'll need to fail >>>> the cases where MAYSHARE && !SHARE - we used to silently let it pass. >>> >>> Sorry I think this is a wrong statement I made.. IIUC we'll fail correctly >>> with/without the patch on any write to hugetlb RO regions. >>> >>> Then I just don't see a difference on checking VM_SHARED or VM_MAYSHARE >>> here, it's just that VM_MAYSHARE check should work too like VM_SHARED so I >>> don't see a problem. >>> >>> It also means I can't think of any valid case of having VM_WRITE when >>> reaching here, then the WARN_ON_ONCE() is okay but maybe also redundant. >>> Using maybe_mkwrite() seems misleading to me if FOLL_FORCE not ready for >>> hugetlbfs after all. >>> >> >> The main reason we'd have it would be to scream out lout and fail >> gracefully if someone would -- for example -- use it for something like >> FOLL_FORCE. > > Having that WARN_ON_ONCE() is okay to me, but just to double check we're on > the same page: why there's concern on using FOLL_FORCE? IIUC we're talking > about shared mappings here, then no FOLL_FORCE possible at all? IOW, > "!is_cow_mapping()" should fail in check_vma_flags() already. This code path also covers the anon case. > > The other thing is I'm wondering whether patch 2 should be postponed anyway > so that we can wait for a full resolution of the problem from Mike. To make the code more robust and avoid any other such surprises I prefer to have this in rather earlier than later. As the commit says "Let's add a safety net ..." -- Thanks, David / dhildenb