From patchwork Thu Jan 20 09:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 12718471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B42C7C433EF for ; Thu, 20 Jan 2022 09:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359550AbiATJ2j (ORCPT ); Thu, 20 Jan 2022 04:28:39 -0500 Received: from out0-156.mail.aliyun.com ([140.205.0.156]:54761 "EHLO out0-156.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359532AbiATJ2f (ORCPT ); Thu, 20 Jan 2022 04:28:35 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047204;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---.MfqJbYj_1642670913; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.MfqJbYj_1642670913) by smtp.aliyun-inc.com(127.0.0.1); Thu, 20 Jan 2022 17:28:33 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: "Hou Wenlong" , "Paolo Bonzini" Subject: [kvm-unit-tests PATCH 2/2] x86/emulator: Add some tests for ljmp instruction emulation Date: Thu, 20 Jan 2022 17:26:59 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Per Intel's SDM on the "Instruction Set Reference", when loading segment descriptor for ljmp, not-present segment check should be after all type and privilege checks. However, __load_segment_descriptor() in x86's emulator does not-present segment check first, so it would trigger #NP instead of #GP if type or privilege checks fail and the segment is not present. So add some tests for ljmp instruction, and it will test those tests in hardware and emulator. Enable kvm.force_emulation_prefix when try to test them in emulator. Signed-off-by: Hou Wenlong --- x86/emulator.c | 102 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/x86/emulator.c b/x86/emulator.c index 480333a40eba..c80e2cf8374e 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -34,6 +34,7 @@ struct fep_test_case { enum fep_test_inst_type { FEP_TEST_LRET, + FEP_TEST_LJMP, }; struct fep_test { @@ -68,6 +69,29 @@ static struct fep_test fep_test_lret = { .user_testcases_count = sizeof(lret_user_testcases) / sizeof(struct fep_test_case), }; +static struct fep_test_case ljmp_kernel_testcases[] = { + {0, DS_TYPE, 0, 0, GP_VECTOR, FIRST_SPARE_SEL, "ljmp desc.type!=code && desc.p=0"}, + {0, NON_CONFORM_CS_TYPE, 3, 0, GP_VECTOR, FIRST_SPARE_SEL, "jmp non-conforming && dpl!=cpl && desc.p=0"}, + {3, NON_CONFORM_CS_TYPE, 0, 0, GP_VECTOR, FIRST_SPARE_SEL, "ljmp conforming && rpl>cpl && desc.p=0"}, + {0, CONFORM_CS_TYPE, 3, 0, GP_VECTOR, FIRST_SPARE_SEL, "ljmp conforming && dpl>cpl && desc.p=0"}, + {0, NON_CONFORM_CS_TYPE, 0, 0, NP_VECTOR, FIRST_SPARE_SEL, "ljmp desc.p=0"}, +}; + +static struct fep_test_case ljmp_user_testcases[] = { + {3, CONFORM_CS_TYPE, 0, 1, -1, -1, "ljmp dpl