Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1653011rwl; Thu, 5 Jan 2023 17:31:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXuKUhuxTZOLbHLWoQ8RD1QNSM/HKz6thQpjPvTbKyrz9Dy8IJDHkozNndsUm+duLTHmwzGe X-Received: by 2002:a62:f203:0:b0:576:b8d0:6034 with SMTP id m3-20020a62f203000000b00576b8d06034mr54032834pfh.31.1672968713249; Thu, 05 Jan 2023 17:31:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672968713; cv=none; d=google.com; s=arc-20160816; b=TlpqoU76GuwELBtdEC/mjytPBFkbYnI1iWCQhB5CUSErTy4rAn4mhJMG1+b7SlR4It PIc99sSiyTPKvVPcogBQ5hQ9Zi8uygMSJFHBnoFdEOj1QK119uq1CUk8Ow1OiFIH23DH fe4Kew8GCHQhKBzM/tm3mlCelUg7QWxguU37KHhSr7X2wUBH0K27dqLSCCfNWPSz3tDs rTFB3w82rrUSFt6Rq9L/r9zRP/gfiYmtuSdNnWPBBZqT+/+sk7r+0H4t89TjZ88uB2eU Tl+nzqXmZEhuHKzcgXuFvyZPnD+a0TIKCF705rcKTOHAq2sVliEUMFORDh86Nw1XHLTT +SjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :reply-to:dkim-signature; bh=exXmbXtQOvjtL6oDSNpvthzMuaVH9c6hK6Io7Q3H2PQ=; b=naQB7k2OtKD7bknS+Fz8rOiDcKLtxLHgUJIWZx33Bl6obS9rPCo2/h2Ce9Q0IteBLu m92BsF+7QVOjQOsor9g6wy/YJ+jcoaNRMoLzE0RFUYdomsQuXkV3/Ot7td0BV8DHj9cO JCjACM2/ZfrqVXS3aWrOShO5ENXD6jlgjvEqa5uqfD3/WUmkBW/LxthOwKLVNKsnaVHm gtg9NTivvdsjU/letvFjQpRRyDOISPpSiiJUowqEZ+KgXVv0TEjrxIByoJHmSJUf9GPS N11IPPnsq9cucNNVjKq+DDSO2q04nXbJm9iZQJisUdqyU+P2mjAqoevvl47c4HQnrHQh /rWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gd2Hc3yA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a056a001aca00b0057f9aa2c9basi41914393pfv.79.2023.01.05.17.31.46; Thu, 05 Jan 2023 17:31:53 -0800 (PST) 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=@google.com header.s=20210112 header.b=Gd2Hc3yA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236624AbjAFBNZ (ORCPT + 57 others); Thu, 5 Jan 2023 20:13:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236736AbjAFBNP (ORCPT ); Thu, 5 Jan 2023 20:13:15 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BC7472D07 for ; Thu, 5 Jan 2023 17:13:14 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-46658ec0cfcso2651217b3.19 for ; Thu, 05 Jan 2023 17:13:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=exXmbXtQOvjtL6oDSNpvthzMuaVH9c6hK6Io7Q3H2PQ=; b=Gd2Hc3yAemxhyPG2YJom6CSzPSNwdfYGbmw+Li60o3dSnVKYx0XiVKd0icK+AHEuIk cr5aDPLRFr/2CT8g2JuA15L4l7Yr9Gv+v4vZE6abq951XP07mH9FmjQbtRMeGxHWqvA1 6+okIXdOG0GcP9+YnE6ajjTn+vj+n3TIqQsyXKSyK3fVAN1scHB4o95WZ7LLHrHJWChj mEF6ZpF8Noq7jcrGsh7Tig0G45woaqJy6021lf/DM3NZxjaWBpvN9MYJxWV6PInswNb4 P5I7cDsWcUr4lBnWnASkz0clzoO1ftn9eCbP+0lbwF3aW8mGbteLdVvaygR51AERV6qs dstg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=exXmbXtQOvjtL6oDSNpvthzMuaVH9c6hK6Io7Q3H2PQ=; b=Iu4pEUlsYl540P1X74MF6HKCEDSS+jN24+Jinjg+J9COFenIawhtsVI9c73yzPd0ZR Le0T5i8g/ZGqdLTzoL6SwSRfl4DDoyE9VSUodAez6UNWs4JyZYS/fbxseC3Ht2qdlir0 T6sYFyKuLVBc8+aY4Hi93DVutPWY1R2kLuCjVhCiDpOBsrUCDzLuYKRabtFXI6IMYEtu KLf6QjVFKlJl1pnv30LZDGn2xLzXeaNao+1jIxPyX8NyE14tBt5sRpw0iFg0DJB6+/LH kEZcLsaEhO4P30qOUxB4Ivl22pguHpgLuQjqEm7kOamLiDbs2Jv6duTloRwuDw6PVFGJ bh/g== X-Gm-Message-State: AFqh2kq5zL73YrZ9TFqF+V2D25jZw53s6GLYqa3WmrQMolbobu3lPneW DXmMajWBgWLIdmZKDs5utsjhluGOXQM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:2e47:0:b0:722:fd7a:94c4 with SMTP id b7-20020a252e47000000b00722fd7a94c4mr3420610ybn.607.1672967593768; Thu, 05 Jan 2023 17:13:13 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 6 Jan 2023 01:12:33 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230106011306.85230-1-seanjc@google.com> Subject: [PATCH v5 00/33] KVM: x86: AVIC and local APIC fixes+cleanups From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Alejandro Jimenez , Maxim Levitsky , Suravee Suthikulpanit , Li RongQing , Greg Edwards Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 Paolo, This is a wholesale (and hopefully a drop-in) replacement for the patches in `kvm-lapic-fix-and-cleanup`. The changes for " KVM: x86: Inhibit APIC memslot if x2APIC and AVIC are enabled" in v5 are relatively minor, but it led to multiple conflicts in later patches, i.e. a patch-to-be-squashed wasn't going to work. Let me know if you've already done a lot of massaging on your side, shouldn't be too difficult to generate patches to go on top. The first half or so patches fix semi-urgent, real-world relevant APICv and AVIC bugs. The second half fixes a variety of AVIC and optimized APIC map bugs where KVM doesn't play nice with various edge cases that are architecturally legal(ish), but are unlikely to occur in most real world scenarios v5: - Fix even more bugs! [Greg] - Collect reviews. [Maxim] - Don't use an inhibit flag for hybrid AVIC. [Maxim] - Fix an LDR cluster calc goof in the AVIC code. [Maxim] - Drop a redundant "ldr == 0" check. [Maxim] - Add helpers for logical vs. physical optimized map calcs. [Maxim] v4: - https://lore.kernel.org/all/20221001005915.2041642-1-seanjc@google.com - Fix more bugs! [Alejandro] - Delete APIC memslot to inhibit xAVIC acceleration when x2APIC is enabled on AMD/SVM instead of using a "partial" inihbit. [Maxim] v3: - https://lore.kernel.org/all/20220920233134.940511-1-seanjc@google.com - Collect reviews. [Paolo] - Drop "partial" x2APIC inhibit and instead delete the memslot. [Maxim, Suravee] - Skip logical mode updates for x2APIC, which just reuses the phys_map with some clever logic. [Suravee] - Add a fix for "nodecode write" traps. [Alejandro] v2: - https://lore.kernel.org/all/20220903002254.2411750-1-seanjc@google.com - Collect reviews. [Li, Maxim] - Disable only MMIO access when x2APIC is enabled (instead of disabling all of AVIC). [Maxim] - Inhibit AVIC when logical IDs are aliased. [Maxim] - Tweak name of set_virtual_apic_mode() hook. [Maxim] - Straight up revert logical ID fastpath mess. [Maxim] - Reword changelog about skipping vCPU during logical setup. [Maxim] - Fix LDR updates on AVIC. [Maxim?] - Fix a nasty ISR caching bug. - Flush TLB when activating AVIC. v1: https://lore.kernel.org/all/20220831003506.4117148-1-seanjc@google.com Greg Edwards (1): KVM: x86: Allow APICv APIC ID inhibit to be cleared Sean Christopherson (31): KVM: x86: Blindly get current x2APIC reg value on "nodecode write" traps KVM: x86: Purge "highest ISR" cache when updating APICv state KVM: SVM: Flush the "current" TLB when activating AVIC KVM: SVM: Process ICR on AVIC IPI delivery failure due to invalid target KVM: x86: Don't inhibit APICv/AVIC on xAPIC ID "change" if APIC is disabled KVM: x86: Don't inhibit APICv/AVIC if xAPIC ID mismatch is due to 32-bit ID KVM: SVM: Don't put/load AVIC when setting virtual APIC mode KVM: x86: Handle APICv updates for APIC "mode" changes via request KVM: x86: Move APIC access page helper to common x86 code KVM: x86: Inhibit APIC memslot if x2APIC and AVIC are enabled KVM: SVM: Replace "avic_mode" enum with "x2avic_enabled" boolean KVM: SVM: Compute dest based on sender's x2APIC status for AVIC kick Revert "KVM: SVM: Use target APIC ID to complete x2AVIC IRQs when possible" KVM: SVM: Document that vCPU ID == APIC ID in AVIC kick fastpatch KVM: SVM: Add helper to perform final AVIC "kick" of single vCPU KVM: x86: Explicitly skip optimized logical map setup if vCPU's LDR==0 KVM: x86: Explicitly track all possibilities for APIC map's logical modes KVM: x86: Skip redundant x2APIC logical mode optimized cluster setup KVM: x86: Disable APIC logical map if logical ID covers multiple MDAs KVM: x86: Disable APIC logical map if vCPUs are aliased in logical mode KVM: x86: Honor architectural behavior for aliased 8-bit APIC IDs KVM: x86: Inhibit APICv/AVIC if the optimized physical map is disabled KVM: SVM: Inhibit AVIC if vCPUs are aliased in logical mode KVM: SVM: Always update local APIC on writes to logical dest register KVM: SVM: Update svm->ldr_reg cache even if LDR is "bad" KVM: SVM: Require logical ID to be power-of-2 for AVIC entry KVM: SVM: Handle multiple logical targets in AVIC kick fastpath KVM: SVM: Ignore writes to Remote Read Data on AVIC write traps Revert "KVM: SVM: Do not throw warning when calling avic_vcpu_load on a running vcpu" KVM: x86: Track required APICv inhibits with variable, not callback KVM: x86: Add helpers to recalc physical vs. logical optimized APIC maps Suravee Suthikulpanit (1): KVM: SVM: Fix x2APIC Logical ID calculation for avic_kick_target_vcpus_fast Documentation/virt/kvm/x86/errata.rst | 11 + arch/x86/include/asm/kvm-x86-ops.h | 1 - arch/x86/include/asm/kvm_host.h | 52 +++- arch/x86/kvm/lapic.c | 319 +++++++++++++++++----- arch/x86/kvm/lapic.h | 2 + arch/x86/kvm/svm/avic.c | 372 ++++++++++++-------------- arch/x86/kvm/svm/nested.c | 2 +- arch/x86/kvm/svm/svm.c | 8 +- arch/x86/kvm/svm/svm.h | 27 +- arch/x86/kvm/vmx/vmx.c | 58 +--- arch/x86/kvm/x86.c | 29 +- 11 files changed, 524 insertions(+), 357 deletions(-) base-commit: c04ec04c0d15a51aa33660be175ed978beb8de0c -- 2.39.0.314.g84b9a713c41-goog