From nobody Sun Nov 24 18:43:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1716993183; cv=none; d=zohomail.com; s=zohoarc; b=V0Qbhsi4YHRgb+oIKs3u7aGxKSXlrMbkuxObsvYXLCWsqHaQwLGyZ9LpliBx5JFoIYUob/H1NFUyoLcZk8XjwjUogbpt4q9WWk7c6dqP8cuNcr1PuMvPbg7SmAXpn8lYFoV0HMbIJHKCUon9EtW2Nnhyupr2UZ+WJKJA29h9yjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716993183; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JQ0Z2MuZPai5+x8nYCnYhzQNJt6RhMWelwC5TWM5Ogs=; b=XRiKBjZYuOz5qejPhIYBdoVmkNZYBFVabbcU3emITjnpy8GIKUXrU0BtRAqmhUy2Q2TrowQokg1nxl4bZ29iB02ObHASuaHkuQqX9rsMIArmBr8qC7yADWURuCk1xHFyf+eYYljL7zOOd42ERmpnF/FY4AZ2wG/DYS0pgs6Xjx4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1716993183683573.0172210182717; Wed, 29 May 2024 07:33:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.732084.1137924 (Exim 4.92) (envelope-from ) id 1sCKMB-0000lX-Mh; Wed, 29 May 2024 14:32:47 +0000 Received: by outflank-mailman (output) from mailman id 732084.1137924; Wed, 29 May 2024 14:32:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCKMB-0000lM-HJ; Wed, 29 May 2024 14:32:47 +0000 Received: by outflank-mailman (input) for mailman id 732084; Wed, 29 May 2024 14:32:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCKMA-0000Tu-6P for xen-devel@lists.xenproject.org; Wed, 29 May 2024 14:32:46 +0000 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [2a00:1450:4864:20::22f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4fceb73a-1dc8-11ef-b4bb-af5377834399; Wed, 29 May 2024 16:32:44 +0200 (CEST) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2e95a74d51fso4463131fa.2 for ; Wed, 29 May 2024 07:32:44 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([217.156.233.157]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a647b827400sm74614166b.69.2024.05.29.07.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:32:41 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4fceb73a-1dc8-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1716993163; x=1717597963; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JQ0Z2MuZPai5+x8nYCnYhzQNJt6RhMWelwC5TWM5Ogs=; b=Cp8KFdxIfSXTeR3eYrG/dK5Z5vA92t89293nTSOlIEcgjvoenjQbdUY3S+TQOzyj5J ViDO4tT9JaODmNi8AOllIwSi74+v9GuJC9BR7nm2iTjwgkNvOWUGtsURj5gEwRQ4rOzh ls8z6EcQ/W/5dm639oxBD2Ax2Yuqup/GqMM9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716993163; x=1717597963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JQ0Z2MuZPai5+x8nYCnYhzQNJt6RhMWelwC5TWM5Ogs=; b=lVyqGRGt8P9gw8JFXBHV+HUvZaeOzAv+UYnqMiQEHZTaYOXdJAmqHo3TRbrY8/IVkW Exbf044EQD4T3FdS3e1r3CvTpex8SJ0E5P9DzyHTk2tjz88Avwj96NeSVEW9iaEnJ6Lm ut+M7lI0LdJg5iKBhbzcFRkCuku3GeqQ6IwSMoaT7w/EjHgpeHq+N6Q0axNR9ouna59n kyYnXCa6yWQtw0IFRqm0JmLfRPbrgbi9VfrAx/kNAbjA11hdrbzK+vR38JTrrtQTtkvR t1l2o3o9BTDcRW5ZCI4xgTxOywRIxQlok2kNIqG7cIeuQ262FpWJUV1ItOOLbpKvsOdQ aH5g== X-Gm-Message-State: AOJu0YzYet9Zbjb5hCRTfK2W+Ha5xo6UboGxHGd48QNdvVQFVyp+Zun9 QVyzSGZjjII/pb9J8Ryv6kwta7UTBHd4Z/5rZ9FCS+HOIYORBp42/c3ZDZ73SxzmeY1hx9ojI7T U X-Google-Smtp-Source: AGHT+IHDUsIhMRGeVQpyBeVL9vJxvadAtJqOlw/C7yhkmpleEPvJsfTSGOUs7kr2FkkLuVGGYY6P2Q== X-Received: by 2002:a05:6512:23a0:b0:529:be5c:8de0 with SMTP id 2adb3069b0e04-529be5c8f07mr4543915e87.49.1716993162398; Wed, 29 May 2024 07:32:42 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 1/6] x86/vlapic: Move lapic migration checks to the check hooks Date: Wed, 29 May 2024 15:32:30 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1716993185092100001 Content-Type: text/plain; charset="utf-8" While doing this, factor out checks common to architectural and hidden stat= e. Signed-off-by: Alejandro Vallejo Reviewed-by: Roger PAu Monn=C3=A9 --- v3: * Moved from v2/patch3. * Added check hook for the architectural state as well. * Use domain_vcpu() rather than the previous open coded checks for vcpu r= ange. --- xen/arch/x86/hvm/vlapic.c | 81 +++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 9cfc82666ae5..a0df62b5ec0a 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1553,60 +1553,85 @@ static void lapic_load_fixup(struct vlapic *vlapic) v, vlapic->loaded.id, vlapic->loaded.ldr, good_ldr); } =20 -static int cf_check lapic_load_hidden(struct domain *d, hvm_domain_context= _t *h) -{ - unsigned int vcpuid =3D hvm_load_instance(h); - struct vcpu *v; - struct vlapic *s; =20 +static int lapic_check_common(const struct domain *d, unsigned int vcpuid) +{ if ( !has_vlapic(d) ) return -ENODEV; =20 /* Which vlapic to load? */ - if ( vcpuid >=3D d->max_vcpus || (v =3D d->vcpu[vcpuid]) =3D=3D NULL ) + if ( !domain_vcpu(d, vcpuid) ) { dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no apic%u\n", d->domain_id, vcpuid); return -EINVAL; } - s =3D vcpu_vlapic(v); =20 - if ( hvm_load_entry_zeroextend(LAPIC, h, &s->hw) !=3D 0 ) + return 0; +} + +static int cf_check lapic_check_hidden(const struct domain *d, + hvm_domain_context_t *h) +{ + unsigned int vcpuid =3D hvm_load_instance(h); + struct hvm_hw_lapic s; + int rc; + + if ( (rc =3D lapic_check_common(d, vcpuid)) ) + return rc; + + if ( hvm_load_entry_zeroextend(LAPIC, h, &s) !=3D 0 ) + return -ENODATA; + + /* EN=3D0 with EXTD=3D1 is illegal */ + if ( (s.apic_base_msr & (APIC_BASE_ENABLE | APIC_BASE_EXTD)) =3D=3D + APIC_BASE_EXTD ) return -EINVAL; =20 + return 0; +} + +static int cf_check lapic_load_hidden(struct domain *d, hvm_domain_context= _t *h) +{ + unsigned int vcpuid =3D hvm_load_instance(h); + struct vcpu *v =3D d->vcpu[vcpuid]; + struct vlapic *s =3D vcpu_vlapic(v); + + if ( hvm_load_entry_zeroextend(LAPIC, h, &s->hw) !=3D 0 ) + BUG(); + s->loaded.hw =3D 1; if ( s->loaded.regs ) lapic_load_fixup(s); =20 - if ( !(s->hw.apic_base_msr & APIC_BASE_ENABLE) && - unlikely(vlapic_x2apic_mode(s)) ) - return -EINVAL; - hvm_update_vlapic_mode(v); =20 return 0; } =20 -static int cf_check lapic_load_regs(struct domain *d, hvm_domain_context_t= *h) +static int cf_check lapic_check_regs(const struct domain *d, + hvm_domain_context_t *h) { unsigned int vcpuid =3D hvm_load_instance(h); - struct vcpu *v; - struct vlapic *s; + int rc; =20 - if ( !has_vlapic(d) ) - return -ENODEV; + if ( (rc =3D lapic_check_common(d, vcpuid)) ) + return rc; =20 - /* Which vlapic to load? */ - if ( vcpuid >=3D d->max_vcpus || (v =3D d->vcpu[vcpuid]) =3D=3D NULL ) - { - dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no apic%u\n", - d->domain_id, vcpuid); - return -EINVAL; - } - s =3D vcpu_vlapic(v); + if ( !hvm_get_entry(LAPIC_REGS, h) ) + return -ENODATA; + + return 0; +} + +static int cf_check lapic_load_regs(struct domain *d, hvm_domain_context_t= *h) +{ + unsigned int vcpuid =3D hvm_load_instance(h); + struct vcpu *v =3D d->vcpu[vcpuid]; + struct vlapic *s =3D vcpu_vlapic(v); =20 if ( hvm_load_entry(LAPIC_REGS, h, s->regs) !=3D 0 ) - return -EINVAL; + BUG(); =20 s->loaded.id =3D vlapic_get_reg(s, APIC_ID); s->loaded.ldr =3D vlapic_get_reg(s, APIC_LDR); @@ -1623,9 +1648,9 @@ static int cf_check lapic_load_regs(struct domain *d,= hvm_domain_context_t *h) return 0; } =20 -HVM_REGISTER_SAVE_RESTORE(LAPIC, lapic_save_hidden, NULL, +HVM_REGISTER_SAVE_RESTORE(LAPIC, lapic_save_hidden, lapic_check_hidden, lapic_load_hidden, 1, HVMSR_PER_VCPU); -HVM_REGISTER_SAVE_RESTORE(LAPIC_REGS, lapic_save_regs, NULL, +HVM_REGISTER_SAVE_RESTORE(LAPIC_REGS, lapic_save_regs, lapic_check_regs, lapic_load_regs, 1, HVMSR_PER_VCPU); =20 int vlapic_init(struct vcpu *v) --=20 2.34.1