From patchwork Thu Nov 27 20:16:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 5399591 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4F0DFBEEA8 for ; Thu, 27 Nov 2014 20:17:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA5642015E for ; Thu, 27 Nov 2014 20:17:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDF5220155 for ; Thu, 27 Nov 2014 20:17:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752728AbaK0UQ6 (ORCPT ); Thu, 27 Nov 2014 15:16:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40990 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752491AbaK0UQx (ORCPT ); Thu, 27 Nov 2014 15:16:53 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sARKGk30013898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 27 Nov 2014 15:16:46 -0500 Received: from potion (dhcp-1-103.brq.redhat.com [10.34.1.103]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id sARKGg2i024039; Thu, 27 Nov 2014 15:16:43 -0500 Received: by potion (sSMTP sendmail emulation); Thu, 27 Nov 2014 21:16:42 +0100 Date: Thu, 27 Nov 2014 21:16:42 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Nadav Amit Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Gleb Natapov , Nadav Amit Subject: Re: [PATCH 3/4] KVM: x86: allow 256 logical x2APICs again Message-ID: <20141127201641.GB383@potion.brq.redhat.com> References: <1417114994-25235-1-git-send-email-rkrcmar@redhat.com> <1417114994-25235-4-git-send-email-rkrcmar@redhat.com> <22F11C34-E2E4-459B-882B-A944AD0853FD@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <22F11C34-E2E4-459B-882B-A944AD0853FD@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 2014-11-27 21:53+0200, Nadav Amit: > Radim Kr?má? wrote: > > - new->cid_mask = (1 << KVM_X2APIC_CID_BITS) - 1; > > - new->lid_mask = 0xffff; > > + new->cid_mask = new->lid_mask = 0xffff; > You set cid_mask to 0xffff, while there are only 16 clusters. I think it is > risky (if you twist my hand would come with a scenario). Let's see :) APIC id is 8 bit, and we compute cluster part of LDR by taking four upper bits, so 16 is enough. It isn't the safest programming practice, but we already fail to check physical_map bounds and any boost to maximal APIC ID is going to require a rewrite, thus I didn't bother to do it ... All uses should be covered with the following hunk, I will add it to v2 after all reviews, > Yet, why not to set > cid_mask to (ARRAY_SIZE(map->logical_map) - 1) ? We would incorrectly deliver messages intended for high clusters, it has to be 0xffff. --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 6c2b8a5..30e4cc1 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -198,7 +198,7 @@ static void recalculate_apic_map(struct kvm *kvm) cid = apic_cluster_id(new, ldr); lid = apic_logical_id(new, ldr); - if (lid) + if (lid && cid < ARRAY_SIZE(map->logical_map)) new->logical_map[cid][ffs(lid) - 1] = apic; } out: