Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2907245yba; Mon, 22 Apr 2019 15:27:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUvlZ+AcU2eaL2E1VT7CnRHaLNmlbiLg5Vd2JQad6FB3OPqr1NNzL7DJ1ZeBzmEga0pEmc X-Received: by 2002:a17:902:2862:: with SMTP id e89mr23158110plb.203.1555972042662; Mon, 22 Apr 2019 15:27:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555972042; cv=none; d=google.com; s=arc-20160816; b=q2XkMQh5GPRiRDdBj3CX1YMefPTuiGNw9WZzly7xjpqBBsMc0yUGWPTENE5s/uPn6+ VlZwhcLypeq3YMugEC5vy/a0HzDkzt8O72KjdyihCRVS64X4ssgNGJG7h0kiFfMaq5fE jRh18PqO7HGJkgDypqazHgAmwNvB7O1B7wFPEv2BObWmJQgCdU9XNcVyGC5NanDJgJqs wapTmL41NAui7W0DW+zDBK/kBkf3JCDkr59hL2914vCYi8HhUiNOpOkMy34dsjc5eXA8 1CJ9G/M2hYVpAPRPrMB+gpPNoE0vqVQHDyksSpm+21wcZ54JlXaFcG6wtN+EzzoMRLwA +1AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zXzGDMQOmJX8ucShspjvBwI0MVp3PiLBr8O7pTgxwwc=; b=DuIfWifYLgkocs24u/s3r+XHgMaPbGauQ2c6h7Z7FXJIJWIv7jyvhAINWUFREzfIIA r7cUX653luLBnjGBpYzJiOtwTCztgxQdxaJ9O1ELizwK1IM3dFduElcVN5zdAp6w16Cf w2CZPe6dMlyJUbvl7Z/CfSCZi/fq5DXokp51JV79wKyCdDtkY+45ulmBDI/hMCXCzoUO 0FpugMUpM/0eGeCvWin/RIpWOHFBM6jOsNEHl9+C03kogSjXarm5Xl2SGmoCdusDDun8 fIn89E/WOFrZEWSMtrB49oqOj1PbiOMhL/TSg9WvmV77Jc0hwq+qjqyEi84XUuTd2/L5 WbnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O0uGv7Qj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v21si14083193plo.34.2019.04.22.15.27.07; Mon, 22 Apr 2019 15:27:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O0uGv7Qj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729562AbfDVTon (ORCPT + 99 others); Mon, 22 Apr 2019 15:44:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:45972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728996AbfDVTom (ORCPT ); Mon, 22 Apr 2019 15:44:42 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 33880204EC; Mon, 22 Apr 2019 19:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962281; bh=92cIZLzRdJ+R1hUq9Og/ly7udWBQBq7Lxs6dI+y0rNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0uGv7QjQqzjjBO1HhIImZTImc/5wKLLnRfOgdCBk9SqUPGkcYjLmy3wGvYS32rxQ +rpG6ML2SOqWYXDgvZFguskrsijA2u8Yb/vB2tUBbG8NCUHFzdJIkpL1FGo3nMjSJU nuBoLui27G2OwNzBc1rn+lMmMQ7JRGPAFmsDAPpQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sean Christopherson , Wei Huang , Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 83/98] KVM: selftests: assert on exit reason in CR4/cpuid sync test Date: Mon, 22 Apr 2019 15:41:50 -0400 Message-Id: <20190422194205.10404-83-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson [ Upstream commit 8df98ae0ab2ead9a02228756eec26f8d7b17f499 ] ...so that the test doesn't end up in an infinite loop if it fails for whatever reason, e.g. SHUTDOWN due to gcc inserting stack canary code into ucall() and attempting to derefence a null segment. Fixes: ca359066889f7 ("kvm: selftests: add cr4_cpuid_sync_test") Cc: Wei Huang Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin (Microsoft) --- .../kvm/x86_64/cr4_cpuid_sync_test.c | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c index d503a51fad30..7c2c4d4055a8 100644 --- a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c +++ b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c @@ -87,22 +87,25 @@ int main(int argc, char *argv[]) while (1) { rc = _vcpu_run(vm, VCPU_ID); - if (run->exit_reason == KVM_EXIT_IO) { - switch (get_ucall(vm, VCPU_ID, &uc)) { - case UCALL_SYNC: - /* emulate hypervisor clearing CR4.OSXSAVE */ - vcpu_sregs_get(vm, VCPU_ID, &sregs); - sregs.cr4 &= ~X86_CR4_OSXSAVE; - vcpu_sregs_set(vm, VCPU_ID, &sregs); - break; - case UCALL_ABORT: - TEST_ASSERT(false, "Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit."); - break; - case UCALL_DONE: - goto done; - default: - TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd); - } + TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, + "Unexpected exit reason: %u (%s),\n", + run->exit_reason, + exit_reason_str(run->exit_reason)); + + switch (get_ucall(vm, VCPU_ID, &uc)) { + case UCALL_SYNC: + /* emulate hypervisor clearing CR4.OSXSAVE */ + vcpu_sregs_get(vm, VCPU_ID, &sregs); + sregs.cr4 &= ~X86_CR4_OSXSAVE; + vcpu_sregs_set(vm, VCPU_ID, &sregs); + break; + case UCALL_ABORT: + TEST_ASSERT(false, "Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit."); + break; + case UCALL_DONE: + goto done; + default: + TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd); } } -- 2.19.1