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 917E5C00140 for ; Mon, 8 Aug 2022 20:21:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 027A68E0001; Mon, 8 Aug 2022 16:21:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF1A96B0073; Mon, 8 Aug 2022 16:21:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6E128E0001; Mon, 8 Aug 2022 16:21:45 -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 C25826B0071 for ; Mon, 8 Aug 2022 16:21:45 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 881A8C0FB4 for ; Mon, 8 Aug 2022 20:21:45 +0000 (UTC) X-FDA: 79777546170.04.81D9B11 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id E6F9518016A for ; Mon, 8 Aug 2022 20:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659990104; 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=W2SyjU4nlrlicLQvmsmQrDI50xPp70ZBk8GnqHoj+j0=; b=f+aGXjZ40riLXjGISla6J4l7khNu/0/zOG75f7xbrxb8gS3QjZHotah9opK91vEXrPyYbE 8t+0pGOopL2WGCrRxw/T5u++pxP2n6EQDA87PAhpGTiBL7EtHUTrtmoK3m35o3IRJDsJTP h7u29bY+N8fz2pFFfORKWUEBYqnXuME= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-sqv9_k5uOTuYKA69ApAyAQ-1; Mon, 08 Aug 2022 16:21:43 -0400 X-MC-Unique: sqv9_k5uOTuYKA69ApAyAQ-1 Received: by mail-il1-f198.google.com with SMTP id s5-20020a056e02216500b002dde8b02f62so7289253ilv.15 for ; Mon, 08 Aug 2022 13:21:43 -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=W2SyjU4nlrlicLQvmsmQrDI50xPp70ZBk8GnqHoj+j0=; b=dJsIBMqOlz/vApfrko9KdnPbx2pyxA/WgvYUXPYVrFrfvGa2foAkP9x3isGnM1Kg5H fVtO0hLp/j20h31sVtC6JjyPzz2SLF+eTRknWRfp6lm1QiSBqaB6ptcAZx6aWouKsrz3 lkOj5uPsHJ7UGOX2qllez7HySIl9KwgrYeNIpxoZKldGJqb2ACGUMCxXew37aZASM0BS +OLv9iuIR0/StfJxv2TVu5iWPKEfGS/3ifWQVCSCpI5nw7euUcZgV4NcPD/OR5wvw311 RMOSoIyuJHh4WxhzVb/FQmtMptMy2hXQdXqSTSOwR8hoVN1AfNMp+71Me/R0VgGHRUIr fS4w== X-Gm-Message-State: ACgBeo3/5oNAgyk61KP0keKsA6kcPa26zyARH5Xwvw5SM07nMWANGD5+ TSxHPpg65ODat+LrnkDKYqkXSey+dIyKHbxgTqVxG5oOP93xCwqvU5HgnWImp8bggCVEwK6ib0Y uyHQiuTG8dqA= X-Received: by 2002:a92:6a12:0:b0:2e0:e25c:e0ea with SMTP id f18-20020a926a12000000b002e0e25ce0eamr3995268ilc.116.1659990102669; Mon, 08 Aug 2022 13:21:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR5gj5a06A0E3N4wf7ujPUZGjSh7N4Ok4Scx3ueVjFKxPQHpyF6e8zLpFWLnL9ZHZTOdnnUbGQ== X-Received: by 2002:a92:6a12:0:b0:2e0:e25c:e0ea with SMTP id f18-20020a926a12000000b002e0e25ce0eamr3995262ilc.116.1659990102486; Mon, 08 Aug 2022 13:21:42 -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 m9-20020a02a149000000b003427967df49sm5583702jah.19.2022.08.08.13.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 13:21:41 -0700 (PDT) Date: Mon, 8 Aug 2022 16:21:39 -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: <8b317ac7-f80e-4aab-4ad1-4e19a1a0740f@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659990105; a=rsa-sha256; cv=none; b=yCvgoNvuw5ghOMUA0xrYDxshz7n8APFGSnDC/zXCsBbSllr1MWfU32euHgyJUX+6CR0kfK YBX0OQC8Ik+LLs5ohG64DCumZCnD7Rcbv9E7riCD4c+goPHw1dJzjWD7SQ2PBHNr5N0aru c967elLdc3w5uPwKEoM0SZPU2CWlvAY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f+aGXjZ4; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1659990105; 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=W2SyjU4nlrlicLQvmsmQrDI50xPp70ZBk8GnqHoj+j0=; b=7fIFTVVof0ZarQ2Os5zNK9kLXKQzMIO9P0uWhdFWWWxs4SaNyN0JW/EOMFjOXHlqwXS3Kl or/ofEWzeDwSZVDIJhFIq3es0sjUJ2qXAaEbD1uaddBEk3+DEEvol6zStyfwF6SsZ1U/Yi AVAXTXUmwTDFMigueGaABmD8ie3qPpY= X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: pdf9j6anq4zmyco4imt6w887sq48shwe X-Rspamd-Queue-Id: E6F9518016A Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f+aGXjZ4; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1659990104-182707 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 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. But then OTOH using WARN_ON_ONCE on the VM_WRITE check is probably not right, because iiuc it can be triggered easily by the userspace. E.g. as simple as mapping hugetlb as RO+shared then write to it? So maybe_mkwrite() seems not an option now - IIUC we really need that !VM_WRITE check to fail properly, but just without the warning to pollute dmesg? Thanks, -- Peter Xu