From nobody Thu Nov 28 02:48:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1732547211; cv=none; d=zohomail.com; s=zohoarc; b=SwgT9PDRY2dfL7mhZ5LsyaSMn7jHkV22NqFTzMGd9iz9J4T5mgeTsjN6Z5wDL8jUhdCxZmnaqrXSTdUcIPa4321hdStCe+qF3OCXM6GH9tSLM7dCgPOWtL6EsKFTRMR5nzruIP217r+wh9U/cdvsVDYvaA0f2XtyBYhjX5dEess= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732547211; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+hWy38W0INr0fT1Z/7Hmh80yQ4AbDhr+rRbWKgFup8E=; b=IAoHv0DffWWZB7YpXxyYaO5RL67CELJgxvOBtV2+jeOyHNooi3bk/utpJjFunopcuKLlmq14FXjkQOWqmrGr7YlvRKnTz+Ky4M35Ak0BqeY226QUrw6OoFj9zdZI5BC9ugHHkUecJPPMpVyzpudXMKeAQYwYao9uWfuQJnvx6Fw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1732547211916523.3450517032077; Mon, 25 Nov 2024 07:06:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.842717.1258394 (Exim 4.92) (envelope-from ) id 1tFafb-00048d-BS; Mon, 25 Nov 2024 15:06:35 +0000 Received: by outflank-mailman (output) from mailman id 842717.1258394; Mon, 25 Nov 2024 15:06:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tFafb-00048W-78; Mon, 25 Nov 2024 15:06:35 +0000 Received: by outflank-mailman (input) for mailman id 842717; Mon, 25 Nov 2024 15:06:34 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tFafZ-00046A-VL for xen-devel@lists.xenproject.org; Mon, 25 Nov 2024 15:06:34 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d950ad8a-ab3e-11ef-99a3-01e77a169b0f; Mon, 25 Nov 2024 16:06:29 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5cfa9979cd1so7735053a12.1 for ; Mon, 25 Nov 2024 07:06:29 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d01d3b88a7sm4211173a12.31.2024.11.25.07.06.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Nov 2024 07:06:20 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d950ad8a-ab3e-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmYiLCJoZWxvIjoibWFpbC1lZDEteDUyZi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImQ5NTBhZDhhLWFiM2UtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyNTQ3MTg5LjU5MzgwNywic2VuZGVyIjoiamJldWxpY2hAc3VzZS5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1732547189; x=1733151989; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=+hWy38W0INr0fT1Z/7Hmh80yQ4AbDhr+rRbWKgFup8E=; b=XB18dayD33JexyuoVp+YMMzVrTg6VL5tQipWXP/tBf6FBodRgt5+7eCNr+5sFGYlEO rM6+rOQmEklHnM8IxkU+YlfCmTWcCRU+CSE4gXzvwrXitgS9U6PKawmt+nqfV/1QhjTw N9ANUtSmdG+FQ0PkRCyApyi7RAUOUrghOvJL6E3+XzBdnZgUb/nM1PUv94RvakKsUlWC pT0fa2vvW2FxVErFHYGViJHhrNYVuqrzc3zPq8IBQBfHM0TO/t0kzoRBlsdtXwF8t4rf wDU8/UdPH7XTvu6dkPgzx2VhzZ10y11csHXx6fJPYabb0qXR4zAayTLhM++3R04l9qbo A9Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732547189; x=1733151989; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+hWy38W0INr0fT1Z/7Hmh80yQ4AbDhr+rRbWKgFup8E=; b=mssTCJJwdlePsR1gKT/Z/XAg8cgiXCf7Tqwmaww9HvH8wws5xVvAjKM3jxobgTWAsN 46AvBCYgyAJNQcIuIt6oZk9lOu3GKxoXYypxxlnLYB+dttj9AGTrKLNSIJJKTYSnVwPK IuqkqxDeYId9tYcL7Rb1wJHLwlXunya6i0b3MBFIEZQyQIH6acOrMOdu3Fdvfv6LO96P TMDfiA3OKtZTGL7qzru5Lhh4sa3Hs9KqLrviL0nBzSWkDj9q/BpfWtRCueUZj7Zyd3GK TKamPvh+48Vun4psBBp5ItH7/0Uvg84yOR9NY6UKVYdUUJJvton1afzQnvKBYWhRU36Z 9v3w== X-Gm-Message-State: AOJu0YyS+xqo0EeNNTqbssKl9B2IaXTjCyJDCoY+kDHX5kwvybq5jpqE Iy2+rLWCDUjtbG5TV7RiYhwACAhNUtIS22vPyVtrhqdXgcrSBjVBKw4C3e5Efmr03TqIivD32c8 = X-Gm-Gg: ASbGncvL+oe5o4OTNMWrs4vqNcjcjpT1FbP/x5kts2UgnQ0CjdI70Pa6fhkQQFabvYD 8k30eJ77ybc9AiBZ8QW/xcxqzd7Cca/nOi++UpdrTITy8buRKT3MS8wyXAavyZz8epP878GFwxf TzclIABfMLXdExSIrNtrs2ibi6r3wTJX2Ipx2dfgLm2QTMPaMMOx2NgeuSFvxeNRHPSVPIm5WSv 910t2rQ+JaCOg4wbGJrEMYw9DX1xGUxDxsk9BnbKdRyBE2z39stZRu1CziCAMzkL2+I/igLui0K lc3TVmB+222TITaeVkEQhsbMmKvZRg++wsE= X-Google-Smtp-Source: AGHT+IGKvoKBVrSLlwqk7iHuCe3HXxksXBDo2yFoYhXAjgpwsOioPmHzS0m4iurwYnBzwV5rKlYIAA== X-Received: by 2002:a05:6402:1e94:b0:5cf:ab49:8439 with SMTP id 4fb4d7f45d1cf-5d007c5a855mr16133365a12.9.1732547181035; Mon, 25 Nov 2024 07:06:21 -0800 (PST) Message-ID: <30368e5d-67ce-43de-9c46-3d263e11afd4@suse.com> Date: Mon, 25 Nov 2024 16:06:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v7 2/7] x86emul+VMX: support {RD,WR}MSRLIST From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <3a25cd59-e1cb-4bfc-b868-fb11599d22f5@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <3a25cd59-e1cb-4bfc-b868-fb11599d22f5@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1732547214900019100 Content-Type: text/plain; charset="utf-8" These are "compound" instructions to issue a series of RDMSR / WRMSR respectively. In the emulator we can therefore implement them by using the existing msr_{read,write}() hooks. The memory accesses utilize that the HVM ->read() / ->write() hooks are already linear-address (x86_seg_none) aware (by way of hvmemul_virtual_to_linear() handling this case). Preemption is being checked for in WRMSRLIST handling only, as only MSR writes are expected to possibly take long. Signed-off-by: Jan Beulich --- RFC: In vmx_vmexit_handler() handling is forwarded to the emulator blindly. Alternatively we could consult the exit qualification and process just a single MSR at a time (without involving the emulator), exiting back to the guest after every iteration. (I don't think a mix of both models makes a lot of sense.) The precise behavior of MSR_BARRIER is still not spelled out in ISE 050, so the (minimal) implementation continues to be a guess for now. Wouldn't calculate_hvm_max_policy() for MPX better behave the same way as done here, at least from an abstract perspective (assuming that AMD won't add such functionality now that Intel have deprecated it)? --- v6: Use MSR constants in test harness. Re-base. v5: Add missing vmx_init_vmcs_config() and construct_vmcs() adjustments. Avoid unnecessary uses of r(). Re-base. v3: Add dependency on LM. Limit exposure to HVM. Utilize new info from ISE 050. Re-base. v2: Use X86_EXC_*. Add preemption checking to WRMSRLIST handling. Remove the feature from "max" when the VMX counterpart isn't available. --- a/tools/tests/x86_emulator/predicates.c +++ b/tools/tests/x86_emulator/predicates.c @@ -342,6 +342,8 @@ static const struct { { { 0x01, 0xc4 }, { 2, 2 }, F, N }, /* vmxoff */ { { 0x01, 0xc5 }, { 2, 2 }, F, N }, /* pconfig */ { { 0x01, 0xc6 }, { 2, 2 }, F, N }, /* wrmsrns */ + { { 0x01, 0xc6 }, { 0, 2 }, F, W, pfx_f2 }, /* rdmsrlist */ + { { 0x01, 0xc6 }, { 0, 2 }, F, R, pfx_f3 }, /* wrmsrlist */ { { 0x01, 0xc8 }, { 2, 2 }, F, N }, /* monitor */ { { 0x01, 0xc9 }, { 2, 2 }, F, N }, /* mwait */ { { 0x01, 0xca }, { 2, 2 }, F, N }, /* clac */ --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -625,7 +625,7 @@ static int write( if ( verbose ) printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, byt= es); =20 - if ( !is_x86_user_segment(seg) ) + if ( !is_x86_user_segment(seg) && seg !=3D x86_seg_none ) return X86EMUL_UNHANDLEABLE; memcpy((void *)offset, p_data, bytes); return X86EMUL_OKAY; @@ -717,6 +717,10 @@ static int read_msr( { switch ( reg ) { + case MSR_BARRIER: + *val =3D 0; + return X86EMUL_OKAY; + case MSR_EFER: *val =3D ctxt->addr_size > 32 ? EFER_LME | EFER_LMA : 0; return X86EMUL_OKAY; @@ -1434,9 +1438,53 @@ int main(int argc, char **argv) (gs_base !=3D 0x0000111122224444UL) || gs_base_shadow ) goto fail; + printf("okay\n"); =20 cpu_policy.extd.nscb =3D i; emulops.write_segment =3D NULL; + + printf("%-40s", "Testing rdmsrlist..."); + instr[0] =3D 0xf2; instr[1] =3D 0x0f; instr[2] =3D 0x01; instr[3] =3D = 0xc6; + regs.rip =3D (unsigned long)&instr[0]; + regs.rsi =3D (unsigned long)(res + 0x80); + regs.rdi =3D (unsigned long)(res + 0x80 + 0x40 * 2); + regs.rcx =3D 0x0002000100008000UL; + gs_base_shadow =3D 0x0000222244446666UL; + memset(res + 0x80, ~0, 0x40 * 8 * 2); + res[0x80 + 0x0f * 2] =3D MSR_GS_BASE; + res[0x80 + 0x0f * 2 + 1] =3D 0; + res[0x80 + 0x20 * 2] =3D MSR_SHADOW_GS_BASE; + res[0x80 + 0x20 * 2 + 1] =3D 0; + res[0x80 + 0x31 * 2] =3D MSR_BARRIER; + res[0x80 + 0x31 * 2 + 1] =3D 0; + rc =3D x86_emulate(&ctxt, &emulops); + if ( (rc !=3D X86EMUL_OKAY) || + (regs.rip !=3D (unsigned long)&instr[4]) || + regs.rcx || + (res[0x80 + (0x40 + 0x0f) * 2] !=3D (unsigned int)gs_base) || + (res[0x80 + (0x40 + 0x0f) * 2 + 1] !=3D (gs_base >> (8 * sizeof(i= nt)))) || + (res[0x80 + (0x40 + 0x20) * 2] !=3D (unsigned int)gs_base_shadow)= || + (res[0x80 + (0x40 + 0x20) * 2 + 1] !=3D (gs_base_shadow >> (8 * s= izeof(int)))) || + res[0x80 + (0x40 + 0x31) * 2] || res[0x80 + (0x40 + 0x31) * 2 + 1= ] ) + goto fail; + printf("okay\n"); + + printf("%-40s", "Testing wrmsrlist..."); + instr[0] =3D 0xf3; instr[1] =3D 0x0f; instr[2] =3D 0x01; instr[3] =3D = 0xc6; + regs.eip =3D (unsigned long)&instr[0]; + regs.rsi -=3D 0x11 * 8; + regs.rdi -=3D 0x11 * 8; + regs.rcx =3D 0x0002000100000000UL; + res[0x80 + 0x0f * 2] =3D MSR_SHADOW_GS_BASE; + res[0x80 + 0x20 * 2] =3D MSR_GS_BASE; + rc =3D x86_emulate(&ctxt, &emulops); + if ( (rc !=3D X86EMUL_OKAY) || + (regs.rip !=3D (unsigned long)&instr[4]) || + regs.rcx || + (gs_base !=3D 0x0000222244446666UL) || + (gs_base_shadow !=3D 0x0000111122224444UL) ) + goto fail; + emulops.write_msr =3D NULL; #endif printf("okay\n"); --- a/tools/tests/x86_emulator/x86-emulate.c +++ b/tools/tests/x86_emulator/x86-emulate.c @@ -87,6 +87,7 @@ bool emul_test_init(void) cpu_policy.feat.rdpid =3D true; cpu_policy.feat.lkgs =3D true; cpu_policy.feat.wrmsrns =3D true; + cpu_policy.feat.msrlist =3D true; cpu_policy.extd.clzero =3D true; =20 if ( cpu_has_xsave ) --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -757,6 +757,9 @@ static void __init calculate_hvm_max_pol __clear_bit(X86_FEATURE_XSAVES, fs); } =20 + if ( !cpu_has_vmx_msrlist ) + __clear_bit(X86_FEATURE_MSRLIST, fs); + /* * Xen doesn't use PKS, so the guest support for it has opted to not u= se * the VMCS load/save controls for efficiency reasons. This depends on --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -366,7 +366,8 @@ static int vmx_init_vmcs_config(bool bsp =20 if ( _vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_TERTIARY_CONTROL= S ) { - uint64_t opt =3D TERTIARY_EXEC_VIRT_SPEC_CTRL; + uint64_t opt =3D TERTIARY_EXEC_ENABLE_MSRLIST | + TERTIARY_EXEC_VIRT_SPEC_CTRL; =20 _vmx_tertiary_exec_control =3D adjust_vmx_controls2( "Tertiary Exec Control", 0, opt, @@ -1119,7 +1120,8 @@ static int construct_vmcs(struct vcpu *v v->arch.hvm.vmx.exec_control |=3D CPU_BASED_RDTSC_EXITING; =20 v->arch.hvm.vmx.secondary_exec_control =3D vmx_secondary_exec_control; - v->arch.hvm.vmx.tertiary_exec_control =3D vmx_tertiary_exec_control; + v->arch.hvm.vmx.tertiary_exec_control =3D vmx_tertiary_exec_control & + ~TERTIARY_EXEC_ENABLE_MSRLIST; =20 /* * Disable features which we don't want active by default: --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -871,6 +871,20 @@ static void cf_check vmx_cpuid_policy_ch else vmx_set_msr_intercept(v, MSR_PKRS, VMX_MSR_RW); =20 + if ( cp->feat.msrlist ) + { + vmx_clear_msr_intercept(v, MSR_BARRIER, VMX_MSR_RW); + v->arch.hvm.vmx.tertiary_exec_control |=3D TERTIARY_EXEC_ENABLE_MS= RLIST; + vmx_update_tertiary_exec_control(v); + } + else if ( v->arch.hvm.vmx.tertiary_exec_control & + TERTIARY_EXEC_ENABLE_MSRLIST ) + { + vmx_set_msr_intercept(v, MSR_BARRIER, VMX_MSR_RW); + v->arch.hvm.vmx.tertiary_exec_control &=3D ~TERTIARY_EXEC_ENABLE_M= SRLIST; + vmx_update_tertiary_exec_control(v); + } + out: vmx_vmcs_exit(v); =20 @@ -3728,6 +3742,22 @@ gp_fault: return X86EMUL_EXCEPTION; } =20 +static bool cf_check is_msrlist( + const struct x86_emulate_state *state, const struct x86_emulate_ctxt *= ctxt) +{ + + if ( ctxt->opcode =3D=3D X86EMUL_OPC(0x0f, 0x01) ) + { + unsigned int rm, reg; + int mode =3D x86_insn_modrm(state, &rm, ®); + + /* This also includes WRMSRNS; should be okay. */ + return mode =3D=3D 3 && rm =3D=3D 6 && !reg; + } + + return false; +} + static void vmx_do_extint(struct cpu_user_regs *regs) { unsigned long vector; @@ -4535,6 +4565,17 @@ void asmlinkage vmx_vmexit_handler(struc } break; =20 + case EXIT_REASON_RDMSRLIST: + case EXIT_REASON_WRMSRLIST: + if ( vmx_guest_x86_mode(v) !=3D 8 || !currd->arch.cpuid->feat.msrl= ist ) + { + ASSERT_UNREACHABLE(); + hvm_inject_hw_exception(X86_EXC_UD, X86_EVENT_NO_EC); + } + else if ( !hvm_emulate_one_insn(is_msrlist, "MSR list") ) + hvm_inject_hw_exception(X86_EXC_GP, 0); + break; + case EXIT_REASON_VMXOFF: case EXIT_REASON_VMXON: case EXIT_REASON_VMCLEAR: --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -267,6 +267,7 @@ extern u32 vmx_secondary_exec_control; #define TERTIARY_EXEC_EPT_PAGING_WRITE BIT(2, UL) #define TERTIARY_EXEC_GUEST_PAGING_VERIFY BIT(3, UL) #define TERTIARY_EXEC_IPI_VIRT BIT(4, UL) +#define TERTIARY_EXEC_ENABLE_MSRLIST BIT(6, UL) #define TERTIARY_EXEC_VIRT_SPEC_CTRL BIT(7, UL) extern uint64_t vmx_tertiary_exec_control; =20 @@ -391,6 +392,9 @@ extern u64 vmx_ept_vpid_cap; #define cpu_has_vmx_notify_vm_exiting \ (IS_ENABLED(CONFIG_INTEL_VMX) && \ vmx_secondary_exec_control & SECONDARY_EXEC_NOTIFY_VM_EXITING) +#define cpu_has_vmx_msrlist \ + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + (vmx_tertiary_exec_control & TERTIARY_EXEC_ENABLE_MSRLIST)) =20 #define VMCS_RID_TYPE_MASK 0x80000000U =20 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -201,6 +201,8 @@ static inline void pi_clear_sn(struct pi #define EXIT_REASON_XRSTORS 64 #define EXIT_REASON_BUS_LOCK 74 #define EXIT_REASON_NOTIFY 75 +#define EXIT_REASON_RDMSRLIST 78 +#define EXIT_REASON_WRMSRLIST 79 /* Remember to also update VMX_PERF_EXIT_REASON_SIZE! */ =20 /* --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -24,6 +24,8 @@ #define APIC_BASE_ENABLE (_AC(1, ULL) << 11) #define APIC_BASE_ADDR_MASK _AC(0x000ffffffffff000, ULL) =20 +#define MSR_BARRIER 0x0000002f + #define MSR_TEST_CTRL 0x00000033 #define TEST_CTRL_SPLITLOCK_DETECT (_AC(1, ULL) << 29) #define TEST_CTRL_SPLITLOCK_DISABLE (_AC(1, ULL) << 31) --- a/xen/arch/x86/include/asm/perfc_defn.h +++ b/xen/arch/x86/include/asm/perfc_defn.h @@ -6,7 +6,7 @@ PERFCOUNTER_ARRAY(exceptions, =20 #ifdef CONFIG_HVM =20 -#define VMX_PERF_EXIT_REASON_SIZE 76 +#define VMX_PERF_EXIT_REASON_SIZE 80 #define VMEXIT_NPF_PERFC 143 #define SVM_PERF_EXIT_REASON_SIZE (VMEXIT_NPF_PERFC + 1) PERFCOUNTER_ARRAY(vmexits, "vmexits", --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -74,6 +74,12 @@ int guest_rdmsr(struct vcpu *v, uint32_t case MSR_AMD_PPIN: goto gp_fault; =20 + case MSR_BARRIER: + if ( !cp->feat.msrlist ) + goto gp_fault; + *val =3D 0; + break; + case MSR_IA32_FEATURE_CONTROL: /* * Architecturally, availability of this MSR is enumerated by the @@ -347,6 +353,7 @@ int guest_wrmsr(struct vcpu *v, uint32_t uint64_t rsvd; =20 /* Read-only */ + case MSR_BARRIER: case MSR_IA32_PLATFORM_ID: case MSR_CORE_CAPABILITIES: case MSR_INTEL_CORE_THREAD_COUNT: --- a/xen/arch/x86/x86_emulate/0f01.c +++ b/xen/arch/x86/x86_emulate/0f01.c @@ -11,6 +11,7 @@ #include "private.h" =20 #ifdef __XEN__ +#include #include #endif =20 @@ -28,6 +29,7 @@ int x86emul_0f01(struct x86_emulate_stat switch ( s->modrm ) { unsigned long base, limit, cr0, cr0w, cr4; + unsigned int n; struct segment_register sreg; uint64_t msr_val; =20 @@ -42,6 +44,64 @@ int x86emul_0f01(struct x86_emulate_stat ((uint64_t)regs->r(dx) << 32) | regs->eax, ctxt); goto done; + + case vex_f3: /* wrmsrlist */ + vcpu_must_have(msrlist); + generate_exception_if(!mode_64bit(), X86_EXC_UD); + generate_exception_if(!mode_ring0() || (regs->esi & 7) || + (regs->edi & 7), + X86_EXC_GP, 0); + fail_if(!ops->write_msr); + while ( regs->r(cx) ) + { + n =3D __builtin_ffsl(regs->r(cx)) - 1; + if ( (rc =3D ops->read(x86_seg_none, regs->r(si) + n * 8, + &msr_val, 8, ctxt)) !=3D X86EMUL_OKAY= ) + break; + generate_exception_if(msr_val !=3D (uint32_t)msr_val, + X86_EXC_GP, 0); + base =3D msr_val; + if ( (rc =3D ops->read(x86_seg_none, regs->r(di) + n * 8, + &msr_val, 8, ctxt)) !=3D X86EMUL_OKAY= || + (rc =3D ops->write_msr(base, msr_val, ctxt)) !=3D X86= EMUL_OKAY ) + break; + regs->r(cx) &=3D ~(1UL << n); + +#ifdef __XEN__ + if ( regs->r(cx) && local_events_need_delivery() ) + { + rc =3D X86EMUL_RETRY; + break; + } +#endif + } + goto done; + + case vex_f2: /* rdmsrlist */ + vcpu_must_have(msrlist); + generate_exception_if(!mode_64bit(), X86_EXC_UD); + generate_exception_if(!mode_ring0() || (regs->esi & 7) || + (regs->edi & 7), + X86_EXC_GP, 0); + fail_if(!ops->read_msr || !ops->write); + while ( regs->r(cx) ) + { + n =3D __builtin_ffsl(regs->r(cx)) - 1; + if ( (rc =3D ops->read(x86_seg_none, regs->r(si) + n * 8, + &msr_val, 8, ctxt)) !=3D X86EMUL_OKAY= ) + break; + generate_exception_if(msr_val !=3D (uint32_t)msr_val, + X86_EXC_GP, 0); + if ( (rc =3D ops->read_msr(msr_val, &msr_val, + ctxt)) !=3D X86EMUL_OKAY || + (rc =3D ops->write(x86_seg_none, regs->r(di) + n * 8, + &msr_val, 8, ctxt)) !=3D X86EMUL_OKA= Y ) + break; + regs->r(cx) &=3D ~(1UL << n); + } + if ( rc !=3D X86EMUL_OKAY ) + ctxt->regs->r(cx) =3D regs->r(cx); + goto done; } generate_exception(X86_EXC_UD); =20 --- a/xen/arch/x86/x86_emulate/private.h +++ b/xen/arch/x86/x86_emulate/private.h @@ -597,6 +597,7 @@ amd_like(const struct x86_emulate_ctxt * #define vcpu_has_lkgs() (ctxt->cpuid->feat.lkgs) #define vcpu_has_wrmsrns() (ctxt->cpuid->feat.wrmsrns) #define vcpu_has_avx_ifma() (ctxt->cpuid->feat.avx_ifma) +#define vcpu_has_msrlist() (ctxt->cpuid->feat.msrlist) #define vcpu_has_avx_vnni_int8() (ctxt->cpuid->feat.avx_vnni_int8) #define vcpu_has_avx_ne_convert() (ctxt->cpuid->feat.avx_ne_convert) #define vcpu_has_avx_vnni_int16() (ctxt->cpuid->feat.avx_vnni_int16) --- a/xen/arch/x86/x86_emulate/util.c +++ b/xen/arch/x86/x86_emulate/util.c @@ -100,6 +100,9 @@ bool cf_check x86_insn_is_mem_access(con break; =20 case X86EMUL_OPC(0x0f, 0x01): + /* {RD,WR}MSRLIST */ + if ( mode_64bit() && s->modrm =3D=3D 0xc6 ) + return s->vex.pfx >=3D vex_f3; /* Cover CLZERO. */ return (s->modrm_rm & 7) =3D=3D 4 && (s->modrm_reg & 7) =3D=3D 7; } @@ -160,7 +163,11 @@ bool cf_check x86_insn_is_mem_write(cons case 0xff: /* Grp5 */ break; =20 - case X86EMUL_OPC(0x0f, 0x01): /* CLZERO is the odd one. */ + case X86EMUL_OPC(0x0f, 0x01): + /* RDMSRLIST */ + if ( mode_64bit() && s->modrm =3D=3D 0xc6 ) + return s->vex.pfx =3D=3D vex_f2; + /* CLZERO is another odd one. */ return (s->modrm_rm & 7) =3D=3D 4 && (s->modrm_reg & 7) =3D=3D= 7; =20 default: --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -313,6 +313,7 @@ XEN_CPUFEATURE(WRMSRNS, 10*32+19) / XEN_CPUFEATURE(NMI_SRC, 10*32+20) /* NMI-source reporting */ XEN_CPUFEATURE(AMX_FP16, 10*32+21) /* AMX FP16 instruction */ XEN_CPUFEATURE(AVX_IFMA, 10*32+23) /*A AVX-IFMA Instructions */ +XEN_CPUFEATURE(MSRLIST, 10*32+27) /*s MSR list instructions */ =20 /* AMD-defined CPU features, CPUID level 0x80000021.eax, word 11 */ XEN_CPUFEATURE(NO_NEST_BP, 11*32+ 0) /*A No Nested Data Breakpoin= ts */ --- a/xen/tools/gen-cpuid.py +++ b/xen/tools/gen-cpuid.py @@ -275,7 +275,7 @@ def crunch_numbers(state): # NO_LMSL indicates the absense of Long Mode Segment Limits, which # have been dropped in hardware. LM: [CX16, PCID, LAHF_LM, PAGE1GB, PKU, NO_LMSL, AMX_TILE, CMPCCXA= DD, - LKGS], + LKGS, MSRLIST], =20 # AMD K6-2+ and K6-III processors shipped with 3DNow+, beyond the # standard 3DNow in the earlier K6 processors.