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 4241EC25B06 for ; Wed, 10 Aug 2022 09:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0AF48E0002; Wed, 10 Aug 2022 05:37:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBB738E0001; Wed, 10 Aug 2022 05:37:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B81F68E0002; Wed, 10 Aug 2022 05:37:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AAAD38E0001 for ; Wed, 10 Aug 2022 05:37:20 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 81A63A05CB for ; Wed, 10 Aug 2022 09:37:20 +0000 (UTC) X-FDA: 79783179840.11.4A08EB9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 2699640071 for ; Wed, 10 Aug 2022 09:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660124239; 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=tgtUL/ut4ckTYGF2mnm2NIvF4nw0MtnKMGbr3fh8PYE=; b=A9CanXhgUj/p75gdpvYVyusXoxbvRRWNVmDPH8VKkt/In6N3C1buGWJ32AnlfLhPQfVaYp 0WTaylzeVie4a8sK1n9s/WvcHQAeK34WtwYGCkgxVEpGrDJ5yKb89DUP01hhRFl8sFX3++ 6v37PjUPCz9ZdgHWTF4SieFHhlqOx8s= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-530-gWpJCjpoOvaZkxKyaxSW0g-1; Wed, 10 Aug 2022 05:37:16 -0400 X-MC-Unique: gWpJCjpoOvaZkxKyaxSW0g-1 Received: by mail-wm1-f71.google.com with SMTP id c17-20020a7bc011000000b003a2bfaf8d3dso7195229wmb.0 for ; Wed, 10 Aug 2022 02:37:16 -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=tgtUL/ut4ckTYGF2mnm2NIvF4nw0MtnKMGbr3fh8PYE=; b=VU4qj2lKU11DFSCH3jAmWgMv8SQ2f7Bpm0EUS34+dGEZQssmfYG+fFj83i4pWvPXZ7 CrjRwp6fsKsWbQmMHn3Zn+KUct1dh5Q0oisYCq1rAEW5/9iKBDs8UPg85RpiDKB2kiWq Yp6/lHYJyoDxqXjVdrs3EabBw6fDTgeRV7LrF4vdfQnlEJFTOIFcVq+pg/mdjdpR4Kdg XoZwUo9JpkrL3NMfo9L8UH6VPyncf4rs5Zyzei0Zjcd+0n8XytLJE40c9JNwoesPiQfe Hk5FTlrDYsTdaxZqVY8go6yABRpRQpIlvr3e1vhFUWeuN84Y0LZSLN1XGekt2HfqN1f0 YkDA== X-Gm-Message-State: ACgBeo3vNO52IBiXoYUDJ4EQCdZ/lDZ6A5E2/icKA30uK4eVce0MPrlh 9NmBeqz0WGeUGwl+8ODYxkh+bZGdM6TUGPf/IR3+F6eqFrtjBI1FODYLS1MGh7f06j/W1MbgTky p6sPxA6fMhL8= X-Received: by 2002:a5d:5584:0:b0:220:6c21:2fbf with SMTP id i4-20020a5d5584000000b002206c212fbfmr16884029wrv.320.1660124235294; Wed, 10 Aug 2022 02:37:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR7wiJ4EkLf7y2zWa+evXh4h5i+8Ti76R2immsKuI2Y3gywe4sfOc8qVhE2oghIFgQyWoXzY7g== X-Received: by 2002:a5d:5584:0:b0:220:6c21:2fbf with SMTP id i4-20020a5d5584000000b002206c212fbfmr16884018wrv.320.1660124235026; Wed, 10 Aug 2022 02:37:15 -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 p23-20020a1c5457000000b003a54f5fcc5dsm1786318wmi.10.2022.08.10.02.37.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 02:37:14 -0700 (PDT) Message-ID: <12c65d91-5fc0-cb2e-c415-2b3447960b43@redhat.com> Date: Wed, 10 Aug 2022 11:37:13 +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> 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660124240; 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=tgtUL/ut4ckTYGF2mnm2NIvF4nw0MtnKMGbr3fh8PYE=; b=6GgVLoz5ThsFhJkwIUqXyEu3p/XgMMyndjKBpK+ZG+BadQiPLeXYtNsW6/ZPGLp8MDXph+ JVcJ2n8P3LJTeJlpkWmc19dvzrPvvxuYh4pvzsaaa8q7CCIX0gNsnRWM/OcLjKCnfXIQ9u /W8VDsRJzMpK8R6LMP11lGw0yK0UV2Y= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A9CanXhg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660124240; a=rsa-sha256; cv=none; b=ws8GaYmSzPRu5aqkaq3ICYEERy47Lb15v1/zWA926lChX6U+lbWRq4H9e3KwPrv8g+cd9X Mgs2p1rR8t6lVjCLl+WA81eYiJ3jHjAVAGnZI0Uwi5+zUctfQqMyaphBJ6PaoP2CamXUae QxAT/J6l87no7+5QTHZfMcxpvY+BMIk= X-Rspamd-Queue-Id: 2699640071 X-Rspamd-Server: rspam03 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A9CanXhg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Stat-Signature: mszzx4jw7zphu3eck71n38y7azbao6bz X-HE-Tag: 1660124239-566205 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 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. I mean triggering a write fault without VM_WRITE on !hugetlb works, so it would be easy to assume that it similarly simply works for hugetlb as well. And the code most probably wouldn't even blow up immediately :) -- Thanks, David / dhildenb