File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1010//
1111//
1212
13+ #[ cfg( feature = "kvm" ) ]
14+ use std:: os:: fd:: RawFd ;
1315#[ cfg( target_arch = "aarch64" ) ]
1416use std:: sync:: Arc ;
1517
@@ -602,4 +604,11 @@ pub trait Vcpu: Send + Sync {
602604 /// Trigger NMI interrupt
603605 ///
604606 fn nmi ( & self ) -> Result < ( ) > ;
607+ /// Returns the underlying vCPU FD of KVM.
608+ ///
609+ /// # SAFETY
610+ /// This is safe if we do only use this to map the KVM_RUN structure for the
611+ /// signal handler and only use it from there.
612+ #[ cfg( feature = "kvm" ) ]
613+ unsafe fn get_kvm_vcpu_raw_fd ( & self ) -> RawFd ;
605614}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ use std::collections::HashMap;
1616use std:: fs:: File ;
1717#[ cfg( target_arch = "x86_64" ) ]
1818use std:: os:: unix:: io:: AsRawFd ;
19- #[ cfg( feature = "tdx" ) ]
19+ #[ cfg( any ( feature = "tdx" , feature = "kvm" ) ) ]
2020use std:: os:: unix:: io:: RawFd ;
2121use std:: result;
2222#[ cfg( target_arch = "x86_64" ) ]
@@ -2769,6 +2769,13 @@ impl cpu::Vcpu for KvmVcpu {
27692769 self . fd . lock ( ) . unwrap ( ) . set_kvm_immediate_exit ( exit. into ( ) ) ;
27702770 }
27712771
2772+ #[ cfg( feature = "kvm" ) ]
2773+ unsafe fn get_kvm_vcpu_raw_fd ( & self ) -> RawFd {
2774+ let kvm_vcpu = self . fd . lock ( ) . unwrap ( ) ;
2775+ let kvm_vcpu = & * kvm_vcpu;
2776+ kvm_vcpu. as_raw_fd ( )
2777+ }
2778+
27722779 ///
27732780 /// Returns the details about TDX exit reason
27742781 ///
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ pub mod x86_64;
4343pub mod aarch64;
4444#[ cfg( target_arch = "x86_64" ) ]
4545use std:: fs:: File ;
46+ use std:: os:: fd:: RawFd ;
4647use std:: os:: unix:: io:: AsRawFd ;
4748#[ cfg( target_arch = "aarch64" ) ]
4849use std:: sync:: Mutex ;
@@ -1576,6 +1577,11 @@ impl cpu::Vcpu for MshvVcpu {
15761577
15771578 Ok ( ( ) )
15781579 }
1580+
1581+ #[ cfg( feature = "kvm" ) ]
1582+ unsafe fn get_kvm_vcpu_raw_fd ( & self ) -> RawFd {
1583+ todo ! ( )
1584+ }
15791585}
15801586
15811587impl MshvVcpu {
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ use std::collections::BTreeMap;
1616use std:: io:: Write ;
1717#[ cfg( all( target_arch = "x86_64" , feature = "guest_debug" ) ) ]
1818use std:: mem:: size_of;
19+ #[ cfg( feature = "kvm" ) ]
20+ use std:: os:: fd:: RawFd ;
1921use std:: os:: unix:: thread:: JoinHandleExt ;
2022use std:: sync:: atomic:: { AtomicBool , Ordering } ;
2123use std:: sync:: { Arc , Barrier , Mutex } ;
@@ -487,6 +489,12 @@ impl Vcpu {
487489 . map_err ( Error :: VcpuSetGicrBaseAddr ) ?;
488490 Ok ( ( ) )
489491 }
492+
493+ #[ cfg( feature = "kvm" ) ]
494+ pub fn get_kvm_vcpu_raw_fd ( & self ) -> RawFd {
495+ // SAFETY: We hold onto the contract.
496+ unsafe { self . vcpu . get_kvm_vcpu_raw_fd ( ) }
497+ }
490498}
491499
492500impl Pausable for Vcpu { }
You can’t perform that action at this time.
0 commit comments