{"id":831054,"url":"http://patchwork.ozlabs.org/api/1.2/patches/831054/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20171027040833.3644-13-aneesh.kumar@linux.vnet.ibm.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/1.2/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<20171027040833.3644-13-aneesh.kumar@linux.vnet.ibm.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20171027040833.3644-13-aneesh.kumar@linux.vnet.ibm.com/","date":"2017-10-27T04:08:29","name":"[12/16] powerpc/kvm/hash: Implement HASH_BULK_REMOVE hcall","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"8e318d4d41981a638f027c7041771f051c30fea4","submitter":{"id":664,"url":"http://patchwork.ozlabs.org/api/1.2/people/664/?format=json","name":"Aneesh Kumar K.V","email":"aneesh.kumar@linux.vnet.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20171027040833.3644-13-aneesh.kumar@linux.vnet.ibm.com/mbox/","series":[{"id":10486,"url":"http://patchwork.ozlabs.org/api/1.2/series/10486/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=10486","date":"2017-10-27T04:08:17","name":"Remove hash page table slot tracking from linux PTE","version":1,"mbox":"http://patchwork.ozlabs.org/series/10486/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/831054/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/831054/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yNW5j4249z9t2d\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri, 27 Oct 2017 15:26:01 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yNW5j2yJ1zDsf7\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri, 27 Oct 2017 15:26:01 +1100 (AEDT)","from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com\n\t[148.163.156.1])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yNVl83Sm9zDrcm\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tFri, 27 Oct 2017 15:09:56 +1100 (AEDT)","from pps.filterd (m0098399.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9R492YT091648\n\tfor <linuxppc-dev@lists.ozlabs.org>; Fri, 27 Oct 2017 00:09:54 -0400","from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2duvcejqt2-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Fri, 27 Oct 2017 00:09:54 -0400","from localhost\n\tby e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from\n\t<aneesh.kumar@linux.vnet.ibm.com>; Thu, 26 Oct 2017 22:09:53 -0600","from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19)\n\tby e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tThu, 26 Oct 2017 22:09:50 -0600","from b03ledav001.gho.boulder.ibm.com\n\t(b03ledav001.gho.boulder.ibm.com [9.17.130.232])\n\tby b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9R49o9K64880756; Thu, 26 Oct 2017 21:09:50 -0700","from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 3947E6E121;\n\tThu, 26 Oct 2017 22:09:50 -0600 (MDT)","from skywalker.ibmmodules.com (unknown [9.85.199.61])\n\tby b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 306016E175;\n\tThu, 26 Oct 2017 22:09:45 -0600 (MDT)"],"Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com\n\t(client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=aneesh.kumar@linux.vnet.ibm.com; receiver=<UNKNOWN>)","From":"\"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>","To":"benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au","Subject":"[PATCH 12/16] powerpc/kvm/hash: Implement HASH_BULK_REMOVE hcall","Date":"Fri, 27 Oct 2017 09:38:29 +0530","X-Mailer":"git-send-email 2.13.6","In-Reply-To":"<20171027040833.3644-1-aneesh.kumar@linux.vnet.ibm.com>","References":"<20171027040833.3644-1-aneesh.kumar@linux.vnet.ibm.com>","X-TM-AS-GCONF":"00","x-cbid":"17102704-0004-0000-0000-0000131F722E","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007958; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000239; SDB=6.00937034; UDB=6.00472246;\n\tIPR=6.00717297; \n\tBA=6.00005660; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009;\n\tZB=6.00000000; \n\tZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017735;\n\tXFM=3.00000015; UTC=2017-10-27 04:09:52","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17102704-0005-0000-0000-000084A29FA0","Message-Id":"<20171027040833.3644-13-aneesh.kumar@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-27_02:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tpriorityscore=1501\n\tmalwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0\n\tclxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0\n\tclassifier=spam adjust=0 reason=mlx scancount=1\n\tengine=8.0.1-1707230000\n\tdefinitions=main-1710270053","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"linuxppc-dev@lists.ozlabs.org,\n\t\"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"},"content":"This is equivalent to H_BULK_REMOVE hcall, but then takes hash value as the arg\ninstead of hashpte slot number. We will use this later to speed up bulk remove\noperation in guest. Instead of finding slot number using H_READ4 hcall, we can\nuse hash value directly using this hcall.\n\nonly support H_AVPN operation\n\nSigned-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>\n---\n arch/powerpc/include/asm/book3s/64/mmu-hash.h |  2 +\n arch/powerpc/include/asm/hvcall.h             |  3 +-\n arch/powerpc/kvm/book3s_hv.c                  |  1 +\n arch/powerpc/kvm/book3s_hv_rm_mmu.c           | 95 +++++++++++++++++++++++++++\n arch/powerpc/kvm/book3s_hv_rmhandlers.S       |  1 +\n 5 files changed, 101 insertions(+), 1 deletion(-)","diff":"diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h b/arch/powerpc/include/asm/book3s/64/mmu-hash.h\nindex 8b1d924a2f85..c24157fa200c 100644\n--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h\n+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h\n@@ -68,6 +68,8 @@\n  */\n \n #define HPTES_PER_GROUP 8\n+/* ISA defines max HTAB SIZE bits 46 */\n+#define MAX_HTAB_MASK ((1UL << 46) - 1)\n \n #define HPTE_V_SSIZE_SHIFT\t62\n #define HPTE_V_AVPN_SHIFT\t7\ndiff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h\nindex 725d4fadec82..c4feb950dd9f 100644\n--- a/arch/powerpc/include/asm/hvcall.h\n+++ b/arch/powerpc/include/asm/hvcall.h\n@@ -293,7 +293,8 @@\n #define H_INT_RESET             0x3D0\n #define H_HASH_REMOVE\t\t0x3D4\n #define H_HASH_PROTECT\t\t0x3D8\n-#define MAX_HCALL_OPCODE\tH_HASH_PROTECT\n+#define H_HASH_BULK_REMOVE\t0x3DC\n+#define MAX_HCALL_OPCODE\tH_HASH_BULK_REMOVE\n \n /* H_VIOCTL functions */\n #define H_GET_VIOA_DUMP_SIZE\t0x01\ndiff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c\nindex 822e91ba1dbe..9c6db0cb8a1c 100644\n--- a/arch/powerpc/kvm/book3s_hv.c\n+++ b/arch/powerpc/kvm/book3s_hv.c\n@@ -4173,6 +4173,7 @@ static unsigned int default_hcall_list[] = {\n #endif\n \tH_HASH_PROTECT,\n \tH_HASH_REMOVE,\n+\tH_HASH_BULK_REMOVE,\n \t0\n };\n \ndiff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c\nindex d6782fab2584..24668e499a01 100644\n--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c\n+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c\n@@ -752,6 +752,101 @@ long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu)\n \treturn ret;\n }\n \n+long kvmppc_h_hash_bulk_remove(struct kvm_vcpu *vcpu)\n+{\n+\tstruct kvm *kvm = vcpu->kvm;\n+\tunsigned long *args = &vcpu->arch.gpr[4];\n+\t__be64 *hp, *hptes[4];\n+\tunsigned long tlbrb[4];\n+\tlong int i, j, k, n, pte_index[4];\n+\tunsigned long flags, req, hash, rcbits;\n+\tint global;\n+\tlong int ret = H_SUCCESS;\n+\tstruct revmap_entry *rev, *revs[4];\n+\tu64 hp0, hp1;\n+\n+\tif (kvm_is_radix(kvm))\n+\t\treturn H_FUNCTION;\n+\n+\tglobal = global_invalidates(kvm);\n+\tfor (i = 0; i < 4 && ret == H_SUCCESS; ) {\n+\t\tn = 0;\n+\t\tfor (; i < 4; ++i) {\n+\t\t\tj = i * 2;\n+\t\t\thash = args[j];\n+\t\t\tflags = hash >> 56;\n+\t\t\thash &= ((1ul << 56) - 1);\n+\t\t\treq = flags >> 6;\n+\t\t\tflags &= 3;\n+\t\t\tif (req == 3) {\t\t/* no more requests */\n+\t\t\t\ti = 4;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\t/* only support avpn flag */\n+\t\t\tif (req != 1 || flags != 2) {\n+\t\t\t\t/* parameter error */\n+\t\t\t\targs[j] = ((0xa0 | flags) << 56) + hash;\n+\t\t\t\tret = H_PARAMETER;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\t/*\n+\t\t\t * We wait here to take lock for all hash values\n+\t\t\t * FIXME!! will that deadlock ?\n+\t\t\t */\n+\t\t\thp = kvmppc_find_hpte_slot(kvm, hash,\n+\t\t\t\t\t\t   args[j + 1], &pte_index[n]);\n+\t\t\tif (!hp) {\n+\t\t\t\targs[j] = ((0x90 | flags) << 56) + hash;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\thp0 = be64_to_cpu(hp[0]);\n+\t\t\thp1 = be64_to_cpu(hp[1]);\n+\t\t\tif (cpu_has_feature(CPU_FTR_ARCH_300)) {\n+\t\t\t\thp0 = hpte_new_to_old_v(hp0, hp1);\n+\t\t\t\thp1 = hpte_new_to_old_r(hp1);\n+\t\t\t}\n+\t\t\targs[j] = ((0x80 | flags) << 56) + hash;\n+\t\t\trev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index[n]]);\n+\t\t\tnote_hpte_modification(kvm, rev);\n+\n+\t\t\tif (!(hp0 & HPTE_V_VALID)) {\n+\t\t\t\t/* insert R and C bits from PTE */\n+\t\t\t\trcbits = rev->guest_rpte & (HPTE_R_R|HPTE_R_C);\n+\t\t\t\targs[j] |= rcbits << (56 - 5);\n+\t\t\t\thp[0] = 0;\n+\t\t\t\tif (is_mmio_hpte(hp0, hp1))\n+\t\t\t\t\tatomic64_inc(&kvm->arch.mmio_update);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\t/* leave it locked */\n+\t\t\thp[0] &= ~cpu_to_be64(HPTE_V_VALID);\n+\t\t\ttlbrb[n] = compute_tlbie_rb(hp0, hp1, pte_index[n]);\n+\t\t\thptes[n] = hp;\n+\t\t\trevs[n] = rev;\n+\t\t\t++n;\n+\t\t}\n+\n+\t\tif (!n)\n+\t\t\tbreak;\n+\n+\t\t/* Now that we've collected a batch, do the tlbies */\n+\t\tdo_tlbies(kvm, tlbrb, n, global, true);\n+\n+\t\t/* Read PTE low words after tlbie to get final R/C values */\n+\t\tfor (k = 0; k < n; ++k) {\n+\t\t\thp = hptes[k];\n+\t\t\trev = revs[k];\n+\t\t\tremove_revmap_chain(kvm, pte_index[k], rev,\n+\t\t\t\tbe64_to_cpu(hp[0]), be64_to_cpu(hp[1]));\n+\t\t\trcbits = rev->guest_rpte & (HPTE_R_R|HPTE_R_C);\n+\t\t\targs[j] |= rcbits << (56 - 5);\n+\t\t\t__unlock_hpte(hp, 0);\n+\t\t}\n+\t}\n+\n+\treturn ret;\n+}\n+\n long __kvmppc_do_hash_protect(struct kvm *kvm, __be64 *hpte,\n \t\t\t      unsigned long flags, unsigned long pte_index)\n {\ndiff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S\nindex 8e190eb8b26d..c2fe9851f4dc 100644\n--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S\n+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S\n@@ -2378,6 +2378,7 @@ hcall_real_table:\n \t.space\t((H_HASH_REMOVE - 4) - H_RANDOM), 0\n \t.long\tDOTSYM(kvmppc_h_hash_remove) - hcall_real_table\n \t.long\tDOTSYM(kvmppc_h_hash_protect) - hcall_real_table\n+\t.long\tDOTSYM(kvmppc_h_hash_bulk_remove) - hcall_real_table\n \t.globl\thcall_real_table_end\n hcall_real_table_end:\n \n","prefixes":["12/16"]}