From patchwork Mon Oct 21 06:22:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 837403 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2076.outbound.protection.outlook.com [40.107.100.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00B821CF7C3; Mon, 21 Oct 2024 06:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491877; cv=fail; b=u1RpA4MNVRBP5AOv4PUkohaVOrw3cd6dJhjTzLtr+QsCJSZVLyp7f7owDCzlhjiXalHGvvtHAyxAWg3yOkt7Z/97uV9EqfvuXnHbzIJ70QgZ8GXX/qNsKQA9bOGi+xMPqWIPXtwaqDHfjIjhTLpogHTQ+24+j7Bmtxyklx2dD/0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491877; c=relaxed/simple; bh=G9ewBhFcB34xufQPYi0PMYcU4rOHi6JnbgiCsR2/B04=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q63JXfqopthBBN2fS4DWFHTfhQPU8TVAlmWQbmorxuGNNJFPur3ZmPQOQXMcjlOtdyvb0FfdKE4zkv5EfvIftSZZovGxTfequo2TRyyIHODFI5Er+IGuoPEsjnFTv6V2QoVdIm4glgAr2ELka6XRPzR1dE+74IgIoZ3mqceOE2E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=lsE2HV6q; arc=fail smtp.client-ip=40.107.100.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="lsE2HV6q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SJejNHZ5dEOlYhe/pacUmTKI8TiEwI0jBRgNIv9ED3IiC14YvOfkZrvtDlh1+lYDUYhvoeTFHJeqW8KegYYG0rMAipIaf58kQ265ud5Vhj0q0CEjyhpICIHucK2dge6Eor7IaJMaDVUOVVi+xz9DBTv3xtkim4Nv1v56zw82gd099sQ3lk9yEFYchEqZxeWtLU6g82oHJEtlzrx1h8G5DxE2OF3OKP3Oj2CJJJs5ZyPzLOt3ZFoQO+NIH1EfSJuLgIhjeNFAlCqQhU368CtRZirjHepkxaxPdFbq0pYSZ2k4DVne9KQSsJ7zlU6N2zSscNFacRQwU1g0UJWof0+WMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TzQnFEjrJDWgN6nJLiQ+aRhw4kj4MyJ639glRa9Topk=; b=j+AtJgK/ULoZDkxbTp22XyZHY/g1m9AofHjUGiczAae5AUqmeaM7G6DSd180KRVwL6S7DS0CBr3kTF6hUaCjjYxg8pHF4QSs6yGcZFvd1/oxjopdff4Z8/tWH7kLaOyccdf9gRYgin992bWfTHtY0g0v83R90tWVt72v8e/csuHjy9Mditu6XIgkpxe3d+XHFvkvr5CxC+/NbNq4Avvi/ThIrRLe9YOS9iCH8v0WZZmNgNrTMhFxuDIV5Ac2owQ5g3lyaZm8tks0SwMnXn0HvoxxBd6wmKHlO9YL77rZrpNgZ/bv9YxLdA4oNqeWuo94pScZLiGHLCHTN5xEOgWa2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=TzQnFEjrJDWgN6nJLiQ+aRhw4kj4MyJ639glRa9Topk=; b=lsE2HV6qCb7Jjharp5TUwlqk74Km7r/8FVrK5qS/wBujex6Dc3mDm/sD3PxIAhGJxLALxCmmhq/GaV28sSm/6msy85+8wToz0rJ/RWcU/fBo6QMFoWvabqgkEWcc+x9KuYtqgvlKWW6YTLI2+PdQZl9cqAjli8Pl4w0zw3+kJBQ= Received: from DM6PR06CA0043.namprd06.prod.outlook.com (2603:10b6:5:54::20) by DM4PR12MB5865.namprd12.prod.outlook.com (2603:10b6:8:64::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.27; Mon, 21 Oct 2024 06:24:32 +0000 Received: from DS1PEPF00017093.namprd03.prod.outlook.com (2603:10b6:5:54:cafe::8c) by DM6PR06CA0043.outlook.office365.com (2603:10b6:5:54::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Mon, 21 Oct 2024 06:24:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017093.mail.protection.outlook.com (10.167.17.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Mon, 21 Oct 2024 06:24:32 +0000 Received: from chalupa-d178host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 21 Oct 2024 01:23:42 -0500 From: Manali Shukla To: , CC: , , , , Subject: [PATCH v1 1/4] KVM: selftests: Add safe_halt() and cli() helpers to common code Date: Mon, 21 Oct 2024 06:22:23 +0000 Message-ID: <20241021062226.108657-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241021062226.108657-1-manali.shukla@amd.com> References: <20241021062226.108657-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017093:EE_|DM4PR12MB5865:EE_ X-MS-Office365-Filtering-Correlation-Id: 1dca4eb9-5c18-4936-9257-08dcf1990693 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: JXxvTao7L6hVLMEXiH8k09Rtimt+Pj/msIFjDASvubTVkhRRQ7GEXLsxVX6kDLacG+4fZatOVszAWtHTXnCs2EscaPsziRaZozarGiIkC+zbsn6Ub1vwDun925NhHYpUG8nqXGi6imcxbUcNxbajgrqzW+XCflvzZsIR/KSxDtrEcDoVjp0pn8scGTcgvfFRV4OTc7HrolWNa3pqCfIg0+wSTce9dEm0XEundwfcRWi6gtiOYkubkwfXHF8/qXJ8MehzCiD7piQJXdbtLtVy7+pyTANxu+1pkQGJwMCaQ/lH27ugHQQB3JiFmvl7sQvsM1ei1TwriUuj15UbFQj0hCkKam1OcElWQm66GdO+m6XYZYZ/UbQRVEleFMKYtV/8j/5Tw/nUaCsH/NYt5kiquUpRAUjlG3qro+sSxwDjsn15+64meOq4dvkLejGTlNt5NbCLwWowAo3RIbId0ovaBjX1xw1Ani1VHV/XbdmU/nr+Yw4qbV1qcssoRnB4rBBeqOOOjwlWwrunyDscaTRhyYnqzWNfoMa5KAYDKEx3Ys+lBxL7FY8bP251cr5cDLrHwp87V/oRKJLlxiiA8YEPAO3rXprWByqaBSBo6TNlVtdNK7Pi4ZvwWO1tzMReCC4dqW8f2atxkqXIHhBAp4vLmyciepwEoznXFSIhYotxuqmHz5Z1wkEFebUBwIfkb84uJ/o2kd3CA5/ZVsE9v0iZVJBIOEyVpVE2l9qy4Z8vgXdf7grq5azjXaG4oEpQEKZakZvmbduwr1IJmimOYK24yF7ge7clL89Yb6pbOumIGbKvL+4/uOkppdgS3HwptY9uOy3MJ2hEIJkq5dkeWuMypbvmdRYiYEtm0aDaUOBz/Y5Tdp6v78FQbILFJTgTnmNEOiG8Xck+yzCv4OCXfZY8jVna7U3Oe1n59NfMBk/rCsssEYG9mqOmZp4HZBlHbLHPisl8XeiCcEQzl57XwCHBFudOdrEuWttkTugdRuxnyEpxAKex+F58LaJsAW/N9HmsaaDUWLfGtNW9kNhsOWwRV9AOf8a0pVPncR4ez5yaqATeFW66o4kwi02UFrsIRqTznXcYZO9P4OaZauvoo38VYTtjvLmBN/ZkX2l3A7pnN5z0wvG+6vP+0otuA1f2he1hNU/bkPZKr2QkkYYK9llLAeSF17tPhwuzqwAzWwRzs7ZkiT6wU/Oum96ugTgHTJPM+A0qkYoVjf/Bm9AnGcuLL6h2r8/9R+mwBTpSiq9YTaCRuIYOLJWWk56/7CaRCMJIVNcXIeBgxIHSOEE+hEL+IztnmX4UK4lL+5tXeBlvCifriLXob8GunAe2RFGgiEplRsndJGh+tYKy5gfH+osMIdS/0k93m4VSXHbHvBywbtLloKCIkvJ4owgwM/KyjH1bK6gxlhPU/V4PsYFk32rR0w== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 06:24:32.1298 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1dca4eb9-5c18-4936-9257-08dcf1990693 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017093.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5865 Add safe_halt() and cli() helpers to processor.h to make them broadly available in KVM selftests. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- .../selftests/kvm/include/x86_64/processor.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) base-commit: c8d430db8eec7d4fd13a6bea27b7086a54eda6da diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index e247f99e0473..8e36de85b68f 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1325,6 +1325,23 @@ static inline void kvm_hypercall_map_gpa_range(uint64_t gpa, uint64_t size, GUEST_ASSERT(!ret); } +/* + * Execute HLT in an STI interrupt shadow to ensure that a pending IRQ that's + * intended to be a wake event arrives *after* HLT is executed. Modern CPUs, + * except for a few oddballs that KVM is unlikely to run on, block IRQs for one + * instruction after STI, *if* RFLAGS.IF=0 before STI. Note, Intel CPUs may + * block other events beyond regular IRQs, e.g. may block NMIs and SMIs too. + */ +static inline void safe_halt(void) +{ + asm volatile("sti; hlt"); +} + +static inline void cli(void) +{ + asm volatile ("cli"); +} + void __vm_xsave_require_permission(uint64_t xfeature, const char *name); #define vm_xsave_require_permission(xfeature) \ From patchwork Mon Oct 21 06:22:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 837966 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2068.outbound.protection.outlook.com [40.107.100.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CA0EBA27; Mon, 21 Oct 2024 06:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491878; cv=fail; b=D75MICN0zxNUW5yjsmKmSSviecIVZSf2NG7/X5w4r/Z3pjR+Udo7Y0s4UtJs1UnEycaZOKww2NP7hiQaTXGIDCaMBzpNoNzwJNvhYOBbJHnfOB9tVOsgr4U2umjhm8s8K8v+EFnPPOmz7tC5xjGe+jT3+UVGIFs6jg78z14a0Eg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491878; c=relaxed/simple; bh=JA4rZrHAdDI6B9C4XI7I4TI5z7jmh9LATs4CwTYF52s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZQ+u/4WYoO0bXERLEPRTajFoILIiFhOgBSRa70vbfEqCwhFH3KHN46mZvU8WL3h2z9nGeOQWtYXgRI+gRvtpB8XvYlTXb5TTV8IWzfo3HmDaxYF01Tfi0A86xdj+vSOOnzULDKULhrHUJBrMUjct3N5KwbJmaJCSc2qFJCv/GKo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=JWWROcCT; arc=fail smtp.client-ip=40.107.100.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="JWWROcCT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LBYmfmvqWSYBYD6vMXku9CZOmUnq4zk+7eicOFSQcWrMcB9R9p8h+K0u2dfvASJQK/PTAOnLPEQCEoA5eCtXKBcQO6k0ZCp2E4mz1fXJLnh5nRqXKr4Psxpy++pnlxhUZamAY/hIHSLl3+Ep+icVK2ySStikxzrlk+2K4yrXaDAVFP4qngnWxsrqAtkW4YCAXg7T+EjoswCGRsk2eNgMpjUgi0sp+FzPYW/UvulyFiOActgEvl77Ezb3+6MVRKY2/9Pn09PM4EHlycG9agy5M9++rKghzOY183BIoWrJhMnyKLlNKFSJO37bgBgVcJHFLvzgPRVz3ieG3dF1DXX0GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=szStCUFv/aYYwCvuT3Xvfxk5fSKxke5/5su9L/eNTNo=; b=euQhBQzsEYrqcqzMH6I4GukGoWHJ1zYfbJj71HLbBdC4Fkuv6rQahSXIyS+ksDW6ourcv8pcDM1Kwe0rSUZEiNQSHqgoGqB2M2Qtl3OC0bAossNzipn3U4Ym7S/uq3JR30uWacEvcOyCGtnVFXfAmEnX6qsqatFRCnu9rgHVqKOMgihvV/ROxmBBpx0qsWnmDj6l8VxJxFnKEzDiKmjlPhCPvU2KpcvQniW2fG/9ss9oLaH7nEZmU3NQuw6j7yG5hWCrjhQSiukVrkzCjxI0+WezBOzsjgEiCZh6ug9FlYUbkoiPDh3NGLofoZ1dl6uJN8FGtEh2IuGlGdlYpmVgmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=szStCUFv/aYYwCvuT3Xvfxk5fSKxke5/5su9L/eNTNo=; b=JWWROcCTkbniFY0/MWhV4G2PPUK3NZwFYQjRK4I/Oq0+xpEkSm1EEHHWajcntyD+T9rJb8Q+tP8p4Nk2nM3OPMlI9ACHL6xXxSmz3o9jpmFE0bGEIm0lJXH+D4Bfm5cK1lTdHr2/y+HVi9KZQO82BnkI28qd15KLmy1DCRbIrWA= Received: from DM6PR06CA0045.namprd06.prod.outlook.com (2603:10b6:5:54::22) by MW4PR12MB5601.namprd12.prod.outlook.com (2603:10b6:303:168::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 21 Oct 2024 06:24:32 +0000 Received: from DS1PEPF00017093.namprd03.prod.outlook.com (2603:10b6:5:54:cafe::7c) by DM6PR06CA0045.outlook.office365.com (2603:10b6:5:54::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Mon, 21 Oct 2024 06:24:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017093.mail.protection.outlook.com (10.167.17.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Mon, 21 Oct 2024 06:24:32 +0000 Received: from chalupa-d178host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 21 Oct 2024 01:23:43 -0500 From: Manali Shukla To: , CC: , , , , Subject: [PATCH v1 2/4] KVM: selftests: Add an interface to read the data of named vcpu stat Date: Mon, 21 Oct 2024 06:22:24 +0000 Message-ID: <20241021062226.108657-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241021062226.108657-1-manali.shukla@amd.com> References: <20241021062226.108657-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017093:EE_|MW4PR12MB5601:EE_ X-MS-Office365-Filtering-Correlation-Id: 5fd1e347-5826-435b-415e-08dcf19906c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: 2+r7DS/VU7Nmo0u9N/WxwdouDrxwqiEysimSl2ZSCqbEvwyJs1oNcEX9PQAouPuHIO0TlpWK3QqvcN2bJ3khVyVZJZF7KUfWN7A714lh9Ug4u6plpRbRXFBLYtBAuqF3HdaRT56lJtyRRS/uOsb/XfW4hsuCosy8p3vQaZTV6j2bHzgN8DXG8WiB4V2v43fvMjkThJiXdln2FZ+R5VxT/Hne5TD2wC5lduK7/RdUOfS2Xup1zKmXmINbNS7Vgihfj0ovbKLj4tMhJxZ/PR8ceXA0hcEjVw5HHv+0Mb9fGSmGF2u3uxSfAQdabSzh9crzD2GSFs7qvID84DtNtOk6bEBAWXzNDeJESmPYQUSpox/a+pgg3i1G27/U/cJQ/Q5dfh28K2vYCFerBMI4eEKLmfXF+u8/z2+L2IuDc5A3S+SiEdj7mSyFFaPf6M5p79PIa5atl+BJMtoQPDqkJUr1vqw+TNYZeukXDJlSdltHv5qPVvNhik8UgzDr1LTX4OihLOjQcI56cEL1Z5mV1HzNLi1Cjlr9UP8zXgQYAG1ySiTStcYVlCplngMshrFMD5Jt2xauY5Z84wXRfm2O+HnbazTUKeM9xYVkmgGQ0ffbON5yJcC0swKJQi/3P+XCEOT8eacLpCje+FuaVlzUMw0qjVIPhdKZtOkUH+5wsrBIxdPnpFhb96sP2kH4VJ0C8PTaMleK1PX+6DdUiW5Pxx+CJX6WJZgEaWWoCcBS6sMa+ppku2t0K4bSQbwc9tZqUop28NRcqBomiXcQK+1PNMBEFe4nv/mC8R5kO56lXV+1TDYYGv2sv7UILbEh4rSnWeac+j0E+ACd4YQxdhy5TR7F2ruoTuwsD5bEXbFmCxA6lG60zc9gh3pq23H7JLsQe/iv5fO3K+ifhJtAJgCLoYdFPHcuBHZxvR+X3rILgcA77LhMRFmcMLDwaXVF8f6SXG4NLV9gC22W7LOFMsesE+p63Z5CcyC1Mb966DbHNPhrtic6lRqHWSpweH1qqmfLeNA+8T1VQeE7xAjJOJyVVxQWon1dM7yF1ZHVA/wc0qZO4ZlwpRNgdOocgNbdqeODkAdvBmMGFKQhQ7rUyjB63uLX9FocdVDYlVx6qcop0anHYknKI8auFdb1hsDPh9aFb6fBivwCoqLgm4v2U9t07ECG3hATAOOwxiZmqYf8dZlg4zZHfdn9wqne8bMu8dBZ6Sa/Rsx9f5O0vidfGx1ItPBQyQKIGysz9hYI/PURs76lov4c5Tu6Ogw6+oCrBlDlYZmb+aWePJ0xxvL+YgRiisdAhtWsb+u607N9stniAh7eiPFBMJC0aAI2Vznh5LT+TubhPzBNMCK9/ZiCN5GO6j0gzNACQDoouFXr5AMg6bVqHDWf5ooHXYYE+hp8msQcRWet6VeWOnjnWYyYdJ8siyah9A== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 06:24:32.4423 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fd1e347-5826-435b-415e-08dcf19906c3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017093.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5601 From: Manali Shukla The interface is used to read the data values of a specified vcpu stat from the currenly available binary stats interface. Add a concatenation trickery to trigger compiler error if the stat doesn't exist, so that it is not possible to pass a per-VM stat into vcpu_get_stat(). Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- .../testing/selftests/kvm/include/kvm_util.h | 52 +++++++++++++++++++ .../kvm/include/x86_64/kvm_util_arch.h | 36 +++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 40 ++++++++++++++ 3 files changed, 128 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index bc7c242480d6..5dd3acf174f8 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -531,6 +531,14 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, struct kvm_stats_desc *desc, uint64_t *data, size_t max_elements); +#define DEFINE_CHECK_STAT(type, stat) \ +static inline int check_##type##_##stat##_exists(void) \ +{ \ + return 1; \ +} \ + +#define STAT_EXISTS(type, stat) (check_##type##_##stat##_exists()) + void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, size_t max_elements); @@ -542,6 +550,50 @@ static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name) return data; } +#define DEFINE_GENERIC_VCPU_STAT \ + DEFINE_CHECK_STAT(vcpu, halt_successfull_poll) \ + DEFINE_CHECK_STAT(vcpu, halt_attempted_poll) \ + DEFINE_CHECK_STAT(vcpu, halt_poll_invalid) \ + DEFINE_CHECK_STAT(vcpu, halt_wakeup) \ + DEFINE_CHECK_STAT(vcpu, halt_poll_success_ns) \ + DEFINE_CHECK_STAT(vcpu, halt_poll_fail_ns) \ + DEFINE_CHECK_STAT(vcpu, halt_wait_ns) \ + DEFINE_CHECK_STAT(vcpu, halt_poll_success_hist) \ + DEFINE_CHECK_STAT(vcpu, halt_poll_fail_hist) \ + DEFINE_CHECK_STAT(vcpu, halt_wait_hist) \ + DEFINE_CHECK_STAT(vcpu, blocking) \ + +/* + * Define a default empty macro for architectures which do not specify + * arch specific vcpu stats + */ + +#ifndef DEFINE_ARCH_VCPU_STAT +#define DEFINE_ARCH_VCPU_STAT +#endif + +DEFINE_GENERIC_VCPU_STAT +DEFINE_ARCH_VCPU_STAT + +#undef DEFINE_CHECK_STAT +#undef DEFINE_GENERIC_VCPU_STAT +#undef DEFINE_ARCH_VCPU_STAT + +void __vcpu_get_stat(struct kvm_vcpu *vcpu, const char *stat_name, uint64_t *data, + size_t max_elements); + +#define vcpu_get_stat(vcpu, stat_name) \ +({ \ + uint64_t data; \ + \ + STAT_EXISTS(vcpu, stat_name); \ + __vcpu_get_stat(vcpu, #stat_name, &data, 1); \ + data; \ +}) \ + +#undef DEFINE_CHECK_STAT +#undef DEFINE_GENERIC_VCPU_STAT + void vm_create_irqchip(struct kvm_vm *vm); static inline int __vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, diff --git a/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h b/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h index 972bb1c4ab4c..3cdc3c856ed2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h +++ b/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h @@ -48,4 +48,40 @@ do { \ } \ } while (0) +#define DEFINE_ARCH_VCPU_STAT \ + DEFINE_CHECK_STAT(vcpu, pf_taken) \ + DEFINE_CHECK_STAT(vcpu, pf_fixed) \ + DEFINE_CHECK_STAT(vcpu, pf_emulate) \ + DEFINE_CHECK_STAT(vcpu, pf_spurious) \ + DEFINE_CHECK_STAT(vcpu, pf_fast) \ + DEFINE_CHECK_STAT(vcpu, pf_mmio_spte_created) \ + DEFINE_CHECK_STAT(vcpu, pf_guest) \ + DEFINE_CHECK_STAT(vcpu, tlb_flush) \ + DEFINE_CHECK_STAT(vcpu, invlpg) \ + DEFINE_CHECK_STAT(vcpu, exits) \ + DEFINE_CHECK_STAT(vcpu, io_exits) \ + DEFINE_CHECK_STAT(vcpu, mmio_exits) \ + DEFINE_CHECK_STAT(vcpu, signal_exits) \ + DEFINE_CHECK_STAT(vcpu, irq_window_exits) \ + DEFINE_CHECK_STAT(vcpu, nmi_window_exits) \ + DEFINE_CHECK_STAT(vcpu, l1d_flush) \ + DEFINE_CHECK_STAT(vcpu, halt_exits) \ + DEFINE_CHECK_STAT(vcpu, request_irq_exits) \ + DEFINE_CHECK_STAT(vcpu, irq_exits) \ + DEFINE_CHECK_STAT(vcpu, host_state_reload) \ + DEFINE_CHECK_STAT(vcpu, fpu_reload) \ + DEFINE_CHECK_STAT(vcpu, insn_emulation) \ + DEFINE_CHECK_STAT(vcpu, insn_emulation_fail) \ + DEFINE_CHECK_STAT(vcpu, hypercalls) \ + DEFINE_CHECK_STAT(vcpu, irq_injections) \ + DEFINE_CHECK_STAT(vcpu, nmi_injections) \ + DEFINE_CHECK_STAT(vcpu, req_event) \ + DEFINE_CHECK_STAT(vcpu, nested_run) \ + DEFINE_CHECK_STAT(vcpu, directed_yield_attempted) \ + DEFINE_CHECK_STAT(vcpu, directed_yield_successful) \ + DEFINE_CHECK_STAT(vcpu, preemption_reported) \ + DEFINE_CHECK_STAT(vcpu, preemption_other) \ + DEFINE_CHECK_STAT(vcpu, guest_mode) \ + DEFINE_CHECK_STAT(vcpu, notify_window_exits) \ + #endif // SELFTEST_KVM_UTIL_ARCH_H diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index a2b7df5f1d39..3ee84e117a04 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2195,6 +2195,46 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, desc->name, size, ret); } +/* + * Read the data of the named vcpu stat + * + * Input Args: + * vcpu - the vcpu for which the stat should be read + * stat_name - the name of the stat to read + * max_elements - the maximum number of 8-byte values to read into data + * + * Output Args: + * data - the buffer into which stat data should be read + * + * Read the data values of a specified stat from the binary stats interface. + */ +void __vcpu_get_stat(struct kvm_vcpu *vcpu, const char *stat_name, uint64_t *data, + size_t max_elements) +{ + int vcpu_stats_fd; + struct kvm_stats_header header; + struct kvm_stats_desc *desc, *t_desc; + size_t size_desc; + int i; + + vcpu_stats_fd = vcpu_get_stats_fd(vcpu); + read_stats_header(vcpu_stats_fd, &header); + + desc = read_stats_descriptors(vcpu_stats_fd, &header); + size_desc = get_stats_descriptor_size(&header); + + for (i = 0; i < header.num_desc; ++i) { + t_desc = (void *)desc + (i * size_desc); + + if (strcmp(t_desc->name, stat_name)) + continue; + + read_stat_data(vcpu_stats_fd, &header, t_desc, + data, max_elements); + break; + } +} + /* * Read the data of the named stat * From patchwork Mon Oct 21 06:22:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 837402 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2074.outbound.protection.outlook.com [40.107.92.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 946E91946A0; Mon, 21 Oct 2024 06:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491879; cv=fail; b=WQZFaGOZ1gDa/4makp2I3R/iX2PoMKB6Qe3vzWSpEnsnYgoRkcgfpz3BccuNWFCU8fQPkYxf5GHnIeLkx+ajBOf8aaj8GuufKf6t8qobIZ8XveR/+/MrUz/k7aJAphSO45dTIdeLiYOqiv4VK+uoXXBRfVtvS8gbGR2iFEQei6c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491879; c=relaxed/simple; bh=LGVNcsmGjBeXtZsxcz3pixZ1uoltgNyVDFYA/Qr3yRs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jQCuC1MnHqg7nEv7Vo56oo3bl8bitd8lj+7ost/PhtZeyU8O0m0tU+gEXYkMWeTm8YhcMdt/5R28dr5OQEEVFU3M4UBuylY5+LUPc6gK2z12O0TZULF99L32JtIL8oXA19XPHME/r9xdmnuG4lXdSporngNlpTRwa0vsZdTUCpQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=dvjXzAms; arc=fail smtp.client-ip=40.107.92.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="dvjXzAms" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vd097029CXiwxwZc2/FrscIzUQHHksIbWbWIA8eKR6YhPC6KsSmrnd//6ZLYYsgct+QQGzEuIYlu9oJz32XFeivG3ZPe4r7gYV3Kn54Oai6MvpaqFKuCSkOW+49/MSTTl2nVrEJb1zIImR2oAeknPhK7C77uMdl16BL5Ukl52srdaYniV269gdfhy6PzZGwosveny/AhZHYKjxo8qhc3TVh3ZqycZkc9x/tqZms/w0XZ+k95AyqSkUxvTixD36MJSz+QvQJEGehSeCmdV/Oxzw04srtzMtQr8kv7EK+PhEdY5Hd2t5bRSQ5HMKG4Mr3TjNyiP6IwDQfladfUl0br3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=v1V+RgIZhLgXnF7NvBaxt5BRFn5EuMI1cUsH1AGFvXw=; b=Z2Xhtyap6pEuZlSqzsf+vQ4M51G77KV8zhFQ53DJ+We5fRUUBY4llphw3gHhVKR8nwALqIKM7NEYvjta+T4lHUAoW18iOIzugx8U3FMgdmmUSd/PAQAT3cecAEK1kmFZsL5BhXsmLF9TpixLlKpHLG8obBB6Mo0tIQfeJFq1tWgfa3iYbDBsRf/HQhjwEwkT6XhWsMGXUCm/xZrrUf9+3JKV6WkxY4/TQhgknQ9tcM2IFLFMTUOaPdlRbJpl1q+9E+l2oF2ekJCA90SEclqLbojFraCEN4DTjY1JXX0KlLxGnq3LiycLf4MgXBUekS3P4QXAHXykoo0Qd61tQgtKLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=v1V+RgIZhLgXnF7NvBaxt5BRFn5EuMI1cUsH1AGFvXw=; b=dvjXzAmsjHPBgxNphrocDUfaHv8TzFAYxiKtIXjI2rxUbzUiIMlS2EW4E6tzK/iewBnvSzQXeyi7zsgBJ679RI9egk4LJEiOcEHYEX+OvMM6pHT5zM733PbvavRZxcxzWpdSi+ZmP0KifY9IoHk2H9V+L6XIYDPXNP2KGwkEtzA= Received: from DS7PR03CA0036.namprd03.prod.outlook.com (2603:10b6:5:3b5::11) by BN5PR12MB9512.namprd12.prod.outlook.com (2603:10b6:408:2ab::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 21 Oct 2024 06:24:33 +0000 Received: from DS1PEPF0001708E.namprd03.prod.outlook.com (2603:10b6:5:3b5:cafe::8b) by DS7PR03CA0036.outlook.office365.com (2603:10b6:5:3b5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Mon, 21 Oct 2024 06:24:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0001708E.mail.protection.outlook.com (10.167.17.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Mon, 21 Oct 2024 06:24:32 +0000 Received: from chalupa-d178host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 21 Oct 2024 01:23:44 -0500 From: Manali Shukla To: , CC: , , , , Subject: [PATCH v1 3/4] KVM: selftests: convert vm_get_stat to macro Date: Mon, 21 Oct 2024 06:22:25 +0000 Message-ID: <20241021062226.108657-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241021062226.108657-1-manali.shukla@amd.com> References: <20241021062226.108657-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001708E:EE_|BN5PR12MB9512:EE_ X-MS-Office365-Filtering-Correlation-Id: f52781f4-636a-48bd-8890-08dcf19906f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: Wo8haZxF5qagx2Ss8f+fPcvHlss+8GCDWejOZr13kNj+3vg9LyOLaRzkHGbbJoeX6W3SJ5fQckRqc4KndloQTEZtkfaMV7ow43bq0mwAO4QXyvNz2Dtm5RegCK7Cur0fdsA2FsyKjZRT/aNbTexH3OX2wn7LTkEkSmwrU1r79VRDc0BFjgZNbACwPc/Dt45ggJIRMCAfnaJ5nojBJabX1td1eyfKtAqM4eIYeOeJAgcMOkxMxe0p8CcA7J+Kg1DZ8hT7aLzke6KEbDoKl52xJJU6t0siFr/M5xIk0q28IWYbPLm7mAkMKK7CL4scnmrxeQX80B5OvD8YVDyfDcrr9j5FnYlxbyTvfAoU+BLYdFvUXbSup0ixeTtMxvDz+RiIWj5dLG7Vrgn3HypMsq48YShkCq14WJeOQQvbwnyfLK8skZNKdNwOQxcdIjm9aqjwh2/X/Xu9pC06Bxv7Ca85gdLgJqpUVbhNT2CHjjlHDJXPXSH0/GKq/np2obFSXWhVzNJJhCEtAVdZJvP0l/5QcBLA/tpiDpuC6xE4umLzSyC5OxStallMvalQRijpQ1iZLUXl+/z+iYUU6F2eivXOOBXvTxE0gT3nlvRmOH6+JAWnue4IQLyduKvJr1Xn4lCRbz6NzGccs/suUat9OKsYubzDsWJf7BBCoSTSKdnLPDceAO1mRGOY4uihB4K2Ye8P7/e7nVpipog3zh1wwfEbv9DwSd5J6oA25C+iu+PtW31UYM7IcwUTk1Ku1C+hVkEDtEhETogWvWclROGdmv3/9z9c9NgmFhWk75GHKWhxQH2qN3LmaGqw+n8I0V1+h8G+UQNFjjPvzPnNWMKGw3UnQuBKEkDW799+3x86+L+rKAHnsr+2jByWqMNRRpTnVVqIzIBTet884rdwHuK6huBRj7jCktGq/VvRxZacE9E3l4lrONUMJqv4Xv4JwhWvcLZYS5i0UgEeDpige8LRV/+inCE3+SxCGdtVEOwG4Dv1PFm8b8/fdIJ7sQc3GKlw1EbEfFTNRUGh46RYYT0yLi2LChdmw+dCr9Dbszn2QpB6flHgnACkqTFK1Z/Z72yNHJzzQ7Sp/2zrGID3/+jUHa9t5ZQLhMsex30ffq8LqQD64zGgErLIwqF9tNzDtXRntHar6ej63Sn0zAuQQoa2jBsBIEazt7rtSZPE8M7SpULQ/pdbKyfxTMW/YPjV/mJTzun+5uv2kZjr/760BSMg1a2U6bApn6j7SH9zTtcnhvMP9W+VFv4OlUw4S1sKGash5NVZp3b2WnyVZPd2UhvAChF3Dc80I1ZVbz8KD43z0BpaUVsOreiTmPgtRnyep5dQEhD6EkjnZBoZojsgIV3A5k5Q80FRq96kW1UJZ87/OFI6HA3nneu+qgdCn7KzOSXCgbqLIV2wcP16wdVjsy2hGWybaA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(376014)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 06:24:32.7456 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f52781f4-636a-48bd-8890-08dcf19906f1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001708E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9512 Convert vm_get_stat() to macro to detect typos at compile time. Add a concatenation trickery to trigger compiler error if vm stat doesn't exist, so that it is not possible to pass a vcpu stat into vm_get_stat(). Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- .../testing/selftests/kvm/include/kvm_util.h | 33 +++++++++++++++---- .../kvm/include/x86_64/kvm_util_arch.h | 16 +++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 5dd3acf174f8..bd486a2899ca 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -539,16 +539,35 @@ static inline int check_##type##_##stat##_exists(void) \ #define STAT_EXISTS(type, stat) (check_##type##_##stat##_exists()) +#define DEFINE_GENERIC_VM_STAT \ + DEFINE_CHECK_STAT(vm, remote_tlb_flush) \ + DEFINE_CHECK_STAT(vm, remote_tlb_flush_requests) \ + +/* + * Define a default empty macro for architectures which do not specify + * arch specific vm stats. + */ +#ifndef DEFINE_ARCH_VM_STAT +#define DEFINE_ARCH_VM_STAT +#endif + +DEFINE_GENERIC_VM_STAT +DEFINE_ARCH_VM_STAT + +#undef DEFINE_GENERIC_VM_STAT +#undef DEFINE_ARCH_VM_STAT + void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, size_t max_elements); -static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name) -{ - uint64_t data; - - __vm_get_stat(vm, stat_name, &data, 1); - return data; -} +#define vm_get_stat(vm, stat_name) \ +({ \ + uint64_t data; \ + \ + STAT_EXISTS(vm, stat_name); \ + __vm_get_stat(vm, #stat_name, &data, 1); \ + data; \ +}) #define DEFINE_GENERIC_VCPU_STAT \ DEFINE_CHECK_STAT(vcpu, halt_successfull_poll) \ diff --git a/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h b/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h index 3cdc3c856ed2..6341c786dc9a 100644 --- a/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h +++ b/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h @@ -48,6 +48,22 @@ do { \ } \ } while (0) +#define DEFINE_ARCH_VM_STAT \ + DEFINE_CHECK_STAT(vm, mmu_shadow_zapped) \ + DEFINE_CHECK_STAT(vm, mmu_pte_write) \ + DEFINE_CHECK_STAT(vm, mmu_pde_zapped) \ + DEFINE_CHECK_STAT(vm, mmu_flooded) \ + DEFINE_CHECK_STAT(vm, mmu_recycled) \ + DEFINE_CHECK_STAT(vm, mmu_cache_miss) \ + DEFINE_CHECK_STAT(vm, mmu_unsync) \ + DEFINE_CHECK_STAT(vm, pages_4k) \ + DEFINE_CHECK_STAT(vm, pages_2m) \ + DEFINE_CHECK_STAT(vm, pages_1g) \ + DEFINE_CHECK_STAT(vm, pages) \ + DEFINE_CHECK_STAT(vm, nx_lpage_splits) \ + DEFINE_CHECK_STAT(vm, max_mmu_page_hash_collisions) \ + DEFINE_CHECK_STAT(vm, max_mmu_rmap_size) \ + #define DEFINE_ARCH_VCPU_STAT \ DEFINE_CHECK_STAT(vcpu, pf_taken) \ DEFINE_CHECK_STAT(vcpu, pf_fixed) \ From patchwork Mon Oct 21 06:22:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 837965 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2087.outbound.protection.outlook.com [40.107.236.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 706FABA27; Mon, 21 Oct 2024 06:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491919; cv=fail; b=H2j8fFN845J27FUc5n1BNIiF7UPBKyBHt0Gj5mp6jCeunU5MUBgCClwiFoVCGpI33q1cR1Is2Og8/RHHiI9xurplix1poklCkw5FhHPE31jCNKtx+AKFdDwEuTQoosXRaV1ztGZgS+0aT+MMgn3o7d+FZWnbORkmPrwTOfPye10= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729491919; c=relaxed/simple; bh=pJD14E31clExXzdFCqoH6ZaccMHZfB8lDG+3/jKVya8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bdmqW6zah5NP8tvfqbY9ikYLIq7iDfPNqxL7Cr52XgJZsLI2FKbVYoJOrstaGxopgpXg9cmBKAH/1ZbsTC+BkeAOZZzDZojENykMNMO2vlZNQ+m9Ieltl3Jwvi9O3kjpb2GZTkyJ2soXE5xz4Won9xqSlcXMHUuHzZYRpxheVjk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=yovC6gT9; arc=fail smtp.client-ip=40.107.236.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="yovC6gT9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gjF4PWZTuG8wkiKf+KoJBc95qF3HDKVPRFaSPV4/UDSPAlzHUPXFfQJGt6ar/+dnSCUjrAKuypvw8GFQTNHBCuEbeQR3lOKxdC0j4XzczfybGB6JN8ZXQ6iI+OEEgNBf0UB1F9KHwST7p+UYNFLfnVz+RLZTfQ5ph3LAuI1EtQLgA0iLVZmHXPd1GsQjS9LrEWi+ck6AVP3W2o/NbHcpwt92DAIroer60eynB7vtbKVdAAgAwyjj8P4eYHLA97/jq7gaiTtnfOeWGRUOsok0llDxO7uE3rnPhuDGIW/XUY6Ay0r35ptSKmhn5RJxxom3banVqiKIpvmXOoL1iaDEsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qTkYWsARXFEdh/wm/cMGDCJSL8tCgVGV72PtZCshkSw=; b=bqAUFm4qvwWUISi8B9x4XQcbP53s9rfdyxml+hwCJGQYdwO7Ke3+yKgp7heLRY3UtjnJhsr8k1CdcR9AZJqJ/DEnl/bqnODZLgDdqDRXb+j6lyIupSXxLxYfHeW9N3SJZ9oFkcg5oExI6KEbkOAjVne2FyN5lvIH0N2fNnNfPI3SqgWPczuQNoAfwMvMkoccgtrTzamU1F5Hz9xTVApsu30UUDvzY+LAU/kh3EAvVAzqUA89LnAArzqPXz/nBWNKnPQT76OE6X9JyyvVGPzYpbAV55qmYQKL5ulsYXGplCCnntBRPcIe6lPfqOuoj+ZuKIZBuIj3GovgeEebZpzwUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=qTkYWsARXFEdh/wm/cMGDCJSL8tCgVGV72PtZCshkSw=; b=yovC6gT9rje9Cf16mbpYAqsL7ZctUH7RpXYXTnjIxxrjYXgjQcKG+grtvtvj2N1obVGL3zVmnC9lNluBOXGErlmfXsG5oRvXELO9zWL+JCcNprdKXIzIVarIirIHw2wIGa5D9VwOZkxbUZqPvyG36eK2PYau+HRqrrAIdvz4qh4= Received: from DS7PR03CA0034.namprd03.prod.outlook.com (2603:10b6:5:3b5::9) by CY5PR12MB6299.namprd12.prod.outlook.com (2603:10b6:930:20::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 21 Oct 2024 06:25:15 +0000 Received: from DS1PEPF0001708E.namprd03.prod.outlook.com (2603:10b6:5:3b5:cafe::bf) by DS7PR03CA0034.outlook.office365.com (2603:10b6:5:3b5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29 via Frontend Transport; Mon, 21 Oct 2024 06:25:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0001708E.mail.protection.outlook.com (10.167.17.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Mon, 21 Oct 2024 06:25:14 +0000 Received: from chalupa-d178host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 21 Oct 2024 01:23:45 -0500 From: Manali Shukla To: , CC: , , , , Subject: [PATCH v1 4/4] KVM: selftests: Replace previously used vm_get_stat() to macro Date: Mon, 21 Oct 2024 06:22:26 +0000 Message-ID: <20241021062226.108657-5-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241021062226.108657-1-manali.shukla@amd.com> References: <20241021062226.108657-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001708E:EE_|CY5PR12MB6299:EE_ X-MS-Office365-Filtering-Correlation-Id: ccfef50d-0d06-47da-39ca-08dcf1991ffa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: C5e+8teejLswvITN03e+MOar2EgUo+UcLa7fguS+zNSclYjorGp3xlZ9xrfS9Anhqnl8CPElzNZmUEjZtRFhslWl1aHNoXk1RyRuCQ88o2iAQtc6tiq2guZBt7H1xOjmoFX2xEMiCM1mpo+jn5Pbgp/GfQ+u9ZJsHY6A4EE6AKCQwrxyrubumd226BjgGyUza95PIHxmRTMIV0U8bTu4vXUt6mkipM7VgeSLRRspNvMABUd1qz3mXfYthp92h5ygo/V0g6GC/t46MvzHZwXFxXj5fnNcn4LE6LhcQ9RKzCASFcVZJcbTcAYABP9zFrsIdrmp6Ertp44aZ2TPIordu63ol0oA9fId0rfRvnf9fksKdd3PoLxNQlRccmCilmvAJyn3SzF3MYLMrcFpydI3lHNqp8au5T9/4yi2DfbTyTUdFAiPirhWG4AwXNODQcCFFR3EYj2rPXTtU6YY2ye1UN7cAZmcLIUCj4JxV3mKYcxknDXPzar3gAXmPz+6eZA2CzTSvCqSdco2zfx8snL7dA/rr2TT0BLxsFuU7CsyQhOJJLTikFCuGJOtE5CVOUI2T9/lkjDNBCFLy2ARlgDMktmD+GL2FNw0BGVF00WK+F9LHs3TBLBtxu2EEPTcrEYgIwApssFI7tBx0j3qoLLpHF0zztxgipZ8AxOEuJmcw6IFiA717zf5yjCvIXp1iRaRIf/UAS1URkdJsGN7RcuUor3V1cIbVcEnPnvEJSlwde0usxRNZ5pAlWxGSnVGqsKIYHn2//e9o4t1XziiSE+mjhb3LbloC3+F3u/36yB8mtQs4ExRQwSy2cG0g1900G90MvqQrqD1Es1PzTgnhygZqs/R1rUYG4ed6/vu9jGnR2eFN6z3YNaFL6FpYa4R6RlPvLqFfNgSz4doEF5H5PrW2EMRVSDsUUTOpMXP29GxX9P8mHWxxM3tPJ+kvBC++iTt4K9nX0U6iSuoCXr5oqABpf93Mn9E+qlf2pDt/6zvrPbga529OgkxsiCuAJW+w/lRgsM/dGIfpMknk/5zfEojTwtNIg85C1KM1WKX8ieCM+ODFT/E5jazgCqTsOUC6V7si1Yc4AicaFsS9Cya6W87kvwWXUQw5GkNTiPwNvIlRPl/jbn12LaPwuiXAdSWo5MvigItUkVP6ZzbUgTL2oGx3xH0BOdZPvCEDLZGJ4T1egS8OnYk4K11M/uUohc92eRNUUUaUf1SuUm70K0zH5/OiNLB1UrJbLS1EFzjANPYB1+setdlXBq1W0pxm1sClfG1rCOq/fQQ9/IJDft3f5+oHif8/ezm0YZavO9nDdtlX79cgUdlsirKQCBkYDHgiua3Wd3vxUBPWZSC2WU0DvjQY472suqKPVWGLA9bNRpo7VvvZuZNUcavvbU2+xNvChpWUoewiKQMKuMnGybnWI0qgg== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 06:25:14.7456 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ccfef50d-0d06-47da-39ca-08dcf1991ffa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001708E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6299 Previous patch converts vm_get_stat() to macro and adds a concatenation trickery to generate compilation error if the stat doesn't exist. Improve nx_huge_pages_test.c and dirty_log_page_splitting_test.c based on the macro. Compile tested both the selftests. Signed-off-by: Manali Shukla --- .../selftests/kvm/x86_64/dirty_log_page_splitting_test.c | 6 +++--- tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/dirty_log_page_splitting_test.c b/tools/testing/selftests/kvm/x86_64/dirty_log_page_splitting_test.c index 2929c067c207..b0d2b04a7ff2 100644 --- a/tools/testing/selftests/kvm/x86_64/dirty_log_page_splitting_test.c +++ b/tools/testing/selftests/kvm/x86_64/dirty_log_page_splitting_test.c @@ -41,9 +41,9 @@ struct kvm_page_stats { static void get_page_stats(struct kvm_vm *vm, struct kvm_page_stats *stats, const char *stage) { - stats->pages_4k = vm_get_stat(vm, "pages_4k"); - stats->pages_2m = vm_get_stat(vm, "pages_2m"); - stats->pages_1g = vm_get_stat(vm, "pages_1g"); + stats->pages_4k = vm_get_stat(vm, pages_4k); + stats->pages_2m = vm_get_stat(vm, pages_2m); + stats->pages_1g = vm_get_stat(vm, pages_1g); stats->hugepages = stats->pages_2m + stats->pages_1g; pr_debug("\nPage stats after %s: 4K: %ld 2M: %ld 1G: %ld huge: %ld\n", diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c index e7efb2b35f8b..c0d84827f736 100644 --- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c @@ -73,7 +73,7 @@ static void check_2m_page_count(struct kvm_vm *vm, int expected_pages_2m) { int actual_pages_2m; - actual_pages_2m = vm_get_stat(vm, "pages_2m"); + actual_pages_2m = vm_get_stat(vm, pages_2m); TEST_ASSERT(actual_pages_2m == expected_pages_2m, "Unexpected 2m page count. Expected %d, got %d", @@ -84,7 +84,7 @@ static void check_split_count(struct kvm_vm *vm, int expected_splits) { int actual_splits; - actual_splits = vm_get_stat(vm, "nx_lpage_splits"); + actual_splits = vm_get_stat(vm, nx_lpage_splits); TEST_ASSERT(actual_splits == expected_splits, "Unexpected NX huge page split count. Expected %d, got %d",