From patchwork Tue Dec 20 01:07:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 217A3C4332F for ; Tue, 20 Dec 2022 01:10:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466400.725290 (Exim 4.92) (envelope-from ) id 1p7R9J-0004nG-Pr; Tue, 20 Dec 2022 01:10:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466400.725290; Tue, 20 Dec 2022 01:10:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9J-0004mD-JF; Tue, 20 Dec 2022 01:10:29 +0000 Received: by outflank-mailman (input) for mailman id 466400; Tue, 20 Dec 2022 01:10:28 +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 1p7R9I-0004iO-Gf for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:28 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 14dc3411-8003-11ed-91b6-6bf2151ebd3b; Tue, 20 Dec 2022 02:10:26 +0100 (CET) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id EF040320095A; Mon, 19 Dec 2022 20:10:22 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 19 Dec 2022 20:10:23 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:21 -0500 (EST) 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: 14dc3411-8003-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1671498622; x=1671585022; bh=T3JB3kL6ns TUfVOdUZ48s4PCkZspjbxgDHHV7LQWbjM=; b=JD/+FaE7fJs6j5TeETViAu3l81 nb/iVzkvbBw0JleHTMfCG/YLM80D1AmU1YJeD3carbL/kH7aseLVbQBQSBgfytJk MH9oC7tlPpZA1hRnokeNjaMD3oCH6XX/K6VrMKG+pyJumqPWbcyYfeCVfYreFJ/E 3PkF0UVWNxKNMV3fgG//baOeH3pJHxHoexIuyMi+keOOaNFFaFH/Jd3GZlgscLZv QUpg7AZrGOgC30+KZglKCJKLBureW64uvRTCpUkl2vzw0ueDV2/njcLu57+mEZQP htp7kwGLM2ClRZmSpisZOE5jdFFSPfvztgzqVF9jijQYMgw269C1ixHe/vRA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1671498622; x= 1671585022; bh=T3JB3kL6nsTUfVOdUZ48s4PCkZspjbxgDHHV7LQWbjM=; b=C LlC9TzLfpW5gg2BzEXfKcpiTjcURzlgOwpX09d8th9nQ6agEIVNeDnY9bselE0AW fwOitWW0OFnrgSY8mDxAxBqMIR2PtIfsC3pvaz6hcbarcYZfUeWeGSjR8D0ZRGNw kSb18jBiA3UmAySSD1Q9980NM/PpeVC7iaB68EdIAlx4zdmaB1vjdg9FQRnk1VS3 s6MoytsYclb2MvFplmoMmWIAciUH0S6hUX7eaH2hTnEMTGxGSLfxmKAymnk0cO8J fI2UqQViTeCQLMJNV4kPw1HU98Im3dn7ZGfDpnIF2Xzo0GbdnkqbWovd1fmlwa7Y jPZ5EQSwXALUoQbGhbTrg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepledukeelleejkeevkeefgefhffeg vdeigeelieegjefffeeiveeivdejgeevteeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 01/10] x86: Add memory type constants Date: Mon, 19 Dec 2022 20:07:03 -0500 Message-Id: <704c1437341e70e0cd1d652e7681a2947a5c8969.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 These are not currently used, so there is no functional change. Future patches will use these constants. Suggested-by: Andrew Cooper Signed-off-by: Demi Marie Obenour Acked-by: Jan Beulich --- Changes since v4: - Add Jan Beulich’s Acked-by Changes since v3: - Name the reserved values X86_MT_RSVD_2 and X86_MT_RSVD_3, to match the architectural values of 0x02 and 0x03. Changes since v2: - Avoid using _AC where not required. - Define reserved memory types inline --- xen/arch/x86/include/asm/x86-defns.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/x86/include/asm/x86-defns.h b/xen/arch/x86/include/asm/x86-defns.h index 28628807cb9897cf6fa8e266f71f5f220813984d..42b5f382d438d21ac97b6438e8c810c7b964cf6d 100644 --- a/xen/arch/x86/include/asm/x86-defns.h +++ b/xen/arch/x86/include/asm/x86-defns.h @@ -153,4 +153,15 @@ (1u << X86_EXC_AC) | (1u << X86_EXC_CP) | \ (1u << X86_EXC_VC) | (1u << X86_EXC_SX)) +/* Memory types */ +#define X86_MT_UC 0x00 /* uncachable */ +#define X86_MT_WC 0x01 /* write-combined */ +#define X86_MT_RSVD_2 0x02 /* reserved */ +#define X86_MT_RSVD_3 0x03 /* reserved */ +#define X86_MT_WT 0x04 /* write-through */ +#define X86_MT_WP 0x05 /* write-protect */ +#define X86_MT_WB 0x06 /* write-back */ +#define X86_MT_UCM 0x07 /* UC- */ +#define X86_NUM_MT 0x08 + #endif /* __XEN_X86_DEFNS_H__ */ From patchwork Tue Dec 20 01:07:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13232C001B2 for ; Tue, 20 Dec 2022 01:10:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466399.725284 (Exim 4.92) (envelope-from ) id 1p7R9J-0004in-DI; Tue, 20 Dec 2022 01:10:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466399.725284; Tue, 20 Dec 2022 01:10:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9J-0004ig-A7; Tue, 20 Dec 2022 01:10:29 +0000 Received: by outflank-mailman (input) for mailman id 466399; Tue, 20 Dec 2022 01:10:28 +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 1p7R9I-0004T7-7x for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:28 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 162de5f6-8003-11ed-8fd4-01056ac49cbb; Tue, 20 Dec 2022 02:10:27 +0100 (CET) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 327673200920; Mon, 19 Dec 2022 20:10:25 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Dec 2022 20:10:26 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:24 -0500 (EST) 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: 162de5f6-8003-11ed-8fd4-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498624; x=1671585024; bh=lFzZnM+/36X+U2Bz3srDM/CbhK+VJ5H9+Eg QROq3rOc=; b=iA9XJxccY2qqzS10W2SYmjCC3UMj5C2JQwLrsXD96iUGXFY4Mds FPRuqztrlcGpNw/5+bhkI46ixbHLkcsgurVus+XepkPpEmrolttmR/Te/OF4nnX3 0cWYKJVa/0gT2c7Hf2MEWTnQ8PL/OnMW6nucA85uvEjHeLh/AMy+5GybxN8Jl9MF j4L8Z0vuoa9KnWaoZ1mg/xem00QXBVYEAt/mhBQ0XGMnFsWIIuExrDZpRCJlhEUg +RUj6SAVrOgLvK/UjKcZZraUKy7V2PRlxopMS6zLaSbwtXlqmxp7QVaEukjWnxFZ 1zHiSEKB8V+rm80QK/G+kanGEbrmMxtxWFA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498624; x=1671585024; bh=lFzZnM+/36X+U 2Bz3srDM/CbhK+VJ5H9+EgQROq3rOc=; b=aKsXSSeAszrVsf8DcxvcP8u1V4yC3 dZVvfL9G7nCXU9oyNTBaTjby+uiDwTzjQRA0j3e6igozQ2RL1PeeJM8yzcP08mLP TIahCl6NC2Fn00BhryORgWbY9y6PFcBO3a8FFaNZByI1ljaIIN/RvfouB8QTF9Xb LShnAYADb6jRP6yFcOk6i6JD0EoNF2c6EK4Rgcpg8Rl+SIQ6Fzy+VUuLKCrl3McV RHlPVJ/5YprxQdD7y4rS2NZqnrk3R/jBW2L1jT1lzMd6NOH8iAre3qO1pP/tX0FX iQObTREmD7KQOLRSm5RrFQLoqMV7Sai0iIoSycp1kO+TbjdtSiueCz4Hw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 02/10] x86/mm: Avoid hard-coding PAT in get_page_from_l1e() Date: Mon, 19 Dec 2022 20:07:04 -0500 Message-Id: <0026e56a0c91cb0dde9fe19200f473d720a9a950.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 get_page_from_l1e() relied on Xen's choice of PAT, which is brittle in the face of future PAT changes. Instead, compute the actual cacheability used by the CPU and switch on that, as this will work no matter what PAT Xen uses. No functional change intended. This code is itself questionable and may be removed in the future, but removing it would be an observable behavior change and so is out of scope for this patch series. Signed-off-by: Demi Marie Obenour Reviewed-by: Jan Beulich --- Changes since v4: - Do not add new pte_flags_to_cacheability() helper, as this code may be removed in the near future and so adding a new helper for it is a bad idea. - Do not BUG() in the event of an unexpected cacheability. This cannot happen, but it is simpler to force such types to UC than to prove that the BUG() is not reachable. Changes since v3: - Compute and use the actual cacheability as seen by the processor. Changes since v2: - Improve commit message. --- xen/arch/x86/mm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 78b1972e4170cacccc9c37c6e64e76e66a7da87f..dba6c77ef2f7ed7fcb7f7e526583ccadd35e62cc 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -959,14 +959,16 @@ get_page_from_l1e( flip = _PAGE_RW; } - switch ( l1f & PAGE_CACHE_ATTRS ) + switch ( 0xFF & (XEN_MSR_PAT >> (8 * pte_flags_to_cacheattr(l1f))) ) { - case 0: /* WB */ - flip |= _PAGE_PWT | _PAGE_PCD; + case X86_MT_UC: + case X86_MT_UCM: + case X86_MT_WC: + /* not cacheable */ break; - case _PAGE_PWT: /* WT */ - case _PAGE_PWT | _PAGE_PAT: /* WP */ - flip |= _PAGE_PCD | (l1f & _PAGE_PAT); + default: + /* cacheable */ + flip |= ((l1f & PAGE_CACHE_ATTRS) ^ _PAGE_UC); break; } From patchwork Tue Dec 20 01:07:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23715C4167B for ; Tue, 20 Dec 2022 01:10:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466401.725306 (Exim 4.92) (envelope-from ) id 1p7R9N-0005H0-0T; Tue, 20 Dec 2022 01:10:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466401.725306; Tue, 20 Dec 2022 01:10:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9M-0005Gp-Tb; Tue, 20 Dec 2022 01:10:32 +0000 Received: by outflank-mailman (input) for mailman id 466401; Tue, 20 Dec 2022 01:10:31 +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 1p7R9L-0004iO-5X for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:31 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 17934ca8-8003-11ed-91b6-6bf2151ebd3b; Tue, 20 Dec 2022 02:10:29 +0100 (CET) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8376C3200926; Mon, 19 Dec 2022 20:10:27 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 19 Dec 2022 20:10:28 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:26 -0500 (EST) 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: 17934ca8-8003-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498627; x=1671585027; bh=xq/7AzYNw/o1jMOYl29ZQus5z/RisXCH6hV d+SD7smw=; b=w6ZJflAbxkhdp8rDHDXWmdvSz4uBmkwowpG8PYBa8iIKBzQM4t2 Fcr16poTZcocLz+nrGjF+xN1QLqixuJRXfEQnBTpdjA0J1Z7DQdgLb1XYBI6SLYi k5xAs+1Tqxs6lvsn0o3Goxl2pPJsJ5xZACq4Z7zUsVsl4hXNdYmn8fMLSOOOADCC wt9qaVQnTiItanuHk7Pt+sJLlvkXMB3krK3r04r1lxMB6Mj93PaZTGk5+BPrFdkw +QwFngO0Dy8YzlIZ5PSxdd6hT0LQOf/ZRQRispPIiRKiVs/fBISHXMijVNJQcPp4 vp0bZPmL/zADTu3uz68PmIGA44ztTQvJHMQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498627; x=1671585027; bh=xq/7AzYNw/o1j MOYl29ZQus5z/RisXCH6hVd+SD7smw=; b=PMhID3NSx7nNQ6pxF3MuStWV2Jch5 d07Ge2mNppeHwkyGlCOB478ncUCsdyxWoQfyAm37/7PU7HPoeqxMSw27bUJv1A54 J4JqoXY2xwgg5XrrBrfDdAO6QAOJQh29k4ylXGDg0a3VYEAX9MAMzNEKqy9VUK3c nXApj9nnFUcXv9FMaPftHiDkbTlRBaOaRPzWyXzok1Wjfd6icV/GLvZXsKeBijY8 BzX4OWZTd990wb20X8JbuxnPaql7XzaYlwQ5AjDuQv8/DcfKuhhyvPo08DmtN37P zGCGrIYLEWJdoloJZBBrrXxM5aiN0uCa5cNWlngO5cNzQqGTVK2inn5hA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeefkeelveethfeuffetvdeigeduteev geffhfekieettdfhuedtvdduteetgffftdenucffohhmrghinhephhhvmhdrihhsnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepuggvmhhisehi nhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 03/10] x86: Replace PAT_* with X86_MT_* Date: Mon, 19 Dec 2022 20:07:05 -0500 Message-Id: <0608bf920678c774477cc64de4d536c9f2d75924.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 This allows eliminating the former. Suggested-by: Andrew Cooper Signed-off-by: Demi Marie Obenour Reviewed-by: Jan Beulich --- Changes since v2: Style adjustments --- xen/arch/x86/hvm/hvm.c | 12 ++++---- xen/arch/x86/hvm/mtrr.c | 52 ++++++++++++++++----------------- xen/arch/x86/hvm/vmx/vmx.c | 16 +++++----- xen/arch/x86/include/asm/mtrr.h | 12 +------- xen/arch/x86/mm/p2m-ept.c | 4 +-- xen/arch/x86/mm/shadow/multi.c | 4 +-- 6 files changed, 45 insertions(+), 55 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index ae4368ec4b338cf8c6cb14d383f612c91c98e800..00b3fa56e25e2934e2870e11fd19b120daff2715 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -307,12 +307,12 @@ int hvm_set_guest_pat(struct vcpu *v, uint64_t guest_pat) for ( i = 0, tmp = guest_pat; i < 8; i++, tmp >>= 8 ) switch ( tmp & 0xff ) { - case PAT_TYPE_UC_MINUS: - case PAT_TYPE_UNCACHABLE: - case PAT_TYPE_WRBACK: - case PAT_TYPE_WRCOMB: - case PAT_TYPE_WRPROT: - case PAT_TYPE_WRTHROUGH: + case X86_MT_UCM: + case X86_MT_UC: + case X86_MT_WB: + case X86_MT_WC: + case X86_MT_WP: + case X86_MT_WT: break; default: return 0; diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 4d2aa6def86de45aeeaade7a1a7815c5ef2b3d7a..242623f3c239ee18a44f882ecb3910a00c615825 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -37,7 +37,7 @@ static const uint8_t pat_entry_2_pte_flags[8] = { _PAGE_PAT | _PAGE_PCD, _PAGE_PAT | _PAGE_PCD | _PAGE_PWT }; /* Effective mm type lookup table, according to MTRR and PAT. */ -static const uint8_t mm_type_tbl[MTRR_NUM_TYPES][PAT_TYPE_NUMS] = { +static const uint8_t mm_type_tbl[MTRR_NUM_TYPES][X86_NUM_MT] = { #define RS MEMORY_NUM_TYPES #define UC MTRR_TYPE_UNCACHABLE #define WB MTRR_TYPE_WRBACK @@ -72,8 +72,8 @@ static uint8_t __read_mostly mtrr_epat_tbl[MTRR_NUM_TYPES][MEMORY_NUM_TYPES] = }; /* Lookup table for PAT entry of a given PAT value in host PAT. */ -static uint8_t __read_mostly pat_entry_tbl[PAT_TYPE_NUMS] = - { [0 ... PAT_TYPE_NUMS-1] = INVALID_MEM_TYPE }; +static uint8_t __read_mostly pat_entry_tbl[X86_NUM_MT] = + { [0 ... X86_NUM_MT - 1] = INVALID_MEM_TYPE }; static int __init cf_check hvm_mtrr_pat_init(void) { @@ -81,7 +81,7 @@ static int __init cf_check hvm_mtrr_pat_init(void) for ( i = 0; i < MTRR_NUM_TYPES; i++ ) { - for ( j = 0; j < PAT_TYPE_NUMS; j++ ) + for ( j = 0; j < X86_NUM_MT; j++ ) { unsigned int tmp = mm_type_tbl[i][j]; @@ -90,9 +90,9 @@ static int __init cf_check hvm_mtrr_pat_init(void) } } - for ( i = 0; i < PAT_TYPE_NUMS; i++ ) + for ( i = 0; i < X86_NUM_MT; i++ ) { - for ( j = 0; j < PAT_TYPE_NUMS; j++ ) + for ( j = 0; j < X86_NUM_MT; j++ ) { if ( pat_cr_2_paf(XEN_MSR_PAT, j) == i ) { @@ -115,7 +115,7 @@ uint8_t pat_type_2_pte_flags(uint8_t pat_type) * given pat_type. If host PAT covers all the PAT types, it can't happen. */ if ( unlikely(pat_entry == INVALID_MEM_TYPE) ) - pat_entry = pat_entry_tbl[PAT_TYPE_UNCACHABLE]; + pat_entry = pat_entry_tbl[X86_MT_UC]; return pat_entry_2_pte_flags[pat_entry]; } @@ -145,14 +145,14 @@ int hvm_vcpu_cacheattr_init(struct vcpu *v) m->mtrr_cap = (1u << 10) | (1u << 8) | num_var_ranges; v->arch.hvm.pat_cr = - ((uint64_t)PAT_TYPE_WRBACK) | /* PAT0: WB */ - ((uint64_t)PAT_TYPE_WRTHROUGH << 8) | /* PAT1: WT */ - ((uint64_t)PAT_TYPE_UC_MINUS << 16) | /* PAT2: UC- */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 24) | /* PAT3: UC */ - ((uint64_t)PAT_TYPE_WRBACK << 32) | /* PAT4: WB */ - ((uint64_t)PAT_TYPE_WRTHROUGH << 40) | /* PAT5: WT */ - ((uint64_t)PAT_TYPE_UC_MINUS << 48) | /* PAT6: UC- */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 56); /* PAT7: UC */ + ((uint64_t)X86_MT_WB) | /* PAT0: WB */ + ((uint64_t)X86_MT_WT << 8) | /* PAT1: WT */ + ((uint64_t)X86_MT_UCM << 16) | /* PAT2: UC- */ + ((uint64_t)X86_MT_UC << 24) | /* PAT3: UC */ + ((uint64_t)X86_MT_WB << 32) | /* PAT4: WB */ + ((uint64_t)X86_MT_WT << 40) | /* PAT5: WT */ + ((uint64_t)X86_MT_UCM << 48) | /* PAT6: UC- */ + ((uint64_t)X86_MT_UC << 56); /* PAT7: UC */ if ( is_hardware_domain(v->domain) ) { @@ -356,7 +356,7 @@ uint32_t get_pat_flags(struct vcpu *v, */ pat_entry_value = mtrr_epat_tbl[shadow_mtrr_type][guest_eff_mm_type]; /* If conflit occurs(e.g host MTRR is UC, guest memory type is - * WB),set UC as effective memory. Here, returning PAT_TYPE_UNCACHABLE will + * WB), set UC as effective memory. Here, returning X86_MT_UC will * always set effective memory as UC. */ if ( pat_entry_value == INVALID_MEM_TYPE ) @@ -371,7 +371,7 @@ uint32_t get_pat_flags(struct vcpu *v, "because the host mtrr type is:%d\n", gl1e_flags, (uint64_t)gpaddr, guest_eff_mm_type, shadow_mtrr_type); - pat_entry_value = PAT_TYPE_UNCACHABLE; + pat_entry_value = X86_MT_UC; } /* 4. Get the pte flags */ return pat_type_2_pte_flags(pat_entry_value); @@ -620,13 +620,13 @@ int hvm_set_mem_pinned_cacheattr(struct domain *d, uint64_t gfn_start, p2m_memory_type_changed(d); switch ( type ) { - case PAT_TYPE_UC_MINUS: + case X86_MT_UCM: /* * For EPT we can also avoid the flush in this case; * see epte_get_entry_emt(). */ if ( hap_enabled(d) && cpu_has_vmx ) - case PAT_TYPE_UNCACHABLE: + case X86_MT_UC: break; /* fall through */ default: @@ -638,12 +638,12 @@ int hvm_set_mem_pinned_cacheattr(struct domain *d, uint64_t gfn_start, rcu_read_unlock(&pinned_cacheattr_rcu_lock); return -ENOENT; - case PAT_TYPE_UC_MINUS: - case PAT_TYPE_UNCACHABLE: - case PAT_TYPE_WRBACK: - case PAT_TYPE_WRCOMB: - case PAT_TYPE_WRPROT: - case PAT_TYPE_WRTHROUGH: + case X86_MT_UCM: + case X86_MT_UC: + case X86_MT_WB: + case X86_MT_WC: + case X86_MT_WP: + case X86_MT_WT: break; default: @@ -681,7 +681,7 @@ int hvm_set_mem_pinned_cacheattr(struct domain *d, uint64_t gfn_start, list_add_rcu(&range->list, &d->arch.hvm.pinned_cacheattr_ranges); p2m_memory_type_changed(d); - if ( type != PAT_TYPE_WRBACK ) + if ( type != X86_MT_WB ) flush_all(FLUSH_CACHE); return 0; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 7c81b80710f99e08fe8291d3e413c449322b777d..b543c3983d77ae807e8bd97330691a79d8d39bae 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1231,14 +1231,14 @@ static void cf_check vmx_handle_cd(struct vcpu *v, unsigned long value) * memory type are all UC. */ u64 uc_pat = - ((uint64_t)PAT_TYPE_UNCACHABLE) | /* PAT0 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 8) | /* PAT1 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 16) | /* PAT2 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 24) | /* PAT3 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 32) | /* PAT4 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 40) | /* PAT5 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 48) | /* PAT6 */ - ((uint64_t)PAT_TYPE_UNCACHABLE << 56); /* PAT7 */ + ((uint64_t)X86_MT_UC) | /* PAT0 */ + ((uint64_t)X86_MT_UC << 8) | /* PAT1 */ + ((uint64_t)X86_MT_UC << 16) | /* PAT2 */ + ((uint64_t)X86_MT_UC << 24) | /* PAT3 */ + ((uint64_t)X86_MT_UC << 32) | /* PAT4 */ + ((uint64_t)X86_MT_UC << 40) | /* PAT5 */ + ((uint64_t)X86_MT_UC << 48) | /* PAT6 */ + ((uint64_t)X86_MT_UC << 56); /* PAT7 */ vmx_get_guest_pat(v, pat); vmx_set_guest_pat(v, uc_pat); diff --git a/xen/arch/x86/include/asm/mtrr.h b/xen/arch/x86/include/asm/mtrr.h index 7733800b798fc2c72ba87e4ce6500e4183553d04..92fc930c692039b6c709d6a04f6553593f40aa55 100644 --- a/xen/arch/x86/include/asm/mtrr.h +++ b/xen/arch/x86/include/asm/mtrr.h @@ -16,17 +16,7 @@ #define NORMAL_CACHE_MODE 0 #define NO_FILL_CACHE_MODE 2 -enum { - PAT_TYPE_UNCACHABLE=0, - PAT_TYPE_WRCOMB=1, - PAT_TYPE_WRTHROUGH=4, - PAT_TYPE_WRPROT=5, - PAT_TYPE_WRBACK=6, - PAT_TYPE_UC_MINUS=7, - PAT_TYPE_NUMS -}; - -#define INVALID_MEM_TYPE PAT_TYPE_NUMS +#define INVALID_MEM_TYPE X86_NUM_MT /* In the Intel processor's MTRR interface, the MTRR type is always held in an 8 bit field: */ diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index d61d66c20e4180f8cbe21bcd97b568519e0b738e..126437285d8a9f222fca6a7b6ff4434b60637847 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -573,8 +573,8 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, if ( gmtrr_mtype >= 0 ) { *ipat = true; - return gmtrr_mtype != PAT_TYPE_UC_MINUS ? gmtrr_mtype - : MTRR_TYPE_UNCACHABLE; + return gmtrr_mtype != X86_MT_UCM ? gmtrr_mtype + : MTRR_TYPE_UNCACHABLE; } if ( gmtrr_mtype == -EADDRNOTAVAIL ) return -1; diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index 6bb564b0145285afc93b72a60b7797fcfe8696dc..b64bba70fc17906236872a017ad48ce91fd30803 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -561,7 +561,7 @@ _sh_propagate(struct vcpu *v, (type = hvm_get_mem_pinned_cacheattr(d, target_gfn, 0)) >= 0 ) sflags |= pat_type_2_pte_flags(type); else if ( d->arch.hvm.is_in_uc_mode ) - sflags |= pat_type_2_pte_flags(PAT_TYPE_UNCACHABLE); + sflags |= pat_type_2_pte_flags(X86_MT_UC); else if ( iomem_access_permitted(d, mfn_x(target_mfn), mfn_x(target_mfn)) ) { @@ -572,7 +572,7 @@ _sh_propagate(struct vcpu *v, mfn_to_maddr(target_mfn), MTRR_TYPE_UNCACHABLE); else if ( iommu_snoop ) - sflags |= pat_type_2_pte_flags(PAT_TYPE_WRBACK); + sflags |= pat_type_2_pte_flags(X86_MT_WB); else sflags |= get_pat_flags(v, gflags, From patchwork Tue Dec 20 01:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67A7DC3DA7B for ; Tue, 20 Dec 2022 01:10:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466402.725317 (Exim 4.92) (envelope-from ) id 1p7R9O-0005Yc-Ey; Tue, 20 Dec 2022 01:10:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466402.725317; Tue, 20 Dec 2022 01:10:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9O-0005YL-Bh; Tue, 20 Dec 2022 01:10:34 +0000 Received: by outflank-mailman (input) for mailman id 466402; Tue, 20 Dec 2022 01:10:33 +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 1p7R9N-0004T7-J5 for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:33 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 18f6490e-8003-11ed-8fd4-01056ac49cbb; Tue, 20 Dec 2022 02:10:32 +0100 (CET) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id D5D143200916; Mon, 19 Dec 2022 20:10:29 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 19 Dec 2022 20:10:30 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:28 -0500 (EST) 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: 18f6490e-8003-11ed-8fd4-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498629; x=1671585029; bh=bgytBg0d5kZ/2u9oOHlePhKhWAPvt5pdQvy Ccbzuwv0=; b=chKYcnlUCeNwbxoEdiFHiyx/gI9eYjeet/HxlgkfzmRa74bPJHl XqMAyii+coVyzypKraJAPAODQRvWD+X4qhtRfOLaEcmubWr5pegbSIbFJzz+Xp+x hoG9EgPBcMXZmlmf/g/UxmKTWPAvCJqXKEcQkKDkxAs7EZ6X1Z1DqZmU+IdzuTJV lGOfoigHUDLgp8Lf1HV/gusetJN4tcwrJPEzF6yeuTDO6KviS5Fo1yzMZ68YoRcB nWxvcQKzjtpjn5+5yb0o6aXhlHbLmkqdsqRUKU74eDuzGLX7Lzej1LxIshAAdFNk twJYW2nRfTt4lsP1XbycAA+YihGb+K7QVTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498629; x=1671585029; bh=bgytBg0d5kZ/2 u9oOHlePhKhWAPvt5pdQvyCcbzuwv0=; b=bKJ7jMaNn3VReebkzJoSti0T9sYgu u2kjtqslyTwtyHI3ztPoIcHzUWSb4RdE7FGxpd3o4bjRhmX74Wo28ExGyiTv39zG 7hChxlljdDQS6EuQNrw6Br8Vb2nhf24to50HIt4pUkaLjiviz2TzNodkZsGyWvZR cPIShhLcR11Fvn/ae0ffzNJCYo5OTFxrhaZV0ejXJiGfmf/SeMTIh6vffEKnyHVq a/JFnLs9z0Mg/wc+IqwM09aPCErF12iAbppD0h5uKImaKULKNl5b046YTD+iGIFt 0F1A3f9flXGN9e2L5Wr3JggRS8g5OMi6UcbIQRu3yHFv5+o+KmZ3SwgyQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 04/10] x86: Replace MTRR_* constants with X86_MT_* constants Date: Mon, 19 Dec 2022 20:07:06 -0500 Message-Id: <7a0c5f8f12b97e93258d91c4ffd036a8e9d74061.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 This allows eliminating of the former, with the exception of MTRR_NUM_TYPES. MTRR_NUM_TYPES is kept, as due to a quirk of the x86 architecture X86_MT_UCM (7) is not valid in an MTRR. Suggested-by: Andrew Cooper Signed-off-by: Demi Marie Obenour Reviewed-by: Jan Beulich --- Changes since v2: - Improve commit message - Do not replace MTRR_NUM_TYPES with X86_MT_UCM - State explicitly that MTRR_NUM_TYPES is kept --- xen/arch/x86/cpu/mtrr/generic.c | 10 ++--- xen/arch/x86/cpu/mtrr/main.c | 26 ++++++------- xen/arch/x86/e820.c | 4 +- xen/arch/x86/hvm/mtrr.c | 30 +++++++-------- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 2 +- xen/arch/x86/include/asm/mtrr.h | 10 +---- xen/arch/x86/mm/p2m-ept.c | 51 ++++++++++++------------- xen/arch/x86/mm/shadow/multi.c | 2 +- 10 files changed, 66 insertions(+), 73 deletions(-) diff --git a/xen/arch/x86/cpu/mtrr/generic.c b/xen/arch/x86/cpu/mtrr/generic.c index 47aaf76226e0a8a0712b7211ed339a4a032ab3f3..660ae26c2350b3436a471155fc0426699ba8ac1d 100644 --- a/xen/arch/x86/cpu/mtrr/generic.c +++ b/xen/arch/x86/cpu/mtrr/generic.c @@ -127,11 +127,11 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x) { static const char __initconst strings[MTRR_NUM_TYPES][16] = { - [MTRR_TYPE_UNCACHABLE] = "uncachable", - [MTRR_TYPE_WRCOMB] = "write-combining", - [MTRR_TYPE_WRTHROUGH] = "write-through", - [MTRR_TYPE_WRPROT] = "write-protect", - [MTRR_TYPE_WRBACK] = "write-back", + [X86_MT_UC] = "uncachable", + [X86_MT_WC] = "write-combining", + [X86_MT_WT] = "write-through", + [X86_MT_WP] = "write-protect", + [X86_MT_WB] = "write-back", }; return (x < ARRAY_SIZE(strings) && strings[x][0]) ? strings[x] : "?"; diff --git a/xen/arch/x86/cpu/mtrr/main.c b/xen/arch/x86/cpu/mtrr/main.c index 4e01c8d6f9df6562b94438f265d79a0a6fca8de6..2946003b84938f3b83c98b62dfaa3ace90822983 100644 --- a/xen/arch/x86/cpu/mtrr/main.c +++ b/xen/arch/x86/cpu/mtrr/main.c @@ -163,10 +163,10 @@ static void cf_check ipi_handler(void *info) } static inline int types_compatible(mtrr_type type1, mtrr_type type2) { - return type1 == MTRR_TYPE_UNCACHABLE || - type2 == MTRR_TYPE_UNCACHABLE || - (type1 == MTRR_TYPE_WRTHROUGH && type2 == MTRR_TYPE_WRBACK) || - (type1 == MTRR_TYPE_WRBACK && type2 == MTRR_TYPE_WRTHROUGH); + return type1 == X86_MT_UC || + type2 == X86_MT_UC || + (type1 == X86_MT_WT && type2 == X86_MT_WB) || + (type1 == X86_MT_WB && type2 == X86_MT_WT); } /** @@ -297,13 +297,13 @@ static void set_mtrr(unsigned int reg, unsigned long base, * * The available types are * - * %MTRR_TYPE_UNCACHABLE - No caching + * %X86_MT_UC - No caching * - * %MTRR_TYPE_WRBACK - Write data back in bursts whenever + * %X86_MT_WB - Write data back in bursts whenever * - * %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts + * %X86_MT_WC - Write data back soon but allow bursts * - * %MTRR_TYPE_WRTHROUGH - Cache reads but not writes + * %X86_MT_WT - Cache reads but not writes * * BUGS: Needs a quiet flag for the cases where drivers do not mind * failures and do not wish system log messages to be sent. @@ -328,7 +328,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, } /* If the type is WC, check that this processor supports it */ - if ((type == MTRR_TYPE_WRCOMB) && !have_wrcomb()) { + if ((type == X86_MT_WC) && !have_wrcomb()) { printk(KERN_WARNING "mtrr: your processor doesn't support write-combining\n"); return -EOPNOTSUPP; @@ -442,13 +442,13 @@ static int mtrr_check(unsigned long base, unsigned long size) * * The available types are * - * %MTRR_TYPE_UNCACHABLE - No caching + * %X86_MT_UC - No caching * - * %MTRR_TYPE_WRBACK - Write data back in bursts whenever + * %X86_MT_WB - Write data back in bursts whenever * - * %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts + * %X86_MT_WC - Write data back soon but allow bursts * - * %MTRR_TYPE_WRTHROUGH - Cache reads but not writes + * %X86_MT_WT - Cache reads but not writes * * BUGS: Needs a quiet flag for the cases where drivers do not mind * failures and do not wish system log messages to be sent. diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index b653a19c93afb98c2d64330384cb4fa7b4d2e1ec..c5911cf48dc4a281c03ddef35f23b19bc7af42eb 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -459,7 +459,7 @@ static uint64_t __init mtrr_top_of_ram(void) printk(" MTRR cap: %"PRIx64" type: %"PRIx64"\n", mtrr_cap, mtrr_def); /* MTRRs enabled, and default memory type is not writeback? */ - if ( !test_bit(11, &mtrr_def) || ((uint8_t)mtrr_def == MTRR_TYPE_WRBACK) ) + if ( !test_bit(11, &mtrr_def) || ((uint8_t)mtrr_def == X86_MT_WB) ) return 0; /* @@ -476,7 +476,7 @@ static uint64_t __init mtrr_top_of_ram(void) printk(" MTRR[%d]: base %"PRIx64" mask %"PRIx64"\n", i, base, mask); - if ( !test_bit(11, &mask) || ((uint8_t)base != MTRR_TYPE_WRBACK) ) + if ( !test_bit(11, &mask) || ((uint8_t)base != X86_MT_WB) ) continue; base &= addr_mask; mask &= addr_mask; diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 242623f3c239ee18a44f882ecb3910a00c615825..093103f6c768cf64f880d1b20e1c14f5918c1250 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -39,11 +39,11 @@ static const uint8_t pat_entry_2_pte_flags[8] = { /* Effective mm type lookup table, according to MTRR and PAT. */ static const uint8_t mm_type_tbl[MTRR_NUM_TYPES][X86_NUM_MT] = { #define RS MEMORY_NUM_TYPES -#define UC MTRR_TYPE_UNCACHABLE -#define WB MTRR_TYPE_WRBACK -#define WC MTRR_TYPE_WRCOMB -#define WP MTRR_TYPE_WRPROT -#define WT MTRR_TYPE_WRTHROUGH +#define UC X86_MT_UC +#define WB X86_MT_WB +#define WC X86_MT_WC +#define WP X86_MT_WP +#define WT X86_MT_WT /* PAT(UC, WC, RS, RS, WT, WP, WB, UC-) */ /* MTRR(UC) */ {UC, WC, RS, RS, UC, UC, UC, UC}, @@ -202,7 +202,7 @@ int mtrr_get_type(const struct mtrr_state *m, paddr_t pa, unsigned int order) unsigned int seg, num_var_ranges = MASK_EXTR(m->mtrr_cap, MTRRcap_VCNT); if ( unlikely(!m->enabled) ) - return MTRR_TYPE_UNCACHABLE; + return X86_MT_UC; pa &= mask; if ( (pa < 0x100000) && m->fixed_enabled ) @@ -277,13 +277,13 @@ int mtrr_get_type(const struct mtrr_state *m, paddr_t pa, unsigned int order) return -1; /* Two or more matches, one being UC? */ - if ( overlap_mtrr & (1 << MTRR_TYPE_UNCACHABLE) ) - return MTRR_TYPE_UNCACHABLE; + if ( overlap_mtrr & (1 << X86_MT_UC) ) + return X86_MT_UC; /* Two or more matches, all of them WT and WB? */ if ( overlap_mtrr == - ((1 << MTRR_TYPE_WRTHROUGH) | (1 << MTRR_TYPE_WRBACK)) ) - return MTRR_TYPE_WRTHROUGH; + ((1 << X86_MT_WT) | (1 << X86_MT_WB)) ) + return X86_MT_WT; /* Behaviour is undefined, but return the last overlapped type. */ return overlap_mtrr_pos; @@ -381,11 +381,11 @@ static inline bool_t valid_mtrr_type(uint8_t type) { switch ( type ) { - case MTRR_TYPE_UNCACHABLE: - case MTRR_TYPE_WRBACK: - case MTRR_TYPE_WRCOMB: - case MTRR_TYPE_WRPROT: - case MTRR_TYPE_WRTHROUGH: + case X86_MT_UC: + case X86_MT_WB: + case X86_MT_WC: + case X86_MT_WP: + case X86_MT_WT: return 1; } return 0; diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 84dbb88d33b76111833a37339186199f8bc03b5e..f0825216d722d978f221bb34a797d8de5505cb80 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -555,7 +555,7 @@ static int vmx_init_vmcs_config(bool bsp) /* Require Write-Back (WB) memory type for VMCS accesses. */ opt = (vmx_basic_msr_high & (VMX_BASIC_MEMORY_TYPE_MASK >> 32)) / ((VMX_BASIC_MEMORY_TYPE_MASK & -VMX_BASIC_MEMORY_TYPE_MASK) >> 32); - if ( opt != MTRR_TYPE_WRBACK ) + if ( opt != X86_MT_WB ) { printk("VMX: CPU%d has unexpected VMCS access type %u\n", smp_processor_id(), opt); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index b543c3983d77ae807e8bd97330691a79d8d39bae..4ae7dd56c9981d32ac545d6e7b7c126b15f68969 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -434,7 +434,7 @@ static void cf_check domain_creation_finished(struct domain *d) return; ASSERT(epte_get_entry_emt(d, gfn, apic_access_mfn, 0, &ipat, - p2m_mmio_direct) == MTRR_TYPE_WRBACK); + p2m_mmio_direct) == X86_MT_WB); ASSERT(ipat); if ( set_mmio_p2m_entry(d, gfn, apic_access_mfn, PAGE_ORDER_4K) ) diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h index 75f9928abfad28e3895fe3dd4058b2b0a6e145c3..65e9e27b5437adff59abc46976f73a9f2cc587da 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -38,7 +38,7 @@ struct vmx_msr_entry { u64 data; }; -#define EPT_DEFAULT_MT MTRR_TYPE_WRBACK +#define EPT_DEFAULT_MT X86_MT_WB struct ept_data { union { diff --git a/xen/arch/x86/include/asm/mtrr.h b/xen/arch/x86/include/asm/mtrr.h index 92fc930c692039b6c709d6a04f6553593f40aa55..e4f6ca6048334b2094a1836cc2f298453641232f 100644 --- a/xen/arch/x86/include/asm/mtrr.h +++ b/xen/arch/x86/include/asm/mtrr.h @@ -3,15 +3,9 @@ #include -/* These are the region types. They match the architectural specification. */ -#define MTRR_TYPE_UNCACHABLE 0 -#define MTRR_TYPE_WRCOMB 1 -#define MTRR_TYPE_WRTHROUGH 4 -#define MTRR_TYPE_WRPROT 5 -#define MTRR_TYPE_WRBACK 6 -#define MTRR_NUM_TYPES 7 +#define MTRR_NUM_TYPES X86_MT_UCM #define MEMORY_NUM_TYPES MTRR_NUM_TYPES -#define NO_HARDCODE_MEM_TYPE MTRR_NUM_TYPES +#define NO_HARDCODE_MEM_TYPE MTRR_NUM_TYPES #define NORMAL_CACHE_MODE 0 #define NO_FILL_CACHE_MODE 2 diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 126437285d8a9f222fca6a7b6ff4434b60637847..bb143c6c42c69db4e054b9156aad9a18ea0b2378 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -506,7 +506,7 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, mfn_x(mfn) | ((1UL << order) - 1)) ) { *ipat = true; - return MTRR_TYPE_UNCACHABLE; + return X86_MT_UC; } /* Force invalid memory type so resolve_misconfig() will split it */ return -1; @@ -515,7 +515,7 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, if ( !mfn_valid(mfn) ) { *ipat = true; - return MTRR_TYPE_UNCACHABLE; + return X86_MT_UC; } /* @@ -526,7 +526,7 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, !cache_flush_permitted(d) ) { *ipat = true; - return MTRR_TYPE_WRBACK; + return X86_MT_WB; } for ( special_pgs = i = 0; i < (1ul << order); i++ ) @@ -539,13 +539,13 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, return -1; *ipat = true; - return MTRR_TYPE_WRBACK; + return X86_MT_WB; } switch ( type ) { case p2m_mmio_direct: - return MTRR_TYPE_UNCACHABLE; + return X86_MT_UC; case p2m_grant_map_ro: case p2m_grant_map_rw: @@ -563,7 +563,7 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, * diverges. See p2m_type_to_flags for the AMD attributes. */ *ipat = true; - return MTRR_TYPE_WRBACK; + return X86_MT_WB; default: break; @@ -573,15 +573,14 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, if ( gmtrr_mtype >= 0 ) { *ipat = true; - return gmtrr_mtype != X86_MT_UCM ? gmtrr_mtype - : MTRR_TYPE_UNCACHABLE; + return gmtrr_mtype != X86_MT_UCM ? gmtrr_mtype : X86_MT_UC; } if ( gmtrr_mtype == -EADDRNOTAVAIL ) return -1; gmtrr_mtype = v ? mtrr_get_type(&v->arch.hvm.mtrr, gfn_x(gfn) << PAGE_SHIFT, order) - : MTRR_TYPE_WRBACK; + : X86_MT_WB; hmtrr_mtype = mtrr_get_type(&mtrr_state, mfn_x(mfn) << PAGE_SHIFT, order); if ( gmtrr_mtype < 0 || hmtrr_mtype < 0 ) @@ -592,14 +591,14 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, return hmtrr_mtype; /* If either type is UC, we have to go with that one. */ - if ( gmtrr_mtype == MTRR_TYPE_UNCACHABLE || - hmtrr_mtype == MTRR_TYPE_UNCACHABLE ) - return MTRR_TYPE_UNCACHABLE; + if ( gmtrr_mtype == X86_MT_UC || + hmtrr_mtype == X86_MT_UC ) + return X86_MT_UC; /* If either type is WB, we have to go with the other one. */ - if ( gmtrr_mtype == MTRR_TYPE_WRBACK ) + if ( gmtrr_mtype == X86_MT_WB ) return hmtrr_mtype; - if ( hmtrr_mtype == MTRR_TYPE_WRBACK ) + if ( hmtrr_mtype == X86_MT_WB ) return gmtrr_mtype; /* @@ -610,13 +609,13 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, * permit this), while WT and WP require writes to go straight to memory * (WC can buffer them). */ - if ( (gmtrr_mtype == MTRR_TYPE_WRTHROUGH && - hmtrr_mtype == MTRR_TYPE_WRPROT) || - (gmtrr_mtype == MTRR_TYPE_WRPROT && - hmtrr_mtype == MTRR_TYPE_WRTHROUGH) ) - return MTRR_TYPE_WRPROT; + if ( (gmtrr_mtype == X86_MT_WT && + hmtrr_mtype == X86_MT_WP) || + (gmtrr_mtype == X86_MT_WP && + hmtrr_mtype == X86_MT_WT) ) + return X86_MT_WP; - return MTRR_TYPE_UNCACHABLE; + return X86_MT_UC; } /* @@ -1426,12 +1425,12 @@ void ept_p2m_uninit(struct p2m_domain *p2m) static const char *memory_type_to_str(unsigned int x) { static const char memory_types[8][3] = { - [MTRR_TYPE_UNCACHABLE] = "UC", - [MTRR_TYPE_WRCOMB] = "WC", - [MTRR_TYPE_WRTHROUGH] = "WT", - [MTRR_TYPE_WRPROT] = "WP", - [MTRR_TYPE_WRBACK] = "WB", - [MTRR_NUM_TYPES] = "??" + [X86_MT_UC] = "UC", + [X86_MT_WC] = "WC", + [X86_MT_WT] = "WT", + [X86_MT_WP] = "WP", + [X86_MT_WB] = "WB", + [MTRR_NUM_TYPES] = "??", }; ASSERT(x < ARRAY_SIZE(memory_types)); diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index b64bba70fc17906236872a017ad48ce91fd30803..f5f7ff021bd9e057c5b6f6329de7acb5ef05d58f 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -570,7 +570,7 @@ _sh_propagate(struct vcpu *v, gflags, gfn_to_paddr(target_gfn), mfn_to_maddr(target_mfn), - MTRR_TYPE_UNCACHABLE); + X86_MT_UC); else if ( iommu_snoop ) sflags |= pat_type_2_pte_flags(X86_MT_WB); else From patchwork Tue Dec 20 01:07:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05C87C10F1D for ; Tue, 20 Dec 2022 01:10:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466403.725328 (Exim 4.92) (envelope-from ) id 1p7R9Q-0005s2-Oe; Tue, 20 Dec 2022 01:10:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466403.725328; Tue, 20 Dec 2022 01:10:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9Q-0005rv-Jr; Tue, 20 Dec 2022 01:10:36 +0000 Received: by outflank-mailman (input) for mailman id 466403; Tue, 20 Dec 2022 01:10:35 +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 1p7R9P-0004iO-O2 for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:35 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1a9807f8-8003-11ed-91b6-6bf2151ebd3b; Tue, 20 Dec 2022 02:10:34 +0100 (CET) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 4E0C3320095B; Mon, 19 Dec 2022 20:10:32 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Dec 2022 20:10:33 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:30 -0500 (EST) 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: 1a9807f8-8003-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498631; x=1671585031; bh=uxmdOs+lCg3lNRcLgLV7XD5izHM7UdEv5Kn bujPlCxE=; b=dedffQ5lwM/nq4YhPhfB4flTbftjq38/ex3njQi6prBsfMhUcCm tAgeCU6n+25b0Bi6xgamQilfesd6EMsBtpQ4YrQkZhSGPpdx5tOCCH29DHs2x7Fm 8T/7CLw5+1oqj3jP0VgZnXWPQUWcqMjLWL9GCnP5An0gOMaZpQWbLBDl1Kg9UM0C S1e1d5tsOhmMGXG61UcrF6rV7SeJeTJY8yxz5fwIPpPjxf97NQKk48NF/XJNisdu SznWVd/jwAUeA6Wihb8IILeL63d023powN38W2s3tJdnD0RyyIoa5E7inwTXq7gk 5HgnmwCnR2Xz6l55urKlZTRgZbEFks98/Mw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498631; x=1671585031; bh=uxmdOs+lCg3lN RcLgLV7XD5izHM7UdEv5KnbujPlCxE=; b=j9o81iF0qvmDWFXXMig8tGbyLlftU BTh+lQcviJX07WBuVDFA/oLY6135P6l64E+2Ak9yL6H/45xn7rEPfEVFS1rzueW0 kmCxBj6Vi7l9O1cAwMXL1MJlNgJIptIFOBHYMOaHtQe9G3By4gdPmdv5B8fl4PzU dNtU3brZPwoSjWqWcRsvgEi4PEzlvB2ynLWXqLuthnHgg3RnwQ9rO2LHCChXaZUl X0VNI0/fLP1zazon5hxQZSaDOctr7ikj/U35BqUD4UgXCJL47i6qxPeAnSK707/X t6UbdeOjQqHwhVUhgMT16DhVXfD3Ypy4Ux7BK4UUbwhm7cpPjCirh0ACA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedunecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 05/10] x86: Replace EPT_EMT_* constants with X86_MT_* Date: Mon, 19 Dec 2022 20:07:07 -0500 Message-Id: <4b5f6b6bcc4ed00db6b5f4c6def68606c190a74e.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 This allows eliminating the former. No functional change intended. Suggested-by: Andrew Cooper Signed-off-by: Demi Marie Obenour Reviewed-by: Jan Beulich --- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 9 --------- xen/arch/x86/mm/hap/nested_ept.c | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index 8eedf59155e01ec1ca84dcc6b30961f9c884cb3b..49fe9822fac5eae15b67f0cfd3d0cb96347dc7ed 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -80,15 +80,6 @@ typedef enum { #define EPTE_RWX_MASK 0x7 #define EPTE_FLAG_MASK 0x7f -#define EPT_EMT_UC 0 -#define EPT_EMT_WC 1 -#define EPT_EMT_RSV0 2 -#define EPT_EMT_RSV1 3 -#define EPT_EMT_WT 4 -#define EPT_EMT_WP 5 -#define EPT_EMT_WB 6 -#define EPT_EMT_RSV2 7 - #define PI_xAPIC_NDST_MASK 0xFF00 void vmx_asm_vmexit_handler(struct cpu_user_regs); diff --git a/xen/arch/x86/mm/hap/nested_ept.c b/xen/arch/x86/mm/hap/nested_ept.c index 1cb7fefc37091bf7d92a277203e652add5611871..23fb3889b7605be62805731218c314819d5027b5 100644 --- a/xen/arch/x86/mm/hap/nested_ept.c +++ b/xen/arch/x86/mm/hap/nested_ept.c @@ -84,8 +84,8 @@ static bool_t nept_emt_bits_check(ept_entry_t e, uint32_t level) { if ( e.sp || level == 1 ) { - if ( e.emt == EPT_EMT_RSV0 || e.emt == EPT_EMT_RSV1 || - e.emt == EPT_EMT_RSV2 ) + if ( e.emt == X86_MT_RSVD_2 || e.emt == X86_MT_RSVD_3 || + e.emt == X86_MT_UCM ) return 1; } return 0; From patchwork Tue Dec 20 01:07:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01863C4332F for ; Tue, 20 Dec 2022 01:10:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466404.725339 (Exim 4.92) (envelope-from ) id 1p7R9U-0006Dz-37; Tue, 20 Dec 2022 01:10:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466404.725339; Tue, 20 Dec 2022 01:10:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9T-0006DZ-Un; Tue, 20 Dec 2022 01:10:39 +0000 Received: by outflank-mailman (input) for mailman id 466404; Tue, 20 Dec 2022 01:10:38 +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 1p7R9S-0004iO-9d for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:38 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1c000886-8003-11ed-91b6-6bf2151ebd3b; Tue, 20 Dec 2022 02:10:37 +0100 (CET) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E4B963200920; Mon, 19 Dec 2022 20:10:34 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 19 Dec 2022 20:10:35 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:33 -0500 (EST) 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: 1c000886-8003-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498634; x=1671585034; bh=ZFVd1zipbDmyuM5p7z7I6kIgLQvhgJ+UDrK byLqFiao=; b=uIn3JRZh+wE8wl0bAnlNSxLWynzbB/S5/vfgKn89TTu7J428rcb r7jYay3VCc3p9h909ZWHe1c26nbsrLeM3rIqHOiWlhhPSQDzvcVEo5/9eajKe+e8 0vV3nqh5WNDr7EV7h4jfGyw0eqfgGh4z4Y9ScQ4wW3vC7MLT896aFTWCzRwscdf3 nIDJwNxzivuhpAcz6fPaqauhlsE0qxe9xZ9LBrw6DfLwmsht/BQtmah08WmSSn1W yUv0tlV40PRJbfjZy1SWUuEFthWSSZXTBw5Zc2lAPks3wPWRkbO1onaszAH3XEoe dhBmuj+rxMg+NQrzFPulsznNoa+voZ7PCbg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498634; x=1671585034; bh=ZFVd1zipbDmyu M5p7z7I6kIgLQvhgJ+UDrKbyLqFiao=; b=DDpCTCT5d0Acst/Kd2JqpA8/+2WKO mPKwax/l8HA7rkaiv3Gb/UgU0oO0ctNmsmo0vMyrS4NX6z8Qjridl1sOomqozglf h5JopvMDpH/myu32XMbQIh16qYXxHrxNsybzWn8JIRByZ8uZXPx49uWx6pZukvSM ip87LWtoKjUP5dMdMkHDF+SJpO07eB6cfqteCQRz95t8MSyzSzxo7gMQrRd+QRCl fXf3JbiPuEOnU2+dtjCjU74dmfBmVnweLnhi1qtY3IpFclfSrn5VuWRgeI6aOwg/ kPXM0eqsHn9lSxd/0flVR6UDrXwTKEvOixqBnmk0O+uXGKd9RMlb/hPGQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 06/10] x86: Remove MEMORY_NUM_TYPES and NO_HARDCODE_MEM_TYPE Date: Mon, 19 Dec 2022 20:07:08 -0500 Message-Id: <8516b1a8da8ea536e65653e998e7c79d98cb53b4.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 No functional change intended. Signed-off-by: Demi Marie Obenour --- This patch is optional. Subsequent patches should not depend on it. Changes since v2: - Keep MTRR_NUM_TYPES and adjust commit message accordingly --- xen/arch/x86/hvm/mtrr.c | 18 +++++++++--------- xen/arch/x86/include/asm/mtrr.h | 2 -- xen/arch/x86/mm/shadow/multi.c | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 093103f6c768cf64f880d1b20e1c14f5918c1250..05e978041d62fd0d559462de181a04bef8a5bca9 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -38,7 +38,7 @@ static const uint8_t pat_entry_2_pte_flags[8] = { /* Effective mm type lookup table, according to MTRR and PAT. */ static const uint8_t mm_type_tbl[MTRR_NUM_TYPES][X86_NUM_MT] = { -#define RS MEMORY_NUM_TYPES +#define RS MTRR_NUM_TYPES #define UC X86_MT_UC #define WB X86_MT_WB #define WC X86_MT_WC @@ -66,9 +66,9 @@ static const uint8_t mm_type_tbl[MTRR_NUM_TYPES][X86_NUM_MT] = { * Reverse lookup table, to find a pat type according to MTRR and effective * memory type. This table is dynamically generated. */ -static uint8_t __read_mostly mtrr_epat_tbl[MTRR_NUM_TYPES][MEMORY_NUM_TYPES] = - { [0 ... MTRR_NUM_TYPES-1] = - { [0 ... MEMORY_NUM_TYPES-1] = INVALID_MEM_TYPE } +static uint8_t __read_mostly mtrr_epat_tbl[MTRR_NUM_TYPES][MTRR_NUM_TYPES] = + { [0 ... MTRR_NUM_TYPES - 1] = + { [0 ... MTRR_NUM_TYPES - 1] = INVALID_MEM_TYPE } }; /* Lookup table for PAT entry of a given PAT value in host PAT. */ @@ -85,7 +85,7 @@ static int __init cf_check hvm_mtrr_pat_init(void) { unsigned int tmp = mm_type_tbl[i][j]; - if ( tmp < MEMORY_NUM_TYPES ) + if ( tmp < MTRR_NUM_TYPES ) mtrr_epat_tbl[i][tmp] = j; } } @@ -317,11 +317,11 @@ static uint8_t effective_mm_type(struct mtrr_state *m, uint8_t gmtrr_mtype) { uint8_t mtrr_mtype, pat_value; - + /* if get_pat_flags() gives a dedicated MTRR type, * just use it - */ - if ( gmtrr_mtype == NO_HARDCODE_MEM_TYPE ) + */ + if ( gmtrr_mtype == MTRR_NUM_TYPES ) mtrr_mtype = mtrr_get_type(m, gpa, 0); else mtrr_mtype = gmtrr_mtype; @@ -346,7 +346,7 @@ uint32_t get_pat_flags(struct vcpu *v, /* 1. Get the effective memory type of guest physical address, * with the pair of guest MTRR and PAT */ - guest_eff_mm_type = effective_mm_type(g, pat, gpaddr, + guest_eff_mm_type = effective_mm_type(g, pat, gpaddr, gl1e_flags, gmtrr_mtype); /* 2. Get the memory type of host physical address, with MTRR */ shadow_mtrr_type = mtrr_get_type(&mtrr_state, spaddr, 0); diff --git a/xen/arch/x86/include/asm/mtrr.h b/xen/arch/x86/include/asm/mtrr.h index e4f6ca6048334b2094a1836cc2f298453641232f..4b7f840a965954cc4b59698327a37e47026893a4 100644 --- a/xen/arch/x86/include/asm/mtrr.h +++ b/xen/arch/x86/include/asm/mtrr.h @@ -4,8 +4,6 @@ #include #define MTRR_NUM_TYPES X86_MT_UCM -#define MEMORY_NUM_TYPES MTRR_NUM_TYPES -#define NO_HARDCODE_MEM_TYPE MTRR_NUM_TYPES #define NORMAL_CACHE_MODE 0 #define NO_FILL_CACHE_MODE 2 diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index f5f7ff021bd9e057c5b6f6329de7acb5ef05d58f..1faf9940db6b0afefc5977c00c00fb6a39cd27d2 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -578,7 +578,7 @@ _sh_propagate(struct vcpu *v, gflags, gfn_to_paddr(target_gfn), mfn_to_maddr(target_mfn), - NO_HARDCODE_MEM_TYPE); + MTRR_NUM_TYPES); } } From patchwork Tue Dec 20 01:07:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3197C001B2 for ; Tue, 20 Dec 2022 01:10:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466407.725350 (Exim 4.92) (envelope-from ) id 1p7R9W-0006ee-Q8; Tue, 20 Dec 2022 01:10:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466407.725350; Tue, 20 Dec 2022 01:10:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9W-0006dv-Js; Tue, 20 Dec 2022 01:10:42 +0000 Received: by outflank-mailman (input) for mailman id 466407; Tue, 20 Dec 2022 01:10:41 +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 1p7R9V-0004T7-AB for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:41 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1d57d520-8003-11ed-8fd4-01056ac49cbb; Tue, 20 Dec 2022 02:10:39 +0100 (CET) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 35F233200916; Mon, 19 Dec 2022 20:10:37 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Dec 2022 20:10:38 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:36 -0500 (EST) 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: 1d57d520-8003-11ed-8fd4-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498636; x=1671585036; bh=mmWwiUKIb7PKGWRCiRecDTE1zKV4JKWsn7i luc16UuM=; b=mStWYdgNQql7gh33QrtSnuD/GPYeOwdy0tQoWGDcdM6j8JOX3+O wFrhh2RJsswfyPbKucVAtlyhKp60sujLAgav30AFFhFuY6iGA8+S8fcNcCxjZtzu iDn7g7/4nxj74a4IZz0xvtNPwjsvyFfXOvNR/JmzOJoz1STbXFmEkPLAOzyYtZ5B OWBY2mKi9St0jWTrM+GoXonuDOOkxNdJPHVvq4Irt+oBqARn0Xr5rDP4TTDXlrK2 D4d0rvbjY/mYnHPGb5aBrcZ//UJHD12usFf6QZTPsIUyF3oabjSezIGhnpvp4BFb Pd8nCxhGddDJnP0foFn5zis+R0yUUyJruBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498636; x=1671585036; bh=mmWwiUKIb7PKG WRCiRecDTE1zKV4JKWsn7iluc16UuM=; b=p9ek3Qdd5Fn/9SP4cGDijKonsSSYW BcCcQqcBuzN61DKYq+1onW4EIJYULeM3pPMXjmYY4aW3kIzkbhbyTA0tpBRqiAxE Emu2FLtBhzL8pjwzzrX770LdDZkajM0edELRcqHJZa2toxGAZ1e/JHhfTjhrx9zB GM9CmI4e08aelshDzaBt7zzLXMEtWO41zTHgH161l9CGSVl4QG5+cLmdVLrEdtHO +R+WuGbaYTEkPARpiREbAkRWYySqsk2qpcLQDKiNjgoKj1aW3xaOLRuhQuGn/k/b br9/TzswYMH4adK5BAkf7Ufl9uG0NKCjrAi4P2jQuHytBCrLPnGRfIaWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedvnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 07/10] x86: Derive XEN_MSR_PAT from its individual entries Date: Mon, 19 Dec 2022 20:07:09 -0500 Message-Id: <3f38d913e270fed69a336d08d689ac9268cc54c2.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 This avoids it being a magic constant that is difficult for humans to decode. Use BUILD_BUG_ON to check that the old and new values are identical. Signed-off-by: Demi Marie Obenour Reviewed-by: Jan Beulich --- Changes since v4: - Explain that changing XEN_MSR_PAT breaks guests that rely on the API in xen.h instead of reading the PAT from Xen. --- xen/arch/x86/include/asm/processor.h | 9 ++++++++- xen/arch/x86/mm.c | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/include/asm/processor.h b/xen/arch/x86/include/asm/processor.h index 8e2816fae9b97bd4e153a30cc3802971fe0355af..60b902060914584957db8afa5c7c1e6abdad4d13 100644 --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -96,7 +96,14 @@ * Host IA32_CR_PAT value to cover all memory types. This is not the default * MSR_PAT value, and is an ABI with PV guests. */ -#define XEN_MSR_PAT _AC(0x050100070406, ULL) +#define XEN_MSR_PAT ((_AC(X86_MT_WB, ULL) << 0x00) | \ + (_AC(X86_MT_WT, ULL) << 0x08) | \ + (_AC(X86_MT_UCM, ULL) << 0x10) | \ + (_AC(X86_MT_UC, ULL) << 0x18) | \ + (_AC(X86_MT_WC, ULL) << 0x20) | \ + (_AC(X86_MT_WP, ULL) << 0x28) | \ + (_AC(X86_MT_UC, ULL) << 0x30) | \ + (_AC(X86_MT_UC, ULL) << 0x38)) #ifndef __ASSEMBLY__ diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index dba6c77ef2f7ed7fcb7f7e526583ccadd35e62cc..b40a575b61418ea1137299e68b64f7efd9efeced 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -6352,6 +6352,17 @@ unsigned long get_upper_mfn_bound(void) return min(max_mfn, 1UL << (paddr_bits - PAGE_SHIFT)) - 1; } +static void __init __maybe_unused build_assertions(void) +{ + /* + * If this trips, any guest that blindly rely on the public API in xen.h + * (instead of reading the PAT from Xen, as Linux 3.19+ does) will be + * broken. Furthermore, live migration of PV guests between Xen versions + * using different PATs will not work. + */ + BUILD_BUG_ON(XEN_MSR_PAT != 0x050100070406ULL); +} + /* * Local variables: * mode: C From patchwork Tue Dec 20 01:07:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FB23C4332F for ; Tue, 20 Dec 2022 01:10:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466410.725361 (Exim 4.92) (envelope-from ) id 1p7R9Z-00074H-9L; Tue, 20 Dec 2022 01:10:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466410.725361; Tue, 20 Dec 2022 01:10:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9Z-00073g-24; Tue, 20 Dec 2022 01:10:45 +0000 Received: by outflank-mailman (input) for mailman id 466410; Tue, 20 Dec 2022 01:10:43 +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 1p7R9X-0004T7-Af for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:43 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1ea99cc1-8003-11ed-8fd4-01056ac49cbb; Tue, 20 Dec 2022 02:10:41 +0100 (CET) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 6AA89320095B; Mon, 19 Dec 2022 20:10:39 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Dec 2022 20:10:40 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:38 -0500 (EST) 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: 1ea99cc1-8003-11ed-8fd4-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498639; x=1671585039; bh=jKBlqS6uBObDCxBMOYDitp/iZJTqwZogf21 3ESuaELQ=; b=MSaeBHKGAH+IOl5giKrtBihGrYO/b+hEQf4tVD9sGYKeS4m8Cr9 r4TUK5EOfcKH0EAKVWDP0sTaq0C0/I0k2G03qr3Uox28wtQ2xGkKBa2A/7H6JPRP v1XcDKXkB8NkDKSfdeYb6NetTEUidV41xiCD3CVT48xpg4JklhKyuQ3TSCMgxNBL Uy8uQvSp863FN1QMkvjSD9rXcFRHcpWlGc2PY7aQCR2YuZ1ytARh/sV9Cmmgf8tI xqwFvyyA9UaNa5thQb6JEqWiKlrLUADL27Ga+ZrFI14jOskJZ7Ewu4wDi6V/IFY3 Yi/HOt1mJwX6oSaOijnCEkSu8rmirtNnRAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498639; x=1671585039; bh=jKBlqS6uBObDC xBMOYDitp/iZJTqwZogf213ESuaELQ=; b=UwdSKLUnFnHN8MiJLuuWEcEvzsqaf rcW6TjkLfLnBmILAQ1l0chWyXb7y2qd3y/Hs5BNInQXNw7JqABRwY0xAYBGJg0Fe xhliD38/fXcw1tPo13I4W7gKw8ouHrSRmOe0vmaNOSau471xFAD2HFgke1/0M+OH q6dwGmXT8uWOImos7y7ivHnid+HqYS1UBnqEKPIXhrilixbMptCMt9FAZjhit4GA 7L7nUlK/Yyq4OYfBrf9zMoDCe2bbULFDKGeJPMNo9LouBeCtIQLSXAUWj3zMCCtr jbLS+nq+cXF0dzt417HKSs3o4mlMwiBp3q6sruroEWC6QH7mci++n0VSw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedvnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 08/10] x86/mm: make code robust to future PAT changes Date: Mon, 19 Dec 2022 20:07:10 -0500 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 It may be desirable to change Xen's PAT for various reasons. This requires changes to several _PAGE_* macros as well. Add static assertions to check that XEN_MSR_PAT is consistent with the _PAGE_* macros, and that _PAGE_WB is 0 as required by Linux. Signed-off-by: Demi Marie Obenour --- Changes since v4: - Add lots of comments explaining what the various BUILD_BUG_ON()s mean. Changes since v3: - Refactor some macros - Avoid including a string literal in BUILD_BUG_ON --- xen/arch/x86/mm.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index b40a575b61418ea1137299e68b64f7efd9efeced..a72556668633ee57b77c9a57d3a13dd5a12d9bbf 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -6352,6 +6352,11 @@ unsigned long get_upper_mfn_bound(void) return min(max_mfn, 1UL << (paddr_bits - PAGE_SHIFT)) - 1; } + +/* + * A bunch of static assertions to check that the XEN_MSR_PAT is valid + * and consistent with the _PAGE_* macros, and that _PAGE_WB is zero. + */ static void __init __maybe_unused build_assertions(void) { /* @@ -6361,6 +6366,72 @@ static void __init __maybe_unused build_assertions(void) * using different PATs will not work. */ BUILD_BUG_ON(XEN_MSR_PAT != 0x050100070406ULL); + + /* + * _PAGE_WB must be zero for several reasons, not least because Linux + * assumes it. + */ + BUILD_BUG_ON(_PAGE_WB); + + /* A macro to convert from cache attributes to actual cacheability */ +#define PAT_ENTRY(v) (0xFF & (XEN_MSR_PAT >> (8 * (v)))) + + /* Validate at compile-time that v is a valid value for a PAT entry */ +#define CHECK_PAT_ENTRY_VALUE(v) \ + BUILD_BUG_ON((v) < 0 || (v) > 7 || \ + (v) == X86_MT_RSVD_2 || (v) == X86_MT_RSVD_3) + + /* Validate at compile-time that PAT entry v is valid */ +#define CHECK_PAT_ENTRY(v) do { \ + BUILD_BUG_ON((v) < 0 || (v) > 7); \ + CHECK_PAT_ENTRY_VALUE(PAT_ENTRY(v)); \ +} while (0); + + /* + * If one of these trips, the corresponding entry in XEN_MSR_PAT is invalid. + * This would cause Xen to crash (with #GP) at startup. + */ + CHECK_PAT_ENTRY(0); + CHECK_PAT_ENTRY(1); + CHECK_PAT_ENTRY(2); + CHECK_PAT_ENTRY(3); + CHECK_PAT_ENTRY(4); + CHECK_PAT_ENTRY(5); + CHECK_PAT_ENTRY(6); + CHECK_PAT_ENTRY(7); + +#undef CHECK_PAT_ENTRY +#undef CHECK_PAT_ENTRY_VALUE + + /* Macro version of page_flags_to_cacheattr(), for use in BUILD_BUG_ON()s */ +#define PAGE_FLAGS_TO_CACHEATTR(page_value) \ + ((((page_value) >> 5) & 4) | (((page_value) >> 3) & 3)) + + /* Check that a PAT-related _PAGE_* macro is correct */ +#define CHECK_PAGE_VALUE(page_value) do { \ + /* Check that the _PAGE_* macros only use bits from PAGE_CACHE_ATTRS */ \ + BUILD_BUG_ON(((_PAGE_##page_value) & PAGE_CACHE_ATTRS) != \ + (_PAGE_##page_value)); \ + /* Check that the _PAGE_* are consistent with XEN_MSR_PAT */ \ + BUILD_BUG_ON(PAT_ENTRY(PAGE_FLAGS_TO_CACHEATTR(_PAGE_##page_value)) != \ + (X86_MT_##page_value)); \ +} while (0) + + /* + * If one of these trips, the corresponding _PAGE_* macro is inconsistent + * with XEN_MSR_PAT. This would cause Xen to use incorrect cacheability + * flags, with results that are undefined and probably harmful. + */ + CHECK_PAGE_VALUE(WT); + CHECK_PAGE_VALUE(WB); + CHECK_PAGE_VALUE(WC); + CHECK_PAGE_VALUE(UC); + CHECK_PAGE_VALUE(UCM); + CHECK_PAGE_VALUE(WP); + +#undef CHECK_PAGE_VALUE +#undef PAGE_FLAGS_TO_CACHEATTR +#undef PAT_ENTRY } /* From patchwork Tue Dec 20 01:07:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B25BC4167B for ; Tue, 20 Dec 2022 01:10:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466413.725370 (Exim 4.92) (envelope-from ) id 1p7R9a-0007RX-J2; Tue, 20 Dec 2022 01:10:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466413.725370; Tue, 20 Dec 2022 01:10:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9a-0007Q7-EI; Tue, 20 Dec 2022 01:10:46 +0000 Received: by outflank-mailman (input) for mailman id 466413; Tue, 20 Dec 2022 01:10:45 +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 1p7R9Y-0004T7-Uh for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:45 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 200739c9-8003-11ed-8fd4-01056ac49cbb; Tue, 20 Dec 2022 02:10:44 +0100 (CET) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B20993200921; Mon, 19 Dec 2022 20:10:41 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Dec 2022 20:10:42 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:40 -0500 (EST) 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: 200739c9-8003-11ed-8fd4-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1671498641; x=1671585041; bh=dQmXzlQNbA lNxQz0KfETxLEGBuchpoA/a77dyYWm3FQ=; b=ZYFv88AfVgir6MuG9l5M96lTM+ zuWtK2zrRpgJXrnNC/GnSacaInFMlrz5gBNmmfhgrx4vfNWm98tNNw+Naam2ftdb 8Lche4uyozSj4pm8VxhjPHp/j0Qwze4qXw2j8gG+eaYsoZypwoi+HXniy/3qT7B0 kkAatIPLWaX2nZ/uPsMIROYnN+IQZYa9QlyicHxAEyTmsumxgYL7Y+NKZnyndZv/ PnvrNSIT12XbQnudfkzKy5SSRj6ARmhQ/hjTUEdgKuz70v9dmF4zfRQR/dIzwyUy lAFCDGURkeoQro7tovPwkqYiEtL2iYZMx27RlXzy1/cpiZCPaYd7hMwdj7jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1671498641; x= 1671585041; bh=dQmXzlQNbAlNxQz0KfETxLEGBuchpoA/a77dyYWm3FQ=; b=V WwUzKhnFhCUIXcR9n0Llq5y6fK7FX/YGEXJ2h7naas/DJstEqbfst8jdsOoBmrZX Sb+y4Ny6DT3Z4SRIP2NACv/6DDCj/a/Vww42gbS4CgwX4gm1HQPR0tDdzMdSup7X PTqEDSghlpg4MxWamlAfQwzi6DcxjcOF6VHuYL7TlQiCXsp7occDpTxDutyISKgV yr/KnNRgIRRMD2alzWhwlAblxSCuDE36Gq84gKk23n+L2u/LABmc46C8tPeoltwZ RVHg7CyQTP/0lAVonx/Ub6faYO1/M9G9QzC0GcnnQDumWFOxRC5AYywcAKrtqFL8 RuwV6geJxgN4wwILU0LQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepledukeelleejkeevkeefgefhffeg vdeigeelieegjefffeeiveeivdejgeevteeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 09/10] x86/mm: Reject invalid cacheability in PV guests by default Date: Mon, 19 Dec 2022 20:07:11 -0500 Message-Id: <64d81a49e5e00527ae01b707080f6f0e14ee667c.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Setting cacheability flags that are not ones specified by Xen is a bug in the guest. By default, inject #GP into any guest that does this. allow_invalid_cacheability can be used on the Xen command line to disable this check. Suggested-by: Andrew Cooper Signed-off-by: Demi Marie Obenour --- Changes since v4: - Remove pointless BUILD_BUG_ON(). - Add comment explaining why an exception is being injected. Changes since v3: - Add Andrew Cooper’s Suggested-by --- xen/arch/x86/mm.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index a72556668633ee57b77c9a57d3a13dd5a12d9bbf..69ce597c7cd5283ae4b5f3bc0a6dfa0bb3228d3d 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -145,6 +145,8 @@ #ifdef CONFIG_PV #include "pv/mm.h" +bool allow_invalid_cacheability; +boolean_param("allow_invalid_cacheability", allow_invalid_cacheability); #endif /* Override macros from asm/page.h to make them work with mfn_t */ @@ -1343,7 +1345,33 @@ static int promote_l1_table(struct page_info *page) } else { - switch ( ret = get_page_from_l1e(pl1e[i], d, d) ) + l1_pgentry_t l1e = pl1e[i]; + + if ( !allow_invalid_cacheability ) + { + switch ( l1e.l1 & PAGE_CACHE_ATTRS ) + { + case _PAGE_WB: + case _PAGE_UC: + case _PAGE_UCM: + case _PAGE_WC: + case _PAGE_WT: + case _PAGE_WP: + break; + default: + /* + * If we get here, a PV guest tried to use one of the + * reserved values in Xen's PAT. This indicates a bug in + * the guest, so inject #GP to cause the guest to log a + * stack trace. + */ + pv_inject_hw_exception(TRAP_gp_fault, 0); + ret = -EINVAL; + goto fail; + } + } + + switch ( ret = get_page_from_l1e(l1e, d, d) ) { default: goto fail; From patchwork Tue Dec 20 01:07:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 13077384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35AE1C4708D for ; Tue, 20 Dec 2022 01:10:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.466418.725383 (Exim 4.92) (envelope-from ) id 1p7R9d-0007yK-2t; Tue, 20 Dec 2022 01:10:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 466418.725383; Tue, 20 Dec 2022 01:10:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7R9c-0007xX-U3; Tue, 20 Dec 2022 01:10:48 +0000 Received: by outflank-mailman (input) for mailman id 466418; Tue, 20 Dec 2022 01:10:47 +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 1p7R9b-0004T7-MT for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 01:10:47 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2163f3cf-8003-11ed-8fd4-01056ac49cbb; Tue, 20 Dec 2022 02:10:46 +0100 (CET) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 03E093200923; Mon, 19 Dec 2022 20:10:43 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Dec 2022 20:10:44 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Dec 2022 20:10:42 -0500 (EST) 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: 2163f3cf-8003-11ed-8fd4-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1671498643; x=1671585043; bh=vPoqzj6g32+lW3ulAao0CxzhFnjnkx9j+MP o3++8UOA=; b=m1u8GR2Gkl9J3oa5GZw3nkVQ1u7902bz4GwiPsaorTuSZs/mC/6 DdPB1s1TlopFgJ/GFndd8iTEC8mbyom+8TxEs75W/zjxBoZAkuMvCV1qr3KhkrhY TFe2KIeDYv2WyPKElQYeM0tHV8oHtUXzRiEcp3ZiY4NZ6JN6rIQsIfOdcVKHNBmO ntSkbco6oLEFZPmnsC2izuUdDQzu59Nj06afRh8UFwTPQzHoM5lhVNqVl4qs8KF8 JC9DfI1AMj5ROo07eWSKcFLeDVYpKDqQ8ouhXamteDgGwieMI6uvJfYPf0tm2sL7 frOMK4UcexKEqw9LXwRJMuBv2A05guerrnA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671498643; x=1671585043; bh=vPoqzj6g32+lW 3ulAao0CxzhFnjnkx9j+MPo3++8UOA=; b=RG10dTwbaW7TutpHtS5Mwcdb4K29b K8Kjz1bcM3/9tzZ6CFtjShWh9W8xgUWQs/Lei07XnvIqfF47CZ0VafxMQfJn6Ad7 W85aF0ytTSBx7OPlwHVqXi/PX67yn8quQvqS8/L5Y824haYi0hUNa8yCR+Ey85T4 ZaTiARx0RvWjCxmGvYYfqsduK7LqHToasXCPWRr5/9DrRsp7xpqT6tp15NA1N42c eU3G7EzTaFI8GQcvPgIaNsA1f/eQqPyzr13b2to3eJfeVXbG0dXDyOIgHGkRf3d5 WESJMYvI8YyRQ8GUoDkctWLgDQ9Rf4qSXesP/j3gNzNPcy1ia6fy1H6jA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeggdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefghefg hffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpeegnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , George Dunlap , Tim Deegan Subject: [PATCH v5 10/10] x86: Use Linux's PAT Date: Mon, 19 Dec 2022 20:07:12 -0500 Message-Id: <17b2c9baa3a561919354c2fcb77c0873df9715b7.1671497984.git.demi@invisiblethingslab.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 This is purely for testing, to see if it works around a bug in i915. It is not intended to be merged. NOT-signed-off-by: DO NOT MERGE --- xen/arch/x86/include/asm/page.h | 4 ++-- xen/arch/x86/include/asm/processor.h | 10 +++++----- xen/arch/x86/mm.c | 8 -------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/include/asm/page.h b/xen/arch/x86/include/asm/page.h index b585235d064a567082582c8e92a4e8283fd949ca..ab9b46f1d0901e50a83fd035ff28d1bda0b781a2 100644 --- a/xen/arch/x86/include/asm/page.h +++ b/xen/arch/x86/include/asm/page.h @@ -333,11 +333,11 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t); /* Memory types, encoded under Xen's choice of MSR_PAT. */ #define _PAGE_WB ( 0) -#define _PAGE_WT ( _PAGE_PWT) +#define _PAGE_WC ( _PAGE_PWT) #define _PAGE_UCM ( _PAGE_PCD ) #define _PAGE_UC ( _PAGE_PCD | _PAGE_PWT) -#define _PAGE_WC (_PAGE_PAT ) #define _PAGE_WP (_PAGE_PAT | _PAGE_PWT) +#define _PAGE_WT (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT) /* * Debug option: Ensure that granted mappings are not implicitly unmapped. diff --git a/xen/arch/x86/include/asm/processor.h b/xen/arch/x86/include/asm/processor.h index 60b902060914584957db8afa5c7c1e6abdad4d13..3993d5638626f0948bb7ac8192d2eda187eb1bdb 100644 --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -94,16 +94,16 @@ /* * Host IA32_CR_PAT value to cover all memory types. This is not the default - * MSR_PAT value, and is an ABI with PV guests. + * MSR_PAT value, and is needed by the Linux i915 driver. */ #define XEN_MSR_PAT ((_AC(X86_MT_WB, ULL) << 0x00) | \ - (_AC(X86_MT_WT, ULL) << 0x08) | \ + (_AC(X86_MT_WC, ULL) << 0x08) | \ (_AC(X86_MT_UCM, ULL) << 0x10) | \ (_AC(X86_MT_UC, ULL) << 0x18) | \ - (_AC(X86_MT_WC, ULL) << 0x20) | \ + (_AC(X86_MT_WB, ULL) << 0x20) | \ (_AC(X86_MT_WP, ULL) << 0x28) | \ - (_AC(X86_MT_UC, ULL) << 0x30) | \ - (_AC(X86_MT_UC, ULL) << 0x38)) + (_AC(X86_MT_UCM, ULL) << 0x30) | \ + (_AC(X86_MT_WT, ULL) << 0x38)) #ifndef __ASSEMBLY__ diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 69ce597c7cd5283ae4b5f3bc0a6dfa0bb3228d3d..c536f7807a418c160366c22b6c4f937a5023f14b 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -6387,14 +6387,6 @@ unsigned long get_upper_mfn_bound(void) */ static void __init __maybe_unused build_assertions(void) { - /* - * If this trips, any guest that blindly rely on the public API in xen.h - * (instead of reading the PAT from Xen, as Linux 3.19+ does) will be - * broken. Furthermore, live migration of PV guests between Xen versions - * using different PATs will not work. - */ - BUILD_BUG_ON(XEN_MSR_PAT != 0x050100070406ULL); - /* * _PAGE_WB must be zero for several reasons, not least because Linux * assumes it. From patchwork Tue Dec 20 16:13:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13078014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68136C4332F for ; Tue, 20 Dec 2022 16:13:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.467187.726207 (Exim 4.92) (envelope-from ) id 1p7fEt-0007hI-41; Tue, 20 Dec 2022 16:13:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 467187.726207; Tue, 20 Dec 2022 16:13:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7fEt-0007hB-0m; Tue, 20 Dec 2022 16:13:11 +0000 Received: by outflank-mailman (input) for mailman id 467187; Tue, 20 Dec 2022 16:13:09 +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 1p7fEr-0007h5-OH for xen-devel@lists.xenproject.org; Tue, 20 Dec 2022 16:13:09 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2065.outbound.protection.outlook.com [40.107.21.65]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3149952d-8081-11ed-91b6-6bf2151ebd3b; Tue, 20 Dec 2022 17:13:08 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8853.eurprd04.prod.outlook.com (2603:10a6:10:2e0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Tue, 20 Dec 2022 16:13:06 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8%4]) with mapi id 15.20.5924.016; Tue, 20 Dec 2022 16:13:06 +0000 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: 3149952d-8081-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ac6gvO56dVczBUP8yUSPCUd/3CTUpkwu1AfErkqN1NRN7eKn8z/fe2d+dZyqzMTkOVDJj0Rr7pW9LhoyCYYDuZ+f+1WG2oMbYEZMBInBcyDTBvltzi4tb3P+0mElKMFBDVi1FdwTk7OFa0gS3cjSsJDGQtYxrEBnh6z1I4NkoXqvbJWNlr6g9y21L7eO1xkdeOq0AzvH8aS7ttdG/phi4iYQkFKzHZdZ2qkf1XCj0qHcKwP25V9YVlprO/KlC8AkFm6Q7uNrmhvbqGOIp6CBKX9GIjM97uxEQVJJpLswWgZd1SkLCANvwoHk+r3PZaTP2KWxBYc861RHX+SFuVfMXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H2i5E9tOi8XSxmU9nTTjr33Mj2BDqfSuTEWfHh/LLJE=; b=E7kk7f/nUquy3KFFZVj9fyoQTUNb+B3vD+S8Tusc2GbhhSsc5tgQ0ZMWikwW1/Z4Zm7uEiIA2AcS+d/Kg8HTk+TLdjRDCSblywDu9jbB/z0BiUV9zmTws4RnPlQMi5/2LtgnMVVHPkue0gk7X31qDDpP4lWVFoBOIgRW8JOe4s4WvnczwAq7ftMuh9PdkHOLUaGtndz8Wvx/ShJmBaQ0GcK+H6k2Q60+7+ziJVJg6fyiHsnZ1YQQoc9EVGUMMjsweZack1F27sUF4154DgogrBIHKsgCQKlXrNanhtDZO4hZZymHV1d77WLVg1LL++Qc6r2/i6fGglaE9+ZhElzOlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H2i5E9tOi8XSxmU9nTTjr33Mj2BDqfSuTEWfHh/LLJE=; b=dIfvD+befnsV0vWGp3gIuX/HDCe/1qBU0gOAnQAo9YRzV6s6/Gnu9kNvhXyXefVwRzlaqaYCpMds1dAvaLes+AnHemD+rE+RFv4r8pykHN50Cj8sSDPoppNAoGhAjoU3NPcYS2TMquzrZMLMJ5GNdyCqNhIXNQVI12w/H4XVKjmRXDNxEYZjtpTIiPUmkk9xNYDsLg7RasNmJ8gt73mWaSAia4D65lmHoNwqM0xaLWM32EPwp3MuM9aViiYoBXmkzXN2V4kJ04ENldUBHXfk7w0y9feBDgKNs9FqA0FoDWgkTfsW+i+Tx6Y5sBrFtPlGYgO3fdXSbFcww1LfXgX5YQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <24461a6b-b118-aad9-6407-d215d07a2924@suse.com> Date: Tue, 20 Dec 2022 17:13:04 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v5 11/10] hvmloader: use memory type constants Content-Language: en-US To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Wei Liu , Demi Marie Obenour References: From: Jan Beulich In-Reply-To: X-ClientProxiedBy: FR0P281CA0091.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::11) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8853:EE_ X-MS-Office365-Filtering-Correlation-Id: 50ee373d-2383-4499-ee09-08dae2a513ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M4McA4BIwo/K8zwt1YAuR3hHnKt6BnASkan20foUlSppJiI9bjQFKw2t8JNil4CNgSc8BnopgNXLAyxCWHIJJu526bZL6Aj4uJRx0ydGqYl+13+7IIS/VE2Sce/xACwUyD3XNGRm6ClPy2g0hCQtx+lCmJ4momxmd4/MpoZpd74zKz6WeMuWiI+EkI4MyQautrQ3GJxdGdehnAdA2NHHYEkYAK0AlxroVPMlQC+YiJyqLqIem/LqbQ/bMdREi3hYpgZx0yfhRpYQ5SwOfRz/bxCR+xeQA2oUzBZJ4wknZb7DlHhQA55ZoBkz3Szfq56WMjZIzWg7Mm32XbMGQM506M68aN5ej3+H6Ul2PYyu8XfB7fL9RckYStB2wUnlXnSekMsYDJ86rOu4c2GVLsc6gWd4m3V6RnL+efDnZwwY7RYO8OpDgrGmIDp11U9YWgxgXKTJo+Iio5nal53eGdcfJeMbWSTdlhq/TzRYcx9ckSrCesfKRQjgAERRBGUoMxUTSPn27Ebg5XpFhoqv+bCj218ERaiET0bfQ9+R/3y5IVeea6fbWkmfysQqF2GRzDq1MdGPji85D7xWKGqK7LqoJmaabWVEeyHUkXPRGGVvua5JCO8WBzWCLyuCEz2yb6HF5/KRPxncG2O0Gs97usCmHZTVEhBlNg6XWG2qanN1CxxHLsZkKJckV2CANa9uFR2uzC8G2ErAuFkWSj066HHRR7zuVNtjnbmbZk0Jl3sR2/o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(136003)(346002)(39860400002)(396003)(376002)(451199015)(6506007)(31686004)(2616005)(6512007)(26005)(186003)(86362001)(31696002)(38100700002)(41300700001)(2906002)(36756003)(66476007)(66556008)(316002)(5660300002)(6916009)(66946007)(6486002)(8936002)(8676002)(478600001)(54906003)(4326008)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1XWs0cHw+ercofS+3YSiBc91e6uo?= =?utf-8?q?3E5OEEehJr/oYv8U42hJpdxJeHRxqHYn98TtWqrvXcRZMf20aW3rp1c07P9GWYE63?= =?utf-8?q?gK9Zd8QQhQRNdM0Vg3VjGbEkBfyH3m7tmxjTWNvyWduPdMZiJu+3qraGYbQ82S4kf?= =?utf-8?q?Bf4OU9gxyJhIHxV6pAFbbfU7C9UkxKfAxB0nvtjYKp6/hzr2mW1wwk0Rfxub/bHUS?= =?utf-8?q?nq3EcP3vRhxWUMo2MbuAcUDnIdREs98QUXNFo9VmN5wiEfHTRNbC94crDrShLQd9v?= =?utf-8?q?j/tpG+K7dAJqRWAqXD8WhxY2ZXp7xhmeNd+9XBJgWCRssIkh/pPFTBjr3pqB5c69L?= =?utf-8?q?4okekeBH4fviseq1Tja/Mh03rhPIMOxDTcKSIG9B2wBcJzig5Ba+ONdRN/2eASDPE?= =?utf-8?q?1ooxHsadcOlj4QAHKM3DSdGapNX00ygXtOK4wgWvlmq3j0UBTShZx86XysSQgXBYS?= =?utf-8?q?IV3fScaUNWxkyXx+XpEmorYiiMF39uPWJruHla57z9MHl6rQfjD9wpyk/a/NFIaLe?= =?utf-8?q?Q5SjZkNCXWUPh4QU0ywG8edCK3gfndvVyR8UqwgbbAbMD8ldNGjDDi3HVcPkye0C2?= =?utf-8?q?QGSzEg5l2pQX4v5m1XrPY9QEdiWP84hu0lc8RPG5D92Fw2s3Alg+NcKMi610VcCoh?= =?utf-8?q?resDxlfEWPQHiiVIStA9ZpXGTv10N1v9+CZnhw70jGr5ubiSolk/tSaJze1vnxbrB?= =?utf-8?q?lV0aOM/Qqh0f/ufDlM4MVT0NlLHo3aJJyxLW/9FYDHskT7Bw0rInSsyUKM7/lMJkv?= =?utf-8?q?ocGTAVnO+mR2FtJA3OYiG9C9VgHZvcBA8/nMWnGajkgAur7GFazBTonG19kngpCsZ?= =?utf-8?q?MkjLBhgnYl7qw7KO11PpnZXZjL0/B4b9N39hfWOD+mz/b6SHjrV72YYXdksroOb9I?= =?utf-8?q?dpPx7oLrvAFUP1o5ENt970LiErS3tKmIz4Su8hyeAPh/AN2OIkNqkjYh/tKd8wIuX?= =?utf-8?q?xLSqlDmAEYhgs7q0OIaIhGdENCFK/jTs8rbawupmyMrtCDQrjOTXUQ3pLIBtOD57m?= =?utf-8?q?F59+K1QGAtcYqrPyw3uFZoDa+/ORtH1VbpWq0FJEQQ8z08I0nxBkD2jQNH6a3M32B?= =?utf-8?q?OJCO1pQclX40KkCmaIHrQQ9tHRY9fiR+UYvPg9edCuoyGe7xNvp3nY+v3osJBLHyM?= =?utf-8?q?v67Bow6ZaNlYsZDuBa+XNzDDWO8MOjmb4RRKmlP0uD9siRJckyrSg3mYRhjlw6/Ys?= =?utf-8?q?08PAFTqMaWSyZwfdxZXwIMblNDLAPTZvKGwNlQ+JXlXkqexF2S//u5N3XLunwFCf5?= =?utf-8?q?RnExcnHgubH7mgGs8uOELHbGCTQF4jTEnZuUbFFPoHq3gRyemjUBgurZZZkfgvfc/?= =?utf-8?q?X9WRdfEinXdEF5rtTEJAAfIUS0WiFkBqrvgJlqub2oQQqv899pE7TQC4XiZ8uGnhO?= =?utf-8?q?04XPxl88B6Ak5ny8P1wjL5Kpk2Vn33Wr4JHBX6oVsgRkM/7swvwheTuwahabNiXgo?= =?utf-8?q?hwOT80XfXcChskJ/zoTaCY8IIuHc5SEAtPvhMQ9xCL5kEvSGlxrWFqe/jrXN6fji1?= =?utf-8?q?miMGl/U4Wyz5?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50ee373d-2383-4499-ee09-08dae2a513ce X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2022 16:13:06.1780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /dImKuBNG/VBKbWuTaV7rQvRAb71ta5V/Cs2JlGYPhb1U6NTkMALH0FyCk+Uh8oaXVO8oh2iv+0cKYkWvLisOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8853 Now that we have them available in a header which is okay to use from hvmloader sources, do away with respective literal numbers and silent assumptions. Signed-off-by: Jan Beulich Acked-by: Demi Marie Obenour --- a/tools/firmware/hvmloader/cacheattr.c +++ b/tools/firmware/hvmloader/cacheattr.c @@ -22,6 +22,8 @@ #include "util.h" #include "config.h" +#include + #define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg)) #define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1) #define MSR_MTRRcap 0x00fe @@ -71,23 +73,32 @@ void cacheattr_init(void) addr_mask = ((1ull << phys_bits) - 1) & ~((1ull << 12) - 1); mtrr_cap = rdmsr(MSR_MTRRcap); - mtrr_def = (1u << 11) | 6; /* E, default type WB */ + mtrr_def = (1u << 11) | X86_MT_WB; /* E, default type WB */ /* Fixed-range MTRRs supported? */ if ( mtrr_cap & (1u << 8) ) { +#define BCST2(mt) ((mt) | ((mt) << 8)) +#define BCST4(mt) (BCST2(mt) | (BCST2(mt) << 16)) +#define BCST8(mt) (BCST4(mt) | ((uint64_t)BCST4(mt) << 32)) /* 0x00000-0x9ffff: Write Back (WB) */ - content = 0x0606060606060606ull; + content = BCST8(X86_MT_WB); wrmsr(MSR_MTRRfix64K_00000, content); wrmsr(MSR_MTRRfix16K_80000, content); + /* 0xa0000-0xbffff: Write Combining (WC) */ if ( mtrr_cap & (1u << 10) ) /* WC supported? */ - content = 0x0101010101010101ull; + content = BCST8(X86_MT_WC); wrmsr(MSR_MTRRfix16K_A0000, content); + /* 0xc0000-0xfffff: Write Back (WB) */ - content = 0x0606060606060606ull; + content = BCST8(X86_MT_WB); for ( i = 0; i < 8; i++ ) wrmsr(MSR_MTRRfix4K_C0000 + i, content); +#undef BCST8 +#undef BCST4 +#undef BCST2 + mtrr_def |= 1u << 10; /* FE */ printf("fixed MTRRs ... "); } @@ -106,7 +117,7 @@ void cacheattr_init(void) while ( ((base + size) < base) || ((base + size) > pci_mem_end) ) size >>= 1; - wrmsr(MSR_MTRRphysBase(i), base); + wrmsr(MSR_MTRRphysBase(i), base | X86_MT_UC); wrmsr(MSR_MTRRphysMask(i), (~(size - 1) & addr_mask) | (1u << 11)); base += size; @@ -121,7 +132,7 @@ void cacheattr_init(void) while ( (base + size < base) || (base + size > pci_hi_mem_end) ) size >>= 1; - wrmsr(MSR_MTRRphysBase(i), base); + wrmsr(MSR_MTRRphysBase(i), base | X86_MT_UC); wrmsr(MSR_MTRRphysMask(i), (~(size - 1) & addr_mask) | (1u << 11)); base += size;