Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5535757pxb; Wed, 26 Jan 2022 14:24:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1vjZTc6zXAdXnqy9oYXYxmN2xvq7Wh7imqGhjUqKMxFUgFTHXbUA22qf7W4NUoG0bMX+u X-Received: by 2002:aa7:da81:: with SMTP id q1mr998056eds.25.1643235886019; Wed, 26 Jan 2022 14:24:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643235886; cv=none; d=google.com; s=arc-20160816; b=pzuqz2B/SulqcdvlQB012Ig+v5qjk40iSUcZEBnS/7yRckt76PcsF5FT70W2ZKtWE0 7O6GysnJTlOsB1h+0HbWs3qa0gvAiBf+AV4lUBYi9zL2H6IGIHA6SKvIGVRY7vEcgR+H techWNu+qFtgSpM9tHyHESkr3iNZWbf/FwKBcUzeFK8GjylcfviAAlccJXbOjL77LONS /xzCssZchmj4YhLsb2WiqMaFVVidZl7kLYCNcSrB2Da46mF9fmqeT6Xn6HhOv7r6GK+r ph75NMuduKWEhL0WgglLZJXl0piqRDOmvU366KL7RjgG1RnzWy7uWSxt1KGPOjonEQDY b/tg== 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=8kp/kdqZYSDOTB99cbJOrLYGHcreBh0cH6sdXNt8tlU=; b=mWvg2KbymbPdWHSmop1PzTvN1/ejbSq6I8nydmwsvfhlwjnMT/8uM2ZY7mU8KBkSE5 8FDy1mXE8fqe9hFc1X808jQ2Y2IgBWB++5t8Xx45BoPhA1G1ACaS9ZwGgw5t3Hx5yv1+ DVaXNhkMw6OP7Aka69wJbVsv1GzzFEZNmopEMJoguomtDLEUhA2/4eewyR/DGTuTyVW2 Z8UVWUM4fYI9RCMhcldLZPVf7XcfqOaYTGAt3SwSCdfGqbfv1ybzfoLr6PAt2agurBPS zkCBzVH4On+h2RIuGB7voKvt6HSYwjHhJklcJyACLxETaHeTxCeF/Z56Z03wHYHjdNs9 n8LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Q7TXcAj2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x21si272960eds.528.2022.01.26.14.24.21; Wed, 26 Jan 2022 14:24:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Q7TXcAj2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243779AbiAZReO (ORCPT + 99 others); Wed, 26 Jan 2022 12:34:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49850 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243769AbiAZReN (ORCPT ); Wed, 26 Jan 2022 12:34:13 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20QHDWej022868; Wed, 26 Jan 2022 17:34:09 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=8kp/kdqZYSDOTB99cbJOrLYGHcreBh0cH6sdXNt8tlU=; b=Q7TXcAj2j5wQsdq6NcVM6L+62KPa9KpA9Vb6k0M+4QDYpoRC5YZ3yfN0uHSBo/J+WE2N FYOKSvrIrix7nSFzs3DrRMKZ28lYM9fEEWj8+3nAB/9LKemkKLCGZ3DnaauTjjU2cnVp VrdqnemMjidFgJ9GI7zT06KmX2wGvuj4E1YsNBK8OvrcShwiIAj6Isl8rbWbp1NekwQO EpUjIPnkl0QxIUUnzXaUMadRJT/ww/u55ff2aqz3j1/0fC7wPze/arE+spcOFGvKDK1n qICDdmC3grpPFcXQZg1qDr91DfD00/LPdJxuyCSTSMrEN3Qrcyh3Qgv69WD1fpFjrua5 nA== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3duagwgdqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 17:34:08 +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 20QHWTjv030510; Wed, 26 Jan 2022 17:34:05 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3dr96jr9rj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 17:34:05 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 20QHY2Up32178436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Jan 2022 17:34:02 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 822384203F; Wed, 26 Jan 2022 17:34:02 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B89E42041; Wed, 26 Jan 2022 17:34:02 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 Jan 2022 17:34:02 +0000 (GMT) From: Janis Schoetterl-Glausch To: Arnd Bergmann , Andrew Morton , Heiko Carstens Cc: Janis Schoetterl-Glausch , Alexander Viro , Kees Cook , Christian Borntraeger , linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] s390/uaccess: Provide raw_copy_from/to_user_key Date: Wed, 26 Jan 2022 18:33:58 +0100 Message-Id: <20220126173358.2951879-3-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220126173358.2951879-1-scgl@linux.ibm.com> References: <20220126173358.2951879-1-scgl@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UoU--Z2AOjDmpzQGgcpCoT_UAG-uLCVG X-Proofpoint-ORIG-GUID: UoU--Z2AOjDmpzQGgcpCoT_UAG-uLCVG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-26_06,2022-01-26_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 clxscore=1011 phishscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201260107 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This makes the user access functions that perform storage key checking available, so they can be used by KVM for emulation. Since the existing uaccess implementation on s390 makes use of move instructions that support having an additional access key supplied, we can implement raw_copy_from/to_user_key by enhancing the existing implementation. Signed-off-by: Janis Schoetterl-Glausch --- arch/s390/include/asm/uaccess.h | 22 +++++++++++++-- arch/s390/lib/uaccess.c | 48 +++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h index 147cb3534ce4..422066d7c5e2 100644 --- a/arch/s390/include/asm/uaccess.h +++ b/arch/s390/include/asm/uaccess.h @@ -33,15 +33,33 @@ static inline int __range_ok(unsigned long addr, unsigned long size) #define access_ok(addr, size) __access_ok(addr, size) +#define raw_copy_from_user_key raw_copy_from_user_key unsigned long __must_check -raw_copy_from_user(void *to, const void __user *from, unsigned long n); +raw_copy_from_user_key(void *to, const void __user *from, unsigned long n, + unsigned long key); +#define raw_copy_to_user_key raw_copy_to_user_key unsigned long __must_check -raw_copy_to_user(void __user *to, const void *from, unsigned long n); +raw_copy_to_user_key(void __user *to, const void *from, unsigned long n, + unsigned long key); + +static __always_inline unsigned long __must_check +raw_copy_from_user(void *to, const void __user *from, unsigned long n) +{ + return raw_copy_from_user_key(to, from, n, 0); +} + +static __always_inline unsigned long __must_check +raw_copy_to_user(void __user *to, const void *from, unsigned long n) +{ + return raw_copy_to_user_key(to, from, n, 0); +} #ifndef CONFIG_KASAN #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER +#define INLINE_COPY_FROM_USER_KEY +#define INLINE_COPY_TO_USER_KEY #endif int __put_user_bad(void) __attribute__((noreturn)); diff --git a/arch/s390/lib/uaccess.c b/arch/s390/lib/uaccess.c index 8a5d21461889..689a5ab3121a 100644 --- a/arch/s390/lib/uaccess.c +++ b/arch/s390/lib/uaccess.c @@ -59,11 +59,13 @@ static inline int copy_with_mvcos(void) #endif static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr, - unsigned long size) + unsigned long size, unsigned long key) { unsigned long tmp1, tmp2; union oac spec = { + .oac2.key = key, .oac2.as = PSW_BITS_AS_SECONDARY, + .oac2.k = 1, .oac2.a = 1, }; @@ -94,19 +96,19 @@ static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr } static inline unsigned long copy_from_user_mvcp(void *x, const void __user *ptr, - unsigned long size) + unsigned long size, unsigned long key) { unsigned long tmp1, tmp2; tmp1 = -256UL; asm volatile( " sacf 0\n" - "0: mvcp 0(%0,%2),0(%1),%3\n" + "0: mvcp 0(%0,%2),0(%1),%[key]\n" "7: jz 5f\n" "1: algr %0,%3\n" " la %1,256(%1)\n" " la %2,256(%2)\n" - "2: mvcp 0(%0,%2),0(%1),%3\n" + "2: mvcp 0(%0,%2),0(%1),%[key]\n" "8: jnz 1b\n" " j 5f\n" "3: la %4,255(%1)\n" /* %4 = ptr + 255 */ @@ -115,7 +117,7 @@ static inline unsigned long copy_from_user_mvcp(void *x, const void __user *ptr, " slgr %4,%1\n" " clgr %0,%4\n" /* copy crosses next page boundary? */ " jnh 6f\n" - "4: mvcp 0(%4,%2),0(%1),%3\n" + "4: mvcp 0(%4,%2),0(%1),%[key]\n" "9: slgr %0,%4\n" " j 6f\n" "5: slgr %0,%0\n" @@ -123,24 +125,28 @@ static inline unsigned long copy_from_user_mvcp(void *x, const void __user *ptr, EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b) EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) - : : "cc", "memory"); + : [key] "d" (key << 4) + : "cc", "memory"); return size; } -unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n) +unsigned long raw_copy_from_user_key(void *to, const void __user *from, + unsigned long n, unsigned long key) { if (copy_with_mvcos()) - return copy_from_user_mvcos(to, from, n); - return copy_from_user_mvcp(to, from, n); + return copy_from_user_mvcos(to, from, n, key); + return copy_from_user_mvcp(to, from, n, key); } -EXPORT_SYMBOL(raw_copy_from_user); +EXPORT_SYMBOL(raw_copy_from_user_key); static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x, - unsigned long size) + unsigned long size, unsigned long key) { unsigned long tmp1, tmp2; union oac spec = { + .oac1.key = key, .oac1.as = PSW_BITS_AS_SECONDARY, + .oac1.k = 1, .oac1.a = 1, }; @@ -171,19 +177,19 @@ static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x, } static inline unsigned long copy_to_user_mvcs(void __user *ptr, const void *x, - unsigned long size) + unsigned long size, unsigned long key) { unsigned long tmp1, tmp2; tmp1 = -256UL; asm volatile( " sacf 0\n" - "0: mvcs 0(%0,%1),0(%2),%3\n" + "0: mvcs 0(%0,%1),0(%2),%[key]\n" "7: jz 5f\n" "1: algr %0,%3\n" " la %1,256(%1)\n" " la %2,256(%2)\n" - "2: mvcs 0(%0,%1),0(%2),%3\n" + "2: mvcs 0(%0,%1),0(%2),%[key]\n" "8: jnz 1b\n" " j 5f\n" "3: la %4,255(%1)\n" /* %4 = ptr + 255 */ @@ -192,7 +198,7 @@ static inline unsigned long copy_to_user_mvcs(void __user *ptr, const void *x, " slgr %4,%1\n" " clgr %0,%4\n" /* copy crosses next page boundary? */ " jnh 6f\n" - "4: mvcs 0(%4,%1),0(%2),%3\n" + "4: mvcs 0(%4,%1),0(%2),%[key]\n" "9: slgr %0,%4\n" " j 6f\n" "5: slgr %0,%0\n" @@ -200,17 +206,19 @@ static inline unsigned long copy_to_user_mvcs(void __user *ptr, const void *x, EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b) EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) - : : "cc", "memory"); + : [key] "d" (key << 4) + : "cc", "memory"); return size; } -unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n) +unsigned long raw_copy_to_user_key(void __user *to, const void *from, + unsigned long n, unsigned long key) { if (copy_with_mvcos()) - return copy_to_user_mvcos(to, from, n); - return copy_to_user_mvcs(to, from, n); + return copy_to_user_mvcos(to, from, n, key); + return copy_to_user_mvcs(to, from, n, key); } -EXPORT_SYMBOL(raw_copy_to_user); +EXPORT_SYMBOL(raw_copy_to_user_key); static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size) { -- 2.32.0