From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05DB5A29; Mon, 16 Sep 2024 03:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726456574; cv=none; b=BVY3rieU98yqaDgJHvgA8iGU+wNjafiz6NW1WmZMOPLlWwo9jtb/WWMxeSM71d+Cbu6Naxqk4opTuB/ol2lgO8DQoBg1GlXZu165pX8sy6c5bXCiwxMTVWqN3U10ew67n3gi34IzlyKBIf6oTM1L3ndMZPLxt6G/Q3JJawY9l5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726456574; c=relaxed/simple; bh=6SSCBBeuPSVazQCubyg4niWqsTWvXTxDLK1LRS4x7b0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=D+k4nBny9i8WiSdIqjRZUCQ2uGA3zx+wmdVpxMTMeS5oXGwmMCiYzB/xY59QbhciWoSRrpt9JlxUlDkp5KoIARFrMvjDxZxZGXkTODCBImBbN16WKsHWtnIb2AknYMtMUP9SF0uZHm3U6ZPqk9wMqjbeQ3cDA3PW/E+H4Pu+A9k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B1A6D1476; Sun, 15 Sep 2024 20:16:41 -0700 (PDT) Received: from [10.162.16.84] (a077893.blr.arm.com [10.162.16.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E6B5E3F64C; Sun, 15 Sep 2024 20:16:08 -0700 (PDT) Message-ID: <357931ba-d059-453b-a91d-1bed7fbe5914@arm.com> Date: Mon, 16 Sep 2024 08:46:06 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/7] mm: Use ptep_get() for accessing PTE entries To: Ryan Roberts , linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , "Mike Rapoport (IBM)" , Arnd Bergmann , x86@kernel.org, linux-m68k@lists.linux-m68k.org, linux-fsdevel@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org References: <20240913084433.1016256-1-anshuman.khandual@arm.com> <20240913084433.1016256-4-anshuman.khandual@arm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 9/13/24 15:57, Ryan Roberts wrote: > On 13/09/2024 09:44, Anshuman Khandual wrote: >> Convert PTE accesses via ptep_get() helper that defaults as READ_ONCE() but >> also provides the platform an opportunity to override when required. >> >> Cc: Andrew Morton >> Cc: David Hildenbrand >> Cc: Ryan Roberts >> Cc: "Mike Rapoport (IBM)" >> Cc: linux-mm@kvack.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual >> --- >> include/linux/pgtable.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >> index 2a6a3cccfc36..05e6995c1b93 100644 >> --- a/include/linux/pgtable.h >> +++ b/include/linux/pgtable.h >> @@ -1060,7 +1060,7 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) >> */ >> #define set_pte_safe(ptep, pte) \ >> ({ \ >> - WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ >> + WARN_ON_ONCE(pte_present(ptep_get(ptep)) && !pte_same(ptep_get(ptep), pte)); \ > > Suggest reading once into a temporary so that the pte can't change between the 2 > gets. In practice, it's not likely to be a huge problem for this instance since > its under the PTL so can only be racing with HW update of access and dirty. But > good practice IMHO: > > pte_t __old = ptep_get(ptep); \ > WARN_ON_ONCE(pte_present(__old) && !pte_same(__old, pte)); \ Sure, will change as suggested. > > Thanks, > Ryan > >> set_pte(ptep, pte); \ >> }) >> >