From nobody Sat Apr 18 02:46:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 803F7C433EF for ; Tue, 19 Jul 2022 05:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235597AbiGSF0w (ORCPT ); Tue, 19 Jul 2022 01:26:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbiGSF0l (ORCPT ); Tue, 19 Jul 2022 01:26:41 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FA322494D; Mon, 18 Jul 2022 22:26:41 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J5KYUB032397; Tue, 19 Jul 2022 05:26:32 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=YFD/RonJhySGGefvyKaAb9AJoup2bE+KD4MJgR4iy2Q=; b=qfeZKaYxAKRQ/K04trbtHbv8OgeNq5lhGsSTfoh+Q6blehEXXomlxVhd9ji8BN5B794r KmR15QejjX+ZgpJWbPmJQXL45PoKOYcLgJs3iFrnJMnqRwZeJjn+bcc7kPBPTPL+Qf2o rZe2DXEtt6XA56oZptkLJb14wb5UGc+2x0y0Ad0PuA1jSG2BqSXOi9RV71vWWJmr0XBj 2luRbOuQ6fhRFfDThzBBvvNwP4gWZCMivlNvuzqrccNJCP3U+D4Bu3aRXtwV2AkHJ61T Tlpg4C4y3dZc+7Cnu1ls0Qa1khu4tocebv/B3bp3X3GJeZ3MnSZ/iRvRW8n7Vv4hlMtZ 6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdpcq836p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:32 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26J5L7wt001287; Tue, 19 Jul 2022 05:26:32 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdpcq8364-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:32 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26J5L3xd024482; Tue, 19 Jul 2022 05:26:29 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3hbmy8uh83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:29 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26J5QQYs18088412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jul 2022 05:26:26 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0E74A4055; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF8D4A4051; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55669) id 7BEA1E01D7; Tue, 19 Jul 2022 07:16:36 +0200 (CEST) From: Alexander Gordeev To: Matthew Wilcox , Alexander Egorenkov , Heiko Carstens Cc: Baoquan He , Christoph Hellwig , Vasily Gorbik , Al Viro , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v4 1/4] s390/zcore: fix race when reading from hardware system area Date: Tue, 19 Jul 2022 07:16:33 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vHe9p_lO6SoHxjRWlS9rA4IRNet1JtHX X-Proofpoint-ORIG-GUID: Cvqq4MDGPObEKoiht7oW7MZ220olxn5u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190019 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Memory buffer used for reading out data from hardware system area is not protected against concurrent access. Reported-by: Matthew Wilcox Fixes: 411ed3225733 ("[S390] zfcpdump support.") Signed-off-by: Alexander Gordeev Acked-by: Heiko Carstens Tested-by: Alexander Egorenkov --- drivers/s390/char/zcore.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c index 516783ba950f..92b32ce645b9 100644 --- a/drivers/s390/char/zcore.c +++ b/drivers/s390/char/zcore.c @@ -50,6 +50,7 @@ static struct dentry *zcore_reipl_file; static struct dentry *zcore_hsa_file; static struct ipl_parameter_block *zcore_ipl_block; =20 +static DEFINE_MUTEX(hsa_buf_mutex); static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE); =20 /* @@ -66,19 +67,24 @@ int memcpy_hsa_user(void __user *dest, unsigned long sr= c, size_t count) if (!hsa_available) return -ENODATA; =20 + mutex_lock(&hsa_buf_mutex); while (count) { if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) { TRACE("sclp_sdias_copy() failed\n"); + mutex_unlock(&hsa_buf_mutex); return -EIO; } offset =3D src % PAGE_SIZE; bytes =3D min(PAGE_SIZE - offset, count); - if (copy_to_user(dest, hsa_buf + offset, bytes)) + if (copy_to_user(dest, hsa_buf + offset, bytes)) { + mutex_unlock(&hsa_buf_mutex); return -EFAULT; + } src +=3D bytes; dest +=3D bytes; count -=3D bytes; } + mutex_unlock(&hsa_buf_mutex); return 0; } =20 @@ -96,9 +102,11 @@ int memcpy_hsa_kernel(void *dest, unsigned long src, si= ze_t count) if (!hsa_available) return -ENODATA; =20 + mutex_lock(&hsa_buf_mutex); while (count) { if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) { TRACE("sclp_sdias_copy() failed\n"); + mutex_unlock(&hsa_buf_mutex); return -EIO; } offset =3D src % PAGE_SIZE; @@ -108,6 +116,7 @@ int memcpy_hsa_kernel(void *dest, unsigned long src, si= ze_t count) dest +=3D bytes; count -=3D bytes; } + mutex_unlock(&hsa_buf_mutex); return 0; } =20 --=20 2.34.1 From nobody Sat Apr 18 02:46:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A297CC433EF for ; Tue, 19 Jul 2022 05:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235903AbiGSF0n (ORCPT ); Tue, 19 Jul 2022 01:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbiGSF0k (ORCPT ); Tue, 19 Jul 2022 01:26:40 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A66613F60; Mon, 18 Jul 2022 22:26:39 -0700 (PDT) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J5CxIF013821; Tue, 19 Jul 2022 05:26:32 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=8H7WOwXqw+3wr9CerSM2hWVM0N01TwTjsRnLxOLOLV8=; b=j6ulJdd3t0qjZPqYD/Y+qmjFXKnQrbmjUouyEmFK4SzLpr64rB/6XpqroydpfvZ+jth7 QRKcXsQI2G3PQG8yrYhBnfn73VjRzOOFC2gziP7cyigEHeVsipC2UXlx6RU+janPkdiF OPmPCTibiGZr3V492iug5vAQyPbOBkBMJqf3CBZPra5u3ahZK5tGMXqXQmEknRU5nXUv sW9GDKvrHOI8R/bjyR5JahweKLhET6yY8apSvC0pXOBhyTukasQzQ8VpVW1Ur52mp+ne cXzCCchbsgF2VeCou24bqcsRTNMpfk4ckuOJynczzhHoTfijZUDKYQyA8bPJn98bOo4W og== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdp93886m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:31 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26J5KpLJ004374; Tue, 19 Jul 2022 05:26:31 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdp93886a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:31 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26J5KmiL024404; Tue, 19 Jul 2022 05:26:29 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3hbmy8uh82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:29 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26J5QQJn20906312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jul 2022 05:26:26 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ECB02A4060; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DB9B5A4054; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55669) id 7F138E048E; Tue, 19 Jul 2022 07:16:36 +0200 (CEST) From: Alexander Gordeev To: Matthew Wilcox , Alexander Egorenkov , Heiko Carstens Cc: Baoquan He , Christoph Hellwig , Vasily Gorbik , Al Viro , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v4 2/4] s390/crash: move copy_to_user_real() to crash_dump.c Date: Tue, 19 Jul 2022 07:16:34 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: J7H0ETT66FQCGBIkZ6JRPzT_Hn2fINvZ X-Proofpoint-GUID: pVKI15JBF9lXc3nlMSuVkdt8heUQeE-X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 impostorscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=731 suspectscore=0 clxscore=1015 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190019 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Function copy_to_user_real() does not really belong to maccess.c. It is only used for copying oldmem to user space, so let's move it to the friends. Signed-off-by: Alexander Gordeev Acked-by: Heiko Carstens Tested-by: Alexander Egorenkov --- arch/s390/include/asm/uaccess.h | 1 - arch/s390/kernel/crash_dump.c | 26 ++++++++++++++++++++++++++ arch/s390/mm/maccess.c | 26 -------------------------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uacces= s.h index f4511e21d646..2a067315fe59 100644 --- a/arch/s390/include/asm/uaccess.h +++ b/arch/s390/include/asm/uaccess.h @@ -285,7 +285,6 @@ static inline unsigned long __must_check clear_user(voi= d __user *to, unsigned lo return __clear_user(to, n); } =20 -int copy_to_user_real(void __user *dest, unsigned long src, unsigned long = count); void *s390_kernel_write(void *dst, const void *src, size_t size); =20 int __noreturn __put_kernel_bad(void); diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c index 0efee5c49b1e..8d7332d4444c 100644 --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -173,6 +173,32 @@ int copy_oldmem_kernel(void *dst, unsigned long src, s= ize_t count) return 0; } =20 +/* + * Copy memory from kernel (real) to user (virtual) + */ +static int copy_to_user_real(void __user *dest, unsigned long src, unsigne= d long count) +{ + int offs =3D 0, size, rc; + char *buf; + + buf =3D (char *)__get_free_page(GFP_KERNEL); + if (!buf) + return -ENOMEM; + rc =3D -EFAULT; + while (offs < count) { + size =3D min(PAGE_SIZE, count - offs); + if (memcpy_real(buf, src + offs, size)) + goto out; + if (copy_to_user(dest + offs, buf, size)) + goto out; + offs +=3D size; + } + rc =3D 0; +out: + free_page((unsigned long)buf); + return rc; +} + /* * Copy memory of the old, dumped system to a user space virtual address */ diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c index 421efa46946b..d6d84e02f35a 100644 --- a/arch/s390/mm/maccess.c +++ b/arch/s390/mm/maccess.c @@ -171,32 +171,6 @@ void memcpy_absolute(void *dest, void *src, size_t cou= nt) arch_local_irq_restore(flags); } =20 -/* - * Copy memory from kernel (real) to user (virtual) - */ -int copy_to_user_real(void __user *dest, unsigned long src, unsigned long = count) -{ - int offs =3D 0, size, rc; - char *buf; - - buf =3D (char *) __get_free_page(GFP_KERNEL); - if (!buf) - return -ENOMEM; - rc =3D -EFAULT; - while (offs < count) { - size =3D min(PAGE_SIZE, count - offs); - if (memcpy_real(buf, src + offs, size)) - goto out; - if (copy_to_user(dest + offs, buf, size)) - goto out; - offs +=3D size; - } - rc =3D 0; -out: - free_page((unsigned long) buf); - return rc; -} - /* * Check if physical address is within prefix or zero page */ --=20 2.34.1 From nobody Sat Apr 18 02:46:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CED01C43334 for ; Tue, 19 Jul 2022 05:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236525AbiGSF0y (ORCPT ); Tue, 19 Jul 2022 01:26:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235686AbiGSF0l (ORCPT ); Tue, 19 Jul 2022 01:26:41 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5237913F60; Mon, 18 Jul 2022 22:26:41 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J4xkaI017833; Tue, 19 Jul 2022 05:26:32 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=NFJpky4uco3lbQValaNSmJG54/jhmHCftSq6cGqKwPo=; b=Lf5TqBfwXMMsm4Xxg0p8Ng2DxusTn1NR/8xc1LQvOVxtlxqeWsCVHuqi+QVqn72IywdN szVCjsRtaB8vrny0HUWogTlee2XE1XaXODPOBk2dDxPLDVYYMcOv6svvs2pJ0ldbx7v9 pP8mFjjaQEjSnL0gVjsSsP3NZIJOzxsgJcfAW1T9TmYc8l8S/ZLELoCvSkgO6ZRdPWma 7Hf1w253UugThcVntatp1w1k46vnuW5LEUg98beX6saPW3BabqRcn8idGRCSjbDHumZ7 7rmyHnsH8JgHzjkR8s40AbUsZeXZywtFWtg/djLsZ6cDBV/KdMm4VlGSNhAMS6LMnRRZ YA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdp2wgjky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:32 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26J55XLT010333; Tue, 19 Jul 2022 05:26:31 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdp2wgjkd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:31 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26J5KmH4016644; Tue, 19 Jul 2022 05:26:29 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3hbmkj3hbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:29 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26J5QQj014156184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jul 2022 05:26:26 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0666411C054; Tue, 19 Jul 2022 05:26:26 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7CA211C04C; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55669) id 81E65E04D8; Tue, 19 Jul 2022 07:16:36 +0200 (CEST) From: Alexander Gordeev To: Matthew Wilcox , Alexander Egorenkov , Heiko Carstens Cc: Baoquan He , Christoph Hellwig , Vasily Gorbik , Al Viro , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v4 3/4] s390/crash: use static swap buffer for copy_to_user_real() Date: Tue, 19 Jul 2022 07:16:35 +0200 Message-Id: <334ed359680c4d45dd32feb104909f610312ef0f.1658206891.git.agordeev@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: gTSrczo0b3qgh1GEf65CMgfLJ7878cQz X-Proofpoint-ORIG-GUID: 9WeZ8ZgoP8roDIsHMbuxaCevs4HG48cp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 impostorscore=0 suspectscore=0 mlxscore=0 malwarescore=0 clxscore=1015 phishscore=0 bulkscore=0 spamscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190019 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently a temporary page-size buffer is allocated for copying oldmem to user space. That limits copy_to_user_real() operation only to stages when virtual memory is available and still makes it possible to fail while the system is being dumped. Instead of reallocating single page on each copy_oldmem_page() iteration use a statically allocated buffer. This also paves the way for a further memcpy_real() rework where no swap buffer is needed altogether. Signed-off-by: Alexander Gordeev Acked-by: Heiko Carstens Tested-by: Alexander Egorenkov --- arch/s390/kernel/crash_dump.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c index 8d7332d4444c..1662f1d81abe 100644 --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -53,6 +53,8 @@ struct save_area { }; =20 static LIST_HEAD(dump_save_areas); +static DEFINE_MUTEX(memcpy_real_mutex); +static char memcpy_real_buf[PAGE_SIZE]; =20 /* * Allocate a save area @@ -178,25 +180,21 @@ int copy_oldmem_kernel(void *dst, unsigned long src, = size_t count) */ static int copy_to_user_real(void __user *dest, unsigned long src, unsigne= d long count) { - int offs =3D 0, size, rc; - char *buf; + unsigned long offs =3D 0, size; =20 - buf =3D (char *)__get_free_page(GFP_KERNEL); - if (!buf) - return -ENOMEM; - rc =3D -EFAULT; + mutex_lock(&memcpy_real_mutex); while (offs < count) { size =3D min(PAGE_SIZE, count - offs); - if (memcpy_real(buf, src + offs, size)) - goto out; - if (copy_to_user(dest + offs, buf, size)) - goto out; + if (memcpy_real(memcpy_real_buf, src + offs, size)) + break; + if (copy_to_user(dest + offs, memcpy_real_buf, size)) + break; offs +=3D size; } - rc =3D 0; -out: - free_page((unsigned long)buf); - return rc; + mutex_unlock(&memcpy_real_mutex); + if (offs < count) + return -EFAULT; + return 0; } =20 /* --=20 2.34.1 From nobody Sat Apr 18 02:46:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF0DACCA483 for ; Tue, 19 Jul 2022 05:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236640AbiGSF04 (ORCPT ); Tue, 19 Jul 2022 01:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233271AbiGSF0n (ORCPT ); Tue, 19 Jul 2022 01:26:43 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0479C2408F; Mon, 18 Jul 2022 22:26:41 -0700 (PDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J5DhnY023315; Tue, 19 Jul 2022 05:26:32 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=GHbIcTb/DqS73smnmwTzFigD5dqs+A/EVrmL0mtm6AM=; b=AdZOizW9qY7D1N0IxyAuBSH86MwS5gqkRQJUwWdW5r5iZN/7EvQZdCg/a7T628tiqW4M JAJB5vxQEAJoBFjstiHBVup8m6Lu2tI5u3vvoZ6Mh8Zh+EEPLjHqDMjuQ2ng3DHPQt1a VwD79eXlx23Zr5UesrhnTmOK82J2AAzhZ6l2bESN2vw/dpay4Kgq2O6FBC04yMYRCSuU ZFPq7hdPN9UyTFiGnv49qRjzWb8bHXGMkASd6aS4MDZ2gQG0g2Gbz9h+PyyPGgbZimyT yyz0VDL7Aa965OIsste/jDmr3gRSJ0bb0qMLgOnDv4TK72ziz4QAPY2nteIU+F/Wm+h/ bg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdp9cr7v7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:32 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26J5Fn0I003868; Tue, 19 Jul 2022 05:26:31 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdp9cr7ut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:31 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26J5KfqX018179; Tue, 19 Jul 2022 05:26:29 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 3hbmy8um9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:29 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26J5QQai21823868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jul 2022 05:26:26 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFB7F5204F; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id DE5255204E; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55669) id 8494BE050F; Tue, 19 Jul 2022 07:16:36 +0200 (CEST) From: Alexander Gordeev To: Matthew Wilcox , Alexander Egorenkov , Heiko Carstens Cc: Baoquan He , Christoph Hellwig , Vasily Gorbik , Al Viro , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v4 4/4] s390/crash: support multi-segment iterators Date: Tue, 19 Jul 2022 07:16:36 +0200 Message-Id: <5af6da3a0bffe48a90b0b7139ecf6a818b2d18e8.1658206891.git.agordeev@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SuhCjwKEJDMXjS9EkVen5x1XA-BUYV-X X-Proofpoint-ORIG-GUID: xU7Ynz_IEeT75Qibfkoll8XKTLhUHwmJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190019 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make it possible to handle not only single-, but also multi- segment iterators in copy_oldmem_iter() callback. Change the semantics of called functions to match the iterator model - instead of an error code the exact number of bytes copied is returned. The swap page used to copy data to user space is adopted for kernel space too. That does not bring any performance impact. Suggested-by: Matthew Wilcox Fixes: 49b11524d648 ("s390/crash: add missing iterator advance in copy_oldm= em_page()") Signed-off-by: Alexander Gordeev Acked-by: Heiko Carstens Tested-by: Alexander Egorenkov --- arch/s390/include/asm/os_info.h | 17 ++++- arch/s390/include/asm/sclp.h | 4 +- arch/s390/kernel/crash_dump.c | 128 ++++++-------------------------- drivers/s390/char/zcore.c | 58 ++++++--------- 4 files changed, 63 insertions(+), 144 deletions(-) diff --git a/arch/s390/include/asm/os_info.h b/arch/s390/include/asm/os_inf= o.h index 147a8d547ef9..85248d8fee0c 100644 --- a/arch/s390/include/asm/os_info.h +++ b/arch/s390/include/asm/os_info.h @@ -8,6 +8,8 @@ #ifndef _ASM_S390_OS_INFO_H #define _ASM_S390_OS_INFO_H =20 +#include + #define OS_INFO_VERSION_MAJOR 1 #define OS_INFO_VERSION_MINOR 1 #define OS_INFO_MAGIC 0x4f53494e464f535aULL /* OSINFOSZ */ @@ -39,7 +41,20 @@ u32 os_info_csum(struct os_info *os_info); =20 #ifdef CONFIG_CRASH_DUMP void *os_info_old_entry(int nr, unsigned long *size); -int copy_oldmem_kernel(void *dst, unsigned long src, size_t count); +size_t copy_oldmem_iter(struct iov_iter *iter, unsigned long src, size_t c= ount); + +static inline int copy_oldmem_kernel(void *dst, unsigned long src, size_t = count) +{ + struct iov_iter iter; + struct kvec kvec; + + kvec.iov_base =3D dst; + kvec.iov_len =3D count; + iov_iter_kvec(&iter, WRITE, &kvec, 1, count); + if (copy_oldmem_iter(&iter, src, count) < count) + return -EFAULT; + return 0; +} #else static inline void *os_info_old_entry(int nr, unsigned long *size) { diff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h index addefe8ccdba..9d4c7f71e070 100644 --- a/arch/s390/include/asm/sclp.h +++ b/arch/s390/include/asm/sclp.h @@ -17,6 +17,7 @@ #define EXT_SCCB_READ_CPU (3 * PAGE_SIZE) =20 #ifndef __ASSEMBLY__ +#include #include #include =20 @@ -146,8 +147,7 @@ int sclp_pci_deconfigure(u32 fid); int sclp_ap_configure(u32 apid); int sclp_ap_deconfigure(u32 apid); int sclp_pci_report(struct zpci_report_error_header *report, u32 fh, u32 f= id); -int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count); -int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count); +size_t memcpy_hsa_iter(struct iov_iter *iter, unsigned long src, size_t co= unt); void sclp_ocf_cpc_name_copy(char *dst); =20 static inline int sclp_get_core_info(struct sclp_core_info *info, int earl= y) diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c index 1662f1d81abe..bad8f47fc5d6 100644 --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -116,102 +116,35 @@ void __init save_area_add_vxrs(struct save_area *sa,= __vector128 *vxrs) memcpy(sa->vxrs_high, vxrs + 16, 16 * sizeof(__vector128)); } =20 -/* - * Return physical address for virtual address - */ -static inline void *load_real_addr(void *addr) -{ - unsigned long real_addr; - - asm volatile( - " lra %0,0(%1)\n" - " jz 0f\n" - " la %0,0\n" - "0:" - : "=3Da" (real_addr) : "a" (addr) : "cc"); - return (void *)real_addr; -} - -/* - * Copy memory of the old, dumped system to a kernel space virtual address - */ -int copy_oldmem_kernel(void *dst, unsigned long src, size_t count) -{ - unsigned long len; - void *ra; - int rc; - - while (count) { - if (!oldmem_data.start && src < sclp.hsa_size) { - /* Copy from zfcp/nvme dump HSA area */ - len =3D min(count, sclp.hsa_size - src); - rc =3D memcpy_hsa_kernel(dst, src, len); - if (rc) - return rc; - } else { - /* Check for swapped kdump oldmem areas */ - if (oldmem_data.start && src - oldmem_data.start < oldmem_data.size) { - src -=3D oldmem_data.start; - len =3D min(count, oldmem_data.size - src); - } else if (oldmem_data.start && src < oldmem_data.size) { - len =3D min(count, oldmem_data.size - src); - src +=3D oldmem_data.start; - } else { - len =3D count; - } - if (is_vmalloc_or_module_addr(dst)) { - ra =3D load_real_addr(dst); - len =3D min(PAGE_SIZE - offset_in_page(ra), len); - } else { - ra =3D dst; - } - if (memcpy_real(ra, src, len)) - return -EFAULT; - } - dst +=3D len; - src +=3D len; - count -=3D len; - } - return 0; -} - -/* - * Copy memory from kernel (real) to user (virtual) - */ -static int copy_to_user_real(void __user *dest, unsigned long src, unsigne= d long count) +static size_t copy_to_iter_real(struct iov_iter *iter, unsigned long src, = size_t count) { - unsigned long offs =3D 0, size; + size_t len, copied, res =3D 0; =20 mutex_lock(&memcpy_real_mutex); - while (offs < count) { - size =3D min(PAGE_SIZE, count - offs); - if (memcpy_real(memcpy_real_buf, src + offs, size)) + while (count) { + len =3D min(PAGE_SIZE, count); + if (memcpy_real(memcpy_real_buf, src, len)) break; - if (copy_to_user(dest + offs, memcpy_real_buf, size)) + copied =3D copy_to_iter(memcpy_real_buf, len, iter); + count -=3D copied; + src +=3D copied; + res +=3D copied; + if (copied < len) break; - offs +=3D size; } mutex_unlock(&memcpy_real_mutex); - if (offs < count) - return -EFAULT; - return 0; + return res; } =20 -/* - * Copy memory of the old, dumped system to a user space virtual address - */ -static int copy_oldmem_user(void __user *dst, unsigned long src, size_t co= unt) +size_t copy_oldmem_iter(struct iov_iter *iter, unsigned long src, size_t c= ount) { - unsigned long len; - int rc; + size_t len, copied, res =3D 0; =20 while (count) { if (!oldmem_data.start && src < sclp.hsa_size) { /* Copy from zfcp/nvme dump HSA area */ len =3D min(count, sclp.hsa_size - src); - rc =3D memcpy_hsa_user(dst, src, len); - if (rc) - return rc; + copied =3D memcpy_hsa_iter(iter, src, len); } else { /* Check for swapped kdump oldmem areas */ if (oldmem_data.start && src - oldmem_data.start < oldmem_data.size) { @@ -223,15 +156,15 @@ static int copy_oldmem_user(void __user *dst, unsigne= d long src, size_t count) } else { len =3D count; } - rc =3D copy_to_user_real(dst, src, len); - if (rc) - return rc; + copied =3D copy_to_iter_real(iter, src, len); } - dst +=3D len; - src +=3D len; - count -=3D len; + count -=3D copied; + src +=3D copied; + res +=3D copied; + if (copied < len) + break; } - return 0; + return res; } =20 /* @@ -241,26 +174,9 @@ ssize_t copy_oldmem_page(struct iov_iter *iter, unsign= ed long pfn, size_t csize, unsigned long offset) { unsigned long src; - int rc; =20 - if (!(iter_is_iovec(iter) || iov_iter_is_kvec(iter))) - return -EINVAL; - /* Multi-segment iterators are not supported */ - if (iter->nr_segs > 1) - return -EINVAL; - if (!csize) - return 0; src =3D pfn_to_phys(pfn) + offset; - - /* XXX: pass the iov_iter down to a common function */ - if (iter_is_iovec(iter)) - rc =3D copy_oldmem_user(iter->iov->iov_base, src, csize); - else - rc =3D copy_oldmem_kernel(iter->kvec->iov_base, src, csize); - if (rc < 0) - return rc; - iov_iter_advance(iter, csize); - return csize; + return copy_oldmem_iter(iter, src, csize); } =20 /* diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c index 92b32ce645b9..f6da215ccf9f 100644 --- a/drivers/s390/char/zcore.c +++ b/drivers/s390/char/zcore.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 #include #include @@ -54,38 +55,37 @@ static DEFINE_MUTEX(hsa_buf_mutex); static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE); =20 /* - * Copy memory from HSA to user memory (not reentrant): + * Copy memory from HSA to iterator (not reentrant): * - * @dest: User buffer where memory should be copied to + * @iter: Iterator where memory should be copied to * @src: Start address within HSA where data should be copied * @count: Size of buffer, which should be copied */ -int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count) +size_t memcpy_hsa_iter(struct iov_iter *iter, unsigned long src, size_t co= unt) { - unsigned long offset, bytes; + size_t bytes, copied, res =3D 0; + unsigned long offset; =20 if (!hsa_available) - return -ENODATA; + return 0; =20 mutex_lock(&hsa_buf_mutex); while (count) { if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) { TRACE("sclp_sdias_copy() failed\n"); - mutex_unlock(&hsa_buf_mutex); - return -EIO; + break; } offset =3D src % PAGE_SIZE; bytes =3D min(PAGE_SIZE - offset, count); - if (copy_to_user(dest, hsa_buf + offset, bytes)) { - mutex_unlock(&hsa_buf_mutex); - return -EFAULT; - } - src +=3D bytes; - dest +=3D bytes; - count -=3D bytes; + copied =3D copy_to_iter(hsa_buf + offset, bytes, iter); + count -=3D copied; + src +=3D copied; + res +=3D copied; + if (copied < bytes) + break; } mutex_unlock(&hsa_buf_mutex); - return 0; + return res; } =20 /* @@ -95,28 +95,16 @@ int memcpy_hsa_user(void __user *dest, unsigned long sr= c, size_t count) * @src: Start address within HSA where data should be copied * @count: Size of buffer, which should be copied */ -int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count) +static inline int memcpy_hsa_kernel(void *dst, unsigned long src, size_t c= ount) { - unsigned long offset, bytes; + struct iov_iter iter; + struct kvec kvec; =20 - if (!hsa_available) - return -ENODATA; - - mutex_lock(&hsa_buf_mutex); - while (count) { - if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) { - TRACE("sclp_sdias_copy() failed\n"); - mutex_unlock(&hsa_buf_mutex); - return -EIO; - } - offset =3D src % PAGE_SIZE; - bytes =3D min(PAGE_SIZE - offset, count); - memcpy(dest, hsa_buf + offset, bytes); - src +=3D bytes; - dest +=3D bytes; - count -=3D bytes; - } - mutex_unlock(&hsa_buf_mutex); + kvec.iov_base =3D dst; + kvec.iov_len =3D count; + iov_iter_kvec(&iter, WRITE, &kvec, 1, count); + if (memcpy_hsa_iter(&iter, src, count) < count) + return -EIO; return 0; } =20 --=20 2.34.1