From patchwork Wed Jun 19 15:44:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13704238 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 04D98C27C79 for ; Wed, 19 Jun 2024 16:32:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 862886B00D7; Wed, 19 Jun 2024 12:32:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EC396B00D8; Wed, 19 Jun 2024 12:32:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 615E86B030A; Wed, 19 Jun 2024 12:32:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 368446B00D7 for ; Wed, 19 Jun 2024 12:32:14 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E198BA405A for ; Wed, 19 Jun 2024 16:32:13 +0000 (UTC) X-FDA: 82248180546.19.D94502B Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf04.hostedemail.com (Postfix) with ESMTP id 7A32740011 for ; Wed, 19 Jun 2024 16:32:11 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=giV3GCSu; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf04.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=iii@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718814725; a=rsa-sha256; cv=none; b=25M0hwWGsPqYShddo09Lg3nqT5+sV/ccmFIpT6TeCnxsrYyM/Ul5BfKz50SJyto/TQUOw5 9EVkFWKNocec/LvpOqOblh3peHfB46ubntAUB2OEO2dcTg8QkBXonxwVRJA8Vx9u3TgBAJ eGUTkKo4fbD7GgtWP0rIiGfP8VrDvh4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=giV3GCSu; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf04.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=iii@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718814725; 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=1loLMhtSJ//mVR2W6iv7p+SprUeUNXIsjh3OlBetJcI=; b=hte4/2Fb895JugnHqwM23mYqHkX++MdjpGpTvP/qOupvNYjQ4sHwzeEBe0Jnwc8b7UWZMT aAGsa1KJrT1C4XMqEqHAEoc8oi+KbUSI53ptxRr8W/9Mpu8oj+9Gsm6uKWSPdUQNrtyjoq SlJ7q6wKNW1+kgGIt5lEShT9CZZU/2c= Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45JFQlR4018028; Wed, 19 Jun 2024 15:45:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=1loLMhtSJ//mV R2W6iv7p+SprUeUNXIsjh3OlBetJcI=; b=giV3GCSuSRIby5ry/DXskg0sjwva3 yiZF0NIBT1G9/u3p/Bi/StG2hvOMT8dskezLNFjmjhQ8eZPoyTStwq3Gig1C3v96 4cLKPTtk8ulvP6SSdOutkJu9CVz9AZP51GLXwvlkkA6s2ktB9dZ9bOqMakw3f2EG WDFSjAiTHmnSG4OFpX3xz5J3hyft2PES/TAPlCa/Iv1XSLxGjxlgStM9XJJYPd3e NeXa2KpcNj2pkYER7I0BlkAfbnRdbRwZx43ybmRofB6Xxo2ifM23Lkb1AYX2jW0i cmrzxKVX40FxFqxvtvj9eHz/RBVEAwN4vPAO8FYah+8xgxlxf5d2mqp6Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yv1jg8546-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:51 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45JFjol9016365; Wed, 19 Jun 2024 15:45:51 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yv1jg8543-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:50 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45JExeaH006285; Wed, 19 Jun 2024 15:45:49 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ysn9ux8n7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45JFji9C20382130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jun 2024 15:45:46 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 49C5A2004E; Wed, 19 Jun 2024 15:45:44 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF5F52006A; Wed, 19 Jun 2024 15:45:43 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 19 Jun 2024 15:45:43 +0000 (GMT) From: Ilya Leoshkevich To: Alexander Gordeev , Alexander Potapenko , Andrew Morton , Christoph Lameter , David Rientjes , Heiko Carstens , Joonsoo Kim , Marco Elver , Masami Hiramatsu , Pekka Enberg , Steven Rostedt , Vasily Gorbik , Vlastimil Babka Cc: Christian Borntraeger , Dmitry Vyukov , Hyeonggon Yoo <42.hyeyoo@gmail.com>, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Mark Rutland , Roman Gushchin , Sven Schnelle , Ilya Leoshkevich Subject: [PATCH v5 30/37] s390/mm: Define KMSAN metadata for vmalloc and modules Date: Wed, 19 Jun 2024 17:44:05 +0200 Message-ID: <20240619154530.163232-31-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240619154530.163232-1-iii@linux.ibm.com> References: <20240619154530.163232-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: AecUav4zPu2pbA3kMbY9tgEYraj6MXQ1 X-Proofpoint-ORIG-GUID: aq7PB1sVMkX90gQQlshy4s4Ee0lgg62B X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-19_02,2024-06-19_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=702 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 mlxscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406190115 X-Rspamd-Queue-Id: 7A32740011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1eu4rkp4mzbsspra1o7ute5cnhj6t38e X-HE-Tag: 1718814731-888525 X-HE-Meta: U2FsdGVkX18uHHz7I4Q5YNvqAFhAT3VtKarr/6W9zmGITlAYiByHr+vPTBh5jNFFnmC8LJ3AhBF7sxBGWuJ0nIkqVzlW/SIPcrfSDeaKDwXV+tHnMtFRJgU8tNkn0gfaFVcmECyfV4hEFysTeMfSNAx8cofRq3R0C4/z/VvS2hhYvSE+TVM4Otqr789+bLNLJwCW78VGnPUIlQwAczkM+UB1fQVsjpydHgvScAIn2jrpLUAHrxKDv+yP2A/2bEsmwLLt88ajnCdv6eb4MUGKek91czfgqsZGkcoImJJRw8ESIGLsqV3rsd2F520u0vuaBBw1G+5R8S0XDws9PF4iHhm2uQ/0B6MnpBEEdQvoRuW/cGXeO4N9ObSbgYG6/7+sHLEJy1S7+ZStrQ8/G3QfkyxlWxgzvkNzzJ+8ZWSnY0z0f01H0AgvGsHDaHr8jzFEGNIR78SBU2i8Y7nOl6qdNPPJN0QebOv5AvCfWpgrQE+e95eKHUbkAru+6d5w5bJoStXAAeXcXeazoS9EhFhDSMCYnUAq4BmOe0RBHIq3kAqK1MF3fcPGfCzbE/pEU3owRXjKkxAoN9rFiCyH90G95f+EiyKrQ9fONnBfBBjoAw+x0wCBdtE4RDtM4gbhzly9WtsbMIJG7dKZbwaTgOo/Y3dXck2N1ztyWa75uui0E0RYioarTVZrDL5F3fTVOlINYoithne/8YE8HJK4LsiDlXJIkNMy+4Hos/1DZ8sJOLNXmJPDEE8dHl+ErQRonH2ew9c3bm95X2vytvtbs4YatEOn/c88ngbFhacoMNn6j4xNIh6ih97fH8gHtQKImTJGkB89WJQJKOKA1NKuYWCudYlenZ4Lpm0Clnb6to4YCRBpS/2xMpE+pVuD3mooX2cVPQz2+f8hj8DtdIgsrWpVJ/irmozozDJx/em1i69ZKe/x3I9BBOsk5fdUlhpLkt5kqWIG94Q/WbuGBMoKqTJ gSGVVGNe ICYq+3abm0miTePra5GlxXfasjLUN2/li47qFckQDRlvaAHTuw4FLRg69Hk6Hg/je0k65hpNQcKgv/tjQDIwfsWEdAiXa9o/jdVbyftJ1zfaMHFbuwU2X/1nMXVZEvzNQ2R2wh8hNIAVnibfvlIyPcMZ3NLzQz4RUPR7P/ZBJ+YiaWQJIJOwMBlX9aiYnOHF7fvERE++ZOZfFwq+Em6FS6uOnB2O8AqKmRRdzgxr0GIMSCyaQOp6gEevI8kerfn0wRHSoQBSpVdGjttiktGPqIYmdG+9+rSveQNWYodwBjFZIvpFNjGrquqBaSe/VAcKUjmpapXgkNja7rUCxbEwOB3WlDCr3DtfTiXl+EXB/G1vWSqi9AokEYo7j7w== 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: The pages for the KMSAN metadata associated with most kernel mappings are taken from memblock by the common code. However, vmalloc and module metadata needs to be defined by the architectures. Be a little bit more careful than x86: allocate exactly MODULES_LEN for the module shadow and origins, and then take 2/3 of vmalloc for the vmalloc shadow and origins. This ensures that users passing small vmalloc= values on the command line do not cause module metadata collisions. Reviewed-by: Alexander Potapenko Acked-by: Alexander Gordeev Acked-by: Heiko Carstens Signed-off-by: Ilya Leoshkevich --- arch/s390/boot/startup.c | 7 +++++++ arch/s390/include/asm/pgtable.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c index 48ef5fe5c08a..d6b0d114939a 100644 --- a/arch/s390/boot/startup.c +++ b/arch/s390/boot/startup.c @@ -301,11 +301,18 @@ static unsigned long setup_kernel_memory_layout(unsigned long kernel_size) MODULES_END = round_down(kernel_start, _SEGMENT_SIZE); MODULES_VADDR = MODULES_END - MODULES_LEN; VMALLOC_END = MODULES_VADDR; + if (IS_ENABLED(CONFIG_KMSAN)) + VMALLOC_END -= MODULES_LEN * 2; /* allow vmalloc area to occupy up to about 1/2 of the rest virtual space left */ vsize = (VMALLOC_END - FIXMAP_SIZE) / 2; vsize = round_down(vsize, _SEGMENT_SIZE); vmalloc_size = min(vmalloc_size, vsize); + if (IS_ENABLED(CONFIG_KMSAN)) { + /* take 2/3 of vmalloc area for KMSAN shadow and origins */ + vmalloc_size = round_down(vmalloc_size / 3, _SEGMENT_SIZE); + VMALLOC_END -= vmalloc_size * 2; + } VMALLOC_START = VMALLOC_END - vmalloc_size; __memcpy_real_area = round_down(VMALLOC_START - MEMCPY_REAL_SIZE, PAGE_SIZE); diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 70b6ee557eb2..2f44c23efec0 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -107,6 +107,14 @@ static inline int is_module_addr(void *addr) return 1; } +#ifdef CONFIG_KMSAN +#define KMSAN_VMALLOC_SIZE (VMALLOC_END - VMALLOC_START) +#define KMSAN_VMALLOC_SHADOW_START VMALLOC_END +#define KMSAN_VMALLOC_ORIGIN_START (KMSAN_VMALLOC_SHADOW_START + KMSAN_VMALLOC_SIZE) +#define KMSAN_MODULES_SHADOW_START (KMSAN_VMALLOC_ORIGIN_START + KMSAN_VMALLOC_SIZE) +#define KMSAN_MODULES_ORIGIN_START (KMSAN_MODULES_SHADOW_START + MODULES_LEN) +#endif + #ifdef CONFIG_RANDOMIZE_BASE #define KASLR_LEN (1UL << 31) #else