Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp100437lqs; Mon, 4 Mar 2024 16:53:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWoktp1r5Bc8PnhCYiDdhLYRb/32XhaIHuEM2mzwgHvOUF2Xk9lvo7tWp2aeRaDwfoNSryPBStf7AoOH/j2RekrVjZrvzvxxu5+2KhOrQ== X-Google-Smtp-Source: AGHT+IEr04/wEMw4cC024HfbMADYznbDvtcQG3H7OB6RNWbVLdSOLghou5qjoV+xZluaX7pyL2hf X-Received: by 2002:a17:906:3c4f:b0:a3f:1530:ab16 with SMTP id i15-20020a1709063c4f00b00a3f1530ab16mr7712820ejg.74.1709600011542; Mon, 04 Mar 2024 16:53:31 -0800 (PST) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p19-20020a170906b21300b00a44444998ebsi4358178ejz.215.2024.03.04.16.53.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 16:53:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91478-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0iORBiK; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-91478-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91478-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 21BA41F2255E for ; Tue, 5 Mar 2024 00:53:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 599E0BA50; Tue, 5 Mar 2024 00:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P0iORBiK" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 4F5B49460; Tue, 5 Mar 2024 00:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.12 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709599935; cv=fail; b=PvKMP1jKCjeaPQJn99THP8WVUkbi8yuAZR9tQeS1Lht1gr2I5BfVkZxU5HYxWtua7A54Cz3uWwNRxEoxQZZvjHteC0/Nb6A2gMp7YtNZicj1WYcki4aUzhNU8tzxJ5yLZD5SIos8OZWE+dDZA8EZS/MruPWoqZ6AJMm6p/Tc99w= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709599935; c=relaxed/simple; bh=EcZUQMr8YgEtutGpgHzgam4wxPigXNpQh9u/5sqt3uI=; h=Date:From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=ixy+2Z/RmgGq+L4lGCkZuzn+lWarPUFXEE2T3F7dXD0wEGLvdjB5O1tcgkymbUHHs+nLnCEvJVPOtO3yIdDoSS/bsVP5PFRmi8aCNq3xzrf7QC2I3Iurx4E7au3BQ9JrIPx7nPxJLlGo986+Bhx84+350HaFFs3Au7QgxXcrGdU= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=P0iORBiK; arc=fail smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709599933; x=1741135933; h=date:from:to:cc:subject:message-id:reply-to:references: in-reply-to:mime-version; bh=EcZUQMr8YgEtutGpgHzgam4wxPigXNpQh9u/5sqt3uI=; b=P0iORBiKVhowyHEwaZhTrLeGBF0gkM1ib0MHQLkRuu45j5E7uBZzpOZ3 LEfdU/78F/8aDUHHaNIfNNww4hh4S4iukw64qqTWHTuQ8jhCg80vsmExo dO+Z8mnnak0cHITZwUMWNMx9pCgyhAkvunzN6Q0hmEm89KSmqFTq9Ybqt pMq8IVAKRzIxwJ5S66NgDGP8xcrl6aeHIABXezVgkFCgqP8+D7ZAoaiBA tG7BZgiRqkvdSPxle6rYHMzY23Qfrwry6Qu8Iw6Mvqc5/+c5UoiTxF5X1 TfhWK3IzVMivPfAj4VLMO/XvLi0BhnkToo8i13NBaKnCqZ9++0sIkUCHt Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11003"; a="15557129" X-IronPort-AV: E=Sophos;i="6.06,204,1705392000"; d="scan'208";a="15557129" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 16:52:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,204,1705392000"; d="scan'208";a="40174364" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmviesa001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 04 Mar 2024 16:52:13 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 4 Mar 2024 16:52:11 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Mon, 4 Mar 2024 16:52:11 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.101) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 4 Mar 2024 16:52:11 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GHvB0POeEKlSLSGCG46x6jZ15id2/8GbXmCMiI4DEqPa38WQH1LUW64PMFIPiufz+sVWYCkkDb2Aw+Na0HlvdQ3JmF//oza4dsx/zMAMVf1gHD9nPR1SOAf3kXeX49iD5da18YyWGPwCae+Uj3T0o+T5xkKqN8C951LElSQvgdpwVFTqD0YR5FJqGEQ6xc3GJ5vY81MGy7kIUUpIZsU6h3C3c0v1AHwITEwc8subIT1uQan6xpWMZtZy2Eu3UbnUGptHMCywkc/l8rtFTrjERbc1FRLyFgM1dvwwWA92U+4bt4KmgdFLLavAfxWcf05tyGNYGj9NljQCAnEYPSBlBQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FU3eRwUUWr7P4LtgaP/kkxsXbIeP+/aoGCkSzirpy3A=; b=WMqoDVRYsMoqbvIJP9znz/hvz2hOH+RukAbwGrRT71IiqIJ9FGCqgx9hAMrYbX6j9z+XYBXRrrNnJeWbZzgMScsd+2wQatx+N6r2a26fxDPLIQ18kNA+7LqoNZR9MoWC39TNuihfxylKrv0QBtKMezcxSMz1D2YR6pB+jV7UM7iCFMpyS4tjn8L7R4yHHQFfI6oTUNgyEfW2bH3XtXaJFuRHTwsggNfwmyd6wdt2p4XJBzdVn+vWOJMfi9xZVMbt0Jo/GrJSbotu5gZIbddI4nndHk2bIR3UkAmKQSiYumqiMokbou2gQxiQVnSJkXEDd1LTlPFqxFbZ1mRzhWph2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS7PR11MB5966.namprd11.prod.outlook.com (2603:10b6:8:71::6) by MN0PR11MB6111.namprd11.prod.outlook.com (2603:10b6:208:3cd::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.23; Tue, 5 Mar 2024 00:52:09 +0000 Received: from DS7PR11MB5966.namprd11.prod.outlook.com ([fe80::55f1:8d0:2fa1:c7af]) by DS7PR11MB5966.namprd11.prod.outlook.com ([fe80::55f1:8d0:2fa1:c7af%5]) with mapi id 15.20.7362.019; Tue, 5 Mar 2024 00:52:09 +0000 Date: Tue, 5 Mar 2024 08:22:14 +0800 From: Yan Zhao To: Sagi Shahar CC: , Ackerley Tng , Ryan Afranji , Erdem Aktas , "Isaku Yamahata" , Sean Christopherson , Paolo Bonzini , Shuah Khan , "Peter Gonda" , Haibo Xu , Chao Peng , Vishal Annapurve , Roger Wang , Vipin Sharma , , , , , Subject: Re: [RFC PATCH v5 15/29] KVM: selftests: TDX: Add TDX MSR read/write tests Message-ID: Reply-To: Yan Zhao References: <20231212204647.2170650-1-sagis@google.com> <20231212204647.2170650-16-sagis@google.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20231212204647.2170650-16-sagis@google.com> X-ClientProxiedBy: SI2PR06CA0001.apcprd06.prod.outlook.com (2603:1096:4:186::21) To DS7PR11MB5966.namprd11.prod.outlook.com (2603:10b6:8:71::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5966:EE_|MN0PR11MB6111:EE_ X-MS-Office365-Filtering-Correlation-Id: 91423ad8-8c1f-4be6-265a-08dc3cae7c6c X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QSJL59CNysEdSB6Q+W//thu9jKfn3tr+iPYzXvT4lreHrTtaxmKlTy/UPQ+ibCDsAuQ0/Rajk9jdarKm9Yw4BLJ/D2HuUR/SPSDXsYcLZ2fP7/uEP7W2vQi/Wa2/Sh+KoP+TDiX/la9zQCXdpUojVbXOzltRYIkGXU1hQrfTgUac3PcA/xIzLNzfBq35JSfZuPIAw5Es1gPtSr0Y/vGn55hDS/XX7di2QndAAyfmVTCdMPXiHShbISYwyAL6CxWvWWfIbOEHLCDwVDCZGgK/MorYuO46aujXxhyCmv14YCwRl1Nj8GppUWhJe1q0W9DF68VgYWeXrNUeo6w5xPNxFrnMzeSFvJOIDQ4raJufHHUQTK/DFMPKzjoDXIdu70f99O1Vk+r1OByEKVhtmSuXlMZV98tcbTZcL1vp3dbWwBJVdw/dMuCErANP8vomFEtQAPVtswzLmxafDae3o9VrmEbSrx5grLcHtm011VQabhXC4JDoL3UoZx1zX0tHZ6lJf0Adr4zURQTydhzJ075kaYZKDf+fOHU7tU3qDXqXXyo6IrQ8OA5ZLDsSMrdsdm4K8jenYMzIDLa1XrkIgixKjU94VseBk2NjAkItvmdjoJuu2PmGU6iTE1yK/GQE8KCYPirbeIYhtPFgjRfU9XFYr3oTzdKD2VbPUpH3klNiC2Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR11MB5966.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?3KcUKitvZODug1855T9I0KePPw12buOX4bdFMYiV7hdIb2ONE+o7Vtco3Iku?= =?us-ascii?Q?IHcxxKRBZ1B/jAiWG4sVUVT5aFXELGvyCm+g3b59l9fo5Mk+q5TRJO4IlP0O?= =?us-ascii?Q?LsZ75gtYYpYbh8SJHzbK+BNsJ+MynZIrEM6plbdL1hqfyXsZONiM3GkwJWq8?= =?us-ascii?Q?lG6PbWBS377aNErLYcavY1UDaX3HdOW7o81EuTxmj2RFwI3nZS8/ok0AveiS?= =?us-ascii?Q?8tq/Ucbnztbi1FKAaJjgcyLoBHm9JuioYSBE6cC6U48QbK9nQBsFzrkLJaI8?= =?us-ascii?Q?iCblz+Ah4YRxpTuziLAVixloGLK0eBVXwM/YVyvLFIW7sgCUBcPdH8RTmMxa?= =?us-ascii?Q?CZDN462W+IueApG0Ec7ohI9aT9QtxPViK6VL5bQ0wNGOyI291FRm2y0Zze0i?= =?us-ascii?Q?BHR+y3AYoq1ThEhGW1Gj0vgLi//9tmx0jx3E59cxUOjbmb4D7NnqB5Q/Avt/?= =?us-ascii?Q?4ea0LSnuXeHxylb1d0RG9Q5BeUI6FX5XnilpFjMEzo7GaqPyU5V42Xb1gt2s?= =?us-ascii?Q?x/vx+bgIFOo29n3oAVi3FpZtm45t9bHYx4wc3NWZymTtJ82fsSDC/RhFgRTo?= =?us-ascii?Q?xsYagrkg+xSf4ou75zqVzKeidpbAyY5rt4BXJYFUlfgmmAmQhtVhrjPvUKw4?= =?us-ascii?Q?nGf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GTYVuF9z+9boHhbF?= =?us-ascii?Q?uNQkmRUrFfwmcmX/vESPGYbfpMSbtM3HwVG5cPYE?= X-MS-Exchange-CrossTenant-Network-Message-Id: 91423ad8-8c1f-4be6-265a-08dc3cae7c6c X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5966.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Mar 2024 00:52:09.1127 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yqJZ6PuuLOoaMrWIquVVJ6JN7h4KS4ZE/ZgmtNl+6o+OVGdyRI0Pf/WDqXSnpTktqMajYtZlWU21YrEsy8GAuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR11MB6111 X-OriginatorOrg: intel.com > +void verify_guest_msr_writes(void) > +{ > + struct kvm_vcpu *vcpu; > + struct kvm_vm *vm; > + > + uint64_t data; > + int ret; > + > + vm = td_create(); > + td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0); > + > + /* > + * Set explicit MSR filter map to control access to the MSR registers > + * used in the test. > + */ > + printf("\t ... Setting test MSR filter\n"); > + ret = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR); > + TEST_ASSERT(ret, "KVM_CAP_X86_USER_SPACE_MSR is unavailable"); > + vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER); > + > + ret = kvm_check_cap(KVM_CAP_X86_MSR_FILTER); > + TEST_ASSERT(ret, "KVM_CAP_X86_MSR_FILTER is unavailable"); > + > + ret = ioctl(vm->fd, KVM_X86_SET_MSR_FILTER, &tdx_msr_test_filter); > + TEST_ASSERT(ret == 0, > + "KVM_X86_SET_MSR_FILTER failed, ret: %i errno: %i (%s)", > + ret, errno, strerror(errno)); > + > + vcpu = td_vcpu_add(vm, 0, guest_msr_write); > + td_finalize(vm); > + > + printf("Verifying guest msr writes:\n"); > + > + printf("\t ... Running guest\n"); > + /* Only the write to MSR_IA32_MISC_ENABLE should trigger an exit */ > + td_vcpu_run(vcpu); > + TDX_TEST_CHECK_GUEST_FAILURE(vcpu); > + data = tdx_test_read_64bit_report_from_guest(vcpu); > + TEST_ASSERT_EQ(data, TDG_VP_VMCALL_INVALID_OPERAND); > + > + td_vcpu_run(vcpu); > + TDX_TEST_ASSERT_SUCCESS(vcpu); > + > + printf("\t ... Verifying MSR values writen by guest\n"); > + > + TEST_ASSERT_EQ(vcpu_get_msr(vcpu, MSR_X2APIC_APIC_ICR), 4); > + TEST_ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_MISC_ENABLE), 0x1800); It's not staightforward to assert MSR_IA32_MISC_ENABLE is 0x1800. Rather than assume MSR_IA32_MISC_ENABLE is reset to (MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL | MSR_IA32_MISC_ENABLE_BTS_UNAVAIL) which is 0x1800, why not call vcpu_get_msr() before guest write and compare the saved value here? > + TEST_ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_POWER_CTL), 6); > + > + kvm_vm_free(vm); > + printf("\t ... PASSED\n"); > +} > + > + > int main(int argc, char **argv) > { > setbuf(stdout, NULL); > @@ -531,6 +738,8 @@ int main(int argc, char **argv) > run_in_new_process(&verify_get_td_vmcall_info); > run_in_new_process(&verify_guest_writes); > run_in_new_process(&verify_guest_reads); > + run_in_new_process(&verify_guest_msr_writes); > + run_in_new_process(&verify_guest_msr_reads); > > return 0; > } > -- > 2.43.0.472.g3155946c3a-goog > >