From patchwork Tue Sep 10 19:15:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13799280 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 9A7B1EDE9AB for ; Tue, 10 Sep 2024 19:16:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 383E18D00A7; Tue, 10 Sep 2024 15:16:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3325C8D0002; Tue, 10 Sep 2024 15:16:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F9E18D00A7; Tue, 10 Sep 2024 15:16:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F26A68D0002 for ; Tue, 10 Sep 2024 15:16:10 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 702AEA8A34 for ; Tue, 10 Sep 2024 19:16:10 +0000 (UTC) X-FDA: 82549784100.18.A5B3373 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id BE79F180010 for ; Tue, 10 Sep 2024 19:16:08 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hro5NJpp; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725995665; 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=Xq/TMyiVBlIW+rwu1EuyYBMF+1VwzZ0MGyvT9zBb2aI=; b=MqaIfOQaH9sJzgDYIpuwmSg7wz2y1VFxb/NxqwEkbtRGnY1Z16/cRJTs6uSPFkWjKwClfq zM7Aj9YChgoiHSwzYc3EhUIS79G7miODYJrYgFvQBJxxmiSAkNAQ3Bm5eF9/8s8bnXGsop IAY6EWlG+EQV7mvmXxbb/sfsdAISL0o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725995665; a=rsa-sha256; cv=none; b=2HckYvYf7bsjjPY/5EtRP1eZ1W0CpBC9nC6QwUvc7V8SOyBvyhqP3rAxSunAIZM/2FNOnT ThBJDpHkNKA+AUSc1qklChtNfNH/A2wag0wHuVhpzST4pe8MMyRyI+C7k8Hodu75nRSnDi t6lrrEn+zAIQKx7m2cgx80zOGaXAYwg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hro5NJpp; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725995768; 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=Xq/TMyiVBlIW+rwu1EuyYBMF+1VwzZ0MGyvT9zBb2aI=; b=hro5NJppvJnZtDrBB60Z5heUGMKyrJQfkySMpPZvrrkD5ejP2fMBB43gw28NlBGW6WMzzX z+iT0zcBBgQlYxPB18lHuCGQWXHeg2d90u5XF+s0GhBVYbS0YuYxniewv2E/uARi18U3aa FXbtZyGTPKnDWDc2TT4YQ9KxGsc64/E= Received: from mx-prod-mc-05.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-125-xGJCYATCMwGtvkeozeKKzg-1; Tue, 10 Sep 2024 15:16:05 -0400 X-MC-Unique: xGJCYATCMwGtvkeozeKKzg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EA6F21955F07; Tue, 10 Sep 2024 19:16:02 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.17.222]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E8D730001A1; Tue, 10 Sep 2024 19:15:56 +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, 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?= , Andrew Morton Subject: [PATCH v1 2/5] s390/physmem_info: query diag500(STORAGE_LIMIT) to support QEMU/KVM memory devices Date: Tue, 10 Sep 2024 21:15:36 +0200 Message-ID: <20240910191541.2179655-3-david@redhat.com> In-Reply-To: <20240910191541.2179655-1-david@redhat.com> References: <20240910191541.2179655-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: qgr5urxkfhmjx7zgcwagewbxehu9j376 X-Rspamd-Queue-Id: BE79F180010 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725995768-882753 X-HE-Meta: U2FsdGVkX19PHPiSfmzZkY+0aSaSCSnRxYRKDE9zF+iqtyPeYTMOw+L/Pj8qN8FYNGrvmQaLfjphhEg6uJ27e9frZ8Vmcws12B2S6U3UWs18QG/2wpyy2durCXqBl20WPnTPgcTAgJOgPJoJXj3MAcb1zBoofRPsRxjvpIUdSNtytLf+4H9NJXEwUnrRvWaU2h5mJYki1CC9eVsfvtkJrrGs3GUBPREQPw0m+3ng3lCwCaEa8pFpPByrJJcoJQwVUnJwQa4r8nq8d66IAqpIWgh5gQz1qy3RZ23r8XF34vZrGkE/8UFz7aiPVxNF9exsq4Ae5BB60uKKfbtoqByaHDpvM5Pe0qDCHDJGJrwWM2OmTwTfmOPpgzqCLHlIH6WoF3Zm3oRZMQzqiBavGJCuihfQxgbTRNIzj+/P49moYtX1aeeQPuSX9t1rJLb8+uBsFVhvceQF6Itid8e7w/t81g2zHrFYg0ZKgODK8BM2Kfysv/Cd7NWObvTGr/u1AtWNRxeesPbfnUHx6mfnfFaodKEbunteyY5IHDg5cI8K7q5W9DaizH/RaW9C6RCZofEZU8VdMSpvyObGzhAGXdMoLUUqHOmXNlxyPOz40VKvUz3SJTf5VS+nptEjpE7BRHj18n4ymS+AtGeYEkqXXD0RAXHEj+zAzkCD1Us+mJFIcPcY3DpK0KCMhUHDqzqkKj2fBeqKPbaPDeePHy3dzV+YKsiYn10BK86GvOZe4Ket5nMwDV3ki/bfqr7GPXjqvxZDjsa3V84aewslSggFfOM/4bZ0cV9MtHQFNF0hALgI8EgIUjscuXvSMC9xAJMBrjIeHd2ApYdAIoB7yuDek4dIMyVb3xIFqpOGytjcb0T9VeDuQ1w1uCe2b6qAtCRA+v5H8qEe//f+WtKgEyzwC06M8m9sVwCFb8axKT/YnM224k8QPX3fFlyYfaMAstB9N6glPn9GO8121lZMf130IkC zYyF5fV/ L5TEbLh8oVIpvCBgxEuxQkmexFc9+9GNx3Wh1FKNymyyWOZP/Fc+2J5X/nnZ0IvTt2g+4w+AzTeq9M3ZLe49x4kWGXk4QDY7AONQNVwh0i4fTByC11YaH6jjRfrhaOJqgCLk6n8yfGlQhejn9veEOuB7Cfc2N1DoCVKmVZY4HR9RMMD8Yxl41AY9SF9Qxcz1+hWttcw4JMINKKjRaeYTt8uUsfHniWaF3QxWDUjK3vxImPFlp3ztrNhzcL58/osrfq6UpDrumwivk1nsuvLNWAy3/svoKyK8DMaNL/r3PWDgX1DBbhPM9yBT0A/dC2/JLTG/VqXjSlPqAtCejcJeWnisbxm3PC0DDWcf3BZv53kF2E3TrXgSlCgZVkg== 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 s390x 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). Signed-off-by: David Hildenbrand --- arch/s390/boot/physmem_info.c | 46 ++++++++++++++++++++++++++-- arch/s390/include/asm/physmem_info.h | 3 ++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/arch/s390/boot/physmem_info.c b/arch/s390/boot/physmem_info.c index 4c9ad8258f7e..9cac8550bdca 100644 --- a/arch/s390/boot/physmem_info.c +++ b/arch/s390/boot/physmem_info.c @@ -109,6 +109,38 @@ static int diag260(void) return 0; } +static int diag500_storage_limit(unsigned long *max_physmem_end) +{ + register unsigned long __nr asm("1") = 0x4; + register unsigned long __storage_limit asm("2") = 0; + 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" + " diag 2,4,0x500\n" + "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" + : [reg1] "=&d" (reg1), + [reg2] "=&a" (reg2), + "+&d" (__storage_limit), + "=Q" (get_lowcore()->program_new_psw), + "=Q" (old) + : [psw_old] "a" (&old), + [psw_pgm] "a" (&get_lowcore()->program_new_psw), + "d" (__nr) + : "memory"); + 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 +189,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,11 +204,17 @@ 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; + return; } else if (!diag260()) { physmem_info.info_source = MEM_DETECT_DIAG260; - } else if (max_physmem_end) { - add_physmem_online_range(0, max_physmem_end); + return; + } else if (physmem_info.info_source == MEM_DETECT_DIAG500_STOR_LIMIT) { + max_physmem_end = 0; + if (!sclp_early_get_memsize(&max_physmem_end)) + physmem_info.info_source = MEM_DETECT_SCLP_READ_INFO; } + if (max_physmem_end) + add_physmem_online_range(0, max_physmem_end); } void physmem_set_usable_limit(unsigned long limit) 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: