Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2459629rdb; Wed, 15 Nov 2023 01:01:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHznKvYaDZZiReCelpFjpTKdH4taastP0OdCwZO7iB2ugnNnIGVHBMnVB69xlROFiJsU4uA X-Received: by 2002:a17:90b:38c2:b0:280:3d16:8811 with SMTP id nn2-20020a17090b38c200b002803d168811mr10079653pjb.27.1700038876245; Wed, 15 Nov 2023 01:01:16 -0800 (PST) Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id g8-20020a17090a7d0800b00280c9b49738si9746770pjl.84.2023.11.15.01.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 01:01:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nkcnb4rl; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 44D3E80842E5; Wed, 15 Nov 2023 01:00:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343525AbjKOJAT (ORCPT + 99 others); Wed, 15 Nov 2023 04:00:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbjKOJAS (ORCPT ); Wed, 15 Nov 2023 04:00:18 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 186F0114; Wed, 15 Nov 2023 01:00:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700038815; x=1731574815; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=mZB7SIi8V32x7+u2APAW1ncuNJ7EVHmfD2mbC+xFFP4=; b=nkcnb4rl0oXKWL5qSmARFqMOQ3Yi+KUgX/J1hBHI3EMLeBOhhBjDKhlW NsSfNGSVKJwaQBEYdm8RlntaSG1IFVMuOVNAXmTepLPByOVKGhTzHE7SU S4jn+CjaA4V4cYKmD1cTcSKRk/RJMwitLF2lJidhae+UjeR+NR6+XHeAW HpbCmOGC7FcG4IFuk50WR8oak1t2+RNpefSu6up8nyDf2vdsLvb/rxCCd p4WwOqBnINzYG07GPsyFNA9nr3O2429VVZyYPwxGVPP1wMVBQrmTWgxSW +DvgLaFXh4h8Gd/dHzVAHzAjmjzt9uoAGpA3n9jStZvnvMi/RKWmy+OwE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="389693434" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="389693434" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 01:00:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="758428340" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="758428340" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 15 Nov 2023 01:00:13 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 15 Nov 2023 01:00:13 -0800 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 15 Nov 2023 01:00:12 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Wed, 15 Nov 2023 01:00:12 -0800 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.40) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Wed, 15 Nov 2023 01:00:11 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zc5T1UgvtvbLPP1+2ebIvMYK4gG0M0oxWpUQ3vm/6IpNKxQblGE5IwITc4LhcxpHtp/LE6OPwPTF4fH1IOR19ZQFggf10nSbBUsn2EB2u7laZoIGj/6nw+/jT+vD+0B36stCsj4NRMwuspntMm02LfAX2SVtvacYUJMxPeTx0/vmwW+aRrNfgHlw3RXMzExsL+Wg/klnqr8ZqNK4UvdXp4NSHXGQqJwGupCCqopYhD7YwaWS0nNPq4rmp1wbNEsb6gP/IcTYctitTZB2Ru9SWqbs1vFs2Zj65KkvIiKf8axWbZbCVzP46OKF7swsmlvg864PgmWVru3QxFGYrPkKPQ== 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=Ss3KfZsva2bKqaqqaFz5tSQYMhw+iGBwRrXStzAaMZA=; b=D6h6bdmFBNgtxYZ3ddkoXq237F8V0CSlSi0rkIFpk6qSIhrZTiLBY9jC5F01kRMDNQNLj5DpZyLxBYEKaBGh8TorYOaCXQVsmGuv9c8+ByOIcQjzLtpS1zwdBUdeYnKsqgolSkGhk/bl63mG+GUyI+6d9jcqbiPGitUTHhgCU4lRCGHmLQ/0lx4VzCuaDKiYiIru/Xm9Wh13HiceIKQDk8c2+qdnqH72+MtPy5VpaXPiZbwYuDwypYbdnFkpekXX5S9SjqChoNgiKCsF1G48M5hqpR/lYXHZpY+M50NzrQAjsVlR/GrSm99uKLzDRZ4FAWXTUfA/CRkDcsaZ6VClvg== 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 PH0PR11MB4965.namprd11.prod.outlook.com (2603:10b6:510:34::7) by SA3PR11MB7528.namprd11.prod.outlook.com (2603:10b6:806:317::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.31; Wed, 15 Nov 2023 09:00:10 +0000 Received: from PH0PR11MB4965.namprd11.prod.outlook.com ([fe80::ea04:122f:f20c:94e8]) by PH0PR11MB4965.namprd11.prod.outlook.com ([fe80::ea04:122f:f20c:94e8%2]) with mapi id 15.20.7002.015; Wed, 15 Nov 2023 09:00:09 +0000 Message-ID: <1d56efce-8417-4026-80b6-bd03ccd26862@intel.com> Date: Wed, 15 Nov 2023 17:00:00 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 10/25] KVM: x86: Add kvm_msr_{read,write}() helpers Content-Language: en-US To: Maxim Levitsky , Sean Christopherson CC: , , , , , , , References: <20230914063325.85503-1-weijiang.yang@intel.com> <20230914063325.85503-11-weijiang.yang@intel.com> <92faa0085d1450537a111ed7d90faa8074201bed.camel@redhat.com> <1e9921f687abe09d8797e6fb83760acf970f344e.camel@redhat.com> From: "Yang, Weijiang" In-Reply-To: <1e9921f687abe09d8797e6fb83760acf970f344e.camel@redhat.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SI2PR01CA0026.apcprd01.prod.exchangelabs.com (2603:1096:4:192::16) To PH0PR11MB4965.namprd11.prod.outlook.com (2603:10b6:510:34::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR11MB4965:EE_|SA3PR11MB7528:EE_ X-MS-Office365-Filtering-Correlation-Id: d04abe68-cdcf-4d23-cb95-08dbe5b944f1 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: fipM1AwUKFTU2+ZYRE2UTiiIa2esBH6543OOfgrK1lj1tRZOogU2HpvydDCMnHaq4A85MrOQ7Ra1/nyA4HPCcI8rIkktyar77k2m/F+BflTLvsI5pq7auyFxotBRTnIe/hPQkxod+kCgH7TkOlRcXVGNC7jp0/z8O9JHx54+yb3j9/zSHNN5PRVxe2Cu69FKh9pgAQTL3h0s1wvUiwocAE9z2jG0iaBbFOFdyqk+Lpz169CiV7GP7mRBhs721VkJS+NDy62EzGc24luKlD3SrlsGqWZJcKEcM2S+e7Y5Q3DdxMSjV8SGoyqtUHVLmsYkcaKkyojM1rlarC+629SM5jQnl4DpAupDI8sEWejdREfeAhXvZSNJaoYQm3lSolPGS5FE0WGGRh1IdcMFuk30PbwFxufqwbfp9s7PkEaG9ZGaHyTPHlgIVZv9ywlfHWZ6JhfloS5xOvPNLoI88Nwz+1mh2DMk9swhmJWMKz5tfxGC2TUzYUMQQOvOCzUcdyesWE5eNy2aOAy1aV2O9JUsBeLU+jK8YeAEsSEn/feYvpQTtErMk/wSGxlKfCjMJlm78sjvVTurZKVIfhMPx2mTUAUj6hWs/nK/o4uXpylt62NS8Aaf4JXM+oYn68D2emEZmgOxRr/+E/eRATCGWyHmtA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB4965.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(346002)(39860400002)(366004)(376002)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2906002)(66476007)(5660300002)(38100700002)(41300700001)(53546011)(316002)(86362001)(66556008)(66946007)(31696002)(82960400001)(36756003)(110136005)(478600001)(2616005)(26005)(6512007)(6666004)(6506007)(6486002)(966005)(8936002)(83380400001)(8676002)(4326008)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?QmpIcVc3S3ZvM1pmcUE4NEVXUmx2a2pac2lmMEZONXJreHl5MzVpazd2dDdw?= =?utf-8?B?NGQrSkViRHBJVFIrUWtDdzFVNDVFUTRuTVI5RjNab3hhQzRPS1Y0dytqemhv?= =?utf-8?B?R0ZCQXJ5dVc3Q3JteTM2ZnFoY2lkcHpBckQ3dU5wWi9GbzhrQ0N6LzEvcENL?= =?utf-8?B?SVR0bXZXcEhpb08yOWxZcEVaUFBENUVGbzhPWU5Yd29ucWUxL3YxaEJDVkNl?= =?utf-8?B?REk4Y1hHcGpGcEdpMVpvcytnTFNlRnovTmVQaUpLTkhvcnBLMG84MHhxK3k2?= =?utf-8?B?c0Zqczk4MFFEeU9PNXMwNHZJRUI3TU8ySTRuTEo0SEcxckF4WjN4YVM5SmxO?= =?utf-8?B?MDFra2FzaFB2QzhWZnJFSjRkYnhJUE9XWlk3eU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ange-CrossTenant-Network-Message-Id: d04abe68-cdcf-4d23-cb95-08dbe5b944f1 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB4965.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2023 09:00:09.5160 (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: V0RYcBcwJ9P0Wlzts/8u/iW0ZTgc3z4X1444Blz+n8bfnz5rGsa76nnaWznSmziAEDhsW2DP0HscTLy6BktbCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR11MB7528 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 01:00:34 -0800 (PST) On 11/3/2023 2:26 AM, Maxim Levitsky wrote: > On Wed, 2023-11-01 at 12:32 -0700, Sean Christopherson wrote: >> On Tue, Oct 31, 2023, Maxim Levitsky wrote: >>> On Thu, 2023-09-14 at 02:33 -0400, Yang Weijiang wrote: >>>> Wrap __kvm_{get,set}_msr() into two new helpers for KVM usage and use the >>>> helpers to replace existing usage of the raw functions. >>>> kvm_msr_{read,write}() are KVM-internal helpers, i.e. used when KVM needs >>>> to get/set a MSR value for emulating CPU behavior. >>> I am not sure if I like this patch or not. On one hand the code is cleaner >>> this way, but on the other hand now it is easier to call kvm_msr_write() on >>> behalf of the guest. >>> >>> For example we also have the 'kvm_set_msr()' which does actually set the msr >>> on behalf of the guest. >>> >>> How about we call the new function kvm_msr_set_host() and rename >>> kvm_set_msr() to kvm_msr_set_guest(), together with good comments explaning >>> what they do? >> LOL, just call me Nostradamus[*] ;-) >> >> : > SSP save/load should go to enter_smm_save_state_64() and rsm_load_state_64(), >> : > where other fields of SMRAM are handled. >> : >> : +1. The right way to get/set MSRs like this is to use __kvm_get_msr() and pass >> : %true for @host_initiated. Though I would add a prep patch to provide wrappers >> : for __kvm_get_msr() and __kvm_set_msr(). Naming will be hard, but I think we >> ^^^^^^^^^^^^^^^^^^^ >> : can use kvm_{read,write}_msr() to go along with the KVM-initiated register >> : accessors/mutators, e.g. kvm_register_read(), kvm_pdptr_write(), etc. >> >> [*] https://lore.kernel.org/all/ZM0YZgFsYWuBFOze@google.com >> >>> Also functions like kvm_set_msr_ignored_check(), kvm_set_msr_with_filter() and such, >>> IMHO have names that are not very user friendly. >> I don't like the host/guest split because KVM always operates on guest values, >> e.g. kvm_msr_set_host() in particular could get confusing. > That makes sense. > >> IMO kvm_get_msr() and kvm_set_msr(), and to some extent the helpers you note below, >> are the real problem. >> >> What if we rename kvm_{g,s}et_msr() to kvm_emulate_msr_{read,write}() to make it >> more obvious that those are the "guest" helpers? And do that as a prep patch in >> this series (there aren't _that_ many users). > Makes sense. Then I'll modify related code and add the pre-patch in next version, thanks! >> I'm also in favor of renaming the "inner" helpers, but I think we should tackle >> those separately.separately > OK. > > Best regards, > Maxim Levitsky > >