Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp550302imu; Wed, 9 Jan 2019 02:16:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN5ilC95XvH6PcvXEKJ2pQcrUlTUTfv3qroT9TpZc82r6avwgvjPJsXRPpMf74RecPO3JMq2 X-Received: by 2002:a62:5486:: with SMTP id i128mr5214799pfb.215.1547028978666; Wed, 09 Jan 2019 02:16:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547028978; cv=none; d=google.com; s=arc-20160816; b=MK4ZTngNDezbP+9atWZ/TjC3uAXZtKuzI6XAUnGeMR84kzJN6jZQ73wcn29Ot7TFEc jxxfzJcNObBHpzANzUfdchjrvEFfiOxDVPpTobHjmsx+t8QdCtx3i1lw3dsKTmUp2jeY o7rED444gYXhPgNIGdZtFCfoKXSlVrUB+JrdwYEMG8d5BNSwQGTXJ3xPHPGRFDmdMxAk otMMyMrdENvZLBWwnFgx36nngMtwfsnR5rFgopZ/maF78776sJjTgVaqHP22aWdvqncC /FbQ/6bikweL6wC76eu4Y+XPvqgYfKNS+unxffNdgCduib7wewQAuIf3YuoMkU8e37PE 41Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=c5e7uEwQ7kViD8TT2MLtxA9UmIYrPj+o79zc1IYuEQA=; b=YreT2DlBHkWZgIHpmfRYAXvjFqwkmAWl4+cORKoA1pSo+1Cm2k1kNjUI4UIDTvUiSQ cNU70q2FtbTxeNqtAnHvnFdwjoFjn1UnRcNdR0vgBG1J3ZzGPvryK5zizwjhrzq0xKO8 zyfZxcl8MzCExGtv9kngI6glYh9ZGsXX7pe2h9itwgslMWn2Z41kE7cu8qzRShGh8+4e /oDGJm6Oiwhr5lUlHANXlLfv3DyqhtPGyvIq28tzFq6fTjUm6xQo9zKCvHqTGc7q6tki OeLi1Hvtykrl3m47Z4qM4o81xz0Xvy5ohe31HinBxXTn2c+4PoM7SulNtBlJ8gPuYHAN 06VA== 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 c81si13099889pfc.82.2019.01.09.02.16.03; Wed, 09 Jan 2019 02:16:18 -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 S1730336AbfAIKOD (ORCPT + 99 others); Wed, 9 Jan 2019 05:14:03 -0500 Received: from foss.arm.com ([217.140.101.70]:40130 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730314AbfAIKOC (ORCPT ); Wed, 9 Jan 2019 05:14:02 -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 7071B80D for ; Wed, 9 Jan 2019 02:14:02 -0800 (PST) Received: from mail-io1-f53.google.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5496D3F70D for ; Wed, 9 Jan 2019 02:14:02 -0800 (PST) Received: by mail-io1-f53.google.com with SMTP id m19so5589911ioh.3 for ; Wed, 09 Jan 2019 02:14:02 -0800 (PST) X-Gm-Message-State: AJcUuke3sPYtypTMeqh2Wbj3HRpe/OT1gz5sEFV/Tgu6r/zR8dLa3/5P w7VxpEcLlrSo2pZUXZyLzWGAdBS+2qz7garB+38= X-Received: by 2002:a6b:b717:: with SMTP id h23mr3180991iof.14.1547028841575; Wed, 09 Jan 2019 02:14:01 -0800 (PST) MIME-Version: 1.0 References: <1545119810-12182-1-git-send-email-amit.kachhap@arm.com> <1545119810-12182-4-git-send-email-amit.kachhap@arm.com> <49474d5f-6f4e-b57d-4b45-94c16d85136c@arm.com> In-Reply-To: <49474d5f-6f4e-b57d-4b45-94c16d85136c@arm.com> From: Amit Daniel Kachhap Date: Wed, 9 Jan 2019 15:43:50 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 3/6] arm64/kvm: add a userspace option to enable pointer authentication To: James Morse Cc: LAK , Marc Zyngier , Catalin Marinas , Will Deacon , Kristina Martsenko , kvmarm@lists.cs.columbia.edu, Ramana Radhakrishnan , Dave Martin , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sat, Jan 5, 2019 at 12:05 AM James Morse wrote: > > Hi Amit, > > On 18/12/2018 07:56, 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 select this feature. > > What is the motivation for doing this? Doesn't ptrauth 'just' need turning on? > It doesn't need additional setup to be useable, or rely on some qemu support to > work properly. There isn't any hidden state that can't be migrated in the usual way. > Is it just because we don't want to commit to the ABI? This allows migration of guest to non pointer authenticated supported systems and hides the extra ptrauth registers. Basically this suggestion was given by Christoffer (https://lore.kernel.org/lkml/20180206123847.GY21802@cbox/). I don't have strong reservation to have this option and can be dropped if this doesn't make sense. > > > > diff --git a/Documentation/arm64/pointer-authentication.txt b/Documentation/arm64/pointer-authentication.txt > > index 5baca42..8c0f338 100644 > > --- a/Documentation/arm64/pointer-authentication.txt > > +++ b/Documentation/arm64/pointer-authentication.txt > > @@ -87,7 +87,8 @@ used to get and set the keys for a thread. > > 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) 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. > > > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > > index cd209f7..e20583a 100644 > > --- a/Documentation/virtual/kvm/api.txt > > +++ b/Documentation/virtual/kvm/api.txt > > @@ -2634,6 +2634,10 @@ Possible features: > > Depends on KVM_CAP_ARM_PSCI_0_2. > > - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU. > > Depends on KVM_CAP_ARM_PMU_V3. > > + - KVM_ARM_VCPU_PTRAUTH: Emulate Pointer authentication for the CPU. > > + Depends on KVM_CAP_ARM_PTRAUTH and only on arm64 architecture. If > > + set, then the KVM guest allows the execution of pointer authentication > > + instructions or treats them as undefined if not set. > > > diff --git a/arch/arm64/kvm/hyp/ptrauth-sr.c b/arch/arm64/kvm/hyp/ptrauth-sr.c > > index 1bfaf74..03999bb 100644 > > --- a/arch/arm64/kvm/hyp/ptrauth-sr.c > > +++ b/arch/arm64/kvm/hyp/ptrauth-sr.c > > @@ -71,3 +71,19 @@ void __hyp_text __ptrauth_switch_to_host(struct kvm_vcpu *vcpu, > > __ptrauth_save_state(guest_ctxt); > > __ptrauth_restore_state(host_ctxt); > > } > > + > > +/** > > + * kvm_arm_vcpu_ptrauth_allowed - checks if ptrauth feature is present in vcpu > > + * > > + * @vcpu: The VCPU pointer > > + * > > + * This function will be used to enable/disable ptrauth in guest as configured > > + * by the KVM userspace API. > > + */ > > +bool kvm_arm_vcpu_ptrauth_allowed(struct kvm_vcpu *vcpu) > > +{ > > + if (test_bit(KVM_ARM_VCPU_PTRAUTH, vcpu->arch.features)) > > + return true; > > + else > > + return false; > > +} > > Can't you return the result of test_bit() directly? ok. > > > Thanks, > > James //Amit