From patchwork Sat Dec 17 18:55:32 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: 34252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1636669wrn; Sat, 17 Dec 2022 10:59:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qwkejDqIzgzlVf7I1fKmcT2IN+i5b925ZyxoC8bb3Rqsf6FkoDncn2aZBzgRTNWEfvn2m X-Received: by 2002:a05:6402:2408:b0:461:f0a7:156 with SMTP id t8-20020a056402240800b00461f0a70156mr33286227eda.36.1671303599547; Sat, 17 Dec 2022 10:59:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671303599; cv=none; d=google.com; s=arc-20160816; b=fmP/pa2/qpKT3nDJ2PsumaVR4eNU1rNE3PSUDjAIESGIqcwP/5V6FH1jWiuHqONyxY K9gWtiiVq6A83UbnVnZrc/qBxzpHkWWXmfsuMmISd5Eqmvzb+mz5uzSQn0WVgc6+wpS6 slwYcJmPwST3YtZvHkbWRGjX8iq+AEW9RT3bhRjjgpnvvyCqpBI7BAwOCJthRAH58rgE H3TAQfxbxYisAGLtaYJOH0RoIrpwZnKR73E7uhgHKx9ujFmEMAhSMscRcEOPlJAq4PSc sIJqxmLbkXM3MhQxjO0Ixis915bmFOaaSb7q+K/UQinzdokMRdxssSVWqHhDVL1bom/R o9HA== 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=7eNvTjTLqRAbPy5cQPJ6gsPDxp6OvPC1Mc2GQawkk1o=; b=z++Z1pzcUTGEvZjE3+hiaso3AER6Kzxg0CmBAZGTD5utkZtShjkmVPy0GJw0S/5A8l P7x+zIQ9Z8u1ERVQtOD3vdnsEOa33fnMS1OZs+u68nK6yM7zL+mggbFk0IXp7MQ//dms vIeGVuCb83B+RU9FyMNrBH32WlMiir9U4M+u6oWyaoPiXou3CgC9m5f8l9/qUgZyMv80 7FUSkjvOZJWYuHWQmk0R5rGwwvwWpRNHt/GiGp7UrAdR0tmKB5h7PSWpXlUvqcc9qkin 6yp7IucQqOsKVk7D9r34V7E/qGSS6oBIVwkDh8JhxOfcSF8soGCcdMUGpPAa8YzICe4o a4yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3EHZPT0W; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=k2TlqL5z; 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 e18-20020a056402191200b0047039339346si6823547edz.550.2022.12.17.10.59.36; Sat, 17 Dec 2022 10:59:59 -0800 (PST) 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=3EHZPT0W; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=k2TlqL5z; 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 S230397AbiLQS45 (ORCPT + 99 others); Sat, 17 Dec 2022 13:56:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbiLQSzj (ORCPT ); Sat, 17 Dec 2022 13:55:39 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 332A02D4; Sat, 17 Dec 2022 10:55:37 -0800 (PST) Date: Sat, 17 Dec 2022 18:55:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1671303332; 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=7eNvTjTLqRAbPy5cQPJ6gsPDxp6OvPC1Mc2GQawkk1o=; b=3EHZPT0WHwNNcF9vvs3sGTN/UYK3tye7pIYR1moiYp48e0wrzwecvqwLhHIV8wxO2/cX8t m5Aq2Mf+54JczjJGLu9mqMKdM9r2xO0g4pPxI1PUa2+3XAI64/1DqHHggAbAypdmBAIN83 cKr4OhbeWI5Rp9wag2koziZ39hDnmSCi3OXjMGPslWXZh1MqjXaF/xgU5liADfQ5o4sUJw ejh9X7kAVi4oAlS7FTeIZ3u+ABUPFT+rYQJqFSsaSIfaHn9qA3WrZL+x6BWIhYEGrJt4gr iV2TBGzcs1zoVr3wgUqtXjnQQQOxRnuSpUEk7WX7a86diyLF+9NdV8xdpZR/tg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1671303332; 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=7eNvTjTLqRAbPy5cQPJ6gsPDxp6OvPC1Mc2GQawkk1o=; b=k2TlqL5ztb7mCGbagKp0HRTUFJy+l3ImOe8pJCOLFXuJGKPIFy1lfeHcUdFu+Do5T/5Ay8 zGk0RWtUMmQ6SrCw== 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: <167130333238.4906.2107855285027662487.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?1752488843106998969?= X-GMAIL-MSGID: =?utf-8?q?1752488843106998969?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: b7301f20105a27112f7ca8040cfb0b0505a32fbd Gitweb: https://git.kernel.org/tip/b7301f20105a27112f7ca8040cfb0b0505a32fbd Author: Peter Zijlstra AuthorDate: Mon, 30 Nov 2020 12:21:25 +01:00 Committer: Dave Hansen CommitterDate: Thu, 15 Dec 2022 10:37:27 -08: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