Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3718972ybz; Mon, 20 Apr 2020 08:13:52 -0700 (PDT) X-Google-Smtp-Source: APiQypLeL+8V84z4P7NnmakFQNw+tPkl7CzZ1o3cOccd9Q+2LY3aOB640FS1qxQRwZfqIYoy6rhI X-Received: by 2002:aa7:d683:: with SMTP id d3mr13911506edr.268.1587395631975; Mon, 20 Apr 2020 08:13:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1587395631; cv=pass; d=google.com; s=arc-20160816; b=nTDveYwdlJ9/OYbt9N/009wta1pQRwCIhufOvYyzgqiLmIu2/8nkrlNh4CkmkXpi+2 Y6gTFMJbuOcDFC58LigFukf3RbQ2pKdRdQS+Jg+oBljb0c8DCXuXZndw0+6B0y1f6H93 YEuP6XBFf8LrcQMxepX+maN1uHnhecqNB0Q9yTXR/DUzZBUzPkfla1XK47hI9c2b/6/T VY5TQgoAAdPmtQ+XR0CPulDOL8BZTAoVmUic8N9PehIuPJxMV44tT+g3cJcHUslJziD1 P8jItveu6gDnSAkwAS7CYPjrFFrgeYhQmLPc5bB6hTksEOHYRgjJvEPeKE/FyAYyAIOC ZNdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=pr7WkK6uotISoQS1Cwh5eywXlMdgCCRm7a9/cWHUxbw=; b=V3hOt0QBv3NCpLT+SxDx4zTBhfAHbMYVegIwudOHhnDmXlPjDLNlpQfsrntyDbRa+k 13iFkt6ZpfuYJ+vFAFOMGP+X+r25vLZxRBMY3EuMe/SLtF7V1Wlq68zlTYAL8fbdvO+g E4HDMzeIuUPQpYgVb1KFXrbVNY9F1x8LejjJQXmPtDDH3s7EZsWouXCyVhG/8MS5ZrtJ bzAVL8bsvXCoHjeSSekUY853WODWyrRSi9OtKneY+rbtY4d4s2IJnn5ZtHu7d7MhMAG3 yeRvXdC55TUwn3gH+NC0uw5vbDBFtC877YFWCEsZ3if0Yw6dYou12DiCJI/oXuxalyMt QT4g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b="CyQb/m+s"; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z5si853226edp.102.2020.04.20.08.13.27; Mon, 20 Apr 2020 08:13:51 -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=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b="CyQb/m+s"; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729838AbgDTO1C (ORCPT + 99 others); Mon, 20 Apr 2020 10:27:02 -0400 Received: from mail-co1nam11on2071.outbound.protection.outlook.com ([40.107.220.71]:6881 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725958AbgDTO1B (ORCPT ); Mon, 20 Apr 2020 10:27:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jo4wEagL474xnBz+cw1fcqf6KE1V8FJ1/jVoESse4EyWfumDK5pkI/anP6pZ+f0rC5EXtDTsc2rkF2ZepSRs/agWziafXOLE6EYSv5S0gzSlIqCGaglt+a0p0Dmg/MB5DGTNPme8KKcpRkVvgeooa0gsCV9viMHJi0SHpQEGayY6amGfjP/9VUkvupD2mMxmrHZocPfbaTg/j6YJNjMkBUsPnDt15W9b6LLk3Yj8JreWcBfI39kCw/gpwCntIuFnNzq8Vdp7KbW4dG5n4jsL/KyoP5YyLUIKREbNtG/7Rt6Z5eu5erQ6qtaV2oVEh5XNhbkqtbePFIFQdytVYeE7bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pr7WkK6uotISoQS1Cwh5eywXlMdgCCRm7a9/cWHUxbw=; b=bSLzk/kWNw0QVs7rB04CenbNLnYYzltkbkQMHDIuC94y6UGQiXHcSPJ35ITofhaKC3M+ROrCg5ozAxei86Vhem3R66I4d6mSVhKrtkOdMUvgNyVGM4UyqYottHROtToeeF2h/z/AJ9sm+F33qCdOeB08kR6P8jTFSyMc3e0DMPWIMqsDc6v+CZrxELvv9aMYYagqElLwPfs7YFBXgmcrQzikkuV3rlO4MGsOFJ+ABSnlUdGbRx8L00EQohKqCu3Y+ppUo4HR8IrbMXsx382ES1Dg37Q53KKUkYPprDQfsFLUUi7bcV/Q0wK98OJh77+k4wn6mumSCpTvsrSztgY3fA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pr7WkK6uotISoQS1Cwh5eywXlMdgCCRm7a9/cWHUxbw=; b=CyQb/m+slmHTKiCc/VwXBy7Yx7EW9CwNrr4HibMzAUaid86WEi09332zL0jdWEGWkxb2+vvYesZ1/+yTKRfjmFbRLHeCV89Opdkznpg1Yzf5uph+tZAfeSDKriHtU3KfMQr0lConoQiEEh1b1NUvOrcaKCIxAgaoniWya2rC/e4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB2731.namprd12.prod.outlook.com (2603:10b6:5:45::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.29; Mon, 20 Apr 2020 14:26:57 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Mon, 20 Apr 2020 14:26:57 +0000 Subject: Re: [patch 05/15] x86/tlb: Move __flush_tlb() out of line To: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= , Thomas Gleixner , LKML Cc: x86@kernel.org, Kees Cook , Paolo Bonzini , Boris Ostrovsky References: <20200419203137.214111265@linutronix.de> <20200419203336.134117165@linutronix.de> <5857df01-abeb-c6cd-8e92-64eb365dc835@amd.com> From: Tom Lendacky Message-ID: <852c1af7-bc1c-a86c-d390-7547563bdde4@amd.com> Date: Mon, 20 Apr 2020 09:26:55 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from office-linux.texastahm.com (67.79.209.213) by SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.6 via Frontend Transport; Mon, 20 Apr 2020 14:26:57 +0000 X-Originating-IP: [67.79.209.213] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 14b4b2e0-7479-4202-9132-08d7e536e1e1 X-MS-TrafficTypeDiagnostic: DM6PR12MB2731: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 03793408BA X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3163.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(136003)(376002)(366004)(396003)(346002)(39860400002)(66946007)(66556008)(81156014)(2906002)(66476007)(8676002)(26005)(52116002)(36756003)(5660300002)(316002)(54906003)(110136005)(86362001)(31686004)(956004)(478600001)(186003)(4326008)(16526019)(6512007)(6506007)(53546011)(8936002)(31696002)(6486002)(66574012)(2616005);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RIKQZ1eXMH+Kdqcl2oyIJQ5YAKriqEdSrhZZSgFW1NYMmfwH63WDMxy7mehB16lJCMyai66td6aB29+wsmYpZ4x2l2+AMd79kf/z3VwAjTSYLdozKB7BBe31g9gpk8Tb/DIfEGfqbWE9QSgBahlRwjRzP1mv1ajzVTExydHfIBoND9EJ/g2aKQMf42A9SlusC22pxhxEkthuXH3wgFs8KBlrCebyrfrqm+4s332qQGgsjw6jvdzCny7t7ShaNANWRwQL2nIchC7SwqeJknYho8eipjbBt6hh6buryzJLZoF2956O4AiThS9RnZmK80g7b7a9c0ackHV5+W4OzFMKXFHfyDp4ABE8RXh8q1bIDh8vlGCgT+wMn/bzsxEBfo7u4H950N/sfddGaH9ZaLKbjQookmGhBvyzcorn0IakPD9OsB/6RZibdatrSKeT0ae1 X-MS-Exchange-AntiSpam-MessageData: AVb9Ys16jQ+SllNk3tA2yKlUN15UXS7qzYNPC/NTPdEN4HN5Jybz0dc3+icAJK6HBtjw4/3XC/7Tw6V5CQqTC60JsV6CzhkOY710cOTzQNDIjfQkXFH0Iw7vhc6sWAAudac6Bqnnc0jbS1infWmfGg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14b4b2e0-7479-4202-9132-08d7e536e1e1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2020 14:26:57.8374 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hJmU6xsGkqxvfeb1n7ap/nB7Vd8kFD1lqG8ByCVfnHKxdeVeC2y8llakw26w+Hi/XNVeArZRvbpCaVbGLkWe2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2731 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/20/20 9:03 AM, Jürgen Groß wrote: > On 20.04.20 15:48, Tom Lendacky wrote: >> On 4/19/20 3:31 PM, Thomas Gleixner wrote: >>> cpu_tlbstate is exported because various TLB related functions need access >>> to it, but cpu_tlbstate is sensitive information which should only be >>> accessed by well contained kernel functions and not be directly exposed to >>> modules. >>> >>> The various TLB flush functions need access to cpu_tlbstate. As a first >>> step move __flush_tlb() out of line and hide the native function. The >>> latter can be static when CONFIG_PARAVIRT is disabled. >>> >>> Consolidate the name space while at it and remove the pointless extra >>> wrapper in the paravirt code. >>> >>> No functional change. >>> >>> Signed-off-by: Thomas Gleixner >>> Cc: Thomas Lendacky >>> Cc: Juergen Gross >>> --- >>>   arch/x86/include/asm/paravirt.h    |    4 +++- >>>   arch/x86/include/asm/tlbflush.h    |   29 +++++------------------------ >>>   arch/x86/kernel/cpu/mtrr/generic.c |    4 ++-- >>>   arch/x86/kernel/paravirt.c         |    7 +------ >>>   arch/x86/mm/mem_encrypt.c          |    2 +- >>>   arch/x86/mm/tlb.c                  |   33 >>> ++++++++++++++++++++++++++++++++- >>>   arch/x86/platform/uv/tlb_uv.c      |    2 +- >>>   7 files changed, 45 insertions(+), 36 deletions(-) >>> >>> --- a/arch/x86/include/asm/paravirt.h >>> +++ b/arch/x86/include/asm/paravirt.h >>> @@ -47,7 +47,9 @@ static inline void slow_down_io(void) >>>   #endif >>>   } >>> -static inline void __flush_tlb(void) >>> +void native_flush_tlb_local(void); >>> + >>> +static inline void __flush_tlb_local(void) >>>   { >>>       PVOP_VCALL0(mmu.flush_tlb_user); >>>   } >>> --- a/arch/x86/include/asm/tlbflush.h >>> +++ b/arch/x86/include/asm/tlbflush.h >>> @@ -140,12 +140,13 @@ static inline unsigned long build_cr3_no >>>       return __sme_pa(pgd) | kern_pcid(asid) | CR3_NOFLUSH; >>>   } >>> +void flush_tlb_local(void); >>> + >>>   #ifdef CONFIG_PARAVIRT >>>   #include >>>   #else >>> -#define __flush_tlb() __native_flush_tlb() >>> -#define __flush_tlb_global() __native_flush_tlb_global() >>> -#define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr) >>> +#define __flush_tlb_global()        __native_flush_tlb_global() >>> +#define __flush_tlb_one_user(addr)    __native_flush_tlb_one_user(addr) >>>   #endif >>>   struct tlb_context { >>> @@ -371,24 +372,6 @@ static inline void invalidate_user_asid( >>>   } >>>   /* >>> - * flush the entire current user mapping >>> - */ >>> -static inline void __native_flush_tlb(void) >>> -{ >>> -    /* >>> -     * Preemption or interrupts must be disabled to protect the access >>> -     * to the per CPU variable and to prevent being preempted between >>> -     * read_cr3() and write_cr3(). >>> -     */ >>> -    WARN_ON_ONCE(preemptible()); >>> - >>> -    invalidate_user_asid(this_cpu_read(cpu_tlbstate.loaded_mm_asid)); >>> - >>> -    /* If current->mm == NULL then the read_cr3() "borrows" an mm */ >>> -    native_write_cr3(__native_read_cr3()); >>> -} >>> - >>> -/* >>>    * flush everything >>>    */ >>>   static inline void __native_flush_tlb_global(void) >>> @@ -461,7 +444,7 @@ static inline void __flush_tlb_all(void) >>>           /* >>>            * !PGE -> !PCID (setup_pcid()), thus every flush is total. >>>            */ >>> -        __flush_tlb(); >>> +        flush_tlb_local(); >>>       } >>>   } >>> @@ -537,8 +520,6 @@ struct flush_tlb_info { >>>       bool            freed_tables; >>>   }; >>> -#define local_flush_tlb() __flush_tlb() >>> - >>>   #define flush_tlb_mm(mm)                        \ >>>           flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL, true) >>> --- a/arch/x86/kernel/cpu/mtrr/generic.c >>> +++ b/arch/x86/kernel/cpu/mtrr/generic.c >>> @@ -761,7 +761,7 @@ static void prepare_set(void) __acquires >>>       /* Flush all TLBs via a mov %cr3, %reg; mov %reg, %cr3 */ >>>       count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL); >>> -    __flush_tlb(); >>> +    flush_tlb_local(); >>>       /* Save MTRR state */ >>>       rdmsr(MSR_MTRRdefType, deftype_lo, deftype_hi); >>> @@ -778,7 +778,7 @@ static void post_set(void) __releases(se >>>   { >>>       /* Flush TLBs (no need to flush caches - they are disabled) */ >>>       count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL); >>> -    __flush_tlb(); >>> +    flush_tlb_local(); >>>       /* Intel (P6) standard MTRRs */ >>>       mtrr_wrmsr(MSR_MTRRdefType, deftype_lo, deftype_hi); >>> --- a/arch/x86/kernel/paravirt.c >>> +++ b/arch/x86/kernel/paravirt.c >>> @@ -160,11 +160,6 @@ unsigned paravirt_patch_insns(void *insn >>>       return insn_len; >>>   } >>> -static void native_flush_tlb(void) >>> -{ >>> -    __native_flush_tlb(); >>> -} >>> - >>>   /* >>>    * Global pages have to be flushed a bit differently. Not a real >>>    * performance problem because this does not happen often. >>> @@ -359,7 +354,7 @@ struct paravirt_patch_template pv_ops = >>>   #endif /* CONFIG_PARAVIRT_XXL */ >>>       /* Mmu ops. */ >>> -    .mmu.flush_tlb_user    = native_flush_tlb, >>> +    .mmu.flush_tlb_user    = native_flush_tlb_local, >>>       .mmu.flush_tlb_kernel    = native_flush_tlb_global, >>>       .mmu.flush_tlb_one_user    = native_flush_tlb_one_user, >>>       .mmu.flush_tlb_others    = native_flush_tlb_others, >>> --- a/arch/x86/mm/mem_encrypt.c >>> +++ b/arch/x86/mm/mem_encrypt.c >>> @@ -134,7 +134,7 @@ static void __init __sme_early_map_unmap >>>           size = (size <= PMD_SIZE) ? 0 : size - PMD_SIZE; >>>       } while (size); >>> -    __native_flush_tlb(); >>> +    flush_tlb_local(); >> >> This invoked __native_flush_tlb() because of how early it is called and >> the paravirt ops support isn't set up yet, resulting in a crash if not >> invoking the native version directly. So this needs a "native" version >> of the tlb flush to invoke. > > I don't think this is still true. With my rework of pvops to have all > functions in one struct which is initialized statically initially > everything should work from the time the kernel is mapped. > > In case it doesn't there is something very wrong IMO. The memory encryption support was implemented in 4.14, so it's quite possible that this isn't an issue now. I'll test out the patch and verify it. What release did your pvops rework land in? Thanks, Tom > > > Juergen