From patchwork Fri Oct 25 14:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D39AAD0C616 for ; Fri, 25 Oct 2024 14:15:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72CB76B009B; Fri, 25 Oct 2024 10:15:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DAF96B009C; Fri, 25 Oct 2024 10:15:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A2FD6B009D; Fri, 25 Oct 2024 10:15:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3ED4A6B009B for ; Fri, 25 Oct 2024 10:15:39 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AE027C0BA9 for ; Fri, 25 Oct 2024 14:15:17 +0000 (UTC) X-FDA: 82712322378.18.6E8791A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id A5C83C002A for ; Fri, 25 Oct 2024 14:15:12 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ds8kipDp; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729865566; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=P/OWBKgNxsqut2xHOcIgEvQRSrYiossJkI+amYxch/4=; b=1jZPFQE1R+CG8lZlIFrWxA8mkQY7YCVOhCmxea8mrRQK9pr76sZwxRDGjLngcT+H1NKoxS tQqlCSp+GcELoB/N7JCBYNO+9o+mv+LBuJA+8/jAlGeU6XuPeWpuewguo26VwimQGQoEI/ SwIATY7NAQjTUmGq3ThSi+ijqigGL9g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729865566; a=rsa-sha256; cv=none; b=js8tJgJ5DDfMOC14cIQFZKo+f6ADSVoOmp5o7AxkntdqnQZtGpeaGrKZF/+f+i+E2ZZu1n sYcQKM29tQ8sslVbNxj/fn7GNTYhz7VPj5bKFmPM7DF0YkkXsB7s+meFcAFmOBPXYaWbYm YC5uOe2xtW0GGQFq1hdx90yzghmkRa4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ds8kipDp; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729865736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P/OWBKgNxsqut2xHOcIgEvQRSrYiossJkI+amYxch/4=; b=Ds8kipDpbfjYEWY5jY1RGOxLt41HdxtmJVjhSfvE4mDzE+Qe9ucUteSSRWSSryKP1GNDMZ fvmfSTLPHypbeUn0NEfQa/DqP0LDmcjAVn8gOXMq32DJFcZOe8D9PBKOjofNjF7jRcLn97 4hQU1oDwilVbIsJACPCoqDh3xuk9pxo= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-u59Cgv1VPbS7mn3iPCL1Vg-1; Fri, 25 Oct 2024 10:15:33 -0400 X-MC-Unique: u59Cgv1VPbS7mn3iPCL1Vg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4636A1955F3B; Fri, 25 Oct 2024 14:15:26 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.22.65.27]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C14B519560A2; Fri, 25 Oct 2024 14:15:18 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, virtualization@lists.linux.dev, linux-doc@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Huth , Cornelia Huck , Janosch Frank , Claudio Imbrenda , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Eric Farman , Andrew Morton , Jonathan Corbet , Mario Casquero Subject: [PATCH v3 3/7] s390/physmem_info: query diag500(STORAGE LIMIT) to support QEMU/KVM memory devices Date: Fri, 25 Oct 2024 16:14:48 +0200 Message-ID: <20241025141453.1210600-4-david@redhat.com> In-Reply-To: <20241025141453.1210600-1-david@redhat.com> References: <20241025141453.1210600-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A5C83C002A X-Stat-Signature: r3kc7fuqcr59xojw97frhmajdcsp7r38 X-Rspam-User: X-HE-Tag: 1729865712-688075 X-HE-Meta: U2FsdGVkX18wIdpbUFrwwiy+aODYiu+RsIB4cob5G9sbl6u7oeV/FHOkmonW6CAI8/7iT/tKvUwR8CJuZ7I1tyCbTaYu1J6xRv+90vbveDlft3Fwe4+gVemIqCj5AB0mQsqmjFKrnPSgnI3neZIK1ZhT4XTs3d2rsIXZOYInPw6hFXdg8e6XATPHVvV0axlzkNgtfF1DlnGDUZCSQ94rEA6FM5THJpLUEiTWDDvajwtVLNSjCL4FTnwoSh8jPqKe9WUp4JnCUSr4sK5d+q3aH93scn7Bd0NzjE8JI8RiIh/4bZhoeg/uqA05j2pr8ya2Yb6rR0aSErxhvxS/10Df7rFG83zPisWEsG9snY4OW8PT8MJul0zjLXSXv6oBTylsH3x+U9pYdaSTT9WVP2EuVY5UsgVXdLKbJhGAHP995k+DI6ZbhkTTJF0oNFdDwqQrPZLXwajW4EvecImju+7DesJIZ5TCt099yMh9R5t5Pam5Nz5WxQOcULgBb5e/U5qoVmgtCJT4BbkLUlXsNFH9wmdca6gV7JbE95JxRrgXsJE5uLIrSD9bTya2DWoz0STwextl9E0fahjUhfgRaXDMxW1kZicqGW9n5zXSSnyu8fRYXNSWDfhn1lUFPFs9IOdwCf73KJ9/1nKGGDd6L+8VtrioZFt01q8OJH+UMTe7zg/QN7eQz7vZgEiu1JkKK1dBVq5rqUU+KYmWeaXGs/J8nyIRxLqQoPmsxSBMrRl+WnINORDwGidKL/1XxNcB2HplbPwMomOM9sXr1Rb56GQDtglaZ2q/VikS9P5+byGU7fvQUoW5Rs60irHYRHFEFLtWcvOItNqCWxs4mCMdfDuAEu1y0N23DdA5rO2i949xiWCn1QafPifjQnYcF8xeTNPtlJwcYxXsxO7khJ4f6X4uRfMvxYQC7kb8/QarXiTqtaav/kWkO9i1yscH5G23eYpNKZN2u8VFdshzn+ibctG VsLC10Ql QAoxoFbhQ2UVxpQ2fIFMBn3sgsmk/fHrmxKyp5/xHnfpLIJmF9j45O/nTQuPJ8N31ftKA3QRqczUpj3Ws1G9Xc6A6XvqZEpnfWQdczaN2bzzQ4vaaWCSviaayIqf0XHtueVZTsbR0fhS9dye9sZiJaQ3Z/wYjYAoeKnIXpn/pXBeVCK2a0k8/S3zq0Xtx7MkCsVWha7r03rRPadmN2UdTq6nBDJhGDj+qMXQ5J+JngiopfVZIATt+Dt02jvAqNyyCNJok8AVfG9uuc1/fWY/7d7ka1+HEflOX+L3hcRdRG9SeK476+clRIxX1CVrYZYt2AMBVzzEdHmDTRll8yegAoT1cj/Ok2LFBjsIePJrkjj+D2sO0sfCglWe0Ow== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To support memory devices under QEMU/KVM, such as virtio-mem, we have to prepare our kernel virtual address space accordingly and have to know the highest possible physical memory address we might see later: the storage limit. The good old SCLP interface is not suitable for this use case. In particular, memory owned by memory devices has no relationship to storage increments, it is always detected using the device driver, and unaware OSes (no driver) must never try making use of that memory. Consequently this memory is located outside of the "maximum storage increment"-indicated memory range. Let's use our new diag500 STORAGE_LIMIT subcode to query this storage limit that can exceed the "maximum storage increment", and use the existing interfaces (i.e., SCLP) to obtain information about the initial memory that is not owned+managed by memory devices. If a hypervisor does not support such memory devices, the address exposed through diag500 STORAGE_LIMIT will correspond to the maximum storage increment exposed through SCLP. To teach kdump on s390 to include memory owned by memory devices, there will be ways to query the relevant memory ranges from the device via a driver running in special kdump mode (like virtio-mem already implements to filter /proc/vmcore access so we don't end up reading from unplugged device blocks). Update setup_ident_map_size(), to clarify that there can be more than just online and standby memory. Tested-by: Mario Casquero Signed-off-by: David Hildenbrand Acked-by: Heiko Carstens Reviewed-by: Alexander Gordeev --- arch/s390/boot/physmem_info.c | 47 +++++++++++++++++++++++++++- arch/s390/boot/startup.c | 7 +++-- arch/s390/include/asm/physmem_info.h | 3 ++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/arch/s390/boot/physmem_info.c b/arch/s390/boot/physmem_info.c index 1d131a81cb8b..f3ea5dbff10b 100644 --- a/arch/s390/boot/physmem_info.c +++ b/arch/s390/boot/physmem_info.c @@ -109,6 +109,42 @@ static int diag260(void) return 0; } +#define DIAG500_SC_STOR_LIMIT 4 + +static int diag500_storage_limit(unsigned long *max_physmem_end) +{ + unsigned long storage_limit; + unsigned long reg1, reg2; + psw_t old; + + asm volatile( + " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" + " epsw %[reg1],%[reg2]\n" + " st %[reg1],0(%[psw_pgm])\n" + " st %[reg2],4(%[psw_pgm])\n" + " larl %[reg1],1f\n" + " stg %[reg1],8(%[psw_pgm])\n" + " lghi 1,%[subcode]\n" + " lghi 2,0\n" + " diag 2,4,0x500\n" + "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" + " lgr %[slimit],2\n" + : [reg1] "=&d" (reg1), + [reg2] "=&a" (reg2), + [slimit] "=d" (storage_limit), + "=Q" (get_lowcore()->program_new_psw), + "=Q" (old) + : [psw_old] "a" (&old), + [psw_pgm] "a" (&get_lowcore()->program_new_psw), + [subcode] "i" (DIAG500_SC_STOR_LIMIT) + : "memory", "1", "2"); + if (!storage_limit) + return -EINVAL; + /* Convert inclusive end to exclusive end */ + *max_physmem_end = storage_limit + 1; + return 0; +} + static int tprot(unsigned long addr) { unsigned long reg1, reg2; @@ -157,7 +193,9 @@ unsigned long detect_max_physmem_end(void) { unsigned long max_physmem_end = 0; - if (!sclp_early_get_memsize(&max_physmem_end)) { + if (!diag500_storage_limit(&max_physmem_end)) { + physmem_info.info_source = MEM_DETECT_DIAG500_STOR_LIMIT; + } else if (!sclp_early_get_memsize(&max_physmem_end)) { physmem_info.info_source = MEM_DETECT_SCLP_READ_INFO; } else { max_physmem_end = search_mem_end(); @@ -170,6 +208,13 @@ void detect_physmem_online_ranges(unsigned long max_physmem_end) { if (!sclp_early_read_storage_info()) { physmem_info.info_source = MEM_DETECT_SCLP_STOR_INFO; + } else if (physmem_info.info_source == MEM_DETECT_DIAG500_STOR_LIMIT) { + unsigned long online_end; + + if (!sclp_early_get_memsize(&online_end)) { + physmem_info.info_source = MEM_DETECT_SCLP_READ_INFO; + add_physmem_online_range(0, online_end); + } } else if (!diag260()) { physmem_info.info_source = MEM_DETECT_DIAG260; } else if (max_physmem_end) { diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c index c8f149ad77e5..76c33c7442df 100644 --- a/arch/s390/boot/startup.c +++ b/arch/s390/boot/startup.c @@ -182,12 +182,15 @@ static void kaslr_adjust_got(unsigned long offset) * Merge information from several sources into a single ident_map_size value. * "ident_map_size" represents the upper limit of physical memory we may ever * reach. It might not be all online memory, but also include standby (offline) - * memory. "ident_map_size" could be lower then actual standby or even online + * memory or memory areas reserved for other means (e.g., memory devices such as + * virtio-mem). + * + * "ident_map_size" could be lower then actual standby/reserved or even online * memory present, due to limiting factors. We should never go above this limit. * It is the size of our identity mapping. * * Consider the following factors: - * 1. max_physmem_end - end of physical memory online or standby. + * 1. max_physmem_end - end of physical memory online, standby or reserved. * Always >= end of the last online memory range (get_physmem_online_end()). * 2. CONFIG_MAX_PHYSMEM_BITS - the maximum size of physical memory the * kernel is able to support. diff --git a/arch/s390/include/asm/physmem_info.h b/arch/s390/include/asm/physmem_info.h index f45cfc8bc233..51b68a43e195 100644 --- a/arch/s390/include/asm/physmem_info.h +++ b/arch/s390/include/asm/physmem_info.h @@ -9,6 +9,7 @@ enum physmem_info_source { MEM_DETECT_NONE = 0, MEM_DETECT_SCLP_STOR_INFO, MEM_DETECT_DIAG260, + MEM_DETECT_DIAG500_STOR_LIMIT, MEM_DETECT_SCLP_READ_INFO, MEM_DETECT_BIN_SEARCH }; @@ -107,6 +108,8 @@ static inline const char *get_physmem_info_source(void) return "sclp storage info"; case MEM_DETECT_DIAG260: return "diag260"; + case MEM_DETECT_DIAG500_STOR_LIMIT: + return "diag500 storage limit"; case MEM_DETECT_SCLP_READ_INFO: return "sclp read info"; case MEM_DETECT_BIN_SEARCH: