From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Laight Subject: RE: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Date: Wed, 16 Feb 2022 13:35:25 +0000 Message-ID: <4a7e026b07c94668a18cb4857ad6b7a5@AcuMS.aculab.com> References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-3-arnd@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jr3Dh3k7CC7YgbsgaubNDDBD8Tig0SDZzvDMZMY1Ihw=; b=skLxJe66B/MSAF qnnbXTc19HanljddGLWPTdYvlhvzVkyljShFrjJdPpDY1p+F40Hzp8oYreaO7RgeCMywkENf6y9kw XZ9iIKflbj78D0uRvHYRXqFwjYNtYPUl7w59/Snt727RPespBb1yu5M0eMWIpG2whOJU7WLk5CY6s qs6pjZXtStfk6H8iEuXacPi1+ZZulLIn9X/2fLnY+DpxHBYV8pa5KgS5MRU3pMXVrk2+8M4ZSPyGM cLQJ6Sm6I7ZOn/dLmIgjUGMyUcB27TdMCwvulDok/oc5zy6UE7HrHXiCOrB0GaNc9dsneLQd+yw5b iUzzdyDr97Y/Gli07eeA==; In-Reply-To: <20220216131332.1489939-3-arnd@kernel.org> Content-Language: en-US List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+glpr-linux-riscv=m.gmane-mx.org@lists.infradead.org To: 'Arnd Bergmann' , Linus Torvalds , Christoph Hellwig , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" Cc: "linux@armlinux.org.uk" , "will@kernel.org" , "guoren@kernel.org" , "bcain@codeaurora.org" , "geert@linux-m68k.org" , "monstr@monstr.eu" , "tsbogend@alpha.franken.de" , "nickhu@andestech.com" , "green.hu@gmail.com" , "dinguyen@kernel.org" , "shorne@gmail.com" , "deller@gmx.de" , "mpe@ellerman.id.au" , "peterz@infradead.org" , "mingo@redhat.com" , "mark.rutland@arm.com" , "hca@linux.ibm.com" , "dalias@libc.org" , "davem@davemloft.net" , "richard@nod.at" , "x86@kernel.org" From: Arnd Bergmann > Sent: 16 February 2022 13:13 > > These two architectures implement 8-byte get_user() through > a memcpy() into a four-byte variable, which won't fit. > > Use a temporary 64-bit variable instead here, and use a double > cast the way that risc-v and openrisc do to avoid compile-time > warnings. > ... > case 4: \ > - __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ > + __get_user_asm("lw", (ptr), x, __gu_err); \ > break; \ > - case 8: \ > - __gu_err = __copy_from_user(&__gu_val, ptr, 8); \ > - if (__gu_err) \ > - __gu_err = -EFAULT; \ > + case 8: { \ > + __u64 __x = 0; \ > + __gu_err = raw_copy_from_user(&__x, ptr, 8) ? \ > + -EFAULT : 0; \ > + (x) = (typeof(x))(typeof((x) - (x)))__x; \ > break; \ Wouldn't it be better to just fetch two 32bit values: Something like (for LE - nios2 is definitely LE: __u32 val_lo, val_hi; __get_user_asm("lw", (ptr), val_lo, __gu_err); __get_user_asm("lw", (ptr) + 4, val_hi, __gu_err); x = val_lo | val_hi << 32; break; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From mboxrd@z Thu Jan 1 00:00:00 1970 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 DD365C4167E for ; Wed, 16 Feb 2022 13:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234553AbiBPNf7 convert rfc822-to-8bit (ORCPT ); Wed, 16 Feb 2022 08:35:59 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234574AbiBPNfp (ORCPT ); Wed, 16 Feb 2022 08:35:45 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5148F2ABD0F for ; Wed, 16 Feb 2022 05:35:30 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mtapsc-5-x7kvjQ_dNbmfJSCohruuVA-1; Wed, 16 Feb 2022 13:35:28 +0000 X-MC-Unique: x7kvjQ_dNbmfJSCohruuVA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Wed, 16 Feb 2022 13:35:25 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Wed, 16 Feb 2022 13:35:25 +0000 From: David Laight To: 'Arnd Bergmann' , Linus Torvalds , Christoph Hellwig , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" CC: "linux@armlinux.org.uk" , "will@kernel.org" , "guoren@kernel.org" , "bcain@codeaurora.org" , "geert@linux-m68k.org" , "monstr@monstr.eu" , "tsbogend@alpha.franken.de" , "nickhu@andestech.com" , "green.hu@gmail.com" , "dinguyen@kernel.org" , "shorne@gmail.com" , "deller@gmx.de" , "mpe@ellerman.id.au" , "peterz@infradead.org" , "mingo@redhat.com" , "mark.rutland@arm.com" , "hca@linux.ibm.com" , "dalias@libc.org" , "davem@davemloft.net" , "richard@nod.at" , "x86@kernel.org" , "jcmvbkbc@gmail.com" , "ebiederm@xmission.com" , "akpm@linux-foundation.org" , "ardb@kernel.org" , "linux-alpha@vger.kernel.org" , "linux-snps-arc@lists.infradead.org" , "linux-csky@vger.kernel.org" , "linux-hexagon@vger.kernel.org" , "linux-ia64@vger.kernel.org" , "linux-m68k@lists.linux-m68k.org" , "linux-mips@vger.kernel.org" , "openrisc@lists.librecores.org" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "linux-sh@vger.kernel.org" , "sparclinux@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-xtensa@linux-xtensa.org" Subject: RE: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Topic: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Index: AQHYIzdfY+IsqXyFuUGlEUsFmAHn6KyWK9Eg Date: Wed, 16 Feb 2022 13:35:25 +0000 Message-ID: <4a7e026b07c94668a18cb4857ad6b7a5@AcuMS.aculab.com> References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-3-arnd@kernel.org> In-Reply-To: <20220216131332.1489939-3-arnd@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org From: Arnd Bergmann > Sent: 16 February 2022 13:13 > > These two architectures implement 8-byte get_user() through > a memcpy() into a four-byte variable, which won't fit. > > Use a temporary 64-bit variable instead here, and use a double > cast the way that risc-v and openrisc do to avoid compile-time > warnings. > ... > case 4: \ > - __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ > + __get_user_asm("lw", (ptr), x, __gu_err); \ > break; \ > - case 8: \ > - __gu_err = __copy_from_user(&__gu_val, ptr, 8); \ > - if (__gu_err) \ > - __gu_err = -EFAULT; \ > + case 8: { \ > + __u64 __x = 0; \ > + __gu_err = raw_copy_from_user(&__x, ptr, 8) ? \ > + -EFAULT : 0; \ > + (x) = (typeof(x))(typeof((x) - (x)))__x; \ > break; \ Wouldn't it be better to just fetch two 32bit values: Something like (for LE - nios2 is definitely LE: __u32 val_lo, val_hi; __get_user_asm("lw", (ptr), val_lo, __gu_err); __get_user_asm("lw", (ptr) + 4, val_hi, __gu_err); x = val_lo | val_hi << 32; break; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 471AEC433EF for ; Wed, 16 Feb 2022 13:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jr3Dh3k7CC7YgbsgaubNDDBD8Tig0SDZzvDMZMY1Ihw=; b=skLxJe66B/MSAF qnnbXTc19HanljddGLWPTdYvlhvzVkyljShFrjJdPpDY1p+F40Hzp8oYreaO7RgeCMywkENf6y9kw XZ9iIKflbj78D0uRvHYRXqFwjYNtYPUl7w59/Snt727RPespBb1yu5M0eMWIpG2whOJU7WLk5CY6s qs6pjZXtStfk6H8iEuXacPi1+ZZulLIn9X/2fLnY+DpxHBYV8pa5KgS5MRU3pMXVrk2+8M4ZSPyGM cLQJ6Sm6I7ZOn/dLmIgjUGMyUcB27TdMCwvulDok/oc5zy6UE7HrHXiCOrB0GaNc9dsneLQd+yw5b iUzzdyDr97Y/Gli07eeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKKT5-007Dhx-Ti; Wed, 16 Feb 2022 13:35:39 +0000 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKKT1-007Dck-2t for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 13:35:37 +0000 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mtapsc-5-x7kvjQ_dNbmfJSCohruuVA-1; Wed, 16 Feb 2022 13:35:28 +0000 X-MC-Unique: x7kvjQ_dNbmfJSCohruuVA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Wed, 16 Feb 2022 13:35:25 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Wed, 16 Feb 2022 13:35:25 +0000 From: David Laight To: 'Arnd Bergmann' , Linus Torvalds , Christoph Hellwig , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" CC: "linux@armlinux.org.uk" , "will@kernel.org" , "guoren@kernel.org" , "bcain@codeaurora.org" , "geert@linux-m68k.org" , "monstr@monstr.eu" , "tsbogend@alpha.franken.de" , "nickhu@andestech.com" , "green.hu@gmail.com" , "dinguyen@kernel.org" , "shorne@gmail.com" , "deller@gmx.de" , "mpe@ellerman.id.au" , "peterz@infradead.org" , "mingo@redhat.com" , "mark.rutland@arm.com" , "hca@linux.ibm.com" , "dalias@libc.org" , "davem@davemloft.net" , "richard@nod.at" , "x86@kernel.org" , "jcmvbkbc@gmail.com" , "ebiederm@xmission.com" , "akpm@linux-foundation.org" , "ardb@kernel.org" , "linux-alpha@vger.kernel.org" , "linux-snps-arc@lists.infradead.org" , "linux-csky@vger.kernel.org" , "linux-hexagon@vger.kernel.org" , "linux-ia64@vger.kernel.org" , "linux-m68k@lists.linux-m68k.org" , "linux-mips@vger.kernel.org" , "openrisc@lists.librecores.org" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "linux-sh@vger.kernel.org" , "sparclinux@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-xtensa@linux-xtensa.org" Subject: RE: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Topic: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Index: AQHYIzdfY+IsqXyFuUGlEUsFmAHn6KyWK9Eg Date: Wed, 16 Feb 2022 13:35:25 +0000 Message-ID: <4a7e026b07c94668a18cb4857ad6b7a5@AcuMS.aculab.com> References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-3-arnd@kernel.org> In-Reply-To: <20220216131332.1489939-3-arnd@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_053535_419303_A3047C9A X-CRM114-Status: UNSURE ( 7.24 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann > Sent: 16 February 2022 13:13 > > These two architectures implement 8-byte get_user() through > a memcpy() into a four-byte variable, which won't fit. > > Use a temporary 64-bit variable instead here, and use a double > cast the way that risc-v and openrisc do to avoid compile-time > warnings. > ... > case 4: \ > - __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ > + __get_user_asm("lw", (ptr), x, __gu_err); \ > break; \ > - case 8: \ > - __gu_err = __copy_from_user(&__gu_val, ptr, 8); \ > - if (__gu_err) \ > - __gu_err = -EFAULT; \ > + case 8: { \ > + __u64 __x = 0; \ > + __gu_err = raw_copy_from_user(&__x, ptr, 8) ? \ > + -EFAULT : 0; \ > + (x) = (typeof(x))(typeof((x) - (x)))__x; \ > break; \ Wouldn't it be better to just fetch two 32bit values: Something like (for LE - nios2 is definitely LE: __u32 val_lo, val_hi; __get_user_asm("lw", (ptr), val_lo, __gu_err); __get_user_asm("lw", (ptr) + 4, val_hi, __gu_err); x = val_lo | val_hi << 32; break; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55331C433F5 for ; Wed, 16 Feb 2022 13:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Nih0PaW9DzMILO8ja+Xdwg3quUpHazJAPgfheo131sA=; b=w1dUpxNf7d2CPA F1hBmDyzBMaVx2yKiPdtcl4R76gl998TmE/Aw0skohzbsCiWlUyxGFoDjDDS4iMiyaYH/QffsgCxq R1RnVuCqbJe5zva9KL2W1I8ErLaM8UqGERbrcHgMUfY4OIrMtCcnG8+SUZNpe9ks7LwB6jFhEuVD8 msDLD4CFdl7xMRAO4lBNAMh9P8lmvoBTLFtzBBNk1hAs9z8O/ROwlEuRwG2umHJTnTkd5x1kQHppz O2zbhZK0+X2xyM4WEVOuIar48OXk5DR3LQkKPn50xT96+TlV23QyhHqRid+YD1qnCfPV1pZMHge4w ZdepTI3DnNjgjBQoefJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKKT3-007Dgf-E5; Wed, 16 Feb 2022 13:35:37 +0000 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKKT0-007Dcl-Hw for linux-snps-arc@lists.infradead.org; Wed, 16 Feb 2022 13:35:36 +0000 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mtapsc-5-x7kvjQ_dNbmfJSCohruuVA-1; Wed, 16 Feb 2022 13:35:28 +0000 X-MC-Unique: x7kvjQ_dNbmfJSCohruuVA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Wed, 16 Feb 2022 13:35:25 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Wed, 16 Feb 2022 13:35:25 +0000 From: David Laight To: 'Arnd Bergmann' , Linus Torvalds , Christoph Hellwig , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" CC: "linux@armlinux.org.uk" , "will@kernel.org" , "guoren@kernel.org" , "bcain@codeaurora.org" , "geert@linux-m68k.org" , "monstr@monstr.eu" , "tsbogend@alpha.franken.de" , "nickhu@andestech.com" , "green.hu@gmail.com" , "dinguyen@kernel.org" , "shorne@gmail.com" , "deller@gmx.de" , "mpe@ellerman.id.au" , "peterz@infradead.org" , "mingo@redhat.com" , "mark.rutland@arm.com" , "hca@linux.ibm.com" , "dalias@libc.org" , "davem@davemloft.net" , "richard@nod.at" , "x86@kernel.org" , "jcmvbkbc@gmail.com" , "ebiederm@xmission.com" , "akpm@linux-foundation.org" , "ardb@kernel.org" , "linux-alpha@vger.kernel.org" , "linux-snps-arc@lists.infradead.org" , "linux-csky@vger.kernel.org" , "linux-hexagon@vger.kernel.org" , "linux-ia64@vger.kernel.org" , "linux-m68k@lists.linux-m68k.org" , "linux-mips@vger.kernel.org" , "openrisc@lists.librecores.org" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "linux-sh@vger.kernel.org" , "sparclinux@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-xtensa@linux-xtensa.org" Subject: RE: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Topic: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Index: AQHYIzdfY+IsqXyFuUGlEUsFmAHn6KyWK9Eg Date: Wed, 16 Feb 2022 13:35:25 +0000 Message-ID: <4a7e026b07c94668a18cb4857ad6b7a5@AcuMS.aculab.com> References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-3-arnd@kernel.org> In-Reply-To: <20220216131332.1489939-3-arnd@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_053534_898746_DF0A13E3 X-CRM114-Status: UNSURE ( 7.24 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann > Sent: 16 February 2022 13:13 > > These two architectures implement 8-byte get_user() through > a memcpy() into a four-byte variable, which won't fit. > > Use a temporary 64-bit variable instead here, and use a double > cast the way that risc-v and openrisc do to avoid compile-time > warnings. > ... > case 4: \ > - __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ > + __get_user_asm("lw", (ptr), x, __gu_err); \ > break; \ > - case 8: \ > - __gu_err = __copy_from_user(&__gu_val, ptr, 8); \ > - if (__gu_err) \ > - __gu_err = -EFAULT; \ > + case 8: { \ > + __u64 __x = 0; \ > + __gu_err = raw_copy_from_user(&__x, ptr, 8) ? \ > + -EFAULT : 0; \ > + (x) = (typeof(x))(typeof((x) - (x)))__x; \ > break; \ Wouldn't it be better to just fetch two 32bit values: Something like (for LE - nios2 is definitely LE: __u32 val_lo, val_hi; __get_user_asm("lw", (ptr), val_lo, __gu_err); __get_user_asm("lw", (ptr) + 4, val_hi, __gu_err); x = val_lo | val_hi << 32; break; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Laight Date: Wed, 16 Feb 2022 13:35:25 +0000 Subject: [OpenRISC] [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() In-Reply-To: <20220216131332.1489939-3-arnd@kernel.org> References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-3-arnd@kernel.org> Message-ID: <4a7e026b07c94668a18cb4857ad6b7a5@AcuMS.aculab.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: openrisc@lists.librecores.org From: Arnd Bergmann > Sent: 16 February 2022 13:13 > > These two architectures implement 8-byte get_user() through > a memcpy() into a four-byte variable, which won't fit. > > Use a temporary 64-bit variable instead here, and use a double > cast the way that risc-v and openrisc do to avoid compile-time > warnings. > ... > case 4: \ > - __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ > + __get_user_asm("lw", (ptr), x, __gu_err); \ > break; \ > - case 8: \ > - __gu_err = __copy_from_user(&__gu_val, ptr, 8); \ > - if (__gu_err) \ > - __gu_err = -EFAULT; \ > + case 8: { \ > + __u64 __x = 0; \ > + __gu_err = raw_copy_from_user(&__x, ptr, 8) ? \ > + -EFAULT : 0; \ > + (x) = (typeof(x))(typeof((x) - (x)))__x; \ > break; \ Wouldn't it be better to just fetch two 32bit values: Something like (for LE - nios2 is definitely LE: __u32 val_lo, val_hi; __get_user_asm("lw", (ptr), val_lo, __gu_err); __get_user_asm("lw", (ptr) + 4, val_hi, __gu_err); x = val_lo | val_hi << 32; break; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E159C433F5 for ; Wed, 16 Feb 2022 13:36:06 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4JzJrM6FpCz3dmM for ; Thu, 17 Feb 2022 00:36:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=aculab.com (client-ip=185.58.86.151; helo=eu-smtp-delivery-151.mimecast.com; envelope-from=david.laight@aculab.com; receiver=) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4JzJqr2mdvz2xC6 for ; Thu, 17 Feb 2022 00:35:34 +1100 (AEDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mtapsc-5-x7kvjQ_dNbmfJSCohruuVA-1; Wed, 16 Feb 2022 13:35:28 +0000 X-MC-Unique: x7kvjQ_dNbmfJSCohruuVA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Wed, 16 Feb 2022 13:35:25 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Wed, 16 Feb 2022 13:35:25 +0000 From: David Laight To: 'Arnd Bergmann' , Linus Torvalds , Christoph Hellwig , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" Subject: RE: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Topic: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Thread-Index: AQHYIzdfY+IsqXyFuUGlEUsFmAHn6KyWK9Eg Date: Wed, 16 Feb 2022 13:35:25 +0000 Message-ID: <4a7e026b07c94668a18cb4857ad6b7a5@AcuMS.aculab.com> References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-3-arnd@kernel.org> In-Reply-To: <20220216131332.1489939-3-arnd@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "mark.rutland@arm.com" , "dalias@libc.org" , "linux-ia64@vger.kernel.org" , "linux-sh@vger.kernel.org" , "peterz@infradead.org" , "jcmvbkbc@gmail.com" , "guoren@kernel.org" , "sparclinux@vger.kernel.org" , "linux-hexagon@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "will@kernel.org" , "ardb@kernel.org" , "linux-s390@vger.kernel.org" , "bcain@codeaurora.org" , "deller@gmx.de" , "x86@kernel.org" , "linux@armlinux.org.uk" , "linux-csky@vger.kernel.org" , "mingo@redhat.com" , "geert@linux-m68k.org" , "linux-snps-arc@lists.infradead.org" , "linux-xtensa@linux-xtensa.org" , "hca@linux.ibm.com" , "linux-alpha@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-m68k@lists.linux-m68k.org" , "openrisc@lists.librecores.org" , "green.hu@gmail.com" , "shorne@gmail.com" , "monstr@monstr.eu" , "tsbogend@alpha.franken.de" , "linux-parisc@vger.kernel.org" , "nickhu@andestech.com" , "linux-mips@vger.kernel.org" , "dinguyen@kernel.org" , "ebiederm@xmission.com" , "richard@nod.at" , "akpm@linux-foundation.org" , "linuxppc-dev@lists.ozlabs.org" , "davem@davemloft.net" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Arnd Bergmann > Sent: 16 February 2022 13:13 >=20 > These two architectures implement 8-byte get_user() through > a memcpy() into a four-byte variable, which won't fit. >=20 > Use a temporary 64-bit variable instead here, and use a double > cast the way that risc-v and openrisc do to avoid compile-time > warnings. >=20 ... > =09case 4:=09=09=09=09=09=09=09=09\ > -=09=09__get_user_asm("lw", (ptr), __gu_val, __gu_err);=09\ > +=09=09__get_user_asm("lw", (ptr), x, __gu_err);=09=09\ > =09=09break;=09=09=09=09=09=09=09\ > -=09case 8:=09=09=09=09=09=09=09=09\ > -=09=09__gu_err =3D __copy_from_user(&__gu_val, ptr, 8);=09=09\ > -=09=09if (__gu_err)=09=09=09=09=09=09\ > -=09=09=09__gu_err =3D -EFAULT;=09=09=09=09\ > +=09case 8: {=09=09=09=09=09=09=09\ > +=09=09__u64 __x =3D 0;=09=09=09=09=09=09\ > +=09=09__gu_err =3D raw_copy_from_user(&__x, ptr, 8) ?=09=09\ > +=09=09=09=09=09=09=09-EFAULT : 0;=09\ > +=09=09(x) =3D (typeof(x))(typeof((x) - (x)))__x;=09=09\ > =09=09break;=09=09=09=09=09=09=09\ Wouldn't it be better to just fetch two 32bit values: Something like (for LE - nios2 is definitely LE: =09=09__u32 val_lo, val_hi; =09=09__get_user_asm("lw", (ptr), val_lo, __gu_err); =09=09__get_user_asm("lw", (ptr) + 4, val_hi, __gu_err); =09=09x =3D val_lo | val_hi << 32; =09=09break; =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)