From nobody Fri Sep 12 23:58:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68F17C61DA4 for ; Tue, 7 Feb 2023 00:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230209AbjBGAWF (ORCPT ); Mon, 6 Feb 2023 19:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbjBGAWC (ORCPT ); Mon, 6 Feb 2023 19:22:02 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B55AE30B33 for ; Mon, 6 Feb 2023 16:22:00 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id qb3-20020a17090b280300b002307b2547b5so54055pjb.1 for ; Mon, 06 Feb 2023 16:22:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=nzcAfp64RgqcLL8tXedEG2XEeGgWNFMNxiM0uRzJp4w=; b=Q6qEG83GMi8v8ZeZsxpbkqifoEW4rwCPZIInoKHwi4YthNxXboTG0Fhk1oeHAIthAg 7LMmg45BVvXqMMHjAtXuEyv9eTpx5EBX8yA7Q+UmY6a5PivElMs8Gv7Y+BrwetMI1E3z Oh+kaNm6/qiIeIzO6P+Vydkj6iPPzLfXfgCMUo2wdMx/9ju+/1mTcSt8D1H0wA06VQcS uPnkSfeVdOdDPQTX5uiLDHXqIW3ABwVMPjJA1aUyh4mRlShQZVmAmbDE0n+YcKP7o6tb vrYzSG/HKcN4jMGJ0vJBGK2g+Z/dM6DQvrPg9dy5t2OgPm28bIGfZRZI71T1yQ4iKsZs bFOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nzcAfp64RgqcLL8tXedEG2XEeGgWNFMNxiM0uRzJp4w=; b=Sdwoacrs0PGvBkuZRGbMNVE2cmYSCX9+PsGkYjvzpjgPZFD0oVqfnAQriGA9DqBCda XfFcID4OIkxunrYCEqnHpIouC6nDmMyQoNLg7dLcTRpKHRlOYZw0fnC7QNi1BOyzD0pg VOxJF4lSOhztuEPM+Cbj4khMEV1Xc3l/fyWi6o8wt0+kifVyvW26lwp9q+vVmD3GRxqa 9EhcefU4AvdtBK2HMtqgAUCR0itQkhozZJwm5oVyK2WRzLhDLTbDtPCc84r2WoL4g1gD VTk5WRxGhFKtFQFKit4mq2E5HHc7YkwvCBtd+qeQDTQ0L/cI2xr82riR+WdSOJqYXbk2 Bkuw== X-Gm-Message-State: AO0yUKUc9KDC2Tm0Cg26bwdBUum8LEmmXk0ubVVwSooE5zbkExi21O3c P6+ARAmj6++G4bV4Lxy9OxJ5X/P+Vxs= X-Google-Smtp-Source: AK7set/TtEmNMITnoUdIjvea4mIwpEfLF4mEaqloWfuQfGau/ehx6R7oR9q8c2pwHigEZiZ46oaqcc1nez0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a62:1a4a:0:b0:58d:bb58:ac78 with SMTP id a71-20020a621a4a000000b0058dbb58ac78mr275531pfa.48.1675729320237; Mon, 06 Feb 2023 16:22:00 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 7 Feb 2023 00:21:54 +0000 In-Reply-To: <20230207002156.521736-1-seanjc@google.com> Mime-Version: 1.0 References: <20230207002156.521736-1-seanjc@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230207002156.521736-2-seanjc@google.com> Subject: [PATCH v2 1/3] KVM: SVM: Fix a benign off-by-one bug in AVIC physical table mask From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Alejandro Jimenez , Suravee Suthikulpanit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define the "physical table max index mask" as bits 8:0, not 9:0. x2AVIC currently supports a max of 512 entries, i.e. the max index is 511, and the inputs to GENMASK_ULL() are inclusive. The bug is benign as bit 9 is reserved and never set by KVM, i.e. KVM is just clearing bits that are guaranteed to be zero. Note, as of this writing, APM "Rev. 3.39-October 2022" incorrectly states that bits 11:8 are reserved in Table B-1. VMCB Layout, Control Area. I.e. that table wasn't updated when x2AVIC support was added. Opportunistically fix the comment for the max AVIC ID to align with the code, and clean up comment formatting too. Fixes: 4d1d7942e36a ("KVM: SVM: Introduce logic to (de)activate x2AVIC mode= ") Cc: stable@vger.kernel.org Cc: Alejandro Jimenez Cc: Suravee Suthikulpanit Signed-off-by: Sean Christopherson Reviewed-by: Suravee Suthikulpanit Tested-by: Suravee Suthikulpanit --- arch/x86/include/asm/svm.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index cb1ee53ad3b1..770dcf75eaa9 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -261,20 +261,22 @@ enum avic_ipi_failure_cause { AVIC_IPI_FAILURE_INVALID_BACKING_PAGE, }; =20 -#define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(9, 0) +#define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0) =20 /* - * For AVIC, the max index allowed for physical APIC ID - * table is 0xff (255). + * For AVIC, the max index allowed for physical APIC ID table is 0xfe (254= ), as + * 0xff is a broadcast to all CPUs, i.e. can't be targeted individually. */ #define AVIC_MAX_PHYSICAL_ID 0XFEULL =20 /* - * For x2AVIC, the max index allowed for physical APIC ID - * table is 0x1ff (511). + * For x2AVIC, the max index allowed for physical APIC ID table is 0x1ff (= 511). */ #define X2AVIC_MAX_PHYSICAL_ID 0x1FFUL =20 +static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) =3D=3D= AVIC_MAX_PHYSICAL_ID); +static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) =3D= =3D X2AVIC_MAX_PHYSICAL_ID); + #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL =20 --=20 2.39.1.519.gcb327c4b5f-goog From nobody Fri Sep 12 23:58:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C76C05027 for ; Tue, 7 Feb 2023 00:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbjBGAWO (ORCPT ); Mon, 6 Feb 2023 19:22:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230205AbjBGAWE (ORCPT ); Mon, 6 Feb 2023 19:22:04 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7946D31E3F for ; Mon, 6 Feb 2023 16:22:02 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id z8-20020a170902834800b001990ad8de5bso2954081pln.10 for ; Mon, 06 Feb 2023 16:22:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=I+Z+wnDCARltqljoL3uU/iOxjVMjPeIS4mK0SvgvmXM=; b=E+x/tX7HzgELHcR+Ij6x7Y0MW/bHTaFLnLIVqRX3JDz8e8Tvpq5w7lT+zejYXOjKcm 147j5MdceO1IYTLoomosRta3aOcWTzHdvvjyBYnXrX7C6rAQW7rNYFm78r9QSo3bt/Xt dA4RKuHph/QH7FmEfBbPnxJslYmLR+Wb1gLR4n8A7sYsnr88bxF6pumaDYSAXWQPrvLB krCdEp6vYemo605TU9sVcoJgE65NsIgGaYhamjmFukKJZCeiphVfdXJ9FMq7r/+j2Bju Js5/j0LA4vFOq1K36AfQvjeZNWvmodCjPYkpEiSsI+7M4gvjrqNWBv0lqedseD5pMUtn 5SXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=I+Z+wnDCARltqljoL3uU/iOxjVMjPeIS4mK0SvgvmXM=; b=w0Pm5SJA8HQ4o9fD1qtzl8PwmtEIXgEOldhAWp8C9+9yjdmqvvh0uLi7fBbcQ9Im4Z /45P7Q6HIfwDC8V9GFQ5RtPUUb6m71KpbbP2x3Q3d5eYQ74vHtqHYwtWNaKbr5+Yhoh+ zZD3+BlTTqXrcIpj/lOov98tfniLyFe/T2T1FpTbBf2iySwUfvy88rJK/necHn63J0zX uxUEsziHMvDVbFdB5Q4Uepm/xyI/0cImxudQLbzIA18RZo4b65xsmwUnbveQvEZKKmi0 XtFGhhzr3t5h1+/2AbHBl0W/161WAIzWrrbNECFcJ9jC5mxGcRRflOfG3AGoRJH1X9BF ydNA== X-Gm-Message-State: AO0yUKXdq7T/7vU9XINJvCOmw5OrmxP4uUPbL3yXKBOB/Oit4YDzKoun en4Su1fesGjD2bRRcKjk7fZ4Wq3kPcQ= X-Google-Smtp-Source: AK7set8SfQBsfaz/UvElBol4nLp55vhh2sP6i/9kvIyliVJ6c9yEtjjeOBDxe83WkEEHSP+zX2xYU1BSyo4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:f54b:b0:192:c7f1:977b with SMTP id h11-20020a170902f54b00b00192c7f1977bmr219867plf.1.1675729321872; Mon, 06 Feb 2023 16:22:01 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 7 Feb 2023 00:21:55 +0000 In-Reply-To: <20230207002156.521736-1-seanjc@google.com> Mime-Version: 1.0 References: <20230207002156.521736-1-seanjc@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230207002156.521736-3-seanjc@google.com> Subject: [PATCH v2 2/3] KVM: SVM: Modify AVIC GATag to support max number of 512 vCPUs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Alejandro Jimenez , Suravee Suthikulpanit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Suravee Suthikulpanit Define AVIC_VCPU_ID_MASK based on AVIC_PHYSICAL_MAX_INDEX, i.e. the mask that effectively controls the largest guest physical APIC ID supported by x2AVIC, instead of hardcoding the number of bits to 8 (and the number of VM bits to 24). The AVIC GATag is programmed into the AMD IOMMU IRTE to provide a reference back to KVM in case the IOMMU cannot inject an interrupt into a non-running vCPU. In such a case, the IOMMU notifies software by creating a GALog entry with the corresponded GATag, and KVM then uses the GATag to find the correct VM+vCPU to kick. Dropping bit 8 from the GATag results in kicking the wrong vCPU when targeting vCPUs with x2APIC ID > 255. Fixes: 4d1d7942e36a ("KVM: SVM: Introduce logic to (de)activate x2AVIC mode= ") Cc: stable@vger.kernel.org Reported-by: Alejandro Jimenez Signed-off-by: Suravee Suthikulpanit Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Reviewed-by: Suravee Suthikulpanit Tested-by: Suravee Suthikulpanit --- arch/x86/kvm/svm/avic.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index ca684979e90d..326341a22153 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -27,19 +27,29 @@ #include "irq.h" #include "svm.h" =20 -/* AVIC GATAG is encoded using VM and VCPU IDs */ -#define AVIC_VCPU_ID_BITS 8 -#define AVIC_VCPU_ID_MASK ((1 << AVIC_VCPU_ID_BITS) - 1) +/* + * Encode the arbitrary VM ID and the vCPU's default APIC ID, i.e the vCPU= ID, + * into the GATag so that KVM can retrieve the correct vCPU from a GALog e= ntry + * if an interrupt can't be delivered, e.g. because the vCPU isn't running. + * + * For the vCPU ID, use however many bits are currently allowed for the max + * guest physical APIC ID (limited by the size of the physical ID table), = and + * use whatever bits remain to assign arbitrary AVIC IDs to VMs. Note, the + * size of the GATag is defined by hardware (32 bits), but is an opaque va= lue + * as far as hardware is concerned. + */ +#define AVIC_VCPU_ID_MASK AVIC_PHYSICAL_MAX_INDEX_MASK =20 -#define AVIC_VM_ID_BITS 24 -#define AVIC_VM_ID_NR (1 << AVIC_VM_ID_BITS) -#define AVIC_VM_ID_MASK ((1 << AVIC_VM_ID_BITS) - 1) +#define AVIC_VM_ID_SHIFT HWEIGHT32(AVIC_PHYSICAL_MAX_INDEX_MASK) +#define AVIC_VM_ID_MASK (GENMASK(31, AVIC_VM_ID_SHIFT) >> AVIC_VM_ID_SHI= FT) =20 -#define AVIC_GATAG(x, y) (((x & AVIC_VM_ID_MASK) << AVIC_VCPU_ID_BITS) | \ +#define AVIC_GATAG(x, y) (((x & AVIC_VM_ID_MASK) << AVIC_VM_ID_SHIFT) | \ (y & AVIC_VCPU_ID_MASK)) -#define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VCPU_ID_BITS) & AVIC_VM_ID_MASK) +#define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VM_ID_SHIFT) & AVIC_VM_ID_MASK) #define AVIC_GATAG_TO_VCPUID(x) (x & AVIC_VCPU_ID_MASK) =20 +static_assert(AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) =3D=3D -1u); + static bool force_avic; module_param_unsafe(force_avic, bool, 0444); =20 --=20 2.39.1.519.gcb327c4b5f-goog From nobody Fri Sep 12 23:58:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 413F0C61DA4 for ; Tue, 7 Feb 2023 00:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229921AbjBGAWR (ORCPT ); Mon, 6 Feb 2023 19:22:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjBGAWF (ORCPT ); Mon, 6 Feb 2023 19:22:05 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E19D32E60 for ; Mon, 6 Feb 2023 16:22:03 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id mm21-20020a17090b359500b00230aa18342bso1921985pjb.4 for ; Mon, 06 Feb 2023 16:22:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=Z+LmZZRuX+KyZW/71ICS7KxhCfKW5CHjrLQNU61de+A=; b=l/9qGaSnf0c5yPSH7xrquOODy/3TnXfj8KaD3epHTviVTmOJYgWndznufP1aYLuuOJ YcbUl1G15s146UHSB3syejf9+slsLGXulYhLZl94LQQTvZtL6CaIknehSmbIgdn4cuG8 KGf7Vkd1FQsk0Am3KInurKzNKnym94ZGoLzBolWTHVLKIaNveW2X9CjCTvidppbeAyyn YGN6dcxtuwBK5mRxnzrYu7GaEsHS91pz6AbfHdH4R0ek8afC+JCp0vWT7q+aprQRY/4k swb0UaCOdiztOvS54BhVN7lOq3Fw1VssYVcgxbKPjJIE87zu4m65o4HxiuQ0GwnuqPAJ obUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z+LmZZRuX+KyZW/71ICS7KxhCfKW5CHjrLQNU61de+A=; b=ijba8I79UcAW7c3B2ue/VECLW6PDmJBJMdsMtDVzzNkR4HC27UGydn/k9s3nkFfh8j z+5wEnlgDJY+ED4YFtkliehYj4b02H9S/DNQVt2vP+uMImAPHSbY4fFN+qPt4wveUYYl GQwOOY1Rl1PGDtbMjU0trpLSJOv2sYpzwwdybmIu2beNv1nshyMnA3KT8y9+EIblxuxW 9taL6hbwuxShWFLrGjBPgBspEOpZ1zQnjEwhe9sxQ8qT6dNQccIqFLq06fEmDKhelFIu ws+SMOCjChFIAhw3chxqj8eUeJdJRgD7hV/h9See8AOVAAqfA1SgtBhkZEEqcV8xtj37 tDww== X-Gm-Message-State: AO0yUKXMMlylBRYw0o5TFKv0o6tBeftq2/GJmIQCFXvxOzOeqc88DhLm k1n5J7uHve1tIOvHD0UlKX5VnG+A6RY= X-Google-Smtp-Source: AK7set+a49kwgE2Gq18gJWSmXwig5Y6bm6XhOCGLCUFhuXgeoq2FvJZfOy6P0wExL/IzHZ/6K+LDfxRA0wY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:2309:b0:199:292f:dbc7 with SMTP id d9-20020a170903230900b00199292fdbc7mr225078plh.1.1675729323330; Mon, 06 Feb 2023 16:22:03 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 7 Feb 2023 00:21:56 +0000 In-Reply-To: <20230207002156.521736-1-seanjc@google.com> Mime-Version: 1.0 References: <20230207002156.521736-1-seanjc@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230207002156.521736-4-seanjc@google.com> Subject: [PATCH v2 3/3] KVM: SVM: WARN if GATag generation drops VM or vCPU ID information From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Alejandro Jimenez , Suravee Suthikulpanit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" WARN if generating a GATag given a VM ID and vCPU ID doesn't yield the same IDs when pulling the IDs back out of the tag. Don't bother adding error handling to callers, this is very much a paranoid sanity check as KVM fully controls the VM ID and is supposed to reject too-big vCPU IDs. Signed-off-by: Sean Christopherson Reviewed-by: Suravee Suthikulpanit Tested-by: Suravee Suthikulpanit --- arch/x86/kvm/svm/avic.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 326341a22153..cfc8ab773025 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -43,12 +43,21 @@ #define AVIC_VM_ID_SHIFT HWEIGHT32(AVIC_PHYSICAL_MAX_INDEX_MASK) #define AVIC_VM_ID_MASK (GENMASK(31, AVIC_VM_ID_SHIFT) >> AVIC_VM_ID_SHI= FT) =20 -#define AVIC_GATAG(x, y) (((x & AVIC_VM_ID_MASK) << AVIC_VM_ID_SHIFT) | \ - (y & AVIC_VCPU_ID_MASK)) #define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VM_ID_SHIFT) & AVIC_VM_ID_MASK) #define AVIC_GATAG_TO_VCPUID(x) (x & AVIC_VCPU_ID_MASK) =20 -static_assert(AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) =3D=3D -1u); +#define __AVIC_GATAG(vm_id, vcpu_id) ((((vm_id) & AVIC_VM_ID_MASK) << AVIC= _VM_ID_SHIFT) | \ + ((vcpu_id) & AVIC_VCPU_ID_MASK)) +#define AVIC_GATAG(vm_id, vcpu_id) \ +({ \ + u32 ga_tag =3D __AVIC_GATAG(vm_id, vcpu_id); \ + \ + WARN_ON_ONCE(AVIC_GATAG_TO_VCPUID(ga_tag) !=3D (vcpu_id)); \ + WARN_ON_ONCE(AVIC_GATAG_TO_VMID(ga_tag) !=3D (vm_id)); \ + ga_tag; \ +}) + +static_assert(__AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) =3D=3D -1u); =20 static bool force_avic; module_param_unsafe(force_avic, bool, 0444); --=20 2.39.1.519.gcb327c4b5f-goog