From patchwork Tue Mar 23 17:50:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 12159037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1E77C433DB for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BBB4619C5 for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232031AbhCWSjI (ORCPT ); Tue, 23 Mar 2021 14:39:08 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:44822 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbhCWSiv (ORCPT ); Tue, 23 Mar 2021 14:38:51 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIOjDH166831; Tue, 23 Mar 2021 18:38:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=oI+jRfUT8/LTeal7sxTiD5VotikYIf0caD3DMotVJEI=; b=Q/+nDaZK9aQdRBSq0Bk66zX9NLtTLCwUnoOD7Ea1aAYpxoY5FIkaBzaWTV+lm57bHsse TEI7AlinKEGKyGsjSr6Qr8yEE7HlDSFhSRGxlBhPfb/B2bcCFZ37j6UT6mgY6fqY+ZwQ L8tmd8vHxs89oUtU11W4e9nm0RXbjFaOq/SqII7EVhunqRfG/K9TxnfGgsvlp33xFl/1 yNGbfS6/NJ8dCQScSuFButNYZ4uhwhSn+KLXbE5oNmNrpDjOnKzssjffcByOGkntt8cs lpLpWYYO6gCrCIiHRWM09wjPHThmZqUsfQA7l3+rmtxyNwjaLIAxhShvGYLM5VTxzeCo rw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 37d9pn0634-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:46 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIQNs4075389; Tue, 23 Mar 2021 18:38:46 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by aserp3020.oracle.com with ESMTP id 37dtxym92t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c7t4nYJAxCjAKi7ZxmCiGCkDpYoo7/eaFQVsYqfu+mObX8fBS8Oh0iud1/wS8ImJJ+us5K3iedLOFJw7dFplZkGi0ZVek0FCTVmK97MSC8bpWgHclAOcmMp4TZx3+ku+1Q9o2gNMc4/VctdjW7eB33iUJcUszxEgXeiLx5z1bxXeOv75br1cFVw5+EbhqTy3Sk314V2vqbGdxZBVj2sCxG0OYGsSqFR+qBjkb+yXWZZu1F9YaX2rSFxJoV2+GLeoiDjcNynw5BQkxrOSp2cOe5Y6UscCv5NZ6u9Je+7kA7oa10Jw9hLEpVOMmbmSJTgjuoSjufS4x84yO7YJAMiynw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oI+jRfUT8/LTeal7sxTiD5VotikYIf0caD3DMotVJEI=; b=GfcDLA4zxOMBZ1bQPj3UxfeR0FQoV3HpZ7WfrDkQQKmckhIV9DyHjyir5ZJH0FmY3olN6ZRsZXdLqDphtoNSFViD0TcivLcU4+V2PY5CFsDyd1GmVpq9aJmh5+Z4GOFFx6l/KCPtI8oXrfLs/2VBiPeO0ru8CCu0MP+JD2yZ3We9mokIg46MbezHSTfwvxIxWMTnknAmgGLKnsQrkn+QGaEsRG6irRVVBIOJJnw8O8Ye7MDkcmlP2CC9oJ9Vz3j8Zk1KeFlb/zThWUz5UPWFyO8PTlCRnCKcfa7thZqH3fWfijMw5f++mq4U/pNnZssbeNsuSalfdXBl3/bsaHTWFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oI+jRfUT8/LTeal7sxTiD5VotikYIf0caD3DMotVJEI=; b=SrDJGs4QoPcG5H6vPQ3U+Yi7Z+XcvLkSx4jKjH0xLUAOSCm/ixV88zBb6RUzUmQF3k85x7M8U6RlurfLUTyHorInrP55/fK+2+N31OVt21JPzxVsiArB4VzVT91f+CYJ1KR9gCMcQKHFf/H/HeZHDN88xx8yhnoxua3IiHcHSTQ= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) by SA2PR10MB4508.namprd10.prod.outlook.com (2603:10b6:806:11d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 18:38:44 +0000 Received: from SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7]) by SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7%7]) with mapi id 15.20.3955.025; Tue, 23 Mar 2021 18:38:43 +0000 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com Subject: [PATCH 1/4 v5] KVM: nSVM: If VMRUN is single-stepped, queue the #DB intercept in nested_svm_vmexit() Date: Tue, 23 Mar 2021 13:50:03 -0400 Message-Id: <20210323175006.73249-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210323175006.73249-1-krish.sadhukhan@oracle.com> References: <20210323175006.73249-1-krish.sadhukhan@oracle.com> X-Originating-IP: [138.3.201.29] X-ClientProxiedBy: BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) To SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ban25x6uut29.us.oracle.com (138.3.201.29) by BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 18:38:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fdfe4f03-ebda-40cc-b982-08d8ee2ae1e2 X-MS-TrafficTypeDiagnostic: SA2PR10MB4508: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uAnlQnUXEDDWc2ezj73RGZrZlvg/ZbXjyu0KL1PAhpGpQlhzRCI/fqSGjwaNU3NvYgf2S6ATWaP1qXpEopHPphL3Zgw0NdtdoYCcasG5fzyfwkoRDizhHJnOhS+yr2bjkjtIxgVEpfSaAjObhwUooICDvTqWmVs8L+bDT7ewM8F0CkFQaODL7MgYzqTfOPKmPtHzw4IXiXHyjuNp9cmV4O+7zSWnkgZEUl3dEpLzxwzsDosOP4t0W5UyZElDiKuqnfS32X4DnvI+Y6bl0yam1ZRTxbbto7LgYFhnzJUchJAUgocv05w54rUko85H6x4ejzt6k4j8CYYFmZ3xS7BqxkJsdfFFn4U+SSmOwHgoW6ZOyukfumsDQ0GZ776qc4F2qiez6OFd2/pKIIFvl8FJF8DSQLjbn374VGbGXxkHBMY3aaDmXDQkAMrlDaF+mWWr7TAFKYc8AODrfmmI5vU+WwF7oDEkxev68FJT6+00Huw+T77QnyHKDIbeUmKvlGuykajxhKJrgJIpFyilLQUuV6KiMBgfqXCtopmbKl/AvijiZK0GVhYGJjXo8Xt18gSISfJ/otlsfZICAYeEGRyaY+5q4mgNcPGV6p3+gvjMcChLxuRiph0V0V5yCy8zE+iNnp6RmQ15UeD/lTyEOOYTWQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3021.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(39860400002)(376002)(346002)(136003)(366004)(44832011)(1076003)(16526019)(2906002)(316002)(2616005)(6486002)(5660300002)(83380400001)(38100700001)(66556008)(478600001)(66476007)(8936002)(66946007)(36756003)(6916009)(7696005)(86362001)(6666004)(8676002)(4326008)(52116002)(26005)(186003)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3o88P0C0pyrZW6SqhSfeCcvbWD3xwMGYuSacvKsX/HPVQZZMLDfWeZZ0N5cZSI3GRw3eaWIi8fS+Bapj+3e86/1EnCSwZUEqOrmUrmjWKYviitv4QzTgBc7cdheiWpaEAzIKvNSir5/pG23x9Dud1D7gvIEQloiST3fHAx183zvPTv3X8ozGUWe+JfznPULCNDRv9lsu+pUBKzkCRe2NqT7zU8TmEaZmv0vRGrS8tmFdKgRtwh+GK1/Xkgkq6IH0arxM5GTdlMemO8mktJC8L8c3XzjChl3521KaFj+MS4N7T0zkPpH2InY1bToQG1EVUXMMzgMguArHXCa8XhBU2iBP7jlndmvHy2S8o92UPECzA+OFBOBSfzSQSU6jPAiGN+zqva9O00iuCM8zk++M9ACNwyLLaOm9M0NAXCS1K6pVFMNyZonKI4Q8WltcbLSLHo+y22+jaPivM8UiG7pdO+LZN0s1t6oLM7eiF6YWK3ZzPNoGXF7ZGxLTNzWeQ8V6/qHYr1X4R8soNRGpWTXtnjBEZy5DJ43wvQCN7d/r7F1j2c9cp+iV76O6nN/+FdYTEYcgtCTPeT+5zx6WQzZofQ0SiwYBMFS5NKeMA4RyV5NL0EXV/rfhsnVivTqfGiPyQoVPVyfSKRwkVBN86bHS3ivgOgnbZSHLyHHDvqCKHxZS0BLPILGMHIgRZWR7Xhv5xmY2nB+akZnreHnuYzlxOKkL5PS9w+YhLu4p5UY7+Ju1pzUuRnr7Skb86Vmu1O6ohJakFsARPG+r+iAGR03GRcbnpinz/+hbZAHTrKWgzQOMSKS4GWDXBO7vco06AouLvi6bvcWJZi8AhMAShzUl1cXSx4W+VhJz1WuIQq4ZaRPt9IEfz06I6X8P4He1+UFwtiQlXTaVqJ5iHDBwEC0kO0Mkd885JLLVOI6u/t+runnt4aiH7szgWmzwo9/FIRn/PM7u2b5CFNVDZVmbQSD8reU5ZszSA24V8law4OvXM1tJ6ou+YRWpHWdDf3akGnPW2PupLln31K8B77iA2+xrurU9b9H4AwWRks7a2OCJ/MBrEVN85CK7wYiONwygqXscNK4HNTgQLaFuqG33LdEc8i4cTWUXPfTDK5cXV1oOp4iVp/AbLJUMTH4+nB81CjOVxTlDu1Ud9YudD6RPpCnRHb+7pCdQmUFcvux/D/SPIcK+X6TERbhl//QqxA9ZYocdUz9xWNbeQfb8jpVZk5USxyuzIcTErjlkpdKvqxmHeInO4N/4LaqKYToWfHSg3Er9SX2sb9rXd2fHMjOUQDRzQzcZToMjKGEOCI7coVKi3f3ENzm1QLRsLLYrBRiZXFsl X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fdfe4f03-ebda-40cc-b982-08d8ee2ae1e2 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3021.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 18:38:43.9602 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pIIoYDqTdx39spZRtsOOtRSUVhOTlS38c1aVpbKDB81bH/u59LeVA9ontDlO44AreJaVkIiWvMoayhc9q0VjgBnGXwBhApoC3E88Y303ZDQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4508 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org According to APM, the #DB intercept for a single-stepped VMRUN must happen after the completion of that instruction, when the guest does #VMEXIT to the host. However, in the current implementation of KVM, the #DB intercept for a single-stepped VMRUN happens after the completion of the instruction that follows the VMRUN instruction. When the #DB intercept handler is invoked, it shows the RIP of the instruction that follows VMRUN, instead of of VMRUN itself. This is an incorrect RIP as far as single-stepping VMRUN is concerned. This patch fixes the problem by checking, in nested_svm_vmexit(), for the condition that the VMRUN instruction is being single-stepped and if so, queues the pending #DB intercept so that the #DB is accounted for before we execute L1's next instruction. Suggested-by: Paolo Bonzini Signed-off-by: Krish Sadhukhan --- arch/x86/kvm/svm/nested.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 35891d9a1099..713ce5cfb0db 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -720,6 +720,16 @@ int nested_svm_vmexit(struct vcpu_svm *svm) kvm_clear_exception_queue(&svm->vcpu); kvm_clear_interrupt_queue(&svm->vcpu); + /* + * If we are here following the completion of a VMRUN that + * is being single-stepped, queue the pending #DB intercept + * right now so that it an be accounted for before we execute + * L1's next instruction. + */ + if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_VMRUN && + svm->vmcb->save.rflags & X86_EFLAGS_TF)) + kvm_queue_exception(&(svm->vcpu), DB_VECTOR); + return 0; } From patchwork Tue Mar 23 17:50:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 12159043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAAFDC433E5 for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC7F2619CD for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231764AbhCWSjJ (ORCPT ); Tue, 23 Mar 2021 14:39:09 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:44868 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231845AbhCWSi5 (ORCPT ); Tue, 23 Mar 2021 14:38:57 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIOjDI166831; Tue, 23 Mar 2021 18:38:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=BL5GJjqPb3UGDbiKYengH5LU8rxeB4qWKQj44cG12Vg=; b=UiCTxQIgtVRfqM0+XV9COjXnUOdBYCeQoSpvmGJn6Hr9myQzkXexWnzIIqoY/u2gFJ/E 2zw5I1iqeIxZIlRu41g6Qp3z1XIzMsIsMDmTkg5vDbUWJf1SztKuUZMvKqMHjHzPlN/V 8xpSC/oUCncqCpEn9by9Yr2+BJm59F1qz7xFMzBVzEAICtRRJJgLSmqVdE/xbiYB3Mdm ZvoPgZcbZUqjV8l6CLwcgKGPd+lKQbQ6ODa84hAJJN/cMdmjxGMEqo5cJLKIWmjI+dx0 YoHcHrIQ2jWnPTqI5mN5/FkZkq+cQOJvfy9SNdUrVSwlSms3ob4fbz0ZX8FxZI429cBN 8Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 37d9pn063m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:53 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIQNRF075340; Tue, 23 Mar 2021 18:38:52 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by aserp3020.oracle.com with ESMTP id 37dtxym95e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SVnkCqcw5qb531Fe++NGsaUnlL+AOjhvViIHM0pfE8AyhT/teLcK0nPrq/9gq3K1Dp2pUGRnNaGaRIK8sXygCxhbtNp8xi4JJtIdoQmTaiZ2h/XaRtf89j8Wa+8sUO/NcbCn4/9XttoX5X3L7i60NE6e0s5lBAJw4At2ZV4TiqUSe/3K10VcZ+DomM/Wru0lQQeS1oqj/19ArKLYdlP/TepGH8tgGKCrJo4yTGDbpGX2O7uHrNcp5XeRZtfrEVQHBvXI6OWMSeH6vJGLIfWBnskQv+cqDUrSq6hI8PaXwyE0XuXd5VT8jGo+Ubc8C7CGIhh6HeVkuxrafYhKxn/8vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BL5GJjqPb3UGDbiKYengH5LU8rxeB4qWKQj44cG12Vg=; b=jFWqBZhk762KFd2KpA4SGjXUQROMFDZbuQjMbzysbjtsUVbmPIStzYKpzv1b3fnAXlgX+epLS1fmw3wWhCcBbyLdqKwjEX4znt7fizht0Mrou14nfj2iFaxG6iWUk2cEjAlUky/n3hDnQZDlr6B1cXqcB4Tn8WjpbpBz3SSwm8rqxeB7vejJnxyrfu5xextWD3QeaPFjpscZGrYsHNUSRKHw8ryvnp+XCJCZjY1SwiJ35a05w5/nnHv+061sxdYWI01Qf7Rc280O/bgV7s6jby+Vd8uB03N0FW3ZSKBrvfNtrS1e6qck1AMbVbxvh9EG1QRlLNp7Upt5CF6ggBB2+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BL5GJjqPb3UGDbiKYengH5LU8rxeB4qWKQj44cG12Vg=; b=tZGIQMdvbScz+giOH8jDGi6++JLaBLyf+T6wTbi9WUoNeTykfjsibKsU6XldT7HGUbzIilpY/OnIlrWK09tgjNdWJNXHsOqKGo3Nzq1YrvNOxEnmv5yjeoEb301gKgLCI6CTeuWlM3Tw2tiJuxTnLHMcMN+LuT2gDav6wvtUNXM= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) by SN6PR10MB2829.namprd10.prod.outlook.com (2603:10b6:805:ce::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.23; Tue, 23 Mar 2021 18:38:50 +0000 Received: from SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7]) by SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7%7]) with mapi id 15.20.3955.025; Tue, 23 Mar 2021 18:38:50 +0000 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com Subject: [PATCH 2/4 v5] KVM: X86: Add a utility function to read current RIP Date: Tue, 23 Mar 2021 13:50:04 -0400 Message-Id: <20210323175006.73249-3-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210323175006.73249-1-krish.sadhukhan@oracle.com> References: <20210323175006.73249-1-krish.sadhukhan@oracle.com> X-Originating-IP: [138.3.201.29] X-ClientProxiedBy: BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) To SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ban25x6uut29.us.oracle.com (138.3.201.29) by BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 18:38:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 654814fd-d5ec-4045-0261-08d8ee2ae450 X-MS-TrafficTypeDiagnostic: SN6PR10MB2829: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NsgMvWqanxT7Czt5+i/8+htFnNNAw2C8I1OzuGz7sAAB6eAtT3xUmOiWCUUP+VWOUjDcHvm85eieXTJYKJg/AvQvPafcYdubN2XH+0hYbwWLs9c3z00XW+7LaEMpYPVV6PzpqqKdYjwKk2quBFBe8jrvhwklGwSBeqBmzP7+1/ZFiVLTKsJmwGh8vaaDX9e840MFaOXFNa14LqvdCK6wmNlST+XcTq9v2kQsV2hrcrjuQcpGQrTjlwm8lNiDfHZ0bbxgvkfjuzfdlOGYT8vbG/sl7VQNR9mQS2+GRnsVkLk8JbacFja7g2mdSQiVow+MCOu/ArHU2isR36ogk8cl+RunzvRUcHkkfnSTBKJWevP9vhCinv5myHHXFueozyPIEYRauHa+ZOUrK75StclUwysKDZxygq+qiKDQq7x9qkv3JL8sjoaSya6BYvCAw2k6Kwmiau+fdbSTfQhnT/xmGule5ftGLe4eRo8aBu5wonWh8vK9Lvsf77yluS//3MiAyQFjpPlkC0ODTcgNi6zJHjMWMJyZh686EB/WeGq74bvcIlLSa/mpiQs+rfd6gZtNcHe7AOjkIFhjJnRHiSNLLCvquMvN5fihtV76M8V2fJH8LT5hJXauRicTMPV5KARmvNLMH+PsEFhTXZdPXW1PQA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3021.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(346002)(366004)(136003)(376002)(396003)(6666004)(44832011)(52116002)(1076003)(7696005)(86362001)(66556008)(956004)(66476007)(6486002)(2616005)(66946007)(36756003)(26005)(5660300002)(4326008)(38100700001)(2906002)(8676002)(16526019)(316002)(8936002)(6916009)(186003)(478600001)(83380400001)(4744005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: E9X7WgIvHkZp11KSJMkH0g9xWg3G10rqSefMGNudD9fjOuHI6BALgYkahNXL65ZYrzbi5vwxNEgwmP7hRgp3XuMaOIA1nCPpSexIcl/aUcdqE/4ndRB0/80ctzI6d+NXPTcJRPmMPhiyZUziZvnrWA9t18apqTKEj9dMbuqdefdEviGUpWrUoQNMnaR/8YiCYuVGIywwGFB4vP0w3LAdXj1bynLzQaEhsiuuPIGzdHydKf5n0gReRHo/UoBMSMsc0HiXpoqbbKuO6FGsl6D0LDve4c9UUQbuJKXB2wilngoTwln1VPDNmA2Eur0NOn8J2MlDuZBHVDwBY3w2JaOwZkbqxMXw2xL/Th4gNX/J2K+od3dbuZ6cJGx3Pa1TBb6ktJy0TExNM1V3hRKKGvbbdCmggz5OzhO95s5rnCs0ZGq9bLvgYI1lG0FcI6/hNpoe1H+8Q/PoAc9jOtimjaF64lk4fMRdto1GtMR+okVz4tPoKTGGW51/7BjBF9ssu/B80iYiT2hTczTXbBTyvYDvL6/d08PRfaOFi8m5zaMP4j3mlmDmY5OuyOqfNqNEHFf3czQi6EwBkl6mmPMRSl965bEqE/c/w8UzJYV3BGTEKxQ+ghukNcODXdRkhdKKG433Gg4KqfHYyNtndOgEI3kYBN58cig1yHTZQf0YEnKUL2tSQ4QZZ6FxR7c5/0zxOFP8FTHow8L5NAymI63oKZigw/JvwZpayl7I38Dx20XfaUJhBFJhOMiV+TK0IpIyOCifiXEVoNmI1IGbc+7Oc3poXCdDZNVL1jrzsA45v3cPAV2cJd7Gwah2ZlchmdMfZOveoJ2YqUSR3VsRtkH86lgQG92KVd/csPpgj8bZ+VmWY9YuI0heePLZOWoFhPOFznPzh8zrn1W44/DKvk72LYhLxqc+6GwlrD8ekAbU/LbF2OquIb/Cs/NVuIXLb+OobQEMb/9g/pmWQ6K64mcAKT+Fae99aMOcJlBGrUbrXL9fHKxmZDLmzu3PJsYKgcKiPgt881kCj36CuL5vCdbw/wE3BGrNKlJQiYVhqceQvLwsFRTPJLUZ43NGUruprMA2Eq4wipYgbNuuo4xv1ar3P6IHmYDbSalgMAJ9grJE9aowgnFlJnj7kEgdu0wE4ZXSOt2Fz2Nw2Qmje+7F1fbq2WT8xKoKJp7ARA+2kjhcT+H7gPhvs/AFqmsEkG9APhNbruQzOTF7GchKjwoRFUNu+cFuZ6fDs8IO1rgssI5N2HoojtGQ9JGVHJ5CBHiPDeGBqOQtHyBsmF22WGv22CLFizBM6t1Ke2fizwLK91YcdyQtxLAE0lBq/alTMHvz8K0bN7vl X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 654814fd-d5ec-4045-0261-08d8ee2ae450 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3021.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 18:38:50.1266 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DId1yENxREE1xiG251hlUYW9fKcpWl8cA9Narx8kyQukRClkObpTaTjjcQN7hi47ZdRmCKI7nt8XfrIplfTqKQE+8dv0vHw9XiRDLgkBERE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB2829 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some tests may require to know the current RIP to compares tests results. Add a function to read current RIP. Signed-off-by: Krish Sadhukhan --- lib/x86/processor.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 87112bd..5604874 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -489,6 +489,13 @@ static inline unsigned long long rdtsc(void) return r; } +static inline u64 read_rip(void) +{ + u64 val; + asm volatile ("lea (%%rip),%0" : "=r"(val) : : "memory"); + return val; +} + /* * Per the advice in the SDM, volume 2, the sequence "mfence; lfence" * executed immediately before rdtsc ensures that rdtsc will be From patchwork Tue Mar 23 17:50:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 12159035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDA7FC433E1 for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE853619B8 for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231817AbhCWSjJ (ORCPT ); Tue, 23 Mar 2021 14:39:09 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60464 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbhCWSi5 (ORCPT ); Tue, 23 Mar 2021 14:38:57 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIPMjF009484; Tue, 23 Mar 2021 18:38:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=DoLsFaw/3M7p92yrqsvpbA1Q/z6kTAeuUn6VDbkWP/0=; b=uj/yiCUVw/uTjR8zYJtgmEs1WSK1v+Qxw1V5aUJTUsbjVoJBvYUXdvBp23atO7yKgA4i GsUPX3jWlaP6uOlh24Z/O56TdojOW22yBOLDFDxDGqS31rJTLqRE8pmb3R0OJlnJXYkG quCoMsBoA7hYlMOIjv9fQRBCVYbt1JWq5ZTtzkA7CaD3JIyBTc1Epx6drj2xVJnCpkg1 gYXSpNE5shizNxW1f9xlrpL1LOLQZER7CxVCKztmwDntoCz5IatRfQPpzVJlJaCoLgrZ KHMO0YkAI0U4SsFqOt5fE+3lix9oPmk0yglHDePuYgUuIJf8N3WuvGAFXlwoQGFYF+l9 Sw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 37d90mg6m4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:54 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIOkgm144196; Tue, 23 Mar 2021 18:38:53 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2105.outbound.protection.outlook.com [104.47.55.105]) by userp3030.oracle.com with ESMTP id 37dtyxtv99-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mgBjM9LFCYsedeij8wDN/b/5Km7/mXdp/XpxnpDO8q1eRajObIja3qzjUDlVunLSu4hcfyhJ5NdIEprce2OOfCGQfyKsEKZLhJpM9nGNdhuSCnKLydP4X0GM+OgY9iEutds6ulA9ZiY/rMue80BSv8nOIKzyIOTANNowV5t7l05oy/+0uRaY5ZXq5vToZhb17rWpeV6hKeWJrEpgDRSeeHOlCcSNyN8dltiWREzmeKNES3QgzHoYWTjvGIjtlt0JT097YWPzI2s3OhVlRd8DKMzvV0a+CdmIJXA2vzOoNYjFoel1/WCeI+TodEbAE0AhsxrxcOFvCkYxnE13oyRyFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DoLsFaw/3M7p92yrqsvpbA1Q/z6kTAeuUn6VDbkWP/0=; b=KwkN2ys/w6mffF2HNF1KYgDreDfhu83xXcpVCvJmeW9GRGfHfiP90himCJoK2bB9kEjv/boYe/HVXC4Q2PMcG5Mp2G6wQ/HUVSq/7P71byFz2a/gF8irEHPxyQt9r0/d0NtN9G007xg5gbAHgx70dczgN678dG/q8TLSBgQT8DRyTjfJ2DCtYc/WGvBFp9qIaa+EwjbnZB41YecCjDlTcE6PvkGkcC6doDnPSddYUF68xzQL3eatUco5P7fvzs8vlvs8NHrzsoK9iPaN24Hhy/H82C/lEDZnRedB/cqc0zEaIaRoA8rJ2pV0cUu5z/ku5sqznaz2OJfF5MJAyWPzog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DoLsFaw/3M7p92yrqsvpbA1Q/z6kTAeuUn6VDbkWP/0=; b=qB+Xv8jXqpyHhgHu49tdwZ+r354Htk6WWJHORR27ql5oxIKFyqFqUfdTKMEApDABOgTxKyxrZFVsWiTQSYn1ck2xcZj/fd8KrPwD2SqFmP9OQdpvTNgH1I7ya9vuJQijTycnDBqld5P9vTGGRKalJ6MqMjYKriO75fQ4QLeTNtE= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) by SA2PR10MB4682.namprd10.prod.outlook.com (2603:10b6:806:110::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 18:38:51 +0000 Received: from SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7]) by SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7%7]) with mapi id 15.20.3955.025; Tue, 23 Mar 2021 18:38:51 +0000 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com Subject: [PATCH 3/4 v5] KVM: nSVM: Add assembly label to VMRUN instruction Date: Tue, 23 Mar 2021 13:50:05 -0400 Message-Id: <20210323175006.73249-4-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210323175006.73249-1-krish.sadhukhan@oracle.com> References: <20210323175006.73249-1-krish.sadhukhan@oracle.com> X-Originating-IP: [138.3.201.29] X-ClientProxiedBy: BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) To SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ban25x6uut29.us.oracle.com (138.3.201.29) by BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 18:38:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe1d3d2e-8103-4495-5948-08d8ee2ae765 X-MS-TrafficTypeDiagnostic: SA2PR10MB4682: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Lq5xKD9AdgFRy09z9MpOa6Wv9LAST0yv5JPUfcjZpM6EzwEIMT2W22iO4pt3QsIhy+0NqlHi/yoHVC+rNul0ClNhUn7k1eXCN40o3fK5esblC0Xk2suRwUkLrBZi67QGxxCtNUsc33glvuIqb9ZNZcaUlHGhwRwLs55woRn5d3mpVfHTP3IfJPNcZht1cMlKgOZwiyWF3AvJjXAq5jGs6FZGCSHGG8Ax5FmCb4YLuMO1Zq4/xlKeiHENxEX9ZsYOzZ5GvKabt0wTI4qC1MqVya88B53Ujp44BcbqCqAiqZ4nnjlF5evCnLqgSOCH12ChLguOU3rm8hreAtwdZvVMYWdlML2f+6/3N5i3tDg1GfXymn+PPGE0BUH9v8r1VIaNeIWxggFsEGTIrAoDu/TT8YMqcYw8LGr85sf5jAo1ECzz9TC7FBze4a0FVWZ6hspy2CQyHG/2reS8YJYaOBdlGzVKd/hsRE/GF4bt+H5FGKGyy1J9g8KjPVK6gPVN5u6B2fJ+qq3IX2hGk0lUbU/119jm1g8wj18dWbEzn+NGo8fmSZpLpAy4+Np9xNo79EzOC5n6pMJUT1LKncItJRSeeLAD0Gv4ZcmIiKBr1HVKRx6iSfKS5vK4FueHZiISg/BmyIPiL213r7sfK8rdUIlLQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3021.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(39860400002)(346002)(136003)(366004)(376002)(66946007)(44832011)(38100700001)(7696005)(6486002)(2906002)(4326008)(36756003)(956004)(86362001)(66476007)(83380400001)(66556008)(8936002)(2616005)(1076003)(52116002)(6666004)(186003)(5660300002)(26005)(478600001)(6916009)(316002)(8676002)(16526019);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: llzEkuF1D8ctu0SoI0vxaPGbPD0BLkTvQLpSkQOMMs9509iPW0Hwp03tac0Tvqg5vDIF51M46YX+rLxkMYQPjI2lOYP3BqZY29dPKLiH4AE4N5+Y2U7KK6bNvGuv7ymYSSOs8DKp4PEOz3//Au9n4WU0r936oaUzX6j8agFdZxeami/zI98ZIrY+9gtIZf2YCHW4g4FvnPVdKTLLXcQnm8QJ3DJW7EqiDrU2H7+gi4oCY71kn4cm+rmob2bUwTmbubPtyWwoe14Jq4JzoceeYfq0JirwLxOXuDq4g015910eYqftmL/aKcpduRzgyFIbKaDbnUFHSMasH+MbRTaEVpDi6pBeiNUs4uwAC9t26Vide4DPBMQb+D3lHSFAZaxhS1JUQwSspkNa3kk7pSLmLM02LJTTxslg+l4VBV662hDIFkCfwWTT+wgpJIplHU8B8H3sweceFszXK+2A82JhRw383qpHT4v4FhigY2EBVEdGzqGlu5oz0sO+8qQxcUy2GUrPEEUJXzvtyzLJR9M+cXf5n2mG99dLtAMHqKE99R5W9eGAA04bm6CFK1z2QptCTve6cnmHpvSYoAJLDm7CBS+90pCrvB9JtYNtNxyj3utm6bGvgCxctf1iqku1Nxjor7UKB7Ztql7z+JZY2DKyjHFoSIp6kBBGkCGmOjhYr3WRZzuYv7sJvp3HM+1ero8DZi51mURcsHzoMb/2XbRr0VW9t+7bOuYzbOU9lNTB7a/v701Foh5S0nI73/NpgRrBOfBsiEPfnQbu60m8ICHuYvOugJ81kxWC+sB2B0seueefLb0BOfEmKxuYu+XjcerswmsWQCiGH4rd0Zkky4hX+s2Uv20a5JK60/p9oKq2Jo7sRioFkwKoONuZW3kKe3GfLMuJd3LG0pW839RVIxKrYxRKOOE48msK//WFRSVOfJ++9dqtnG8RpgHt2zidXz035CitAmIqqseMGRoP9tl6af+Bp2pi4Owl+2ont+GvZe4jak2qZ7wCMF2wnhchGZqiNZB19Dshj2vV4G7ZRYK69LsYevv8YqUMh3Xg3+QhijYKJBw2Nm1+CZaDxZyy/byHZPFrY8f9wruV4wFLtZ7mhTUpMVgO6VV/IB2PqcsXNyj9fLpFUqy8UAGYF0i1+i6I15iiLcugmo8nuHjXIKBF46haKjbjre/alBDygEChMUcr5riztxMLC8gMYDQYCTdGJ1AzKxJBcprp8nH+ADJbvQFBDZ8zQG0H+hEy4kqoYe3X8I7v9RGimsliup3IEe8Mcf9RBGcqfBYPAk7Gxrjb3U3T2lo1Olf2zd6pV3GIZvUFFh2UB+DQxnZl/RPPNwwt X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe1d3d2e-8103-4495-5948-08d8ee2ae765 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3021.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 18:38:51.6707 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3KoQmEEAUATV0myhMdoULEWSD4OZ4Ijc2UQgaqap0vavaQ/1dkd4TKbEdTXaImumTzIYizv1E24cN4CnnjyfxZJYz82r6DhFgP0bw9KVmW4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4682 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add an assembly label to the VMRUN instruction so that its RIP can be known to test cases. This will be used by the test in the next patch. Suggested-by: Paolo Bonzini Signed-off-by: Krish Sadhukhan --- x86/svm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/x86/svm.c b/x86/svm.c index a1808c7..0cf3b97 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -208,14 +208,15 @@ struct regs get_regs(void) struct svm_test *v2_test; -#define ASM_VMRUN_CMD \ +#define ASM_PRE_VMRUN_CMD \ "vmload %%rax\n\t" \ "mov regs+0x80, %%r15\n\t" \ "mov %%r15, 0x170(%%rax)\n\t" \ "mov regs, %%r15\n\t" \ "mov %%r15, 0x1f8(%%rax)\n\t" \ LOAD_GPR_C \ - "vmrun %%rax\n\t" \ + +#define ASM_POST_VMRUN_CMD \ SAVE_GPR_C \ "mov 0x170(%%rax), %%r15\n\t" \ "mov %%r15, regs+0x80\n\t" \ @@ -232,7 +233,9 @@ int svm_vmrun(void) regs.rdi = (ulong)v2_test; asm volatile ( - ASM_VMRUN_CMD + ASM_PRE_VMRUN_CMD + "vmrun %%rax\n\t" \ + ASM_POST_VMRUN_CMD : : "a" (virt_to_phys(vmcb)) : "memory", "r15"); @@ -240,6 +243,8 @@ int svm_vmrun(void) return (vmcb->control.exit_code); } +extern u64 *vmrun_rip; + static void test_run(struct svm_test *test) { u64 vmcb_phys = virt_to_phys(vmcb); @@ -258,7 +263,10 @@ static void test_run(struct svm_test *test) "sti \n\t" "call *%c[PREPARE_GIF_CLEAR](%[test]) \n \t" "mov %[vmcb_phys], %%rax \n\t" - ASM_VMRUN_CMD + ASM_PRE_VMRUN_CMD + ".global vmrun_rip\n\t" \ + "vmrun_rip: vmrun %%rax\n\t" \ + ASM_POST_VMRUN_CMD "cli \n\t" "stgi" : // inputs clobbered by the guest: From patchwork Tue Mar 23 17:50:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 12159041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAABCC433E3 for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD29A619C9 for ; Tue, 23 Mar 2021 18:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbhCWSjK (ORCPT ); Tue, 23 Mar 2021 14:39:10 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:55802 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231449AbhCWSjB (ORCPT ); Tue, 23 Mar 2021 14:39:01 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIOTe5050737; Tue, 23 Mar 2021 18:38:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=FveCPFlVVNpCz5DRVWj+aSDizFMfGbWwnX4r/8ljZJw=; b=epHQYCOpMWWSbPqvNyRHPaQuSqdHX7taJQ2S95/2/8RLn/HWC3eNGBu+N3Z9KIrzjNSn P1HJrg8wnw5xcLZYScN4TxoHvVwKQlnrg9zKOOKkyveOlaCeGLgvTy3R4A7rsipJRbR/ 16MAKnPCMrRx2FvMRCb9b+xCP9QeLaC1WiqTtZGSuC0NqyCPSm/+l5YZQ3V/zDhlxk/c eZzsa48cdypIwpBvjFqVayar/MEH9SmRgPZfHdcjOWH1++dRtTCWqoNmY1PNyUY6zqr0 tI0lXWpYtXXHSZRryffDZXLjWDMt4DpAZnoUHrm99eevYd9dsTj9EqWOijnrdfltcEbH Nw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 37d6jbgb14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NIP8Bj022922; Tue, 23 Mar 2021 18:38:57 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by aserp3030.oracle.com with ESMTP id 37dtmpv606-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 18:38:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K2Jy25Ep2INxEjeurUYL9dgySh8N+bR8xNh7jS2kaoc/oUo6vYdyB3qovnhHCSZLSfN+wChbzlMYZlWzs8T9GTvuxfjRrxL4lJlycNtVh8Yhk7fbbnecNuUex+mYA5RhB4C+mJXWM5F0tEdXyA4Yo2DHd+Dx2sde0VhmZrZPS08TOf9DN+y7K5IfBza5tlFgap+cHrspf0iJ1Y5yKzVmsrUoqTpgpD4ukuFmVVNRzdLb5HGAflIRhT26bltAAENHfCijndeWAPhjT3WJ1ZDXqyDXTLR1jl4oK+OsrfOKcV+GAoKi9AG+G1pYK5zHW9YxAVIUG/ZtcZR5J42YekcJrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FveCPFlVVNpCz5DRVWj+aSDizFMfGbWwnX4r/8ljZJw=; b=eI1oaDvZDsi8ykUWSX+XiUrKMWKj9JxdpySnn3C/f0ZwnYzGkXHttxTqLoHXuWnXmWIT6KOtkMdKXK9xc953VocbFZ0mpR+91zlKlAT92Ofz+WeEN4mMVuWmWJudLoOkJGe4JavMk4lMivx5JDFViOZa/tmzv9uHmkv1VlHlzTWob8f941SEdbDz9woE8pECk3tfOSRc/ekZkpu9enfbXHiVUpMuR17JFMpkvVmnCjuuKxJ5zLFnF2Y9wmqfmB/by3m1yoU3VaKzLNZgCQZdqHFEXUFjAWN/dICKtIU45MZVJI4KPz0rZDRYfgVpHDopQ8IAcqO8kEqdBO9MaXJNoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FveCPFlVVNpCz5DRVWj+aSDizFMfGbWwnX4r/8ljZJw=; b=YhyInHdK8QqecGdb3KL8YFG8hhSFZ8PFcJnBA+xizSp5HkZ22Q0ke0wU889uU0YYT3Pbx3w4ERatOuVMgYRlaCsT9EMNxxuyw9kGdiO9dEnxyum17E+hcUMj91Xv5DA1KtL17ASpfO83M5CkFA6CgU4t6oUy8gfWBnzA5K1HFpo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) by SN6PR10MB2829.namprd10.prod.outlook.com (2603:10b6:805:ce::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.23; Tue, 23 Mar 2021 18:38:54 +0000 Received: from SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7]) by SN6PR10MB3021.namprd10.prod.outlook.com ([fe80::1871:3741:cc17:bcf7%7]) with mapi id 15.20.3955.025; Tue, 23 Mar 2021 18:38:54 +0000 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com Subject: [PATCH 4/4 v5] nSVM: Test effect of host RFLAGS.TF on VMRUN Date: Tue, 23 Mar 2021 13:50:06 -0400 Message-Id: <20210323175006.73249-5-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210323175006.73249-1-krish.sadhukhan@oracle.com> References: <20210323175006.73249-1-krish.sadhukhan@oracle.com> X-Originating-IP: [138.3.201.29] X-ClientProxiedBy: BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) To SN6PR10MB3021.namprd10.prod.outlook.com (2603:10b6:805:cc::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ban25x6uut29.us.oracle.com (138.3.201.29) by BY5PR20CA0008.namprd20.prod.outlook.com (2603:10b6:a03:1f4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 18:38:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ba2b82c1-946a-40ed-1c6f-08d8ee2ae897 X-MS-TrafficTypeDiagnostic: SN6PR10MB2829: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SmtusVb2YiB45mZsZDvhcvTISeABfmYvF82tr4fReECYcthejb2UC4OWkZzxbUceIgt9xTrmq+gYzMcNwV89eBobB3gJImLbq2XnNnrtJy/A7dsvO/p+QVUhS4EUHEm56PrbP0Q+xb3OSBAFtK2vJMCBJWGV/HsLdz5eSPfpn2umQeqZlXtQuBgyt17A4c4kOdzqJpFkLu/1ndi6sPRiuXTtmXHr/dZ31cZaZavsB9gu545CnpCjxzp6snnNqG0OiNwUAQPvZ8yRAI6Hs7t+X1Bp9sBfhxG7wn5//p1XL5H0gs9HJpZO0vYCxSzSbin3oHyN7iqKm0WcS3Jh9Wf1HysDnn1kz0rO9vnbHAJzhX5XKb6UMcBnz6Q5duRtu42ZNgCyUdJsKVv3ms3aNJYnB9oXGpZpTm7qb7avT/IKwAYd+sN4pNJbsaAq/i6eTcUZDTIfqbORvJEvOaGldaQqj7RE9temLMlHxXu0D2/bT0jisImmgUsz6s3GO3XDX0tzdUDNckp9H2VqhF31cSp4ozurKyRLJkjA7TJ55ivsUwEcvKPvAPjzgK3FxN6UihmhYPhDuXFQrVBV9BsqdlvqNcc9CTfYwTfWNC41gtsBx6FQrhxOlrA6jHh68+OLHosy/OnXaMl9HlA/NnAJF34GhQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3021.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(346002)(366004)(136003)(376002)(396003)(6666004)(44832011)(52116002)(1076003)(7696005)(86362001)(66556008)(956004)(66476007)(6486002)(2616005)(66946007)(36756003)(26005)(5660300002)(4326008)(38100700001)(2906002)(8676002)(16526019)(316002)(8936002)(6916009)(186003)(478600001)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YU+8ozzjF0spT7vRKfpm3N+IvYWwX0YHYg1T3w0k9eX8vo0geuZcSUQUaKDWfSy1gooV7GEjoZXY7oBpOxPfi9tynzFloy6+Mab2jNOCb/yKwQ4xqliSCjqWp7e92TsOKs48ccVZg54PCEzemrSJ3YE1ZJHAl7wnLah7gGLzYzc/DFdrA43elNTe8UtRd5ZpNzK3jZagwVLsT25bx7HvZBTDsEG2HPEJ4hfsSaie4D6Fa9N7sgOGEHeS2JiLvvxjjuTDte1f0jGlmTq1ipixOCZxeT1Bbw71olZhl88A6OtUn6GFzo2vdCcCsgw0jd2CnItYdLRmTkiMzbEFiYkXtMu1VHAxOJtHImlX7KWKb9LrXIgDjIo96dAZHcBvptGiuzp8tJZusZu3Bp5OM0/HBIRdFQXI7bkE5blyMd2CcuUwurvp2GsSeOHKxkhl7XwGjPWx1ykC7r4VvwOUCfITyeGAUJ3qSCdFIEUc6+AihYoAbbXAHuahVtK3I67tl2w5+zEE8BcmQ44VebLVQHmheV7haRgzw8m/B7OUdrvCA+8fFrcYPZwh+IO3yWvemNJmhkwkmA0hTH6qxVBg7y2gNep6PU9TGxyO9CVudybyJ+vZIMoJbpaSoXzc56hJ7gJpJfBYzDveFuaIxP8Xth82Cp792nNUg3NltCrq7UydNMHwW76Y/SU9xz+1hN8udRUVdWiTsrC4NjIKZNvfmICqNdKgTwxorcbeJLNeQsyzaD/MXFsSZs1dUpX9Fm031ceGZOUO0Tdb5V9Nw8DQBNZVa1qG3nVwIjyYgZeBpr3Gq+FegSw92KtOCH3vubLWKr963Bcw24Lz/U5Xs9Jr/4m2T6zt+iJgoT74ZrV7GA4PgM9ZVrIwvwNmidgsVrdxrFK5colPsFv14kNCFYo6eveud5yr/gnl5kOMsYs/VBxO0Ktyyd90HnoWkShpWhDUrdPPFFIRXk6KDjr+UelDuDZwKc10QNBKhVQL9yfhvapH7PbWq+2oFFVo2hWC4d6hVKwAQA8caJBqZjOhpCNe15DhRPKgIJQwdU5hHETt5vhJfNcPx2dzUPtZr1HdKYS7Fc/D0zakjRA1BHe5wZZbuW8f3qS81uEn4rNLb4syLSSbmq6b5I4+E14XVwN5jEpC3NUdGqiEm1xebsgCRHNlphEOXI9mmRmgNtmKKY3G4ZRMTFv/H/uehQ2CTbu1YAxspa3CUIJl2Tu5LG53qi4jErl4heoLfOCVVuba4z+9buh6ygdCzXxhMMtgeG3DkUJjzmRJkZzjD1E+QRmwvUJcosfofCTEDEHZ+B/+rsQIQL6X4l2fHqlYegyxO1uN7Q914E5P X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba2b82c1-946a-40ed-1c6f-08d8ee2ae897 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3021.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 18:38:54.7050 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VruLbgB/+a4tAiZMf/p62zuctfj41A/vsjqnwxtzH7G5JIAShfOhK046mYq7MGRPyNhLF4t8tIIwOhEr+FHCVnMI/EcKM1UT0/ROoGsDg78= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB2829 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 spamscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230135 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org According to section "VMRUN and TF/RF Bits in EFLAGS" in AMD APM vol 2, "From the host point of view, VMRUN acts like a single instruction, even though an arbitrary number of guest instructions may execute before a #VMEXIT effectively completes the VMRUN. As a single host instruction, VMRUN interacts with EFLAGS.TF like ordinary instructions. EFLAGS.TF causes a #DB trap after the VMRUN completes on the host side (i.e., after the #VMEXIT from the guest). Suggested-by: Paolo Bonzini Signed-off-by: Krish Sadhukhan --- x86/svm_tests.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 29a0b59..46db49a 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2002,6 +2002,118 @@ static bool init_intercept_check(struct svm_test *test) return init_intercept; } +/* + * Setting host EFLAGS.TF causes a #DB trap after the VMRUN completes on the + * host side (i.e., after the #VMEXIT from the guest). + * + * [AMD APM] + */ +static volatile u8 host_rflags_guest_main_flag = 0; +static volatile u8 host_rflags_db_handler_flag = 0; +static volatile bool host_rflags_ss_on_vmrun = false; +static volatile bool host_rflags_vmrun_reached = false; +static volatile bool host_rflags_set_tf = false; +static u64 post_vmrun_rip; + +extern u64 *vmrun_rip; + +static void host_rflags_db_handler(struct ex_regs *r) +{ + if (host_rflags_ss_on_vmrun) { + if (host_rflags_vmrun_reached) { + r->rflags &= ~X86_EFLAGS_TF; + post_vmrun_rip = r->rip; + } else { + if (r->rip == (u64)&vmrun_rip) + host_rflags_vmrun_reached = true; + } + } else { + r->rflags &= ~X86_EFLAGS_TF; + } +} + +static void host_rflags_prepare(struct svm_test *test) +{ + default_prepare(test); + handle_exception(DB_VECTOR, host_rflags_db_handler); + set_test_stage(test, 0); +} + +static void host_rflags_prepare_gif_clear(struct svm_test *test) +{ + if (host_rflags_set_tf) + write_rflags(read_rflags() | X86_EFLAGS_TF); +} + +static void host_rflags_test(struct svm_test *test) +{ + while (1) { + if (get_test_stage(test) > 0 && host_rflags_set_tf && + (!host_rflags_ss_on_vmrun) && + (!host_rflags_db_handler_flag)) + host_rflags_guest_main_flag = 1; + if (get_test_stage(test) == 3) + break; + vmmcall(); + } +} + +static bool host_rflags_finished(struct svm_test *test) +{ + switch (get_test_stage(test)) { + case 0: + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) { + report(false, "Unexpected VMEXIT. Exit reason 0x%x", + vmcb->control.exit_code); + return true; + } + vmcb->save.rip += 3; + /* + * Setting host EFLAGS.TF not immediately before VMRUN, causes + * #DB trap before first guest instruction is executed + */ + host_rflags_set_tf = true; + break; + case 1: + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL || + (!host_rflags_guest_main_flag)) { + report(false, "Unexpected VMEXIT or #DB handler" + " invoked before guest main. Exit reason 0x%x", + vmcb->control.exit_code); + return true; + } + vmcb->save.rip += 3; + /* + * Setting host EFLAGS.TF immediately before VMRUN, causes #DB + * trap after VMRUN completes on the host side (i.e., after + * VMEXIT from guest). + */ + host_rflags_ss_on_vmrun = true; + break; + case 2: + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL || + (post_vmrun_rip - (u64)&vmrun_rip) != 3) { + report(false, "Unexpected VMEXIT or RIP mismatch." + " Exit reason 0x%x, VMRUN RIP: %lx, post-VMRUN" + " RIP: %lx", vmcb->control.exit_code, + (u64)&vmrun_rip, post_vmrun_rip); + return true; + } + host_rflags_set_tf = false; + vmcb->save.rip += 3; + break; + default: + return true; + } + inc_test_stage(test); + return get_test_stage(test) == 4; +} + +static bool host_rflags_check(struct svm_test *test) +{ + return get_test_stage(test) == 3; +} + #define TEST(name) { #name, .v2 = name } /* @@ -2492,6 +2604,9 @@ struct svm_test svm_tests[] = { { "svm_init_intercept_test", smp_supported, init_intercept_prepare, default_prepare_gif_clear, init_intercept_test, init_intercept_finished, init_intercept_check, .on_vcpu = 2 }, + { "host_rflags", default_supported, host_rflags_prepare, + host_rflags_prepare_gif_clear, host_rflags_test, + host_rflags_finished, host_rflags_check }, TEST(svm_cr4_osxsave_test), TEST(svm_guest_state_test), TEST(svm_vmrun_errata_test),