From patchwork Thu Feb 29 06:36:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13576557 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E86A45941 for ; Thu, 29 Feb 2024 06:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188885; cv=none; b=A2cD/bILxU4h7AGFrgWWB9qtKky+9Kio3vBwGUK4yQnjuxLHKvYdnw/+Xu6J2w7UvBgADzsUfd+tjswhhZCinx/ViJ9+96G7V6ZFtV0NDZfsoU9Qs7ZFl4pB18GxVRPIhOEwZSf1Uu8xHMQFuyZi5xHNFNm4pd5VcLPW+OeCGBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188885; c=relaxed/simple; bh=e+2C9uKtbhbExisrx4zbEuOZzq0QWHDfGmG/4u6UwRk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LzxMrQqkXmo7pHSqJ6oqX1bhuFLrUv12BaLZZgZeAJWBM7p4RVZuaLhNxNfNg/MfwbSd1UATZfkQt1oEqmNciq9tpiXDt5rlLBaQ9MRPlubjBa59Ya4GQ666bnglV2C7+MI104y/9bTpbgDkTdQpBRMCkaFBtsKhR/doYVkXOX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JdD3R/ty; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JdD3R/ty" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709188884; x=1740724884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e+2C9uKtbhbExisrx4zbEuOZzq0QWHDfGmG/4u6UwRk=; b=JdD3R/tykcE74St6lsCtoqN08xImBt5iydy67IDzz6tg7czepOMXMz7Z BzC4Q1XIVernca5LT7G29CHYOpzXfZVNHgUVHk6LAW3Okw1Eh3ruR/k/v I/3OJ+O6NIxzPmpdO48pvRZ57uOBZd4J85VcXXWklYnm+0FXC0qkkN9Mp wZJpaOIRY1MMivMy5819lgREDBPqvJpxyx4+84rD9vWXMox+8SHgImDUW q+HIt2yM4FYEgrXNIhnTRp8xfkHNfiD88px/gAFBuSJFcvp8Jo3Ru6D+o oN8cpFKYS+qbI8SZwGv6av3bm0BgzAdVT3hhP70168E4y3Ait7HwMKpqo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3802882" X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="3802882" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:41:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="8075656" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by orviesa007.jf.intel.com with ESMTP; 28 Feb 2024 22:41:18 -0800 From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , "Michael S. Tsirkin" , Richard Henderson , Ani Sinha , Peter Xu , Cornelia Huck , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, Michael Roth , Claudio Fontana , Gerd Hoffmann , Isaku Yamahata , Chenyi Qiang , xiaoyao.li@intel.com Subject: [PATCH v5 35/65] memory: Introduce memory_region_init_ram_guest_memfd() Date: Thu, 29 Feb 2024 01:36:56 -0500 Message-Id: <20240229063726.610065-36-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229063726.610065-1-xiaoyao.li@intel.com> References: <20240229063726.610065-1-xiaoyao.li@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce memory_region_init_ram_guest_memfd() to allocate private guset memfd on the MemoryRegion initialization. It's for the use case of TDVF, which must be private on TDX case. Signed-off-by: Xiaoyao Li --- Changes in v5: - drop memory_region_set_default_private() because this function is dropped in this v5 series; --- include/exec/memory.h | 6 ++++++ system/memory.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 679a8476852e..1e351f6fc875 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1603,6 +1603,12 @@ bool memory_region_init_ram(MemoryRegion *mr, uint64_t size, Error **errp); +bool memory_region_init_ram_guest_memfd(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + Error **errp); + /** * memory_region_init_rom: Initialize a ROM memory region. * diff --git a/system/memory.c b/system/memory.c index c756950c0c0f..85a22408e9a4 100644 --- a/system/memory.c +++ b/system/memory.c @@ -3606,6 +3606,31 @@ bool memory_region_init_ram(MemoryRegion *mr, return true; } +bool memory_region_init_ram_guest_memfd(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + Error **errp) +{ + DeviceState *owner_dev; + + if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, size, + RAM_GUEST_MEMFD, errp)) { + return false; + } + + /* This will assert if owner is neither NULL nor a DeviceState. + * We only want the owner here for the purposes of defining a + * unique name for migration. TODO: Ideally we should implement + * a naming scheme for Objects which are not DeviceStates, in + * which case we can relax this restriction. + */ + owner_dev = DEVICE(owner); + vmstate_register_ram(mr, owner_dev); + + return true; +} + bool memory_region_init_rom(MemoryRegion *mr, Object *owner, const char *name,