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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 515D5C433FE for ; Wed, 10 Nov 2021 08:31:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F0F2F610A3 for ; Wed, 10 Nov 2021 08:30:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F0F2F610A3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 89B596B0073; Wed, 10 Nov 2021 03:30:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 823EF6B0074; Wed, 10 Nov 2021 03:30:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69D556B0075; Wed, 10 Nov 2021 03:30:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id 549D66B0073 for ; Wed, 10 Nov 2021 03:30:59 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1E2A97CA2F for ; Wed, 10 Nov 2021 08:30:59 +0000 (UTC) X-FDA: 78792350238.03.C4D118A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 677A0500030C for ; Wed, 10 Nov 2021 08:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636533058; 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=ayTHtFS6vxG5PWHe3XGZ+Bm3dOMLAgqt3D/qHsMzfog=; b=FC9aTLpl/ar8pqwo/5JHQlmYhF3g3qHEiHyTDRsmShZmYWTKrtwI03wsIlE+iZS3YGmr99 ZnNgUDLOHRgB/UQhxm9jDRge1cmE2Jut4x/cn01dafg3xlg3BdLTsxr10TZlzORyQ2LUe4 BHN/th5VXDDOc+tuT/ULKw58NvaOXtg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-201-96Ldg1TuNKi5tjyhZn8MQQ-1; Wed, 10 Nov 2021 03:30:54 -0500 X-MC-Unique: 96Ldg1TuNKi5tjyhZn8MQQ-1 Received: by mail-wm1-f70.google.com with SMTP id m1-20020a1ca301000000b003231d5b3c4cso2745240wme.5 for ; Wed, 10 Nov 2021 00:30:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=ayTHtFS6vxG5PWHe3XGZ+Bm3dOMLAgqt3D/qHsMzfog=; b=oDlo01PaILAlboN8yPcMPOCGBIQ1g6/meGu7ApQ/1/x6GTne9vMdp3k5fiJVNmOQON h23867bMZatOAgypsmnJ0CpqtOyn/qO6PK/Slcu5TSsjNc33w74VhUm3QaHPZehMfZta Kk/VW8qtuzutw1QUxt7bsBp5/Fs8p/4SzF6zGO7Z0nH149/Ywe8C/2T2CYST3a9i5Dvg S4W131Lgs5FzfTGrNRykfIq9Jg/oKkwe0tNSMLbnaCtYzGcY3JQ8ZRoXedNw3fl/SrZz FfJXzKkMIf/1hVE11Y7c+y5dQJXJe2f9WihjTx7QRYxBtPTRzbydndmk3qnfD9pezEwH FOBA== X-Gm-Message-State: AOAM532/+CX8ACbhglBqLJXwhqq25DGEpTCjSlOQjs6Duol2NmUpplBA 5kvVGQ4D/Z82DGHvK/apYD8BrUsb7LBu18T/vYuTMz58kXklm3pjPdJTC1EZAUUJhNYTst4v3CM ZHxGxR/0NPOM= X-Received: by 2002:a05:6000:1010:: with SMTP id a16mr17184403wrx.155.1636533053353; Wed, 10 Nov 2021 00:30:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8YcFMEsRvKaXtzYm0YXi/nOXwlwvFD48+I3aZMgZRH2q7e3nrnFqGxYiGaWtqCC/IDnNoZA== X-Received: by 2002:a05:6000:1010:: with SMTP id a16mr17184370wrx.155.1636533053092; Wed, 10 Nov 2021 00:30:53 -0800 (PST) Received: from [192.168.3.132] (p5b0c604f.dip0.t-ipconnect.de. [91.12.96.79]) by smtp.gmail.com with ESMTPSA id c5sm19156137wrd.13.2021.11.10.00.30.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Nov 2021 00:30:52 -0800 (PST) Message-ID: <793685d2-be3f-9a74-c9a3-65c486e0ef1f@redhat.com> Date: Wed, 10 Nov 2021 09:30:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v4] mm: Add PM_HUGE_THP_MAPPING to /proc/pid/pagemap To: Peter Xu Cc: Mina Almasry , Matthew Wilcox , "Paul E . McKenney" , Yu Zhao , Jonathan Corbet , Andrew Morton , Ivan Teterevkov , Florian Schmidt , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <20211107235754.1395488-1-almasrymina@google.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 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 677A0500030C X-Stat-Signature: 1ibqdujpzhu1uix7qd6591x5xuimz9n9 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FC9aTLpl; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf04.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1636533048-355711 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.11.21 09:27, Peter Xu wrote: > On Wed, Nov 10, 2021 at 09:14:42AM +0100, David Hildenbrand wrote: >> On 10.11.21 08:03, Peter Xu wrote: >>> Hi, Mina, >>> >>> Sorry to comment late. >>> >>> On Sun, Nov 07, 2021 at 03:57:54PM -0800, Mina Almasry wrote: >>>> diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst >>>> index fdc19fbc10839..8a0f0064ff336 100644 >>>> --- a/Documentation/admin-guide/mm/pagemap.rst >>>> +++ b/Documentation/admin-guide/mm/pagemap.rst >>>> @@ -23,7 +23,8 @@ There are four components to pagemap: >>>> * Bit 56 page exclusively mapped (since 4.2) >>>> * Bit 57 pte is uffd-wp write-protected (since 5.13) (see >>>> :ref:`Documentation/admin-guide/mm/userfaultfd.rst `) >>>> - * Bits 57-60 zero >>>> + * Bit 58 page is a huge (PMD size) THP mapping >>>> + * Bits 59-60 zero >>>> * Bit 61 page is file-page or shared-anon (since 3.5) >>>> * Bit 62 page swapped >>>> * Bit 63 page present >>>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c >>>> index ad667dbc96f5c..6f1403f83b310 100644 >>>> --- a/fs/proc/task_mmu.c >>>> +++ b/fs/proc/task_mmu.c >>>> @@ -1302,6 +1302,7 @@ struct pagemapread { >>>> #define PM_SOFT_DIRTY BIT_ULL(55) >>>> #define PM_MMAP_EXCLUSIVE BIT_ULL(56) >>>> #define PM_UFFD_WP BIT_ULL(57) >>>> +#define PM_HUGE_THP_MAPPING BIT_ULL(58) >>> >>> The ending "_MAPPING" seems redundant to me, how about just call it "PM_THP" or >>> "PM_HUGE" (as THP also means HUGE already)? >>> >>> IMHO the core problem is about permission controls, and it seems to me we're >>> actually trying to workaround it by duplicating some information we have.. so >>> it's kind of a pity. Totally not against this patch, but imho it'll be nicer >>> if it's the permission part that to be enhanced, rather than a new but slightly >>> duplicated interface. >> >> It's not a permission problem AFAIKS: even with permissions "changed", >> any attempt to use /proc/kpageflags is just racy. Let's not go down that >> path, it's really the wrong mechanism to export to random userspace. > > I agree it's racy, but IMHO that's fine. These are hints for userspace to make > decisions, they cannot be always right. Even if we fetch atomically and seeing > that this pte is swapped out, it can be quickly accessed at the same time and > it'll be in-memory again. Only if we can freeze the whole pgtable but we > can't, so they can only be used as hints. Sorry, I don't think /proc/kpageflags (or exporting the PFNs to random users via /proc/self/pagemap) is the way to go. "Since Linux 4.0 only users with the CAP_SYS_ADMIN capability can get PFNs. In 4.0 and 4.1 opens by unprivileged fail with -EPERM. Starting from 4.2 the PFN field is zeroed if the user does not have CAP_SYS_ADMIN. Reason: information about PFNs helps in exploiting Rowhammer vulnerability." > >> >> We do have an interface to access this information from userspace >> already: /proc/self/smaps IIRC. Mina commented that they are seeing >> performance issues with that approach. >> >> It would be valuable to add these details to the patch description, >> including a performance difference when using both interfaces we have >> available. As the patch description stands, there is no explanation >> "why" we want this change. > > I didn't notice Mina mention about performance issues with kpageflags, if so > then I agree this solution helps. The performance issue seems to be with /proc/self/smaps. -- Thanks, David / dhildenb