From patchwork Mon Oct 14 14:46:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13835143 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 BB646D1627E for ; Mon, 14 Oct 2024 14:47:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F56B6B0096; Mon, 14 Oct 2024 10:47:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47F176B0098; Mon, 14 Oct 2024 10:47:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F8C06B0099; Mon, 14 Oct 2024 10:47:11 -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 0B4786B0096 for ; Mon, 14 Oct 2024 10:47:11 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6A48141028 for ; Mon, 14 Oct 2024 14:47:05 +0000 (UTC) X-FDA: 82672485252.05.4A45021 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id D460D100013 for ; Mon, 14 Oct 2024 14:46:56 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PPwt6Lu+; spf=pass (imf05.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=1728917156; 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=jQUFS3Gk+h07Pyzz5SlEqpZc8ARhWR4alZK+qKnRzag=; b=OtnqOc6XOn8DVhd8KrNbzD/7wtPg1Klcgg/yZ/fjfqNqOOdfxaCgV3tekamWX1uY6cuAVz 5xqDfvRZR9NMMU61GrIBCFmxWudi6SahNOI3vI0XiQ+8mvbi4pRyy5uPxMr+VYiqz1T88X fPJnKMc0AvJE6dtsqCrno/ROrdNQMHc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PPwt6Lu+; spf=pass (imf05.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728917156; a=rsa-sha256; cv=none; b=MXCC2t4vFZ+/2WTwXFX1y3LDLmrKOKU0yBL1DBgP24tci94V4Cl5Oqf/tcSsyWNABilVk9 rAwEe5ZRI/Cski2odY53lig1gFsOwejVFZMMmBKWF48SoVhAw9RXshgHIf/wk20dIKu7xa eNhM/1FAVa5SfiOpZdI2Vb9CkX49HLw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728917228; 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=jQUFS3Gk+h07Pyzz5SlEqpZc8ARhWR4alZK+qKnRzag=; b=PPwt6Lu+rc/bDPm+uBZjcj27xRGA8GtVwtfyi2Jv2foSCu4Vgn3rBI5IHeJZ9w5thhKJpB WJLtB/1MMDJ4OKcx5+2xfAQ85jkixKNSBbF6bffJmXhlbWYLYg5zK0jCB659lzBSP5Ub4b /Ky6vLBzwCkoHG7XH2Psaqmz0fm26gE= Received: from mx-prod-mc-04.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-453-gZo0ZuGeNOKYSOCW-Fnf8w-1; Mon, 14 Oct 2024 10:47:04 -0400 X-MC-Unique: gZo0ZuGeNOKYSOCW-Fnf8w-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3D72E1955F42; Mon, 14 Oct 2024 14:47:02 +0000 (UTC) Received: from t14s.cit.tum.de (unknown [10.22.32.146]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CDE7B1955E93; Mon, 14 Oct 2024 14:46:54 +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?= , Andrew Morton , Jonathan Corbet , Mario Casquero Subject: [PATCH v2 4/7] s390/physmem_info: query diag500(STORAGE LIMIT) to support QEMU/KVM memory devices Date: Mon, 14 Oct 2024 16:46:16 +0200 Message-ID: <20241014144622.876731-5-david@redhat.com> In-Reply-To: <20241014144622.876731-1-david@redhat.com> References: <20241014144622.876731-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: D460D100013 X-Stat-Signature: zyq9kgzwxgjihrjoouggrxf6c53na83b X-HE-Tag: 1728917216-978250 X-HE-Meta: U2FsdGVkX1+LTzIXO23B1XZYq2k+m1bBIB01FrfdbmtX9B8YOQNb/37/y5UiOgOjU8wSUBMqA4Ci0kfGVUPYUtplGVBiMwJ+Pj74p6vjC0T+iqCCvfM47v95u4WHNtUTGAgpns/KmJeCHXpXoQ2EEzylQw3QV693e/8jjagzrTrOB4ALslyD/PGyAjgG9NuBBZAaIfQvT70oqME9slOrUUKnPkY036Wqf1bCs6qdz4MvtivkiK6M4MeN/R8P3EAvRTn7ABwA2GAYs+tZyrRtzbqwQmTqij52QW0bmFiJPZ+vr9PCxvDqgGRfNNNiZkb2t3yyLZzBDKlX1oFrok0V6MAHyp0jFJMouDltZviK3oFna3yyFkUyVNnty+pKc6+FfMblHaS+HiwY7kNp5nq1w60VpqfOhVkb84Y/bUKCvMprUIhr7y5xGyBKign8T/SYM4utMd5mJWDVv23gkfc+N+KTwJSNYuAXrP5dBWnIf3U2+AaQd3PzlbPNWsXVM6HgC+WANV69e+PBa4E6t8eVB2mkFeb8PRE3SJTgis9dET3p6QZeD1wsCfGB5zWK/D6+Il6rLFtLvRRgM/5bmhBWnRFFAa+5/qYzkMy5M6E8I8UTJJdcZbSWTsg3ocZuwAonB0cT1RpUdltoL2SiiSbKRe0ZUibhJNpWDqx/Jshij0JtacYZXpd5LuUD0QF4tfA7JoP6x6tS6KjuCZWsJ3ORYDZeC3hkgyp81ureSPRTfzxzNVn704VW2Cz+9DSK9JZP7hk1Y47inG4BbjxXsROcmnC3G+4wxxrnuyXTBLnHTJtSEET26feH9bCaJDRaTQP06a1b2g1qTs4coQ1WjTz/lUUSfNIKfjYTzUNWymtT23eaytZ6o9RpV7pwRTnPrq/yzm5d3fnKomEs7KIT3Zouiph7KHbu2PtWd4jxHgoF3bW0ppP307JdZ9TfR75oiH6xFmA729ipr+8qy8sXSC2 W5W7bbV4 P2Iz2mVmoGDojHpMwRc1GM44viYU+v3N2WLihWiIADZO/IzoJUAa/DPFW6A2QIAxvSyfI4qp8r/Y+3fznyMzy+Vi2PGUomCMfOPKtq8goDvwygEbwZg302X1/tSaWV4MThwflY43HfqV72MvQbvnHVqUi3FVlpI9hVHWmKBCiwV5clOWayoRcn22DhkzuczeKFGGsKP4tqmD4Z1NWJm4ogvq9stO4iwLIsY6+/cTPUAYCBqiDEDk+1jBAzDe3aIpDOfksAFsKXMcAKlzHba9srfqwIsueMJRvnt19fkvAvyoQ5GxFF3VgppPqBmbOKcDMW4S8icPlCHJY/2PzAQOC6FdaYiRhDmEmxK5Pbjr89n9YXi0lrpuMy79AOA== 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). Tested-by: Mario Casquero Signed-off-by: David Hildenbrand Reviewed-by: Alexander Gordeev --- 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 1d131a81cb8b..fb4e66e80fd8 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: