From patchwork Mon Nov 30 11:27:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 11940251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C67CC64E7B for ; Mon, 30 Nov 2020 11:38:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 48F4F2073C for ; Mon, 30 Nov 2020 11:38:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="sNy3qGAi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48F4F2073C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3B5738D0008; Mon, 30 Nov 2020 06:38:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 367528D0005; Mon, 30 Nov 2020 06:38:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 280698D0008; Mon, 30 Nov 2020 06:38:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 01DC48D0005 for ; Mon, 30 Nov 2020 06:38:26 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C10B28249980 for ; Mon, 30 Nov 2020 11:38:26 +0000 (UTC) X-FDA: 77540886612.11.kite54_240b735273a1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id A46E2180F8B80 for ; Mon, 30 Nov 2020 11:38:26 +0000 (UTC) X-HE-Tag: kite54_240b735273a1 X-Filterd-Recvd-Size: 3944 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Mon, 30 Nov 2020 11:38:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=xH6cVi24iSh0Z6RI2Sd+J27ye9DAHC3TEE3Mr7hJfxo=; b=sNy3qGAiEjXLyHzpUioeA1iNVj kxI/wm2ONT9/EW9Zy5jZI/BdH6tiIDmN86xxtJv+KEpCwA3EtMI2Pq2kGJ/UClCZMFOPPU+/KQ+Qq 9VmH/LYfiWgUoyzrDHdHK9+Xq9Bllz0/IpZrZn4arQDnBBU+Xxv2GVPTz7vwkpXDR7k7M071B8Ewt 4AmGRWfggI2KBA2GifsgP2Um2Qtrf7x2OmeO6LWeHiCjDonbzYVM4SJURDcziUVKVMjxXvqkLmeir vCzPO2buys+Ka7Bh3R4k5iWhnZrhihoTQK+btdTaHWvEtwLsCp62RKwSMV7tfFaIY69bR81HrgbHl Zuxwguyg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjhVc-0007Qp-6R; Mon, 30 Nov 2020 11:38:20 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 37E6D3077E1; Mon, 30 Nov 2020 12:38:18 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 006072B84F9CB; Mon, 30 Nov 2020 12:38:17 +0100 (CET) Message-ID: <20201130113603.324154533@infradead.org> User-Agent: quilt/0.66 Date: Mon, 30 Nov 2020 12:27:14 +0100 From: Peter Zijlstra To: x86@kernel.org, willy@infradead.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, aarcange@redhat.com, kirill.shutemov@linux.intel.com, jroedel@suse.de, peterz@infradead.org Subject: [RFC][PATCH 9/9] x86/mm/pae: Be consistent with pXXp_get_and_clear() References: <20201130112705.900705277@infradead.org> MIME-Version: 1.0 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: 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. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/pgtable-3level.h | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) --- a/arch/x86/include/asm/pgtable-3level.h +++ b/arch/x86/include/asm/pgtable-3level.h @@ -108,14 +108,13 @@ static inline pte_t native_ptep_get_and_ #ifdef CONFIG_SMP static inline pmd_t native_pmdp_get_and_clear(pmd_t *pmdp) { - pmd_t res; + pmd_t old; - /* 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); + do { + old = *pmdp; + } while (cmpxchg64(&pmdp->pmd, old.pmd, 0ULL) != old.pmd); - return res; + return old; } #else #define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp) @@ -151,28 +150,15 @@ static inline pmd_t pmdp_establish(struc #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; + pud_t old; -#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; + do { + old = *pudp; + } while (cmpxchg64(&pudp->pud, old.pud, 0ULL) != old.pud); - return res.pud; + return old; } #else #define native_pudp_get_and_clear(xp) native_local_pudp_get_and_clear(xp)