Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3574725img; Mon, 25 Mar 2019 13:06:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGchNTGV9F3ypoSTLYMe4U+rKDoxcFevL6ef6OjQRFR3yK8lUSkUftFJRSArW+YAF8uwgr X-Received: by 2002:a17:902:2888:: with SMTP id f8mr27564552plb.244.1553544371576; Mon, 25 Mar 2019 13:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553544371; cv=none; d=google.com; s=arc-20160816; b=J1vhSM/OaV9MzWdRnNDi+kwwTajpUxtDYa6UoBrfhSuMANIxySJfJLHjaljPaDe9bn 60SnuZlAmkB5Xn8YzP1e8GDuMXFquVpdtg4Bv17Zb3cjrbAFl5VM6cPI8uKCYS+UqlAk O7lubK90v97imiuFdSI8cmKPBrhZn7deeTlWA0cz/3IQu+NbFKYs4iAeZvhCJ3buFlEl ktitLbWsDHrE+VZmSc3Xp4DWlRPzB2jfcyi0+KF93uGZXzivU177I8y505RudY7NSQ3L dyr6EnEGf667DTjsCcrx6or+GC4LDaoNO1XFru+rhXSfZEiVVTQ6MgyS5+5cZrbJ4jiy lWHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from; bh=ZcxgVXFmeIOVM4V2/eEN6arlf5mv+/C8WtDTs9CS+HU=; b=eV92HkajYVcZshCt4IhARksmqTMlY1o2SCBJOQdC9IrB4MUonAObXsBzFVCBt4Fzqd bboROGrDW9BXNELLzW21/Dydea6qFnXfBwOAUFWloXoskXu+umM9i4GV6aweY5XxOcxo t08BIW9PExd9rK2c+D+/ahxPikFLS0LBd+BPRQ6QWt9ynWAdLSBU+C0ttVOKkTU/PwG+ xOyENQws/bM1xXEeXTGndq/6EKWXuGtenLbhT+/HVSIlONZfYH5spEg3pDpmPOSGXx4w sJc+0DlOJIRBij1fe/RPVc9ZFJbNTPZpQm7V+eLRurDmIAkOEHSQaLkz7EdQUlWZ2oQc +nvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q189si14485607pgq.240.2019.03.25.13.05.56; Mon, 25 Mar 2019 13:06:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730084AbfCYUE6 (ORCPT + 99 others); Mon, 25 Mar 2019 16:04:58 -0400 Received: from foss.arm.com ([217.140.101.70]:54580 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729610AbfCYUE6 (ORCPT ); Mon, 25 Mar 2019 16:04:58 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BFBC11596; Mon, 25 Mar 2019 13:04:57 -0700 (PDT) Received: from [10.1.197.21] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 87A1E3F59C; Mon, 25 Mar 2019 13:04:55 -0700 (PDT) From: Kristina Martsenko Subject: Re: [PATCH v7 7/10] KVM: arm/arm64: context-switch ptrauth registers To: Amit Daniel Kachhap , linux-arm-kernel@lists.infradead.org Cc: Christoffer Dall , Marc Zyngier , Catalin Marinas , Will Deacon , Andrew Jones , Dave Martin , Ramana Radhakrishnan , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Mark Rutland , James Morse , Julien Thierry References: <1552984243-7689-1-git-send-email-amit.kachhap@arm.com> <1552984243-7689-8-git-send-email-amit.kachhap@arm.com> Message-ID: <64505666-8a1f-cf64-7067-4b2dd53b0b40@arm.com> Date: Mon, 25 Mar 2019 20:04:54 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <1552984243-7689-8-git-send-email-amit.kachhap@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/03/2019 08:30, Amit Daniel Kachhap wrote: > From: Mark Rutland > > When pointer authentication is supported, a guest may wish to use it. > This patch adds the necessary KVM infrastructure for this to work, with > a semi-lazy context switch of the pointer auth state. > > Pointer authentication feature is only enabled when VHE is built > in the kernel and present in the CPU implementation so only VHE code > paths are modified. > > When we schedule a vcpu, we disable guest usage of pointer > authentication instructions and accesses to the keys. While these are > disabled, we avoid context-switching the keys. When we trap the guest > trying to use pointer authentication functionality, we change to eagerly > context-switching the keys, and enable the feature. The next time the > vcpu is scheduled out/in, we start again. However the host key save is > optimized and implemented inside ptrauth instruction/register access > trap. > > Pointer authentication consists of address authentication and generic > authentication, and CPUs in a system might have varied support for > either. Where support for either feature is not uniform, it is hidden > from guests via ID register emulation, as a result of the cpufeature > framework in the host. > > Unfortunately, address authentication and generic authentication cannot > be trapped separately, as the architecture provides a single EL2 trap > covering both. If we wish to expose one without the other, we cannot > prevent a (badly-written) guest from intermittently using a feature > which is not uniformly supported (when scheduled on a physical CPU which > supports the relevant feature). Hence, this patch expects both type of > authentication to be present in a cpu. > > This switch of key is done from guest enter/exit assembly as preperation > for the upcoming in-kernel pointer authentication support. Hence, these > key switching routines are not implemented in C code as they may cause > pointer authentication key signing error in some situations. > > Signed-off-by: Mark Rutland > [Only VHE, key switch in full assembly, vcpu_has_ptrauth checks > , save host key in ptrauth exception trap] > Signed-off-by: Amit Daniel Kachhap > Reviewed-by: Julien Thierry > Cc: Marc Zyngier > Cc: Christoffer Dall > Cc: kvmarm@lists.cs.columbia.edu [...] > +/* SPDX-License-Identifier: GPL-2.0 > + * arch/arm64/include/asm/kvm_ptrauth_asm.h: Guest/host ptrauth save/restore > + * Copyright 2019 Arm Limited > + * Author: Mark Rutland > + * Amit Daniel Kachhap > + */ I think the license needs to be in its own comment, like /* SPDX-License-Identifier: GPL-2.0 */ /* arch/arm64/include/asm/kvm_ptrauth_asm.h: ... * ... */ > + > +#ifndef __ASM_KVM_ASM_PTRAUTH_H > +#define __ASM_KVM_ASM_PTRAUTH_H __ASM_KVM_PTRAUTH_ASM_H ? (to match the file name) > + if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) || > + test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features)) { > + /* Verify that KVM startup matches the conditions for ptrauth */ > + if (WARN_ON(!vcpu_has_ptrauth(vcpu))) > + return -EINVAL; > + } I think this now needs to have "goto out;" instead of "return -EINVAL;", since 5.1-rcX contains commit e761a927bc9a ("KVM: arm/arm64: Reset the VCPU without preemption and vcpu state loaded") which changed some of this code. > @@ -385,6 +385,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > vcpu_clear_wfe_traps(vcpu); > else > vcpu_set_wfe_traps(vcpu); > + > + kvm_arm_vcpu_ptrauth_setup_lazy(vcpu); This version of the series seems to have lost the arch/arm/ definition of kvm_arm_vcpu_ptrauth_setup_lazy (previously kvm_arm_vcpu_ptrauth_reset), so KVM no longer compiles for arch/arm/ :( Thanks, Kristina