Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp428566pxh; Wed, 10 Nov 2021 04:07:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQq9ohWuJk6D7B/dRYYRHDvxe4cBEPHd/jbaevVsu0ZfRcaz6OyDZIiF1EDtTnF6xej/3X X-Received: by 2002:aa7:d601:: with SMTP id c1mr21117380edr.17.1636546020696; Wed, 10 Nov 2021 04:07:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636546020; cv=none; d=google.com; s=arc-20160816; b=GWshwIo7yTsHByrN9kOzHABR6LWg5xIVIFPglYGgtSo1WorHok7Lhia8wRJiFgDo+E 5213U3oYzfIc/J8yHiDxm1gjKZZeSWZCg1gDNhwDoMu1dVuCBc8RuqS3JI3r7BDAL3B9 6UFCrIc1adi4rd+RBhOV4AMFdUKMDyJwuPllsNyUtEWBiqkiD7N2IIjSbaMhJZ4wwWT1 VTD4v64Khel3lKfYFzmOlNZFACkb24V2Z0Qr45OoqKVyWoeRXMNMJ/B7l2eMZ4geXF0j yTbnr4eWfuBWqWbA113CDxkR9xCuePBAY67dZX8mQIjyTMxaN5Tcou4nEI0YqoeF6dfr CnOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/VEIBCWf8eZkwgfgrE3MrvMN5GhRK8VB75123ohWZZA=; b=L3PB55oEXlAGqPKDNvmq7iKRV+EUL/KMTOG8MvY4Lz7OxBBLKH8CgGEgH9uXowklpi cBFqQZ2mEe412mVsem34fOX2GQIUFJp4qNyTpViMbVuTSVaWDxzXavz7+VxzLyUCICTY DIVma60AQacQzyGesGIAVlhaYN4U3JRS58LiVrLos9sYHAWLci9tuf2sLDwyKhVx/tY0 LZIGjNeFfqjk3dyxXFLyDrKfyG+pAeBa0nlDMYoBhXXI2JrnOoxTyGEsEGnRXbLIUC5U yFqwti5Xnst2COc7fp6EOx/JJBaBVDukG2/FL14kEtXzxv0mSQ9k2zFem3IY2tG77SUA TIIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="D/9xAO2P"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sa10si51080015ejc.689.2021.11.10.04.06.28; Wed, 10 Nov 2021 04:07:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="D/9xAO2P"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbhKJMDp (ORCPT + 99 others); Wed, 10 Nov 2021 07:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231571AbhKJMDg (ORCPT ); Wed, 10 Nov 2021 07:03:36 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F391C061767 for ; Wed, 10 Nov 2021 04:00:49 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id m26so2469872pff.3 for ; Wed, 10 Nov 2021 04:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/VEIBCWf8eZkwgfgrE3MrvMN5GhRK8VB75123ohWZZA=; b=D/9xAO2P9sR448Bu17ScY52ajZkr0h8NEsif2AGDKmhTcPArnYyt1J1RuwZdskjSKv l6U6lsrrVHf71SJFZmtqI76ywDlDvZTxRJNFKkIPhUyLYLK4HDIiyeys8DTdi7+ou1eY I/iJlDfvxYIGN1Uwi6UsSUK0sB/ZV1XEQBdkXT7YqzqcLAuUSOyoubA0t9ILBSgoLAuI rsNPPfbfTQKUjfRGOqV2GISthWy1U87f4Cs7arnjlWNm4nNXr7izMXtGiT808LYGbagg PW0m1SgQl/9cRlE+LJQfBZpBEC3Ql7doSvwYnPHXU71KkcH8L6QC390s4nh7d3qJQGT7 Ik+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/VEIBCWf8eZkwgfgrE3MrvMN5GhRK8VB75123ohWZZA=; b=BjjES2yRtLyNhZZ0fbKOxxAWnIRxEHe/R36jtjsZ34+Jcj2/qaAo8a7UcIjwLb8jPQ UQk2wlhbttp6pd4p9atxAd0JBhLgUO9k8Aq+pArveptHu/V1Zr/yLYOcQefCWg5L7KPh hU/1cRPDau2o3i2p1bsUdnPQWwnHE9HyeuP5hYkrLkCL9YPwMsDNKjq5XCBgfvIL7PaV LWhagRI8d9R9wu5GlA0tjVPv+oLpDAZuQWgzjglCxmU2maCmszi52pYzr3zr44vY/HKQ C2qOgdyZJ5VYca+qRlG0+1qsZwj97XnbNJZJ/KPlyyRYyEuYn3skMArr96NsGR6bvoMB Gx5A== X-Gm-Message-State: AOAM530SW0G/q3bf2foxj+hknorF5Hn1DcZAQ1F0aZRVGLghtXF6mIWD NP3H4jSCRPMARw3UvsiiJlVeqSPbnFs= X-Received: by 2002:a63:7d04:: with SMTP id y4mr11386992pgc.131.1636545648411; Wed, 10 Nov 2021 04:00:48 -0800 (PST) Received: from localhost ([198.11.178.15]) by smtp.gmail.com with ESMTPSA id pg13sm5953411pjb.8.2021.11.10.04.00.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Nov 2021 04:00:47 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Lai Jiangshan , Peter Zijlstra , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH V5 32/50] x86/entry: Skip CR3 write when the saved CR3 is kernel CR3 in RESTORE_CR3 Date: Wed, 10 Nov 2021 19:57:18 +0800 Message-Id: <20211110115736.3776-33-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211110115736.3776-1-jiangshanlai@gmail.com> References: <20211110115736.3776-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lai Jiangshan When the original CR3 is kernel CR3, paranoid_entry() hasn't changed the CR3, so the CR3 doesn't need to restored when paranoid_exit() in the this case. Cc: Peter Zijlstra Signed-off-by: Lai Jiangshan --- arch/x86/entry/calling.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h index 996b041e92d2..9065c31d2875 100644 --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -231,14 +231,11 @@ For 32-bit we have the following conventions - kernel is built with .macro RESTORE_CR3 scratch_reg:req save_reg:req ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI - ALTERNATIVE "jmp .Lwrcr3_\@", "", X86_FEATURE_PCID - - /* - * KERNEL pages can always resume with NOFLUSH as we do - * explicit flushes. - */ + /* No need to restore when the saved CR3 is kernel CR3. */ bt $PTI_USER_PGTABLE_BIT, \save_reg - jnc .Lnoflush_\@ + jnc .Lend_\@ + + ALTERNATIVE "jmp .Lwrcr3_\@", "", X86_FEATURE_PCID /* * Check if there's a pending flush for the user ASID we're @@ -256,10 +253,6 @@ For 32-bit we have the following conventions - kernel is built with SET_NOFLUSH_BIT \save_reg .Lwrcr3_\@: - /* - * The CR3 write could be avoided when not changing its value, - * but would require a CR3 read *and* a scratch register. - */ movq \save_reg, %cr3 .Lend_\@: .endm -- 2.19.1.6.gb485710b