Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp355087imw; Fri, 15 Jul 2022 04:47:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1soHmH0eOo9Axptr+3mFJ2V76slYLDfUj9ZGU3FbP+glXA2TjmHVwpXBpdxtHbHzqUflo0Q X-Received: by 2002:a17:90b:3ece:b0:1f0:6b2e:6fbf with SMTP id rm14-20020a17090b3ece00b001f06b2e6fbfmr18958604pjb.203.1657885632691; Fri, 15 Jul 2022 04:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657885632; cv=none; d=google.com; s=arc-20160816; b=v13VlA/WQTeugciM93Eav8GnJ8JTTxnlOU9sNIvE0C9W9QsBYi5HAGOgts4nLTOuet aPAhN29jcY1rSydRFusYjEFnxD+DG3fUzp+AbF1g9xakENKb51FVlpr7h4QhyOoHvAck DZyPbFIbPn+oOh7tcz7vB0ZqL51X9E2q8Jg3zkYhuvm2pvsObr5nUTcINAglDTs1vtg6 pgaQlE3khekg1TX73GgVhmplij265bd/rtpvibB1Ttfdeou1HfEcQsBITpbjKvhu1HjX 8ofSu5DvPRRAAO/o5NMWDoPqVSMV+b11AQgaD0HSfZuZMGLtkDvR2ynB/5UImn12lRfZ 5yww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=ki/rg86NxH+wVXrdnmin0JzoM5KA471l52TevDjA+74=; b=yTkm3TGututIFXoDT+pr9IPBdMjRUP5nqgJmo8J62TQWa6AX6sOoJy2xjz/celBSyv zAY8B6XJnSno+EPXgLK9kJ5aqpBemidUKt+m/brTJqDWX35X9LzOpaHpQMcUSml86EBC Nu4qhHClUaKWimdtJP1pbPeIRfETSvq7QNKorm3zG1MWDQHbTtUf1w3Rd+pgCcy+W9Rs R4rqJasFldSJa61RNuAIBs0DhxFMvPx8qJPVnF+TieGdyluoIEdGkePGrfisyADeInVh O7qTI8EXvUIR8rjgDtSjVm/RAR+3Av5+znwSZLqukMuTgMa4QcsOAyg2j2k9RJ9jCgFg K5Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gmGJ3Y5A; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h70-20020a638349000000b0040c8a3c4980si825596pge.190.2022.07.15.04.46.57; Fri, 15 Jul 2022 04:47:12 -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=gmGJ3Y5A; 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 S234441AbiGOLnb (ORCPT + 99 others); Fri, 15 Jul 2022 07:43:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232305AbiGOLn3 (ORCPT ); Fri, 15 Jul 2022 07:43:29 -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 ESMTP id 0719B88CC7 for ; Fri, 15 Jul 2022 04:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657885407; 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: in-reply-to:in-reply-to:references:references; bh=ki/rg86NxH+wVXrdnmin0JzoM5KA471l52TevDjA+74=; b=gmGJ3Y5ATUZPwfEq9QrYgbiAF/M6in7TeIHKm9Om3MRSuWfrX3+LQdvpthKf0/X1juxIZ0 niWb/cXMBmUAY+7kPtieUFUhGVfRWB6L23kM1vyDEiHEeSTqKlp99p7ZmyqQzCQoLOolP/ BvrN/qBCCXXqnrsrmQ5xYtVWRpECbhc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-478-30UILfKFP32zO5rZiERzcQ-1; Fri, 15 Jul 2022 07:43:26 -0400 X-MC-Unique: 30UILfKFP32zO5rZiERzcQ-1 Received: by mail-wm1-f71.google.com with SMTP id a6-20020a05600c348600b003a2d72b7a15so4129789wmq.9 for ; Fri, 15 Jul 2022 04:43:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=ki/rg86NxH+wVXrdnmin0JzoM5KA471l52TevDjA+74=; b=DCWO1pbbjK3oasyq3kEZ5arR4fd1IV9Jo/Wt+e55QHBQ+hQXPESCqp6VIA7DRcDtMW xpWJdKeU0lUKY3Q9P0P7O2GBnNu+ZN/69WWRCfPToco9DqfSDRRKiRSWOk/0nsdA+o6c YoCAGlaNvtIIaGE8u4ocCQLcZukYugfUJe8JU5OyAPpQk+tv5+xS2P+2GWcmM/CLlXZM WjEA9shsNfYmvzbxQvMdfPZVgVApo+hop7z4mc9cUbsMOkJoUsXY1x0/LArrzOCRJa7m KekmFUURgTJOgT7RIub/cXFq9DAOMg9IoKFSzS31BIoLuvcaq8REa6yNbRzktNnbncnO dubQ== X-Gm-Message-State: AJIora+CWR8I3BP6qyPwwMEbXO2Fo/GXLZ2Ud4APILN3yWG2TMoBfKc2 f+fCj11Cvwc4N7McDoppBt3NzmoZG3VpeqLt3l7lBWQyqMnsIO6IXu2UFI4Mz9jbiUBTDrzXYGW J0susof5mUXw0dqsYRkkqUuUM X-Received: by 2002:a05:600c:4e90:b0:3a0:57d6:4458 with SMTP id f16-20020a05600c4e9000b003a057d64458mr13918805wmq.198.1657885404891; Fri, 15 Jul 2022 04:43:24 -0700 (PDT) X-Received: by 2002:a05:600c:4e90:b0:3a0:57d6:4458 with SMTP id f16-20020a05600c4e9000b003a057d64458mr13918780wmq.198.1657885404641; Fri, 15 Jul 2022 04:43:24 -0700 (PDT) Received: from fedora (nat-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id m24-20020a056000181800b0021d68e1fd42sm3655846wrh.89.2022.07.15.04.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 04:43:23 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , "Durrant, Paul" Cc: "x86@kernel.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , David Woodhouse , Paolo Bonzini , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: Re: [PATCH v5] KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present In-Reply-To: References: <20220629130514.15780-1-pdurrant@amazon.com> <369c3e9e02f947e2a2b0c093cbddc99c@EX13D32EUC003.ant.amazon.com> Date: Fri, 15 Jul 2022 13:43:22 +0200 Message-ID: <87ilnymwit.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 Sean Christopherson writes: > On Tue, Jul 12, 2022, Durrant, Paul wrote: >> > > @@ -1855,3 +1858,51 @@ void kvm_xen_destroy_vm(struct kvm *kvm) >> > > if (kvm->arch.xen_hvm_config.msr) >> > > static_branch_slow_dec_deferred(&kvm_xen_enabled); >> > > } >> > > + >> > > +void kvm_xen_after_set_cpuid(struct kvm_vcpu *vcpu) >> > > +{ >> > > + u32 base = 0; >> > > + u32 limit; >> > > + u32 function; >> > > + >> > > + vcpu->arch.xen.cpuid_tsc_info = 0; >> > > + >> > > + for_each_possible_hypervisor_cpuid_base(function) { >> > > + struct kvm_cpuid_entry2 *entry = kvm_find_cpuid_entry(vcpu, function, 0); >> > > + >> > > + if (entry && >> > > + entry->ebx == XEN_CPUID_SIGNATURE_EBX && >> > > + entry->ecx == XEN_CPUID_SIGNATURE_ECX && >> > > + entry->edx == XEN_CPUID_SIGNATURE_EDX) { >> > > + base = function; >> > > + limit = entry->eax; >> > > + break; >> > > + } >> > > + } >> > > + if (!base) >> > > + return; >> > >> > Rather than open code a variant of kvm_update_kvm_cpuid_base(), that helper can >> > be tweaked to take a signature. Along with a patch to provide a #define for Xen's >> > signature as a string, this entire function becomes a one-liner. >> > >> >> Sure, but as said above, we could make capturing the limit part of the >> general function too. It could even be extended to capture the Hyper-V >> base/limit too. As for defining the sig as a string... I guess it would be >> neater to use the values from the Xen header, but it'll probably make the >> code more ugly so a secondary definition is reasonable. > > The base needs to be captured separately for KVM and Xen because KVM (and presumably > Xen itself since Xen also allows a variable base) supports advertising multiple > hypervisors to the guest. I don't know if there are any guests that will concurrently > utilize multiple hypervisor's paravirt features, so maybe we could squeak by, but > saving 4 bytes isn't worth the risk. > > AFAIK, Hyper-V doesn't allow for a variable base, and so doesn't utilize the > for_each_possible... macro. FWIW, this matches my understanding too: Windows guests don't seem to check anything besides 0x40000001 and give up if Hyper-V's id is not there. -- Vitaly