Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBD96C433FE for ; Wed, 5 Jan 2022 19:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243421AbiAETN6 (ORCPT ); Wed, 5 Jan 2022 14:13:58 -0500 Received: from mail-dm6nam12on2055.outbound.protection.outlook.com ([40.107.243.55]:22856 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S243404AbiAETNw (ORCPT ); Wed, 5 Jan 2022 14:13:52 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ggagsk+PPi+eLgnvYjoC+R64gwBFTSn/qNr0RNbjNifk2FtTEySnqp65pKEeXlpngqLt7cg1q790cAe6/6UAhIJOCoZ0V0ZL1VxIZdaux57zU66oJovg6Wv8KEz4JENIUES+wSqGfZD4UrAjGg3P556fbHob/tjFSZ2iEqlMzbWsb+eTX5vWaW43AzxzXTmwmp8mSwA3UyLW2rbJRzffo58AS/KLs0/I0K8REonB5I6rVNKH8zTarW6c+Hl8A6cK/sBR29sTy02g25dbJ82xX3/q3ceH45y0kQHWA0aejPsaIAAC0YI0UyhHDS83nr2NXE4iV+sJmqPpcvvh5W6N7Q== 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=YXVoxUmZ/L+hFG514SPIFWQy6hIyqCt/5bqeDC7G4tM=; b=KI7ey6ek2ZA29uiDpfxaXa/ZzGloRbSgTClzUkOHZ4us5Xb+To9fOzthq08xNfXIdBeIfeOC2DpJyhK1MIxKMnbK1L9iQfkcxoP3X2lkjvgt0ixr1IbyhHXpwJBG7KhbolG9vsHQmEGSb2lQrfHtJf9G6ctZ5VCr3s+T58LcVn0MGVD0uLatWhZ+cpOF8NZitbU4A3kvvSKhDSfqcIzr9al2yYAemesEWO+DCggImMB64L2FOcKSmDMBTnUe2HhFrmzjDIA1HuKoFqvcENFXiRsK+gFlID1dDhDAqOmrP/YllMF+G8hlEwXKCv3iRrlkIC9vH9CEwteGWwlB0nq3eA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=YXVoxUmZ/L+hFG514SPIFWQy6hIyqCt/5bqeDC7G4tM=; b=eww8MNS+zzYNsVkEFPm/EFiy4pI9QJCS2JyLTcicoVx9XnRgOGikwWYE6xhoNw6fniX6WC3fS29I9fLnOe+Au+h8HHzoypqWN0KrCTMRYNaSHKBiWFPKASjYFEEB3+ZWSOm/tg9yymPeJXP8pEIAMUf70VTe7r0AwYwwH9ZBc08= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by DM8PR12MB5414.namprd12.prod.outlook.com (2603:10b6:8:3e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.15; Wed, 5 Jan 2022 19:13:50 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::2429:24de:1fd2:12c5]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::2429:24de:1fd2:12c5%7]) with mapi id 15.20.4823.023; Wed, 5 Jan 2022 19:13:50 +0000 Subject: Re: [PATCH v5 7/8] KVM: VMX: Update PID-pointer table entry when APIC ID is changed To: Zeng Guang , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, Dave Hansen , Tony Luck , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , Kai Huang Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Robert Hu , Gao Chao References: <20211231142849.611-1-guang.zeng@intel.com> <20211231142849.611-8-guang.zeng@intel.com> From: Tom Lendacky Message-ID: <640e82f3-489d-60af-1d31-25096bef1a46@amd.com> Date: Wed, 5 Jan 2022 13:13:46 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <20211231142849.611-8-guang.zeng@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: CH2PR04CA0029.namprd04.prod.outlook.com (2603:10b6:610:52::39) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 03001b38-7bc4-4966-3a7e-08d9d07f815c X-MS-TrafficTypeDiagnostic: DM8PR12MB5414:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:597; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ssyZjPEliEZ7rcdYU61hKqktAyIDj1ZrPmy1UV+VVEDjsc2J5cdhK9LR2WwRlTvz/PPwv7bJubGOfTUwlVf0mfcGsSp+1FMrqxBVwAu2wCFsVujPhJxeR8FXncPFEzeAvIw/cs3pbCgch2J2mggfrNiO5F/fk+7jvkR5dBgB3Q0thtCBcI9hwM9iAz8OZxeWCyvw+FZLeX5YCiBHrewE7SJphOJMHNntVrXiKJe5R9GLz/KH3MDGjQS3FpjJh/7xcV5JXgl8IV3lOFU+0Huh7B0H3I3Tww2uiZVbS+HGZR/x/zq+DjZnycxmKG2fuy/81KFsHDAKUtxC5N98dZ4UABZkCwil/HK7NKDcdESjd56hPng2/uSVDyu6ZwyW5ykO22ohoApM8R2O86w4EtdJQTq0Stz4lt58sB51bh3Fhcrq2ei/W2/GqZJpf+EEd8vlTFMImUUvLHA0OgZKiXdzkx6WefHjjoXikQxJ4GAJ7+6GTRX4yhUl2Plekewtt8IQeLmijcSlArfXbKhlAt3FqOmwg3qo1XkxxA6QuOFrprFku3YDAkXBR/Kn58U1fyclRJuE6LtR0PfrJRe0iP/ITsOdT1Yev6L7NbzgrJYIMJWwDCSb8pKVEXtpNqoX51dHWV9nwVkVbkmCOEzBhsQFn95GVGuI6WFrnzVgXurERm2EAkcFPZ1XC9x7uFbse570SfmV7khKJzyXPw9GJSJF61VAAt2UvXApJ44TxOqKonNoyH+Nu3C//j4hVKXBlcjb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(316002)(508600001)(2906002)(4326008)(6486002)(86362001)(31686004)(6666004)(921005)(83380400001)(6512007)(36756003)(15650500001)(66946007)(110136005)(38100700002)(5660300002)(8676002)(54906003)(66476007)(66556008)(186003)(6506007)(26005)(7416002)(31696002)(8936002)(2616005)(53546011)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?a0xJM2UycXlRNHord0k1bFpoaXV2aTRvZlh0ODJ4K3ZZS3JCS2x0dXhKb0hS?= =?utf-8?B?eFJKYTloSUtMOEJmT0U3SHFtU3hGaTIx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dnp0?= =?utf-8?B?SnVXaWhjL1E4QXV1bHU3NTZDVEtNRlcwVzNVVmcvcjhMVUZyNkhrWTBCZ2pO?= =?utf-8?B?YW94K1ZTVldOVmx5V0hSeWFJRldEU2QrVzlIMWpIczhYcVIzSG0wL3JoQjA4?= =?utf-8?B?Z3lBeUljakFWTFRra29ocTRmbnlmdFpBQlpERGpsRUZPMHRZclByOHFVbllR?= =?utf-8?B?MmNPL2Q5RERrZnhObVE4dkV2eEkvMktURzhhOUdXQXd3cnFkM0NSeFNzSzBH?= =?utf-8?B?WnhXd1ZTcjFidS9ZQ1RDNlNRSHFLWlEwdGNaMnI3Qm5kMVhGaEkzNXcyeHdi?= =?utf-8?Q?yf2CbDgIraQVOQp/SAnXsfo=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03001b38-7bc4-4966-3a7e-08d9d07f815c X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2022 19:13:50.1583 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /n2XML08Lto0gUFCO4qcfqc/EhagYQeplb/TS2noTQrSLW69gBWWm2x7mh65L/Ug3S1raJphJskyrrQZVOSS6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5414 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/31/21 8:28 AM, Zeng Guang wrote: > In xAPIC mode, guest is allowed to modify APIC ID at runtime. > If IPI virtualization is enabled, corresponding entry in > PID-pointer table need change accordingly. > > Signed-off-by: Zeng Guang > --- > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/lapic.c | 7 +++++-- > arch/x86/kvm/vmx/vmx.c | 12 ++++++++++++ > 3 files changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 2164b9f4c7b0..753bf2a7cebc 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1493,6 +1493,7 @@ struct kvm_x86_ops { > int (*complete_emulated_msr)(struct kvm_vcpu *vcpu, int err); > > void (*vcpu_deliver_sipi_vector)(struct kvm_vcpu *vcpu, u8 vector); > + void (*update_ipiv_pid_entry)(struct kvm_vcpu *vcpu, u8 old_id, u8 new_id); > }; > > struct kvm_x86_nested_ops { > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 3ce7142ba00e..83c2c7594bcd 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -2007,9 +2007,12 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) > > switch (reg) { > case APIC_ID: /* Local APIC ID */ > - if (!apic_x2apic_mode(apic)) > + if (!apic_x2apic_mode(apic)) { > + u8 old_id = kvm_lapic_get_reg(apic, APIC_ID) >> 24; > + > kvm_apic_set_xapic_id(apic, val >> 24); > - else > + kvm_x86_ops.update_ipiv_pid_entry(apic->vcpu, old_id, val >> 24); Won't this blow up on AMD since there is no corresponding SVM op? Thanks, Tom > + } else > ret = 1; > break; > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 2e65464d6dee..f21ce15c5eb8 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -7633,6 +7633,17 @@ static void vmx_vm_destroy(struct kvm *kvm) > free_pages((unsigned long)kvm_vmx->pid_table, MAX_PID_TABLE_ORDER); > } > > +static void vmx_update_ipiv_pid_entry(struct kvm_vcpu *vcpu, u8 old_id, u8 new_id) > +{ > + if (enable_ipiv && kvm_vcpu_apicv_active(vcpu)) { > + u64 *pid_table = to_kvm_vmx(vcpu->kvm)->pid_table; > + > + WRITE_ONCE(pid_table[old_id], 0); > + WRITE_ONCE(pid_table[new_id], __pa(&to_vmx(vcpu)->pi_desc) | > + PID_TABLE_ENTRY_VALID); > + } > +} > + > static struct kvm_x86_ops vmx_x86_ops __initdata = { > .name = "kvm_intel", > > @@ -7770,6 +7781,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { > .complete_emulated_msr = kvm_complete_insn_gp, > > .vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector, > + .update_ipiv_pid_entry = vmx_update_ipiv_pid_entry, > }; > > static __init void vmx_setup_user_return_msrs(void) >