From patchwork Tue Jan 9 09:21:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10151271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5E32C60223 for ; Tue, 9 Jan 2018 09:25:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 646481FE8D for ; Tue, 9 Jan 2018 09:25:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55FB0286C7; Tue, 9 Jan 2018 09:25:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C9FB31FE8D for ; Tue, 9 Jan 2018 09:25:10 +0000 (UTC) Received: from localhost ([::1]:40745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYq9d-0000fY-4T for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jan 2018 04:25:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYq65-0006RW-Ay for qemu-devel@nongnu.org; Tue, 09 Jan 2018 04:21:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYq64-0001L4-73 for qemu-devel@nongnu.org; Tue, 09 Jan 2018 04:21:29 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:36818) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eYq5y-00018f-Ct; Tue, 09 Jan 2018 04:21:22 -0500 Received: by mail-pg0-x243.google.com with SMTP id j2so6387545pgv.3; Tue, 09 Jan 2018 01:21:22 -0800 (PST) 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=qO15djiOOipVjoIG8GQWcpKdlXxw9oarjgBHu8+YLHc=; b=c6LNvI4ESVgacQqJVMjbd1a1G6Hehq1RjdpEtQNSdcKbHVPfTOF0npHoyaS+SfARim b8/3K7Hlw9fcTROEG44TSLAiLfJCINsE2Wv6SApBwSCoWzMgpVqVtRsKyvANp1XQtTi7 ZvLCIVbFRpKHYI8M79ilp/kmV/SZ3dK3YrsF2GmMoZyU6S75Nafevg7ZNRYZ+vp/zryT k5hwgFjw2USyeLE2gsVUzSB+MsJ8qymK1XpYnaBZCVRO8QhHgFztefFhjrrALDu5NkKH z03uJTvcz/fwIEo1yPrie6qZf6u1M6IuuoXSb/pBCjsuXuAIumipX3VvH6gNQ5UCOIZi hWIw== 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=qO15djiOOipVjoIG8GQWcpKdlXxw9oarjgBHu8+YLHc=; b=d4oSJ5IQ0qrl3weBlhPnXgZflc4o5Qq3cUw+kgB5tMo1yLsSnX5888MUhiAq3UKRZJ QscjY9pkLEq/ngncL3jGbK4Dj6Qr0p/os8f4r7ItS/tddLeV6UZUBaHyJm1+CZ24qmon d3WWc7FFwXe8YPqnTjow9LWbyzQUsxbztbDMz3O+Y9Evt2x5OYDKqTwzqqsh3Gen6ZJf SHNgrKVc0Auxuz5RGTTfHhQmkj+nyEx4Br+vakUH7WH3vw8IF0QdoRah7OJW76s+PcHE 3ShmIYF7otMbcdd6E/QKIvyQJpCfzC1g7r9oF90crsqVEbXIcEz4GQy6y0wlXe/gsBWM Smcw== X-Gm-Message-State: AKGB3mJCd+U5cElHoVgrLSXMLPKLp9ZbR9UBzyZdsws1rcsh4oRAsRRp tvJMaVTwbQjIeiES3WcqXGeVkvKt X-Google-Smtp-Source: ACJfBotI8A0AbT6lpoRcZKWYgqEMiVgvTKWdIULmA4k+wZvJ/bFOeb0gPVL4sdLVyE2haFg4zREqTQ== X-Received: by 10.99.126.84 with SMTP id o20mr5137768pgn.329.1515489681320; Tue, 09 Jan 2018 01:21:21 -0800 (PST) Received: from surajjs1.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id e79sm2611867pfl.61.2018.01.09.01.21.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 01:21:20 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Tue, 9 Jan 2018 20:21:03 +1100 Message-Id: <20180109092103.18458-4-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180109092103.18458-1-sjitindarsingh@gmail.com> References: <20180109092103.18458-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [QEMU-PPC] [RFC 3/3] target/ppc: Add H-Call H_GET_CPU_CHARACTERISTICS 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: paulus@ozlabs.org, qemu-devel@nongnu.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The new H-Call H_GET_CPU_CHARACTERISTICS is used by the guest to query behaviours and available characteristics of the cpu. Implement the handler for this new H-Call which formulates its response based on the setting of the new capabilities added in the previous patch. Note: Currently we return H_FUNCTION under TCG which will direct the guest to fall back to doing a displacement flush Discussion: Is TCG affected? Is there any point in telling the guest to do these workarounds on TCG given they're unlikely to translate to host instructions which have the desired effect? --- hw/ppc/spapr_hcall.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + 2 files changed, 82 insertions(+) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 51eba52e86..b62b47c8d9 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1654,6 +1654,84 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, return H_SUCCESS; } +#define CPU_CHARACTERISTIC_SPEC_BARRIER (1ULL << (63 - 0)) +#define CPU_CHARACTERISTIC_BCCTR_SERIAL (1ULL << (63 - 1)) +#define CPU_CHARACTERISTIC_ORI_L1_CACHE (1ULL << (63 - 2)) +#define CPU_CHARACTERISTIC_MTTRIG_L1_CACHE (1ULL << (63 - 3)) +#define CPU_CHARACTERISTIC_L1_CACHE_PRIV (1ULL << (63 - 4)) +#define CPU_CHARACTERISTIC_BRANCH_HINTS (1ULL << (63 - 5)) +#define CPU_CHARACTERISTIC_MTTRIG_THR_RECONF (1ULL << (63 - 6)) +#define CPU_BEHAVIOUR_FAVOUR_SECURITY (1ULL << (63 - 0)) +#define CPU_BEHAVIOUR_L1_CACHE_FLUSH (1ULL << (63 - 1)) +#define CPU_BEHAVIOUR_SPEC_BARRIER (1ULL << (63 - 2)) + +static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu, + sPAPRMachineState *spapr, + target_ulong opcode, + target_ulong *args) +{ + uint64_t characteristics = CPU_CHARACTERISTIC_BRANCH_HINTS; + uint64_t behaviour = CPU_BEHAVIOUR_FAVOUR_SECURITY; + uint8_t safe_cache = spapr_get_cap(spapr, SPAPR_CAP_CFPC); + uint8_t safe_bounds_check = spapr_get_cap(spapr, SPAPR_CAP_SBBC); + uint8_t safe_indirect_branch = spapr_get_cap(spapr, SPAPR_CAP_IBS); + + /* TODO: Is TCG vulnerable? */ + if (!kvm_enabled()) { + return H_FUNCTION; + } + + switch (safe_cache) { + case SPAPR_CAP_WORKAROUND: + characteristics |= CPU_CHARACTERISTIC_ORI_L1_CACHE; + characteristics |= CPU_CHARACTERISTIC_MTTRIG_L1_CACHE; + characteristics |= CPU_CHARACTERISTIC_L1_CACHE_PRIV; + behaviour |= CPU_BEHAVIOUR_L1_CACHE_FLUSH; + break; + case SPAPR_CAP_FIXED: + break; + default: /* broken */ + if (safe_cache != SPAPR_CAP_BROKEN) { + error_report("Invalid value for KVM_CAP_PPC_SAFE_CACHE (%d), assuming broken", + safe_cache); + } + behaviour |= CPU_BEHAVIOUR_L1_CACHE_FLUSH; + break; + } + + switch (safe_bounds_check) { + case SPAPR_CAP_WORKAROUND: + characteristics |= CPU_CHARACTERISTIC_SPEC_BARRIER; + behaviour |= CPU_BEHAVIOUR_SPEC_BARRIER; + break; + case SPAPR_CAP_FIXED: + break; + default: /* broken */ + if (safe_bounds_check != SPAPR_CAP_BROKEN) { + error_report("Invalid value for KVM_CAP_PPC_SAFE_BOUNDS_CHECK (%d), assuming broken", + safe_bounds_check); + } + behaviour |= CPU_BEHAVIOUR_SPEC_BARRIER; + break; + } + + switch (safe_indirect_branch) { + case SPAPR_CAP_FIXED: + characteristics |= CPU_CHARACTERISTIC_BCCTR_SERIAL; + default: /* broken */ + if (safe_indirect_branch != SPAPR_CAP_BROKEN) { + error_report("Invalid value for KVM_CAP_PPC_SAFE_INDIRECT_BRANCH (%d), assuming broken", + safe_indirect_branch); + } + break; + } + + args[0] = characteristics; + args[1] = behaviour; + + 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_HCALL_BASE + 1]; @@ -1733,6 +1811,9 @@ static void hypercall_register_types(void) spapr_register_hypercall(H_INVALIDATE_PID, h_invalidate_pid); spapr_register_hypercall(H_REGISTER_PROC_TBL, h_register_process_table); + /* hcall-get-cpu-characteristics */ + spapr_register_hypercall(H_GET_CPU_CHARACTERISTICS, h_get_cpu_characteristics); + /* "debugger" hcalls (also used by SLOF). Note: We do -not- differenciate * here between the "CI" and the "CACHE" variants, they will use whatever * mapping attributes qemu is using. When using KVM, the kernel will diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 2db2f3e2e2..5677c38d2a 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -396,6 +396,7 @@ struct sPAPRMachineState { #define H_GET_HCA_INFO 0x1B8 #define H_GET_PERF_COUNT 0x1BC #define H_MANAGE_TRACE 0x1C0 +#define H_GET_CPU_CHARACTERISTICS 0x1C8 #define H_FREE_LOGICAL_LAN_BUFFER 0x1D4 #define H_QUERY_INT_STATE 0x1E4 #define H_POLL_PENDING 0x1D8