From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663548; cv=none; d=zohomail.com; s=zohoarc; b=Q5RLNOz3UcVicaLQ6OjNXjve3NEz25I3aa+n2UXoWez6WUvRDv2uNJPahUWWQuBSKT8c6IPxczXoBu8aWXkF48KR9WFHujmj/qT1rw5giuwqSqC3JgaEw2OJiEC2i5eVHRk/3kYR517moiQjDsnqMaqOizImjKhthCRgxBOsVqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663548; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QrRBgZo4qGMLZuEpqNCxbSAOSZQpRBQKzCbR3NDnQLE=; b=CXOiWzWOYKtCOvsHPZOey6UOg1lI+rTh/ewNBHAV3xVZkpMiQqzy09l24VnjGoKqcB7A4elIjrEBuVYbOW/yR/MyB9yd2jSWTWPvtlwyDu4+OaiNbjXiYzuotrJnFviyIeiRCtyG933EuA+33TO6TGsU7LEylcQRP5UTmESEehI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663548551817.9285992872022; Wed, 13 Sep 2023 20:52:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOA-0005kz-OL; Wed, 13 Sep 2023 23:51:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdO7-0005iT-4V for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:31 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdO5-0000q4-Cg for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:30 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:28 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663489; x=1726199489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ekv0ksBj/MNS9E1IHSCjapcpIdXM/HpSUStp7qPoMck=; b=iywCt7EO3sn1RX9gcT1b+iOhHoccktR6lKQjgBV+UDPm//e75UOAKAQk CZw4oF1C56E1BnNa1Bwdncp+2VT7uy6nUA6tcMGTpaMfuJWsQZMnqzZSD gI+XKvoR5K/XjOBIj4gNYXe3UXaD1nivpaE/njlj+CUy8bGdWkjty4bp+ p3mdVbcvwbmTkg7o0n+LKIXLLudXmuCrcGCmS47aAlPaOkhGqP2fLZj1M /5FTjA/vj9nM5U1ofiScxhlKkilus0jbVMKBB1Aj3yf6RMik2f/IXlDhm wcTiOEztPE9e5F6KAztKRXL1SbZuIcPs2IkAtifJdQ5ORlX3bQ9iFgzo/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528283" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528283" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500537" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500537" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 01/21] *** HACK *** linux-headers: Update headers to pull in gmem APIs Date: Wed, 13 Sep 2023 23:50:57 -0400 Message-Id: <20230914035117.3285885-2-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663549649100002 Content-Type: text/plain; charset="utf-8" This patch needs to be updated by script scripts/update-linux-headers.sh once gmem fd support is upstreamed in Linux kernel. Signed-off-by: Xiaoyao Li --- linux-headers/asm-x86/kvm.h | 3 +++ linux-headers/linux/kvm.h | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 2b3a8f7bd2c0..003fb745347c 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -560,4 +560,7 @@ struct kvm_pmu_event_filter { /* x86-specific KVM_EXIT_HYPERCALL flags. */ #define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0) =20 +#define KVM_X86_DEFAULT_VM 0 +#define KVM_X86_SW_PROTECTED_VM 1 + #endif /* _ASM_X86_KVM_H */ diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 1f3f3333a4d8..278bed78f98e 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -95,6 +95,19 @@ struct kvm_userspace_memory_region { __u64 userspace_addr; /* start of the userspace allocated memory */ }; =20 +/* for KVM_SET_USER_MEMORY_REGION2 */ +struct kvm_userspace_memory_region2 { + __u32 slot; + __u32 flags; + __u64 guest_phys_addr; + __u64 memory_size; + __u64 userspace_addr; + __u64 gmem_offset; + __u32 gmem_fd; + __u32 pad1; + __u64 pad2[14]; +}; + /* * The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for * userspace, other bits are reserved for kvm internal use which are defin= ed @@ -102,6 +115,7 @@ struct kvm_userspace_memory_region { */ #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) #define KVM_MEM_READONLY (1UL << 1) +#define KVM_MEM_PRIVATE (1UL << 2) =20 /* for KVM_IRQ_LINE */ struct kvm_irq_level { @@ -264,6 +278,7 @@ struct kvm_xen_exit { #define KVM_EXIT_RISCV_SBI 35 #define KVM_EXIT_RISCV_CSR 36 #define KVM_EXIT_NOTIFY 37 +#define KVM_EXIT_MEMORY_FAULT 38 =20 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -506,6 +521,13 @@ struct kvm_run { #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0) __u32 flags; } notify; + /* KVM_EXIT_MEMORY_FAULT */ + struct { +#define KVM_MEMORY_EXIT_FLAG_PRIVATE (1ULL << 3) + __u64 flags; + __u64 gpa; + __u64 size; + } memory; /* Fix the size of the union. */ char padding[256]; }; @@ -1188,6 +1210,9 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_COUNTER_OFFSET 227 #define KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 228 #define KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES 229 +#define KVM_CAP_USER_MEMORY2 230 +#define KVM_CAP_MEMORY_ATTRIBUTES 231 +#define KVM_CAP_VM_TYPES 232 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 @@ -1462,6 +1487,8 @@ struct kvm_vfio_spapr_tce { struct kvm_userspace_memory_region) #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) #define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64) +#define KVM_SET_USER_MEMORY_REGION2 _IOW(KVMIO, 0x49, \ + struct kvm_userspace_memory_region2) =20 /* enable ucontrol for s390 */ struct kvm_s390_ucas_mapping { @@ -2245,4 +2272,27 @@ struct kvm_s390_zpci_op { /* flags for kvm_s390_zpci_op->u.reg_aen.flags */ #define KVM_S390_ZPCIOP_REGAEN_HOST (1 << 0) =20 +/* Available with KVM_CAP_MEMORY_ATTRIBUTES */ +#define KVM_GET_SUPPORTED_MEMORY_ATTRIBUTES _IOR(KVMIO, 0xd2, __u64) +#define KVM_SET_MEMORY_ATTRIBUTES _IOW(KVMIO, 0xd3, struct k= vm_memory_attributes) + +struct kvm_memory_attributes { + __u64 address; + __u64 size; + __u64 attributes; + __u64 flags; +}; + +#define KVM_MEMORY_ATTRIBUTE_PRIVATE (1ULL << 3) + +#define KVM_CREATE_GUEST_MEMFD _IOWR(KVMIO, 0xd4, struct kvm_create_guest= _memfd) + +#define KVM_GUEST_MEMFD_ALLOW_HUGEPAGE (1ULL << 0) + +struct kvm_create_guest_memfd { + __u64 size; + __u64 flags; + __u64 reserved[6]; +}; + #endif /* __LINUX_KVM_H */ --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663579; cv=none; d=zohomail.com; s=zohoarc; b=ZTkfQKucx+9SiItpEseIG+8hon8qCebyVhHsRB6q19QOrQi0vZRDzlnuXy/FnL/XubmRQA/pMrvPJLBvi8TkQ8aMA0CfD0TDP+Aq9hNv8qdLnZpJdq+/8uq+TuskdCzTHZz5pj7RPmsBt6GbpFSZCen3lj8x05IJ2kTorswo33s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663579; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DDNh/1e/kyWrC02QRaMzHcMuPpRH5At7N+/U5hot6jg=; b=SU5bzifA1HmtAxs2QG+tFebBETREBMaBqW1loGggnZUaHN6epmokp/zNez+0OqQjvor+QuAjqKXJsp9CEdDq3yCBE2Ws5ZDIhZU3yjK/t6qwZEfwTNzYLuUbsZpj1EKWQXwcORB7ui7q9A1r3SuDJ4BuYJYtsQvoslnywaAEwgI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663579561137.72338116677963; Wed, 13 Sep 2023 20:52:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOE-0005lV-Jl; Wed, 13 Sep 2023 23:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOD-0005lI-6X for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:37 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOB-0000r7-9g for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:36 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:32 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663495; x=1726199495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hZCUPboW6UfJI06fOT3oOcMz9rEziUW2umb4XG87Vss=; b=WYyHhUB5zLRDm0IKZ2yOmczURPjSSgClZAe98Y5Eq1p+EH4ohNDcoQK/ n2hio6EcfC+IBzb14UJevNgdKW4N8TZKxCCob/+EGzYG6ix11U78N++HK Pqb/J1rHnEV7GtkeEcqvrXgAZs8NAsVos8wSQF9uhfKj7f/5DvXkwuW/4 yCrkgpsNpaY8nKtxHP1eHrM8wzkWYScpYa2X0F3Em7NQ3NWIQ1FGeDdRB qK+Tzlw2kadrHKKK3crygidkwQvAG4RfqymgjjvHCpEV7htUzjltNsep7 v0ZllkrGvqdnG5wwPeDlUHiBjCeMw2WiVsBThpTH/tBnQlTVLOopuOUHq w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528299" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528299" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500547" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500547" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem Date: Wed, 13 Sep 2023 23:50:58 -0400 Message-Id: <20230914035117.3285885-3-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663581052100005 Content-Type: text/plain; charset="utf-8" From: Chao Peng Add KVM gmem support to RAMBlock so both normal hva based memory and kvm gmem fd based private memory can be associated in one RAMBlock. Introduce new flag RAM_KVM_GMEM. It calls KVM ioctl to create private gmem for the RAMBlock when it's set. Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 17 +++++++++++++++++ include/exec/memory.h | 3 +++ include/exec/ramblock.h | 1 + include/sysemu/kvm.h | 2 ++ softmmu/physmem.c | 18 +++++++++++++++--- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 60aacd925393..185ae16d9620 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -4225,3 +4225,20 @@ void query_stats_schemas_cb(StatsSchemaList **result= , Error **errp) query_stats_schema_vcpu(first_cpu, &stats_args); } } + +int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp) +{ + int fd; + struct kvm_create_guest_memfd gmem =3D { + .size =3D size, + /* TODO: to decide whether KVM_GUEST_MEMFD_ALLOW_HUGEPAGE is suppo= rted */ + .flags =3D flags, + }; + + fd =3D kvm_vm_ioctl(kvm_state, KVM_CREATE_GUEST_MEMFD, &gmem); + if (fd < 0) { + error_setg_errno(errp, errno, "%s: error creating kvm gmem\n", __f= unc__); + } + + return fd; +} diff --git a/include/exec/memory.h b/include/exec/memory.h index 68284428f87c..227cb2578e95 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -235,6 +235,9 @@ typedef struct IOMMUTLBEvent { /* RAM is an mmap-ed named file */ #define RAM_NAMED_FILE (1 << 9) =20 +/* RAM can be private that has kvm gmem backend */ +#define RAM_KVM_GMEM (1 << 10) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 69c6a5390293..0d158b3909c9 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -41,6 +41,7 @@ struct RAMBlock { QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers; int fd; uint64_t fd_offset; + int gmem_fd; size_t page_size; /* dirty bitmap used during migration */ unsigned long *bmap; diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 115f0cca79d1..f5b74c8dd8c5 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -580,4 +580,6 @@ bool kvm_arch_cpu_check_are_resettable(void); bool kvm_dirty_ring_enabled(void); =20 uint32_t kvm_dirty_ring_size(void); + +int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp); #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 3df73542e1fe..2d98a88f41f0 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1824,6 +1824,16 @@ static void ram_block_add(RAMBlock *new_block, Error= **errp) } } =20 + if (kvm_enabled() && new_block->flags & RAM_KVM_GMEM && + new_block->gmem_fd < 0) { + new_block->gmem_fd =3D kvm_create_guest_memfd(new_block->max_lengt= h, + 0, errp); + if (new_block->gmem_fd < 0) { + qemu_mutex_unlock_ramlist(); + return; + } + } + new_ram_size =3D MAX(old_ram_size, (new_block->offset + new_block->max_length) >> TARGET_PAGE_B= ITS); if (new_ram_size > old_ram_size) { @@ -1885,7 +1895,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, =20 /* Just support these ram flags by now. */ assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE | - RAM_PROTECTED | RAM_NAMED_FILE)) =3D=3D 0); + RAM_PROTECTED | RAM_NAMED_FILE | RAM_KVM_GMEM)) = =3D=3D 0); =20 if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -1920,6 +1930,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, new_block->used_length =3D size; new_block->max_length =3D size; new_block->flags =3D ram_flags; + new_block->gmem_fd =3D -1; new_block->host =3D file_ram_alloc(new_block, size, fd, readonly, !file_size, offset, errp); if (!new_block->host) { @@ -1978,7 +1989,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ra= m_addr_t max_size, Error *local_err =3D NULL; =20 assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | - RAM_NORESERVE)) =3D=3D 0); + RAM_NORESERVE| RAM_KVM_GMEM)) =3D=3D 0); assert(!host ^ (ram_flags & RAM_PREALLOC)); =20 size =3D HOST_PAGE_ALIGN(size); @@ -1990,6 +2001,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ra= m_addr_t max_size, new_block->max_length =3D max_size; assert(max_size >=3D size); new_block->fd =3D -1; + new_block->gmem_fd =3D -1; new_block->page_size =3D qemu_real_host_page_size(); new_block->host =3D host; new_block->flags =3D ram_flags; @@ -2012,7 +2024,7 @@ RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, vo= id *host, RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { - assert((ram_flags & ~(RAM_SHARED | RAM_NORESERVE)) =3D=3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_NORESERVE | RAM_KVM_GMEM)) =3D= =3D 0); return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, = errp); } =20 --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663569; cv=none; d=zohomail.com; s=zohoarc; b=QTotFSdH+9+bIDcLpGiazC4MVH/Ix9aKsR6wA/30XKnOnoNPtr969S2Mji7XnGjBis1/RkJ9M1KmKd0aMNlIQ5uxXiaajow6N5Es9320++b/w664Oy2eM3asoEfm9mI1W71EQXph29O2AkyfQz0F7kPqSlRIDtw2by0RZoaY64U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663569; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wYbvJjt1pSz5t0eobO0kentrqcw5V6pU8cLW6L0lTa0=; b=EXXtLrXb78tORX9YC9pxy/e6iAT7MD81tSsRWALEosdFtSmLzTwACFpbYTchDol7RI8OYG1nphIRYv4smoPir6a/eine4PMHBimHZuA7A/1icYJh8KpG74axsB1WsYudDgM3+yMS6iCJRgLNdvLXMRBmR5iF2y4hRt90H1ZW0gg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663569186590.8492731934896; Wed, 13 Sep 2023 20:52:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOJ-0005lt-5M; Wed, 13 Sep 2023 23:51:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOF-0005ll-SN for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:39 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOD-0000r7-Vr for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:39 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:37 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663498; x=1726199498; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H92kwpzNZpBa5P3PcIKApYqTKPa48fU3DQboSoQydpY=; b=MvL4AuYQsXN+iqX23qNSzqGivEDjkzTnxhf+z/obF1O6/1MGQdlrHEkD baYfAFJJmG2RDoffMvwwLQAt36gu6IM7QfsbLbrCx86fXcEJPYP3LBDSd pGLD7EFcEIJ/Ge+T0dULgF46tYpfcZ3ZTVgNehWMygOpl8Wqw2lkT4nJ4 /l4V4aIPu/C2RL7dJEDPD9hWA33QKrSLZaXXLkdTcHbwKqfeKu5uNR66s 9iheLHDwDdZ2xgodO4wrbd40AD1okCBeGaADLjIiF/3Kvti4wyhlmZu0r QKZ2YS10R+BlLZ2EQMErae6so5uMx7zCWpBbx26MtEkjnAKuxFubdbS90 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528315" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528315" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500557" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500557" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 03/21] HostMem: Add private property and associate it with RAM_KVM_GMEM Date: Wed, 13 Sep 2023 23:50:59 -0400 Message-Id: <20230914035117.3285885-4-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663570133100003 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata Add a new property "private" to memory backends. When it's set to true, it indicates the RAMblock of the backend also requires kvm gmem. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- backends/hostmem-file.c | 1 + backends/hostmem-memfd.c | 1 + backends/hostmem-ram.c | 1 + backends/hostmem.c | 18 ++++++++++++++++++ include/sysemu/hostmem.h | 2 +- qapi/qom.json | 4 ++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index b4335a80e6da..861f76f2de8a 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -56,6 +56,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Err= or **errp) name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |=3D backend->private ? RAM_KVM_GMEM : 0; ram_flags |=3D fb->is_pmem ? RAM_PMEM : 0; ram_flags |=3D RAM_NAMED_FILE; memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name, diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 3fc85c3db81b..f49990ce3bbd 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -55,6 +55,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |=3D backend->private ? RAM_KVM_GMEM : 0; memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, ram_flags, fd, 0, errp); g_free(name); diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index b8e55cdbd0f8..d6c46250dcfd 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -30,6 +30,7 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Erro= r **errp) name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |=3D backend->private ? RAM_KVM_GMEM : 0; memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), = name, backend->size, ram_flags, errp); g_free(name); diff --git a/backends/hostmem.c b/backends/hostmem.c index 747e7838c031..dbdbb0aafd45 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -461,6 +461,20 @@ static void host_memory_backend_set_reserve(Object *o,= bool value, Error **errp) } backend->reserve =3D value; } + +static bool host_memory_backend_get_private(Object *o, Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + + return backend->private; +} + +static void host_memory_backend_set_private(Object *o, bool value, Error *= *errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + + backend->private =3D value; +} #endif /* CONFIG_LINUX */ =20 static bool @@ -541,6 +555,10 @@ host_memory_backend_class_init(ObjectClass *oc, void *= data) host_memory_backend_get_reserve, host_memory_backend_set_reserve); object_class_property_set_description(oc, "reserve", "Reserve swap space (or huge pages) if applicable"); + object_class_property_add_bool(oc, "private", + host_memory_backend_get_private, host_memory_backend_set_private); + object_class_property_set_description(oc, "private", + "Use KVM gmem private memory"); #endif /* CONFIG_LINUX */ /* * Do not delete/rename option. This option must be considered stable diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index 39326f1d4f9c..d88970395618 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -65,7 +65,7 @@ struct HostMemoryBackend { /* protected */ uint64_t size; bool merge, dump, use_canonical_path; - bool prealloc, is_mapped, share, reserve; + bool prealloc, is_mapped, share, reserve, private; uint32_t prealloc_threads; ThreadContext *prealloc_context; DECLARE_BITMAP(host_nodes, MAX_NODES + 1); diff --git a/qapi/qom.json b/qapi/qom.json index fa3e88c8e6ab..d28c5403bc0f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -605,6 +605,9 @@ # @reserve: if true, reserve swap space (or huge pages) if applicable # (default: true) (since 6.1) # +# @private: if true, use KVM gmem private memory (default: false) +# (since 8.2) +# # @size: size of the memory region in bytes # # @x-use-canonical-path-for-ramblock-id: if true, the canonical path @@ -631,6 +634,7 @@ '*prealloc-context': 'str', '*share': 'bool', '*reserve': 'bool', + '*private': 'bool', 'size': 'size', '*x-use-canonical-path-for-ramblock-id': 'bool' } } =20 --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663524; cv=none; d=zohomail.com; s=zohoarc; b=K015d27FAyUFsz5za9RtgYLPRTc7YGLIW4YzSZDJoZ+bozBz/X8VUO2ANcKwQIawGXWi7YhXbg1Tn5aXKUSuuru/wRM7tLMDP6rE1VqxjWDHSrCrqzrWVroE8KyNtBopHfmmq+MHp9YI5BvDkMKyvywMhg+ntSusefu1Y0rO7AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663524; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OU+8SR8TL3WLcNApDAr6LpNgwMjoeSq7E+xmsbkUibk=; b=IjTTSwxqIQYpC1OElkW5bVsd7jA9LDRipyUZkYIS6QVdIsGny1SnjFgKC/pVNMNiy2tVKP/CKdyZ0V8t16/v+Wm9B/37hCivTuIGJ1o8UuapMPoKUwvHjRPtEctDf4htiTh+UMim42VtfhqLePPMf6ih0toYvbPNi5uRY5CA5Bc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663524452834.6677488616094; Wed, 13 Sep 2023 20:52:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOL-0005mQ-Q5; Wed, 13 Sep 2023 23:51:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOK-0005mH-9H for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:44 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOI-0000r7-Hv for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:44 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:41 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663502; x=1726199502; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Bz7wCSve/nZkE1jWq4TK9eEpAIR2dm0qaoQY8fTWjd8=; b=OCSLnPlrwZEYrx9SB8yPkD6FBxzkTY/4sIwxBx0FDLxEfhtd250L5sC8 pU486caFbudLR2sGcSGXDFzbITmOrpp6uRaXnV95nx9dTpDB+FHk2bLCe nqnqif87auRbZiuSkFoNyHOke/Wuq37draFYx3yrNhRTxlhTK9p+hS8JU VqsgJx/GB5s391Jly7xG89ubtouVZnexKujCbe4fF5Y6BvF2Rn8DoktX/ 2TXE3Fz4jzXVKm7Kts/lLb5KjOuLY2APNODymOnlW65Vj5MYR7BmKnQOn Qnj80SX9avOdQYx2NamNeYqxMgfCEWnPWdGvCUovdS1cbCq06o9Anluz3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528331" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528331" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500562" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500562" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 04/21] memory: Introduce memory_region_has_gmem_fd() Date: Wed, 13 Sep 2023 23:51:00 -0400 Message-Id: <20230914035117.3285885-5-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663525154100003 Content-Type: text/plain; charset="utf-8" Introduce memory_region_has_gmem_fd() to query if the MemoryRegion has KVM gmem fd allocated. Signed-off-by: Xiaoyao Li --- include/exec/memory.h | 10 ++++++++++ softmmu/memory.c | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 227cb2578e95..4b8486ca3632 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1674,6 +1674,16 @@ static inline bool memory_region_is_romd(MemoryRegio= n *mr) */ bool memory_region_is_protected(MemoryRegion *mr); =20 +/** + * memory_region_has_gmem_fd: check whether a memory region has KVM gmem fd + * associated + * + * Returns %true if a memory region's ram_block has valid gmem fd assigned. + * + * @mr: the memory region being queried + */ +bool memory_region_has_gmem_fd(MemoryRegion *mr); + /** * memory_region_get_iommu: check whether a memory region is an iommu * diff --git a/softmmu/memory.c b/softmmu/memory.c index 7d9494ce7028..e69a5f96d5d1 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1846,6 +1846,11 @@ bool memory_region_is_protected(MemoryRegion *mr) return mr->ram && (mr->ram_block->flags & RAM_PROTECTED); } =20 +bool memory_region_has_gmem_fd(MemoryRegion *mr) +{ + return mr->ram_block && mr->ram_block->gmem_fd >=3D 0; +} + uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) { uint8_t mask =3D mr->dirty_log_mask; --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663640; cv=none; d=zohomail.com; s=zohoarc; b=SiXtO+tq0JS9pQnr5YLvf83VUjQE/rmV3WA01vK+PBCCFy3aiibFZ211lhxECDMVE9iZifZPU7am0Qz5Rt/EEs8n7pIQv9aAxxOVCwtbrJZdND4y+AQ3rctNcZqLxUJyqy1WpQS70V8qZ+HBISYwjXwzIpNlpQgUylWkoRPsvCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663640; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TnohJQA2A6mcY0fE8fJZlec9Dwm72UmlV4vWRlAlk3c=; b=FSQ9Tf3cDoYkQOiY2yKvFQnh0iQeoGV7nfbrD2Mt8ssHdgqbGNKc2jLk/W17Xs7ny1vBnxMr6aioQ8aVV0QMX1E2J0j4+rAbCo7gAtBNAUfu8rUVJkb2OdYMFv0JTAu/cIMNknmXwktnRuLpd8YRoiSLhNTIuLULrCYypv7xGD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663640759537.6732939389703; Wed, 13 Sep 2023 20:54:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOQ-0005nN-GO; Wed, 13 Sep 2023 23:51:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOP-0005mr-L0 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:49 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdON-0000r7-Hn for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:49 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:46 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663507; x=1726199507; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/jXG+nYWes+m4u3i/upIK6DDfXg0VKkiaU2dn2txLpQ=; b=S2u4G2034YW1GEIPGzruJpxc4ll9Yme6W4/Hu7ORwy39v60cA1D7IMlv UWb3A1E5FRjyuW8lD14RcbL7K514RAWZsdNpfQYyvUKpxuGeVKzeN5VCX 3xQ4UDeuWkkH+sTTir1ZJYfG2lDEeBDQr3qqY2wvoGxseP1y9ChvC6J72 4coWh3vQoqgnhW+emSUM/qt4+WHLSXueSbu8rK4imxNdIPz/87zh3MCVq xO3Si4dOg/z9Hqj+hEeLOLUnyVs9nqNkEc1aayPGzXLPsbuQrRgDKfzyZ uwaHzBB+Z3gOoab/9YpXOS/QSjks0dWmfXwPlp8Zc48i4S1kaWq6BERQp A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528348" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528348" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500567" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500567" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 05/21] kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot Date: Wed, 13 Sep 2023 23:51:01 -0400 Message-Id: <20230914035117.3285885-6-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663642612100002 Content-Type: text/plain; charset="utf-8" From: Chao Peng Switch to KVM_SET_USER_MEMORY_REGION2 when supported by KVM. With KVM_SET_USER_MEMORY_REGION2, QEMU can set up memory region that backend'ed both by hva-based shared memory and gmem fd based private memory. Signed-off-by: Chao Peng Codeveloped-by: Xiaoyao Li Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 55 ++++++++++++++++++++++++++++++++++------ accel/kvm/trace-events | 2 +- include/sysemu/kvm_int.h | 2 ++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 185ae16d9620..91cee0878366 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -288,35 +288,68 @@ int kvm_physical_memory_addr_from_host(KVMState *s, v= oid *ram, static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slo= t, bool new) { KVMState *s =3D kvm_state; - struct kvm_userspace_memory_region mem; + struct kvm_userspace_memory_region2 mem; + static int cap_user_memory2 =3D -1; int ret; =20 + if (cap_user_memory2 =3D=3D -1) { + cap_user_memory2 =3D kvm_check_extension(s, KVM_CAP_USER_MEMORY2); + } + + if (!cap_user_memory2 && slot->gmem_fd >=3D 0) { + error_report("%s, KVM doesn't support gmem!", __func__); + exit(1); + } + mem.slot =3D slot->slot | (kml->as_id << 16); mem.guest_phys_addr =3D slot->start_addr; mem.userspace_addr =3D (unsigned long)slot->ram; mem.flags =3D slot->flags; + mem.gmem_fd =3D slot->gmem_fd; + mem.gmem_offset =3D slot->ofs; =20 if (slot->memory_size && !new && (mem.flags ^ slot->old_flags) & KVM_M= EM_READONLY) { /* Set the slot size to 0 before setting the slot to the desired * value. This is needed based on KVM commit 75d61fbc. */ mem.memory_size =3D 0; - ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + + if (cap_user_memory2) { + ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION2, &mem); + } else { + ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + } if (ret < 0) { goto err; } } mem.memory_size =3D slot->memory_size; - ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + if (cap_user_memory2) { + ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION2, &mem); + } else { + ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + } slot->old_flags =3D mem.flags; err: trace_kvm_set_user_memory(mem.slot >> 16, (uint16_t)mem.slot, mem.flag= s, mem.guest_phys_addr, mem.memory_size, - mem.userspace_addr, ret); + mem.userspace_addr, mem.gmem_fd, + mem.gmem_offset, ret); if (ret < 0) { - error_report("%s: KVM_SET_USER_MEMORY_REGION failed, slot=3D%d," - " start=3D0x%" PRIx64 ", size=3D0x%" PRIx64 ": %s", - __func__, mem.slot, slot->start_addr, - (uint64_t)mem.memory_size, strerror(errno)); + if (cap_user_memory2) { + error_report("%s: KVM_SET_USER_MEMORY_REGION2 failed, slot= =3D%d," + " start=3D0x%" PRIx64 ", size=3D0x%" PRIx64 "," + " flags=3D0x%" PRIx32 "," + " gmem_fd=3D%" PRId32 ", gmem_offset=3D0x%" PRIx64= ": %s", + __func__, mem.slot, slot->start_addr, + (uint64_t)mem.memory_size, mem.flags, + mem.gmem_fd, (uint64_t)mem.gmem_offset, + strerror(errno)); + } else { + error_report("%s: KVM_SET_USER_MEMORY_REGION failed, slot= =3D%d," + " start=3D0x%" PRIx64 ", size=3D0x%" PRIx64 ":= %s", + __func__, mem.slot, slot->start_addr, + (uint64_t)mem.memory_size, strerror(errno)); + } } return ret; } @@ -472,6 +505,9 @@ static int kvm_mem_flags(MemoryRegion *mr) if (readonly && kvm_readonly_mem_allowed) { flags |=3D KVM_MEM_READONLY; } + if (memory_region_has_gmem_fd(mr)) { + flags |=3D KVM_MEM_PRIVATE; + } return flags; } =20 @@ -1402,6 +1438,9 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->ram_start_offset =3D ram_start_offset; mem->ram =3D ram; mem->flags =3D kvm_mem_flags(mr); + mem->gmem_fd =3D mr->ram_block->gmem_fd; + mem->ofs =3D (uint8_t*)ram - mr->ram_block->host; + kvm_slot_init_dirty_bitmap(mem); err =3D kvm_set_user_memory_region(kml, mem, true); if (err) { diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index 14ebfa1b991c..80694683acea 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -15,7 +15,7 @@ kvm_irqchip_update_msi_route(int virq) "Updating MSI rout= e virq=3D%d" kvm_irqchip_release_virq(int virq) "virq %d" kvm_set_ioeventfd_mmio(int fd, uint64_t addr, uint32_t val, bool assign, u= int32_t size, bool datamatch) "fd: %d @0x%" PRIx64 " val=3D0x%x assign: %d = size: %d match: %d" kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint32_t val, bool assign, ui= nt32_t size, bool datamatch) "fd: %d @0x%x val=3D0x%x assign: %d size: %d m= atch: %d" -kvm_set_user_memory(uint16_t as, uint16_t slot, uint32_t flags, uint64_t g= uest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, int ret) "Ad= drSpace#%d Slot#%d flags=3D0x%x gpa=3D0x%"PRIx64 " size=3D0x%"PRIx64 " ua= =3D0x%"PRIx64 " ret=3D%d" +kvm_set_user_memory(uint16_t as, uint16_t slot, uint32_t flags, uint64_t g= uest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, uint32_t fd,= uint64_t fd_offset, int ret) "AddrSpace#%d Slot#%d flags=3D0x%x gpa=3D0x%"= PRIx64 " size=3D0x%"PRIx64 " ua=3D0x%"PRIx64 " gmem_fd=3D%d" " gmem_fd_offs= et=3D0x%" PRIx64 " ret=3D%d" kvm_clear_dirty_log(uint32_t slot, uint64_t start, uint32_t size) "slot#%"= PRId32" start 0x%"PRIx64" size 0x%"PRIx32 kvm_resample_fd_notify(int gsi) "gsi %d" kvm_dirty_ring_full(int id) "vcpu %d" diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 511b42bde5c4..9990889d3494 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -30,6 +30,8 @@ typedef struct KVMSlot int as_id; /* Cache of the offset in ram address space */ ram_addr_t ram_start_offset; + int gmem_fd; + hwaddr ofs; } KVMSlot; =20 typedef struct KVMMemoryUpdate { --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663539; cv=none; d=zohomail.com; s=zohoarc; b=QxvOW4uPzgTY8fnrEI4r99Z/yG+wpcJyvxDETejrpQ/I3qQeu9f23/oYIBFpWQQl6utc6jI5uy1J0syLIWDvaVCsAD1Mbf8jvumvNHHQSwfn18NjuhKCQ0VUR/Cz1/2BNllQguRZ61JmoiM9TyL5phmCZPesuAbn8NyT5uPl/zU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663539; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z+mYHbocYa4KsB2gvgctb9x5xA5iHPaQ4W1Pv99gKo4=; b=Dd7F34+3g+iMrkF2iAJ2Hnmcvfb0yS1khIGIVGjBJ2ouvFx1yWixxqPbkQ4tV4vf8C71SJxZfV1bzzgOEn0RZG6cxnUQ+2AXjpIwCX853IO8aRdD33juKK1ZgKRkOuElL8pUDvxHUey+oFHcNP4LCTNbmrkQ8znXh1Gu8H1xrdI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663539594715.9425897072103; Wed, 13 Sep 2023 20:52:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOW-0005np-5c; Wed, 13 Sep 2023 23:51:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOT-0005ne-Ob for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:53 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOR-0000r7-V9 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:53 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:51 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663511; x=1726199511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nXW61my95eNNBPjniGhuCSrvIHpi6M9elto/Cof61xQ=; b=Tr08YD+kckJ5qvZDg7gO2p2K0gzOBJ/D/OvKq7w49LExeoy2tjoN2efW G4GrKAYgHunjVn15IufJgFPEaYE7FX3IaUfPKDnJ7CKAke4zSfnqndjMR uInDvOp4MvN+hZllA8FrK3Vlkx+MSvUpWbk0Owgn5B+9D2ZvbhKbxNlI7 aQC38Ag2d/3glrSCNiCK6WeqsMyy2Lg+YxwIl1jdAUTMweAR392A1pwZr lLDHT19OO6WFfu4IubGv8+B5+gRQGr296MLQfJX2gtV5ORpFdiYnWcsxJ 5afr7Lu/jSLIF/lVIbm6kOfsHrqZMtIsOd9x0gvqNJO9Zy+48kH5cmRjj A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528360" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528360" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500581" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500581" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 06/21] i386: Add support for sw-protected-vm object Date: Wed, 13 Sep 2023 23:51:02 -0400 Message-Id: <20230914035117.3285885-7-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663540651100001 Content-Type: text/plain; charset="utf-8" Introduce sw-protected-vm object which implements the interface of CONFIDENTIAL_GUEST_SUPPORT, and will be used to create X86_SW_PROTECTED_VM via $qemu -machine ...,confidential-guest-support=3Dsp-vm0 \ -object sw-protected-vm,id=3Dsp-vm0 Signed-off-by: Xiaoyao Li --- qapi/qom.json | 1 + target/i386/kvm/meson.build | 1 + target/i386/kvm/sw-protected-vm.c | 35 +++++++++++++++++++++++++++++++ target/i386/kvm/sw-protected-vm.h | 17 +++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 target/i386/kvm/sw-protected-vm.c create mode 100644 target/i386/kvm/sw-protected-vm.h diff --git a/qapi/qom.json b/qapi/qom.json index d28c5403bc0f..be054ee2f348 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -944,6 +944,7 @@ 'if': 'CONFIG_SECRET_KEYRING' }, 'sev-guest', 'thread-context', + 'sw-protected-vm', 's390-pv-guest', 'throttle-group', 'tls-creds-anon', diff --git a/target/i386/kvm/meson.build b/target/i386/kvm/meson.build index 40fbde96cac6..a31e760b3f19 100644 --- a/target/i386/kvm/meson.build +++ b/target/i386/kvm/meson.build @@ -5,6 +5,7 @@ i386_softmmu_kvm_ss =3D ss.source_set() i386_softmmu_kvm_ss.add(files( 'kvm.c', 'kvm-cpu.c', + 'sw-protected-vm.c', )) =20 i386_softmmu_kvm_ss.add(when: 'CONFIG_XEN_EMU', if_true: files('xen-emu.c'= )) diff --git a/target/i386/kvm/sw-protected-vm.c b/target/i386/kvm/sw-protect= ed-vm.c new file mode 100644 index 000000000000..62a1d3d5d3fe --- /dev/null +++ b/target/i386/kvm/sw-protected-vm.c @@ -0,0 +1,35 @@ +/* + * QEMU X86_SW_PROTECTED_VM SUPPORT + * + * Author: + * Xiaoyao Li + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory + * + */ + +#include "qemu/osdep.h" +#include "qom/object_interfaces.h" + +#include "sw-protected-vm.h" + +/* x86-sw-protected-vm */ +OBJECT_DEFINE_TYPE_WITH_INTERFACES(SwProtectedVm, + sw_protected_vm, + SW_PROTECTED_VM, + CONFIDENTIAL_GUEST_SUPPORT, + { TYPE_USER_CREATABLE }, + { NULL }) + +static void sw_protected_vm_init(Object *obj) +{ +} + +static void sw_protected_vm_finalize(Object *obj) +{ +} + +static void sw_protected_vm_class_init(ObjectClass *oc, void *data) +{ +} diff --git a/target/i386/kvm/sw-protected-vm.h b/target/i386/kvm/sw-protect= ed-vm.h new file mode 100644 index 000000000000..db192a81c75e --- /dev/null +++ b/target/i386/kvm/sw-protected-vm.h @@ -0,0 +1,17 @@ +#ifndef QEMU_I386_SW_PROTECTED_VM_H +#define QEMU_I386_SW_PROTECTED_VM_H + +#include "exec/confidential-guest-support.h" + +#define TYPE_SW_PROTECTED_VM "sw-protected-vm" +#define SW_PROTECTED_VM(obj) OBJECT_CHECK(SwProtectedVm, (obj), TYPE_SW= _PROTECTED_VM) + +typedef struct SwProtectedVmClass { + ConfidentialGuestSupportClass parent_class; +} SwProtectedVmClass; + +typedef struct SwProtectedVm { + ConfidentialGuestSupport parent_obj; +} SwProtectedVm; + +#endif /* QEMU_I386_SW_PROTECTED_VM_H */ --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663671; cv=none; d=zohomail.com; s=zohoarc; b=Xlp6QG5Ac7oWTdDGJ7n1diThl+S/IDAqevt0cleZ2kW9yrPntoN1OhUrFXI5G2LBInFNQGR6n5ffRBHo/OFXF39o0lQ3kZ0bLdPCgbnjKbuJtofEMkR+oKE79GDW31wdi5rJKCUWMMuyKFP11Xq7SDBRa92jxna9cFMy4v1aDxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663671; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fRDxxiIXx3Wus4Ct28M5mdUfqyb1v3+wKCd/0MkJdNM=; b=NujrRx31LewENn4UmU7nIfmW3sUep08cQMvH3bYjX+Zm8OGvmIFHD0APomDtt4r8BTKj+pMgQ6wv/uuZEF/1JLRtGIBQPVuF0Rdh/3attiYPKzBvusmUFORHqargbKGTKLQ6n4QOluzPVBfM+DrX9pXh+zLOpVR4pJbyraFgKwc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663671481243.2448737813761; Wed, 13 Sep 2023 20:54:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOa-0006Ac-5F; Wed, 13 Sep 2023 23:52:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOY-0005xQ-Fx for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:58 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOW-0000r7-Ob for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:51:58 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:51:55 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663516; x=1726199516; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FG1fIIQsL7KuIyJ5EhfyBMqHsFgdwKABD8LZczmIAnc=; b=PyNw6cSHFQ35uOy18lfxKMIZXZPY48DxxSGc6kDgBbWPeNOCQwC9+MEB B5UyV/WCjfuC02zuXaOqZrmTgIadwxUdt4JbUVGqQcezggXz58tX7RVTj HGORQe5cuXYBtfZFIawXMzH1R2cXr6yZtW15wx7ZR02W6tt/57K1D+OkE kcN5cWbaAFZvAIZ0iPXR7tBqtmDV5JKABFmazWIOHVR3CUJsdaMFpY3mV JAdPe6oUvphdK4Axrb1l0KL3bPFvzhivQKb04x/XD/Ihn5+JBRGpkHiTt jDukPPlGypyhecsnImdj+ow6Xb1B8SVWB7Vk55dVavxeywkj9TlSFg/zC g==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528393" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528393" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500592" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500592" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 07/21] i386/pc: Drop pc_machine_kvm_type() Date: Wed, 13 Sep 2023 23:51:03 -0400 Message-Id: <20230914035117.3285885-8-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663673116100003 Content-Type: text/plain; charset="utf-8" pc_machine_kvm_type() was introduced by commit e21be724eaf5 ("i386/xen: add pc_machine_kvm_type to initialize XEN_EMULATE mode") to do Xen specific initialization by utilizing kvm_type method. commit eeedfe6c6316 ("hw/xen: Simplify emulated Xen platform init") moves the Xen specific initialization to pc_basic_device_init(). There is no need to keep the PC specific kvm_type() implementation anymore. On the other hand, later patch will implement kvm_type() method for all x86/i386 machines to support KVM_X86_SW_PROTECTED_VM. Signed-off-by: Xiaoyao Li Reviewed-by: Isaku Yamahata Acked-by: David Woodhouse Reviewed-by: David Hildenbrand --- hw/i386/pc.c | 5 ----- include/hw/i386/pc.h | 3 --- 2 files changed, 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 3109d5e0e035..abeadd903827 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1794,11 +1794,6 @@ static void pc_machine_initfn(Object *obj) cxl_machine_init(obj, &pcms->cxl_devices_state); } =20 -int pc_machine_kvm_type(MachineState *machine, const char *kvm_type) -{ - return 0; -} - static void pc_machine_reset(MachineState *machine, ShutdownCause reason) { CPUState *cs; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index d54e8b1101e4..c98d628a76f3 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -296,15 +296,12 @@ extern const size_t pc_compat_1_5_len; extern GlobalProperty pc_compat_1_4[]; extern const size_t pc_compat_1_4_len; =20 -int pc_machine_kvm_type(MachineState *machine, const char *vm_type); - #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \ static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *da= ta) \ { \ MachineClass *mc =3D MACHINE_CLASS(oc); \ optsfn(mc); \ mc->init =3D initfn; \ - mc->kvm_type =3D pc_machine_kvm_type; \ } \ static const TypeInfo pc_machine_type_##suffix =3D { \ .name =3D namestr TYPE_MACHINE_SUFFIX, \ --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663579; cv=none; d=zohomail.com; s=zohoarc; b=H/fH3LdBmY5S6i1pcIntqmSDdVtJ6sXeP6+bgWzbdzl6uvTOBiexjmHe3ISg4yz/ch+aW4Bs7aGPyvgrX0UkuYGUQ8Obh7yet6j34ryc0oXS7C+mr3tmlKHK7QhKIfvfl4CGXRg3aeAzL+48gw+IM2tn9+0kxaLrw9jsrPBxLfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663579; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8z3FMd83pT1syilWeHdbF6kjceI9Rju2PCdqnuViitE=; b=Ckzka+ZFqIop3c70bRsBLo80yVl2v/LMAN4yskkqSywxsMom0zHMaDy0OY+Ckc22bKlDQRPPHtzZTC9oloofBGefuG3ecV2in7Bfc0pAyGxBuSOVDOhz7ZIMhdTcTIsLac4ELC8fnJ8ksg3ItmejqmvxG0cVT8pn0Rhn7RSuZdQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663579465883.0458932406342; Wed, 13 Sep 2023 20:52:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOe-0006df-RR; Wed, 13 Sep 2023 23:52:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOd-0006VL-2N for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:03 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOb-0000r7-6v for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:02 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:00 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:51:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663521; x=1726199521; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8xg5bqjhBbAM8gPiQzHBRvDRVKCRRm1mhZpgTQ/bsFc=; b=jQpDTDcUpcnxirxhw6LRF6RGNhKOy7uVYxcJUJnz3KzOS7bLAQuUVrjk ayg6tiEwZfkttGV7bu0SUPl/+7RyNpDT6s5a4QAziOrfTumSwvMtIOalq gv7gSaFwz+PTE7m00Np0Yg1FT1hWww9dB1uU8mr7rT9ij7+85DF6FbOCZ 35VWDIx4ty3iX5+x2agrNZF1xzJPuzzjkIOFHQUlWOLfURhDDvUkwqFAq qjdC5ejad0RdMWvA8lZDVHY5cWhkDVlfQA86sspUfROZbSXb6TWDgZ4rE QuNIw766ad6+2X8OlX3qGL+cYv6tHMaYiKL+uhgXQ+IS4LiwnSDwBaDW6 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528409" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528409" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500596" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500596" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 08/21] target/i386: Implement mc->kvm_type() to get VM type Date: Wed, 13 Sep 2023 23:51:04 -0400 Message-Id: <20230914035117.3285885-9-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663580399100003 Content-Type: text/plain; charset="utf-8" Implement mc->kvm_type() for i386 machines. It provides a way for user to create SW_PROTECTE_VM. Also store the vm_type in machinestate to other code to query what the VM type is. Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 12 ++++++++++++ include/hw/i386/x86.h | 1 + target/i386/kvm/kvm.c | 30 ++++++++++++++++++++++++++++++ target/i386/kvm/kvm_i386.h | 1 + 4 files changed, 44 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index a88a126123be..660f83935315 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1382,6 +1382,17 @@ static void machine_set_sgx_epc(Object *obj, Visitor= *v, const char *name, qapi_free_SgxEPCList(list); } =20 +static int x86_kvm_type(MachineState *ms, const char *vm_type) +{ + X86MachineState *x86ms =3D X86_MACHINE(ms); + int kvm_type; + + kvm_type =3D kvm_get_vm_type(ms, vm_type); + x86ms->vm_type =3D kvm_type; + + return kvm_type; +} + static void x86_machine_initfn(Object *obj) { X86MachineState *x86ms =3D X86_MACHINE(obj); @@ -1406,6 +1417,7 @@ static void x86_machine_class_init(ObjectClass *oc, v= oid *data) mc->cpu_index_to_instance_props =3D x86_cpu_index_to_props; mc->get_default_cpu_node_id =3D x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids =3D x86_possible_cpu_arch_ids; + mc->kvm_type =3D x86_kvm_type; x86mc->save_tsc_khz =3D true; x86mc->fwcfg_dma_enabled =3D true; nc->nmi_monitor_handler =3D x86_nmi; diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index da19ae15463a..ab1d38569019 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -41,6 +41,7 @@ struct X86MachineState { MachineState parent; =20 /*< public >*/ + unsigned int vm_type; =20 /* Pointers to devices and objects: */ ISADevice *rtc; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index f8cc8eb1fe70..d1cf6c1f63b3 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -32,6 +32,7 @@ #include "sysemu/runstate.h" #include "kvm_i386.h" #include "sev.h" +#include "sw-protected-vm.h" #include "xen-emu.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -154,6 +155,35 @@ static KVMMSRHandlers msr_handlers[KVM_MSR_FILTER_MAX_= RANGES]; static RateLimit bus_lock_ratelimit_ctrl; static int kvm_get_one_msr(X86CPU *cpu, int index, uint64_t *value); =20 +static const char* vm_type_name[] =3D { + [KVM_X86_DEFAULT_VM] =3D "default", + [KVM_X86_SW_PROTECTED_VM] =3D "sw-protected-vm", +}; + +int kvm_get_vm_type(MachineState *ms, const char *vm_type) +{ + int kvm_type =3D KVM_X86_DEFAULT_VM; + + if (ms->cgs && object_dynamic_cast(OBJECT(ms->cgs), TYPE_SW_PROTECTED_= VM)) { + kvm_type =3D KVM_X86_SW_PROTECTED_VM; + } + + /* + * old KVM doesn't support KVM_CAP_VM_TYPES and KVM_X86_DEFAULT_VM + * is always supported + */ + if (kvm_type =3D=3D KVM_X86_DEFAULT_VM) { + return kvm_type; + } + + if (!(kvm_check_extension(KVM_STATE(ms->accelerator), KVM_CAP_VM_TYPES= ) & BIT(kvm_type))) { + error_report("vm-type %s not supported by KVM", vm_type_name[kvm_t= ype]); + exit(1); + } + + return kvm_type; +} + int kvm_has_pit_state2(void) { return has_pit_state2; diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index e24753abfe6a..ea3a5b174ac0 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -37,6 +37,7 @@ bool kvm_has_adjust_clock(void); bool kvm_has_adjust_clock_stable(void); bool kvm_has_exception_payload(void); void kvm_synchronize_all_tsc(void); +int kvm_get_vm_type(MachineState *ms, const char *vm_type); void kvm_arch_reset_vcpu(X86CPU *cs); void kvm_arch_after_reset_vcpu(X86CPU *cpu); void kvm_arch_do_init_vcpu(X86CPU *cs); --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663541; cv=none; d=zohomail.com; s=zohoarc; b=ORDbtUTStQp2MSAjxQX/gy3z4eKzrzZCWR4XR/7x3ZPlp/EUzqyuNuLLw1b3CcRjhdT4y5Yjw1GBfz3ROclQdQae6YS9ftTJ1YaqyrhGli3QZ5QSG7hEHExEmFxtvdaNIzJqWkWeFQyKemY1QLLtLeBBttLjbpTq+dyv18puebg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663541; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ih7z9DUQHVk6F+5hO8Ecd7YX5gp03od48bIlWFeY08s=; b=UCN/kUCbm9SFe8r4QMDoSqN6JIn5fy84y8B/4aq9+7fB7uNGN4HzKXEgxistgbfh8zotYIqxCVqkAneQqMYZXzu2YrVQDEHiQ4y0dqgJKgle+qSH+L3OQXEarr5ioqi0mZ/4b2+L3FzsGOrQEn66u22wuTm5s9hQ8dKlnqNzrd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663541842686.5552180256516; Wed, 13 Sep 2023 20:52:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOi-0006fs-0T; Wed, 13 Sep 2023 23:52:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOh-0006fc-3a for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:07 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOf-0000r7-EG for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:06 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:04 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663525; x=1726199525; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=irH/wLKdEugUhkFaQFSUiyQL8CkBW40MSIixqkcbXPo=; b=VVHC0issyyfXfyLFe2pTW/GqQaWym6Zhl2IIuFHGPD5jARuVN+PRKtmc LY40cPZZqUbAd1S/WjrSTX5xt0teA4HnlWqvX1Io8ci2IvGlerxUOY1r9 OwitTU70U+SasddJ9xtj8a788p/EDla5hZyLeMSzZh/7bKGKk1ttvROjc z2TP7sxpmUsn8bZiC1bT1zgTINvRX1yUYsrUuWXLAkhfFoHzfQgJzUmZd fkxWFbjwhFyiT0wjeNLaYTt74oIznr5UL/ZnTTcleq02VCYbGl6m2kYAF Pg9ojA4w2xlGO2KXyqXmjei26r4lFHBebGUzKvsUb4uDnd5yDaEflCBKI w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528422" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528422" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500599" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500599" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 09/21] target/i386: Introduce kvm_confidential_guest_init() Date: Wed, 13 Sep 2023 23:51:05 -0400 Message-Id: <20230914035117.3285885-10-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663542676100005 Introduce a separate function kvm_confidential_guest_init(), which dispatches specific confidential guest initialization function by ms->cgs type. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/i386/kvm/kvm.c | 11 ++++++++++- target/i386/sev.c | 1 - target/i386/sev.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index d1cf6c1f63b3..fb1be16471b4 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2583,6 +2583,15 @@ static void register_smram_listener(Notifier *n, voi= d *unused) &smram_address_space, 1, "kvm-smram"); } =20 +static int kvm_confidential_guest_init(MachineState *ms, Error **errp) +{ + if (object_dynamic_cast(OBJECT(ms->cgs), TYPE_SEV_GUEST)) { + return sev_kvm_init(ms->cgs, errp); + } + + return 0; +} + int kvm_arch_init(MachineState *ms, KVMState *s) { uint64_t identity_base =3D 0xfffbc000; @@ -2603,7 +2612,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) * mechanisms are supported in future (e.g. TDX), they'll need * their own initialization either here or elsewhere. */ - ret =3D sev_kvm_init(ms->cgs, &local_err); + ret =3D kvm_confidential_guest_init(ms, &local_err); if (ret < 0) { error_report_err(local_err); return ret; diff --git a/target/i386/sev.c b/target/i386/sev.c index fe2144c0388b..5aa04863846d 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -39,7 +39,6 @@ #include "hw/i386/pc.h" #include "exec/address-spaces.h" =20 -#define TYPE_SEV_GUEST "sev-guest" OBJECT_DECLARE_SIMPLE_TYPE(SevGuestState, SEV_GUEST) =20 =20 diff --git a/target/i386/sev.h b/target/i386/sev.h index 7b1528248a54..64fbf186dbd2 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -20,6 +20,8 @@ =20 #include "exec/confidential-guest-support.h" =20 +#define TYPE_SEV_GUEST "sev-guest" + #define SEV_POLICY_NODBG 0x1 #define SEV_POLICY_NOKS 0x2 #define SEV_POLICY_ES 0x4 --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663603; cv=none; d=zohomail.com; s=zohoarc; b=G2tutIi6EC0LOZ8blIb29R6RVcgSpefQXmeo0JEXLwpWvx31AGjWaVGjV6R80UMGuJBMT8xsDVrEi7ecBQCmcAenm0SYQuSIb8iqS7ZuUpHlbXF7oHUnJZLuD2GYq2BTI1+dvg/cKnhpXRZgLn6F4D1lcX1b+83YZnVCaKADIAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663603; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1PMcUzA4ZTsZ+ZGFmLRjSGEeTzSw+CjQxSEXCwbMttY=; b=ZNCBpz43h9+zXw4ZusfRCADMEtORuTELQ+uwydkFejJRj6et6tMLVyDXOVtvIodWq4sYKxRpxbAW47VfEwC+ZnZsuq/la+3Bv63e1l0Hw1NV4W4XahF6Q/vVPGIg5y8z/ojlSfOvfCZ/uzJBs5j/9VXSFcNgMr8y7xgFi9fLPFc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663603732411.44140834605537; Wed, 13 Sep 2023 20:53:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOm-0006gq-Vs; Wed, 13 Sep 2023 23:52:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOl-0006gQ-Ai for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:11 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOj-0000r7-PL for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:11 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:08 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663529; x=1726199529; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WYVBZ6N9BbdY7ZsfmGtk4oyUMldz486IyDgKkpOyBr4=; b=DIrb8MNo7A/KZmewECEmS91nUmO8076l4wHO+kD6NlJE/LlXcBdkQOfX KOsvnfFeh6OXo/fhep3cdTEgh8a8AbVhdksOcb0iS5XJ+crSAJJ24nDyM 4xm60I53CXrAJkERj9JdDruP+R8dXlSG1dHKdss9JUKyYkjbiRGx+FaAb a0s/8oomMiaREtBIksjlzT7hIfer6ZqMmP3KeoJls1AF7576QKzu5qd4Y koOjvlrb41U4J8/hgdQvRD7FQbdhGe7riImyyQDSVXBGZ7dU4sOgk+CXq BBduCdaBROmuvLZLXeYFNP5sTXR4NnEThS4YWBwEbTb2aAeVgt8wX/VJP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528441" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528441" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500603" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500603" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 10/21] i386/kvm: Implement kvm_sw_protected_vm_init() for sw-protcted-vm specific functions Date: Wed, 13 Sep 2023 23:51:06 -0400 Message-Id: <20230914035117.3285885-11-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663605036100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 2 ++ target/i386/kvm/sw-protected-vm.c | 10 ++++++++++ target/i386/kvm/sw-protected-vm.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index fb1be16471b4..e126bf4e7ddd 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2587,6 +2587,8 @@ static int kvm_confidential_guest_init(MachineState *= ms, Error **errp) { if (object_dynamic_cast(OBJECT(ms->cgs), TYPE_SEV_GUEST)) { return sev_kvm_init(ms->cgs, errp); + } else if (object_dynamic_cast(OBJECT(ms->cgs), TYPE_SW_PROTECTED_VM))= { + return sw_protected_vm_kvm_init(ms, errp); } =20 return 0; diff --git a/target/i386/kvm/sw-protected-vm.c b/target/i386/kvm/sw-protect= ed-vm.c index 62a1d3d5d3fe..3cfcc89202a6 100644 --- a/target/i386/kvm/sw-protected-vm.c +++ b/target/i386/kvm/sw-protected-vm.c @@ -10,10 +10,20 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "qom/object_interfaces.h" =20 +#include "hw/i386/x86.h" #include "sw-protected-vm.h" =20 +int sw_protected_vm_kvm_init(MachineState *ms, Error **errp) +{ + SwProtectedVm *spvm =3D SW_PROTECTED_VM(OBJECT(ms->cgs)); + + spvm->parent_obj.ready =3D true; + return 0; +} + /* x86-sw-protected-vm */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(SwProtectedVm, sw_protected_vm, diff --git a/target/i386/kvm/sw-protected-vm.h b/target/i386/kvm/sw-protect= ed-vm.h index db192a81c75e..15f63bfc7c60 100644 --- a/target/i386/kvm/sw-protected-vm.h +++ b/target/i386/kvm/sw-protected-vm.h @@ -14,4 +14,6 @@ typedef struct SwProtectedVm { ConfidentialGuestSupport parent_obj; } SwProtectedVm; =20 +int sw_protected_vm_kvm_init(MachineState *ms, Error **errp); + #endif /* QEMU_I386_SW_PROTECTED_VM_H */ --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663594; cv=none; d=zohomail.com; s=zohoarc; b=Wzg+WUOGqEENB1Uhnkwy7wDuoPFSkAfELeEi/dzPrMMwL0Fhl/aNCiVR9GRItwVj5iir8ND4P4ytPZ7bbOI0jCfLjOswSUB9YRL4sAqstqgZRz/EJUX8Z3IpT963e5qfJJKkfaNSBj4uVhu+yZmhGEsmURKLqKhWlg9yatKcxPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663594; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sy6LkyuW/6CeNnQdyymCIApmsiZ2KrpAEg2CT7VUmN0=; b=j/vOVO5L4tTxKThYotKB3AHD5n/Gg490OOOfqPiR0MM2A5mcebP9rzKKAx/0BO5lt/5HJQ1hcTU7gv1EEl6J+TeWe9gL2tXqpvGeaPIUM/KsGNQNtanu8FWiEJixcAxPNp8WJF3B6j4Mq/b44ti7dw+uNAFh1tVjrGF4teJumSw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663594411546.7008950905617; Wed, 13 Sep 2023 20:53:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOr-0006hL-IF; Wed, 13 Sep 2023 23:52:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOq-0006hB-52 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:16 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOo-0000r7-E1 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:15 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:13 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663534; x=1726199534; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vCKRMaNknqFrFUgJ/LQCwxN585GwBYkxwhiQ9YWmWXg=; b=i3jvRYU+U6t5dspDKPilpLSPPr/qc/nw1IOSmWG0Zj0lqX0dKld2W5Ft c9xvWrmaWyC6CGocisqoNf9u5PqBT6iAQmrlpetSxFOjkqNGwgZzNOs9C LBiyQFimsmxQqCKkLoNqwmCDFa5NEI6RQAvTcCmCqn40iwA10lmxpOBJe QEB+bo1yMuMu/tbo5ilsuieQGfcUflWsWjmFOkmT1Hz003f56u0yjYhfO jxm64AqvnN0EKXgW2alIyXAbHckzc+8fM//L36JBismZ71t+jW3J8uvUx TMfgvWNaSlFzmKrNfj/cwFa1mlEjGQOtpW9vPWZRwoNpP1D+p7bYigZKw g==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528456" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528456" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500606" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500606" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 11/21] kvm: Introduce support for memory_attributes Date: Wed, 13 Sep 2023 23:51:07 -0400 Message-Id: <20230914035117.3285885-12-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663595336100001 Content-Type: text/plain; charset="utf-8" Introcude the helper functions to set the attributes of a range of memory to private and shared. Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/sysemu/kvm.h | 3 +++ 2 files changed, 46 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 91cee0878366..eeccc6317fa9 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -105,6 +105,7 @@ bool kvm_msi_use_devid; bool kvm_has_guest_debug; static int kvm_sstep_flags; static bool kvm_immediate_exit; +static uint64_t kvm_supported_memory_attributes; static hwaddr kvm_max_slot_size =3D ~0; =20 static const KVMCapabilityInfo kvm_required_capabilites[] =3D { @@ -1343,6 +1344,44 @@ void kvm_set_max_memslot_size(hwaddr max_slot_size) kvm_max_slot_size =3D max_slot_size; } =20 +static int kvm_set_memory_attributes(hwaddr start, hwaddr size, uint64_t a= ttr) +{ + struct kvm_memory_attributes attrs; + int r; + + attrs.attributes =3D attr; + attrs.address =3D start; + attrs.size =3D size; + attrs.flags =3D 0; + + r =3D kvm_vm_ioctl(kvm_state, KVM_SET_MEMORY_ATTRIBUTES, &attrs); + if (r) { + warn_report("%s: failed to set memory (0x%lx+%#zx) with attr 0x%lx= error '%s'", + __func__, start, size, attr, strerror(errno)); + } + return r; +} + +int kvm_set_memory_attributes_private(hwaddr start, hwaddr size) +{ + if (!(kvm_supported_memory_attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE))= { + error_report("KVM doesn't support PRIVATE memory attribute\n"); + return -EINVAL; + } + + return kvm_set_memory_attributes(start, size, KVM_MEMORY_ATTRIBUTE_PRI= VATE); +} + +int kvm_set_memory_attributes_shared(hwaddr start, hwaddr size) +{ + if (!(kvm_supported_memory_attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE))= { + error_report("KVM doesn't support PRIVATE memory attribute\n"); + return -EINVAL; + } + + return kvm_set_memory_attributes(start, size, 0); +} + /* Called with KVMMemoryListener.slots_lock held */ static void kvm_set_phys_mem(KVMMemoryListener *kml, MemoryRegionSection *section, bool add) @@ -2556,6 +2595,10 @@ static int kvm_init(MachineState *ms) } s->as =3D g_new0(struct KVMAs, s->nr_as); =20 + if (kvm_check_extension(s, KVM_CAP_MEMORY_ATTRIBUTES)) { + kvm_supported_memory_attributes =3D kvm_ioctl(s, KVM_GET_SUPPORTED= _MEMORY_ATTRIBUTES, 0); + } + if (object_property_find(OBJECT(current_machine), "kvm-type")) { g_autofree char *kvm_type =3D object_property_get_str(OBJECT(curre= nt_machine), "kvm-type", diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index f5b74c8dd8c5..0f78f1246c7f 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -582,4 +582,7 @@ bool kvm_dirty_ring_enabled(void); uint32_t kvm_dirty_ring_size(void); =20 int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp); + +int kvm_set_memory_attributes_private(hwaddr start, hwaddr size); +int kvm_set_memory_attributes_shared(hwaddr start, hwaddr size); #endif --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663560; cv=none; d=zohomail.com; s=zohoarc; b=P2Wmh1U4v7d4b1N2jX2PYxkdMRjiUBXN/NYvXFuy0nBpE1D6VDQPyh8+vb8E9RI78Ck29YbkB16XlQv1v2K9WkMQoESzhtKej8jsUUOq05XX1jBccb3b+I87NKjvhEk5B4/23kmAqG9ZciVBDKakeOQym+LHiazKdN/DnJYvg4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663560; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6yHI9pZOsz4eqkMZMZYCVbeD94xbKDKZjg1Jhi89vDQ=; b=np+j/mWAu3W/5Y1wevHe207Cr4rlK2T2WjZnsrhFkvFPcptwwA/mefSBpwyv1lz4Mh5v7P8FLJwrCpyUEpDAEn7nbEglOvGsaeSUmwIa8dHMr0y2GOvfFcEHfbb6q9RQTn4e55v9NIVoLHa2fSzzZIEDQKFHxrc4Kui6DdLQr2c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663560561492.94387131382325; Wed, 13 Sep 2023 20:52:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdOw-00071X-6E; Wed, 13 Sep 2023 23:52:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOu-0006nf-Mb for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:20 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOs-0000r7-Ov for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:20 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:18 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663538; x=1726199538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CMoUkTu0XoMVNmvzrbCVHiTlm286z9ePGh8MA6ueE+o=; b=ahyRE0PUsn2osuFBnWwzNZzEjilcV9DGtqQLDVd06K6L4YWgGH6OJPOR 2AXHShpkJbQ2PCpsM4z7VKWZcK7+upAy+WnBYaRKS3oklUWymfD0+jxu7 jyHQW65W2gSGT3tuY04oq19UGXHe+LIjYOAIV5FP393DbgwwYs1iiS5wh akgq7FV5Y+TPJSgztAelUS0Ep9thPlobTtIeOuJbJ5smMhljS5hqu2b2/ AEFHFi+k77zsbeXX/PrHPwtW56RN5+BAAXZf3cYn/jHHZId+bntBkB2EG J0uGLsLbEby2cvXA1OtSrBrNyBIi+DCmXkL6gU7FH5j536AeZ841fFL7J Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528471" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528471" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500617" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500617" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 12/21] kvm/memory: Introduce the infrastructure to set the default shared/private value Date: Wed, 13 Sep 2023 23:51:08 -0400 Message-Id: <20230914035117.3285885-13-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663561042100001 Content-Type: text/plain; charset="utf-8" Introduce new flag RAM_DEFAULT_PRIVATE for RAMBlock. It's used to indicate the default attribute, private or not. Set the RAM range to private explicitly when it's default private. Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 10 ++++++++++ include/exec/memory.h | 6 ++++++ softmmu/memory.c | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index eeccc6317fa9..7e32ee83b258 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1487,6 +1487,16 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, strerror(-err)); abort(); } + + if (memory_region_is_default_private(mr)) { + err =3D kvm_set_memory_attributes_private(start_addr, slot_siz= e); + if (err) { + error_report("%s: failed to set memory attribute private: = %s\n", + __func__, strerror(-err)); + exit(1); + } + } + start_addr +=3D slot_size; ram_start_offset +=3D slot_size; ram +=3D slot_size; diff --git a/include/exec/memory.h b/include/exec/memory.h index 4b8486ca3632..2c738b5dc420 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -238,6 +238,9 @@ typedef struct IOMMUTLBEvent { /* RAM can be private that has kvm gmem backend */ #define RAM_KVM_GMEM (1 << 10) =20 +/* RAM is default private */ +#define RAM_DEFAULT_PRIVATE (1 << 11) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, @@ -1684,6 +1687,9 @@ bool memory_region_is_protected(MemoryRegion *mr); */ bool memory_region_has_gmem_fd(MemoryRegion *mr); =20 +void memory_region_set_default_private(MemoryRegion *mr); +bool memory_region_is_default_private(MemoryRegion *mr); + /** * memory_region_get_iommu: check whether a memory region is an iommu * diff --git a/softmmu/memory.c b/softmmu/memory.c index e69a5f96d5d1..dc5d0d7703b5 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1851,6 +1851,19 @@ bool memory_region_has_gmem_fd(MemoryRegion *mr) return mr->ram_block && mr->ram_block->gmem_fd >=3D 0; } =20 +bool memory_region_is_default_private(MemoryRegion *mr) +{ + return memory_region_has_gmem_fd(mr) && + (mr->ram_block->flags & RAM_DEFAULT_PRIVATE); +} + +void memory_region_set_default_private(MemoryRegion *mr) +{ + if (memory_region_has_gmem_fd(mr)) { + mr->ram_block->flags |=3D RAM_DEFAULT_PRIVATE; + } +} + uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) { uint8_t mask =3D mr->dirty_log_mask; --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663649; cv=none; d=zohomail.com; s=zohoarc; b=Vfzz3ueLv343yThRphp4iHr5r4I6EeNymDzXQN1jvD7lzyfJVQBVsftzlEG+Io6O2759AeZeZKAziqi4Rx+LyWlWsaIOXtB9/b8Kk7xYl8SI50uP21tuzFvCikpCqgOy5Xo0LxGbTKEJ8JHJ5aXYwy9EMgQpO062tLkWdHgtOf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663649; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qO8MKA6up8WF0vqPNVbD5T0jvCJW+fnX7COqaq6KUwo=; b=LfBVNs/1YDVef4kP23t3QvdjAT69J9yHCbsny9MPylgEoIUsjj9yMJ+MOin3ChZAroQXH2y+A2O84bK3zkff17h2+RQIwwBCquHV/frRJ9mBst6Or5m/TiYC9+GoYV7r4Y9yS7Rmf/WsVelZQeOUXB0dMOKdldJ39zc0pbQFIwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169466364978082.3459471630772; Wed, 13 Sep 2023 20:54:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdP0-0007FM-Rv; Wed, 13 Sep 2023 23:52:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOz-0007Dl-Bo for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:25 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdOx-0000r7-Kp for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:25 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:22 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663543; x=1726199543; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eKloPCcRi+HIRDzS+h7jCyuEt7bYm6PhIvGdqysJsx8=; b=CODPZ7y83/toBuJ3Pa9/G2/PjbH4unXpjTi+5msW0fxteLbWFkhxEoKk hDCb0GfUllPgV20Vrlk6LsJNeKA3vndNP/2o+PszsQfRUk6mQqNSKuF2I 5qszPDMaB9WzQdiZRg6ba17skSUTStQBwVKNVxMEk2iD6RDdEo7zV+naY yPmVIB2e7cztFgZf+pxkCzL4nfqQomqxT3Rr30mjZQYw+IM+ngYs7JS6r p3XazqPwwBGeqVZX1/Bpe8hPNP8ImmZXT5HC4QTffd58cxY/91l1twc3J F4FuHvE3mPtbEQZDXZALIjm68t9oDwk/Y9X3Xk1mQzHR1zQf3Av96g4Kw w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528480" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528480" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500625" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500625" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 13/21] i386/kvm: Set memory to default private for KVM_X86_SW_PROTECTED_VM Date: Wed, 13 Sep 2023 23:51:09 -0400 Message-Id: <20230914035117.3285885-14-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663650125100001 Content-Type: text/plain; charset="utf-8" Register a memory listener for KVM_X86_SW_PROVTED_VM. It set RAM to private by default. Signed-off-by: Xiaoyao Li --- include/exec/memory.h | 1 + target/i386/kvm/sw-protected-vm.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 2c738b5dc420..a2602b783a38 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -820,6 +820,7 @@ struct IOMMUMemoryRegion { #define MEMORY_LISTENER_PRIORITY_MIN 0 #define MEMORY_LISTENER_PRIORITY_ACCEL 10 #define MEMORY_LISTENER_PRIORITY_DEV_BACKEND 10 +#define MEMORY_LISTENER_PRIORITY_ACCEL_HIGH 20 =20 /** * struct MemoryListener: callbacks structure for updates to the physical = memory map diff --git a/target/i386/kvm/sw-protected-vm.c b/target/i386/kvm/sw-protect= ed-vm.c index 3cfcc89202a6..f47ac383e1dd 100644 --- a/target/i386/kvm/sw-protected-vm.c +++ b/target/i386/kvm/sw-protected-vm.c @@ -12,14 +12,32 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qom/object_interfaces.h" +#include "exec/address-spaces.h" +#include "sysemu/kvm.h" =20 #include "hw/i386/x86.h" #include "sw-protected-vm.h" =20 +static void kvm_x86_sw_protected_vm_region_add(MemoryListener *listenr, + MemoryRegionSection *sectio= n) +{ + memory_region_set_default_private(section->mr); +} + +static MemoryListener kvm_x86_sw_protected_vm_memory_listener =3D { + .name =3D "kvm_x86_sw_protected_vm_memory_listener", + .region_add =3D kvm_x86_sw_protected_vm_region_add, + /* Higher than KVM memory listener =3D 10. */ + .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL_HIGH, +}; + int sw_protected_vm_kvm_init(MachineState *ms, Error **errp) { SwProtectedVm *spvm =3D SW_PROTECTED_VM(OBJECT(ms->cgs)); =20 + memory_listener_register(&kvm_x86_sw_protected_vm_memory_listener, + &address_space_memory); + spvm->parent_obj.ready =3D true; return 0; } --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663584; cv=none; d=zohomail.com; s=zohoarc; b=QdlQfmsOaUv2mTldHWFhYjAHGtH8GblM85NwcIlHdKwihKQAeBH0mvY/efufWxyCIhgLPNPl24TnHLdtESYx7Ci+QRqT4oF1nHdVkeVErUZgSGrLfvJsU/laQLRgqCRfmtJ+b9KSlBavW3dWgkQnlCHbSn0kmm/u7rTHv4FAiKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663584; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yo5Y6k+krNUAbATZALwuvHpy1Mt08pLGjvO1CHdszCg=; b=ErcDkuoB5FtWgNu2CxMdQblP9xPQJjL9LZdbNGlKaCM0etk30zgzn0layylG1lb7vadz58pEsmWnsRufr46zIpwxl8pK9Vicw0Se9nuzDFPIzYexmNhxri/peL8cfk7m2NGXVYRhN7q6TRDXZcFJ+NdI4KDiopqdkPdcUTGKvoI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663584762452.1929025057681; Wed, 13 Sep 2023 20:53:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPA-0007e5-SO; Wed, 13 Sep 2023 23:52:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdP4-0007UF-Sa for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:31 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdP2-0000r7-QK for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:30 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:27 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663548; x=1726199548; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K9SNVbRXg6fOO0WdYvXxGQ1S9s3Q8v1uTfTUmIhxgis=; b=WS7d9WyyX25MgVDO+83b7jyj72q0A+QXmWjPGBu4cDVFu+MLAl96522Z ooc1N1bbldHGh5vbdPSp84IPEjo5rVKLoXSCO0w+44Hw+wh+k9QSdBAJr UImkQDdkzaSjoYD1rWs+pVVH0x7dmQDogIUc1Tg3Y/lrUuX1o7c0nVQL1 F2S8ria3dOkyHMnxchMkurYIUAubbyUJMZJ7JmyrcaxDMg7mWCi3RDfkg 9yV5NMYdX8d7HhqSvvDtGZYmg5AKZ9VuR7sQ54SC9dwVC9nsn8VvpZQPB pCQBvzoikWknxhMmQDzBuOxoGGSXE9UrZVxhk6pIcJv70bLK+EzbJGdEl A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528492" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528492" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500650" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500650" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 14/21] physmem: replace function name with __func__ in ram_block_discard_range() Date: Wed, 13 Sep 2023 23:51:10 -0400 Message-Id: <20230914035117.3285885-15-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663586623100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaoyao Li --- softmmu/physmem.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 2d98a88f41f0..34d580ec0d39 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3440,16 +3440,15 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t = start, size_t length) uint8_t *host_startaddr =3D rb->host + start; =20 if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) { - error_report("ram_block_discard_range: Unaligned start address: %p= ", - host_startaddr); + error_report("%s: Unaligned start address: %p", + __func__, host_startaddr); goto err; } =20 if ((start + length) <=3D rb->max_length) { bool need_madvise, need_fallocate; if (!QEMU_IS_ALIGNED(length, rb->page_size)) { - error_report("ram_block_discard_range: Unaligned length: %zx", - length); + error_report("%s: Unaligned length: %zx", __func__, length); goto err; } =20 @@ -3479,27 +3478,26 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t = start, size_t length) * file. */ if (!qemu_ram_is_shared(rb)) { - warn_report_once("ram_block_discard_range: Discarding RAM" + warn_report_once("%s: Discarding RAM" " in private file mappings is possibly" " dangerous, because it will modify the" " underlying file and will affect other" - " users of the file"); + " users of the file", __func__); } =20 ret =3D fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEE= P_SIZE, start, length); if (ret) { ret =3D -errno; - error_report("ram_block_discard_range: Failed to fallocate= " - "%s:%" PRIx64 " +%zx (%d)", - rb->idstr, start, length, ret); + error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx = (%d)", + __func__, rb->idstr, start, length, ret); goto err; } #else ret =3D -ENOSYS; - error_report("ram_block_discard_range: fallocate not available= /file" + error_report("%s: fallocate not available/file" "%s:%" PRIx64 " +%zx (%d)", - rb->idstr, start, length, ret); + __func__, rb->idstr, start, length, ret); goto err; #endif } @@ -3517,25 +3515,23 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t = start, size_t length) } if (ret) { ret =3D -errno; - error_report("ram_block_discard_range: Failed to discard r= ange " + error_report("%s: Failed to discard range " "%s:%" PRIx64 " +%zx (%d)", - rb->idstr, start, length, ret); + __func__, rb->idstr, start, length, ret); goto err; } #else ret =3D -ENOSYS; - error_report("ram_block_discard_range: MADVISE not available" - "%s:%" PRIx64 " +%zx (%d)", - rb->idstr, start, length, ret); + error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%= d)", + __func__, rb->idstr, start, length, ret); goto err; #endif } trace_ram_block_discard_range(rb->idstr, host_startaddr, length, need_madvise, need_fallocate, ret); } else { - error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu= 64 - "/%zx/" RAM_ADDR_FMT")", - rb->idstr, start, length, rb->max_length); + error_report("%s: Overrun block '%s' (%" PRIu64 "/%zx/" RAM_ADDR_F= MT")", + __func__, rb->idstr, start, length, rb->max_length); } =20 err: --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663625; cv=none; d=zohomail.com; s=zohoarc; b=Hb3GpVsl9nzO59WDCLR0DrjPcDLYl3W2qIqZEwooqiq7B84lmPVj/Dg102mtLixkOgmc4l0qUBkvwnR5rZWBPDW4rkw1G4dW+xI4pg5f2e6j1dRkk202RNhiDUsxqWpTNHtIKr5VnLZ9LJP93JJWWBQnrhFieROMVhN/ZmOwkmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663625; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u3ZmwtXmD6KeejGIl0lOjGN/NDxKP0KrPNwQ8nX2LJ4=; b=OnkGBrFJWeFwHG6HezQ+sH+x0U4ufE7eJgLMKuU46ZeCrOLvIoDGxARKkmbmPuIsXKExUtNuKuB9ur+aFYymjHGyk8bS0XHp+u8Rn8zOWFOvnj+3JbHZu2vY8ceSDCJ7O26phl86IOcSGZPu0N6q/DVYMvrTKlBcvKNPuembE28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663625131972.0135312577555; Wed, 13 Sep 2023 20:53:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPJ-000837-0B; Wed, 13 Sep 2023 23:52:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdP9-0007dp-2d for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:36 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdP6-0000r7-Ko for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:34 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:31 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663552; x=1726199552; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P7JD5Z/Zea9/ImjYPBZjZe+vU1JZG61vgXwgTLUb5Js=; b=g2D/R85zhhIMkPTEeRC7h9Sdl+FtU6IeP6v2fK0yrDR3iyDOCBis5w7Z zDX0npoIcP/0MqlxaTZfw99EBuS2cTE5RAFHgO6qpIA5+Gh78vDnVDFIF 0eON0ClbcPUSPBiyLj4NuNIS+rXZ/jZ7rZpNkkdIH9VVHspZ1TdSDWl34 ydeB+mpNLNpIrJHxnIVXL7f3IH7qeRbtz4oA04U5fQC7j7yZS08LBdKuO hhwvolvCSqK+IrUq+WMUqhUsDR/IgpO/kpks7zhUN2kMkaK+v2hzdhmly epP8FkwpqgBKZRG1GBuoiPgEldXgd9fAp/Lzjc3RCv6HIU2dBtTYQFwAz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528503" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528503" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500659" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500659" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 15/21] physmem: extract ram_block_discard_range_fd() from ram_block_discard_range() Date: Wed, 13 Sep 2023 23:51:11 -0400 Message-Id: <20230914035117.3285885-16-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663625384100001 Content-Type: text/plain; charset="utf-8" Extract the alignment check and sanity check out from ram_block_discard_range() into a seperate function ram_block_discard_range_fd(), which can be passed with an explicit fd as input parameter. ram_block_discard_range_fd() can be used to discard private memory range from gmem fd with later patch. When doing private memory <-> shared memory conversion, it requires 4KB alignment instead of RamBlock.page_size. Signed-off-by: Xiaoyao Li --- softmmu/physmem.c | 192 ++++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 92 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 34d580ec0d39..6ee6bc794f44 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3425,117 +3425,125 @@ int qemu_ram_foreach_block(RAMBlockIterFunc func,= void *opaque) return ret; } =20 +static int ram_block_discard_range_fd(RAMBlock *rb, uint64_t start, + size_t length, int fd) +{ + uint8_t *host_startaddr =3D rb->host + start; + bool need_madvise, need_fallocate; + int ret =3D -1; + + errno =3D ENOTSUP; /* If we are missing MADVISE etc */ + + /* The logic here is messy; + * madvise DONTNEED fails for hugepages + * fallocate works on hugepages and shmem + * shared anonymous memory requires madvise REMOVE + */ + need_madvise =3D (rb->page_size =3D=3D qemu_host_page_size) && (rb->fd= =3D=3D fd); + need_fallocate =3D fd !=3D -1; + + if (need_fallocate) { + /* For a file, this causes the area of the file to be zero'd + * if read, and for hugetlbfs also causes it to be unmapped + * so a userfault will trigger. + */ +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE + /* + * We'll discard data from the actual file, even though we only + * have a MAP_PRIVATE mapping, possibly messing with other + * MAP_PRIVATE/MAP_SHARED mappings. There is no easy way to + * change that behavior whithout violating the promised + * semantics of ram_block_discard_range(). + * + * Only warn, because it works as long as nobody else uses that + * file. + */ + if (!qemu_ram_is_shared(rb)) { + warn_report_once("%s: Discarding RAM" + " in private file mappings is possibly" + " dangerous, because it will modify the" + " underlying file and will affect other" + " users of the file", __func__); + } + + ret =3D fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + start, length); + if (ret) { + ret =3D -errno; + error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)= ", + __func__, rb->idstr, start, length, ret); + return ret; + } +#else + ret =3D -ENOSYS; + error_report("%s: fallocate not available/file " + "%s:%" PRIx64 " +%zx (%d)", + __func__, rb->idstr, start, length, ret); + return ret; +#endif + } + + if (need_madvise) { + /* For normal RAM this causes it to be unmapped, + * for shared memory it causes the local mapping to disappear + * and to fall back on the file contents (which we just + * fallocate'd away). + */ +#if defined(CONFIG_MADVISE) + if (qemu_ram_is_shared(rb) && fd < 0) { + ret =3D madvise(host_startaddr, length, QEMU_MADV_REMOVE); + } else { + ret =3D madvise(host_startaddr, length, QEMU_MADV_DONTNEED); + } + if (ret) { + ret =3D -errno; + error_report("%s: Failed to discard range %s:%" PRIx64 " +%zx = (%d)", + __func__, rb->idstr, start, length, ret); + return ret; + } +#else + ret =3D -ENOSYS; + error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%d)", + __func__, rb->idstr, start, length, ret); + return ret; +#endif + } + + trace_ram_block_discard_range(rb->idstr, host_startaddr, length, + need_madvise, need_fallocate, ret); + return ret; +} + /* * Unmap pages of memory from start to start+length such that * they a) read as 0, b) Trigger whatever fault mechanism * the OS provides for postcopy. + * * The pages must be unmapped by the end of the function. - * Returns: 0 on success, none-0 on failure - * + * Returns: 0 on success, none-0 on failure. */ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) { - int ret =3D -1; - uint8_t *host_startaddr =3D rb->host + start; =20 if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) { error_report("%s: Unaligned start address: %p", __func__, host_startaddr); - goto err; + return -1; } =20 - if ((start + length) <=3D rb->max_length) { - bool need_madvise, need_fallocate; - if (!QEMU_IS_ALIGNED(length, rb->page_size)) { - error_report("%s: Unaligned length: %zx", __func__, length); - goto err; - } - - errno =3D ENOTSUP; /* If we are missing MADVISE etc */ - - /* The logic here is messy; - * madvise DONTNEED fails for hugepages - * fallocate works on hugepages and shmem - * shared anonymous memory requires madvise REMOVE - */ - need_madvise =3D (rb->page_size =3D=3D qemu_host_page_size); - need_fallocate =3D rb->fd !=3D -1; - if (need_fallocate) { - /* For a file, this causes the area of the file to be zero'd - * if read, and for hugetlbfs also causes it to be unmapped - * so a userfault will trigger. - */ -#ifdef CONFIG_FALLOCATE_PUNCH_HOLE - /* - * We'll discard data from the actual file, even though we only - * have a MAP_PRIVATE mapping, possibly messing with other - * MAP_PRIVATE/MAP_SHARED mappings. There is no easy way to - * change that behavior whithout violating the promised - * semantics of ram_block_discard_range(). - * - * Only warn, because it works as long as nobody else uses that - * file. - */ - if (!qemu_ram_is_shared(rb)) { - warn_report_once("%s: Discarding RAM" - " in private file mappings is possibly" - " dangerous, because it will modify the" - " underlying file and will affect other" - " users of the file", __func__); - } - - ret =3D fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEE= P_SIZE, - start, length); - if (ret) { - ret =3D -errno; - error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx = (%d)", - __func__, rb->idstr, start, length, ret); - goto err; - } -#else - ret =3D -ENOSYS; - error_report("%s: fallocate not available/file" - "%s:%" PRIx64 " +%zx (%d)", - __func__, rb->idstr, start, length, ret); - goto err; -#endif - } - if (need_madvise) { - /* For normal RAM this causes it to be unmapped, - * for shared memory it causes the local mapping to disappear - * and to fall back on the file contents (which we just - * fallocate'd away). - */ -#if defined(CONFIG_MADVISE) - if (qemu_ram_is_shared(rb) && rb->fd < 0) { - ret =3D madvise(host_startaddr, length, QEMU_MADV_REMOVE); - } else { - ret =3D madvise(host_startaddr, length, QEMU_MADV_DONTNEED= ); - } - if (ret) { - ret =3D -errno; - error_report("%s: Failed to discard range " - "%s:%" PRIx64 " +%zx (%d)", - __func__, rb->idstr, start, length, ret); - goto err; - } -#else - ret =3D -ENOSYS; - error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%= d)", - __func__, rb->idstr, start, length, ret); - goto err; -#endif - } - trace_ram_block_discard_range(rb->idstr, host_startaddr, length, - need_madvise, need_fallocate, ret); - } else { + if ((start + length) > rb->max_length) { error_report("%s: Overrun block '%s' (%" PRIu64 "/%zx/" RAM_ADDR_F= MT")", __func__, rb->idstr, start, length, rb->max_length); + return -1; } =20 -err: - return ret; + if (!QEMU_IS_ALIGNED(length, rb->page_size)) { + error_report("%s: Unaligned length: %zx", __func__, length); + return -1; + } + + return ram_block_discard_range_fd(rb, start, length, rb->fd); } =20 bool ramblock_is_pmem(RAMBlock *rb) --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663614; cv=none; d=zohomail.com; s=zohoarc; b=iczb4C3jPpifoQxlivBLLh+5SjqxPtEE6YSB2GTVZ5c/sckjQTiHsudqu63DT+ZeZVI1TedcPgyj65YNQenSQ4F7HxMh5er5eJrmRYSCb9knjt5nlE/l3Es8xZBPNqsr5HMM6mO3gR2DUJJnIxmpN/SozQuqbQSP0gUGIW38Llo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663614; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c8exSkFDX2BToWjQy811NNOuLPEGaQPohE1GicyMPIQ=; b=kqlCGUWxamSzj+0r+mPK93vOgR5IryhavaTGvbaCdbPvCGlmrkP4THFUR5eLWDU+/jspXtBZWYSRkhqErzcerNHPzMBlvHgs669wy+8DfjTGiZP/kRWGt4lI2j5EhMdDvbW4oko+3QF3knIU7+dOabLy8a09cF41ZtXjGne5WpU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169466361434645.74388575480987; Wed, 13 Sep 2023 20:53:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPM-0000Am-KG; Wed, 13 Sep 2023 23:52:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPF-0007xa-4k for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:42 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPB-0000r7-0Y for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:40 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:36 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663557; x=1726199557; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C1mGXkusPnhkfU37hQJOr1iYXe1QHqcmTFhsRyRYjTI=; b=O4JaCnfQ/rbii/1nNX/wgeAdxvQth2uFXblgaChUbOjj5MDMpjUJgpMO qXC8rFA0VM0RCKOU2o5wdm+UXUIQWAV60F0akdaBSqjaewnvvYdh4KOYY GYzMQYL0WqU5/ohyHJj2OzGBFxRPdQyTbQkesqVLfLBfSZypAjbg7d4aQ RcdpInjZeOPWzZUe8I7pY76LjCqzPpuhwbkHKbNApkPfJdVvoUCi4ANEH T0SH1QgqqJHYvTUkDqEpCo9KgLx+8xRUQuKLzmdy5KHRuFGPwEkehUQjO EtwuJI8uIfPQlWotOyLmAP6iOAKI5AHGAv/GrvAp88GX57co8sIBHDujB A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528513" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528513" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500677" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500677" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 16/21] physmem: Introduce ram_block_convert_range() Date: Wed, 13 Sep 2023 23:51:12 -0400 Message-Id: <20230914035117.3285885-17-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663615239100005 Content-Type: text/plain; charset="utf-8" It's used for discarding oppsite memory after memory conversion to shared/private. Note, private-shared page conversion is done at 4KB granularity. Don't check alignment with rb->page_size, instead qemu_host_page_size, which is 4K. Originally-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- include/exec/cpu-common.h | 2 ++ softmmu/physmem.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 87dc9a752c9a..558684b9f246 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -157,6 +157,8 @@ typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaq= ue); =20 int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque); int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length); +int ram_block_convert_range(RAMBlock *rb, uint64_t start, size_t length, + bool shared_to_private); =20 #endif =20 diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 6ee6bc794f44..dab3247d461c 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3733,3 +3733,39 @@ bool ram_block_discard_is_required(void) return qatomic_read(&ram_block_discard_required_cnt) || qatomic_read(&ram_block_coordinated_discard_required_cnt); } + +int ram_block_convert_range(RAMBlock *rb, uint64_t start, size_t length, + bool shared_to_private) +{ + int fd; + + if (!rb || rb->gmem_fd < 0) { + return -1; + } + + if (!QEMU_PTR_IS_ALIGNED(start, qemu_host_page_size) || + !QEMU_PTR_IS_ALIGNED(length, qemu_host_page_size)) { + return -1; + } + + if (!length) { + return -1; + } + + if (start + length > rb->max_length) { + return -1; + } + + if (shared_to_private) { + void *host_startaddr =3D rb->host + start; + + if (!QEMU_PTR_IS_ALIGNED(host_startaddr, qemu_host_page_size)) { + return -1; + } + fd =3D rb->fd; + } else { + fd =3D rb->gmem_fd; + } + + return ram_block_discard_range_fd(rb, start, length, fd); +} --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663625; cv=none; d=zohomail.com; s=zohoarc; b=c5vtzQ7L668HgT/2DHcohdlnY4s67KZ56sDeLC1lb/pI+ehV+HX06xqUvEqj4yLm0pMyYpN2QqDMxRJODm1V9aSluUgM29D4bvLtrDAT+wjCz8yzl7irvbNmu6sagA7acMZzalN5y2dplzLonnpKmM9FVXjFpVhvii1Y06r3oqI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663625; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8rjJCJ1HOgo3zNgJ7ivnpU8Y+TSQskZjYmS+6wcoeTU=; b=WGfrrUoVnGMYbr4doD+fbfj1VQf2n9H63TXa3zDIKMQNCG1LdQ7hH3By8dgbWE7KGBpFQcifNGTQYXJm9xa7I/+RT+P+xGibaFJbNSDU2L8sMVzU+iY+Zk7xVRcfwcxyfAp+j6oGtbiG7zlDD4Qxt6bwE0GmQNMUyx14YCbOOPA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663625585923.5188540783967; Wed, 13 Sep 2023 20:53:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPK-0008Qt-QR; Wed, 13 Sep 2023 23:52:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPI-00086k-QO for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:44 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPH-0000r7-4V for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:44 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:40 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663563; x=1726199563; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HN90WpAcWxivDLGkYoPpDo7sWsy3b6+tOvB3ht8MLBY=; b=BTev+agIVvOVzSfM3f690ydEBugotf0WpJZ9+VrDT5fFxmjO9AE+3tPo TNfL0jQD+kVCXVoJLvPmHE9HNyX02PT6WeilqQ8J/nQyp6jFwHJ8O5vM9 PNM5RsbAp5I/DhoWpGn5k2D5Ak69w2ilOxjiaOz3S5RhaNDqiT5+ukzfx tHZ7+FzaMkahxZK6G3/KlhikbWvVRHIkdBKgKCzPmKWCvhKt+ZqeBnvf1 XB4ac0VEhqHNt3N5slcJJWImknXBBojRP+FSjuuKIIZKgHnS2YKpJAP7J /3H47nMHiNlAvmFoh5DFwPu/GVGf2PbwTvlCyX58Nx5BvtX2To3AzPwHU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528538" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528538" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500685" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500685" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 17/21] kvm: handle KVM_EXIT_MEMORY_FAULT Date: Wed, 13 Sep 2023 23:51:13 -0400 Message-Id: <20230914035117.3285885-18-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663627374100011 Content-Type: text/plain; charset="utf-8" From: Chao Peng Currently only KVM_MEMORY_EXIT_FLAG_PRIVATE in flags is valid when KVM_EXIT_MEMORY_FAULT happens. It indicates userspace needs to do the memory conversion on the RAMBlock to turn the memory into desired attribute, i.e., private/shared. Note, KVM_EXIT_MEMORY_FAULT makes sense only when the RAMBlock has gmem memory backend. Signed-off-by: Chao Peng Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 7e32ee83b258..c67aa66b0559 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3040,6 +3040,50 @@ static void kvm_eat_signals(CPUState *cpu) } while (sigismember(&chkset, SIG_IPI)); } =20 +static int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private) +{ + MemoryRegionSection section; + ram_addr_t offset; + RAMBlock *rb; + void *addr; + int ret =3D -1; + + section =3D memory_region_find(get_system_memory(), start, size); + if (!section.mr) { + return ret; + } + + if (memory_region_has_gmem_fd(section.mr)) { + if (to_private) { + ret =3D kvm_set_memory_attributes_private(start, size); + } else { + ret =3D kvm_set_memory_attributes_shared(start, size); + } + + if (ret) { + memory_region_unref(section.mr); + return ret; + } + + addr =3D memory_region_get_ram_ptr(section.mr) + + section.offset_within_region; + rb =3D qemu_ram_block_from_host(addr, false, &offset); + /* + * With KVM_SET_MEMORY_ATTRIBUTES by kvm_set_memory_attributes(), + * operation on underlying file descriptor is only for releasing + * unnecessary pages. + */ + ram_block_convert_range(rb, offset, size, to_private); + } else { + warn_report("Convert non guest-memfd backed memory region " + "(0x%"HWADDR_PRIx" ,+ 0x%"HWADDR_PRIx") to %s", + start, size, to_private ? "private" : "shared"); + } + + memory_region_unref(section.mr); + return ret; +} + int kvm_cpu_exec(CPUState *cpu) { struct kvm_run *run =3D cpu->kvm_run; @@ -3198,6 +3242,16 @@ int kvm_cpu_exec(CPUState *cpu) break; } break; + case KVM_EXIT_MEMORY_FAULT: + if (run->memory.flags & ~KVM_MEMORY_EXIT_FLAG_PRIVATE) { + error_report("KVM_EXIT_MEMORY_FAULT: Unknown flag 0x%" PRI= x64, + (uint64_t)run->memory.flags); + ret =3D -1; + break; + } + ret =3D kvm_convert_memory(run->memory.gpa, run->memory.size, + run->memory.flags & KVM_MEMORY_EXIT_F= LAG_PRIVATE); + break; default: DPRINTF("kvm_arch_handle_exit\n"); ret =3D kvm_arch_handle_exit(cpu, run); --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663625; cv=none; d=zohomail.com; s=zohoarc; b=jmpNqPrcuMpD3Utm1gievI1AtjEjjdK9MwFVzHjma9ZGU9xlGEhkgIKU/mnba9UvfBDavGU4yprygt/WuZ3QCWV4Sg7vAElzF7Ym7mRjA/XbpL35sbixqNSvpxEH7AS3LuBfSwDeBAs4pSBJe+ODt94/lqGk3mVxNT/nj3owt1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663625; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=idgKDAmtp2CVcuszUbBwJXa7WWZbfRHvVePgQ6vR1M8=; b=Su57Cc6fHJKZOFK8MKyjSPb+Ifkt2Jxk+Za0Wm8emn+vhF2BOFeM405Ab1J6oex8Cb5zIgyIosqWFWXwcn2VQpyoy2WZ7Nuf4xToPMDBWirr1tsB0llVb82PCrPlfOHvnVXMpd/7suCZLMwKpxgUbAOJrwFcfIB/RUiuuujFpPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663625381197.54861432067014; Wed, 13 Sep 2023 20:53:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPc-0000uj-LA; Wed, 13 Sep 2023 23:53:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPY-0000ch-9u for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:00 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPU-0000r7-0n for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:52:59 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:45 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663576; x=1726199576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zrz3HhFIEcTQ9vz8USdPZet2h8wV0BzTOylzEBsMwj4=; b=GlehkUBTtk/03bg5HL8KNEhX/Sjx/tx+YFoNL4C0RVXFhv+KRGNB/xDr XZ4N+ZRJJ/w3ub5sy+AKtyiIDD49vI1b1MrdgfXRVf2PcpGRD/JSsPeus lmyox9W5OFDE0MOhz8pB7hXAroKzkMi3O8UVh67Tv+ZPumo7OJwo69Yzr D0eX/GVciaD7p4JRsFtyASAQerQiCxOnbczGsXe+t48ayAcWKrCF/q1kY pVBKV4EVN+vBvZoE2usl1VulW5B4gWPPB1riJ0XxqBxz3n1+NkgoaW94V XTRbH7cp0q8bNYMV+Iyz26282w63lZNW3OJripBRy2p/re6lzMWRjHUOv w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528555" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528555" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500688" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500688" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 18/21] trace/kvm: Add trace for page convertion between shared and private Date: Wed, 13 Sep 2023 23:51:14 -0400 Message-Id: <20230914035117.3285885-19-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663626052100003 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 1 + accel/kvm/trace-events | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c67aa66b0559..229b7038a4c2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3048,6 +3048,7 @@ static int kvm_convert_memory(hwaddr start, hwaddr si= ze, bool to_private) void *addr; int ret =3D -1; =20 + trace_kvm_convert_memory(start, size, to_private ? "shared_to_private"= : "private_to_shared"); section =3D memory_region_find(get_system_memory(), start, size); if (!section.mr) { return ret; diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index 80694683acea..4935c9c5cf0b 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -25,4 +25,4 @@ kvm_dirty_ring_reaper(const char *s) "%s" kvm_dirty_ring_reap(uint64_t count, int64_t t) "reaped %"PRIu64" pages (to= ok %"PRIi64" us)" kvm_dirty_ring_reaper_kick(const char *reason) "%s" kvm_dirty_ring_flush(int finished) "%d" - +kvm_convert_memory(uint64_t start, uint64_t size, const char *msg) "start = 0x%" PRIx64 " size 0x%" PRIx64 " %s" --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663613; cv=none; d=zohomail.com; s=zohoarc; b=gBkn9Kc4+dL2YZUS/dRuVU+hiOi0mZOxssXh4WLjJW8ZvWoKxQo+cTa/dWeKPXc0wyQoGXgW0ag6UYYEGzGVxEAoRiS7rB8oT9BMSEFMaTJitxLrN2nlHi2wMFf6RJ4OOzwIiK1kiEoaNo2eb9W6FHhML9jHuqa/UW+yfK56PXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663613; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HvRZLOga2yf+mmxo/NSalq8ZltFf6QIhtl0ye+JO3dU=; b=kLXyyeD3qp42MUh36rWtqDeUZFjc0V2Ymkz0id0AGb8ByHKs5NV8Uc02ejUgjMRw5Fa0nKimg2YkTKJzBVyVHwtRH7DQQE2EBPHUbZKscvydfLOS7cOj/FGeBCBVfkL8Awwm4yrMbTrSLKfyUq+Y9ZGTamN5e5546HtYJ6oV6Jg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663613519212.8674756876511; Wed, 13 Sep 2023 20:53:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPi-0001Bh-Rs; Wed, 13 Sep 2023 23:53:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPa-0000ud-Uf for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:04 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPZ-00018k-93 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:02 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:49 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663581; x=1726199581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aoypxCuYdLER3/LcqIyTOOIsOC8SNNr7NYzaoP86WMg=; b=dzMaur271b6f6FaqfMinvhcwkpkx8Kjj9yVzwGIdyZf+RJquu8RML62s iu3YKNXgqcwzfuFFjJYW6upg79Z8nv4+QvcJ0f4Qw3r56VSpw3YqZRLkt Bte+9aey7wbJBQaVWECRMcZMkqKnJa6dUqDtpICi6uwNsPEclnfG3BQe0 G++HlcEQ0pVN6kZfPOYa9ApkHPRaaHm5OeKWEBqhRZJJAKWQP3l0o45UD N9gleOKYEHNxq+c68+fcMqEL1VuzcJ4fUN7wrCpczsSrIoONqU0zwJPA2 VT2lt0WYy3o6ZFxju32qiqe02PWZn3W8MtXfXfhFwt2fDvUGqE/2kyFr+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528571" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528571" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500716" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500716" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 19/21] pci-host/q35: Move PAM initialization above SMRAM initialization Date: Wed, 13 Sep 2023 23:51:15 -0400 Message-Id: <20230914035117.3285885-20-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663613793100001 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata In mch_realize(), process PAM initialization before SMRAM initialization so that later patch can skill all the SMRAM related with a single check. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- hw/pci-host/q35.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 91c46df9ae31..ac1518a94ee4 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -575,6 +575,16 @@ static void mch_realize(PCIDevice *d, Error **errp) /* setup pci memory mapping */ pc_pci_as_mapping_init(mch->system_memory, mch->pci_address_space); =20 + /* PAM */ + init_pam(&mch->pam_regions[0], OBJECT(mch), mch->ram_memory, + mch->system_memory, mch->pci_address_space, + PAM_BIOS_BASE, PAM_BIOS_SIZE); + for (i =3D 0; i < ARRAY_SIZE(mch->pam_regions) - 1; ++i) { + init_pam(&mch->pam_regions[i + 1], OBJECT(mch), mch->ram_memory, + mch->system_memory, mch->pci_address_space, + PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); + } + /* if *disabled* show SMRAM to all CPUs */ memory_region_init_alias(&mch->smram_region, OBJECT(mch), "smram-regio= n", mch->pci_address_space, MCH_HOST_BRIDGE_SMRAM= _C_BASE, @@ -641,15 +651,6 @@ static void mch_realize(PCIDevice *d, Error **errp) =20 object_property_add_const_link(qdev_get_machine(), "smram", OBJECT(&mch->smram)); - - init_pam(&mch->pam_regions[0], OBJECT(mch), mch->ram_memory, - mch->system_memory, mch->pci_address_space, - PAM_BIOS_BASE, PAM_BIOS_SIZE); - for (i =3D 0; i < ARRAY_SIZE(mch->pam_regions) - 1; ++i) { - init_pam(&mch->pam_regions[i + 1], OBJECT(mch), mch->ram_memory, - mch->system_memory, mch->pci_address_space, - PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); - } } =20 uint64_t mch_mcfg_base(void) --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663597; cv=none; d=zohomail.com; s=zohoarc; b=Ea61seY2lj1d4uIUT9SnaT/FFM4Ka+4zYaDVxk099tlwAN3wQQJjkSZLLScY7nGVvsyfSvl/ein1a08xWSQ/KBae1LpOfRYknOR3jy4U1rry+2ohZa3DxwQaPL35Ng8A69sUT94ahfj1wamz2AUPJU0Hqc8uVZ3hmcuBW7dix7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663597; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LW+5SylbxpaqYk6pkpeIZB2itxyzXHrfSFMo6bHQuq8=; b=RgIP8CyJW/dOmfiLtqXNQPN4ehggBXTZGY+CMGsrJxvCOiaGWSqD3YX5XBwEAuV05h9nXUGvn07h61wG+7X4O2i9/6/42BaMhA00bxdlQABCKRtvzqEFvRXncoOFbXod7GaBV+vBnkH33fhWQqra1yWNwvnGZw9saz6cf9UB3f0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663597327140.2871453928566; Wed, 13 Sep 2023 20:53:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPk-0001M6-1z; Wed, 13 Sep 2023 23:53:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPi-00018u-Gp for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:10 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPd-0001Bv-N6 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:07 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:54 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663585; x=1726199585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QoBc+IVWDb42m9hfWIVmJcD1aYMSQ1vw/jwLkspqX3E=; b=k/ke7fYGGzxc6g/XNJw7IINExv6OC2Bnp3pN/ArHjqzVGG+GwSW4RHP4 +gLG4oaVMI0bvhTyefqRetH+K4m/rWBUMgN5vJpHp8puTHuhiG8Fa/9EI eAOA5QrprgsY60GndDtzkUYrUq0Nafv7lnoVgUYhTakGqRAkH6UYri0Yj uzC7LzWp127kLn/f/6t8yNtZZm5Q8/i3PyCvcUwkk9EBgaDS+eATBzw0U +tvd3VgBnFKR+ij6QjM4qKaB6rKeg35OHNezMMTUO/eoHL187gLL9o2J1 10yjUEQd/DPqivSa7JpGy8wlcYtuCX3YjiFQFFP+J9p1IcOiXTwnF4Ngd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528586" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528586" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500726" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500726" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 20/21] q35: Introduce smm_ranges property for q35-pci-host Date: Wed, 13 Sep 2023 23:51:16 -0400 Message-Id: <20230914035117.3285885-21-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663599040100003 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata Add a q35 property to check whether or not SMM ranges, e.g. SMRAM, TSEG, etc... exist for the target platform. TDX doesn't support SMM and doesn't play nice with QEMU modifying related guest memory ranges. Signed-off-by: Isaku Yamahata Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li --- hw/i386/pc_q35.c | 3 ++- hw/pci-host/q35.c | 42 +++++++++++++++++++++++++++------------ include/hw/i386/pc.h | 1 + include/hw/pci-host/q35.h | 1 + 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index dc27a9e223a2..73eb3bc5e826 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -232,8 +232,9 @@ static void pc_q35_init(MachineState *machine) x86ms->above_4g_mem_size, NULL); object_property_set_bool(phb, PCI_HOST_BYPASS_IOMMU, pcms->default_bus_bypass_iommu, NULL); + object_property_set_bool(phb, PCI_HOST_PROP_SMM_RANGES, + x86_machine_is_smm_enabled(x86ms), NULL); sysbus_realize_and_unref(SYS_BUS_DEVICE(phb), &error_fatal); - /* pci */ host_bus =3D PCI_BUS(qdev_get_child_bus(DEVICE(phb), "pcie.0")); pcms->bus =3D host_bus; diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index ac1518a94ee4..f5c01f7080f9 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -186,6 +186,8 @@ static Property q35_host_props[] =3D { mch.below_4g_mem_size, 0), DEFINE_PROP_SIZE(PCI_HOST_ABOVE_4G_MEM_SIZE, Q35PCIHost, mch.above_4g_mem_size, 0), + DEFINE_PROP_BOOL(PCI_HOST_PROP_SMM_RANGES, Q35PCIHost, + mch.has_smm_ranges, true), DEFINE_PROP_BOOL("x-pci-hole64-fix", Q35PCIHost, pci_hole64_fix, true), DEFINE_PROP_END_OF_LIST(), }; @@ -221,6 +223,7 @@ static void q35_host_initfn(Object *obj) /* mch's object_initialize resets the default value, set it again */ qdev_prop_set_uint64(DEVICE(s), PCI_HOST_PROP_PCI_HOLE64_SIZE, Q35_PCI_HOST_HOLE64_SIZE_DEFAULT); + object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32", q35_host_get_pci_hole_start, NULL, NULL, NULL); @@ -483,6 +486,10 @@ static void mch_write_config(PCIDevice *d, mch_update_pciexbar(mch); } =20 + if (!mch->has_smm_ranges) { + return; + } + if (ranges_overlap(address, len, MCH_HOST_BRIDGE_SMRAM, MCH_HOST_BRIDGE_SMRAM_SIZE)) { mch_update_smram(mch); @@ -501,10 +508,13 @@ static void mch_write_config(PCIDevice *d, static void mch_update(MCHPCIState *mch) { mch_update_pciexbar(mch); + mch_update_pam(mch); - mch_update_smram(mch); - mch_update_ext_tseg_mbytes(mch); - mch_update_smbase_smram(mch); + if (mch->has_smm_ranges) { + mch_update_smram(mch); + mch_update_ext_tseg_mbytes(mch); + mch_update_smbase_smram(mch); + } =20 /* * pci hole goes from end-of-low-ram to io-apic. @@ -545,19 +555,21 @@ static void mch_reset(DeviceState *qdev) pci_set_quad(d->config + MCH_HOST_BRIDGE_PCIEXBAR, MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT); =20 - d->config[MCH_HOST_BRIDGE_SMRAM] =3D MCH_HOST_BRIDGE_SMRAM_DEFAULT; - d->config[MCH_HOST_BRIDGE_ESMRAMC] =3D MCH_HOST_BRIDGE_ESMRAMC_DEFAULT; - d->wmask[MCH_HOST_BRIDGE_SMRAM] =3D MCH_HOST_BRIDGE_SMRAM_WMASK; - d->wmask[MCH_HOST_BRIDGE_ESMRAMC] =3D MCH_HOST_BRIDGE_ESMRAMC_WMASK; + if (mch->has_smm_ranges) { + d->config[MCH_HOST_BRIDGE_SMRAM] =3D MCH_HOST_BRIDGE_SMRAM_DEFAULT; + d->config[MCH_HOST_BRIDGE_ESMRAMC] =3D MCH_HOST_BRIDGE_ESMRAMC_DEF= AULT; + d->wmask[MCH_HOST_BRIDGE_SMRAM] =3D MCH_HOST_BRIDGE_SMRAM_WMASK; + d->wmask[MCH_HOST_BRIDGE_ESMRAMC] =3D MCH_HOST_BRIDGE_ESMRAMC_WMAS= K; =20 - if (mch->ext_tseg_mbytes > 0) { - pci_set_word(d->config + MCH_HOST_BRIDGE_EXT_TSEG_MBYTES, - MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_QUERY); + if (mch->ext_tseg_mbytes > 0) { + pci_set_word(d->config + MCH_HOST_BRIDGE_EXT_TSEG_MBYTES, + MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_QUERY); + } + + d->config[MCH_HOST_BRIDGE_F_SMBASE] =3D 0; + d->wmask[MCH_HOST_BRIDGE_F_SMBASE] =3D 0xff; } =20 - d->config[MCH_HOST_BRIDGE_F_SMBASE] =3D 0; - d->wmask[MCH_HOST_BRIDGE_F_SMBASE] =3D 0xff; - mch_update(mch); } =20 @@ -585,6 +597,10 @@ static void mch_realize(PCIDevice *d, Error **errp) PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); } =20 + if (!mch->has_smm_ranges) { + return; + } + /* if *disabled* show SMRAM to all CPUs */ memory_region_init_alias(&mch->smram_region, OBJECT(mch), "smram-regio= n", mch->pci_address_space, MCH_HOST_BRIDGE_SMRAM= _C_BASE, diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index c98d628a76f3..3c9ced22cea9 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -156,6 +156,7 @@ void pc_guest_info_init(PCMachineState *pcms); #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size" #define PCI_HOST_BELOW_4G_MEM_SIZE "below-4g-mem-size" #define PCI_HOST_ABOVE_4G_MEM_SIZE "above-4g-mem-size" +#define PCI_HOST_PROP_SMM_RANGES "smm-ranges" =20 =20 void pc_pci_as_mapping_init(MemoryRegion *system_memory, diff --git a/include/hw/pci-host/q35.h b/include/hw/pci-host/q35.h index 1d98bbfe0dd2..930af3870e8a 100644 --- a/include/hw/pci-host/q35.h +++ b/include/hw/pci-host/q35.h @@ -50,6 +50,7 @@ struct MCHPCIState { MemoryRegion tseg_blackhole, tseg_window; MemoryRegion smbase_blackhole, smbase_window; bool has_smram_at_smbase; + bool has_smm_ranges; Range pci_hole; uint64_t below_4g_mem_size; uint64_t above_4g_mem_size; --=20 2.34.1 From nobody Fri May 17 05:54:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694663636; cv=none; d=zohomail.com; s=zohoarc; b=E+oKgz+W0aNVep5d76esALn8SjR6nkclLZj5AFQEeTkjX7uaVdD7Q4wh9Z0UnIE1sdXeEVLn1pxkS3tVr0w6XXsHaGQp7L8egnlXIvv+QcG2v4VnOKgzwqjmd+Q9Z61gMIam1QENptF6WHcRsafxflF94BAFifqu8vuLePoPcwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694663636; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OsBRcF6yjaKNw4bQomNKVC7xKUSmSctH5ctGQoulESE=; b=EfL47YsBmOSmuDDqrNl1ipsVjLOV9ckrLo5ksLvPeSkfDZ9So7+vltRviS9OoOHb35JfD8CkyaMq9qa4ym8ewIhhjUSZ7BqQ4sdJ/dMhE371VVAYhE/Jo5pKGRHkcuM0nCQ6Z41CGvD9PRoQujSY30qW+CBE7dsMK6mqHlrkliI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694663636486493.0843547162481; Wed, 13 Sep 2023 20:53:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgdPm-0001kv-NY; Wed, 13 Sep 2023 23:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPl-0001YM-2D for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:13 -0400 Received: from mgamail.intel.com ([134.134.136.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgdPi-0000r7-Lo for qemu-devel@nongnu.org; Wed, 13 Sep 2023 23:53:12 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 20:52:58 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmsmga004.fm.intel.com with ESMTP; 13 Sep 2023 20:52:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694663590; x=1726199590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h2VTCw5i0cKuV38BdOMgzq2DUKXjm2pDKAxaCdcmMTA=; b=g1R2EO5V9iUP2br22YMAbqYL8wgukS57TUib01liyJpEGvTT1kn0RztG 5LffrE4Tge9BnbOdEj8GjXBHWahTW66snEHWSP7SIHWsaomhMX9/qQlME qBArX4JUcSzk9ZNjLLc5QRd97l6aIBwY6g96HNzoG5gpAfX8Hg24prGe3 PEHSOT0M67xCrojTBqoWTF5Ou+NIuGsiVKMFm/44jD6O+K4Fey7UAsyk0 kk+3Q8+Uimq8XER45y46GaluC1QVkqU9lbdryBLKlD9za3l0f6+CkAKCB 0pOH1kz+tme7b8ButvoN8eFFftCMB+f9jLXdNztnaO1ehcAuTMKnTpH4t A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="381528608" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="381528608" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="814500731" X-IronPort-AV: E=Sophos;i="6.02,144,1688454000"; d="scan'208";a="814500731" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , isaku.yamahata@gmail.com, Sean Christopherson , Claudio Fontana Subject: [RFC PATCH v2 21/21] i386: Disable SMM mode for X86_SW_PROTECTED_VM Date: Wed, 13 Sep 2023 23:51:17 -0400 Message-Id: <20230914035117.3285885-22-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914035117.3285885-1-xiaoyao.li@intel.com> References: <20230914035117.3285885-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.24; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1694663638529100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaoyao Li --- target/i386/kvm/sw-protected-vm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/i386/kvm/sw-protected-vm.c b/target/i386/kvm/sw-protect= ed-vm.c index f47ac383e1dd..65347067aa03 100644 --- a/target/i386/kvm/sw-protected-vm.c +++ b/target/i386/kvm/sw-protected-vm.c @@ -34,10 +34,18 @@ static MemoryListener kvm_x86_sw_protected_vm_memory_li= stener =3D { int sw_protected_vm_kvm_init(MachineState *ms, Error **errp) { SwProtectedVm *spvm =3D SW_PROTECTED_VM(OBJECT(ms->cgs)); + X86MachineState *x86ms =3D X86_MACHINE(ms); =20 memory_listener_register(&kvm_x86_sw_protected_vm_memory_listener, &address_space_memory); =20 + if (x86ms->smm =3D=3D ON_OFF_AUTO_AUTO) { + x86ms->smm =3D ON_OFF_AUTO_OFF; + } else if (x86ms->smm =3D=3D ON_OFF_AUTO_ON) { + error_setg(errp, "X86_SW_PROTECTED_VM doesn't support SMM"); + return -EINVAL; + } + spvm->parent_obj.ready =3D true; return 0; } --=20 2.34.1