From patchwork Tue Sep 17 07:31:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13805943 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 C022CC35FEB for ; Tue, 17 Sep 2024 07:31:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 554906B0092; Tue, 17 Sep 2024 03:31:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 504306B0093; Tue, 17 Sep 2024 03:31:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CC406B0095; Tue, 17 Sep 2024 03:31:48 -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 20D646B0092 for ; Tue, 17 Sep 2024 03:31:48 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CA3B41201D1 for ; Tue, 17 Sep 2024 07:31:47 +0000 (UTC) X-FDA: 82573410654.23.632ACBE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 2FF064000D for ; Tue, 17 Sep 2024 07:31:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf11.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726558183; 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:in-reply-to:references:references; bh=WBPoMFgWT2ZiqZhDgBB8E2TVvrfOMNhXDz2ju2nc0jk=; b=LsVjf2TuKeeqX01bIPA+ufjcnPiLwKpMnDttfOpYsV8GdoNMiiWnvMkbTu/N6tpWv3HLxk 18yN5FW/v9HEMfCrd5cHF5mS4nIK119DawodYphvlpVHm7B0LyP8jEsSQX14VmRSM2B6Rg lS/hNuuryyNJOSFv36yfPIHUFP12LsM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726558183; a=rsa-sha256; cv=none; b=egk1mgjBR0CYGxIiqfRmasOJHBmmU3ls8kNnNdAutdOuz8jNS24fHNhOLFEtetzy23Rjoz OKevYJbx/PqZ5ErFIVX/2PN6KSfROn+RGet9M1kmp/iNGKJovuZqjP3nVYCdw3NM6Odz4q iH1fZa1r4/AH4kr7WHpS8/pgGseGZhg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf11.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@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 0434D106F; Tue, 17 Sep 2024 00:32:15 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.61.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 11DEC3F64C; Tue, 17 Sep 2024 00:31:40 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Andrew Morton , David Hildenbrand , Ryan Roberts , "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 Subject: [PATCH V2 3/7] mm: Use ptep_get() for accessing PTE entries Date: Tue, 17 Sep 2024 13:01:13 +0530 Message-Id: <20240917073117.1531207-4-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240917073117.1531207-1-anshuman.khandual@arm.com> References: <20240917073117.1531207-1-anshuman.khandual@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2FF064000D X-Stat-Signature: ha6j7bqw96u8mfrm91s3mybh56udj1m5 X-Rspam-User: X-HE-Tag: 1726558305-417326 X-HE-Meta: U2FsdGVkX19H+fAbvDJCNDZNZl+iipoGo9lk8o/miGXY7COXu9zmSNayy3OvYQmhPYDjKKbPqqptY33mkzq87JrjoOVvPAvS8yJcg39zuvDHMwYcNUa7sHamFQs7g41cxg5DQQzMgtg+hQu/IKViRwembWhuYwfT63TGQHDY9dGBroCL82uNSylKZCC6EbsroG56mNdlxZRdIvPVM98C+dzEf4+FZxe2x4HvDGMRYY8BNJfhkptOAHYr0jdIoREwSe8Kqn6qH/FzTOU+YrK4QY1stYkonmHJsPfmyo5QAyVwxgIs8vMEtMIr+2Bs8l97IS50lZEw5rXCo33w6eTS9hTe1IyxocZUvd8Ui93T+rb9GNRJ4SRISR5WnRPsmYBvo+NhMdbfjkoP4RiKwoEJPTuFUORwm+aysPjRQuypM04JerjNUfW4RVQqMgDXIBdrEj88emojGxG9oHj+i8HIZpuVCUyru5FZVMsefi6btpEBStBXj4FEoEBZeBqV/4iIkqbQDxUcUrvD63n2NEILYrKJu19Kd8kkFV651jsJfQkbtfk0PLeVhlsBNFeGLLl5uLG5bJ5ajfAmdmde1zGz3U6K3E453bAsyfZBkTiWxTCKEe14g778xkmYM0ThFDbKK6zYQ2/SPiSJiRNfyIcs3ZQZ56wu/fdjqvxCv2hB3lw0Q30pumpVkjvIzfXoJsAnRAt1cQlx04uRswy9sQp0y3ddbN0VtQ/Yxbt3fYkhgFlMT8wnPxE1RtNW28dFiHkyhMWJyrxtHTSN4O/uWQ66LGKTvPr2+Xec3Uhvc2TOsyisLGjoDpp4XRBPtISt+LqCZH/B7qr2hSZbfyyQLyPJ8qbE0NDgljqHN86MqmKYaYTW/uNGa4XHAXQO8I+94wmDiLkeRbrybcwZkumNepmETyu7QVfeTc6Q2OzkT0MUqdyUxoHDCLdQJu0ncdfjRGBnn7W32rsNELMCH5OoSil gOq/pAyk 2M5w/nwGI5VJh6w/kHPNWz5qcgFWO2WyUH2Fy4XqvFRPhD0O+i9TWB4Mi8woWDuCQ0AQfAQrCX6n9WADrfFtQLe2inKCU/gjPPWC7ZearEGOIPJwrAbGa8vzbqOteXgHeYxBeSNdg3pnhOLOXxzVVkhoFP4VIc2eURXXETIkX3KmwQSAnKc63VeLa0ifabR7GtOM3YpkLxTc0+p+bJU5irEZP9XzH38mghFxPTEgcd47sFYrMiwDQsTA6gqhaiQYpmmN3uO9/kIbizv0VS0L2GiWaMUKtQCC47mnULA7xosUXfcKYd95chHlv5I1pvwFPO+lbcMRCsTYoNUqXb0BaLdFjH51EUjXDl9vLxD5ndITUICky+KSaHIgZ9g== 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: Convert PTE accesses via ptep_get() helper that defaults as READ_ONCE() but also provides the platform an opportunity to override when required. This stores read page table entry value in a local variable which can be used in multiple instances there after. This helps in avoiding multiple memory load operations as well possible race conditions. 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 Reviewed-by: Ryan Roberts --- include/linux/pgtable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 2a6a3cccfc36..547eeae8c43f 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1060,7 +1060,8 @@ 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)); \ + pte_t __old = ptep_get(ptep); \ + WARN_ON_ONCE(pte_present(__old) && !pte_same(__old, pte)); \ set_pte(ptep, pte); \ })