From patchwork Sat Feb 3 00:09:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13543620 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3ED1C48298 for ; Sat, 3 Feb 2024 00:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :Mime-Version:Date:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Y09sDaNHETeqEnl50ZfLdB77Hit88dE4LU9GgAjaaIQ=; b=sAKWZ1VOf38tkn ftTiMCRH7tEv+fERPP4CRPVtOcLTNxSKtMoUASWOL1RUXl5c6PrFg8QH/wp54jh1tmJOiNPZBAY0+ e2IqxbvIqvM4fs/RkPI69Pxn1OIjJ0kqq4CLOehypcvj0rETDj0HGx9oiqpVzYA0DAsh6dvAHiEBz FT6WsyBKYrSBxLOdVaC06Jibg+OCBkG9vIBQln0HKTBEhLMn8Jm1eh3zPGcnq7r6DMGuix1KoFKNO PUVQvDdi+k21cd0QLzrCH32T3bu4Qc3vvTZvvzfcYAo0UPenCqm+j7NWtGpGkcjtngvAhHYMOqmg+ SxFsscoufyLNWqYhijCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rW3b2-0000000DsW8-2ujK; Sat, 03 Feb 2024 00:09:24 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rW3az-0000000DsUh-3fpN for linux-arm-kernel@lists.infradead.org; Sat, 03 Feb 2024 00:09:23 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5d8dbe37d56so2837182a12.0 for ; Fri, 02 Feb 2024 16:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706918961; x=1707523761; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=Tvzfq6Tb+/LmzZGCY47OcGl4Yg3FqwT4x8FVTh6/pw0=; b=axwDI5GhRlgv0wFHbkF5FuzjD0J36h2MWANXQqwaghl+QpX4wDaDSc5AahRGdQHmPu mDfM+A5D//ZG3bPMygBH9eaw0XA/sRqoCeTbXTsJCdx4Aj4inkrESEPrfOWTP4xsIN+S dieEDdH+679hkyYjgbroyL+/j2bB/Vqvj7Ek9UN0KIItaxBo+/xixpWm5uXW43Evyued MHOzLYN72dVQIymkgXofXMKtc2Eev4PxRuQmpzT3DAIImloEUioUeAP6NYG51ZGA0Ux1 PACalkIA6Fnub1y0t7UfBeW+2EQXusPX+PB9RlNyae1reyCAGiM8rB53w7O8MG+FNCuV 1lHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706918961; x=1707523761; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tvzfq6Tb+/LmzZGCY47OcGl4Yg3FqwT4x8FVTh6/pw0=; b=X/YJjs2sCQ6CAWy5S0VXZGSmnPybEm8fF2zq0UMqIZD+DfMXNTJTzsTs694tTsewt9 y/H+RGqLl43AjaH069yx6uuFdAHLyFrMIoYmYdEPEUlzvM0GYdIIxbOy+c1ehE7u6BV1 0eirEPZ2UfdMsJgX97KH6rYEH+Yu7yHQV2nXbpTwRmyJBvca8ZB/u7rllUNNzN9fzyg3 FqVssECAerzaLbrjM35CZjQEWHRTb+L39ulaLQ3SaC0i+v7ZVP7kMphSeNb+mxV7jGSX TAISr503QPqpuinVmN0yCAZzCr2jMmtcwJJ+GKKz0L/dKmn09JHnqyBwI94+4e+fiFl7 xE1g== X-Gm-Message-State: AOJu0YzdJhW8ICsa0XA+e61CamFLnI+uw6MTPzKMixMPsOXsqBoOi1Eb fSrLYaBQ5DCzCVarO/IMn6Kp5tGNtSQqczy88Nb8K95g207EUZI5hzFAOSWTNxnZwKzztsHphtS yjw== X-Google-Smtp-Source: AGHT+IEqzXCmN6ReYMmNGcuC8mmtBhOi0vEe5B/tBx3edOgmg4Vw4BtLnbB387naOpc+iWQYiMA/3I2Kvpo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:670b:0:b0:5d7:9b27:8ad4 with SMTP id u11-20020a65670b000000b005d79b278ad4mr18346pgf.3.1706918960728; Fri, 02 Feb 2024 16:09:20 -0800 (PST) Date: Fri, 2 Feb 2024 16:09:06 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240203000917.376631-1-seanjc@google.com> Subject: [PATCH v8 00/10] KVM: selftests: Add SEV smoke test From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Vishal Annapurve , Ackerley Tng , Andrew Jones , Tom Lendacky , Michael Roth , Peter Gonda X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240202_160921_963797_8B8F959D X-CRM114-Status: GOOD ( 15.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a basic SEV smoke test. Unlike the intra-host migration tests, this one actually runs a small chunk of code in the guest. v8: - Undo the kvm.h uAPI breakage. - Take advantage of "struct vm_shape", introduced by the guest_memfd selftests, to simply tracking the SEV/SEV-ES subtypes. - Rename the test to "sev_smoke_test" instead of "sev_all_boot_test", as the "all" is rather nonsensical, and the test isn't booting anything in the traditional sense of the word. - Drop vm->protected and instead add an arch hook to query if the VM has protected memory. - Assert that the target memory region supports protected memory when allocating protected memory. - Allocate protected_phy_pages for memory regions if and only if the VM supports protected memory. - Rename kvm_host.h to kvm_util_arch.h, and move it to selftests/kvm where it belongs. - Fix up some SoB goofs. - Convert the intrahost SEV/SEV-ES migration tests to use common ioctl() wrappers. V7 * https://lore.kernel.org/all/20231218161146.3554657-1-pgonda@google.com * See https://github.com/sean-jc/linux/tree/x86/sev_selftests_for_peter. * I kept is_pt_protected because without it the page tables are never readable. Its used for the elf loading in kvm_vm_elf_load(). V6 * Updated SEV VM create function based on Seanjc's feedback and new changes to VM creation functions. * Removed pte_me_mask based on feedback. * Fixed s_bit usage based on TDX * Fixed bugs and took Ackerly's code for enc_region setup code. V5 * Rebase onto seanjc@'s latest ucall pool series. * More review changes based on seanjc: ** use protected instead of encrypted outside of SEV specific files ** Swap memcrypt struct for kvm_vm_arch arch specific struct ** Make protected page table data agnostic of address bit stealing specifics of SEV ** Further clean up for SEV library to just vm_sev_create_one_vcpu() * Due to large changes moved more authorships from mroth@ to pgonda@. Gave originally-by tags to mroth@ as suggested by Seanjc for this. V4 * Rebase ontop of seanjc@'s latest Ucall Pool series: https://lore.kernel.org/linux-arm-kernel/20220825232522.3997340-8-seanjc@google.com/ * Fix up review comments from seanjc * Switch authorship on 2 patches because of significant changes, added * Michael as suggested-by or originally-by. V3 * Addressed more of andrew.jones@ in ucall patches. * Fix build in non-x86 archs. V2 * Dropped RFC tag * Correctly separated Sean's ucall patches into 2 as originally intended. * Addressed andrew.jones@ in ucall patches. * Fixed ucall pool usage to work for other archs V1 * https://lore.kernel.org/all/20220715192956.1873315-1-pgonda@google.com/ Ackerley Tng (1): KVM: selftests: Add a macro to iterate over a sparsebit range Michael Roth (2): KVM: selftests: Make sparsebit structs const where appropriate KVM: selftests: Add support for protected vm_vaddr_* allocations Peter Gonda (5): KVM: selftests: Add support for allocating/managing protected guest memory KVM: selftests: Explicitly ucall pool from shared memory KVM: selftests: Allow tagging protected memory in guest page tables KVM: selftests: Add library for creating and interacting with SEV guests KVM: selftests: Add a basic SEV smoke test Sean Christopherson (2): KVM: selftests: Extend VM creation's @shape to allow control of VM subtype KVM: selftests: Use the SEV library APIs in the intra-host migration test tools/testing/selftests/kvm/Makefile | 2 + .../kvm/include/aarch64/kvm_util_arch.h | 7 + .../selftests/kvm/include/kvm_util_base.h | 50 ++++++- .../kvm/include/riscv/kvm_util_arch.h | 7 + .../kvm/include/s390x/kvm_util_arch.h | 7 + .../testing/selftests/kvm/include/sparsebit.h | 56 +++++--- .../kvm/include/x86_64/kvm_util_arch.h | 23 ++++ .../selftests/kvm/include/x86_64/processor.h | 8 ++ .../selftests/kvm/include/x86_64/sev.h | 110 +++++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 67 +++++++-- tools/testing/selftests/kvm/lib/sparsebit.c | 48 +++---- .../testing/selftests/kvm/lib/ucall_common.c | 3 +- .../selftests/kvm/lib/x86_64/processor.c | 32 ++++- tools/testing/selftests/kvm/lib/x86_64/sev.c | 128 ++++++++++++++++++ .../selftests/kvm/x86_64/sev_migrate_tests.c | 67 +++------ .../selftests/kvm/x86_64/sev_smoke_test.c | 58 ++++++++ 16 files changed, 570 insertions(+), 103 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/aarch64/kvm_util_arch.h create mode 100644 tools/testing/selftests/kvm/include/riscv/kvm_util_arch.h create mode 100644 tools/testing/selftests/kvm/include/s390x/kvm_util_arch.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/sev.h create mode 100644 tools/testing/selftests/kvm/lib/x86_64/sev.c create mode 100644 tools/testing/selftests/kvm/x86_64/sev_smoke_test.c base-commit: 60eedcfceda9db46f1b333e5e1aa9359793f04fb Tested-by: Carlos Bilbao