From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556862949; cv=none; d=zoho.com; s=zohoarc; b=Lji6qqjhezCMY3RxDgVl+69MFHdWPZyxkL4+4HYsWPaTDWSt/X6llMmIQWtiU3gsKZ2KqPNA4GnXWrVHpohaTzpRim5RYzxoCuJKPWyF1vC035+orZbVi5GIseYWe3qNFi24jecroMY7b/d8DOKo7oUYUG7isAGZViTyawy5fa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556862949; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=XkCV3eLxqyBlikFgPtJ27XXNEcQJUOtpk+hewO4Cx4s=; b=EivR394ZEefM6J+O+qAj19t5Z4MxdAy4JuHq+ZXQC6kNSenks1/eVt8X4ROnPWas53YF5youeA+CbL4Sl1utxnAvMKPfmT8DTJwW2bqrq5tY/gwT2xH9qCFaka18rGIdjFMfSXCe/cKrTT/dqPsx8UJjQo3jyftVVBtXuzxDTZU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556862949628594.5793507042383; Thu, 2 May 2019 22:55:49 -0700 (PDT) Received: from localhost ([127.0.0.1]:34944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRAZ-0006CR-Bi for importer@patchew.org; Fri, 03 May 2019 01:55:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR8l-00054v-9Z for qemu-devel@nongnu.org; Fri, 03 May 2019 01:53:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR8j-0002nZ-VC for qemu-devel@nongnu.org; Fri, 03 May 2019 01:53:47 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:34528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR8i-0002mb-LR; Fri, 03 May 2019 01:53:45 -0400 Received: by mail-pl1-x642.google.com with SMTP id ck18so2191449plb.1; Thu, 02 May 2019 22:53:44 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.53.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XkCV3eLxqyBlikFgPtJ27XXNEcQJUOtpk+hewO4Cx4s=; b=kCX3enejx7PdantJYDPknyfvc7AVOwr/P6XPSajQAGbrmsGpSbIPmhe6zxv4IbQHQw pXbggSCaaCEgGP1qU1fOzq1fJomKtU+drMz6FiqRUqwemRPnbUg+6tq+YdaQSiT0GsXj KNfZJ73cOGEH3otTUz80Zk2Th7rIk1eR+DFPXCEAB18J/Oy5zbLNup3lrmJLg1mZORtB xXulI3yKHgAJPR8fGrskj5M20QN8wLfxXeXmqzJBYP2fbl308wl56j5rclRVdomkamLe alIl4ZTJsPfTY8wHdysnGQsIQMarqJGhxKE69s79UTW9DALXlUAM15OLpUJwow9SBAsm TOkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XkCV3eLxqyBlikFgPtJ27XXNEcQJUOtpk+hewO4Cx4s=; b=f8PANXNRKYAzdQLeXSxQ0wRs1OiBJyHEU7TvLygaPeAFWGVRjz1zt0fKQGfo6pO/j9 N2e3hXecZAWA0GqACNZIX/KajS3ct7qDI7sGOKC4vzF/g9e5TJGAIikzN03clnq4bMm3 IuEs6FyoBNIn+skGIhmvfDPYexX6kR34EOgRijd6LFuNjg+OCk+mHh21FhgtnOCIC6+w hvP5PgLD5QMQa1RUxkPEQbOuVXkTZ0+Y24hTa0ztJSZdTkd4Uc2xumBTIeIZxv2wMkv5 yg4KaCrIag1MfSXu67xMc0XlYH5GpZci+cQE45JmCYs2GFozmbCimCTInEKiKa2uAiCe Ta/A== X-Gm-Message-State: APjAAAU9xkqVSadCz7imA72gho5b6SQEHQeQ7heyPoTn5ThJvndEQAka hysumvw7iIvgb15YYHOb+j47aSJn+78= X-Google-Smtp-Source: APXvYqx7Fydcr5rifxG32JbrejJsjyCE3oqSWnLzqvx7pN/wcSgkr/MMheEc4GHfEUfElv7KYLC55g== X-Received: by 2002:a17:902:704c:: with SMTP id h12mr8096746plt.270.1556862823206; Thu, 02 May 2019 22:53:43 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:04 +1000 Message-Id: <20190503055316.6441-2-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 01/13] target/ppc: Implement the VTB for HV access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The virtual timebase register (VTB) is a 64-bit register which increments at the same rate as the timebase register, present on POWER8 and later processors. The register is able to be read/written by the hypervisor and read by the supervisor. All other accesses are illegal. Currently the VTB is just an alias for the timebase (TB) register. Implement the VTB so that is can be read/written independent of the TB. Make use of the existing method for accessing timebase facilities where by the compensation is stored and used to compute the value on reads/is updated on writes. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/ppc.c | 16 ++++++++++++++++ include/hw/ppc/ppc.h | 1 + linux-user/ppc/cpu_loop.c | 5 +++++ target/ppc/cpu.h | 2 ++ target/ppc/helper.h | 2 ++ target/ppc/timebase_helper.c | 10 ++++++++++ target/ppc/translate_init.inc.c | 19 +++++++++++++++---- 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index b2ff99ec66..a57ca64626 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -694,6 +694,22 @@ void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t va= lue) &tb_env->atb_offset, ((uint64_t)value << 32) | tb); } =20 +uint64_t cpu_ppc_load_vtb(CPUPPCState *env) +{ + ppc_tb_t *tb_env =3D env->tb_env; + + return cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->vtb_offset); +} + +void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t value) +{ + ppc_tb_t *tb_env =3D env->tb_env; + + cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + &tb_env->vtb_offset, value); +} + static void cpu_ppc_tb_stop (CPUPPCState *env) { ppc_tb_t *tb_env =3D env->tb_env; diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h index 4bdcb8bacd..205150e6b4 100644 --- a/include/hw/ppc/ppc.h +++ b/include/hw/ppc/ppc.h @@ -23,6 +23,7 @@ struct ppc_tb_t { /* Time base management */ int64_t tb_offset; /* Compensation */ int64_t atb_offset; /* Compensation */ + int64_t vtb_offset; uint32_t tb_freq; /* TB frequency */ /* Decrementer management */ uint64_t decr_next; /* Tick for next decr interrupt */ diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c index 801f5ace29..c715861804 100644 --- a/linux-user/ppc/cpu_loop.c +++ b/linux-user/ppc/cpu_loop.c @@ -46,6 +46,11 @@ uint32_t cpu_ppc_load_atbu(CPUPPCState *env) return cpu_ppc_get_tb(env) >> 32; } =20 +uint64_t cpu_ppc_load_vtb(CPUPPCState *env) +{ + return cpu_ppc_get_tb(env); +} + uint32_t cpu_ppc601_load_rtcu(CPUPPCState *env) __attribute__ (( alias ("cpu_ppc_load_tbu") )); =20 diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index fe93cf0555..70167bae22 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1327,6 +1327,8 @@ uint64_t cpu_ppc_load_atbl (CPUPPCState *env); uint32_t cpu_ppc_load_atbu (CPUPPCState *env); void cpu_ppc_store_atbl (CPUPPCState *env, uint32_t value); void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t value); +uint64_t cpu_ppc_load_vtb(CPUPPCState *env); +void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t value); bool ppc_decr_clear_on_delivery(CPUPPCState *env); target_ulong cpu_ppc_load_decr (CPUPPCState *env); void cpu_ppc_store_decr (CPUPPCState *env, target_ulong value); diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 69cbf7922f..3701bcbf1b 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -680,6 +680,7 @@ DEF_HELPER_FLAGS_1(load_tbl, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_1(load_tbu, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_1(load_atbl, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_1(load_atbu, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_FLAGS_1(load_vtb, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_1(load_601_rtcl, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env) #if !defined(CONFIG_USER_ONLY) @@ -700,6 +701,7 @@ DEF_HELPER_FLAGS_1(load_decr, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_decr, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_FLAGS_1(load_hdecr, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_hdecr, TCG_CALL_NO_RWG, void, env, tl) +DEF_HELPER_FLAGS_2(store_vtb, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_2(store_hid0_601, void, env, tl) DEF_HELPER_3(store_403_pbr, void, env, i32, tl) DEF_HELPER_FLAGS_1(load_40x_pit, TCG_CALL_NO_RWG, tl, env) diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c index 73363e08ae..8c3c2fe67c 100644 --- a/target/ppc/timebase_helper.c +++ b/target/ppc/timebase_helper.c @@ -45,6 +45,11 @@ target_ulong helper_load_atbu(CPUPPCState *env) return cpu_ppc_load_atbu(env); } =20 +target_ulong helper_load_vtb(CPUPPCState *env) +{ + return cpu_ppc_load_vtb(env); +} + #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) target_ulong helper_load_purr(CPUPPCState *env) { @@ -113,6 +118,11 @@ void helper_store_hdecr(CPUPPCState *env, target_ulong= val) cpu_ppc_store_hdecr(env, val); } =20 +void helper_store_vtb(CPUPPCState *env, target_ulong val) +{ + cpu_ppc_store_vtb(env, val); +} + target_ulong helper_load_40x_pit(CPUPPCState *env) { return load_40x_pit(env); diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index 0bd555eb19..e3f941800b 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -310,6 +310,16 @@ static void spr_write_hdecr(DisasContext *ctx, int spr= n, int gprn) } } =20 +static void spr_read_vtb(DisasContext *ctx, int gprn, int sprn) +{ + gen_helper_load_vtb(cpu_gpr[gprn], cpu_env); +} + +static void spr_write_vtb(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_vtb(cpu_env, cpu_gpr[gprn]); +} + #endif #endif =20 @@ -8133,10 +8143,11 @@ static void gen_spr_power8_ebb(CPUPPCState *env) /* Virtual Time Base */ static void gen_spr_vtb(CPUPPCState *env) { - spr_register_kvm(env, SPR_VTB, "VTB", - SPR_NOACCESS, SPR_NOACCESS, - &spr_read_tbl, SPR_NOACCESS, - KVM_REG_PPC_VTB, 0x00000000); + spr_register_kvm_hv(env, SPR_VTB, "VTB", + SPR_NOACCESS, SPR_NOACCESS, + &spr_read_vtb, SPR_NOACCESS, + &spr_read_vtb, &spr_write_vtb, + KVM_REG_PPC_VTB, 0x00000000); } =20 static void gen_spr_power8_fscr(CPUPPCState *env) --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863107; cv=none; d=zoho.com; s=zohoarc; b=cYmJb2Xzkk1htM4Bg03R7Crg9eMxLJevr8v/H6RiXOVv7mAPrY0qRzdedBs1yXR/hno3t6i5myUBL7w+1BpirCqHnWPTQu1Fxfc9j5bk2fmeFX32lK9ILK7oNsxrL6bzWMBe5C1pyBNikH0tvCX4gsuBREIw/kXy7MJxwphiVY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863107; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+U5Xv5nRQkdeJtYZNg9oFGARkmWbZ28i9pDdO6rteRQ=; b=nojWq5Rdp2sAb3Y//Hs3gj9DWqz45jFVdzL18mkTdea7E/EgP164RgJd/mbwMuvInMCiTgjJrT9M1nTahODa2BlH6DTSJJ2sKBNWXTlSIIB+vdXHwFQWvQu5ZBIvhu/3nX9V3guFtAdBg5ub1msjW7klcHtTiQBIAzMVZbM/45k= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863107905551.2990352850813; Thu, 2 May 2019 22:58:27 -0700 (PDT) Received: from localhost ([127.0.0.1]:35001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRDD-0000b2-Q8 for importer@patchew.org; Fri, 03 May 2019 01:58:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR8q-00058x-E9 for qemu-devel@nongnu.org; Fri, 03 May 2019 01:53:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR8o-0002qI-NI for qemu-devel@nongnu.org; Fri, 03 May 2019 01:53:52 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:43660) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR8o-0002pI-G7; Fri, 03 May 2019 01:53:50 -0400 Received: by mail-pf1-x443.google.com with SMTP id e67so2337905pfe.10; Thu, 02 May 2019 22:53:49 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.53.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+U5Xv5nRQkdeJtYZNg9oFGARkmWbZ28i9pDdO6rteRQ=; b=t9FlaSMipOT+6uSGxf9TYwmJELIZgFUFs0YxwrYbg1B6xhhfBnkBEpNCHWRa8reirh imrOU7R8cJUneks7QklLpGpBaoUoVUVKOc8RJuM/ZHcYvl9sJy+tmHvvbrYYIwz6JOXH rhF34px1PX/pUQvniZ8KkBqr9afP7dAoUk5BB3de4LAA3BV4dlrUKe6cR9VgxKy8zwD/ LnY3lYxNF4xSPAZrfcITZUCjrhgE2iBqAscV31/zTmD5MdDImBmDG0GFqe/T8NT+uStq mrk1GmSLzLIc9CqR5zqrlmGi095FPDrkRvjzrH7F1Et2pIIsZ4ZD2T9unbjWzFh8QDHM topg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+U5Xv5nRQkdeJtYZNg9oFGARkmWbZ28i9pDdO6rteRQ=; b=NYRCHJ9yKWLPLmCSljQcpoiOc55qy7kLVA4aSKTZZXsAydUJ8nPF/kuXf1X9tSCW6w rWJoshSkLyduG3fzalq/b7rvTzYwpzOYHaMCzKfFPrmuNyPklQrNQtfQoOQOmUQyR/Hx 1lDIH45DaDU569MDix+jlTZ7wc1cRuZeiWObPqU4gc7yj+7ttgSDGxqnD27QnZYE3Y0h otztYWBbyeoXRRA9cLU41KTlbqqNyZqcGPIgTHTJfnEXdZSyAFeEcNoIw+HsTFkBJCwk amnSK70/zaHk5ppZ4XtOIn1jN4oLasa1rUbkoVa/uxn6XzNRXtmWdBImNr2D/Sch7u6h kIiA== X-Gm-Message-State: APjAAAXGi0vG0jqQYfYrVz7AtsCRa6TluRpYcz1fxIQKDVlvG1ybTDFr JdxxKEgRJIAT5tsJ1VYeiPiMlQ1PZ+s= X-Google-Smtp-Source: APXvYqxamtQpx4WdxqMUxDiVtqsUN/lZj0pjTk5+9oopHAFXQy9Py1ftSz0Rzve53vVAmn2OCgwAKw== X-Received: by 2002:a63:4714:: with SMTP id u20mr8222472pga.316.1556862828574; Thu, 02 May 2019 22:53:48 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:05 +1000 Message-Id: <20190503055316.6441-3-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 02/13] target/ppc: Work [S]PURR implementation and add HV support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The Processor Utilisation of Resources Register (PURR) and Scaled Processor Utilisation of Resources Register (SPURR) provide an estimate of the resources used by the thread, present on POWER7 and later processors. Currently the [S]PURR registers simply count at the rate of the timebase. Preserve this behaviour but rework the implementation to store an offset like the timebase rather than doing the calculation manually. Also allow hypervisor write access to the register along with the currently available read access. Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson --- hw/ppc/ppc.c | 17 +++++++---------- include/hw/ppc/ppc.h | 3 +-- target/ppc/cpu.h | 1 + target/ppc/helper.h | 1 + target/ppc/timebase_helper.c | 5 +++++ target/ppc/translate_init.inc.c | 23 +++++++++++++++-------- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index a57ca64626..b567156f97 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -819,12 +819,9 @@ target_ulong cpu_ppc_load_hdecr (CPUPPCState *env) uint64_t cpu_ppc_load_purr (CPUPPCState *env) { ppc_tb_t *tb_env =3D env->tb_env; - uint64_t diff; =20 - diff =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - tb_env->purr_start; - - return tb_env->purr_load + - muldiv64(diff, tb_env->tb_freq, NANOSECONDS_PER_SECOND); + return cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->purr_offset); } =20 /* When decrementer expires, @@ -980,12 +977,12 @@ static void cpu_ppc_hdecr_cb(void *opaque) cpu_ppc_hdecr_excp(cpu); } =20 -static void cpu_ppc_store_purr(PowerPCCPU *cpu, uint64_t value) +void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value) { - ppc_tb_t *tb_env =3D cpu->env.tb_env; + ppc_tb_t *tb_env =3D env->tb_env; =20 - tb_env->purr_load =3D value; - tb_env->purr_start =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + &tb_env->purr_offset, value); } =20 static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq) @@ -1002,7 +999,7 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t= freq) */ _cpu_ppc_store_decr(cpu, 0xFFFFFFFF, 0xFFFFFFFF, 32); _cpu_ppc_store_hdecr(cpu, 0xFFFFFFFF, 0xFFFFFFFF, 32); - cpu_ppc_store_purr(cpu, 0x0000000000000000ULL); + cpu_ppc_store_purr(env, 0x0000000000000000ULL); } =20 static void timebase_save(PPCTimebase *tb) diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h index 205150e6b4..b09ffbf300 100644 --- a/include/hw/ppc/ppc.h +++ b/include/hw/ppc/ppc.h @@ -32,8 +32,7 @@ struct ppc_tb_t { /* Hypervisor decrementer management */ uint64_t hdecr_next; /* Tick for next hdecr interrupt */ QEMUTimer *hdecr_timer; - uint64_t purr_load; - uint64_t purr_start; + int64_t purr_offset; void *opaque; uint32_t flags; }; diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 70167bae22..19b3e1de0e 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1335,6 +1335,7 @@ void cpu_ppc_store_decr (CPUPPCState *env, target_ulo= ng value); target_ulong cpu_ppc_load_hdecr (CPUPPCState *env); void cpu_ppc_store_hdecr (CPUPPCState *env, target_ulong value); uint64_t cpu_ppc_load_purr (CPUPPCState *env); +void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value); uint32_t cpu_ppc601_load_rtcl (CPUPPCState *env); uint32_t cpu_ppc601_load_rtcu (CPUPPCState *env); #if !defined(CONFIG_USER_ONLY) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 3701bcbf1b..336e7802fb 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -686,6 +686,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, = env) #if !defined(CONFIG_USER_ONLY) #if defined(TARGET_PPC64) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_FLAGS_2(store_purr, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_2(store_ptcr, void, env, tl) #endif DEF_HELPER_2(store_sdr1, void, env, tl) diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c index 8c3c2fe67c..2395295b77 100644 --- a/target/ppc/timebase_helper.c +++ b/target/ppc/timebase_helper.c @@ -55,6 +55,11 @@ target_ulong helper_load_purr(CPUPPCState *env) { return (target_ulong)cpu_ppc_load_purr(env); } + +void helper_store_purr(CPUPPCState *env, target_ulong val) +{ + cpu_ppc_store_purr(env, val); +} #endif =20 target_ulong helper_load_601_rtcl(CPUPPCState *env) diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index e3f941800b..9cd33e79ef 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -285,6 +285,11 @@ static void spr_read_purr(DisasContext *ctx, int gprn,= int sprn) gen_helper_load_purr(cpu_gpr[gprn], cpu_env); } =20 +static void spr_write_purr(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_purr(cpu_env, cpu_gpr[gprn]); +} + /* HDECR */ static void spr_read_hdecr(DisasContext *ctx, int gprn, int sprn) { @@ -7972,14 +7977,16 @@ static void gen_spr_book3s_purr(CPUPPCState *env) { #if !defined(CONFIG_USER_ONLY) /* PURR & SPURR: Hack - treat these as aliases for the TB for now */ - spr_register_kvm(env, SPR_PURR, "PURR", - &spr_read_purr, SPR_NOACCESS, - &spr_read_purr, SPR_NOACCESS, - KVM_REG_PPC_PURR, 0x00000000); - spr_register_kvm(env, SPR_SPURR, "SPURR", - &spr_read_purr, SPR_NOACCESS, - &spr_read_purr, SPR_NOACCESS, - KVM_REG_PPC_SPURR, 0x00000000); + spr_register_kvm_hv(env, SPR_PURR, "PURR", + &spr_read_purr, SPR_NOACCESS, + &spr_read_purr, SPR_NOACCESS, + &spr_read_purr, &spr_write_purr, + KVM_REG_PPC_PURR, 0x00000000); + spr_register_kvm_hv(env, SPR_SPURR, "SPURR", + &spr_read_purr, SPR_NOACCESS, + &spr_read_purr, SPR_NOACCESS, + &spr_read_purr, &spr_write_purr, + KVM_REG_PPC_SPURR, 0x00000000); #endif } =20 --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556862962; cv=none; d=zoho.com; s=zohoarc; b=ZFxQf96iSX02dZZOh7AmCxGyA3dX5mO9nGZol5OowBZ2MAjjibJos/3gLp70r3DjXV85GEgiDMb0kdQ8vOeLyjY+9FBhljb3RKKhq+8UaHEY5nnTsmd/9K+Vzv842Ti3XVRlbF1uanHsJGJiWvcrPGFcXEUBfPH3V7OxHVRmqj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556862962; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=uTEnt+RwoXTMSi/BpLCLpLWRLd685MOhFLDweZ3zqHQ=; b=nV1VPGMr+1csO2ZWuHxElmcXNQiMBkdNvOO/Q7rO4oBB8zHwhgbEkblNXQV2wCJwBmc3fkVehMPw9EMCVX2Eg+836WOsdcCvmWHo3yMJWiD2d5FFvLpQnPaEL3Orx7IkkdN2Bqc8zif6DpLZz7gWafdYNQwDSmLYb1L0euEZPwE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556862962707308.6430459511994; Thu, 2 May 2019 22:56:02 -0700 (PDT) Received: from localhost ([127.0.0.1]:34957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRAp-0006UI-Hn for importer@patchew.org; Fri, 03 May 2019 01:55:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR8t-0005BW-9f for qemu-devel@nongnu.org; Fri, 03 May 2019 01:53:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR8s-0002rl-CR for qemu-devel@nongnu.org; Fri, 03 May 2019 01:53:55 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:33750) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR8r-0002rF-NE; Fri, 03 May 2019 01:53:53 -0400 Received: by mail-pl1-x641.google.com with SMTP id y3so2188555plp.0; Thu, 02 May 2019 22:53:53 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.53.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uTEnt+RwoXTMSi/BpLCLpLWRLd685MOhFLDweZ3zqHQ=; b=deu3rIMdLtquHaUSHxUqfqfcx2R4qmvGtDPO3T7n7VJO5ILXuxCPLWSPT5WUT5nymW uTn9lxC4AkuOAf8ugOF6jTXFMqGtOqSaMtjmWCM3EWUsy7W5xMgjyhS9m1TSKTc6ZGsC /UVvJ7DebhcX+rPXJ82mxuYcfA0Elij2Ax3F9xMH76b+F+tv05x9UjN7RXFz49yNmoRL s0hSz5nxIh+sKGq2ZtavJCW5I45x7CiYCjmIRIhvZeZpyoEOnnk53IFU6eu/hQhHxJAa dB6TGlurnSgRWULkXZqGY39OU1tSkojjsx294s+RfSf3ZYpDlkUXig5aJ61xMubnKZ9T rmJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uTEnt+RwoXTMSi/BpLCLpLWRLd685MOhFLDweZ3zqHQ=; b=kao0wAO4rQ52SavDYrIJCKzfeEBuhTNILfknVKz98hq3VgRAw/Xzja6QFkwyuFYdYv hUC6pMvMl9XqaoTLcMzgVqZKx29NXFj8iZBBp3zufqII2+soCbHms1rBpCbPkcVl+W03 TCiLXyDCSpNg3bpR0+txaT9mXQhJcVSKo4ntf1Cb0nHbmLCYRgjxbKl3q3gQ2c0TwyCz 6hc/yu18pYC/WSSIK28eH0vHng78vRhS6pOF2hEnPnV86UYNeOI5tF9is7VTDtU7t1lx 5r0QGGfLEDMpoTpZWS7zlw/uMmUk7BZnltW0VNqAf4h2u+J2xTWC8dhqjk4cRtHlWWv3 AkPQ== X-Gm-Message-State: APjAAAXi8ar8JW+hJ/3oNCU3iRxb7bJQ1WR4dqHCBf2Odsb7jPy0G5rZ tzJHQdZ6qy0/nRia3dElmMehbgG8keQ= X-Google-Smtp-Source: APXvYqzXKO2z5d17jS/s3LAplDet1MmTkrbaX1wDz5fqRMZWZCGcqX1czsq0bAQ+7P5sM96/syBycg== X-Received: by 2002:a17:902:76c5:: with SMTP id j5mr8137857plt.337.1556862832667; Thu, 02 May 2019 22:53:52 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:06 +1000 Message-Id: <20190503055316.6441-4-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 03/13] target/ppc: Add SPR ASDR X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The Access Segment Descriptor Register (ASDR) provides information about the storage element when taking a hypervisor storage interrupt. When performing nested radix address translation, this is normally the guest real address. This register is present on POWER9 processors and later. Implement the ADSR, note read and write access is limited to the hypervisor. Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson --- target/ppc/cpu.h | 1 + target/ppc/translate_init.inc.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 19b3e1de0e..8d66265e5a 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1797,6 +1797,7 @@ void ppc_compat_add_property(Object *obj, const char = *name, #define SPR_MPC_MD_DBRAM1 (0x32A) #define SPR_RCPU_L2U_RA3 (0x32B) #define SPR_TAR (0x32F) +#define SPR_ASDR (0x330) #define SPR_IC (0x350) #define SPR_VTB (0x351) #define SPR_MMCRC (0x353) diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index 9cd33e79ef..a0cae58e19 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -8243,6 +8243,12 @@ static void gen_spr_power9_mmu(CPUPPCState *env) SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_ptcr, KVM_REG_PPC_PTCR, 0x00000000); + /* Address Segment Descriptor Register */ + spr_register_hv(env, SPR_ASDR, "ASDR", + SPR_NOACCESS, SPR_NOACCESS, + SPR_NOACCESS, SPR_NOACCESS, + &spr_read_generic, &spr_write_generic, + 0x0000000000000000); #endif } =20 --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863118; cv=none; d=zoho.com; s=zohoarc; b=n5GbxHf5RPy4HpIyuSjIRKWRYvajIQ/FhQH4IHQorIzRD5F+ah0HQhGhpuzQwSjIVZtbJM6wXjLxAR8Gczksgk3KgyXG5ovKjtF7BduPKN6xlPClVQ4I1gSbb4gkeJFWSo8VRG6fZZULVK/ceiM2olFkumvVm1GPK90QE4UVwpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863118; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=tDDmbBxXcuGX6xPjl7n2FpWe9iGxr+XHYg3A3IEDeRE=; b=TO6iSpiFAk8I9uy93LZB17XaJArxcNIualvno0KlKmaJ9cSmizUbcfCFsZGvi5taU1GAAAW1QUG98J9CzFMk4jTANxwhXeSGkvFxisFjQPh2Sx0CQBE+fnXhLyn6lZhKfdWziEF6NJ0IcVC9kklKMZ3WhIIuxYldVJtEm05YFUc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863118235675.7342421492499; Thu, 2 May 2019 22:58:38 -0700 (PDT) Received: from localhost ([127.0.0.1]:35003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRDO-0000kQ-2D for importer@patchew.org; Fri, 03 May 2019 01:58:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR8y-0005Gd-9V for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR8w-0002tg-Mv for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:00 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:44376) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR8w-0002t7-GM; Fri, 03 May 2019 01:53:58 -0400 Received: by mail-pg1-x544.google.com with SMTP id z16so2183042pgv.11; Thu, 02 May 2019 22:53:58 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.53.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tDDmbBxXcuGX6xPjl7n2FpWe9iGxr+XHYg3A3IEDeRE=; b=Ru1FpV+sCVwjXKccpVkwDVU5vr4I6vyAJkU+r0jkDy0fgGpvYwHbAXGUz5iel6l/51 F2M+sK1mNW3jaRJd16BuW5cTVZHstDxAQij+Sp454QviEJsky3mg9J9zie6NTRJ3duWK wuMb/fuB7zdhkAAZVKI/5RWmJLXYpkiLRUZtCdSaGiZ0Hf3z4W+gwjW9TiYK3RIajJA3 t8ZZd8bIVryexibeMNkEtuKYPia6zThp0kUSiQvyAo0op67MsbXI4XjLRylde6jaJKR6 1hJUcGAPD7Ctv80UnSNZgP1auzOKyRdxi6ZMuCTMU7wS22ul4vmM4WRuPOTbDY03H2vr kTTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tDDmbBxXcuGX6xPjl7n2FpWe9iGxr+XHYg3A3IEDeRE=; b=iAxb/w+eHegjLPXql/R5gZDDUXA0EsaL02075dpoiwtnt4fAwISnXm+RC9pAkUz0/F kFp4v/WoU5ebmNZUzT6fKiF3L3tMvEGpdQhsJXALs6dSIhbSjusX978SAjnjBeoMtbC8 duSeJ2NiMbSXJF1+KsPLzUllHBqNk8rNraLqiJ/NN62a/LIxLTWhgCNL1V8T53ou4KAT fTxYTeDlr8NFkv/ZCWitZvOYAS4RZrVvQbsaYO/tM9+ltXlZpSl6FM+TF3ZrywDWfoph WIKXiulHLF7B0bahtNoUu9xr56rac3VFT0vqMtOUW5Vhn262tssU0VDidcukNdNbdV0R R5cQ== X-Gm-Message-State: APjAAAUTKWOMlmaYE8442LRYK/LbXwA+G9kEc2Pis9xfON6+PlMpYmLT 73TBoIPeYO0UfbfIKZ5NBwRtCGgCaLg= X-Google-Smtp-Source: APXvYqwUV4Qrj0iDW8hsIgn58cUNKyGdKqPYol4h6dCMdKfpOhaKKqvt0Jf0Cc7NnlYiQfxO7GrXsg== X-Received: by 2002:a62:14d6:: with SMTP id 205mr8540100pfu.4.1556862837325; Thu, 02 May 2019 22:53:57 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:07 +1000 Message-Id: <20190503055316.6441-5-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 04/13] target/ppc: Add SPR TBU40 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The spr TBU40 is used to set the upper 40 bits of the timebase register, present on POWER5+ and later processors. This register can only be written by the hypervisor, and cannot be read. Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson --- hw/ppc/ppc.c | 13 +++++++++++++ target/ppc/cpu.h | 1 + target/ppc/helper.h | 1 + target/ppc/timebase_helper.c | 5 +++++ target/ppc/translate_init.inc.c | 19 +++++++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index b567156f97..b618c6f615 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -710,6 +710,19 @@ void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t valu= e) &tb_env->vtb_offset, value); } =20 +void cpu_ppc_store_tbu40(CPUPPCState *env, uint64_t value) +{ + ppc_tb_t *tb_env =3D env->tb_env; + uint64_t tb; + + tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->tb_offset); + tb &=3D 0xFFFFFFUL; + tb |=3D (value & ~0xFFFFFFUL); + cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + &tb_env->tb_offset, tb); +} + static void cpu_ppc_tb_stop (CPUPPCState *env) { ppc_tb_t *tb_env =3D env->tb_env; diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 8d66265e5a..e324064111 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1334,6 +1334,7 @@ target_ulong cpu_ppc_load_decr (CPUPPCState *env); void cpu_ppc_store_decr (CPUPPCState *env, target_ulong value); target_ulong cpu_ppc_load_hdecr (CPUPPCState *env); void cpu_ppc_store_hdecr (CPUPPCState *env, target_ulong value); +void cpu_ppc_store_tbu40(CPUPPCState *env, uint64_t value); uint64_t cpu_ppc_load_purr (CPUPPCState *env); void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value); uint32_t cpu_ppc601_load_rtcl (CPUPPCState *env); diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 336e7802fb..6aee195528 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -703,6 +703,7 @@ DEF_HELPER_FLAGS_2(store_decr, TCG_CALL_NO_RWG, void, e= nv, tl) DEF_HELPER_FLAGS_1(load_hdecr, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_hdecr, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_FLAGS_2(store_vtb, TCG_CALL_NO_RWG, void, env, tl) +DEF_HELPER_FLAGS_2(store_tbu40, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_2(store_hid0_601, void, env, tl) DEF_HELPER_3(store_403_pbr, void, env, i32, tl) DEF_HELPER_FLAGS_1(load_40x_pit, TCG_CALL_NO_RWG, tl, env) diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c index 2395295b77..703bd9ed18 100644 --- a/target/ppc/timebase_helper.c +++ b/target/ppc/timebase_helper.c @@ -128,6 +128,11 @@ void helper_store_vtb(CPUPPCState *env, target_ulong v= al) cpu_ppc_store_vtb(env, val); } =20 +void helper_store_tbu40(CPUPPCState *env, target_ulong val) +{ + cpu_ppc_store_tbu40(env, val); +} + target_ulong helper_load_40x_pit(CPUPPCState *env) { return load_40x_pit(env); diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index a0cae58e19..8e287066e5 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -325,6 +325,11 @@ static void spr_write_vtb(DisasContext *ctx, int sprn,= int gprn) gen_helper_store_vtb(cpu_env, cpu_gpr[gprn]); } =20 +static void spr_write_tbu40(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_tbu40(cpu_env, cpu_gpr[gprn]); +} + #endif #endif =20 @@ -7812,6 +7817,16 @@ static void gen_spr_power5p_ear(CPUPPCState *env) 0x00000000); } =20 +static void gen_spr_power5p_tb(CPUPPCState *env) +{ + /* TBU40 (High 40 bits of the Timebase register */ + spr_register_hv(env, SPR_TBU40, "TBU40", + SPR_NOACCESS, SPR_NOACCESS, + SPR_NOACCESS, SPR_NOACCESS, + SPR_NOACCESS, &spr_write_tbu40, + 0x00000000); +} + #if !defined(CONFIG_USER_ONLY) static void spr_write_hmer(DisasContext *ctx, int sprn, int gprn) { @@ -8352,6 +8367,7 @@ static void init_proc_power5plus(CPUPPCState *env) gen_spr_power5p_common(env); gen_spr_power5p_lpar(env); gen_spr_power5p_ear(env); + gen_spr_power5p_tb(env); =20 /* env variables */ env->dcache_line_size =3D 128; @@ -8464,6 +8480,7 @@ static void init_proc_POWER7(CPUPPCState *env) gen_spr_power5p_common(env); gen_spr_power5p_lpar(env); gen_spr_power5p_ear(env); + gen_spr_power5p_tb(env); gen_spr_power6_common(env); gen_spr_power6_dbg(env); gen_spr_power7_book4(env); @@ -8605,6 +8622,7 @@ static void init_proc_POWER8(CPUPPCState *env) gen_spr_power5p_common(env); gen_spr_power5p_lpar(env); gen_spr_power5p_ear(env); + gen_spr_power5p_tb(env); gen_spr_power6_common(env); gen_spr_power6_dbg(env); gen_spr_power8_tce_address_control(env); @@ -8793,6 +8811,7 @@ static void init_proc_POWER9(CPUPPCState *env) gen_spr_power5p_common(env); gen_spr_power5p_lpar(env); gen_spr_power5p_ear(env); + gen_spr_power5p_tb(env); gen_spr_power6_common(env); gen_spr_power6_dbg(env); gen_spr_power8_tce_address_control(env); --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863283; cv=none; d=zoho.com; s=zohoarc; b=GA5TSSF4wqleKQDudV/4G8HOaRiJWJgx4Y1oUqiJU1rN+s4Rdljg2bsZvzPZIxyzZTAFDUrEZXgnsT8BPyBFHJxoyHTXMUm0BNLn9mLhcgwf/eoqTCYvViy06YRf4KKGMaB/euQuk/CbzWUyXNF94Bhpm3nwTLfqxUXp4+fjHMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863283; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=hDsDbN5xixiLnkL2VfXbM6rcGpngAkKIrMWVWa3efJM=; b=GjyAJO3gpR3zcE6SFnPvUUmlLFCIW9HJo6ydEj0pqkxIvHcXzjkSKx5JiTsXtufssPsWanofUEQXiqSwhL4kaYAFxlZJ00ycXGjt8xa3uZs2Xbe8KuSBLskrQe6bX5TBBIoZXmQrM6/2eUUEz5i9M5YLGlENB/wwOD1nlj9Pf/c= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863283071875.0648377530173; Thu, 2 May 2019 23:01:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:35067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRFz-0003FW-Td for importer@patchew.org; Fri, 03 May 2019 02:01:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR98-0005N0-8l for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR91-0002xm-RL for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:10 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:36081) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR91-0002xI-HX; Fri, 03 May 2019 01:54:03 -0400 Received: by mail-pl1-x644.google.com with SMTP id w20so2185863plq.3; Thu, 02 May 2019 22:54:03 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.53.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hDsDbN5xixiLnkL2VfXbM6rcGpngAkKIrMWVWa3efJM=; b=dCt8MJdJMSGsT2FgWLwo7n8sJfJtqiCSexxPk5D3Ww+WHmYDSWrs02NKvjkaD2S97l 8ywdmb/iWCf+R4qASy9haeTXlLt89l1IiMUw7lLgTjq4L6xiLHOEl4cxn34Om8BokXM7 xkl5j1v4lmwnfOkAOKM/Jrib9fDIpSbNyzMU0z65PZUoI7H6ESakj5KekW3nGroDjw4y pkDYPDSgXo/QbndRZ/aFkMnmiYIYaObhM4FW1U/ZNXyy5jiJ/OawKouDOKWMMOQ6smVG 897nchlhOzLRsOHhWhumjjLcytKGsUKu4PqCtQg5/gFTJLE0ZOSd/VW2O6LCkUhYblf+ hocg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hDsDbN5xixiLnkL2VfXbM6rcGpngAkKIrMWVWa3efJM=; b=O4RdUAuUFkSyrXk/TjeCMAPoxxW2t6gl3WWFgV1ru8XIU808Gljwux6FR+FcvM8EZa piCafEhuS8HOwiwDH6utVg6xxA596cEyrFQMQMaZlDySgwLa6zSHUDVjMB7FuOitBjVf NouLzFkog0dS6AtEJfdT/mBNUjdZZlTAUnHUD0gmW56duNurKG75Lplv6YPVSGSQ7+CW K2rD0t2bj6scRKqsx2ClLO8uKl/JLxdxkjPSxuUV/2BMcuCAvytjjh9fSgk/o7+pQV4e i/Hbjswl6WFVQf6UlAhoWXSGdmbPhBAGcxwi2FBUSwmFy7q0mclN+HFk0JEtdrOxiazN ApyA== X-Gm-Message-State: APjAAAVSs7UHbjWeiGaxS5aseuceC71XgXICPsA0ENnuBfMKbWpel0Ql ggeu1Hq2ERjV2IA5qWk7rq39kmrykdc= X-Google-Smtp-Source: APXvYqygwVcw02BcNlL7Ivb13R0OTjVgbyZcm7A6EnMiEgkT4XjNt3MVJar/LsrOsqa3aqXPqzi1JA== X-Received: by 2002:a17:902:8302:: with SMTP id bd2mr8050069plb.58.1556862842239; Thu, 02 May 2019 22:54:02 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:08 +1000 Message-Id: <20190503055316.6441-6-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 05/13] target/ppc: Add privileged message send facilities X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Privileged message send facilities exist on POWER8 processors and later and include a register and instructions which can be used to generate, observe/modify the state of and clear privileged doorbell exceptions as described below. The Directed Privileged Doorbell Exception State (DPDES) register reflects the state of pending privileged doorbell exceptions and can also be used to modify that state. The register can be used to read and modify the state of privileged doorbell exceptions for all threads of a subprocessor and thus is a shared facility for that subprocessor. The register can be read/written by the hypervisor and read by the supervisor if enabled in the HFSCR, otherwise a hypervisor facility unavailable exception is generated. The privileged message send and clear instructions (msgsndp & msgclrp) are used to generate and clear the presence of a directed privileged doorbell exception, respectively. The msgsndp instruction can be used to target any thread of the current subprocessor, msgclrp acts on the thread issuing the instruction. These instructions are privileged, but will generate a hypervisor facility unavailable exception if not enabled in the HFSCR and executed in privileged non-hypervisor state. Add and implement this register and instructions by reading or modifying the pending interrupt state of the cpu. Note that TCG only supports one thread per core and so we only need to worry about the cpu making the access. Signed-off-by: Suraj Jitindar Singh --- target/ppc/cpu.h | 7 +++++ target/ppc/excp_helper.c | 63 +++++++++++++++++++++++++++++++++++++= ---- target/ppc/helper.h | 5 ++++ target/ppc/misc_helper.c | 46 ++++++++++++++++++++++++++++++ target/ppc/translate.c | 28 ++++++++++++++++++ target/ppc/translate_init.inc.c | 40 ++++++++++++++++++++++++++ 6 files changed, 184 insertions(+), 5 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index e324064111..1d2a088391 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -425,6 +425,10 @@ typedef struct ppc_v3_pate_t { #define PSSCR_ESL PPC_BIT(42) /* Enable State Loss */ #define PSSCR_EC PPC_BIT(43) /* Exit Criterion */ =20 +/* HFSCR bits */ +#define HFSCR_MSGSNDP PPC_BIT(53) /* Privileged Message Send Facilitie= s */ +#define HFSCR_IC_MSGSNDP 0xA + #define msr_sf ((env->msr >> MSR_SF) & 1) #define msr_isf ((env->msr >> MSR_ISF) & 1) #define msr_shv ((env->msr >> MSR_SHV) & 1) @@ -1355,6 +1359,8 @@ void cpu_ppc_set_vhyp(PowerPCCPU *cpu, PPCVirtualHype= rvisor *vhyp); #endif =20 void store_fpscr(CPUPPCState *env, uint64_t arg, uint32_t mask); +void gen_hfscr_facility_check(DisasContext *ctx, int facility_sprn, int bi= t, + int sprn, int cause); =20 static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn) { @@ -1501,6 +1507,7 @@ void ppc_compat_add_property(Object *obj, const char = *name, #define SPR_MPC_ICTRL (0x09E) #define SPR_MPC_BAR (0x09F) #define SPR_PSPB (0x09F) +#define SPR_DPDES (0x0B0) #define SPR_DAWR (0x0B4) #define SPR_RPR (0x0BA) #define SPR_CIABR (0x0BB) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index beafcf1ebd..7a4da7bdba 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -461,6 +461,13 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int e= xcp_model, int excp) env->spr[SPR_FSCR] |=3D ((target_ulong)env->error_code << 56); #endif break; + case POWERPC_EXCP_HV_FU: /* Hypervisor Facility Unavailable Except= ion */ + env->spr[SPR_HFSCR] |=3D ((target_ulong)env->error_code << FSCR_IC= _POS); + srr0 =3D SPR_HSRR0; + srr1 =3D SPR_HSRR1; + new_msr |=3D (target_ulong)MSR_HVB; + new_msr |=3D env->msr & ((target_ulong)1 << MSR_RI); + break; case POWERPC_EXCP_PIT: /* Programmable interval timer interrupt = */ LOG_EXCP("PIT exception\n"); break; @@ -884,7 +891,11 @@ static void ppc_hw_interrupt(CPUPPCState *env) } if (env->pending_interrupts & (1 << PPC_INTERRUPT_DOORBELL)) { env->pending_interrupts &=3D ~(1 << PPC_INTERRUPT_DOORBELL); - powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_DOORI); + if (env->insns_flags & PPC_SEGMENT_64B) { + powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_SDOOR); + } else { + powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_DOORI); + } return; } if (env->pending_interrupts & (1 << PPC_INTERRUPT_HDOORBELL)) { @@ -1202,19 +1213,26 @@ void helper_msgsnd(target_ulong rb) } =20 /* Server Processor Control */ -static int book3s_dbell2irq(target_ulong rb) +static int book3s_dbell2irq(target_ulong rb, bool hv_dbell) { int msg =3D rb & DBELL_TYPE_MASK; =20 /* A Directed Hypervisor Doorbell message is sent only if the * message type is 5. All other types are reserved and the * instruction is a no-op */ - return msg =3D=3D DBELL_TYPE_DBELL_SERVER ? PPC_INTERRUPT_HDOORBELL : = -1; + if (msg =3D=3D DBELL_TYPE_DBELL_SERVER) { + if (hv_dbell) + return PPC_INTERRUPT_HDOORBELL; + else + return PPC_INTERRUPT_DOORBELL; + } + + return -1; } =20 void helper_book3s_msgclr(CPUPPCState *env, target_ulong rb) { - int irq =3D book3s_dbell2irq(rb); + int irq =3D book3s_dbell2irq(rb, 1); =20 if (irq < 0) { return; @@ -1225,7 +1243,42 @@ void helper_book3s_msgclr(CPUPPCState *env, target_u= long rb) =20 void helper_book3s_msgsnd(target_ulong rb) { - int irq =3D book3s_dbell2irq(rb); + int irq =3D book3s_dbell2irq(rb, 1); + int pir =3D rb & DBELL_PROCIDTAG_MASK; + CPUState *cs; + + if (irq < 0) { + return; + } + + qemu_mutex_lock_iothread(); + CPU_FOREACH(cs) { + PowerPCCPU *cpu =3D POWERPC_CPU(cs); + CPUPPCState *cenv =3D &cpu->env; + + /* TODO: broadcast message to all threads of the same processor */ + if (cenv->spr_cb[SPR_PIR].default_value =3D=3D pir) { + cenv->pending_interrupts |=3D 1 << irq; + cpu_interrupt(cs, CPU_INTERRUPT_HARD); + } + } + qemu_mutex_unlock_iothread(); +} + +void helper_book3s_msgclrp(CPUPPCState *env, target_ulong rb) +{ + int irq =3D book3s_dbell2irq(rb, 0); + + if (irq < 0) { + return; + } + + env->pending_interrupts &=3D ~(1 << irq); +} + +void helper_book3s_msgsndp(target_ulong rb) +{ + int irq =3D book3s_dbell2irq(rb, 0); int pir =3D rb & DBELL_PROCIDTAG_MASK; CPUState *cs; =20 diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 6aee195528..040f59d1af 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -657,6 +657,8 @@ DEF_HELPER_1(msgsnd, void, tl) DEF_HELPER_2(msgclr, void, env, tl) DEF_HELPER_1(book3s_msgsnd, void, tl) DEF_HELPER_2(book3s_msgclr, void, env, tl) +DEF_HELPER_1(book3s_msgsndp, void, tl) +DEF_HELPER_2(book3s_msgclrp, void, env, tl) #endif =20 DEF_HELPER_4(dlmzb, tl, env, tl, tl, i32) @@ -674,6 +676,7 @@ DEF_HELPER_3(store_dcr, void, env, tl, tl) =20 DEF_HELPER_2(load_dump_spr, void, env, i32) DEF_HELPER_2(store_dump_spr, void, env, i32) +DEF_HELPER_4(hfscr_facility_check, void, env, i32, i32, i32) DEF_HELPER_4(fscr_facility_check, void, env, i32, i32, i32) DEF_HELPER_4(msr_facility_check, void, env, i32, i32, i32) DEF_HELPER_FLAGS_1(load_tbl, TCG_CALL_NO_RWG, tl, env) @@ -688,6 +691,8 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, = env) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_purr, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_2(store_ptcr, void, env, tl) +DEF_HELPER_FLAGS_1(load_dpdes, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_FLAGS_2(store_dpdes, TCG_CALL_NO_RWG, void, env, tl) #endif DEF_HELPER_2(store_sdr1, void, env, tl) DEF_HELPER_2(store_pidr, void, env, tl) diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index c65d1ade15..d7d4acca7f 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -39,6 +39,17 @@ void helper_store_dump_spr(CPUPPCState *env, uint32_t sp= rn) } =20 #ifdef TARGET_PPC64 +static void raise_hv_fu_exception(CPUPPCState *env, uint32_t bit, + uint32_t sprn, uint32_t cause, + uintptr_t raddr) +{ + qemu_log("Facility SPR %d is unavailable (SPR HFSCR:%d)\n", sprn, bit); + + env->spr[SPR_HFSCR] &=3D ~((target_ulong)FSCR_IC_MASK << FSCR_IC_POS); + + raise_exception_err_ra(env, POWERPC_EXCP_HV_FU, cause, raddr); +} + static void raise_fu_exception(CPUPPCState *env, uint32_t bit, uint32_t sprn, uint32_t cause, uintptr_t raddr) @@ -53,6 +64,17 @@ static void raise_fu_exception(CPUPPCState *env, uint32_= t bit, } #endif =20 +void helper_hfscr_facility_check(CPUPPCState *env, uint32_t bit, + uint32_t sprn, uint32_t cause) +{ +#ifdef TARGET_PPC64 + if ((env->msr_mask & MSR_HVB) && !msr_hv && + !(env->spr[SPR_HFSCR] & (1UL << bit))= ) { + raise_hv_fu_exception(env, bit, sprn, cause, GETPC()); + } +#endif +} + void helper_fscr_facility_check(CPUPPCState *env, uint32_t bit, uint32_t sprn, uint32_t cause) { @@ -107,6 +129,30 @@ void helper_store_pcr(CPUPPCState *env, target_ulong v= alue) =20 env->spr[SPR_PCR] =3D value & pcc->pcr_mask; } + +target_ulong helper_load_dpdes(CPUPPCState *env) +{ + helper_hfscr_facility_check(env, HFSCR_MSGSNDP, SPR_DPDES, + HFSCR_IC_MSGSNDP); + + if (env->pending_interrupts & (1 << PPC_INTERRUPT_DOORBELL)) + return 1; + return 0; +} + +void helper_store_dpdes(CPUPPCState *env, target_ulong val) +{ + PowerPCCPU *cpu =3D ppc_env_get_cpu(env); + CPUState *cs =3D CPU(cpu); + + if (val) { + /* Only one cpu for now */ + env->pending_interrupts |=3D 1 << PPC_INTERRUPT_DOORBELL; + cpu_interrupt(cs, CPU_INTERRUPT_HARD); + } else { + env->pending_interrupts &=3D ~(1 << PPC_INTERRUPT_DOORBELL); + } +} #endif /* defined(TARGET_PPC64) */ =20 void helper_store_pidr(CPUPPCState *env, target_ulong val) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index fb42585a1c..2c3e83d18e 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -6537,6 +6537,30 @@ static void gen_msgsnd(DisasContext *ctx) #endif /* defined(CONFIG_USER_ONLY) */ } =20 +static void gen_msgclrp(DisasContext *ctx) +{ +#if defined(CONFIG_USER_ONLY) + GEN_PRIV; +#else + CHK_SV; + gen_hfscr_facility_check(ctx, SPR_HFSCR, HFSCR_MSGSNDP, 0, + HFSCR_IC_MSGSNDP); + gen_helper_book3s_msgclrp(cpu_env, cpu_gpr[rB(ctx->opcode)]); +#endif /* defined(CONFIG_USER_ONLY) */ +} + +static void gen_msgsndp(DisasContext *ctx) +{ +#if defined(CONFIG_USER_ONLY) + GEN_PRIV; +#else + CHK_SV; + gen_hfscr_facility_check(ctx, SPR_HFSCR, HFSCR_MSGSNDP, 0, + HFSCR_IC_MSGSNDP); + gen_helper_book3s_msgsndp(cpu_gpr[rB(ctx->opcode)]); +#endif /* defined(CONFIG_USER_ONLY) */ +} + static void gen_msgsync(DisasContext *ctx) { #if defined(CONFIG_USER_ONLY) @@ -7054,6 +7078,10 @@ GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0= x03ff0001, PPC_NONE, PPC2_PRCNTL), GEN_HANDLER2_E(msgsync, "msgsync", 0x1F, 0x16, 0x1B, 0x00000000, PPC_NONE, PPC2_PRCNTL), +GEN_HANDLER2_E(msgsndp, "msgsndp", 0x1F, 0x0E, 0x04, 0x03ff0001, + PPC_NONE, PPC2_ISA207S), +GEN_HANDLER2_E(msgclrp, "msgclrp", 0x1F, 0x0E, 0x05, 0x03ff0001, + PPC_NONE, PPC2_ISA207S), GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index 8e287066e5..46f9399097 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -454,6 +454,19 @@ static void spr_write_pcr(DisasContext *ctx, int sprn,= int gprn) { gen_helper_store_pcr(cpu_env, cpu_gpr[gprn]); } + +/* DPDES */ +static void spr_read_dpdes(DisasContext *ctx, int gprn, int sprn) +{ + gen_hfscr_facility_check(ctx, SPR_HFSCR, HFSCR_MSGSNDP, sprn, + HFSCR_IC_MSGSNDP); + gen_helper_load_dpdes(cpu_gpr[gprn], cpu_env); +} + +static void spr_write_dpdes(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_dpdes(cpu_env, cpu_gpr[gprn]); +} #endif #endif =20 @@ -7478,6 +7491,20 @@ POWERPC_FAMILY(e600)(ObjectClass *oc, void *data) #define POWERPC970_HID5_INIT 0x00000000 #endif =20 +void gen_hfscr_facility_check(DisasContext *ctx, int facility_sprn, int bi= t, + int sprn, int cause) +{ + TCGv_i32 t1 =3D tcg_const_i32(bit); + TCGv_i32 t2 =3D tcg_const_i32(sprn); + TCGv_i32 t3 =3D tcg_const_i32(cause); + + gen_helper_hfscr_facility_check(cpu_env, t1, t2, t3); + + tcg_temp_free_i32(t3); + tcg_temp_free_i32(t2); + tcg_temp_free_i32(t1); +} + static void gen_fscr_facility_check(DisasContext *ctx, int facility_sprn, int bit, int sprn, int cause) { @@ -8249,6 +8276,17 @@ static void gen_spr_power8_rpr(CPUPPCState *env) #endif } =20 +static void gen_spr_power8_dpdes(CPUPPCState *env) +{ +#if !defined(CONFIG_USER_ONLY) + spr_register_kvm_hv(env, SPR_DPDES, "DPDES", + SPR_NOACCESS, SPR_NOACCESS, + &spr_read_dpdes, SPR_NOACCESS, + &spr_read_dpdes, &spr_write_dpdes, + KVM_REG_PPC_DPDES, 0x0UL); +#endif +} + static void gen_spr_power9_mmu(CPUPPCState *env) { #if !defined(CONFIG_USER_ONLY) @@ -8637,6 +8675,7 @@ static void init_proc_POWER8(CPUPPCState *env) gen_spr_power8_ic(env); gen_spr_power8_book4(env); gen_spr_power8_rpr(env); + gen_spr_power8_dpdes(env); =20 /* env variables */ env->dcache_line_size =3D 128; @@ -8826,6 +8865,7 @@ static void init_proc_POWER9(CPUPPCState *env) gen_spr_power8_ic(env); gen_spr_power8_book4(env); gen_spr_power8_rpr(env); + gen_spr_power8_dpdes(env); gen_spr_power9_mmu(env); =20 /* POWER9 Specific registers */ --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863431; cv=none; d=zoho.com; s=zohoarc; b=aq+rouf3nIFiXxC9+mh5OipY1FjNrtgIgUmhBzXi3U+736uwwB5imbFDsiranOLm07cBrVsMJtIOB9V9kFdVqG5OUKhXcCuw+o8pfJ7iVJm+9QMwIZmjUa7ndJv6C3xKYK7tZ1ufjqlO9rmMX1bCpixpgW3lk2SFlZhO8n3IPYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863431; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=wUZAXOTwdw2I/hZuC5jS4/OqNN0mBHOWVDEizVGw6GQ=; b=F53pJIC1/AKnvU/x0dcMcnchCrIpEMoiXucWZ+Lu7+90ycLaydY1sQYTq/eMy8Ww/E6D1Vw1/2GB0hVaRhmJSxgQuty8aZERftZhW3gO/mJE46Pg9iVB9gYOlu7zgi4vMHy/2xCP+lHRVMAVttujmT8jESIVS130QVpFFstKinI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863431122825.7853030815809; Thu, 2 May 2019 23:03:51 -0700 (PDT) Received: from localhost ([127.0.0.1]:35091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRIP-0005JF-5F for importer@patchew.org; Fri, 03 May 2019 02:03:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9D-0005S0-W2 for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9C-00032k-A2 for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:15 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:36068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9C-0002zZ-0e; Fri, 03 May 2019 01:54:14 -0400 Received: by mail-pf1-x442.google.com with SMTP id v80so2353483pfa.3; Thu, 02 May 2019 22:54:09 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wUZAXOTwdw2I/hZuC5jS4/OqNN0mBHOWVDEizVGw6GQ=; b=Af6AxvyqyVqgdx5sR9vt6CetSMY498qPkmWf3OjJNGMDcg2ddNIfbPZzyq332xmqsh NBeya8BT1uEgWonEwLsDp0/ne3QtR6PIDAj7nXYqtdPCPT2iablRFHZPdA4jSbVOJ2DC lxS9KGmLzAx2wgO+Q6jrlzyczAAU18o8BnwqvswvsjMRvOGV9ga1aPLZPWxIHv15f9pC 2Gh/X9ZyQDVS2ObIlOzM+pdcwbjAlrp+tSH2+BKG4wRgZK+9ziayr1LhDM67RFvQM4d5 tCxrigMfEz85CBu9Y+RotUlGLdpLo92zY5I09Bq/Uo6/BzeLicQXP9tj/f5HYKTCD9Tt F/4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wUZAXOTwdw2I/hZuC5jS4/OqNN0mBHOWVDEizVGw6GQ=; b=tDC2aLc5XRJPV3Jq9kFocopDf2qSU6B58UDEgLkFGOsXQfnISbsIC7MS+sPC8Tl3RB kdwwnaSwaysD70ge++46GKTHyhhTrZaKi6HwGcbXAerZ6HlBFfvQcmzPPGP7I1Ncuh8k aQ+Zjrl7Eqek7U/ptw82z4MR7f4QqetwGUrJMAanWB0McFjsKahXjRRe+Ny/iYrpkxgy WqmyJLGcJGCAx6BpW6qm3kdNuX3+XzMHFA/Foovk7VyepejbBWmkwHwUIxtTEnsT+2g3 gcEKsYIgiTikPR9GeqM9n+JHdw/q3j11uBNMUMD0pA38L08aBZkcJ3vzzr0AS/vpo4GY l0Vw== X-Gm-Message-State: APjAAAWb0xajo2J7SYoLLSpl2s4C0UBPfLxngs1kpIxUCfJVWHeF9p+B oAitc5WK8cO9WUfnl3VQvEbSKENOCpA= X-Google-Smtp-Source: APXvYqxPUPVhxF4jxE8BFdmppxcc+9qa8+6brNnYwfd4qF10qVOD5UY8ZyVwxrLGWVAt/gTJ4VchIQ== X-Received: by 2002:a63:9541:: with SMTP id t1mr4336289pgn.97.1556862848390; Thu, 02 May 2019 22:54:08 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:09 +1000 Message-Id: <20190503055316.6441-7-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 06/13] target/ppc: Enforce that the root page directory size must be at least 5 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" According to the ISA the root page directory size of a radix tree for either process or partition scoped translation must be >=3D 5. Thus add this to the list of conditions checked when validating the partition table entry in validate_pate(); Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson --- target/ppc/mmu-radix64.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index a6ab290323..afa5ba506a 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -249,6 +249,8 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpi= d, ppc_v3_pate_t *pate) if (lpid =3D=3D 0 && !msr_hv) { return false; } + if ((pate->dw0 & PATE1_R_PRTS) < 5) + return false; /* More checks ... */ return true; } --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863005; cv=none; d=zoho.com; s=zohoarc; b=JTK7ib3QTDl/IeBmiqLtcWb9JN1i5PjVXslO4Lsmqw1zUn2qQxfThOlWIwIaOutA3dIWzjfXF2kJJtg89UqQMO5aaDon4UbySO7HxQs1kOn/wljOVy60YjOT6+WfdZ1ktHQUlMI9OA732a9gZDR7pHD2IOD+QNLRs2SmiI1Gajw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863005; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5p7dythzPg2R8zM7QniifT+PR6Pz87+BWYaHGV9RzYc=; b=YaHsjJGJLv6nAZtgLxWzdRPDDc3IWIZ6K2ZZjbTlAeTs3/g4a533kLceNDfRsPr+yb6DP5ja63D0PKHdLLX495aC7wue8exWN0j15rNFxDZXPy93LjhWpnsV7bdhOe2p5/7liAv8zOcHJw8KeQKktQGq8dHGgXqj8QMlG+lmtc0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155686300559785.9298411083704; Thu, 2 May 2019 22:56:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:34971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRBX-0007TY-BG for importer@patchew.org; Fri, 03 May 2019 01:56:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9H-0005XE-Od for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9E-00035K-4h for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:19 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:33755) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9C-00032L-8A; Fri, 03 May 2019 01:54:15 -0400 Received: by mail-pl1-x644.google.com with SMTP id y3so2188929plp.0; Thu, 02 May 2019 22:54:14 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5p7dythzPg2R8zM7QniifT+PR6Pz87+BWYaHGV9RzYc=; b=Db9ZcVXc2kqLWFtBRLMROinl9Vi5zznUBoVyJ3P7lYyBZSdnpnxbYtxePurrxAv487 Lamw4FN+lpyiY/0gjx+Ev+8pVI6Om4ZQ4CIFWcFbLgzO3pREjjwrJCZAhuoqcHkxbTsr 1NIGh1KwJPpRRrkgbvs6lHrCLjil2j7P3D+QcW30UkYcxldAbNuv5PZZGZSSwso8nI9k SQ9T7lKoG/Yrl/ejD3X6RV9icqG7SIneV/DJFjAbsyL9WW9lSic/m0RbeEBIJtlDPNUA LgwiRxaToHXbDW+My6w4+bf2oxLfVeSi1U+fqMiLD+nZIPpvt6IOol/xSxPBSh8mSdXu ICLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5p7dythzPg2R8zM7QniifT+PR6Pz87+BWYaHGV9RzYc=; b=dlSOFFlZolIZhDKxfO48yE9bjQPqfEt7OkU8AR+SzCnTZHsl/yxEDfcWfrdrOWx133 O9ovZGye4VBVYqwaS1k7EADMKgybmLousOmGMAvpASOVMQfpKRq4rvbf2VULrQUPmKcQ tbTRruSpiSiRMq/7SZfyElKAnFnCzdZjAOubc5keJYHOxPpV/Ue82h17PyoHKWq/ognE 114XWM3Pzt540k0WrJ/GKOdoI6ZJ149go0v4pCmjOk5uMG+q0eyxhoTjK7fPxMsFxL+1 EMZoiHEpzJUUn2Cq1YWEf/hOw+VjYQEVl7ChXKbg+En9Kkx3l/MpLqVceJNBGYZNZe9Z qp8A== X-Gm-Message-State: APjAAAX+oScluTBhMDMIPpDC4nCsjOo4P+/tgiwzzjsmYYJo6vDjl3Ej lXpeAp7rKfVcxaWIJ3qRyJnTORxYj0A= X-Google-Smtp-Source: APXvYqxG2lvx3NLDn2QHwVQspSpO7QEGZlV1mMEj1PghVqLAJfvMelptUM4cEacSgAfFQNVkmQqCMA== X-Received: by 2002:a17:902:b181:: with SMTP id s1mr8269664plr.9.1556862852898; Thu, 02 May 2019 22:54:12 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:10 +1000 Message-Id: <20190503055316.6441-8-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 07/13] target/ppc: Handle partition scoped radix tree translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Radix tree translation is a 2 step process: Process Scoped Translation: Effective Address (EA) -> Virtual Address (VA) Paritition Scoped Translation: Virtual Address (VA) -> Real Address (RA) Performed based on: MSR[HV] ----------------------------------------------- | | HV =3D 0 | HV =3D 1 | ----------------------------------------------- | Relocation | Partition | No | | =3D Off | Scoped | Translation | Relocation ----------------------------------------------- | Relocation | Partition & | Process | | =3D On |Process Scoped | Scoped | ----------------------------------------------- Currently only process scoped translation is handled. Implement partitition scoped translation. The process of using the radix trees to perform partition scoped translation is identical to process scoped translation, however hypervisor exceptions are generated, and thus we can reuse the radix tree traversing code. Signed-off-by: Suraj Jitindar Singh --- target/ppc/cpu.h | 2 + target/ppc/excp_helper.c | 3 +- target/ppc/mmu-radix64.c | 407 +++++++++++++++++++++++++++++++++----------= ---- 3 files changed, 293 insertions(+), 119 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 1d2a088391..3acc248f40 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -501,6 +501,8 @@ typedef struct ppc_v3_pate_t { /* Unsupported Radix Tree Configuration */ #define DSISR_R_BADCONFIG 0x00080000 #define DSISR_ATOMIC_RC 0x00040000 +/* Unable to translate address of (guest) pde or process/page table entry = */ +#define DSISR_PRTABLE_FAULT 0x00020000 =20 /* SRR1 error code fields */ =20 diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 7a4da7bdba..10091d4624 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -441,9 +441,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int e= xcp_model, int excp) case POWERPC_EXCP_ISEG: /* Instruction segment exception = */ case POWERPC_EXCP_TRACE: /* Trace exception = */ break; + case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excepti= on */ + msr |=3D env->error_code; case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception = */ case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception = */ - case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excepti= on */ case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception = */ case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment excepti= on */ case POWERPC_EXCP_SDOOR_HV: /* Hypervisor Doorbell interrupt = */ diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index afa5ba506a..6118ad1b00 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -112,9 +112,31 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int = rwx, vaddr eaddr, } } =20 +static void ppc_radix64_raise_hsi(PowerPCCPU *cpu, int rwx, vaddr eaddr, + hwaddr g_raddr, uint32_t cause) +{ + CPUState *cs =3D CPU(cpu); + CPUPPCState *env =3D &cpu->env; + + if (rwx =3D=3D 2) { /* H Instruction Storage Interrupt */ + cs->exception_index =3D POWERPC_EXCP_HISI; + env->spr[SPR_ASDR] =3D g_raddr; + env->error_code =3D cause; + } else { /* H Data Storage Interrupt */ + cs->exception_index =3D POWERPC_EXCP_HDSI; + if (rwx =3D=3D 1) { /* Write -> Store */ + cause |=3D DSISR_ISSTORE; + } + env->spr[SPR_HDSISR] =3D cause; + env->spr[SPR_HDAR] =3D eaddr; + env->spr[SPR_ASDR] =3D g_raddr; + env->error_code =3D 0; + } +} =20 static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, - int *fault_cause, int *prot) + int *fault_cause, int *prot, + bool partition_scoped) { CPUPPCState *env =3D &cpu->env; const int need_prot[] =3D { PAGE_READ, PAGE_WRITE, PAGE_EXEC }; @@ -130,11 +152,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, i= nt rwx, uint64_t pte, } =20 /* Determine permissions allowed by Encoded Access Authority */ - if ((pte & R_PTE_EAA_PRIV) && msr_pr) { /* Insufficient Privilege */ + if (!partition_scoped && (pte & R_PTE_EAA_PRIV) && msr_pr) { *prot =3D 0; - } else if (msr_pr || (pte & R_PTE_EAA_PRIV)) { + } else if (msr_pr || (pte & R_PTE_EAA_PRIV) || partition_scoped) { *prot =3D ppc_radix64_get_prot_eaa(pte); - } else { /* !msr_pr && !(pte & R_PTE_EAA_PRIV) */ + } else { /* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */ *prot =3D ppc_radix64_get_prot_eaa(pte); *prot &=3D ppc_radix64_get_prot_amr(cpu); /* Least combined permis= sions */ } @@ -199,44 +221,196 @@ static uint64_t ppc_radix64_set_rc(PowerPCCPU *cpu, = int rwx, uint64_t pte, hwadd return npte; } =20 -static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr, - uint64_t base_addr, uint64_t nls, - hwaddr *raddr, int *psize, - int *fault_cause, hwaddr *pte_addr) +static uint64_t ppc_radix64_next_level(PowerPCCPU *cpu, vaddr eaddr, + uint64_t *pte_addr, uint64_t *nls, + int *psize, int *fault_cause) { CPUState *cs =3D CPU(cpu); uint64_t index, pde; =20 - if (nls < 5) { /* Directory maps less than 2**5 entries */ + if (*nls < 5) { /* Directory maps less than 2**5 entries */ *fault_cause |=3D DSISR_R_BADCONFIG; return 0; } =20 /* Read page entry from guest address space */ - index =3D eaddr >> (*psize - nls); /* Shift */ - index &=3D ((1UL << nls) - 1); /* Mask */ - pde =3D ldq_phys(cs->as, base_addr + (index * sizeof(pde))); - if (!(pde & R_PTE_VALID)) { /* Invalid Entry */ + pde =3D ldq_phys(cs->as, *pte_addr); + if (!(pde & R_PTE_VALID)) { /* Invalid Entry */ *fault_cause |=3D DSISR_NOPTE; return 0; } =20 - *psize -=3D nls; + *psize -=3D *nls; + if (!(pde & R_PTE_LEAF)) { /* Prepare for next iteration */ + *nls =3D pde & R_PDE_NLS; + index =3D eaddr >> (*psize - *nls); /* Shift */ + index &=3D ((1UL << *nls) - 1); /* Mask */ + *pte_addr =3D (pde & R_PDE_NLB) + (index * sizeof(pde)); + } + return pde; +} + +static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr, + uint64_t base_addr, uint64_t nls, + hwaddr *raddr, int *psize, + int *fault_cause, hwaddr *pte_addr) +{ + uint64_t index, pde; + + index =3D eaddr >> (*psize - nls); /* Shift */ + index &=3D ((1UL << nls) - 1); /* Mask */ + *pte_addr =3D base_addr + (index * sizeof(pde)); + do { + pde =3D ppc_radix64_next_level(cpu, eaddr, pte_addr, &nls, psize, + fault_cause); + } while ((pde & R_PTE_VALID) && !(pde & R_PTE_LEAF)); =20 - /* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ - if (pde & R_PTE_LEAF) { + /* Did we find a valid leaf? */ + if ((pde & R_PTE_VALID) && (pde & R_PTE_LEAF)) { uint64_t rpn =3D pde & R_PTE_RPN; uint64_t mask =3D (1UL << *psize) - 1; =20 /* Or high bits of rpn and low bits to ea to form whole real addr = */ *raddr =3D (rpn & ~mask) | (eaddr & mask); - *pte_addr =3D base_addr + (index * sizeof(pde)); - return pde; } =20 - /* Next Level of Radix Tree */ - return ppc_radix64_walk_tree(cpu, eaddr, pde & R_PDE_NLB, pde & R_PDE_= NLS, - raddr, psize, fault_cause, pte_addr); + return pde; +} + +static int ppc_radix64_partition_scoped_xlate(PowerPCCPU *cpu, int rwx, + vaddr eaddr, hwaddr g_raddr, + ppc_v3_pate_t pate, + hwaddr *h_raddr, int *h_prot, + int *h_page_size, bool pde_a= ddr, + bool cause_excp) +{ + CPUPPCState *env =3D &cpu->env; + int fault_cause =3D 0; + hwaddr pte_addr; + uint64_t pte; + +restart: + *h_page_size =3D PRTBE_R_GET_RTS(pate.dw0); + pte =3D ppc_radix64_walk_tree(cpu, g_raddr, pate.dw0 & PRTBE_R_RPDB, + pate.dw0 & PRTBE_R_RPDS, h_raddr, h_page_s= ize, + &fault_cause, &pte_addr); + /* No valid pte or access denied due to protection */ + if (!(pte & R_PTE_VALID) || + ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, h_prot, 1)= ) { + if (pde_addr) /* address being translated was that of a guest pde = */ + fault_cause |=3D DSISR_PRTABLE_FAULT; + if (cause_excp) + ppc_radix64_raise_hsi(cpu, rwx, eaddr, g_raddr, fault_cause); + return 1; + } + + /* Update Reference and Change Bits */ + if (ppc_radix64_hw_rc_updates(env)) { + pte =3D ppc_radix64_set_rc(cpu, rwx, pte, pte_addr); + if (!pte) { + goto restart; + } + } + + /* If the page doesn't have C, treat it as read only */ + if (!(pte & R_PTE_C)) + *h_prot &=3D ~PAGE_WRITE; + + return 0; +} + +static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, + vaddr eaddr, uint64_t lpid, ui= nt64_t pid, + ppc_v3_pate_t pate, hwaddr *g_= raddr, + int *g_prot, int *g_page_size, + bool cause_excp) +{ + CPUState *cs =3D CPU(cpu); + CPUPPCState *env =3D &cpu->env; + uint64_t offset, size, prtbe_addr, prtbe0, base_addr, nls, index, pte; + int fault_cause =3D 0, h_page_size, h_prot, ret; + hwaddr h_raddr, pte_addr; + + /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ + offset =3D pid * sizeof(struct prtb_entry); + size =3D 1ULL << ((pate.dw1 & PATE1_R_PRTS) + 12); + if (offset >=3D size) { + /* offset exceeds size of the process table */ + if (cause_excp) + ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); + return 1; + } + prtbe_addr =3D (pate.dw1 & PATE1_R_PRTB) + offset; + /* address subject to partition scoped translation */ + if (cpu->vhyp && (lpid =3D=3D 0)) { + prtbe0 =3D ldq_phys(cs->as, prtbe_addr); + } else { + ret =3D ppc_radix64_partition_scoped_xlate(cpu, 0, eaddr, prtbe_ad= dr, + pate, &h_raddr, &h_prot, + &h_page_size, 1, 1); + if (ret) + return ret; + prtbe0 =3D ldq_phys(cs->as, h_raddr); + } + + /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ +restart: + *g_page_size =3D PRTBE_R_GET_RTS(prtbe0); + base_addr =3D prtbe0 & PRTBE_R_RPDB; + nls =3D prtbe0 & PRTBE_R_RPDS; + if (msr_hv || (cpu->vhyp && (lpid =3D=3D 0))) { + /* Can treat process tree addresses as real addresses */ + pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, base_addr= , nls, + g_raddr, g_page_size, &fault_cause, + &pte_addr); + } else { + index =3D (eaddr & R_EADDR_MASK) >> (*g_page_size - nls); /* Shift= */ + index &=3D ((1UL << nls) - 1); /* Mask = */ + pte_addr =3D base_addr + (index * sizeof(pte)); + + /* Each process tree address subject to partition scoped translati= on */ + do { + ret =3D ppc_radix64_partition_scoped_xlate(cpu, 0, eaddr, pte_= addr, + pate, &h_raddr, &h_pr= ot, + &h_page_size, 1, 1); + if (ret) + return ret; + + pte =3D ppc_radix64_next_level(cpu, eaddr & R_EADDR_MASK, &h_r= addr, + &nls, g_page_size, &fault_cause); + pte_addr =3D h_raddr; + } while ((pte & R_PTE_VALID) && !(pte & R_PTE_LEAF)); + + /* Did we find a valid leaf? */ + if ((pte & R_PTE_VALID) && (pte & R_PTE_LEAF)) { + uint64_t rpn =3D pte & R_PTE_RPN; + uint64_t mask =3D (1UL << *g_page_size) - 1; + + /* Or high bits of rpn and low bits to ea to form whole real a= ddr */ + *g_raddr =3D (rpn & ~mask) | (eaddr & mask); + } + } + + if (!(pte & R_PTE_VALID) || + ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, g_prot, 0)= ) { + /* No valid pte or access denied due to protection */ + if (cause_excp) + ppc_radix64_raise_si(cpu, rwx, eaddr, fault_cause); + return 1; + } + + /* Update Reference and Change Bits */ + if (ppc_radix64_hw_rc_updates(env)) { + pte =3D ppc_radix64_set_rc(cpu, rwx, pte, pte_addr); + if (!pte) + goto restart; + } + + /* If the page doesn't have C, treat it as read only */ + if (!(pte & R_PTE_C)) + *g_prot &=3D ~PAGE_WRITE; + + return 0; } =20 static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *p= ate) @@ -255,22 +429,99 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t l= pid, ppc_v3_pate_t *pate) return true; } =20 +static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, + uint64_t lpid, uint64_t pid, bool relocation, + hwaddr *raddr, int *psizep, int *protp, + bool cause_excp) +{ + CPUPPCState *env =3D &cpu->env; + ppc_v3_pate_t pate; + int psize, prot; + hwaddr g_raddr; + + *psizep =3D INT_MAX; + *protp =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + + /* Get Process Table */ + if (cpu->vhyp && (lpid =3D=3D 0)) { + PPCVirtualHypervisorClass *vhc; + vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + vhc->get_pate(cpu->vhyp, &pate); + } else { + if (!ppc64_v3_get_pate(cpu, lpid, &pate)) { + if (cause_excp) + ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); + return 1; + } + if (!validate_pate(cpu, lpid, &pate)) { + if (cause_excp) + ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_R_BADCONFIG); + return 1; + } + } + + /* + * Radix tree translation is a 2 step translation process: + * 1. Process Scoped translation - Guest Eff Addr -> Guest Real Addr + * 2. Partition Scoped translation - Guest Real Addr -> Host Real Addr + * + * MSR[HV] + * ----------------------------------------------- + * | | HV =3D 0 | HV =3D 1 | + * ----------------------------------------------- + * | Relocation | Partition | No | + * | =3D Off | Scoped | Translation | + * Relocation ----------------------------------------------- + * | Relocation | Partition & | Process | + * | =3D On |Process Scoped | Scoped | + * ----------------------------------------------- + */ + + /* Perform process scoped translation if relocation enabled */ + if (relocation) { + int ret =3D ppc_radix64_process_scoped_xlate(cpu, rwx, eaddr, lpid= , pid, + pate, &g_raddr, &prot, + &psize, cause_excp); + if (ret) + return ret; + *psizep =3D MIN(*psizep, psize); + *protp &=3D prot; + } else { + g_raddr =3D eaddr & R_EADDR_MASK; + } + + /* Perform partition scoped xlate if !HV or HV access to quadrants 1 o= r 2 */ + if ((lpid !=3D 0) || (!cpu->vhyp && !msr_hv)) { + int ret =3D ppc_radix64_partition_scoped_xlate(cpu, rwx, eaddr, g_= raddr, + pate, raddr, &prot, &= psize, + 0, cause_excp); + if (ret) + return ret; + *psizep =3D MIN(*psizep, psize); + *protp &=3D prot; + } else { + *raddr =3D g_raddr; + } + + return 0; +} + int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx, int mmu_idx) { CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; - PPCVirtualHypervisorClass *vhc; - hwaddr raddr, pte_addr; - uint64_t lpid =3D 0, pid =3D 0, offset, size, prtbe0, pte; - int page_size, prot, fault_cause =3D 0; - ppc_v3_pate_t pate; + uint64_t pid, lpid =3D env->spr[SPR_LPIDR]; + int psize, prot; + bool relocation; + hwaddr raddr; =20 + assert(!(msr_hv && cpu->vhyp)); assert((rwx =3D=3D 0) || (rwx =3D=3D 1) || (rwx =3D=3D 2)); =20 + relocation =3D ((rwx =3D=3D 2) && (msr_ir =3D=3D 1)) || ((rwx !=3D 2) = && (msr_dr =3D=3D 1)); /* HV or virtual hypervisor Real Mode Access */ - if ((msr_hv || cpu->vhyp) && - (((rwx =3D=3D 2) && (msr_ir =3D=3D 0)) || ((rwx !=3D 2) && (msr_dr= =3D=3D 0)))) { + if (!relocation && (msr_hv || (cpu->vhyp && (lpid =3D=3D 0)))) { /* In real mode top 4 effective addr bits (mostly) ignored */ raddr =3D eaddr & 0x0FFFFFFFFFFFFFFFULL; =20 @@ -294,75 +545,26 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vad= dr eaddr, int rwx, return 1; } =20 - /* Get Process Table */ - if (cpu->vhyp) { - vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); - vhc->get_pate(cpu->vhyp, &pate); - } else { - if (!ppc64_v3_get_pate(cpu, lpid, &pate)) { - ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); - return 1; - } - if (!validate_pate(cpu, lpid, &pate)) { - ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_R_BADCONFIG); - } - /* We don't support guest mode yet */ - if (lpid !=3D 0) { - error_report("PowerNV guest support Unimplemented"); - exit(1); - } - } - - /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ - offset =3D pid * sizeof(struct prtb_entry); - size =3D 1ULL << ((pate.dw1 & PATE1_R_PRTS) + 12); - if (offset >=3D size) { - /* offset exceeds size of the process table */ - ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); - return 1; - } - prtbe0 =3D ldq_phys(cs->as, (pate.dw1 & PATE1_R_PRTB) + offset); - - /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =3D PRTBE_R_GET_RTS(prtbe0); - restart: - pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, - prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, - &raddr, &page_size, &fault_cause, &pte_add= r); - if (!pte || ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, &prot)= ) { - /* Couldn't get pte or access denied due to protection */ - ppc_radix64_raise_si(cpu, rwx, eaddr, fault_cause); + /* Translate eaddr to raddr (where raddr is addr qemu needs for access= ) */ + if (ppc_radix64_xlate(cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &psize, &prot, 1)) { return 1; } =20 - /* Update Reference and Change Bits */ - if (ppc_radix64_hw_rc_updates(env)) { - pte =3D ppc_radix64_set_rc(cpu, rwx, pte, pte_addr); - if (!pte) { - goto restart; - } - } - /* If the page doesn't have C, treat it as read only */ - if (!(pte & R_PTE_C)) { - prot &=3D ~PAGE_WRITE; - } tlb_set_page(cs, eaddr & TARGET_PAGE_MASK, raddr & TARGET_PAGE_MASK, - prot, mmu_idx, 1UL << page_size); + prot, mmu_idx, 1UL << psize); return 0; } =20 hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr) { - CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; - PPCVirtualHypervisorClass *vhc; - hwaddr raddr, pte_addr; - uint64_t lpid =3D 0, pid =3D 0, offset, size, prtbe0, pte; - int page_size, fault_cause =3D 0; - ppc_v3_pate_t pate; + uint64_t lpid =3D 0, pid =3D 0; + int psize, prot; + hwaddr raddr; =20 /* Handle Real Mode */ - if (msr_dr =3D=3D 0) { + if ((msr_dr =3D=3D 0) && (msr_hv || (cpu->vhyp && (lpid =3D=3D 0)))) { /* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr & 0x0FFFFFFFFFFFFFFFULL; } @@ -372,39 +574,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu= , target_ulong eaddr) return -1; } =20 - /* Get Process Table */ - if (cpu->vhyp) { - vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); - vhc->get_pate(cpu->vhyp, &pate); - } else { - if (!ppc64_v3_get_pate(cpu, lpid, &pate)) { - return -1; - } - if (!validate_pate(cpu, lpid, &pate)) { - return -1; - } - /* We don't support guest mode yet */ - if (lpid !=3D 0) { - error_report("PowerNV guest support Unimplemented"); - exit(1); - } - } - - /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ - offset =3D pid * sizeof(struct prtb_entry); - size =3D 1ULL << ((pate.dw1 & PATE1_R_PRTS) + 12); - if (offset >=3D size) { - /* offset exceeds size of the process table */ - return -1; - } - prtbe0 =3D ldq_phys(cs->as, (pate.dw1 & PATE1_R_PRTB) + offset); - - /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =3D PRTBE_R_GET_RTS(prtbe0); - pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, - prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, - &raddr, &page_size, &fault_cause, &pte_add= r); - if (!pte) { + if (ppc_radix64_xlate(cpu, eaddr, 0, lpid, pid, msr_dr, &raddr, &psize, + &prot, 0)) { return -1; } =20 --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863575; cv=none; d=zoho.com; s=zohoarc; b=Eh97kY3410MdHLLM30ezVDI8OdAsNGt3G1u2ZH4fqs1y9Ba3NFW6ShKAePGOt8K/YQs3jDqO19cmSWpQvXbLlgFmOfTByl0zDz9qabKIvQq+U273o+7hIRpdOgOWgVrV1JtAeNbmfw5VcIxMqYJ6w1XAOMtLwq6dtfQQVywMbcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863575; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gtYREJ6wLh93MiaNJLpdXl6ZvqtubSybEdUbcIWsFl0=; b=FpcF2Revz+iD3PdCoIKDuEh4IflsO8eeWJ4sV7wWUOXVq5s6oWWC9QMV/i6R1navEEMaZR7hsP82L0E5GiR/g8hcSdNLiA7Y4VPhpLK2ObQHIEjA4Co/+CSazHyu26TsqiL2/2bn11U8ZzDX2IJoRbv8bgO5MrRmCEDzWzEulZ0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863575179750.6817861691366; Thu, 2 May 2019 23:06:15 -0700 (PDT) Received: from localhost ([127.0.0.1]:35144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRKj-00079G-6d for importer@patchew.org; Fri, 03 May 2019 02:06:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9J-0005Xi-Pz for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9H-0003BA-Ts for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:21 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:46057) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9H-00039B-N6; Fri, 03 May 2019 01:54:19 -0400 Received: by mail-pg1-x544.google.com with SMTP id i21so2180212pgi.12; Thu, 02 May 2019 22:54:18 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gtYREJ6wLh93MiaNJLpdXl6ZvqtubSybEdUbcIWsFl0=; b=trskbFfQefrhnK+Cjs5e1j/6cAjG4RZmdk3u3FYCGxANeGiqRBmZnQnCQbKTrzcSRX p+ArU1UzDRgJ1IHpqSfMTmpwRKReSLX+1XHxgvANKExOIF17AnHC/lckAt4+R/EKu5tk 7OTw18lmLXTKjszvsKSIbDs5TgjebVDAd0YsvPV7B/Ze9KnX8Dv/3Q9zjC8K9dVSEGY0 pre5iT5N8QDj9+uwIP2bSQEysYluhIjP0KLhiMKQdcYfvQpIcvx4x37H5DaZUFNYZ7FK qykHSl+N66+D6abCjLdle0WwPa9VBX5r21eGhsTrlFKkMUy+yqagU2R8GSbhegqRL7q0 dMwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gtYREJ6wLh93MiaNJLpdXl6ZvqtubSybEdUbcIWsFl0=; b=Mg+77HoEvb4xh9zKL+Prw2yi0CJYob9COYHJRM4Z3hFjeXd6etr5Nh1iW3NORALBhK ld1xRNk/82Mq12uzs91YZPFZjcZvhyr9amdggxdlDhdOv/kHN8Zh7n0FdEkd1LQxzB/j NLWgG7l7FXt8ADPbjwEzkdu/hxxm1WvQHkPgn8NX6NrlMszUNEeKCOcABcII8j9DzP/m YMK+fh8gFlhaEdG/ShvVz/EX19cFTFxr2r9ibL+X7czGzepAdBLeN/D2XZn76Q2RL2C8 /3NIxlb0dN6cg4U9DppbAkEMYbQvuEaZzmAOzQS9f0Pl4E/kef6LaUvbs7EMn3B9nBg2 9A7A== X-Gm-Message-State: APjAAAUfrKhpi5wNHptYc0I7jZmknv7uhGK1hQtaED1Qu5Am8HsOZaiP WOUxrsXKEBfidn2DFVjQbhQUXpOMgBI= X-Google-Smtp-Source: APXvYqwKLHECau+wOCXrfcfYSijLgBdqgF3WdrOFfHw1FnjUDAlavv2il/LNe9O5XieDoEBHo098Ug== X-Received: by 2002:a63:4714:: with SMTP id u20mr8224571pga.316.1556862857150; Thu, 02 May 2019 22:54:17 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:11 +1000 Message-Id: <20190503055316.6441-9-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 08/13] target/ppc: Implement hcall H_SET_PARTITION_TABLE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The hcall H_SET_PARTITION_TABLE is used by a guest acting as a nested hypervisor to register the partition table entry for one of its guests with the real hypervisor. Implement this hcall for a spapr guest. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr_hcall.c | 22 ++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 4d7fe337a1..704ceff8e1 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1828,6 +1828,25 @@ static target_ulong h_update_dt(PowerPCCPU *cpu, Spa= prMachineState *spapr, return H_SUCCESS; } =20 +static target_ulong h_set_partition_table(PowerPCCPU *cpu, + SpaprMachineState *spapr, + target_ulong opcode, + target_ulong *args) +{ + CPUPPCState *env =3D &cpu->env; + target_ulong ptcr =3D args[0]; + + if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) =3D=3D 0) { + return H_FUNCTION; + } + + if ((ptcr & PTCR_PATS) > 24) + return H_PARAMETER; + + env->spr[SPR_PTCR] =3D ptcr; + return H_SUCCESS; +} + static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1]; static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCA= LL_BASE + 1]; =20 @@ -1934,6 +1953,9 @@ static void hypercall_register_types(void) =20 spapr_register_hypercall(KVMPPC_H_UPDATE_DT, h_update_dt); =20 + /* Platform-specific hcalls used for nested HV KVM */ + spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table); + /* Virtual Processor Home Node */ spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY, h_home_node_associativity); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 4251215908..e591ee0ba0 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -501,7 +501,9 @@ struct SpaprMachineState { /* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2) #define KVMPPC_H_UPDATE_DT (KVMPPC_HCALL_BASE + 0x3) -#define KVMPPC_HCALL_MAX KVMPPC_H_UPDATE_DT +/* Platform-specific hcalls used for nested HV KVM */ +#define H_SET_PARTITION_TABLE 0xF800 +#define KVMPPC_HCALL_MAX H_SET_PARTITION_TABLE =20 typedef struct SpaprDeviceTreeUpdateHeader { uint32_t version_id; --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863665; cv=none; d=zoho.com; s=zohoarc; b=L/yKOKj/kGcsHgkdk6/MhPIE5efH/Z1uYnyjRaQr6dsh9+bMFdQ4VSxRpsSPzlHW41G5Eq/6+WzOtTJxU1A2/fCadGSd3h0qWrXZ6YUzUVNpE2gBOuIxVx8RRpd2gYrTltxiHDtf+kc4XegXTMng1zBYY7SPvifjcrec+iHMNi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863665; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WVKzTubn+fwCm8+EatH1HPYZd3qCwfmXk8iyRF28f6I=; b=bOQjrJp/P44bii7b8QclZtPcXgr/adzJad5igcvkKDl0ArZ3qgQFwFDbxjJyE0FbTHEiR4YK66DRY2r/vKL4FCCAKKl1bQGFEkSj6bShreRomecaJk3A0ogJ1xA5C1+ydwU79NTAo03zgslpJJCTt/nhD+Num2QzxY25t+TCxf0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863665163882.0312695414586; Thu, 2 May 2019 23:07:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:35169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRMD-0008Qz-1R for importer@patchew.org; Fri, 03 May 2019 02:07:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9O-0005cz-KD for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9M-0003Dh-9h for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:26 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:35332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9M-0003D4-0r; Fri, 03 May 2019 01:54:24 -0400 Received: by mail-pf1-x42c.google.com with SMTP id t87so1770194pfa.2; Thu, 02 May 2019 22:54:23 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WVKzTubn+fwCm8+EatH1HPYZd3qCwfmXk8iyRF28f6I=; b=eFR1n3PiP+zG5i9ZEZTy52GGaMrA4xyDfc5F5lpXP7RRbXzIK6FgEafxRjOCWXSFPV B6EvGne+vtt0PjNV/7J5TgX18W4a9QfSUbrUt3PNB+Nuynd1Tv4j080IwpgvV+lFPYnY 5XDiZI2ibxjAGuFTgR/r776MA12QP00P5wWS4g6Y/BkWj1k3iWSo65ST/rAzE3aCROZB mihIXvE/db00zX/9HuaSI4KntsxeeU9YTkJstQCK2PgjRao9CEuudWTJR3HRibsm5+eH cJGCcNlAwAHgUZ3ojJTz2RpH8XXte49v9kkKd4zQkxqVDxqQRzRJ29xo6L5GquauYxAZ WUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WVKzTubn+fwCm8+EatH1HPYZd3qCwfmXk8iyRF28f6I=; b=hFOXS/EpI0h88buMJc84ikbU8916cTqKJT40HszQQ3K8FX6lqMNGaO/JDUk8/UcUtc YfQiO+ff1pyIzCkkZ+5g8cPZUYkgaXf3swftluriLGYpT6j0KTVsSdTjQIo2VfN7Y52a O4rnHn75QQBnRnuLSfzSiZ7yy0FXMlachZ9P6Pla3eQkzpwHDnQA0hXpzHPqqMDdwIZz In7VE0x8RHINoUGrnatXj4mJpJyCOhZVW9gz4XzePnELnYimP6Y/449bpQcnVCemjuVI azq7j8vEXRUQdzJ3+4DVQaZycqbJ9PDIX4R2iLo9G73kAdRkVfA1NUnXp/65zsL96OrD UTUQ== X-Gm-Message-State: APjAAAX7w9FKvizoxi7Z77LOHnx4eQxQY4AGd/OVZPl/88RLNFLbj4ZT 1aZbM6Ov0pAsDRlwZcQNASaO+TZDYUE= X-Google-Smtp-Source: APXvYqzqWHDv0/ctB3M21d60dXgM8SgXMhdhrtOK1n65M9QT2D9yT1Z45C5tGpJIEndRkA64PiBF8w== X-Received: by 2002:a63:fd58:: with SMTP id m24mr8025283pgj.298.1556862862372; Thu, 02 May 2019 22:54:22 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:12 +1000 Message-Id: <20190503055316.6441-10-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42c Subject: [Qemu-devel] [QEMU-PPC] [PATCH 09/13] target/ppc: Implement hcall H_ENTER_NESTED X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The hcall H_ENTER_NESTED is used by a guest acting as a nested hypervisor to provide the state of one of its guests which it would like the real hypervisor to load onto the cpu and execute on its behalf. The hcall takes as arguments 2 guest real addresses which provide the location of a regs struct and a hypervisor regs struct which provide the values to use to execute the guest. These are loaded into the cpu state and then the function returns to continue tcg execution in the new context. When an interrupt requires us to context switch back we restore the old register values and save the cpu state back into the guest memory. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr_hcall.c | 285 +++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/ppc/spapr.h | 3 +- target/ppc/cpu.h | 55 +++++++++ target/ppc/excp_helper.c | 13 ++- 4 files changed, 353 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 704ceff8e1..68f3282214 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -16,6 +16,7 @@ #include "hw/ppc/spapr_ovec.h" #include "mmu-book3s-v3.h" #include "hw/mem/memory-device.h" +#include "hw/ppc/ppc.h" =20 static bool has_spr(PowerPCCPU *cpu, int spr) { @@ -1847,6 +1848,289 @@ static target_ulong h_set_partition_table(PowerPCCP= U *cpu, return H_SUCCESS; } =20 +static void byteswap_pt_regs(struct pt_regs *regs) +{ + target_ulong *addr =3D (target_ulong *) regs; + + for (; addr < ((target_ulong *) (regs + 1)); addr++) { + *addr =3D bswap64(*addr); + } +} + +static void byteswap_hv_regs(struct hv_guest_state *hr) +{ + hr->version =3D bswap64(hr->version); + hr->lpid =3D bswap32(hr->lpid); + hr->vcpu_token =3D bswap32(hr->vcpu_token); + hr->lpcr =3D bswap64(hr->lpcr); + hr->pcr =3D bswap64(hr->pcr); + hr->amor =3D bswap64(hr->amor); + hr->dpdes =3D bswap64(hr->dpdes); + hr->hfscr =3D bswap64(hr->hfscr); + hr->tb_offset =3D bswap64(hr->tb_offset); + hr->dawr0 =3D bswap64(hr->dawr0); + hr->dawrx0 =3D bswap64(hr->dawrx0); + hr->ciabr =3D bswap64(hr->ciabr); + hr->hdec_expiry =3D bswap64(hr->hdec_expiry); + hr->purr =3D bswap64(hr->purr); + hr->spurr =3D bswap64(hr->spurr); + hr->ic =3D bswap64(hr->ic); + hr->vtb =3D bswap64(hr->vtb); + hr->hdar =3D bswap64(hr->hdar); + hr->hdsisr =3D bswap64(hr->hdsisr); + hr->heir =3D bswap64(hr->heir); + hr->asdr =3D bswap64(hr->asdr); + hr->srr0 =3D bswap64(hr->srr0); + hr->srr1 =3D bswap64(hr->srr1); + hr->sprg[0] =3D bswap64(hr->sprg[0]); + hr->sprg[1] =3D bswap64(hr->sprg[1]); + hr->sprg[2] =3D bswap64(hr->sprg[2]); + hr->sprg[3] =3D bswap64(hr->sprg[3]); + hr->pidr =3D bswap64(hr->pidr); + hr->cfar =3D bswap64(hr->cfar); + hr->ppr =3D bswap64(hr->ppr); +} + +static void save_regs(PowerPCCPU *cpu, struct pt_regs *regs) +{ + CPUPPCState env =3D cpu->env; + int i; + + for (i =3D 0; i < 32; i++) + regs->gpr[i] =3D env.gpr[i]; + regs->nip =3D env.nip; + regs->msr =3D env.msr; + regs->ctr =3D env.ctr; + regs->link =3D env.lr; + regs->xer =3D env.xer; + regs->ccr =3D 0UL; + for (i =3D 0; i < 8; i++) + regs->ccr |=3D ((env.crf[i] & 0xF) << ((7 - i) * 4)); + regs->dar =3D env.spr[SPR_DAR]; + regs->dsisr =3D env.spr[SPR_DSISR]; +} + +static void save_hv_regs(PowerPCCPU *cpu, struct hv_guest_state *hv_regs) +{ + CPUPPCState env =3D cpu->env; + + hv_regs->lpid =3D env.spr[SPR_LPIDR]; + hv_regs->lpcr =3D env.spr[SPR_LPCR]; + hv_regs->pcr =3D env.spr[SPR_PCR]; + hv_regs->amor =3D env.spr[SPR_AMOR]; + hv_regs->dpdes =3D !!(env.pending_interrupts & (1 << PPC_INTERRUPT_DOO= RBELL)); + hv_regs->hfscr =3D env.spr[SPR_HFSCR]; + hv_regs->tb_offset =3D env.tb_env->tb_offset; + hv_regs->dawr0 =3D env.spr[SPR_DAWR]; + hv_regs->dawrx0 =3D env.spr[SPR_DAWRX]; + hv_regs->ciabr =3D env.spr[SPR_CIABR]; + hv_regs->purr =3D cpu_ppc_load_purr(&env); + hv_regs->spurr =3D cpu_ppc_load_purr(&env); + hv_regs->ic =3D env.spr[SPR_IC]; + hv_regs->vtb =3D cpu_ppc_load_vtb(&env); + hv_regs->hdar =3D env.spr[SPR_HDAR]; + hv_regs->hdsisr =3D env.spr[SPR_HDSISR]; + hv_regs->asdr =3D env.spr[SPR_ASDR]; + hv_regs->srr0 =3D env.spr[SPR_SRR0]; + hv_regs->srr1 =3D env.spr[SPR_SRR1]; + hv_regs->sprg[0] =3D env.spr[SPR_SPRG0]; + hv_regs->sprg[1] =3D env.spr[SPR_SPRG1]; + hv_regs->sprg[2] =3D env.spr[SPR_SPRG2]; + hv_regs->sprg[3] =3D env.spr[SPR_SPRG3]; + hv_regs->pidr =3D env.spr[SPR_BOOKS_PID]; + hv_regs->cfar =3D env.cfar; + hv_regs->ppr =3D env.spr[SPR_PPR]; +} + +static void restore_regs(PowerPCCPU *cpu, struct pt_regs regs) +{ + CPUPPCState *env =3D &cpu->env; + int i; + + for (i =3D 0; i < 32; i++) + env->gpr[i] =3D regs.gpr[i]; + env->nip =3D regs.nip; + ppc_store_msr(env, regs.msr); + env->ctr =3D regs.ctr; + env->lr =3D regs.link; + env->xer =3D regs.xer; + for (i =3D 0; i < 8; i++) + env->crf[i] =3D (regs.ccr >> ((7 - i) * 4)) & 0xF; + env->spr[SPR_DAR] =3D regs.dar; + env->spr[SPR_DSISR] =3D regs.dsisr; +} + +static void restore_hv_regs(PowerPCCPU *cpu, struct hv_guest_state hv_regs) +{ + CPUPPCState *env =3D &cpu->env; + target_ulong lpcr_mask =3D LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_AIL |= LPCR_LD + | LPCR_LPES0 | LPCR_LPES1 | LPCR_ME= R; + + env->spr[SPR_LPIDR] =3D hv_regs.lpid; + ppc_store_lpcr(cpu, (hv_regs.lpcr & lpcr_mask) | + (env->spr[SPR_LPCR] & ~lpcr_mask)); + env->spr[SPR_PCR] =3D hv_regs.pcr; + env->spr[SPR_AMOR] =3D hv_regs.amor; + if (hv_regs.dpdes) { + env->pending_interrupts |=3D 1 << PPC_INTERRUPT_DOORBELL; + cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); + } else { + env->pending_interrupts &=3D ~(1 << PPC_INTERRUPT_DOORBELL); + } + env->spr[SPR_HFSCR] =3D hv_regs.hfscr; + env->spr[SPR_DAWR] =3D hv_regs.dawr0; + env->spr[SPR_DAWRX] =3D hv_regs.dawrx0; + env->spr[SPR_CIABR] =3D hv_regs.ciabr; + cpu_ppc_store_purr(env, hv_regs.purr); /* for TCG PURR =3D=3D SPU= RR */ + env->spr[SPR_IC] =3D hv_regs.ic; + cpu_ppc_store_vtb(env, hv_regs.vtb); + env->spr[SPR_HDAR] =3D hv_regs.hdar; + env->spr[SPR_HDSISR] =3D hv_regs.hdsisr; + env->spr[SPR_ASDR] =3D hv_regs.asdr; + env->spr[SPR_SRR0] =3D hv_regs.srr0; + env->spr[SPR_SRR1] =3D hv_regs.srr1; + env->spr[SPR_SPRG0] =3D hv_regs.sprg[0]; + env->spr[SPR_SPRG1] =3D hv_regs.sprg[1]; + env->spr[SPR_SPRG2] =3D hv_regs.sprg[2]; + env->spr[SPR_SPRG3] =3D hv_regs.sprg[3]; + env->spr[SPR_BOOKS_PID] =3D hv_regs.pidr; + env->cfar =3D hv_regs.cfar; + env->spr[SPR_PPR] =3D hv_regs.ppr; + tlb_flush(CPU(cpu)); +} + +static void sanitise_hv_regs(PowerPCCPU *cpu, struct hv_guest_state *hv_re= gs) +{ + CPUPPCState env =3D cpu->env; + + /* Apply more restrictive set of facilities */ + hv_regs->hfscr &=3D ((0xFFUL << 56) | env.spr[SPR_HFSCR]); + + /* Don't match on hypervisor address */ + hv_regs->dawrx0 &=3D ~(1UL << 2); + + /* Don't match on hypervisor address */ + if ((hv_regs->ciabr & 0x3) =3D=3D 0x3) + hv_regs->ciabr &=3D ~0x3UL; +} + +static inline bool needs_byteswap(const CPUPPCState *env) +{ +#if defined(HOST_WORDS_BIGENDIAN) + return msr_le; +#else + return !msr_le; +#endif +} + +static target_ulong h_enter_nested(PowerPCCPU *cpu, SpaprMachineState *spa= pr, + target_ulong opcode, target_ulong *args) +{ + CPUPPCState *env =3D &cpu->env; + env->hv_ptr =3D args[0]; + env->regs_ptr =3D args[1]; + uint64_t hdec; + + assert(env->spr[SPR_LPIDR] =3D=3D 0); + + if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) =3D=3D 0) { + return H_FUNCTION; + } + + if (!env->has_hv_mode || !ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_= 00, 0, + spapr->max_compat_pvr) + || !ppc64_v3_radix(cpu)) { + error_report("pseries guest support only implemented for POWER9 ra= dix\n"); + return H_HARDWARE; + } + + if (!env->spr[SPR_PTCR]) + return H_NOT_AVAILABLE; + + memset(&env->l1_saved_hv, 0, sizeof(env->l1_saved_hv)); + memset(&env->l1_saved_regs, 0, sizeof(env->l1_saved_regs)); + + /* load l2 state from l1 memory */ + cpu_physical_memory_read(env->hv_ptr, &env->l2_hv, sizeof(env->l2_hv)); + if (needs_byteswap(env)) { + byteswap_hv_regs(&env->l2_hv); + } + if (env->l2_hv.version !=3D 1) + return H_P2; + if (env->l2_hv.lpid =3D=3D 0) + return H_P2; + if (!(env->l2_hv.lpcr & LPCR_HR)) { + error_report("pseries guest support only implemented for POWER9 ra= dix guests\n"); + return H_P2; + } + + cpu_physical_memory_read(env->regs_ptr, &env->l2_regs, sizeof(env->l2_= regs)); + if (needs_byteswap(env)) { + byteswap_pt_regs(&env->l2_regs); + } + + /* save l1 values of things */ + save_regs(cpu, &env->l1_saved_regs); + save_hv_regs(cpu, &env->l1_saved_hv); + + /* adjust for timebase */ + hdec =3D env->l2_hv.hdec_expiry - cpu_ppc_load_tbl(env); + env->tb_env->tb_offset +=3D env->l2_hv.tb_offset; + /* load l2 values of things */ + sanitise_hv_regs(cpu, &env->l2_hv); + restore_regs(cpu, env->l2_regs); + env->msr &=3D ~MSR_HVB; + restore_hv_regs(cpu, env->l2_hv); + cpu_ppc_store_hdecr(env, hdec); + + assert(env->spr[SPR_LPIDR] !=3D 0); + + return env->gpr[3]; +} + +void h_exit_nested(PowerPCCPU *cpu) +{ + CPUPPCState *env =3D &cpu->env; + uint64_t delta_purr, delta_ic, delta_vtb; + target_ulong trap =3D env->nip; + + assert(env->spr[SPR_LPIDR] !=3D 0); + + /* save l2 values of things */ + if (trap =3D=3D 0x100 || trap =3D=3D 0x200 || trap =3D=3D 0xc00) { + env->nip =3D env->spr[SPR_SRR0]; + env->msr =3D env->spr[SPR_SRR1]; + } else { + env->nip =3D env->spr[SPR_HSRR0]; + env->msr =3D env->spr[SPR_HSRR1]; + } + save_regs(cpu, &env->l2_regs); + delta_purr =3D cpu_ppc_load_purr(env) - env->l2_hv.purr; + delta_ic =3D env->spr[SPR_IC] - env->l2_hv.ic; + delta_vtb =3D cpu_ppc_load_vtb(env) - env->l2_hv.vtb; + save_hv_regs(cpu, &env->l2_hv); + + /* restore l1 state */ + restore_regs(cpu, env->l1_saved_regs); + env->tb_env->tb_offset =3D env->l1_saved_hv.tb_offset; + env->l1_saved_hv.purr +=3D delta_purr; + env->l1_saved_hv.ic +=3D delta_ic; + env->l1_saved_hv.vtb +=3D delta_vtb; + restore_hv_regs(cpu, env->l1_saved_hv); + + /* save l2 state back to l1 memory */ + if (needs_byteswap(env)) { + byteswap_hv_regs(&env->l2_hv); + byteswap_pt_regs(&env->l2_regs); + } + cpu_physical_memory_write(env->hv_ptr, &env->l2_hv, sizeof(env->l2_hv)= ); + cpu_physical_memory_write(env->regs_ptr, &env->l2_regs, sizeof(env->l2= _regs)); + + assert(env->spr[SPR_LPIDR] =3D=3D 0); + + env->gpr[3] =3D trap; +} + static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1]; static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCA= LL_BASE + 1]; =20 @@ -1955,6 +2239,7 @@ static void hypercall_register_types(void) =20 /* Platform-specific hcalls used for nested HV KVM */ spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table); + spapr_register_hypercall(H_ENTER_NESTED, h_enter_nested); =20 /* Virtual Processor Home Node */ spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY, diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index e591ee0ba0..7083dea9ef 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -503,7 +503,8 @@ struct SpaprMachineState { #define KVMPPC_H_UPDATE_DT (KVMPPC_HCALL_BASE + 0x3) /* Platform-specific hcalls used for nested HV KVM */ #define H_SET_PARTITION_TABLE 0xF800 -#define KVMPPC_HCALL_MAX H_SET_PARTITION_TABLE +#define H_ENTER_NESTED 0xF804 +#define KVMPPC_HCALL_MAX H_ENTER_NESTED =20 typedef struct SpaprDeviceTreeUpdateHeader { uint32_t version_id; diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 3acc248f40..426015c9cd 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -982,6 +982,54 @@ struct ppc_radix_page_info { #define PPC_CPU_OPCODES_LEN 0x40 #define PPC_CPU_INDIRECT_OPCODES_LEN 0x20 =20 +struct pt_regs { + target_ulong gpr[32]; + target_ulong nip; + target_ulong msr; + target_ulong orig_gpr3; + target_ulong ctr; + target_ulong link; + target_ulong xer; + target_ulong ccr; + target_ulong softe; + target_ulong trap; + target_ulong dar; + target_ulong dsisr; + target_ulong result; +}; + +struct hv_guest_state { + uint64_t version; /* version of this structure layout */ + uint32_t lpid; + uint32_t vcpu_token; + /* These registers are hypervisor privileged (at least for writing) */ + uint64_t lpcr; + uint64_t pcr; + uint64_t amor; + uint64_t dpdes; + uint64_t hfscr; + int64_t tb_offset; + uint64_t dawr0; + uint64_t dawrx0; + uint64_t ciabr; + uint64_t hdec_expiry; + uint64_t purr; + uint64_t spurr; + uint64_t ic; + uint64_t vtb; + uint64_t hdar; + uint64_t hdsisr; + uint64_t heir; + uint64_t asdr; + /* These are OS privileged but need to be set late in guest entry */ + uint64_t srr0; + uint64_t srr1; + uint64_t sprg[4]; + uint64_t pidr; + uint64_t cfar; + uint64_t ppr; +}; + struct CPUPPCState { /* First are the most commonly used resources * during translated code execution @@ -1184,6 +1232,11 @@ struct CPUPPCState { uint32_t tm_vscr; uint64_t tm_dscr; uint64_t tm_tar; + + /* used to store register state when running a nested kvm guest */ + target_ulong hv_ptr, regs_ptr; + struct hv_guest_state l2_hv, l1_saved_hv; + struct pt_regs l2_regs, l1_saved_regs; }; =20 #define SET_FIT_PERIOD(a_, b_, c_, d_) \ @@ -2647,4 +2700,6 @@ static inline ppc_avr_t *cpu_avr_ptr(CPUPPCState *env= , int i) void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env); =20 void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len); + +void h_exit_nested(PowerPCCPU *cpu); #endif /* PPC_CPU_H */ diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 10091d4624..9470c02512 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -347,7 +347,7 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int ex= cp_model, int excp) env->nip +=3D 4; =20 /* "PAPR mode" built-in hypercall emulation */ - if ((lev =3D=3D 1) && cpu->vhyp) { + if ((lev =3D=3D 1) && (cpu->vhyp && (env->spr[SPR_LPIDR] =3D=3D 0)= )) { PPCVirtualHypervisorClass *vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); vhc->hypercall(cpu->vhyp, cpu); @@ -664,7 +664,7 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int ex= cp_model, int excp) env->spr[srr1] =3D msr; =20 /* Sanity check */ - if (!(env->msr_mask & MSR_HVB)) { + if (!(env->msr_mask & MSR_HVB) && (env->spr[SPR_LPIDR] =3D=3D 0)) { if (new_msr & MSR_HVB) { cpu_abort(cs, "Trying to deliver HV exception (MSR) %d with " "no HV support\n", excp); @@ -770,6 +770,15 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int e= xcp_model, int excp) /* Reset the reservation */ env->reserve_addr =3D -1; =20 + if ((!(env->msr_mask & MSR_HVB) && (new_msr & MSR_HVB))) { + /* + * We were in a guest, but this interrupt is setting the MSR[HV] b= it + * meaning we want to handle this at l1. Call h_exit_nested to con= text + * switch back. + */ + h_exit_nested(cpu); + } + /* Any interrupt is context synchronizing, check if TCG TLB * needs a delayed flush on ppc64 */ --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863318; cv=none; d=zoho.com; s=zohoarc; b=Sby+paB2qhN0xshF4tpilxkKm297bPqRu/WgoY1/qapW7Vs1lYyw7I/ZevcRzkGDPLZMdZ281ZJrfYz7Jb1pMvEzQT3Aqvc3lsceZ2MOQeBdhzjBuH8Hjr/4Pv9YAseB9vm+nnZz8mM6QetSDhheLIt60fGG9ao8dCjxF4EpXuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863318; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JdwoaU5GV525JDI8/HF+XmgK9OOCinXikocReCcBxn4=; b=UX/oke0wMMSmgb2MgfGW1xmytp6PeEW/5LEm8+chDu0pyMtZGpZgJtaQck0F38QFmyzUP13qKKO4CS8VdmO8u+uLgcJlT6B3l1jhtOD0T3aA177uL3VtS4nNk6Oi5HHNmjezVB1QLSnLrImn7YOini4LOoFPIilwxzzL9jUKwYA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863318051321.1266986480408; Thu, 2 May 2019 23:01:58 -0700 (PDT) Received: from localhost ([127.0.0.1]:35077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRGa-0003xW-Tt for importer@patchew.org; Fri, 03 May 2019 02:01:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9R-0005fU-2H for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9Q-0003Gq-1J for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:29 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:45257) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9P-0003Gb-S0; Fri, 03 May 2019 01:54:27 -0400 Received: by mail-pf1-x443.google.com with SMTP id e24so2329331pfi.12; Thu, 02 May 2019 22:54:27 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JdwoaU5GV525JDI8/HF+XmgK9OOCinXikocReCcBxn4=; b=qApfJgqs8EpXqJRftrYvr5Ti9d0x/7e92xEzsVrMCFwax9zYcWfJRR9Ak6BqinjpJV DTVWQeUJEGFB2+6oENOrOc9pSnArvvfeARzx2iBcVGSzqO1es/jmpGd2iSHNb42axjoV OMO9J1qSgWvbi3YgSTo8tONv/2G/kzHA2f6UJ3guUtx8KsCX//IjPEtneTy6vnK7GTiG HcCCQjHaPnDq2X8LSsbLVU8ORqFjCByVQsvskvWnBrEI5a43D7lNuIKinOhbqTikVG5R H8+rKwo35dAziXqFaRqrwUA92Wvd7fRMgUUHBCaYyDP3wu9JAmmKhIh3qJGON1+TIbGS T0Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JdwoaU5GV525JDI8/HF+XmgK9OOCinXikocReCcBxn4=; b=ObkGcNEgVc5S6RTT+P4lyTZ0Lk/HDlLssQJP3GVgoAoPXLcOTJfDfp4O5Rd0c9BiG8 L6XP1xfEBEnahgCmGUfp+1c1hNgq76lehSrxZE7+d15GLkPbKdRI0H5pjmXymIhrR3ob dI/KeVX2vef4wwLh5gvNCg4UTrznHRbttQbYY4IeIMGTKPl0VF2Nz7tHYCt7DG/6djuL soTy61lj9LitmZsUMmF6NOhBl4t+2r+UKS5zrIzDaYKLMEquYg3CJOfffihaexojyrME G40a1cJGDn7ydWggb55d8FLV8/Z6/nQOjkYNQVHolCKLobHdUd9geFCaTJkJEJOqT7hA rUhw== X-Gm-Message-State: APjAAAWOmQrItqmNXHrfBu5jNxqAQAqLA0yAfWFx1+oRAcNt//F21HSK MNwSEp7Vo7lzX+0B+yoatqSUihLV1LA= X-Google-Smtp-Source: APXvYqwSscdK1Ak4kgItbXamj3Q6FloJ5nr0fg9Ug3RWgZhmeCrjKOAjOQQwIacS0gU9Nmjr+7sdNA== X-Received: by 2002:a62:5885:: with SMTP id m127mr8587947pfb.33.1556862866867; Thu, 02 May 2019 22:54:26 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:13 +1000 Message-Id: <20190503055316.6441-11-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 10/13] target/ppc: Implement hcall H_TLB_INVALIDATE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The hcall H_TLB_INVALIDATE is used by a guest acting as a nested hypervisor to perform partition scoped tlb invalidation since these instructions are hypervisor privileged. Check the arguments are valid and then invalidate the entire tlb since this is about all we can do in tcg. Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson --- hw/ppc/spapr_hcall.c | 28 ++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 68f3282214..a84d5e2163 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -2131,6 +2131,33 @@ void h_exit_nested(PowerPCCPU *cpu) env->gpr[3] =3D trap; } =20 +static target_ulong h_nested_tlb_invalidate(PowerPCCPU *cpu, + SpaprMachineState *spapr, + target_ulong opcode, + target_ulong *args) +{ + target_ulong instr =3D args[0]; + target_ulong rbval =3D args[2]; + int r, ric, prs, is; + + if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) =3D=3D 0) { + return H_FUNCTION; + } + + ric =3D (instr >> 18) & 0x3; + prs =3D (instr >> 17) & 0x1; + r =3D (instr >> 16) & 0x1; + is =3D (rbval >> 10) & 0x3; + + if ((!r) || (prs) || (ric =3D=3D 3) || (is =3D=3D 1) || ((!is) && (ric= =3D=3D 1 || + ric =3D=3D = 2))) + return H_PARAMETER; + + /* Invalidate everything, not much else we can do */ + cpu->env.tlb_need_flush =3D TLB_NEED_GLOBAL_FLUSH | TLB_NEED_LOCAL_FLU= SH; + return H_SUCCESS; +} + static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1]; static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCA= LL_BASE + 1]; =20 @@ -2240,6 +2267,7 @@ static void hypercall_register_types(void) /* Platform-specific hcalls used for nested HV KVM */ spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table); spapr_register_hypercall(H_ENTER_NESTED, h_enter_nested); + spapr_register_hypercall(H_TLB_INVALIDATE, h_nested_tlb_invalidate); =20 /* Virtual Processor Home Node */ spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY, diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 7083dea9ef..6a614c445f 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -504,7 +504,8 @@ struct SpaprMachineState { /* Platform-specific hcalls used for nested HV KVM */ #define H_SET_PARTITION_TABLE 0xF800 #define H_ENTER_NESTED 0xF804 -#define KVMPPC_HCALL_MAX H_ENTER_NESTED +#define H_TLB_INVALIDATE 0xF808 +#define KVMPPC_HCALL_MAX H_TLB_INVALIDATE =20 typedef struct SpaprDeviceTreeUpdateHeader { uint32_t version_id; --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863226; cv=none; d=zoho.com; s=zohoarc; b=ARNjWA/gHFyMUdCCkutnFkyusfiL48JFCvYvYiC/m+YHOwe8g4PVU71EXKl+VkbFDaCP0/QnnorLq5sNkcv5WBPrMWHupfgrSbTc2aUn6rQM8j2Zed00z8K5AHEKcUvs6zT5J74CG8dPoXV5b4qRur5wIAohlh9Onu0Wo461XrI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863226; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=elRKXRVfoRQF6uK9NfqLi1F1+jjT6vwp9JP7+Qj3qL8=; b=e3Ut1I3ZMcmwdqQODJAt37u2gpYpxylhPXBzZUco4YHG0iV0LfxO61/AWu0c+dGt9DvT2tLDBJYAGSvhK0ztKQHowPNsBSJaRKn0hV3dNwjhXbnYFreh8qm8wrRzKYGnkGUnTHgE8pLx1htXY+8CPo+wmzH7h+9HC9+8ClU9XXk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863226558909.0641666484586; Thu, 2 May 2019 23:00:26 -0700 (PDT) Received: from localhost ([127.0.0.1]:35027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRF8-0002Rj-CS for importer@patchew.org; Fri, 03 May 2019 02:00:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9W-0005lI-H2 for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9V-0003P4-84 for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:34 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:44364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9U-0003Nt-Uw; Fri, 03 May 2019 01:54:33 -0400 Received: by mail-pf1-x443.google.com with SMTP id y13so2338099pfm.11; Thu, 02 May 2019 22:54:32 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=elRKXRVfoRQF6uK9NfqLi1F1+jjT6vwp9JP7+Qj3qL8=; b=m7GuNIGIkKmPcpaO9FwVC6S1nQRAN7bQfY8NDbSNfT64HO5rAlBsJ0tYIsFmWU9ThS x8gzYQUn5vwPU8xQ5cOLsC3cUsgSx7ptPYZg58zYaQtlcQTGdviN82E+65loV63rNVCq JR01GuBG0A2xd/T8WE6nrZjGL8Y3psbosEEVl1xpuLQta0q6jK0yNQWLn6D8L2R/0ABq 4rEFIDYtUKEN4BxIRf0bNUFGLJWdiaOP7XKWhG/wYsB1G4JGwJvTpi90mXi4mVNMPs6T lxBJGlj6/ybsaoDQOPA6BI0xw1crIwHHGO1/ukheQAP+FLN2oOkEofjdkRfCcIS/hHAC n/DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=elRKXRVfoRQF6uK9NfqLi1F1+jjT6vwp9JP7+Qj3qL8=; b=RbAbeDmk6CMfJunIqTkhS/swuyOZ3NgRR5KvGquKcctPOnI1z2koxktxxIRBMlr3N8 s1LLlHxk73AIQfHCLZHzSwV/zam8BAWZw4INrilHJPU2qmwcOjSAtCOmiaoCHOANHOTx U/mOPV31z2MTxNmy/EBZqWCdY6rELTncTm98RmX34YTpqrbHXVChzVoxuRepB58dp+Sc x7t5/bqCDxEfI3xl9nhtZnrcyAFkT9joa+AdN7S16iWJ/g3wi2y7/XrrEK9aIAgLL1iA Wtr8EMwoR2AUaTp83xmk7IQ+RYYKokdw0c5Ix1FaTrQJmnLKrb/6nQJVCMxj2BwF2aKw ySPg== X-Gm-Message-State: APjAAAXS7l22NY+QdoMxsZ2njL8FUO7rtVY9Q7FlKH/KQ0JAkUawhbUJ 5fq4KTiyr1ftAinp2wOql2UVDtNi2GQ= X-Google-Smtp-Source: APXvYqxRGbomoas+YKP/qHC2eUqK27+bQfXvI5dGW0/u1FjoIgnpvW0o9FSpQyF0lZWGxOELDVZK2w== X-Received: by 2002:aa7:8c1a:: with SMTP id c26mr8485737pfd.25.1556862871882; Thu, 02 May 2019 22:54:31 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:14 +1000 Message-Id: <20190503055316.6441-12-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 11/13] target/ppc: Implement hcall H_COPY_TOFROM_GUEST X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The hcall H_COPY_TOFROM_GUEST of used by a guest acting as a nested hypervisor to access quadrants since quadrant access is hypervisor privileged. Translate the guest address to be accessed, map the memory and perform the access on behalf of the guest. If the parameters are invalid, the address can't be translated or the memory cannot be mapped then fail the access. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr_hcall.c | 74 ++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/ppc/spapr.h | 3 +- target/ppc/mmu-radix64.c | 7 ++--- target/ppc/mmu-radix64.h | 4 +++ 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index a84d5e2163..a370d70500 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -17,6 +17,7 @@ #include "mmu-book3s-v3.h" #include "hw/mem/memory-device.h" #include "hw/ppc/ppc.h" +#include "mmu-radix64.h" =20 static bool has_spr(PowerPCCPU *cpu, int spr) { @@ -2158,6 +2159,78 @@ static target_ulong h_nested_tlb_invalidate(PowerPCC= PU *cpu, return H_SUCCESS; } =20 +static target_ulong h_copy_tofrom_guest(PowerPCCPU *cpu, + SpaprMachineState *spapr, + target_ulong opcode, target_ulong = *args) +{ + target_ulong lpid =3D args[0]; + target_ulong pid =3D args[1]; + vaddr eaddr =3D args[2]; + target_ulong gp_to =3D args[3]; + target_ulong gp_from =3D args[4]; + target_ulong n =3D args[5]; + int is_load =3D !!gp_to; + void *from, *to; + int prot, psize; + hwaddr raddr, to_len, from_len; + + if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) =3D=3D 0) { + return H_FUNCTION; + } + + if ((gp_to && gp_from) || (!gp_to && !gp_from)) { + return H_PARAMETER; + } + + if (eaddr & (0xFFFUL << 52)) { + return H_PARAMETER; + } + + if (!lpid) { + return H_PARAMETER; + } + + /* Translate eaddr to raddr */ + if (ppc_radix64_xlate(cpu, eaddr, is_load, lpid, pid, 1, &raddr, &psiz= e, + &prot, 0)) { + return H_NOT_FOUND; + } + if (((raddr & ((1UL << psize) - 1)) + n) >=3D (1UL << psize)) { + return H_PARAMETER; + } + + if (is_load) { + gp_from =3D raddr; + } else { + gp_to =3D raddr; + } + + /* Map the memory regions and perform a memory copy */ + from =3D cpu_physical_memory_map(gp_from, &from_len, 0); + if (!from) { + return H_NOT_FOUND; + } + if (from_len < n) { + cpu_physical_memory_unmap(from, from_len, 0, 0); + return H_PARAMETER; + } + to =3D cpu_physical_memory_map(gp_to, &to_len, 1); + if (!to) { + cpu_physical_memory_unmap(from, from_len, 0, 0); + return H_PARAMETER; + } + if (to_len < n) { + cpu_physical_memory_unmap(from, from_len, 0, 0); + cpu_physical_memory_unmap(to, to_len, 1, 0); + return H_PARAMETER; + } + memcpy(to, from, n); + cpu_physical_memory_unmap(from, from_len, 0, n); + cpu_physical_memory_unmap(to, to_len, 1, n); + + return H_SUCCESS; +} + static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1]; static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCA= LL_BASE + 1]; =20 @@ -2268,6 +2341,7 @@ static void hypercall_register_types(void) spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table); spapr_register_hypercall(H_ENTER_NESTED, h_enter_nested); spapr_register_hypercall(H_TLB_INVALIDATE, h_nested_tlb_invalidate); + spapr_register_hypercall(H_COPY_TOFROM_GUEST, h_copy_tofrom_guest); =20 /* Virtual Processor Home Node */ spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY, diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 6a614c445f..d62f4108d4 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -505,7 +505,8 @@ struct SpaprMachineState { #define H_SET_PARTITION_TABLE 0xF800 #define H_ENTER_NESTED 0xF804 #define H_TLB_INVALIDATE 0xF808 -#define KVMPPC_HCALL_MAX H_TLB_INVALIDATE +#define H_COPY_TOFROM_GUEST 0xF80C +#define KVMPPC_HCALL_MAX H_COPY_TOFROM_GUEST =20 typedef struct SpaprDeviceTreeUpdateHeader { uint32_t version_id; diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 6118ad1b00..2a8147fc38 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -429,10 +429,9 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lp= id, ppc_v3_pate_t *pate) return true; } =20 -static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, - uint64_t lpid, uint64_t pid, bool relocation, - hwaddr *raddr, int *psizep, int *protp, - bool cause_excp) +int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, uint64_t lpid, + uint64_t pid, bool relocation, hwaddr *raddr, int *p= sizep, + int *protp, bool cause_excp) { CPUPPCState *env =3D &cpu->env; ppc_v3_pate_t pate; diff --git a/target/ppc/mmu-radix64.h b/target/ppc/mmu-radix64.h index 96228546aa..c0bbd5c332 100644 --- a/target/ppc/mmu-radix64.h +++ b/target/ppc/mmu-radix64.h @@ -66,6 +66,10 @@ static inline int ppc_radix64_get_prot_amr(PowerPCCPU *c= pu) (iamr & 0x1 ? 0 : PAGE_EXEC); } =20 +int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, uint64_t lpid, + uint64_t pid, bool relocation, hwaddr *raddr, int *p= sizep, + int *protp, bool cause_excp); + #endif /* TARGET_PPC64 */ =20 #endif /* CONFIG_USER_ONLY */ --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863146; cv=none; d=zoho.com; s=zohoarc; b=b5XLps/EsD8+/pwRRWt6POcJ6tgQNHQI9BaitLAMnT15gR2sFT7rkm8DDvOlnqmAWaYF+/Q0eCAfRg/jH1gUg/CUjaxKJhdNahgOJhmXA/Djo+PsDWp9stwfc/MssIdk2BRJMHCN/gidqoTfnxHSd5L8MvbqS+btV1cLNp+KLcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863146; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PRRyyHPMZqJcq6mFtbX00mmQicMI/diLMW9xGgUxrSg=; b=gn0HCahrEd+I2aFaXWQz7+lKVY0Q+iySFS7I9d3PC+3EuSrJu8wMtKt1ZwamS43nSjACd9uyFuDJrLUF4LVhPbsd0IcEP2RC7b/QuTgaUopPstafJ4+y+knUlYBhLdrlzzZyh/ipUUcQYLbDla/bYifHfdEyMa+sVj7eRA1o0uE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863146525973.7269716869088; Thu, 2 May 2019 22:59:06 -0700 (PDT) Received: from localhost ([127.0.0.1]:35005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRDq-0001Br-HP for importer@patchew.org; Fri, 03 May 2019 01:59:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9a-0005oY-4K for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9Z-0003Sq-7O for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:38 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:38775) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9Z-0003Sd-1t; Fri, 03 May 2019 01:54:37 -0400 Received: by mail-pf1-x444.google.com with SMTP id 10so2350712pfo.5; Thu, 02 May 2019 22:54:36 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PRRyyHPMZqJcq6mFtbX00mmQicMI/diLMW9xGgUxrSg=; b=ud9kmGZbKa7dfS2B58RkF+XraKDxgZYjM5EM54Qor7TJioEcSFgOpPQ0nqvIY1fGpa m9PQmb7BESi7M6PSVFEbGsNyX5g94NVzGRhPRYFjd3KSZQ9Rp+k0iw94Jr6vNx7h0FX8 9DGxDE5aHX3Rryu60nYckKrtHdVX2D8HFDLkFV6PSQrey+ZyfPl60EAqiCsUFcgrnd3w ItAqBpVjr/gubwdF18TCDUCSn2OtTi0jo0sBFxSWc8PdA4jS9q4TjEppbUI0Q2MIsm48 fOfZkQ/1NgNGRecd3o6EJvaf0kKfFY1LQM7DMP8h30fmcXGaz1pZKNtniZuT6JZYBgj/ u5EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PRRyyHPMZqJcq6mFtbX00mmQicMI/diLMW9xGgUxrSg=; b=fst1pb4HW5vscCJG/dRpfRNs9gVNh2Uz+w7CQ4jdGcSKEKlGXMeDXJLf076bEXdJiR 3EGHlsj+yIwpxbrUduEZ0QJ52sayfB7LjXeB8nLUlt3Q6YrZNY1MDWj0uEwSH8OaxP73 gUZd3Co1hpkANDVeOaTGI5Cy365AwR3/WcJGz9Igem8Rr8DHVoYh3mqrbVBFE6mwBw2V sNpW4B4HuPwZfZUf7/phTw2xbj7p5r5I8sAweThnBhpwqQJKxIW1OU3GgBj6m24j9NuF uA5vfSsvtpRV5qjHz3Bcp3NcUTjmdjpGhJbwaCwcVBm086fjgV6mTRqL3LYe8gCZkYos 2KsQ== X-Gm-Message-State: APjAAAXvCZvagq0fnOTmFyEU0UKm34JHRwCmcUQIVVv4l7huVQ2AwvdW FEe+3KloQnAVfjqPpvvKD9DeNvKduOU= X-Google-Smtp-Source: APXvYqy6Nh/VwdZ+tSpaHJgSes/MFeGOhabe3zf2d4zfs2kMxncBOXt5eeEctAvIng9hv2bcNTqmKg== X-Received: by 2002:a63:f809:: with SMTP id n9mr7941670pgh.201.1556862875973; Thu, 02 May 2019 22:54:35 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:15 +1000 Message-Id: <20190503055316.6441-13-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 12/13] target/ppc: Introduce POWER9 DD2.2 cpu type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce a POWER9 DD2.2 cpu type with pvr 0x004E1202. A DD2.2 POWER9 cpu type is needed to enable kvm for pseries tcg guests since it means they will use the H_ENTER_NESTED hcall to run a guest rather than trying the generic entry path which will fail. Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson --- hw/ppc/spapr_cpu_core.c | 1 + target/ppc/cpu-models.c | 2 ++ target/ppc/cpu-models.h | 1 + 3 files changed, 4 insertions(+) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 40e7010cf0..98d46c6edb 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -399,6 +399,7 @@ static const TypeInfo spapr_cpu_core_type_infos[] =3D { DEFINE_SPAPR_CPU_CORE_TYPE("power8nvl_v1.0"), DEFINE_SPAPR_CPU_CORE_TYPE("power9_v1.0"), DEFINE_SPAPR_CPU_CORE_TYPE("power9_v2.0"), + DEFINE_SPAPR_CPU_CORE_TYPE("power9_v2.2"), #ifdef CONFIG_KVM DEFINE_SPAPR_CPU_CORE_TYPE("host"), #endif diff --git a/target/ppc/cpu-models.c b/target/ppc/cpu-models.c index 7c75963e3c..603ae7f5b4 100644 --- a/target/ppc/cpu-models.c +++ b/target/ppc/cpu-models.c @@ -773,6 +773,8 @@ "POWER9 v1.0") POWERPC_DEF("power9_v2.0", CPU_POWERPC_POWER9_DD20, POWER= 9, "POWER9 v2.0") + POWERPC_DEF("power9_v2.2", CPU_POWERPC_POWER9_DD22, POWER= 9, + "POWER9 v2.2") #endif /* defined (TARGET_PPC64) */ =20 /*************************************************************************= **/ diff --git a/target/ppc/cpu-models.h b/target/ppc/cpu-models.h index efdb2fa53c..820e94b0c8 100644 --- a/target/ppc/cpu-models.h +++ b/target/ppc/cpu-models.h @@ -373,6 +373,7 @@ enum { CPU_POWERPC_POWER9_BASE =3D 0x004E0000, CPU_POWERPC_POWER9_DD1 =3D 0x004E0100, CPU_POWERPC_POWER9_DD20 =3D 0x004E1200, + CPU_POWERPC_POWER9_DD22 =3D 0x004E1202, CPU_POWERPC_970_v22 =3D 0x00390202, CPU_POWERPC_970FX_v10 =3D 0x00391100, CPU_POWERPC_970FX_v20 =3D 0x003C0200, --=20 2.13.6 From nobody Wed May 15 01:16:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556863486; cv=none; d=zoho.com; s=zohoarc; b=OaqOxTZFzShGeuahcqWLKdO9ETBbwpWmuNqD7wGFTIK1vmewjEf5NH913BtEcwn2acXvdODHG/Vldt4EdSj7wfxVtmOIwQ/ZH/fHEuCtQuNZEQ6T38yPCDpQ6MHjrx3YeJ0wVrMPIfBamxoGFN32NHvjsUe3PjY4IieNLL0qMmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556863486; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=iRgrjuJWAeNPPmfwJhAiW5ZkTsvnUdrbfqd5lYY/Gao=; b=h6CnB3zqB4i0wsuY2zEaeFoTwCzEJEItPyBo2RujJUjPyfXJc5yIbMYp4G17zSN6IwcQb//qnKFDzYjqPlVNVSxqwsjo+CUX5PzMlyRDZ4bv79L/KorWic37ifEMCe842DovClEXICyuT5oH17s8/CYbjcoI+AfpvVtVSM6Cn2U= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556863486993457.3650671500775; Thu, 2 May 2019 23:04:46 -0700 (PDT) Received: from localhost ([127.0.0.1]:35099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMRJK-0005yp-1I for importer@patchew.org; Fri, 03 May 2019 02:04:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMR9e-0005tB-Jh for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMR9d-0003UC-IB for qemu-devel@nongnu.org; Fri, 03 May 2019 01:54:42 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:33476) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMR9d-0003Tu-Cd; Fri, 03 May 2019 01:54:41 -0400 Received: by mail-pf1-x443.google.com with SMTP id z28so2361384pfk.0; Thu, 02 May 2019 22:54:41 -0700 (PDT) Received: from localhost.ibm.com ([1.129.142.217]) by smtp.gmail.com with ESMTPSA id h187sm1292983pfc.52.2019.05.02.22.54.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 22:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iRgrjuJWAeNPPmfwJhAiW5ZkTsvnUdrbfqd5lYY/Gao=; b=J6MWrrGNtXMEAyyLNtz2wxWmsJYN/EMNmQKK1zxdLiWWWgRhchYdhypyJtZ/enyrGf uYcpvK058DCyLnICTItewfkVEqMQRVRuquA130/1MX2JRWtfpDGVXTEArm8MZcj/5nyV iHwWhafVbP92A195FnIK0H+286k5n5oB4Pi6KQodPR649zElWuG0EZEH2ZAvJcQgA4F3 C804Yjr3WruWdO25WyY8wDPhYY1JyBFqSXLrHYdvvvp+u7v7LZmD4xaBkt2ZmmkY67uZ GaSwc4jqDV+HX7cLb+OOHluaIhz52yyQP0m5hO41pD+tLm00jtyacWOE5Q56CuH/FSPK OcGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iRgrjuJWAeNPPmfwJhAiW5ZkTsvnUdrbfqd5lYY/Gao=; b=hXAnRPMoWL2MVLKNsqPf7boComPXSJUyj4IspBMEypjpcMhE1Gaad2JaRQ8JEVYB+Y 6as9k6uMpZEnKsfuFPh4luRw1+hvB+YFuhIgBxk8rAGRiEmMaFo0LFFw/aqj8WXlBagU zn1EbtVshZuqT5qCv7TAuOIX7NMKoC2efMsqcsteBW/+ZHlZ/6if5dHw2BykAvyTu1kc Xd6r1eLIqgIh7B3RSV1wRWRaKL3NUzp83gsktOrJtko5UtZyEpkAgz02ZVYqw0djZPrZ sATIPbnLbB6M1C6tJ2joRHo4GI/NZndt6HaPmP5lPfL5hnFIbeCguTFSOW1+tXKrYeoD dgUg== X-Gm-Message-State: APjAAAWtrQPKkUpjCgQDo9VyYPMR4jsRbrfwsp4cc/uiL/6uhWu/hdjG QX5B1Ba7vv9/Q4zM2WW7KwZkybsxMjI= X-Google-Smtp-Source: APXvYqxFzLNfjlVGTT7FMlUfUDWgfYOsYKnCqqiXjmNRzcwjZTwOyRF298YUrILqk/ft8qsmqCWGIg== X-Received: by 2002:a63:1d4f:: with SMTP id d15mr7840690pgm.347.1556862880285; Thu, 02 May 2019 22:54:40 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Fri, 3 May 2019 15:53:16 +1000 Message-Id: <20190503055316.6441-14-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190503055316.6441-1-sjitindarsingh@gmail.com> References: <20190503055316.6441-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 13/13] target/ppc: Enable SPAPR_CAP_NESTED_KVM_HV under tcg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is now possible to use nested kvm-hv under tcg, thus allow for it to be enabled. Note that nested kvm-hv requires that rc updates to ptes be done by software, otherwise the page tables get out of sync. So disable hardware rc updates when nested kvm-hv is enabled. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr_caps.c | 22 ++++++++++++++++++---- target/ppc/cpu.h | 1 + target/ppc/mmu-radix64.c | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 3278c09b0f..7fe07d83dd 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -389,10 +389,7 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState = *spapr, return; } =20 - if (tcg_enabled()) { - error_setg(errp, - "No Nested KVM-HV support in tcg, try cap-nested-hv=3Do= ff"); - } else if (kvm_enabled()) { + if (kvm_enabled()) { if (!kvmppc_has_cap_nested_kvm_hv()) { error_setg(errp, "KVM implementation does not support Nested KVM-HV, try cap-nested-hv=3Dof= f"); @@ -400,6 +397,22 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState = *spapr, error_setg(errp, "Error enabling cap-nested-hv with KVM, try cap-nested-hv=3Doff"); } + } /* else { nothing required for tcg } */ +} + +static void cap_nested_kvm_hv_cpu_apply(SpaprMachineState *spapr, + PowerPCCPU *cpu, + uint8_t val, Error **errp) +{ + CPUPPCState *env =3D &cpu->env; + + if (tcg_enabled() && val) { + if (env->spr[SPR_PVR] !=3D 0x004E1202) { + error_setg(errp, "Nested KVM-HV only supported on POWER9 DD2.2= , " + "try cap-nested-hv=3Doff or -cpu power9_v2.2"= ); + return; + } + env->disable_hw_rc_updates =3D true; } } =20 @@ -544,6 +557,7 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D= { .set =3D spapr_cap_set_bool, .type =3D "bool", .apply =3D cap_nested_kvm_hv_apply, + .cpu_apply =3D cap_nested_kvm_hv_cpu_apply, }, [SPAPR_CAP_LARGE_DECREMENTER] =3D { .name =3D "large-decr", diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 426015c9cd..6502e0de82 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1237,6 +1237,7 @@ struct CPUPPCState { target_ulong hv_ptr, regs_ptr; struct hv_guest_state l2_hv, l1_saved_hv; struct pt_regs l2_regs, l1_saved_regs; + bool disable_hw_rc_updates; }; =20 #define SET_FIT_PERIOD(a_, b_, c_, d_) \ diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 2a8147fc38..cc06967dbe 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -31,9 +31,9 @@ static inline bool ppc_radix64_hw_rc_updates(CPUPPCState *env) { #ifdef CONFIG_ATOMIC64 - return true; + return !env->disable_hw_rc_updates; #else - return !qemu_tcg_mttcg_enabled(); + return !qemu_tcg_mttcg_enabled() && !env->disable_hw_rc_updates; #endif } =20 --=20 2.13.6