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 3D587C00140 for ; Wed, 10 Aug 2022 19:52:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C0628E0001; Wed, 10 Aug 2022 15:52:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86EE86B0072; Wed, 10 Aug 2022 15:52:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70F0D8E0001; Wed, 10 Aug 2022 15:52:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 61E936B0071 for ; Wed, 10 Aug 2022 15:52:43 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2B23040A19 for ; Wed, 10 Aug 2022 19:52:43 +0000 (UTC) X-FDA: 79784730606.24.86F2A54 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 9FD80140061 for ; Wed, 10 Aug 2022 19:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660161162; 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: in-reply-to:in-reply-to:references:references; bh=w05t+rLGLxKHngeNj1Dk/emo7DjYevCR6PViqoPcu98=; b=RPKKYsT3iZwVQgFMJKXUcXNsd/QH25o0jtuDhTGiucKeKs10wj7eLHlatmX8Cd2ZZuc6Ha xEervzTDpwiCDtZ/2l8FNbXx5Fy5sRdezNEDsJxKbF4ZLvwIhQCUyERk3iuMMqQoK/8Uzm aojz8mYH/ZxJoAiekDLMI85mS7aSrCs= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-137-meMAPbgFOK2wNrgH4H68ZA-1; Wed, 10 Aug 2022 15:52:41 -0400 X-MC-Unique: meMAPbgFOK2wNrgH4H68ZA-1 Received: by mail-io1-f72.google.com with SMTP id l18-20020a6bd112000000b0067cb64ad9b2so8693754iob.20 for ; Wed, 10 Aug 2022 12:52:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=w05t+rLGLxKHngeNj1Dk/emo7DjYevCR6PViqoPcu98=; b=DwjjXvFmubMWoBFH/2qNUxRLRtAMI3u+zOyuU/WmggzSDtXsZSJ5mcY8975uxjm2Fl i5v0HUVi8t2yRomHs0J+HI8UR5fOmKKiW8qBNcwz2C2z9Cdr14vYX3lKbiqcYsPQyxNF uTGpdXzknT7z3Q7C+xfv8/L2qNwPJAr3epjLaTSW5Np+dm29lmBTscEOFZcZFm7sZI91 16pXS6AApiFKtG5as1DJ8yeen+KEgwHuY0IyT4rtA/by3ShTnHY+IKt7Apjz5g8Y9vkI RM7PAjLGdSBH/AQJYeaxH8NC5VF4YNcNMPHRXVqIpRtZngikfV4X5FAUCpaUkQS2YLSC sKtw== X-Gm-Message-State: ACgBeo0ZBbfGwO7wosrd3a3gKsYmBLw8mrJUybKckZQqvo0/N3K2nzvN PPUphQD0bEMNUHvjBRENEGG9L0kHkCi+MJwjOSUQGZ+KPv6Mm0BwKsoILQ/I8L5Jt4s3a9A6zSJ nUdvhKNiLgB0= X-Received: by 2002:a5d:9d9e:0:b0:67c:2675:50a with SMTP id ay30-20020a5d9d9e000000b0067c2675050amr12220053iob.184.1660161160416; Wed, 10 Aug 2022 12:52:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR4E1ySyuz/xm3IUeQGZWCYW0/w8nq9zXzROPbsMRuRJzvlRvQXA+i6JOt8Th+E/1MwIlG0UHA== X-Received: by 2002:a5d:9d9e:0:b0:67c:2675:50a with SMTP id ay30-20020a5d9d9e000000b0067c2675050amr12220047iob.184.1660161160187; Wed, 10 Aug 2022 12:52:40 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id s24-20020a02cf38000000b0034339c2dd5fsm1464329jar.91.2022.08.10.12.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:52:39 -0700 (PDT) Date: Wed, 10 Aug 2022 15:52:38 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mike Kravetz , Muchun Song , Peter Feiner , "Kirill A . Shutemov" Subject: Re: [PATCH v1 2/2] mm/hugetlb: support write-faults in shared mappings Message-ID: References: <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> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RPKKYsT3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660161162; a=rsa-sha256; cv=none; b=bbM0zY2tIgiJI90vr1K/Et5sVhW0VTRtc3poSByNN5f32Sjq6U0PpHgj3m9XjpE03Y/0Az 3veRoCM6AiNOPhjZo25mSeji4B4ctXVFTozn/cyMShJOKnJvMMQPu1D0x4syQD6EKucHYm JbTnuVA88lyrwK/krtk/HyNe9juGg40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660161162; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w05t+rLGLxKHngeNj1Dk/emo7DjYevCR6PViqoPcu98=; b=3PXpzEGwJGrJoXWxblGgipEm2phPboKTNNVVGaBfXuc8/pxhIn9Qm09vSroAP+J4+xa5yv iZ0a+EmqRXRKrfKaeWSUPM2rgz5HA8uETo/M85SXg6vzp7iQFaTbpSqBgQYAWZ8+afXFXo HpfBFlRCePPzKi62uii8PmQN2h+ehM4= X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RPKKYsT3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: hgyetgsgaimwew7qpjmc5mueb1m1heuu X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 9FD80140061 X-HE-Tag: 1660161162-702392 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 Wed, Aug 10, 2022 at 09:40:11PM +0200, David Hildenbrand wrote: > 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. But this specific warning is under the VM_MAYSHARE if clause just added in this patch? My understanding is any FOLL_FORCE will always constantly fail before this patch, and it should keep failing as usual and I don't see any case it'll be failing at the warn_on_once here. So again, I'm fine with having the warning, but I just want to make sure what you want to capture is what you expected.. > > > > 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 ..." Sure, no strong opinion. I'll leave that to Mike. Thanks, -- Peter Xu