From patchwork Fri Jun 21 00:25: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: 13706590 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 9A78EC2BA18 for ; Fri, 21 Jun 2024 00:28:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4D538D010C; Thu, 20 Jun 2024 20:27:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD5F08D0108; Thu, 20 Jun 2024 20:27:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B65B38D010C; Thu, 20 Jun 2024 20:27:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8C3458D0108 for ; Thu, 20 Jun 2024 20:27:16 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 477AE40681 for ; Fri, 21 Jun 2024 00:27:16 +0000 (UTC) X-FDA: 82253006472.12.5199E1E Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf01.hostedemail.com (Postfix) with ESMTP id EE8624000A for ; Fri, 21 Jun 2024 00:27:13 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="W/Djp9Zt"; spf=pass (imf01.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.156.1 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=1718929628; 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=4fSSH6vmg2ttVHljZbCX1MTEpHEt2+4cCxd5p/437jKskHMcpTs0VfCfVg3eV0IZr64gXI Q9fI38Bgcr2ZcBc+e1VRC0OEGUoh5HgG2o1tF4WvSfrxhOf1fMri+OHLEhvkVNKiTDcgAD 4WXiFBvXCvDjkIXdQ82vNaimTpKFLZQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="W/Djp9Zt"; spf=pass (imf01.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.156.1 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=1718929628; a=rsa-sha256; cv=none; b=DOjVjhKmliwhVmEbvSzjCzAVoL3KCfKYm3ckxSL4w/JJmBg1vSyHjwFxoWXBq/Aw8KqtxN a4L0x8dGLkzvlGUd7mHDE7ZN1Z/ocAsTAHP96SOu2hQRYSDdPXl7TW5OlTcWzmogGJGN9Q 25/ze8cGepKldID8TZGagzqzwotJf5Y= Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45KNQq5q017556; Fri, 21 Jun 2024 00:27:06 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=W/Djp9ZtsfVEpx9QWWwFkzt8Fv3ap QSwktim8QLOry4OiQYZxRoOLDLIyi8ZoxjR+Rv0FvLEsdBfswRxN3tmpWh3wFr9f QXzjDQHtq4HdTZykS8NoObH4NHqzIxm982ozsNg4vYn+zB7uVp1tSZb4ky/4RBoF LHybOvuJoMJXyHoXuCIfA+hFzoN2hWYs3YrghVR3Zh6/zYU5emAiyerhyWj6MRJ1 1/ygwrPHxfDlEIooBOgZe+wwKnR2PUZV+7r15BfMuU535DthUOQwk0Nc8VO7MrMe jY+Kkf/GqvuNK7gOlxq/nnNdrMR89jL++qriIuxlKXv0D047CfEHxmbyg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yvvrdr8be-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:06 +0000 (GMT) Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45L0QaaE009416; Fri, 21 Jun 2024 00:27:05 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yvvrdr8bb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:05 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45L0PHZm031330; Fri, 21 Jun 2024 00:27:03 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3yvrrq2ncq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:03 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45L0Qw3v46924224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 00:27:00 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E97EE20040; Fri, 21 Jun 2024 00:26:57 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C698D20043; Fri, 21 Jun 2024 00:26:56 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.171.10.44]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Jun 2024 00:26:56 +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 v6 31/39] s390/mm: Define KMSAN metadata for vmalloc and modules Date: Fri, 21 Jun 2024 02:25:05 +0200 Message-ID: <20240621002616.40684-32-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621002616.40684-1-iii@linux.ibm.com> References: <20240621002616.40684-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: bwF18VfazW8eN9kbTGux1ece82genkGJ X-Proofpoint-ORIG-GUID: vQS0SDPy88_48lPJre9HnK-Wr12hlnFB 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-20_09,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxlogscore=663 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406200174 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: EE8624000A X-Stat-Signature: gemcy8ndcj8z1co3pb3ugjnaw5naqdc1 X-Rspam-User: X-HE-Tag: 1718929633-591288 X-HE-Meta: U2FsdGVkX1/KOnvGJjZboRVvAeXoOaLvBa13Rf4z0F5naDOH9nJGR8IDkHBK6IhNJeKnVSf2aP3DzFlZhhH1eFR2guANm3ypUsf9nmiSxlFSey0RE/jkt2ELQ/3r6oPHWd1D78A8Y7ICOIxZ0iBeJ8RjqRcjTrWkBAAwwEPnL13DckVnKv7kbDCsJemG5XrDlFUH8gIM7L2E72JwHPPDoNgolPHpArrSnXiBiH3RRY7Al5BmuKRDsq+qGt4Loe2NNMs2RyTbyLA3zYNHEcuCNRvySHiS1vdgjsLxK+79DaHbc7RVNBZS+upGAZetsePENf6G86yZW3nbTXBBhdBvE3BxNoAtOhivO9onhqtH1L8Y+Ia7Iu7kuLK3TiGWI9K/v+03wlTxDKVkM7rZRFpDfrUrT8TVGaVyZ929PKOlth3NFqsTQVnep9/Vb+wbI30u6bOt3mtNbX7O8T0nsLLdVnO+zulewk+SvnfKqIaG2/lor0b5jqG8RfcS+bhwF8VRfx4tGcu+pqviydA/RU9DBRXGohgyVsTxiBhNszscarcoOqB5m9/qJPqU0kIZFebqC9yR5OEHr0KQ3teh/OlCNLTQ6QV8bRtuvX+kGo/y3JKSoIHcmvUENktvXqN6F9hygLZQbHJk5oR9KHxn94XmJE5BxPX4fKOAqwIGvdP9AXuui5mntCzZdFKa8+sNYG8AsnOUIizHbcAiCtE+XslbPQPuNwSzvPj8cRvxDRO9mWQvlTvnHkSUv08z5D4WgVqUFVxCmMxWPCrbetcIuHTc5mwK2BY72upSxMNqe65mOmONWM5wz5v4uO35N9zRWbwqSxZ/k0FG0N4aU9IJY9wyWkEZyUJlPc25geCJbC1oJ+Lx3VG6dlGNvSBgiR/R84OmXVO9P2doS4yaT5F9natwqQmrh/rHMulD22mkWVYtrTnsq8IzHdw5A24x5ovbnwIbVTHa8Dwr7pnhKAj690m MB47xyC1 j+8mW0eAzqDoqisLVaUBI1eASMQE1ZIZHvZKCToJNFz1tuKjk0/gtFMOQG5ZnyvNLvMkHZTp31fuF9QVW0yN50BgHM8l7pZEOtN4yYq1QEIxrxrvjBgSiRvtTxesErDnPi1aoPkk9JmqniirlW4BYNMrfSfiCIzs5ztBgdg4czShdkd1J+A2yK1pcwSJ5A93Aw0//318/mXaC78xaEweWc0PqMnXLfqeu+allRAN+ubZw4jgq54WadhW8Nh/4JAxWhoQIl7DVu9KBGtLr10En7TJXrw== 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