From mboxrd@z Thu Jan 1 00:00:00 1970 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 74119E7AD45 for ; Thu, 5 Oct 2023 16:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbjJEQfJ (ORCPT ); Thu, 5 Oct 2023 12:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234708AbjJEQdB (ORCPT ); Thu, 5 Oct 2023 12:33:01 -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 ESMTPS id 76D8B2D79 for ; Thu, 5 Oct 2023 06:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696513861; 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=xzJsIbEdC1wOEGvDx6w4HMSs5sdtsVv5hyJaAp9aFTU=; b=Dmt72+eq1GVZrly8ySQuKI5E4jLSD8ZWcUz8pOy+D+oxXgM9JZRuxP/odIaCIhML4ORkoz KxU886IRflku7oDyBFmCiAvyO51cJjnsqyUpr0fEV0KqMiB3pCJtfVkBCc+769LIXOFsw4 JlH71pb+HKAD+jLclDu2eOWS0ZM7TjM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-178-six0725SOHufAbyivyIScA-1; Thu, 05 Oct 2023 08:50:00 -0400 X-MC-Unique: six0725SOHufAbyivyIScA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4064b38dc63so9533435e9.1 for ; Thu, 05 Oct 2023 05:50:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696510199; x=1697114999; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xzJsIbEdC1wOEGvDx6w4HMSs5sdtsVv5hyJaAp9aFTU=; b=gGijXZ/UgjR40vVf2ui4zfLAO2WK2ADDA9yVfdcywtrpJfFhy8xfq47C9t/gL0j/XU p5OqMZznbkCw/TAkAVo/w0QFKfyvCcquQvaQXTknj3hjJa+f4zQbrH0EJ1wZsSAFJC2i fHHWwsjg/CK8ZaGaf4CO8DXbh6O+X8JpqImi8L0i1tv4SEbQcrIZJeOXsv35LBv7CVdk K7bVmurllwin1+JBwm+CQLlmO/s7cdEt8iB5FlIAJRsAmOWCqrYkOjQpYgunYsYwdAUu 6TEuQ3BfMjX/r9Gd/fe5CV/r6VqAvhZjxEsppiBVtDcpfNFS9F9W4Sx+QvT2awe9Nv01 IVxA== X-Gm-Message-State: AOJu0YxzSJa9gzouciAvnP9urqkoz/x9oh7IJzHKAvOo5vW4oSIAJLFP yv47Li0T7jDtOVNjNNYy1PReg9clZHoY8toOywoN9pRtlEMuf8BObFptxt0BZ66TeTnK7E+N/8g 6sGEmICo2ZIN7/q2shO4ql76e X-Received: by 2002:a05:600c:1c96:b0:405:3622:382c with SMTP id k22-20020a05600c1c9600b004053622382cmr1352350wms.17.1696510199507; Thu, 05 Oct 2023 05:49:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEH/NInPYmO1UfH7A7RZ9fUuJQjy8h9hg0sJsC7opG/J+MuehyjgG03sU18g5lM4H7ISOKsIQ== X-Received: by 2002:a05:600c:1c96:b0:405:3622:382c with SMTP id k22-20020a05600c1c9600b004053622382cmr1352337wms.17.1696510199189; Thu, 05 Oct 2023 05:49:59 -0700 (PDT) Received: from starship ([89.237.100.246]) by smtp.gmail.com with ESMTPSA id v5-20020a05600c214500b003fbe791a0e8sm1486081wml.0.2023.10.05.05.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 05:49:58 -0700 (PDT) Message-ID: <74477cff348512fd88da8bb8fa901207fa29e316.camel@redhat.com> Subject: Re: [PATCH 02/10] KVM: SVM: Use AVIC_HPA_MASK when initializing vCPU's Physical ID entry From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini , Joerg Roedel Cc: kvm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Date: Thu, 05 Oct 2023 15:49:57 +0300 In-Reply-To: <20230815213533.548732-3-seanjc@google.com> References: <20230815213533.548732-1-seanjc@google.com> <20230815213533.548732-3-seanjc@google.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org У вт, 2023-08-15 у 14:35 -0700, Sean Christopherson пише: > 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. Masks are identical, but they refer to different things. AVIC_HPA_MASK is about avic's fields in vmcb, while AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK is about the portion of the physical id entry which has the address. They are the same currently but for documentation purposes I don't understand why removal of one of them makes sense. IMHO, it's best to define them to the same value, e.g: #define AVIC_HPA_MASK GENMASK_ULL(51, 12) #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK GENMASK_ULL(51, 12) Best regards, Maxim Levitsky > 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) == AVIC_MAX_ > static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_MAX_PHYSICAL_ID); > > #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) > +static_assert(AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK == AVIC_HPA_MASK); > +static_assert(AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK == GENMASK_ULL(51, 12)); > > #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) > > 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; > > - new_entry = __sme_set((page_to_phys(svm->avic_backing_page) & > - AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK) | > - AVIC_PHYSICAL_ID_ENTRY_VALID_MASK); > + new_entry = __sme_set(page_to_phys(svm->avic_backing_page) & AVIC_HPA_MASK) | > + AVIC_PHYSICAL_ID_ENTRY_VALID_MASK; > WRITE_ONCE(*entry, new_entry); > > svm->avic_physical_id_cache = entry;