Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5783899rdb; Wed, 13 Dec 2023 21:57:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAHO2B+n9F+yV7+RaQmzuLhERDO8StBBc6FvPuGDPhwlBtqFe9GUyBqgOadjB9u30CaHI6 X-Received: by 2002:a05:6870:8926:b0:203:521f:7611 with SMTP id i38-20020a056870892600b00203521f7611mr57189oao.4.1702533468055; Wed, 13 Dec 2023 21:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702533468; cv=none; d=google.com; s=arc-20160816; b=LK6awVSwCOhg232+ltN2h4hstQj8h2ulyrffQjvjs3DJzmmOgRoYI+vcCkp6BzkxuD 5WGUfRRKZ26kDk5p6KniNdeiVGRMwVvVz9VAzzdXxhZuT2ZNvQbKI0ZjKcvZRwvcIT2Q HG8FcX+5Vls25dToNlnpNWpkbfK5TW93RbIuvVopPeVKopRJaYDqUCCqmPoflO/2jq21 hGDncOMuZqtLl9UclUsTnfID4AZ5q/geRh03guwkBcs9fAGAjOexS/x6dzCtAfn8fp3x GMPDGA5e9WZdh0+rkCIwN4nJvA+WjZTIBPaoF4JVt2UAVtVYatecCjc8oP2k0bAu15c9 8MAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Or+ER3iSwLY+2GcnBysJHFAbWg54QnxrivHZZRWSUlo=; fh=JZjI76tHrPFh9wXiZ9caJKwSuDkcoMAMvZd7/HZf8J0=; b=CFdZPNCec/HW9MfPXaquajNNcgx5pWAz0ZpsErDy9xbRR34FkLI3qVNTIOFNPFywi9 eZyEhs/WwhoVIUMD6b1WM+md1/7Vn/a15pUomN9hEH5XGu0HySpG2PZIPaOKmfsBhFCt I9cbGCeuKlyDPbYyf6l2GoTg6L3vUvjGve5PCFqvsSk2FLG7yQM82mvb39vjSfCggoSn P9QtwVTN9Vl1cg4lfMcB4DbV7WUDpkJJMS4VKEIX/iPC0Z6a4WUYcLY4YbDjj9dA9FTq PHDb5kKB7vtlN0P1RgBn0LnBUZYbb9Qk6Mwcfufap+AoLtC3TLPLPLeUiwLHBlAiSGij 2EUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jPBCCJIq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o2-20020a655202000000b005c65dc887dbsi10299259pgp.557.2023.12.13.21.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 21:57:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jPBCCJIq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 78B9B8028A48; Wed, 13 Dec 2023 21:57:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443192AbjLNF5Y (ORCPT + 99 others); Thu, 14 Dec 2023 00:57:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235522AbjLNF5L (ORCPT ); Thu, 14 Dec 2023 00:57:11 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D57196 for ; Wed, 13 Dec 2023 21:56:53 -0800 (PST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BE5bkhT003442; Thu, 14 Dec 2023 05:56:41 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=Or+ER3iSwLY+2GcnBysJHFAbWg54QnxrivHZZRWSUlo=; b=jPBCCJIq3GKGrIuMP1yn436SePKJpby26k22ilj2Zem4QVli3eQCXD+/wL1bjAOD1iuJ /FZtdWsm7ipjuytRcepQOR1cQXIRTw3R6XshoDZQbbrMErpEkwAwJybCndj1K544Yg25 hq1zYmXU2FZ70rTaisY9r79SKKj32xliME3keJfd4RILx2JlFn6DWkOnvsx4oqAnlI3Z FLh87rcb7Y5C9OUm5eFP+TfQRbo+BTby94YosokRO49Hij6k/J8r461vUgCrpGWYxL/9 rIyYoy6VBsqO1l7ojZyS8F+AiRjyaA6xdhYF+9W+WdGUwSwls8UJ4ltppIgHzDPjmNV9 1A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3uyuqp0av5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 05:56:40 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BE5rRSq022695; Thu, 14 Dec 2023 05:56:39 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 3uyuqp0asc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 05:56:39 +0000 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 3BE3jVip008467; Thu, 14 Dec 2023 05:56:26 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uw2jtpnfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 05:56:26 +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 3BE5uO5O46727664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Dec 2023 05:56:25 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D30272004D; Thu, 14 Dec 2023 05:56:24 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E42AE20040; Thu, 14 Dec 2023 05:56:23 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 14 Dec 2023 05:56:23 +0000 (GMT) Received: from nicholasmvm.. (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 98F37606F0; Thu, 14 Dec 2023 16:56:19 +1100 (AEDT) From: Nicholas Miehlbradt To: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: linux-mm@kvack.org, kasan-dev@googlegroups.com, iii@linux.ibm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Nicholas Miehlbradt Subject: [PATCH 10/13] powerpc: Define KMSAN metadata address ranges for vmalloc and ioremap Date: Thu, 14 Dec 2023 05:55:36 +0000 Message-Id: <20231214055539.9420-11-nicholas@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231214055539.9420-1-nicholas@linux.ibm.com> References: <20231214055539.9420-1-nicholas@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: BSRtrog9VNVw4H1y8EPLE2_PMzM43F4_ X-Proofpoint-GUID: z-dPmrvTGG-i94A2fIfwubmwfRHh6Qb7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-14_02,2023-12-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312140035 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 21:57:45 -0800 (PST) Splits the vmalloc region into four. The first quarter is the new vmalloc region, the second is used to store shadow metadata and the third is used to store origin metadata. The fourth quarter is unused. Do the same for the ioremap region. Module data is stored in the vmalloc region so alias the modules metadata addresses to the respective vmalloc metadata addresses. Define MODULES_VADDR and MODULES_END to the start and end of the vmalloc region. Since MODULES_VADDR was previously only defined on ppc32 targets checks for if this macro is defined need to be updated to include defined(CONFIG_PPC32). Signed-off-by: Nicholas Miehlbradt --- arch/powerpc/include/asm/book3s/64/pgtable.h | 42 ++++++++++++++++++++ arch/powerpc/kernel/module.c | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index cb77eddca54b..b3a02b8d96e3 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -249,7 +249,38 @@ enum pgtable_index { extern unsigned long __vmalloc_start; extern unsigned long __vmalloc_end; #define VMALLOC_START __vmalloc_start + +#ifndef CONFIG_KMSAN #define VMALLOC_END __vmalloc_end +#else +/* + * In KMSAN builds vmalloc area is four times smaller, and the remaining 3/4 + * are used to keep the metadata for virtual pages. The memory formerly + * belonging to vmalloc area is now laid out as follows: + * + * 1st quarter: VMALLOC_START to VMALLOC_END - new vmalloc area + * 2nd quarter: KMSAN_VMALLOC_SHADOW_START to + * KMSAN_VMALLOC_SHADOW_START+VMALLOC_LEN - vmalloc area shadow + * 3rd quarter: KMSAN_VMALLOC_ORIGIN_START to + * KMSAN_VMALLOC_ORIGIN_START+VMALLOC_LEN - vmalloc area origins + * 4th quarter: unused + */ +#define VMALLOC_LEN ((__vmalloc_end - __vmalloc_start) >> 2) +#define VMALLOC_END (VMALLOC_START + VMALLOC_LEN) + +#define KMSAN_VMALLOC_SHADOW_START VMALLOC_END +#define KMSAN_VMALLOC_ORIGIN_START (VMALLOC_END + VMALLOC_LEN) + +/* + * Module metadata is stored in the corresponding vmalloc metadata regions + */ +#define KMSAN_MODULES_SHADOW_START KMSAN_VMALLOC_SHADOW_START +#define KMSAN_MODULES_ORIGIN_START KMSAN_VMALLOC_ORIGIN_START +#endif /* CONFIG_KMSAN */ + +#define MODULES_VADDR VMALLOC_START +#define MODULES_END VMALLOC_END +#define MODULES_LEN (MODULES_END - MODULES_VADDR) static inline unsigned int ioremap_max_order(void) { @@ -264,7 +295,18 @@ extern unsigned long __kernel_io_start; extern unsigned long __kernel_io_end; #define KERN_VIRT_START __kernel_virt_start #define KERN_IO_START __kernel_io_start +#ifndef CONFIG_KMSAN #define KERN_IO_END __kernel_io_end +#else +/* + * In KMSAN builds IO space is 4 times smaller, the remaining space is used to + * store metadata. See comment for vmalloc regions above. + */ +#define KERN_IO_LEN ((__kernel_io_end - __kernel_io_start) >> 2) +#define KERN_IO_END (KERN_IO_START + KERN_IO_LEN) +#define KERN_IO_SHADOW_START KERN_IO_END +#define KERN_IO_ORIGIN_START (KERN_IO_SHADOW_START + KERN_IO_LEN) +#endif /* !CONFIG_KMSAN */ extern struct page *vmemmap; extern unsigned long pci_io_base; diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c index f6d6ae0a1692..5043b959ad4d 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -107,7 +107,7 @@ __module_alloc(unsigned long size, unsigned long start, unsigned long end, bool void *module_alloc(unsigned long size) { -#ifdef MODULES_VADDR +#if defined(MODULES_VADDR) && defined(CONFIG_PPC32) unsigned long limit = (unsigned long)_etext - SZ_32M; void *ptr = NULL; -- 2.40.1