From: Ryan Afranji <afranji@google.com>
To: afranji@google.com, ackerleytng@google.com, pbonzini@redhat.com,
seanjc@google.com, tglx@linutronix.de, x86@kernel.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, tabba@google.com
Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
hpa@zytor.com, shuah@kernel.org, andrew.jones@linux.dev,
ricarkol@google.com, chao.p.peng@linux.intel.com,
jarkko@kernel.org, yu.c.zhang@linux.intel.com,
vannapurve@google.com, erdemaktas@google.com,
mail@maciej.szmigiero.name, vbabka@suse.cz, david@redhat.com,
qperret@google.com, michael.roth@amd.com, wei.w.wang@intel.com,
liam.merwick@oracle.com, isaku.yamahata@gmail.com,
kirill.shutemov@linux.intel.com, sagis@google.com,
jthoughton@google.com
Subject: [RFC PATCH v2 07/13] KVM: x86: Refactor sev's flag migration_in_progress to kvm struct
Date: Fri, 16 May 2025 19:19:27 +0000 [thread overview]
Message-ID: <6ef77cc986aa89c1799cf3709de30edd6e4e70ee.1747368093.git.afranji@google.com> (raw)
In-Reply-To: <cover.1747368092.git.afranji@google.com>
From: Ackerley Tng <ackerleytng@google.com>
The migration_in_progress flag will also be needed for migration of
non-sev VMs.
Co-developed-by: Sagi Shahar <sagis@google.com>
Signed-off-by: Sagi Shahar <sagis@google.com>
Co-developed-by: Vishal Annapurve <vannapurve@google.com>
Signed-off-by: Vishal Annapurve <vannapurve@google.com>
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
Signed-off-by: Ryan Afranji <afranji@google.com>
---
arch/x86/kvm/svm/sev.c | 17 ++++++-----------
arch/x86/kvm/svm/svm.h | 1 -
include/linux/kvm_host.h | 1 +
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 0bc708ee2788..89c06cfcc200 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -1838,8 +1838,6 @@ static bool is_cmd_allowed_from_mirror(u32 cmd_id)
static int sev_lock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
{
- struct kvm_sev_info *dst_sev = to_kvm_sev_info(dst_kvm);
- struct kvm_sev_info *src_sev = to_kvm_sev_info(src_kvm);
int r = -EBUSY;
if (dst_kvm == src_kvm)
@@ -1849,10 +1847,10 @@ static int sev_lock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
* Bail if these VMs are already involved in a migration to avoid
* deadlock between two VMs trying to migrate to/from each other.
*/
- if (atomic_cmpxchg_acquire(&dst_sev->migration_in_progress, 0, 1))
+ if (atomic_cmpxchg_acquire(&dst_kvm->migration_in_progress, 0, 1))
return -EBUSY;
- if (atomic_cmpxchg_acquire(&src_sev->migration_in_progress, 0, 1))
+ if (atomic_cmpxchg_acquire(&src_kvm->migration_in_progress, 0, 1))
goto release_dst;
r = -EINTR;
@@ -1865,21 +1863,18 @@ static int sev_lock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
unlock_dst:
mutex_unlock(&dst_kvm->lock);
release_src:
- atomic_set_release(&src_sev->migration_in_progress, 0);
+ atomic_set_release(&src_kvm->migration_in_progress, 0);
release_dst:
- atomic_set_release(&dst_sev->migration_in_progress, 0);
+ atomic_set_release(&dst_kvm->migration_in_progress, 0);
return r;
}
static void sev_unlock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
{
- struct kvm_sev_info *dst_sev = to_kvm_sev_info(dst_kvm);
- struct kvm_sev_info *src_sev = to_kvm_sev_info(src_kvm);
-
mutex_unlock(&dst_kvm->lock);
mutex_unlock(&src_kvm->lock);
- atomic_set_release(&dst_sev->migration_in_progress, 0);
- atomic_set_release(&src_sev->migration_in_progress, 0);
+ atomic_set_release(&dst_kvm->migration_in_progress, 0);
+ atomic_set_release(&src_kvm->migration_in_progress, 0);
}
/* vCPU mutex subclasses. */
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index d4490eaed55d..35df8be621c5 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -107,7 +107,6 @@ struct kvm_sev_info {
struct list_head mirror_vms; /* List of VMs mirroring */
struct list_head mirror_entry; /* Use as a list entry of mirrors */
struct misc_cg *misc_cg; /* For misc cgroup accounting */
- atomic_t migration_in_progress;
void *snp_context; /* SNP guest context page */
void *guest_req_buf; /* Bounce buffer for SNP Guest Request input */
void *guest_resp_buf; /* Bounce buffer for SNP Guest Request output */
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 1dedc421b3e3..0c1d637a6e7d 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -862,6 +862,7 @@ struct kvm {
/* Protected by slots_locks (for writes) and RCU (for reads) */
struct xarray mem_attr_array;
#endif
+ atomic_t migration_in_progress;
char stats_id[KVM_STATS_NAME_SIZE];
};
--
2.49.0.1101.gccaa498523-goog
next prev parent reply other threads:[~2025-05-16 19:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 19:19 [RFC PATCH v2 00/13] New KVM ioctl to link a gmem inode to a new gmem file Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 01/13] fs: Refactor to provide function that allocates a secure anonymous inode Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 02/13] KVM: guest_memfd: Make guest mem use guest mem inodes instead of anonymous inodes Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 03/13] KVM: guest_mem: Refactor out kvm_gmem_alloc_view() Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 04/13] KVM: guest_mem: Add ioctl KVM_LINK_GUEST_MEMFD Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 05/13] KVM: selftests: Add tests for KVM_LINK_GUEST_MEMFD ioctl Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 06/13] KVM: selftests: Test transferring private memory to another VM Ryan Afranji
2025-05-16 19:19 ` Ryan Afranji [this message]
2025-05-16 19:19 ` [RFC PATCH v2 08/13] KVM: x86: Refactor common code out of sev.c Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 09/13] KVM: x86: Refactor common migration preparation code out of sev_vm_move_enc_context_from Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 10/13] KVM: x86: Let moving encryption context be configurable Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 11/13] KVM: x86: Handle moving of memory context for intra-host migration Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 12/13] KVM: selftests: Generalize migration functions from sev_migrate_tests.c Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 13/13] KVM: selftests: Add tests for migration of private mem Ryan Afranji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6ef77cc986aa89c1799cf3709de30edd6e4e70ee.1747368093.git.afranji@google.com \
--to=afranji@google.com \
--cc=ackerleytng@google.com \
--cc=andrew.jones@linux.dev \
--cc=bp@alien8.de \
--cc=chao.p.peng@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=erdemaktas@google.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@gmail.com \
--cc=jarkko@kernel.org \
--cc=jthoughton@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mail@maciej.szmigiero.name \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qperret@google.com \
--cc=ricarkol@google.com \
--cc=sagis@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=tabba@google.com \
--cc=tglx@linutronix.de \
--cc=vannapurve@google.com \
--cc=vbabka@suse.cz \
--cc=wei.w.wang@intel.com \
--cc=x86@kernel.org \
--cc=yu.c.zhang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®