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 6DF37C00140 for ; Mon, 8 Aug 2022 22:08:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5311E6B0071; Mon, 8 Aug 2022 18:08:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B9C06B0072; Mon, 8 Aug 2022 18:08:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 333648E0001; Mon, 8 Aug 2022 18:08:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1E16A6B0071 for ; Mon, 8 Aug 2022 18:08:13 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E1DF51A01FD for ; Mon, 8 Aug 2022 22:08:12 +0000 (UTC) X-FDA: 79777814424.28.22C5CE7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 7988118017F for ; Mon, 8 Aug 2022 22:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659996491; 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=YQ8C+2+wwMYd+/eKAYReWcvetA2Bfz8WaHNNc7Hh+0s=; b=RVH/7TZXW6Jg86NLa0D5whbdyHmCwB2xp0HXdzFpg2NS0RNirJOKSznQB00dL1kENdD7Az mA2jhix7oYTSrXAyKXdAYZ4FMGPk0AsRJoYjuF4i1DTVtgNAPnxMBE/Fevw06n1PyHiFKq tDqQGgBgF+UYmj6ajZDh/U5fD+t3GnE= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-529-Fv8xaNltNsaA-x0TlCLOfQ-1; Mon, 08 Aug 2022 18:08:04 -0400 X-MC-Unique: Fv8xaNltNsaA-x0TlCLOfQ-1 Received: by mail-il1-f199.google.com with SMTP id s3-20020a056e021a0300b002e10f0e8965so2487493ild.23 for ; Mon, 08 Aug 2022 15:08:04 -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=YQ8C+2+wwMYd+/eKAYReWcvetA2Bfz8WaHNNc7Hh+0s=; b=E5tcGopvxH7bU+Sm3iQKhoQIDsDzSy4Ehm8eAzrEZSmgqjwtSY1RzAJe/02ZD56zv+ 5mydc61SA+xLY4TC+vu6xJB0sRq3H8X1bVgGanfjJEbJFFVmXj0lK7AwQSGa56Kg1vG/ 4XBsKSGwOjqeERAur7HDBPPPrW/BMhLJjqdKCBZeMbfl3kuUOi27c5PQukiCtM+Ntdaf IQK1C5tudEbP/4dI4HXYu8xiL5lctPnVRKJcphoV1OMv79GOMJOebmeA9IyaoKiNyjQk abc59aS0QWf4hzFMCIZ8gUGDSe/i/r7uCwo9OU2SIvj+mgVoybIM8KdTVtr12Ng13mst UlSw== X-Gm-Message-State: ACgBeo3er8emqGwvgOCHsuX7iXpn7GT9PKUmPxY0Ks8fh61wy+84bANx P5O6J6Ymqaxm40dJgq/sezSWB2b/6RfJc5Us31CV6/TL2ag5RIb2gkiuhGuoAZIrlamF1M/D7eG eujFPk/ul9xs= X-Received: by 2002:a05:6e02:1a48:b0:2df:443:fe1a with SMTP id u8-20020a056e021a4800b002df0443fe1amr9574494ilv.264.1659996483568; Mon, 08 Aug 2022 15:08:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR64i2ipjaPkYMQxVPXhZdL8CBTayyhbEDdMwRIlK9Eub6ZsTD+NjpQc4gAj2TlnDMeELRQDdw== X-Received: by 2002:a05:6e02:1a48:b0:2df:443:fe1a with SMTP id u8-20020a056e021a4800b002df0443fe1amr9574484ilv.264.1659996483371; Mon, 08 Aug 2022 15:08:03 -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 f17-20020a926a11000000b002df4dccf449sm321285ilc.64.2022.08.08.15.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 15:08:02 -0700 (PDT) Date: Mon, 8 Aug 2022 18:08:01 -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-1-david@redhat.com> <20220805110329.80540-3-david@redhat.com> <4f644ac5-c40b-32d4-3234-c1dac3d09f83@redhat.com> <8b317ac7-f80e-4aab-4ad1-4e19a1a0740f@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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659996492; 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=YQ8C+2+wwMYd+/eKAYReWcvetA2Bfz8WaHNNc7Hh+0s=; b=3oPiXy0DAVZdAxrfP3qUrbdBVciN0Qg00s1n1k651ZSixuUQ258tggRfIZEa/EirAgU7Xo SqktLjJAYflPWD38gIUIhUYn1Jkjx7nrV7ov2EJkSW1Wb8pCtev+de2TbyKPr3ojbccsu/ 8YxOmrl6ZnNKypWz1G139vn2R0uHopY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RVH/7TZX"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1659996492; a=rsa-sha256; cv=none; b=YZK7lvMo2OITE3JJfUyYgloTfSo0kDIlmCXf1udL+8WdmwD1kkkPygiiIXegp8Y2Oyi/CM Zbw7BqyoX9toxkNr8TGnrY5Yj0VdrfngaXtP96kiCVyhCFp2HGLkpJ86lhyC9rhujocasb ErLi1+PZ0Kn1pZ6JZKihhdzdWDgp1RI= X-Rspamd-Queue-Id: 7988118017F X-Rspamd-Server: rspam03 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RVH/7TZX"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: o4d1k3i7nrrkmymrjco1uhfefuq47y4q X-HE-Tag: 1659996491-476794 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 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. -- Peter Xu