From patchwork Wed Jul 26 13:59:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 12651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp432070vqo; Wed, 26 Jul 2023 07:12:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlEUMzH8fdiGE5pyg1dymSWnX/JOb79vek/OGRtIMaL7GspX/yndlTM9he1y3GAaAirvv0+/ X-Received: by 2002:a05:6a21:3d85:b0:134:3013:cdb5 with SMTP id bj5-20020a056a213d8500b001343013cdb5mr1776320pzc.35.1690380772282; Wed, 26 Jul 2023 07:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690380772; cv=none; d=google.com; s=arc-20160816; b=gsXKjim78oGkW3ero/ZxxSS247UTsoD8pYhRdXNUwe6tGoIqPaVH0mgaS9Wq8etCKm H9f8/BWYgUGplcnDuH26QmpRUg7g+sryDWBfPwqzevU/OOHiG8mUy9CzfwMnfAZR8ABc eUvaNwOkdhZbDK1xSHZ13Tzy8ZRB/eu+5HiJw2N6QLaMCrJ51y3aIKC16DqlF1T7PZ0d 6zWtYoxyaYEoAQM8DaCJlFtq0Quw/iJTgT/15LyWWHnlQwBB5R8uzKcz6N3F/Ek82rmx GOG/QVf0pbE6oppQ+cdIEv1CLy8AVb/8cF0sILEqCvmrmNyVbxvr0OmSZHI7z0tw6Ytv 7m2w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=hI+xZjnjOx6iQYY+/HFIgbw6khCjngJ7Cxx7Odmq6DI=; fh=2NfF+VcPdV2h2hRMeHegn63ohbGEV/1oT544guq3jvE=; b=tftRSrmVunQo9AwAmkv+UcoKX+PeT6XrAh8vN/hsEszZFCAoZx+ZUkrLcqIMoMF3jp Gtdm/WZkv8z/3i8nbDYbfN12hKk2l64d7ccMUSGwK2+umDKUMf0erdA/l4ofmXtYJfLI wHTuMaRC2KbhqsKK3ksJhG6v6kzbZvimKsWgS+vLuc2H5nQ8Uun+74+nJPgrvNOSYR72 T9g8xTArtsqWL9UiS/4tE4RyyAOXgAZvveJt5WLlBqhi/6f5yJJRN9ynWaBToQlirqoY fg0N8WGhVximVV1iMZWJxf0+qKH62Z0x6tx9XKINKIB+HsSgOXTn4mEe+ubjQSwCxA9U cEBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C7yMC1i4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a056a00089600b006768627bc5asi13499416pfj.199.2023.07.26.07.12.37; Wed, 26 Jul 2023 07:12:52 -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=C7yMC1i4; 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 S234210AbjGZOAt (ORCPT + 99 others); Wed, 26 Jul 2023 10:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbjGZOAr (ORCPT ); Wed, 26 Jul 2023 10:00:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20342211B for ; Wed, 26 Jul 2023 07:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690379999; 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; bh=hI+xZjnjOx6iQYY+/HFIgbw6khCjngJ7Cxx7Odmq6DI=; b=C7yMC1i40LKp6E5PjnGS55hYeEKO25dAn2+zPF944DVSxQGjsJkckeVs26N0Ga1jk4a751 syyP90/AfriDqhZ1pvtDLk2zYRrpzGnwscq3SRNbd5iYGggGHvZuAqyb+YfFbHSFPtwlLx 6/ReQgeRRsmg61cc0ELEEjvU87UhrZ0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-346-02aUmBj3PxCnqC9BrYH_Dw-1; Wed, 26 Jul 2023 09:59:56 -0400 X-MC-Unique: 02aUmBj3PxCnqC9BrYH_Dw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF4EF8028B2; Wed, 26 Jul 2023 13:59:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.224.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2265840C2063; Wed, 26 Jul 2023 13:59:51 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Borislav Petkov , Paolo Bonzini , Sean Christopherson , Dave Hansen , Thomas Gleixner , "H. Peter Anvin" , Ingo Molnar , Maxim Levitsky Subject: [PATCH v2 0/3] Fix 'Spurious APIC interrupt (vector 0xFF) on CPU#n' issue Date: Wed, 26 Jul 2023 16:59:42 +0300 Message-Id: <20230726135945.260841-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772492708430593089 X-GMAIL-MSGID: 1772492708430593089 Recently we found an issue which causes these error messages to be sometimes logged if the guest has VFIO device attached: 'Spurious APIC interrupt (vector 0xFF) on CPU#0, should never happen' It was traced to the incorrect APICv inhibition bug which started with 'KVM: x86: inhibit APICv/AVIC on changes to APIC ID or APIC base' (All these issues are now fixed) However, there are valid cases for the APICv to be inhibited and it should not cause spurious interrupts to be injected to the guest. After some debug, the root cause was found and it is that __kvm_apic_update_irr doesn't set irr_pending which later triggers a int->unsigned char conversion bug which leads to the wrong 0xFF injection. This also leads to an unbounded delay in injecting the interrupt and hurts performance. In addition to that, I also noticed that __kvm_apic_update_irr is not atomic in regard to IRR, which can lead to an even harder to debug bug. V2: applied Paolo's feedback for the patch 1. Best regards, Maxim Levitsky Maxim Levitsky (3): KVM: x86: VMX: __kvm_apic_update_irr must update the IRR atomically KVM: x86: VMX: set irr_pending in kvm_apic_update_irr KVM: x86: check the kvm_cpu_get_interrupt result before using it arch/x86/kvm/lapic.c | 25 +++++++++++++++++-------- arch/x86/kvm/x86.c | 10 +++++++--- 2 files changed, 24 insertions(+), 11 deletions(-) --- 2.26.3