Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751383AbdLATa0 (ORCPT ); Fri, 1 Dec 2017 14:30:26 -0500 Received: from mail-by2nam01on0086.outbound.protection.outlook.com ([104.47.34.86]:30603 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750984AbdLATaY (ORCPT ); Fri, 1 Dec 2017 14:30:24 -0500 Subject: Re: [PATCH v2 3/4] Add support for AMD Core Perf Extension in guest To: Borislav Petkov , Paolo Bonzini , Radim Krcmar Cc: kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Len Brown , Kyle Huey , Kan Liang , Grzegorz Andrejczuk , Tom Lendacky , Tony Luck References: <5113a9d6e76d2c6050c1fba4007068340321521c.1509985085.git.Janakarajan.Natarajan@amd.com> <20171109183425.rhqc5wrltznt5tcf@pd.tnic> <07f23e5e-2747-b0bc-1b93-f83f3982649a@amd.com> <20171115190755.5n2zskcr2d4bmewp@pd.tnic> <20171116172520.4lgdvpcdxuxenxc7@pd.tnic> <2c785f9f-faac-58d5-2efd-3fce80d24c18@amd.com> <20171117114445.iv2s7sm2mjqusztx@pd.tnic> From: "Natarajan, Janakarajan" Message-ID: <8ff957e3-67b7-3986-05ef-3e42bd7143f6@amd.com> Date: Fri, 1 Dec 2017 13:30:15 -0600 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171117114445.iv2s7sm2mjqusztx@pd.tnic> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR19CA0021.namprd19.prod.outlook.com (10.175.226.159) To BN6PR12MB1667.namprd12.prod.outlook.com (10.172.19.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab9bd10c-b036-4ab1-045c-08d538f1f5f2 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603286);SRVR:BN6PR12MB1667; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1667;3:gv6XgOid0bhNqvMCQwqgJU4s7iC+1TIJMpzitGKxvrPTTmcMmAHqEpndAGAcJyvr/AlxYj+imY9y3KJegw0xMK3s9Ja5dC3lmAFCOQs8+bJHhi+95ZWVtZkeYYwcUIlGmCVOmFcyFTh5hRBBLj9s4V9lLSVJqQSVUlUtsrJ7dtBzsrArDTdJsH6OHo5HCqczd1f5vxKv+vK41SZcFGu+ctXPWOH9KhtGlov9KybscSTqgMG/vFMkB0uR/6qQa5lm;25:st5lnG5Ms5KRyJeMyHLftxEYCgsKi3m71hr/XNeM86PMrEnGyRcoReghlVg9/yuH+/QVIPXGik2PplJx5Bly8VPx99vem25KfStYI36JWzUsIn2sRX1BQqWTn8mTgP+DgRJKROJYmYrSdYnAzTIJP/HHBBHxvg5G+xH+P3sZbjtIhrjnxhEj3Ai5pfmMr3ZcbWduKsYTW4L0Rf3xLzbD4d1UaAzJVGLnJXpp6Z7osVgLyOA1yQL6mjniYbzvxZQjHB2zg3xDxKSBw5yh8Z6ndCHdgVIZ54uRigv6gpVEtNewy+ZPfZGgbc1wDVqRHgtIutQk3XuMhpX/0BIIVcbU1A==;31:vmX5DbBpRmZDsfarVjuFuepYkJ0u4G6/4kmhNmJQ4YZzWz8EsvkNIl8fZjVGOPq+WIGro2LdgJP0/xD8sTY2wboWDznF9j2BL6nMVDoDDp+fjS+A4nLZ40LElLcs0rlOPfTy8y80+Gwg+Lqml2QhaaDsAWHhVB2nH8sLJpcO++8XxivJh6OzJ3lAQMt1FPFpUbQlt3O7LNXp+/KxOMjqOYSs6HRlmvNRBA5gD+tUKow= X-MS-TrafficTypeDiagnostic: BN6PR12MB1667: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Janakarajan.Natarajan@amd.com; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1667;20:HXMouhMA2xabbWalkpXIODpTUIakSuKsoK9PXry8zTJy5crA44XR+YM4Nk+7YbblbQrCH0Bp4b7GzRwsgXvACBeC1zHA+BVMrlm/Ey+0ZSAIhGwk6ZBMIOvmBWOqRcm8vNixkcRoH1TOxw2G/T3q0I8d2I8lfC2f6lhl8lbshnesZLVqSN3OidazEqxPufKC36OYH9ysxFyiYJ3uVXG/6UpG/4fOlg+K4KXH4BuNcBaJENU4ByqY8TNVv+VrMrNZ2G7UixNAJNy6fSAHW9ZarFy4rdxokZUd9TMwi38fzcutKWiNQVV8hMj0cz2fV8IRxq+koyt5XMBoMXsIgqdBbri0LMhv7384zdJNMgNuqXNlLJFzF2FJmI0JpCU2oeNylhGiluzXYDTwxH/v9AwQ5gkJtAcMh35PDoVLoaIACgchoD9CV4teIWvS8Ga4dhhujN0ZCj7h/AtDfIuG2WxcINIrl6zldmCP0c9s9hCAaLGXln6tST7Qa6kA+OUmWQRu;4:Cs5zAEcnt5pB9Cao8ByaKZiRdO5vrWaJSdwSW96dXZg2xPYnysaaxt/oCkyuf4DK2w2IWgW1lvLbYwqcz2EHEvAzvFASZ1/GpNm75GjbR8VU4yU8cZ/zHfCVTAkWj62yH3McWlGyb15jn8y1hW+5trDuDHaFg398C9mzPtz9jfvjJrMlAyKYSoPG1T1PBHB7Xo+TCI+dcAw+3RJydhSxA1f5wkkTghFQXeJFlv65S9iHIixXjCh0FfcUu4dNcU5D3hA8jiFSPHSzk8muQDVZNQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3231022)(3002001)(6055026)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011);SRVR:BN6PR12MB1667;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BN6PR12MB1667; X-Forefront-PRVS: 05087F0C24 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(6009001)(376002)(39860400002)(366004)(346002)(189002)(199003)(24454002)(105586002)(97736004)(106356001)(52116002)(23676004)(52146003)(2486003)(25786009)(16526018)(33646002)(36756003)(16576012)(76176011)(72206003)(189998001)(478600001)(53936002)(316002)(54906003)(54356011)(101416001)(83506002)(58126008)(6246003)(110136005)(67846002)(64126003)(47776003)(86362001)(229853002)(65956001)(93886005)(90366009)(65806001)(65826007)(5660300001)(31696002)(6486002)(77096006)(6666003)(31686004)(7416002)(8936002)(66066001)(4326008)(53546010)(230700001)(305945005)(6116002)(3846002)(2906002)(2950100002)(68736007)(50466002)(81156014)(7736002)(8676002)(81166006);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1667;H:[10.236.68.193];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxNjY3OzIzOllJVGNHdXlJVGRGQ3Y2OWZTaEg3OUc5Rjgy?= =?utf-8?B?NmVHK1lsdzhjTGhpSzh4R0dEKzVWY0srSmsxWUZ0ZllxQ25EQ0srT3FRQm52?= =?utf-8?B?WUE5YkJuYWhnSGxuNisxOEpuL05sL3V5TW1YczJJTEdhV1BEejkvdWpWWE1v?= =?utf-8?B?MGV2ZWt4eW5DaEZ3cjVoOGVsNUFXcHB6MG8vdHpHejN1UVMzemdwbk1Nck9x?= =?utf-8?B?MEJCMGI5dDhpS28vVm9BdzJWUnFURHdkalkwNmZ3Y21xWWUwemwzYkREaWhY?= =?utf-8?B?ODl2NHdqZXp6YW12TUVHUnhoQ0hOR0RsSkNhOXpFYnZadjRlSkliMFZjNVU5?=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zdBZX3TpteOkdFPzuET7Dic7dPqWvBlPHEQIh+I3G472+lYLRk+8owAF60aJ5yyJIzHrrcRhIfEtQm6t4wPXiDQNSqhUK6w0+MMBIhhnV3uVOfrfKD7t1UJS4rceM8h5Z6yyQFYMm3Xpp6Uqk4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2017 19:30:18.6564 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab9bd10c-b036-4ab1-045c-08d538f1f5f2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1667 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1071 Lines: 34 On 11/17/2017 5:44 AM, Borislav Petkov wrote: > On Thu, Nov 16, 2017 at 12:00:11PM -0600, Natarajan, Janakarajan wrote: >> Ah my apologies. So when the pmu is initialized the cpuid entries >> aren't available then. > So let's see: > > ... kvm_arch_vcpu_create() -> > svm_create_vcpu() -> > kvm_vcpu_init() -> > kvm_arch_vcpu_init() -> > > <--- HERE > > kvm_pmu_init() > > But at HERE in kvm_arch_vcpu_init() right before kvm_pmu_init() we do already query > cpuid: > > vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); > > so it's not like we don't know about cpuid leafs at that point. Which > would mean that the code can be made to set the CPU family earlier, > before kvm_pmu_init() runs so that you have the proper CPU family and > thus have this thing properly designed. > > Maybe Paolo and Radim have a better suggestion here... Paolo, Radim any suggestions about this. I feel that the number of counters initialized can be 6 and the subsequent code (kvm_pmu_refresh()) takes care of the number of counters to be used (4 or 6) based on the vcpu family. >