Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3844779pxy; Mon, 26 Apr 2021 11:05:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZwHoIVJgX+EeBYgKBYQWWzDNj6R4DD33WRh75Sbp74VunAqO6rTl6wsfe7qkhW5aY4dss X-Received: by 2002:a50:8fe6:: with SMTP id y93mr22526504edy.224.1619460310282; Mon, 26 Apr 2021 11:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460310; cv=none; d=google.com; s=arc-20160816; b=oCP6yKHtUNPTOqhryaAI2q293T/OYH5xLrKZtL9IcieFBrBIvJPbVo0d5D+RHewmgM vTADH+CCv+5qUHF38LoqC0oZEOBTrGzuOT/fZcO75okTrFCpfN0B8tFARiqni4IIdY3y zrnOolqET+naTztJvpBpJaO2hm1QDQ01cVredIRkyuKY6UCgcLUdkukMVQPkqRMH2cNM Svi82kEawWEo+g0y+rO3gRCm80zJw17B3/LC4DLqsTnSoEd9/7kNH6AbUhG6m1eL9jX8 nUgtkl8dTnKHOd5YdObArNgHSGOhaBY0zYICklnuUidlCGdRQXihg39lpQg/8VHeCNKF ZJ6g== 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 :ironport-sdr:ironport-sdr; bh=Lx299NBWGzynNHj8gx14HYAXXF5vVWbCyrkK+oezkpE=; b=jeuEjWBcq3FDc7jgHs9IQ69o2d04d/ikglVizH1rGxqV84C05r9DGgLCdkbSsDtzZs N3S/tWrk9gj0FTRzGXghCXGWDRjyG0emlR+gW/FTzHPSC6Th3Pmgz3730klpKBfYCWOn CaUQXTIkRhiQP6apHojBepoYZGVMlAHZg087imSfD30Vd4q64Q2dTB93SvgvNSZJyOYJ qevYO/rDfKVKCbMDl+VNnF5Xbo+RJsgFDtoqPhITavrPdvp19MJQbAR02dkJ+LwfDriz 8sgxbvJMDLvyx9HelvUPeNg8JDrZKSz2I8fEsYrMoOHw0/svKGQ2EypReQ/aivpXnK8W E7Yw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si14123198ejx.546.2021.04.26.11.04.46; Mon, 26 Apr 2021 11:05:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234583AbhDZSDw (ORCPT + 99 others); Mon, 26 Apr 2021 14:03:52 -0400 Received: from mga14.intel.com ([192.55.52.115]:31744 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234274AbhDZSD3 (ORCPT ); Mon, 26 Apr 2021 14:03:29 -0400 IronPort-SDR: sxx8pUkxq1B0dGwp1x/LkjVoglALx0hJoD4cHI1BtdIF6+RT0OGaplSjo2Gu9BahKpErK2hxPb bWX97YBdh+/g== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="195934039" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="195934039" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:47 -0700 IronPort-SDR: Dj/XabYGD3+8a4SEaRD3ilnatyaYCbNIGkY5EtmIY8ZrZPfs+F5+U3mXr/u9ceytqrGmMqAdTm vp46lhGUCbcw== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353355" Received: from ssumanpx-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.254.34.197]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:43 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Dan Williams , Tony Luck Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , linux-kernel@vger.kernel.org, Kuppuswamy Sathyanarayanan Subject: [RFC v2 07/32] =?UTF-8?q?x86/traps:=20Add=C2=A0do=5Fgeneral=5Fpro?= =?UTF-8?q?tection()=20helper=20function?= Date: Mon, 26 Apr 2021 11:01:34 -0700 Message-Id: <00eeea950502dbaa5f6d48509307c806e08c6e4d.1619458733.git.sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TDX guest #VE exception handler treats unsupported exceptions as #GP. So to handle the #GP, move the protection fault handler code to out of exc_general_protection() and create new helper function for it. Also since exception handler is responsible to decide when to turn on/off IRQ, move cond_local_irq_{enable/disable)() calls out of do_general_protection(). This is a preparatory patch for adding #VE exception handler support for TDX guests. Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/traps.c | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 651e3e508959..213d4aa8e337 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -527,44 +527,28 @@ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs, #define GPFSTR "general protection fault" -DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) +static void do_general_protection(struct pt_regs *regs, long error_code) { char desc[sizeof(GPFSTR) + 50 + 2*sizeof(unsigned long) + 1] = GPFSTR; enum kernel_gp_hint hint = GP_NO_HINT; - struct task_struct *tsk; + struct task_struct *tsk = current; unsigned long gp_addr; int ret; - cond_local_irq_enable(regs); - - if (static_cpu_has(X86_FEATURE_UMIP)) { - if (user_mode(regs) && fixup_umip_exception(regs)) - goto exit; - } - - if (v8086_mode(regs)) { - local_irq_enable(); - handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); - local_irq_disable(); - return; - } - - tsk = current; - if (user_mode(regs)) { 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; + return; show_signal(tsk, SIGSEGV, "", desc, regs, error_code); force_sig(SIGSEGV); - goto exit; + return; } if (fixup_exception(regs, X86_TRAP_GP, error_code, 0)) - goto exit; + return; tsk->thread.error_code = error_code; tsk->thread.trap_nr = X86_TRAP_GP; @@ -576,11 +560,11 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) if (!preemptible() && kprobe_running() && kprobe_fault_handler(regs, X86_TRAP_GP)) - goto exit; + return; ret = notify_die(DIE_GPF, desc, regs, error_code, X86_TRAP_GP, SIGSEGV); if (ret == NOTIFY_STOP) - goto exit; + return; if (error_code) snprintf(desc, sizeof(desc), "segment-related " GPFSTR); @@ -601,8 +585,27 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) gp_addr = 0; die_addr(desc, regs, error_code, gp_addr); +} -exit: +DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) +{ + cond_local_irq_enable(regs); + + if (static_cpu_has(X86_FEATURE_UMIP)) { + if (user_mode(regs) && fixup_umip_exception(regs)) { + cond_local_irq_disable(regs); + return; + } + } + + if (v8086_mode(regs)) { + local_irq_enable(); + handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); + local_irq_disable(); + return; + } + + do_general_protection(regs, error_code); cond_local_irq_disable(regs); } -- 2.25.1