Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4062673pxb; Sun, 24 Oct 2021 18:53:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3kRNlvDYYzBuGAsND+vdyEHFoYfaICsipRRsI1GG7mTp0KSDR9RaXXVfYlWRjEiAQb5fs X-Received: by 2002:a17:906:ad97:: with SMTP id la23mr19433081ejb.305.1635126800532; Sun, 24 Oct 2021 18:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635126800; cv=none; d=google.com; s=arc-20160816; b=TqmnC7GZVP2M7H9bFPqz+t9Yk2mD6O+cUH894kNqbSG1H//NOO4irRXut+bMQvIPH9 xzyaPkd48oXUD5c0CHfOKeQjJAWoyja2l0vgGl4PfPbtnqdQ5Jj3bAzkaaalUWtis6+K qEcwgLp6tELJ3UEJnxXoWKjytDlSa99PFqPU2sXcutDRwQWzyy4fGd8kT3voyoPq9xf4 CcEedrvX1ejmAbbh4finii/6Jcx1LGH1UuMspVAyG+tFpRRXxN9zjzzBo/aPSGwPC7iE BmXoo5U/vw/HTru9r7FMj2e5BizcjK+O5QypMC/1FJCEFwIXzIqdJyqsEbHPdUPcuPuX KA5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hOLlZX762RU5af8/NNyJtzm5bln7tTCbxfFHlagVxqU=; b=WrEM162bPy1tT+zuI8xzP+St42wSVzQFxlisxO3+4xnB+YBAxqoLillJ7+MWZXyb/k 6LjdkZwzK/Umf2NFVXaeG4aiG1KSTpAjtxVkOHVHA+XGLaU2UlQVVpYSwvs3Em4F6j9t tOnVYpmpdLG7NlQ8BFbNmX2JeULzhx+/E3Si9NmtZN2FD3gAZo4yZe9/D2tQUNk5jZ1m R1BWtBDkRfbApdvGteSS5pLValP3z8NwDbnsS8xoVl1ogznIK8D5DNQWmWbfPJN6geIa p2+oJFowUhjHjwvMHCWGniqmYP8LfWtgHb0HPDleJGhXvQuauol0nQvPozlvMlGDarl0 0FgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TkNaOXOJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si12684048edd.254.2021.10.24.18.52.57; Sun, 24 Oct 2021 18:53:20 -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=@google.com header.s=20210112 header.b=TkNaOXOJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231954AbhJYBdf (ORCPT + 99 others); Sun, 24 Oct 2021 21:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbhJYBdf (ORCPT ); Sun, 24 Oct 2021 21:33:35 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACD93C061767 for ; Sun, 24 Oct 2021 18:31:13 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id o83so13420675oif.4 for ; Sun, 24 Oct 2021 18:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hOLlZX762RU5af8/NNyJtzm5bln7tTCbxfFHlagVxqU=; b=TkNaOXOJkzMC/4YS68UKZsixboDKL+fTnwKOI4TzlCB+1Ozwmv2detwjUcvSRQJDq+ nmB+TBXyDhTBoEChQ7wjOVDk/Ga5X3LMg9Hj09ObYr5+Ez+IV5DG58zOvlbOO/m7yJyS pLJVxkqzZCk0TFsYoqt2gLvBgnXcQjR1pKL+xLbm/5HdLAyVKb3h5sEy17VxhUjKpYRl 0kTi0+CFF/fx0vJGJa8sDJerOImUFf0KMW/0mxR7S4O1B2FdaGGOjBdrtoBrpWkkzz4D eEp3VF4O/Y/1ynX8o8d5JRiVQakJOQnU9mBggLGsCUT6gEmxGSNxCemEoeArO16CkX+u 5blA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hOLlZX762RU5af8/NNyJtzm5bln7tTCbxfFHlagVxqU=; b=xpM2yPEqQDmSRt/PmM+y45cF+1m8AbueWFCMDry5fx5Uqy0KjHx1c4QRffC6Atcaph EloNjJiPagSsi9/+OtyxvrIpZENeb9xKwAWE6EF5cD9FabsPMzoTh0taGBM0njXjunnx lAPwr4Hh/rgrCYPSkk/n5FHGA/Saion/yvNb+fOjm6cCLKRzRJj96YeUXmFI81oUOsiv DxN6xtF9dAzs8/XhwaPLpuTUcFchQvzIAQpb5zBZdPxRu1nvfVnyXXHSO/6cozGHRC55 KbkKFbryrcfNc2nKq+hjlezZg4H0ajmgUH3wVnQU7rv06EiPGnJIxyHUpYHS26lPncbe 4qNQ== X-Gm-Message-State: AOAM5336tmgb/i6lAGxI3pQYjIbTel9HnBtNHTxUv8ZpTa3T6otUa7Zp fuOxhOdN8cwHkCJndbdjSI0r5/ve3JISIgeQO2531w== X-Received: by 2002:a05:6808:a1d:: with SMTP id n29mr11806544oij.164.1635125472740; Sun, 24 Oct 2021 18:31:12 -0700 (PDT) MIME-Version: 1.0 References: <20211013165616.19846-1-pbonzini@redhat.com> <20211013165616.19846-2-pbonzini@redhat.com> In-Reply-To: <20211013165616.19846-2-pbonzini@redhat.com> From: Marc Orr Date: Sun, 24 Oct 2021 18:31:01 -0700 Message-ID: Subject: Re: [PATCH 1/8] KVM: SEV-ES: fix length of string I/O To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, fwilhelm@google.com, seanjc@google.com, oupton@google.com, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 9:56 AM Paolo Bonzini wrote: > > The size of the data in the scratch buffer is not divided by the size of > each port I/O operation, so vcpu->arch.pio.count ends up being larger > than it should be by a factor of size. > > Cc: stable@vger.kernel.org > Fixes: 7ed9abfe8e9f ("KVM: SVM: Support string IO operations for an SEV-ES guest") > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/svm/sev.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index c36b5fe4c27c..e672493b5d8d 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -2583,7 +2583,7 @@ int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in) > return -EINVAL; > > return kvm_sev_es_string_io(&svm->vcpu, size, port, > - svm->ghcb_sa, svm->ghcb_sa_len, in); > + svm->ghcb_sa, svm->ghcb_sa_len / size, in); > } > > void sev_es_init_vmcb(struct vcpu_svm *svm) > -- > 2.27.0 > > I could be missing something, but I'm pretty sure that this is wrong. The GHCB spec says that `exit_info_2` is the `rep` count. Not the string length. For example, given a `rep outsw` instruction, with `ECX` set to `8`, the rep count written into `SW_EXITINFO2` should be eight x86 words (i.e., 16 bytes) and the IO size should be one x86 word (i.e., 2 bytes). In other words, the code was correct before this patch. This patch is incorrectly dividing the rep count by the IO size, causing the string IO to be truncated.