Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2440946imu; Sat, 22 Dec 2018 23:07:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN6X5DYZgnYIukt8WYjH2gsxKa5E3QFJwcPyJrfZX/vhifl9tApwFTenHoFzb5c0LSmD1FPD X-Received: by 2002:a05:660c:a8f:: with SMTP id m15mr5939618itk.114.1545548823673; Sat, 22 Dec 2018 23:07:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545548823; cv=none; d=google.com; s=arc-20160816; b=azYOCyJwvTwYf0fpChON2Nykn/9+ZZkCaxAf302pPSjDBoKnFQUzF48KW8b4aCFQFY 1hIMDKPhYjMwlHtot2CHOq/d+Bm4aHsUNYLYUlIERWFegwGD6FOx9Je1TAoOI0DjBP3w L5ZfcohNTlJcgAlIToruZTm5/6R/NvN5qpPEeTiDsNBil8pAf5c+dsv0qFJ0Bp+Ylrbe WGmp6Fr8OLCjOrkFd4U+2vOuzl/dO5YJ68bWp9phHlQSPL8ZikRQRcUav3RTmzCr5Jda JViQ1018dPoT/i6/bvMwGpPvbb0mgI0iquoA60bmrHJgmPb19Gps0Ffh/ZCh3BT/c70o QXkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CJK0vlftLh59hb5ucUvK/RXaMuhgiOcUq6O0AB1Qu8w=; b=oe2q1ZFiwcRQCLwgfAdWeImXiSzz7PefdUs/AdRmWf68w3OyVkSRTqklVL7BClDGYW gyLSzu920s2dpnYkr2LygipWPiJ05h2qYcP/dsQD6//osgVj1oGcOs+nDOFlCez7CuXf A5NtVrDYSgdijaxRAG5ERvyG6xTCo304lmVCZ8VVvNlpetuHcOy3lCmSGwtF92dxzD8S Zs1Q/psES95/knbQT8/yRqLnv83Tro6fyx3QU65XGFvVoP2VI3mRGWIPgYwFERLJ5QW6 lVs8SnIY9/GC7GfXbYQiY95Mu0wGnrdznPi75aKFbp5n934PBe70zSyNONonVpuaa4Xt lYDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=R6Z8237Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6si7482205ioj.64.2018.12.22.23.06.50; Sat, 22 Dec 2018 23:07:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=R6Z8237Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390377AbeLUU3x (ORCPT + 99 others); Fri, 21 Dec 2018 15:29:53 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:36020 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388411AbeLUU3w (ORCPT ); Fri, 21 Dec 2018 15:29:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CJK0vlftLh59hb5ucUvK/RXaMuhgiOcUq6O0AB1Qu8w=; b=R6Z8237YCp2CV7LnsI6mgRRIE DN0uygBaz2qpK4IgmubzHiSeLPC+GsnmJO9v1PyGUvOJzJ+3yYA3Jktunqf8MXNTB48RxZQ88tn2M klkacMpbM7a/gkO1/wd8lyhZtk0+9RBjOq3C/cfa7x0oPRHf15ucXY1Sk6r1C2gw+E9EnLhOEd/US TcVDouOC+9A0tZ2NQZo44xyb1RPkJiv8T6VMj48bYZKbqhSEQn2fIj4AKJqjZRkdhfiQIBPEpYBJc chjwGSyUgr73c7r6dExVL94O0O7IfY7tLM9smjTbtO0OyPNO3Zu3AVlLBvMFu2B+37PcRB2pOH0dz VPNDJOWXw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gaRQY-0005qa-RD; Fri, 21 Dec 2018 20:29:46 +0000 Date: Fri, 21 Dec 2018 12:29:46 -0800 From: Matthew Wilcox To: Cyrill Gorcunov Cc: Igor Stoppa , Andy Lutomirski , Peter Zijlstra , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann , igor.stoppa@huawei.com, Nadav Amit , Kees Cook , Ahmed Soliman , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/12] x86_64: memset_user() Message-ID: <20181221202946.GJ10600@bombadil.infradead.org> References: <20181221181423.20455-1-igor.stoppa@huawei.com> <20181221181423.20455-2-igor.stoppa@huawei.com> <20181221182515.GF10600@bombadil.infradead.org> <20181221200546.GA8441@uranus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181221200546.GA8441@uranus> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 21, 2018 at 11:05:46PM +0300, Cyrill Gorcunov wrote: > On Fri, Dec 21, 2018 at 10:25:16AM -0800, Matthew Wilcox wrote: > > On Fri, Dec 21, 2018 at 08:14:12PM +0200, Igor Stoppa wrote: > > > +unsigned long __memset_user(void __user *addr, int c, unsigned long size) > > > +{ > > > + long __d0; > > > + unsigned long pattern = 0; > > > + int i; > > > + > > > + for (i = 0; i < 8; i++) > > > + pattern = (pattern << 8) | (0xFF & c); > > > > That's inefficient. > > > > pattern = (unsigned char)c; > > pattern |= pattern << 8; > > pattern |= pattern << 16; > > pattern |= pattern << 32; > > Won't > > pattern = 0x0101010101010101 * c; > > do the same but faster? Depends on your CPU. Some yes, some no. (Also you need to cast 'c' to unsigned char to avoid someone passing in 0x1234 and getting 0x4646464646464634 instead of 0x3434343434343434)