Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp427273pxm; Wed, 23 Feb 2022 03:35:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZEhEP6N7fyv05HOuLlFJ8K00OEx/XQiiMY2cWTVwG+7yBQoOgQfXs7b3H6XhLNubycSSj X-Received: by 2002:a05:6a00:140c:b0:4e1:530c:edc0 with SMTP id l12-20020a056a00140c00b004e1530cedc0mr29392530pfu.18.1645616126389; Wed, 23 Feb 2022 03:35:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645616126; cv=none; d=google.com; s=arc-20160816; b=LYQPsdCLo52aLOhk6PCeRNNtj9OwbFeuxSSiiZOdUFpAJRw1duxYMdhVTvv1tKI4a+ sMyRHjU8ILQ/BC2FcMGjj+Gpc3r6v6VyLrvVzc5CItfZ0KQPaQMGRS660f0Yn88c8Xo8 E/t334q1QDS7gg+jj5m08BSRRDpQUFbnzl9uyf40PEW0GimrvybeF+VcTXVz6iHbB5iE 0UkAWRfdSK/g7uxGkUiRa7ufuxYzJweBndsdyI1Rz2i/UWZt6a13Z5PL5PO0Y97F2g5B EI6Wi0fCXvHxQUhQlS9Y6OeNCibsDWmfqrzdCenJzAhIeh+qKTnjmCrMAjFnnf4Y/ac5 53TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=LI1Qxw8YovJHKPYFPYoCf4datmDsbayp3z46DL8Kp8Q=; b=vD2c8CRW/6Reo62QpDHY8WdXPHlnx/aSeio7c+3/s+UbEDollb1u4+etZQlc+nHSyd ZjPcceZLgZg904rqttEThmLfiFEhSv0SolxngLaLelUmVo+IhL8MAYENbQyqpgwnh6CR 7+HRWSSWTvlno4dSmHbNKnkgQfoyhTcVXjmoyKJO2lltIBZQW8J/BavyOXq5p0zkGLpB NxTk7kFobzMVMkvBxyagzwcnzLcmuTZBYpgKz0c0lO97QYBX/UMmFnQTMLXEHZXRUyFO nPgLqGZIrO23CSNjxJmCWepDf+wGM353VNJaeQyPXpYLty2f/pvoUqi/vnJSaToU1DAc aqWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=U7xDPHt7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11si355947pla.55.2022.02.23.03.35.12; Wed, 23 Feb 2022 03:35:26 -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=@google.com header.s=20210112 header.b=U7xDPHt7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238134AbiBWFYk (ORCPT + 99 others); Wed, 23 Feb 2022 00:24:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237992AbiBWFYY (ORCPT ); Wed, 23 Feb 2022 00:24:24 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF6A69CFE for ; Tue, 22 Feb 2022 21:23:57 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id b12-20020a056902030c00b0061d720e274aso26585917ybs.20 for ; Tue, 22 Feb 2022 21:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LI1Qxw8YovJHKPYFPYoCf4datmDsbayp3z46DL8Kp8Q=; b=U7xDPHt7nJyB2GTAgVc+5mVNa5D9AiEIkeTSJpYyuShkSe5G+Xo37Cmu4z2S0ODbd3 Wm5Eeq8cvy6TNvAv3A7bWuNv++i7NTg2KMLHM/m4eHjfRoQqwVJ2y/Yi5MDF7xrDbsQI j5wRAvkCT4cYk3Bc/Ve5H0pU1FD7r6VuCExamGfvXcE67Mlg9W1l1RFlwTf48DP0g9j8 zrQbvmaWMqoIe6J4oo0xoCcquiVzfC7OAHWIqYk7V7cZwcAdfqwpYM8UaM/ZPk1iYlJM o8gS8/KkwFxTjJeXBM9VLMqxRp+ccKcT56QtTvv+HXupkPEETHBW4Z+e7zRt00MQFKUT ixgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LI1Qxw8YovJHKPYFPYoCf4datmDsbayp3z46DL8Kp8Q=; b=MYd/DEBU0YO7vo0i+L0cMWECEq1OYVjT0ex6drnvqUgfKVVz5OufSMngCnRq+hiIyC kMr2JzcvbPiJdSHwrFb7FTuCKMJKUUHea6fVanekTLhGk4WgZ4pi+hNYgPHloAaNIze5 s8a5mz8MWPgayUuZu56vAzsFkP4lOfqyWMfLEoSNpMhLD65xzAxtTw2rI2ZTCNsGZi5H 8qDx6LPazxnbqqoswHlGA7RnwhaCXTF1kOGE93trVYm++TXrKPT7Qc6KH5BZjQo6+NBF i9wVgKbUp/9O80C26xG3SWaOBZb9zmZ5mma+jAFfiHxTM/JXLHxIJpuBfULZR+/5qeSG ILgQ== X-Gm-Message-State: AOAM532S/NYfm+3MKn4iL4tX6Y09xnfdobV3VA9M6lAi1K4Kz58eGCNn zxel16wvmund7HOfEEcVIObXgSEHWtgutxFDo7AzqvoZkQvf6qWo24qRel39eSsysg4GJr369X9 QtASa+Gyc0gylMAK8apiEHBt9Esd8tDki/ku2eQ1tlMyo4ryseufQOn8LklFzNIPm9Z67PLKN X-Received: from js-desktop.svl.corp.google.com ([2620:15c:2cd:202:ccbe:5d15:e2e6:322]) (user=junaids job=sendgmr) by 2002:a81:5cc3:0:b0:2d0:a2d0:9c0e with SMTP id q186-20020a815cc3000000b002d0a2d09c0emr27666033ywb.270.1645593836836; Tue, 22 Feb 2022 21:23:56 -0800 (PST) Date: Tue, 22 Feb 2022 21:21:41 -0800 In-Reply-To: <20220223052223.1202152-1-junaids@google.com> Message-Id: <20220223052223.1202152-6-junaids@google.com> Mime-Version: 1.0 References: <20220223052223.1202152-1-junaids@google.com> X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [RFC PATCH 05/47] mm: asi: Make __get_current_cr3_fast() ASI-aware From: Junaid Shahid To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com, pjt@google.com, oweisse@google.com, alexandre.chartre@oracle.com, rppt@linux.ibm.com, dave.hansen@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, luto@kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 When ASI is active, __get_current_cr3_fast() adjusts the returned CR3 value accordingly to reflect the actual ASI CR3. Signed-off-by: Junaid Shahid --- arch/x86/include/asm/asi.h | 7 +++++++ arch/x86/mm/tlb.c | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/asi.h b/arch/x86/include/asm/asi.h index 7702332c62e8..95557211dabd 100644 --- a/arch/x86/include/asm/asi.h +++ b/arch/x86/include/asm/asi.h @@ -112,6 +112,11 @@ static inline void asi_intr_exit(void) } } +static inline pgd_t *asi_pgd(struct asi *asi) +{ + return asi->pgd; +} + #else /* CONFIG_ADDRESS_SPACE_ISOLATION */ static inline void asi_intr_enter(void) { } @@ -120,6 +125,8 @@ static inline void asi_intr_exit(void) { } static inline void asi_init_thread_state(struct thread_struct *thread) { } +static inline pgd_t *asi_pgd(struct asi *asi) { return NULL; } + #endif /* CONFIG_ADDRESS_SPACE_ISOLATION */ #endif diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 88d9298720dc..25bee959d1d3 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "mm_internal.h" @@ -1073,12 +1074,27 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end) */ unsigned long __get_current_cr3_fast(void) { - unsigned long cr3 = build_cr3(this_cpu_read(cpu_tlbstate.loaded_mm)->pgd, - this_cpu_read(cpu_tlbstate.loaded_mm_asid)); + unsigned long cr3; + pgd_t *pgd; + u16 asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid); + struct asi *asi = asi_get_current(); + + if (asi) + pgd = asi_pgd(asi); + else + pgd = this_cpu_read(cpu_tlbstate.loaded_mm)->pgd; + + cr3 = build_cr3(pgd, asid); /* For now, be very restrictive about when this can be called. */ VM_WARN_ON(in_nmi() || preemptible()); + /* + * CR3 is unstable if the target ASI is unrestricted + * and a restricted ASI is currently loaded. + */ + VM_WARN_ON_ONCE(asi && asi_is_target_unrestricted()); + VM_BUG_ON(cr3 != __read_cr3()); return cr3; } -- 2.35.1.473.g83b2b277ed-goog