From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86402C433F5 for ; Thu, 6 Oct 2022 18:31:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231873AbiJFSbh (ORCPT ); Thu, 6 Oct 2022 14:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbiJFSb1 (ORCPT ); Thu, 6 Oct 2022 14:31:27 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A1E8AA34D for ; Thu, 6 Oct 2022 11:31:23 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id c7so2551089pgt.11 for ; Thu, 06 Oct 2022 11:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=5tqpyzMMfKgYRQNtK1HpD/acwmpZ7QOJOYhsAzwpzxM=; b=fa84eRR0WULkX9PBmJMowIb5wtxulEbChbHx3QTmTywdR3H6dUR/OFCekwJ9kX0ion OWnMU/X1h2xenNFoqVG2wT9CD8RVh1x+KpExrKV0TUZeWtGTu1hNbhISFT6xKfuCCNlg b02zuzlNM875Aa2StQEoExcxePzpXHnoRlgWWJy0hvoRhPVb8GAGS66PqfsmyeYH2F+C 6StSx3vUSCdPCSmm4auVTAAapZvfeLaUIsZuoXEu0LYvHF9Frx5QMw6bIpoOIVn/WGbT rQ5shfWYf9QPRMZR65zMZUrFSdah7Yp3e1/GXxfIgQ84Seij9vRsR+2tF5c1gliC0MHR 26lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5tqpyzMMfKgYRQNtK1HpD/acwmpZ7QOJOYhsAzwpzxM=; b=rfVtoepFmtqv1mlBkNplXr7N6BjNjhCO4Jk5+KnNXu0i1yA5tNS0bvHgj5hABLEx7f ZMfRmYGuoDN8dV7wYJkSdnH/1npzYV0aHXMk/gYvc4KvAAOZsVQBhTkxa6RKc3xebWeu a73aY9ZFFDV7ih1YOx88d2ey9g7FajhpMCh2dG0TthQBlhgirkal+HuPQpSRCQNoGtsZ Tfun8M6h0jxm8IjGxWJBHEvxXXtcf6juJ3/HgNzvmjedUeFsq9bWAFr5fHeLBHw9dbq4 l37Rn2fBiB3LeJGnL/7NZJfSYI0cPtE/Aq5g9/3bYmSehXcJhzm8k578EivXoHEUq6c6 +R8Q== X-Gm-Message-State: ACrzQf2huzS6mIDKG6FI7zIR/7e4gmUydiE5gOvpPPA8ElR3C2llHw2+ iunFyIA0xs42sMrbqqIORi4fdw== X-Google-Smtp-Source: AMsMyM5VjpJstVpZ6fMJq81hg2Zk1rlj0F5x+JOErJlhi+pl/A09JgHlzkidlzgGzMAna0/X4lqJ8A== X-Received: by 2002:a63:d145:0:b0:443:c25f:5dd5 with SMTP id c5-20020a63d145000000b00443c25f5dd5mr1010382pgj.554.1665081082646; Thu, 06 Oct 2022 11:31:22 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id j12-20020a170903024c00b0017a04542a45sm12849930plh.159.2022.10.06.11.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 11:31:21 -0700 (PDT) Date: Thu, 6 Oct 2022 18:31:18 +0000 From: Sean Christopherson To: Peter Gonda Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, marcorr@google.com, michael.roth@amd.com, thomas.lendacky@amd.com, joro@8bytes.org, mizhang@google.com, pbonzini@redhat.com, andrew.jones@linux.dev Subject: Re: [V4 8/8] KVM: selftests: Add simple sev vm testing Message-ID: References: <20220829171021.701198-1-pgonda@google.com> <20220829171021.701198-9-pgonda@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220829171021.701198-9-pgonda@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 29, 2022, Peter Gonda wrote: > + for (i = 0; i <= NR_SYNCS; ++i) { > + vcpu_run(vcpu); > + switch (get_ucall(vcpu, &uc)) { > + case UCALL_SYNC: > + continue; > + case UCALL_DONE: > + return; > + case UCALL_ABORT: > + TEST_ASSERT(false, "%s at %s:%ld\n\tvalues: %#lx, %#lx", > + (const char *)uc.args[0], __FILE__, > + uc.args[1], uc.args[2], uc.args[3]); REPORT_GUEST_ASSERT > + default: > + TEST_ASSERT( > + false, "Unexpected exit: %s", > + exit_reason_str(vcpu->run->exit_reason)); TEST_FAIL > + } > + } > +} > + > +static void guest_sev_code(void) > +{ > + uint32_t eax, ebx, ecx, edx; > + uint64_t sev_status; > + > + GUEST_SYNC(1); > + > + GUEST_ASSERT(this_cpu_has(X86_FEATURE_SEV)); > + > + sev_status = rdmsr(MSR_AMD64_SEV); > + GUEST_ASSERT((sev_status & 0x1) == 1); Add a #define for the magic 0x1. And the "== 1" is unnecessary. Hmm, and the querying of SEV/SEV-ES/etc status in MSR_AMD64_SEV should be done in helpers. > + > + GUEST_DONE(); > +} > + > +static struct sev_vm *setup_test_common(void *guest_code, uint64_t policy, > + struct kvm_vcpu **vcpu) > +{ > + uint8_t measurement[512]; > + struct sev_vm *sev; > + struct kvm_vm *vm; > + int i; > + > + sev = sev_vm_create(policy, TOTAL_PAGES); > + TEST_ASSERT(sev, "sev_vm_create() failed to create VM\n"); See earlier comments on using TEST_REQUIRE. > + > + vm = sev->vm; > + > + /* Set up VCPU and initial guest kernel. */ > + *vcpu = vm_vcpu_add(vm, 0, guest_code); > + kvm_vm_elf_load(vm, program_invocation_name); > + > + /* Allocations/setup done. Encrypt initial guest payload. */ > + sev_vm_launch(sev); > + > + /* Dump the initial measurement. A test to actually verify it would be nice. */ > + sev_vm_launch_measure(sev, measurement); > + pr_info("guest measurement: "); > + for (i = 0; i < 32; ++i) > + pr_info("%02x", measurement[i]); > + pr_info("\n"); > + > + sev_vm_launch_finish(sev); I believe this entire function gets replaced with vm = ____vm_create_with_one_vcpu(VM_MODE_PXXV48_4K_SEV, &vcpu, 0, guest_code); > + > + return sev; > +} > + > +static void test_sev(void *guest_code, uint64_t policy) > +{ > + struct sev_vm *sev; > + struct kvm_vcpu *vcpu; > + > + sev = setup_test_common(guest_code, policy, &vcpu); > + > + /* Guest is ready to run. Do the tests. */ Comment doesn't add much value. > + guest_run_loop(vcpu); > + > + pr_info("guest ran successfully\n"); Meh, the test passing is a good indication the test ran successfully. > + > + sev_vm_free(sev); > +} > + > +int main(int argc, char *argv[]) > +{ > + /* SEV tests */ Again, stating the obvious. > + test_sev(guest_sev_code, SEV_POLICY_NO_DBG); > + test_sev(guest_sev_code, 0); > + > + return 0; > +} > -- > 2.37.2.672.g94769d06f0-goog >