Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp675856rdb; Tue, 31 Oct 2023 21:22:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGImfihgjAbqWNvG6gEcWu8p8uNyrijbyCE8U5UYjWHEEWjqxVTwtFq5N12/+h100Ogn/Df X-Received: by 2002:a05:6a21:4881:b0:181:39a7:4fd4 with SMTP id av1-20020a056a21488100b0018139a74fd4mr1245182pzc.30.1698812569926; Tue, 31 Oct 2023 21:22:49 -0700 (PDT) Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id m9-20020a170902db0900b001cc2523cf08si2256933plx.428.2023.10.31.21.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 21:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AhVJsN2x; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 4C61F8087245; Tue, 31 Oct 2023 21:22:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344529AbjKAEV4 (ORCPT + 99 others); Wed, 1 Nov 2023 00:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236222AbjKAEVw (ORCPT ); Wed, 1 Nov 2023 00:21:52 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAF4AB7; Tue, 31 Oct 2023 21:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698812506; x=1730348506; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=h9x6HcqckduPPqX0A0nJM/81Nj+eFyvUUF5P1CJ0Oyk=; b=AhVJsN2xFj1bAaEJqJ8EZb7mOCXVw7ZcdrEdNgEZagREHiOdCZJjKOzs TuR9/ylAMHPbj1u0BK5rxvMUdZuuBbEBCV9OEMLFN6BthkP3pCrgUteAH ao0PViN4+vbe+b5hOiIFLmfAwo0HF8NnMkRdhuRCEtekit5woYt0a8g88 qyMOS6OeBJr+TCW0UKCa3XoCFC6PN8RtEwn08AmkJyd0kEDxHslNRjpkY 8KanzAxUfvIZOQ59jwEcAsOQk34DHK2GVOwlvTeNvI5+m+vjZhzh6EE/p Uk+dHaZIOoM88F2qbRMra+qeeK2YkUMM0f5+rrG9zUIZi1Hro3swZhA6F Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10880"; a="7060405" X-IronPort-AV: E=Sophos;i="6.03,267,1694761200"; d="scan'208";a="7060405" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 21:21:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10880"; a="934325835" X-IronPort-AV: E=Sophos;i="6.03,267,1694761200"; d="scan'208";a="934325835" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga005.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 31 Oct 2023 21:21:46 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Tue, 31 Oct 2023 21:21:45 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Tue, 31 Oct 2023 21:21:45 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) 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.34 via Frontend Transport; Tue, 31 Oct 2023 21:21:45 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.100) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Tue, 31 Oct 2023 21:21:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UTz8BrN31IO7O5blqv93lD0nlVhSaqyDXpNqRmACR2/vk+dmoPWqKK3aIapLItJgSHl/RTZ1C3QlKcSt0GyMHBajBykaac0M2+ZhprayV9Hv6nDEYQCHYQ7s//ubnakQTZUrTJnhdDWq3BRWYcbGfmJ0/ldzv8+02bCopvSIVO+0lsFA9Al5j+LlyoCt4LfP7DU/wbUYjDIl1sm4bBPAVJmiRpu8xZlchF8qidi91DpHNzFLFRFZIRKtLBvGpTX0em2BMRde0XPRhQIvRcX8Pzzo9Hp1sN5VQkqkO7NH3rttmPIUSjTVyIbOvU8wX5PN/4LpdIQB6JBt1v7+hzqwNg== 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=AmVtWoaOgikjuRx742+DNRKSSyGa9jLC+odBXoVqO8I=; b=eOtaNnU0TyvwbOy3BDj6gZNCGIceAZOqzlpLTH50iOpQdc0m9VjMTcgg0pthslw1D89CV0Ialiwjkq8Spfay9QwW9azBWzTjbRNbvLjZsqRxm0XYMFmeYY0R1RY93zwY+OyOB0+b2boUnPudFKUa9RGMcIk0CKjGv1ht/3drpugaRGSWxnt7/QsJhmxPgCjy3az5Ii36FcQeIaN/B87HL2AYsZvCUG9h44qNgys4S1L1d2GnX3Ftb4U9jjrUvtsJlqY7BC+60ZeLfDxlJfNM2D7qdUIYZWhj/exVeXTwsTTlsHdJWxs25SCZwwOJ02u2A17YgWfZS98GMj6ZDBZ3UA== 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 CH3PR11MB8660.namprd11.prod.outlook.com (2603:10b6:610:1ce::13) by CYYPR11MB8306.namprd11.prod.outlook.com (2603:10b6:930:c6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Wed, 1 Nov 2023 04:21:42 +0000 Received: from CH3PR11MB8660.namprd11.prod.outlook.com ([fe80::6227:c967:5d1d:2b72]) by CH3PR11MB8660.namprd11.prod.outlook.com ([fe80::6227:c967:5d1d:2b72%5]) with mapi id 15.20.6954.019; Wed, 1 Nov 2023 04:21:42 +0000 Date: Wed, 1 Nov 2023 12:21:32 +0800 From: Chao Gao To: Yang Weijiang CC: , , , , , , , Subject: Re: [PATCH v6 24/25] KVM: nVMX: Introduce new VMX_BASIC bit for event error_code delivery to L1 Message-ID: References: <20230914063325.85503-1-weijiang.yang@intel.com> <20230914063325.85503-25-weijiang.yang@intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20230914063325.85503-25-weijiang.yang@intel.com> X-ClientProxiedBy: SI2PR01CA0007.apcprd01.prod.exchangelabs.com (2603:1096:4:191::11) To CH3PR11MB8660.namprd11.prod.outlook.com (2603:10b6:610:1ce::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR11MB8660:EE_|CYYPR11MB8306:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a3f8eeb-3dbb-4211-b259-08dbda920c7c 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: dxgayWQP8f0/p9GrXWpqpzqwU/NokD09/cUJAjvcww4Jy2DArChW9xao0hvDU15nuarrxoqJsPl26hXWDBzj7i94ziMZN7pJaF30hfFCqhpqRQxBGNUBGzFlh0YXtLGkdInjuIncuo41No5D5p5llf/dL7V98tNxi/p3zqlxYHxP+5e8d+bPH1mUqd9sJkD3W8P7vzfUxzcZxmunONWcKTvSlRwKZV6wjBafbf9VkyGrBH/PEbaoQrxE0D3aOzoJi0kN0c99LaiygFeqYpgeUE5w1e58i+EnFbDzfym6mBIbeHbxzz7gnvO/W7Za80LStB12YjEBcofh0ZqDWK2pQrg/pw8zaZu+CeoaE2bGEUL1wqJAmLpsm9AnDiYSQANU6nzRL0+RWVh2/y4sg1LxSltZJxUHTaVrOmSX54HOOmQfz9NkWwoJUrrLYcfGpBpRccCfRc0r3jxZ47j9/T5drnAg+K8aYyypyNBI5zTXaDsmyffdoctNvnYYDEmcdaGzPUbIIycz4ymVakfu3giuFKmqi6fvvfj8YcUt/08kaICdOvyMSULi2gCoTu45pMXn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR11MB8660.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7916004)(366004)(346002)(376002)(396003)(39860400002)(136003)(230922051799003)(186009)(451199024)(64100799003)(1800799009)(86362001)(33716001)(82960400001)(6512007)(9686003)(478600001)(6486002)(41300700001)(8676002)(6862004)(4326008)(8936002)(44832011)(6666004)(83380400001)(2906002)(26005)(6506007)(5660300002)(66946007)(6636002)(316002)(66556008)(66476007)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?RsKzhYdTjfL+PgU4ExVanZmE7EaXVAxbYuR+yJ0YRgZdYYdsWLtBKW4TF+gZ?= =?us-ascii?Q?qLL/58UF9J0W+be/RtMsMRsW5jk7GCvzuM+6XUwi95YKWyb2Ph7qJILZ368O?= =?us-ascii?Q?lC3wZggkFTEkyvGG4TEDH89wFhbwfi+mCf0nhvALs7f3RAYVb2NDdGjo5OAo?= =?us-ascii?Q?WBxFiHVKHVF0uWXQCE5Z99pAJnVq1mUtrAohoXHY/reQ0UckfrUmNir06fi1?= =?us-ascii?Q?4qY/ZddftnNvfcjE4KUC9LeWxd+2AXIDvvuZ0Guf5hTaVKYAhRykExMy7Qvg?= =?us-ascii?Q?zFQmibNkx3a8c2Ln//LFaOJVvTKvJPbDO5JCr2Fepy/JI+Ukznbyk8mBPkE8?= =?us-ascii?Q?9hmIDMO7J714X5jI3NG+nJPYf7NdviAgdTa1ce4xqnk5rbc6PdpHin3xLEkB?= =?us-ascii?Q?fXyI2Bpa8vBt75NEPnMy7i4pnDPyEsG4rQ+OFikvX2UudJO61REq3TiJQDz7?= =?us-ascii?Q?RtB/fhoTkbVS5rcSslAbKm+/8wMp4tJ6yfgPpSmYWYCW+P8Nx6Tydax5LR5I?= =?us-ascii?Q?W4TCXt+BePjK2U43Lb9TVbvI3C7bN3B4Tv5FqJnEUB541TNacn7zY9lH8m81?= =?us-ascii?Q?uN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9h?= =?us-ascii?Q?M0d7S3Em3e4+0r9wbcZyV7C/LOfAZ279T9RuI4r3RwHYtFdiShm9vb82RKgO?= =?us-ascii?Q?2tF6QN28btLZTgpwoG+uZhJCbfd6KD6j6CVgDagC?= X-MS-Exchange-CrossTenant-Network-Message-Id: 2a3f8eeb-3dbb-4211-b259-08dbda920c7c X-MS-Exchange-CrossTenant-AuthSource: CH3PR11MB8660.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2023 04:21:41.3945 (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: 4HXzk5TwGusN1IDJALCesZ9B8NbSTyeH1eWI0RZPFWFC4jfqko+rqxlIRiD/+2LDpfUxPLq1vowK4gifrJXRIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR11MB8306 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR, T_SPF_TEMPERROR,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 31 Oct 2023 21:22:16 -0700 (PDT) On Thu, Sep 14, 2023 at 02:33:24AM -0400, Yang Weijiang wrote: >Per SDM description(Vol.3D, Appendix A.1): >"If bit 56 is read as 1, software can use VM entry to deliver a hardware >exception with or without an error code, regardless of vector" > >Modify has_error_code check before inject events to nested guest. Only >enforce the check when guest is in real mode, the exception is not hard >exception and the platform doesn't enumerate bit56 in VMX_BASIC, in all >other case ignore the check to make the logic consistent with SDM. > >Signed-off-by: Yang Weijiang >--- > arch/x86/kvm/vmx/nested.c | 22 ++++++++++++++-------- > arch/x86/kvm/vmx/nested.h | 5 +++++ > 2 files changed, 19 insertions(+), 8 deletions(-) > >diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c >index c5ec0ef51ff7..78a3be394d00 100644 >--- a/arch/x86/kvm/vmx/nested.c >+++ b/arch/x86/kvm/vmx/nested.c >@@ -1205,9 +1205,9 @@ static int vmx_restore_vmx_basic(struct vcpu_vmx *vmx, u64 data) > { > const u64 feature_and_reserved = > /* feature (except bit 48; see below) */ >- BIT_ULL(49) | BIT_ULL(54) | BIT_ULL(55) | >+ BIT_ULL(49) | BIT_ULL(54) | BIT_ULL(55) | BIT_ULL(56) | > /* reserved */ >- BIT_ULL(31) | GENMASK_ULL(47, 45) | GENMASK_ULL(63, 56); >+ BIT_ULL(31) | GENMASK_ULL(47, 45) | GENMASK_ULL(63, 57); > u64 vmx_basic = vmcs_config.nested.basic; > > if (!is_bitwise_subset(vmx_basic, data, feature_and_reserved)) >@@ -2846,12 +2846,16 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu, > CC(intr_type == INTR_TYPE_OTHER_EVENT && vector != 0)) > return -EINVAL; > >- /* VM-entry interruption-info field: deliver error code */ >- should_have_error_code = >- intr_type == INTR_TYPE_HARD_EXCEPTION && prot_mode && >- x86_exception_has_error_code(vector); >- if (CC(has_error_code != should_have_error_code)) >- return -EINVAL; >+ if (!prot_mode || intr_type != INTR_TYPE_HARD_EXCEPTION || >+ !nested_cpu_has_no_hw_errcode_cc(vcpu)) { >+ /* VM-entry interruption-info field: deliver error code */ >+ should_have_error_code = >+ intr_type == INTR_TYPE_HARD_EXCEPTION && >+ prot_mode && >+ x86_exception_has_error_code(vector); >+ if (CC(has_error_code != should_have_error_code)) >+ return -EINVAL; >+ } prot_mode and intr_type are used twice, making the code a little hard to read. how about: /* * Cannot deliver error code in real mode or if the * interruption type is not hardware exception. For other * cases, do the consistency check only if the vCPU doesn't * enumerate VMX_BASIC_NO_HW_ERROR_CODE_CC. */ if (!prot_mode || intr_type != INTR_TYPE_HARD_EXCEPTION) { if (CC(has_error_code)) return -EINVAL; } else if (!nested_cpu_has_no_hw_errcode_cc(vcpu)) { if (CC(has_error_code != x86_exception_has_error_code(vector))) return -EINVAL; } and drop should_have_error_code.