From patchwork Fri Jun 21 00:25:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13706593 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 4DD1FC2BA18 for ; Fri, 21 Jun 2024 00:28:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A833A8D010F; Thu, 20 Jun 2024 20:27:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A062C8D0108; Thu, 20 Jun 2024 20:27:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80BBF8D010F; Thu, 20 Jun 2024 20:27:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4E8BC8D0108 for ; Thu, 20 Jun 2024 20:27:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0EB7DA06CA for ; Fri, 21 Jun 2024 00:27:24 +0000 (UTC) X-FDA: 82253006808.01.A538006 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf06.hostedemail.com (Postfix) with ESMTP id AE6A7180003 for ; Fri, 21 Jun 2024 00:27:21 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=PrZp0P9v; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf06.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=1718929633; a=rsa-sha256; cv=none; b=0YbzxX8UPvEr81J55fTTLKiHBiYa2ZAAicJzlSTA0CTAsX+3DeDvtihf1oei2i96T9kQdS oZw/Gjk4k9orAnR/LBSIi9ok9HMvHEBmZLRiKB4pdXHdtccgD41zdc3DE2vJ8/ELr7GMqv y6pCKGDImPepqdYtRKXXkrxe35ASVC0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=PrZp0P9v; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf06.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=1718929633; 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=dJTBCTVm+DYwwDfuPqhjkMdDHVgbTJOgQUj+bRO14r8=; b=PaVfY3oIXUwuvTMRynkqe7HZt6h7pIjsXgU6upVSyDeVPR39FntC9wcT2oi/LxVXGot7pT MK3x/QACYz7k5uZiyKZFRlSqlm46ZIUiW1xrJnEh3BZiakXYRdTr6jFP3j6uxcWEOiyrt/ sdOjMPUXFJ1y7Y/IkHTWs1uEOh0bWDo= Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45L0RD1Y009176; Fri, 21 Jun 2024 00:27:13 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=dJTBCTVm+DYww DfuPqhjkMdDHVgbTJOgQUj+bRO14r8=; b=PrZp0P9vS4SIuZRygqUYIsIzed3SS bl5Pa8eSYbFHwaAv4guVbMcHJHGvt37IUUI3wEa2iPyfXe4xk+bxzDECOakKTx1s TNc5uxKBFJn5qx3PMcSLibc8OENUUc5wOGS01hZbBQvqpe+Bapyn1HjmuRVgfbby SsijLCYzLuMKifQZUrk/wy9XEpllq9ijGb85AYGJ5/ZNMwSGbfFLuDUIKUwDz8JA fyC/wG5MyqCT+SqjzUEox+rjGz7+Q4q/ac4nvIps+0LyiRO3DEa/HKUXINgkXWTb Uo1xeaJLgyVdDaH46KtUAZY13GIFr5kkEzuLQd+dwldYx2EoGwp7b7g+g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yvw8c876y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:13 +0000 (GMT) Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45L0RDWT009113; Fri, 21 Jun 2024 00:27:13 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 3yvw8c876t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:12 +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 45KLiBxN007687; Fri, 21 Jun 2024 00:27:12 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yvrspamsp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:11 +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 45L0R6rw56885562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 00:27:08 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7450120043; Fri, 21 Jun 2024 00:27:06 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5446D2004B; Fri, 21 Jun 2024 00:27:05 +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:27:05 +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 38/39] s390/kmsan: Implement the architecture-specific functions Date: Fri, 21 Jun 2024 02:25:12 +0200 Message-ID: <20240621002616.40684-39-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: qJzneyKICj495LR47ihcGQ3AFyfHC4KA X-Proofpoint-ORIG-GUID: DAUWdLee_Gr_anSc8J4SE-nczW9B-DNE 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_11,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 mlxlogscore=926 malwarescore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210001 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AE6A7180003 X-Stat-Signature: wai9k77wyn9un87kyjhd39hbfgejzsqs X-Rspam-User: X-HE-Tag: 1718929641-835467 X-HE-Meta: U2FsdGVkX1+FkaOv2bmMsk+O7/Qk596R5xCnCUEquXEQuJdIdrPf2B1E0EsHQyBGH3wGqUSto3oSEKAwu/hl+3thVF8TwWrkiU6o6Yarfyip05gcGjh+dqXTVmgSu0pfvw8nEC8qJgsKgpwU6CHlWrArnoA3tqpTB9U5wpuL1wFN2d1/86OUKIJiNX5e1Y+Qj9mFD7CfQAvk+y8c/WA3Dhil5QKYva8JOO7mG/SXCwcpVmG3Mt6CSB6aJD2PmXMMeBTka4lJ8pzG1C4aUcl+AMjjiz0cnI5jN9JvXBWalHJxOMTUSXbw7mHDW9gVKBBd99DcLQuPFQD7HUR6YE7L0O1/kkl1eajvfQtkmPpBqbqkHPghzetd0VsN5x+BmwngMV9CVfWf5T0pz7CRQsfGihXriWm56Yp9Yd/hLxIupG3MuL7gjTGyJv/f5HbDN81j/x6GBt3R4qUdf8IFdFSmHB5ppFQpQF6MU7GMBcWjpRrisTx1dGiZuMBWjmV9l7qgyQFRcpfUhgwkq4/aXPoZ43ZVrZIcTFgBkXMQGi44ncXsZm4nGj0OMz47GeMFUb6ohkmeHe1XmeWdE3DuZfNuvazbs6F0XEnDwcVGON9RPOKMs0S7MCsfPmp/b6hT6+ejWT6/8e6jEdCbrfjIsUTnRc4cc9xCA1jxGCwdFoopmeLJzzH6W3VLq71oSiYKkwUz9U1L1UmT9JIQlsvgiakFQMmYWMcKTaZiEu9zc1Epk0EJq6C612qeLtClIEWpVKEDgR/1ftYsaaWHnYT+3cImkqgFfwZqpZoCRE8APRNysL7+HW31AX7oi1DSdTwNeN+DebdJUsk0z2k9Om8W8i+TOD3t231xYF1ErTnbbMUspyhSzjI7U6H5yKRpq5xt58v2EvwZMGKfClMSo8LfOm02YTwTMxbsfPxgy5Fvwr1yALRYmUjJFNM2frhIWYBJM2Oa2FMizQEXvqLG5NhhEeR xPN7NPoM lbKt4a+5Zf9KAef8GZmnFOBQmoZ++rn48kp9JU9MgQwXu2rR+/Q8BZxg+lfBILbZZoC1NcoqmRrnALTx70R7x//Gj2U/5En1ACujZBkGMA48uZNBXorLpVyjqo2cV4aIUWZWGRXEoOrqd8cK2+Pj1+6q7Cy3SjT+wyOdpeTuay+kUFdoRkRu/s7Xj31PcTzxPp9mWw395agLKqmwH3qwePaB3l6mFz67JecubiWWiime54YbXyEmOzkJ5KrOkwWMgaWIMNT5dx7PJb8kUzThed/opibUYPVECUFoNUmaDO7CMDsw1yWOHStIi+ZlxrNBX/IxChYBSRKwC5TtxJMrgntRY9eLUv4kviVsd7pGMK5Hbegem8mOl8/CStw== 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: arch_kmsan_get_meta_or_null() finds the lowcore shadow by querying the prefix and calling kmsan_get_metadata() again. kmsan_virt_addr_valid() delegates to virt_addr_valid(). Acked-by: Alexander Gordeev Reviewed-by: Alexander Potapenko Signed-off-by: Ilya Leoshkevich --- arch/s390/include/asm/kmsan.h | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 arch/s390/include/asm/kmsan.h diff --git a/arch/s390/include/asm/kmsan.h b/arch/s390/include/asm/kmsan.h new file mode 100644 index 000000000000..27db65fbf3f6 --- /dev/null +++ b/arch/s390/include/asm/kmsan.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_S390_KMSAN_H +#define _ASM_S390_KMSAN_H + +#include +#include +#include +#include +#include + +#ifndef MODULE + +static inline bool is_lowcore_addr(void *addr) +{ + return addr >= (void *)&S390_lowcore && + addr < (void *)(&S390_lowcore + 1); +} + +static inline void *arch_kmsan_get_meta_or_null(void *addr, bool is_origin) +{ + if (is_lowcore_addr(addr)) { + /* + * Different lowcores accessed via S390_lowcore are described + * by the same struct page. Resolve the prefix manually in + * order to get a distinct struct page. + */ + addr += (void *)lowcore_ptr[raw_smp_processor_id()] - + (void *)&S390_lowcore; + if (KMSAN_WARN_ON(is_lowcore_addr(addr))) + return NULL; + return kmsan_get_metadata(addr, is_origin); + } + return NULL; +} + +static inline bool kmsan_virt_addr_valid(void *addr) +{ + bool ret; + + /* + * pfn_valid() relies on RCU, and may call into the scheduler on exiting + * the critical section. However, this would result in recursion with + * KMSAN. Therefore, disable preemption here, and re-enable preemption + * below while suppressing reschedules to avoid recursion. + * + * Note, this sacrifices occasionally breaking scheduling guarantees. + * Although, a kernel compiled with KMSAN has already given up on any + * performance guarantees due to being heavily instrumented. + */ + preempt_disable(); + ret = virt_addr_valid(addr); + preempt_enable_no_resched(); + + return ret; +} + +#endif /* !MODULE */ + +#endif /* _ASM_S390_KMSAN_H */