Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp182915iol; Thu, 9 Jun 2022 01:26:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjmGvF7emo309hqqbsn7foFscswWYpujZOkGpBuBUSI+yXRILgjRzWhdeYSBhPQDb0y7Sx X-Received: by 2002:a17:906:8501:b0:711:bf65:2a47 with SMTP id i1-20020a170906850100b00711bf652a47mr21097973ejx.150.1654763194694; Thu, 09 Jun 2022 01:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654763194; cv=none; d=google.com; s=arc-20160816; b=IGVY7A5rvUzHn9neUNE8G75zjNALNQvlMX4ldLdl1XDK4Oyora9hakPJmjXB9TTCSz Vp61VX181efCF5saZkXopWY80Bw+4Pk5vN2yruyREpX8olC6l8/y2jJWnXifh3Qd+hiL VpzJXuuyAAqGlJ5sPwL6kmvBlX+KzjgwqvlnKwHq4FtbnRkU59HqWBJ4vOzDJhlOk0DZ SLKcvAGdmP7jyZXuf7CllI4enXAGbvSmDEdv27BQCw+6bYyBwuydc8YERgOx1oz+Xuth d6TTcXfzAPcJgtYCiBM+VXNCAx+rBu5q/lmsr8/lWzQ1ki7y1RLNEYwO8uJJUzhBtxHr 3NNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=0UBhD5YEWFNp4aDc/ahVKPUNtBuVUhhYKUmhLtmUs50=; b=RSfKJxEE1e9/P+mO9XfbIPbrzjqQNq5jX7NGD2ZvlPHClSTE/bGjAqgioqmXqGjpbi 3CEUo/MOp3fJwp3aiFCMCL9EsSElJF3+UMwjuVhyNTSRzeTmbHtqCUaZ1gMcAD0H6568 sUgpYaGGgTl1bMM96IhKmQOuiMNr9I4IoFiRVWAwizJhY50fYfTXzPB87c3TD4kiFQxK 8giYG0cxpwL0HMzWIkGpTYePkCUYOD9TnBASub2YJQbg0soDrqpInDrT4YsSprxqomcm 2s0lUDl2kQZB7xRQnZlsWhpWIlSPoQSE2HV7KOcRaz2xgfs0eAkmPsinFtqKTrvfoYfY cPzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gZzX9GF1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa37-20020a17090786a500b006fe178ca718si25051945ejc.662.2022.06.09.01.26.09; Thu, 09 Jun 2022 01:26:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gZzX9GF1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240598AbiFIINi (ORCPT + 99 others); Thu, 9 Jun 2022 04:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240594AbiFIINd (ORCPT ); Thu, 9 Jun 2022 04:13:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 365FC5EDE6 for ; Thu, 9 Jun 2022 01:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654762411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0UBhD5YEWFNp4aDc/ahVKPUNtBuVUhhYKUmhLtmUs50=; b=gZzX9GF1NuOTJ/lWGBC+MFKjq/F8t4B2JUwc6fbGAwBAImjs44uBDu2QEXbU8IKCFW/ENw bs/nYZYGBh7QO55PLDFPydIhsRgiKJBEpljSW/Mji6RuG/f5cW4NEszcNhnCBg0iO6bzFr dZBpSLswvlgY21RcqzWIMFbV7noFgt8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-LSqcigi8OVWcf-rDwFRfYQ-1; Thu, 09 Jun 2022 04:13:27 -0400 X-MC-Unique: LSqcigi8OVWcf-rDwFRfYQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEF381C004E9; Thu, 9 Jun 2022 08:13:26 +0000 (UTC) Received: from starship (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id C72111121315; Thu, 9 Jun 2022 08:13:22 +0000 (UTC) Message-ID: <909920fcfb5a614861fbc2654b3e8c1f0240bb51.camel@redhat.com> Subject: Re: [PATCH 4/7] KVM: x86: SVM: fix avic_kick_target_vcpus_fast From: Maxim Levitsky To: Paolo Bonzini , kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Thomas Gleixner , x86@kernel.org, Borislav Petkov , stable@vger.kernel.org Date: Thu, 09 Jun 2022 11:13:21 +0300 In-Reply-To: References: <20220606180829.102503-1-mlevitsk@redhat.com> <20220606180829.102503-5-mlevitsk@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2022-06-08 at 15:21 +0200, Paolo Bonzini wrote: > On 6/6/22 20:08, Maxim Levitsky wrote: > > There are two issues in avic_kick_target_vcpus_fast > > > > 1. It is legal to issue an IPI request with APIC_DEST_NOSHORT > > and a physical destination of 0xFF (or 0xFFFFFFFF in case of x2apic), > > which must be treated as a broadcast destination. > > > > Fix this by explicitly checking for it. > > Also don’t use ‘index’ in this case as it gives no new information. > > > > 2. It is legal to issue a logical IPI request to more than one target. > > Index field only provides index in physical id table of first > > such target and therefore can't be used before we are sure > > that only a single target was addressed. > > > > Instead, parse the ICRL/ICRH, double check that a unicast interrupt > > was requested, and use that info to figure out the physical id > > of the target vCPU. > > At that point there is no need to use the index field as well. > > > > > > In addition to fixing the above issues, also skip the call to > > kvm_apic_match_dest. > > > > It is possible to do this now, because now as long as AVIC is not > > inhibited, it is guaranteed that none of the vCPUs changed their > > apic id from its default value. > > > > > > This fixes boot of windows guest with AVIC enabled because it uses > > IPI with 0xFF destination and no destination shorthand. > > > > Fixes: 7223fd2d5338 ("KVM: SVM: Use target APIC ID to complete AVIC IRQs when possible") > > Cc: stable@vger.kernel.org > > > > Signed-off-by: Maxim Levitsky > > Is it possible to use kvm_intr_is_single_vcpu_fast, or am I missing > something? Yes, except that it needs 'struct kvm_lapic_irq' which we won't have when we emulate guest<->guest interrupts, and also it goes over apic map and such, which can be be skipped. It also does more unneeded things like dealing with low priority mode for example, which thankfully AVIC doenst' support and if attempted will still VM exit with 'incomplete IPI' but with AVIC_IPI_FAILURE_INVALID_INT_TYPE subreason, which goes through full APIC register emulation. I do think about the fact that ICRL/H parsing in the case of logical ID, (which depends on cluser mode and x2apic mode) can be moved to some common code, but I wasn't able yet to find a clean way to do it. BTW: there is another case where AVIC must be inhibited: in xapic mode, logical ids, don't have to have a single bit set in the mask area of the logical id, (low 4 bits in cluster mode and all 8 bits in flat mode) and neither there is a guarnantee that multilple CPUs don't share these bits. AVIC however has a logical ID table which maps each (bit x cluster value) to a physical id, and therefore a single vCPU, so tha later is not possible to support with AVIC. I haven't studied the code that is responsible for this, I will do this soon. Thankfully IPIv only supports physical IPI mode (this is what I heard, don't know for sure). I also will write a unit test for this very soon, to test various logical id IPIs, messing with logical id registers, etc, etc. Best regards, Maxim Levitsky > > Series queued, thanks. > > Paolo >