From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDBFA38DE4 for ; Fri, 9 Aug 2024 15:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723218315; cv=none; b=rDQH1dzLsouKYfhQyMnRLXy7FsowMPlUt3MceF4pQ5otOYi3XwZDC3nTwoVyK2yOT/BNhgCHYgfi0OcDBz6eWcxdC+hiL/X00AoZc2jUMJah3DCKdtryBxYUt0LJ6W2t8W4mDfUOi60kF8oTpy+BRknmK0/MFxxO4ZtnkAJBB/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723218315; c=relaxed/simple; bh=4xKAdAddRSzH31ADhKLaPGKj1tnhAdZ+HE6xwKWHgfw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pAoReWobpfCLKdN8nBw2CJzID8Xwj8Y8/8qx3ZZaUsc3Nl11o4gCXiyqCn6/mNxauN7Han5og2qZnkAS5AcUFBee/ESwZ5RRuwtfJVPPQGfU+D1v2TKU2c60Qx3XC/kpMaxtJkr3LNHJ+OrAvXbLB12/XHiRNIjSrlIhU/U3upw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ags7VAjT; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ags7VAjT" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-64b70c4a269so45186817b3.1 for ; Fri, 09 Aug 2024 08:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723218313; x=1723823113; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ufzxNYpm833F4D+it9EVre+p13feWMXlScCKKRbhPtg=; b=Ags7VAjTEKTy69FBDkWR/XJ5jldPb/DhIGL4gTq7FIeNqV0WdSc28yWvkCj8XOANxF 1jviKApndwtFJNKzB/hgm9dX3I+3WiWBTREUUHqnAgQazJWQ4YnpZE7U8Kj1ceOuNus5 WjusSSsDTsAvG7kwQXam1lCgkj9o3bRbdrvkiFkHNNsX/p0oZkulGvXw5TC/QiSJ4pP0 eRRgiYDxt65JJd0NTTJlWGFG1xjqD1ZDYzz0SNb9FoDrE994jSA+KFGCLe4ryVwg4yUt UR8HuqTOUBLSvuV6IDSU0cyXRzM2MRtWtkG1j1nEosOtFmKtKWUb9LIqSD2n2jljhQ3H JTzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723218313; x=1723823113; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ufzxNYpm833F4D+it9EVre+p13feWMXlScCKKRbhPtg=; b=HRmOXK9/sNIY8UZe2s0ZgKq01VwXlq9iFEosALBZEcyeDDoQ3k7Oon/K6rszVK7SMu Vm7LgM1aYoaUO2WYDJWS4hE3Hc6E0gPNDd364CMrKlq04snGM0h7+p1TgFpj3klabxBj 2eFYbbW+vVqQaUDjTLObOaPNzq42dTxN2PykUdfvtfdVikv1HG/Y06jK6dmXpokdNQ2x EBR/pxrJ7X/WrH24Rgrd5xYD8kgPCT59cejLrQZlNsxNXkGaISQDufX9ws26PqLTwNN1 1ryRsgpvrZXXDX8ZtIp+0tAtN3U6VuRAt905phK7eX0cfbKj59bT9cSyN2SCaq/X5NC7 I7Og== X-Forwarded-Encrypted: i=1; AJvYcCVlmcR+M7UqtJdUXDa6ZjbTUt5v5CrSgPfHIc7evAaWRg55rPWgji1EPkfqTjNqkof1E04HzwLzdS8ZCnOQeolB/ZqBLqlvh748xRWA X-Gm-Message-State: AOJu0YzX0wJvv33x1K8VZdY8ha2BjwCZsuqpjbJIhfMqBNL5fPZ6mVWE LcVVEn5GI9fsvXrkvZQf+/jhItPMiVvl71GuRf/JwKJsJ7QHTUUi5VTmcg4XDLoLAzwpJE1g6FH 5VQ== X-Google-Smtp-Source: AGHT+IGmKxWqzG8EPgakjna8JtWGPg62vJdK+0Bc2Qodmrlh2F+IyIYu6Pp5IsmyEemyLyeZWsSJxb5C0rY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:2f04:b0:65c:1db1:9235 with SMTP id 00721157ae682-69ebf29b861mr647807b3.0.1723218312835; Fri, 09 Aug 2024 08:45:12 -0700 (PDT) Date: Fri, 9 Aug 2024 08:45:11 -0700 In-Reply-To: <98c1f8e2-3b24-49c4-b5fc-506e4283248d@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240710220540.188239-1-pratikrajesh.sampat@amd.com> <20240710220540.188239-4-pratikrajesh.sampat@amd.com> <8870ca39-f5a9-8d33-3372-77a6693ad739@amd.com> <98c1f8e2-3b24-49c4-b5fc-506e4283248d@amd.com> Message-ID: Subject: Re: [RFC 3/5] selftests: KVM: SEV IOCTL test From: Sean Christopherson To: Pratik Rajesh Sampat Cc: Tom Lendacky , kvm@vger.kernel.org, shuah@kernel.org, michael.roth@amd.com, pbonzini@redhat.com, pgonda@google.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Thu, Jul 11, 2024, Pratik Rajesh Sampat wrote: > >> +static void sev_guest_status_assert(struct kvm_vm *vm, uint32_t type) > >> +{ > >> + struct kvm_sev_guest_status status; > >> + bool cond; > >> + int ret; > >> + > >> + ret = __vm_sev_ioctl(vm, KVM_SEV_GUEST_STATUS, &status); > >> + cond = type == KVM_X86_SEV_VM ? !ret : ret; > >> + TEST_ASSERT(cond, > >> + "KVM_SEV_GUEST_STATUS should fail, invalid VM Type."); > >> +} > >> + > >> +static void test_sev_launch(void *guest_code, uint32_t type, uint64_t policy) > >> +{ > >> + struct kvm_vcpu *vcpu; > >> + struct kvm_vm *vm; > >> + struct ucall uc; > >> + bool cond; > >> + int ret; > >> + > > > > Maybe a block comment here indicating what you're actually doing would > > be good, because I'm a bit confused. > > > > A policy value of 0 is valid for SEV, so you expect each call to > > succeed, right? And, actually, for SEV-ES the launch start will succeed, > > too, but the launch update will fail because LAUNCH_UPDATE_VMSA is not > > valid for SEV, but then the launch measure should succeed. Is that > > right? What about the other calls? > > > > Sure, I can do that. > Yes for SEV, the policy value of 0 succeeds for everything except when > we try to run and we see a KVM_EXIT_IO. > > For SEV-ES, with the policy value of 0 - we don't see launch_start > succeed. It fails with EIO in this case. Post that all the calls for > SEV-ES also fail subsequent to that. I guess the core idea behind this > test is to ensure that once the first bad case of launch_start fails, we > should see a cascading list of failures. > > >> + vm = vm_sev_create_with_one_vcpu(type, guest_code, &vcpu); > >> + ret = sev_vm_launch_start(vm, 0); > >> + cond = type == KVM_X86_SEV_VM ? !ret : ret; > >> + TEST_ASSERT(cond, Don't bury the result in a local boolean. It's confusing, and _worse_ for debug as it makes it impossible to see what actually failed (the assert message will simply print "cond", which is useless). > >> + "KVM_SEV_LAUNCH_START should fail, invalid policy."); This is a blatant lie, because the KVM_X86_SEV_VM case apparently expects success. Similar to Tom's comments about explaing what this code is doing, these assert messages need to explain what the actually expected result it, provide a hint as to _why_ that result is expected, and print the result. As is, this will be unnecessarily difficult to debug if/when it fails.