From patchwork Thu Oct 5 14:38:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp431010vqb; Thu, 5 Oct 2023 09:51:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXW/xEU0d7AR6JbWJl9ykfb+GUIBU/vN0BUboO2PqYQdxZqsCtz4DTI7/05qTLUDjl6VOa X-Received: by 2002:a17:902:a40f:b0:1c8:7800:a241 with SMTP id p15-20020a170902a40f00b001c87800a241mr4533087plq.0.1696524702521; Thu, 05 Oct 2023 09:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696524702; cv=none; d=google.com; s=arc-20160816; b=QraktFTxdi9MykI62X12j2HR4odXSVT/GdhAEF7eKLR/fV1hrXIzcU4+wIGytVxNTg 4AzoV+EA5MOL6X3GybQXq0WHuIVIOXDUmxlW8JbFIfbU8JejVt9nuAy+0AisEm1H10rZ qwWZfY+ejaTOZfEgpKRwGH0na31oJYx3TR7g65EvZzwnSubzWYibHybxNCNsc1dFvOTB HHRAsrX23OXHs5hGpZlKJIr0vFaLJlP8p4TZxzcZfZjzDKGOy43SdD/+l+RS2zKKIGrh f3B5MDi685EYEB7aj/r6XKJpg44mJlcssRARPdDzCb6LTITKx1s26Zg8Zn/otdBIutTa +ySg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7fRALsU5S6eLAjk1M7NePd5tc1bB04QjkR7XwRkL9gc=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=oMoBoropJjC2Slk5j7naMMabeQpcq5xUs3bAoVoEfFE6Of8gbUUqQc4gHF/9vV0Okn f/QnB3XID/x4TWxSyBg0IpYsYTsZst16/jgXzl6UzH4WKbd7TJH2+eC6A8dR/i04tR9D i+ty/bub/yfok725R+bBEwgh50kpGU5/b92JolepSx7iVzSwkSUOc44EnuOnZ51SCCWS zE8H6sNJ2NhDGrjRZvCRY9bYKSOwjkNvh6YRhAv8XWLPqXpHrjI6hyUJhfjPcemcahqU Bvx1WsVfYVrW+gZiAStYLY8Yf6prV0i/9JIjJVR5oxcpzVPncE2YDKX6nRKD8rEIERU+ 8blw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E91tY47N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id kr7-20020a170903080700b001c6189eaadesi1732763plb.132.2023.10.05.09.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E91tY47N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A164C80725CC; Thu, 5 Oct 2023 09:49:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbjJEQol (ORCPT + 18 others); Thu, 5 Oct 2023 12:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233281AbjJEQm0 (ORCPT ); Thu, 5 Oct 2023 12:42:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C4427562 for ; Thu, 5 Oct 2023 07:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516737; 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: in-reply-to:in-reply-to:references:references; bh=7fRALsU5S6eLAjk1M7NePd5tc1bB04QjkR7XwRkL9gc=; b=E91tY47NOVMJdqNsm8ogzd8Uek1wQGBp3G+xbczcH8Nv/7gocaY0hgEWpifWqbOvt8VNVI MTZvO1MN0cjk4uIBmaHJmxoijgjZfRbpSeEOD4WNtGDvPLJurqJEyQM1QUoI/Imk9Bm1ac pbZ4o3zc4/uYjUzWY4y83oMI/HGnpe8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-104-N2YAPGxPOrWyAqCYBD00Ag-1; Thu, 05 Oct 2023 10:38:44 -0400 X-MC-Unique: N2YAPGxPOrWyAqCYBD00Ag-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C227C8115DC; Thu, 5 Oct 2023 14:38:43 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 936C040C6EA8; Thu, 5 Oct 2023 14:38:42 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 1/7] KVM: selftests: x86: sync_regs_test: Use vcpu_run() where appropriate Date: Thu, 5 Oct 2023 16:38:33 +0200 Message-ID: <20231005143839.365297-2-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 05 Oct 2023 09:49:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778935086510900842 X-GMAIL-MSGID: 1778935086510900842 In the spots where we are expecting a successful run, we should use vcpu_run() instead of _vcpu_run() to make sure that the run did not fail. Suggested-by: Sean Christopherson Signed-off-by: Thomas Huth --- tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c index 00965ba33f730..8c3898cf79b31 100644 --- a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c +++ b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c @@ -259,7 +259,7 @@ int main(int argc, char *argv[]) /* Request and verify all valid register sets. */ /* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */ run->kvm_valid_regs = TEST_SYNC_FIELDS; - rv = _vcpu_run(vcpu); + vcpu_run(vcpu); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); vcpu_regs_get(vcpu, ®s); @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) run->kvm_valid_regs = TEST_SYNC_FIELDS; run->kvm_dirty_regs = KVM_SYNC_X86_REGS | KVM_SYNC_X86_SREGS; - rv = _vcpu_run(vcpu); + vcpu_run(vcpu); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); TEST_ASSERT(run->s.regs.regs.rbx == 0xBAD1DEA + 1, "rbx sync regs value incorrect 0x%llx.", @@ -302,7 +302,7 @@ int main(int argc, char *argv[]) run->kvm_valid_regs = TEST_SYNC_FIELDS; run->kvm_dirty_regs = 0; run->s.regs.regs.rbx = 0xDEADBEEF; - rv = _vcpu_run(vcpu); + vcpu_run(vcpu); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); TEST_ASSERT(run->s.regs.regs.rbx != 0xDEADBEEF, "rbx sync regs value incorrect 0x%llx.", @@ -317,7 +317,7 @@ int main(int argc, char *argv[]) run->s.regs.regs.rbx = 0xAAAA; regs.rbx = 0xBAC0; vcpu_regs_set(vcpu, ®s); - rv = _vcpu_run(vcpu); + vcpu_run(vcpu); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); TEST_ASSERT(run->s.regs.regs.rbx == 0xAAAA, "rbx sync regs value incorrect 0x%llx.", @@ -334,7 +334,7 @@ int main(int argc, char *argv[]) run->kvm_valid_regs = 0; run->kvm_dirty_regs = TEST_SYNC_FIELDS; run->s.regs.regs.rbx = 0xBBBB; - rv = _vcpu_run(vcpu); + vcpu_run(vcpu); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); TEST_ASSERT(run->s.regs.regs.rbx == 0xBBBB, "rbx sync regs value incorrect 0x%llx.", From patchwork Thu Oct 5 14:38:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp355630vqb; Thu, 5 Oct 2023 07:59:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFT96s968ef83HYIpduTNny9IfvV8W+KaIrCiWIwRDpG62q00waPxF1sPaekW2fQx0I81fI X-Received: by 2002:a05:6a21:33a6:b0:15d:1646:285a with SMTP id yy38-20020a056a2133a600b0015d1646285amr4230744pzb.21.1696517986405; Thu, 05 Oct 2023 07:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517986; cv=none; d=google.com; s=arc-20160816; b=0jcqtMrHO6TWL1IQ3rOZeEY7x56IrUP8CM/iaZnF129Hwmizgcr7qZTqaKiZ2Sx+px 6ed8k3hntdWp2TNL8i8Bo2HvBzfpkY5otUklnmBriLZQwLnIY/KPWpeVJXrAiR8cFTZo AjEBftrYzuMh0/FM4EZb16hZ/Ofyg12DY3FX/WAVxYKNZVARaFYRhoaX2LhF3TjHs3Ro 5wHhi+J5CVnWCPU2lKoSSE5kZ5R55gyIfgFx7+8KxcehO0aXROSz6yj3lbwuCoy1SehO TG74dfDao0JW/E3+VUUgVdhoQKp7mUfduM84ca8hNKmhgqnAyBdrd70m9H7u2ZIWtNBL CrfQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nomghUslg4Iyvv3Vz3Tvghec7CwG436Cn/tuDQA6cKI=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=Bq4PCRNWwS235SSsLgSpa7hR1saIMOOIel3NOwZqZ15sYIPdZlYddwvB0XU/GqrJYC oK5rV6F2si8f8WnmYjVsLBXQFAXfBPY8sJhqdb2Q3J3KEEuRlHVI1YShFyLTZXuWaZEA wgpKNHZHBp8EZnoK8K6nAK3gBpmMf0Xau4pnI74/u8DEkNdPOrcBNwd3W+YfiqEQZvnx bQJD+U7GlwPaLVcrkZu/lIZ/+dkyu8g1wd1DtMvz3qw2X+ja84EVCcD0X6BLivFhJcUC NvoaeArLAahmIpk9gJneZa2oNKK4uWdLY8BP+npvdmNSaftAZ03L1J9ymEKz1biQtcB9 Q5QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HZwwKisX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x69-20020a638648000000b005859cea158fsi1519088pgd.207.2023.10.05.07.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:59:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HZwwKisX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4E6D682F7FA5; Thu, 5 Oct 2023 07:59:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233254AbjJEO7M (ORCPT + 19 others); Thu, 5 Oct 2023 10:59:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234447AbjJEO5R (ORCPT ); Thu, 5 Oct 2023 10:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9CD526A50 for ; Thu, 5 Oct 2023 07:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516730; 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: in-reply-to:in-reply-to:references:references; bh=nomghUslg4Iyvv3Vz3Tvghec7CwG436Cn/tuDQA6cKI=; b=HZwwKisXAC+1aIuCVL9x1pKH9nEt/2D9zU/jedY4B6Fw2EOqtqwHr7ezdZaimmlddJRNzo VmQAEellGV3yAHFot6gc8nwM1eOxXtlU8RLxFg7j6pRXD7Y+8nnW8GOASjRiJMMM21TAYx 52QnZmKJt6zgH132JPg9iEStWBX2rdo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-199-_87W7J7TNkGAVM6VMBmiFw-1; Thu, 05 Oct 2023 10:38:46 -0400 X-MC-Unique: _87W7J7TNkGAVM6VMBmiFw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45FF118172C2; Thu, 5 Oct 2023 14:38:45 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13F8540C6EA8; Thu, 5 Oct 2023 14:38:43 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 2/7] KVM: selftests: x86: sync_regs_test: Get regs structure before modifying it Date: Thu, 5 Oct 2023 16:38:34 +0200 Message-ID: <20231005143839.365297-3-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:59:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778928044053300263 X-GMAIL-MSGID: 1778928044053300263 The regs structure just accidentially contains the right values from the previous test in the spot where we want to change rbx. It's cleaner if we properly initialize the structure here before using it. Suggested-by: Sean Christopherson Signed-off-by: Thomas Huth --- tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c index 8c3898cf79b31..1cd19dfa0046c 100644 --- a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c +++ b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c @@ -315,6 +315,7 @@ int main(int argc, char *argv[]) run->kvm_valid_regs = 0; run->kvm_dirty_regs = 0; run->s.regs.regs.rbx = 0xAAAA; + vcpu_regs_get(vcpu, ®s); regs.rbx = 0xBAC0; vcpu_regs_set(vcpu, ®s); vcpu_run(vcpu); From patchwork Thu Oct 5 14:38:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp354973vqb; Thu, 5 Oct 2023 07:58:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEp3DPBFNuZa2bVcOJUt0DgoHAoqUTSZlmq5IEL5v0mlJ5KwEQXC/3jUzP/NrRgAt3qzYxk X-Received: by 2002:a9d:6d0d:0:b0:6c4:6aef:cd58 with SMTP id o13-20020a9d6d0d000000b006c46aefcd58mr5279967otp.8.1696517902328; Thu, 05 Oct 2023 07:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517902; cv=none; d=google.com; s=arc-20160816; b=b3rZMb90qe2zQDdEqMLYeeB3aGkyidG6TCQBuhyQwGDY8EOxxzBKe1NdSSKd4cakLb EvyNXLoTFJ89JYIQYpxb0DHZjm3uf38jqwAFVLLVd2A87IMrw0evJhEzVnqFvopAREF2 PTs3+JiFmQ496941uD0BeFeAlicu7S/9YS/J6Q1V6BiWL/sICyz2/LZkvqOohnlFIAxF 68mc9m0kruJVmJKIH1G36WBFnTsZ0D3CqREz0AlPUaFBOZd28a79DFJJjOSs4ImyE8+P R2WhbjPFBm2GQmAX7vwYwSeRXok0JJWPOivrpZd54Rnd/iEbVvZU5nNaSDa08bx+guhC UXCw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vazohg9FZ6E9GP8kzgkpGCob+IwdhO7BJaWstWzvEzQ=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=BIjy3QtsYg6en+6dNM1yIYpFmW42jSxfMyJ4bfwrlu9wvVBhkqqzqSWHQIiEqAQIVL QWRuzLYqVOFWxcr1SN9je9xHKXTCQN6bEJsB6/WH4p3P4aHh6Al2c3y3pJLwFaYppSSF +pr7P4JSyZr75Wz9Ah2hhxoumxhM7OT37lZ7LJQzDpV9icmsiALHhshoxpF/sGv3dFzX xSCTvB1FepkxJ8ye56gxWwhv+z2YzgQdG2beP8Sw+8ZyarVhFJBEoq2o2EMPInt2XGUn hkQPCxVO1N5UytzalCDK/1bpkEZNwyuBDaC8vesgATfvw+Wym/CHIsnxo+QsbE806LRq hSFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/twEhDr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id i63-20020a638742000000b00574035fd472si1587193pge.31.2023.10.05.07.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/twEhDr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 98F3F869EAE6; Thu, 5 Oct 2023 07:58:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234296AbjJEO46 (ORCPT + 19 others); Thu, 5 Oct 2023 10:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237459AbjJEOz2 (ORCPT ); Thu, 5 Oct 2023 10:55:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8805D26A4D for ; Thu, 5 Oct 2023 07:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516729; 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: in-reply-to:in-reply-to:references:references; bh=vazohg9FZ6E9GP8kzgkpGCob+IwdhO7BJaWstWzvEzQ=; b=S/twEhDraY8Vsn5CJJfUD7aYTGADaVG2MyFDXe7gNRSOYyXSQSQkjGuUQjUWoT5pB4j6ts +BhjBOonoSxb5icaZUr5pY+mn2z+IxcP+WvsIsyD6AlrhLpAT0JqJoFRLP8eKjsYoKXtZz eiBxYMDBlkvXWeRS3+BnDCnN7AWOO2Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-RutCxQ4vM7W0K_V5cIuMSw-1; Thu, 05 Oct 2023 10:38:47 -0400 X-MC-Unique: RutCxQ4vM7W0K_V5cIuMSw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFF9C3C1E9D7; Thu, 5 Oct 2023 14:38:46 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BA0A40C6EA8; Thu, 5 Oct 2023 14:38:45 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 3/7] KVM: selftests: Add a macro to define a test with one vcpu Date: Thu, 5 Oct 2023 16:38:35 +0200 Message-ID: <20231005143839.365297-4-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:58:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778927955832455200 X-GMAIL-MSGID: 1778927955832455200 Most tests are currently not giving any proper output for the user to see how much sub-tests have already been run, or whether new sub-tests are part of a binary or not. So it would be good to support TAP output in the KVM selftests. There is already a nice framework for this in the kselftest_harness.h header which we can use. But since we also need a vcpu in most KVM selftests, it also makes sense to introduce our own wrapper around this which takes care of creating a VM with one vcpu, so we don't have to repeat this boilerplate in each and every test. Thus let's introduce a KVM_ONE_VCPU_TEST() macro here which takes care of this. Suggested-by: Sean Christopherson Link: https://lore.kernel.org/all/Y2v+B3xxYKJSM%2FfH@google.com/ Signed-off-by: Thomas Huth --- .../selftests/kvm/include/kvm_test_harness.h | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/kvm_test_harness.h diff --git a/tools/testing/selftests/kvm/include/kvm_test_harness.h b/tools/testing/selftests/kvm/include/kvm_test_harness.h new file mode 100644 index 0000000000000..04cfc44e3b506 --- /dev/null +++ b/tools/testing/selftests/kvm/include/kvm_test_harness.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Macros for defining a KVM test + * + * Copyright (C) 2022, Google LLC. + */ + +#ifndef SELFTEST_KVM_TEST_HARNESS_H +#define SELFTEST_KVM_TEST_HARNESS_H + +#include "kselftest_harness.h" + +#define KVM_ONE_VCPU_TEST_SUITE(name, guest_code) \ + FIXTURE(name) { \ + struct kvm_vcpu *vcpu; \ + }; \ + \ + FIXTURE_SETUP(name) { \ + (void)vm_create_with_one_vcpu(&self->vcpu, guest_code); \ + } \ + \ + FIXTURE_TEARDOWN(name) { \ + kvm_vm_free(self->vcpu->vm); \ + } + +#define KVM_ONE_VCPU_TEST(suite, test) \ +static void __suite##_##test(struct kvm_vcpu *vcpu); \ + \ +TEST_F(suite, test) \ +{ \ + __suite##_##test(self->vcpu); \ +} \ +static void __suite##_##test(struct kvm_vcpu *vcpu) + +#endif /* SELFTEST_KVM_TEST_HARNESS_H */ From patchwork Thu Oct 5 14:38:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148796 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp355602vqb; Thu, 5 Oct 2023 07:59:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWuPYYytCxwap/sk5AlyA6MXxxTDI5qAv9MNOhfpyYQ1fDyUWBlNXy4XOK4fdynjDYSbrd X-Received: by 2002:a05:6a00:2d8d:b0:68e:236a:93d9 with SMTP id fb13-20020a056a002d8d00b0068e236a93d9mr6194784pfb.17.1696517981633; Thu, 05 Oct 2023 07:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517981; cv=none; d=google.com; s=arc-20160816; b=IFjFKO8MPQkt0y+OU4tc2PrvFLLJT47DvzQIOBzCpo1pNAfMysAjUV4icd7P9f3+fl KF0w3B0DWbiyvUcjg72+0uNtOiGzrWLuAji5sSUobSOb0hqG435hAAc1oBMoaCc8bhzw OxYLe7UBbh63svnbstkXZIU9Bmh5oDU8hdg49kLkVSGGH0uoJKestjVmFPBQQJC3G+6J 0SvH4YUct/o6Tz5ew5zJnFnvvtG22pulnlmnafCc5izQaZRy+ZLHMWuerGADsK8QTvDh FXZVTbkyfzDPRLRIhWr36Jpjbt6NZ9AVNRxD3K9Lcjun/srUfsabZoSLXJ+b2roEjhWL l2zg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iOPMQ+O8zkPvCQldrm25BT2cWKNHJa32wCRyAB9nIAI=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=MB+IUkv7fjQKnQ/i7Kd269TDThj2qs4O1wYEj0Bp8/0gc0ObF6BWkpJLMUyYHEK7Iy GPSxZobqkvRwqA8+VFrERw74asOoPLsxjXe69D5Un91ef7xXWRkmb51ToZ1BBJBZMo3g /fdtBZnNarOxTsG+Cs8jZC9vcf3V5z3rh4bm5Z3HTedA+NOswQ1Hl13QylRiWlpOTId/ FBJS1z7Ctj853DdI/OzRPz1LS//AHXc8xYEL2TKcs4MyqNAB8cGpZiQ1R8TGevZDbTv6 +p/CqadKtuWlQcjntXQKMUv9LlmWqIds8xiFkNw7mejwpCF9c0hyi8rnxHZP6JFinSmq SN/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RIjE7IoP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ca24-20020a056a00419800b0068c0300a3f7si1529305pfb.279.2023.10.05.07.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:59:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RIjE7IoP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 9D4A3867F1EE; Thu, 5 Oct 2023 07:59:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbjJEO7H (ORCPT + 19 others); Thu, 5 Oct 2023 10:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234460AbjJEO5R (ORCPT ); Thu, 5 Oct 2023 10:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 219D726A4F for ; Thu, 5 Oct 2023 07:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516730; 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: in-reply-to:in-reply-to:references:references; bh=iOPMQ+O8zkPvCQldrm25BT2cWKNHJa32wCRyAB9nIAI=; b=RIjE7IoPn1aIHY8ulRyfvntHpu1hAvLpGZNKkk2FdCCi9dEueCL0D8XDOgwizAstppcTpK 1AgKE6HBnqQF5cbM2gg6YSn5n24p77uYoQ9nBkwvaiyx1pRViBlYYS28yzpmbi1A6OUil/ d8DHp+BkoFOkWvRfXJfNL7g9runaaoA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-450-AwPrNZl6PJKwHq-xa8ZrlQ-1; Thu, 05 Oct 2023 10:38:48 -0400 X-MC-Unique: AwPrNZl6PJKwHq-xa8ZrlQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 464493C1E9D6; Thu, 5 Oct 2023 14:38:48 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1142A40C6EA8; Thu, 5 Oct 2023 14:38:46 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 4/7] KVM: selftests: x86: Use TAP interface in the sync_regs test Date: Thu, 5 Oct 2023 16:38:36 +0200 Message-ID: <20231005143839.365297-5-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:59:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778928039029434694 X-GMAIL-MSGID: 1778928039029434694 The sync_regs test currently does not have any output (unless one of the TEST_ASSERT statement fails), so it's hard to say for a user whether a certain new sub-test has been included in the binary or not. Let's make this a little bit more user-friendly and include some TAP output via the kselftest_harness.h / kvm_test_harness.h interface. To be able to use the interface, we have to break up the huge main() function here in more fine grained parts - then we can use the new KVM_ONE_VCPU_TEST() macro to define the individual tests. Since these are run with a separate VM now, we have also to make sure to create the expected state at the beginning of each test, so some parts grow a little bit - which should be OK considering that the individual tests are more self-contained now. Suggested-by: David Matlack Suggested-by: Sean Christopherson Signed-off-by: Thomas Huth --- .../selftests/kvm/x86_64/sync_regs_test.c | 110 +++++++++++++----- 1 file changed, 84 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c index 1cd19dfa0046c..c857244762bb2 100644 --- a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c +++ b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c @@ -17,6 +17,7 @@ #include #include +#include "kvm_test_harness.h" #include "test_util.h" #include "kvm_util.h" #include "processor.h" @@ -41,6 +42,8 @@ void guest_code(void) : "rax", "rbx"); } +KVM_ONE_VCPU_TEST_SUITE(sync_regs_test, guest_code); + static void compare_regs(struct kvm_regs *left, struct kvm_regs *right) { #define REG_COMPARE(reg) \ @@ -152,18 +155,15 @@ static noinline void *race_sregs_cr4(void *arg) return NULL; } -static void race_sync_regs(void *racer) +static void race_sync_regs(struct kvm_vcpu *vcpu, void *racer) { const time_t TIMEOUT = 2; /* seconds, roughly */ struct kvm_x86_state *state; struct kvm_translation tr; - struct kvm_vcpu *vcpu; struct kvm_run *run; - struct kvm_vm *vm; pthread_t thread; time_t t; - vm = vm_create_with_one_vcpu(&vcpu, guest_code); run = vcpu->run; run->kvm_valid_regs = KVM_SYNC_X86_SREGS; @@ -205,26 +205,12 @@ static void race_sync_regs(void *racer) TEST_ASSERT_EQ(pthread_join(thread, NULL), 0); kvm_x86_state_cleanup(state); - kvm_vm_free(vm); } -int main(int argc, char *argv[]) +KVM_ONE_VCPU_TEST(sync_regs_test, read_invalid) { - struct kvm_vcpu *vcpu; - struct kvm_vm *vm; - struct kvm_run *run; - struct kvm_regs regs; - struct kvm_sregs sregs; - struct kvm_vcpu_events events; - int rv, cap; - - cap = kvm_check_cap(KVM_CAP_SYNC_REGS); - TEST_REQUIRE((cap & TEST_SYNC_FIELDS) == TEST_SYNC_FIELDS); - TEST_REQUIRE(!(cap & INVALID_SYNC_FIELD)); - - vm = vm_create_with_one_vcpu(&vcpu, guest_code); - - run = vcpu->run; + struct kvm_run *run = vcpu->run; + int rv; /* Request reading invalid register set from VCPU. */ run->kvm_valid_regs = INVALID_SYNC_FIELD; @@ -240,6 +226,12 @@ int main(int argc, char *argv[]) "Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n", rv); run->kvm_valid_regs = 0; +} + +KVM_ONE_VCPU_TEST(sync_regs_test, set_invalid) +{ + struct kvm_run *run = vcpu->run; + int rv; /* Request setting invalid register set into VCPU. */ run->kvm_dirty_regs = INVALID_SYNC_FIELD; @@ -255,6 +247,14 @@ int main(int argc, char *argv[]) "Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n", rv); run->kvm_dirty_regs = 0; +} + +KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid) +{ + struct kvm_run *run = vcpu->run; + struct kvm_vcpu_events events; + struct kvm_sregs sregs; + struct kvm_regs regs; /* Request and verify all valid register sets. */ /* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */ @@ -270,6 +270,19 @@ int main(int argc, char *argv[]) vcpu_events_get(vcpu, &events); compare_vcpu_events(&events, &run->s.regs.events); +} + +KVM_ONE_VCPU_TEST(sync_regs_test, set_and_verify_various) +{ + struct kvm_run *run = vcpu->run; + struct kvm_vcpu_events events; + struct kvm_sregs sregs; + struct kvm_regs regs; + + /* Run once to get register set */ + run->kvm_valid_regs = TEST_SYNC_FIELDS; + vcpu_run(vcpu); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); /* Set and verify various register values. */ run->s.regs.regs.rbx = 0xBAD1DEA; @@ -295,6 +308,11 @@ int main(int argc, char *argv[]) vcpu_events_get(vcpu, &events); compare_vcpu_events(&events, &run->s.regs.events); +} + +KVM_ONE_VCPU_TEST(sync_regs_test, clear_kvm_dirty_regs_bits) +{ + struct kvm_run *run = vcpu->run; /* Clear kvm_dirty_regs bits, verify new s.regs values are * overwritten with existing guest values. @@ -307,6 +325,17 @@ int main(int argc, char *argv[]) TEST_ASSERT(run->s.regs.regs.rbx != 0xDEADBEEF, "rbx sync regs value incorrect 0x%llx.", run->s.regs.regs.rbx); +} + +KVM_ONE_VCPU_TEST(sync_regs_test, clear_kvm_valid_and_dirty_regs) +{ + struct kvm_run *run = vcpu->run; + struct kvm_regs regs; + + /* Run once to get register set */ + run->kvm_valid_regs = TEST_SYNC_FIELDS; + vcpu_run(vcpu); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); /* Clear kvm_valid_regs bits and kvm_dirty_bits. * Verify s.regs values are not overwritten with existing guest values @@ -327,6 +356,17 @@ int main(int argc, char *argv[]) TEST_ASSERT(regs.rbx == 0xBAC0 + 1, "rbx guest value incorrect 0x%llx.", regs.rbx); +} + +KVM_ONE_VCPU_TEST(sync_regs_test, clear_kvm_valid_regs_bits) +{ + struct kvm_run *run = vcpu->run; + struct kvm_regs regs; + + /* Run once to get register set */ + run->kvm_valid_regs = TEST_SYNC_FIELDS; + vcpu_run(vcpu); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); /* Clear kvm_valid_regs bits. Verify s.regs values are not overwritten * with existing guest values but that guest values are overwritten @@ -344,12 +384,30 @@ int main(int argc, char *argv[]) TEST_ASSERT(regs.rbx == 0xBBBB + 1, "rbx guest value incorrect 0x%llx.", regs.rbx); +} + +KVM_ONE_VCPU_TEST(sync_regs_test, race_cr4) +{ + race_sync_regs(vcpu, race_sregs_cr4); +} + +KVM_ONE_VCPU_TEST(sync_regs_test, race_exc) +{ + race_sync_regs(vcpu, race_events_exc); +} - kvm_vm_free(vm); +KVM_ONE_VCPU_TEST(sync_regs_test, race_inj_pen) +{ + race_sync_regs(vcpu, race_events_inj_pen); +} + +int main(int argc, char *argv[]) +{ + int cap; - race_sync_regs(race_sregs_cr4); - race_sync_regs(race_events_exc); - race_sync_regs(race_events_inj_pen); + cap = kvm_check_cap(KVM_CAP_SYNC_REGS); + TEST_REQUIRE((cap & TEST_SYNC_FIELDS) == TEST_SYNC_FIELDS); + TEST_REQUIRE(!(cap & INVALID_SYNC_FIELD)); - return 0; + return test_harness_run(argc, argv); } From patchwork Thu Oct 5 14:38:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp354984vqb; Thu, 5 Oct 2023 07:58:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJQ1eFUoSSrpyztc31PABt8TP2/PVqE123/1/J/EzTY7rjChCBHPdNOyXYrQRE3pTlYBmj X-Received: by 2002:a17:902:e5c7:b0:1c6:ec8:4c67 with SMTP id u7-20020a170902e5c700b001c60ec84c67mr5735416plf.18.1696517903521; Thu, 05 Oct 2023 07:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517903; cv=none; d=google.com; s=arc-20160816; b=J14FbNASv6EJYDSALUXqMwNssXOYvNSygN/Ttab1IoQ/MiNj2IVoWydMrvXri2sPE9 uGe+azwvzYhWyOna7/anv67tMZeP0ruzFwz1vNdTE6a2HD5Y+yOMXHdk3wXyXPa18Ils y4dbUqwjrZG9lC4GgJQSqp0dJqgZcJjWbyNovFRXlt1psk/ByfJ0Yt2cSJTzNXoON30t Kj1yglE6XOD5Y8/EuDC3yKvMmcVD3vHQzzJocpvW9slIRLMQw92JTtomUF6h9Q0wN4tE tF1lBRyeradPd/cYxHPQCcT8FHbbsMQzwpEI7oN4z3VlpHLIMHpEdiuba6oqz/5d/QHu YdBg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0ftZTUSszjDaBYMwepJocwkUW/juZNz/Q5LGCufgOFs=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=u6f5L5dmodxxJYDO/O6Dart+iiUhrxgzfAquGJWabdi5S/a4bh+F133AcNZML8XLyF qjcwtYt84njxc80z7uv7kJDj2jrpxGZq3LXK3OkCsUCnPCU2hFabFpFZ7Fs3gkLwgtGE PmR7/hZFtFNrtkNPr3x11zkgJ4bwxgupUM25Jn78nT7BIMOxfLsgWiOMf2TA9OkvK8IZ KwRTv/HhOhxVJfNPTyU2cMAw20sj9VgYmVAnVnu7EiOdIYMEPs4ERxawuoedkpet1Lgr i+c65Hj7xqix1iRCZ2IgpXfRAghkyVxt8hH82Cb7+A9FHonaOYnCms4UyMlnwNHe5+px E9vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SnBYr1fN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z13-20020a170903018d00b001c746b986e8si1632864plg.461.2023.10.05.07.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:58:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SnBYr1fN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E6F75867FEB8; Thu, 5 Oct 2023 07:58:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234336AbjJEO5D (ORCPT + 19 others); Thu, 5 Oct 2023 10:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237666AbjJEOzg (ORCPT ); Thu, 5 Oct 2023 10:55:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79D7826A74 for ; Thu, 5 Oct 2023 07:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516732; 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: in-reply-to:in-reply-to:references:references; bh=0ftZTUSszjDaBYMwepJocwkUW/juZNz/Q5LGCufgOFs=; b=SnBYr1fN+gmtbBOEPqNRfvkw3U87jMSZTS60h1T55lDcILw9Fux3LQr4RX//jyrSEcBHuH f0LsqWuPKhtfcOdr1viKUgGmOY43ahestB3E7ezzrgIu6NIihydrnVdhD/X58VWSB2eSXF iWh/LBLhd/J8lh0PVlGPFIfVq1dQq/Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-627-HpW_D5Y1Peequ5SsnYIDUA-1; Thu, 05 Oct 2023 10:38:50 -0400 X-MC-Unique: HpW_D5Y1Peequ5SsnYIDUA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C216981D795; Thu, 5 Oct 2023 14:38:49 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DC9340C6EA8; Thu, 5 Oct 2023 14:38:48 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 5/7] KVM: selftests: x86: Use TAP interface in the fix_hypercall test Date: Thu, 5 Oct 2023 16:38:37 +0200 Message-ID: <20231005143839.365297-6-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:58:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778927957338053285 X-GMAIL-MSGID: 1778927957338053285 Use the kvm_test_harness.h interface in this test to get TAP output, so that it is easier for the user to see what the test is doing. Signed-off-by: Thomas Huth --- .../selftests/kvm/x86_64/fix_hypercall_test.c | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c index 0f728f05ea82f..59c389aff3961 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -9,6 +9,7 @@ #include #include +#include "kvm_test_harness.h" #include "apic.h" #include "test_util.h" #include "kvm_util.h" @@ -83,6 +84,8 @@ static void guest_main(void) GUEST_DONE(); } +KVM_ONE_VCPU_TEST_SUITE(fix_hypercall, guest_main); + static void enter_guest(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; @@ -103,14 +106,11 @@ static void enter_guest(struct kvm_vcpu *vcpu) } } -static void test_fix_hypercall(bool disable_quirk) +static void test_fix_hypercall(struct kvm_vcpu *vcpu, bool disable_quirk) { - struct kvm_vcpu *vcpu; - struct kvm_vm *vm; - - vm = vm_create_with_one_vcpu(&vcpu, guest_main); + struct kvm_vm *vm = vcpu->vm; - vm_init_descriptor_tables(vcpu->vm); + vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler); @@ -126,10 +126,19 @@ static void test_fix_hypercall(bool disable_quirk) enter_guest(vcpu); } -int main(void) +KVM_ONE_VCPU_TEST(fix_hypercall, enable_quirk) +{ + test_fix_hypercall(vcpu, false); +} + +KVM_ONE_VCPU_TEST(fix_hypercall, disable_quirk) +{ + test_fix_hypercall(vcpu, true); +} + +int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_check_cap(KVM_CAP_DISABLE_QUIRKS2) & KVM_X86_QUIRK_FIX_HYPERCALL_INSN); - test_fix_hypercall(false); - test_fix_hypercall(true); + return test_harness_run(argc, argv); } From patchwork Thu Oct 5 14:38:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp357219vqb; Thu, 5 Oct 2023 08:01:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEctbc1sTiZsjnESc5XQs/hMBznt9MUPrr1o7oo0EQtkBGSIHyptzzAtGgCSF6Dj9mJR8V X-Received: by 2002:a05:6358:5e12:b0:139:d5b9:87d3 with SMTP id q18-20020a0563585e1200b00139d5b987d3mr3986416rwn.5.1696518091878; Thu, 05 Oct 2023 08:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696518091; cv=none; d=google.com; s=arc-20160816; b=g4mOFn4qSku3oDd1oF44x09z7cjuk8b4to1t5K/Xn7T+tWRnZWuvwvjCSf/4X+V2fD 6wFNmlJ8Pqg0GvxYsN3xiwkWewu4m1dJVFI/g8JfI7qu1w8jRW1wg4d4MNriRvHuAXdO JXEKUSQmRZAg2uAyu2j08zhWUM/1xYQ+quPVn+Z5fXqUklWsba9SmyMSuCgGk8wut8rx rAvnZSTsBuWr5hsYIFMhXSvsGxqH84qb7n+rMY3MNIdDI6ZttL7nSAcSZmxXaLD3gRFw Eg8xwfHhp6xgtRNTZQcua4GCKSUFJnUqylojyYxdVbbmKARzN9nul1/MWaK2xWoyUoCh /O2g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/LY4axRS36d7oYClxVQXChDpT6oDS0570aCeAUiKUZ8=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=KZfBlc5o43Vksqc2phDuj/aHoeFkOGDduJNorNfttx9WNaJ9hG+tVXDyo0G8rgvh78 WOmnYUljtx4QOgBANxAQX/be1pJcfVeiIPM0KSb0ls6DZdaLWJrpllnNWuZso1pR+HWL hH5txfeTDGKtb8SV1LdLzSPmUtciRZ2s7RMNTd3aJ65bY7sv0uxG4dBF13i4NscrpVTk udXFfMDBZIWSn2IWRabJhdTWTqDWMW3e0O2Xm/0R3CR7A4DY0qwQEwfPIZLB1Nk6pZyc 9NMnlz0nLRWbJ0XLsRsHgTlOPHM+CvHVwiFtzlA2okO0gESSw21QhGyL4Jps2S8GLn3n yFoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PxCcHebh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x34-20020a634a22000000b005694492c259si1529774pga.282.2023.10.05.08.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 08:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PxCcHebh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4752880D0816; Thu, 5 Oct 2023 08:01:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232840AbjJEPAm (ORCPT + 19 others); Thu, 5 Oct 2023 11:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbjJEO7G (ORCPT ); Thu, 5 Oct 2023 10:59:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A7311FCB for ; Thu, 5 Oct 2023 07:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516746; 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: in-reply-to:in-reply-to:references:references; bh=/LY4axRS36d7oYClxVQXChDpT6oDS0570aCeAUiKUZ8=; b=PxCcHebhqWpTtTwuKUGRgswtCwUxbjJF7XPe1upIFzXT+SbNtzPo095q7dSs3/cG+z3CXX V5o6cq180LQw7DJi7rN5aynXVQZoYqpCfRiNS+VS6CZU1EBQWk4E98dWtVtR+pZubO0+Bf eji483gqI71feZLh/bph7uGFcvAJG8E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-YzPl-BixNdaHuF1X2AM5yA-1; Thu, 05 Oct 2023 10:38:51 -0400 X-MC-Unique: YzPl-BixNdaHuF1X2AM5yA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D36C803498; Thu, 5 Oct 2023 14:38:51 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11C0A40C6EA8; Thu, 5 Oct 2023 14:38:49 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 6/7] KVM: selftests: x86: Use TAP interface in the vmx_pmu_caps test Date: Thu, 5 Oct 2023 16:38:38 +0200 Message-ID: <20231005143839.365297-7-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 05 Oct 2023 08:01:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778928155128368818 X-GMAIL-MSGID: 1778928155128368818 Use the kvm_test_harness.h interface in this test to get TAP output, so that it is easier for the user to see what the test is doing. Signed-off-by: Thomas Huth --- .../selftests/kvm/x86_64/vmx_pmu_caps_test.c | 50 ++++--------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index ebbcb0a3f7438..20c9c411de9fb 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -15,6 +15,7 @@ #include +#include "kvm_test_harness.h" #include "kvm_util.h" #include "vmx.h" @@ -32,7 +33,7 @@ union perf_capabilities { u64 anythread_deprecated:1; }; u64 capabilities; -}; +} host_cap; /* * The LBR format and most PEBS features are immutable, all other features are @@ -73,19 +74,19 @@ static void guest_code(uint64_t current_val) GUEST_DONE(); } +KVM_ONE_VCPU_TEST_SUITE(vmx_pmu_caps, guest_code); + /* * Verify that guest WRMSRs to PERF_CAPABILITIES #GP regardless of the value * written, that the guest always sees the userspace controlled value, and that * PERF_CAPABILITIES is immutable after KVM_RUN. */ -static void test_guest_wrmsr_perf_capabilities(union perf_capabilities host_cap) +KVM_ONE_VCPU_TEST(vmx_pmu_caps, guest_wrmsr_perf_capabilities) { - struct kvm_vcpu *vcpu; - struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, guest_code); struct ucall uc; int r, i; - vm_init_descriptor_tables(vm); + vm_init_descriptor_tables(vcpu->vm); vcpu_init_descriptor_tables(vcpu); vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities); @@ -117,31 +118,21 @@ static void test_guest_wrmsr_perf_capabilities(union perf_capabilities host_cap) TEST_ASSERT(!r, "Post-KVM_RUN write '0x%llx'didn't fail", host_cap.capabilities ^ BIT_ULL(i)); } - - kvm_vm_free(vm); } /* * Verify KVM allows writing PERF_CAPABILITIES with all KVM-supported features * enabled, as well as '0' (to disable all features). */ -static void test_basic_perf_capabilities(union perf_capabilities host_cap) +KVM_ONE_VCPU_TEST(vmx_pmu_caps, basic_perf_capabilities) { - struct kvm_vcpu *vcpu; - struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, NULL); - vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, 0); vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities); - - kvm_vm_free(vm); } -static void test_fungible_perf_capabilities(union perf_capabilities host_cap) +KVM_ONE_VCPU_TEST(vmx_pmu_caps, fungible_perf_capabilities) { const uint64_t fungible_caps = host_cap.capabilities & ~immutable_caps.capabilities; - - struct kvm_vcpu *vcpu; - struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, NULL); int bit; for_each_set_bit(bit, &fungible_caps, 64) { @@ -150,8 +141,6 @@ static void test_fungible_perf_capabilities(union perf_capabilities host_cap) host_cap.capabilities & ~BIT_ULL(bit)); } vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities); - - kvm_vm_free(vm); } /* @@ -160,14 +149,11 @@ static void test_fungible_perf_capabilities(union perf_capabilities host_cap) * separately as they are multi-bit values, e.g. toggling or setting a single * bit can generate a false positive without dedicated safeguards. */ -static void test_immutable_perf_capabilities(union perf_capabilities host_cap) +KVM_ONE_VCPU_TEST(vmx_pmu_caps, immutable_perf_capabilities) { const uint64_t reserved_caps = (~host_cap.capabilities | immutable_caps.capabilities) & ~format_caps.capabilities; - - struct kvm_vcpu *vcpu; - struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, NULL); union perf_capabilities val = host_cap; int r, bit; @@ -201,8 +187,6 @@ static void test_immutable_perf_capabilities(union perf_capabilities host_cap) TEST_ASSERT(!r, "Bad PEBS FMT = 0x%x didn't fail, host = 0x%x", val.pebs_format, host_cap.pebs_format); } - - kvm_vm_free(vm); } /* @@ -211,17 +195,13 @@ static void test_immutable_perf_capabilities(union perf_capabilities host_cap) * LBR_TOS as those bits are writable across all uarch implementations (arch * LBRs will need to poke a different MSR). */ -static void test_lbr_perf_capabilities(union perf_capabilities host_cap) +KVM_ONE_VCPU_TEST(vmx_pmu_caps, lbr_perf_capabilities) { - struct kvm_vcpu *vcpu; - struct kvm_vm *vm; int r; if (!host_cap.lbr_format) return; - vm = vm_create_with_one_vcpu(&vcpu, NULL); - vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities); vcpu_set_msr(vcpu, MSR_LBR_TOS, 7); @@ -229,14 +209,10 @@ static void test_lbr_perf_capabilities(union perf_capabilities host_cap) r = _vcpu_set_msr(vcpu, MSR_LBR_TOS, 7); TEST_ASSERT(!r, "Writing LBR_TOS should fail after disabling vPMU"); - - kvm_vm_free(vm); } int main(int argc, char *argv[]) { - union perf_capabilities host_cap; - TEST_REQUIRE(get_kvm_param_bool("enable_pmu")); TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM)); @@ -248,9 +224,5 @@ int main(int argc, char *argv[]) TEST_ASSERT(host_cap.full_width_write, "Full-width writes should always be supported"); - test_basic_perf_capabilities(host_cap); - test_fungible_perf_capabilities(host_cap); - test_immutable_perf_capabilities(host_cap); - test_guest_wrmsr_perf_capabilities(host_cap); - test_lbr_perf_capabilities(host_cap); + return test_harness_run(argc, argv); } From patchwork Thu Oct 5 14:38:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148794 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp355380vqb; Thu, 5 Oct 2023 07:59:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzOWqMRQB7i/dnM8E1z0sIyHAH69al3WkeYUBi+cealS52vCYMUFB+4NZ4VnE4zHbf7n3O X-Received: by 2002:a05:6e02:184f:b0:351:59db:a206 with SMTP id b15-20020a056e02184f00b0035159dba206mr6938471ilv.19.1696517950896; Thu, 05 Oct 2023 07:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517950; cv=none; d=google.com; s=arc-20160816; b=InjlYXQypAITYZwOxN/Zt6kTq3YsT4kpOBqkbUHyrtXPahalOBGJAwEh+6GHg8mB4B j4EXT1kr7iQbZR8GogZACldNE7m0b1slfKt1zWXyG5gbimmI9c66VQnCwO8LQmPCM8Fb 0oZGzPlL0GzKkkb2dImGnkzItrEL0DXU75AbSwlfpVgb/S4AVYQg6Xyd43G/Lv/plnMz gftihBpkb1k1EDT/dptFjE9Jt0NFYXGEg555W0aeQlRK+Bj2c4D2SK5q4DMj9cSs+e1d xhLlWGbbzB4+isn6uJAnvYmEo5koE4rgT15Q3+eDFt9LFzFplhEflVe1Su4eTFyRoe1u LGBQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WtdGx+OPUYNJ/AOWymXa/bx8UKj2Lj0Mpvrei971DGA=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=sVCiwNlEgeJjGY7jNJ1KMQuEU5ZabpM9YTsDUagmAVUeIyokfre3anfkTf9FpFTDK0 lyqDlGqRGa8UaYJ/qqhLK2G3UZdDUtVvMSX9rko6B+pyXx9w3rGfKTEZ0F/p7CQ+JW68 c7YU/x9fOr3ily70qqPQYXtXVI97J+7plWZmyAzwzdSQQwAE/TBY2azV5aO75Ui4zK98 xCpnskDdmS50jjsolX0VfBmd92SSncYDrlOahtOS0/C5lh8Q+443XgX17vAeWyGXGW+y 6k+0iTS1igW9uVTa+dJNvO9QGE7AgsUMwZ/3CGGjGwaSwqFqCXwRZx2LCGN2zN3gSbDe SuEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UHaFnf4g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k198-20020a636fcf000000b00578e4c1581bsi1590313pgc.866.2023.10.05.07.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:59:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UHaFnf4g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A15C582F4E37; Thu, 5 Oct 2023 07:59:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233532AbjJEO6e (ORCPT + 19 others); Thu, 5 Oct 2023 10:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbjJEO43 (ORCPT ); Thu, 5 Oct 2023 10:56:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1828B1F754 for ; Thu, 5 Oct 2023 07:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516748; 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: in-reply-to:in-reply-to:references:references; bh=WtdGx+OPUYNJ/AOWymXa/bx8UKj2Lj0Mpvrei971DGA=; b=UHaFnf4gtmkFxHvmntH2oqWA9uxij4+UvrLjBE6fn8kudCqvky4SFdOz9rNs4GA9daEWPr pEyp6jv+aFXe6mfpp3VFYoLZFZvbjPoYPssQTQkad9I8+NF7v07J4gAWvZnFIkfevI/wes Y+fp/TFggfUW9+jldSB2sspKxcBP/Ng= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-149-NqYKoLAoM822Sr1SzOzEGQ-1; Thu, 05 Oct 2023 10:38:54 -0400 X-MC-Unique: NqYKoLAoM822Sr1SzOzEGQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEA673C1E9D1; Thu, 5 Oct 2023 14:38:52 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F5C340C6EA8; Thu, 5 Oct 2023 14:38:51 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 7/7] KVM: selftests: x86: Use TAP interface in the userspace_msr_exit test Date: Thu, 5 Oct 2023 16:38:39 +0200 Message-ID: <20231005143839.365297-8-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:59:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778928006620698791 X-GMAIL-MSGID: 1778928006620698791 Use the kselftest_harness.h interface in this test to get TAP output, so that it is easier for the user to see what the test is doing. Note: We're not using the KVM_ONE_VCPU_TEST() macro here (but the generic TEST() macro from kselftest_harness.h) since each of the tests needs a different guest code function. Signed-off-by: Thomas Huth Signed-off-by: Sean Christopherson --- .../kvm/x86_64/userspace_msr_exit_test.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c index 3533dc2fbfeeb..9843528bba0c6 100644 --- a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +++ b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c @@ -8,6 +8,7 @@ #define _GNU_SOURCE /* for program_invocation_short_name */ #include +#include "kselftest_harness.h" #include "test_util.h" #include "kvm_util.h" #include "vmx.h" @@ -527,7 +528,7 @@ static void run_guest_then_process_ucall_done(struct kvm_vcpu *vcpu) process_ucall_done(vcpu); } -static void test_msr_filter_allow(void) +TEST(msr_filter_allow) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; @@ -646,7 +647,7 @@ static void handle_wrmsr(struct kvm_run *run) } } -static void test_msr_filter_deny(void) +TEST(msr_filter_deny) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; @@ -693,7 +694,7 @@ static void test_msr_filter_deny(void) kvm_vm_free(vm); } -static void test_msr_permission_bitmap(void) +TEST(msr_permission_bitmap) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; @@ -786,7 +787,7 @@ static void run_msr_filter_flag_test(struct kvm_vm *vm) } /* Test that attempts to write to the unused bits in a flag fails. */ -static void test_user_exit_msr_flags(void) +TEST(user_exit_msr_flags) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; @@ -804,13 +805,5 @@ static void test_user_exit_msr_flags(void) int main(int argc, char *argv[]) { - test_msr_filter_allow(); - - test_msr_filter_deny(); - - test_msr_permission_bitmap(); - - test_user_exit_msr_flags(); - - return 0; + return test_harness_run(argc, argv); }