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 62F5DC282DE for ; Tue, 11 Mar 2025 03:15:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C725280002; Mon, 10 Mar 2025 23:15:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35071280001; Mon, 10 Mar 2025 23:15:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CB66280002; Mon, 10 Mar 2025 23:15:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EF690280001 for ; Mon, 10 Mar 2025 23:14:59 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B950C57504 for ; Tue, 11 Mar 2025 03:15:01 +0000 (UTC) X-FDA: 83207803602.13.F9C81A4 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf29.hostedemail.com (Postfix) with ESMTP id 1A583120003 for ; Tue, 11 Mar 2025 03:14:58 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=fYe7jhyd; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741662899; 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:in-reply-to:references:references:dkim-signature; bh=7wDXyh3P+UpPlg6mVwHIWa2aSvvn5//xRxBhxTz/PLk=; b=GinarjeiSyYLWvrxYhk0i8kqrhsraIXrSXo7y9J2QjnBdq+c2QClMiQ9O7qA0ZHDcG4l2Z tHgftafyNCueQ4Lkygeui0C/HDZW/sMIvxlDxPqVNNHu3OCRNpUIf8hjaP4at70nfwHsgM qkpPJnK38lkq4urWMz430SlUwiC008I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741662899; a=rsa-sha256; cv=none; b=dx1IKmsJER9fZyW9/OSMg94i+vPLNq/gb6FlZVEqMCin4FeubFM8klYdkVI3pltBKyVbtW ttUob67MqrllD8hfB1Gw+4KzC4VCkpz8Rt7uK/vciF7LmPJFFm3CNfVOin3QPad3oE++p6 3+4oApV6+0XixTeAkcL37QuZ10ZX5oY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=fYe7jhyd; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-22334203781so106322445ad.0 for ; Mon, 10 Mar 2025 20:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1741662897; x=1742267697; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=7wDXyh3P+UpPlg6mVwHIWa2aSvvn5//xRxBhxTz/PLk=; b=fYe7jhyd6kF3R+2AT5p7HXjWpjw1NOyKmio1kj+DgTyYVWdhbW56sclwuEPaQEc7YI 5Ami64i82c77/F++4llzWZwWpGRKkCC1DzIqDYdDSPWlcAly32EDs81Or6V+JFREeThU 9QVpMx6Z0/sYSHNYi4Xo1CPbdwl3J+zs1V7l/9lJ5SMcXpi3oKAYNrYaKw7xykkEr1Tq mGPPxfoF46WGx2P+Mt+PztpA9QSAPLVOhc7YQlCuHhDgFBzhd+Ic+DYDEQhDpnuYx0a5 J3KZQe357nh+P71uJ84bU8y78lMV4JMu9daZE6VvXYE+X9yI5p5IRER7pjGVdYpDScKb oGAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741662897; x=1742267697; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=7wDXyh3P+UpPlg6mVwHIWa2aSvvn5//xRxBhxTz/PLk=; b=qgxcgwG76fYAHVDlWxRgwM+E6TPxRNdvL0lb6fOAuy7BRXThTGEjC7F+s4QZWeQprz 17C/sXpPo8Hjg6Wmhj7++47YNY397CJ+m2PtWpFlbsDgMXPv3NZxGp9Un+pEP1sGzZ1T PVqIJdN5QcFzYA0wCJ1937L8afxUyy9dO6PXkpvadGEm+lbLSlnkpGd0qxEs7fNJXX4H KLydnj+XlBPHPWyAZ4XFUb2Ey38xcvd1UACU+ob2dP2IqV4AQPXlNh97RYYGhgjk0L7Q wMXXIyC+eJgghnLGBpZxgLWoq0iHZa7teQgGpq+gSrWyaqcb55DduHBg0hM/Tc0xsCtM RZWA== X-Gm-Message-State: AOJu0Yyh/Wpw3pJxiufwn7B8Dom+F5BB30+fcmbJn9fmXUrAzlh+SsSr R0Va8UTukWSGLtXUWkEphXtMzQm9DZfSiUHnX0CWcd4h+DBVflQeqhZPXua4dMc= X-Gm-Gg: ASbGnctpB5juy/BSxaWcdRQ/DguI0WPObNj2Cke/pon5xtlo+/+tVsdgMT2R+w8TOl1 20VOA/0J7hWbGdEM5YC84/p0CfbxQutw1DK0dWKeXQfkLQ09lA2jwC62JN0nchcswKaOUYvrm8M KYwCk+oq0ECNiEXhMACrTu950k236tvYBLN3ClLjz4nyeQisQhkLCE4DXzqAYLeB9PYE2eX3BDm yPyiu6uZG3zM5FIKsthmVfiNtRJWGChVD9MOKqnUzV6r69Oufd0JPalCeta2cqgALqafiEtYF8e g7vtvQRPJB+NGqFiNdXj6I4d19Fovx2vl+Lh+aQ6mAgXDzJpNLkjhxgVD3n9ePGM2bP/OoRFML2 jbpsf X-Google-Smtp-Source: AGHT+IE4Q9xs4CVOgVWo6Vf9pcwvQqCaczrVmCXXwXlvnRH9+b8LB0gV2jtbH11midnws0hi1J+7zg== X-Received: by 2002:a05:6a21:6e92:b0:1f3:2e7a:7320 with SMTP id adf61e73a8af0-1f58d7569ebmr2268420637.19.1741662897537; Mon, 10 Mar 2025 20:14:57 -0700 (PDT) Received: from [10.68.122.90] ([203.208.167.148]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af50aa116dcsm6478484a12.16.2025.03.10.20.14.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Mar 2025 20:14:57 -0700 (PDT) Message-ID: <491f272c-c626-4664-b35f-05ad12d65314@bytedance.com> Date: Tue, 11 Mar 2025 11:14:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] mm: use ptep_get() instead of directly dereferencing pte_t* To: Ryan Roberts , Andrew Morton , Lorenzo Stoakes , Anshuman Khandual Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250310140418.1737409-1-ryan.roberts@arm.com> <661898ee-c1f9-4f51-a73d-b70fe2eccd84@arm.com> From: Qi Zheng In-Reply-To: <661898ee-c1f9-4f51-a73d-b70fe2eccd84@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 1A583120003 X-Rspamd-Server: rspam08 X-Stat-Signature: pg897pfyixg1g4og6nq8xsjtf4ni7y91 X-HE-Tag: 1741662898-623067 X-HE-Meta: U2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QGzYizH6LOW/pcu7HdjmdANEUYvGaPATvXC+hv0TG8IgvzM/gHrnE8IO+3KIDArYQMyst8xqCvfHB6ToKQQFWun5SFGan6T3CxJMpOtNKqpJ2LPBoGb9X8XTY/pNIohR92FU+6ESGQ6ovmiyAbC24i8YGJ+B2XOmhA0qvgv8Dj3ghI5sYHzljikdgIxK9ZEppw8CuXVEdexjWBRpu8G40ffhRU4BxsqqjYnzNnpU7CZPSpBogx0JCgmRccQriXR47POCpzqQLpva9fhaIUU/qJuB/Qd9NSTMKV5bwEbuDgQqjjcjrXt1HPlQiS1nSk/TW+mhe2SWEY34evtetP24sJ3Zf1HPCI11Qpz40sJKG9qlMZRhvC32dwS4g6lqQfLSLtfC4hvNkytpEY2k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.056719, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 3/11/25 12:31 AM, Ryan Roberts wrote: > On 10/03/2025 15:51, Qi Zheng wrote: >> Hi Ryan, >> >> On 3/10/25 10:04 PM, Ryan Roberts wrote: >>> It is best practice for all pte accesses to go via the arch helpers, to >>> ensure non-torn values and to allow the arch to intervene where needed >>> (contpte for arm64 for example). While in this case it was probably safe >>> to directly dereference, let's tidy it up for consistency. >>> >>> Signed-off-by: Ryan Roberts >>> --- >>>   mm/migrate.c | 2 +- >>>   1 file changed, 1 insertion(+), 1 deletion(-) >> >> This looks good to me. So >> >> Reviewed-by: Qi Zheng > > Thanks! > >> >> BTW, there are many other places in the kernel that directly >> dereference pmd_t* and pud_t*, etc. > > It's all a little bit murky. For now, from arm64's perspective at least, there > is only a hard requirement for ptes to be accessed through the arch helper. This > is because arm64's contpte layer may apply a transform when reading the pte. > > In general there are also potential issues with tearing, if you don't at least > read with READ_ONCE(). But often to consumer of the value is tolerant to tearing > (e.g. pmd_none(), etc). Also, in practice on arm64 the compiler will emit > instructions that ensure single-copy-atomicity for direct dereferences, so it > all works out. > > That said, Anshuman (cc'ed) has been looking at supporting FEAT_D128 (128 bit > page table descriptors) on arm64. The compiler does not emit single-copy-atomic > loads for direct dereferences of 128 bit data, so he has been working on > converting the other levels to use the accessors for that reason. > > But that has some potentially problematic interactions with level folding that > need to be solved. Some arches rely on the compiler optimizing away the direct > dereferences when folded. But it can't do that for a READ_ONCE(). > > I believe Anshuman is aiming to post a series to do this at some point in the > future. Got it. Thanks!