From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74826C3DA5D for ; Thu, 25 Jul 2024 18:19:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8A976B008C; Thu, 25 Jul 2024 14:19:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3A3B6B0092; Thu, 25 Jul 2024 14:19:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDB0D6B0093; Thu, 25 Jul 2024 14:19:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AC5976B008C for ; Thu, 25 Jul 2024 14:19:32 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3013E14135A for ; Thu, 25 Jul 2024 18:19:32 +0000 (UTC) X-FDA: 82379087784.25.49FB1A8 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 3DC99120025 for ; Thu, 25 Jul 2024 18:19:30 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=idw+SZnM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3MJeiZgsKCCUBDLFSMFZUOHHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--ackerleytng.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3MJeiZgsKCCUBDLFSMFZUOHHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--ackerleytng.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721931568; a=rsa-sha256; cv=none; b=KMApkgCftfwXHHCJgLTeb69KsnNrOSlc03VfMoWgl92aoZtf0EMKCih7vqrlk8Lv5yDGlU 5ItEwOADUJuEAFFWBOc1lXZYIVz4BrZxJe/PQfg3mxz3q5c24Aw81REFolzf59TE0yQ4BV q9nXH+Xktoj68l6pVrdnNulpY0CO7M0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=idw+SZnM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3MJeiZgsKCCUBDLFSMFZUOHHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--ackerleytng.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3MJeiZgsKCCUBDLFSMFZUOHHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--ackerleytng.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721931568; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9+cWinSd71QUFpeng6pkfteDp9R+YDOSFKPyk/5CKIQ=; b=xM+Yod7BwN5QLxGZCgAJHF4sf+bn+I6dZN3oLpNwi6i4ARze00uChs72xUEBbcclnHwfCk EFFUMmdB0rX+5p4wh+xUhmxrbmJeJDklPaunXyv2/yy9sxI9AvqpqosTMlgwm5YVmofkhD UTP5VM26ML1wqB0u1BCmusFlrlAzNIg= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1fc60ef3076so10500795ad.1 for ; Thu, 25 Jul 2024 11:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721931569; x=1722536369; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9+cWinSd71QUFpeng6pkfteDp9R+YDOSFKPyk/5CKIQ=; b=idw+SZnMexG7lV9KJbc4Y7XNCYnMnq8Y8wOSyjZOYTqMTHl8NwlTHhEvjpjad6m+zy X6ypNBJ1Sy863uOS9/46JUf0AexRw80/bjpQkPqpgUUMVK6Yyqj06gibFjGM5LBAbrW7 lAAIabR71oujz9r+wGhAUeF856y1U5qt7Oj6Qv7PHxzgJ9aho0VwAAP8vRdnDI6e6SIX LsnN9uvUayu3GNvYITf/XkG9R+rFRd4czqXbkmwuXa2VKyWUTZUScb9ZJ6Ip3L8KdMd6 f7B5YvmF4Ky0nj3uFYd1dGJ88ldddTnjvHt3ki2DMH9p82M0z/JKFoTNo8fVFydNp073 MbrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721931569; x=1722536369; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9+cWinSd71QUFpeng6pkfteDp9R+YDOSFKPyk/5CKIQ=; b=n6mKoRbOupX5CL5X3hMYCzyKvm8WlmI5b8BcqRfkHJZOP6+MBPuzuue536+pQIsp8i dmVdJ62CkQ1OJUSbgNb1ZWg5fBc6UK+oBxfvTsIAk54Qt8hjvDpl74kOITE0cDTH2969 GNWW8m2w39TpFkSIV9QBJwjQsnnovh7kWMKMvdH+PDpF4fh+cLOyeVBLrW0yng4QpML9 thllf+HJB/Iq9Fup47vvXN1tQz+hIUMmkkh0wlxWHuLNacaemIpuCwVnI3jDVm616yYk DubK6OyjXm59jt+FguJa3w749QQ5/q1UbrG+QNcTceXvNROmADOpXu5IV+aKPYYIFJA3 7M+g== X-Forwarded-Encrypted: i=1; AJvYcCXVSpSTe5CSkVmFeJ27TzEaIMmra6QedjYyzIvxky5gGQEF/de1X03eIbmOwvOFc5oWbHIvRDKKHTrBqhYXLGw+kHM= X-Gm-Message-State: AOJu0YwDPLI9sg5TlyWqo9yRAO/Fx5406w/46DsM3+zSrE50SEcFt2pg 5buSledwYex+OPeD3GwprMHoAnZq6YROmAOOgvjx6ggv9i/LDcDrTdo7FGeBe+WjCUlBaXjhdYW MBCT93EDbnNi627bnOJvyxQ== X-Google-Smtp-Source: AGHT+IEq0/Qf2aH7olYk0jZU1lYwwK43xAQuSUsE/EQnG/wMgzk9gQAK1/L4A02IBfsH1aseVKWvPS3Vq/ZyFeT5Zw== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a17:903:1ce:b0:1fa:acf0:72d6 with SMTP id d9443c01a7336-1fed909f356mr1844455ad.3.1721931568714; Thu, 25 Jul 2024 11:19:28 -0700 (PDT) Date: Thu, 25 Jul 2024 18:19:27 +0000 In-Reply-To: Mime-Version: 1.0 References: Message-ID: Subject: Re: [RFC PATCH v5 07/29] KVM: selftests: TDX: Update load_td_memory_region for VM memory backed by guest memfd From: Ackerley Tng To: Yan Zhao Cc: sagis@google.com, linux-kselftest@vger.kernel.org, afranji@google.com, erdemaktas@google.com, isaku.yamahata@intel.com, seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org, pgonda@google.com, haibo1.xu@intel.com, chao.p.peng@linux.intel.com, vannapurve@google.com, runanwang@google.com, vipinsh@google.com, jmattson@google.com, dmatlack@google.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Queue-Id: 3DC99120025 X-Rspamd-Server: rspam01 X-Stat-Signature: toz1mpojiit8i4kuotceizite51j8fp6 X-HE-Tag: 1721931570-71146 X-HE-Meta: U2FsdGVkX1/C278XMmhfIN384FNfjkMu/xinNf759Nn0scx99fQocyR2OJfhd8523+kx01C9gRNGlDoEJQPj388dh0Mg+P0r5zIeVMORQNSeaY65+TA15wyLE0XGBtgzGnVAMwkWvl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a5GUJgTtabmN7sqVYCpAfV0pF8rNC+1WvLKCq1jhHGmotsM7LkIQxuBsdCgeY9a9Mq9J5hwl7cywwHd4saAFA+f+rHaLxuv0ohXGG+8XxVWAOrWEVGfxefMJ3C+Qoo+sWgGROju1SpVvEKf2Cgs3f56sqVm660lpIlx3l0/KThniWX6ZKo/TI6AZtvJZUGbQON6LSIb9aekRivl6vpDIxvOD9OB36Kv6uvpbQGmOTFqDGKrYi5J9ctLHfj6auJl7J61BdU9lpU7OcrV9wYUI9NqIQaH4T6d74xkpoS8+fD9ktVs2TMfMQ0nbAut7gjNYNKrI0nVkbrrzmAOCVEtTS0W2prHGU7afDPeBW6nM51mLrc54WK3TA0gwkTEAHfZe2iLAIqcsjvkh6PlAYq2Gq+NUbVLy3XM2cwsQGk X-Bogosity: Ham, tests=bogofilter, spamicity=0.000033, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Ackerley Tng writes: > Yan Zhao writes: > >> On Tue, Dec 12, 2023 at 12:46:22PM -0800, Sagi Shahar wrote: >>> From: Ackerley Tng >>> >>> If guest memory is backed by restricted memfd >>> >>> + UPM is being used, hence encrypted memory region has to be >>> registered >>> + Can avoid making a copy of guest memory before getting TDX to >>> initialize the memory region >>> >>> >> >> For memslot 0, 1, 2, when guest_memfd != -1, >> is it possible to also munmap(mmap_start, mmap_size) after finish loading? >> > > Thank you for your review! > > Did you mean "possible" as in whether it is "correct" to do munmap() for > the rest of the earlier memslots containing non-test-code? > > It is correct because the munmap() just deallocates memory that was > recently allocated in mmap() in this same change. The memory set up for > the VM is not affected. > > > > If we are not using guest_memfd (region->region.guest_memfd == -1), then > we need to make the source and destination address different by copying > the contents at the source address somewhere else for the call to > tdx_init_mem_region(). That is what the mmap() is doing. This temporary > buffer then needs to be freed, hence the munmap(). Without this copying, > the destination address for the ioctl's copy would be the same as the > source address, since those very same pages are provided in the memslot > for this memory region. > Update on this: Since TDX requires the use of guest_memfd, this patch will be simplified in the next revision. The checks for region->region.guest_memfd != -1 will be removed, and there will be no need to do any mmap() or munmap(), so those will be removed as well. > If we are using guest_memfd, then the destination address for the > ioctl's copy will be taken from the guest_memfd, which is already > different from the source address, hence we can skip the copying. > >>> } >>> >>> -- >>> 2.43.0.472.g3155946c3a-goog >>> >>>