From nobody Sat Jan 10 01:15:02 2026 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; 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=1767795444; cv=none; d=zohomail.com; s=zohoarc; b=UOZlMfa2t7wVDqjmFVWcikZot1METzbfP31SSvyzfftKPrY9Xy/WmjXmo/uBhqPtqgVdvMFuU5h4OpyQn0vYLrGYKhXByrXw9mUTio4jRu1IhQCAlx9VEaqCDfEZ69Bv/ZtZi8Nkkbs5bbkKHJO6E9PfHQYUrTUpju3L+5IutiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767795444; 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=SnLheoEW/Yh1PkgGyXZklN/D8HIZT01TyPTA06JIXwo=; b=BXvlYdpDjaqinSnKu8cF7HhYm8igc+zlUAk/Ngx3a1VOszrK5LzxNtEBn2P8HV4E7T0Y0+vYnfCYJco0sxBNmmLTq4SPCuFfgPobku06925xTBgn2R0JSIl07XMDClkUnViFuxU15kCJngdsH/2WfE7NjGMiAagRQmFkAEC8hzg= 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 1767795444812853.8311713906974; Wed, 7 Jan 2026 06:17:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1196745.1514479 (Exim 4.92) (envelope-from ) id 1vdULQ-0004Ll-Ff; Wed, 07 Jan 2026 14:17:04 +0000 Received: by outflank-mailman (output) from mailman id 1196745.1514479; Wed, 07 Jan 2026 14:17:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vdULQ-0004Le-D3; Wed, 07 Jan 2026 14:17:04 +0000 Received: by outflank-mailman (input) for mailman id 1196745; Wed, 07 Jan 2026 14:17:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vdULP-0004De-AP for xen-devel@lists.xenproject.org; Wed, 07 Jan 2026 14:17:03 +0000 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [2a00:1450:4864:20::332]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8936668f-ebd3-11f0-b15e-2bf370ae4941; Wed, 07 Jan 2026 15:17:02 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-47d182a8c6cso13309445e9.1 for ; Wed, 07 Jan 2026 06:17:02 -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 5b1f17b1804b1-47d7f68f686sm99574385e9.3.2026.01.07.06.17.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Jan 2026 06:17:01 -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: 8936668f-ebd3-11f0-b15e-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1767795422; x=1768400222; 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=SnLheoEW/Yh1PkgGyXZklN/D8HIZT01TyPTA06JIXwo=; b=XTyQD8+Dh3Qa01ZuAkXOwPbEprxD5E3Kd7JWldEpRpYl2I7eGN1g95unrDElV6d7/j kCYYPQ0w0KfLcYtO93Mc169fpig+wwzlFaUCPoH+BW1Qq5CHvL0lE1Bejnniu+l4ntvc ObZa3K1NisqENEEdiNxvf06amvqE8mMy+xwomua/v0CRvqxdV+ekUP6D7pdAqmFqHKfv s5mSnS7cbTVeeX6FZRok8f1XeaxZZ9FDKlXZixH4l6lW9RIB999yd1tIOB31RLHA17l4 Qf5i78mVGODtWInNJjBBj2MxiSQhKV0MDI4lcPfEy2MErYvMvmZlXmFXeyKcTdgGWrXw RIdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767795422; x=1768400222; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SnLheoEW/Yh1PkgGyXZklN/D8HIZT01TyPTA06JIXwo=; b=qFhyPkHGbZUBjAExGR12OqwX5KkjZicAeqOOPYjSlQVG9p4f5LQ0nS8m50O5f0YXlY 8p66HZPWhe9IocVw7oREHJfpl4V7d7EoMiLp0CeA4czrdoT5iaYPKQjRc0qLvLOMGgUC F3jmqaB9+FubQ8cR/45OKoORB4LgHtu4Yr/MicS5kbnqjrEQUOe0a3m3GSbkwygNb0xM 9GOjIpJeZf9X9pVtjzQdvs/mU9vnH1bYBFM8QJziWHWhVMDduZ7exZPmpED5j+4NraLG 8K8gC5NuuUKhPQ58YDmzsKMZPfVhk4bVYt+Y0gb0+begIp+h3LEWaS/3h08MxOgdcsLn 0nZQ== X-Gm-Message-State: AOJu0YxD8rJ6pZ417RctCpR85Cd630oo4sZKosllYCvX0AeCNhruSIrs gTVlTy62riHC1GaobnGlnPo84W2JKpZuScWU13uMAGPE/OqEeaCfv6quuaxX26U3EgsBDqEi8Fv SNHE= X-Gm-Gg: AY/fxX7rHwbpg5uNlGExmm904T1GkiHoDdHdsI5clb/hQPY1IcdCNHOatHNLmL6x+L0 4namDBqy9wQb1qNYrM4Kj/fVb0NRMYqdcStNV3V8s4ctZS8I2R+ep5GZOOS9L5O9OHeOV8QqOfN oi5I45p9IDGfKxOx4voZ+lDoMqlyo5pzENqMGSzSDFz/g5gMquy9qpvoYX7lyYFT8ViJltarR61 GYmTQb/mO9BdTBuLknApRxwdHy0289WanuOkpgfDtWpbM6V/sBinEP9NlVomEt+t45DRzjvEh63 VogSQmOrI6piYNmZ3OEI0Xqkgtcx9HEyYJ2LszrDYncfs7g5dR9MgGxdMmCsa1duC1qhLNY+4FN qhxh9F1x2kKyvPqJHGC+RAwfRCEm5k5736VwjHSOQzm5oeDirnHT9/T4SQIY5vT1RVYmnUbdRDo BJ8UuRuiuZaGj4KC+7WjXYddSCF+lyhYlp2uMMPJsL/F2oyqsP4RcGg45WIMqLYBg4EIEZE8oYI cqHyhRnkUOfew== X-Google-Smtp-Source: AGHT+IGCI7amaymcZdP7rEvrnNfioibzSU1rmbzl2BdIQYXYOc3pNz/MXDctUUt2rW1kjUO9JaL0bw== X-Received: by 2002:a05:600c:3484:b0:479:2a0b:180d with SMTP id 5b1f17b1804b1-47d84b20fd7mr31986115e9.11.1767795421650; Wed, 07 Jan 2026 06:17:01 -0800 (PST) Message-ID: <7c06bd5e-fad2-42cb-947f-6749f647b068@suse.com> Date: Wed, 7 Jan 2026 15:17:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <4bd68e41-e665-4992-9d3c-0086bb5195ef@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: <4bd68e41-e665-4992-9d3c-0086bb5195ef@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1767795445841158500 Content-Type: text/plain; charset="utf-8" ... to a dedicated subdir of x86's private lib/ sub-tree. For the CPU policy harnesses and libxenguest use $(lib-y) as set by the new Makefile.common, whereas for the emulator harnesses stick to building just cpuid.o for the time being. Requested-by: Andrew Cooper Signed-off-by: Jan Beulich --- v2: New. --- tools/fuzz/cpu-policy/Makefile | 7 +++++-- tools/fuzz/x86_instruction_emulator/Makefile | 2 +- tools/libs/guest/Makefile.common | 7 +++++-- tools/tests/cpu-policy/Makefile | 7 +++++-- tools/tests/x86_emulator/Makefile | 2 +- xen/arch/x86/arch.mk | 1 + xen/arch/x86/lib/Makefile | 2 ++ xen/arch/x86/lib/cpu-policy/Makefile | 1 + xen/arch/x86/lib/cpu-policy/Makefile.common | 3 +++ xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/cpuid.c | 0 xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/msr.c | 0 xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/policy.c | 0 xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/private.h | 0 xen/lib/Makefile | 2 -- xen/lib/x86/Makefile | 3 --- 15 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 xen/arch/x86/lib/cpu-policy/Makefile create mode 100644 xen/arch/x86/lib/cpu-policy/Makefile.common rename xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/cpuid.c (100%) rename xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/msr.c (100%) rename xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/policy.c (100%) rename xen/{lib/x86 =3D> arch/x86/lib/cpu-policy}/private.h (100%) delete mode 100644 xen/lib/x86/Makefile diff --git a/tools/fuzz/cpu-policy/Makefile b/tools/fuzz/cpu-policy/Makefile index 6e7743e0aa12..76ecf20e8dbd 100644 --- a/tools/fuzz/cpu-policy/Makefile +++ b/tools/fuzz/cpu-policy/Makefile @@ -20,9 +20,12 @@ install: all CFLAGS +=3D $(CFLAGS_xeninclude) -D__XEN_TOOLS__ CFLAGS +=3D $(APPEND_CFLAGS) -Og =20 -vpath %.c ../../../xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy =20 -afl-policy-fuzzer: afl-policy-fuzzer.o msr.o cpuid.o +lib-y :=3D +include $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy/Makefile.common + +afl-policy-fuzzer: afl-policy-fuzzer.o $(lib-y) $(CC) $(CFLAGS) $^ -o $@ =20 -include $(DEPS_INCLUDE) diff --git a/tools/fuzz/x86_instruction_emulator/Makefile b/tools/fuzz/x86_= instruction_emulator/Makefile index d104b15f4fbf..4e4877a20322 100644 --- a/tools/fuzz/x86_instruction_emulator/Makefile +++ b/tools/fuzz/x86_instruction_emulator/Makefile @@ -21,7 +21,7 @@ vpath %.h ../../tests/x86_emulator CFLAGS +=3D -iquote ../../tests/x86_emulator =20 # Add libx86 to the build -vpath %.c $(XEN_ROOT)/xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy =20 x86_emulate: mkdir -p $@ diff --git a/tools/libs/guest/Makefile.common b/tools/libs/guest/Makefile.c= ommon index a026a2f662b0..b928a4a246a9 100644 --- a/tools/libs/guest/Makefile.common +++ b/tools/libs/guest/Makefile.common @@ -33,9 +33,12 @@ LIBELF_OBJS +=3D libelf-dominfo.o OBJS-y +=3D $(LIBELF_OBJS) =20 ifeq ($(CONFIG_X86),y) # Add libx86 to the build -vpath %.c ../../../xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy =20 -OBJS-y +=3D cpuid.o msr.o policy.o +lib-y :=3D +include $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy/Makefile.common + +OBJS-y +=3D $(lib-y) endif =20 # new domain builder diff --git a/tools/tests/cpu-policy/Makefile b/tools/tests/cpu-policy/Makef= ile index 24f87e2eca2a..d8e4d222f4e4 100644 --- a/tools/tests/cpu-policy/Makefile +++ b/tools/tests/cpu-policy/Makefile @@ -42,11 +42,14 @@ CFLAGS +=3D $(APPEND_CFLAGS) =20 LDFLAGS +=3D $(APPEND_LDFLAGS) =20 -vpath %.c ../../../xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy + +lib-y :=3D +include $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy/Makefile.common =20 %.o: Makefile =20 -test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o +test-cpu-policy: test-cpu-policy.o $(lib-y) $(CC) $^ -o $@ $(LDFLAGS) =20 -include $(DEPS_INCLUDE) diff --git a/tools/tests/x86_emulator/Makefile b/tools/tests/x86_emulator/M= akefile index 376cfe244d1c..e18725d0c303 100644 --- a/tools/tests/x86_emulator/Makefile +++ b/tools/tests/x86_emulator/Makefile @@ -17,7 +17,7 @@ vpath x86_emulate/%.h $(XEN_ROOT)/xen/arch/x86 HOSTCFLAGS +=3D -iquote $(XEN_ROOT)/xen/arch/x86 =20 # Add libx86 to the build -vpath %.c $(XEN_ROOT)/xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy =20 CFLAGS +=3D $(CFLAGS_xeninclude) =20 diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index 0203138a819a..be6c76d2934b 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -4,6 +4,7 @@ export XEN_IMG_OFFSET :=3D 0x200000 =20 ARCH_LIBS-y +=3D arch/x86/lib/lib.a +ALL_LIBS-y +=3D arch/x86/lib/cpu-policy/lib.a =20 CFLAGS +=3D -DXEN_IMG_OFFSET=3D$(XEN_IMG_OFFSET) =20 diff --git a/xen/arch/x86/lib/Makefile b/xen/arch/x86/lib/Makefile index b9a65c662a56..fe9a27187992 100644 --- a/xen/arch/x86/lib/Makefile +++ b/xen/arch/x86/lib/Makefile @@ -6,3 +6,5 @@ lib-y +=3D generic-hweightl.o lib-y +=3D memcpy.o lib-y +=3D memset.o lib-y +=3D scrub-page.o + +obj-y +=3D cpu-policy/ diff --git a/xen/arch/x86/lib/cpu-policy/Makefile b/xen/arch/x86/lib/cpu-po= licy/Makefile new file mode 100644 index 000000000000..b12cf7836d4c --- /dev/null +++ b/xen/arch/x86/lib/cpu-policy/Makefile @@ -0,0 +1 @@ +include $(srcdir)/Makefile.common diff --git a/xen/arch/x86/lib/cpu-policy/Makefile.common b/xen/arch/x86/lib= /cpu-policy/Makefile.common new file mode 100644 index 000000000000..35475af78048 --- /dev/null +++ b/xen/arch/x86/lib/cpu-policy/Makefile.common @@ -0,0 +1,3 @@ +lib-y +=3D cpuid.o +lib-y +=3D msr.o +lib-y +=3D policy.o diff --git a/xen/lib/x86/cpuid.c b/xen/arch/x86/lib/cpu-policy/cpuid.c similarity index 100% rename from xen/lib/x86/cpuid.c rename to xen/arch/x86/lib/cpu-policy/cpuid.c diff --git a/xen/lib/x86/msr.c b/xen/arch/x86/lib/cpu-policy/msr.c similarity index 100% rename from xen/lib/x86/msr.c rename to xen/arch/x86/lib/cpu-policy/msr.c diff --git a/xen/lib/x86/policy.c b/xen/arch/x86/lib/cpu-policy/policy.c similarity index 100% rename from xen/lib/x86/policy.c rename to xen/arch/x86/lib/cpu-policy/policy.c diff --git a/xen/lib/x86/private.h b/xen/arch/x86/lib/cpu-policy/private.h similarity index 100% rename from xen/lib/x86/private.h rename to xen/arch/x86/lib/cpu-policy/private.h diff --git a/xen/lib/Makefile b/xen/lib/Makefile index efca830d924c..850efeb4c570 100644 --- a/xen/lib/Makefile +++ b/xen/lib/Makefile @@ -1,5 +1,3 @@ -obj-$(CONFIG_X86) +=3D x86/ - lib-y +=3D bsearch.o lib-y +=3D ctors.o lib-y +=3D ctype.o diff --git a/xen/lib/x86/Makefile b/xen/lib/x86/Makefile deleted file mode 100644 index 780ea05db158..000000000000 --- a/xen/lib/x86/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -obj-y +=3D cpuid.o -obj-y +=3D msr.o -obj-y +=3D policy.o From nobody Sat Jan 10 01:15:02 2026 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; 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=1767795507; cv=none; d=zohomail.com; s=zohoarc; b=n/of1IxaolE5VT9VQYVN+2VCYJXrrjQDK6wLYvOz8MJt44Losu3r5cLyoD/VN5cEskVqTHY6KZLujsQXRKoogRPofZNuEA7WAHAc8pzdQozmbiRCfuUHqFMrQdnfXgC2Ipx2TCeilhu+bwAvWAo2FyCDIiCi/nF6nsgeICut0ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767795507; 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=B51kdTgZdEeG/nCjLbcF/Mc90bD2P9ay1J22aYRdGG8=; b=nfX2Hp+3JlP96RQPLVIQJzTs8XFTfTwSIOCaNo4exJk1My3YaB/8XBjpAPKQeezNfnRcCae1GRsEr90bd2JwHXKqAr+VWMKhSERLSrRHYuQxCegou0wgP7g+yMnVd3D4Lxe448UtomisQ6eTDVRcS/AbtYf/NFcYXTvyte/f0qs= 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 1767795507833405.8191157702978; Wed, 7 Jan 2026 06:18:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1196753.1514488 (Exim 4.92) (envelope-from ) id 1vdUMK-0004vg-OK; Wed, 07 Jan 2026 14:18:00 +0000 Received: by outflank-mailman (output) from mailman id 1196753.1514488; Wed, 07 Jan 2026 14:18:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vdUMK-0004vZ-Lj; Wed, 07 Jan 2026 14:18:00 +0000 Received: by outflank-mailman (input) for mailman id 1196753; Wed, 07 Jan 2026 14:17:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vdUMJ-0004vN-4A for xen-devel@lists.xenproject.org; Wed, 07 Jan 2026 14:17:59 +0000 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [2a00:1450:4864:20::32b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a988fb47-ebd3-11f0-b15e-2bf370ae4941; Wed, 07 Jan 2026 15:17:56 +0100 (CET) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4775e891b5eso10088615e9.2 for ; Wed, 07 Jan 2026 06:17:56 -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 5b1f17b1804b1-47d865e3d22sm14836415e9.1.2026.01.07.06.17.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Jan 2026 06:17:55 -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: a988fb47-ebd3-11f0-b15e-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1767795476; x=1768400276; 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=B51kdTgZdEeG/nCjLbcF/Mc90bD2P9ay1J22aYRdGG8=; b=f3LIjd6SMJwA+IGNBXAmpLrn+YRheYtBAzuN45DiYYL7IVV8OgFscxAFO5k8CRT02o /Fdez4RZV5Yea2lqpTnKsMZ1kEwfsw6o0K2tZMsZrpuKkpbOVDUgcjMa0jA2YaqyHMrO UC4iklCG5IljosUSmToaTX959d0KhppOOQTZOzoXQtG7wlXHqnXG8V5aqkja3J45bCjt rN+TzPdux6yBo6ZWU8gwul77dqibkt5JrMYI1xZfXqySkWkoN5K7lHG5fL5tqZXHoQvp ei4R0qmnYt6Ix7Yj8fLdwjdjtAboxvNaC61OcxEfYtnitOgv1FyO+B4WdhXheRX5WvR8 xlkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767795476; x=1768400276; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=B51kdTgZdEeG/nCjLbcF/Mc90bD2P9ay1J22aYRdGG8=; b=b8wFp/NgPl4p2Pgg5ZhSFK7C0R8jBzCwg5e7sqXGd93S7N2oYkZNnDs6MlnxqLLnkJ CRTB535f3wTuwIsCMfEvfLKquiSERVs3zY7Jc/UVzZWi/EIbyoIJJimOPWPaTbHoHR+y nHb9sRDBmq+GBf+DgzMB9A3ST1Xu+MTHKz7sv9flYRZLQCSqDRG0FiutpiupUVutVzOW WVJI/80j9UgbudetkuVmocc39T9GHl9l6/cXhK/ZVSy5EUFXlcnUSC7U2B70xJKXxaZW zLFrAw1JHfWmNYHem6Vr3JsP5lvBLZZyqEtPjCwdBlK4AZmHSlVggdH1f4IwlEsdGrJD aDIg== X-Gm-Message-State: AOJu0YwAdiEMZEN5AM/4zK1Qj8ZafHD4mHxZJCvxTZdlMqjy8QSurYsO 2lBbRK6DSMATP4qiFBXMrtO/v7ojfi2Jkv9IFmSQVxS8WG1phTXEHdQZSBxCPrxjH/JADOgOQaC Vfrg= X-Gm-Gg: AY/fxX79lOum2QiLmySDXBAcO13/iAOgDQEFa4+jIxYVjcygQaSyW9mTwPQe63wUXLG aJWf4S+6eWr7XaX/q8eYbuRRNnrmX6A3dciwN1srcJglReatRJrtt3Y+R8ZAR8SHrgtnrn3pDGV oBbRnfZpq2ha2zp467pmQKHT1Q15ohvdiQOsPK2Rzxe06RkRskxr76yw6OpDDugWQ5RpH8JS5Ie HrD7Jcj0xd6AM9LEwTo1CFdpAWF+2FS4H0qe+NLifkz7dBMWXBqRU1/NT739DY5ywLDIhi1JgVw uEBliFpeE+DaVnIbuMhLrhzoWh+IfTIAth85e/QQVxQ8Rp68zeFw1BdQMYgC+Saz+OBYtYUtnPQ rIm7Y1vEOygg5jjvhmA4VMcB/LK0GajefnBe57MoSBYzG8H17MnV/uXqaR9nwJB4TS2c9t9y61N hLkb1eazMXwKKICWga48me4X5xxzkVwxqX0GXCyGXtGRKfb433/xyefI8jloq2Ja0AYzKapQ50A YE= X-Google-Smtp-Source: AGHT+IHmSoe83rxhwzHPP+KD5pqvo4aJb6x8vD2N1054k/CIKMHmACtTrPmbbUkHsYqblgUcKKFC0A== X-Received: by 2002:a05:600c:1991:b0:477:55c9:c3ea with SMTP id 5b1f17b1804b1-47d84b40aa4mr34943525e9.35.1767795475783; Wed, 07 Jan 2026 06:17:55 -0800 (PST) Message-ID: Date: Wed, 7 Jan 2026 15:17:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/2] x86/cpu-policy: split out copy-in/-out functions From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Penny Zheng References: <4bd68e41-e665-4992-9d3c-0086bb5195ef@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: <4bd68e41-e665-4992-9d3c-0086bb5195ef@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1767795509988158500 Content-Type: text/plain; charset="utf-8" This is to aid with MGMT_HYPERCALL work, leaving the functions potentially unreferenced (which Misra dislikes). By moving them to separate archive members, the linker simply will not pick them up when not needed. As the CPUID and MSR ones are always used together, put the "from" and "to" variants of each together in one file respectively. Signed-off-by: Jan Beulich --- v2: Re-base over moving of the entire directory. --- xen/arch/x86/lib/cpu-policy/Makefile.common | 3 +- .../x86/lib/cpu-policy/copy-from-buffer.c | 238 ++++++++++++++++++ xen/arch/x86/lib/cpu-policy/copy-to-buffer.c | 204 +++++++++++++++ xen/arch/x86/lib/cpu-policy/cpuid.c | 226 ----------------- xen/arch/x86/lib/cpu-policy/msr.c | 130 ---------- xen/arch/x86/lib/cpu-policy/private.h | 31 --- 6 files changed, 444 insertions(+), 388 deletions(-) create mode 100644 xen/arch/x86/lib/cpu-policy/copy-from-buffer.c create mode 100644 xen/arch/x86/lib/cpu-policy/copy-to-buffer.c delete mode 100644 xen/arch/x86/lib/cpu-policy/msr.c diff --git a/xen/arch/x86/lib/cpu-policy/Makefile.common b/xen/arch/x86/lib= /cpu-policy/Makefile.common index 35475af78048..aff662aae83b 100644 --- a/xen/arch/x86/lib/cpu-policy/Makefile.common +++ b/xen/arch/x86/lib/cpu-policy/Makefile.common @@ -1,3 +1,4 @@ +lib-y +=3D copy-from-buffer.o +lib-y +=3D copy-to-buffer.o lib-y +=3D cpuid.o -lib-y +=3D msr.o lib-y +=3D policy.o diff --git a/xen/arch/x86/lib/cpu-policy/copy-from-buffer.c b/xen/arch/x86/= lib/cpu-policy/copy-from-buffer.c new file mode 100644 index 000000000000..24f7bc79d2bd --- /dev/null +++ b/xen/arch/x86/lib/cpu-policy/copy-from-buffer.c @@ -0,0 +1,238 @@ +#ifdef __XEN__ + +#include +#include +#include +#include + +#include + +#define copy_from_buffer_offset copy_from_guest_offset + +#else /* !__XEN__ */ + +#include +#include +#include +#include +#include + +#include + +#include + +#define array_access_nospec(a, i) (a)[(i)] + +/* memcpy(), but with copy_from_guest_offset()'s API. */ +#define copy_from_buffer_offset(dst, src, index, nr) \ +({ \ + const typeof(*(src)) *src_ =3D (src); \ + typeof(*(dst)) *dst_ =3D (dst); \ + typeof(index) index_ =3D (index); \ + typeof(nr) nr_ =3D (nr), i_; \ + \ + for ( i_ =3D 0; i_ < nr_; i_++ ) \ + dst_[i_] =3D src_[index_ + i_]; \ + 0; \ +}) + +#endif /* __XEN__ */ + +#include + +int x86_cpuid_copy_from_buffer(struct cpu_policy *p, + const cpuid_leaf_buffer_t leaves, + uint32_t nr_entries, uint32_t *err_leaf, + uint32_t *err_subleaf) +{ + unsigned int i; + xen_cpuid_leaf_t data; + + if ( err_leaf ) + *err_leaf =3D -1; + if ( err_subleaf ) + *err_subleaf =3D -1; + + /* + * A well formed caller is expected to pass an array with leaves in or= der, + * and without any repetitions. However, due to per-vendor difference= s, + * and in the case of upgrade or levelled scenarios, we typically expe= ct + * fewer than MAX leaves to be passed. + * + * Detecting repeated entries is prohibitively complicated, so we don't + * bother. That said, one way or another if more than MAX leaves are + * passed, something is wrong. + */ + if ( nr_entries > CPUID_MAX_SERIALISED_LEAVES ) + return -E2BIG; + + for ( i =3D 0; i < nr_entries; ++i ) + { + struct cpuid_leaf l; + + if ( copy_from_buffer_offset(&data, leaves, i, 1) ) + return -EFAULT; + + l =3D (struct cpuid_leaf){ data.a, data.b, data.c, data.d }; + + switch ( data.leaf ) + { + case 0 ... ARRAY_SIZE(p->basic.raw) - 1: + switch ( data.leaf ) + { + case 0x4: + if ( data.subleaf >=3D ARRAY_SIZE(p->cache.raw) ) + goto out_of_range; + + array_access_nospec(p->cache.raw, data.subleaf) =3D l; + break; + + case 0x7: + if ( data.subleaf >=3D ARRAY_SIZE(p->feat.raw) ) + goto out_of_range; + + array_access_nospec(p->feat.raw, data.subleaf) =3D l; + break; + + case 0xb: + if ( data.subleaf >=3D ARRAY_SIZE(p->topo.raw) ) + goto out_of_range; + + array_access_nospec(p->topo.raw, data.subleaf) =3D l; + break; + + case 0xd: + if ( data.subleaf >=3D ARRAY_SIZE(p->xstate.raw) ) + goto out_of_range; + + array_access_nospec(p->xstate.raw, data.subleaf) =3D l; + break; + + default: + if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) + goto out_of_range; + + array_access_nospec(p->basic.raw, data.leaf) =3D l; + break; + } + break; + + case 0x40000000: + if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) + goto out_of_range; + + p->hv_limit =3D l.a; + break; + + case 0x40000100: + if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) + goto out_of_range; + + p->hv2_limit =3D l.a; + break; + + case 0x80000000U ... 0x80000000U + ARRAY_SIZE(p->extd.raw) - 1: + if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) + goto out_of_range; + + array_access_nospec(p->extd.raw, data.leaf & 0xffff) =3D l; + break; + + default: + goto out_of_range; + } + } + + x86_cpu_policy_recalc_synth(p); + + return 0; + + out_of_range: + if ( err_leaf ) + *err_leaf =3D data.leaf; + if ( err_subleaf ) + *err_subleaf =3D data.subleaf; + + return -ERANGE; +} + +int x86_msr_copy_from_buffer(struct cpu_policy *p, + const msr_entry_buffer_t msrs, uint32_t nr_en= tries, + uint32_t *err_msr) +{ + unsigned int i; + xen_msr_entry_t data; + int rc; + + if ( err_msr ) + *err_msr =3D -1; + + /* + * A well formed caller is expected to pass an array with entries in + * order, and without any repetitions. However, due to per-vendor + * differences, and in the case of upgrade or levelled scenarios, we + * typically expect fewer than MAX entries to be passed. + * + * Detecting repeated entries is prohibitively complicated, so we don't + * bother. That said, one way or another if more than MAX entries are + * passed, something is wrong. + */ + if ( nr_entries > MSR_MAX_SERIALISED_ENTRIES ) + return -E2BIG; + + for ( i =3D 0; i < nr_entries; i++ ) + { + if ( copy_from_buffer_offset(&data, msrs, i, 1) ) + return -EFAULT; + + if ( data.flags ) /* .flags MBZ */ + { + rc =3D -EINVAL; + goto err; + } + + switch ( data.idx ) + { + /* + * Assign data.val to p->field, checking for truncation if the + * backing storage for field is smaller than uint64_t + */ +#define ASSIGN(field) \ +({ \ + if ( (typeof(p->field))data.val !=3D data.val ) \ + { \ + rc =3D -EOVERFLOW; \ + goto err; \ + } \ + p->field =3D data.val; \ +}) + + case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break; + case MSR_ARCH_CAPABILITIES: ASSIGN(arch_caps.raw); break; + +#undef ASSIGN + + default: + rc =3D -ERANGE; + goto err; + } + } + + return 0; + + err: + if ( err_msr ) + *err_msr =3D data.idx; + + return rc; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/lib/cpu-policy/copy-to-buffer.c b/xen/arch/x86/li= b/cpu-policy/copy-to-buffer.c new file mode 100644 index 000000000000..190dac746cdf --- /dev/null +++ b/xen/arch/x86/lib/cpu-policy/copy-to-buffer.c @@ -0,0 +1,204 @@ +#ifdef __XEN__ + +#include +#include +#include + +#include + +#define copy_to_buffer_offset copy_to_guest_offset + +#else /* !__XEN__ */ + +#include +#include +#include +#include +#include + +#include + +#include + +/* memcpy(), but with copy_to_guest_offset()'s API. */ +#define copy_to_buffer_offset(dst, index, src, nr) \ +({ \ + const typeof(*(src)) *src_ =3D (src); \ + typeof(*(dst)) *dst_ =3D (dst); \ + typeof(index) index_ =3D (index); \ + typeof(nr) nr_ =3D (nr), i_; \ + \ + for ( i_ =3D 0; i_ < nr_; i_++ ) \ + dst_[index_ + i_] =3D src_[i_]; \ + 0; \ +}) + +#endif /* __XEN__ */ + +#include + +/* + * Copy a single cpuid_leaf into a provided xen_cpuid_leaf_t buffer, + * performing boundary checking against the buffer size. + */ +static int copy_leaf_to_buffer(uint32_t leaf, uint32_t subleaf, + const struct cpuid_leaf *data, + cpuid_leaf_buffer_t leaves, + uint32_t *curr_entry, const uint32_t nr_ent= ries) +{ + const xen_cpuid_leaf_t val =3D { + leaf, subleaf, data->a, data->b, data->c, data->d, + }; + + if ( *curr_entry =3D=3D nr_entries ) + return -ENOBUFS; + + if ( copy_to_buffer_offset(leaves, *curr_entry, &val, 1) ) + return -EFAULT; + + ++*curr_entry; + + return 0; +} + +int x86_cpuid_copy_to_buffer(const struct cpu_policy *p, + cpuid_leaf_buffer_t leaves, uint32_t *nr_entr= ies_p) +{ + const uint32_t nr_entries =3D *nr_entries_p; + uint32_t curr_entry =3D 0, leaf, subleaf; + +#define COPY_LEAF(l, s, data) \ + ({ \ + int ret; \ + \ + if ( (ret =3D copy_leaf_to_buffer( \ + l, s, data, leaves, &curr_entry, nr_entries)) ) \ + return ret; \ + }) + + /* Basic leaves. */ + for ( leaf =3D 0; leaf <=3D MIN(p->basic.max_leaf, + ARRAY_SIZE(p->basic.raw) - 1); ++leaf ) + { + switch ( leaf ) + { + case 0x4: + for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->cache.raw); ++sub= leaf ) + { + COPY_LEAF(leaf, subleaf, &p->cache.raw[subleaf]); + + if ( p->cache.subleaf[subleaf].type =3D=3D 0 ) + break; + } + break; + + case 0x7: + for ( subleaf =3D 0; + subleaf <=3D MIN(p->feat.max_subleaf, + ARRAY_SIZE(p->feat.raw) - 1); ++subleaf ) + COPY_LEAF(leaf, subleaf, &p->feat.raw[subleaf]); + break; + + case 0xb: + for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->topo.raw); ++subl= eaf ) + { + COPY_LEAF(leaf, subleaf, &p->topo.raw[subleaf]); + + if ( p->topo.subleaf[subleaf].type =3D=3D 0 ) + break; + } + break; + + case 0xd: + { + uint64_t xstates =3D cpu_policy_xstates(p); + + COPY_LEAF(leaf, 0, &p->xstate.raw[0]); + COPY_LEAF(leaf, 1, &p->xstate.raw[1]); + + for ( xstates >>=3D 2, subleaf =3D 2; + xstates && subleaf < ARRAY_SIZE(p->xstate.raw); + xstates >>=3D 1, ++subleaf ) + COPY_LEAF(leaf, subleaf, &p->xstate.raw[subleaf]); + break; + } + + default: + COPY_LEAF(leaf, XEN_CPUID_NO_SUBLEAF, &p->basic.raw[leaf]); + break; + } + } + + /* TODO: Port Xen and Viridian leaves to the new CPUID infrastructure.= */ + COPY_LEAF(0x40000000, XEN_CPUID_NO_SUBLEAF, + &(struct cpuid_leaf){ p->hv_limit }); + COPY_LEAF(0x40000100, XEN_CPUID_NO_SUBLEAF, + &(struct cpuid_leaf){ p->hv2_limit }); + + /* Extended leaves. */ + for ( leaf =3D 0; leaf <=3D MIN(p->extd.max_leaf & 0xffffUL, + ARRAY_SIZE(p->extd.raw) - 1); ++leaf ) + COPY_LEAF(0x80000000U | leaf, XEN_CPUID_NO_SUBLEAF, &p->extd.raw[l= eaf]); + +#undef COPY_LEAF + + *nr_entries_p =3D curr_entry; + + return 0; +} + +/* + * Copy a single MSR into the provided msr_entry_buffer_t buffer, performi= ng a + * boundary check against the buffer size. + */ +static int copy_msr_to_buffer(uint32_t idx, uint64_t val, + msr_entry_buffer_t msrs, + uint32_t *curr_entry, const uint32_t nr_entr= ies) +{ + const xen_msr_entry_t ent =3D { .idx =3D idx, .val =3D val }; + + if ( *curr_entry =3D=3D nr_entries ) + return -ENOBUFS; + + if ( copy_to_buffer_offset(msrs, *curr_entry, &ent, 1) ) + return -EFAULT; + + ++*curr_entry; + + return 0; +} + +int x86_msr_copy_to_buffer(const struct cpu_policy *p, + msr_entry_buffer_t msrs, uint32_t *nr_entries_p) +{ + const uint32_t nr_entries =3D *nr_entries_p; + uint32_t curr_entry =3D 0; + +#define COPY_MSR(idx, val) \ + ({ \ + int ret; \ + \ + if ( (ret =3D copy_msr_to_buffer( \ + idx, val, msrs, &curr_entry, nr_entries)) ) \ + return ret; \ + }) + + COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw); + COPY_MSR(MSR_ARCH_CAPABILITIES, p->arch_caps.raw); + +#undef COPY_MSR + + *nr_entries_p =3D curr_entry; + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/lib/cpu-policy/cpuid.c b/xen/arch/x86/lib/cpu-pol= icy/cpuid.c index 6298d051f2a6..3162e795bc21 100644 --- a/xen/arch/x86/lib/cpu-policy/cpuid.c +++ b/xen/arch/x86/lib/cpu-policy/cpuid.c @@ -322,232 +322,6 @@ const uint32_t *x86_cpu_policy_lookup_deep_deps(uint3= 2_t feature) return NULL; } =20 -/* - * Copy a single cpuid_leaf into a provided xen_cpuid_leaf_t buffer, - * performing boundary checking against the buffer size. - */ -static int copy_leaf_to_buffer(uint32_t leaf, uint32_t subleaf, - const struct cpuid_leaf *data, - cpuid_leaf_buffer_t leaves, - uint32_t *curr_entry, const uint32_t nr_ent= ries) -{ - const xen_cpuid_leaf_t val =3D { - leaf, subleaf, data->a, data->b, data->c, data->d, - }; - - if ( *curr_entry =3D=3D nr_entries ) - return -ENOBUFS; - - if ( copy_to_buffer_offset(leaves, *curr_entry, &val, 1) ) - return -EFAULT; - - ++*curr_entry; - - return 0; -} - -int x86_cpuid_copy_to_buffer(const struct cpu_policy *p, - cpuid_leaf_buffer_t leaves, uint32_t *nr_entr= ies_p) -{ - const uint32_t nr_entries =3D *nr_entries_p; - uint32_t curr_entry =3D 0, leaf, subleaf; - -#define COPY_LEAF(l, s, data) \ - ({ \ - int ret; \ - \ - if ( (ret =3D copy_leaf_to_buffer( \ - l, s, data, leaves, &curr_entry, nr_entries)) ) \ - return ret; \ - }) - - /* Basic leaves. */ - for ( leaf =3D 0; leaf <=3D MIN(p->basic.max_leaf, - ARRAY_SIZE(p->basic.raw) - 1); ++leaf ) - { - switch ( leaf ) - { - case 0x4: - for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->cache.raw); ++sub= leaf ) - { - COPY_LEAF(leaf, subleaf, &p->cache.raw[subleaf]); - - if ( p->cache.subleaf[subleaf].type =3D=3D 0 ) - break; - } - break; - - case 0x7: - for ( subleaf =3D 0; - subleaf <=3D MIN(p->feat.max_subleaf, - ARRAY_SIZE(p->feat.raw) - 1); ++subleaf ) - COPY_LEAF(leaf, subleaf, &p->feat.raw[subleaf]); - break; - - case 0xb: - for ( subleaf =3D 0; subleaf < ARRAY_SIZE(p->topo.raw); ++subl= eaf ) - { - COPY_LEAF(leaf, subleaf, &p->topo.raw[subleaf]); - - if ( p->topo.subleaf[subleaf].type =3D=3D 0 ) - break; - } - break; - - case 0xd: - { - uint64_t xstates =3D cpu_policy_xstates(p); - - COPY_LEAF(leaf, 0, &p->xstate.raw[0]); - COPY_LEAF(leaf, 1, &p->xstate.raw[1]); - - for ( xstates >>=3D 2, subleaf =3D 2; - xstates && subleaf < ARRAY_SIZE(p->xstate.raw); - xstates >>=3D 1, ++subleaf ) - COPY_LEAF(leaf, subleaf, &p->xstate.raw[subleaf]); - break; - } - - default: - COPY_LEAF(leaf, XEN_CPUID_NO_SUBLEAF, &p->basic.raw[leaf]); - break; - } - } - - /* TODO: Port Xen and Viridian leaves to the new CPUID infrastructure.= */ - COPY_LEAF(0x40000000, XEN_CPUID_NO_SUBLEAF, - &(struct cpuid_leaf){ p->hv_limit }); - COPY_LEAF(0x40000100, XEN_CPUID_NO_SUBLEAF, - &(struct cpuid_leaf){ p->hv2_limit }); - - /* Extended leaves. */ - for ( leaf =3D 0; leaf <=3D MIN(p->extd.max_leaf & 0xffffUL, - ARRAY_SIZE(p->extd.raw) - 1); ++leaf ) - COPY_LEAF(0x80000000U | leaf, XEN_CPUID_NO_SUBLEAF, &p->extd.raw[l= eaf]); - -#undef COPY_LEAF - - *nr_entries_p =3D curr_entry; - - return 0; -} - -int x86_cpuid_copy_from_buffer(struct cpu_policy *p, - const cpuid_leaf_buffer_t leaves, - uint32_t nr_entries, uint32_t *err_leaf, - uint32_t *err_subleaf) -{ - unsigned int i; - xen_cpuid_leaf_t data; - - if ( err_leaf ) - *err_leaf =3D -1; - if ( err_subleaf ) - *err_subleaf =3D -1; - - /* - * A well formed caller is expected to pass an array with leaves in or= der, - * and without any repetitions. However, due to per-vendor difference= s, - * and in the case of upgrade or levelled scenarios, we typically expe= ct - * fewer than MAX leaves to be passed. - * - * Detecting repeated entries is prohibitively complicated, so we don't - * bother. That said, one way or another if more than MAX leaves are - * passed, something is wrong. - */ - if ( nr_entries > CPUID_MAX_SERIALISED_LEAVES ) - return -E2BIG; - - for ( i =3D 0; i < nr_entries; ++i ) - { - struct cpuid_leaf l; - - if ( copy_from_buffer_offset(&data, leaves, i, 1) ) - return -EFAULT; - - l =3D (struct cpuid_leaf){ data.a, data.b, data.c, data.d }; - - switch ( data.leaf ) - { - case 0 ... ARRAY_SIZE(p->basic.raw) - 1: - switch ( data.leaf ) - { - case 0x4: - if ( data.subleaf >=3D ARRAY_SIZE(p->cache.raw) ) - goto out_of_range; - - array_access_nospec(p->cache.raw, data.subleaf) =3D l; - break; - - case 0x7: - if ( data.subleaf >=3D ARRAY_SIZE(p->feat.raw) ) - goto out_of_range; - - array_access_nospec(p->feat.raw, data.subleaf) =3D l; - break; - - case 0xb: - if ( data.subleaf >=3D ARRAY_SIZE(p->topo.raw) ) - goto out_of_range; - - array_access_nospec(p->topo.raw, data.subleaf) =3D l; - break; - - case 0xd: - if ( data.subleaf >=3D ARRAY_SIZE(p->xstate.raw) ) - goto out_of_range; - - array_access_nospec(p->xstate.raw, data.subleaf) =3D l; - break; - - default: - if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) - goto out_of_range; - - array_access_nospec(p->basic.raw, data.leaf) =3D l; - break; - } - break; - - case 0x40000000: - if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) - goto out_of_range; - - p->hv_limit =3D l.a; - break; - - case 0x40000100: - if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) - goto out_of_range; - - p->hv2_limit =3D l.a; - break; - - case 0x80000000U ... 0x80000000U + ARRAY_SIZE(p->extd.raw) - 1: - if ( data.subleaf !=3D XEN_CPUID_NO_SUBLEAF ) - goto out_of_range; - - array_access_nospec(p->extd.raw, data.leaf & 0xffff) =3D l; - break; - - default: - goto out_of_range; - } - } - - x86_cpu_policy_recalc_synth(p); - - return 0; - - out_of_range: - if ( err_leaf ) - *err_leaf =3D data.leaf; - if ( err_subleaf ) - *err_subleaf =3D data.subleaf; - - return -ERANGE; -} - /* * Local variables: * mode: C diff --git a/xen/arch/x86/lib/cpu-policy/msr.c b/xen/arch/x86/lib/cpu-polic= y/msr.c deleted file mode 100644 index e04b9ca01302..000000000000 --- a/xen/arch/x86/lib/cpu-policy/msr.c +++ /dev/null @@ -1,130 +0,0 @@ -#include "private.h" - -#include - -/* - * Copy a single MSR into the provided msr_entry_buffer_t buffer, performi= ng a - * boundary check against the buffer size. - */ -static int copy_msr_to_buffer(uint32_t idx, uint64_t val, - msr_entry_buffer_t msrs, - uint32_t *curr_entry, const uint32_t nr_entr= ies) -{ - const xen_msr_entry_t ent =3D { .idx =3D idx, .val =3D val }; - - if ( *curr_entry =3D=3D nr_entries ) - return -ENOBUFS; - - if ( copy_to_buffer_offset(msrs, *curr_entry, &ent, 1) ) - return -EFAULT; - - ++*curr_entry; - - return 0; -} - -int x86_msr_copy_to_buffer(const struct cpu_policy *p, - msr_entry_buffer_t msrs, uint32_t *nr_entries_p) -{ - const uint32_t nr_entries =3D *nr_entries_p; - uint32_t curr_entry =3D 0; - -#define COPY_MSR(idx, val) \ - ({ \ - int ret; \ - \ - if ( (ret =3D copy_msr_to_buffer( \ - idx, val, msrs, &curr_entry, nr_entries)) ) \ - return ret; \ - }) - - COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw); - COPY_MSR(MSR_ARCH_CAPABILITIES, p->arch_caps.raw); - -#undef COPY_MSR - - *nr_entries_p =3D curr_entry; - - return 0; -} - -int x86_msr_copy_from_buffer(struct cpu_policy *p, - const msr_entry_buffer_t msrs, uint32_t nr_en= tries, - uint32_t *err_msr) -{ - unsigned int i; - xen_msr_entry_t data; - int rc; - - if ( err_msr ) - *err_msr =3D -1; - - /* - * A well formed caller is expected to pass an array with entries in - * order, and without any repetitions. However, due to per-vendor - * differences, and in the case of upgrade or levelled scenarios, we - * typically expect fewer than MAX entries to be passed. - * - * Detecting repeated entries is prohibitively complicated, so we don't - * bother. That said, one way or another if more than MAX entries are - * passed, something is wrong. - */ - if ( nr_entries > MSR_MAX_SERIALISED_ENTRIES ) - return -E2BIG; - - for ( i =3D 0; i < nr_entries; i++ ) - { - if ( copy_from_buffer_offset(&data, msrs, i, 1) ) - return -EFAULT; - - if ( data.flags ) /* .flags MBZ */ - { - rc =3D -EINVAL; - goto err; - } - - switch ( data.idx ) - { - /* - * Assign data.val to p->field, checking for truncation if the - * backing storage for field is smaller than uint64_t - */ -#define ASSIGN(field) \ -({ \ - if ( (typeof(p->field))data.val !=3D data.val ) \ - { \ - rc =3D -EOVERFLOW; \ - goto err; \ - } \ - p->field =3D data.val; \ -}) - - case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break; - case MSR_ARCH_CAPABILITIES: ASSIGN(arch_caps.raw); break; - -#undef ASSIGN - - default: - rc =3D -ERANGE; - goto err; - } - } - - return 0; - - err: - if ( err_msr ) - *err_msr =3D data.idx; - - return rc; -} - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/xen/arch/x86/lib/cpu-policy/private.h b/xen/arch/x86/lib/cpu-p= olicy/private.h index aedd8e482121..57f254c3e917 100644 --- a/xen/arch/x86/lib/cpu-policy/private.h +++ b/xen/arch/x86/lib/cpu-policy/private.h @@ -12,9 +12,6 @@ =20 #include =20 -#define copy_to_buffer_offset copy_to_guest_offset -#define copy_from_buffer_offset copy_from_guest_offset - #else =20 #include @@ -35,34 +32,6 @@ static inline bool test_bit(unsigned int bit, const void= *vaddr) return addr[bit / 8] & (1u << (bit % 8)); } =20 -#define array_access_nospec(a, i) (a)[(i)] - -/* memcpy(), but with copy_to_guest_offset()'s API. */ -#define copy_to_buffer_offset(dst, index, src, nr) \ -({ \ - const typeof(*(src)) *src_ =3D (src); \ - typeof(*(dst)) *dst_ =3D (dst); \ - typeof(index) index_ =3D (index); \ - typeof(nr) nr_ =3D (nr), i_; \ - \ - for ( i_ =3D 0; i_ < nr_; i_++ ) \ - dst_[index_ + i_] =3D src_[i_]; \ - 0; \ -}) - -/* memcpy(), but with copy_from_guest_offset()'s API. */ -#define copy_from_buffer_offset(dst, src, index, nr) \ -({ \ - const typeof(*(src)) *src_ =3D (src); \ - typeof(*(dst)) *dst_ =3D (dst); \ - typeof(index) index_ =3D (index); \ - typeof(nr) nr_ =3D (nr), i_; \ - \ - for ( i_ =3D 0; i_ < nr_; i_++ ) \ - dst_[i_] =3D src_[index_ + i_]; \ - 0; \ -}) - #endif /* __XEN__ */ =20 #endif /* XEN_LIB_X86_PRIVATE_H */