From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310956875611015.7795556447385; Wed, 8 Sep 2021 03:08:07 -0700 (PDT) Received: from localhost ([::1]:54636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuUw-0003Rs-H9 for importer@patchew.org; Wed, 08 Sep 2021 06:08:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRd-0006IR-1V for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:42 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:39570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRa-0002nf-Ps for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:40 -0400 Received: by mail-wm1-x331.google.com with SMTP id 196-20020a1c04cd000000b002fa489ffe1fso661678wme.4 for ; Wed, 08 Sep 2021 03:04:38 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/7nrEReoQoR7zRCQbazGzZCmxeeaU0xNt1erxfpNR44=; b=Jl2WDNkDxjNlYSn0T7v7Xi/YacypRI7oLRjL4LtdUKG6KlP0PVKYVRYbUg4f9ghwPi erB0LQPNP0q1W/IcLPjXs+BSe5PHPFcmBKeGiWWCwYpvxrn4AYifUmbfXlehddbATfkc H02+ywr6jBzi8NbM1th84OlITbB7HUT5/WEOOxN1XqdZ6AObh0LvZ+heznFMmjeIJxe5 Nor5jyVJYCGpQvWII3vGswRCFy5CQ4+nEk82nnA9Iq0zZLg7ehCc+8in/HJke8fM7S77 C57/m74Zsz3GasPkmborBkmw25A9PgAl5fWIgSUO6cweIPvU7ORqo1/N0Bu4HqrnlaZ0 cPdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/7nrEReoQoR7zRCQbazGzZCmxeeaU0xNt1erxfpNR44=; b=k3Dce2cKNTUIDV1KitRcjHuisbaHW6ko4TI3MX7fczxfjFT9pZy2oKWtuOsS6vZDDq rgsmeuMxqlVmMrK4rKEsJyRwi+MJK85LJAEdMdUlw9pL09f3GBoo93NQgACqT9XYF2Mk KthzY4s0U7DJMz2rWqtXYxb2Ial1TWPjci6QSaOpjtDvtmaTJZVtV4gIFWEEZX9hJN+3 5WM72CUkO83fNBJ0XXPK6TUdpQKOBNoUDEfTdYT+QYA2m3k+H4hAO+ZfEtH3f9IlWnQe hpENO21reg/qGbCoAkiDvuTXz3j32JiwPu/9FDedOp+qHvfZsutjsIhwupyinDSe2Rda l2hw== X-Gm-Message-State: AOAM530Nuo1VPlJXmlt183K34/wXk4H51gVCEjcuxEYNvuGMld2YREhC x7MsdYOJExmkYxOCegzpuampzlldEYk= X-Google-Smtp-Source: ABdhPJxKgj34GnuDvlSOj9PIseR0L+8FDE2Ky2N1sNDHStJfdNyJBmIHA7IeZyVm1QVtD6sPe4iz7g== X-Received: by 2002:a1c:238a:: with SMTP id j132mr2666200wmj.185.1631095476774; Wed, 08 Sep 2021 03:04:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 01/43] target/i386: add missing bits to CR4_RESERVED_MASK Date: Wed, 8 Sep 2021 12:03:44 +0200 Message-Id: <20210908100426.264356-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Richard W . M . Jones" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095689711100001 From: Daniel P. Berrang=C3=A9 Booting Fedora kernels with -cpu max hangs very early in boot. Disabling the la57 CPUID bit fixes the problem. git bisect traced the regression to commit 213ff024a2f92020290296cb9dc29c2af3d4a221 (HEAD, refs/bisect/bad) Author: Lara Lazier Date: Wed Jul 21 17:26:50 2021 +0200 target/i386: Added consistency checks for CR4 All MBZ bits in CR4 must be zero. (APM2 15.5) Added reserved bitmask and added checks in both helper_vmrun and helper_write_crN. Signed-off-by: Lara Lazier Message-Id: <20210721152651.14683-2-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini In this commit CR4_RESERVED_MASK is missing CR4_LA57_MASK and two others. Adding this lets Fedora kernels boot once again. Signed-off-by: Daniel P. Berrang=C3=A9 Tested-by: Richard W.M. Jones Message-Id: <20210831175033.175584-1-berrange@redhat.com> [Removed VMXE/SMXE, matching the commit message. - Paolo] Fixes: 213ff024a2 ("target/i386: Added consistency checks for CR4", 2021-07= -22) Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 6c50d3ab4f..21b33fbe2e 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -257,6 +257,7 @@ typedef enum X86Seg { | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \ | CR4_MCE_MASK | CR4_PGE_MASK | CR4_PCE_MASK \ | CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK |CR4_UMIP_MASK \ + | CR4_LA57_MASK \ | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \ | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_M= ASK)) =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095832332814.4733575357976; Wed, 8 Sep 2021 03:10:32 -0700 (PDT) Received: from localhost ([::1]:34916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuXH-0000gh-8j for importer@patchew.org; Wed, 08 Sep 2021 06:10:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRe-0006J2-QU for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:42 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:40505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRa-0002os-TN for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:41 -0400 Received: by mail-wm1-x32a.google.com with SMTP id n14-20020a05600c3b8e00b002f8bd2f8ab6so1108454wms.5 for ; Wed, 08 Sep 2021 03:04:38 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XWN6TWfYGXaOKzPRhA5oC6s5wzK7ZkowpHJRh9f6v9w=; b=VD+3ToXJonH47J01v3WUPNcO8cWSXb0zt8WcylqE6o9Hgpr0tS1UDSdOC65vCvxtWj QnEmBy/3tigpC+X1GHeaLHXO5uLYGLN6dxcHyKD/SPndRDzZfsXioQC9nQ2zMn6F9cD9 aQumrkmrp1zwIbNoK+mQZQ5Y4hvRs5Lm6ecY0MRmDmadnEc+xqA4pFwlFBll8Y5vwPQY 85dxvqmVzeHWn8IoYvDCRHKOyU4bfFqZPecfDgKDLCCpcRdip2E9+rM5QsE+FEFkk63o PrGEd9JY6tpw7CZVoS4dHhkNrUyshgnot6Xk3EzN/+bOKDOWlI4YxDQ2zU/9ofvyUi1h +ZZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=XWN6TWfYGXaOKzPRhA5oC6s5wzK7ZkowpHJRh9f6v9w=; b=EUVA4HXPvqjvQ32LLQ7r1gKqylva08sZh2ro4bPnDW8WHnsyw/upwuHp6VndQ5zvOl +XmL2KXoodW8HHvisOYomuxTXUAJY0yF93Iy45ma5/G30U1CXttfJyY58CwYCJ9Ctfmh MRM5wWZdvdxX4QI4nrLYJtiGi/LD2sNdowFcXnBNZEUMyzwlz8jOj/AVTl9+rqijzGYm SZUa7F8zenh0+L3SHsJRsxKr3uTiUQScM4vLUni9sA29kGZaplfqrKnh7SKFPhcMcC1O kne015draJbowt46CpJDiHqsKWEUO4HZ2SoZ9D6P8hfIqleUaQKDcRax3cRGg+IEU1sc qQoQ== X-Gm-Message-State: AOAM530nJYsVssvqCo+3mVmleXD8HxkIX64Ar5Shqu+BqOG0hts85d1f xmr3bBX8FedMHxWreTPfRNzXcQSOD5o= X-Google-Smtp-Source: ABdhPJxIkVjDy3WUHnImH4G6qXKnvG6sMQWF72aqpsAnEyy9VvDjMpBB6RXcbe32wthiLrveFqMEWQ== X-Received: by 2002:a05:600c:3209:: with SMTP id r9mr2712287wmp.106.1631095477481; Wed, 08 Sep 2021 03:04:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 02/43] target/i386: VMRUN and VMLOAD canonicalizations Date: Wed, 8 Sep 2021 12:03:45 +0200 Message-Id: <20210908100426.264356-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095833311100001 Content-Type: text/plain; charset="utf-8" From: Lara Lazier APM2 requires that VMRUN and VMLOAD canonicalize (sign extend to 63 from 48/57) all base addresses in the segment registers that have been respectively loaded. Signed-off-by: Lara Lazier Message-Id: <20210804113058.45186-1-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 19 +++++++++++-------- target/i386/cpu.h | 2 ++ target/i386/tcg/sysemu/svm_helper.c | 27 +++++++++++++++++---------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 97e250e876..fbca4e5860 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5115,6 +5115,15 @@ static void x86_register_cpudef_types(const X86CPUDe= finition *def) =20 } =20 +uint32_t cpu_x86_virtual_addr_width(CPUX86State *env) +{ + if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_LA57) { + return 57; /* 57 bits virtual */ + } else { + return 48; /* 48 bits virtual */ + } +} + void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) @@ -5517,16 +5526,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, break; case 0x80000008: /* virtual & phys address size in low 2 bytes. */ + *eax =3D cpu->phys_bits; if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) { /* 64 bit processor */ - *eax =3D cpu->phys_bits; /* configurable physical bits */ - if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_LA57) { - *eax |=3D 0x00003900; /* 57 bits virtual */ - } else { - *eax |=3D 0x00003000; /* 48 bits virtual */ - } - } else { - *eax =3D cpu->phys_bits; + *eax |=3D (cpu_x86_virtual_addr_width(env) << 8); } *ebx =3D env->features[FEAT_8000_0008_EBX]; if (cs->nr_cores * cs->nr_threads > 1) { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 21b33fbe2e..aafc2eb696 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1955,6 +1955,8 @@ typedef struct PropValue { } PropValue; void x86_cpu_apply_props(X86CPU *cpu, PropValue *props); =20 +uint32_t cpu_x86_virtual_addr_width(CPUX86State *env); + /* cpu.c other functions (cpuid) */ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 0d549b3d6c..0e7de4e054 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -41,6 +41,16 @@ static inline void svm_save_seg(CPUX86State *env, hwaddr= addr, ((sc->flags >> 8) & 0xff) | ((sc->flags >> 12) & 0x0f00)); } =20 +/* + * VMRUN and VMLOAD canonicalizes (i.e., sign-extend to bit 63) all base + * addresses in the segment registers that have been loaded. + */ +static inline void svm_canonicalization(CPUX86State *env, target_ulong *se= g_base) +{ + uint16_t shift_amt =3D 64 - cpu_x86_virtual_addr_width(env); + *seg_base =3D ((((long) *seg_base) << shift_amt) >> shift_amt); +} + static inline void svm_load_seg(CPUX86State *env, hwaddr addr, SegmentCache *sc) { @@ -53,6 +63,7 @@ static inline void svm_load_seg(CPUX86State *env, hwaddr = addr, sc->limit =3D x86_ldl_phys(cs, addr + offsetof(struct vmcb_seg, limit)= ); flags =3D x86_lduw_phys(cs, addr + offsetof(struct vmcb_seg, attrib)); sc->flags =3D ((flags & 0xff) << 8) | ((flags & 0x0f00) << 12); + svm_canonicalization(env, &sc->base); } =20 static inline void svm_load_seg_cache(CPUX86State *env, hwaddr addr, @@ -245,16 +256,6 @@ void helper_vmrun(CPUX86State *env, int aflag, int nex= t_eip_addend) env->tsc_offset =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.tsc_offset)); =20 - env->gdt.base =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmc= b, - save.gdtr.base)); - env->gdt.limit =3D x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmc= b, - save.gdtr.limit)); - - env->idt.base =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmc= b, - save.idtr.base)); - env->idt.limit =3D x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmc= b, - save.idtr.limit)); - new_cr0 =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save= .cr0)); if (new_cr0 & SVM_CR0_RESERVED_MASK) { cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); @@ -308,6 +309,10 @@ void helper_vmrun(CPUX86State *env, int aflag, int nex= t_eip_addend) R_SS); svm_load_seg_cache(env, env->vm_vmcb + offsetof(struct vmcb, save.ds), R_DS); + svm_load_seg(env, env->vm_vmcb + offsetof(struct vmcb, save.idtr), + &env->idt); + svm_load_seg(env, env->vm_vmcb + offsetof(struct vmcb, save.gdtr), + &env->gdt); =20 env->eip =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.rip)); @@ -446,6 +451,7 @@ void helper_vmload(CPUX86State *env, int aflag) env->lstar =3D x86_ldq_phys(cs, addr + offsetof(struct vmcb, save.lsta= r)); env->cstar =3D x86_ldq_phys(cs, addr + offsetof(struct vmcb, save.csta= r)); env->fmask =3D x86_ldq_phys(cs, addr + offsetof(struct vmcb, save.sfma= sk)); + svm_canonicalization(env, &env->kernelgsbase); #endif env->star =3D x86_ldq_phys(cs, addr + offsetof(struct vmcb, save.star)= ); env->sysenter_cs =3D x86_ldq_phys(cs, @@ -454,6 +460,7 @@ void helper_vmload(CPUX86State *env, int aflag) save.sysenter_esp)); env->sysenter_eip =3D x86_ldq_phys(cs, addr + offsetof(struct vmcb, save.sysenter_eip)); + } =20 void helper_vmsave(CPUX86State *env, int aflag) --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163109595836266.21026317027474; Wed, 8 Sep 2021 03:12:38 -0700 (PDT) Received: from localhost ([::1]:43366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuZJ-0006On-1w for importer@patchew.org; Wed, 08 Sep 2021 06:12:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRe-0006J1-Q1 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:42 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:41802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRb-0002oy-GI for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:41 -0400 Received: by mail-wm1-x332.google.com with SMTP id u15-20020a05600c19cf00b002f6445b8f55so1101884wmq.0 for ; Wed, 08 Sep 2021 03:04:39 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vC4CLxS3uATszG/9NMGUyh1mVGgnFuJ2ybR8crd545U=; b=Ci4rfq40KHsI+VeX6B3eJlLruNF7Dj5F1jbUKs/SceTHwJ5rZfTAFpgMomyUOskvlA QE4VkR3ac4hyXuR5vq+1JzkWdAP/VvomBks9iGfe9AokKE/uiMFwcrSGddcD6cx1sSAm dZVRwPu3+nMo/jUU0UNWACw8iJa+yCVX1T/U60xR8jKiQC552W2S5xIYKqTfuPqqN61v 668GRI15elll7BvWfZjj0lYQICoTnh5wHVSWP0dJqkalGMbCG41JurGgBOjlBbEKMGc0 IsapZ3zWfnJXKA1FubIR4C/Gvt8T2bFhPIY8dnV75JFaq+qnzXMg87IceefFW7w687Tn mxeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=vC4CLxS3uATszG/9NMGUyh1mVGgnFuJ2ybR8crd545U=; b=MqwD+xI7hXidMZy2hSQQc0o5nHrj538KKjuShtkQVpT8Xev/l1ljwGK+sVtgo0xJmh asChoSLPIXW531wwKuaob+cmko2kIPXNvlRDgys4qHLoC8CRHyRxOFA2zzTQel8bDVFb SgMNTTFiMarmh+54Cm0qoFUnaVegqFKLKJ0As8kgZp/HmOksBnOAetGhDUckyn0TdI2B 2Cnu9wVAKf17LMCNSShJHuWYhauVXpWa0FmnB0NhQEUezBledEqoAMc2yXdXCM5jMOlR WlS+ApoQBojl2R602Xvuzv0DSUkN9t7DAMqKMxGqx6f//X8PXda39W9bjYZa9kqB0eFM HcUA== X-Gm-Message-State: AOAM5303JEVdZihqoAdW1TShELCFGYq5k1g5+Jv5Fy3VmLuFKlGtJd9y ZBeqcvw4FkgpSAFoIyP83kXMPeQ514U= X-Google-Smtp-Source: ABdhPJzwcrrkwWrh9l2G3lLMfonPGbiwd4MSFqJd3c9wRx5t+ZDDxLuFaKJkAYdoilIvYIWs1wfJXg== X-Received: by 2002:a1c:ac05:: with SMTP id v5mr2753744wme.13.1631095478119; Wed, 08 Sep 2021 03:04:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 03/43] target/i386: Added VGIF feature Date: Wed, 8 Sep 2021 12:03:46 +0200 Message-Id: <20210908100426.264356-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095960085100001 Content-Type: text/plain; charset="utf-8" From: Lara Lazier VGIF allows STGI and CLGI to execute in guest mode and control virtual interrupts in guest mode. When the VGIF feature is enabled then: * executing STGI in the guest sets bit 9 of the VMCB offset 60h. * executing CLGI in the guest clears bit 9 of the VMCB offset 60h. Signed-off-by: Lara Lazier Message-Id: <20210730070742.9674-1-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 3 ++- target/i386/svm.h | 6 ++++++ target/i386/tcg/sysemu/svm_helper.c | 31 +++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index fbca4e5860..86064ea1f9 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -631,7 +631,8 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendo= r1, #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A) #define TCG_EXT4_FEATURES 0 -#define TCG_SVM_FEATURES CPUID_SVM_NPT +#define TCG_SVM_FEATURES (CPUID_SVM_NPT | CPUID_SVM_VGIF | \ + CPUID_SVM_SVME_ADDR_CHK) #define TCG_KVM_FEATURES 0 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX | \ diff --git a/target/i386/svm.h b/target/i386/svm.h index adc058dc76..036597a2ff 100644 --- a/target/i386/svm.h +++ b/target/i386/svm.h @@ -9,6 +9,12 @@ #define V_IRQ_SHIFT 8 #define V_IRQ_MASK (1 << V_IRQ_SHIFT) =20 +#define V_GIF_ENABLED_SHIFT 25 +#define V_GIF_ENABLED_MASK (1 << V_GIF_ENABLED_SHIFT) + +#define V_GIF_SHIFT 9 +#define V_GIF_MASK (1 << V_GIF_SHIFT) + #define V_INTR_PRIO_SHIFT 16 #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT) =20 diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 0e7de4e054..66c2c1e61f 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -121,6 +121,17 @@ static inline bool is_efer_invalid_state (CPUX86State = *env) return false; } =20 +static inline bool virtual_gif_enabled(CPUX86State *env, uint32_t *int_ctl) +{ + if (likely(env->hflags & HF_GUEST_MASK)) { + *int_ctl =3D x86_ldl_phys(env_cpu(env), + env->vm_vmcb + offsetof(struct vmcb, control.int_ct= l)); + return (env->features[FEAT_SVM] & CPUID_SVM_VGIF) + && (*int_ctl & V_GIF_ENABLED_MASK); + } + return false; +} + void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) { CPUState *cs =3D env_cpu(env); @@ -510,13 +521,29 @@ void helper_vmsave(CPUX86State *env, int aflag) void helper_stgi(CPUX86State *env) { cpu_svm_check_intercept_param(env, SVM_EXIT_STGI, 0, GETPC()); - env->hflags2 |=3D HF2_GIF_MASK; + + CPUState *cs =3D env_cpu(env); + uint32_t int_ctl; + if (virtual_gif_enabled(env, &int_ctl)) { + x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_= ctl), + int_ctl | V_GIF_MASK); + } else { + env->hflags2 |=3D HF2_GIF_MASK; + } } =20 void helper_clgi(CPUX86State *env) { cpu_svm_check_intercept_param(env, SVM_EXIT_CLGI, 0, GETPC()); - env->hflags2 &=3D ~HF2_GIF_MASK; + + CPUState *cs =3D env_cpu(env); + uint32_t int_ctl; + if (virtual_gif_enabled(env, &int_ctl)) { + x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_= ctl), + int_ctl & ~V_GIF_MASK); + } else { + env->hflags2 &=3D ~HF2_GIF_MASK; + } } =20 bool cpu_svm_has_intercept(CPUX86State *env, uint32_t type) --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095905083232.37106547149108; Wed, 8 Sep 2021 03:11:45 -0700 (PDT) Received: from localhost ([::1]:39744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuYS-0003zQ-0O for importer@patchew.org; Wed, 08 Sep 2021 06:11:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRg-0006K1-PE for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:45 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:36742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRc-0002qE-6K for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:43 -0400 Received: by mail-wm1-x32e.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so1121060wmq.1 for ; Wed, 08 Sep 2021 03:04:39 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yGGcFCxa3DPzLBu/R2mPTHRKMWG0DNlo6ftGn6pELgQ=; b=HU2hAwzxirySmjCpkp7CXD7VoauGvEQJdF3TFmNVT0hIHpy5db61qzduqeQa7/nyoe 4JErJOKzfjDzcpK6wLFENm30tdOMXOGM/aeMYoT6HDORrl9EVcaX25OnR4myZADo+hAj 0ju6VvCBo1pcQDsXKlqr4TDtv2g/1g4cTLljHXICkGGpgbD7pkLpxsnI2Ljxj9qw74Et QE52ynAx6AKXNYJUXq9JVsvsKJ0210qqmk++6920EmPWZPIQCxNRMR0IoSjbiYqZafPt 7knI4wvoULD5ysB7ggYk9GuHUWoyLwMViXb36M5FwprAR2iqU4+3dYxM/ACUS08klYHV d4kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=yGGcFCxa3DPzLBu/R2mPTHRKMWG0DNlo6ftGn6pELgQ=; b=W93kHC0rdh8QFmMv9z6B8DVi8gIzj9wWOwf1zFVV+kK3SYsogMEP8TuxPNCXWgIqYC RYx5UD/7Xbv8PJWY3ODeewnpTY2bxcJq+BCz9l97zggbXNbZUp/1TW+cGzRWBjeJzkB1 TpqH+nFz8+rWqKJRZNs9lyqRhVawPzERiTT4FtmDQnJGc1fvKwr1zVUnrjiK49//aS/7 z/toVr3QWNZJ3D1a1I0xefFcUNhyzoPMYKzj/8iC+qVXsbfFge3JGMZ2SlC5+8h6+3sL TLthvlyOnfvBZDxPMGTEWuPhbbUTrZtk/e/j73Kl2BODycK5uGWOnT0/9199Xo1W+k7v v9wg== X-Gm-Message-State: AOAM531NunMvGVpP4mrfe530CKlFX/t1uc89ZLLuFTDdSxdidOQx2Qsu /8SUh900fSdVw4qcK3pSNhwVSGtSYMY= X-Google-Smtp-Source: ABdhPJxzXpwzpQfqGWYEJygIqY/zpnw9dHrVHFwBB85SBFSkYm3/Xoewp8+Tg3UTeNV55KBfM5KvSA== X-Received: by 2002:a05:600c:2f90:: with SMTP id t16mr2673259wmn.136.1631095478828; Wed, 08 Sep 2021 03:04:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 04/43] target/i386: Moved int_ctl into CPUX86State structure Date: Wed, 8 Sep 2021 12:03:47 +0200 Message-Id: <20210908100426.264356-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095906831100001 Content-Type: text/plain; charset="utf-8" From: Lara Lazier Moved int_ctl into the CPUX86State structure. It removes some unnecessary stores and loads, and prepares for tracking the vIRQ state even when it is masked due to vGIF. Signed-off-by: Lara Lazier Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 2 +- target/i386/cpu.h | 1 + target/i386/machine.c | 22 ++++++++++++- target/i386/tcg/seg_helper.c | 2 +- target/i386/tcg/sysemu/misc_helper.c | 4 +-- target/i386/tcg/sysemu/svm_helper.c | 48 +++++++++------------------- 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 86064ea1f9..ddc3b63cb8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5655,7 +5655,7 @@ static void x86_cpu_reset(DeviceState *dev) env->old_exception =3D -1; =20 /* init to reset state */ - + env->int_ctl =3D 0; env->hflags2 |=3D HF2_GIF_MASK; env->hflags &=3D ~HF_GUEST_MASK; =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index aafc2eb696..3dfe630d7e 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1578,6 +1578,7 @@ typedef struct CPUX86State { uint64_t nested_cr3; uint32_t nested_pg_mode; uint8_t v_tpr; + uint32_t int_ctl; =20 /* KVM states, automatically cleared on reset */ uint8_t nmi_injected; diff --git a/target/i386/machine.c b/target/i386/machine.c index f6f094f1c9..b0943118d1 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -203,7 +203,7 @@ static int cpu_pre_save(void *opaque) X86CPU *cpu =3D opaque; CPUX86State *env =3D &cpu->env; int i; - + env->v_tpr =3D env->int_ctl & V_TPR_MASK; /* FPU */ env->fpus_vmstate =3D (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; env->fptag_vmstate =3D 0; @@ -1356,6 +1356,25 @@ static const VMStateDescription vmstate_svm_npt =3D { } }; =20 +static bool svm_guest_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + CPUX86State *env =3D &cpu->env; + + return tcg_enabled() && env->int_ctl; +} + +static const VMStateDescription vmstate_svm_guest =3D { + .name =3D "cpu/svm_guest", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D svm_guest_needed, + .fields =3D (VMStateField[]){ + VMSTATE_UINT32(env.int_ctl, X86CPU), + VMSTATE_END_OF_LIST() + } +}; + #ifndef TARGET_X86_64 static bool intel_efer32_needed(void *opaque) { @@ -1524,6 +1543,7 @@ const VMStateDescription vmstate_x86_cpu =3D { &vmstate_msr_intel_pt, &vmstate_msr_virt_ssbd, &vmstate_svm_npt, + &vmstate_svm_guest, #ifndef TARGET_X86_64 &vmstate_efer32, #endif diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index 3ed20ca31d..cef68b610a 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -1166,7 +1166,6 @@ bool x86_cpu_exec_interrupt(CPUState *cs, int interru= pt_request) break; #if !defined(CONFIG_USER_ONLY) case CPU_INTERRUPT_VIRQ: - /* FIXME: this should respect TPR */ cpu_svm_check_intercept_param(env, SVM_EXIT_VINTR, 0, 0); intno =3D x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_vector)); @@ -1174,6 +1173,7 @@ bool x86_cpu_exec_interrupt(CPUState *cs, int interru= pt_request) "Servicing virtual hardware INT=3D0x%02x\n", intno); do_interrupt_x86_hardirq(env, intno, 1); cs->interrupt_request &=3D ~CPU_INTERRUPT_VIRQ; + env->int_ctl &=3D ~V_IRQ_MASK; break; #endif } diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/= misc_helper.c index e7a2ebde81..91b0fc916b 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -73,7 +73,7 @@ target_ulong helper_read_crN(CPUX86State *env, int reg) if (!(env->hflags2 & HF2_VINTR_MASK)) { val =3D cpu_get_apic_tpr(env_archcpu(env)->apic_state); } else { - val =3D env->v_tpr; + val =3D env->int_ctl & V_TPR_MASK; } break; } @@ -121,7 +121,7 @@ void helper_write_crN(CPUX86State *env, int reg, target= _ulong t0) cpu_set_apic_tpr(env_archcpu(env)->apic_state, t0); qemu_mutex_unlock_iothread(); } - env->v_tpr =3D t0 & 0x0f; + env->int_ctl =3D (env->int_ctl & ~V_TPR_MASK) | (t0 & V_TPR_MASK); break; default: env->cr[reg] =3D t0; diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 66c2c1e61f..24c58b6a38 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -76,14 +76,14 @@ static inline void svm_load_seg_cache(CPUX86State *env,= hwaddr addr, sc->base, sc->limit, sc->flags); } =20 -static inline bool ctl_has_irq(uint32_t int_ctl) +static inline bool ctl_has_irq(CPUX86State *env) { uint32_t int_prio; uint32_t tpr; =20 - int_prio =3D (int_ctl & V_INTR_PRIO_MASK) >> V_INTR_PRIO_SHIFT; - tpr =3D int_ctl & V_TPR_MASK; - return (int_ctl & V_IRQ_MASK) && (int_prio >=3D tpr); + int_prio =3D (env->int_ctl & V_INTR_PRIO_MASK) >> V_INTR_PRIO_SHIFT; + tpr =3D env->int_ctl & V_TPR_MASK; + return (env->int_ctl & V_IRQ_MASK) && (int_prio >=3D tpr); } =20 static inline bool is_efer_invalid_state (CPUX86State *env) @@ -121,13 +121,11 @@ static inline bool is_efer_invalid_state (CPUX86State= *env) return false; } =20 -static inline bool virtual_gif_enabled(CPUX86State *env, uint32_t *int_ctl) +static inline bool virtual_gif_enabled(CPUX86State *env) { if (likely(env->hflags & HF_GUEST_MASK)) { - *int_ctl =3D x86_ldl_phys(env_cpu(env), - env->vm_vmcb + offsetof(struct vmcb, control.int_ct= l)); return (env->features[FEAT_SVM] & CPUID_SVM_VGIF) - && (*int_ctl & V_GIF_ENABLED_MASK); + && (env->int_ctl & V_GIF_ENABLED_MASK); } return false; } @@ -139,7 +137,6 @@ void helper_vmrun(CPUX86State *env, int aflag, int next= _eip_addend) target_ulong addr; uint64_t nested_ctl; uint32_t event_inj; - uint32_t int_ctl; uint32_t asid; uint64_t new_cr0; uint64_t new_cr3; @@ -292,11 +289,10 @@ void helper_vmrun(CPUX86State *env, int aflag, int ne= xt_eip_addend) cpu_x86_update_cr3(env, new_cr3); env->cr[2] =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr2)); - int_ctl =3D x86_ldl_phys(cs, + env->int_ctl =3D x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_ct= l)); env->hflags2 &=3D ~(HF2_HIF_MASK | HF2_VINTR_MASK); - if (int_ctl & V_INTR_MASKING_MASK) { - env->v_tpr =3D int_ctl & V_TPR_MASK; + if (env->int_ctl & V_INTR_MASKING_MASK) { env->hflags2 |=3D HF2_VINTR_MASK; if (env->eflags & IF_MASK) { env->hflags2 |=3D HF2_HIF_MASK; @@ -362,7 +358,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next= _eip_addend) =20 env->hflags2 |=3D HF2_GIF_MASK; =20 - if (ctl_has_irq(int_ctl)) { + if (ctl_has_irq(env)) { CPUState *cs =3D env_cpu(env); =20 cs->interrupt_request |=3D CPU_INTERRUPT_VIRQ; @@ -522,11 +518,8 @@ void helper_stgi(CPUX86State *env) { cpu_svm_check_intercept_param(env, SVM_EXIT_STGI, 0, GETPC()); =20 - CPUState *cs =3D env_cpu(env); - uint32_t int_ctl; - if (virtual_gif_enabled(env, &int_ctl)) { - x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_= ctl), - int_ctl | V_GIF_MASK); + if (virtual_gif_enabled(env)) { + env->int_ctl |=3D V_GIF_MASK; } else { env->hflags2 |=3D HF2_GIF_MASK; } @@ -536,11 +529,8 @@ void helper_clgi(CPUX86State *env) { cpu_svm_check_intercept_param(env, SVM_EXIT_CLGI, 0, GETPC()); =20 - CPUState *cs =3D env_cpu(env); - uint32_t int_ctl; - if (virtual_gif_enabled(env, &int_ctl)) { - x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_= ctl), - int_ctl & ~V_GIF_MASK); + if (virtual_gif_enabled(env)) { + env->int_ctl &=3D ~V_GIF_MASK; } else { env->hflags2 &=3D ~HF2_GIF_MASK; } @@ -688,7 +678,6 @@ void cpu_vmexit(CPUX86State *env, uint32_t exit_code, u= int64_t exit_info_1, void do_vmexit(CPUX86State *env) { CPUState *cs =3D env_cpu(env); - uint32_t int_ctl; =20 if (env->hflags & HF_INHIBIT_IRQ_MASK) { x86_stl_phys(cs, @@ -731,16 +720,8 @@ void do_vmexit(CPUX86State *env) env->vm_vmcb + offsetof(struct vmcb, save.cr3), env->cr[3]); x86_stq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4), env->cr[4]); - - int_ctl =3D x86_ldl_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, control.int_ct= l)); - int_ctl &=3D ~(V_TPR_MASK | V_IRQ_MASK); - int_ctl |=3D env->v_tpr & V_TPR_MASK; - if (cs->interrupt_request & CPU_INTERRUPT_VIRQ) { - int_ctl |=3D V_IRQ_MASK; - } x86_stl_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, control.int_ctl), int_ct= l); + env->vm_vmcb + offsetof(struct vmcb, control.int_ctl), env->i= nt_ctl); =20 x86_stq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.rflags), cpu_compute_eflags(env)); @@ -763,6 +744,7 @@ void do_vmexit(CPUX86State *env) env->intercept =3D 0; env->intercept_exceptions =3D 0; cs->interrupt_request &=3D ~CPU_INTERRUPT_VIRQ; + env->int_ctl =3D 0; env->tsc_offset =3D 0; =20 env->gdt.base =3D x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vm= cb, --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095778020179.10625642623643; Wed, 8 Sep 2021 03:09:38 -0700 (PDT) Received: from localhost ([::1]:59370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuWP-0006cJ-0i for importer@patchew.org; Wed, 08 Sep 2021 06:09:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRg-0006K3-Qf for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:45 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:38873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRd-0002sR-SR for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:43 -0400 Received: by mail-wr1-x431.google.com with SMTP id u16so2408325wrn.5 for ; Wed, 08 Sep 2021 03:04:40 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rury9kyy7jESqyjutVRPw1Pj5BJEZzJk31MIDToIicI=; b=NLJxwM0v8u8domZxof01Fb+zSDUOAUcNX834xmMhG6Qu33GXHY3w9RJrpjkzvuv2wp 1nQazUji1Cq0DqLh5x2QG1afEkZ7jXerr/mTIE3cKqnVfZP/mPQcQ4U5yizTxbQqIkNj +5SMajGH0Mb7w16E/pT9b4RoHJuhefdcqbHpaGZ6sX7YMdTEvoRHop2uKHqKDorG8fjm s/wEp7kgXwWTW5b5DRUVMF1GLMmInujZR/2qHROiOC1KHjKlteBragu6R7unnh72rj4X aY90DdvLM6GEdodgGtUJLGXbwRqDlRreGSP+mqvBLrnOP4YjlCIcKIcL/gr4EgZh3ShX /Jrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rury9kyy7jESqyjutVRPw1Pj5BJEZzJk31MIDToIicI=; b=RQOkdMYxzuSxxL35Q2V7wAHuQA+qZ0GAS062+RU3HH3JG2ya26QfD7pfQlfkTor1on wPwRIc1Ixb52zQl4BmPuu2L+9P8c4vPP3PqCj62N1UuppDEXN+5REhEc/GYglx8No7LO FQ8sDef1BmzBE/iV64Zuy4myShedF7x7oI/e30CAncu5Te39Mdee4Lbf6qW6loKXFi6b g7ixmIfcVd2A1mzfPGWUdjJRBiMMkLC6T9qOZgzyJvaDfQNY+wSv1t0pmjbStNiabEnl f6mSrZUU51Swm2cTHmtv1AX4zb2IsxN15vjJfR7QcL1Nv6bJc4TVigEWMRS0sIVm+nvL zfPg== X-Gm-Message-State: AOAM533FwjLgKwgvoWV8PLo9pmDKkJow8TTRpWb6YlNl/1RXxyXHRcDp jooBF4GA5A2NcHxesty/XhO7taSdCQo= X-Google-Smtp-Source: ABdhPJzhHFgHFkT5rBSfIEZjy79GnwyloKsWwJvc9watwKxZC6qqkIh2rs8RUtCxtUZ9EdumBD1sXQ== X-Received: by 2002:adf:cd92:: with SMTP id q18mr3048114wrj.211.1631095479492; Wed, 08 Sep 2021 03:04:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 05/43] target/i386: Added VGIF V_IRQ masking capability Date: Wed, 8 Sep 2021 12:03:48 +0200 Message-Id: <20210908100426.264356-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095778382100001 Content-Type: text/plain; charset="utf-8" From: Lara Lazier VGIF provides masking capability for when virtual interrupts are taken. (APM2) Signed-off-by: Lara Lazier Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 7 +++++-- target/i386/cpu.h | 2 ++ target/i386/tcg/sysemu/svm_helper.c | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ddc3b63cb8..6b029f1bdf 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5657,6 +5657,7 @@ static void x86_cpu_reset(DeviceState *dev) /* init to reset state */ env->int_ctl =3D 0; env->hflags2 |=3D HF2_GIF_MASK; + env->hflags2 |=3D HF2_VGIF_MASK; env->hflags &=3D ~HF_GUEST_MASK; =20 cpu_x86_update_cr0(env, 0x60000010); @@ -6540,10 +6541,12 @@ int x86_cpu_pending_interrupt(CPUState *cs, int int= errupt_request) !(env->hflags & HF_INHIBIT_IRQ_MASK))))) { return CPU_INTERRUPT_HARD; #if !defined(CONFIG_USER_ONLY) - } else if ((interrupt_request & CPU_INTERRUPT_VIRQ) && + } else if (env->hflags2 & HF2_VGIF_MASK) { + if((interrupt_request & CPU_INTERRUPT_VIRQ) && (env->eflags & IF_MASK) && !(env->hflags & HF_INHIBIT_IRQ_MASK)) { - return CPU_INTERRUPT_VIRQ; + return CPU_INTERRUPT_VIRQ; + } #endif } } diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 3dfe630d7e..24e8ec5273 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -203,6 +203,7 @@ typedef enum X86Seg { #define HF2_MPX_PR_SHIFT 5 /* BNDCFGx.BNDPRESERVE */ #define HF2_NPT_SHIFT 6 /* Nested Paging enabled */ #define HF2_IGNNE_SHIFT 7 /* Ignore CR0.NE=3D0 */ +#define HF2_VGIF_SHIFT 8 /* Can take VIRQ*/ =20 #define HF2_GIF_MASK (1 << HF2_GIF_SHIFT) #define HF2_HIF_MASK (1 << HF2_HIF_SHIFT) @@ -212,6 +213,7 @@ typedef enum X86Seg { #define HF2_MPX_PR_MASK (1 << HF2_MPX_PR_SHIFT) #define HF2_NPT_MASK (1 << HF2_NPT_SHIFT) #define HF2_IGNNE_MASK (1 << HF2_IGNNE_SHIFT) +#define HF2_VGIF_MASK (1 << HF2_VGIF_SHIFT) =20 #define CR0_PE_SHIFT 0 #define CR0_MP_SHIFT 1 diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 24c58b6a38..4612dae1ac 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -130,6 +130,11 @@ static inline bool virtual_gif_enabled(CPUX86State *en= v) return false; } =20 +static inline bool virtual_gif_set(CPUX86State *env) +{ + return !virtual_gif_enabled(env) || (env->int_ctl & V_GIF_MASK); +} + void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) { CPUState *cs =3D env_cpu(env); @@ -364,6 +369,10 @@ void helper_vmrun(CPUX86State *env, int aflag, int nex= t_eip_addend) cs->interrupt_request |=3D CPU_INTERRUPT_VIRQ; } =20 + if (virtual_gif_set(env)) { + env->hflags2 |=3D HF2_VGIF_MASK; + } + /* maybe we need to inject an event */ event_inj =3D x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.event_inj)); @@ -520,6 +529,7 @@ void helper_stgi(CPUX86State *env) =20 if (virtual_gif_enabled(env)) { env->int_ctl |=3D V_GIF_MASK; + env->hflags2 |=3D HF2_VGIF_MASK; } else { env->hflags2 |=3D HF2_GIF_MASK; } @@ -531,6 +541,7 @@ void helper_clgi(CPUX86State *env) =20 if (virtual_gif_enabled(env)) { env->int_ctl &=3D ~V_GIF_MASK; + env->hflags2 &=3D ~HF2_VGIF_MASK; } else { env->hflags2 &=3D ~HF2_GIF_MASK; } @@ -812,6 +823,7 @@ void do_vmexit(CPUX86State *env) env->vm_vmcb + offsetof(struct vmcb, control.event_inj), 0); =20 env->hflags2 &=3D ~HF2_GIF_MASK; + env->hflags2 &=3D ~HF2_VGIF_MASK; /* FIXME: Resets the current ASID register to zero (host ASID). */ =20 /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095901959242.86541005746392; Wed, 8 Sep 2021 03:11:41 -0700 (PDT) Received: from localhost ([::1]:39516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuYO-0003qB-No for importer@patchew.org; Wed, 08 Sep 2021 06:11:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0006NH-Hu for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:48 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:39575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRe-0002sX-Gm for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:44 -0400 Received: by mail-wm1-x336.google.com with SMTP id 196-20020a1c04cd000000b002fa489ffe1fso661778wme.4 for ; Wed, 08 Sep 2021 03:04:41 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F257kBkfuJl6Q7MoJ0dNQEoRR26oeybWJUiYLakF928=; b=UEewsJibo/FBKsVDTspq5PC/Q34asjP8IiCqZcl/0szvNcPnaDCOZWhunIOy8iS7ZJ OypnPDpVSvLBZNhKA/m3uLXCE7wvkGuP3d+VE+QMkI2fAJuZ8X/NTYOXDNTdJ0yDzfM7 FKP8dcemmhBDyNRot9fKenv1ueoufvSH7uWkBBjt+X+0tCyHkkJ1FfgwQWqsxYO+1m4r pibv5oV5ozcqQNUsAlduiIRHOY45d7WOtxkxVIdVvM5c2DVg8PAmvbiR9ppNuKBibyEj 7IL7y2aHVOEXGeGbcnqA3mfviwQjWccU+Nxxu/KxAvN9H5zWQkZKqDpH5dgSC5JAzjK+ DKoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=F257kBkfuJl6Q7MoJ0dNQEoRR26oeybWJUiYLakF928=; b=KdI01TFIZi2buqorTYvo5ROQFT38HsUxHYJrXDVr4W3wu1UCc/rWIP3fRaDDLndyMs fz+0F1FlN8FZOxC/lsYrVvMhhH43brFFZzwoYZmOMXXsJn0ubBpDM4izzG0xuLpZjuFe sX+MQQQp1J+yq7XpapdC1Qm0fzI00jUXglyk992Hy2cP2N7QbCzmn+uFij6JAVZ8MEim QNn5cb9vMS2UqWMorQY27kXXpRX1VFD1Apuy7RpdCU6vmHKuRrJCT4bGIO4k7W24THMX hOBCQhk+HzhfoxscL8OHbgRjcHLQTY5oKBEv532smXQwAmZs41mB0C1Yz3dIvv9rYw9c XgWw== X-Gm-Message-State: AOAM533tbP+3R8M5thXRXF/b4rsOhhdMNdRbZ4fZysZWFd4CndQUEAkU VP9S9XekgbMKYy2R9o2Ts3qWWOksddQ= X-Google-Smtp-Source: ABdhPJwBjmgsh5aGTXWUL29KsIRs1Wsn8GuB9aoeveGRpe4u65X1Ue21ixncW2Hgz03XDiZd0CfsHA== X-Received: by 2002:a1c:2c3:: with SMTP id 186mr2688823wmc.195.1631095480197; Wed, 08 Sep 2021 03:04:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 06/43] target/i386: Added ignore TPR check in ctl_has_irq Date: Wed, 8 Sep 2021 12:03:49 +0200 Message-Id: <20210908100426.264356-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095902431100001 Content-Type: text/plain; charset="utf-8" From: Lara Lazier The APM2 states that if V_IGN_TPR is nonzero, the current virtual interrupt ignores the (virtual) TPR. Signed-off-by: Lara Lazier Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/svm_helper.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 4612dae1ac..a35b79548a 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -83,6 +83,11 @@ static inline bool ctl_has_irq(CPUX86State *env) =20 int_prio =3D (env->int_ctl & V_INTR_PRIO_MASK) >> V_INTR_PRIO_SHIFT; tpr =3D env->int_ctl & V_TPR_MASK; + + if (env->int_ctl & V_IGN_TPR_MASK) { + return env->int_ctl & V_IRQ_MASK; + } + return (env->int_ctl & V_IRQ_MASK) && (int_prio >=3D tpr); } =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163109561255144.95242265347849; Wed, 8 Sep 2021 03:06:52 -0700 (PDT) Received: from localhost ([::1]:50850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuTj-0000pd-CN for importer@patchew.org; Wed, 08 Sep 2021 06:06:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRg-0006K0-Oh for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:45 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:36777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRe-0002sg-Hc for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:43 -0400 Received: by mail-wr1-x42b.google.com with SMTP id g16so2419411wrb.3 for ; Wed, 08 Sep 2021 03:04:41 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/8CXdZuaVrNzRFWLPIhtZbQOhTCypBHZ9xL86lrreCQ=; b=OtX/xTITrC5XdlLqAU6izsKSYa9xbjUv/i6H4vnVSoJj4ZN5NiaTLTrUFwkCJBX/2R VrCexvvO+B48qZD8k5CKDFqiclmYkkO3AIsF0TtrClgyfOVoji+qQuiVPzSm9z5NiWoA cwqkNss8LAg12zKmihEvHaHP8oklEXfi1xomxl8hZrpGtuc7eXJ59t3Hs5UJdrDm+kN1 7RaszYBBgWUudR9Kk+giWG+s+5iCQyWwwlSE7ChU5oQtNX5ZtropANdIeMv183UGDY7z i2CHOLqrv872GVpdh9OhmocTSXB0UBbIbHhwEX/YhIrOVIX2CygKlINFfCb0WrSMHRBC tFwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/8CXdZuaVrNzRFWLPIhtZbQOhTCypBHZ9xL86lrreCQ=; b=4QwQn87EzOXq9GIcIv7LtjiLSilN1ujw7uBsjPzfXKVE3bSMLsWOVFSKoCXpTPe/6D UGPk3d1rYpQk6BxP0rutqgSMxaE7GkE14reCamfJYyJtxcz0aFnp60PiY3+/b0QgRBIn E5LJOkB+kjSeqNd2OqCUvOT9rCOd7QytbupvpJB1leaum/Kzb9TYO0LLL6vI04do/uX/ vyuDZwPCHQfiAe8WCRg6QpyzFn8K2+VGFYl1qmc9Robl22e1AJLiWvtsqO6qXFaUDXne AbWhFi1JqynQsdVeEe4grSZVDSSqoI018t0rb0ZXyXKjjBwpmMY3Rdp2TqEwBhbjKDS9 dvGg== X-Gm-Message-State: AOAM531Fz/QCcuzeHuyo0X7mm1xg5stvXeTsywVxasMiprsYYDx+DD5Z R8o/+75EOuPItqo1jPLHEuL6huQiX14= X-Google-Smtp-Source: ABdhPJwD5y0H7Skd5Z4xfRiduDUh8cLc3xCBpOVNZ8zmwlbnHOH/4YHrhDjOUs/UTrvP+NcHTvltNw== X-Received: by 2002:a5d:4b0b:: with SMTP id v11mr2384088wrq.359.1631095480879; Wed, 08 Sep 2021 03:04:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 07/43] target/i386: Added changed priority check for VIRQ Date: Wed, 8 Sep 2021 12:03:50 +0200 Message-Id: <20210908100426.264356-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095614120100001 Content-Type: text/plain; charset="utf-8" From: Lara Lazier Writes to cr8 affect v_tpr. This could set or unset an interrupt request as the priority might have changed. Signed-off-by: Lara Lazier Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 15 +++++++++++++++ target/i386/tcg/sysemu/misc_helper.c | 7 +++++++ target/i386/tcg/sysemu/svm_helper.c | 15 --------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 24e8ec5273..6b09b8b62f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2246,6 +2246,21 @@ static inline uint64_t cr4_reserved_bits(CPUX86State= *env) return reserved_bits; } =20 +static inline bool ctl_has_irq(CPUX86State *env) +{ + uint32_t int_prio; + uint32_t tpr; + + int_prio =3D (env->int_ctl & V_INTR_PRIO_MASK) >> V_INTR_PRIO_SHIFT; + tpr =3D env->int_ctl & V_TPR_MASK; + + if (env->int_ctl & V_IGN_TPR_MASK) { + return (env->int_ctl & V_IRQ_MASK); + } + + return (env->int_ctl & V_IRQ_MASK) && (int_prio >=3D tpr); +} + #if defined(TARGET_X86_64) && \ defined(CONFIG_USER_ONLY) && \ defined(CONFIG_LINUX) diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/= misc_helper.c index 91b0fc916b..9ccaa054c4 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -122,6 +122,13 @@ void helper_write_crN(CPUX86State *env, int reg, targe= t_ulong t0) qemu_mutex_unlock_iothread(); } env->int_ctl =3D (env->int_ctl & ~V_TPR_MASK) | (t0 & V_TPR_MASK); + + CPUState *cs =3D env_cpu(env); + if (ctl_has_irq(env)) { + cpu_interrupt(cs, CPU_INTERRUPT_VIRQ); + } else { + cpu_reset_interrupt(cs, CPU_INTERRUPT_VIRQ); + } break; default: env->cr[reg] =3D t0; diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index a35b79548a..7bbd3a18c9 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -76,21 +76,6 @@ static inline void svm_load_seg_cache(CPUX86State *env, = hwaddr addr, sc->base, sc->limit, sc->flags); } =20 -static inline bool ctl_has_irq(CPUX86State *env) -{ - uint32_t int_prio; - uint32_t tpr; - - int_prio =3D (env->int_ctl & V_INTR_PRIO_MASK) >> V_INTR_PRIO_SHIFT; - tpr =3D env->int_ctl & V_TPR_MASK; - - if (env->int_ctl & V_IGN_TPR_MASK) { - return env->int_ctl & V_IRQ_MASK; - } - - return (env->int_ctl & V_IRQ_MASK) && (int_prio >=3D tpr); -} - static inline bool is_efer_invalid_state (CPUX86State *env) { if (!(env->efer & MSR_EFER_SVME)) { --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095778110667.7288287886896; Wed, 8 Sep 2021 03:09:38 -0700 (PDT) Received: from localhost ([::1]:59326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuWP-0006ah-3c for importer@patchew.org; Wed, 08 Sep 2021 06:09:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0006NI-IA for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:48 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:42551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRg-0002t5-EY for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:47 -0400 Received: by mail-wr1-x42b.google.com with SMTP id q11so2383569wrr.9 for ; Wed, 08 Sep 2021 03:04:42 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IBf010dxB3czTGLExguHE9lNbcC2xzM9osq4hO9COOE=; b=FHf0PE3myyZg2p2t50MzInogsWdFdUaZgyPZbNKmv/hfBjxVss7UjrYv+tpybpZK45 AtDJ/wWWypksNlPw4RjBg3A+6LmOg+dOMKuExtNycs2kW3Nhot+OWfUFjIKnz3eeIjGA 7M8mGSyDjGo1IAfzR6OBITiSdVE4rn3cuEwaG0PqCH8lPfCnQFf4j38zWxOMugX6w061 vYtX9fT6+5u3PjFq4EPf/hr+iI34ZG8QpuVb+cMu5YM3mMp6Nd2T7SAppaM/opWdBjnb 8q9sUc/oPPP2mIg+VecSQ8sfEEsxMnvNs3+5TkPgw5VauDG7u8FAb48ZqY0knQf70uDw 0PlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IBf010dxB3czTGLExguHE9lNbcC2xzM9osq4hO9COOE=; b=SJHrlJ+pOX3+9zLNfo3iAiLE2CeEq18+CjH6zpnOlXm62W3P4hE0VDEtjf+4Y9DzRc PD5yfqCZ9jX4C32Lc1RejajlbCZbnzsUKPCb59hxA2MT9yUPu93dTcCxA7yWGCzaNbuy sxow3RWYOwgXvYjW1ImI1aXFlYXt9fi63tKyqiFf5AvaYWzKIPiUTCyztaRqIdKUIN6z WLO1lypQDk1N4RYdmaelBGlG/u+/XJI5uR1+8cTk1qdCoFyP2JZCqVl08rOV3w/h8A+K UuhrcAMq40OadBB0ED/3dLINohZN9diUMjrFhbg/WuEs87t5AZvbc5AAlWV8wjW1IzmH BPgQ== X-Gm-Message-State: AOAM533AoRFN606nM5n/uMCDchoP3qrt3LHl/hPqLqZy6T40vsW5t1XU d9CZDk+gtENHTjAncdLQXikmQjSwwbw= X-Google-Smtp-Source: ABdhPJwUkaXw9BwMTRx/9xKzPvhJyYH3ohh71b2Y4NuzEvcUNutx/2hr3p4VE5xeYuy+R2kaQET+yA== X-Received: by 2002:a5d:4568:: with SMTP id a8mr3096572wrc.200.1631095481579; Wed, 08 Sep 2021 03:04:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 08/43] target/i386: Added vVMLOAD and vVMSAVE feature Date: Wed, 8 Sep 2021 12:03:51 +0200 Message-Id: <20210908100426.264356-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lara Lazier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095780283100003 Content-Type: text/plain; charset="utf-8" From: Lara Lazier The feature allows the VMSAVE and VMLOAD instructions to execute in guest m= ode without causing a VMEXIT. (APM2 15.33.1) Signed-off-by: Lara Lazier Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 2 ++ target/i386/svm.h | 2 ++ target/i386/tcg/sysemu/excp_helper.c | 2 +- target/i386/tcg/sysemu/svm_helper.c | 29 ++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 6b09b8b62f..71ae3141c3 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2261,6 +2261,8 @@ static inline bool ctl_has_irq(CPUX86State *env) return (env->int_ctl & V_IRQ_MASK) && (int_prio >=3D tpr); } =20 +hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_type, + int *prot); #if defined(TARGET_X86_64) && \ defined(CONFIG_USER_ONLY) && \ defined(CONFIG_LINUX) diff --git a/target/i386/svm.h b/target/i386/svm.h index 036597a2ff..f9a785489d 100644 --- a/target/i386/svm.h +++ b/target/i386/svm.h @@ -24,6 +24,8 @@ #define V_INTR_MASKING_SHIFT 24 #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) =20 +#define V_VMLOAD_VMSAVE_ENABLED_MASK (1 << 1) + #define SVM_INTERRUPT_SHADOW_MASK 1 =20 #define SVM_IOIO_STR_SHIFT 2 diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index b6d940e04e..7af887be4d 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -358,7 +358,7 @@ do_check_protect_pse36: return error_code; } =20 -static hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_t= ype, +hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_type, int *prot) { CPUX86State *env =3D &X86_CPU(cs)->env; diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 7bbd3a18c9..6d39611eb6 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -120,6 +120,25 @@ static inline bool virtual_gif_enabled(CPUX86State *en= v) return false; } =20 +static inline bool virtual_vm_load_save_enabled(CPUX86State *env, uint32_t= exit_code, uintptr_t retaddr) +{ + uint64_t lbr_ctl; + + if (likely(env->hflags & HF_GUEST_MASK)) { + if (likely(!(env->hflags2 & HF2_NPT_MASK)) || !(env->efer & MSR_EF= ER_LMA)) { + cpu_vmexit(env, exit_code, 0, retaddr); + } + + lbr_ctl =3D x86_ldl_phys(env_cpu(env), env->vm_vmcb + offsetof(str= uct vmcb, + control.lbr_ctl)); + return (env->features[FEAT_SVM] & CPUID_SVM_V_VMSAVE_VMLOAD) + && (lbr_ctl & V_VMLOAD_VMSAVE_ENABLED_MASK); + + } + + return false; +} + static inline bool virtual_gif_set(CPUX86State *env) { return !virtual_gif_enabled(env) || (env->int_ctl & V_GIF_MASK); @@ -431,6 +450,7 @@ void helper_vmload(CPUX86State *env, int aflag) { CPUState *cs =3D env_cpu(env); target_ulong addr; + int prot; =20 cpu_svm_check_intercept_param(env, SVM_EXIT_VMLOAD, 0, GETPC()); =20 @@ -440,6 +460,10 @@ void helper_vmload(CPUX86State *env, int aflag) addr =3D (uint32_t)env->regs[R_EAX]; } =20 + if (virtual_vm_load_save_enabled(env, SVM_EXIT_VMLOAD, GETPC())) { + addr =3D get_hphys(cs, addr, MMU_DATA_LOAD, &prot); + } + qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmload! " TARGET_FMT_lx "\nFS: %016" PRIx64 " | " TARGET_FMT_lx "\n", addr, x86_ldq_phys(cs, addr + offsetof(struct vmcb, @@ -473,6 +497,7 @@ void helper_vmsave(CPUX86State *env, int aflag) { CPUState *cs =3D env_cpu(env); target_ulong addr; + int prot; =20 cpu_svm_check_intercept_param(env, SVM_EXIT_VMSAVE, 0, GETPC()); =20 @@ -482,6 +507,10 @@ void helper_vmsave(CPUX86State *env, int aflag) addr =3D (uint32_t)env->regs[R_EAX]; } =20 + if (virtual_vm_load_save_enabled(env, SVM_EXIT_VMSAVE, GETPC())) { + addr =3D get_hphys(cs, addr, MMU_DATA_STORE, &prot); + } + qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmsave! " TARGET_FMT_lx "\nFS: %016" PRIx64 " | " TARGET_FMT_lx "\n", addr, x86_ldq_phys(cs, --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163109561383512.910051445675435; Wed, 8 Sep 2021 03:06:53 -0700 (PDT) Received: from localhost ([::1]:50950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuTk-0000tW-Tj for importer@patchew.org; Wed, 08 Sep 2021 06:06:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0006NT-Jr for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:48 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:41795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRg-0002uV-Fl for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:46 -0400 Received: by mail-wr1-x429.google.com with SMTP id u9so2387694wrg.8 for ; Wed, 08 Sep 2021 03:04:43 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tVOq4P2b9fV7Bm+VGFLgDnTn5rJi9DMdnCOkpoB4vL0=; b=VroxlX5ftuTbsEDPxOAgb0ADcC25C7ActfvuOS+OyeJkQDCmxDIyFT3TsvKKA7y210 daHXFdQwry0c9BleXi0scPWyi/uhwFGvsnMzW3r3In0VgN0iY1vkiQkE0GfVRFBV1nRR BvDPcAl2dIfFaw7ypqYxeNbqD6Pm9r5RmanyDD9ONHswCYULW9vvQpGTI+lVPQj6ZtmW xnUkFdO3DSCpGh8ZqRsq4KYrXPlPNQS2IdSZRt97kKHKc19A6AhleDXbcrPROpisNDed oHblsDsJkqd8VAIIWSM705go9oGPQ80vx/QWiQFbJaV6MPiTpSML7oVq+bx40WTfbd6U W+1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=tVOq4P2b9fV7Bm+VGFLgDnTn5rJi9DMdnCOkpoB4vL0=; b=IcIc1mA78PBI5ZkDlzmaBPE1O6FOhdVAYgWjBJnwC5lESYy9yum0j9Yxl0SmwIaSfP v/gdQepY8rvFhPjxnddjrH0W7BNKYRqcKpPRugm3ZUQShZ/AzUDsoLqM2osadC/YFQsj uahu3XSYOOQG2XfFlhb7aEQSPWdkCRtG206fr/XAVd1vuYYnN/lpcyMg5M2b1dI7N3f4 BWB7YDL4TMBFgZQjg4LDmwSb+maY9HKuXZvOACOtuKVCMKsyr1F2Dv+WISA1/519h0Yu hKVfsiNbSHQkyk4Ng63ILWaouVNPgmU74HYlUtgn/k19ASw0M0XH0M1weEJR9GR4chub 9hNg== X-Gm-Message-State: AOAM533GHbLJ/HyphIU5UO3jBm2nPNIDrqKCa+5IFqr/VxC3wXXHHz1Q tv6y1H+Cec5guYW57taDWcRmOtrrOzA= X-Google-Smtp-Source: ABdhPJwylfDWP9g2Gk1ZJ+8lgbVx5n2BQXUWB+g3Op71gMYiSu0C0WgN+NntNWBFK22L2uiARi1hKg== X-Received: by 2002:adf:ec8b:: with SMTP id z11mr3054852wrn.122.1631095482415; Wed, 08 Sep 2021 03:04:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 09/43] memory: Add RAM_PROTECTED flag to skip IOMMU mappings Date: Wed, 8 Sep 2021 12:03:52 +0200 Message-Id: <20210908100426.264356-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095614204100005 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Add a new RAMBlock flag to denote "protected" memory, i.e. memory that looks and acts like RAM but is inaccessible via normal mechanisms, including DMA. Use the flag to skip protected memory regions when mapping RAM for DMA in VFIO. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong v1-->v2: - Unified the "share" and "protected" arguments with ram_flags in the memory_region_init_ram_from_fd()(Paolo). Message-Id: <20210719112136.57018-2-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/vfio/common.c | 1 + include/exec/memory.h | 15 ++++++++++++++- softmmu/memory.c | 5 +++++ softmmu/physmem.c | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8728d4d5c2..1289cfa8be 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -562,6 +562,7 @@ static bool vfio_listener_skipped_section(MemoryRegionS= ection *section) { return (!memory_region_is_ram(section->mr) && !memory_region_is_iommu(section->mr)) || + memory_region_is_protected(section->mr) || /* * Sizing an enabled 64-bit BAR can cause spurious mappings to * addresses in the upper part of the 64-bit address space. Th= ese diff --git a/include/exec/memory.h b/include/exec/memory.h index c3d417d317..9446874d21 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -190,6 +190,9 @@ typedef struct IOMMUTLBEvent { */ #define RAM_NORESERVE (1 << 7) =20 +/* RAM that isn't accessible through normal means. */ +#define RAM_PROTECTED (1 << 8) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, @@ -1267,7 +1270,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, * @name: the name of the region. * @size: size of the region. * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, - * RAM_NORESERVE. + * RAM_NORESERVE, RAM_PROTECTED. * @fd: the fd to mmap. * @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. @@ -1568,6 +1571,16 @@ static inline bool memory_region_is_romd(MemoryRegio= n *mr) return mr->rom_device && mr->romd_mode; } =20 +/** + * memory_region_is_protected: check whether a memory region is protected + * + * Returns %true if a memory region is protected RAM and cannot be accessed + * via standard mechanisms, e.g. DMA. + * + * @mr: the memory region being queried + */ +bool memory_region_is_protected(MemoryRegion *mr); + /** * memory_region_get_iommu: check whether a memory region is an iommu * diff --git a/softmmu/memory.c b/softmmu/memory.c index bfedaf9c4d..54cd0e9824 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1811,6 +1811,11 @@ bool memory_region_is_ram_device(MemoryRegion *mr) return mr->ram_device; } =20 +bool memory_region_is_protected(MemoryRegion *mr) +{ + return mr->ram && (mr->ram_block->flags & RAM_PROTECTED); +} + uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) { uint8_t mask =3D mr->dirty_log_mask; diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 23e77cb771..088660d973 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2055,7 +2055,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, int64_t file_size, file_align; =20 /* Just support these ram flags by now. */ - assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE)) =3D=3D 0= ); + assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE | + RAM_PROTECTED)) =3D=3D 0); =20 if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096094480218.45829100225205; Wed, 8 Sep 2021 03:14:54 -0700 (PDT) Received: from localhost ([::1]:51824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNubV-0003bo-D2 for importer@patchew.org; Wed, 08 Sep 2021 06:14:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0006Mx-Gh for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:48 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:35434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRg-0002vQ-FO for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:45 -0400 Received: by mail-wm1-x32e.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so1147956wmi.0 for ; Wed, 08 Sep 2021 03:04:44 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dln8prTmajRRRjGUQwEQEBEP968IxcO7qYkDNzD6MX0=; b=hptywpjLTd7nGDYXg8vfB/bM0S1qDxgZ4/UEO23xtE+nEThnnyRi5N3HYeIyaCvZXq l6+eWIjUXOXfEJWYHgFmEAlPG2YvLnb39y9SGoEYdVg6vHvjcWhlFePJ8tCmqouXA8i/ 89RubwjTf1FN7GXrudmPBdSOnWmfKuKkauDc16ITD3ZrVXNC8nzfZic5h5DDrVKg7ntN FCm+u1FGJ0EIPxpf7enuSKECEivfswNwt1ayf5fHay9J44tU8xwxtmNsRJ4LeP5qx3Qs QplrruPAkOi8zyWEGvV00ZyKj/esdJByUcXiXMpllPNROlLlAv1Bqta2cpZBWHT2P4/e htvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Dln8prTmajRRRjGUQwEQEBEP968IxcO7qYkDNzD6MX0=; b=L9CPrRADkGdSZirGPGmr16CUFubTlm0D/2fplWinNQ+7V3UYdQV4ZiyNdQb0jAEOrf i7mLeyQV7wh+0hsD+6xIYQ6/0tn9lh2fwW5z8FIEHUatk5ujtPnqOpQ4b23dmeHo1NeD ZUnUXjbtSzSZ0xYHUmqOaELpiJcDy5jJmy6SgvH46hmNMp41oc3rU8Qlzg34MaAs9m/z ScgH8u5MN2lOOiCc+fu4tSOFpPeSXHMdi1GAxTQWVsFGtTU/8uiWB6dZQeFA/38c1euP 3lR1Jn3aYYVWiWAcYbr6MRLJ2RqtSbRw8mFY2rBzIISJZPp3KII5yYcIFspHnPcXkadO YwTw== X-Gm-Message-State: AOAM533ohKysOiGshfLHtM7a1+ioxu8rt84PWj0Bca34nRjs6UT3LcBR NgJ8dJfu1eoiLr5bwYpA33BdMIRIFyU= X-Google-Smtp-Source: ABdhPJxdPdUsGZECZtde8UGaW5U8OsAdxue1DlymjicArmtz0WNQx5Ivst2cIsQLJftOpvJAEeli3A== X-Received: by 2002:a05:600c:4f52:: with SMTP id m18mr2658838wmq.34.1631095483123; Wed, 08 Sep 2021 03:04:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 10/43] hostmem: Add hostmem-epc as a backend for SGX EPC Date: Wed, 8 Sep 2021 12:03:53 +0200 Message-Id: <20210908100426.264356-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096095938100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson EPC (Enclave Page Cahe) is a specialized type of memory used by Intel SGX (Software Guard Extensions). The SDM desribes EPC as: The Enclave Page Cache (EPC) is the secure storage used to store enclave pages when they are a part of an executing enclave. For an EPC page, hardware performs additional access control checks to restrict access to the page. After the current page access checks and translations are performed, the hardware checks that the EPC page is accessible to the program currently executing. Generally an EPC page is only accessed by the owner of the executing enclave or an instruction which is setting up an EPC page. Because of its unique requirements, Linux manages EPC separately from normal memory. Similar to memfd, the device /dev/sgx_vepc can be opened to obtain a file descriptor which can in turn be used to mmap() EPC memory. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong v1-->v2: - Unified the "share" and "protected" arguments with ram_flags in the memory_region_init_ram_from_fd()(Paolo). Message-Id: <20210719112136.57018-3-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- backends/hostmem-epc.c | 92 ++++++++++++++++++++++++++++++++++++++++++ backends/meson.build | 1 + 2 files changed, 93 insertions(+) create mode 100644 backends/hostmem-epc.c diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c new file mode 100644 index 0000000000..b512a68cb0 --- /dev/null +++ b/backends/hostmem-epc.c @@ -0,0 +1,92 @@ +/* + * QEMU host SGX EPC memory backend + * + * Copyright (C) 2019 Intel Corporation + * + * Authors: + * Sean Christopherson + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qom/object_interfaces.h" +#include "qapi/error.h" +#include "sysemu/hostmem.h" + +#define TYPE_MEMORY_BACKEND_EPC "memory-backend-epc" + +#define MEMORY_BACKEND_EPC(obj) \ + OBJECT_CHECK(HostMemoryBackendEpc, (obj), TYPE_MEMORY_BACKEND_EPC) + +typedef struct HostMemoryBackendEpc HostMemoryBackendEpc; + +struct HostMemoryBackendEpc { + HostMemoryBackend parent_obj; +}; + +static void +sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) +{ + uint32_t ram_flags; + char *name; + int fd; + + if (!backend->size) { + error_setg(errp, "can't create backend with size 0"); + return; + } + + fd =3D qemu_open_old("/dev/sgx_vepc", O_RDWR); + if (fd < 0) { + error_setg_errno(errp, errno, + "failed to open /dev/sgx_vepc to alloc SGX EPC"); + return; + } + + name =3D object_get_canonical_path(OBJECT(backend)); + ram_flags =3D (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED; + memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + name, backend->size, ram_flags, + fd, 0, errp); + g_free(name); +} + +static void sgx_epc_backend_instance_init(Object *obj) +{ + HostMemoryBackend *m =3D MEMORY_BACKEND(obj); + + m->share =3D true; + m->merge =3D false; + m->dump =3D false; +} + +static void sgx_epc_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); + + bc->alloc =3D sgx_epc_backend_memory_alloc; +} + +static const TypeInfo sgx_epc_backed_info =3D { + .name =3D TYPE_MEMORY_BACKEND_EPC, + .parent =3D TYPE_MEMORY_BACKEND, + .instance_init =3D sgx_epc_backend_instance_init, + .class_init =3D sgx_epc_backend_class_init, + .instance_size =3D sizeof(HostMemoryBackendEpc), +}; + +static void register_types(void) +{ + int fd =3D qemu_open_old("/dev/sgx_vepc", O_RDWR); + if (fd >=3D 0) { + close(fd); + + type_register_static(&sgx_epc_backed_info); + } +} + +type_init(register_types); diff --git a/backends/meson.build b/backends/meson.build index d4221831fc..46fd16b269 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -16,5 +16,6 @@ softmmu_ss.add(when: ['CONFIG_VHOST_USER', 'CONFIG_VIRTIO= '], if_true: files('vho softmmu_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('cryptodev-vho= st.c')) softmmu_ss.add(when: ['CONFIG_VIRTIO_CRYPTO', 'CONFIG_VHOST_CRYPTO'], if_t= rue: files('cryptodev-vhost-user.c')) softmmu_ss.add(when: 'CONFIG_GIO', if_true: [files('dbus-vmstate.c'), gio]) +softmmu_ss.add(when: 'CONFIG_LINUX', if_true: files('hostmem-epc.c')) =20 subdir('tpm') --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310960503521006.0059439960468; Wed, 8 Sep 2021 03:14:10 -0700 (PDT) Received: from localhost ([::1]:48306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuan-0001F3-AB for importer@patchew.org; Wed, 08 Sep 2021 06:14:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRl-0006QH-Qe for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:49 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:43864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRh-0002vW-G0 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:49 -0400 Received: by mail-wr1-x433.google.com with SMTP id b6so2368167wrh.10 for ; Wed, 08 Sep 2021 03:04:44 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X98lXPUBye1x4dkXr+a8pPzZR1wl6g0L6Pc/Ipe7d9w=; b=qf0uuzVNUhnYljnDkFE2MoufHi4JdO1D3J0ujV9mBWJ8uMNZXzafI9eqZ5RNHIfH2l 9RiEapBMxWODDGpon8wmsSKzULVySysz4rV+U3YfTxSAqcvGkai1jTL6BeoKpaR+nLFQ cjgifgh+qknQPTlTDyM/b6MNqIoDcR1zsU7a/CO2DLRo2VPdwutATIafM91LewAQd3CV cZvX5mavWD48Kuc1H31wKXLcX+1RSdq4EMXEJINI5a92jBZw/umCo0b6xea/AgJBnVj/ XUtvV8XwiYKpiMvdXu+XoctfeR+APXxOFlfGOA1jqb0rTHe6cInQcBYK4wUHcsI1X6Xf Rubg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=X98lXPUBye1x4dkXr+a8pPzZR1wl6g0L6Pc/Ipe7d9w=; b=k6cCpn2f5FfQHtMmvzFaJoabXScmQLMMOmSXGj9A2CDN3BY30Co5sfLdA40wVrTjfT OnzjyoqtBRbH2KSYWL+5UABGW6Z+xTWqkL3Pt1MibSofip4UCJ8Wfik0r6gBJuT9JkI/ AqjGIOiBfYagP7p52saoqdlPg5d/bWsEAgGmW7vDKu5qx5v4GgQO16ALHCn9iA9qOG7K JwwT2CxQafh9NAOZ8CtLolo+SgBS3rYbvAhFeXITssFusU+qp/1cvXaxOe2cVEwCCwxG ha6kYFXqUoF0DzaePfKYKWx5sqpQN9KHJwFUnE2NqIM/JILZDku5sFOX5tCpWTS70f+e Y2+g== X-Gm-Message-State: AOAM532v+nKv8h7BOnMj69kD7jozoFHxZIwLiQwqf6a93R5NCSKZNWiz F97Qwu2mNwFmEDA7D0B0K0kdx747uIc= X-Google-Smtp-Source: ABdhPJz8On8Voxfu0Cyg3R2JA7Q7B7vtfUQfvS6zYaBz7s6oo2tLCsN7W9UDi9yS49X+q1eyRhe4Uw== X-Received: by 2002:a05:6000:1569:: with SMTP id 9mr3147641wrz.242.1631095483816; Wed, 08 Sep 2021 03:04:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 11/43] qom: Add memory-backend-epc ObjectOptions support Date: Wed, 8 Sep 2021 12:03:54 +0200 Message-Id: <20210908100426.264356-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096052367100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong Add the new 'memory-backend-epc' user creatable QOM object in the ObjectOptions to support SGX since v6.1, or the sgx backend object cannot bootup. Signed-off-by: Yang Zhong v1-->v2: - Added the new MemoryBackendEpcProperties and related documents, and updated the blurb(Eric Blake). Message-Id: <20210719112136.57018-4-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- qapi/qom.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/qapi/qom.json b/qapi/qom.json index a25616bc7a..16ba30e5b9 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -647,6 +647,23 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } =20 +## +# @MemoryBackendEpcProperties: +# +# Properties for memory-backend-epc objects. +# +# The @share boolean option is true by default with epc +# +# The @merge boolean option is false by default with epc +# +# The @dump boolean option is false by default with epc +# +# Since: 6.1 +## +{ 'struct': 'MemoryBackendEpcProperties', + 'base': 'MemoryBackendProperties', + 'data': {} } + ## # @PrManagerHelperProperties: # @@ -797,6 +814,7 @@ { 'name': 'memory-backend-memfd', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', + 'memory-backend-epc', 'pef-guest', 'pr-manager-helper', 'qtest', @@ -855,6 +873,7 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdPropertie= s', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-epc': 'MemoryBackendEpcProperties', 'pr-manager-helper': 'PrManagerHelperProperties', 'qtest': 'QtestProperties', 'rng-builtin': 'RngProperties', --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096558675407.1514701429968; Wed, 8 Sep 2021 03:22:38 -0700 (PDT) Received: from localhost ([::1]:45536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuix-0001bR-OR for importer@patchew.org; Wed, 08 Sep 2021 06:22:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRr-0006cM-1U for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:55 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:36783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRj-0002vs-3c for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:54 -0400 Received: by mail-wr1-x431.google.com with SMTP id g16so2419665wrb.3 for ; Wed, 08 Sep 2021 03:04:45 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4iMjuoQHF2hMgz9rRlyo7y8BWexeTkanfLhhNNfYVfg=; b=I54CMS+23rBFtrfFTzjvkRzMyuMzcLjCG1hafp/2NXc7XqfOWWHhFsOc76jhhSrF4k NqJZOlkHL/n1Fdbgv97v44ItdpzjivmWoYDskxPXcdO1WecVP3T6ZsrZNpliQj3H9K3s XMCAzjjkRJCUXFiiZOM0QXV9mQ2lAnwoeIWGjOHfH9nNeuskbdGdH4yz28a7xRT+PhNT nLlmqgtMQSopUHpvn+YpdV4ZL7CGmHXNZMQJhG3K+jNm4LoLAotMnXXMDOXH34DWNOyC 2oLssiKMnGrxNNBjvIXustVgOk6wac3j0Dx2aBPz6i5g6HKXYXjmSEd2/6DMgWi4sHyn vWAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=4iMjuoQHF2hMgz9rRlyo7y8BWexeTkanfLhhNNfYVfg=; b=2l8Wyx9z03Ao+r9pJs6Rmw/knQosS2WqckHfLVF0OVSyRQh+QWOeEJZEiE1pofhaui DnuUbomMCROIss+1m5WML4J+nNg9KqUOjVUS+HbMAsitAAzOMsAhQyTVd9JmVGxVPBha oNsteTNFenvhRkC+b2RyfXM/LfZp7TMzBsckjGjgPQkGkvR0hGpq/YO0uAYxP4re7UX+ Ap3HgwsW+Bna3QUEauqYW6uLqkVTvus+xtz0AEH5fLjImbGt+BvF1LQcMw1zGKgGAQx2 9fSs7BQ4CcXzM2w/XO3U0nT7GgblfpRUlfWPe2LqACgKMZbOlOS3jMN0afSeBQR7kOqQ 6y7w== X-Gm-Message-State: AOAM530eu8ERcUP7wrLSD9ldnQ6BsmhJFkpFUwEula9t9NzqrEUHVo+5 ElonxGmXBNZODh98S1kI1Fq2tMe8iSE= X-Google-Smtp-Source: ABdhPJz4ZLxvjYssyXDnxwZlUogbFeZZChblSLiG2cTZdhgAapdS+a7kZvoQPjiodlATDHFmQ3vT5Q== X-Received: by 2002:adf:d1c3:: with SMTP id b3mr3090220wrd.286.1631095484530; Wed, 08 Sep 2021 03:04:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 12/43] i386: Add 'sgx-epc' device to expose EPC sections to guest Date: Wed, 8 Sep 2021 12:03:55 +0200 Message-Id: <20210908100426.264356-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096561509100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson SGX EPC is enumerated through CPUID, i.e. EPC "devices" need to be realized prior to realizing the vCPUs themselves, which occurs long before generic devices are parsed and realized. Because of this, do not allow 'sgx-epc' devices to be instantiated after vCPUS have been created. The 'sgx-epc' device is essentially a placholder at this time, it will be fully implemented in a future patch along with a dedicated command to create 'sgx-epc' devices. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-5-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/meson.build | 1 + hw/i386/sgx-epc.c | 161 ++++++++++++++++++++++++++++++++++++++ include/hw/i386/sgx-epc.h | 44 +++++++++++ 3 files changed, 206 insertions(+) create mode 100644 hw/i386/sgx-epc.c create mode 100644 include/hw/i386/sgx-epc.h diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 80dad29f2b..27476b36bb 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -5,6 +5,7 @@ i386_ss.add(files( 'e820_memory_layout.c', 'multiboot.c', 'x86.c', + 'sgx-epc.c', )) =20 i386_ss.add(when: 'CONFIG_X86_IOMMU', if_true: files('x86-iommu.c'), diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c new file mode 100644 index 0000000000..aa487dea79 --- /dev/null +++ b/hw/i386/sgx-epc.c @@ -0,0 +1,161 @@ +/* + * SGX EPC device + * + * Copyright (C) 2019 Intel Corporation + * + * Authors: + * Sean Christopherson + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" +#include "hw/i386/sgx-epc.h" +#include "hw/mem/memory-device.h" +#include "hw/qdev-properties.h" +#include "monitor/qdev.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include "qemu/units.h" +#include "target/i386/cpu.h" +#include "exec/address-spaces.h" + +static Property sgx_epc_properties[] =3D { + DEFINE_PROP_UINT64(SGX_EPC_ADDR_PROP, SGXEPCDevice, addr, 0), + DEFINE_PROP_LINK(SGX_EPC_MEMDEV_PROP, SGXEPCDevice, hostmem, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void sgx_epc_get_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Error *local_err =3D NULL; + uint64_t value; + + value =3D memory_device_get_region_size(MEMORY_DEVICE(obj), &local_err= ); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + visit_type_uint64(v, name, &value, errp); +} + +static void sgx_epc_init(Object *obj) +{ + object_property_add(obj, SGX_EPC_SIZE_PROP, "uint64", sgx_epc_get_size, + NULL, NULL, NULL); +} + +static void sgx_epc_realize(DeviceState *dev, Error **errp) +{ + PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); + X86MachineState *x86ms =3D X86_MACHINE(pcms); + SGXEPCDevice *epc =3D SGX_EPC(dev); + const char *path; + + if (x86ms->boot_cpus !=3D 0) { + error_setg(errp, "'" TYPE_SGX_EPC "' can't be created after vCPUs," + "e.g. via -device"); + return; + } + + if (!epc->hostmem) { + error_setg(errp, "'" SGX_EPC_MEMDEV_PROP "' property is not set"); + return; + } else if (host_memory_backend_is_mapped(epc->hostmem)) { + path =3D object_get_canonical_path_component(OBJECT(epc->hostmem)); + error_setg(errp, "can't use already busy memdev: %s", path); + return; + } + + error_setg(errp, "'" TYPE_SGX_EPC "' not supported"); +} + +static void sgx_epc_unrealize(DeviceState *dev) +{ + SGXEPCDevice *epc =3D SGX_EPC(dev); + + host_memory_backend_set_mapped(epc->hostmem, false); +} + +static uint64_t sgx_epc_md_get_addr(const MemoryDeviceState *md) +{ + const SGXEPCDevice *epc =3D SGX_EPC(md); + + return epc->addr; +} + +static void sgx_epc_md_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), SGX_EPC_ADDR_PROP, addr, errp); +} + +static uint64_t sgx_epc_md_get_plugged_size(const MemoryDeviceState *md, + Error **errp) +{ + return 0; +} + +static MemoryRegion *sgx_epc_md_get_memory_region(MemoryDeviceState *md, + Error **errp) +{ + SGXEPCDevice *epc =3D SGX_EPC(md); + + if (!epc->hostmem) { + error_setg(errp, "'" SGX_EPC_MEMDEV_PROP "' property must be set"); + return NULL; + } + + return host_memory_backend_get_memory(epc->hostmem); +} + +static void sgx_epc_md_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + /* TODO */ +} + +static void sgx_epc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(oc); + + dc->hotpluggable =3D false; + dc->realize =3D sgx_epc_realize; + dc->unrealize =3D sgx_epc_unrealize; + dc->desc =3D "SGX EPC section"; + device_class_set_props(dc, sgx_epc_properties); + + mdc->get_addr =3D sgx_epc_md_get_addr; + mdc->set_addr =3D sgx_epc_md_set_addr; + mdc->get_plugged_size =3D sgx_epc_md_get_plugged_size; + mdc->get_memory_region =3D sgx_epc_md_get_memory_region; + mdc->fill_device_info =3D sgx_epc_md_fill_device_info; +} + +static TypeInfo sgx_epc_info =3D { + .name =3D TYPE_SGX_EPC, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(SGXEPCDevice), + .instance_init =3D sgx_epc_init, + .class_init =3D sgx_epc_class_init, + .class_size =3D sizeof(DeviceClass), + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void sgx_epc_register_types(void) +{ + type_register_static(&sgx_epc_info); +} + +type_init(sgx_epc_register_types) diff --git a/include/hw/i386/sgx-epc.h b/include/hw/i386/sgx-epc.h new file mode 100644 index 0000000000..5fd9ae2d0c --- /dev/null +++ b/include/hw/i386/sgx-epc.h @@ -0,0 +1,44 @@ +/* + * SGX EPC device + * + * Copyright (C) 2019 Intel Corporation + * + * Authors: + * Sean Christopherson + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#ifndef QEMU_SGX_EPC_H +#define QEMU_SGX_EPC_H + +#include "sysemu/hostmem.h" + +#define TYPE_SGX_EPC "sgx-epc" +#define SGX_EPC(obj) \ + OBJECT_CHECK(SGXEPCDevice, (obj), TYPE_SGX_EPC) +#define SGX_EPC_CLASS(oc) \ + OBJECT_CLASS_CHECK(SGXEPCDeviceClass, (oc), TYPE_SGX_EPC) +#define SGX_EPC_GET_CLASS(obj) \ + OBJECT_GET_CLASS(SGXEPCDeviceClass, (obj), TYPE_SGX_EPC) + +#define SGX_EPC_ADDR_PROP "addr" +#define SGX_EPC_SIZE_PROP "size" +#define SGX_EPC_MEMDEV_PROP "memdev" + +/** + * SGXEPCDevice: + * @addr: starting guest physical address, where @SGXEPCDevice is mapped. + * Default value: 0, means that address is auto-allocated. + * @hostmem: host memory backend providing memory for @SGXEPCDevice + */ +typedef struct SGXEPCDevice { + /* private */ + DeviceState parent_obj; + + /* public */ + uint64_t addr; + HostMemoryBackend *hostmem; +} SGXEPCDevice; + +#endif --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096230583639.9021524065765; Wed, 8 Sep 2021 03:17:10 -0700 (PDT) Received: from localhost ([::1]:56606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNudh-0006v8-AD for importer@patchew.org; Wed, 08 Sep 2021 06:17:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRn-0006Vl-UT for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:52 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:56218) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0002wp-9q for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:51 -0400 Received: by mail-wm1-x336.google.com with SMTP id g74so1260847wmg.5 for ; Wed, 08 Sep 2021 03:04:46 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PlNf/NL33SJB44aLcDvUwXgbMaW7SjiGO9YcWlIMlPk=; b=M16/r2JeekGvmuQf5x/YTHgRkx71ZP2pUtbbwDEWSPQOASWc+Bfb89DT09pZ1QM3My 7zOjLLydgEpM7Er4HVxItUj8DqfCtBQDLGcgKp1FblAMJF07EYT9D6PrFsVZ2UKc9zi2 IUXBWYsFPae12BwTE2Ua50H1xZlF+9fZoz9tK6ysCWyjQTCeb2DXjluO+ncdPu/b4egR 6mjH5vrpEXmpgGFQ9l/Z1DUD15tgiCb+mo9RtYLsA9ZU336UdeiX1ibejmo53Vu6SDxJ nMSHbMS9UT5Exh889gk58z8dYqEQf0dA/yr1opOX4Crr9bGsQfSEb8CGioErP714bWif EY7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PlNf/NL33SJB44aLcDvUwXgbMaW7SjiGO9YcWlIMlPk=; b=Tl0HOql7o21fHL9WzU6MpH0a1hr9H2Zxk26ln0L+7Cl8hvr9K2Wo3rr89R05ZIDGib XBpDt/2vSwUlYqnQCWcTL96VujNxpHx2G1Jf8ediuvI0YAm8Rh361bp4izjI1ZpEK0Fz /5Ob6q9BEVpuf1kUn2tA/MtCkX7tSnTQLo8fd4o1D7Hyu8zEeNWdFsBP0dtL+nMukMf0 nDRqwAZb2G/XqHvT3Gygc28xd632xBudp1xIjnD9cgq83Z8BjiXdcklfRibzYhR5BIfE uYkvSsJcTkdYkrc/PmK9N68eRxBDwTZBS2WGZNWVgoeSN0an8O+P7peT23hkpYs9DCc1 J5fw== X-Gm-Message-State: AOAM530iJJY4lrNrFdHsUP3g5zU8AFJGPUBbbiF62QE2Z/oeJz5Keftr QzD2rmOM1EZl3uQlzB+fDIOli9pRaPA= X-Google-Smtp-Source: ABdhPJzlr+NzoaEp2BrmBo6gTncSfh5ifHwwUACVckLMASjP89z02dXzjlJyk7D3HZNFs5sNlTj/Zg== X-Received: by 2002:a05:600c:2245:: with SMTP id a5mr2742240wmm.19.1631095485320; Wed, 08 Sep 2021 03:04:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 13/43] vl: Add sgx compound properties to expose SGX EPC sections to guest Date: Wed, 8 Sep 2021 12:03:56 +0200 Message-Id: <20210908100426.264356-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096231392100005 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Because SGX EPC is enumerated through CPUID, EPC "devices" need to be realized prior to realizing the vCPUs themselves, i.e. long before generic devices are parsed and realized. From a virtualization perspective, the CPUID aspect also means that EPC sections cannot be hotplugged without paravirtualizing the guest kernel (hardware does not support hotplugging as EPC sections must be locked down during pre-boot to provide EPC's security properties). So even though EPC sections could be realized through the generic -devices command, they need to be created much earlier for them to actually be usable by the guest. Place all EPC sections in a contiguous block, somewhat arbitrarily starting after RAM above 4g. Ensuring EPC is in a contiguous region simplifies calculations, e.g. device memory base, PCI hole, etc..., allows dynamic calculation of the total EPC size, e.g. exposing EPC to guests does not require -maxmem, and last but not least allows all of EPC to be enumerated in a single ACPI entry, which is expected by some kernels, e.g. Windows 7 and 8. The new compound properties command for sgx like below: ...... -object memory-backend-epc,id=3Dmem1,size=3D28M,prealloc=3Don \ -object memory-backend-epc,id=3Dmem2,size=3D10M \ -M sgx-epc.0.memdev=3Dmem1,sgx-epc.1.memdev=3Dmem2 Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong v3-->v4: - Moved sgx compound property setter/getter from MachineState to X86MachineState(Paolo). - Re-defined struct SgxEPC, removed 'id' property and added struct SgxEPCList for sgx-epc.0.{memdev}(Paolo). - Removed g_malloc0(), and changed the 'SGXEPCState *sgx_epc' to 'SGXEPCState sgx_epc' in struct PCMachineState(Paolo). - Changed the SGX compound property cmdline from sgx-epc.{memdev}.0 to sgx-epc.0.{memdev}(Paolo). v2-->v3: - Removed the QemuOptsList for sgx-epc virtual device and used the '-M' = to replace '-sgx-epc' with compound properties(Paolo). Message-Id: <20210719112136.57018-6-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/meson.build | 1 + hw/i386/sgx-epc.c | 20 ++++++++---- hw/i386/sgx.c | 67 +++++++++++++++++++++++++++++++++++++++ hw/i386/x86.c | 29 +++++++++++++++++ include/hw/i386/pc.h | 6 ++++ include/hw/i386/sgx-epc.h | 14 ++++++++ include/hw/i386/x86.h | 1 + qapi/machine.json | 26 +++++++++++++++ qemu-options.hx | 10 ++++-- 9 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 hw/i386/sgx.c diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 27476b36bb..fefce9e4ba 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -6,6 +6,7 @@ i386_ss.add(files( 'multiboot.c', 'x86.c', 'sgx-epc.c', + 'sgx.c' )) =20 i386_ss.add(when: 'CONFIG_X86_IOMMU', if_true: files('x86-iommu.c'), diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c index aa487dea79..924dea22f0 100644 --- a/hw/i386/sgx-epc.c +++ b/hw/i386/sgx-epc.c @@ -14,13 +14,8 @@ #include "hw/i386/sgx-epc.h" #include "hw/mem/memory-device.h" #include "hw/qdev-properties.h" -#include "monitor/qdev.h" #include "qapi/error.h" #include "qapi/visitor.h" -#include "qemu/config-file.h" -#include "qemu/error-report.h" -#include "qemu/option.h" -#include "qemu/units.h" #include "target/i386/cpu.h" #include "exec/address-spaces.h" =20 @@ -56,6 +51,8 @@ static void sgx_epc_realize(DeviceState *dev, Error **err= p) { PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); X86MachineState *x86ms =3D X86_MACHINE(pcms); + MemoryDeviceState *md =3D MEMORY_DEVICE(dev); + SGXEPCState *sgx_epc =3D &pcms->sgx_epc; SGXEPCDevice *epc =3D SGX_EPC(dev); const char *path; =20 @@ -74,7 +71,18 @@ static void sgx_epc_realize(DeviceState *dev, Error **er= rp) return; } =20 - error_setg(errp, "'" TYPE_SGX_EPC "' not supported"); + epc->addr =3D sgx_epc->base + sgx_epc->size; + + memory_region_add_subregion(&sgx_epc->mr, epc->addr - sgx_epc->base, + host_memory_backend_get_memory(epc->hostme= m)); + + host_memory_backend_set_mapped(epc->hostmem, true); + + sgx_epc->sections =3D g_renew(SGXEPCDevice *, sgx_epc->sections, + sgx_epc->nr_sections + 1); + sgx_epc->sections[sgx_epc->nr_sections++] =3D epc; + + sgx_epc->size +=3D memory_device_get_region_size(md, errp); } =20 static void sgx_epc_unrealize(DeviceState *dev) diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c new file mode 100644 index 0000000000..e77deb0b00 --- /dev/null +++ b/hw/i386/sgx.c @@ -0,0 +1,67 @@ +/* + * SGX common code + * + * Copyright (C) 2021 Intel Corporation + * + * Authors: + * Yang Zhong + * Sean Christopherson + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" +#include "hw/i386/sgx-epc.h" +#include "hw/mem/memory-device.h" +#include "monitor/qdev.h" +#include "qapi/error.h" +#include "exec/address-spaces.h" + +static int sgx_epc_set_property(void *opaque, const char *name, + const char *value, Error **errp) +{ + Object *obj =3D opaque; + Error *err =3D NULL; + + object_property_parse(obj, name, value, &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return -1; + } + return 0; +} + +void pc_machine_init_sgx_epc(PCMachineState *pcms) +{ + SGXEPCState *sgx_epc =3D &pcms->sgx_epc; + X86MachineState *x86ms =3D X86_MACHINE(pcms); + Error *err =3D NULL; + SgxEPCList *list =3D NULL; + Object *obj; + + memset(sgx_epc, 0, sizeof(SGXEPCState)); + sgx_epc->base =3D 0x100000000ULL + x86ms->above_4g_mem_size; + + memory_region_init(&sgx_epc->mr, OBJECT(pcms), "sgx-epc", UINT64_MAX); + memory_region_add_subregion(get_system_memory(), sgx_epc->base, + &sgx_epc->mr); + + for (list =3D x86ms->sgx_epc_list; list; list =3D list->next) { + obj =3D object_new("sgx-epc"); + + /* set the memdev link with memory backend */ + sgx_epc_set_property(obj, SGX_EPC_MEMDEV_PROP, list->value->memdev, + &err); + object_property_set_bool(obj, "realized", true, &err); + object_unref(obj); + } + + if ((sgx_epc->base + sgx_epc->size) < sgx_epc->base) { + error_report("Size of all 'sgx-epc' =3D0x%"PRIu64" causes EPC to w= rap", + sgx_epc->size); + exit(EXIT_FAILURE); + } + + memory_region_set_size(&sgx_epc->mr, sgx_epc->size); +} diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 00448ed55a..41ef9a84a9 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -30,6 +30,8 @@ #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qapi/qapi-visit-common.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-machine.h" #include "qapi/visitor.h" #include "sysemu/qtest.h" #include "sysemu/whpx.h" @@ -1263,6 +1265,27 @@ static void x86_machine_set_bus_lock_ratelimit(Objec= t *obj, Visitor *v, visit_type_uint64(v, name, &x86ms->bus_lock_ratelimit, errp); } =20 +static void machine_get_sgx_epc(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + X86MachineState *x86ms =3D X86_MACHINE(obj); + SgxEPCList *list =3D x86ms->sgx_epc_list; + + visit_type_SgxEPCList(v, name, &list, errp); +} + +static void machine_set_sgx_epc(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + X86MachineState *x86ms =3D X86_MACHINE(obj); + SgxEPCList *list; + + list =3D x86ms->sgx_epc_list; + visit_type_SgxEPCList(v, name, &x86ms->sgx_epc_list, errp); + + qapi_free_SgxEPCList(list); +} + static void x86_machine_initfn(Object *obj) { X86MachineState *x86ms =3D X86_MACHINE(obj); @@ -1322,6 +1345,12 @@ static void x86_machine_class_init(ObjectClass *oc, = void *data) x86_machine_set_bus_lock_ratelimit, NULL, = NULL); object_class_property_set_description(oc, X86_MACHINE_BUS_LOCK_RATELIM= IT, "Set the ratelimit for the bus locks acquired in VMs"); + + object_class_property_add(oc, "sgx-epc", "SgxEPC", + machine_get_sgx_epc, machine_set_sgx_epc, + NULL, NULL); + object_class_property_set_description(oc, "sgx-epc", + "SGX EPC device"); } =20 static const TypeInfo x86_machine_info =3D { diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 4d2e35a152..f2869437ab 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -12,6 +12,7 @@ #include "hw/acpi/acpi_dev_interface.h" #include "hw/hotplug.h" #include "qom/object.h" +#include "hw/i386/sgx-epc.h" =20 #define HPET_INTCAP "hpet-intcap" =20 @@ -49,6 +50,8 @@ typedef struct PCMachineState { =20 /* ACPI Memory hotplug IO base address */ hwaddr memhp_io_base; + + SGXEPCState sgx_epc; } PCMachineState; =20 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" @@ -198,6 +201,9 @@ extern const size_t pc_compat_6_1_len; extern GlobalProperty pc_compat_6_0[]; extern const size_t pc_compat_6_0_len; =20 +/* sgx-epc.c */ +void pc_machine_init_sgx_epc(PCMachineState *pcms); + extern GlobalProperty pc_compat_5_2[]; extern const size_t pc_compat_5_2_len; =20 diff --git a/include/hw/i386/sgx-epc.h b/include/hw/i386/sgx-epc.h index 5fd9ae2d0c..2b2490892b 100644 --- a/include/hw/i386/sgx-epc.h +++ b/include/hw/i386/sgx-epc.h @@ -41,4 +41,18 @@ typedef struct SGXEPCDevice { HostMemoryBackend *hostmem; } SGXEPCDevice; =20 +/* + * @base: address in guest physical address space where EPC regions start + * @mr: address space container for memory devices + */ +typedef struct SGXEPCState { + uint64_t base; + uint64_t size; + + MemoryRegion mr; + + struct SGXEPCDevice **sections; + int nr_sections; +} SGXEPCState; + #endif diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 6e9244a82c..23267a3674 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -62,6 +62,7 @@ struct X86MachineState { unsigned pci_irq_mask; unsigned apic_id_limit; uint16_t boot_cpus; + SgxEPCList *sgx_epc_list; =20 OnOffAuto smm; OnOffAuto acpi; diff --git a/qapi/machine.json b/qapi/machine.json index 157712f006..10d36da83f 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1194,6 +1194,32 @@ } } =20 +## +# @SgxEPC: +# +# Sgx EPC cmdline information +# +# @memdev: memory backend linked with device +# +# Since: 6.1 +## +{ 'struct': 'SgxEPC', + 'data': { 'memdev': 'str' } +} + +## +# @SgxEPCProperties: +# +# Properties for SgxEPC objects. +# +# @sgx-epc: sgx epc section properties. +# +# Since: 6.1 +## +{ 'struct': 'SgxEPCProperties', + 'data': { 'sgx-epc': ['SgxEPC'] } +} + ## # @MemoryDeviceInfo: # diff --git a/qemu-options.hx b/qemu-options.hx index 8f603cc7e6..ceca52818a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -126,8 +126,14 @@ SRST -m 512M ERST =20 -HXCOMM Deprecated by -machine -DEF("M", HAS_ARG, QEMU_OPTION_M, "", QEMU_ARCH_ALL) +DEF("M", HAS_ARG, QEMU_OPTION_M, + " sgx-epc.0.memdev=3Dmemid\n", + QEMU_ARCH_ALL) + +SRST +``sgx-epc.0.memdev=3D@var{memid}`` + Define an SGX EPC section. +ERST =20 DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, "-cpu cpu select CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096043210758.2425618814906; Wed, 8 Sep 2021 03:14:03 -0700 (PDT) Received: from localhost ([::1]:47940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuaf-00010O-0A for importer@patchew.org; Wed, 08 Sep 2021 06:14:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRn-0006Tf-Bg for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:51 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:46797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0002y1-9v for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:51 -0400 Received: by mail-wm1-x32b.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso1071323wmi.5 for ; Wed, 08 Sep 2021 03:04:46 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wJhic6JItqCcAPRwChb+m/vGC9bolwiHwgIkwbT7HhE=; b=UlFBtp/NEmK++7r6hxB5/CDKb0Bv1u+na8wn0gz5jVMXyNerRbBR6kt5pJC8zPKHaU n9AWBZA+JkQleIU6MFXL5TbaWI1oyL4acvJ2IoJRA1X+diJZpygx3KyOLPLEwk5aW+Cx sluSW/dpj9jqnp6bHfDuNZys74NfVAiaUFtqB+pPOwSbfZ+gGSOP/jzq++EabYREhXDy Q7V6BEjf/EfFiSBHIPXCFDLCRnb44chZQdVDt1ChCymxT1nmv502c8IXFjsgu+ln1+am 6H3226Y6cg4Tfhky97oyQ1oWSCK6Uqf17nLRb92doa8MJ9zlZSHNJTOGAeuHgEMKUAyB qnOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wJhic6JItqCcAPRwChb+m/vGC9bolwiHwgIkwbT7HhE=; b=iByK7GGz0K3aSGnRdrrD1nxkG6vgKD12u8JWnAQ58t13CKl+1imDnvMF8NpG/j7vRL LtyzDKtaZVYul3BjDQsHZrnXhxeNZdCwombPE0HuJTSnx1Z/QBbyDX3qgYzGwNMQHE+N eonfsepzZQi1qxL1IRIKkKGFeCx1v9CYR/ncbB5IJVosBsxOfa07yae9q/5I7kOKNKmc gBASQ0r3K2qdSnvdawT+oZx7FH6vrx0C6hpLY1FkGNVTyPrSeQnFnCN+jyLcP43QNyg9 UukqR5AvuDxcZnFpgNxrwaUcJepMgmnTaY1TSAT18Sa12GJjCRuUepJiWOJpveQmUACE qYRw== X-Gm-Message-State: AOAM531ywq9gf/gwsn1HAEeMnu0ZmqCbLNaoU9+e7GuMrC142pfts397 Yxp13LvNv4UwgsRLzZEyR2qgLeRTX5o= X-Google-Smtp-Source: ABdhPJzvFIR/YmTNZ9/EkrEAMA5oswvvW4M4wOFPqiMtuEtMPC6QQX50PEyBWk5ggxugKk3uW8EZ7A== X-Received: by 2002:a7b:c114:: with SMTP id w20mr2591380wmi.80.1631095486026; Wed, 08 Sep 2021 03:04:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 14/43] i386: Add primary SGX CPUID and MSR defines Date: Wed, 8 Sep 2021 12:03:57 +0200 Message-Id: <20210908100426.264356-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096045340100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Add CPUID defines for SGX and SGX Launch Control (LC), as well as defines for their associated FEATURE_CONTROL MSR bits. Define the Launch Enclave Public Key Hash MSRs (LE Hash MSRs), which exist when SGX LC is present (in CPUID), and are writable when SGX LC is enabled (in FEATURE_CONTROL). Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-7-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 4 ++-- target/i386/cpu.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6b029f1bdf..21d2a325ea 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -795,7 +795,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { [FEAT_7_0_EBX] =3D { .type =3D CPUID_FEATURE_WORD, .feat_names =3D { - "fsgsbase", "tsc-adjust", NULL, "bmi1", + "fsgsbase", "tsc-adjust", "sgx", "bmi1", "hle", "avx2", NULL, "smep", "bmi2", "erms", "invpcid", "rtm", NULL, NULL, "mpx", NULL, @@ -821,7 +821,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { "la57", NULL, NULL, NULL, NULL, NULL, "rdpid", NULL, "bus-lock-detect", "cldemote", NULL, "movdiri", - "movdir64b", NULL, NULL, "pks", + "movdir64b", NULL, "sgxlc", "pks", }, .cpuid =3D { .eax =3D 7, diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 71ae3141c3..a3fe44455d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -389,9 +389,17 @@ typedef enum X86Seg { #define MSR_IA32_PKRS 0x6e1 =20 #define FEATURE_CONTROL_LOCKED (1<<0) +#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1ULL << 1) #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2) +#define FEATURE_CONTROL_SGX_LC (1ULL << 17) +#define FEATURE_CONTROL_SGX (1ULL << 18) #define FEATURE_CONTROL_LMCE (1<<20) =20 +#define MSR_IA32_SGXLEPUBKEYHASH0 0x8c +#define MSR_IA32_SGXLEPUBKEYHASH1 0x8d +#define MSR_IA32_SGXLEPUBKEYHASH2 0x8e +#define MSR_IA32_SGXLEPUBKEYHASH3 0x8f + #define MSR_P6_PERFCTR0 0xc1 =20 #define MSR_IA32_SMBASE 0x9e @@ -718,6 +726,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; =20 /* Support RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE */ #define CPUID_7_0_EBX_FSGSBASE (1U << 0) +/* Support SGX */ +#define CPUID_7_0_EBX_SGX (1U << 2) /* 1st Group of Advanced Bit Manipulation Extensions */ #define CPUID_7_0_EBX_BMI1 (1U << 3) /* Hardware Lock Elision */ @@ -805,6 +815,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_7_0_ECX_MOVDIRI (1U << 27) /* Move 64 Bytes as Direct Store Instruction */ #define CPUID_7_0_ECX_MOVDIR64B (1U << 28) +/* Support SGX Launch Control */ +#define CPUID_7_0_ECX_SGX_LC (1U << 30) /* Protection Keys for Supervisor-mode Pages */ #define CPUID_7_0_ECX_PKS (1U << 31) =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096372074208.6421513463397; Wed, 8 Sep 2021 03:19:32 -0700 (PDT) Received: from localhost ([::1]:36772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNufy-00048W-WA for importer@patchew.org; Wed, 08 Sep 2021 06:19:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS0-0006uT-SU for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:08 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:42732) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0002yP-8L for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:04 -0400 Received: by mail-wm1-x332.google.com with SMTP id u19-20020a7bc053000000b002f8d045b2caso1086185wmc.1 for ; Wed, 08 Sep 2021 03:04:47 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=slJavCchRN6P9oEFDk77dniIx1JCzFVwonQK3t9I4XM=; b=kxdMOTuhtMOyBL+yHpLKxe2TRuxBWii7Abg/ukMrdIRXQTV15euKdYHAaawyUbVuYa HsZmdtjW7L1S40f09hz1VS7FTUUM5oDaWukHYP0nCnS0uVda/B09+tEnFSp3JeAofb7i ksDhIvT5QhHrJ/Bn6HKh4sxINj/vUKG/DaOAkCwI2dkc4W6UEEP+lrR7maH8ZLjerKO3 /DAupNQdYMOrzxFQCdNtxrRBNmo60Cdfm3GUiVslYW6fxC2EljXUrj3HY788C0Dtn8Xz DALN6Xd/I7NEodqUSzmi6R6GVZuRHUzmDoC6PX1S3vKWPQVgKwXY+8NGXtbccvc3WG/8 r4iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=slJavCchRN6P9oEFDk77dniIx1JCzFVwonQK3t9I4XM=; b=kjG3bBXVg46fsf9z+eflN5kV79PKkE8ph0077khdiXATipXDn94OcqjfW/cvE5LA9R AqvLpI+ZzAAxGMdS+RHS7hLmos7vQHjBAIHLFhdbGZB2q60a6YbxraG5VJjwr6pwmlp0 +ZXZ/mHFK+gZgWSKnAy/0qhozokaYKE7e+xY1NWDr476XF88n1AdBWmbSInzatI/45/N Y2jsfydNKsCqJNgKjJJGPNd8++Q+31y/jPfKOgFg3Fza/R3j3GAofydkkCKzUx2hhzkP Cn9zIN/RulYohb7RI2G9DPHxZ8yynNagQULCBBAO/MGBgoGPwOgeHYrJRHFLFLYC5Aai I08w== X-Gm-Message-State: AOAM530K3gqWUuny1Cj3DXKBcO8zJIpSqGzZT2oGuA1zc6X3bX76gp/a gHbp8SQCuN+okEGrlWWeene+3E5+3ng= X-Google-Smtp-Source: ABdhPJxyOO7GvlWuY9YMUXV8C1FCvS2InPkhHIpFqAp1hYM1zZ2G7PoTJg3f9/6pu/EmtC+lP/u5Aw== X-Received: by 2002:a05:600c:3502:: with SMTP id h2mr2760824wmq.182.1631095486723; Wed, 08 Sep 2021 03:04:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 15/43] i386: Add SGX CPUID leaf FEAT_SGX_12_0_EAX Date: Wed, 8 Sep 2021 12:03:58 +0200 Message-Id: <20210908100426.264356-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096374071100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson CPUID leaf 12_0_EAX is an Intel-defined feature bits leaf enumerating the CPU's SGX capabilities, e.g. supported SGX instruction sets. Currently there are four enumerated capabilities: - SGX1 instruction set, i.e. "base" SGX - SGX2 instruction set for dynamic EPC management - ENCLV instruction set for VMM oversubscription of EPC - ENCLS-C instruction set for thread safe variants of ENCLS Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-8-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 20 ++++++++++++++++++++ target/i386/cpu.h | 1 + 2 files changed, 21 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 21d2a325ea..2cd1487bae 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -654,6 +654,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendo= r1, /* missing: CPUID_XSAVE_XSAVEC, CPUID_XSAVE_XSAVES */ #define TCG_14_0_ECX_FEATURES 0 +#define TCG_SGX_12_0_EAX_FEATURES 0 =20 FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { [FEAT_1_EDX] =3D { @@ -1182,6 +1183,25 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D= { .tcg_features =3D TCG_14_0_ECX_FEATURES, }, =20 + [FEAT_SGX_12_0_EAX] =3D { + .type =3D CPUID_FEATURE_WORD, + .feat_names =3D { + "sgx1", "sgx2", NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .cpuid =3D { + .eax =3D 0x12, + .needs_ecx =3D true, .ecx =3D 0, + .reg =3D R_EAX, + }, + .tcg_features =3D TCG_SGX_12_0_EAX_FEATURES, + }, }; =20 typedef struct FeatureMask { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a3fe44455d..959f679077 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -578,6 +578,7 @@ typedef enum FeatureWord { FEAT_VMX_BASIC, FEAT_VMX_VMFUNC, FEAT_14_0_ECX, + FEAT_SGX_12_0_EAX, /* CPUID[EAX=3D0x12,ECX=3D0].EAX (SGX) */ FEATURE_WORDS, } FeatureWord; =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096228888298.4943358148589; Wed, 8 Sep 2021 03:17:08 -0700 (PDT) Received: from localhost ([::1]:56650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNudf-0006x3-SC for importer@patchew.org; Wed, 08 Sep 2021 06:17:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRo-0006W0-BY for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:52 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:39779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRk-0002yb-UD for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:52 -0400 Received: by mail-wr1-x42b.google.com with SMTP id z4so2395987wrr.6 for ; Wed, 08 Sep 2021 03:04:48 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9O/uSfcdC+cHG3lQWgJFiwzz7AV82zYSbtbYbZk849c=; b=nMR3blziJ6CiWqtEbLhvW8IzLXrNxjitbuyC8ww7wQZNQ6xN8xOrfsFhLoTmcYCey9 EjuG4dp2vqpTUwHBWP5YDLKGc7q8NXQC4A/O9RCiLasmtWneaWyf2n7/atGO/3IxkYKM RpNMP/WLWj+RPCx0Eww/AebXOcdfCz2ikTVcVq422xYzbpee79TpxpJIjQFb6MO+83GX ZhoIuAYF/LpWWWkVI3NjWEW/Fqupwt8RdUzPOZg2HN5NPKgv9JYw19wK+rVBq9sBBS6g Rc/Lix0HhAFvp6OHNp+YtndAgSh4NUCComvJej5uV84gc0YrG8fYjf4jRioGGRSh/C2U jHew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9O/uSfcdC+cHG3lQWgJFiwzz7AV82zYSbtbYbZk849c=; b=uCLERiLwgtypPbh+fk9DK9EU3pAyUmJlLUwOvmEpPGnQyRO48XST+sWDV9x4u3Il41 LDKNb7XhhYggXViypkfiakDaNStTNzGztPfujLEGFYTqEWu8S0WQxMbgMnuLmxmAdPPb Mkbrv3W94Q91EHcBx7ZIAs5WkoGZH54k7pg0o99GMkkVM/3XUYaHXIhy5pDBq2j3mrrP m8kweQfh6PtpvS90SMajez9c/OdNQ2dI+jvksLfuK7jaiCu4BZGcA12VSWaov0H7PyRU IorUaK//3nGs49FtuUCnXU+W+5x1Hr4c+xE1mr7f1RX94XT/vspcemj0jxyghQKtJOOL ogMg== X-Gm-Message-State: AOAM531qoT9yfiSJj5JGgaEluUsN2LNVx6JEvPDtSh0erf2CF2V58CDj PCRC9ouLWMoeIAi4p3nE7tc3M0YfKeI= X-Google-Smtp-Source: ABdhPJxLVbYcJNImx3q97cFgyHe+0iVSzRJFqINSu4xt9gyAz00OucelSFK//mB/9uBxNyWTB2VmiQ== X-Received: by 2002:a05:6000:160d:: with SMTP id u13mr3179003wrb.17.1631095487525; Wed, 08 Sep 2021 03:04:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 16/43] i386: Add SGX CPUID leaf FEAT_SGX_12_0_EBX Date: Wed, 8 Sep 2021 12:03:59 +0200 Message-Id: <20210908100426.264356-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096231159100003 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson CPUID leaf 12_0_EBX is an Intel-defined feature bits leaf enumerating the platform's SGX extended capabilities. Currently there is a single capabilitiy: - EXINFO: record information about #PFs and #GPs in the enclave's SSA Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-9-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 21 +++++++++++++++++++++ target/i386/cpu.h | 1 + 2 files changed, 22 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 2cd1487bae..c0d5c3c621 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -655,6 +655,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendo= r1, CPUID_XSAVE_XSAVEC, CPUID_XSAVE_XSAVES */ #define TCG_14_0_ECX_FEATURES 0 #define TCG_SGX_12_0_EAX_FEATURES 0 +#define TCG_SGX_12_0_EBX_FEATURES 0 =20 FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { [FEAT_1_EDX] =3D { @@ -1202,6 +1203,26 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D= { }, .tcg_features =3D TCG_SGX_12_0_EAX_FEATURES, }, + + [FEAT_SGX_12_0_EBX] =3D { + .type =3D CPUID_FEATURE_WORD, + .feat_names =3D { + "sgx-exinfo" , NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .cpuid =3D { + .eax =3D 0x12, + .needs_ecx =3D true, .ecx =3D 0, + .reg =3D R_EBX, + }, + .tcg_features =3D TCG_SGX_12_0_EBX_FEATURES, + }, }; =20 typedef struct FeatureMask { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 959f679077..cf52f70575 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -579,6 +579,7 @@ typedef enum FeatureWord { FEAT_VMX_VMFUNC, FEAT_14_0_ECX, FEAT_SGX_12_0_EAX, /* CPUID[EAX=3D0x12,ECX=3D0].EAX (SGX) */ + FEAT_SGX_12_0_EBX, /* CPUID[EAX=3D0x12,ECX=3D0].EBX (SGX MISCSELECT[3= 1:0]) */ FEATURE_WORDS, } FeatureWord; =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096354971142.76854735657002; Wed, 8 Sep 2021 03:19:14 -0700 (PDT) Received: from localhost ([::1]:35432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNufh-0003Ej-QM for importer@patchew.org; Wed, 08 Sep 2021 06:19:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRq-0006b8-El for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:54 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:34376) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRm-0002zZ-5p for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:53 -0400 Received: by mail-wm1-x32d.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so885949wmh.1 for ; Wed, 08 Sep 2021 03:04:49 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XRG6UldQ4FAnYMjiIBprwzK+XcImxqgucxt46qHrvz0=; b=cWhdSVTRS08Jy0S0mfUrrcVFEKw2S7K1OLS0oadrzzJvw5GDl8cG9v3f5xzYWN4H8M Q2zhCFeAEEoEu2PKNhVrcsMTNybNBvsNySLjZTZ70gqZjysaYsqnlSonhgCOAGEd/Zkc Ii5QOVb1ONrELIBTgSZnRHd1C5Jd1t1bXU7PJjJ2/eD4mLOxmbCi/DCkYcwTmKAhmIh4 pY36RgZrbVsUsmwK+o88WMOVjWZ4zvFKzq+wt5DGXa3EhuB7++aRfeuPNen2O53MYzjp BmNuYDHOlePIptW7ioDEImmqo1Vcx0CwW/77bQDHEzbhHlNZqhH4e1zJULSV6ORE8s6l gBbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=XRG6UldQ4FAnYMjiIBprwzK+XcImxqgucxt46qHrvz0=; b=BTsrf7vwkmBsTVehmSLDYagAEUSu0RW/GbjFY0VxMLNRx1gMFv8N4rL5m00YnJCte9 9adug9MzTIzyhG9ljPdMlBuNQdGPMiGfdk34mCHXyDHQunCjJs/19+Ax7fKiKic1t5pI TU3X2vwoFwOMOEGZnGfKwtvCLkEOa6/E5CiPLhwZCuuzyRbSA/Zpek5dmXQVefIfxLEM nznEN1ms6ikbXxCnQnrvzmCRzk6czePTQksFfGr+5z/pqHmsKih4DFvc79NVA8O5vx3C 9yLcedPgHYvL1AQ8WMV86zpmdJ6192z25K9b2dIulzHrgyh4CQl3kzGGZ/Y6lM+7k1fX QrVA== X-Gm-Message-State: AOAM533+F7W9CjCxNf/8UsMELCgCz8ymlPZ2O+3R8cbxbw7MlhkIhIln j2i/9Wm6CNq5r/rUo6BTVDxsIOH7YYI= X-Google-Smtp-Source: ABdhPJxi6rtKsdESfWaMR1dHbcNNDRHFjqu5SC5GNHa9KtmsYD26xoLS921pZbnUB1whqcRdCTx2tw== X-Received: by 2002:a05:600c:22d2:: with SMTP id 18mr2769471wmg.57.1631095488275; Wed, 08 Sep 2021 03:04:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 17/43] i386: Add SGX CPUID leaf FEAT_SGX_12_1_EAX Date: Wed, 8 Sep 2021 12:04:00 +0200 Message-Id: <20210908100426.264356-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096357067100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson CPUID leaf 12_1_EAX is an Intel-defined feature bits leaf enumerating the platform's SGX capabilities that may be utilized by an enclave, e.g. whether or not an enclave can gain access to the provision key. Currently there are six capabilities: - INIT: set when the enclave has has been initialized by EINIT. Cannot be set by software, i.e. forced to zero in CPUID. - DEBUG: permits a debugger to read/write into the enclave. - MODE64BIT: the enclave runs in 64-bit mode - PROVISIONKEY: grants has access to the provision key - EINITTOKENKEY: grants access to the EINIT token key, i.e. the enclave can generate EINIT tokens - KSS: Key Separation and Sharing enabled for the enclave. Note that the entirety of CPUID.0x12.0x1, i.e. all registers, enumerates the allowed ATTRIBUTES (128 bits), but only bits 31:0 are directly exposed to the user (via FEAT_12_1_EAX). Bits 63:32 are currently all reserved and bits 127:64 correspond to the allowed XSAVE Feature Request Mask, which is calculated based on other CPU features, e.g. XSAVE, MPX, AVX, etc... and is not exposed to the user. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-10-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 21 +++++++++++++++++++++ target/i386/cpu.h | 1 + 2 files changed, 22 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c0d5c3c621..e9ecbf59e5 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -656,6 +656,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendo= r1, #define TCG_14_0_ECX_FEATURES 0 #define TCG_SGX_12_0_EAX_FEATURES 0 #define TCG_SGX_12_0_EBX_FEATURES 0 +#define TCG_SGX_12_1_EAX_FEATURES 0 =20 FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { [FEAT_1_EDX] =3D { @@ -1223,6 +1224,26 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D= { }, .tcg_features =3D TCG_SGX_12_0_EBX_FEATURES, }, + + [FEAT_SGX_12_1_EAX] =3D { + .type =3D CPUID_FEATURE_WORD, + .feat_names =3D { + NULL, "sgx-debug", "sgx-mode64", NULL, + "sgx-provisionkey", "sgx-tokenkey", NULL, "sgx-kss", + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .cpuid =3D { + .eax =3D 0x12, + .needs_ecx =3D true, .ecx =3D 1, + .reg =3D R_EAX, + }, + .tcg_features =3D TCG_SGX_12_1_EAX_FEATURES, + }, }; =20 typedef struct FeatureMask { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index cf52f70575..e18cceb851 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -580,6 +580,7 @@ typedef enum FeatureWord { FEAT_14_0_ECX, FEAT_SGX_12_0_EAX, /* CPUID[EAX=3D0x12,ECX=3D0].EAX (SGX) */ FEAT_SGX_12_0_EBX, /* CPUID[EAX=3D0x12,ECX=3D0].EBX (SGX MISCSELECT[3= 1:0]) */ + FEAT_SGX_12_1_EAX, /* CPUID[EAX=3D0x12,ECX=3D1].EAX (SGX ATTRIBUTES[3= 1:0]) */ FEATURE_WORDS, } FeatureWord; =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096374101820.3318814093188; Wed, 8 Sep 2021 03:19:34 -0700 (PDT) Received: from localhost ([::1]:36982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNug1-0004Gu-2P for importer@patchew.org; Wed, 08 Sep 2021 06:19:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRr-0006cK-0y for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:55 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:39785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRm-00030t-AM for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:54 -0400 Received: by mail-wr1-x431.google.com with SMTP id z4so2396099wrr.6 for ; Wed, 08 Sep 2021 03:04:49 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7KsTDG3drOXvBLLkYlqfRd7XNSkXLpWqNjlUf+cUrs8=; b=m0I2r2Jtt1wT1V2HHRqBazUOzmjIb2WxtvUdfE3iQ/jer+I9OAMdBjZSLWfOCFUtbB XIohRqCacqORuEdya9rHWsw3i2aPqzjxiaWuNMTO0/QyK5tWPFfg2lnR1UvMV+iAqpD7 SRO2tqrgIBSBZ4/wjoKiLDfIMQJVEsynn1BdSRfAUjmDkXU32kTy8lG3yXETVm78Ksrn x5klKD4TCizaDNrPZnwbAEZBt2caL+4KW3SCzj5At+gNtNfWWJ5tJ/EH0rkKOU/iBMud 1GHJrw09P3dsvY4DpDBbrIet5cIrahfrhNzcU2cT4c/ZlMY0xzuluNdA+SR0izvuA3ZL I6fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=7KsTDG3drOXvBLLkYlqfRd7XNSkXLpWqNjlUf+cUrs8=; b=x3bgeSYi1QeAqVSUYd82KW5dp7kOi4ckI9Njw2u8kQUp9Qcp6uxaK5z842eKoNfg0h RYeRvGysa9A1HvCydQPv95Xm3GsFkKbjTGuB9c3sbkEUY0ENXuiLvjEqwQDShNnNq9zu BOESnATctJLF1Dd2PkPvRi9Rjy7GZINq03Jwt7izOkVNKWoAc5OeIZRAcdSSYc0/VaKj slxfTyHJ37npu2BsRYD30ckoPmlh7B0ZlB/mo97c7n54/Knjb9+/+V9C2+/39n6/YTsc ECFqroKO6HQ3rUJxul7if261xCcvU/rPaLNKHmUcxI4Ob6/aL41y4DQc94YGF3+yubuc kWlg== X-Gm-Message-State: AOAM531OBp8b4iP/4DMExAKjo1bjCtt/YHzfusJUIFW/8m72WGT6203r ix2BoO12Jbw2nu1i1dz67I2k+F6eTyQ= X-Google-Smtp-Source: ABdhPJzkWQH2GoJBg5+soPgPhuO3EwLs4BrAQM4qKxGTkN0F1uHeOKyfWyStSN7xkVseCWaNO2KeHg== X-Received: by 2002:a5d:438f:: with SMTP id i15mr2999199wrq.361.1631095488988; Wed, 08 Sep 2021 03:04:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 18/43] i386: Add get/set/migrate support for SGX_LEPUBKEYHASH MSRs Date: Wed, 8 Sep 2021 12:04:01 +0200 Message-Id: <20210908100426.264356-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Kai Huang , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096376244100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson On real hardware, on systems that supports SGX Launch Control, those MSRs are initialized to digest of Intel's signing key; on systems that don't support SGX Launch Control, those MSRs are not available but hardware always uses digest of Intel's signing key in EINIT. KVM advertises SGX LC via CPUID if and only if the MSRs are writable. Unconditionally initialize those MSRs to digest of Intel's signing key when CPU is realized and reset to reflect the fact. This avoids potential bug in case kvm_arch_put_registers() is called before kvm_arch_get_registers() is called, in which case guest's virtual SGX_LEPUBKEYHASH MSRs will be set to 0, although KVM initializes those to digest of Intel's signing key by default, since KVM allows those MSRs to be updated by Qemu to support live migration. Save/restore the SGX Launch Enclave Public Key Hash MSRs if SGX Launch Control (LC) is exposed to the guest. Likewise, migrate the MSRs if they are writable by the guest. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-11-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 17 ++++++++++++++++- target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 22 ++++++++++++++++++++++ target/i386/machine.c | 20 ++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e9ecbf59e5..59cb2c2d03 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5700,6 +5700,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } } =20 +#ifndef CONFIG_USER_ONLY +static void x86_cpu_set_sgxlepubkeyhash(CPUX86State *env) +{ + env->msr_ia32_sgxlepubkeyhash[0] =3D 0xa6053e051270b7acULL; + env->msr_ia32_sgxlepubkeyhash[1] =3D 0x6cfbe8ba8b3b413dULL; + env->msr_ia32_sgxlepubkeyhash[2] =3D 0xc4916d99f2b3735dULL; + env->msr_ia32_sgxlepubkeyhash[3] =3D 0xd4f8c05909f9bb3bULL; +} +#endif + static void x86_cpu_reset(DeviceState *dev) { CPUState *s =3D CPU(dev); @@ -5832,6 +5842,8 @@ static void x86_cpu_reset(DeviceState *dev) if (kvm_enabled()) { kvm_arch_reset_vcpu(cpu); } + + x86_cpu_set_sgxlepubkeyhash(env); #endif } =20 @@ -6214,6 +6226,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) & CPUID_EXT2_AMD_ALIASES); } =20 +#ifndef CONFIG_USER_ONLY + x86_cpu_set_sgxlepubkeyhash(env); +#endif + /* * note: the call to the framework needs to happen after feature expan= sion, * but before the checks/modifications to ucode_rev, mwait, phys_bits. @@ -6901,7 +6917,6 @@ static const TypeInfo x86_cpu_type_info =3D { .class_init =3D x86_cpu_common_class_init, }; =20 - /* "base" CPU model, used by query-cpu-model-expansion */ static void x86_cpu_base_class_init(ObjectClass *oc, void *data) { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e18cceb851..07daf1d811 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1516,6 +1516,7 @@ typedef struct CPUX86State { uint64_t mcg_status; uint64_t msr_ia32_misc_enable; uint64_t msr_ia32_feature_control; + uint64_t msr_ia32_sgxlepubkeyhash[4]; =20 uint64_t msr_fixed_ctr_ctrl; uint64_t msr_global_ctrl; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 500d2e0e68..11551648f9 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3107,6 +3107,17 @@ static int kvm_put_msrs(X86CPU *cpu, int level) } } =20 + if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_SGX_LC) { + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH0, + env->msr_ia32_sgxlepubkeyhash[0]); + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH1, + env->msr_ia32_sgxlepubkeyhash[1]); + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH2, + env->msr_ia32_sgxlepubkeyhash[2]); + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH3, + env->msr_ia32_sgxlepubkeyhash[3]); + } + /* Note: MSR_IA32_FEATURE_CONTROL is written separately, see * kvm_put_msr_feature_control. */ } @@ -3446,6 +3457,13 @@ static int kvm_get_msrs(X86CPU *cpu) } } =20 + if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_SGX_LC) { + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH0, 0); + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH1, 0); + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH2, 0); + kvm_msr_entry_add(cpu, MSR_IA32_SGXLEPUBKEYHASH3, 0); + } + ret =3D kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, cpu->kvm_msr_buf); if (ret < 0) { return ret; @@ -3735,6 +3753,10 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: env->msr_rtit_addrs[index - MSR_IA32_RTIT_ADDR0_A] =3D msrs[i]= .data; break; + case MSR_IA32_SGXLEPUBKEYHASH0 ... MSR_IA32_SGXLEPUBKEYHASH3: + env->msr_ia32_sgxlepubkeyhash[index - MSR_IA32_SGXLEPUBKEYHASH= 0] =3D + msrs[i].data; + break; } } =20 diff --git a/target/i386/machine.c b/target/i386/machine.c index b0943118d1..4367931623 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1415,6 +1415,25 @@ static const VMStateDescription vmstate_msr_tsx_ctrl= =3D { } }; =20 +static bool intel_sgx_msrs_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + CPUX86State *env =3D &cpu->env; + + return !!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_SGX_LC); +} + +static const VMStateDescription vmstate_msr_intel_sgx =3D { + .name =3D "cpu/intel_sgx", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D intel_sgx_msrs_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINT64_ARRAY(env.msr_ia32_sgxlepubkeyhash, X86CPU, 4), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_x86_cpu =3D { .name =3D "cpu", .version_id =3D 12, @@ -1551,6 +1570,7 @@ const VMStateDescription vmstate_x86_cpu =3D { &vmstate_nested_state, #endif &vmstate_msr_tsx_ctrl, + &vmstate_msr_intel_sgx, NULL } }; --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096811939570.9609150157078; Wed, 8 Sep 2021 03:26:51 -0700 (PDT) Received: from localhost ([::1]:53582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNun4-00073h-LE for importer@patchew.org; Wed, 08 Sep 2021 06:26:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRx-0006qn-8B for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:01 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:35440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRm-00031O-S8 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:00 -0400 Received: by mail-wm1-x334.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so1148208wmi.0 for ; Wed, 08 Sep 2021 03:04:50 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ijvhFm3qkGCih7E+IGi13wOWIV5MP5pvlk/20m1FbI=; b=k2fQcQ+OxCunH4x6hU3mXP7H5jcpKIsRbfD9yzifUHeNdEaS3JchMk0H0naf7bRghN UNc/DTAHH1lKHwCaYY6EP3l9TMl+fWJ6zUeWwn/1rky6FmXVG594v6er9ZTbN6O/P1Gq QiTtWsGcoJ/NMYoPrbpCMRhV3hcm70t8LR73gQ0SDf3+AJ99PnWFJDb8iTGhcp7IgyhV J2jznW4hA2v1jrrrRkLZm0/XVCSTQb+YVyzmJ0AidouBkXX51nR93+DisOOPUMs0WfEG jBfoGdPi/Mx3SZ0Iiw9c/8zRMEvnoSAz/yeP5VLyI31e7F5Mfjwmq30Nx2O2xWiYEcLC 3K9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2ijvhFm3qkGCih7E+IGi13wOWIV5MP5pvlk/20m1FbI=; b=DMO7go8yEztkQe5fiKqiCZieFg6VmBNyGDgIHZtcvD2UUMQObeCywar40QdFUppgzB //H/WRcaghcxXt3PUoir0SZ9BE5RI0SAUOibYvZ4AjydWXHyuL3CzroV+EQY1oEVLk1y 5YyyNqle08XH1KNF9A4g1SoGDI1H7KBNmep+M+PnaEHV6khI4ci0XtTNbaQpa5BBpG32 D9tx1QPr7sbV84eV9+nn5jTmnZkCnHKMG6vJrswE6QbwKwRjQXo3u3X6zjQiFJKND1cn EceL+32QykdC//O4rx6+3Q5dAc3ZfBgvpbOKGeZ/YrbE4I1atHdcdVl74qbEInU17k9T lRhQ== X-Gm-Message-State: AOAM530wRIntGvCyTtZdkd2W3xGv73+uScC9eKA9n1c5wS6bTZwTERE2 x+wXBYQLGjStlNirmxoTwNFqhQydPS0= X-Google-Smtp-Source: ABdhPJwG5BWXMeptXvqr0jd7cB7ai4AnLUxy1JB1Nadn7VanfouBO5ASlmPaC/HCo+Y7sbsr+p+lxA== X-Received: by 2002:a7b:c408:: with SMTP id k8mr2603296wmi.184.1631095489597; Wed, 08 Sep 2021 03:04:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 19/43] fw_cfg: add etc/msr_feature_control Date: Wed, 8 Sep 2021 12:04:02 +0200 Message-Id: <20210908100426.264356-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096813243100001 Content-Type: text/plain; charset="utf-8" The file already existed, but nobody had noticed the warning until now. Add it at the bottom, since that is where unknown files go in legacy mode. Fixes: 217f1b4a721 ("target-i386: Publish advised value of MSR_IA32_FEATURE= _CONTROL via fw_cfg") Signed-off-by: Paolo Bonzini --- hw/nvram/fw_cfg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 9b8dcca4ea..c06b30de11 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -878,6 +878,7 @@ static struct { { "etc/tpm/log", 150 }, { "etc/acpi/rsdp", 160 }, { "bootorder", 170 }, + { "etc/msr_feature_control", 180 }, =20 #define FW_CFG_ORDER_OVERRIDE_LAST 200 }; --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096479260645.0000903416278; Wed, 8 Sep 2021 03:21:19 -0700 (PDT) Received: from localhost ([::1]:43816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuhi-0000St-4s for importer@patchew.org; Wed, 08 Sep 2021 06:21:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRq-0006ba-LW for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:54 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:56212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRn-00031m-IZ for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:54 -0400 Received: by mail-wm1-x32f.google.com with SMTP id g74so1261060wmg.5 for ; Wed, 08 Sep 2021 03:04:51 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5r01uT4tR8NNg495M2MrgoZZ94BYOI+Ryf0JV3pSQkM=; b=c2LM3WhifWeQK8XH4IusxN0HGSfG2y4ZN/419hsiIgRCydrCMUb1FHkthu+ZteWLGa pDS4OCi3XUApQCdrxJ/AbtHOZQv7FC3tVflO0JN82lviIBN/XLIa2Aw8gKFzrYjvjaE6 NM7S5yFdKJLWyqoOnYREZzX0V4X3h6oO9lyTJbEZrpO5Nt0J3XtjxapIfo/YBoSGsGVV 6WWmomW9lysyTBnnQouUA4iyszdsbH9kRG2r8d8+Cq/zcLGkCUk54ZrA7hId+DtCBtlh 8jH8xNP/f6/ab7pY6AfTbKUWCJVwo/TWkNmxtvS6KTEd2xYqCmP0szQy6sp12e4X7wf4 EuLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5r01uT4tR8NNg495M2MrgoZZ94BYOI+Ryf0JV3pSQkM=; b=OJF+E0Con73tqhUryP837E2SrA9lZRcJPVrn3Safya8+IWl7WHj6FZ8GRfqRSlnmoi gVYG525lb3zqVLWrSRcivT9yO3awY/opZ8BpFU+fl6dmYz9RUH7VjMKHEKdP7+zdXHRy 5yJ983SXUU/S6Ccc+S3tLdXv4LlRCoayqgT/sF3FmzwvGSRCPfb4zARUvwVDdGydb88g 16kpzLoXpc8pPwsI/Mxiby1PVu4EAnIsaZ0NnoJzycbnjEsJveR5rRCea7twEGEY3OJL T5Psr/UPnPEe9yQYTz1QdQljyr0xfmQhXPmrYN0sRVjEcmozv/pwlZxE87FVIPiVsow2 QdYw== X-Gm-Message-State: AOAM531Q0/UAmo3lvv1J/NjXn7+T+86Ms2LrCWGYnx0cES88HlRHquPz +zgBRkrLDO9jmO2q1O97g2BxBLX7G6Y= X-Google-Smtp-Source: ABdhPJz97kwvfiKzbRIm19LtcW5rWj6/UJzu8JxukYDo35xNygrEhzvvGwwGabd+X4nOoGdpTlRC8w== X-Received: by 2002:a05:600c:3209:: with SMTP id r9mr2713271wmp.106.1631095490267; Wed, 08 Sep 2021 03:04:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 20/43] i386: Add feature control MSR dependency when SGX is enabled Date: Wed, 8 Sep 2021 12:04:03 +0200 Message-Id: <20210908100426.264356-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096480326100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson SGX adds multiple flags to FEATURE_CONTROL to enable SGX and Flexible Launch Control. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-12-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 11551648f9..6dc40161e0 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1877,6 +1877,11 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx & CPUID_EXT_SMX); } =20 + c =3D cpuid_find_entry(&cpuid_data.cpuid, 7, 0); + if (c && (c->ebx & CPUID_7_0_EBX_SGX)) { + has_msr_feature_control =3D true; + } + if (env->mcg_cap & MCG_LMCE_P) { has_msr_mcg_ext_ctl =3D has_msr_feature_control =3D true; } --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096536434413.7173028465028; Wed, 8 Sep 2021 03:22:16 -0700 (PDT) Received: from localhost ([::1]:45186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuid-0001N6-Bs for importer@patchew.org; Wed, 08 Sep 2021 06:22:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRs-0006f3-DX for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:56 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:51819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRo-00031z-DW for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:56 -0400 Received: by mail-wm1-x32a.google.com with SMTP id y132so1292119wmc.1 for ; Wed, 08 Sep 2021 03:04:51 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LC5VH5NI8pKhGNYk7uPvZs6fVdmsLzpsFOKaHgxPcHE=; b=Oq/zZoGyCtR+6Y9I+DDerY2xBCQ7dnVqDcqBnXCFzCwJ3imFp7rb0vMt/FNnpTHD6k pXMG/quNRWac6UprtWWXtXBSL/YQkZdVTLU2+nQVm+NXPaJ/PaWv04HaZOzt5qUp6ZC7 630MEkMCY6EfIQumQhL/ni24xilfm19SJMIb2fvdkra7wdur7yoJdUiTJBbDcsAmiT3r wrb2ibk+l25P6uIG7NF0EVcqqE+GSA8W6j4MHnKiy+2vUKIh/hxBofVKDYMmwF0vyEwp KYNgKDGPPHd6AfcrJwHZf9p70pidlT8m/lRf65qJ3Lz9wEN1JhccFj+MKGDL7pr1pX+W Fy2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=LC5VH5NI8pKhGNYk7uPvZs6fVdmsLzpsFOKaHgxPcHE=; b=Lyg4OgTRQ2jyxwePcqQG2wFOU6zs2qLZEifyGwqWa50SCG+gM1jEBlypLlx3M+/LT+ m7SCp4MQmvwtwE0mGTu8aU3kB+sL+yfjuHVUnmpwCr2EL/HHUn5yKd7OmtR5F4I1noe8 pdQsY5YxFS63AfrHZqgemIlcY/fia27J7Jv8U0WVEotVxZC1Gu0Cq2T4Oa207vdpJYlG jufkKRiA6TVH9eV2D/hRnz2mwIyflj9SCBwz2GMFfPwUwBogeo1XEg/sWWqKC4jqVxMs 8AB6gv5Ur80E/cOtyNGtzdeOt3yqKCkReWklVHLC1DuJTDWrWeK3+Z0LyVn74gZXjOFC X25w== X-Gm-Message-State: AOAM530tn8mqW1AA4zOSG1PsdbznzpaGVKQ+us8Am4ofre9a8Wi9mhJ3 QjFD6p+V7wugQpfq4zNIiu1TjQhUmAw= X-Google-Smtp-Source: ABdhPJxKIB1PUhDGyqHlddMqxlUUrd+13ncwtkQgcEsGjmvLDZ09AgYfDGy05Nw9mQFJDRED5l/nfw== X-Received: by 2002:a1c:e91a:: with SMTP id q26mr2028896wmc.128.1631095490996; Wed, 08 Sep 2021 03:04:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 21/43] i386: Update SGX CPUID info according to hardware/KVM/user input Date: Wed, 8 Sep 2021 12:04:04 +0200 Message-Id: <20210908100426.264356-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096537071100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Expose SGX to the guest if and only if KVM is enabled and supports virtualization of SGX. While the majority of ENCLS can be emulated to some degree, because SGX uses a hardware-based root of trust, the attestation aspects of SGX cannot be emulated in software, i.e. ultimately emulation will fail as software cannot generate a valid quote/report. The complexity of partially emulating SGX in Qemu far outweighs the value added, e.g. an SGX specific simulator for userspace applications can emulate SGX for development and testing purposes. Note, access to the PROVISIONKEY is not yet advertised to the guest as KVM blocks access to the PROVISIONKEY by default and requires userspace to provide additional credentials (via ioctl()) to expose PROVISIONKEY. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong v3-->v4: - Replaced g_malloc0() with directly .... Message-Id: <20210719112136.57018-13-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/sgx.c | 17 +++++++++ include/hw/i386/sgx-epc.h | 2 + target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c index e77deb0b00..5f988c6368 100644 --- a/hw/i386/sgx.c +++ b/hw/i386/sgx.c @@ -18,6 +18,23 @@ #include "qapi/error.h" #include "exec/address-spaces.h" =20 +int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) +{ + PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); + SGXEPCDevice *epc; + + if (pcms->sgx_epc.size =3D=3D 0 || pcms->sgx_epc.nr_sections <=3D sect= ion_nr) { + return 1; + } + + epc =3D pcms->sgx_epc.sections[section_nr]; + + *addr =3D epc->addr; + *size =3D memory_device_get_region_size(MEMORY_DEVICE(epc), &error_fat= al); + + return 0; +} + static int sgx_epc_set_property(void *opaque, const char *name, const char *value, Error **errp) { diff --git a/include/hw/i386/sgx-epc.h b/include/hw/i386/sgx-epc.h index 2b2490892b..f85fd2a4ca 100644 --- a/include/hw/i386/sgx-epc.h +++ b/include/hw/i386/sgx-epc.h @@ -55,4 +55,6 @@ typedef struct SGXEPCState { int nr_sections; } SGXEPCState; =20 +int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size); + #endif diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 59cb2c2d03..38cf507199 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -36,6 +36,7 @@ #ifndef CONFIG_USER_ONLY #include "exec/address-spaces.h" #include "hw/boards.h" +#include "hw/i386/sgx-epc.h" #endif =20 #include "disas/capstone.h" @@ -5334,6 +5335,25 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ecx |=3D CPUID_7_0_ECX_OSPKE; } *edx =3D env->features[FEAT_7_0_EDX]; /* Feature flags */ + + /* + * SGX cannot be emulated in software. If hardware does not + * support enabling SGX and/or SGX flexible launch control, + * then we need to update the VM's CPUID values accordingly. + */ + if ((*ebx & CPUID_7_0_EBX_SGX) && + (!kvm_enabled() || + !(kvm_arch_get_supported_cpuid(cs->kvm_state, 0x7, 0, R_E= BX) & + CPUID_7_0_EBX_SGX))) { + *ebx &=3D ~CPUID_7_0_EBX_SGX; + } + + if ((*ecx & CPUID_7_0_ECX_SGX_LC) && + (!(*ebx & CPUID_7_0_EBX_SGX) || !kvm_enabled() || + !(kvm_arch_get_supported_cpuid(cs->kvm_state, 0x7, 0, R_E= CX) & + CPUID_7_0_ECX_SGX_LC))) { + *ecx &=3D ~CPUID_7_0_ECX_SGX_LC; + } } else if (count =3D=3D 1) { *eax =3D env->features[FEAT_7_1_EAX]; *ebx =3D 0; @@ -5469,6 +5489,63 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, } break; } + case 0x12: +#ifndef CONFIG_USER_ONLY + if (!kvm_enabled() || + !(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SGX)) { + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + break; + } + + /* + * SGX sub-leafs CPUID.0x12.{0x2..N} enumerate EPC sections. Retr= ieve + * the EPC properties, e.g. confidentiality and integrity, from the + * host's first EPC section, i.e. assume there is one EPC section = or + * that all EPC sections have the same security properties. + */ + if (count > 1) { + uint64_t epc_addr, epc_size; + + if (sgx_epc_get_section(count - 2, &epc_addr, &epc_size)) { + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + break; + } + host_cpuid(index, 2, eax, ebx, ecx, edx); + *eax =3D (uint32_t)(epc_addr & 0xfffff000) | 0x1; + *ebx =3D (uint32_t)(epc_addr >> 32); + *ecx =3D (uint32_t)(epc_size & 0xfffff000) | (*ecx & 0xf); + *edx =3D (uint32_t)(epc_size >> 32); + break; + } + + /* + * SGX sub-leafs CPUID.0x12.{0x0,0x1} are heavily dependent on har= dware + * and KVM, i.e. QEMU cannot emulate features to override what KVM + * supports. Features can be further restricted by userspace, but= not + * made more permissive. + */ + *eax =3D kvm_arch_get_supported_cpuid(cs->kvm_state, 0x12, count, = R_EAX); + *ebx =3D kvm_arch_get_supported_cpuid(cs->kvm_state, 0x12, count, = R_EBX); + *ecx =3D kvm_arch_get_supported_cpuid(cs->kvm_state, 0x12, count, = R_ECX); + *edx =3D kvm_arch_get_supported_cpuid(cs->kvm_state, 0x12, count, = R_EDX); + + if (count =3D=3D 0) { + *eax &=3D env->features[FEAT_SGX_12_0_EAX]; + *ebx &=3D env->features[FEAT_SGX_12_0_EBX]; + } else { + *eax &=3D env->features[FEAT_SGX_12_1_EAX]; + *ebx &=3D 0; /* ebx reserve */ + *ecx &=3D env->features[FEAT_XSAVE_COMP_LO]; + *edx &=3D env->features[FEAT_XSAVE_COMP_HI]; + + /* FP and SSE are always allowed regardless of XSAVE/XCR0. */ + *ecx |=3D XSTATE_FP_MASK | XSTATE_SSE_MASK; + + /* Access to PROVISIONKEY requires additional credentials. */ + *eax &=3D ~(1U << 4); + } +#endif + break; case 0x14: { /* Intel Processor Trace Enumeration */ *eax =3D 0; --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310968265061021.3337399241711; Wed, 8 Sep 2021 03:27:06 -0700 (PDT) Received: from localhost ([::1]:54152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNunJ-0007Y3-GA for importer@patchew.org; Wed, 08 Sep 2021 06:27:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRt-0006hw-Bf for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:57 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:55236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRp-00032w-1X for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:57 -0400 Received: by mail-wm1-x32d.google.com with SMTP id s24so1271200wmh.4 for ; Wed, 08 Sep 2021 03:04:52 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+55luvDgxLUHmSWJWmBqLuALhR/szmakMsXeiwCOEK4=; b=X+KEV0kvOrLCeLTdFnE0vVfyyHPpyYW8R0P0mbP1bd/6e1Akk3Tk+lfuNM3fIOX/zg GASZ7hcGuSrKCoTdY4f9Mq/HHAJTnl3HZ69jaqdhQ+rk/1bARTqCY8vhbrO4dwPWH6qH 56d0ljgM0Tf/qwsaEzZgkIU914xl2xw9dBHGXoiCSatdsO2GpRCfVOBaETWlZ/sBDd7p J3usQzl6Y0ZAE17y/C/N/oUrYUe7MCmEy/YttjZla4hqzy/iTTPWJ5CfaK8qfbgEoSC+ I4pC3R9kTZSnyesWE2/UxXDEaDI0prBe3s0k/IEAiur7t4wqSKhhczsXl6AFKk2Ew8Ie sTug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+55luvDgxLUHmSWJWmBqLuALhR/szmakMsXeiwCOEK4=; b=N2Cto6B8ZbvyD6S4SdGLlZLwK37ROGx3iD3rZncn5xJMOsZSDnUOJ4IsD8bYijt0po Zs5aX2lc/K0Mkc2kaBookGInqmhfuZQTgV3CeOO5wP16XN+GvY1+PlRRarDK7RBPwutt o9Xp7Li7kVwoK4Ehwx7F8b/U7xtS8OE/JqY0Q2wqrsa3Di4Yd2i8GL626Y45m2zZcZZG etq5SfaEDpnRMA/QSUgkMWFDa/fCk1BGsVp4cypjYqmapOom6nGkkb64evsfhqUgAEMU W49wUrFXo73OHKpfWQDmYvlaS1iTlRnE+1OyqINq1b6K4WC1sEzqK9l+Q2Zha3IlVsT0 jEeg== X-Gm-Message-State: AOAM530tBLFM83Tge8y0RlXQ6aZw1WbLwXILcQRkcunJaPkjGrQKk6Bz Iux9FuzSjgwrJGABx/zLZnzT/ZebOaI= X-Google-Smtp-Source: ABdhPJym5/dTr8fFtLtxnoH02g24efqYFaC3xqCBCzOExQADQB1LUQVw0nXj3ZEnpD07ACNsF+5KMA== X-Received: by 2002:a1c:c913:: with SMTP id f19mr2637897wmb.86.1631095491678; Wed, 08 Sep 2021 03:04:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 22/43] i386: kvm: Add support for exposing PROVISIONKEY to guest Date: Wed, 8 Sep 2021 12:04:05 +0200 Message-Id: <20210908100426.264356-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096828130100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson If the guest want to fully use SGX, the guest needs to be able to access provisioning key. Add a new KVM_CAP_SGX_ATTRIBUTE to KVM to support provisioning key to KVM guests. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-14-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 5 ++++- target/i386/kvm/kvm.c | 29 +++++++++++++++++++++++++++++ target/i386/kvm/kvm_i386.h | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 38cf507199..3b1f9cbdf6 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5542,7 +5542,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ecx |=3D XSTATE_FP_MASK | XSTATE_SSE_MASK; =20 /* Access to PROVISIONKEY requires additional credentials. */ - *eax &=3D ~(1U << 4); + if ((*eax & (1U << 4)) && + !kvm_enable_sgx_provisioning(cs->kvm_state)) { + *eax &=3D ~(1U << 4); + } } #endif break; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 6dc40161e0..488926a95f 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4644,6 +4644,35 @@ void kvm_arch_update_guest_debug(CPUState *cpu, stru= ct kvm_guest_debug *dbg) } } =20 +static bool has_sgx_provisioning; + +static bool __kvm_enable_sgx_provisioning(KVMState *s) +{ + int fd, ret; + + if (!kvm_vm_check_extension(s, KVM_CAP_SGX_ATTRIBUTE)) { + return false; + } + + fd =3D qemu_open_old("/dev/sgx_provision", O_RDONLY); + if (fd < 0) { + return false; + } + + ret =3D kvm_vm_enable_cap(s, KVM_CAP_SGX_ATTRIBUTE, 0, fd); + if (ret) { + error_report("Could not enable SGX PROVISIONKEY: %s", strerror(-re= t)); + exit(1); + } + close(fd); + return true; +} + +bool kvm_enable_sgx_provisioning(KVMState *s) +{ + return MEMORIZE(__kvm_enable_sgx_provisioning(s), has_sgx_provisioning= ); +} + static bool host_supports_vmx(void) { uint32_t ecx, unused; diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 54667b35f0..a978509d50 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -51,4 +51,6 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp= ); =20 uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address); =20 +bool kvm_enable_sgx_provisioning(KVMState *s); + #endif --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095903917679.6565428284242; Wed, 8 Sep 2021 03:11:43 -0700 (PDT) Received: from localhost ([::1]:39698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuYQ-0003xH-Ob for importer@patchew.org; Wed, 08 Sep 2021 06:11:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRv-0006mo-OS for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:59 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:56218) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRq-00033m-Sg for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:59 -0400 Received: by mail-wm1-x335.google.com with SMTP id g74so1261128wmg.5 for ; Wed, 08 Sep 2021 03:04:53 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KOb4IPvQ1urvg2WoCHadP1b4B/KHW5IQqVRTE+ZK8/Y=; b=Tepe+3ZBAMhBj/Ivrpe9PNMt1xQBNiAU4R9U/ImCr9henBC3EeHgRs36rjwVvSinU8 Bi0+n2wz2ntEuCeT1WKDe1ftty0SiIORJ6Un6F8rjaBb9a0eTrpXNo5N4/A75Xffu4b2 0FouJ/dG2V4mo90VL6iff9QA8BUS0u048vf9njK4q272jbjsP07UxICjIq9ah7YXJcCZ kBZkMtNFliYNUCbFw6Naa0x8xIIguBsI2gund5EZJ7Ty8B6suAon8IDF97m/j3Uz0zqa xZSnl7XEYm5h+XWGVQv0gcCOWt55dF//ZgNYxsDM9Uea8h8Gf1E6I2bqYb+L9FPPqhWU 4xzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=KOb4IPvQ1urvg2WoCHadP1b4B/KHW5IQqVRTE+ZK8/Y=; b=pXT+zRQB9yzI1TpX7xXJYwhQ0ouHLWoFpI2hF1wFwQLnD/1+Rab0wvSnX3RNTH+Kqb fvhEbzaxNerKVmuEHB/Tl16wJucmB9maavlRpXuP1/6hq/UMuw2cpKWHsdzFykagSeoo MrmcXQ4XpS9LgV/yt4H+jTnYmapFTsV9dxVFFWtbK2Gok4xXgAFY+pbMFKHGOz5BnbSH gxrjVLz0yZ/V74dGRqI1hi0iamoOlWeXNDFNpAsQMH1ykuRy3U49IdmL+BmncMUrRBoj SA96FH/1nwqkjmn8OqokrI9hXzLbWdF6AQgF63dgc5IcLPnHc/C0WokXUGliA8LmtmE+ TVnQ== X-Gm-Message-State: AOAM533xohh7lcJsLpaa9wfBE4+T9BlYMyw1b1wo7lN9ofis6YvDBqkz WvuwqdMiYLfk70chUAJTR3VfNEoTJ14= X-Google-Smtp-Source: ABdhPJy1EjUuOIXj8VTU/shjSDvxTfAtS13+w+Fcx6koDzbDds/qbfBiEshUUpq+ge6AxpsaBVGZAA== X-Received: by 2002:a05:600c:2f90:: with SMTP id t16mr2674286wmn.136.1631095492394; Wed, 08 Sep 2021 03:04:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 23/43] i386: Propagate SGX CPUID sub-leafs to KVM Date: Wed, 8 Sep 2021 12:04:06 +0200 Message-Id: <20210908100426.264356-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x335.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095904641100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson The SGX sub-leafs are enumerated at CPUID 0x12. Indices 0 and 1 are always present when SGX is supported, and enumerate SGX features and capabilities. Indices >=3D2 are directly correlated with the platform's EPC sections. Because the number of EPC sections is dynamic and user defined, the number of SGX sub-leafs is "NULL" terminated. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-15-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 488926a95f..f6bbf33bc1 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1703,6 +1703,25 @@ int kvm_arch_init_vcpu(CPUState *cs) } break; case 0x7: + case 0x12: + for (j =3D 0; ; j++) { + c->function =3D i; + c->flags =3D KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + c->index =3D j; + cpu_x86_cpuid(env, i, j, &c->eax, &c->ebx, &c->ecx, &c->ed= x); + + if (j > 1 && (c->eax & 0xf) !=3D 1) { + break; + } + + if (cpuid_i =3D=3D KVM_MAX_CPUID_ENTRIES) { + fprintf(stderr, "cpuid_data is full, no space for " + "cpuid(eax:0x12,ecx:0x%x)\n", j); + abort(); + } + c =3D &cpuid_data.entries[cpuid_i++]; + } + break; case 0x14: { uint32_t times; =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631095779327197.22940279446607; Wed, 8 Sep 2021 03:09:39 -0700 (PDT) Received: from localhost ([::1]:59460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuWQ-0006fd-Co for importer@patchew.org; Wed, 08 Sep 2021 06:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRt-0006i9-IJ for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:57 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:46797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRq-00034m-Pi for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:57 -0400 Received: by mail-wm1-x32a.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso1071603wmi.5 for ; Wed, 08 Sep 2021 03:04:54 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JwjqCRXQx9MlfSnrV5qD4bpa9qVZzm/hjGfrBWyX5Yo=; b=Qpoxbwikarak01B9E9s5kBIDsoVc+PEr8MDb3gaF2tLF/ibIBwJ0kNGcHkgqHaOk0s +BfLgRaNSwqqd/0FUzDKO8ogXNu+1oCkDh5uS/PCzTxf+gjTLYFLhsiXjXaem61IsoLz WehHM55s9K3jrSRU+wfhSgfNJiCr3YYXUDDXu6GN6rNXg8o20E43Suz18pVpDdC2Lg5q HGgV5uTnt8V1d+0Zu6QZFjz7UvRiomljaS/xfHrXRO3MLscAsgYRYi75jBW/miCuRwnI LsyjGs5B0ttfZ4WxDekQU2LunDUSxhrSZKJIOIvU7QGF+lrnGL9mraSZLf3+1MWFiSNt SECg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=JwjqCRXQx9MlfSnrV5qD4bpa9qVZzm/hjGfrBWyX5Yo=; b=EmhQderwPh4ae1vXAKANlYKZiM9Nkxem2pRk4gOQcLsUEmyDy3twI7JSrUHWoDzial kurEIzGDeX/hwTuYKePN1joFWp7CRJIb8I5xo/WV/CDKx9H9RB0dN5jqqf9AuWKjc63s hm5jzCFJ7QegjrMz3HXX/cEZEyQB040Xd6waTo/Jrfv0UBm9hdl5CQje+mHMoRK8HBJx S84X1diX36i3zGOmKnXegw1kroGWZrj8olw2ULSVyEQh5nCgIajHBor7/SV385KfVEF1 kvrddtO3xUkCVAmqyr+HgR1xSN4DDtpDaaqfN8zA/8GGzOpHhcKBJvRpBH4iEgVNpz2Z vPDA== X-Gm-Message-State: AOAM532Td5EeEyXCDMzRD66/jHqpAGLVUx1L1Csu0a9va5ckvf4EwROn n/Vkql0zbwPAOpV9h3d0aRcbFz3kmFw= X-Google-Smtp-Source: ABdhPJx44nsPEfU+w897ToMcsWaUueCyRBnuhk2keLhv9c4/M2lE35C4pZ6gcmjlKVev8m/Q91Rn2A== X-Received: by 2002:a1c:7201:: with SMTP id n1mr2288752wmc.19.1631095493397; Wed, 08 Sep 2021 03:04:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 24/43] Adjust min CPUID level to 0x12 when SGX is enabled Date: Wed, 8 Sep 2021 12:04:07 +0200 Message-Id: <20210908100426.264356-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631095780550100005 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson SGX capabilities are enumerated through CPUID_0x12. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-16-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3b1f9cbdf6..2774550501 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6153,6 +6153,11 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **er= rp) if (sev_enabled()) { x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000001F); } + + /* SGX requires CPUID[0x12] for EPC enumeration */ + if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SGX) { + x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x12); + } } =20 /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set = */ --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096740122357.93778423396805; Wed, 8 Sep 2021 03:25:40 -0700 (PDT) Received: from localhost ([::1]:52108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNulu-00063c-Pf for importer@patchew.org; Wed, 08 Sep 2021 06:25:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRu-0006kV-Qt for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:58 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:46800) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRr-00034w-DV for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:58 -0400 Received: by mail-wm1-x32d.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso1071629wmi.5 for ; Wed, 08 Sep 2021 03:04:54 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6HvVwDW0UEsMND2Epmw+EH1l2m7EcZiok6GeyK4r1PQ=; b=B4Q+ikA36ht5pIYGDG584KoDMDRt66i7fPbri/PbCM9LMbzXW2nhHpQWxyLXAqHToQ Mct0dLt7yLrFrdTnWfouDCP76bi+rlbz9L3mLd0VtOy31/JWxfiljt4CSFh2/g6BIfLx qF9FqFjkaAfeEhwkjnsSkkg/5nNhcWcjzi1imJsWFH/WdQME7dbWf2CGuVzuTlu7g1H6 6IOqqJ0VxdRG16ZBFe0LOnI7wB1wRHt61oiabBoIpLkhWsQOj4iDrz1XcNbY1kqnlSF5 1iWirUUYV2t9hzWLGroCvcYs79937kzffMg72/xH+H425Qs+JFMXT2CQLhly6XnK6QpW hOxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=6HvVwDW0UEsMND2Epmw+EH1l2m7EcZiok6GeyK4r1PQ=; b=ShlsSyor/692l8lrPjrM+Y1R7i8hCUUfx6YDawyS7ZB/b9ZaVm4tEaEtihVVLC6VKv 2FKGC0GT872pSjI4hvKkC7y+a3yTTPxLK2mFGFRitLs0cOXe7c+yLZMqrU0JTGXXMhYe /GgYH7bXCDiUI3gsN/dd4qFDY+CmNGjcOYTAUSXej9B2Vwy528lhK8d83P3t5GCVtz8M giF5IpQvL6pneAgTfaF8NOPW1saEWTasvlXIIY9mMTSN1I+uLd8IstWK6DuzWU4i8WZs SJS1VfesymMa+3erhHJ7Og7i9zRpFibkBB0Tgv/FPTJlTWwA5MQzAQVPlEz4CAUd7wXR J0sw== X-Gm-Message-State: AOAM53256Sdr6zi4Mw1elJPpefMiLX1Z5XvvXQdAKntmU7BzLK8X6HWC 6zGwnFnN4Ge+/EjDpM/PUigRZFlSr8g= X-Google-Smtp-Source: ABdhPJz4f4Eb5h0Jy9fPsRxbBUKeRwSkpQuXgZ/Q4wejD0F/Y/RyrkAYVANTToUDiX6D4XQ1XUFdZA== X-Received: by 2002:a1c:8086:: with SMTP id b128mr2808344wmd.54.1631095494112; Wed, 08 Sep 2021 03:04:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 25/43] hw/i386/fw_cfg: Set SGX bits in feature control fw_cfg accordingly Date: Wed, 8 Sep 2021 12:04:08 +0200 Message-Id: <20210908100426.264356-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096742372100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Request SGX an SGX Launch Control to be enabled in FEATURE_CONTROL when the features are exposed to the guest. Our design is the SGX Launch Control bit will be unconditionally set in FEATURE_CONTROL, which is unlike host bios. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-17-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/fw_cfg.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c index 4e68d5dea4..f6d036dfbe 100644 --- a/hw/i386/fw_cfg.c +++ b/hw/i386/fw_cfg.c @@ -159,7 +159,7 @@ void fw_cfg_build_feature_control(MachineState *ms, FWC= fgState *fw_cfg) { X86CPU *cpu =3D X86_CPU(ms->possible_cpus->cpus[0].cpu); CPUX86State *env =3D &cpu->env; - uint32_t unused, ecx, edx; + uint32_t unused, ebx, ecx, edx; uint64_t feature_control_bits =3D 0; uint64_t *val; =20 @@ -174,6 +174,14 @@ void fw_cfg_build_feature_control(MachineState *ms, FW= CfgState *fw_cfg) feature_control_bits |=3D FEATURE_CONTROL_LMCE; } =20 + cpu_x86_cpuid(env, 0x7, 0, &unused, &ebx, &ecx, &unused); + if (ebx & CPUID_7_0_EBX_SGX) { + feature_control_bits |=3D FEATURE_CONTROL_SGX; + } + if (ecx & CPUID_7_0_ECX_SGX_LC) { + feature_control_bits |=3D FEATURE_CONTROL_SGX_LC; + } + if (!feature_control_bits) { return; } --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096049528593.8403347067896; Wed, 8 Sep 2021 03:14:09 -0700 (PDT) Received: from localhost ([::1]:48150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuam-00018e-Ez for importer@patchew.org; Wed, 08 Sep 2021 06:14:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRw-0006nu-5p for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:00 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:45011) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRt-00035J-NI for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:59 -0400 Received: by mail-wm1-x32e.google.com with SMTP id l7-20020a1c2507000000b002e6be5d86b3so1072805wml.3 for ; Wed, 08 Sep 2021 03:04:55 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LrpWhKARcoTgZN4W9UXAhXElE4Wt3Yuz4O1+ggge9gI=; b=MZnw4kM+syualv5NlUB1RXF2Yx8EoHbF7dyrfDjQsuBy59sc52tsNte67OW3DEDtn4 Nl+WqX4atlq6WZrV/DEHL7yc15cq2xD9hwiHVIMlAWCCUxnQ1NlyKh2pHGT65ZmiP8ZT 2lk+ksl265ORykH3lKIN+Xh3gNh4bFs6K5ShEz+dtzxJVZ0TTA+DEj/yIxS8GyXQtBhN 6zX85Sdjp6SuBcwmGlwXbpaisP//URDlZDIeUPVxI9A1CQ+FUBSp4txgeTgpz3LiiV+I 8GpL2Y7hYonOz9YcKrMMbA28NFthlqu5cQo9LVXHf294q5B7NF4DSw0dBkoQm7fQ57Su Jy7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=LrpWhKARcoTgZN4W9UXAhXElE4Wt3Yuz4O1+ggge9gI=; b=XD7evLr+DFz7n8XafLWjXtah1AOpx60crknwOy+EYcc+at+9k88HghT1qX47piYlNO dcqTig4TL5SnIr5JqHlotMmtVG71/ghtzsgV3Sam+hBUYFgFv3pum8tvjVqcxy2bQDek fUDq6ZnabUKWzZfpqOpuw7lr5qkDDBXMqcfb453Mz/IouSCZQDI1ol701jWOKZPlxD8W hP3sXngHDPMAf8o2p9UbNA2VQFpYeCH/VAI6TRh725EPJM7oMcxnil/hqh6H/+ZV5XLn IjcMlhZq1BKiIJdcGEM85c2sxDXI0ODy1mWDrOhsWbRwfaHn37i/khT4F8oi9Myu6EOj Dg+Q== X-Gm-Message-State: AOAM531odQMmZrEMpqio832lgCH1pCXSp4ZOpdHVc8B+gH0W4h+GHVHO Tb0xYIcaAPtA4hWBFSWlrYxIbZrIxh0= X-Google-Smtp-Source: ABdhPJwY9bVmWVabsz9txeGcc+cCXyXDPIaWpQsBtllgngVbyHOpHEJorj2+74h0kQ+j4SOQTC6zjA== X-Received: by 2002:a1c:1cc:: with SMTP id 195mr2750080wmb.188.1631095494778; Wed, 08 Sep 2021 03:04:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 26/43] hw/i386/pc: Account for SGX EPC sections when calculating device memory Date: Wed, 8 Sep 2021 12:04:09 +0200 Message-Id: <20210908100426.264356-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096052377100002 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Add helpers to detect if SGX EPC exists above 4g, and if so, where SGX EPC above 4g ends. Use the helpers to adjust the device memory range if SGX EPC exists above 4g. For multiple virtual EPC sections, we just put them together physically contiguous for the simplicity because we don't support EPC NUMA affinity now. Once the SGX EPC NUMA support in the kernel SGX driver, we will support this in the future. Note that SGX EPC is currently hardcoded to reside above 4g. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-18-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 11 ++++++++++- include/hw/i386/sgx-epc.h | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 7e523b913c..58700af138 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -913,8 +913,15 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 + if (pcms->sgx_epc.size !=3D 0) { + machine->device_memory->base =3D sgx_epc_above_4g_end(&pcms->s= gx_epc); + } else { + machine->device_memory->base =3D + 0x100000000ULL + x86ms->above_4g_mem_size; + } + machine->device_memory->base =3D - ROUND_UP(0x100000000ULL + x86ms->above_4g_mem_size, 1 * GiB); + ROUND_UP(machine->device_memory->base, 1 * GiB); =20 if (pcmc->enforce_aligned_dimm) { /* size device region assuming 1G page max alignment per slot = */ @@ -999,6 +1006,8 @@ uint64_t pc_pci_hole64_start(void) if (!pcmc->broken_reserved_end) { hole64_start +=3D memory_region_size(&ms->device_memory->mr); } + } else if (pcms->sgx_epc.size !=3D 0) { + hole64_start =3D sgx_epc_above_4g_end(&pcms->sgx_epc); } else { hole64_start =3D 0x100000000ULL + x86ms->above_4g_mem_size; } diff --git a/include/hw/i386/sgx-epc.h b/include/hw/i386/sgx-epc.h index f85fd2a4ca..155e8fad3e 100644 --- a/include/hw/i386/sgx-epc.h +++ b/include/hw/i386/sgx-epc.h @@ -57,4 +57,11 @@ typedef struct SGXEPCState { =20 int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size); =20 +static inline uint64_t sgx_epc_above_4g_end(SGXEPCState *sgx_epc) +{ + assert(sgx_epc !=3D NULL && sgx_epc->base >=3D 0x100000000ULL); + + return sgx_epc->base + sgx_epc->size; +} + #endif --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097075809468.75068527722544; Wed, 8 Sep 2021 03:31:15 -0700 (PDT) Received: from localhost ([::1]:60646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNurK-0003dp-Np for importer@patchew.org; Wed, 08 Sep 2021 06:31:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRw-0006pD-Fn for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:00 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:56212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRt-00036b-Qf for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:00 -0400 Received: by mail-wm1-x32e.google.com with SMTP id g74so1261239wmg.5 for ; Wed, 08 Sep 2021 03:04:57 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UgkF1mvQK//t6XGujinPfYl2Zezj6c5sitJ7wVbQTZk=; b=Hd7pnbPDuAf0zLagGSdKx1ypt9m+xMEpRS6CDRG8oSyV2lv1chdnlGRC/2pFn2WsYV SSpudIhhnjVco6rfsP0z44v6HbDkd2eEFivSXzUrE+KgZp7LpEaTLohR6sRFBlZQhKSz F5BGmWvZ2u9He/Z3BpUJTYJbuLuQ0FdAIX8gEdwkmwRh57bEHc4pllCFiJy1LFyBmZvk rKqoN3bFepFBl1pXmzGUvJCLJCgqB1bbQ/VCAy9RWqwOCNH3TOB51d7uf8lBv9100wca /R0E2Z4xTi91i/yGib93d7y6K7v4BVK+c+FkaglNKscFq0DD+W+j2Y+kZGASJKNZOZ6v 7lXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=UgkF1mvQK//t6XGujinPfYl2Zezj6c5sitJ7wVbQTZk=; b=Mf3dqS7+m1eLIBWxdnLmNiZose528xgVHwdlGl1vip2PEY+sxrtNtydW7sFjUG0wcf Naxbnwj2t50jkGN0RecqaXhYNL33r5CG/OWTqm2QZ2+qby9r3DptWT9cImoS5YdCpLXa xRY5kuzV2Vp7CxbWprOd7jD2jVVNxENyvgwGM4i7W+CguHczekC2w4i3pvcWPhCtSLBM 21WrLOpHmF5EAFYW+RRFJ79jEoEsD9KIIPQr/wLfDWyGhU8WbHrh2llXTvqPBU1Ue+IW lgeXZdFMBTs16ovSo3InnqaFGO3sI4r9zWIIFyG0W1S4qfblIT689tNnDq+cmYoAmYzq 9KZA== X-Gm-Message-State: AOAM533PMTcntCcusdFVvQDm1yoRHqJrobbqCaieAb8ejbLqhJQtqIRL 4ZHqlXgzyE50x82DB3nbVa9zyIkdXQw= X-Google-Smtp-Source: ABdhPJwlsNIxE3pbkt+4GQAKWhu37LK0Id6WXr5zzJgTC+s77pCj8KcEmNcgPrxsRr8FE2zHWQAqdA== X-Received: by 2002:a05:600c:295:: with SMTP id 21mr2658560wmk.37.1631095495471; Wed, 08 Sep 2021 03:04:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 27/43] i386/pc: Add e820 entry for SGX EPC section(s) Date: Wed, 8 Sep 2021 12:04:10 +0200 Message-Id: <20210908100426.264356-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097077648100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Note that SGX EPC is currently guaranteed to reside in a single contiguous chunk of memory regardless of the number of EPC sections. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-19-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 58700af138..1260fb6197 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -883,6 +883,10 @@ void pc_memory_init(PCMachineState *pcms, e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM); } =20 + if (pcms->sgx_epc.size !=3D 0) { + e820_add_entry(pcms->sgx_epc.base, pcms->sgx_epc.size, E820_RESERV= ED); + } + if (!pcmc->has_reserved_memory && (machine->ram_slots || (machine->maxram_size > machine->ram_size))) { --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310971492831021.9509530167173; Wed, 8 Sep 2021 03:32:29 -0700 (PDT) Received: from localhost ([::1]:34750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNusW-0005Dh-3Y for importer@patchew.org; Wed, 08 Sep 2021 06:32:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRv-0006lU-8X for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:59 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:42555) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRt-00037H-La for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:04:58 -0400 Received: by mail-wr1-x42c.google.com with SMTP id q11so2384659wrr.9 for ; Wed, 08 Sep 2021 03:04:57 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NgWD+4DZm29WOsZx4zHR/ZUlTNniLiRiAhwjufQ97XI=; b=X92kry98NTwgnMsIYB+7/0iC3Np6VGnK9YQCsGJtBHLuIt2Rq+ggmKBW2y7zDpnETH 7lwUAxcZ0eSezAAmuZiIA1oXs2dsuiW5zhLXsvk8Tr60V7UQhw5coFUBwb4lP8zEuTPz P0kY96jp6cjJVqf5Dd5/76hMl1Z4Z8MJCNChnQgVjP4GAeEbURCnc0Ims8CeNazHOtQt GUkNJE/Pgvom8f65xd78gmeKchY7ErNaGeqHVL/5XCO3orS7uzUunBA9K6yCHw1FF+vL 2Dgrwam9dJABaqaVzQOvVQZ6g5aod6W2DTLNvyAeW7igkoH7DjXwBQJPn+GJFRjgMu3n S0aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NgWD+4DZm29WOsZx4zHR/ZUlTNniLiRiAhwjufQ97XI=; b=gTCsjWvSnsWQ7zqk6OAT2hU0C8QtA1QZ4fhjNWz4jA0gfI+g8Dr5KpkpGVXn36juMM f2lQ/QWMM/C275CbUn3jYJ/LrE7zNznipgipeq6KQkRJxwGdKhYu3q7IA8PUI+Rf8dXX 82Q93uzVLeGZikhkWBm8lC8zN0SZ7CeSv/3xcVj/oTQG5dB62Vl5Lb8TBXrUTShAFc6u 0+HIdbADkFmPCzIdNXKfyuDKhdguW5ceZ0v8YB57xNEy/DUDvMYudfkDHY3d6IbxA0DA 53OJJTbPcJQIW+ErKCrUKciW+pQLeIJv2iGJxiIbMkOukZwIZt4h0RzXrDKF4mFockkR sS9Q== X-Gm-Message-State: AOAM533J0mYnYIrRO8KjvvBdprV5OjsdwneNhLHAyjSb4GmDM1UnfclT CICLsg3MJvIKq3DAkqr5nRVEruh5+OQ= X-Google-Smtp-Source: ABdhPJwei5XJXx0eTSpepfblGf0VNaSF8EEWIOI1q3cSpsZTtY4V92SbdCOxVtGdMCZMjAsn+xgUpw== X-Received: by 2002:adf:d1c3:: with SMTP id b3mr3091227wrd.286.1631095496257; Wed, 08 Sep 2021 03:04:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 28/43] i386: acpi: Add SGX EPC entry to ACPI tables Date: Wed, 8 Sep 2021 12:04:11 +0200 Message-Id: <20210908100426.264356-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097149867100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson The ACPI Device entry for SGX EPC is essentially a hack whose primary purpose is to provide software with a way to autoprobe SGX support, e.g. to allow software to implement SGX support as a driver. Details on the individual EPC sections are not enumerated through ACPI tables, i.e. software must enumerate the EPC sections via CPUID. Furthermore, software expects to see only a single EPC Device in the ACPI tables regardless of the number of EPC sections in the system. However, several versions of Windows do rely on the ACPI tables to enumerate the address and size of the EPC. So, regardless of the number of EPC sections exposed to the guest, create exactly *one* EPC device with a _CRS entry that spans the entirety of all EPC sections (which are guaranteed to be contiguous in Qemu). Note, NUMA support for EPC memory is intentionally not considered as enumerating EPC NUMA information is not yet defined for bare metal. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-20-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/acpi-build.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index d1f5fa3b5a..10f52c0c7c 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1841,6 +1841,28 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } #endif =20 + if (pcms->sgx_epc.size !=3D 0) { + uint64_t epc_base =3D pcms->sgx_epc.base; + uint64_t epc_size =3D pcms->sgx_epc.size; + + dev =3D aml_device("EPC"); + aml_append(dev, aml_name_decl("_HID", aml_eisaid("INT0E0C"))); + aml_append(dev, aml_name_decl("_STR", + aml_unicode("Enclave Page Cache 1.0"= ))); + crs =3D aml_resource_template(); + aml_append(crs, + aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, + AML_MAX_FIXED, AML_NON_CACHEABLE, + AML_READ_WRITE, 0, epc_base, + epc_base + epc_size - 1, 0, epc_size)); + aml_append(dev, aml_name_decl("_CRS", crs)); + + method =3D aml_method("_STA", 0, AML_NOTSERIALIZED); + aml_append(method, aml_return(aml_int(0x0f))); + aml_append(dev, method); + + aml_append(sb_scope, dev); + } aml_append(dsdt, sb_scope); =20 /* copy AML table into ACPI tables blob and patch header there */ --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097349915149.01374985809832; Wed, 8 Sep 2021 03:35:49 -0700 (PDT) Received: from localhost ([::1]:43210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuvk-0002dj-S6 for importer@patchew.org; Wed, 08 Sep 2021 06:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRw-0006qL-Th for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:01 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:34453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRu-000383-AM for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:00 -0400 Received: by mail-wr1-x435.google.com with SMTP id m9so2433812wrb.1 for ; Wed, 08 Sep 2021 03:04:57 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mu1UtmsG86JlazQUUmDKwC0IiVFtrn8Kpc5xYuE0ukg=; b=X4ls9LQiAfQIgpQMHraNWu00GOCaCPdOZLk187J40+PWQXwGqwp44Um5AVSot8dzDy av7/nXpzH3sx4TIOVrnDXvt+YqgwcMaNTyeeWMU8idC4upkDLp2QOku79bOE/z+ekFzv Qv8jH0IaSWgRebn5Cp8kcRXhyS2uOi4Gfe73RPN0l4JIC2Fi1ib/0NvkXfSwkGUPIcp5 Odj5cTf9U4qq2XsPMSlsHnpQEzSARK13obWi+U/+cpx712evzt7Fuj+8odquO1O0kvJ6 A9xZ79TaStig2gkkg1aMQoQm71iFa/8qybOmg1FC5q8YFKidcHcV9+ZVo3ZneOrTJjAo UoJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mu1UtmsG86JlazQUUmDKwC0IiVFtrn8Kpc5xYuE0ukg=; b=kR/CyspNkqTQl4vI2gu1ZvcL9eHFd8B+hlKagglrRzKJPCchZDXHWQow1hXhNb2vKE VMyB+4/bJsPB0cIUaWN3SJ+0kyf7NUMguuH6oYDeTtXmuZJ38gloQwvVS6bkQ8gOdwrk BHBmTW1BpLooHmsp1Wh423ywxp8Ooe2Xf7Dy2pPgSpMF4D6o4nBV/GBMOdAcY+PzWCHK VuLhMJ6meDqbHNp+DAu+7I+wVlr6roc3xo4l3slXpdaeIPgE8Oy9DkuBpxifYv3LkCOx +FFIUwNErtn123gf5pY1txcdKpKtN/26lhqQmINj4pH0o1FHTg9454z5YYuThrnNbxBj L0Lg== X-Gm-Message-State: AOAM533I6t09J/xrWHMO4RkwlndyYAjjmergCtbLyF08F4G0xLcfpH7u 16w5RavRK08k75ckFvcI7EiCH+Gz8kM= X-Google-Smtp-Source: ABdhPJypoGzWJ7Kqm6PR+W06W0xo6tEpAc/uZHtmRFfJKuwrQ0VE+YJMBQZf7kRR/PzWx/PRRSsNVw== X-Received: by 2002:adf:c3cd:: with SMTP id d13mr3003293wrg.312.1631095496974; Wed, 08 Sep 2021 03:04:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 29/43] q35: Add support for SGX EPC Date: Wed, 8 Sep 2021 12:04:12 +0200 Message-Id: <20210908100426.264356-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097352028100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Enable SGX EPC virtualization, which is currently only support by KVM. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-21-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc_q35.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 46cd542d17..216e044d45 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -177,6 +177,9 @@ static void pc_q35_init(MachineState *machine) x86ms->below_4g_mem_size =3D machine->ram_size; } =20 + if (x86ms->sgx_epc_list) { + pc_machine_init_sgx_epc(pcms); + } x86_cpus_init(x86ms, pcmc->default_cpu_version); =20 kvmclock_create(pcmc->kvmclock_create_always); --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097459428872.1621023316927; Wed, 8 Sep 2021 03:37:39 -0700 (PDT) Received: from localhost ([::1]:51530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuxW-0008No-AC for importer@patchew.org; Wed, 08 Sep 2021 06:37:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRx-0006qo-9f for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:01 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:37686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRu-00038G-W2 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:00 -0400 Received: by mail-wr1-x435.google.com with SMTP id v10so2412006wrd.4 for ; Wed, 08 Sep 2021 03:04:58 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yPtnnCGwNpWuv+KJHtggVQGhlvl+/IX1Kajo4BpYxPk=; b=T4h3RFFdkiq+Cahbi0bOi4+64hD2Wyp/VGitdsfhTvtL1K0XItBC0tb/6+ISsut8iY Xg9t3cXrFc6ENiml115U/cL/GFHQ+Xts6tWKZLIhe+v7bPeQj99bStU1hxYCawlZ17nE 4tK5TC2grkd77AgiLJPr4HIqZ+rMvhrgD7Mh/dgWTo/LOLlsBp4Apiz6EAlpPC7TWYxN OpgjwoHcORb7mfb/fRnBj1lLvjTW/5VXo6/u3i2gBTgNMyff6XIh7zlAilMzIEwl98Ox iaCSBte4J7LCmXtv2WH3dD0z8TEfFVAWr5339zIap+vDS9GwcsUKzEkJUE1WpxUYXLya 5avw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=yPtnnCGwNpWuv+KJHtggVQGhlvl+/IX1Kajo4BpYxPk=; b=hL2neTjNEsziyuy0qfojVuLvtG/w6+1akd/LJvpRhiWFgaUppOhoQwETvSRMsxgb10 tUeLGj+x8yy9aZV42Qhd670+bGqP2KoKk6tw5II0gbUTNsgFBBAtdnzu4rhAUva+FxbD vlbTSGWZdfelhxf1u2y4S9oQRyS2FOX+rvXewQvHm1Rkyfx6/0toeCo+cIQeUaglg1lG 0es2O1sEtuj1r6VTJGluXXzhrEoLWJ9vWZqeaL1H3/6wUNQ/IZAUaa3e7SHUqloie7nJ tr4bRqKjjKWvTwLEP0CGfsS6U3rhPCGGhLBVoWjfoKRF9FBck1MkxArmM3wSs1iu7RGl atxg== X-Gm-Message-State: AOAM533cWFeW5+Y4sHSHTkmNFRkk2iZMO5v8oZgxd2Rtw3+wjdiqOI4V t7TMv0DXkno8SkDgNZuD8Qwf01sm1+8= X-Google-Smtp-Source: ABdhPJzomZ6xTWBp2R13JCzK3ZBJDL/cF4iXQf7DlflN4pdWPWp0NWEBIsd1SrBgmLdURHb2zBLazw== X-Received: by 2002:a5d:6210:: with SMTP id y16mr2986872wru.290.1631095497780; Wed, 08 Sep 2021 03:04:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 30/43] i440fx: Add support for SGX EPC Date: Wed, 8 Sep 2021 12:04:13 +0200 Message-Id: <20210908100426.264356-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097459843100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Enable SGX EPC virtualization, which is currently only support by KVM. Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-22-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc_piix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index c5da7739ce..dabb66b51d 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -153,6 +153,10 @@ static void pc_init1(MachineState *machine, } } =20 + if (x86ms->sgx_epc_list) { + pc_machine_init_sgx_epc(pcms); + } + x86_cpus_init(x86ms, pcmc->default_cpu_version); =20 if (pcmc->kvmclock_enabled) { --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097300700490.6754627110496; Wed, 8 Sep 2021 03:35:00 -0700 (PDT) Received: from localhost ([::1]:41114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuux-0001C8-Dp for importer@patchew.org; Wed, 08 Sep 2021 06:34:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRz-0006tD-Md for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:04 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:36779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRv-00039Z-Sa for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:02 -0400 Received: by mail-wr1-x42a.google.com with SMTP id g16so2420764wrb.3 for ; Wed, 08 Sep 2021 03:04:59 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yJehKJquhIoU/zA8uyJsKbhN7DD8eaV1JU50Vzj2bEo=; b=fDAOhMWWEHwiFNZ9fETfFR29dAuiQBBLUIWk684KXqJgHmOF8IF8w184HQnJ+wHgpS MEMcW7zSudEzEW7/zB2GJ7/8+lD96h/XTWo7cchlXT1f2IYoW0Cp+7++ghXePAMerTmM aTwEZZOIZt8fXh0DkxdfXlZ5V6K61ANipHLyB57aeXX2F3cNMOzl6FJeRfMqUG7dA3dq 5072nmDV5/fXGK8vnE+YrnOUTpwjRiLiwOAvy7CWkCMRH58Q87tW1XQqqAjUUILZhOH9 IJEXyG+xfCuWZyqhehFtMYx1DjdD13r1LeKro7m8WFIWAq2iwYPwPK1yqBGinqfEiZCe 7vFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=yJehKJquhIoU/zA8uyJsKbhN7DD8eaV1JU50Vzj2bEo=; b=XhQsHGCgjujO+08JPgA1qcfQ5Vc4gNDaXrZVBf6JwwJCWzZrDoQXByBDemAPNEr8AD cVQUFbmWrlRnlr9yI7pAgJrHd+vs//dyYQuLLLvUGkCBCWzwhYaLK+CbbNkL6cijjxsG gLLrsPr9sBZgJgTBq8E2PG8O3EzKC3H/lPUgzmLn3DcZlfRGK7QUzvWE2XvYWNaJqmzH foeSOWBFvrMS3z95JBnrH6X50OyXJIHjZUJEXsyBA5k24OsWvKh0r+L8QO+D9LLw70bD xCrgESUdauuHk9p4UcLzcbMWDXx6qpGOyJf3RtpVFBIhfTa6J05exomlZMLQWJSn34bx xs2A== X-Gm-Message-State: AOAM5325QsZ4VIwEYVUM1DEXYyBUbkLHNM4eIrGbES31esch0Wv0I9dz Fw7HA6L0mgzNyc3RlPr6bBxXgYQYeJs= X-Google-Smtp-Source: ABdhPJz7L1V4k2A9AoJVjtTOs8SZckDGhWXMPxp50nzz3EyJtFJooittH3QWJRrgtPJvWGhH0DXuwQ== X-Received: by 2002:adf:d184:: with SMTP id v4mr3051704wrc.229.1631095498467; Wed, 08 Sep 2021 03:04:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 31/43] hostmem-epc: Add the reset interface for EPC backend reset Date: Wed, 8 Sep 2021 12:04:14 +0200 Message-Id: <20210908100426.264356-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097302291100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong Add the sgx_memory_backend_reset() interface to handle EPC backend reset when VM is reset. This reset function will destroy previous backend memory region and re-mmap the EPC section for guest. Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-23-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- backends/hostmem-epc.c | 16 ++++++++++++++++ include/hw/i386/pc.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c index b512a68cb0..3bd1535d82 100644 --- a/backends/hostmem-epc.c +++ b/backends/hostmem-epc.c @@ -16,6 +16,7 @@ #include "qom/object_interfaces.h" #include "qapi/error.h" #include "sysemu/hostmem.h" +#include "hw/i386/pc.h" =20 #define TYPE_MEMORY_BACKEND_EPC "memory-backend-epc" =20 @@ -55,6 +56,21 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend,= Error **errp) g_free(name); } =20 +void sgx_memory_backend_reset(HostMemoryBackend *backend, int fd, + Error **errp) +{ + MemoryRegion *mr =3D &backend->mr; + + mr->enabled =3D false; + + /* destroy the old memory region if it exist */ + if (fd > 0 && mr->destructor) { + mr->destructor(mr); + } + + sgx_epc_backend_memory_alloc(backend, errp); +} + static void sgx_epc_backend_instance_init(Object *obj) { HostMemoryBackend *m =3D MEMORY_BACKEND(obj); diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index f2869437ab..a5ae380b4b 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -203,6 +203,8 @@ extern const size_t pc_compat_6_0_len; =20 /* sgx-epc.c */ void pc_machine_init_sgx_epc(PCMachineState *pcms); +void sgx_memory_backend_reset(HostMemoryBackend *backend, int fd, + Error **errp); =20 extern GlobalProperty pc_compat_5_2[]; extern const size_t pc_compat_5_2_len; --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097120176297.72336032911244; Wed, 8 Sep 2021 03:32:00 -0700 (PDT) Received: from localhost ([::1]:33978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNus2-0004hm-Px for importer@patchew.org; Wed, 08 Sep 2021 06:31:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRy-0006sd-9l for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:04 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:33630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRw-0003AH-HX for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:02 -0400 Received: by mail-wr1-x431.google.com with SMTP id t18so2485895wrb.0 for ; Wed, 08 Sep 2021 03:05:00 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sAWCVmhntjt3N2I3a0MmSk7QA9BliYQ2Nc92h12oy2c=; b=c1BUFXQhkWxtGSSTdub43rVTPyNFoF7PvYKCeNbLBmzZR2dRNHwUVKFl2qsV6acjZB 9z4VBGs76EOfcboDO+Uoz4Z7VJfP2T13wM+Rcgl+VZwQZXtwoMCoSRy4F+rWrdoXANzJ FXWHFdcIjGWlwZ2JgG/VB6hRz3KJSyUWRjKuKgrpptV3pmykdian4gv//AUEBMzxzF/f 3Eubc5o0qZfRnVC+uPw8WyMT463udns7IXxzbeGhWAAeZMYjZrNUzEzBjw3a7sT9YmBw EIV0iwxEsu7C8y/W+PFdQnob7od9kMnwCOb/Clg+/cdXPSstO8FOXGxE5OGlgSxhCkS9 6nUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=sAWCVmhntjt3N2I3a0MmSk7QA9BliYQ2Nc92h12oy2c=; b=Oq5d/3dCQii3NUaw70a3GRMdiH89doSMZnqm6PhJTOHW3PrWL7hmxdQKDEh4Tu94C8 FM7ihpybfMF9Jt1RuskPkSwJCOBSq1ViYtLJ8RV8KfKiB3vu70B9CPYvgUSaTfKs0GKq TsnrGSP9lF8AsV4LyGTOAnJPL0m0uR/8vVLndtB+61pZ0gXGH7ieZcllv6v8CyyOUQ07 QqjblC5vJTU+o8wNzWlSrE3ecz1HP+25hjKByEnnFvUCk0DmnTkQeksfK4+yIxOtLshz 1GycGV213thRwlP9CzEDCjXodNe4IKxlRsYXQnpuZlJv1YF2GbG6MviqX4aEeu2Bsm7W Gbmg== X-Gm-Message-State: AOAM533TQiL86w5couvSbraDU63rwbAaXjlLs1kGR48idSK+Qs5lHk5U MiHRclItCDJWPsz+1Db9RzJ4hDmV4/0= X-Google-Smtp-Source: ABdhPJyu2eu93ed6VUQxNcijweCkTWL0g87Jio8ysWM35h8vVYTMagw7lPW2QPlZfFlzP6cQ68IoNg== X-Received: by 2002:a5d:4b0b:: with SMTP id v11mr2385696wrq.359.1631095499184; Wed, 08 Sep 2021 03:04:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 32/43] sgx-epc: Add the reset interface for sgx-epc virt device Date: Wed, 8 Sep 2021 12:04:15 +0200 Message-Id: <20210908100426.264356-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097121837100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong If the VM is reset, we need make sure sgx virt epc in clean status. Once the VM is reset, and sgx epc virt device will be reseted by reset callback registered by qemu_register_reset(). Since this epc virt device depend on backend, this reset will call backend reset interface to re-mmap epc to guest. Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-24-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/sgx-epc.c | 94 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c index 924dea22f0..9880d832d5 100644 --- a/hw/i386/sgx-epc.c +++ b/hw/i386/sgx-epc.c @@ -18,6 +18,9 @@ #include "qapi/visitor.h" #include "target/i386/cpu.h" #include "exec/address-spaces.h" +#include "sysemu/reset.h" + +uint32_t epc_num; =20 static Property sgx_epc_properties[] =3D { DEFINE_PROP_UINT64(SGX_EPC_ADDR_PROP, SGXEPCDevice, addr, 0), @@ -47,12 +50,84 @@ static void sgx_epc_init(Object *obj) NULL, NULL, NULL); } =20 +static void sgx_epc_del_subregion(DeviceState *dev) +{ + PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); + SGXEPCState *sgx_epc =3D &pcms->sgx_epc; + SGXEPCDevice *epc =3D SGX_EPC(dev); + + /* del subregion and related operations */ + memory_region_del_subregion(&sgx_epc->mr, + host_memory_backend_get_memory(epc->hostme= m)); + host_memory_backend_set_mapped(epc->hostmem, false); + g_free(sgx_epc->sections); + sgx_epc->sections =3D NULL; + + /* multiple epc devices, only zero the first time */ + if (epc_num =3D=3D sgx_epc->nr_sections) { + sgx_epc->size =3D 0; + sgx_epc->nr_sections =3D 0; + } +} + +static void sgx_epc_initialization(DeviceState *dev) +{ + PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); + SGXEPCState *sgx_epc =3D &pcms->sgx_epc; + MemoryDeviceState *md =3D MEMORY_DEVICE(dev); + SGXEPCDevice *epc =3D SGX_EPC(dev); + Error *errp =3D NULL; + + if (!epc->hostmem) { + error_setg(&errp, "'" SGX_EPC_MEMDEV_PROP "' property is not set"); + return; + } + + epc->addr =3D sgx_epc->base + sgx_epc->size; + + memory_region_add_subregion(&sgx_epc->mr, epc->addr - sgx_epc->base, + host_memory_backend_get_memory(epc->hostme= m)); + + host_memory_backend_set_mapped(epc->hostmem, true); + + sgx_epc->sections =3D g_renew(SGXEPCDevice *, sgx_epc->sections, + sgx_epc->nr_sections + 1); + sgx_epc->sections[sgx_epc->nr_sections++] =3D epc; + + sgx_epc->size +=3D memory_device_get_region_size(md, &errp); +} + +static void sgx_epc_reset(void *opaque) +{ + DeviceState *dev =3D opaque; + SGXEPCDevice *epc =3D SGX_EPC(dev); + Error *errp =3D NULL; + int fd; + + if (!epc->hostmem) { + error_setg(&errp, "'" SGX_EPC_MEMDEV_PROP "' property is not set"); + return; + } + + /* delete subregion and related operations */ + sgx_epc_del_subregion(dev); + + /* reset sgx backend */ + fd =3D memory_region_get_fd(host_memory_backend_get_memory(epc->hostme= m)); + sgx_memory_backend_reset(epc->hostmem, fd, &errp); + if (errp) { + error_setg(&errp, "failed to call sgx_memory_backend_reset"); + return; + } + + /* re-add subregion and related operations */ + sgx_epc_initialization(dev); +} + static void sgx_epc_realize(DeviceState *dev, Error **errp) { PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); X86MachineState *x86ms =3D X86_MACHINE(pcms); - MemoryDeviceState *md =3D MEMORY_DEVICE(dev); - SGXEPCState *sgx_epc =3D &pcms->sgx_epc; SGXEPCDevice *epc =3D SGX_EPC(dev); const char *path; =20 @@ -71,18 +146,11 @@ static void sgx_epc_realize(DeviceState *dev, Error **= errp) return; } =20 - epc->addr =3D sgx_epc->base + sgx_epc->size; + sgx_epc_initialization(dev); + epc_num++; =20 - memory_region_add_subregion(&sgx_epc->mr, epc->addr - sgx_epc->base, - host_memory_backend_get_memory(epc->hostme= m)); - - host_memory_backend_set_mapped(epc->hostmem, true); - - sgx_epc->sections =3D g_renew(SGXEPCDevice *, sgx_epc->sections, - sgx_epc->nr_sections + 1); - sgx_epc->sections[sgx_epc->nr_sections++] =3D epc; - - sgx_epc->size +=3D memory_device_get_region_size(md, errp); + /* register the reset callback for sgx reset */ + qemu_register_reset(sgx_epc_reset, dev); } =20 static void sgx_epc_unrealize(DeviceState *dev) --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096228561786.317017614675; Wed, 8 Sep 2021 03:17:08 -0700 (PDT) Received: from localhost ([::1]:56622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNudf-0006vt-9K for importer@patchew.org; Wed, 08 Sep 2021 06:17:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuRz-0006tJ-RQ for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:06 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:35754) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRx-0003Ac-A8 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:02 -0400 Received: by mail-wr1-x42d.google.com with SMTP id i28so2432493wrb.2 for ; Wed, 08 Sep 2021 03:05:00 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=boHe/TN7iP4dCfI5Lt28Agud/RqY7EKeXZQNrY5FSWM=; b=PgGePefxh3kdOPswUci+IVtBKQUypG4r9vYa/iJrTwhZCtBQ38GndYskjHbe4axiR9 jNKAJZKCzYU29ChE2lA7ZbouU6uFUzEvGAG88bSUUzqP05XVMOp0t/q3wIYlaq0Syl52 ajM2/YIKmuRPPjt7UssFyO7feOfiPoLCGImb0SFFXfWx8XrlN2c/2g+/kWroBavUgRa1 IYM5oUAFhAqw7m0mbV0/fGQ2U+qXzWHrD3AIrxwNAqagCkvANfCcgwNn9doEL5xZNtuz jtdcgpGrw+w3lOAaz78+x2wpcJdc7rxQhtB4dPQ73VZxlna8vZ8bz3S1+iY8EnBJe5aG Shzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=boHe/TN7iP4dCfI5Lt28Agud/RqY7EKeXZQNrY5FSWM=; b=QYWILHCr4Y4xL3XLtwRPELmQRn9sNccRRwWQOBvoco/Z+m99Dn43vNZrl3+/MHSx+J t/2DejcxXpBHzDh8lZwYywI68W/eBkfcIE8GhU2XWwXG+rbxU/jq3ymUh24tHrWQU2Sk foHaXTaRhhErgIGNsjQgq1q8ZhaN+UZmOFkcKnUxO9udm9N7+k7tlHvW0sczv0AEJKhy Wev0L4ujg4sowXgsEKyWSuB7qiXfy34WrexK+pVvWxFipxdIKZyK3wnL96Irry8Epm/r AJPu/vymRRndXX33NXkQUqO73CRUdmMg72VgjENefIPY2S0XqxEaJwpM6QsmdrgfgtZB tIWQ== X-Gm-Message-State: AOAM531qnWR7Zo6+kDsepih/W7xTh9s/ZE1GjW0oJg81jarGmqR38GXA KLHWaYpdYyHVCNLIRV8oSZiXxnJOlfY= X-Google-Smtp-Source: ABdhPJxEZiaOqOx/Jb98g8+iL2pN/PRuBw8nUkWfSIL+aB2EAG6rIjDOX2klh2vgkF1iAeRrfiwPbQ== X-Received: by 2002:a5d:58e2:: with SMTP id f2mr3040907wrd.272.1631095499920; Wed, 08 Sep 2021 03:04:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 33/43] sgx-epc: Avoid bios reset during sgx epc initialization Date: Wed, 8 Sep 2021 12:04:16 +0200 Message-Id: <20210908100426.264356-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096230136100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong Since bios do the reset when qemu boot up, and sgx epc will be reset by the registered reset callback function. Like this, the sgx epc will do two times initialization. This patch will check protected mode from cr0 register, and will bypass reset operation from bios. The reset callback will only accept reset operation from guest. Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-25-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/sgx-epc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c index 9880d832d5..70075db37c 100644 --- a/hw/i386/sgx-epc.c +++ b/hw/i386/sgx-epc.c @@ -19,6 +19,7 @@ #include "target/i386/cpu.h" #include "exec/address-spaces.h" #include "sysemu/reset.h" +#include "sysemu/hw_accel.h" =20 uint32_t epc_num; =20 @@ -97,6 +98,21 @@ static void sgx_epc_initialization(DeviceState *dev) sgx_epc->size +=3D memory_device_get_region_size(md, &errp); } =20 +static bool check_reset_from_guest(void) +{ + CPUState *cs =3D first_cpu; + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; + + cpu_synchronize_state(cs); + + if (env->cr[0] & CR0_PE_MASK) { + return true; + } + + return false; +} + static void sgx_epc_reset(void *opaque) { DeviceState *dev =3D opaque; @@ -104,6 +120,9 @@ static void sgx_epc_reset(void *opaque) Error *errp =3D NULL; int fd; =20 + if (!check_reset_from_guest()) + return; + if (!epc->hostmem) { error_setg(&errp, "'" SGX_EPC_MEMDEV_PROP "' property is not set"); return; --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097343376703.8340893680844; Wed, 8 Sep 2021 03:35:43 -0700 (PDT) Received: from localhost ([::1]:42712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuve-0002Iu-Av for importer@patchew.org; Wed, 08 Sep 2021 06:35:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS2-0006ue-J3 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:08 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:33623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRx-0003BR-Tu for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:05 -0400 Received: by mail-wr1-x429.google.com with SMTP id t18so2485996wrb.0 for ; Wed, 08 Sep 2021 03:05:01 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SlR1D4KQkZZwbyWUBGj/wMkLtBYfhmaSXWEyYmVKf6s=; b=gJIkYG1xIzv3y0cZRaZSnjJyGDHu2SnPdnTjQaPTuf/ODBtgfIuVIN0RcJdUjehpeS zOhTElxL0/0E5SRGLOCbZzoWDLAbBSZ8UNhtqyJ8NjJ+jdpVu3PASWv+C8+Q9nXMhQiu ahGbOL1nOZyis6MSfzdBb476w4rHifu2/jkm2tRgpQ8wBBws+FI6eTe7KUld0Ghoa8IS sPPZiHbxmHAvWXIObvQkQnZ41bJ4kclS6eArCFEbVOBxeaKWLcOV26fwd44YDgQyEvNB YJKHGQTZAAIzXp+xGH7CogYY0umyVSKME4kg7kcAT9mU0gMC3tDTAWmskVVFf7jJm5g8 Ziiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SlR1D4KQkZZwbyWUBGj/wMkLtBYfhmaSXWEyYmVKf6s=; b=kwSP5jJV69/AyivVVx8xVaa2SCUSYI4bkLsMYmmVbmtPn6PddgVMOzGEOhoEtQaJQt DJHtfUF2jj3s+L4lf1yHC4zmT6QGx6Gm8eN/9OGWxTD50L8Ksg10PU5TVMnQjopZOGY4 Ner1if7euFisiPsL1OKIGRXluZaQ/72ZwRMry4u6pJdkXS87SEcken3lWfD6rnW3b9xJ 9J1Hzy/3OIfImyNuQdC3iU0/HSyt5FVyJKNEJrAgoJjUkysCShEbpi5yhiU6o6PHko6k p8bXiFeTiFq8VP2sPn3rT8T4d9g6YtKUxm/9EJKqxVppX+YA3dW2rpuV9umKpfBLoYD+ w7xw== X-Gm-Message-State: AOAM532UE59GwA2vj3Rewm44qjWaZxNaogt1QmjBHPcmjd0tUpfZXz5l rf1V6TH7hAbQe4o1zgMwJsYC4KMUQdI= X-Google-Smtp-Source: ABdhPJxYIoM3x8/9pehl+nfiSAHoyQ8hXAvrrawVIAazTcR07zFW+VoeQOH7JwrQbLQ51a6QWJD8fQ== X-Received: by 2002:a5d:51c7:: with SMTP id n7mr2989892wrv.217.1631095500599; Wed, 08 Sep 2021 03:05:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 34/43] hostmem-epc: Make prealloc consistent with qemu cmdline during reset Date: Wed, 8 Sep 2021 12:04:17 +0200 Message-Id: <20210908100426.264356-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097345443100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong If qemu cmdline set the prealloc property for sgx epc and VM do the reset the prealloc property will be different with cmdline settings. This patch can make sure same prealloc property setting with cmdline. Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-26-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- backends/hostmem-epc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c index 3bd1535d82..9836358841 100644 --- a/backends/hostmem-epc.c +++ b/backends/hostmem-epc.c @@ -60,6 +60,8 @@ void sgx_memory_backend_reset(HostMemoryBackend *backend,= int fd, Error **errp) { MemoryRegion *mr =3D &backend->mr; + void *ptr; + uint64_t sz; =20 mr->enabled =3D false; =20 @@ -69,6 +71,14 @@ void sgx_memory_backend_reset(HostMemoryBackend *backend= , int fd, } =20 sgx_epc_backend_memory_alloc(backend, errp); + + ptr =3D memory_region_get_ram_ptr(&backend->mr); + sz =3D memory_region_size(&backend->mr); + + if (backend->prealloc) { + os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz, + backend->prealloc_threads, errp); + } } =20 static void sgx_epc_backend_instance_init(Object *obj) --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163109751519542.12490028779632; Wed, 8 Sep 2021 03:38:35 -0700 (PDT) Received: from localhost ([::1]:54124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuyQ-0001nG-5X for importer@patchew.org; Wed, 08 Sep 2021 06:38:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuSE-0006yl-8j for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:18 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:38881) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuRy-0003Bk-Jl for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:16 -0400 Received: by mail-wr1-x435.google.com with SMTP id u16so2409858wrn.5 for ; Wed, 08 Sep 2021 03:05:02 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zi6XC7xgXM4E75DCCFQG+dfwQNv3xa2eHtXmh1sF/QU=; b=PJGC99++uvylq0bGOqzma1mnJ2D8unoH6MzAJu0Lw/VmtEerErGfF3xvJkJLDuTRyZ GeDsytpI1531/CheCBmywGmHt/IdlceKp2MV06ZwajlWkBo3dDhEEf/+lZuYLiUPmusA tet1cn4Lfb82Z/HZt+PS3Qkmtuf8DptX27wo/G0IZBSeM8/UcBDjvRxF631MhbNMeXkW FmLBOtaZbpyhSCJ6RCgZ5DqMEMwFjvASzqN5s53ACDFDg8aa4IgUaCt1kiRt6DJ9IgJ4 nhrAjKkRGspVqzwcaV5xzbpxF6ubizeVxho1wJ0BJXJVXZ5jfSyynoT5yMDFN26edLAq vPbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=zi6XC7xgXM4E75DCCFQG+dfwQNv3xa2eHtXmh1sF/QU=; b=KdTslvdMfGvkgad2wsWZwcuuh44i89pq3yyZiQZVGzHocP8Gq9JD1t/Xs0xx59FLsB EW8fhlRSExxwfFdvVk/QUrwI6TBB3bZOqzuUqXzUsWVO/eqhGswH38TYIeo0vZmt74Ga QqH2UQG9eeQ0ZbTar3lq1VNuRppq5zOkmR631wmdkAX27aleK+KREANV0l3OvtS56qWr qBRn0xLzhe0YYE2gXsr0ou3vhC/fSCFnRK60Q9WIHmJrZ2p29brn9Hvy9L+hbfl6LV3t mudwPbzChgj1rkyR5CD75kKMBmnjgM0Oe9rQobUjTACxmjqM1Vt4/gWX3u3E4pOPaWdo 6big== X-Gm-Message-State: AOAM530YAxWwt6gkp0G8ihHd+8534GpIjjJRiw4kscdPyLbcWmrnALpx 0tp+M8ULK5/d1ETUsYpu0YEPsaMhTdE= X-Google-Smtp-Source: ABdhPJwN7p4d7yzEv9mONWbC2wfeD1jf/81s8BdenoUg4X//Q291WlXZVyAl+oO6TApzlEf/nJ4wyQ== X-Received: by 2002:adf:ec8b:: with SMTP id z11mr3056490wrn.122.1631095501257; Wed, 08 Sep 2021 03:05:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 35/43] Kconfig: Add CONFIG_SGX support Date: Wed, 8 Sep 2021 12:04:18 +0200 Message-Id: <20210908100426.264356-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097516688100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong Add new CONFIG_SGX for sgx support in the Qemu, and the Kconfig default enable sgx in the i386 platform. Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-32-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- backends/meson.build | 2 +- configs/devices/i386-softmmu/default.mak | 1 + hw/i386/Kconfig | 5 +++++ hw/i386/meson.build | 4 ++-- hw/i386/sgx-stub.c | 13 +++++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 hw/i386/sgx-stub.c diff --git a/backends/meson.build b/backends/meson.build index 46fd16b269..6e68945528 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -16,6 +16,6 @@ softmmu_ss.add(when: ['CONFIG_VHOST_USER', 'CONFIG_VIRTIO= '], if_true: files('vho softmmu_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('cryptodev-vho= st.c')) softmmu_ss.add(when: ['CONFIG_VIRTIO_CRYPTO', 'CONFIG_VHOST_CRYPTO'], if_t= rue: files('cryptodev-vhost-user.c')) softmmu_ss.add(when: 'CONFIG_GIO', if_true: [files('dbus-vmstate.c'), gio]) -softmmu_ss.add(when: 'CONFIG_LINUX', if_true: files('hostmem-epc.c')) +softmmu_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c')) =20 subdir('tpm') diff --git a/configs/devices/i386-softmmu/default.mak b/configs/devices/i38= 6-softmmu/default.mak index 84d1a2487c..598c6646df 100644 --- a/configs/devices/i386-softmmu/default.mak +++ b/configs/devices/i386-softmmu/default.mak @@ -22,6 +22,7 @@ #CONFIG_TPM_CRB=3Dn #CONFIG_TPM_TIS_ISA=3Dn #CONFIG_VTD=3Dn +#CONFIG_SGX=3Dn =20 # Boards: # diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index ddedcef0b2..962d2c981b 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -6,6 +6,10 @@ config SEV select X86_FW_OVMF depends on KVM =20 +config SGX + bool + depends on KVM + config PC bool imply APPLESMC @@ -21,6 +25,7 @@ config PC imply PVPANIC_ISA imply QXL imply SEV + imply SGX imply SGA imply TEST_DEVICES imply TPM_CRB diff --git a/hw/i386/meson.build b/hw/i386/meson.build index fefce9e4ba..c502965219 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -5,8 +5,6 @@ i386_ss.add(files( 'e820_memory_layout.c', 'multiboot.c', 'x86.c', - 'sgx-epc.c', - 'sgx.c' )) =20 i386_ss.add(when: 'CONFIG_X86_IOMMU', if_true: files('x86-iommu.c'), @@ -18,6 +16,8 @@ i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'= )) i386_ss.add(when: 'CONFIG_VMMOUSE', if_true: files('vmmouse.c')) i386_ss.add(when: 'CONFIG_VMPORT', if_true: files('vmport.c')) i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c')) +i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'), + if_false: files('sgx-stub.c')) =20 i386_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-common.c')) i386_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_= device_x86.c')) diff --git a/hw/i386/sgx-stub.c b/hw/i386/sgx-stub.c new file mode 100644 index 0000000000..edf17c3309 --- /dev/null +++ b/hw/i386/sgx-stub.c @@ -0,0 +1,13 @@ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" +#include "hw/i386/sgx-epc.h" + +void pc_machine_init_sgx_epc(PCMachineState *pcms) +{ + return; +} + +int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) +{ + return 1; +} --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097432706660.5530793874757; Wed, 8 Sep 2021 03:37:12 -0700 (PDT) Received: from localhost ([::1]:49370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNux5-0006ti-KT for importer@patchew.org; Wed, 08 Sep 2021 06:37:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS2-0006ud-ID for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:08 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:39781) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS0-0003DA-CD for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:05 -0400 Received: by mail-wr1-x42a.google.com with SMTP id z4so2397089wrr.6 for ; Wed, 08 Sep 2021 03:05:02 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lmGIbQ3pyoWC76VZj4ie9GYX4qqPuNvX4g9NmbF5xHw=; b=TBnwrRoLDCwbM2Ma97y4qkv0Cou36rN3jg6N9mqstt8QRJmw7Fy38eD/8GEUoHI/0E /RzXPjdorWu+gE0BH8bK9v8ZbirJBp5bfDH5aAYClPz/oHRXxA8EIj93qjAdECtHmaXl P01gTBPNFxNBzKMFHxk2cCpbkniRuEf2o2R3E5tNozxS07/aolCm4nABTh2RQHhuqGL5 k7pEuX85ABZ/cmIpXX60W6awNt++lGy0vU/btdJtFrASNWGziaYYnqlkIbR/dz2GIMiq 1Lv4qoso7nx1jbsA2DHPW+vrucS3uwLzLt4/t0nUTNQjoNIsU9+ME/Oe5+cNor+1nvwL 5kBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=lmGIbQ3pyoWC76VZj4ie9GYX4qqPuNvX4g9NmbF5xHw=; b=DQW++MOqwpsa48PoWI2o+cX18WcBx1w7EqPp+RAxh6FtfdUctNJA+dLlLTWiOFhEgS mEs1Vhq+HaVnSwZ0wMPkT3eooGS3d0p+rGkCh2MUsYfKl2EXX3TG0CVW82NLjtrmwacL IhJpREygn+otiN2uzaMa/uzZ85NX7pDQKi0wLEDRWxCypgc55tb6t+3bc1PheS09w+/G gYNdkD9/XK56+8vspEmPvx7zcJLVaMB+9LxXjgRTtS5l4BFFX0LtEVTOm/ocXuIZm2Ks QTw5y2qB8WcW7VAlx5cW+A9kHDhWAJ6wzyPs24Nnf1R0Y3AcHcmrYjSINDn2VZN70D/c iYKw== X-Gm-Message-State: AOAM530ekYrFuxYLyrAyZ898WuQ6myAZkgrYrr60KVPxuFhyYlSRtyff Xi6KSbLX6gZc5YOU5An1rL2yZJsmESw= X-Google-Smtp-Source: ABdhPJysFQBEMflepTLrfNo0kFjI0JI1hvQjhZCm+PT5EouBgwrbKiBzoEGkd+dkncacLUE1KaI3bg== X-Received: by 2002:a5d:6b8a:: with SMTP id n10mr3049383wrx.276.1631095502041; Wed, 08 Sep 2021 03:05:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 36/43] sgx-epc: Add the fill_device_info() callback support Date: Wed, 8 Sep 2021 12:04:19 +0200 Message-Id: <20210908100426.264356-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097434348100001 Content-Type: text/plain; charset="utf-8" From: Yang Zhong Since there is no fill_device_info() callback support, and when we execute "info memory-devices" command in the monitor, the segfault will be found. This patch will add this callback support and "info memory-devices" will show sgx epc memory exposed to guest. The result as below: qemu) info memory-devices Memory device [sgx-epc]: "" memaddr: 0x180000000 size: 29360128 memdev: /objects/mem1 Memory device [sgx-epc]: "" memaddr: 0x181c00000 size: 10485760 memdev: /objects/mem2 Signed-off-by: Yang Zhong v3-->v4: - Removed the epc device 'id' from compound property(Paolo). v1-->v2: - "Since: 5.1" to "Since: 6.1"(Eric Blake). Message-Id: <20210719112136.57018-33-yang.zhong@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/sgx-epc.c | 11 ++++++++++- monitor/hmp-cmds.c | 10 ++++++++++ qapi/machine.json | 26 +++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/hw/i386/sgx-epc.c b/hw/i386/sgx-epc.c index 70075db37c..7fc3dd81b9 100644 --- a/hw/i386/sgx-epc.c +++ b/hw/i386/sgx-epc.c @@ -214,7 +214,16 @@ static MemoryRegion *sgx_epc_md_get_memory_region(Memo= ryDeviceState *md, static void sgx_epc_md_fill_device_info(const MemoryDeviceState *md, MemoryDeviceInfo *info) { - /* TODO */ + SgxEPCDeviceInfo *se =3D g_new0(SgxEPCDeviceInfo, 1); + SGXEPCDevice *epc =3D SGX_EPC(md); + + se->memaddr =3D epc->addr; + se->size =3D object_property_get_uint(OBJECT(epc), SGX_EPC_SIZE_PROP, + NULL); + se->memdev =3D object_get_canonical_path(OBJECT(epc->hostmem)); + + info->u.sgx_epc.data =3D se; + info->type =3D MEMORY_DEVICE_INFO_KIND_SGX_EPC; } =20 static void sgx_epc_class_init(ObjectClass *oc, void *data) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index e00255f7ee..0d414d60c7 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1823,6 +1823,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDic= t *qdict) VirtioMEMDeviceInfo *vmi; MemoryDeviceInfo *value; PCDIMMDeviceInfo *di; + SgxEPCDeviceInfo *se; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; @@ -1870,6 +1871,15 @@ void hmp_info_memory_devices(Monitor *mon, const QDi= ct *qdict) vmi->block_size); monitor_printf(mon, " memdev: %s\n", vmi->memdev); break; + case MEMORY_DEVICE_INFO_KIND_SGX_EPC: + se =3D value->u.sgx_epc.data; + monitor_printf(mon, "Memory device [%s]: \"%s\"\n", + MemoryDeviceInfoKind_str(value->type), + se->id ? se->id : ""); + monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->mema= ddr); + monitor_printf(mon, " size: %" PRIu64 "\n", se->size); + monitor_printf(mon, " memdev: %s\n", se->memdev); + break; default: g_assert_not_reached(); } diff --git a/qapi/machine.json b/qapi/machine.json index 10d36da83f..61514c6d9f 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1220,6 +1220,29 @@ 'data': { 'sgx-epc': ['SgxEPC'] } } =20 +## +# @SgxEPCDeviceInfo: +# +# Sgx EPC state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @size: size of memory that the device provides +# +# @memdev: memory backend linked with device +# +# Since: 6.1 +## +{ 'struct': 'SgxEPCDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size', + 'size': 'size', + 'memdev': 'str' + } +} + ## # @MemoryDeviceInfo: # @@ -1234,7 +1257,8 @@ 'data': { 'dimm': 'PCDIMMDeviceInfo', 'nvdimm': 'PCDIMMDeviceInfo', 'virtio-pmem': 'VirtioPMEMDeviceInfo', - 'virtio-mem': 'VirtioMEMDeviceInfo' + 'virtio-mem': 'VirtioMEMDeviceInfo', + 'sgx-epc': 'SgxEPCDeviceInfo' } } =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097684005287.2646064260373; Wed, 8 Sep 2021 03:41:24 -0700 (PDT) Received: from localhost ([::1]:59738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv18-0005gl-UZ for importer@patchew.org; Wed, 08 Sep 2021 06:41:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS4-0006v6-DI for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:10 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:40625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS0-0003Du-CU for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:05 -0400 Received: by mail-wr1-x42c.google.com with SMTP id q26so2384407wrc.7 for ; Wed, 08 Sep 2021 03:05:03 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QDW0/wH2iY9wyTNx+C9A/U5ln75ztBlF6G4LQIygGKU=; b=BWC2LQs/C13LAhVpZ7dEIzrFJPQhUE6KuWVMdBiY1cGgHlA9/EKdgrjfNLV/sn+lN/ eqomz8O9MIUPcgLV9+daJ4vyhQV5jLTeYMT69hkG4n6SeWo1gWJpAApO3LHpodVGuUP5 +J/EQK4LLbJuLb8XM1e/MfDBXcDjU/0rrNaiznkLZu2XVJbC/mI4L1Jk2D+xjkxEZ+Jz xYweE9Rh2KNsVsYmaFKV3mTkGFQxI682UaLGBZVIhprsqwS5JhpvWfMNMb1QrQFjOlam UPL3+a1KN66BtK7bRIfAAza/oxx2J6rk7BLFxN/TDFWeTDN0rvl0+uv375XMUAPdcCEo qI9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QDW0/wH2iY9wyTNx+C9A/U5ln75ztBlF6G4LQIygGKU=; b=msTXEdy3HL/KxswkMtDDfNgLe9LJ7YwAJxWwa07gPvlU+jLRgsHPWN5Q15oSyOwH3z 7TnHeUe8AHcYyue3TLpDwEwAoH7ylfvRBIw5E92bnd/utBn5tTMSzH7DjNEY3nl6x8Hn GCqKhVubPzeqyjFR67vuiDNtlKyA+ApmdslosnyA4CHIk8HOIXJ4wfPZpHpioV+UXFHH rrOm7AKRGeJLdyinc30liW9yXt1sP44kTHacjk/mofU1c4/G8K+7b0eTX6V2eRZxNRvf xawrLPT2Fy0fHma5aU/SDLw1JvTSCkt0/h875ktxEcIbuJY/9I+y/PKA1uYVOPlcKf1a TIGw== X-Gm-Message-State: AOAM5314Ft1MLB2pqeotloxhYXF/9dMWOP6a0ELGjJun0NYu7V29bfog ZDb6VRcuhtmKhs1Z110go7DiNKd/nZg= X-Google-Smtp-Source: ABdhPJzuedbEla8GMLzKFKuQe/7SO3U1MW2uSsVqMqc6SY+QBtGohKEaLqGxw2xkmzMqAyjmDVeQpQ== X-Received: by 2002:adf:e887:: with SMTP id d7mr3034814wrm.79.1631095502764; Wed, 08 Sep 2021 03:05:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 37/43] docs: standardize book titles to === with overline Date: Wed, 8 Sep 2021 12:04:20 +0200 Message-Id: <20210908100426.264356-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097684746100002 Content-Type: text/plain; charset="utf-8" Documents within a Sphinx manual are separate files and therefore can use different conventions for headings. However, keeping some consistency is useful so that included files are easy to get right. This patch uses a standard heading format for book titles, so that it is obvious when a file sits at the top level toctree of a book or man page. The heading is irrelevant for man pages, but keep it consistent as well. Reviewed-by: Peter Maydell Signed-off-by: Paolo Bonzini --- docs/index.rst | 1 + docs/system/qemu-block-drivers.rst | 1 + docs/system/qemu-cpu-models.rst | 1 + docs/system/qemu-manpage.rst | 5 +++-- docs/tools/qemu-img.rst | 1 + docs/tools/qemu-nbd.rst | 1 + docs/tools/qemu-pr-helper.rst | 1 + docs/tools/qemu-storage-daemon.rst | 1 + docs/tools/qemu-trace-stap.rst | 1 + 9 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 5f7eaaa632..0b9ee9901d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,6 +3,7 @@ You can adapt this file completely to your liking, but it should at lea= st contain the root `toctree` directive. =20 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D Welcome to QEMU's documentation! =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/system/qemu-block-drivers.rst b/docs/system/qemu-block-dr= ivers.rst index bd99d4fa8e..eb276481d6 100644 --- a/docs/system/qemu-block-drivers.rst +++ b/docs/system/qemu-block-drivers.rst @@ -1,5 +1,6 @@ :orphan: =20 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D QEMU block drivers reference =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D =20 diff --git a/docs/system/qemu-cpu-models.rst b/docs/system/qemu-cpu-models.= rst index 53d7538c47..8c51e2bf49 100644 --- a/docs/system/qemu-cpu-models.rst +++ b/docs/system/qemu-cpu-models.rst @@ -1,5 +1,6 @@ :orphan: =20 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D QEMU / KVM CPU model configuration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/system/qemu-manpage.rst b/docs/system/qemu-manpage.rst index e9a25d0680..d6f44e265b 100644 --- a/docs/system/qemu-manpage.rst +++ b/docs/system/qemu-manpage.rst @@ -6,8 +6,9 @@ parts of the documentation that go in the manpage as well as the HTML manual. =20 -Title -=3D=3D=3D=3D=3D +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +QEMU User Documentation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Synopsis -------- diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index b7d602a288..fe6c30d509 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -1,3 +1,4 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D QEMU disk image utility =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst index ee862fa0bc..e39a9f4b1a 100644 --- a/docs/tools/qemu-nbd.rst +++ b/docs/tools/qemu-nbd.rst @@ -1,3 +1,4 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D QEMU Disk Network Block Device Server =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/tools/qemu-pr-helper.rst b/docs/tools/qemu-pr-helper.rst index ac036180ac..eaebe40da0 100644 --- a/docs/tools/qemu-pr-helper.rst +++ b/docs/tools/qemu-pr-helper.rst @@ -1,3 +1,4 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D QEMU persistent reservation helper =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/tools/qemu-storage-daemon.rst b/docs/tools/qemu-storage-d= aemon.rst index 3ec4bdd914..b8ef4486f1 100644 --- a/docs/tools/qemu-storage-daemon.rst +++ b/docs/tools/qemu-storage-daemon.rst @@ -1,3 +1,4 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D QEMU Storage Daemon =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/docs/tools/qemu-trace-stap.rst b/docs/tools/qemu-trace-stap.rst index fb70445c75..d53073b52b 100644 --- a/docs/tools/qemu-trace-stap.rst +++ b/docs/tools/qemu-trace-stap.rst @@ -1,3 +1,4 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D QEMU SystemTap trace tool =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097596529874.6956695313578; Wed, 8 Sep 2021 03:39:56 -0700 (PDT) Received: from localhost ([::1]:57560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuzj-00049X-6Y for importer@patchew.org; Wed, 08 Sep 2021 06:39:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS4-0006v7-Dx for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:10 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:39789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS0-0003EY-W4 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:06 -0400 Received: by mail-wr1-x432.google.com with SMTP id z4so2397204wrr.6 for ; Wed, 08 Sep 2021 03:05:04 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T9gO+6rZ8JlV74yiESfnbGPf5MMVTMA7x/McqIYwXak=; b=lr2dZ9GGLxih4jBBz3hAydRhHFDq2VqCuEu1I1DewfMrh6SC/XbosLBoV+ws8s5piZ W1RyTmznrq/uFueA0jGhAisd1W5lTIIMiB8p6olCAXD1HFXYjosmAAhfuUZE8dkayoj8 iadNHVSm04Lbxu6kn/QATF+CNYOdim6Vfp/18+DdjSWk96EsC1Ya8ViLBVkhHyg1wcTK ZSMwBd3o5yzK/8lgmjlF9qfv8bGm1tm+YUVNCZlamQEG9TkH8seg2jDDmd7GCIPwG9Ln qthPpAZBZTMKaAFa07YY7xahito+6oraFUbkpSyM07I7MCsOpXLiFNGsey5tBHNej6co /h1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=T9gO+6rZ8JlV74yiESfnbGPf5MMVTMA7x/McqIYwXak=; b=SoDWd156ENEkzl1Vp/XrMmKtFCx+17oUI6QY/fyCkpo54vagvRXGg0sbv9/ju+Od2T hCCkDUIf7FiQBdij87F+ieoavHIJs0xsIgHjCQaTetgyaSz4oxxjj4yyj2dOWuUH3rpl sFKUYX90G3YFY785kKQo//9/l+VSDjEoiGlPfeGyQRLB9dEdfJ94K/p5TpKUAUejv6RK YLow7eoYzjmHq2kGR0shd8l9wmlnmKa7EXuGcPMqjlFg8cqVZDavAUc5D9lpsQna3+dg CUw9SK2W4UlwcpdytPj+44ViHZ9+eHyUqZoU8zQrsYD8K1wUdoqLFwkkdkzJB4uSUjth Tjgg== X-Gm-Message-State: AOAM530EAQret0q7fs5xpMiiTE+HA1zYeHKr6MEiD9x/PvE7DsPOJM68 vk2t6Rlp26eY0YA6/at+AXqiKP5D0QY= X-Google-Smtp-Source: ABdhPJzY1kjOqnaXK1HJ/QDCZIdEE8TkNimhX6zynVai4wApHSEwniGFMyPZl7D+vEM3JLnhgcZJnw== X-Received: by 2002:adf:9d45:: with SMTP id o5mr3048191wre.226.1631095503466; Wed, 08 Sep 2021 03:05:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 38/43] docs: standardize directory index to --- with overline Date: Wed, 8 Sep 2021 12:04:21 +0200 Message-Id: <20210908100426.264356-39-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097597113100001 Content-Type: text/plain; charset="utf-8" Use a standard heading format for the index.rst file in a directory. Using overlines makes it clear that individual documents can use e.g. =3D=3D=3D for chapter titles and --- for section titles, as suggested in the Linux kernel guidelines[1]. They could do it anyway, because documents included in a toctree are parsed separately and therefore are not tied to the same conventions for headings. However, keeping some consistency is useful since sometimes files are included from multiple places. [1] https://www.kernel.org/doc/html/latest/doc-guide/sphinx.html Reviewed-by: Peter Maydell Signed-off-by: Paolo Bonzini --- docs/about/index.rst | 3 ++- docs/devel/index.rst | 3 ++- docs/interop/index.rst | 3 ++- docs/specs/index.rst | 3 ++- docs/system/index.rst | 3 ++- docs/tools/index.rst | 3 ++- docs/user/index.rst | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/about/index.rst b/docs/about/index.rst index beb762aa0a..5bea653c07 100644 --- a/docs/about/index.rst +++ b/docs/about/index.rst @@ -1,5 +1,6 @@ +---------- About QEMU -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +---------- =20 QEMU is a generic and open source machine emulator and virtualizer. =20 diff --git a/docs/devel/index.rst b/docs/devel/index.rst index 5522db7241..f95df10b3e 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -1,5 +1,6 @@ +--------------------- Developer Information -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +--------------------- =20 This section of the manual documents various parts of the internals of QEM= U. You only need to read it if you are interested in reading or diff --git a/docs/interop/index.rst b/docs/interop/index.rst index f9801a9c20..47b9ed82bb 100644 --- a/docs/interop/index.rst +++ b/docs/interop/index.rst @@ -1,5 +1,6 @@ +------------------------------------------------ System Emulation Management and Interoperability -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +------------------------------------------------ =20 This section of the manual contains documents and specifications that are useful for making QEMU interoperate with other software. diff --git a/docs/specs/index.rst b/docs/specs/index.rst index 65e9663916..ecc43896bb 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -1,5 +1,6 @@ +---------------------------------------------- System Emulation Guest Hardware Specifications -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +---------------------------------------------- =20 This section of the manual contains specifications of guest hardware that is specific to QEMU. diff --git a/docs/system/index.rst b/docs/system/index.rst index 7b9276c05f..73bbedbc22 100644 --- a/docs/system/index.rst +++ b/docs/system/index.rst @@ -1,5 +1,6 @@ +---------------- System Emulation -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +---------------- =20 This section of the manual is the overall guide for users using QEMU for full system emulation (as opposed to user-mode emulation). diff --git a/docs/tools/index.rst b/docs/tools/index.rst index ef6041a490..1edd5a8054 100644 --- a/docs/tools/index.rst +++ b/docs/tools/index.rst @@ -1,5 +1,6 @@ +----- Tools -=3D=3D=3D=3D=3D +----- =20 This section of the manual documents QEMU's "tools": its command line utilities and other standalone programs. diff --git a/docs/user/index.rst b/docs/user/index.rst index 9faa4badd7..2c4e29f3db 100644 --- a/docs/user/index.rst +++ b/docs/user/index.rst @@ -1,5 +1,6 @@ +------------------- User Mode Emulation -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +------------------- =20 This section of the manual is the overall guide for users using QEMU for user-mode emulation. In this mode, QEMU can launch --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097766777675.9741902426074; Wed, 8 Sep 2021 03:42:46 -0700 (PDT) Received: from localhost ([::1]:37584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv2T-0001TP-HS for importer@patchew.org; Wed, 08 Sep 2021 06:42:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS6-0006w5-DD for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:12 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:36787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS2-0003Eh-A2 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:10 -0400 Received: by mail-wr1-x431.google.com with SMTP id g16so2421271wrb.3 for ; Wed, 08 Sep 2021 03:05:05 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OFxC3PMcGDPUTIq1mYdRtX5DKUYLQy7cB0NmvTziU58=; b=JO0YnAr5aNq1OQ4jxsORJX5UVSCu0t7Xk3FVdZjxOFA/L+baKwJpw6NX/2Y6lW5kzA NUhZjh7P8WJcJQ7Ny9csvnWwXtF0cYAiH0BPhbq4gaaarUE80dKf69zIakhqYMZHH3Ef n9pFz5+iEM9sUqxtkiNVFsyKe0/FU6T9fvQSeMem9f69au0oQAOLpEjkUpnDpNgB2f0o M6/40EovVijGaSK27N4GAkBxb1L7C35B9oXDw/2rQYgU6rJgkB8doFexs3h6XttwCtz3 gJpSiDPg6K0UfGdbvnJJcA7mMJC7Jqvvr53siP31Qezj/+M2j6SfjI8AtMCH9n5gux5u XSJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=OFxC3PMcGDPUTIq1mYdRtX5DKUYLQy7cB0NmvTziU58=; b=47q8fare5E3xVjS5qqJchbAyJc0BLHjx6fV/VMGOiSgY16C4p6bQiacbl66Pj/sdxw 7HsndV7x2V8QjKUzyrA+O67nYvmTi8ASutllP3CuP0mUXz5df1Xvnz6KmEGAiLfLxhlL bCloXEhWDHYZNnVYJTjRpMRsDlRClAFMx4TcDY2LBJnDGWNq2oTW9cUy6bIMZ1SSXE8S YM84gDQ64nMYdmzhHpRkgNw1gc1NBTHMb52VWZiFq+1dKYYa9OcPQd5kVcRXaFan+ZMT t+SBzjy4x9WeOUA+QMFy6d2oprgINQv3dg4YRbe2ejyKnGuiQ54wG6jgtG3E4JcJBr/a BZEw== X-Gm-Message-State: AOAM532MxNKeBsOW5Ahiz6R8GcaEIiNSolwkcp6m4AOEKZsAAFjIbWC4 /So5D/nv0kxEFvH01x/ifDNsYjVkM7M= X-Google-Smtp-Source: ABdhPJyAjtD31JHd8YKVYbxz00deUyXuiYNichvxODMg+QJTe00ORmb9tDx789vJL7+y9d2TEPXCyg== X-Received: by 2002:a5d:6210:: with SMTP id y16mr2987439wru.290.1631095504207; Wed, 08 Sep 2021 03:05:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 39/43] docs/system: standardize man page sections to --- with overline Date: Wed, 8 Sep 2021 12:04:22 +0200 Message-Id: <20210908100426.264356-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097768894100001 Content-Type: text/plain; charset="utf-8" Man pages in docs/system use file inclusion heavily. Use headings with overlines in the main files, so that the same included file work well from both manuals and man pages. This style of heading is a bit more heavy-weight, so it is not used by the other man pages in interop/ and tools/. If in the future they are changed to use include files, for example to avoid having sections named "synopsis" or "description", they can switch to --- with overline as well. Reviewed-by: Peter Maydell Signed-off-by: Paolo Bonzini --- docs/system/qemu-block-drivers.rst | 3 +++ docs/system/qemu-cpu-models.rst | 9 ++++++--- docs/system/qemu-manpage.rst | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/system/qemu-block-drivers.rst b/docs/system/qemu-block-dr= ivers.rst index eb276481d6..c2c0114cec 100644 --- a/docs/system/qemu-block-drivers.rst +++ b/docs/system/qemu-block-drivers.rst @@ -4,16 +4,19 @@ QEMU block drivers reference =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D =20 +-------- Synopsis -------- =20 QEMU block driver reference manual =20 +----------- Description ----------- =20 .. include:: qemu-block-drivers.rst.inc =20 +-------- See also -------- =20 diff --git a/docs/system/qemu-cpu-models.rst b/docs/system/qemu-cpu-models.= rst index 8c51e2bf49..5cf6e46f8a 100644 --- a/docs/system/qemu-cpu-models.rst +++ b/docs/system/qemu-cpu-models.rst @@ -4,18 +4,21 @@ QEMU / KVM CPU model configuration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +-------- Synopsis -'''''''' +-------- =20 QEMU CPU Modelling Infrastructure manual =20 +----------- Description -''''''''''' +----------- =20 .. include:: cpu-models-x86.rst.inc .. include:: cpu-models-mips.rst.inc =20 +-------- See also -'''''''' +-------- =20 The HTML documentation of QEMU for more precise information and Linux user= mode emulator invocation. diff --git a/docs/system/qemu-manpage.rst b/docs/system/qemu-manpage.rst index d6f44e265b..c47a412758 100644 --- a/docs/system/qemu-manpage.rst +++ b/docs/system/qemu-manpage.rst @@ -10,6 +10,7 @@ QEMU User Documentation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +-------- Synopsis -------- =20 @@ -17,11 +18,13 @@ Synopsis =20 |qemu_system| [options] [disk_image] =20 +----------- Description ----------- =20 .. include:: target-i386-desc.rst.inc =20 +------- Options ------- =20 @@ -34,11 +37,13 @@ not need a disk image. =20 .. include:: mux-chardev.rst.inc =20 +----- Notes ----- =20 .. include:: device-url-syntax.rst.inc =20 +-------- See also -------- =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096537897280.81873214340874; Wed, 8 Sep 2021 03:22:17 -0700 (PDT) Received: from localhost ([::1]:45280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNuie-0001Qx-Nb for importer@patchew.org; Wed, 08 Sep 2021 06:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS6-0006w9-DG for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:12 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:45012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS3-0003FA-B3 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:09 -0400 Received: by mail-wm1-x32e.google.com with SMTP id l7-20020a1c2507000000b002e6be5d86b3so1073196wml.3 for ; Wed, 08 Sep 2021 03:05:05 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WwPR13OXi9fX3IyCvHJSOgO2fs5MlAYtMNrY89yA+cU=; b=kGa7weZckfn/LKikM6Y46uAtx4PFfMkG+I+jqkWEBSGIDY6v17D6x7qzPEl5YR2P9R NhWwyEh6hBvTcLBjt8HW2Fpg1e7uHqz/zj5N9BNpbtJirZ7qTaxaFFCJJeNECSzlzHX0 NP4GKXGseNeRcsWSKCnCAwZyw0myJuN3Fnu+MLEUAkcHg0OYdfQ8CyD2Vl4sxE9NvYLd wPxJLsbuyc7705x0jnixEX5p/56rw86aj5gPwOKTe//ot/yvOC7HOixbpkcWQxbwn9Vj 7edU5ZUcYXd60eABoVxY7B+ZTwlJP/RphEIYY2eLc2DbGVXlNcKt377bdmTAFADZ0RXh xKkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WwPR13OXi9fX3IyCvHJSOgO2fs5MlAYtMNrY89yA+cU=; b=RG9+SFpo39kx0m/HcDVPy77Qzydo34rssDaRSHY20/8KhHsZsSUX5bfMhtB4/UuGiw qvIlBNc25KUKKwzlmudo0fsYvn4xMq7tIaH0Py164TOqghm1n3ujmNRF5yJS4c2PU6hh pS3/zLO8yBu5AJovAvhKN3Y6LmBXFjzjgyaLQVULpGnx3RruWCKNu2m73zNdYlw03Rxp Xb+QgbphXmxO896aWCMjsmXgLpgYJ9Gj72LEzcy5b0oqmhJIacDKiruafz/isHoIY8rs ppLzyT6npUpJOKfKWtW9DQmhno69lb4svIh6wBbn9MV3FGIF0vMJUqXQw9FPe4dI2n9P Ls+A== X-Gm-Message-State: AOAM5322Vmw9P/XJsCVtJmlI/xydfFSaHz52oDp1UKiJZ0v41SdwG4pz waxNOr9uoCG3qZH9YlPDFJ38gzoulTQ= X-Google-Smtp-Source: ABdhPJz6v2gvL9YPYQohmUEkixu03A7nN4rMp2nypqIJsgbgPLjafdSWtOY93T/DFLsw21JueyxF1g== X-Received: by 2002:a7b:c1cf:: with SMTP id a15mr2778820wmj.85.1631095504806; Wed, 08 Sep 2021 03:05:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 40/43] docs/system: move x86 CPU configuration to a separate document Date: Wed, 8 Sep 2021 12:04:23 +0200 Message-Id: <20210908100426.264356-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096539022100003 Content-Type: text/plain; charset="utf-8" Currently, cpu-models-x86.rst.inc is included in target-i386.rst directly. To make the toctree more homogeneous when adding more documentation, include it through a first-class .rst file. Together with the previous changes to the man page skeletons, this also frees "=3D=3D=3D" for the headings, so that cpu-models-x86.rst.inc need not assume anything about the headings used by target-i386.rst. Reviewed-by: Peter Maydell Signed-off-by: Paolo Bonzini --- docs/system/cpu-models-x86.rst.inc | 4 ++-- docs/system/i386/cpu.rst | 1 + docs/system/target-i386.rst | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 docs/system/i386/cpu.rst diff --git a/docs/system/cpu-models-x86.rst.inc b/docs/system/cpu-models-x8= 6.rst.inc index 9119f5dff5..6e8be7d79b 100644 --- a/docs/system/cpu-models-x86.rst.inc +++ b/docs/system/cpu-models-x86.rst.inc @@ -1,5 +1,5 @@ Recommendations for KVM CPU model configuration on x86 hosts -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 The information that follows provides recommendations for configuring CPU models on x86 hosts. The goals are to maximise performance, while @@ -368,7 +368,7 @@ featureset, which prevents guests having optimal perfor= mance. =20 =20 Syntax for configuring CPU models -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D =20 The examples below illustrate the approach to configuring the various CPU models / features in QEMU and libvirt. diff --git a/docs/system/i386/cpu.rst b/docs/system/i386/cpu.rst new file mode 100644 index 0000000000..738719da9a --- /dev/null +++ b/docs/system/i386/cpu.rst @@ -0,0 +1 @@ +.. include:: ../cpu-models-x86.rst.inc diff --git a/docs/system/target-i386.rst b/docs/system/target-i386.rst index 22ba5ce2c0..c9720a8cd1 100644 --- a/docs/system/target-i386.rst +++ b/docs/system/target-i386.rst @@ -19,7 +19,13 @@ Board-specific documentation i386/microvm i386/pc =20 -.. include:: cpu-models-x86.rst.inc +Architectural features +~~~~~~~~~~~~~~~~~~~~~~ + +.. toctree:: + :maxdepth: 1 + + i386/cpu =20 .. _pcsys_005freq: =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631096821447874.325223871516; Wed, 8 Sep 2021 03:27:01 -0700 (PDT) Received: from localhost ([::1]:53918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNunE-0007Lm-5h for importer@patchew.org; Wed, 08 Sep 2021 06:27:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS8-0006x2-Kl for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:15 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:33627) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS4-0003G5-61 for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:11 -0400 Received: by mail-wr1-x42c.google.com with SMTP id t18so2486420wrb.0 for ; Wed, 08 Sep 2021 03:05:06 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n2e71CYdYrgeKoDZGg5aC8FSc4Xw4PN68IZuK98DOS4=; b=YyoYySbrml7plIYvZ2k9kOq0YaI7QOgUisffo8AB1yVp4mHkJ9GMUaDJ+bllXuXoJR 8o0Zg/Rh5O+3bLH3KNMRnZCXkr9UT+ztSDVb+/E/6VMnXZlDERctETRBfpDewcmsFCtX he/Jb0FTHsaSuid8lMLr9/J0QENDJsimj4v29eDM6Il9QtVUlESNE+Fw52+3zsPoNTRu r99OQwf6xCVT4XY+SBHLHzrFQNt/C23eGXe2XQ74eAYTNG8HR9v/o+EPx+wlGKvGgvPM 7q3f4QVpXn6MY59CE069xf/8ChChsomYdNpq9pSdrK8aIHurZGKgy/bZkZ8XqZdDHQTR VPgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=n2e71CYdYrgeKoDZGg5aC8FSc4Xw4PN68IZuK98DOS4=; b=cyIFjOpo6u8DtY26Sqvbos6FnZwsltjkuxEpnkW/z3pURbxm9s3MHsfbyalEYXOSVt +CC8OQBl8rrvY5WG9Q/DIbMJdO06LiWhDCwdWK8G7rrkJJXBi/ddZ38364Ayy4BXIsfo rMLxwEdxOrXjkQocXmjzz3BghdaHs2A8TyRQ6vQzXqP3s5WgdA2itIUgto7C6Tg2ORwb hH03N1ABWkOou6/CouRFvoX1t4MblHJKn95pOqPpyPxk64ZCWlS53AOq4eAvOoAcLG/e yE2ndC9OntcGNf1tcc/WcbDhS5QGwQA35cwu09NXObxdI6CKsc1WnnDBJlJu7KiB/i09 H9tg== X-Gm-Message-State: AOAM530SpukH9WwFosJgDGVfdJKHz8dhmOfezG+TjsdK9Z1sMtFjf0cN X7B2wWwdi/ltq3JNy4g2pMJNnSmaCnQ= X-Google-Smtp-Source: ABdhPJwsniBh9j81179BTIgjb2hOyK76jL69mcGf7HoBP4XLpcOUsycU3q6apqbMKGnYtdrLE3QM+g== X-Received: by 2002:a05:6000:160d:: with SMTP id u13mr3180631wrb.17.1631095505599; Wed, 08 Sep 2021 03:05:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 41/43] docs/system: Add SGX documentation to the system manual Date: Wed, 8 Sep 2021 12:04:24 +0200 Message-Id: <20210908100426.264356-42-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yang Zhong , Sean Christopherson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631096821770100001 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yang Zhong Message-Id: <20210719112136.57018-34-yang.zhong@intel.com> [Convert to reStructuredText, and adopt the standard =3D=3D=3D --- ~~~ head= ings suggested for example by Linux. - Paolo] Signed-off-by: Paolo Bonzini --- docs/system/i386/sgx.rst | 165 ++++++++++++++++++++++++++++++++++++ docs/system/target-i386.rst | 1 + 2 files changed, 166 insertions(+) create mode 100644 docs/system/i386/sgx.rst diff --git a/docs/system/i386/sgx.rst b/docs/system/i386/sgx.rst new file mode 100644 index 0000000000..f103ae2a2f --- /dev/null +++ b/docs/system/i386/sgx.rst @@ -0,0 +1,165 @@ +Software Guard eXtensions (SGX) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + +Overview +-------- + +Intel Software Guard eXtensions (SGX) is a set of instructions and mechani= sms +for memory accesses in order to provide security accesses for sensitive +applications and data. SGX allows an application to use it's pariticular +address space as an *enclave*, which is a protected area provides confiden= tiality +and integrity even in the presence of privileged malware. Accesses to the +enclave memory area from any software not resident in the enclave are prev= ented, +including those from privileged software. + +Virtual SGX +----------- + +SGX feature is exposed to guest via SGX CPUID. Looking at SGX CPUID, we can +report the same CPUID info to guest as on host for most of SGX CPUID. With +reporting the same CPUID guest is able to use full capacity of SGX, and KVM +doesn't need to emulate those info. + +The guest's EPC base and size are determined by Qemu, and KVM needs Qemu to +notify such info to it before it can initialize SGX for guest. + +Virtual EPC +~~~~~~~~~~~ + +By default, Qemu does not assign EPC to a VM, i.e. fully enabling SGX in a= VM +requires explicit allocation of EPC to the VM. Similar to other specialized +memory types, e.g. hugetlbfs, EPC is exposed as a memory backend. + +SGX EPC is enumerated through CPUID, i.e. EPC "devices" need to be realized +prior to realizing the vCPUs themselves, which occurs long before generic +devices are parsed and realized. This limitation means that EPC does not +require -maxmem as EPC is not treated as {cold,hot}plugged memory. + +Qemu does not artificially restrict the number of EPC sections exposed to a +guest, e.g. Qemu will happily allow you to create 64 1M EPC sections. Be a= ware +that some kernels may not recognize all EPC sections, e.g. the Linux SGX d= river +is hardwired to support only 8 EPC sections. + +The following Qemu snippet creates two EPC sections, with 64M pre-allocated +to the VM and an additional 28M mapped but not allocated:: + + -object memory-backend-epc,id=3Dmem1,size=3D64M,prealloc=3Don \ + -object memory-backend-epc,id=3Dmem2,size=3D28M \ + -M sgx-epc.0.memdev=3Dmem1,sgx-epc.1.memdev=3Dmem2 + +Note: + +The size and location of the virtual EPC are far less restricted compared +to physical EPC. Because physical EPC is protected via range registers, +the size of the physical EPC must be a power of two (though software sees +a subset of the full EPC, e.g. 92M or 128M) and the EPC must be naturally +aligned. KVM SGX's virtual EPC is purely a software construct and only +requires the size and location to be page aligned. Qemu enforces the EPC +size is a multiple of 4k and will ensure the base of the EPC is 4k aligned. +To simplify the implementation, EPC is always located above 4g in the guest +physical address space. + +Migration +~~~~~~~~~ + +Qemu/KVM doesn't prevent live migrating SGX VMs, although from hardware's +perspective, SGX doesn't support live migration, since both EPC and the SGX +key hierarchy are bound to the physical platform. However live migration +can be supported in the sense if guest software stack can support recreati= ng +enclaves when it suffers sudden lose of EPC; and if guest enclaves can det= ect +SGX keys being changed, and handle gracefully. For instance, when ERESUME = fails +with #PF.SGX, guest software can gracefully detect it and recreate enclave= s; +and when enclave fails to unseal sensitive information from outside, it can +detect such error and sensitive information can be provisioned to it again. + +CPUID +~~~~~ + +Due to its myriad dependencies, SGX is currently not listed as supported +in any of Qemu's built-in CPU configuration. To expose SGX (and SGX Launch +Control) to a guest, you must either use `-cpu host` to pass-through the +host CPU model, or explicitly enable SGX when using a built-in CPU model, +e.g. via `-cpu ,+sgx` or `-cpu ,+sgx,+sgxlc`. + +All SGX sub-features enumerated through CPUID, e.g. SGX2, MISCSELECT, +ATTRIBUTES, etc... can be restricted via CPUID flags. Be aware that enforc= ing +restriction of MISCSELECT, ATTRIBUTES and XFRM requires intercepting ECREA= TE, +i.e. may marginally reduce SGX performance in the guest. All SGX sub-featu= res +controlled via -cpu are prefixed with "sgx", e.g.:: + + $ qemu-system-x86_64 -cpu help | xargs printf "%s\n" | grep sgx + sgx + sgx-debug + sgx-encls-c + sgx-enclv + sgx-exinfo + sgx-kss + sgx-mode64 + sgx-provisionkey + sgx-tokenkey + sgx1 + sgx2 + sgxlc + +The following Qemu snippet passes through the host CPU but restricts acces= s to +the provision and EINIT token keys:: + + -cpu host,-sgx-provisionkey,-sgx-tokenkey + +SGX sub-features cannot be emulated, i.e. sub-features that are not present +in hardware cannot be forced on via '-cpu'. + +Virtualize SGX Launch Control +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Qemu SGX support for Launch Control (LC) is passive, in the sense that it +does not actively change the LC configuration. Qemu SGX provides the user +the ability to set/clear the CPUID flag (and by extension the associated +IA32_FEATURE_CONTROL MSR bit in fw_cfg) and saves/restores the LE Hash MSRs +when getting/putting guest state, but Qemu does not add new controls to +directly modify the LC configuration. Similar to hardware behavior, locki= ng +the LC configuration to a non-Intel value is left to guest firmware. Unli= ke +host bios setting for SGX launch control(LC), there is no special bios set= ting +for SGX guest by our design. If host is in locked mode, we can still allow +creating VM with SGX. + +Feature Control +~~~~~~~~~~~~~~~ + +Qemu SGX updates the `etc/msr_feature_control` fw_cfg entry to set the SGX +(bit 18) and SGX LC (bit 17) flags based on their respective CPUID support, +i.e. existing guest firmware will automatically set SGX and SGX LC accordi= ngly, +assuming said firmware supports fw_cfg.msr_feature_control. + +Launching a guest +----------------- + +To launch a SGX guest: + +.. parsed-literal:: + + |qemu_system_x86| \\ + -cpu host,+sgx-provisionkey \\ + -object memory-backend-epc,id=3Dmem1,size=3D64M,prealloc=3Don \\ + -object memory-backend-epc,id=3Dmem2,size=3D28M \\ + -M sgx-epc.0.memdev=3Dmem1,sgx-epc.1.memdev=3Dmem2 + +Utilizing SGX in the guest requires a kernel/OS with SGX support. +The support can be determined in guest by:: + + $ grep sgx /proc/cpuinfo + +and SGX epc info by:: + + $ dmesg | grep sgx + [ 1.242142] sgx: EPC section 0x180000000-0x181bfffff + [ 1.242319] sgx: EPC section 0x181c00000-0x1837fffff + +References +---------- + +- `SGX Homepage `__ + +- `SGX SDK `__ + +- SGX specification: Intel SDM Volume 3 diff --git a/docs/system/target-i386.rst b/docs/system/target-i386.rst index c9720a8cd1..6a86d63863 100644 --- a/docs/system/target-i386.rst +++ b/docs/system/target-i386.rst @@ -26,6 +26,7 @@ Architectural features :maxdepth: 1 =20 i386/cpu + i386/sgx =20 .. _pcsys_005freq: =20 --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097891877601.0543650732128; Wed, 8 Sep 2021 03:44:51 -0700 (PDT) Received: from localhost ([::1]:45922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv4U-00079q-LI for importer@patchew.org; Wed, 08 Sep 2021 06:44:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS8-0006x3-KV for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:14 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:40518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS4-0003HD-7H for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:11 -0400 Received: by mail-wm1-x335.google.com with SMTP id n14-20020a05600c3b8e00b002f8bd2f8ab6so1109505wms.5 for ; Wed, 08 Sep 2021 03:05:07 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=14SEeU0UMLkgFlaB4KV5IS119VHrF2FPl2DRudjmlkA=; b=bNWET4vGP10rShYuq8yyJJkVEHqn2ZYQQQsNd1YZC2zFfGnkB3r1vrbrSeJMSgilOj mDx79nfMLMgIBAfsjts1pSPeDLWL1uDXMXEXb4GQMHjt0E0B51VOjPhaoe5pvFNvIMbI copyokqjJ2z5V/QwxyJbft7lgcHvvR3Vo2uMJ5ObSR+ABqSnYvJzpqhRzZRswLfAx2Aw kgnlj6aTx990Gbi4v6ubUHSy1mjy0dBn/EPSLigH4BEPox+B4p4fnywqkhAMBZX/bdL/ ep/CI8gKq8Qot4C6jVlMAWcIct3UsxdCLTdDiTGVogdZZdvLAXbbiLlUaUwTR5mrFe6c dzcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=14SEeU0UMLkgFlaB4KV5IS119VHrF2FPl2DRudjmlkA=; b=WCoDupFkDasj5hcfyiA8P6u3ZRQWdlK3nH7ltho2epkeeUW03N+plUpOlD7zZpS949 9VGriz3b6mcsTUB3b6j2kgvGnUgff15ciMtYvjstX8cfKNr9Hx7LVB59PrCOjwaS8PZU 9PrphY+44C5m6KaeP1ESKagBILP7I9KZeUTtIkdF51p9QKfdWqmTlM+kGZMMiqmi1Zmc s7q3BP1rbCDgKeRre/AydkzurdpcAalE/vS/9gJVc/c7YRl3JKwdl/34a5QOOsMAee3C F/+JFGwKILM5FoTZujVPxKhT/joTOoFK4xUDimxVjNzzL2/lUVDvlXlkrKIBdbHRepzE e0jQ== X-Gm-Message-State: AOAM530jbSXDO+0uPo8wVtTEYvWMsn4XybRj/DMyPHQMUVOo+PTVPQ0h pejIQNhYyOz+ZvFFSJwwNmCxsrCTkfY= X-Google-Smtp-Source: ABdhPJzRrv8IH85xL0kmyQuE/t9nFUOGpYMckjxG+e/M+uQ0e1y5oqIhxTSq5B58TviOHF7lsz51lg== X-Received: by 2002:a05:600c:3209:: with SMTP id r9mr2714492wmp.106.1631095506511; Wed, 08 Sep 2021 03:05:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 42/43] meson.build: Do not look for VNC-related libraries if have_system is not set Date: Wed, 8 Sep 2021 12:04:25 +0200 Message-Id: <20210908100426.264356-43-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x335.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097893947100001 From: Thomas Huth When running "./configure --static --disable-system" there is currently a warning if the static version of libpng is missing: WARNING: Static library 'png16' not found for dependency 'libpng', may not be statically linked Since it does not make sense to look for the VNC-related libraries at all when we're building without system emulator binaries, let's add a check for have_system here to silence this warning. Signed-off-by: Thomas Huth Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210906153939.165567-1-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 7e58e6279b..f07236d947 100644 --- a/meson.build +++ b/meson.build @@ -931,7 +931,7 @@ vnc =3D not_found png =3D not_found jpeg =3D not_found sasl =3D not_found -if not get_option('vnc').disabled() +if have_system and not get_option('vnc').disabled() vnc =3D declare_dependency() # dummy dependency png =3D dependency('libpng', required: get_option('vnc_png'), method: 'pkg-config', kwargs: static_kwargs) --=20 2.31.1 From nobody Tue Apr 30 04:13:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631097801478162.46671975811898; Wed, 8 Sep 2021 03:43:21 -0700 (PDT) Received: from localhost ([::1]:39942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNv32-00035S-E5 for importer@patchew.org; Wed, 08 Sep 2021 06:43:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNuS9-0006xC-MT for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:15 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:51824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNuS4-0003HY-DH for qemu-devel@nongnu.org; Wed, 08 Sep 2021 06:05:11 -0400 Received: by mail-wm1-x32e.google.com with SMTP id y132so1292727wmc.1 for ; Wed, 08 Sep 2021 03:05:07 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm1683715wmq.45.2021.09.08.03.05.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 03:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gp7mqeRq3e3ylXQpJ7SvcJk+47ZSWE8k331AQJCQtB4=; b=crt4fMRKvcBgxvy2W3yzBP+5h0hGg7a80f0gy2SFLpfQYtqmqpAdwpirWLbFFf1bZb +MMESRZyO1m7CvNWhlx0Gz3aXCdgA0bXZCT1ujYBTkpMSjDRnRzQWEvTeiMGkp0zqFkg k5VCzx9UmcLDgMRj1zBwxcHbe+9DUVfLLHJbp2SInf6ap5CMvPqadXtk3dRfujMOQ/8U bunPin1LDEXiDroC2vS56oFZHEZcMhua36IjOHVyTyAyaiPhtKsxaMjZV7gyOJWQmUCh u0MX82nC6EREdo/x6bhkAiRf0MzX6qhFzlZ4wvcXAA/Iwp8CTdR1l45ji7U8Po/lS/c8 DJTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Gp7mqeRq3e3ylXQpJ7SvcJk+47ZSWE8k331AQJCQtB4=; b=bsSvF5lyn5BkUFsc4z1HTRo278YQZVvPzLeOu7nepe3XGXDbxMorhnyYl53VZHmUSg aANnPxNw5tzNsBflwNDdMKb8XJEiQNtG9/O0n3jiYvEZuJqCASCEInqRp+PEX7tK0CGE F/XsH5swKNq1Es30UCbSuVZkgfM9T0gtDb8scZ77xVbMCFAlYS5L3bZW8P4FsGEhSIjW 554cafKZyJmP7GLpKeqgXYDbmfOX2QydMPG4kFu6hNx70S5hO2eqJWq/RZCv3un9eNqr MgS9qbPewjmI68HmwP5Q02C0fG0VAdCxyN10vLJt7DLN/gUUETNbZ9uUMjnq50kUZwAL CDNQ== X-Gm-Message-State: AOAM530AnBTou396OY2Plq6EI0HvbeSlZPKhX8y0zTzg64T/P08pv/mH CnvtA6YBKGJRmXz7gWc29BcI0mTMRIg= X-Google-Smtp-Source: ABdhPJwmLPaNZgFQ2gm1GFEHJOOKfMrtaRNoAvHSj+QwdrQ0lyN4S3EZZASGnnZXZQgrOYhu+yjEiw== X-Received: by 2002:a1c:e91a:: with SMTP id q26mr2030146wmc.128.1631095507206; Wed, 08 Sep 2021 03:05:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL v4 43/43] ebpf: only include in system emulators Date: Wed, 8 Sep 2021 12:04:26 +0200 Message-Id: <20210908100426.264356-44-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908100426.264356-1-pbonzini@redhat.com> References: <20210908100426.264356-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631097803242100001 Content-Type: text/plain; charset="utf-8" eBPF files are being included in user emulators. That is useless, and it also breaks --disable-system compilation because ebpf/trace-events is only processed if a system emulator is included in the build. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/566 Signed-off-by: Paolo Bonzini --- ebpf/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebpf/meson.build b/ebpf/meson.build index 9cd0635370..2dd0fd8948 100644 --- a/ebpf/meson.build +++ b/ebpf/meson.build @@ -1 +1 @@ -common_ss.add(when: libbpf, if_true: files('ebpf_rss.c'), if_false: files(= 'ebpf_rss-stub.c')) +softmmu_ss.add(when: libbpf, if_true: files('ebpf_rss.c'), if_false: files= ('ebpf_rss-stub.c')) --=20 2.31.1