From patchwork Fri Jun 21 11:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13707346 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 2A333C27C4F for ; Fri, 21 Jun 2024 11:38:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DC526B01F9; Fri, 21 Jun 2024 07:37:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 964E86B01FB; Fri, 21 Jun 2024 07:37:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F5C88D0163; Fri, 21 Jun 2024 07:37:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 44B8C6B01F5 for ; Fri, 21 Jun 2024 07:37:47 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 010951A0DE3 for ; Fri, 21 Jun 2024 11:37:46 +0000 (UTC) X-FDA: 82254696174.12.AC2BFB4 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf23.hostedemail.com (Postfix) with ESMTP id A51DA140016 for ; Fri, 21 Jun 2024 11:37:44 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=mvP63znE; spf=pass (imf23.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=1718969855; 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=RchUIgTF+ZpeyElj2GgOmlsIglqoUYuaJAWy7To07R5SGGKy8GYzETAUMB2NeeWVUWS/3O SoKevXJfW6rTdo+QODpWqyiWqxHHZSIFnquCk5Vx/zw3VyTzejPu6jOh+w93/D+p90sra0 YoxEmR7Kyy34J5Vdr7vaAPhdBubdlF4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718969855; a=rsa-sha256; cv=none; b=dfw2/FVlhy9cgGJ08xubwhBABSmBkl0Lw76hN4dHNqMZAsVli4kJo9WERpPB7gEUUQRooK lgzcp5I8r0pbJP2ZE6qOUXBg/plj5jdpp1gWGP8CkrUXhK0gnOIapuvm5g1V8PCOuGg5vm YkG1yhlMxYCwDzqGE7N5ql86KAxW++c= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=mvP63znE; spf=pass (imf23.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 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45LATgMN018262; Fri, 21 Jun 2024 11:37:39 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=mvP63znEJQedkrBiRJ53gaNoRZtDf 3Ebm2PJZRihPVWBP2VvYm0BF/nzOccwhGLxm1Hc3LaTG9DgavCBXcCl5tSEnG06A QzIA88A1RIQCz7a5ztFOk/x8RikEgfwG3pfs0Gz+26gi1xhkQCVQIbQcxDOIVHPd hWOgWzZt4PBsh189PXIMJt5QHARrxyWnDMaTsJugQsTcMqM7L0iYAZl/HhQQh5mX zjcjggCJuaINyFT8pv8A+S4MTODxcIsNWL749Su3sF1VrF7gqeQeJLRMeOwAwjPD pcbv4JlIZ/lArNJ3JmKPBd/Gc46mp9yuKc7e0gntrM1NWKQ+uKXuqYgOQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw7t5046n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:38 +0000 (GMT) Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45LBXEi6012851; Fri, 21 Jun 2024 11:37:38 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw7t5046j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:38 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45L9EbHe025663; Fri, 21 Jun 2024 11:37:37 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yvrqv6w0u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:37 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45LBbVHE35389950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 11:37:33 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1E7920040; Fri, 21 Jun 2024 11:37:31 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3803320043; Fri, 21 Jun 2024 11:37:31 +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:31 +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 37/38] s390/kmsan: Implement the architecture-specific functions Date: Fri, 21 Jun 2024 13:35:21 +0200 Message-ID: <20240621113706.315500-38-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-ORIG-GUID: zaL6FENoUtTNqWUO1NRkU-7HlS4JHT7A X-Proofpoint-GUID: dbvEu-32DCOymeEi7JVqGwWM6oYY8HH_ 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 lowpriorityscore=0 malwarescore=0 phishscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 mlxlogscore=916 suspectscore=0 mlxscore=0 adultscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210084 X-Rspamd-Queue-Id: A51DA140016 X-Stat-Signature: yhrcn4wquss84ypesqzit3h9jj17ak5f X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718969864-573135 X-HE-Meta: U2FsdGVkX18xZH20D4rQpRo/94r6jZAnROt6Px4mFLvnpzXlK8Y8n5QihMl+d/8sXjPfeX51GCzq0V5V2x8OJnp9OiywaN7LHzoQpr4U7M2NI2jhus5qNmCwmUI2zpkMn5mL/lwmJqnUw/BczsvCb/ZEmiHv0FBagDGwHA0qC3CK4D9eDCpNe/uhnfHRrSFON/OSL5j74ueCzR5uTAWFKU/DREpenfTYbgPE/VzqiBONy9IvXODHrxwyHWPSR73JykNDr20Jt1uPPf08QtCti+dL0M8YCiVaB+7pRkwKRRxWnnTDYVA8I8BMObqGG6KQVx2tKEJ+PoQvzP25Z9mZwVpxeQyUCaUl3udCnBq75bg7Kj3r2JUFj0UmbGfwpWSHy4rer1YxHhRqWfNIh37wP13m47pFiwS1Ic35wzRxAd/RjOSgv0vBbyXDAL7qbKoS7x6YS9vmXY0wcW871WGooD4IQnpTKK3JDnU9Fgjp6gFt5zZ13eSz4yYBVkwO1DyZ2t/BtDYgM5eKPpYGYVkirqhBsPkR4qmQfuCwNYKnMGtsg7bgnSVqMmZm5ZlrWPeOP39a9WpRvFj7QkwOObLzU+tCS+uYbNBvcaWhAqztYZEhnTP0TfeM6+OaeYmqExGp/QHuQX4EF6kXNLbjzRwkz3/Uihz7YvDuiO4CeVXQ6vKr9MZceNU58eO8uM3hEbN5mvVSlCbtG7OkUUzQ+2dYmCevzBZUIBZGuMbxLN5d0hTEEo5p2vVel6J768Q7JF7qMKZi5qO68aHVEIuOwxHMJ/M3TsgZlKobr/QucNL4FT78Sy6Ry9mlZxIalO5uufPO7IpZttU0AKhK2AUi7QpMKhwPEfY+RXeEBE8J15MJ+I+IrRi5Bsxml0RgS0CAEFt1avEn1JZvYl/8k7MSGTXrMppYQ2FvlBv9bUmKdm9pXb4flqilTTOvP/x9L7Zv9XFzCDt28JNdj5zehe0YulA Y66/ZvIA m8bEu3K2AXIWeJwcnGKg7Xyib6J7wJUN2DDaRjuc304+opn/TeuXeTgJj56zo+t/yx9cy2bFF0xLMcy5W2WpnMrtwJ5M+gDXAtZvd2bHyl30mfGTdJPnypGmhd6zGhSS60AowIPivoX5Vu3wl64tw95qvUsIpyLto2capjjcybkA+0/mpire77NcCFUyc8k+MxxG2EuSONzMeKYIFSDaNwOnxqo3yd0imDzG/SlQp5QYbIh7hXm7NMfhVnWyIU9Aw4XOpw2zsK/GKRrCCkoMMiiu706+CqM0DN5htFEGwWjHcryrem1qbiQLhA5gZUgftXfCclsd5MXTAwpoAcAwVC8AYJymzhh/qBixE/VbGePhDOuXST3gVdBM9/A== 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 */