From patchwork Tue Jan 10 17:50:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 3816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2885942wrt; Tue, 10 Jan 2023 09:51:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXv1paz/M0GR1/3Ul40SJc2zRWcfmfu7I45WcArRff3L+AfRjKpao7IKWufCKadjf9GrXE6p X-Received: by 2002:a05:6a20:94a1:b0:ad:c694:3fbb with SMTP id hs33-20020a056a2094a100b000adc6943fbbmr70087024pzb.25.1673373104729; Tue, 10 Jan 2023 09:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673373104; cv=none; d=google.com; s=arc-20160816; b=U0oWErCuykhELlbDgf5ygtMlG2nzUC8CW2ClRMfLz66z3xF8L0B3UK/KOHxq6vSZKH H/R3SDnynP7wlWSnzKEWsfVRq5DRAmnyDe2GaILJj3ShYZGtcGR9wR0hHNYAL2Au9Itz Et2fYIKnLfFOFj4/ZSR4Zs44ZXNQiLB/v3WQ5fOhEYSBCqVGc3idT9UaHrQbg0Vnr6Fv 1XUiZfMzrUYmTKNQRuOZght4mizzjNLBs78E5CUUBdNkeJUpO9hEd7vl1dTfKF/W87cF yb6V7owILxE+l5SpHduVXRM8OUSA9vcarqbiDkXREQvVEPngm+J4MNkIlqqBsuEkhTUq Q/3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=hICen6oMGDQkBaOVpNtEPss3TFZW17o9hNwTIHD4XGI=; b=De7ICJ1xKeB2lHeAYT08k5d/kYTD3Ap+kwzfiYrlMI/oll6uuWQpgzoFP+9EkgnzKi iJHh+koTMQD3N3W5h2tT0x/kpu9iDWouM7FNym34f0bH8kRD922bKrdQqnCl39Hue5YC sKRarToAzvZxvgTu3Q3h3SHsrkS16nSpU1ZxJHzkUe60BB2TdLSNKj+uxkSdF80A/0Jw wu7Jm1123Yu15yLOI77EUS8BOINZ5p3ulWFkOsknnUOjnQdOLIofOg88q846IsK1wkOJ ROfPoUWha7d/LkF3fhJ/WIcId1Zzg/D99weidcQNVjlEyyWv9whKv0FwEEmOjNuEVl48 DHWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WpvpBPEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a63ed43000000b00461f124bc4csi12638197pgk.86.2023.01.10.09.51.31; Tue, 10 Jan 2023 09:51:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WpvpBPEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233030AbjAJRvJ (ORCPT + 99 others); Tue, 10 Jan 2023 12:51:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbjAJRvF (ORCPT ); Tue, 10 Jan 2023 12:51:05 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9334232EAD for ; Tue, 10 Jan 2023 09:51:04 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id k20-20020aa792d4000000b0058347d2f5e3so5533205pfa.15 for ; Tue, 10 Jan 2023 09:51:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=hICen6oMGDQkBaOVpNtEPss3TFZW17o9hNwTIHD4XGI=; b=WpvpBPEkoeRepVIhMXcWbpDTls42db3NlhJOX2Xa2fI5tCL+RRSnDNv0d1YyHoB/xL 88vtalk4biVmwYUAr3u/epHuOQPGXZWtc65NpaPUqXDxdhfB2niD80YQ6/pZ+kCsKHj4 RyUX1weIOE9Uqq6pL1AUuC89a/fkgQtde8WIkwVf4ld3RFW+NEXyPOseRzBHiqixNTQB fSzGt0mP4920wARoIPfEbVEEY36C1eBCXu1ezZlaOF/bR/2vuyKDyXSJxfSzKUXgzbCv ypF0kYOcvp6/BhOVuExlLyPfBWbtjKAVMg6yjAdNmFyRSVG/xdc5rpuTpt4ev8iCTyS9 jgmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hICen6oMGDQkBaOVpNtEPss3TFZW17o9hNwTIHD4XGI=; b=aCn6EBCgBgCNJIqMpUWn/+l8G2jZ6E6+nAipm9cuZMfYNwAFFVbMZ4+W81E73GZmR4 nzsNk9NJNG+gdGyIfzZid92+HsB0P0kx8ziLZrQdEUcVD7ZLI4SKaFyZfskajrcPUoYp ldKulRbBSVAB0IeaErHwTiEiIPpuDrz4oXQ2kAlQ08Dpi/MQk8njAcgzwe2UaMpsqIPZ 2NZDLDwIPxNWqUEsVJgdQHPwNjEf8DSjI2auMaev/eoq53gfUI5jw/w0WEBw/gGSjeKM 1kGbQQQe09mmHEci19JYzCZib81tNzm64Eg8hC6L1MnYWBEgvdxolPoH8XbgafBOpxHH +KQQ== X-Gm-Message-State: AFqh2ko3Cm0vfFqswfnO77C2LcZWlkjSO+z2Pq5kY6j6CgdfFmytPTPx JIbs1PdQ+QyLLI2yivYenfwcAv8mbqQ= X-Received: from pgonda1.kir.corp.google.com ([2620:0:1008:11:8358:4c2a:eae1:4752]) (user=pgonda job=sendgmr) by 2002:a62:e512:0:b0:580:c2fb:7ed7 with SMTP id n18-20020a62e512000000b00580c2fb7ed7mr4521991pff.61.1673373064121; Tue, 10 Jan 2023 09:51:04 -0800 (PST) Date: Tue, 10 Jan 2023 09:50:50 -0800 Message-Id: <20230110175057.715453-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH V6 0/7] KVM: selftests: Add simple SEV test From: Peter Gonda To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Gonda , marcorr@google.com, michael.roth@amd.com, thomas.lendacky@amd.com, joro@8bytes.org, pbonzini@redhat.com, andrew.jones@linux.dev, vannapurve@google.com, Sean Christopherson , Ackerley Tng X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754656186997332265?= X-GMAIL-MSGID: =?utf-8?q?1754658876679868530?= This patch series continues the work Michael Roth has done in supporting SEV guests in selftests. It continues on top of the work Sean Christopherson has sent to support ucalls from SEV guests. Along with a very simple version of the SEV selftests Michael originally proposed. 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/ Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: marcorr@google.com Cc: michael.roth@amd.com Cc: thomas.lendacky@amd.com Cc: joro@8bytes.org Cc: pbonzini@redhat.com Cc: andrew.jones@linux.dev Cc: vannapurve@google.com Cc: Sean Christopherson Cc: Ackerley Tng Michael Roth (2): KVM: selftests: sparsebit: add const where appropriate KVM: selftests: add support for protected vm_vaddr_* allocations Peter Gonda (5): KVM: selftests: add hooks for managing protected guest memory KVM: selftests: handle protected bits in page tables KVM: selftests: add library for creating/interacting with SEV guests KVM: selftests: Update ucall pool to allocate from shared memory KVM: selftests: Add simple sev vm testing tools/arch/arm64/include/asm/kvm_host.h | 7 + tools/arch/riscv/include/asm/kvm_host.h | 7 + tools/arch/s390/include/asm/kvm_host.h | 7 + tools/arch/x86/include/asm/kvm_host.h | 14 + tools/testing/selftests/kvm/.gitignore | 84 ++++++ tools/testing/selftests/kvm/Makefile | 4 +- .../selftests/kvm/include/kvm_util_base.h | 49 +++- .../testing/selftests/kvm/include/sparsebit.h | 36 +-- .../selftests/kvm/include/x86_64/processor.h | 1 + .../selftests/kvm/include/x86_64/sev.h | 27 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 66 ++++- tools/testing/selftests/kvm/lib/sparsebit.c | 48 ++-- .../testing/selftests/kvm/lib/ucall_common.c | 2 +- .../selftests/kvm/lib/x86_64/processor.c | 62 ++++- tools/testing/selftests/kvm/lib/x86_64/sev.c | 254 ++++++++++++++++++ .../selftests/kvm/x86_64/sev_all_boot_test.c | 84 ++++++ 16 files changed, 685 insertions(+), 67 deletions(-) create mode 100644 tools/arch/arm64/include/asm/kvm_host.h create mode 100644 tools/arch/riscv/include/asm/kvm_host.h create mode 100644 tools/arch/s390/include/asm/kvm_host.h create mode 100644 tools/arch/x86/include/asm/kvm_host.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_all_boot_test.c