From patchwork Thu Dec 19 23:55:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_Bene=C5=A1?= X-Patchwork-Id: 13915936 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 07E6BE77184 for ; Thu, 19 Dec 2024 23:55:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.861544.1273516 (Exim 4.92) (envelope-from ) id 1tOQMa-0000qj-63; Thu, 19 Dec 2024 23:55:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 861544.1273516; Thu, 19 Dec 2024 23:55:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tOQMa-0000qc-3R; Thu, 19 Dec 2024 23:55:28 +0000 Received: by outflank-mailman (input) for mailman id 861544; Thu, 19 Dec 2024 23:55:27 +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 1tOQMZ-0000c1-C6 for xen-devel@lists.xenproject.org; Thu, 19 Dec 2024 23:55:27 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b814a902-be64-11ef-a0d8-8be0dac302b0; Fri, 20 Dec 2024 00:55:26 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3862e2c9bb5so86479f8f.0 for ; Thu, 19 Dec 2024 15:55:26 -0800 (PST) Received: from lab.home (dynamic-2a00-1028-83a4-4bca-c0bb-96ff-feed-9d50.ipv6.o2.cz. [2a00:1028:83a4:4bca:c0bb:96ff:feed:9d50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8a6dd3sm2628996f8f.96.2024.12.19.15.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 15:55:24 -0800 (PST) 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: b814a902-be64-11ef-a0d8-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734652526; x=1735257326; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e4D++oBXK5nnYb4cn7GeUmCP5459fQygu93iRr5qfas=; b=AKU4fV4pcNIYmnyDhL+T2a2tfNP30UAF2dU/C64JOFRYiMFq0NydvCUD+omHSmabJw uEgodVl8+Jy2wlOczzY5oVqXvVKt1rUJ57/DY8z7idP0GpCR42mmyKOYgGIr28NZzHN4 YRPhQNFUnoVbv+E1p4QVPdt2fKCuAevKoDu7C1zkygThdt+AhBDIn6vBXPCuxst4Y9KG OEwQffRWjPNFfLRwA2p1mYwFKLJC37Ylt5DMtYXhwK3j2LQJReSEdF20HOyEl+ZKVQfk MKGr+MIFdGOGiMI+zL5PJUm+gx6swmGt/r3lvwLZdw+O5Siqf4ty0bzw9GJ5r98SSeQR 8hIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734652526; x=1735257326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e4D++oBXK5nnYb4cn7GeUmCP5459fQygu93iRr5qfas=; b=S+ZJgkIT4qNqQcr8QlMAQ9bkoD3I7qV78h9z1okLAaeqNUmtjDoI16FMTyeX8V69ph +DFtQnKGxOi49SvM3sCI5IqVW2jHnGt2PX4mxwtw1BpgQWw/9YjW1HeeYXfquBkwJXr+ gX0q8Pbk/TgCuQF7RUV8HJAbmp8nK8FxdAXEqLxkt7pHxTWa4+eQaWpGwbkfrWcG/xOL kkAEpn9UHmy/GllEkrLLklAbtgEyHISHLdfRRuhnH/2Pc2RxtMPokxBJrsqq2pQvqsIv k1i8Fnm+9yTSBpPtFr4QfnWUd205q3T2113JNn3wY9wT6mSm0OEQ12MVruW2UV/wiI+6 ayTw== X-Gm-Message-State: AOJu0YwMPIJm3tQX4Kh617R/1+sU/IZtI92lIHacipHmRakyLyL8L7XI /4/ppmAEybGl7R8uE1/S5CIu6bpbTVLY64CQOc4zPMWzOcjkzYCh10U59Q== X-Gm-Gg: ASbGncvK0w/t/zn5fAx4jIF2Zmk3y8M/56V06UaHPJ0+JzkfZSBihxIHXlqbPqoIhzB skWnoeXN0OFQsNV2DNBCgI2qUp43WtB67cx9paNYTRwsfrye+qtZfjmfK0Rsin42Tg+/sAccChm ZeTGfhtClhFP3cwqzcLtbyOcuzYkI6rZSudOd+ZWNSOnnvY8AYblieTjTk8RyYG5EjwdMR6OTgO 4CXzKHR1VQlW8gP/qDqTbpAzhgEQh2DORjEVxQkHNdC+tbvVlWOE3jMS/xLEwOTKXuG/ooUb+aD mDVhVN6512t8oMc/9hUtpojST69ud8Mbx1PN4sNON1hwSNjteJVVNSBl X-Google-Smtp-Source: AGHT+IExPdJoDGnroTJOpIyAQALEK/cHEbyLaeZGfeJwiY7mRsUAu5D1LiA9hpAIXQXdI1f/hamcJQ== X-Received: by 2002:a05:600c:a0a:b0:42c:aeee:e604 with SMTP id 5b1f17b1804b1-43668b93b4fmr2109995e9.8.1734652525548; Thu, 19 Dec 2024 15:55:25 -0800 (PST) From: " =?utf-8?q?Petr_Bene=C5=A1?= " X-Google-Original-From: =?utf-8?q?Petr_Bene=C5=A1?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Petr_Bene=C5=A1?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v2 1/2] x86: Rename _rsvd field to pw and move it to the bit 58 Date: Thu, 19 Dec 2024 23:55:01 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Petr Beneš The EPT Paging-write feature (when enabled by the TERTIARY_EXEC_EPT_PAGING_WRITE bit) uses bit 58 of the EPT entry to indicate that guest paging may update the page, even if the W access is not set. This patch is a preparation for the EPT Paging-write feature. Signed-off-by: Petr Beneš --- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index f0ec459622..d920de96b7 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -34,8 +34,8 @@ typedef union { EPT/VT-d usage */ mfn : 40, /* bits 51:12 - Machine physical frame number */ sa_p2mt : 6, /* bits 57:52 - Software available 2 */ - access : 4, /* bits 61:58 - p2m_access_t */ - _rsvd : 1, /* bit 62 - reserved */ + pw : 1, /* bit 58 - Paging-write access */ + access : 4, /* bits 62:59 - p2m_access_t */ suppress_ve : 1; /* bit 63 - suppress #VE */ }; u64 epte; From patchwork Thu Dec 19 23:55:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_Bene=C5=A1?= X-Patchwork-Id: 13915938 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 3AC2EE7718B for ; Thu, 19 Dec 2024 23:55:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.861545.1273527 (Exim 4.92) (envelope-from ) id 1tOQMf-00017o-Hx; Thu, 19 Dec 2024 23:55:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 861545.1273527; Thu, 19 Dec 2024 23:55:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tOQMf-00017h-Ep; Thu, 19 Dec 2024 23:55:33 +0000 Received: by outflank-mailman (input) for mailman id 861545; Thu, 19 Dec 2024 23:55:32 +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 1tOQMd-00016S-Rc for xen-devel@lists.xenproject.org; Thu, 19 Dec 2024 23:55:31 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b9cddfc5-be64-11ef-99a3-01e77a169b0f; Fri, 20 Dec 2024 00:55:29 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3862c78536bso77221f8f.2 for ; Thu, 19 Dec 2024 15:55:29 -0800 (PST) Received: from lab.home (dynamic-2a00-1028-83a4-4bca-c0bb-96ff-feed-9d50.ipv6.o2.cz. [2a00:1028:83a4:4bca:c0bb:96ff:feed:9d50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8a6dd3sm2628996f8f.96.2024.12.19.15.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 15:55:27 -0800 (PST) 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: b9cddfc5-be64-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734652529; x=1735257329; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CthQh3wSpepsh3Cctkm5dObyUxYj1SWrfSt1ki0rtiY=; b=gqGIgxnd6GARtXYxhqI3vS0r/INNvAbiIGVpUGD4OKZNg1BmlAmK78aZcZGut0j6bk cbYHlvTD191gjtMHl6ce1jtSCvP/SYJzvKGVpRb6gHPqcZ56L11x069zVYJPgCAHTz/8 sZai2Vaob6Xf4exDww3M1spzlLGmeilLBqvsLtXsHHnntKvdH3kkVV8HVND4GlDhnwpY yOsJvqRAtQgqaZ60LEdKv/kc+HC5IRoyaWrAfa/O6KpIMMHmvnVzwrNQ04YJfaNg8/to +0vBczKUaHuuDoZsqFl9Ejp/MHuUWPffmEUa5+tJbxd3/L3QXR3pXjn7bzD0tslJGYo9 sNwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734652529; x=1735257329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CthQh3wSpepsh3Cctkm5dObyUxYj1SWrfSt1ki0rtiY=; b=AdBCbyw2xPNA0K7dulcvZqcUs02FNqhrW8oxU5irsOH3WoNhsmKjIymYXEsOyMZwTf Bh8b8+Tllv/iZ0ZDnAUawu9Gwtc7JEMPeZUNISlh3ESv9ae507ItHcqpAlc9NJI321JV LKfwKTfrjHlTrGwHvF3dPkuPx2m6oX5ree7gERm91kiGBUhrtvsbVvkoHfZo6nTvmMnf Cu/mGbY+7eTjAlMxbpQ76RxcC7UzGDFW81iESa4Zk5YL09ZeagxLBxHCywDzbzlWWEO8 Ke3T/hS6tc9dxq/dpzTAKmhqD7pKEtr0LPJiGlQ4fdTV+0lq/MLD7paK3fEk5Fevij7b 7qAA== X-Gm-Message-State: AOJu0YzFAKqAqVS++dt+OrBv8+IsNqbJ4yogmcS6TKmd5MHP4zy88mbn PGtK+xPkADjSzmEYZSpYySHR5WaDaTRBx8ZWFUQ1idshnzcK/xCAy6N78Q== X-Gm-Gg: ASbGncuFKm1X/e+cOaZyAqvhAkISSC3Vy8DANXtHczn0eS4GyNxtigApM0Xz8Pg9+oC qtADm9gvqYL7721OgSOSj7BnEdntNABFSwoT1HyGtoC6Y5hCh0mIIBnMGvZIayKIU8pSlFbCSZ/ ZMa3wBKC+7dfRV8ub+qVL50E/aJ1rjM2GCL62T+A4rn9yMMVZngt72ug+qZsSiWwCJov5rkiZa3 zXmZFsWtZ5Gd9ZBMb2dVmUgVOxHq9aq3mkif1GxVTGnIhHaUGFbIlOZ3UIzJ7KZy6clbTjGteJC N7V7HfXZFvAxd23JbuGr7SNTm5sSZBskVILhU95rqnT7p6b4RCUto5az X-Google-Smtp-Source: AGHT+IE/8a0ry3uqyDjAC+jYpZW0CgQsBhha5nzrX9tfdLm2bVQZrt9P4T8yqm54s9do75rDp9Lwwg== X-Received: by 2002:a05:600c:3b18:b0:434:ff85:dd77 with SMTP id 5b1f17b1804b1-436686431e0mr2276825e9.3.1734652528424; Thu, 19 Dec 2024 15:55:28 -0800 (PST) From: " =?utf-8?q?Petr_Bene=C5=A1?= " X-Google-Original-From: =?utf-8?q?Petr_Bene=C5=A1?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Petr_Bene=C5=A1?= , Tamas K Lengyel , Alexandru Isaila , Petre Pircalabu , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v2 2/2] x86: Add Support for Paging-Write Feature Date: Thu, 19 Dec 2024 23:55:02 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Petr Beneš This patch introduces a new XENMEM_access_r_pw permission. Functionally, it is similar to XENMEM_access_r, but for processors with TERTIARY_EXEC_EPT_PAGING_WRITE support (Intel 12th Gen/Alder Lake and later), it also permits the CPU to write to the page during guest page-table walks (e.g., updating A/D bits) without triggering an EPT violation. This behavior works by both enabling the EPT paging-write feature and setting the EPT paging-write flag in the EPT leaf entry. This feature provides a significant performance boost for introspection tools that monitor guest page-table updates. Previously, every page-table modification by the guest—including routine updates like setting A/D bits—triggered an EPT violation, adding unnecessary overhead. The new XENMEM_access_r_pw permission allows these "uninteresting" updates to occur without EPT violations, improving efficiency. Additionally, this feature simplifies the handling of race conditions in scenarios where an introspection tool: - Sets an "invisible breakpoint" in the altp2m view for a function F - Monitors guest page-table updates to track whether the page containing F is paged out - Encounters a cleared Access (A) bit on the page containing F while the guest is about to execute the breakpoint In the current implementation: - If xc_monitor_inguest_pagefault() is enabled, the introspection tool must emulate both the breakpoint and the setting of the Access bit. - If xc_monitor_inguest_pagefault() is disabled, Xen handles the EPT violation without notifying the introspection tool, setting the Access bit and emulating the instruction. However, Xen fetches the instruction from the default view instead of the altp2m view, potentially causing the breakpoint to be missed. With this patch, setting XENMEM_access_r_pw for monitored guest page-tables prevents EPT violations in these cases. This change enhances performance and reduces complexity for introspection tools, ensuring seamless breakpoint handling while tracking guest page-table updates. Signed-off-by: Petr Beneš --- xen/arch/arm/mem_access.c | 4 ++++ xen/arch/arm/mmu/p2m.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/hvm/monitor.c | 1 + xen/arch/x86/hvm/vmx/vmcs.c | 4 +++- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 3 +++ xen/arch/x86/include/asm/p2m.h | 1 + xen/arch/x86/mm/hap/nested_hap.c | 3 +++ xen/arch/x86/mm/mem_access.c | 3 +++ xen/arch/x86/mm/p2m-ept.c | 4 ++++ xen/include/public/memory.h | 9 +++++++++ xen/include/xen/mem_access.h | 6 ++++++ 12 files changed, 39 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c index 0ec3462364..2af92bb402 100644 --- a/xen/arch/arm/mem_access.c +++ b/xen/arch/arm/mem_access.c @@ -32,6 +32,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn, ACCESS(rwx), ACCESS(rx2rw), ACCESS(n2rwx), + ACCESS(r_pw), #undef ACCESS }; @@ -172,6 +173,7 @@ p2m_mem_access_check_and_get_page(vaddr_t gva, unsigned long flag, break; else goto err; + case XENMEM_access_r_pw: case XENMEM_access_rx2rw: case XENMEM_access_rx: case XENMEM_access_r: @@ -253,6 +255,7 @@ bool p2m_mem_access_check(paddr_t gpa, vaddr_t gla, const struct npfec npfec) violation = npfec.read_access || npfec.insn_fetch; break; case XENMEM_access_r: + case XENMEM_access_r_pw: violation = npfec.write_access || npfec.insn_fetch; break; default: @@ -361,6 +364,7 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr, ACCESS(rwx), ACCESS(rx2rw), ACCESS(n2rwx), + ACCESS(r_pw), #undef ACCESS }; diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c index 28df6e5d03..7642dbc7c5 100644 --- a/xen/arch/arm/mmu/p2m.c +++ b/xen/arch/arm/mmu/p2m.c @@ -597,6 +597,7 @@ static void p2m_set_permission(lpae_t *e, p2m_type_t t, p2m_access_t a) e->p2m.read = 0; break; case p2m_access_r: + case p2m_access_r_pw: e->p2m.write = 0; e->p2m.xn = 1; break; diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 74e58c653e..495c8290ca 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1897,6 +1897,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, violation = npfec.read_access || npfec.write_access || npfec.insn_fetch; break; case p2m_access_r: + case p2m_access_r_pw: violation = npfec.write_access || npfec.insn_fetch; break; case p2m_access_w: diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c index 74621000b2..523586ca98 100644 --- a/xen/arch/x86/hvm/monitor.c +++ b/xen/arch/x86/hvm/monitor.c @@ -295,6 +295,7 @@ bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn, uint32_t pfec, case XENMEM_access_r: case XENMEM_access_n: + case XENMEM_access_r_pw: if ( pfec & PFEC_write_access ) req.u.mem_access.flags |= MEM_ACCESS_R | MEM_ACCESS_W; if ( pfec & PFEC_insn_fetch ) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 147e998371..8c0ea789c1 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -203,6 +203,7 @@ static void __init vmx_display_features(void) P(cpu_has_vmx_bus_lock_detection, "Bus Lock Detection"); P(cpu_has_vmx_notify_vm_exiting, "Notify VM Exit"); P(cpu_has_vmx_virt_spec_ctrl, "Virtualize SPEC_CTRL"); + P(cpu_has_vmx_ept_paging_write, "EPT Paging-Write"); #undef P if ( !printed ) @@ -366,7 +367,8 @@ static int vmx_init_vmcs_config(bool bsp) if ( _vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ) { - uint64_t opt = TERTIARY_EXEC_VIRT_SPEC_CTRL; + uint64_t opt = (TERTIARY_EXEC_VIRT_SPEC_CTRL | + TERTIARY_EXEC_EPT_PAGING_WRITE); _vmx_tertiary_exec_control = adjust_vmx_controls2( "Tertiary Exec Control", 0, opt, diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h index 939b87eb50..e1d3398141 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -273,6 +273,9 @@ extern uint64_t vmx_tertiary_exec_control; #define cpu_has_vmx_virt_spec_ctrl \ (vmx_tertiary_exec_control & TERTIARY_EXEC_VIRT_SPEC_CTRL) +#define cpu_has_vmx_ept_paging_write \ + (vmx_tertiary_exec_control & TERTIARY_EXEC_EPT_PAGING_WRITE) + #define VMX_EPT_EXEC_ONLY_SUPPORTED 0x00000001 #define VMX_EPT_WALK_LENGTH_4_SUPPORTED 0x00000040 #define VMX_EPT_MEMORY_TYPE_UC 0x00000100 diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h index e6de37f108..aa1bf7c9d0 100644 --- a/xen/arch/x86/include/asm/p2m.h +++ b/xen/arch/x86/include/asm/p2m.h @@ -980,6 +980,7 @@ static inline unsigned int p2m_access_to_iommu_flags(p2m_access_t p2ma) case p2m_access_r: case p2m_access_rx: case p2m_access_rx2rw: + case p2m_access_r_pw: return IOMMUF_readable; case p2m_access_w: diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_hap.c index cc7bc6e5ea..255fba7e1c 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -213,6 +213,9 @@ int nestedhvm_hap_nested_page_fault( case p2m_access_n2rwx: p2ma_10 = p2m_access_n; break; + case p2m_access_r_pw: + p2ma_10 = p2m_access_r; + break; default: p2ma_10 = p2m_access_n; /* For safety, remove all permissions. */ diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 60a0cce68a..21b5b7ecda 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -45,6 +45,7 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, ACCESS(rwx), ACCESS(rx2rw), ACCESS(n2rwx), + ACCESS(r_pw), #undef ACCESS }; @@ -94,6 +95,7 @@ bool p2m_mem_access_emulate_check(struct vcpu *v, break; case XENMEM_access_r: + case XENMEM_access_r_pw: violation = data->flags & MEM_ACCESS_WX; break; @@ -312,6 +314,7 @@ bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, ACCESS(rwx), ACCESS(rx2rw), ACCESS(n2rwx), + ACCESS(r_pw), #undef ACCESS }; diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 21728397f9..5ad78ae4b5 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -176,6 +176,10 @@ static void ept_p2m_type_to_flags(const struct p2m_domain *p2m, break; case p2m_access_rwx: break; + case p2m_access_r_pw: + entry->w = entry->x = 0; + entry->pw = !!cpu_has_vmx_ept_paging_write; + break; } /* diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 5e545ae9a4..bd9fc37b52 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -426,6 +426,15 @@ typedef enum { * pausing the vcpu */ XENMEM_access_n2rwx, + + /* + * Same as XENMEM_access_r, but on processors with + * the TERTIARY_EXEC_EPT_PAGING_WRITE support, + * CPU-initiated page-table walks can still + * write to it (e.g., update A/D bits) + */ + XENMEM_access_r_pw, + /* Take the domain default */ XENMEM_access_default } xenmem_access_t; diff --git a/xen/include/xen/mem_access.h b/xen/include/xen/mem_access.h index 87d93b31f6..2231341b5d 100644 --- a/xen/include/xen/mem_access.h +++ b/xen/include/xen/mem_access.h @@ -64,6 +64,12 @@ typedef enum { * generates an event but does not pause the * vcpu */ + p2m_access_r_pw = 10, /* Special: same as R, but on processors with + * the TERTIARY_EXEC_EPT_PAGING_WRITE support, + * CPU-initiated page-table walks can still + * write to it (e.g., update A/D bits) + */ + /* NOTE: Assumed to be only 4 bits right now on x86. */ } p2m_access_t;