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 X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 193FEC433E2 for ; Sat, 5 Sep 2020 07:14:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E61FE206B8 for ; Sat, 5 Sep 2020 07:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbgIEHOw (ORCPT ); Sat, 5 Sep 2020 03:14:52 -0400 Received: from verein.lst.de ([213.95.11.211]:43936 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbgIEHOu (ORCPT ); Sat, 5 Sep 2020 03:14:50 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id F1F6568BEB; Sat, 5 Sep 2020 09:14:47 +0200 (CEST) Date: Sat, 5 Sep 2020 09:14:47 +0200 From: Christoph Hellwig To: Arnd Bergmann Cc: Christoph Hellwig , Paul Walmsley , Palmer Dabbelt , Alexander Viro , linux-riscv , "linux-kernel@vger.kernel.org" , linux-arch Subject: Re: [PATCH 3/8] asm-generic: fix unaligned access hamdling in raw_copy_{from,to}_user Message-ID: <20200905071447.GA13228@lst.de> References: <20200904165216.1799796-1-hch@lst.de> <20200904165216.1799796-4-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 04, 2020 at 08:04:34PM +0200, Arnd Bergmann wrote: > > if (__builtin_constant_p(n)) { > > switch(n) { > > case 1: > > - *(u8 *)to = *(u8 __force *)from; > > + *(u8 *)to = get_unaligned((u8 __force *)from); > > return 0; > > case 2: > > - *(u16 *)to = *(u16 __force *)from; > > + *(u16 *)to = get_unaligned((u16 __force *)from); > > return 0; > > The change look correct and necessary, but I wonder if this could be done > in a way that is a little easier on the compiler than the nested switch/case. > > If I see it right, __put_user() and __get_user() can probably > be reduced to a plain put_unaligned() and get_unaligned() here, > which would simplify these a lot. > > In turn it seems that the generic raw_copy_to_user() can just be the > a plain memcpy(), IIRC the optimization for small sizes should also > be done by modern compilers whenever they can. Sure, I can look into that.