Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1564288pxb; Tue, 26 Oct 2021 11:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/MCd5PvTv68dE0EK8RQNngO5lYVqJs1nKExB5LtV2eN+lNuRsMw+JEGJ67NvTlznzyaDv X-Received: by 2002:a17:90b:1bd2:: with SMTP id oa18mr369077pjb.164.1635272396905; Tue, 26 Oct 2021 11:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635272396; cv=none; d=google.com; s=arc-20160816; b=z5zXM2gYd5wWTBX1ZjayzEPwzUxzaFflE75/7PKCSTM4etptKodMBNgyXm9I12TiJ+ z1wbH545d/huf+leDNQDr4UvXfgliwePcyIuZ+Ue4lexJqNoSLMF2e84MDv6VGKTTbCj 2Bb3aus0idj2ystnxHYvPvSr7aJ9QGa1X6kdaIyUaCPluw648AK61VWxvGMSRtIKX5h2 1ealf40CzL31M7N+mGHuJqVhyavG4HzRQ20Q7r8xrjVLa0dWdM1139tQkdJx2hYB5yd2 u4Ey4kO1CNoR319rTixfZMs9ek7R3XXS4F8jngZqNslucs1ZVPsgYloaGSNdfioU4qpD 1QAg== 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=0H+JeGyJkw7+XsD6B9OKL2nsE7tddxNDSdsOksbRkDw=; b=Ig8VNFF5YQCnsTdUrZfNSr6QDxMrKxSWjK5esfmWcBp6bLF0Ou1gxoCZYBpGUI2Edu AUXlaLYfW4HKTsryYLiW6SCO0syO643hV3K4WA0Zwm0PMnfD+puUY8vI4Etv7K0izU4r eiCv8YqKz9U1E0KuOi155McFihqkyDQT/58aThEqFFxfwUUF9ADUfVONxGx28tW1M+90 JsBKuFGbgumUO2an3HOPjTbzDkiTCc6FgXXJplYNEhAE98g/BfngTV6Kwy+afNO+dmMy Gjh7wxpnhj14SfL6fisZfzgGWOU7/NpqHxVIcelxgr1OcQspvWFqIEx1d3h/v+rIwib2 /+aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iYbE6NM2; 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 lk17si2221419pjb.132.2021.10.26.11.19.41; Tue, 26 Oct 2021 11:19:56 -0700 (PDT) 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=iYbE6NM2; 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 S236712AbhJZOhy (ORCPT + 99 others); Tue, 26 Oct 2021 10:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235761AbhJZOhx (ORCPT ); Tue, 26 Oct 2021 10:37:53 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ECF5C061745 for ; Tue, 26 Oct 2021 07:35:30 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id t21so10477162plr.6 for ; Tue, 26 Oct 2021 07:35:30 -0700 (PDT) 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=0H+JeGyJkw7+XsD6B9OKL2nsE7tddxNDSdsOksbRkDw=; b=iYbE6NM2VfivMGfnm0SIojXzDcCB9R4Gx8q7YZSnHsKyyyY0LfmUcMJWYYZjdt9rV8 nzpOmbqFbpP5mZlsAY62HTh0TEZ5vA8pBs3Vw2TgkGqU9Vg6x9w1Y2Cl7NsMxej1EnZk Tdso14s1bUbd5xlz+fqP+S9gzW+O36yK2F10TEoYTj16cwycAAbKD1VXgyIoFTRoVjAd WSQn4B2WYNKQf05oenFhwfiPUAfFcpIun2K9oFXmm2DkhEOzJdL2126S9PJsTbQ+dSl+ fGrZHcJy5QqxJvR2luSQqVk3QcJmAyG1Y8TF+llwWcVU+dydjZjpAjFmpgLQKSXrlu4i fafQ== 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=0H+JeGyJkw7+XsD6B9OKL2nsE7tddxNDSdsOksbRkDw=; b=RV4IkUzEocEVJ62b/OnV1mVLORxSrhS2bKdXLVucV6BrfqSduZ3XBqFFwN4a9bZGMj HXzuxxP6mcnAc1DcvCIqw98DrSbKTFEuJhDdwyABIqUekQLr0GDDAPTouzgCfROYdeQe JwinKkYVPEOPDM8Tka6GSS9tVMbcWmsUJdna5KYhwCHgItxtWLcWzkFcd7iXlS0ldfoF wkGxah6XJq8J6QZz8hXSvf3MxWJrS/DeLk5t0LZC5QrITsM+xu3HEDLfnFMmWIQ1aYdL 9mgTFGhbgcK6t9a3yl3ntaT8OKTkc8z/Tt5Pd0vpn+GQnotJ4rDcopI9Wbq0ewlSiIY6 mfxQ== X-Gm-Message-State: AOAM533exN1nNZMHPxi5rWwg3wvMuhoj2XvIS9S1k569TUAA8N0Dkn0z 9h7zyIrrZAynRO1Fl29hUr2KCiH2/zA= X-Received: by 2002:a17:90b:4c88:: with SMTP id my8mr28875183pjb.49.1635258929462; Tue, 26 Oct 2021 07:35:29 -0700 (PDT) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id n9sm2580522pjk.3.2021.10.26.07.35.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Oct 2021 07:35:29 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH V4 31/50] x86/entry: Add the C version ist_switch_to_kernel_cr3() Date: Tue, 26 Oct 2021 22:34:17 +0800 Message-Id: <20211026143436.19071-6-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211026141420.17138-1-jiangshanlai@gmail.com> References: <20211026141420.17138-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 It switches the CR3 to kernel CR3 and returns the original CR3, and the caller should save the return value. It is the C version of SAVE_AND_SWITCH_TO_KERNEL_CR3. Not functional difference intended. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry64.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/entry/entry64.c b/arch/x86/entry/entry64.c index a8e59ae41794..1d6ed444fee0 100644 --- a/arch/x86/entry/entry64.c +++ b/arch/x86/entry/entry64.c @@ -35,8 +35,23 @@ static __always_inline void switch_to_kernel_cr3(void) if (static_cpu_has(X86_FEATURE_PTI)) pti_switch_to_kernel_cr3(__native_read_cr3()); } + +static __always_inline unsigned long ist_switch_to_kernel_cr3(void) +{ + unsigned long cr3 = 0; + + if (static_cpu_has(X86_FEATURE_PTI)) { + cr3 = __native_read_cr3(); + + if (cr3 & PTI_USER_PGTABLE_MASK) + pti_switch_to_kernel_cr3(cr3); + } + + return cr3; +} #else static __always_inline void switch_to_kernel_cr3(void) {} +static __always_inline unsigned long ist_switch_to_kernel_cr3(void) { return 0; } #endif /* -- 2.19.1.6.gb485710b