Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1701824ybh; Tue, 14 Jul 2020 05:13:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykbi0vI0HIbDYaFq6ocjWiPNJKgkBKbfsjWRNK3/h7JKdSZeGuafHHrVmJQQ2VKJEdazp0 X-Received: by 2002:a17:906:a0c8:: with SMTP id bh8mr4508099ejb.190.1594728825962; Tue, 14 Jul 2020 05:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728825; cv=none; d=google.com; s=arc-20160816; b=zgVMlQrd3GwWGhKlX6rtbLylqf4jQzhMHRxb5xwWXdx6+pcDa/9NHmuOKnN8XqSePU 6f7aT+ZzTPzeFEnTXq2ziuzjwPiX0CJTGgpc5xX9sidURcPJKqNKkHfrpF//GGtQZplt VH8H5ppOjk+a3vb2nkp562+Wd+xgY4WXJ8mzq4up02yCtobSP1Mlcfmlvx62JMHcVAD5 UKoBP7XdSmKoAcoHRTtVOTrf0P3XHCWd8Gwhcza+umxPL5gmyW3S0vBJ6FzeYj5L9zKU HCt81kPLm0MB5Ju5XdC++x62HcXKIF7sG1oR6tuIb931Q9Onupde0YY2zrUphyTD5yd7 fD6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Y2nVsFUumK+6+PwZj7i5undgQqTsTuzvxJJMaa6FxlA=; b=bFhm8M8m+tvFJcRdtXy4I3h7AoTFJljLr++awloW8gMq1nHQ6JeB/tArZbN/F5R3fi cINaFmz3IA7o7ellCcj4M8li9k860AiG8GylYhuvyA/oFveINkcqj1RtuFrPbcRedQPG NjfI1m9UfUXLIJeO1g63TewMM1UfUmaLiVAz4hzO9AxCTT4siiyD+OIYWjzO0EgHLmFa TjQkoG5ZpxDE311ufmPRTnATQgkIZSs7hNRoU/31mmDeVEkYe/bIT182pX51sBXtveDL haeBNcKK+tdB9KPUCdDRR7+ZVWD339cbrj38xIdlCIDHrGoATMJpRtn5W3/zamM0Od5Y k/TQ== 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=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v19si10485292ejj.608.2020.07.14.05.13.21; Tue, 14 Jul 2020 05:13:45 -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=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728638AbgGNML0 (ORCPT + 99 others); Tue, 14 Jul 2020 08:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728553AbgGNMLR (ORCPT ); Tue, 14 Jul 2020 08:11:17 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85CF8C061755; Tue, 14 Jul 2020 05:11:17 -0700 (PDT) Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id C5E67FDD; Tue, 14 Jul 2020 14:11:07 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 63/75] x86/sev-es: Handle #DB Events Date: Tue, 14 Jul 2020 14:09:05 +0200 Message-Id: <20200714120917.11253-64-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714120917.11253-1-joro@8bytes.org> References: <20200714120917.11253-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Handle #VC exceptions caused by #DB exceptions in the guest. Those must be handled outside of instrumentation_begin()/end() so that the handler will not be raised recursivly. Handle them by calling the kernels debug exception handler. Signed-off-by: Joerg Roedel --- arch/x86/kernel/sev-es.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c index 8f275e5d1ce7..b0f08d9669f1 100644 --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -928,6 +928,14 @@ static enum es_result vc_handle_trap_ac(struct ghcb *ghcb, return ES_EXCEPTION; } +static __always_inline void vc_handle_trap_db(struct pt_regs *regs) +{ + if (user_mode(regs)) + noist_exc_debug(regs); + else + exc_debug(regs); +} + static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, struct ghcb *ghcb, unsigned long exit_code) @@ -1028,6 +1036,16 @@ DEFINE_IDTENTRY_VC_SAFE_STACK(exc_vmm_communication) struct ghcb *ghcb; lockdep_assert_irqs_disabled(); + + /* + * #DB is special and needs to be handled outside of the intrumentation_begin()/end(). + * Otherwise the #VC handler could be raised recursivly. + */ + if (error_code == SVM_EXIT_EXCP_BASE + X86_TRAP_DB) { + vc_handle_trap_db(regs); + return; + } + instrumentation_begin(); /* -- 2.27.0