From patchwork Wed Nov 2 09:12:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 14129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3504029wru; Wed, 2 Nov 2022 02:14:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yfghe1JEJCWu3Mj0VWRVg2TcEii7Hd3kax0hjYNU4LcvVwZT4VmWjxrSNpXLVHBgOWtXT X-Received: by 2002:a63:1e0f:0:b0:44b:796c:bc14 with SMTP id e15-20020a631e0f000000b0044b796cbc14mr20362251pge.563.1667380484758; Wed, 02 Nov 2022 02:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667380484; cv=none; d=google.com; s=arc-20160816; b=xhNwskcDgf20z2TAnHdTV53BwfHUCt4WLwD6AkZ5bnHo40j+ZmHpPs9ZlVpjNG+ksG gyfrZEOJVlX4SxvpUg9+kWc7CwtQChof8Z3QgfFdXqWY9AJY6zK/1eZd2crPOfhGWQ0g vUDaXaPdt/BL8z5tlN5RjZR97ASJTK1YOUPBnfglpvGmQrVKHyRgGPEh910KI6jgexp7 VjvxNQucz+gsqQwsYj7oDp41wQSNNyyilnhRlfvmCF1XhU4Gi/LKfTUw3NHOPh4oblEG M6o1qNZibkrg5dt0QuWVV4LPX10dAujohatdAyqL32hDCFc2tLHrehMY7V+TIAIWpSIu Uc3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=b1Xd7WLlUunRZgS6wyq5HgrLiH9Z3FGDx37GUrghheI=; b=jbwRPN75irFOWDKu1+xAiSSukG8u4H1CMTvUDP4wu46fdw08ayyfhlkhmBg5HyK5oh FrzSz3vx+UsZJGCNVPV/uOvWUnPXyZ4yQundjOjI9ZUIcFgpHWF4SvXfa/ZOuYeyjNBZ 7UY87IFQJwWR+hOZtsdsOUTc6o3BdyQ1faGAyMto5Bvci5TrSGLNP4MElyPa8fTMqAcM 2UcfQ4jPWxDGhpJ+RIN3dVzT7gNFKE11z6cbiBvC+VUJA4K+23suzfADHpT7it3xOq1U H0J4ndAu2uUbBEM/gzDa7jgWnCmH8I7q6L/1G8peugzHJMCHokuj686/iqtha/dQ8Nml swIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QJuRG7wq; dkim=neutral (no key) header.i=@linutronix.de header.b="/hkp1NVq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020a17090ac90b00b00213d28acc5esi1526357pjt.73.2022.11.02.02.14.31; Wed, 02 Nov 2022 02:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QJuRG7wq; dkim=neutral (no key) header.i=@linutronix.de header.b="/hkp1NVq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231495AbiKBJOS (ORCPT + 99 others); Wed, 2 Nov 2022 05:14:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbiKBJNF (ORCPT ); Wed, 2 Nov 2022 05:13:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9CCF28E25; Wed, 2 Nov 2022 02:12:44 -0700 (PDT) Date: Wed, 02 Nov 2022 09:12:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667380362; h=from:from:sender:sender:reply-to: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; bh=b1Xd7WLlUunRZgS6wyq5HgrLiH9Z3FGDx37GUrghheI=; b=QJuRG7wqk9i16Gjwx4ITxpScs6a8o1iLXukEtQhGJ1g89co7AkVeZn1uX/lJuXAoJazVjd DykXYirxSH66f10q2hVhIEYZ9NvGCq15xWXzdVoZrFBolC39xdp3JIGZVZxybrhyFej9ta zRDSG+AsPIx5YXTt6N4c9S1e5yZYNL7GRZpb965N2XTk58VdpUGGi3Jce7zD0DBOy3r35n TXM3DpzlPS+sC8r+sbr4nNIB48p1GjOR0mcOBl9XBpMaC9ZmxYjaldXUsFQa93KHhyd8so Vj0+0/42CxsnzvCTaVMtBgUpaEn3xDlAbsnZz0GqT4mIc1ujY55sRyWsxnMgJQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667380362; h=from:from:sender:sender:reply-to: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; bh=b1Xd7WLlUunRZgS6wyq5HgrLiH9Z3FGDx37GUrghheI=; b=/hkp1NVqKhLclAKZDRZUQKVszvMIh9QGbNOntuHWE9mcrrQSwkKI9h5Pe54sW214KM1ywa WPuxpH4b/XPhfXCA== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mm/pae: Be consistent with pXXp_get_and_clear() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <166738035620.7716.3394738648837838435.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748375159354745850?= X-GMAIL-MSGID: =?utf-8?q?1748375159354745850?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: 533627610ae7709572a4fac1393fb61153e2a5b3 Gitweb: https://git.kernel.org/tip/533627610ae7709572a4fac1393fb61153e2a5b3 Author: Peter Zijlstra AuthorDate: Mon, 30 Nov 2020 12:21:25 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 01 Nov 2022 13:44:04 +01:00 x86/mm/pae: Be consistent with pXXp_get_and_clear() Given that ptep_get_and_clear() uses cmpxchg8b, and that should be by far the most common case, there's no point in having an optimized variant for pmd/pud. Introduce the pxx_xchg64() helper to implement the common logic once. Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20221022114425.103392961%40infradead.org --- arch/x86/include/asm/pgtable-3level.h | 67 ++++++-------------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h index d3a2492..93c82c6 100644 --- a/arch/x86/include/asm/pgtable-3level.h +++ b/arch/x86/include/asm/pgtable-3level.h @@ -90,34 +90,33 @@ static inline void pud_clear(pud_t *pudp) */ } + +#define pxx_xchg64(_pxx, _ptr, _val) ({ \ + _pxx##val_t *_p = (_pxx##val_t *)_ptr; \ + _pxx##val_t _o = *_p; \ + do { } while (!try_cmpxchg64(_p, &_o, (_val))); \ + native_make_##_pxx(_o); \ +}) + #ifdef CONFIG_SMP static inline pte_t native_ptep_get_and_clear(pte_t *ptep) { - pte_t old = *ptep; - - do { - } while (!try_cmpxchg64(&ptep->pte, &old.pte, 0ULL)); - - return old; + return pxx_xchg64(pte, ptep, 0ULL); } -#else -#define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp) -#endif -#ifdef CONFIG_SMP static inline pmd_t native_pmdp_get_and_clear(pmd_t *pmdp) { - pmd_t res; - - /* xchg acts as a barrier before setting of the high bits */ - res.pmd_low = xchg(&pmdp->pmd_low, 0); - res.pmd_high = READ_ONCE(pmdp->pmd_high); - WRITE_ONCE(pmdp->pmd_high, 0); + return pxx_xchg64(pmd, pmdp, 0ULL); +} - return res; +static inline pud_t native_pudp_get_and_clear(pud_t *pudp) +{ + return pxx_xchg64(pud, pudp, 0ULL); } #else +#define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp) #define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp) +#define native_pudp_get_and_clear(xp) native_local_pudp_get_and_clear(xp) #endif #ifndef pmdp_establish @@ -141,42 +140,10 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, return old; } - do { - old = *pmdp; - } while (cmpxchg64(&pmdp->pmd, old.pmd, pmd.pmd) != old.pmd); - - return old; + return pxx_xchg64(pmd, pmdp, pmd.pmd); } #endif -#ifdef CONFIG_SMP -union split_pud { - struct { - u32 pud_low; - u32 pud_high; - }; - pud_t pud; -}; - -static inline pud_t native_pudp_get_and_clear(pud_t *pudp) -{ - union split_pud res, *orig = (union split_pud *)pudp; - -#ifdef CONFIG_PAGE_TABLE_ISOLATION - pti_set_user_pgtbl(&pudp->p4d.pgd, __pgd(0)); -#endif - - /* xchg acts as a barrier before setting of the high bits */ - res.pud_low = xchg(&orig->pud_low, 0); - res.pud_high = orig->pud_high; - orig->pud_high = 0; - - return res.pud; -} -#else -#define native_pudp_get_and_clear(xp) native_local_pudp_get_and_clear(xp) -#endif - /* Encode and de-code a swap entry */ #define SWP_TYPE_BITS 5