IIUC, this snippet in the spec means KVM can't restrict what requests are made
by the guests. If so, that makes it difficult to detect/ratelimit a misbehaving
guest, and also limits our options if there are firmware issues (hopefully there
aren't). E.g. ratelimiting a guest after KVM has explicitly requested it to
migrate is not exactly desirable.
Now that KVM supports all the VMGEXIT NAEs required for the base SEV-SNP
feature, set the hypervisor feature to advertise it.
It would helpful if this changelog listed the Guest Requests that are required
for "base" SNP, e.g. to provide some insight as to why we care about guest
requests.
static int snp_bind_asid(struct kvm *kvm, int *error)
@@ -1618,6 +1631,12 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp)
if (rc)
goto e_free_context;
+ /* Used for rate limiting SNP guest message request, use the default settings */
+ ratelimit_default_init(&sev->snp_guest_msg_rs);
Is this exposed to userspace in any way? This feels very much like a knob that
needs to be configurable per-VM.
Also, what are the estimated latencies of a guest request? If the worst case
latency is >200ms, a default ratelimit frequency of 5hz isn't going to do a whole
lot.
+
+ if (!__ratelimit(&sev->snp_guest_msg_rs)) {
+ pr_info_ratelimited("svm: too many guest message requests\n");
+ rc = -EAGAIN;
What guarantee do we have that the guest actually understands -EAGAIN? Ditto
for -EINVAL returned by snp_build_guest_buf(). AFAICT, our options are to return
one of the error codes defined in "Table 95. Status Codes for SNP_GUEST_REQUEST"
of the firmware ABI, kill the guest, or ratelimit the guest without returning
control to the guest.
+ goto e_fail;
+ }
+
+ rc = snp_build_guest_buf(svm, &data, req_gpa, resp_gpa);
+ if (rc)
+ goto e_fail;
+
+ sev = &to_kvm_svm(kvm)->sev_info;
+
+ mutex_lock(&kvm->lock);
Question on the VMPCK sequences. The firmware ABI says:
Each guest has four VMPCKs ... Each message contains a sequence number per
VMPCK. The sequence number is incremented with each message sent. Messages
sent by the guest to the firmware and by the firmware to the guest must be
delivered in order. If not, the firmware will reject subsequent messages ...
Does that mean there are four independent sequences, i.e. four streams the guest
can use "concurrently", or does it mean the overall freshess/integrity check is
composed from four VMPCK sequences, all of which must be correct for the message
to be valid?
If it's the latter, then a traditional mutex isn't really necessary because the
guest must implement its own serialization, e.g. it's own mutex or whatever, to
ensure there is at most one request in-flight at any given time.
side it means KVM can simpy reject requests if there is already an in-flight
request. It might also give us more/better options for ratelimiting?