From patchwork Thu Sep 5 08:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13791934 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 7DC26CD4F5B for ; Thu, 5 Sep 2024 08:11:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1076B8D0007; Thu, 5 Sep 2024 04:11:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BA138D0001; Thu, 5 Sep 2024 04:11:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B17278D0007; Thu, 5 Sep 2024 04:11:38 -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 8CD168D0001 for ; Thu, 5 Sep 2024 04:11:38 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4A754C09F9 for ; Thu, 5 Sep 2024 08:11:38 +0000 (UTC) X-FDA: 82529965476.11.A63478F Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf22.hostedemail.com (Postfix) with ESMTP id 82FECC0003 for ; Thu, 5 Sep 2024 08:11:36 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=f0E8Uohk; spf=pass (imf22.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725523799; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=EaeCWvrKm2RHa3wThOp6P+6l9hFn9svFxBtG5OWcJGA=; b=QB8BEHEO8LwZ7WuEH6VK0KHLBux6KMCeJRXqhcHdA1p/PtWjxnYz7tA71s4zpmOUnuVwUN AvB7p/CI3v+DLg5dUbojK7W+c3j/pIDI+mc+nhs1Mf2OeXaG/zycrj0GCkmyTJthveQ6Ss mHdsOyoJ4iFAlI9keLFjwVmJBkHi6D4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725523799; a=rsa-sha256; cv=none; b=qTiPGn9AEc/hiDbGagaA9c/TAca8J85QmZROYk13ehNuQ2SmqL0JpVoP+0gSRZdA57fSqU 09kDDSQM14PI9z6xvsl06KuWhgczyWRyr34YprdvjG0UjvxTWLkhIw6rDrjIn0xoyW9kcv KR+wWjvyvoiWeXU6xsSAu/tW9awXrHM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=f0E8Uohk; spf=pass (imf22.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so453037a12.2 for ; Thu, 05 Sep 2024 01:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725523895; x=1726128695; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EaeCWvrKm2RHa3wThOp6P+6l9hFn9svFxBtG5OWcJGA=; b=f0E8UohkV17qblPwVROC1NUtMwohiSqo5LZwdnnOs5haNmSWElq+DoWYDleMAdQwuW UDFKAtB/vGnzoZnDzRB1nijv3+4DKvAYftUjqfZSZje27/HVOTAtXFkElD+sgRRdSLdy CkcP1cMP2vj21IrbsFeBhdjqmaEEGoQeEyC1X3eb0CuL2GnEYhetAdbc81Jp25LvfYh3 YTemP3qYt7t1Njx6UkxtY7mJnfJsFrEDLrUPTidIqO2ZLfAv92xHenTqn4kb/efppSNy A+3T+/qsiDWvQ+ZD4KybQ7mCxv39WWkWrxYW3sqMYrJC4ILhY4U8Xn3L79BurtDvEJl2 I67g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725523895; x=1726128695; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EaeCWvrKm2RHa3wThOp6P+6l9hFn9svFxBtG5OWcJGA=; b=lucTByWF0i2bbaR6czjS17ILIZ04bdsXpDjdYEbFL4ONqez19u+8h8Hh9ta6TEqekv EhcvT+UftfKL0iXk8HCa9ZVzPsoaOe+hAoPvxk1iqYiDNkBHAdCVJtDZxPPwMaOGyVCo UAVBB1K6L3Wgie84ekSYMhGTZharMycZq1ceIyOlvbu1NyzSDeK+vRMa5+UL7sYW4HoO 7do059yh0/pjgQzNKuhRw5N/mry0++moZox/sTQMtU9mQ0FhjJZx/Ko4svLq1rVIg2Tn h45O/UPdDhRaUWvpTe4F83AxptH6BynzoV8L9eYRt8bl4zij4p6KZO9KZh2zkaNywkWV YCoQ== X-Forwarded-Encrypted: i=1; AJvYcCV+Hb+uoqwt19MJoJNXjE+mF/2AY3i6M2wvuU8xTbcy2+jyoSfhZo5cB2/JpaLnhmrgdHBzhLvChg==@kvack.org X-Gm-Message-State: AOJu0YzvnzG3REmZs6T6pxkkfkcwziT7D3qkrnY4UAYvkQbgsr6FQFt2 J4lvi6bWOHJrH0ELmlEFjUePw5Uieoj4jRfLnOxDLWHCLcD5hAjX X-Google-Smtp-Source: AGHT+IF5X6mxpqooGWsBRolyzeQs8RG5P0iaaZL1WAaxgLNmdadKGF0NIBj1lBF97jl0Zmb/9YS0SQ== X-Received: by 2002:a05:6a21:3987:b0:1ce:e080:185c with SMTP id adf61e73a8af0-1cee0801caemr15613625637.41.1725523895054; Thu, 05 Sep 2024 01:11:35 -0700 (PDT) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:fdcc:5b39:8249:b563]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2da5cb5870esm5470825a91.22.2024.09.05.01.11.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 05 Sep 2024 01:11:34 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Cc: david@redhat.com, ardb@kernel.org, catalin.marinas@arm.com, jhubbard@nvidia.com, mark.rutland@arm.com, v-songbaohua@oppo.com, will@kernel.org, Ryan Roberts Subject: [PATCH v2] mm: arm64: document why pte is not advanced in contpte_ptep_set_access_flags() Date: Thu, 5 Sep 2024 20:11:24 +1200 Message-Id: <20240905081124.9576-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Stat-Signature: qgxkdses7waexjbtzooa6hutxqbp7bds X-Rspamd-Queue-Id: 82FECC0003 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725523896-994148 X-HE-Meta: U2FsdGVkX1+qmxwDScYGQW7oT9Yq9HTvlMOdW0qpxzbxmgCuqmdOYV6Jeakk3F88qT0JMiDoIvLrRApUot72ZtO8ZHNY7OEOo8MG6YtSEuV1+q61uv1Mqeie4Yh/eCqqidU3wOUlMMZIojwyml6jlYsJPGYLIK9zIHJcmAaF2zvVQMKWHSZaN3tuZK3iXPhbaM4fVgGRsh0JPzZJ/jIhMVFXQDOn7i1J27RTiPt1pMLMoOEZy1KDzqLMXFm9XWJ0HMcOUaccaCv2cA2Tlv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PN3orCv2wtQKz9NvGjF11fKQALU3+Wif8AzYJLG9SQTCjrqQ6rTQzhvLiqQDPhrEkb9Axfr9KrAWJ3Mk7X+vCHIVa4ku3Mn2+IB/wMu3hiyhZdJER6i+NmHbkgou7BJxUmCbmgJ18ERjsVkY44RzfQxXf2I72RquiaV2xWBDj9R2w/5Lre4WNOuLmuz+rTUsLRGRSTTp0X15hO/h5GBKKkkSQN7zj4DqbgMig+LE8U= 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: List-Subscribe: List-Unsubscribe: From: Barry Song According to David and Ryan, there isn't a bug here, even though we don't advance the PTE entry, because __ptep_set_access_flags() only uses the access flags from the entry. However, we always check pte_same(pte, entry) using the first entry in __ptep_set_access_flags(). This means that the checks from 1 to nr - 1 are not comparing the same PTE indexes (thus, they always return false), which can be a bit confusing. To clarify the code, let's add some comments. Reviewed-by: Ryan Roberts Signed-off-by: Barry Song Cc: Ard Biesheuvel Cc: John Hubbard Cc: Mark Rutland Cc: Catalin Marinas Cc: David Hildenbrand Cc: Will Deacon Reviewed-by: David Hildenbrand --- -v2: * collect Ryan's rb, thanks! * doc why but not advance entry * refine changelog and subject -v1: https://lore.kernel.org/linux-mm/20240831083537.62111-1-21cnbao@gmail.com/ arch/arm64/mm/contpte.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c index a3edced29ac1..55107d27d3f8 100644 --- a/arch/arm64/mm/contpte.c +++ b/arch/arm64/mm/contpte.c @@ -421,6 +421,12 @@ int contpte_ptep_set_access_flags(struct vm_area_struct *vma, ptep = contpte_align_down(ptep); start_addr = addr = ALIGN_DOWN(addr, CONT_PTE_SIZE); + /* + * We are not advancing entry because __ptep_set_access_flags() + * only consumes access flags from entry. And since we have checked + * for the whole contpte block and returned early, pte_same() + * within __ptep_set_access_flags() is likely false. + */ for (i = 0; i < CONT_PTES; i++, ptep++, addr += PAGE_SIZE) __ptep_set_access_flags(vma, addr, ptep, entry, 0);