From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1F15C072B1 for ; Thu, 30 May 2019 04:36:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 724F425813 for ; Thu, 30 May 2019 04:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559190991; bh=6aA0dcQe6ENMis/t6ev19rZT7jupXUdGLAVw8eog9i0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=b417uCENdAEkucfZo5UDfve0+vGXJWcNjdv/+q8DjiAdVPgChDu0CRuien7l75/Wd Y9cH+O2+8FdsJVkgbjux2YRQ/hmVoK24C5xgX8uZ8KHBLXtidsYb95WX3uaFqUeq18 Imq6ARbS0GhmTqryYhx79wc0ENwVWlxAYR0GeNjg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729311AbfE3DNA (ORCPT ); Wed, 29 May 2019 23:13:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:57002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729305AbfE3DM7 (ORCPT ); Wed, 29 May 2019 23:12:59 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8643B244EF; Thu, 30 May 2019 03:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185978; bh=6aA0dcQe6ENMis/t6ev19rZT7jupXUdGLAVw8eog9i0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jf+f8I4eKGtfPqw2d71T/T2SRoCnUFA2949s7oy3TKFOse2eJhfG06rUdYOowFlmf r+7hr1VuwzAsb6iehOZpgYQeZ6sPNwu1AcNex+pIwW72y8WdqtBLidWtWSmsaouENc 1KtHjQYDZu5T8LPeUsZ0kVQgb5k5Su/asRgiMTz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suravee Suthikulpanit , Paolo Bonzini Subject: [PATCH 5.0 012/346] kvm: svm/avic: fix off-by-one in checking host APIC ID Date: Wed, 29 May 2019 20:01:25 -0700 Message-Id: <20190530030541.176854355@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.363386121@linuxfoundation.org> References: <20190530030540.363386121@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Suthikulpanit, Suravee commit c9bcd3e3335d0a29d89fabd2c385e1b989e6f1b0 upstream. Current logic does not allow VCPU to be loaded onto CPU with APIC ID 255. This should be allowed since the host physical APIC ID field in the AVIC Physical APIC table entry is an 8-bit value, and APIC ID 255 is valid in system with x2APIC enabled. Instead, do not allow VCPU load if the host APIC ID cannot be represented by an 8-bit value. Also, use the more appropriate AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK instead of AVIC_MAX_PHYSICAL_ID_COUNT. Signed-off-by: Suravee Suthikulpanit Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2020,7 +2020,11 @@ static void avic_vcpu_load(struct kvm_vc if (!kvm_vcpu_apicv_active(vcpu)) return; - if (WARN_ON(h_physical_id >= AVIC_MAX_PHYSICAL_ID_COUNT)) + /* + * Since the host physical APIC id is 8 bits, + * we can support host APIC ID upto 255. + */ + if (WARN_ON(h_physical_id > AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK)) return; entry = READ_ONCE(*(svm->avic_physical_id_cache));