From patchwork Fri Aug 25 09:53:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 9921639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 73E4D60349 for ; Fri, 25 Aug 2017 09:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63479269DA for ; Fri, 25 Aug 2017 09:53:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57ECA27F88; Fri, 25 Aug 2017 09:53:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB5C727EE2 for ; Fri, 25 Aug 2017 09:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754666AbdHYJxp (ORCPT ); Fri, 25 Aug 2017 05:53:45 -0400 Received: from ozlabs.org ([103.22.144.67]:43753 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754535AbdHYJxo (ORCPT ); Fri, 25 Aug 2017 05:53:44 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 3xdxLt6Gldz9sPm; Fri, 25 Aug 2017 19:53:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1503654822; bh=cs/2S4Pzi/OydJmmTiYyYuFKIQjSunvESJWtxODkTso=; h=Date:From:To:Cc:Subject:From; b=dhKIAYIMZlsrb/+RyyCMMldTmUxOtziC8mzvifYY71nLmtOBLwu+JUvqARvd2jRwb aUwpHerOtnbP8eFDhHCuxzxPjF9xKSfalMD2tyc6zx99SWfqNqxIxV+SxmWuNpUobK 2jrMnWj2uLakJtd2jf/w5V2rgIdFEtzltYwk8/q7Xp+fnJf3pPHF+D227ptWPT6lPZ BlqeAZ1qdYW3OgpGBVml9obgG69ukJblt/WwymLp/hWBv2aQL2+xpbw1gs03BF0gOl Osv+LA7S+vBf1ym0PTBuF2pkEO45TSCa7gIYTwOcPSCRqB1xnjIaUk7N9BEAvw+WjW KphRoYDi0D7+Q== Date: Fri, 25 Aug 2017 19:53:39 +1000 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: David Gibson Subject: [PATCH] KVM: PPC: Book3S HV: Report storage key support to userspace Message-ID: <20170825095339.GC14035@fergus.ozlabs.ibm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds information about storage keys to the struct returned by the KVM_PPC_GET_SMMU_INFO ioctl. The new fields replace a pad field, which was zeroed by previous kernel versions. Thus userspace that knows about the new fields will see zeroes when running on an older kernel, indicating that storage keys are not supported. The size of the structure has not changed. The number of keys is hard-coded for the CPUs supported by HV KVM, which is just POWER7, POWER8 and POWER9. Signed-off-by: Paul Mackerras Reviewed-by: David Gibson --- This is intended to go in after Ram Pai's patch fixing the H_ENTER code to not drop the top two bits of the key field. arch/powerpc/kvm/book3s_hv.c | 8 ++++++++ include/uapi/linux/kvm.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 359c79c..3d9b661 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3325,6 +3325,14 @@ static int kvm_vm_ioctl_get_smmu_info_hv(struct kvm *kvm, if (radix_enabled()) return -EINVAL; + /* + * POWER7, POWER8 and POWER9 all support 32 storage keys for data. + * POWER7 doesn't support keys for instruction accesses, + * POWER8 and POWER9 do. + */ + info->data_keys = 32; + info->instr_keys = cpu_has_feature(CPU_FTR_ARCH_207S) ? 32 : 0; + info->flags = KVM_PPC_PAGE_SIZES_REAL; if (mmu_has_feature(MMU_FTR_1T_SEGMENT)) info->flags |= KVM_PPC_1T_SEGMENTS; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6cd63c1..8388875 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -711,7 +711,8 @@ struct kvm_ppc_one_seg_page_size { struct kvm_ppc_smmu_info { __u64 flags; __u32 slb_size; - __u32 pad; + __u16 data_keys; /* # storage keys supported for data */ + __u16 instr_keys; /* # storage keys supported for instructions */ struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ]; };