From patchwork Fri Jan 12 14:34:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10161147 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 8306D60327 for ; Fri, 12 Jan 2018 14:35:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71660223C6 for ; Fri, 12 Jan 2018 14:35:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6600B287ED; Fri, 12 Jan 2018 14:35:55 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBADE223C6 for ; Fri, 12 Jan 2018 14:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934034AbeALOfx (ORCPT ); Fri, 12 Jan 2018 09:35:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45188 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933994AbeALOfv (ORCPT ); Fri, 12 Jan 2018 09:35:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A843FC05972B; Fri, 12 Jan 2018 14:35:46 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 718F37C152; Fri, 12 Jan 2018 14:35:35 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Huth , Christian Borntraeger , Cornelia Huck , David Hildenbrand Subject: [PATCH kvm-unit-tests v2 06/11] s390x: detect installed memory Date: Fri, 12 Jan 2018 15:34:12 +0100 Message-Id: <20180112143417.16743-7-david@redhat.com> In-Reply-To: <20180112143417.16743-1-david@redhat.com> References: <20180112143417.16743-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 12 Jan 2018 14:35:51 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unfortunately, there is no easy way to simply read out the amount of installed memory. We have to probe (via TEST PROTECTION) for installed memory in a given range. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 12 ++++++++++ lib/s390x/asm/interrupt.h | 1 + lib/s390x/interrupt.c | 11 +++++++++ lib/s390x/io.c | 1 + lib/s390x/sclp.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/sclp.h | 1 + s390x/Makefile | 1 + 7 files changed, 85 insertions(+) create mode 100644 lib/s390x/sclp.c diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index 72e5c60..ee4c96f 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -151,4 +151,16 @@ struct cpuid { uint64_t reserved : 15; }; +static inline int tprot(unsigned long addr) +{ + int cc; + + asm volatile( + " tprot 0(%1),0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc) : "a" (addr) : "cc"); + return cc; +} + #endif diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h index 41be039..3ccc8e3 100644 --- a/lib/s390x/asm/interrupt.h +++ b/lib/s390x/asm/interrupt.h @@ -13,6 +13,7 @@ void handle_pgm_int(void); void expect_pgm_int(void); +uint16_t clear_pgm_int(void); void check_pgm_int_code(uint16_t code); /* Activate low-address protection */ diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c index 8d861a2..67d581b 100644 --- a/lib/s390x/interrupt.c +++ b/lib/s390x/interrupt.c @@ -23,6 +23,17 @@ void expect_pgm_int(void) mb(); } +uint16_t clear_pgm_int(void) +{ + uint16_t code; + + mb(); + code = lc->pgm_int_code; + lc->pgm_int_code = 0; + pgm_int_expected = false; + return code; +} + void check_pgm_int_code(uint16_t code) { mb(); diff --git a/lib/s390x/io.c b/lib/s390x/io.c index 3121a78..eb4d171 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -43,6 +43,7 @@ void setup() setup_args_progname(ipl_args); setup_facilities(); sclp_ascii_setup(); + sclp_memory_setup(); } void exit(int code) diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c new file mode 100644 index 0000000..199405c --- /dev/null +++ b/lib/s390x/sclp.c @@ -0,0 +1,58 @@ +/* + * s390x SCLP driver + * + * Copyright (c) 2017 Red Hat Inc + * + * Authors: + * David Hildenbrand + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ + +#include +#include +#include +#include +#include "sclp.h" + +static uint64_t storage_increment_size; +static uint64_t max_ram_size; +static uint64_t ram_size; + +void sclp_memory_setup(void) +{ + ReadInfo *ri = (void *)_sccb; + uint64_t rnmax, rnsize; + int cc; + + ri->h.length = SCCB_SIZE; + sclp_service_call(SCLP_CMDW_READ_SCP_INFO_FORCED, ri); + + /* calculate the storage increment size */ + rnsize = ri->rnsize; + if (!rnsize) { + rnsize = ri->rnsize2; + } + storage_increment_size = rnsize << 20; + + /* calculate the maximum memory size */ + rnmax = ri->rnmax; + if (!rnmax) { + rnmax = ri->rnmax2; + } + max_ram_size = rnmax * storage_increment_size; + + /* lowcore is always accessible, so the first increment is accessible */ + ram_size = storage_increment_size; + + /* probe for r/w memory up to max memory size */ + while (ram_size < max_ram_size) { + expect_pgm_int(); + cc = tprot(ram_size + storage_increment_size - 1); + /* stop once we receive an exception or have protected memory */ + if (clear_pgm_int() || cc != 0) + break; + ram_size += storage_increment_size; + } +} diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index d113cf8..21d482b 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -211,5 +211,6 @@ void sclp_ascii_setup(void); void sclp_print(const char *str); extern char _sccb[]; int sclp_service_call(unsigned int command, void *sccb); +void sclp_memory_setup(void); #endif /* SCLP_H */ diff --git a/s390x/Makefile b/s390x/Makefile index f585faf..ce63dd1 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -24,6 +24,7 @@ cflatobjs += lib/util.o cflatobjs += lib/alloc_phys.o cflatobjs += lib/s390x/io.o cflatobjs += lib/s390x/stack.o +cflatobjs += lib/s390x/sclp.o cflatobjs += lib/s390x/sclp-ascii.o cflatobjs += lib/s390x/interrupt.o