lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4b7e7099-79da-4178-8f16-6780d8137ae1@linux.intel.com>
Date: Thu, 14 Aug 2025 10:49:04 +0800
From: Binbin Wu <binbin.wu@...ux.intel.com>
To: Reinette Chatre <reinette.chatre@...el.com>,
 Sean Christopherson <seanjc@...gle.com>, Sagi Shahar <sagis@...gle.com>
Cc: linux-kselftest@...r.kernel.org, Paolo Bonzini <pbonzini@...hat.com>,
 Shuah Khan <shuah@...nel.org>, Ackerley Tng <ackerleytng@...gle.com>,
 Ryan Afranji <afranji@...gle.com>, Andrew Jones <ajones@...tanamicro.com>,
 Isaku Yamahata <isaku.yamahata@...el.com>,
 Erdem Aktas <erdemaktas@...gle.com>,
 Rick Edgecombe <rick.p.edgecombe@...el.com>,
 Roger Wang <runanwang@...gle.com>, Oliver Upton <oliver.upton@...ux.dev>,
 "Pratik R. Sampat" <pratikrajesh.sampat@....com>,
 Ira Weiny <ira.weiny@...el.com>, linux-kernel@...r.kernel.org,
 kvm@...r.kernel.org
Subject: Re: [PATCH v8 08/30] KVM: selftests: TDX: Update
 load_td_memory_region() for VM memory backed by guest memfd



On 8/13/2025 10:42 PM, Reinette Chatre wrote:
> Hi Binbin,
>
> On 8/13/25 2:23 AM, Binbin Wu wrote:
>>
>> On 8/12/2025 4:31 AM, Sean Christopherson wrote:
>>> On Thu, Aug 07, 2025, Sagi Shahar wrote:
>> [...]
>>>> +
>>>>    /*
>>>>     * TD creation/setup/finalization
>>>>     */
>>>> @@ -459,28 +474,35 @@ static void load_td_memory_region(struct kvm_vm *vm,
>>>>        if (!sparsebit_any_set(pages))
>>>>            return;
>>>>    +    if (region->region.guest_memfd != -1)
>>>> +        register_encrypted_memory_region(vm, region);
>>>> +
>>>>        sparsebit_for_each_set_range(pages, i, j) {
>>>>            const uint64_t size_to_load = (j - i + 1) * vm->page_size;
>>>>            const uint64_t offset =
>>>>                (i - lowest_page_in_region) * vm->page_size;
>>>>            const uint64_t hva = hva_base + offset;
>>>>            const uint64_t gpa = gpa_base + offset;
>>>> -        void *source_addr;
>>>> +        void *source_addr = (void *)hva;
>>>>              /*
>>>>             * KVM_TDX_INIT_MEM_REGION ioctl cannot encrypt memory in place.
>>>>             * Make a copy if there's only one backing memory source.
>>>>             */
>>>> -        source_addr = mmap(NULL, size_to_load, PROT_READ | PROT_WRITE,
>>>> -                   MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
>>>> -        TEST_ASSERT(source_addr,
>>>> -                "Could not allocate memory for loading memory region");
>>>> -
>>>> -        memcpy(source_addr, (void *)hva, size_to_load);
>>>> +        if (region->region.guest_memfd == -1) {
>>> Oh, here's the "if".
>> Is it still possible for "region->region.guest_memfd == -1" case?
>> KVM_TDX_INIT_MEM_REGION can only work with guest memfd, right?
>>
> This is still used and supports test "KVM: selftests: TDX: Test
> LOG_DIRTY_PAGES flag to a non-GUEST_MEMFD memslot" found in patch #30 that
> was created to support the issue encountered when QEMU attaches an emulated
> VGA device to a TD. More details available in the fix:
> fbb4adadea55 ("KVM: x86: Make cpu_dirty_log_size a per-VM value")

I think load_td_memory_region() should return directly for non-guest_memfd
region.
In current upstream version, KVM_TDX_INIT_MEM_REGION doesn't support
non-guest_memfd region.

The mmap/memcpy/munmap sequence should be removed because it does nothing but
zero out the original content.



>
> Reinette


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ