Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp524903iof; Mon, 6 Jun 2022 07:56:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT9ETVF3EArEbU5gKVWJUHJpQeU7wUL8uip7lAZWhWZEFRKd5gLvb5xmy1ZYUmVlflkAXX X-Received: by 2002:a17:903:2485:b0:161:da96:1701 with SMTP id p5-20020a170903248500b00161da961701mr24878345plw.58.1654527365813; Mon, 06 Jun 2022 07:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654527365; cv=none; d=google.com; s=arc-20160816; b=TJ5MCJnJVy/GaoJhfhuwSu+QW8wP/MOfkfmbkd2FiiEIxFuf5V1FRRySbfrNA9CaRB R3d7WiCp8oWnuWsxeOFfXBFDaBkhzo+hf6p0SeuIrmVRpDghAyGhuUBR/P4fWFKZBILX NUnh9qzAZTJrgx/qnYxiTXp3rjIv1AZJ88t0EDdrQDQbHwIUIAmI+8uzV0z9LIF8ZFhO sWsiG4QVFQSsf+kkxvkUQY+NOXCEH2Sl9MGsNMWUNsO62eSED9SaaZz9geNNG52CI6VL rPxV5CPk2L7XfKDrNRfwHqER8rIOeOPUcDF+oXmkkNd/czqUIjWYUqeW2QlBWoJVIeiC 1Q7A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jBAA4iYHay9IQkyL5K+TapNcySE+x8r/WS3Y7D8As50=; b=b3TqmkI6KSJC68PQimDNNscWOF8v84A4DaNDEJh9G/P1mYPNuqZhllVAmFUF6A4st/ zzaxsNHhC+SKfcJZBcLtdjxvtdjRcx39TzwfoJs4FJZ3TmJXWKtrLLQrBixFvKlQvtXN BZI+B9vmp/TK3vgUFrug+UsEBOP8BTx9DXFEWSchaX4/o7KbJgJZ31YkciTMpRpZzWNl AeyaY4g4V3+IJRY/hiejgqakky0LIdGPwLHzU7Yy1ZDVjGJcnlWHi+f3qNO/1YLsbcQi ElyKEY7qIjatTzbZfL9VYy6O1PO3OGvLWB9mKwHaMP3IZvw50BoaZ0SAzH6mJpbaSgJu zZBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DbOxjk9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o2-20020a656a42000000b003f5cfa3bbfdsi27184920pgu.233.2022.06.06.07.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 07:56:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DbOxjk9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 25CCB5006D; Mon, 6 Jun 2022 07:44:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239898AbiFFOoZ (ORCPT + 99 others); Mon, 6 Jun 2022 10:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239823AbiFFOoX (ORCPT ); Mon, 6 Jun 2022 10:44:23 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CB3E4F468 for ; Mon, 6 Jun 2022 07:44:22 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id e11so12873034pfj.5 for ; Mon, 06 Jun 2022 07:44:22 -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:mime-version :content-transfer-encoding; bh=jBAA4iYHay9IQkyL5K+TapNcySE+x8r/WS3Y7D8As50=; b=DbOxjk9ucf3qjonFJffz3Ct1P+0PiLR750bdqny3X2ftXXx9Vgh3gpP0dIUpm4Sw6s JKrvykWkcvT6WCWSN6dMMmyT94+egxtTmmNeKpks8O8CA25IVGc/eNBphAvl3YXVWK9D Osd3e6TlgUJw0rTGdBZ2xgfouqA/Tj1BAjCCQaW/OEKQPac2/WPN43cMNEH+6qi1ninw qq4mBW52s0o6NrJgauJqytAI5Jk3W72OqTzreZHW61PP6Pk3ZthMPDltldQfvjt2WDKU pwpsZp7gwZX3OldIAVL2IrYUU0n0THC4mUhfiNo+zu2gviOGfO9+/PJvFJLmioKd8ESK pnCQ== 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:mime-version :content-transfer-encoding; bh=jBAA4iYHay9IQkyL5K+TapNcySE+x8r/WS3Y7D8As50=; b=yqhZXEGfQOFdyMfaXVOrMLyUOvU21xC28BW6HXrRQNHgPE26Y9slPbhZS7tj5q8Btt aaXXU75hrdKI01KknMqXwQPyf++PRhgu2pgG98c78BQtPGQa6qTVamco8/U1+SOatjfm 8R3ZHzuZadm+uM+CgN9PyK4D8mj2vM9bdj/98ogM3ZzutzPCnWkXSwm/D/SO4Bbby7UD qFlhMi0vzDonF54fkL+GkTAdERjqTQMLmHRaAJsUJspd09Zhs+GIe6suf0Ihu2KlFmFC bI2g5zF99h8k5KMfI3W8YWpGoi6C4pa8LQEI6jSna8pYdBZXllbIikeRrpiooyAihtZn eIUw== X-Gm-Message-State: AOAM533DLVcbrVzbwugArPh943Fz21WVapnjioGG11FKdLgFe5AM9g7G 4cc5nbypnpgBwGMJZ+n0hdmv/ujkYiM= X-Received: by 2002:a63:24a:0:b0:3fc:52a9:b5d6 with SMTP id 71-20020a63024a000000b003fc52a9b5d6mr21072765pgc.132.1654526661252; Mon, 06 Jun 2022 07:44:21 -0700 (PDT) Received: from localhost ([198.11.178.15]) by smtp.gmail.com with ESMTPSA id 21-20020a170902c21500b00163bfaf0b17sm8664139pll.233.2022.06.06.07.44.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2022 07:44:20 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , Thomas Gleixner , x86@kernel.org, Lai Jiangshan Subject: [PATCH V3 0/7] x86/entry: Convert error_entry() to C code Date: Mon, 6 Jun 2022 22:45:02 +0800 Message-Id: <20220606144509.617611-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Lai Jiangshan Add some C equivalent functions of the ASM macros and implement the whole error_entry() as C code. The patches are picked and re-made from the huge patchset https://lore.kernel.org/lkml/20211126101209.8613-1-jiangshanlai@gmail.com/ which converts a large chunk of ASM code to C code. The C version generally has better readability and easier to be updated/improved. This smaller patchset converts error_entry() only. The equivalent ASM macros are not removed because they are still used by the IST exceptions. No functional change intended and comments are also copied. The complier generates very similar code for the C code and the original ASM code except minor differences. The complier uses tail-call-optimization for calling sync_regs(). It uses "JMP sync_regs" while the ASM code uses "CALL+RET". The compiler generates "AND $0xe7,%ah" (3 bytes) for the code "cr3 = user_cr3 & ~PTI_USER_PGTABLE_AND_PCID_MASK" while the ASM code in SWITCH_TO_KERNEL_CR3() results "AND $0xffffffffffffe7ff,%rax" (6 bytes). The compiler generates lengthier code for "cr3 |= X86_CR3_PCID_NOFLUSH" because it uses "MOVABS+OR" (13 bytes) rather than a single "BTS" (5 bytes). ALTERNATIVE and static_cpu_has() are also different which depends on what alternative instructions for ALTERNATIVE are. [V2]: https://lore.kernel.org/lkml/20220516131739.521817-1-jiangshanlai@gmail.com/ [V1]: https://lore.kernel.org/lkml/20220511072747.3960-1-jiangshanlai@gmail.com/ Changed from V2: Fix conflict in arch/x86/include/asm/proto.h in patch7 Changed from V1: remove unneeded cleanup in patch2 Changed from the old huge patchset: squash some patches Lai Jiangshan (7): x86/entry: Introduce __entry_text for entry code written in C x86/entry: Move PTI_USER_* to arch/x86/include/asm/processor-flags.h x86: Mark __native_read_cr3() & native_write_cr3() as __always_inline x86/entry: Add arch/x86/entry/entry64.c for C entry code x86/entry: Add the C verion of SWITCH_TO_KERNEL_CR3 as switch_to_kernel_cr3() x86/traps: Add fence_swapgs_{user,kernel}_entry() and user_entry_swapgs_and_fence() x86/entry: Implement the whole error_entry() as C code arch/x86/entry/Makefile | 3 +- arch/x86/entry/calling.h | 10 -- arch/x86/entry/entry64.c | 137 +++++++++++++++++++++++++ arch/x86/entry/entry_64.S | 85 +-------------- arch/x86/include/asm/idtentry.h | 3 + arch/x86/include/asm/processor-flags.h | 15 +++ arch/x86/include/asm/proto.h | 1 + arch/x86/include/asm/special_insns.h | 4 +- arch/x86/include/asm/traps.h | 1 + arch/x86/kernel/traps.c | 2 - include/linux/compiler_types.h | 8 +- 11 files changed, 169 insertions(+), 100 deletions(-) create mode 100644 arch/x86/entry/entry64.c -- 2.19.1.6.gb485710b