Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp966619pxb; Wed, 6 Apr 2022 05:32:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOjoGH/Kv5SjzOE2PUE7VX8Cc04RPwbg0malLY/T809dOLw6WNKzYtU7K3jrhejzu3U7dw X-Received: by 2002:a17:90b:1e4e:b0:1c7:3512:c2ac with SMTP id pi14-20020a17090b1e4e00b001c73512c2acmr9573968pjb.61.1649248362003; Wed, 06 Apr 2022 05:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649248361; cv=none; d=google.com; s=arc-20160816; b=ipBjzXOeb327QMmnOXv6AaVPFSXOD1bKdPHRBlj6DJ+GFtQArqwpJtMive/K7L+DcR qE+tOictW4FQjbO48DFIVohUtq/mvG9pknAolg2TuDp6de5KTztZHrpPVb7eLcEBmgUQ dwlXKFalZ++1LZyYrw5saVpYc0QU0iEzAhLmsAg5f4r8KGOt5BBFUsTWjaYrWMIRhNju ayxtmK1lN7ngF17FkieFjiuwrKLLUJw56Md7+6d31OAhm2JMat2UXU7FNXuwDGVhRcyK kxOTupHtuBJ/qV8EvYWEBsflV4NV+xmUfl+MeR1jYerPsNzIcrO4htK5CwzBQORrFK+u 3PXA== 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=HF5xwbMO0dfh7hNLQhrR9qoB2vdTG4vI8oVrM32sDro=; b=TtsVBSEV3XnvD8swDCdxJTJ+ilsYT0Esbl9mdynAyIH9x4+8eM3zXQkq949H48/La3 tt1RIytLUA8IMyH2Er/OThn2X2dkrnDKMQ8Ilae9E2LfeXzo14fMH/hRA7G2OJ5qGEKm oADNnlGPgIDGW/zukxGpFfQNnMHxN6j07IixUP6U4HArQY+LFjNuXYfBYX4GpUnH/ELv tzBTMWLmDlmOoJ7iZhE8u8YbcYO426bmsraDXcqoPWXbdjXMBTneopxc+27Ge+s+piDW UItUiIOIEToWV7b4vOSxlRFj7V4PFWLSPmoY6lYcd9nR+9GUlbUsZRxwj0VWev0M46fR 1l/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gj6rNgwn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h4-20020a170902f54400b00153b2d1647dsi16893032plf.133.2022.04.06.05.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:32:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gj6rNgwn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DEEA53D7EA; Wed, 6 Apr 2022 02:13:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2359585AbiDFDQO (ORCPT + 99 others); Tue, 5 Apr 2022 23:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357834AbiDFCOQ (ORCPT ); Tue, 5 Apr 2022 22:14:16 -0400 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8893A1B2552 for ; Tue, 5 Apr 2022 16:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649201716; x=1680737716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BwdAHnXe3IiqnqdJL+5CaPqUGulphcchYpvco8UlK2w=; b=gj6rNgwn590ni8ArrnthkG1mJZpO6eNfh8IRjbrkeoI3YUzY/fSp9xn5 N+1l7QySnaybY5eDz6RqES0/LwGlw4cm2tYOR/e17w22rOb0fN/pl/kqW FiJUp7v6xwVSqIBkDlmOJhIyl94cu9Uk5fgmYuJFSDAdtg+L5Y/Xh1N+I MUydCr6KAKmIy5lKb8gAlfs0y7pBhM/aNeHKOdj5qHoiUiJgASPFGcwcY P2DoPlImjm/816e55y7RicpS3Dyla3VAhXFpyS9eI42ORejDHOba5b9kG H7YQsIfBfXCqiBHZVouuo2e2ijCkA63oCfh46IIgFssl1vfJGg7EMJRXq g==; X-IronPort-AV: E=McAfee;i="6200,9189,10308"; a="321586046" X-IronPort-AV: E=Sophos;i="5.90,238,1643702400"; d="scan'208";a="321586046" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2022 16:34:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,238,1643702400"; d="scan'208";a="588136287" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 05 Apr 2022 16:34:41 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id B519360A; Wed, 6 Apr 2022 02:29:45 +0300 (EEST) From: "Kirill A. Shutemov" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: [PATCHv8 06/30] x86/traps: Refactor exc_general_protection() Date: Wed, 6 Apr 2022 02:29:15 +0300 Message-Id: <20220405232939.73860-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405232939.73860-1-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 TDX brings a new exception -- Virtualization Exception (#VE). Handling of #VE structurally very similar to handling #GP. Extract two helpers from exc_general_protection() that can be reused for handling #VE. No functional changes. Suggested-by: Thomas Gleixner Signed-off-by: Kirill A. Shutemov Reviewed-by: Dave Hansen --- arch/x86/kernel/traps.c | 57 ++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 1563fb995005..db8d22a0d003 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -686,13 +686,40 @@ static bool try_fixup_enqcmd_gp(void) #endif } +static bool gp_try_fixup_and_notify(struct pt_regs *regs, int trapnr, + unsigned long error_code, const char *str) +{ + if (fixup_exception(regs, trapnr, error_code, 0)) + return true; + + current->thread.error_code = error_code; + current->thread.trap_nr = trapnr; + + /* + * To be potentially processing a kprobe fault and to trust the result + * from kprobe_running(), we have to be non-preemptible. + */ + if (!preemptible() && kprobe_running() && + kprobe_fault_handler(regs, trapnr)) + return true; + + return notify_die(DIE_GPF, str, regs, error_code, trapnr, SIGSEGV) == NOTIFY_STOP; +} + +static void gp_user_force_sig_segv(struct pt_regs *regs, int trapnr, + unsigned long error_code, const char *str) +{ + current->thread.error_code = error_code; + current->thread.trap_nr = trapnr; + show_signal(current, SIGSEGV, "", str, regs, error_code); + force_sig(SIGSEGV); +} + DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) { char desc[sizeof(GPFSTR) + 50 + 2*sizeof(unsigned long) + 1] = GPFSTR; enum kernel_gp_hint hint = GP_NO_HINT; - struct task_struct *tsk; unsigned long gp_addr; - int ret; if (user_mode(regs) && try_fixup_enqcmd_gp()) return; @@ -711,40 +738,18 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) return; } - tsk = current; - if (user_mode(regs)) { if (fixup_iopl_exception(regs)) goto exit; - tsk->thread.error_code = error_code; - tsk->thread.trap_nr = X86_TRAP_GP; - if (fixup_vdso_exception(regs, X86_TRAP_GP, error_code, 0)) goto exit; - show_signal(tsk, SIGSEGV, "", desc, regs, error_code); - force_sig(SIGSEGV); + gp_user_force_sig_segv(regs, X86_TRAP_GP, error_code, desc); goto exit; } - if (fixup_exception(regs, X86_TRAP_GP, error_code, 0)) - goto exit; - - tsk->thread.error_code = error_code; - tsk->thread.trap_nr = X86_TRAP_GP; - - /* - * To be potentially processing a kprobe fault and to trust the result - * from kprobe_running(), we have to be non-preemptible. - */ - if (!preemptible() && - kprobe_running() && - kprobe_fault_handler(regs, X86_TRAP_GP)) - goto exit; - - ret = notify_die(DIE_GPF, desc, regs, error_code, X86_TRAP_GP, SIGSEGV); - if (ret == NOTIFY_STOP) + if (gp_try_fixup_and_notify(regs, X86_TRAP_GP, error_code, desc)) goto exit; if (error_code) -- 2.35.1