Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp711155ybk; Wed, 13 May 2020 11:03:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxY7P8uv4dPeVwqImBLq54JRP3DYttvNHL8SM2dT2wGBizZmVLJCd/JAufX7HLL107aCIG X-Received: by 2002:a17:906:bce6:: with SMTP id op6mr169217ejb.337.1589392993957; Wed, 13 May 2020 11:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589392993; cv=none; d=google.com; s=arc-20160816; b=AuXdgJf+OakE+I8PzH/PwjWnS+fXouXxd0xDh3MqBFZJbxlS8nrcsxUmwA6rP9Ccsd H7byQnyi74fQWwdzoPSBXLKCVCqWw1ywhafRAb37yalgKlxn/o5uzMrkg9a/MbyZAcK0 ACVyAL2+F1dXf0TpxBdSYST9vK+NXB7RKbTIJDayLmaErOfi1J2keSqFqF8ws1SEplaB p48uYnlpiDLgA+FNbXxHGV23v5uzLKvCRYh8SletKz9pdtiO/UJpLdDUmPLzfDpGn9E7 /1qF7AkCMIoiKvJKB4sMONFI4pH2V9UYVSqsPC2Q/0YYAHWM4xfUm6Qti+qi7wXQ8T6D Qk3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qly6k0bS0jaJ4vTsa92+67UL4fjNB6/GPr5KzlthQcQ=; b=cDYi+eNf/82XDbL+ejQ9NUGen6vCEeusoXvEzhMuqc8vuXb7X8QIIOClHmcDfaKNUF Ey1oJ2ioC/L3E3DcYXqIl6o4uPgaFPaCujvg2lQYbHQp7myT3Pe49Y161C1MaKangDN2 ToFYg2KoV5rVIzZgtaWU7fxilqo5I9n6x+x20lKEYdPVlu7Qh/VLUYKNjwQ2C2zp1BF+ RKD3zRkvlbMfvmYsE48iHxrKGRSu1FfbbXjYgg6o+Yt0/M2141OEoeTp5gClIjW0yavS y72N+yXziz9oAI3bUCYnNGfzQ2kNbMD+egUkCJXgITNWJ5itzzdCLafXRMKOTPzAZJD6 RnuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=b2fmu6R5; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n17si237125ejd.437.2020.05.13.11.02.49; Wed, 13 May 2020 11:03:13 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=b2fmu6R5; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389980AbgEMR7F (ORCPT + 99 others); Wed, 13 May 2020 13:59:05 -0400 Received: from mail.skyhub.de ([5.9.137.197]:35028 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733070AbgEMR7F (ORCPT ); Wed, 13 May 2020 13:59:05 -0400 Received: from zn.tnic (p200300EC2F0AC30000E7FCC03D02E6FD.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:c300:e7:fcc0:3d02:e6fd]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 761AF1EC02CF; Wed, 13 May 2020 19:59:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1589392743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=qly6k0bS0jaJ4vTsa92+67UL4fjNB6/GPr5KzlthQcQ=; b=b2fmu6R5CwARmJ82Ii9IC4F9SFQKrbd7AAjpxwuLzTkb3nJ8H5eHCkXglWJfVEmuzz1jNh 9wHKVT/EDt0M7zvbjvUm7GvesRGaJySqfhPmu0WwV2QzoIoZN1Ajk2fV8n3IJK02XlJ4/A Q9vkNh6Mw13MDMQwarcjHK4wXrl4eA8= Date: Wed, 13 May 2020 19:58:59 +0200 From: Borislav Petkov To: Joerg Roedel 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: <20200513175859.GF4025@zn.tnic> References: <20200428151725.31091-1-joro@8bytes.org> <20200428151725.31091-26-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200428151725.31091-26-joro@8bytes.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 28, 2020 at 05:16:35PM +0200, Joerg Roedel wrote: > From: Tom Lendacky > > Add support for decoding and handling #VC exceptions for IOIO events. > > Signed-off-by: Tom Lendacky > [ jroedel@suse.de: Adapted code to #VC handling framework ] > Co-developed-by: Joerg Roedel > Signed-off-by: Joerg Roedel > --- > arch/x86/boot/compressed/sev-es.c | 32 +++++ > arch/x86/kernel/sev-es-shared.c | 202 ++++++++++++++++++++++++++++++ > 2 files changed, 234 insertions(+) Just nitpicks and some more commenting needed: > +static enum es_result vc_handle_ioio(struct ghcb *ghcb, struct es_em_ctxt *ctxt) > +{ > + struct pt_regs *regs = ctxt->regs; > + u64 exit_info_1, exit_info_2; > + enum es_result ret; > + > + ret = vc_ioio_exitinfo(ctxt, &exit_info_1); > + if (ret != ES_OK) > + return ret; > + > + if (exit_info_1 & IOIO_TYPE_STR) { > + int df = (regs->flags & X86_EFLAGS_DF) ? -1 : 1; > + unsigned int io_bytes, exit_bytes; > + unsigned int ghcb_count, op_count; > + unsigned long es_base; > + u64 sw_scratch; > + > + /* > + * 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 ^ and > + * instruction is emulated. > + */ > + 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); In general, I could use some commenting here to find my way around it: /* Read bytes of OUTS into the shared buffer */ > + > + if (!(exit_info_1 & IOIO_TYPE_IN)) { > + ret = vc_insn_string_read(ctxt, > + (void *)(es_base + regs->si), > + ghcb->shared_buffer, io_bytes, > + exit_info_2, df); > + if (ret) > + return ret; > + } /* * Issue an VMGEXIT to the HV to consume the bytes from the * shared buffer or to have it write them into the shared buffer * depending on the instruction: OUTS or INS. */ > + > + sw_scratch = __pa(ghcb) + offsetof(struct ghcb, shared_buffer); > + ghcb_set_sw_scratch(ghcb, sw_scratch); > + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_IOIO, > + exit_info_1, exit_info_2); Align arguments on the opening brace. > + if (ret != ES_OK) > + return ret; > + > + /* Everything went well, write back results */ /* Read bytes from shared buffer into the guest's destination. */ > + if (exit_info_1 & IOIO_TYPE_IN) { > + ret = vc_insn_string_write(ctxt, > + (void *)(es_base + regs->di), > + ghcb->shared_buffer, io_bytes, > + exit_info_2, df); > + if (ret) > + return ret; > + > + if (df) > + regs->di -= exit_bytes; > + else > + regs->di += exit_bytes; > + } else { > + if (df) > + regs->si -= exit_bytes; > + else > + regs->si += exit_bytes; > + } > + > + if (exit_info_1 & IOIO_REP) > + regs->cx -= exit_info_2; > + > + ret = regs->cx ? ES_RETRY : ES_OK; > + > + } else { /* IN/OUT into/from rAX */ > + int bits = (exit_info_1 & 0x70) >> 1; > + u64 rax = 0; > + > + if (!(exit_info_1 & IOIO_TYPE_IN)) > + rax = lower_bits(regs->ax, bits); > + > + ghcb_set_rax(ghcb, rax); > + > + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_IOIO, exit_info_1, 0); > + if (ret != ES_OK) > + return ret; > + > + if (exit_info_1 & IOIO_TYPE_IN) { > + if (!ghcb_is_valid_rax(ghcb)) > + return ES_VMM_ERROR; > + regs->ax = lower_bits(ghcb->save.rax, bits); > + } > + } > + > + return ret; > +} > -- Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette