Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1564416pxb; Tue, 26 Oct 2021 11:20:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwhniyuoCJhiNhG2krNIFd3Cf+3vsJbTP/38ic8pJh0o6Y+0iIXIUBRCVLKOXrF+eHMmzL X-Received: by 2002:a17:90a:17ce:: with SMTP id q72mr307325pja.229.1635272405816; Tue, 26 Oct 2021 11:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635272405; cv=none; d=google.com; s=arc-20160816; b=Upr1iuoiphFtkfqZsLpMq1R8ohpE6WTVlG+xQirJCgJ8zNIhO+cTiR4nnsbub84gL6 gCsEwZn0Qgg4TBRtO5MY6FH1iPsCjHhcvLWCZ3fYWzhtrGhnhTSRD1mHPjTjbEeBOA3n v28kYR+chi+nWMYZyLiU3BdSuTpqj8xuUT+fAS9KWX+Rwzgrt2JFk+PBWrDh2zdFDo+n XMC2vP0yVakbshyoGnFT7eZ+mGTI5b+IqT2g8lqDorAsGwqWIkk8tNr/cVlpUc+Utmic Js8T2ylCPsz7z2Kt9ZSuX2ae52FwpLJmjEEeh/3keW9aM8hUArdntxBQ5TlKiRCPg5kU P7Bg== 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=4VbMG521+R+KwfRRt8bui7JnW4XiRBCByXrdv/ZKoz8=; b=kN6wDfixa9A5s6OIIcEGwmhII1SVaG+bfwuOWGrfmwntYgXO93YQ/yaJngZ3CPNEsH u8R+EGcNJUOkcm7G+tDpFYlSlMQvV2jGJ+0x7dPpCgbj3WAEmv6J1BpI3CBt4GTePJMP AXFk9Up1XcduskzA8ySCEyn4uqz94GAiEtbsZLpKaeRiv1/0EQeGlIY4XSTXBwmPYDtZ nSdDiUadjbmB7wrqnSWK3NOYGfv7OF7gCWRC1BtE0INlY1h2zZ6umMHg4YvAgBnOQE7Z 9EzFgeRujAHS29oo6Awmh/eXseCf9n/JqFuMU1JoEQXpQyoDkr+Qfsjrz9YxV1ttekS2 +zyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jGFfHYo6; 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 z24si33207082pgv.103.2021.10.26.11.19.53; Tue, 26 Oct 2021 11:20:05 -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=jGFfHYo6; 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 S236640AbhJZObe (ORCPT + 99 others); Tue, 26 Oct 2021 10:31:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236598AbhJZOb1 (ORCPT ); Tue, 26 Oct 2021 10:31:27 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39111C061220 for ; Tue, 26 Oct 2021 07:29:04 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id v1-20020a17090a088100b001a21156830bso2436229pjc.1 for ; Tue, 26 Oct 2021 07:29:04 -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=4VbMG521+R+KwfRRt8bui7JnW4XiRBCByXrdv/ZKoz8=; b=jGFfHYo6PD0erpFbqnYfzRqk8IXk89l3RJQ4gyn9w5tQqBSp6QxpWaABi0FnhUCUab sVxWXtg/UI+hnDxwCEpg5qqhs6vYJX5igsJ5EkCthjso3ZAbnlciog1i9gDffMmV7BX/ NjERVIqiFVWL1nWSyI4bXeP9Xpta5OKXibPxJe+PtjpKejZhEqUo8iOB3KIZ4iqunWB8 lnR3DK/Ss9Uw54jEgXv0IalRd5NS660QykHjYvwYfcUmckBfrC35ClcGGX8Ty2GUPBOZ BRUb1401JXnGG/yyMellcsRroScXPv4A+IAyXemhSiTSQUz/ROCENFm0gO1znYEVu+0+ bc5g== 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=4VbMG521+R+KwfRRt8bui7JnW4XiRBCByXrdv/ZKoz8=; b=l4YhGN5NFcZJRuS2Y8Gby0iBUegkbs39WifbYmVZjLngVP2emqqNkPixqYze4Nl1oc 2eQF11tficDBYKeSS7f/MMATl0aTR1bv2IjyYRUCpXUXKI19h/0lhUgwEYj0IDBJU0zB m6kUcZFdYeddYbJ0lT6RZclLbGr0+ytrCnyuzvL2+HShDRY5w7iPQVehNl+y7H1SY6jU fU7ULCYFvQ/ZjAbeH4olySPtvps7z+mMj7JJcwgkFVD49M74PHFSUBEwR7uA4GNjQTdW WA71sZo3pvagEbMqdbK0TP5SVm7pxv4jrvGedtKczbMZTUDAXcfr0HHr8kKI0AnW+Lub aDyg== X-Gm-Message-State: AOAM531GNZ8AnEVDil2aB4vVyGhtJM1vKRiq4+EyxPbvn86t/eI6+tcf U+wMgWN10BdWRvuKr0bw9IomyJp2FlE= X-Received: by 2002:a17:90b:4b85:: with SMTP id lr5mr29137102pjb.66.1635258543605; Tue, 26 Oct 2021 07:29:03 -0700 (PDT) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id nn14sm1113808pjb.27.2021.10.26.07.29.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Oct 2021 07:29:03 -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" , Peter Zijlstra , Joerg Roedel , Sean Christopherson Subject: [PATCH V4 18/50] x86/traps: Move pt_regs only in fixup_bad_iret() Date: Tue, 26 Oct 2021 22:27:50 +0800 Message-Id: <20211026142824.18362-8-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 Make fixup_bad_iret() works like sync_regs() which doesn't move the return address of error_entry(). It is prepared later patch which implements the body of error_entry() in C code. The fixup_bad_iret() can't handle return address when it is called from C code. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 5 ++++- arch/x86/include/asm/traps.h | 2 +- arch/x86/kernel/traps.c | 17 ++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index daaeeb8acd22..7f2338c3b676 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1047,9 +1047,12 @@ SYM_CODE_START_LOCAL(error_entry) * Pretend that the exception came from user mode: set up pt_regs * as if we faulted immediately after IRET. */ - mov %rsp, %rdi + popq %r12 /* save return addr in %12 */ + movq %rsp, %rdi /* arg0 = pt_regs pointer */ call fixup_bad_iret mov %rax, %rsp + ENCODE_FRAME_POINTER + pushq %r12 jmp .Lerror_entry_from_usermode_after_swapgs SYM_CODE_END(error_entry) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index 6221be7cafc3..1cdd7e8bcba7 100644 --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h @@ -13,7 +13,7 @@ #ifdef CONFIG_X86_64 asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs); asmlinkage __visible notrace -struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s); +struct pt_regs *fixup_bad_iret(struct pt_regs *bad_regs); void __init trap_init(void); asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *eregs); #endif diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 95ac6a9e5ebc..f82f2584389a 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -759,13 +759,8 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r } #endif -struct bad_iret_stack { - void *error_entry_ret; - struct pt_regs regs; -}; - asmlinkage __visible noinstr -struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) +struct pt_regs *fixup_bad_iret(struct pt_regs *bad_regs) { /* * This is called from entry_64.S early in handling a fault @@ -775,19 +770,19 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) * just below the IRET frame) and we want to pretend that the * exception came from the IRET target. */ - struct bad_iret_stack tmp, *new_stack = - (struct bad_iret_stack *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; + struct pt_regs tmp, *new_stack = + (struct pt_regs *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; /* Copy the IRET target to the temporary storage. */ - __memcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); + __memcpy(&tmp.ip, (void *)bad_regs->sp, 5*8); /* Copy the remainder of the stack from the current stack. */ - __memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + __memcpy(&tmp, bad_regs, offsetof(struct pt_regs, ip)); /* Update the entry stack */ __memcpy(new_stack, &tmp, sizeof(tmp)); - BUG_ON(!user_mode(&new_stack->regs)); + BUG_ON(!user_mode(new_stack)); return new_stack; } #endif -- 2.19.1.6.gb485710b