Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp65782ybb; Thu, 19 Mar 2020 11:45:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs+TPPE08nHXf01z5qTjqrsWWMUZiLmF+4wGj1t9/dR7F/kHgaJv0qbcvbt1YhDlpKLG53x X-Received: by 2002:a05:6830:3090:: with SMTP id f16mr3394638ots.211.1584643527963; Thu, 19 Mar 2020 11:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584643527; cv=none; d=google.com; s=arc-20160816; b=WA5bmSj26iHjAlyNQAUdTJqb4jMSJZJ+Lb5GUTYZk5RVVMCl7LXqGan5XXRBKOscwA 7IV0uhtqKTiSn+q936e7FRfHlxvoVT2AU0yuKJGpyUs5p1LEwqjpwiBWHvZcHhPCPw4K Za1lSBqbbVAnxQTov9v6WIVagzdPUHqXhsh2gglO5DkXAIRopXA82VA8x6EKaFLz/dQy s6zuTB7JOGd26Qmxp5Yrvz6FrZbLWCaA0queNx0Dq1gGmhaUpIKnca4cpHRh6yskmIwm sfX5Dd6Ug4ab/TpP2Eyl855fLEWSv1Gt2MKamA70oA3xwxPZdVUB2flDvXvY2Y09FF8U yO+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=YwSzb8em7ARkvf7tjLWrPfCWRgIfZsKAS9bbDJCzVbM=; b=xYF87CG8nnzXd+SdXYYKLyxJZxP6j0tbryzbAfm/gh/9dSgDHeMEoWXr1jGYg+mZe3 nw4ViCUYe3DEExGOrHj1kZ+XYwoZr0mmhvgvqhDHUSyBXPO8MNdWI4JkpKtiNPGn6IUN 5kwVxKrdTlfozimVgMehMlToxdXYhst39EUKNHJChl+1poLq5MPC9zTqIeTGh1RjeZpT pzXNJ3tYjMQU4bzxZZvXF9bPOEKWKlK3scsoA/QQGBIxwmUMLNeZ628wxjDJHZe2UNFi m1rYbEVP2gQ56SjERxjQeM8G56NfPIcXE9O/85qUYzRZKkk+pa0C5gb5VHAVcN8PGdHR bWBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gZnE0N1z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h145si1417734oib.210.2020.03.19.11.45.14; Thu, 19 Mar 2020 11:45:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gZnE0N1z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727382AbgCSSnf (ORCPT + 99 others); Thu, 19 Mar 2020 14:43:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:34070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgCSSnf (ORCPT ); Thu, 19 Mar 2020 14:43:35 -0400 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2E3FE208E4 for ; Thu, 19 Mar 2020 18:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584643414; bh=16Mv0Bki/NfvJX5iwDxd/8tDdJeb33292LnGanZEgHk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gZnE0N1zX3N4hrpdEBg3hayONMFggbn4LZXMYyZpsRN0k2dZjof1Jfd1Qmvhdh93+ sGF9hoGmQ3D9O6lCKLVt/Fn4A0XRLnor5uOC07hgnzJMuGptsX7jsAEzADkZqINynv dtZbN5mYI74zyy3gDrcqFJNyDt6bH15ZmZzbPenY= Received: by mail-wm1-f50.google.com with SMTP id d1so3578708wmb.2 for ; Thu, 19 Mar 2020 11:43:34 -0700 (PDT) X-Gm-Message-State: ANhLgQ3dKMJNm/28MNKF/IBrU5UTL0BRmVihKwSyKSapWPFHbhIL5nyT SXltR5CLByjlzj+oVsoPbKBi3qwTqOTA1zhVvjl+vw== X-Received: by 2002:a1c:1904:: with SMTP id 4mr765861wmz.21.1584643412632; Thu, 19 Mar 2020 11:43:32 -0700 (PDT) MIME-Version: 1.0 References: <20200319091407.1481-1-joro@8bytes.org> <20200319091407.1481-42-joro@8bytes.org> <20200319162439.GE5122@8bytes.org> In-Reply-To: <20200319162439.GE5122@8bytes.org> From: Andy Lutomirski Date: Thu, 19 Mar 2020 11:43:20 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 41/70] x86/sev-es: Add Runtime #VC Exception Handler To: Joerg Roedel Cc: Andy Lutomirski , X86 ML , "H. Peter Anvin" , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , LKML , kvm list , Linux Virtualization , Joerg Roedel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 19, 2020 at 9:24 AM Joerg Roedel wrote: > > On Thu, Mar 19, 2020 at 08:44:03AM -0700, Andy Lutomirski wrote: > > On Thu, Mar 19, 2020 at 2:14 AM Joerg Roedel wrote: > > > > > > From: Tom Lendacky > > > > > > Add the handler for #VC exceptions invoked at runtime. > > > > If I read this correctly, this does not use IST. If that's true, I > > don't see how this can possibly work. There at least two nasty cases > > that come to mind: > > > > 1. SYSCALL followed by NMI. The NMI IRET hack gets to #VC and we > > explode. This is fixable by getting rid of the NMI EFLAGS.TF hack. > > Not an issue in this patch-set, the confusion comes from the fact that I > left some parts of the single-step-over-iret code in the patch. But it > is not used. The NMI handling in this patch-set sends the NMI-complete > message before the IRET, when the kernel is still in a safe environment > (kernel stack, kernel cr3). Got it! > > > 2. tools/testing/selftests/x86/mov_ss_trap_64. User code does MOV > > (addr), SS; SYSCALL, where addr has a data breakpoint. We get #DB > > promoted to #VC with no stack. > > Also not an issue, as debugging is not supported at the moment in SEV-ES > guests (hardware has no way yet to save/restore the debug registers > across #VMEXITs). But this will change with future hardware. If you look > at the implementation for dr7 read/write events, you see that the dr7 > value is cached and returned, but does not make it to the hardware dr7. Eek. This would probably benefit from some ptrace / perf logic to prevent the kernel or userspace from thinking that debugging works. I guess this means that #DB only happens due to TF or INT01. I suppose this is probably okay. > > I though about using IST for the #VC handler, but the implications for > nesting #VC handlers made me decide against it. But for future hardware > that supports debugging inside SEV-ES guests it will be an issue. I'll > think about how to fix the problem, it probably has to be IST :( Or future generations could have enough hardware support for debugging that #DB doesn't need to be intercepted or can be re-injected correctly with the #DB vector. > > Regards, > > Joerg