From patchwork Wed Aug 3 22:03:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12935936 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 4A801C19F2B for ; Wed, 3 Aug 2022 22:03:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0DDA8E0002; Wed, 3 Aug 2022 18:03:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 994E18E0001; Wed, 3 Aug 2022 18:03:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E72E8E0002; Wed, 3 Aug 2022 18:03:35 -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 683768E0001 for ; Wed, 3 Aug 2022 18:03:35 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 44E4CAB8E6 for ; Wed, 3 Aug 2022 22:03:35 +0000 (UTC) X-FDA: 79759658790.03.A385722 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id E2791100129 for ; Wed, 3 Aug 2022 22:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659564213; 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; bh=8Pg56FzwoyjSg3GyH/BFe7fw+AnDdom5pG01uC6nr8k=; b=A7EAZfma39ubx17u4G5WuBnHqlntIMLAlC4twvXJxyc0V98iIIjycOel1rYfwImBOpCt7c vhX/C2V+oQWpK70VT/KqVy0Ma/9It7miG+k0ooX41+4AIY8W1M372VLfO6oNCNk6EFjcT+ C5SOJDmAtYtEsPlOzezK8EaMeRK/ob0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-292-spcZsgklOVmHj78m0lt72g-1; Wed, 03 Aug 2022 18:03:32 -0400 X-MC-Unique: spcZsgklOVmHj78m0lt72g-1 Received: by mail-qk1-f200.google.com with SMTP id s9-20020a05620a254900b006b54dd4d6deso14399115qko.3 for ; Wed, 03 Aug 2022 15:03:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8Pg56FzwoyjSg3GyH/BFe7fw+AnDdom5pG01uC6nr8k=; b=HqDnTsRxyhSGOCf6k1EsVx98uOUCCXLsR4LmTl1hFaYO8zilc3APXpj00mXjVe6B8R g6I2HtpBwep1Mshe8D/rlau9KcS8ie4RdLuPviEtBOv3ehNLz3bPcfFtUfdrqQcplFpw eem9Pj7vG8S/wPCsUSgjtJZ9lEg/Q2OGTKuUKxTiM1d/LrMr4pMR60xo8pNHb7roo8FX ++kX+3CQNkVectV6+Gx+a6mNEDCMMt3zfNaIVSahxYTtmU6IQQQs7l7WWyw8hXMAJgEQ u+e3xn6AmE4XEMbrXGfc/aY3YhLc07WwXbniVtFFxtZGZT79Bm1xtE4FT7A9lg297Mt2 saJg== X-Gm-Message-State: AJIora9zkjIOgK21Feqk5To9sMfgGjBYhA1B437llUnvcmEIC/iRwAwc LVKHiYEaoGdz9uaJBK+lz0KOnnTMz83igIeD44Q1Upu6PFsq9WnREgBUrhXp9Iw0tll/Bb95nzL uPV5+LknWR7g= X-Received: by 2002:ac8:7fcd:0:b0:31f:393a:7320 with SMTP id b13-20020ac87fcd000000b0031f393a7320mr24100634qtk.11.1659564211827; Wed, 03 Aug 2022 15:03:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFAhcA+0k626uPLuOPLEzIsTH3poxMxYEXMAQWRon6c0dxg1QwQiPtmHA90AdCiQ8qBd4agQ== X-Received: by 2002:ac8:7fcd:0:b0:31f:393a:7320 with SMTP id b13-20020ac87fcd000000b0031f393a7320mr24100611qtk.11.1659564211595; Wed, 03 Aug 2022 15:03:31 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id dm40-20020a05620a1d6800b006a6ab259261sm3598994qkb.29.2022.08.03.15.03.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 03 Aug 2022 15:03:31 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: peterx@redhat.com, Yang Shi , Andrew Morton , Nadav Amit , David Hildenbrand , Konstantin Khlebnikov Subject: [PATCH] mm/smaps: Don't access young/dirty bit if pte unpresent Date: Wed, 3 Aug 2022 18:03:29 -0400 Message-Id: <20220803220329.46299-1-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659564215; a=rsa-sha256; cv=none; b=j5Ws6Aj2F+CeWSV17nMFdElFPHAYDMNpCO38C9NzJhy3blMfadUDQuE5q0C6z+godRzt2m VZIxiR4N0u9x7bhbrdL3DDW3IU6jVcoFVrk2tum0rgoJGo/WGm7TOCGNTB311xgtK85h2Z lR/BcMRobcd9hQR/780G4/c2AshGQdc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A7EAZfma; spf=pass (imf14.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659564215; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=8Pg56FzwoyjSg3GyH/BFe7fw+AnDdom5pG01uC6nr8k=; b=3wJRw3ROxt6lY4hXn0lDcohMYDh3Ij6VEfJEBIFNnpzrtXHrWkj+8RVzpwJ1snTpI/cfHd 6k0pIuJkWYwsrR6LBEQZnlJxvjqL6mV9UBc5qlQx2MLTrtZADgMmrNM2+FTOAs6wnIZOFw 0k5Oa8GDJGXMIjiOhUFMGgExswqBfm0= X-Rspamd-Server: rspam04 X-Stat-Signature: nunpfbr7myu5dp39sqncw6cxzdskqbri Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A7EAZfma; spf=pass (imf14.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-Rspamd-Queue-Id: E2791100129 X-Rspam-User: X-HE-Tag: 1659564213-144390 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: These bits should only be valid when the ptes are present. Introducing two booleans for it and set it to false when !pte_present(). Cc: Konstantin Khlebnikov Fixes: b1d4d9e0cbd0 ("proc/smaps: carefully handle migration entries", 2012-05-31) Signed-off-by: Peter Xu Acked-by: Vlastimil Babka Reviewed-by: David Hildenbrand Reviewed-by: Yang Shi --- fs/proc/task_mmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 9913f3be9fd2..482f91577f8c 100644 --- 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