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 CE1E3C25B07 for ; Fri, 5 Aug 2022 15:52:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3F9B8E0002; Fri, 5 Aug 2022 11:52:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEECA8E0001; Fri, 5 Aug 2022 11:52:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB7398E0002; Fri, 5 Aug 2022 11:52:29 -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 CBEEE8E0001 for ; Fri, 5 Aug 2022 11:52:29 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9ABF0C17F3 for ; Fri, 5 Aug 2022 15:52:29 +0000 (UTC) X-FDA: 79765981218.03.EDC97D4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id AA51B180125 for ; Fri, 5 Aug 2022 15:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659714747; 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=XJd5vUiMu1Gz3OoROmpTft8Oc5UhIyzSv8pitRPvQWw=; b=EgWJG4ZtlutdeUSDG7NQBKtR0zdinF2G+67v8RFJqgt3dyeGzPkfoWtCtG9/gtSzaQUwUL QGu/FUEBDhesyzJSYv+qRZAuYLl1kxbK4vLMwArmyh4BtL5AMTRpbUGiBn1hgCuQ4R4CIz AN6TvfMcGSEci6+TB/XnLKt4J29oGJY= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-538-GF6L__TrNbKZ55Ek4WV2Vg-1; Fri, 05 Aug 2022 11:52:21 -0400 X-MC-Unique: GF6L__TrNbKZ55Ek4WV2Vg-1 Received: by mail-qt1-f198.google.com with SMTP id a6-20020ac86106000000b0033f73d965acso2174338qtm.7 for ; Fri, 05 Aug 2022 08:52:20 -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=XJd5vUiMu1Gz3OoROmpTft8Oc5UhIyzSv8pitRPvQWw=; b=EqF7Yot2w6I3mhM8Si7keI28ekxyiYLrLGfDycUhk+Uwetv1YprUjtuGNRYSRfBzz4 9UDEoMGW8nDPg/TKS7KRrT0uzJJq3nxk16nHj53cSjpnA5H2hOeBH4pdkW5zVRdiv6qW hdeN2rvtE0GqOivVY1csK6TQ1QZBthtpd/hTExLau9WvceOtwCL4KgRDafTAD4I/mbGE 8EOu1H6LEVYcjxvADFWxASKjs850M3rz/L4YOYpJ3HdVk/lNAgZ7q4vO2SsxCz352dEp AQioJJ7vmJonPUIU3weAK9zknsUqyVk2Q2BVRn2P2zkHioyyNOdWEYHhTSWl9wHMiGnb Eb7A== X-Gm-Message-State: ACgBeo2D4f1IQF1RhlH4Zsk15Jl4c0wBTI/jZJjFlVQqx/L59+C9BtUB r7yosXhWtFj13YGkRmbaKSDlmchFFAn7gNApZFN5MciZRkdOaucTvgoyGZvpAMCIdQBIx1ZhTCi MP7PUp9sOb/4= X-Received: by 2002:a05:620a:29ce:b0:6a7:1379:62d4 with SMTP id s14-20020a05620a29ce00b006a7137962d4mr5775581qkp.604.1659714740347; Fri, 05 Aug 2022 08:52:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR5JFGGRynPG//0bT7lkXw3mUchQmJr4xYcUMTVvohUPZtgG4jRRHPvVUMuI86q1KrBB0jSOcA== X-Received: by 2002:a05:620a:29ce:b0:6a7:1379:62d4 with SMTP id s14-20020a05620a29ce00b006a7137962d4mr5775564qkp.604.1659714740118; Fri, 05 Aug 2022 08:52:20 -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 bk4-20020a05620a1a0400b006b89a19a32dsm3074109qkb.69.2022.08.05.08.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 08:52:19 -0700 (PDT) Date: Fri, 5 Aug 2022 11:52:18 -0400 From: Peter Xu To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yang Shi , Nadav Amit , David Hildenbrand , Konstantin Khlebnikov Subject: Re: [PATCH] mm/smaps: Don't access young/dirty bit if pte unpresent Message-ID: References: <20220803220329.46299-1-peterx@redhat.com> <20220804154050.e6ab9f8c38e2445acc5b57b1@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: <20220804154050.e6ab9f8c38e2445acc5b57b1@linux-foundation.org> 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=1659714748; 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=XJd5vUiMu1Gz3OoROmpTft8Oc5UhIyzSv8pitRPvQWw=; b=pcTDIvTO2b3/CShEHoeZeRZARFXLVlUzvm8/zrpE9kUQANzyTvjKtpGKXY8oAw4STYPU0D iGT0t55Uf3ITA+lXt6hPV6hh3SvmXMqNAVri1LDfa6ybbXEl8OpU2FOhVDKMTO9+vKeQ4P 3cU9JZlPPMpmUbbod5YxEclJyYCYQjc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EgWJG4Zt; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659714748; a=rsa-sha256; cv=none; b=qdOcMSxZbjrev1rZny8/ICd+PNq7b+GQzjqRJoL6VwrTibzh0/7+u889byN8QZMxpEpRRM S7oG7/Z3V6W0JPIxAjepBR61cCLBCP2ZxoYgScSMRIxEn7hFGgNKLcOtGrv/I1oDY9n2Ys XhhpwCqkqBUP29AmiABug/fJnsmqU2E= X-Stat-Signature: krw7xtdmraco97wjqqb4rqtc9an8yqbj X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: AA51B180125 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EgWJG4Zt; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1659714747-73680 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 Thu, Aug 04, 2022 at 03:40:50PM -0700, Andrew Morton wrote: > On Wed, 3 Aug 2022 18:03:29 -0400 Peter Xu wrote: > > > These bits should only be valid when the ptes are present. Introducing two > > booleans for it and set it to false when !pte_present(). > > Please (always) describe the user visible runtime effects of the bug > which is being fixed? Will do in the future. For this specific one I'll add some more details: The bug is found during code reading and no real world issue reported, but logically such an error can cause incorrect readings for either smaps or smaps_rollup output on quite a few fields. For example, it could cause over-estimate on values like Shared_Dirty, Private_Dirty, Referenced; or it could also cause under-estimate on values like LazyFree, Shared_Clean, Private_Clean. Meanwhile I think I overlooked the pmd handling which seems to have the same issue but done in another commit.. Will repost soon. Thanks, > > > > --- a/fs/proc/task_mmu.c > > +++ b/fs/proc/task_mmu.c > > @@ -527,10 +527,12 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, > > struct vm_area_struct *vma = walk->vma; > > bool locked = !!(vma->vm_flags & VM_LOCKED); > > struct page *page = NULL; > > - bool migration = false; > > + bool migration = false, young = false, dirty = false; > > > > if (pte_present(*pte)) { > > page = vm_normal_page(vma, addr, *pte); > > + young = pte_young(*pte); > > + dirty = pte_dirty(*pte); > > } else if (is_swap_pte(*pte)) { > > swp_entry_t swpent = pte_to_swp_entry(*pte); > > > > @@ -560,8 +562,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, > > if (!page) > > return; > > > > - smaps_account(mss, page, false, pte_young(*pte), pte_dirty(*pte), > > - locked, migration); > > + smaps_account(mss, page, false, young, dirty, locked, migration); > > } > > > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > > -- > > 2.32.0 > -- Peter Xu