From patchwork Fri Jun 21 11:35:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13707343 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 1410DC2BA1A for ; Fri, 21 Jun 2024 11:38:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F4EB8D0162; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82CEB8D0160; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 608348D0162; Fri, 21 Jun 2024 07:37:44 -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 3312C8D0160 for ; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DE2461C1C85 for ; Fri, 21 Jun 2024 11:37:43 +0000 (UTC) X-FDA: 82254696006.04.35AD9F3 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf22.hostedemail.com (Postfix) with ESMTP id 93958C0012 for ; Fri, 21 Jun 2024 11:37:41 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=cHS4AIQu; spf=pass (imf22.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718969854; 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=X1oGap99TVdqBvzHLWhv+TXBuFqzUMdrRG4OBua4bwY=; b=5lNXBJxAJ2cXluHgsRHo2syHVBQjQVJzhPpF7+o2mb5T9kesLaA7XyA0W++tlyFedAabfZ 0koJ40VgXQXpRTP5QIITm/krdHl/JWTA3dHBKnqTEigzTNDrPXfe3va7ZztAkK4S/jDH7L 033U6xjhbp/4TKMIK+dtuBD6XK4lcXg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=cHS4AIQu; spf=pass (imf22.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718969854; a=rsa-sha256; cv=none; b=65i+Xi8vWFTpHPDQGrjDVRlxjGVZ6ReR0vaeqbO7Q1TiYSQbsvX9muN/T1siawpD8Xylgo HcvU/cvjlB4GYjEsX9JIJvW3S/oSAv6vEJ3Y6crnYazz0CJEjTT2iGBnrPdLBhei0+56aG wHpmybTzDorUCx87Q65t9zjlXZ469Ek= Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45LBSug8032437; Fri, 21 Jun 2024 11:37:35 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=X1oGap99TVdqB vzHLWhv+TXBuFqzUMdrRG4OBua4bwY=; b=cHS4AIQufHyIdJNvC/ckC7xvUQXq2 pmE/5t7z1eYxkVNhUNRsW3IQQLLwAVx+wMygpvoScm6hW/ZSvY18/EYjTpqhkSvB ++qp2VmG8ljf1linqVsRk/m7cZUs6kgChtkZidBDJPNLsLa5JeUXOrdg1VQ0gFEP cc6pqrhpJ3NY36cyqS58FR1viJ78PumnsWfk1CWhXMShNyZqNmWfErq8/pSHh5LF sBtF5Ptinmd3Pc6F0gyKH+Y0EvCEwouaeEa3k9t7lJcr66IK9NL1EyjtAh7CoULl nTN6Kv8L9kUC4XSeefoaZ6aDHCLYcnOqpbiq2jkwNln6urM2kZv2zm3Tw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw8p2g0kn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:35 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45LBbYUM014376; Fri, 21 Jun 2024 11:37:34 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw8p2g0kg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:34 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45L9AHOT019941; Fri, 21 Jun 2024 11:37:34 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3yvrqupw0g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:34 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45LBbSnF54853978 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 11:37:30 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D9972004B; Fri, 21 Jun 2024 11:37:28 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 81C262004E; Fri, 21 Jun 2024 11:37:27 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Jun 2024 11:37:27 +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 v7 31/38] s390/mm: Define KMSAN metadata for vmalloc and modules Date: Fri, 21 Jun 2024 13:35:15 +0200 Message-ID: <20240621113706.315500-32-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621113706.315500-1-iii@linux.ibm.com> References: <20240621113706.315500-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 72Oak4PnOY00Ouh9gmqCpCVl-f00e8x0 X-Proofpoint-ORIG-GUID: B6QLHfkbQ1aHYH9UguQEGWXygvTuApGV 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-21_04,2024-06-21_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=663 spamscore=0 clxscore=1015 bulkscore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210084 X-Stat-Signature: pt8zmqdq4qj7z3a7huujycukkdaf7t7f X-Rspam-User: X-Rspamd-Queue-Id: 93958C0012 X-Rspamd-Server: rspam02 X-HE-Tag: 1718969861-671931 X-HE-Meta: U2FsdGVkX19TznQd1C6mAnbWcbib2ZQSO4qJ7Ov8Wkr3RzPv/EbrGo0sHURsn2U2qEHBs2xH2GaBbdr3/gzb1kZpxGGGX8qUKiX81e2+IRPHcjM3P8J+dzWYWdxUq5gsMXdruBIhYHQrauJ4a/OSQpTxg/V3kDimtJPs+tVLMAeXApXsHx3wAhh+K++fqL+mQ6c0m1pM6TJmi3gcOGCMPhSDKL5fwH7OLX7mxIYzVI2peBVVq7nt6Z43uzBBWBAJsfgd8qRAU+466ez/n9qfWLFMXvFUD3tF4juSbPKPhMIddBt8OoxF66CD1tokeJSnKy/xmwZyivkew2iSHVRXVtBwZIE1x2ovmgerX6W9BZPlcRaTM92jfE16UTlrGOCYMO2ZHfQKr/KCdghW0dzCfrAju+BOigHo/fGVNo7cURmpDmtWyGa/jUzRzHqiogIWkisj+K5nABGRHmza82CULh6JXxPadA/mxFtL733/5qCG1UX/iTF/m5wtp4PX4fU6DwqSvWP/sUkF8NxTYOugtxqrG6f8T2galb1ySlBVOgqTJ6slw649/ifvVlKSW6knecDFraB91navuzz27pEdihYiiyz8jpi6XqK7/z/FVypeHVsbdVUViMvtLtH+jpvIvXUeSd/7i76aurXqRikx9Z2MPyEbGdRm6vjNbTeFdOzuGzldugQeioN+4RnXXbEbAb9+GagvZyVL3427paFngBvtsr9BsoWGFQhyMkYFU09MdJEnjZsOI1J5w+BcM3JjTNOKbGuzuiXZ85X9KPNNvCun51vPjqtv1kJa3m2SjHuTl0J8rhUu+d/a+07xWri4jix7vwD7EAVS6jHUXXlchSysmPsFIXGp69XJSPaGL+mh8Oya0yCHj0y4gBkzCRbYBHocnp0zktZSkmpgq2hNUJWkgqFAldxdXSnhU+imWuWl3nElv+XvOnoWtNjGpBDGOmDranwZEA1km20+WQn s43+8Zpn SPPDHUXoaGXcOEeMY8K0s+L3di174VAlbooDlkyYdCUImnxD3XCXnIMqUtWDw7UKx7589qEOqxOCpbDpaUGcD05AwgFczR96I3LEObzrbv48FQQtlJh6H6xgVk9odWBJtfIiiAMabH1b6ACyPQ9Bez2UNOYuIYPBKUvWXA3+IrnRdrOODTTCdzVRPpiH/9kIZjwbSRU6VTGaVsCgl/p1ubcUCueC0x6gWIbqxAY2L0R8K/zMHyzjvBe4qrLGyI7iNbdMv+oz4MlMWLhFygAIHz8OFEvH235SfWWUkOyFIgur8vqUzmIFa/MSWkIvDTqyms01cEF0A29QHzuG9aq5UNgjMOseXiJ/Tr2UJ 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 | 12 ++++++++++++ 2 files changed, 19 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..fb6870384b97 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -107,6 +107,18 @@ 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_SHADOW_END (KMSAN_VMALLOC_SHADOW_START + KMSAN_VMALLOC_SIZE) +#define KMSAN_VMALLOC_ORIGIN_START KMSAN_VMALLOC_SHADOW_END +#define KMSAN_VMALLOC_ORIGIN_END (KMSAN_VMALLOC_ORIGIN_START + KMSAN_VMALLOC_SIZE) +#define KMSAN_MODULES_SHADOW_START KMSAN_VMALLOC_ORIGIN_END +#define KMSAN_MODULES_SHADOW_END (KMSAN_MODULES_SHADOW_START + MODULES_LEN) +#define KMSAN_MODULES_ORIGIN_START KMSAN_MODULES_SHADOW_END +#define KMSAN_MODULES_ORIGIN_END (KMSAN_MODULES_ORIGIN_START + MODULES_LEN) +#endif + #ifdef CONFIG_RANDOMIZE_BASE #define KASLR_LEN (1UL << 31) #else