From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E5EFC433F5 for ; Sun, 24 Apr 2022 07:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238458AbiDXHFV (ORCPT ); Sun, 24 Apr 2022 03:05:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233814AbiDXHFP (ORCPT ); Sun, 24 Apr 2022 03:05:15 -0400 Received: from out0-152.mail.aliyun.com (out0-152.mail.aliyun.com [140.205.0.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAE87167D3 for ; Sun, 24 Apr 2022 00:02:15 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047211;MF=darcy.sh@antgroup.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---.NWmk5tx_1650783733; Received: from localhost(mailfrom:darcy.sh@antgroup.com fp:SMTPD_---.NWmk5tx_1650783733) by smtp.aliyun-inc.com(127.0.0.1); Sun, 24 Apr 2022 15:02:13 +0800 From: "SU Hang" To: , , , , "SU Hang" Subject: [PATCH 2/2] x86: replace `int 0x20` with `syscall` Date: Sun, 24 Apr 2022 15:02:07 +0800 Message-Id: <20220424070207.123597-2-darcy.sh@antgroup.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20220424070207.123597-1-darcy.sh@antgroup.com> References: <20220424070207.123597-1-darcy.sh@antgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: SU Hang --- lib/x86/usermode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c index 477cb9f..e4cb899 100644 --- a/lib/x86/usermode.c +++ b/lib/x86/usermode.c @@ -12,7 +12,6 @@ #include #define USERMODE_STACK_SIZE 0x2000 -#define RET_TO_KERNEL_IRQ 0x20 static jmp_buf jmpbuf; @@ -40,9 +39,11 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, static unsigned char user_stack[USERMODE_STACK_SIZE]; *raised_vector = 0; - set_idt_entry(RET_TO_KERNEL_IRQ, &ret_to_kernel, 3); handle_exception(fault_vector, restore_exec_to_jmpbuf_exception_handler); + wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE); + wrmsr(MSR_STAR, ((u64)(USER_CS32 << 16) | KERNEL_CS) << 32); + wrmsr(MSR_LSTAR, (u64)&ret_to_kernel); if (setjmp(jmpbuf) != 0) { *raised_vector = 1; @@ -73,7 +74,7 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, "mov %[arg4], %%rcx\n\t" "call *%[func]\n\t" /* Return to kernel via system call */ - "int %[kernel_entry_vector]\n\t" + "syscall\n\t" /* Kernel Mode */ "ret_to_kernel:\n\t" "mov %[rsp0], %%rsp\n\t" @@ -89,8 +90,7 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, [user_ds]"i"(USER_DS), [user_cs]"i"(USER_CS), [user_stack_top]"r"(user_stack + - sizeof(user_stack)), - [kernel_entry_vector]"i"(RET_TO_KERNEL_IRQ) + sizeof(user_stack)) : "rsi", "rdi", "rbx", "rcx", "rdx", "r8", "r9", "r10", "r11"); -- 2.32.0.3.g01195cf9f