From patchwork Thu Aug 12 22:47:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12434381 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=-15.7 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,URIBL_BLOCKED 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 E448EC432BE for ; Thu, 12 Aug 2021 22:47:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF1AD610A4 for ; Thu, 12 Aug 2021 22:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238420AbhHLWrc (ORCPT ); Thu, 12 Aug 2021 18:47:32 -0400 Received: from mail-co1nam11on2053.outbound.protection.outlook.com ([40.107.220.53]:38880 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238412AbhHLWra (ORCPT ); Thu, 12 Aug 2021 18:47:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uq3auKGplhYmyaIp3FkSrepx11DrtAdqZW29G132xAYN5aeaOdaHZ0aYMrpfWcVR/rdLvsg0D5Jbl541k8PoKR7YuYIQS/WU3zxV22R7xUGj/T2EsWWal9Vh/qf4h6XlF1fvSwn4m4KSPrqVoLKm1ptp95XmWhFyd+cV6Q6N9ydIiTvm3l1/3ODBLSZwN48+qZRlL7IP2sg2z/qKeLPgKhWY0BYaMsTzCMXw9V4WKKL04Jdr/xC72bZDoV2dMLDsv/fIZUKWMgPEeJE438nQoPIPFUsGO2vdpePUmlFQJEjgYA/QX2v2XXzDfKzbfpsenQ4YEI6jDEcFci2D/ji2dA== 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=TT91SQCKo33BAXE2AFLA0tEtdJ5LjsgIFhy4otfZVpM=; b=nsaMAFxIVSOld05rEE7lt0CGY85tT1gOLx6sTRZ82vwG9TJkY/sY3wjwz9ow1z1Ahabj+zfzZnJqFwmXAjWqY4K2dpVc2MCcTAnBxkaSOFiMVM1+L8Ft2sCfJn0Z1wEfmlGZ2N01qKo64V1NYICq6l+IGOdKGmUU9/i2ZGyIwnlbykOlTmwYuYL5PFqKyZw3kO4V4S9kaCRGA7QlR2NKH//k1HKSkXusJA2sSND+r/N1Fla1fSghopWQt3zlUIjlBFG25fwTmVbkiRnLPs93wtUHAHrRSTZEaTNtPrFPjT6aO+fuaieJY8sNnnvp0T7LprpA/WALkOJ6b21nOguMrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TT91SQCKo33BAXE2AFLA0tEtdJ5LjsgIFhy4otfZVpM=; b=P+52dTL2Exp1PZ8xCFGnKPv8+fTcqT6t+p5BKV+FBEdN/T9mGWi7Bg5OF/x1sppRoPMjySbS0NnXhz95b4f+RREpAUsS93fUlKaE0R98qjlNWvcCAd+2eoUSBhpqspad6nrpP84XI4V3L0q1x7g4+WvTIwYM/AgirMVVMf9SUo0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from MW3PR12MB4553.namprd12.prod.outlook.com (2603:10b6:303:2c::19) by MW3PR12MB4555.namprd12.prod.outlook.com (2603:10b6:303:59::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.16; Thu, 12 Aug 2021 22:47:03 +0000 Received: from MW3PR12MB4553.namprd12.prod.outlook.com ([fe80::3987:37e5:4db7:944e]) by MW3PR12MB4553.namprd12.prod.outlook.com ([fe80::3987:37e5:4db7:944e%6]) with mapi id 15.20.4394.026; Thu, 12 Aug 2021 22:47:03 +0000 Subject: [kvm-unit-tests PATCH v2 1/2] x86: access: Fix timeout failure by limiting number of tests From: Babu Moger To: pbonzini@redhat.com Cc: seanjc@google.com, thuth@redhat.com, drjones@redhat.com, kvm@vger.kernel.org, babu.moger@amd.com Date: Thu, 12 Aug 2021 17:47:01 -0500 Message-ID: <162880842111.21995.9414122849581561486.stgit@bmoger-ubuntu> In-Reply-To: <162880829114.21995.10386671727462287172.stgit@bmoger-ubuntu> References: <162880829114.21995.10386671727462287172.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN7P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::22) To MW3PR12MB4553.namprd12.prod.outlook.com (2603:10b6:303:2c::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SN7P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.17 via Frontend Transport; Thu, 12 Aug 2021 22:47:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ce030ca8-d55c-4c13-12e0-08d95de31a71 X-MS-TrafficTypeDiagnostic: MW3PR12MB4555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PxWGygamGWXSDe8M5MSopluINWu/gU43eliCq1J8KnP4HjpRv83Z+u3UF596wLqHoQvxDw3Lr1iW9U6t5GbEqoyXRaWlY+bAS0qhDKytTb/yGYcam2YP+/2vS9lk7YoNOGvMRYrybQW99GdPqIX7mrBlx3nlXZPOLq8ccB0nbXrcwClY6Kh6fGnIGHJkYpu0a8HZTQ0awIz+UGinttALFmtrC1nV9BEhOsdH1suvJ+TFHJUVFkt+HeLPeqCYBObPP+nPKGOgQ7I4r3k1kT0aiKHKNafqxgW90Y8zJrutzFygGhoSCQi+37FI5Ayj/3hq3/KtZrqLhLtriZn7Ivhsd3VROjRpbQo5N+gIvySmabudjAONef5A4DQJPKr6JuhzhJ8T2kszGoLic9yYMcGWW5IHO72As446TTJCVnuSMthz+dwkhhbSIlxz5GPvIA6XXwi+wXr1ONIUScmEBMtCrKXV+ahBcD0x5sDo+wbDtswq7iEPgZLbxL3uJEeCyukvTPBiEFRqLNTGetkknNsoWFNr8Y4P8NkENuU3xJuqC6kn+sOrc2U+P6jBJzE3LB+RDUwHC2AzDFFo5ANHIix7Zd2/w3gf8oDp/2MUhVkznWL48S4V0pUQ1NXxJUXoCmChlQrqSEk8y2Oiekpiq/F7nIVj8pp607SrWpHiKUX04NoJjnKshXPUE3H7JhE0lAvzRv5UV6GftlcdGcbW6IpghQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4553.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(7916004)(376002)(396003)(136003)(39860400002)(346002)(366004)(83380400001)(9686003)(8936002)(86362001)(103116003)(66476007)(6486002)(66556008)(38100700002)(956004)(38350700002)(33716001)(16576012)(66946007)(316002)(8676002)(26005)(6916009)(2906002)(5660300002)(478600001)(4326008)(52116002)(44832011)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?tdZryHVhSylC3rjuju3n8t4JQE3c?= =?utf-8?q?7nVhRma0/h7UkpPpA2dzZSrBj3ItuL+g31207uOdCtMIW18ClZt1hPObVpqfqhpsA?= =?utf-8?q?xKdq849AEw+YApIwBI26qtEFzfOcLGHWvNeCmh+n6y08c+Fc/GfBc/6z39i4sJNVV?= =?utf-8?q?JpcrjavavH4/zEA6NZG4aWIj6igZ0m25Gdxri3P9pLcF2Xp/DIFtXQSR5+7abZF2r?= =?utf-8?q?71jX11/O+1PZohw79TNeNGVSSsJ+mNy52fISolzfAgALqQdZVzL3w+UGHEB6x+O60?= =?utf-8?q?K4BoIzZ2qYtzr4VVFJH4nsxWi+p9MKNlPxRSRhbF26k/sv0II996OhXXRpM0sxkBT?= =?utf-8?q?ztM095nCXunPt4coyswGPtPiZJZR5Qj6NcxUIYJgFJNw3dYubLn3HGODehxpMYOlp?= =?utf-8?q?V8/WNCoqmzC/AeCZrukMeM3gxNor31WCgYrDcmSA7v3nAOTCRC1b0ieLy5+jO+egY?= =?utf-8?q?SYSCHUIZjItQup17HRDLJ2dOes+i1T1MDok3xk7JzpSRQe6G2HPVMa+nGJADwlqo2?= =?utf-8?q?l0iAKIsSqa1X2ZnMkKN1rSXuOsLC+EIZ0zRtSk5ZrBAn28Oni2uyEFG2IT3PSHiqV?= =?utf-8?q?cI51cawj8ylwrBLbSWn8W68tXe93FikP3xeOhRLEX+MsN42SQ/CU3PsCQGHksDrFe?= =?utf-8?q?GWAi6HrFqenejYD9LYOdlWIt51j+S4W85MH78udN9sZEcOB7vXHpgYLAvt68lJx2W?= =?utf-8?q?xDp1DEZY99CYj8eAOqoS9bO9zvv1bMLUU30HMlXiCbHC1W5f4dx8bnq17N2suGKLM?= =?utf-8?q?rG1hfTtRFA81qKb/C2clzAGSHH8KOtGFHMJ6mv5JIAx/3EUsOaOnpXjL8mN0p5+ph?= =?utf-8?q?JpOMCN4EV1EYfjYoGNtbjdt9P74bSm/+mVJXpX9Wzc8/soBqI5d8Hg0K0gSBTXb5T?= =?utf-8?q?8iU6pN44AIyaDyUN5TDIAaAz6EHoy78HmXLYkdfIfPcL5Kw0Kf2ybGapCFTaHMusG?= =?utf-8?q?28CRr9UNVc+6EiKRSl44PrCi8v0ButXMZPtWTgdnGEqYxwRjIOob+c/6NkgHlHzan?= =?utf-8?q?Hrcb/GBLgWtXgifu0SAxhwoAbEFa8G3tCfsD3KiR72IQ2v2A0e7dS3PhVlL2jYYHv?= =?utf-8?q?edJjQFdMBtvCr4WD9DqEo5VykR0xy4RHcnSagZmkwFy6mG1yGh0AakzoclkKWH+qS?= =?utf-8?q?hq5i7NBerdwtBIadvB8iHVAKOGYEguwzzijRvpA665Ocx5qb6cWhPaUKM3MQHviZH?= =?utf-8?q?MgzB/P0J0mXKI+Vvctzo1DvlHwp8ZRmWgqP4Na8nm+STbcgAoqieTYjFQZivFGvX6?= =?utf-8?q?8N3mE/lhf6Bhzitg?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce030ca8-d55c-4c13-12e0-08d95de31a71 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4553.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2021 22:47:03.3139 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SZ39sA6Lrf+IVdh3+PyQTPtW101HQOwHtIgefBfob18+qlRRroibTSawrNobcbm+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4555 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Babu Moger The test ./x86/access fails with a timeout. This is due to the number test combination. The test cases increase exponentially as the features get enabled. The new machine adds the feature AC_CPU_CR4_PKE. The default timeout is 180 seconds. Seen this problem both on AMD and Intel machines. Test fails with following messages. #./tests/access qemu-system-x86_64: terminating on signal 15 from pid 20050 (timeout) FAIL access (timeout; duration=180) This test can take about 7 minutes without timeout. time ./tests/access 58982405 tests, 0 failures PASS access real 7m10.063s user 7m9.063s sys 0m0.309s Fix the problem by adding a new check to limit to the number of tests. The new a check limits the combinations with more than one reserved bits. With this limit, the runtime goes down from 7 minutes to approximately 2 minutes. Signed-off-by: Babu Moger --- x86/access.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/x86/access.c b/x86/access.c index 47807cc..c71f39d 100644 --- a/x86/access.c +++ b/x86/access.c @@ -315,11 +315,14 @@ static _Bool ac_test_legal(ac_test_t *at) return false; /* - * Shorten the test by avoiding testing too many reserved bit combinations + * Shorten the test by avoiding testing too many reserved bit combinations. + * Skip testing multiple reserved bits to shorten the test. Reserved bit + * page faults are terminal and multiple reserved bits do not affect the + * error code; the odds of a KVM bug are super low, and the odds of actually + * being able to detect a bug are even lower. */ - if ((F(AC_PDE_BIT51) + F(AC_PDE_BIT36) + F(AC_PDE_BIT13)) > 1) - return false; - if ((F(AC_PTE_BIT51) + F(AC_PTE_BIT36)) > 1) + if ((F(AC_PDE_BIT51) + F(AC_PDE_BIT36) + F(AC_PDE_BIT13) + + F(AC_PTE_BIT51) + F(AC_PTE_BIT36)) > 1) return false; return true; From patchwork Thu Aug 12 22:47:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12434383 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=-15.7 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,URIBL_BLOCKED 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 30BEEC4338F for ; Thu, 12 Aug 2021 22:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 173F16104F for ; Thu, 12 Aug 2021 22:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235927AbhHLWri (ORCPT ); Thu, 12 Aug 2021 18:47:38 -0400 Received: from mail-co1nam11on2041.outbound.protection.outlook.com ([40.107.220.41]:9504 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238399AbhHLWrh (ORCPT ); Thu, 12 Aug 2021 18:47:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ESSSZXzegywExf1wb3WGX5eOh4B3rb+yi7BW5m3Au5fEbIYJfeUBiXx475nCqfkqWWrRpxZVx4jlQm6F676jOhI/+TVpCWx/K+p3vkh1t0LD5prR/gCCinxmie3s7UhCUazBX5WE5nftBBTs78IT4rJc/g09C948gRA8XIJD13qOJtLl0bDbzUczClHRBjOz76KcdCgFX2yPZpnauSM+hwpNNVL1syo1oNYqf4rcLyCkfmrfM8jYCqySJDc40L9eaKo5/2vH/4rHPojE8AiCu5Etlv1wxW3ex5apRdPR3vIaoTlBs0LQrVhYdTP4mEJALG/y63oXUvgzyvCDZ7tYoQ== 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=02R5cXxsEh1F3qCsJALrTO0tr6W4fOR9Ikyoy6NV9zU=; b=UNtpz+92DujR+U25rGvhgY/quHJVkfCpDKz2NG+4Ij1w+PIbO+pGkKaRbPnbLv5FyKCfPkXqMVrdUwRqb58oZswEeI3m+9LxWJetJHVX3CiGoMznw9chZ8p6WtEJalwj9bvWOAZ2cOiD03WGODyvNiDJPpgaK3IPpi+4ZGXj6KGXVfqVGL1UX1WuunMtSQ53IWjzYwIx+4Ad0nwi6tZ/+Nk9PAdB1uhgWCqjXWCC5/bcWLIIP6IlNBy7+Ij4U3v+A5UZv6vqDi1rguUei0dZQa9TmLmM6Q/tAeMGYZEXIP8akddV0WRMh7sxf6pE+TX0Z/q1FSoQz6vZB2QKwAh2jA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=02R5cXxsEh1F3qCsJALrTO0tr6W4fOR9Ikyoy6NV9zU=; b=RiCDfYxfti310kgzOQ9xUj/ADt/VqW/iyg6Ynw8RvsdqkYFMOrcXCB69JFEukloMZHYTQZCq4FcwJ6oN6XRVgCxK57d8eSWTEjQw1OX+rgHsdJKrhIfLFE4+30uRcKgfqWBhdm+8ANlZfDzs+QBLpl4BJmYCUYfqqOo1OVQO1RU= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from MW3PR12MB4553.namprd12.prod.outlook.com (2603:10b6:303:2c::19) by MW3PR12MB4555.namprd12.prod.outlook.com (2603:10b6:303:59::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.16; Thu, 12 Aug 2021 22:47:10 +0000 Received: from MW3PR12MB4553.namprd12.prod.outlook.com ([fe80::3987:37e5:4db7:944e]) by MW3PR12MB4553.namprd12.prod.outlook.com ([fe80::3987:37e5:4db7:944e%6]) with mapi id 15.20.4394.026; Thu, 12 Aug 2021 22:47:10 +0000 Subject: [kvm-unit-tests PATCH v2 2/2] nSVM: Fix NPT reserved bits test hang From: Babu Moger To: pbonzini@redhat.com Cc: seanjc@google.com, thuth@redhat.com, drjones@redhat.com, kvm@vger.kernel.org, babu.moger@amd.com Date: Thu, 12 Aug 2021 17:47:08 -0500 Message-ID: <162880842856.21995.11223675477768032640.stgit@bmoger-ubuntu> In-Reply-To: <162880829114.21995.10386671727462287172.stgit@bmoger-ubuntu> References: <162880829114.21995.10386671727462287172.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN1PR12CA0096.namprd12.prod.outlook.com (2603:10b6:802:21::31) To MW3PR12MB4553.namprd12.prod.outlook.com (2603:10b6:303:2c::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SN1PR12CA0096.namprd12.prod.outlook.com (2603:10b6:802:21::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14 via Frontend Transport; Thu, 12 Aug 2021 22:47:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94e18909-6afd-4e5f-8e37-08d95de31ea7 X-MS-TrafficTypeDiagnostic: MW3PR12MB4555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4me2tAh7D5+TdO65b/sMgXDmDO7xEoWp0VCkgznoC5JtQxxBIC4gNCiP2Wo+81isi2sGXOzOT+H+brGxC5kLEclr+frqOlU+h7RO5XzmEUmBza2HDh3rBjYSDY5cBwa/iROoI0N4dQHM5Ngwu2ipApdtW9Us0EL3NjPkuac7FmUe701riX2BUzWSIaG0bu955aEVJbUv0AG4JFBDF0/8vLmrImabu70++4jrI0mPvi8xU6SYfdMJiirgnCDyK+6675sSZW/U9TApNy+kTI0/cjPYVdq9aWcUpbAy85ecFnLs8rqZvcR8R9+UbSSIJLUTRaYlB+9lvR2fhNQn9hniTHniyHXjNzh/+cy9WckwjtY1IDRnO2KgtxP7KmIilRhBiDknNUpn/qssGSPJCDSs8MaGBkVP0hFhW+Km/XKLvH5mziiRLH157YERd6DlnOpSIoSO3tkRhB8L53sgIKSJkv3G0whyOivinD83cIAx+7LzRSzQvHLWATAJ62jLYYE3qxxuute9EMX1GurGEB6PACpZ+zRzU70T9j//6+kQHCwiEjueiM34J6qbVD3D/tZxSBSP6RbvZKOYUgrOoj9D5JlHSKQyYrWoEvsyia8XNLOnvMW9OIGYfUn/BYhqssaTfT2pLBaIj+tmbsW0J8viqXSaXdX4dbxaeJDVL7W4vcVg1iNOoHGqZEb9mshuHdXCC49BANO3Z9AChzWrcKph5w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR12MB4553.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(7916004)(376002)(396003)(136003)(39860400002)(346002)(366004)(83380400001)(9686003)(8936002)(86362001)(103116003)(66476007)(6486002)(66556008)(38100700002)(956004)(38350700002)(33716001)(16576012)(66946007)(316002)(8676002)(26005)(6916009)(2906002)(5660300002)(478600001)(4326008)(52116002)(44832011)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7hCckgl3JsBRgra7sqtzPLAvfD+D?= =?utf-8?q?GZrjflyJRwGkpwH/stWhTKW+02iXHlmXzbIuSn8Qfm2uF3VHrnp2W2eJT9wFIAw4T?= =?utf-8?q?KS8KJrV1fSWQezlkfjcngReZJsIJRMQtpf6AeqauwV/ntLjBW1Y0xYOorZ0EzacP4?= =?utf-8?q?JhoRxGhVj7AjuY/quzrijRSd797zWG80ZrWKn2zzQpAykC8suRwigZt8aRDcqyEie?= =?utf-8?q?QV7qQMezHVQIhcZGsHDGSaBOjK8byofdWkWBJbtiu6aQ8aKzc9Zgfnsgeg3x0RLQ9?= =?utf-8?q?LVbS5rWDMqleAO2+amcnRXW77CmyqAtEdbCMFlTC7AXK/DB42cEr91uh7o2yHeQxS?= =?utf-8?q?a7gKf88OzgbKKIkVt6rM0q8ZLUbA6J0nSBmBqv+UPwvCWJaDQDK9yRWGXvZxdvc5D?= =?utf-8?q?67U5trKVH2kPXHdi3fylrvfrI5JIobLLB/eb8xidgeLe2jgbk7eJR1z38Y/KLftuh?= =?utf-8?q?TOxfBsRfDlxKZ4GcZMY/ujSTDaBVYoJoPz1pxvJKLApI2BDDRvMC/UbeINBN2CfjT?= =?utf-8?q?Z/oJrR3pM/i4idi0/XpVF0pbILlKHNrtwu1esQlc2+9fe62SfKlM1rLM4Vpg2ZCI3?= =?utf-8?q?2qbIOplAD9S0sJjHudXIAt7OqEd417my1kECMJYh893utAiEDODF6RLBTLmcscVmO?= =?utf-8?q?0ZJVnQP7NvSVHStNYjuxcLAPgvCzy3Osg7dw7LYj3/Zl3Y6LBeh6CnrbHCnEiAoKr?= =?utf-8?q?rQF9HOpOOmmIvRuTMMFNJ5zfCYwXwKicljBU8/ilIxyZX/8Di6Sn8iO1d8UeBCYSj?= =?utf-8?q?h15qsQ2AKpbcgRX77uAU7MqEeXZomdb/uGPXluyXNL8C/wLWFaX3f1c3Lx1w1Hm7E?= =?utf-8?q?dSx6ScE9v/EphNMPjuRX++QffMLV9SS1uSRfLjKe5ZvL4ZJVETJkWg54j1FcffjgC?= =?utf-8?q?Fp6wyHrnq2PJBuZdVlXGPzcicxZ3gBkHayn9p+Hr35IStG0lEW2R6b88MzHrhW6HK?= =?utf-8?q?434g+cNQ/5FbvZzFopaOqTFaoIJUfqSFobhL8UBAIZPtlFywmpqLuWz6Tk9O6z9hu?= =?utf-8?q?qx/39sUTEQ9WtcsqiO2AIyXLn/gMtPmmMN6vZ7xmM+5v28yPq52CTsFt4EKuMlVWt?= =?utf-8?q?1WENW4egfwg0AE+kB5ueLV6Uuj0+/1Kyi7Gqw5FvPEoNJiqBpnF53uuJT50xq88La?= =?utf-8?q?nY2ZobsLtSuQPVyXgp5CcX8FU9YrF1vrsbyqLODvrBi3r1ksPNHiv9It7itcGnl/R?= =?utf-8?q?PCiq1Koijw3tuZKUn6Y/t2PVJ4gamcda6mvwIbaapIfOjZ5L9RVY24grb0/H3PMZN?= =?utf-8?q?NEvUaHl4OY7BYkJX?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94e18909-6afd-4e5f-8e37-08d95de31ea7 X-MS-Exchange-CrossTenant-AuthSource: MW3PR12MB4553.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2021 22:47:10.3808 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8Qov1jMlYQA9ItOKVvs+vTNs/p+ij2wG1wi06B8DarFhhLDvVzCYLNFcbjSVZhyx X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4555 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Babu Moger SVM reserved bits tests hangs in a infinite loop. The test uses the instruction 'rdtsc' to generate the random reserved bits. It hangs while generating the valid reserved bits. The AMD64 Architecture Programmers Manual Volume 2: System Programming manual says, When using the TSC to measure elapsed time, programmers must be aware that for some implementations, the rate at which the TSC is incremented varies based on the processor power management state (Pstate). For other implementations, the TSC increment rate is fixed and is not subject to power-management related changes in processor frequency. In AMD gen3 machine, the rdtsc value is a P state multiplier. Here are the rdtsc value in 10 sucessive reads. 0 rdtsc = 0x1ec92919b9710 1 rdtsc = 0x1ec92919c01f0 2 rdtsc = 0x1ec92919c0f70 3 rdtsc = 0x1ec92919c18d0 4 rdtsc = 0x1ec92919c2060 5 rdtsc = 0x1ec92919c28d0 6 rdtsc = 0x1ec92919c30b0 7 rdtsc = 0x1ec92919c5660 8 rdtsc = 0x1ec92919c6150 9 rdtsc = 0x1ec92919c7c80 This test uses the lower nibble and right shifts to generate the valid reserved bit. It loops forever because the lower nibble is always zero. Fixing the issue with replacing rdrand instruction if available or skipping the test if we cannot generate the valid reserved bits. Signed-off-by: Babu Moger --- lib/x86/processor.h | 11 +++++++++++ x86/svm_tests.c | 28 ++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index a08ea1f..1e10cc3 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -531,6 +531,17 @@ static inline void sti(void) asm volatile ("sti"); } +static inline unsigned long long rdrand(void) +{ + long long r; + + asm volatile("rdrand %0\n\t" + "jc 1f\n\t" + "mov $0, %0\n\t" + "1:\n\t" : "=r" (r)); + return r; +} + static inline unsigned long long rdtsc(void) { long long r; diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 79ed48e..b998b24 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2671,6 +2671,14 @@ static void _svm_npt_rsvd_bits_test(u64 *pxe, u64 pxe_rsvd_bits, u64 efer, u64 rsvd_bits; int i; + /* + * RDTSC or RDRAND can sometimes fail to generate a valid reserved bits + */ + if (!pxe_rsvd_bits) { + report_skip("svm_npt_rsvd_bits_test: Reserved bits are not valid"); + return; + } + /* * Test all combinations of guest/host EFER.NX and CR4.SMEP. If host * EFER.NX=0, use NX as the reserved bit, otherwise use the passed in @@ -2704,11 +2712,23 @@ static void _svm_npt_rsvd_bits_test(u64 *pxe, u64 pxe_rsvd_bits, u64 efer, static u64 get_random_bits(u64 hi, u64 low) { - u64 rsvd_bits; + unsigned retry = 5; + u64 rsvd_bits = 0; + + if (this_cpu_has(X86_FEATURE_RDRAND)) { + do { + rsvd_bits = (rdrand() << low) & GENMASK_ULL(hi, low); + retry--; + } while (!rsvd_bits && retry); + } - do { - rsvd_bits = (rdtsc() << low) & GENMASK_ULL(hi, low); - } while (!rsvd_bits); + if (!rsvd_bits) { + retry = 5; + do { + rsvd_bits = (rdtsc() << low) & GENMASK_ULL(hi, low); + retry--; + } while (!rsvd_bits && retry); + } return rsvd_bits; }