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: 13791935 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 750F6CD4F5B for ; Thu, 5 Sep 2024 08:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=EaeCWvrKm2RHa3wThOp6P+6l9hFn9svFxBtG5OWcJGA=; b=mb1vUXF/h63cZZQwrkcZGQ+FGR eWhWFpAscdknxt8X6B18+oOPWF+fft1ChFKkS1ESxHrNrXHUCS6g+4WVUz/ZTljfEdagk9YpOnA6Q qGqKPNJusz2K5f8//HLMC8C81KpOq8KqL23XqOwOlPIBiJspj01IlgiaMxQlTxuk5m5qsKjUntp3K E8ggDu/kQxhIL/7InBLB9QnHZkwg53ZB1CqX6S9OCzyNJclsanXO7+RTjUcTQg7Hm27dl5MsfQpC6 BybiHIGjW3Q5y4ADviyKNZz3Ccrn/GAnSqs8Feqs6fukj2PpMeMFn/yFya5N4pXytns37KJEsjg5q bTS2d5+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm7dA-00000007VnR-01pM; Thu, 05 Sep 2024 08:14:16 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm7ai-00000007VES-2UfB for linux-arm-kernel@bombadil.infradead.org; Thu, 05 Sep 2024 08:11:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=EaeCWvrKm2RHa3wThOp6P+6l9hFn9svFxBtG5OWcJGA=; b=SXv8LhmOONYULjGoPTKMsIDB61 M00eHW7rIcHGe15pBHMskyf+IEmOOytbTZvKdnSPLqD08s3A72Aa4SunKVNXr/gaQtx7RnljFEbkz 9cHWwrPpQo3yqRNZDBHWVJSWFgXnTNnVeFSz7GLddc0OjWwROWli6FEG5Owxe4U1IY08cCO/iTXlv ckWnexZHH7vwzRXOSDkWO3AIDNswVl3hhYagKfZBwvb0Ad31X8KbqWvrPvlHC1ywPkumWk91hcU90 3YlXnXQ07Mj7uWstCk2K2PpQp44XWDUnJQtsZaLG5rJiga0/1PDuda4jbysyBr99fOMvIAb5parZe 5jsuFPLQ==; Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sm7ac-00000000QND-3iN6 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 08:11:43 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so453038a12.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=lists.infradead.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=lkXGqOO+JMgh12zRlCZ71cRea/kJRaRQSG/LJLtVA4ou4tC/Ne/Tqf2/tQDy1jrb2x TtNSYfDIatbcQg3EkT3/DlQdA+KQ1otNakvbciMDsVDRP4NE7zmon5EDNfCO3Gus6NxR p0eX5dF0VAgUA7JRMDnFltUE5M1NZN7huG8fuRKAeTMvXg8Men6HLtcaDWXobBX1sEwk ikgd5UmZoD0vy4pCkGrfYyWLy0xFUBlA5LzVRTE6pxeZt/JM+206MR8eXecj5xon9IIS EEjR4TsroXvEj7J5WIDgDYmu6y6f6tafVhLT/sfcWpm7D+2kuqlgm9JaK6KAtEzoXbeL m0Ow== 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=gZfpngpwcgw7r4B9H+yRgc5XurZP7FbNWe23TjjU7PdJvcr4A3wFoE4LHR67//+bu+ it+jX90zbO54r8gdzsOsJ/7EmsREdsFokBKIuD0uEobqNVanR/D6V3CY0BV1KpfrTZLS DCe4LjNbCoVgU7ofTaDqmuhS0r4l5H/WvdMX/oM5Hq69p5vWiz0PCM/y1k4q9IVqFSRt 5Hg56vum1v1dl78ZxcCwoxRQQinlrgHN2VensK71Y1BhjTGNaxAJFiFdjflHX4+EO00t aCO1M5ov/OYW7CRs7yb/2gLhObAuTWpZC3UQfUeqWtzpinJ+R4ArM5y01Q+u/dzww5qz eG9Q== X-Forwarded-Encrypted: i=1; AJvYcCXSz4liiWFzasyHblzULhv4LssuQgWHhNXB6sIHb7MoUJ2WHqBfvay+Unh6wX6V5OTH2fT35N2ooKfSkePaSmzt@lists.infradead.org X-Gm-Message-State: AOJu0YwHr73GaaclGLhQc3rSYa3ajUkXg43iFZc4RbmYo5ftfBbqGQma sJ9UoqgbUWe3pusCE2YOhaJFyvjGFJz0kHpimmzEms44Y1rdwYGl 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_091139_296527_81A52D1E X-CRM114-Status: GOOD ( 14.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);