Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5434855rwb; Wed, 17 Aug 2022 18:07:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4M17e2PWmoYK/pNs7swpre/XlXXqkokvwI0LsHTS3WpXVZxZVzjd/Yh1NMEKmbYPU84bsn X-Received: by 2002:aa7:c78e:0:b0:441:c311:9dcd with SMTP id n14-20020aa7c78e000000b00441c3119dcdmr442910eds.155.1660784857879; Wed, 17 Aug 2022 18:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660784857; cv=none; d=google.com; s=arc-20160816; b=lyU0Fwyz8oHo3QlQCgJ+Kkpkya3JhHCLPBlYWtSHjSPKzM4k7x5HVeldtLZp7Zvob7 CYROi6j7im9Kwn1X+ILyRcW3dYCIO0cf7yie4q0ZoUy6iN63+6mNAO3PBRKysKZwnexI 2sG5CIAPEQXb7d0toPtWwU1SFaohAh4xVVEFHjfc2y1x14M44w+NxKiYRHNvxfAnMCDA SlXBGgdMikCdn8xAB9YRY0LW85svD49tWPo+GI+3r/sgI4euMfwf3RF+yx3UM8G9yOdu 5dEJXU1H/XSnESoln2EZItKcCB8DKZUdZmxxrkZ6jP0PP5xG1YSlIEkxHFrhS5aqy8ZR 7tUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=4nRbabAkARnSIG+u8FeReuRQmGyah2c7zQ8H9oQgg2s=; b=TAW+fdTukM+/mua1LjyIh7IdCC4B32Nffh3asdtKs0iGAZlrdAe+gPFMqNiJa58cSh z6J3RE+oK908Fop9o0KqXGtF9Oxq6FpeJMDb7e4SAYPflbaFqRCSlTE2p8RGztQLKfZ6 nNJEZWzntm0Tkqlrc7aAwjsGW6ayZqOPg7EgbYhXJkEVtoIhV7gYrJjnb8A8sRYrtqzU OpOpveC6aVeVYIvA8ACu12KV7N53sLI47hYkCjuJg9VR6jLtvs/Jx9gfUaNF9Fwtzt0b Cu9HPcpwaE48YNb/nY7JE9dRgQqq4FdojHfzQVvdtimQ9LS23bseZc1R1s4BROwzuymo SCMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a056402348e00b0043da37d0d7dsi230595edc.63.2022.08.17.18.07.09; Wed, 17 Aug 2022 18:07:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242273AbiHRBFy (ORCPT + 99 others); Wed, 17 Aug 2022 21:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239618AbiHRBFv (ORCPT ); Wed, 17 Aug 2022 21:05:51 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E213719B8 for ; Wed, 17 Aug 2022 18:05:49 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VMYSBOp_1660784746; Received: from 30.97.48.48(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VMYSBOp_1660784746) by smtp.aliyun-inc.com; Thu, 18 Aug 2022 09:05:46 +0800 Message-ID: Date: Thu, 18 Aug 2022 09:05:58 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] mm/damon: Validate if the pmd entry is present before accessing To: SeongJae Park Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220817160902.98613-1-sj@kernel.org> From: Baolin Wang In-Reply-To: <20220817160902.98613-1-sj@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/18/2022 12:09 AM, SeongJae Park wrote: > Hi Baolin, > > > Thank you always for your great patch! > > On Wed, 17 Aug 2022 14:21:12 +0800 Baolin Wang wrote: > >> The pmd_huge() is used to validate if the pmd entry is mapped by a huge >> page, also including the case of non-present (migration or hwpoisoned) >> pmd entry on arm64 or x86 architectures. Thus we should validate if it >> is present before making the pmd entry old or getting young state, >> otherwise we can not get the correct corresponding page. > > Maybe I'm missing something, but... I'm unsure if the page is present or not > really matters from the perspective of access checking. In the case, DAMON > could simply report the page has accessed once for the first check after the > page being non-present if it really accessed before, and then report the page > as not accessed, which is true. Yes, that's the patch's goal to make the accesses correct. However if the PMD entry is not present, we can not get the correct page object by pmd_pfn(*pmd), since the non-present pmd entry will contain swap type and swap offset with below format on ARM64, that means the pfn number is saved in bits 8-57 in a migration or poisoned entry, but pmd_pfn() still treat bits 12-47 as the pfn number on ARM64, which may get an incorrect page struct (also maybe is NULL by pfn_to_online_page()) to make the access statistics incorrect. /* * Encode and decode a swap entry: * bits 0-1: present (must be zero) * bits 2: remember PG_anon_exclusive * bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) */ Moreoever I don't think we should still waste time to get the page of the non-present entry, just treat it as not-accessed and skip it, that keeps consistent with non-present pte level entry. Does that make sense for you? Thanks.