Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7328030imu; Thu, 31 Jan 2019 08:27:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN4KHz0jRnRobi57r6uOLScaCtk36YmSdjEu33UkNnrmLgSOR6DaJSp1O4qbkcTFgxNW+S8T X-Received: by 2002:a63:4f5e:: with SMTP id p30mr32009755pgl.71.1548952072706; Thu, 31 Jan 2019 08:27:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548952072; cv=none; d=google.com; s=arc-20160816; b=ZuX1VQ8On+VGHao51czPcbujqr1xZ4i+HTF/XMabFGqXnRiK0hb0JU6JYTsZ41IYZQ 4usGUkDl6U62bXOqgAlv2Rs4RClk5jcalpXbbnkPyFyeMJ9dy8IafH57u8Cf4RlN8wzC 7utmlIBCq7Fjltck7ABVwOl+6SwOGX96GJEzcqGVgU35mfPqG0vuj+S2m7nfp2fqRfpI vOl44cAFT4RJFTpgvTXTPzBBbUKNAUAQDPNy28Uyt/MhBqFD9dnlJmsWW0WNlr0OAf/O 7zF4v9YNVC1rQjeHD6F+pmkFwJAp6VP9PAsz+oaj2dntbOIq1QPvg+bnCruoHY4WrFM2 JfGA== 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:from:references:cc:to:subject; bh=1rOkh6gco64T8xQJ3vUeSyKE/DjvdgTL2kcBmfjuqbI=; b=F3Qo4rNzh0IIvHB7LlLkl7lz967eC7tbgYxKj5+LYgbRgAEGczCc1FKPBzFhPoUZBk j2tfmPZhibp2yju59FP2+9kJRDBcJQqsH/Wf/aYY0PJ8prWgktoU5gnNGkjJPAhG4GDu K3f2bEVW4GU4QXRKGcOBL+xIEDes6wJrcD5BCNsg8i14e31uV1TbFvY9qeeGTugFBl+d TA4MqTrtOgVJ73rw+t+zVTiubfjYOHaNGsxHUL3IyVSVYggx8yJCcOerGPfUJytEeLjM zZm2IUX5NDNldMIN6Y78OcMCCr0TnFjIZBbNPSu+a716OV6Dmp/s8WtR7oZGuD+Znoh6 X5RA== 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 p15si157606plq.24.2019.01.31.08.27.36; Thu, 31 Jan 2019 08:27:52 -0800 (PST) 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 S2388304AbfAaQ12 (ORCPT + 99 others); Thu, 31 Jan 2019 11:27:28 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47504 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731284AbfAaQ11 (ORCPT ); Thu, 31 Jan 2019 11:27:27 -0500 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 12B7880D; Thu, 31 Jan 2019 08:27:27 -0800 (PST) Received: from [10.1.196.105] (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 654133F557; Thu, 31 Jan 2019 08:27:25 -0800 (PST) Subject: Re: [PATCH v5 4/5] arm64/kvm: add a userspace option to enable pointer authentication To: Amit Daniel Kachhap Cc: linux-arm-kernel@lists.infradead.org, Marc Zyngier , Catalin Marinas , Will Deacon , Kristina Martsenko , kvmarm@lists.cs.columbia.edu, Ramana Radhakrishnan , Dave Martin , linux-kernel@vger.kernel.org References: <1548658727-14271-1-git-send-email-amit.kachhap@arm.com> <1548658727-14271-5-git-send-email-amit.kachhap@arm.com> From: James Morse Message-ID: <1e3f2a9a-e3f7-bb06-495a-24f77a73cae0@arm.com> Date: Thu, 31 Jan 2019 16:27:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1548658727-14271-5-git-send-email-amit.kachhap@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Amit, On 28/01/2019 06:58, Amit Daniel Kachhap wrote: > This feature will allow the KVM guest to allow the handling of > pointer authentication instructions or to treat them as undefined > if not set. It uses the existing vcpu API KVM_ARM_VCPU_INIT to > supply this parameter instead of creating a new API. > > A new register is not created to pass this parameter via > SET/GET_ONE_REG interface as just a flag (KVM_ARM_VCPU_PTRAUTH) > supplied is enough to enable this feature. > diff --git a/Documentation/arm64/pointer-authentication.txt b/Documentation/arm64/pointer-authentication.txt > index a25cd21..0529a7d 100644 > --- a/Documentation/arm64/pointer-authentication.txt > +++ b/Documentation/arm64/pointer-authentication.txt > @@ -82,7 +82,8 @@ pointers). > Virtualization > -------------- > > -Pointer authentication is not currently supported in KVM guests. KVM > -will mask the feature bits from ID_AA64ISAR1_EL1, and attempted use of > -the feature will result in an UNDEFINED exception being injected into > -the guest. > +Pointer authentication is enabled in KVM guest when virtual machine is > +created by passing a flag (KVM_ARM_VCPU_PTRAUTH) Isn't that a VCPU flag? Shouldn't this be when each VCPU is created? > requesting this feature > +to be enabled. Without this flag, pointer authentication is not enabled > +in KVM guests and attempted use of the feature will result in an UNDEFINED > +exception being injected into the guest. ... what happens if KVM's user-space enables ptrauth on some vcpus, but not on others? You removed the id-register suppression in the previous patch, but it doesn't get hooked up to kvm_arm_vcpu_ptrauth_allowed() here. (you could add kvm_arm_vcpu_ptrauth_allowed() earlier, and default it to true to make it easier). Doesn't this mean that if the CPU supports pointer auth, but user-space doesn't specify this flag, the guest gets mysterious undef's whenever it tries to use the advertised feature? (whether we support big/little virtual-machines is probably a separate issue, but the id registers need to be consistent with our trap-and-undef behaviour) > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index c798d0c..4a6ec40 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -453,14 +453,15 @@ static inline bool kvm_arch_requires_vhe(void) > > void kvm_arm_vcpu_ptrauth_enable(struct kvm_vcpu *vcpu); > void kvm_arm_vcpu_ptrauth_disable(struct kvm_vcpu *vcpu); > +bool kvm_arm_vcpu_ptrauth_allowed(struct kvm_vcpu *vcpu); > > static inline void kvm_arm_vcpu_ptrauth_reset(struct kvm_vcpu *vcpu) > { > /* Disable ptrauth and use it in a lazy context via traps */ > - if (has_vhe() && kvm_supports_ptrauth()) > + if (has_vhe() && kvm_supports_ptrauth() > + && kvm_arm_vcpu_ptrauth_allowed(vcpu)) > kvm_arm_vcpu_ptrauth_disable(vcpu); > } > - > void kvm_arm_vcpu_ptrauth_trap(struct kvm_vcpu *vcpu); > > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > index 5b980e7..c0e5dcd 100644 > --- a/arch/arm64/kvm/handle_exit.c > +++ b/arch/arm64/kvm/handle_exit.c > @@ -179,7 +179,8 @@ static int handle_sve(struct kvm_vcpu *vcpu, struct kvm_run *run) > */ > void kvm_arm_vcpu_ptrauth_trap(struct kvm_vcpu *vcpu) > { > - if (has_vhe() && kvm_supports_ptrauth()) > + if (has_vhe() && kvm_supports_ptrauth() > + && kvm_arm_vcpu_ptrauth_allowed(vcpu)) Duplication. If has_vhe() moved into kvm_supports_ptrauth(), and kvm_supports_ptrauth() was called from kvm_arm_vcpu_ptrauth_allowed() it would be clearer that use of this feature was becoming user-controlled policy. (We don't need to list the dependencies at every call site) > diff --git a/arch/arm64/kvm/hyp/ptrauth-sr.c b/arch/arm64/kvm/hyp/ptrauth-sr.c > index 0576c01..369624f 100644 > --- a/arch/arm64/kvm/hyp/ptrauth-sr.c > +++ b/arch/arm64/kvm/hyp/ptrauth-sr.c > @@ -42,3 +42,16 @@ void __no_ptrauth __hyp_text __ptrauth_switch_to_host(struct kvm_vcpu *vcpu, > ptrauth_keys_store((struct ptrauth_keys *) &guest_ctxt->sys_regs[APIAKEYLO_EL1]); > ptrauth_keys_switch((struct ptrauth_keys *) &host_ctxt->sys_regs[APIAKEYLO_EL1]); > } > + > +/** > + * kvm_arm_vcpu_ptrauth_allowed - checks if ptrauth feature is present in vcpu ('enabled by KVM's user-space' may be clearer. 'Present in vcpu' could be down to a cpufeature thing) > + * > + * @vcpu: The VCPU pointer > + * > + * This function will be used to enable/disable ptrauth in guest as configured ... but it just tests the bit ... > + * by the KVM userspace API. > + */ > +bool kvm_arm_vcpu_ptrauth_allowed(struct kvm_vcpu *vcpu) > +{ > + return test_bit(KVM_ARM_VCPU_PTRAUTH, vcpu->arch.features); > +} Thanks, James