[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <kjt2m2aqnhmwqgn3ox6bkqtn5qurxawgnx3xyh42pu5sp3mwyj@qwyjttwubfck>
Date: Fri, 28 Jun 2024 13:04:38 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Dexuan Cui <decui@...rosoft.com>
Cc: x86@...nel.org, linux-coco@...ts.linux.dev, ak@...ux.intel.com,
arnd@...db.de, bp@...en8.de, brijesh.singh@....com, dan.j.williams@...el.com,
dave.hansen@...el.com, dave.hansen@...ux.intel.com, haiyangz@...rosoft.com,
hpa@...or.com, jane.chu@...cle.com, kys@...rosoft.com, luto@...nel.org,
mingo@...hat.com, peterz@...radead.org, rostedt@...dmis.org,
sathyanarayanan.kuppuswamy@...ux.intel.com, seanjc@...gle.com, tglx@...utronix.de, tony.luck@...el.com,
wei.liu@...nel.org, Jason@...c4.com, nik.borisov@...e.com, mhklinux@...look.com,
linux-hyperv@...r.kernel.org, linux-kernel@...r.kernel.org, Tianyu.Lan@...rosoft.com,
rick.p.edgecombe@...el.com, andavis@...hat.com, mheslin@...hat.com, vkuznets@...hat.com,
xiaoyao.li@...el.com, stable@...r.kernel.org
Subject: Re: [PATCH] x86/tdx: Support vmalloc() for tdx_enc_status_changed()
On Mon, May 20, 2024 at 07:12:38PM -0700, Dexuan Cui wrote:
> @@ -785,15 +799,22 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc)
> */
> static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc)
> {
> - phys_addr_t start = __pa(vaddr);
> - phys_addr_t end = __pa(vaddr + numpages * PAGE_SIZE);
> + unsigned long start = vaddr;
> + unsigned long end = start + numpages * PAGE_SIZE;
> + unsigned long step = end - start;
> + unsigned long addr;
>
> - if (!tdx_map_gpa(start, end, enc))
> - return false;
> + /* Step through page-by-page for vmalloc() mappings */
> + if (is_vmalloc_addr((void *)vaddr))
> + step = PAGE_SIZE;
>
> - /* shared->private conversion requires memory to be accepted before use */
> - if (enc)
> - return tdx_accept_memory(start, end);
> + for (addr = start; addr < end; addr += step) {
> + phys_addr_t start_pa = slow_virt_to_phys((void *)addr);
> + phys_addr_t end_pa = start_pa + step;
> +
> + if (!tdx_enc_status_changed_phys(start_pa, end_pa, enc))
> + return false;
> + }
>
> return true;
> }
This patch collied with kexec changes. tdx_kexec_finish() calls
tdx_enc_status_changed() after clearing pte, so slow_virt_to_phys()
crashes on in.
Daxuan, could you check if the fixup below works for you on vmalloc
addresses?
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index ef8ec2425998..5e455c883bcc 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -813,8 +813,15 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc)
step = PAGE_SIZE;
for (addr = start; addr < end; addr += step) {
- phys_addr_t start_pa = slow_virt_to_phys((void *)addr);
- phys_addr_t end_pa = start_pa + step;
+ phys_addr_t start_pa;
+ phys_addr_t end_pa;
+
+ if (virt_addr_valid(addr))
+ start_pa = __pa(addr);
+ else
+ start_pa = slow_virt_to_phys((void *)addr);
+
+ end_pa = start_pa + step;
if (!tdx_enc_status_changed_phys(start_pa, end_pa, enc))
return false;
--
Kiryl Shutsemau / Kirill A. Shutemov
Powered by blists - more mailing lists