From patchwork Mon Nov 9 11:32:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11891295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 549BEC388F7 for ; Mon, 9 Nov 2020 11:39:38 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98A1F206B6 for ; Mon, 9 Nov 2020 11:39:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KnbIlsOZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dKdv3AFV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98A1F206B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=x1N/ktO7hZJXyKjCYN57/TWIWWlWuuEN5uYac4ebaUQ=; b=KnbIlsOZaWrZ+zpEJOLc7ntDC 2asQQSVxTfIMPchmWCP2lU5ETBHArnIVK1VuhXHicwLjLW4aUaXSrodJQmFaZnn7QXrOhyP9XykWM ucCHXjXnKoaQonkLjz/rCpxxpqRgE+pGWMI3OJu0Ao2T/3Mp8jb6BAXfX3zvGDo+AC1eGLfYEt5DC EfbBKDbeZQdunIj/EyB0qlfsU+K2ay4UagRF5Q2UqWPMNog5ohT4TlcAx5/PyGZeoslk8Qh9FS3bb KQri9o1mXbovNfeBKovHRiCqAR2+L6M/LkllUH43o60ZKDcs4gbscev8NX9rVTx81r3wd8vTUEkC8 uv75c6Pfw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5VX-0007CU-8b; Mon, 09 Nov 2020 11:38:47 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5QK-0004Zg-HC for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:33:35 +0000 Received: by mail-wr1-x441.google.com with SMTP id j7so1054807wrp.3 for ; Mon, 09 Nov 2020 03:33:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p42rRkCPYWoJ8F/zuYYtS8myDLEcghdypmEMJwmGPuM=; b=dKdv3AFVKNz2TvbhuhQkVsFgrhEhdWpmA59RmYXb77rE0FCbJb/j5vpMfMW43tImW7 nwhBJx0rjj5/lc2OcC5nwslciSR0hKuNAZr2T72xTUwkIclTmg564tL3F31GwRFhKPR7 Itxsk2XYH/HTOdKO4Q27CV0q+y4uGbSCoG071/20ox9dRRYOm0g8Iwvlhie2sKdvUFw4 +5Ok5Sj7CoWCGK9NJIONc4pfJZrnObcg3Wupi7pVmeXf0F/fwx2p3/XAbWIuOtk972jW Tg6kgBygp+akhSDRD4/0L7CUDrp61OUjLbHuI/WEu6Mj7vh5QYBq4UYeumYwqZmeIHS1 4ovw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p42rRkCPYWoJ8F/zuYYtS8myDLEcghdypmEMJwmGPuM=; b=GIJYW+fCt9Pjbtazvq6wesq/VYL6OgGjfPpQy9kwGIXOZmXkvoiPkq2s9uFBSpY+Pm pJOkFsmznn0+PGwGquNOZl98TNAXB4qQ2+VdVrXU3pda+nEa+HH3WYJEYnw0bMeY9TAK PZO9d64Za1ed1Q+HtlN9QOEGDpUwsSUcpv9MAB/QjUNcbjKS0j8EXTnom/r8SHaBSArv YwzwdgDQ6LEGREMq1kwLZJQyk+24G7C3l8i9Y8/fqiGRY3ufwcU1fRsuxDM2GQ39lnIT Ky/OHWsnfvHBaQN6LpGnw/2k0k3cRir9qN7+LldaD2qCNHmi0YVnFFs4V8mSAv2sgkTn s0nA== X-Gm-Message-State: AOAM5324HlYjKuWnMe9pY28zpP8K18B2h45v7D9CHz05NIHz8dSQZrsS ZQLD0NKGVEwKxRlE/4lib733N4lQ7Zg24Bjf X-Google-Smtp-Source: ABdhPJyxgdjvEUnFGKqjP6pt6kqP/0XM/at3rDogZRjLUzJLV7kTcwVriYMD+vgSsOaDAx+Ws5AFWw== X-Received: by 2002:a5d:4ec4:: with SMTP id s4mr3533343wrv.31.1604921602589; Mon, 09 Nov 2020 03:33:22 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id s202sm12526094wme.39.2020.11.09.03.33.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:33:21 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 21/24] kvm: arm64: Add kvm-arm.protected early kernel parameter Date: Mon, 9 Nov 2020 11:32:30 +0000 Message-Id: <20201109113233.9012-22-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_063325_039950_0BEF739C X-CRM114-Status: GOOD ( 19.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Lorenzo Pieralisi , Andrew Walbran , Suzuki K Poulose , Marc Zyngier , Quentin Perret , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Tejun Heo , Dennis Zhou , Christoph Lameter , David Brazdil , Will Deacon , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add an early parameter that allows users to opt into protected KVM mode when using the nVHE hypervisor. In this mode, guest state will be kept private from the host. This will primarily involve enabling stage-2 address translation for the host, restricting DMA to host memory, and filtering host SMCs. Signed-off-by: David Brazdil --- arch/arm64/include/asm/virt.h | 9 +++++++++ arch/arm64/kvm/arm.c | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 6069be50baf9..2c3124512c00 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -65,6 +65,8 @@ extern u32 __boot_cpu_mode[2]; void __hyp_set_vectors(phys_addr_t phys_vector_base); void __hyp_reset_vectors(void); +DECLARE_STATIC_KEY_FALSE(kvm_protected_mode); + /* Reports the availability of HYP mode */ static inline bool is_hyp_mode_available(void) { @@ -97,6 +99,13 @@ static __always_inline bool has_vhe(void) return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN); } +static __always_inline bool is_kvm_protected_mode(void) +{ + return IS_ENABLED(CONFIG_KVM) && + (is_nvhe_hyp_code() || !is_kernel_in_hyp_mode()) && + static_branch_likely(&kvm_protected_mode); +} + #endif /* __ASSEMBLY__ */ #endif /* ! __ASM__VIRT_H */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a931253ebb61..452a01afaf33 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -47,6 +47,8 @@ __asm__(".arch_extension virt"); #endif +DEFINE_STATIC_KEY_FALSE(kvm_protected_mode); + DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector); static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); @@ -1796,6 +1798,11 @@ int kvm_arch_init(void *opaque) return -ENODEV; } + if (in_hyp_mode && static_branch_unlikely(&kvm_protected_mode)) { + kvm_pr_unimpl("VHE protected mode unsupported, not initializing\n"); + return -ENODEV; + } + if (cpus_have_final_cap(ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) || cpus_have_final_cap(ARM64_WORKAROUND_1508412)) kvm_info("Guests without required CPU erratum workarounds can deadlock system!\n" \ @@ -1827,7 +1834,9 @@ int kvm_arch_init(void *opaque) if (err) goto out_hyp; - if (in_hyp_mode) + if (is_kvm_protected_mode()) + kvm_info("Protected nVHE mode initialized successfully\n"); + else if (in_hyp_mode) kvm_info("VHE mode initialized successfully\n"); else kvm_info("Hyp mode initialized successfully\n"); @@ -1848,6 +1857,18 @@ void kvm_arch_exit(void) kvm_perf_teardown(); } +static int __init early_kvm_protected_cfg(char *buf) +{ + bool val; + int err; + + err = strtobool(buf, &val); + if (!err && val) + static_branch_enable(&kvm_protected_mode); + return err; +} +early_param("kvm-arm.protected", early_kvm_protected_cfg); + static int arm_init(void) { int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);