From patchwork Wed Apr 25 11:54:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guo X-Patchwork-Id: 904186 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40WJmR0xGnz9rxs for ; Wed, 25 Apr 2018 22:05:11 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vZ/0m3Aj"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40WJmQ6747zF24N for ; Wed, 25 Apr 2018 22:05:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vZ/0m3Aj"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::241; helo=mail-pf0-x241.google.com; envelope-from=wei.guo.simon@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vZ/0m3Aj"; dkim-atps=neutral Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40WJXw2CNxzF24T for ; Wed, 25 Apr 2018 21:55:12 +1000 (AEST) Received: by mail-pf0-x241.google.com with SMTP id l27so15007980pfk.12 for ; Wed, 25 Apr 2018 04:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qj2Psrg5UWsP6y9MZwF7FIPDraCfoulZnJnBj/yNjxM=; b=vZ/0m3Ajrs89bNFdT+C22QRvS+tBuFRqH0mGWOqeenyrllp9dZpH2ksyEANpN0pKcf yVhli0Q1LV9z0r+5/fcM90HMf4v95K/B5TzaN0Aye1v6M7fqBbjl/lMlNr8cmwgsd1yv UXSlHKvTV/RWC2jMaC2BxHmoPMw93h/uI4se4rpsCJSowfd+QlIkqViGEgOZ93l/artU z3kj79ArudwUurejBROW2Y6+qv/i98m+J3lYXlHuqcwUkCJZvaKYbILRXD1jautykxQD l6ZnBf81CW/sk66L8N9KqAtgweZL942sxhSzx+m8IJ0JQEeYnelA1gXtJ6zxTy3e+OQz MZXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qj2Psrg5UWsP6y9MZwF7FIPDraCfoulZnJnBj/yNjxM=; b=FzzQXqbA44w6iGwQu0OFga9uxzxsOjYdOXeXebjymtybRv/7jqAwXgjqCION+GPq4L nZ0LdBy8i9pF+SHAjmZ/gFo9q6xSy3qMEbMCXG+mE64b7RF8wSVKgjEkyteazGhR9n5G DNhA01WIKpBg+JD/AtzkMm7531IehCPyael6wJ323//dFLdwxZ2kq8YaCrQeYzVuIszc oFWXTfB4WuaQs7QbsCl/qMFJDEyR77PxCliQgfkx0oIwqsLs0dtE+UnSACmW9+wvZEGd /TcOFTGB/P8JtPTjEMZnlEP0+ixzL+eHQ6z/Osk11VDOQOiv8scB6IsJf53zBhngzaAX DGWQ== X-Gm-Message-State: ALQs6tChRk+gyGcqWwtR1ixwpTaEt/C1TX6LdgkIkwPJyzqFpGXHjoXY NsV0DsasTLzVZOjCWtfCGm8= X-Google-Smtp-Source: AIpwx48NCVblw5/ySReSfD5WnC1b0bml1YcSvm5AFuJ8mSQEDOuo5hVs3tgf65otuK/J+wpKV+ve4w== X-Received: by 2002:a17:902:a50d:: with SMTP id s13-v6mr28516291plq.228.1524657309022; Wed, 25 Apr 2018 04:55:09 -0700 (PDT) Received: from simonLocalRHEL7.cn.ibm.com ([112.73.0.87]) by smtp.gmail.com with ESMTPSA id j1sm30912934pgn.69.2018.04.25.04.55.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 04:55:08 -0700 (PDT) From: wei.guo.simon@gmail.com To: kvm-ppc@vger.kernel.org Subject: [PATCH 03/11] KVM: PPC: Fix a mmio_host_swabbed uninitialized usage issue when VMX store Date: Wed, 25 Apr 2018 19:54:36 +0800 Message-Id: <1524657284-16706-4-git-send-email-wei.guo.simon@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1524657284-16706-1-git-send-email-wei.guo.simon@gmail.com> References: <1524657284-16706-1-git-send-email-wei.guo.simon@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Guo , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Simon Guo When KVM emulates VMX store, it will invoke kvmppc_get_vmx_data() to retrieve VMX reg val. kvmppc_get_vmx_data() will check mmio_host_swabbed to decide which double word of vr[] to be used. But the mmio_host_swabbed can be uninitiazed during VMX store procedure: kvmppc_emulate_loadstore \- kvmppc_handle_store128_by2x64 \- kvmppc_get_vmx_data This patch corrects this by using kvmppc_need_byteswap() to choose double word of vr[] and initialized mmio_host_swabbed to avoid invisble trouble. Signed-off-by: Simon Guo --- arch/powerpc/kvm/emulate_loadstore.c | 1 + arch/powerpc/kvm/powerpc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/emulate_loadstore.c b/arch/powerpc/kvm/emulate_loadstore.c index a382e15..b8a3aef 100644 --- a/arch/powerpc/kvm/emulate_loadstore.c +++ b/arch/powerpc/kvm/emulate_loadstore.c @@ -111,6 +111,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) vcpu->arch.mmio_sp64_extend = 0; vcpu->arch.mmio_sign_extend = 0; vcpu->arch.mmio_vmx_copy_nums = 0; + vcpu->arch.mmio_host_swabbed = 0; switch (get_op(inst)) { case 31: diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 4e38764..bef27b1 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -1374,7 +1374,7 @@ static inline int kvmppc_get_vmx_data(struct kvm_vcpu *vcpu, int rs, u64 *val) if (di > 1) return -1; - if (vcpu->arch.mmio_host_swabbed) + if (kvmppc_need_byteswap(vcpu)) di = 1 - di; w0 = vrs.u[di * 2];