From patchwork Fri Jan 29 06:42:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 8159581 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E1EB4BEEE5 for ; Fri, 29 Jan 2016 06:43:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 329972037E for ; Fri, 29 Jan 2016 06:43:37 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 5C90F20340 for ; Fri, 29 Jan 2016 06:43:36 +0000 (UTC) Received: from localhost ([::1]:60246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP2mN-0001jE-EB for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Jan 2016 01:43:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP2kV-0006cS-EQ for qemu-devel@nongnu.org; Fri, 29 Jan 2016 01:41:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aP2kS-0000Sl-2e for qemu-devel@nongnu.org; Fri, 29 Jan 2016 01:41:39 -0500 Received: from ozlabs.org ([103.22.144.67]:44597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP2kR-0000SH-O1; Fri, 29 Jan 2016 01:41:36 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 668FA140C5D; Fri, 29 Jan 2016 17:41:32 +1100 (AEDT) From: David Gibson To: benh@kernel.crashing.org, paulus@samba.org, aik@ozlabs.ru Date: Fri, 29 Jan 2016 17:42:24 +1100 Message-Id: <1454049744-19131-7-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454049744-19131-1-git-send-email-david@gibson.dropbear.id.au> References: <1454049744-19131-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 103.22.144.67 Cc: lvivier@redhat.com, thuth@redhat.com, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, agraf@suse.de, qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [RFCv2 6/6] pseries: Use smaller default hash page tables when guest can resize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We've now implemented a PAPR extension allowing PAPR guest to resize their hash page table (HPT) during runtime. This patch makes use of that facility to allocate smaller HPTs by default. Specifically when a guest is aware of the HPT resize facility, qemu sizes the HPT to the initial memory size, rather than the maximum memory size on the assumption that the guest will resize its HPT if necessary for hot plugged memory. When the initial memory size is much smaller than the maximum memory size (a common configuration with e.g. oVirt / RHEV) then this can save significant memory on the HPT. If the guest does *not* advertise HPT resize awareness when it makes the ibm,client-architecture-support call, qemu resizes the HPT for maxmimum memory size (unless it's been configured not to allow such guests at all). For now we make that reallocation assuming the guest has not yet used the HPT at all. That's true in practice, but not, strictly, an architectural or PAPR requirement. If we need to in future we can fix this by having the client-architecture-support call reboot the guest with the revised HPT size (the client-architecture-support call is explicitly permitted to trigger a reboot in this way). Signed-off-by: David Gibson --- hw/ppc/spapr.c | 10 +++++++--- hw/ppc/spapr_hcall.c | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0d2759a..c7b3814 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1137,14 +1137,18 @@ static void ppc_spapr_reset(void) sPAPRMachineState *spapr = SPAPR_MACHINE(machine); PowerPCCPU *first_ppc_cpu; uint32_t rtas_limit; + int hpt_shift; /* Check for unknown sysbus devices */ foreach_dynamic_sysbus_device(find_unknown_sysbus_device, NULL); /* Allocate and/or reset the hash page table */ - spapr_reallocate_hpt(spapr, - spapr_hpt_shift_for_ramsize(machine->maxram_size), - &error_fatal); + if (spapr->resize_hpt == SPAPR_RESIZE_HPT_DISABLED) { + hpt_shift = spapr_hpt_shift_for_ramsize(machine->maxram_size); + } else { + hpt_shift = spapr_hpt_shift_for_ramsize(machine->ram_size); + } + spapr_reallocate_hpt(spapr, hpt_shift, &error_fatal); /* Update the RMA size if necessary */ if (spapr->vrma_adjust) { diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 2345196..b33c83d 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1160,12 +1160,14 @@ static void do_set_compat(void *arg) ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0) #define OV5_DRCONF_MEMORY 0x20 +#define OV5_HPT_RESIZE 0x80 static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { + MachineState *machine = MACHINE(spapr); target_ulong list = ppc64_phys_to_real(args[0]); target_ulong ov_table, ov5; PowerPCCPUClass *pcc_ = POWERPC_CPU_GET_CLASS(cpu_); @@ -1175,7 +1177,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, unsigned compat_lvl = 0, cpu_version = 0; unsigned max_lvl = get_compat_level(cpu_->max_compat); int counter; - char ov5_byte2; + char ov5_byte2, ov5_byte8; /* Parse PVR list */ for (counter = 0; counter < 512; ++counter) { @@ -1265,6 +1267,30 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, memory_update = true; } + ov5_byte8 = ldub_phys(&address_space_memory, ov5 + 8); + if (!(ov5_byte8 & OV5_HPT_RESIZE)) { + int maxshift = spapr_hpt_shift_for_ramsize(machine->maxram_size); + + if (spapr->resize_hpt == SPAPR_RESIZE_HPT_REQUIRED) { + error_report( + "h_client_architecture_support: Guest doesn't support HPT resizing with resize-hpt=required"); + exit(1); + } + + if (spapr->htab_shift < maxshift) { + CPUState *cs; + /* Guest doesn't know about HPT resizing, so we + * pre-emptively resize for the maximum permitted RAM. At + * the point this is called, nothing should have been + * entered into the existing HPT */ + spapr_reallocate_hpt(spapr, maxshift, &error_fatal); + CPU_FOREACH(cs) { + run_on_cpu(cs, pivot_hpt, cs); + } + cpu_update = true; + } + } + if (spapr_h_cas_compose_response(spapr, args[1], args[2], cpu_update, memory_update)) { qemu_system_reset_request();