Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp544011rdb; Thu, 30 Nov 2023 11:19:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGImRfiT5IpWSLxLt1hmJFNV6F82SIM8n3m7099GFwtqmra9WDKaAlncX1Od4uT4mPjK9uo X-Received: by 2002:a17:902:dac7:b0:1cf:c397:8f09 with SMTP id q7-20020a170902dac700b001cfc3978f09mr20187835plx.55.1701371955855; Thu, 30 Nov 2023 11:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701371955; cv=none; d=google.com; s=arc-20160816; b=mpIY3atpRCNqTnsIGu1kv1c+0iHy9Bv+M8QoLsvJEj3q8hzlmVZCwI7mWgapOs7XhR 3/Wlv5y03oIhxDoi4bIfSOunv1GRPjIfAwUyjqQo7Z04HZiWg9f0HOyvjjnfKgvUKB7h PNB37UcYS9pUdwcEJ/lq/NtahIdPtQ79i9Sc3yBS8WOguXbEHjsM9nJ+DQS/jYa+49xy buNv8loukQ6mBfE8Ki2UVQU8v1jd73wB5fFzd36mwOtUyTEqH/Ec8Xlq5iXTsU1h6iw3 ebJ3snRXMSzwYUGTtzIVQqEgaKxmcBIZ1abvz6nOGaA1+hdl8Atie0DzDA8Rz70ewhdL W5Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=9ROI9QsVBebZ2z46uwx8HAg7XDg30OxxOQZ6JWNYVYc=; fh=qm/3G+Adpj/B7TaijAEJbs/udoUfJHgp4MqQlWOh7ts=; b=mu9d3PkB88+YIasHo0NWJzWQOBlm5QkZQdQiGfhpcsYF6J5MMZRrJCPMrV7GBYtdjy 0Apu9fVtrM0sFWSnRxZ+F9ZP4mkwhjcF6b6NXGdSHfV8F4ujYeLmna8pmqybZyd0j4hx nZWn4w2PYSABC72wkdq1j3UFy8uwoymvIyGFHeHM6Y+Ix4Hb0811V3KPRd/gcMFlffg3 0HvLB8GqAxOHK3TBBiBEcLVc7hf5TmTm0KradYpPwNuEsNHYW0AiTq7W38hy4b4zd9BT 2rCiKEM2ZwLYxve0+ldfWN6IzWC0jnQZzyZVhZQ6X7eRnCulNAcowgamg8jamq+Mbi5/ hR9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hZjRjnul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id e10-20020a17090301ca00b001cc644a2131si1873578plh.74.2023.11.30.11.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 11:19:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hZjRjnul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 65B2680CCD01; Thu, 30 Nov 2023 11:19:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376337AbjK3TTA (ORCPT + 99 others); Thu, 30 Nov 2023 14:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbjK3TS7 (ORCPT ); Thu, 30 Nov 2023 14:18:59 -0500 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 B141B1A4 for ; Thu, 30 Nov 2023 11:19:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701371945; 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=9ROI9QsVBebZ2z46uwx8HAg7XDg30OxxOQZ6JWNYVYc=; b=hZjRjnulxF4DcNZlP2rHsM2fLqi7/b/XTxQRgCAIFh+LlpdlqrvE4n3BbnIiNWYpFgAPjK EOdgNPdPixL7srjB/sdpc9ADpT3FsZEIpxVmFNlowS6G8i/4aLlzbtBG7V5cnEztGrIdt2 W/Vg4U7Xbm8hjcNuyzx2CAMu9beI3gg= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-uB6Xh8-AMjC6FLMqRpIFVQ-1; Thu, 30 Nov 2023 14:19:00 -0500 X-MC-Unique: uB6Xh8-AMjC6FLMqRpIFVQ-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-54366567af4so1783977a12.1 for ; Thu, 30 Nov 2023 11:18:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701371937; x=1701976737; 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=9ROI9QsVBebZ2z46uwx8HAg7XDg30OxxOQZ6JWNYVYc=; b=cjO302y6DnNU1d1NBcwjtPynYFLByeOwRx2zNhV+bb+0igDzpg5HC7bUuXN2UZ+N+1 y+Xs0Dm49HZ4jZ+YbqqsMi7CCA7BkQY3InqAmvdY7ArYekeNF7cg0eXEHK8ftFwO9n0j 1axO5rM7waJohwl5xdnZRoPsSi0ddLeiRXvAxTmEynXUt4fwMdGWsmtmWBaihkfkvKUk ES3J+QHz+DdbKlW/9fLw3AB/TQjeFPB5TKoCLQ0U60zrNZNIlMglbyhv1wN/t9Tf0CkL 2jv1I5ysUh+5SQwwww+H4xM4uU6bPgyzI08PYJVaVecohNvsas/rG7NjifVpN8iSVpJT FJxA== X-Gm-Message-State: AOJu0Yx0IGTsECrbEH/CsEvUxdtMcUfn6cAhzKOLjjel3FN5my9+QTEj mrO5iYm/wfyxRxYFxBxKI0d8ylcxZmKwaLiBAIC2UgurrA5txJMMNXJ7t0aZQ5BYT57Z5yGyeor pIGaxd1hjfS6IazxHKwim8+n9BryuPlkA X-Received: by 2002:aa7:d4d1:0:b0:54b:3f0c:7fe0 with SMTP id t17-20020aa7d4d1000000b0054b3f0c7fe0mr12643edr.6.1701371936832; Thu, 30 Nov 2023 11:18:56 -0800 (PST) X-Received: by 2002:a05:6512:50b:b0:50b:d552:267c with SMTP id o11-20020a056512050b00b0050bd552267cmr42172lfb.3.1701365812565; Thu, 30 Nov 2023 09:36:52 -0800 (PST) Received: from starship ([5.28.147.32]) by smtp.gmail.com with ESMTPSA id v13-20020a056512048d00b0050bbdf9616bsm214270lfq.217.2023.11.30.09.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 09:36:52 -0800 (PST) Message-ID: <156f037f96407f77dd71373be504da50b78f671c.camel@redhat.com> Subject: Re: [PATCH v7 10/26] KVM: x86: Refine xsave-managed guest register/MSR reset handling From: Maxim Levitsky To: Yang Weijiang , seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, john.allen@amd.com Date: Thu, 30 Nov 2023 19:36:49 +0200 In-Reply-To: <20231124055330.138870-11-weijiang.yang@intel.com> References: <20231124055330.138870-1-weijiang.yang@intel.com> <20231124055330.138870-11-weijiang.yang@intel.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: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 11:19:13 -0800 (PST) On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote: > Tweak the code a bit to facilitate resetting more xstate components in > the future, e.g., adding CET's xstate-managed MSRs. > > No functional change intended. > > Signed-off-by: Yang Weijiang > --- > arch/x86/kvm/x86.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index b9c2c0cd4cf5..16b4f2dd138a 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -12132,6 +12132,11 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) > static_branch_dec(&kvm_has_noapic_vcpu); > } > > +static inline bool is_xstate_reset_needed(void) > +{ > + return kvm_cpu_cap_has(X86_FEATURE_MPX); > +} > + > void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > { > struct kvm_cpuid_entry2 *cpuid_0x1; > @@ -12189,7 +12194,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > kvm_async_pf_hash_reset(vcpu); > vcpu->arch.apf.halted = false; > > - if (vcpu->arch.guest_fpu.fpstate && kvm_mpx_supported()) { > + if (vcpu->arch.guest_fpu.fpstate && is_xstate_reset_needed()) { > struct fpstate *fpstate = vcpu->arch.guest_fpu.fpstate; > > /* > @@ -12199,8 +12204,12 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > if (init_event) > kvm_put_guest_fpu(vcpu); > > - fpstate_clear_xstate_component(fpstate, XFEATURE_BNDREGS); > - fpstate_clear_xstate_component(fpstate, XFEATURE_BNDCSR); > + if (kvm_cpu_cap_has(X86_FEATURE_MPX)) { > + fpstate_clear_xstate_component(fpstate, > + XFEATURE_BNDREGS); > + fpstate_clear_xstate_component(fpstate, > + XFEATURE_BNDCSR); > + } > > if (init_event) > kvm_load_guest_fpu(vcpu); Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky