Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp542930ybg; Wed, 3 Jun 2020 07:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQUoNsEwj/gkphSNFj4LCl5m7LunAVfC+pSRLR4/BOgwEQp7aAEllJnP3y+WSao85cBXaD X-Received: by 2002:a50:d09b:: with SMTP id v27mr8844369edd.235.1591194359486; Wed, 03 Jun 2020 07:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591194359; cv=none; d=google.com; s=arc-20160816; b=f2eBwvrMkI63Mz9/tRUYlv4RmPgj3WBEdStLh21cf4QW6XTRdtmoZ87XIPbbpzrsY5 aPQbgAGTFcW0ZrFpchR2WyNb0rcQoWwJRyFeNdCrkFuTwVWta4nyimzewvgxjxeKbuLK n1H8RPv8/Dk/KgP7MdshMjQGQIn8bIfmQbD+sYNuS245OYkrkenxIwx6nxrleiq8OF8m 74xGOGQB7mVhx9yhg2ezcM6Hd6ZSqY996vx5ZxsyGR03nio9ggnHgAr7DvQamL++g4QK QRZH2Z7dvZC6FuDk+ID8Q8IvQjXVqk6kQvpBVghVCJuNdv+UxpvbJ6rYbQx3DrcbPkvF EBMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=GrSapM/5pNTs2/+vOBbc1voVKrrCXcDQ+9+ZLJp4BOw=; b=RYRgnRdVhhP1SArVtqpIBARiw4eGrI5HquDVs6Ra7QmgIGzhS4vKFhBNXwrxNXD278 2lfw8DEV3mmqdxobLmL7qTmPfskww8DwhTn6OrWTJWhandPwr95dbd9MEeBOnlfufn73 A6SfLZQYP0DDe7w6WnDxpVCB/e/VezAClvBBnAYrLH3tBrCKrDL5z3XshsENOk8PUpzf Yjh5CTqAIKlCCzC8tOZN/YAmLF4ePNT5tVU8eQJ9jpaYESHnR3Kzf5s0NuyMCwX3EA+8 1Ob3jPItNma3IlXKPgx5NY0VUhwiWBiHzVsQMhZwNfTfY0SyGOpKkJSNHSJTZyK49CYp W2/Q== 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 d4si1218828edm.583.2020.06.03.07.25.33; Wed, 03 Jun 2020 07:25:59 -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 S1726010AbgFCOXa (ORCPT + 99 others); Wed, 3 Jun 2020 10:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbgFCOX3 (ORCPT ); Wed, 3 Jun 2020 10:23:29 -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 4C1A3C08C5C0; Wed, 3 Jun 2020 07:23:29 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id B4EF728B; Wed, 3 Jun 2020 16:23:26 +0200 (CEST) Date: Wed, 3 Jun 2020 16:23:25 +0200 From: Joerg Roedel To: Sean Christopherson Cc: x86@kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v3 25/75] x86/sev-es: Add support for handling IOIO exceptions Message-ID: <20200603142325.GB23071@8bytes.org> References: <20200428151725.31091-1-joro@8bytes.org> <20200428151725.31091-26-joro@8bytes.org> <20200520062055.GA17090@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200520062055.GA17090@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jean, On Tue, May 19, 2020 at 11:20:55PM -0700, Sean Christopherson wrote: > On Tue, Apr 28, 2020 at 05:16:35PM +0200, Joerg Roedel wrote: > > + /* > > + * For the string variants with rep prefix the amount of in/out > > + * operations per #VC exception is limited so that the kernel > > + * has a chance to take interrupts an re-schedule while the > > + * instruction is emulated. > > Doesn't this also suppress single-step #DBs? Yes it does. > > > + */ > > + io_bytes = (exit_info_1 >> 4) & 0x7; > > + ghcb_count = sizeof(ghcb->shared_buffer) / io_bytes; > > + > > + op_count = (exit_info_1 & IOIO_REP) ? regs->cx : 1; > > + exit_info_2 = min(op_count, ghcb_count); > > + exit_bytes = exit_info_2 * io_bytes; > > + > > + es_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_ES); > > + > > + if (!(exit_info_1 & IOIO_TYPE_IN)) { > > + ret = vc_insn_string_read(ctxt, > > + (void *)(es_base + regs->si), > > SEV(-ES) is 64-bit only, why bother with the es_base charade? User-space can also cause IOIO #VC exceptions, and user-space can be 32-bit legacy code with segments, so es_base has to be taken into account. > > > + ghcb->shared_buffer, io_bytes, > > + exit_info_2, df); > > df handling is busted, it's aways non-zero. Same goes for the SI/DI > adjustments below. Right, this is fixed now. > Batching the memory accesses and I/O accesses separately is technically > wrong, e.g. a #DB on a memory access will result in bogus data being shown > in the debugger. In practice it seems unlikely to matter, but I'm curious > as to why string I/O is supported in the first place. I didn't think there > was that much string I/O in the kernel? True, #DBs won't be correct anymore. Currently debugging is not supported in SEV-ES guests anyway, but if it is supported the #DB exception would happen in the #VC handler and not on the original instruction. Regards, Joerg