From patchwork Wed Jun 19 15:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13704204 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 0B9B7C27C53 for ; Wed, 19 Jun 2024 15:47:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E35166B02FA; Wed, 19 Jun 2024 11:46:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE3E88D0082; Wed, 19 Jun 2024 11:46:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE8A66B02FC; Wed, 19 Jun 2024 11:46:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A01796B02FA for ; Wed, 19 Jun 2024 11:46:04 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5B19B140258 for ; Wed, 19 Jun 2024 15:46:04 +0000 (UTC) X-FDA: 82248064248.14.1A2D8B6 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf06.hostedemail.com (Postfix) with ESMTP id F2F35180003 for ; Wed, 19 Jun 2024 15:46:01 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=BEPtJdz5; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf06.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 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=1718811953; 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=nB1l8vkNyM9mVWovTL+NH+w81puT/zMq+tuxLWRrLkQ=; b=mc11c5Ae+m8XqkRHe/b0vjMZQ0VuXTwCo/da/wSU6q+vdq7YioTg/pPY/ZMOp/A1TMglAu VruvfCaMECq1VnvKa5APdUY8Wgm7leEefQJg90lr4sg2hDRfV6QNP1hZG+dGc1a+gQ67YJ 4lu2WwD+eBUgNaGu/Pe1UoGv2imMvFQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718811953; a=rsa-sha256; cv=none; b=zYom/NLo4ZTXa7IoVcRqN50kAiMEr6CPJiInJi4SdPrDGnpRGKDGWJf9zRbfQGmpeRP3Eh 8nbQeySvfypduC2iQa+YZb9zFX2MCWeNbEWNjESdp03JDmA7Jdy0hgOPbbOYcNybFPtoEq CEvJEExkaTUp7il6wFGJg6b0xIUu4x8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=BEPtJdz5; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf06.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45JBQbWl032598; Wed, 19 Jun 2024 15:45:54 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=nB1l8vkNyM9mV WovTL+NH+w81puT/zMq+tuxLWRrLkQ=; b=BEPtJdz5fdSHB/qoJNKVVp8rooBgK nOefoKLPv8qtPV2MAhok/6BWIVhVNTjFPlwu7tGwoFxrYavuvyqc+UeDOtkAuBZi /ToHlvNmEBH86RH0EUHrGTB5WXsw3VWY9k7sml719JbxQSStYzM7yPCTQ1HEjVit tmuNHraS3v/eRve2Oss6g4kdKOHthT6eSHST/pCq9k1z1M4ccZZwu4RuJmslxcU6 zwU74Nb1n1RnJQ1L7G9XJtMbsQyRuq//VGCmbhT4XYI758mhE6xQID294YlPxl/r GAbXZq3iXoHajoeI+r/xZdq7JgrZ95yXRDqgexFUzGec8L8cEFcw2ndJQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yux7j0tcs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:53 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45JFjVIg028737; Wed, 19 Jun 2024 15:45:53 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yux7j0tcn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:53 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45JEeOYF013440; Wed, 19 Jun 2024 15:45:52 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ysr03wkre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45JFjku833555194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jun 2024 15:45:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 661AA20063; Wed, 19 Jun 2024 15:45:46 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17F8E20071; Wed, 19 Jun 2024 15:45:46 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 19 Jun 2024 15:45:46 +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 v5 36/37] s390/kmsan: Implement the architecture-specific functions Date: Wed, 19 Jun 2024 17:44:11 +0200 Message-ID: <20240619154530.163232-37-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240619154530.163232-1-iii@linux.ibm.com> References: <20240619154530.163232-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: G-HYbmsxvmzkpVnASbMNe4jf4vNgUmy7 X-Proofpoint-ORIG-GUID: voXdK99_pqsmHaCFVP5r8s2pFVOzBayF 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-19_02,2024-06-19_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 malwarescore=0 clxscore=1015 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=916 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406190115 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F2F35180003 X-Stat-Signature: zxpjkpjg5a83ou1jsan9ni7dskzz9rtp X-Rspam-User: X-HE-Tag: 1718811961-805860 X-HE-Meta: U2FsdGVkX1/QWsZq8aU684gtSstb85GqCmmYgktwj/UyfQQUExxp4XDSQB4g8rl4bXlaI+blsQItm5ckXesWrtRGwvBLk+aQUdYrL7Tq37iV5Pb/savsmRk3piLU4ao3o+CoXFzYwSEBob5cF6UQFjnEQx3p1ikeLzo5QfB9AYVLmFnTcPvW0gygJIWkB9O5WyoCDPDGBYJyNii4Feo3Y30ClVgF2zItNn4cgQUGeOZPfwePeAfFhxDYcCoaCcpRDSHCsKG0qz7daKX6zDloILJQEdLNhCznSrcjsCELUhnQ+9rhC42MqcU//krpOQsq1NlKHjkVQt6cINW5aWS+tylf/IplSvpGgY7kA8MZT0Z87UvTal6JB+LMeNhlzAt4D1FZp2+uUtT2dSI82QFVIaMNSp/r0/hNvjDZCgaclRG0xEFtRulITAoqQjODok3FhadTr2z0ffp46fX/9yhnSV+OhEMYSVM+JKISWUWBmR/4WFAfMzuizZx6BipeTYeCrHvZYM3fxRf9h/hnBWUMjIwgA3k5OEOMVITTPElKBEhMCBUXFKgIFWUMs9R21Uk/Y4z4Tvf1K+dTm0C02ES0Yo/S4OvHS/8UxMC7CS+KuBwdwGYRNcg6T1UGYB/fJMI9kR4CeslbYa8zfHWx4tnqUXR8+mXAGx4US1NulY+2tTi4pGmhSE3QZGqN2Mlnl7usx6z/uNwI8CTAWIosiEviGLXbxm6LN5i+vtfGlFtsjpTlU09AePomcc2FZC0TbAxa0vUI4wSKfkR0ihXOQO/xV+k6jmPOmVbrFkpai9026RK4uz/VYrvSh+EfrwOka9W5fj5QkOTvm+kxMR75hkjY5UWrNHvxLVZ4O1k0/wbjzxB658GoKzUEv9WIOQtqp/2Q4px5mW7rvwS0ZuadU60gr1K2M4DTYqDxyZpQVtCKkXoPIyuKTcmNcPHxgqXi0Q1AH2vi2wVSORXEJp7qwDO M/S/o2HH +Cf0ocBK6xIsxMOW6eZ+WFt2VI0RikzQxOqCn6xlFu1GFiyN5DQhnnqe/iUpLui6CXPYAyen/nQkfbdw4hE43ew8IF2ocOYF9WvEyTNO7WFOh3mnqMHLqBXISb7hAMq+VyMZMggDBX17rd4XVPJ10gYKb1YiuDCiIO0ulv0o+gn0NXqxkflQXKC3UYQL/30AXfuAKZUcfRcU3sIvfU5eJzc1nUeE02Cd7AH747YRZ1k9TBGuX0JWFB+jYbGa0BZG4kGIvMhE5f5m+D0KU9BZzATIDsuGApyKCLzKHdsA2kf5HNlnMG1fD3lrqn0b+3ekMoM4dHKWUD0YHC6ehwz1Ei3QSeA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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(). Signed-off-by: Ilya Leoshkevich Acked-by: Alexander Gordeev Reviewed-by: Alexander Potapenko --- 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..eb850c942204 --- /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 (WARN_ON_ONCE(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 */