From nobody Thu Dec 18 07:51:19 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 88DBFC04FE0 for ; Tue, 15 Aug 2023 21:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240288AbjHOVgR (ORCPT ); Tue, 15 Aug 2023 17:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240295AbjHOVfw (ORCPT ); Tue, 15 Aug 2023 17:35:52 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DE5B1FCE for ; Tue, 15 Aug 2023 14:35:42 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-68877684da1so753452b3a.1 for ; Tue, 15 Aug 2023 14:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692135342; x=1692740142; 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=SFpi+WGuvYcTqc5iutU3gDOga20tlCn0kmKYiGzba1s=; b=74tVcNm00OZaHpD1xVuPf4Jjj8KBDUlS++wNuw6IOr9Xww7JLEHfMfpDin20hyekXn UAZzdeOvKkgZUS6btGqtbj1EtOcbudgfP8uunjSwa10kl53dOsD2H4PMXQQ7CpyOKOA0 fFJjtiO9IkGgau4YpenIfY616mMKNSNOk/KybhEQhb/R1OBjzFS1FxAE5sc0kRQ+eebR f+hPBPVTsmtcKA98ubnfVz6rHszpNxsmqCasREoyiC8y1zLZQWM3maIi8g+mst+1jtCV qq4sZhxyR+JYTtYagySkZoMNAZfN36FpIVb+Q3rAOdXkc6+JefuhcRoK+Iwm0FGQTYOH wB+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692135342; x=1692740142; 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=SFpi+WGuvYcTqc5iutU3gDOga20tlCn0kmKYiGzba1s=; b=M4wFFSbebaN4Xj0hBKTS11vw5PTWluKnUVG7z1R19OVx6yAR1YIymLexhTvE4RVkPY 3wKHmRyRf4vV7wKaRpkSOj4TNgffOhf5w+X6DbtFzXQolzX2mJ8LZZE7PbOEk9z70SON nngzCgcVoniT2+bYIqQ0qUXw31B5QZQJ+ZL5ev3dHbEsI+xi8m3qWRCebqK2AR0vD9Vk 4WY5Fnh+/OTYy+yM8rMQyKHUaniiOetsFK/TkrXvJ57URnoccPpQ7f8jQZrEnSvGgRSY uXzYQFXLMd+DJSA31h1r89D+lroaXVHQmFsQ2RlSDIt0JZEWUOrGO4CrSn01XL5rxtPl CC+A== X-Gm-Message-State: AOJu0YyEJjW6t4vXwl58HGCzfhNDe6LuMfp9HkcZXylccMTdSzeAT/7q PYRw119hU1zKvVk5FMPgwhkaH0GSshA= X-Google-Smtp-Source: AGHT+IG5MHzZLav8gJ1/MnkDQMEocS8Nk95fglVaOP6iG8M0zB5pJMu3CTRFZ48wrIVfKHX4OCFGKU3C7d8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:a17:b0:682:24c1:2951 with SMTP id p23-20020a056a000a1700b0068224c12951mr8029pfh.0.1692135342319; Tue, 15 Aug 2023 14:35:42 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 15 Aug 2023 14:35:25 -0700 In-Reply-To: <20230815213533.548732-1-seanjc@google.com> Mime-Version: 1.0 References: <20230815213533.548732-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230815213533.548732-3-seanjc@google.com> Subject: [PATCH 02/10] KVM: SVM: Use AVIC_HPA_MASK when initializing vCPU's Physical ID entry From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Joerg Roedel Cc: kvm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Maxim Levitsky Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use AVIC_HPA_MASK instead of AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK when initializing a vCPU's Physical ID table entry, the two masks are identical. Keep both #defines for now, along with a few new static asserts. A future change will clean up the entire mess (spoiler alert, the masks are pointless). Opportunisitically move the bitwise-OR of AVIC_PHYSICAL_ID_ENTRY_VALID_MASK outside of the call to __sme_set(), again to pave the way for code deduplication. __sme_set() is purely additive, i.e. ORing in the valid bit before or after the C-bit does not change the end result. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/svm.h | 2 ++ arch/x86/kvm/svm/avic.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 1e70600e84f7..609c9b596399 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -285,6 +285,8 @@ static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX= _INDEX_MASK) =3D=3D AVIC_MAX_ static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) =3D= =3D X2AVIC_MAX_PHYSICAL_ID); =20 #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) +static_assert(AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK =3D=3D AVIC_HPA_MAS= K); +static_assert(AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK =3D=3D GENMASK_ULL(= 51, 12)); =20 #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) =20 diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 7062164e4041..442c58ef8158 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -308,9 +308,8 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu) if (!entry) return -EINVAL; =20 - new_entry =3D __sme_set((page_to_phys(svm->avic_backing_page) & - AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK) | - AVIC_PHYSICAL_ID_ENTRY_VALID_MASK); + new_entry =3D __sme_set(page_to_phys(svm->avic_backing_page) & AVIC_HPA_M= ASK) | + AVIC_PHYSICAL_ID_ENTRY_VALID_MASK; WRITE_ONCE(*entry, new_entry); =20 svm->avic_physical_id_cache =3D entry; --=20 2.41.0.694.ge786442a9b-goog