Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp237333lqs; Thu, 13 Jun 2024 08:45:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUqG2OU0X2/V4o5TtqX3/OIWWQN4BE1NFR6XBFfj14mtYACnl/6RVDWvsLlbyEbPSe9kSjl5xrDGHOXOLNufDoqTG586blbrwsUSGEAGA== X-Google-Smtp-Source: AGHT+IGQLtcV2GAzcs50gsgwfWvKjwTlyzbLRx/4X0/ffQUD6mQk24Dme0Z7z5TQANEI6Zc2GVxw X-Received: by 2002:aa7:8b94:0:b0:702:65de:19e5 with SMTP id d2e1a72fcca58-705d722b7a3mr7322b3a.33.1718293504685; Thu, 13 Jun 2024 08:45:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718293504; cv=pass; d=google.com; s=arc-20160816; b=VItwfMOOoD20bAn0/oKFS/hMZBheU+Q1tEQYvbWu0Bgz5n6shvW9q/Xw6rBBagZUJg eweluyQOU7ZR8MqbkBtiTsBgC8Dqz4vzx7VAFgNqLdMPP7bj3X9/W6fi4xOxSJFafxVE QHg650q7/tnZTe6Z7rd+xvfU0Qb67MBst2xyU0ZxwpdpvuJqaFcGhZYl7u9DHzCVqczY qHr3cbjnnuawUuTCbJC0wJOo9lMyoU+CGkQ3l4JB4WjqILS6BV995chn3TkbK9A4IWBN ezPjfr0WhHJx+/SA0HS4XPOYbOx0+2k+/68Y9e5i93wj6DRQ8ToxPQbUlML09d2q8z3T Ni7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Lf8JDXEAibfeu4y+WuUMeyCObr8U6xtLlRth+wjWPFs=; fh=TQATEbdDZNcnk8L2eDP6eFL9HlexFaHIexhR1TH2IlY=; b=bYorJhjIyGy8ORfu7i++OFesVbfRl0K/hlmZva90lNBzJmVFPt4DpBJ0JaBn5HvGpr ZdlwCJeY0f6ZsQ+q9kCCUASs2HbNb6inedRqztfEaLQi3K5zKp176KSAP3NLx3gdFYMo Tk+PftvdArtsaJtS+Z2c3gk/79fU5Hf14yTb+stzapAhyZV3d6Skoa1XhSn3JbrVcGyQ ouhpWu2E3bN/OBebSAKj/aXYWUPVTczpjHvd8YzLqWKoJEVffjqwqd5HceE49V4E2+j4 sucrvf04+YGJDlj4x0ArcVB2rsLmKnfQx/mFwBad+OxpQ/OyvnYJuUDkaqHsnRUkNxJR B8qA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HmIS1qUj; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-213585-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fede7286ccsi1507259a12.195.2024.06.13.08.45.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 08:45:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213585-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HmIS1qUj; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-213585-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5FF3628E330 for ; Thu, 13 Jun 2024 15:45:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 408041581FC; Thu, 13 Jun 2024 15:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="HmIS1qUj" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA10B155CA3; Thu, 13 Jun 2024 15:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718293221; cv=none; b=MMr0IiupZseHHvDl5/dIjcxbUt9ddyzpwY7L0S9P8pR/j0miJJpwjGzN6IFeenIloZWTLzplB9HU5172K/SxCN8IEQ8qfQctTO+8eI7Wv0n/uHndiZTsk4fmX1McuJdDbWG/bvs/4jv62IffjJ8clJWTMifeEpaH41g9lmDvU/E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718293221; c=relaxed/simple; bh=0r+mj0WHoOK5XU05tDWkuhV0guJgDxHLN3hdlmvl4FM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uVTghgT7pWWjg1y+qmFhic3I3RRqsIyYWSa+IhTllnMXcjCdT+bOnbzEzS2qGSSc/2K+GG/KsvUMwc9EZQmKeGgRKe+HWIC4w3p6BJLHPuR52eSDOvqAPc/GPM/wiaCok5TmbGdm/Nz8Ib5VfsZj89XVn8Csjb5UA5B+Cv6GKRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=HmIS1qUj; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com 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 45DFMPaL026307; Thu, 13 Jun 2024 15:39:58 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=Lf8JDXEAibfeu 4y+WuUMeyCObr8U6xtLlRth+wjWPFs=; b=HmIS1qUjW/tRR+bUEdy5btx3OQgyr umdrhVFIfANsPUb/RDv6yccWECWCTg3jiyd0kfqnSYGkFpfFsv9s4V2u7i56WcST tSTHcTxYUP89Q7DgnXmqxZtDuB0Vrz0ATe6cgaHmz/mtHOxqruuYSB1ifx+tOnPX YUFpJfpCQPQDMPBPwS8D4bTmvKYt+oFhgkZh1/W/PxETnGsSWeOv7EGGlOUtpXVJ L9XYev+jgYLk0OqDqf3goL0ed0TtkcGlvuDRWpg4sNdfkpZc7mcFIOJguQLhj7F6 8qI6n1IcvXQdSHeNvdKBKYnr3b0gTZ9S0TYiOWdev5LpqOBFNwgxFK5+Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yqq4rt37g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jun 2024 15:39:57 +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 45DFdvZk026874; Thu, 13 Jun 2024 15:39:57 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 3yqq4rt37c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jun 2024 15:39:56 +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 45DEjjfs028690; Thu, 13 Jun 2024 15:39:55 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yn1mus9ga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jun 2024 15:39:55 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45DFdo1k49086754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jun 2024 15:39:52 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D49042004E; Thu, 13 Jun 2024 15:39:48 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 614DE2006E; Thu, 13 Jun 2024 15:39:48 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Jun 2024 15:39:48 +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 v4 29/35] s390/mm: Define KMSAN metadata for vmalloc and modules Date: Thu, 13 Jun 2024 17:34:31 +0200 Message-ID: <20240613153924.961511-30-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240613153924.961511-1-iii@linux.ibm.com> References: <20240613153924.961511-1-iii@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: pD6uyOhh-bdrq5oWD9AJUmqZbuVWYtd9 X-Proofpoint-GUID: hE3He5xumiJgo0Zbuv3p-52CPM54okmR 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-13_08,2024-06-13_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=697 adultscore=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406130109 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 182aac6a0f77..93775142322d 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 -- 2.45.1