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 AE01CC433EF for ; Thu, 27 Jan 2022 21:17:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95BC36B0071; Thu, 27 Jan 2022 16:17:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9088F6B0072; Thu, 27 Jan 2022 16:17:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A86C6B0073; Thu, 27 Jan 2022 16:17:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id 676B96B0071 for ; Thu, 27 Jan 2022 16:17:05 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1DBD085409 for ; Thu, 27 Jan 2022 21:17:05 +0000 (UTC) X-FDA: 79077327210.19.7447186 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf04.hostedemail.com (Postfix) with ESMTP id C07C540045 for ; Thu, 27 Jan 2022 21:17:04 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id me13so8777569ejb.12 for ; Thu, 27 Jan 2022 13:17:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vK3O5xU/kDvpC1TY8wAbZnvb+Z1YDXs3E7FOpCSGFrE=; b=e58gnAgOojyV60UkneFpVxVMsLU4Zov6g4GoK0ybOHVmrN9t/jNQcmtnU7ssHc5I+s vLxK0zG1wbIW7FadS4WnMA5s3bb0Ucu+Ra7WozizPzxJuNdSc8WY4Vxq0aTBGMioxHWq mrMsEtTC56V5TJrFEnzaXtVrVpbLtRY4GO7xn2ygSmlyuA/14102+3guY3/vK/o7man3 wzBaTMsDJbKdtgWo/OcqEYtzebzEBmk5AK3JCl38JGBhIjJI4u8L00Cew/qVaMjbWDj3 i4O3InHDsHUeEOLkqX8hxRJWC0cdxKn7I1sb1dDOO2en5NEAmZXwiUyra1prtabpF1wx ye+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vK3O5xU/kDvpC1TY8wAbZnvb+Z1YDXs3E7FOpCSGFrE=; b=Dz5YBbjyhAdDy5OiI+txt1vmjAdhet5Q0PRf2nFYFL2JFK+JyFeSMNFxUTkDLTjmiE cefafypqEsmLG/M/qsz0VDNsNwaImd4JindJF5z240kdow1oe+dmmmVlv4HBhZerj4jO ogQB1CRaNXGWv09z6XlJU73dLBYO2Iq9El7FbqPJzrXQvZTm+vB6YQA4SCyQFXM7JRDv Wk+37/m5N7gyI8ku9ykHriLHefa+X4iswe87phBEwyuCVkocfXx/M9JWYqMizLx/+OFe 5W+i8NSYyuPp6C/gRM9MgoWnoAB/5Cwv3rS/X4/lZg8JxLLIwKfB4PSJuizdh5iHncCP PtBw== X-Gm-Message-State: AOAM530YeM1KveY69HTXi7z/Jb18lgF8G6b8xQ4BDTgy9ueC9HHWg48J oDSIHvw4brJ8/i3oYj9j6P8JAhvZSlXFEix+d8E= X-Google-Smtp-Source: ABdhPJwNpo25p3cIrN5oTAXtkNb4Mi5A68K7YEBZvzb3Dl9MLwx/5LT7nXeEIdTd+aUkUYX7hbk+cIjmisD46+wZ15o= X-Received: by 2002:a17:906:4fcd:: with SMTP id i13mr4231891ejw.644.1643318223500; Thu, 27 Jan 2022 13:17:03 -0800 (PST) MIME-Version: 1.0 References: <20220120202805.3369-1-shy828301@gmail.com> <5b4e2c29-8f1a-5a68-d243-a30467cc02d4@redhat.com> <5a565d5a-0540-4041-ce63-a8fd5d1bb340@redhat.com> <2a1c5bd2-cb8c-b93b-68af-de620438d19a@redhat.com> In-Reply-To: <2a1c5bd2-cb8c-b93b-68af-de620438d19a@redhat.com> From: Yang Shi Date: Thu, 27 Jan 2022 13:16:51 -0800 Message-ID: Subject: Re: [v2 PATCH] fs/proc: task_mmu.c: don't read mapcount for migration entry To: David Hildenbrand Cc: Jann Horn , "Kirill A. Shutemov" , Matthew Wilcox , Andrew Morton , Linux MM , Linux Kernel Mailing List , stable Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 4qtnueiu1xn867pe1sud65g4fbkx1nc1 X-Rspam-User: nil Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=e58gnAgO; spf=pass (imf04.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.42 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C07C540045 X-HE-Tag: 1643318224-843684 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, Jan 26, 2022 at 10:54 AM David Hildenbrand wrote: > > >>> Just page lock or elevated page refcount could serialize against THP > >>> split AFAIK. > >>> > >>>> > >>>> But yeah, using the mapcount of a page that is not even mapped > >>>> (migration entry) is clearly wrong. > >>>> > >>>> To summarize: reading the mapcount on an unlocked page will easily > >>>> return a wrong result and the result should not be relied upon. reading > >>>> the mapcount of a migration entry is dangerous and certainly wrong. > >>> > >>> Depends on your usecase. Some just want to get a snapshot, just like > >>> smaps, they don't care. > >> > >> Right, but as discussed, even the snapshot might be slightly wrong. That > >> might be just fine for smaps (and I would have enjoyed a comment in the > >> code stating that :) ). > > > > I think that is documented already, see Documentation/filesystems/proc.rst: > > > > Note: reading /proc/PID/maps or /proc/PID/smaps is inherently racy (consistent > > output can be achieved only in the single read call). > > Right, but I think there is a difference between > > * Atomic values that change immediately afterwards ("this value used to > be true at one point in time") > * Values that are unstable because we cannot read them atomically ("this > value never used to be true") > > I'd assume with the documented race we actually talk about the first > point, but I might be just wrong. > > > > > Of course, if the extra note is preferred in the code, I could try to > > add some in a separate patch. > > When staring at the (original) code I would have hoped to find something > like: > > /* > * We use page_mapcount() to get a snapshot of the mapcount. Without > * holding the page lock this snapshot can be slightly wrong as we > * cannot always read the mapcount atomically. As long we hold the PT > * lock, the page cannot get unmapped and it's at safe to call > * page_mapcount(). > */ > > With the addition of > > "... For unmapped pages (e.g., migration entries) we cannot guarantee > that, so treat the mapcount as being 1." It seems a little bit confusing to me, it is not safe to call with PTL held either, right? I'd like to rephrase the note to: /* * The page_mapcount() is called to get a snapshot of the mapcount. * Without holding the page lock this snapshot can be slightly wrong as * we cannot always read the mapcount atomically. Holding PTL doesn't * guarantee calling page_mapcount() is safe for all cases either, for * example, migration entries. */ > > But this is just my personal preference ... :) I do think the patch does > the right thing in regard to migration entries. > > -- > Thanks, > > David / dhildenb >