Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1017773pxu; Mon, 23 Nov 2020 09:33:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoBRCVriw4ciPvbAKzloRw1HLshT70HtEgBtQQBeKMGYGCCedqaadlZ3tLGBdc49gWPRpP X-Received: by 2002:a17:906:f0c3:: with SMTP id dk3mr633410ejb.366.1606152789211; Mon, 23 Nov 2020 09:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606152789; cv=none; d=google.com; s=arc-20160816; b=Xb9DZy+MtOGcPdGQWbcbpgLvoUu4iiEiUB14ZB3QD6QwsmmyqRuJ7rJWVb3GuuIu41 uNk1VyW5oC9bnzG9fn9Ee7jHIs/Oe2OqIYLMu8ev8KfHthqLZlQU/3UwI6WqFD8cYvoX k/oI2BrJAkm+rI0Oln35W2ozmtFexn7fbzeiQicwJl6JXck0082h4BDJUVj61Pryimlf S80M/h8e4teQPiBHRiD1OdqH/KLhGx38/oKki7n2ANCREbT/DUIiLFPpS31XyIDC4ZAV IdLniJ8Suro4bag5K4HlRTr7Tjv4xyOZrMkN4s6PY916YGptqng1I4UQwJTT6PJIybbW u4TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=erVyBiN6J0WI1KyF4sHTmLrIsWCB3B/VKVEYcfAWE5g=; b=eeSmhhub4xu6Gjw+GeS2TEWkSpd90zcG+QKMQbeUZaQ4JCQ7Hp4tw+IKKM3TqwZ54j RHB/zKDwdnSWfAkYoGsLSfO2Q7FTr2WjqtionJtqidOI+R0gx1/P1dJpcV3mNHKMbztK PJk+qaL/G9IdjS7BvKK/A3A1EU0HPJwnFbll4Mmlxwvo/dyuf/vgXYZPu23e9UQSVADk oHpPJW/EyHxqKF/UfLutavoHW4YoMpa/WxQ7UwlRqAX4k2pzad/7XnD0bZkuYMeVeNRM OCXBEwWTJKtkLD5S4derxFAUaX0V6O0lDPmFz+NTLPXRxrrEI8Wa2PhGvAUHO8hmuARx SS4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dyDnD2a0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 41si7129598edq.580.2020.11.23.09.32.41; Mon, 23 Nov 2020 09:33:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dyDnD2a0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390296AbgKWRaT (ORCPT + 99 others); Mon, 23 Nov 2020 12:30:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:47066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbgKWRaS (ORCPT ); Mon, 23 Nov 2020 12:30:18 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD76E20758; Mon, 23 Nov 2020 17:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606152618; bh=oz9JmIWa3XvZOAzCbCMICe2nj2WJ7qbp9Ua7W1eEYYc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dyDnD2a0fu0SnFH9Caat93EMmFaB9b4qWf64Zh4wx7cGpP39t3pQS0MdiqJEyOz0b 7xT9bl5rfjXtO1H+SZob50e7UFUmV+TQVsM1BShiutxjA2cbnAAo8+TnB7sPMIFWa2 2p8CrxT6zuyljZtaQk0r0w6wYhsNtjk6HcvFC7Qw= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1khFfL-00D18Q-JR; Mon, 23 Nov 2020 17:30:15 +0000 Date: Mon, 23 Nov 2020 17:30:14 +0000 Message-ID: <87eekk56c9.wl-maz@kernel.org> From: Marc Zyngier To: David Brazdil Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Quentin Perret , Andrew Scull , Andrew Walbran , kernel-team@android.com Subject: Re: [PATCH v2 21/24] kvm: arm64: Add kvm-arm.protected early kernel parameter In-Reply-To: <20201116204318.63987-22-dbrazdil@google.com> References: <20201116204318.63987-1-dbrazdil@google.com> <20201116204318.63987-22-dbrazdil@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, dennis@kernel.org, tj@kernel.org, cl@linux.com, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, qperret@google.com, ascull@google.com, qwandor@google.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 16 Nov 2020 20:43:15 +0000, David Brazdil wrote: > > 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. > > Capability ARM64_PROTECTED_KVM is set if the param is passed, CONFIG_KVM > is enabled and the kernel was not booted with VHE. > > Signed-off-by: David Brazdil > --- > arch/arm64/include/asm/cpucaps.h | 3 ++- > arch/arm64/include/asm/virt.h | 8 ++++++++ > arch/arm64/kernel/cpufeature.c | 29 +++++++++++++++++++++++++++++ > arch/arm64/kvm/arm.c | 10 +++++++++- > 4 files changed, 48 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h > index e7d98997c09c..ac075f70b2e4 100644 > --- a/arch/arm64/include/asm/cpucaps.h > +++ b/arch/arm64/include/asm/cpucaps.h > @@ -66,7 +66,8 @@ > #define ARM64_HAS_TLB_RANGE 56 > #define ARM64_MTE 57 > #define ARM64_WORKAROUND_1508412 58 > +#define ARM64_PROTECTED_KVM 59 > > -#define ARM64_NCAPS 59 > +#define ARM64_NCAPS 60 > > #endif /* __ASM_CPUCAPS_H */ > diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h > index 6069be50baf9..2fde1186b962 100644 > --- a/arch/arm64/include/asm/virt.h > +++ b/arch/arm64/include/asm/virt.h > @@ -97,6 +97,14 @@ static __always_inline bool has_vhe(void) > return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN); > } > > +static __always_inline bool is_protected_kvm_enabled(void) > +{ > + if (is_vhe_hyp_code()) > + return false; > + else > + return cpus_have_final_cap(ARM64_PROTECTED_KVM); > +} > + > #endif /* __ASSEMBLY__ */ > > #endif /* ! __ASM__VIRT_H */ > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 6f36c4f62f69..dd5bc0f0cf0d 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -1709,6 +1709,29 @@ static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) > } > #endif /* CONFIG_ARM64_MTE */ > > +#ifdef CONFIG_KVM > +static bool enable_protected_kvm; > + > +static bool has_protected_kvm(const struct arm64_cpu_capabilities *entry, int __unused) > +{ > + if (!enable_protected_kvm) > + return false; > + > + if (is_kernel_in_hyp_mode()) { > + pr_warn("Protected KVM not available with VHE\n"); > + return false; > + } > + > + return true; > +} > + > +static int __init early_protected_kvm_cfg(char *buf) > +{ > + return strtobool(buf, &enable_protected_kvm); > +} > +early_param("kvm-arm.protected", early_protected_kvm_cfg); Please add some documentation to Documentation/admin-guide/kernel-parameters.txt. > +#endif /* CONFIG_KVM */ > + > /* Internal helper functions to match cpu capability type */ > static bool > cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap) > @@ -1822,6 +1845,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = { > .field_pos = ID_AA64PFR0_EL1_SHIFT, > .min_field_value = ID_AA64PFR0_EL1_32BIT_64BIT, > }, > + { > + .desc = "Protected KVM", > + .capability = ARM64_PROTECTED_KVM, > + .type = ARM64_CPUCAP_SYSTEM_FEATURE, > + .matches = has_protected_kvm, > + }, > #endif > { > .desc = "Kernel page table isolation (KPTI)", > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index c76a8e5bd19c..49d2474f2a80 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1796,6 +1796,12 @@ int kvm_arch_init(void *opaque) > return -ENODEV; > } > > + /* The PROTECTED_KVM cap should not have been enabled for VHE. */ > + if (in_hyp_mode && is_protected_kvm_enabled()) { > + kvm_pr_unimpl("VHE protected mode unsupported, not initializing\n"); > + return -ENODEV; How can this happen? Don't we already take care of this? > + } > + > 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 +1833,9 @@ int kvm_arch_init(void *opaque) > if (err) > goto out_hyp; > > - if (in_hyp_mode) > + if (is_protected_kvm_enabled()) > + 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"); > -- > 2.29.2.299.gdc1121823c-goog > > Thanks, M. -- Without deviation from the norm, progress is not possible.