Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4699226imw; Tue, 12 Jul 2022 12:39:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u3MbSJEgkVw61z69Qelohqb+82FQZafYscGYRvOy8k5983T2Fkg1TNWVLJDVWUeCSjGqO1 X-Received: by 2002:a17:906:a402:b0:72b:8e6e:64ea with SMTP id l2-20020a170906a40200b0072b8e6e64eamr2347074ejz.469.1657654789142; Tue, 12 Jul 2022 12:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654789; cv=none; d=google.com; s=arc-20160816; b=bunBF8T8KHsMw3Ih8Fp35b40lsBAIUG68zxeNSmUT7uXqb4SRk6Ifhub6FdyLXYwOn 6E1MQRF06g0ucs6cmZbHW6RAASU9HNCxaNUwQ0Jd/VTDRb/Za5sr7IHo3J93oP4IDyCK L2JLLG7ndOvhj/K9Q1auSNRDbDw689Y2L6FDzbz6YliopFIus0JDghcz9BrX0MzvDj16 l5ZpN+JsOLIcZNdNQPneqD0Bf22qi7S87FkDlqQG+SbncP+AlUef73UutyuHokH83S7v W9acy1+lNwVxXEOr1KtsPlv+QYAEQYHRd65boDdqJA+zts955aK0dsUrOPHNEpcOCnQs /mug== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XZokDkA9XUB+cmiCWljvxGhRdHT0a4cnxtMBxFFgnjY=; b=clJws/YmxsSamzMSg4CiPG2GG6kZHyAaeuuSioGhM5Qw/sCqxly/ZrWm769WPsW070 9qr7wuwOBwaIGJnOzLW8LlIUQpuZDPygfRLZGeJYyUty1lPpQwi8i1GLXxjSOIU7JChW KLQCL75ai71nijDRBlvZhFXrsBX+ZrVjQXgtffpm8beRxBLkIPZQQZ/c33p/Q3vS+4H8 cWy27jp0zUC0hc3ceCYK6dy7UdTV93XumXS7eDVTtvf26oWbrHFzu72tc9YwRmnqwUGl lMGiDXh7f9yaZio7Az1qMOCS/s8JaH6JIbmspz6USAT9ZYDVcX/1yMnjBQdjQjJ3Aqzf MFeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OiAeobPr; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rn9-20020a170906d92900b00718ccb0a135si14340558ejb.507.2022.07.12.12.39.23; Tue, 12 Jul 2022 12:39:49 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=OiAeobPr; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235650AbiGLTIT (ORCPT + 99 others); Tue, 12 Jul 2022 15:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235581AbiGLTHj (ORCPT ); Tue, 12 Jul 2022 15:07:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCB0AFC998; Tue, 12 Jul 2022 11:51:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D5C9161274; Tue, 12 Jul 2022 18:51:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5CE1C3411C; Tue, 12 Jul 2022 18:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651883; bh=Az7tafjlMAHHUibJrTHvA+4CWrMRaYbgi8eIJ5nAc2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OiAeobPr3G/+a3NJzRXvCdYwy9rCW5PjDJMu5eMfVAi1cSVsTAIzXYnFmvncrO+0a /xzf1lhLo4871feo09/ts0cwPYaE9kGUBWJNlQcWPQc05QWqkYBxGBRMs24Q+IRO3K foJeQInpwgD9GqYfKpCZqpDG3Sql3NQ0k+SfJEZk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lai Jiangshan , Borislav Petkov , Juergen Gross , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.18 03/61] x86/entry: Move PUSH_AND_CLEAR_REGS out of error_entry() Date: Tue, 12 Jul 2022 20:39:00 +0200 Message-Id: <20220712183237.075467548@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183236.931648980@linuxfoundation.org> References: <20220712183236.931648980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 commit ee774dac0da1543376a69fd90840af6aa86879b3 upstream. The macro idtentry() (through idtentry_body()) calls error_entry() unconditionally even on XENPV. But XENPV needs to only push and clear regs. PUSH_AND_CLEAR_REGS in error_entry() makes the stack not return to its original place when the function returns, which means it is not possible to convert it to a C function. Carve out PUSH_AND_CLEAR_REGS out of error_entry() and into a separate function and call it before error_entry() in order to avoid calling error_entry() on XENPV. It will also allow for error_entry() to be converted to C code that can use inlined sync_regs() and save a function call. [ bp: Massage commit message. ] Signed-off-by: Lai Jiangshan Signed-off-by: Borislav Petkov Reviewed-by: Juergen Gross Link: https://lore.kernel.org/r/20220503032107.680190-4-jiangshanlai@gmail.com Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_64.S | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -318,6 +318,14 @@ SYM_CODE_END(ret_from_fork) #endif .endm +/* Save all registers in pt_regs */ +SYM_CODE_START_LOCAL(push_and_clear_regs) + UNWIND_HINT_FUNC + PUSH_AND_CLEAR_REGS save_ret=1 + ENCODE_FRAME_POINTER 8 + RET +SYM_CODE_END(push_and_clear_regs) + /** * idtentry_body - Macro to emit code calling the C function * @cfunc: C function to be called @@ -325,6 +333,9 @@ SYM_CODE_END(ret_from_fork) */ .macro idtentry_body cfunc has_error_code:req + call push_and_clear_regs + UNWIND_HINT_REGS + call error_entry movq %rax, %rsp /* switch to the task stack if from userspace */ ENCODE_FRAME_POINTER @@ -986,13 +997,11 @@ SYM_CODE_START_LOCAL(paranoid_exit) SYM_CODE_END(paranoid_exit) /* - * Save all registers in pt_regs, and switch GS if needed. + * Switch GS and CR3 if needed. */ SYM_CODE_START_LOCAL(error_entry) UNWIND_HINT_FUNC cld - PUSH_AND_CLEAR_REGS save_ret=1 - ENCODE_FRAME_POINTER 8 testb $3, CS+8(%rsp) jz .Lerror_kernelspace