Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3643189pxb; Wed, 13 Oct 2021 09:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMPGPUPVFn0FL1jGplnAgBmKvRmRAsr3l4sWnsEsV38TKrE4Et7HXG7pkysntZm3BDe4Dc X-Received: by 2002:a17:906:9414:: with SMTP id q20mr425901ejx.241.1634144320640; Wed, 13 Oct 2021 09:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634144320; cv=none; d=google.com; s=arc-20160816; b=JHMKyuEow/617spX7DQrnlMmK09fGakt2RfJKZhEC/6IaOREDEibR9L8G9olC5cSl9 fVTJCHaUFi25Knax4BLpJMYesp68mQfqu+Pr6Rtbpj/ARCMi0qVu3T5Jjg9zP007BvrJ xXS5FDRTYwaBFXdFDjae73eJN/7piv6M5eM+gM+6l9WUXWtBU0AVDW7aJJ5eUsTQbyy1 L96k+X1fMf0BV9Pb29GebNic4I9LP27UEgLM2odRNXXUHxLmIeB3lmngKLbdlOByKdMy jZxwPDRlnW7IEjcZEE7JoC/kmpEIwUyLt4VQSgC2xda2YOmjLTniDs0SrcaYFNNVZfr8 XKdA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KTXsB7y98qjD44G3XE71PU+BjMImn/7agIimOiEWzwY=; b=cTvp4gxMz5mo1L8aue+l/j1klCys25eENZDyspVissjQwpAZcFgsDBnq1+Et25IuxN ud+DJmomoBByQ3tN3D3WOn2+JZt/mElCbn7KJQmdncyxF3IWI8AuGV4S3qxSpP5D2rBG RQJ6CA79GYyXB3Ea/KLYiMmLoz8uefXQgDjicXNazuLDJd2QhQG7eLQf2rIe1bCEdd+U Suk2aBIIZYJWj8gZZXvpteCa8rP4q7rsQF7ycX2ZWnIkgvHZsuz7/O6GW0dNMsVd1lg8 hYLwWdbz3d67L7AOl5iPRq+ackSECd63YbOB1T9O1AUT8iLJE+YYoavXOg48XudKsdp7 shKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NSa5YJTb; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si90717edd.214.2021.10.13.09.58.13; Wed, 13 Oct 2021 09:58:40 -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=@redhat.com header.s=mimecast20190719 header.b=NSa5YJTb; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237528AbhJMQ6b (ORCPT + 99 others); Wed, 13 Oct 2021 12:58:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56782 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237650AbhJMQ6Z (ORCPT ); Wed, 13 Oct 2021 12:58:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634144182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KTXsB7y98qjD44G3XE71PU+BjMImn/7agIimOiEWzwY=; b=NSa5YJTbI9rMwVVkvpczLGOoPEn0MwxqP5rbT2Qpk57odmOc23sRjMAxii94GH2DR21hcB xUn92gQd8sgY99M+KJnWvYLABtzJKe3PU+qr7MKgeE388pkOehFoGX51x1CWHyIjCqi9zf fBlqwe4k3S+i84NyA2Nq9F7gYO05Ui0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-N_dHGBNIN4qREs7u67X3nw-1; Wed, 13 Oct 2021 12:56:18 -0400 X-MC-Unique: N_dHGBNIN4qREs7u67X3nw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AE04801FCE; Wed, 13 Oct 2021 16:56:17 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CC715DA60; Wed, 13 Oct 2021 16:56:16 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: fwilhelm@google.com, seanjc@google.com, oupton@google.com Subject: [PATCH 0/8] KVM: SEV-ES: fixes for string I/O emulation Date: Wed, 13 Oct 2021 12:56:08 -0400 Message-Id: <20211013165616.19846-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series, namely patches 1 and 8, fix two bugs in string I/O emulation for SEV-ES: - first, the length is completely off for "rep ins" and "rep outs" operation of size > 1. After setup_vmgexit_scratch, svm->ghcb_sa_len is in bytes, but kvm_sev_es_string_io expects the number of PIO operations. - second, the size of the GHCB buffer can exceed the size of vcpu->arch.pio_data. If that happens, we need to go over the GHCB buffer in multiple passes. The second bug was reported by Felix Wilhelm. The first was found by me by code inspection; on one hand it seems *too* egregious so I'll be gladly proven wrong on this, on the other hand... I know I'm bad at code review, but not _that_ bad. Patches 2 to 7 are a bunch of cleanups to emulator_pio_in and emulator_pio_in_out, so that the final SEV code is a little easier to reason on. Just a little, no big promises. Tested by booting a SEV-ES guest and with "regular" kvm-unit-tests. For SEV-ES I also bounded the limit to 12 bytes, and checked in the resulting trace that both the read and write paths were hit when booting a guest. Paolo Paolo Bonzini (8): KVM: SEV-ES: fix length of string I/O KVM: SEV-ES: rename guest_ins_data to sev_pio_data KVM: x86: leave vcpu->arch.pio.count alone in emulator_pio_in_out KVM: SEV-ES: clean up kvm_sev_es_ins/outs KVM: x86: split the two parts of emulator_pio_in KVM: x86: remove unnecessary arguments from complete_emulator_pio_in KVM: SEV-ES: keep INS functions together KVM: SEV-ES: go over the sev_pio_data buffer in multiple passes if needed arch/x86/include/asm/kvm_host.h | 3 +- arch/x86/kvm/svm/sev.c | 2 +- arch/x86/kvm/x86.c | 136 +++++++++++++++++++++----------- 3 files changed, 95 insertions(+), 46 deletions(-) -- 2.27.0