Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp725974pxb; Mon, 25 Oct 2021 17:32:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8p7nPgYk0qxvsYmLYm+UaKsMjB7hks+pFWWIo0G2CX7uT3hU8sXjDuI5WA8WdcvlKvjQQ X-Received: by 2002:a65:62d5:: with SMTP id m21mr16696311pgv.124.1635208378355; Mon, 25 Oct 2021 17:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635208378; cv=none; d=google.com; s=arc-20160816; b=ErAFVbH2fp/HF8uMmcpoM0iTVAGXjUvSMe55M0QxRxOhrRL1JsJUVHaC1ScvbtAJD0 AZ8kJSu+gj6VWQS3Uw/okPqibJzWSFvH6tAkRdbliQ/kyoh7JYJOngplyTY+SvbbqGIw zif8Pxx1fV4OMGX0zUBxKQxv9u+5sBOdaBGS9Q/sr/F+7SBMKEnDfl+6enbENL1RxEf8 sbzN4mCbhnFu9CtU6wkQDjTx1nooviHax4jTXQkgOPIVSvJQJCip0UOIivq7WakEXiOk RQAtmKt0RGdkNtMqfAx/mTFtCZEn5ZALcRqfBYgVuY8dDJDEOL/mIzxedb6dMcxe8pOz ZdCQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IA9bjJFVV0bXYSShtODY5Z9yI2l9xu/n6h//NJoevwg=; b=yMnBeLGNQ8jJ/ZfMWq8KLWc3bDe+48jfqVcIiygJdltyH42ry9dQTpjnl8HgcCkBpo 4ABts1xa6A7MBwFOPKTH9LUIUlLEt+Qc5VHYK9wSNkyBP8P2ntUGK3yIuU8Vwa2cGgCT e8L0UpNDIVLYIJVm6D6fCOfLhW5WO/EsQWkSfi68C72UGEtLPny9gBAZ/z09qoolKGkk U79e7Ou/+LlsCD4XMRTlZj6idGeozlNVnyoFYTrAtGvBc6olIoh+AnFlGXuAUfano4v8 e+Fz55oa1cFOcZeJAmxQkvRbEfnMTu9khOqK/ywt3oXvv1Hsg2fZ97b/PE1m9pOxi/Ws Y0QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CxWau5a4; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h17si20478477plf.222.2021.10.25.17.32.46; Mon, 25 Oct 2021 17:32:58 -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=@linuxfoundation.org header.s=korg header.b=CxWau5a4; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236497AbhJYTzs (ORCPT + 99 others); Mon, 25 Oct 2021 15:55:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:38050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238656AbhJYTu7 (ORCPT ); Mon, 25 Oct 2021 15:50:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D998860F9B; Mon, 25 Oct 2021 19:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635190962; bh=Y732O1lxj+halw2WJiGRr2uq8g81Vo5/Ubj/Be0jxpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CxWau5a4EMm0p0M21BJGWx/wLBDVdTkq4wyk8dEB1jM35O2z9zoxWjASqZmTbxxMG g9gpmcteh/Z00iP6PqVMGl6i0xOfA4+0a6MeNQzilYn20iaVkHRvsVKjEGWPOQitaY m+d4E/eaa1GpmC0HGUzu9eoteBzQ/IC86cAO3a/8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Levitsky , Paolo Bonzini Subject: [PATCH 5.14 112/169] KVM: x86: leave vcpu->arch.pio.count alone in emulator_pio_in_out Date: Mon, 25 Oct 2021 21:14:53 +0200 Message-Id: <20211025191032.208466232@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025191017.756020307@linuxfoundation.org> References: <20211025191017.756020307@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini commit 0d33b1baeb6ca7165d5ed4fdd1a8f969985e35b9 upstream. Currently emulator_pio_in clears vcpu->arch.pio.count twice if emulator_pio_in_out performs kernel PIO. Move the clear into emulator_pio_out where it is actually necessary. No functional change intended. Cc: stable@vger.kernel.org Fixes: 7ed9abfe8e9f ("KVM: SVM: Support string IO operations for an SEV-ES guest") Reviewed-by: Maxim Levitsky Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6915,10 +6915,8 @@ static int emulator_pio_in_out(struct kv vcpu->arch.pio.count = count; vcpu->arch.pio.size = size; - if (!kernel_pio(vcpu, vcpu->arch.pio_data)) { - vcpu->arch.pio.count = 0; + if (!kernel_pio(vcpu, vcpu->arch.pio_data)) return 1; - } vcpu->run->exit_reason = KVM_EXIT_IO; vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT; @@ -6964,9 +6962,16 @@ static int emulator_pio_out(struct kvm_v unsigned short port, const void *val, unsigned int count) { + int ret; + memcpy(vcpu->arch.pio_data, val, size * count); trace_kvm_pio(KVM_PIO_OUT, port, size, count, vcpu->arch.pio_data); - return emulator_pio_in_out(vcpu, size, port, (void *)val, count, false); + ret = emulator_pio_in_out(vcpu, size, port, (void *)val, count, false); + if (ret) + vcpu->arch.pio.count = 0; + + return ret; + } static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,