Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp652456pxb; Fri, 16 Apr 2021 14:54:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLjQ/+7bDgDn8WKe8poC3f6lxMHWDWQLeDsjSODwDYhfabcR5dY+OCOt7Jt6wpbSnF6Uvl X-Received: by 2002:a17:906:3a94:: with SMTP id y20mr10192786ejd.35.1618610093365; Fri, 16 Apr 2021 14:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618610093; cv=none; d=google.com; s=arc-20160816; b=vD3Z0isa4w8TCjtaUX1IR9YcvrP+3pyL6ISpeaccqLW+WeLyHptd+Dq1mrSV5dAfao NrO0AobiLt8xgqVnIxHpBAeo6t/7v3I+6wVFyz9un7/XrSf9+4EcChefoy3cgKL3/+Gx +4Vo/Wxgu+FhXHqZ3OMPytBn1cK2ZjvFrp8hNN/5q7cIugG37rTIBnmzb6XRAb+2ol0r 1WIHx+BnKsVy32jMs/CHsy6GoBeecoHwPTtkkpevEUWgNw4al/IYgDkC2tPWoV9lou5A sllGeKSIJzc2we3YIh+af7ujnr1owIAzFMcApyiGVrDM8QHeeWbZ5ODeMlj3haob5B9t g0Jw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=au1OzdUxzPBTnWVZvWu79dip0mAHZrKvjjowjMqY2UE=; b=idbVU+Gi995hRTX4E4XBv65tVIQUUzOjv4ALtxo0OG62vgqI44DBJ5SdTWT9Dvx8ZD ihle8pUYH8d2Hrr+asnWuLURxeusRXs2vZErexJzYtLaSnFs5Jt1e/yyJvx8Zb15ymcw hUAkwx4gOIjf5+6vwdwczkqjgnwUgZyHsHc01RwfH531El6dv9t1/cKmIqijvWdLMdGF OV8RsjSNfMDmg+nIKBntTSu9Of97Az8t1oGhSLYR0iw1Min7kwsBnj+Vmzxxdo20pdRn cC1sB98slOFunN3RcPh32SYJR0ytuA/6oo/vbXJaTeaXlxLu3aCcjzcu+mgfe8ShPjsU j91g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SFC7x0J8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gg20si4088421ejc.614.2021.04.16.14.54.30; Fri, 16 Apr 2021 14:54:53 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=SFC7x0J8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241824AbhDPTYp (ORCPT + 99 others); Fri, 16 Apr 2021 15:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235362AbhDPTYo (ORCPT ); Fri, 16 Apr 2021 15:24:44 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D437C061574 for ; Fri, 16 Apr 2021 12:24:18 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id w8so15513533pfn.9 for ; Fri, 16 Apr 2021 12:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=au1OzdUxzPBTnWVZvWu79dip0mAHZrKvjjowjMqY2UE=; b=SFC7x0J8SZ4vw/i2LY+v4bsGGAoWUKBp0ag81cE6lwfqHZz/brkekp9aUSxYBRvG6G iFnjHIE6BbuPkqiiYjQ5D6x9Xklg64ZwzU+USKoO83qddMKI4KalsjjG//3jECdmEPIz YrD7UcN7g69P97mMV2DO1f3I/bBZANGQCDqfxIelUt7Iv8KgUkheX2MVvzT8QMAOD2KK EdQOT9gTvNfhJXcloJ1YqsmxVX4TkYcwclCAVRrSzhoGOkIf1HXzB14MLqU3TR8IX6gp P+hUO376GN0wkefINe8RVxRmynRyqpnXvyRnRYSeBWBpW34Lu+XxCxT81KHfbK4zaQ8I Znhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=au1OzdUxzPBTnWVZvWu79dip0mAHZrKvjjowjMqY2UE=; b=HEh0PXPziJIcl6IMk1Deg4TAlBpziS/DjoGCuO9bfhZi8QWFyD1+2Wtu/u7WDVhSEK 3PG6s4X6VMfSOMXov8E1mlB1EvvRkj7swOXXTik9ip3agiElY5jpfuAMTU2ClzLFo581 0JmwJnFnAqMfIGolEOlIkG17IK2hDTEQ1DI/MJvQuPTRoHQNr3OoeRdanLLS+bg/IKWh fm2STrPTayFtoShgZyH5271I3tK6iyOcJFsZmkwK9gcDs7xh501otEGF8Ku7Ntn07i9z Ymj+i4XhZDZVlghvrfJjmQn3qvgXe1cM5/15sZLZqGfvz0iUdaRzPdebjZ8n7p4iF/fQ XUeg== X-Gm-Message-State: AOAM530fmhOYuAqPe4s+jGRQh3kEwSUZcUaiBuVNrJ2nS12IXfyoWK/Y yJ3Q88xkwTOxV1Xw/nuttGs= X-Received: by 2002:a63:e552:: with SMTP id z18mr588609pgj.100.1618601058251; Fri, 16 Apr 2021 12:24:18 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8178:2218:96f0:c55c]) by smtp.gmail.com with ESMTPSA id s9sm5440076pfc.192.2021.04.16.12.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 12:24:17 -0700 (PDT) From: Eric Dumazet To: Thomas Gleixner , Linus Torvalds Cc: linux-kernel , Eric Dumazet , Eric Dumazet Subject: [PATCH] x86/uaccess: small optimization in unsafe_copy_to_user() Date: Fri, 16 Apr 2021 12:24:13 -0700 Message-Id: <20210416192413.1514419-1-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet We have to loop only to copy u64 values. After this first loop, we copy at most one u32, one u16 and one byte. Signed-off-by: Eric Dumazet --- arch/x86/include/asm/uaccess.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index c9fa7be3df82ddb9495961b3e2f22b1ac07edafa..ddb19bb8c86786d78407dcfb59623943ccbce8a8 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -517,15 +517,23 @@ do { \ len -= sizeof(type); \ } +#define unsafe_copy_elem(dst, src, len, type, label) \ + if (len >= sizeof(type)) { \ + unsafe_put_user(*(type *)(src),(type __user *)(dst),label); \ + dst += sizeof(type); \ + src += sizeof(type); \ + len -= sizeof(type); \ + } + #define unsafe_copy_to_user(_dst,_src,_len,label) \ do { \ char __user *__ucu_dst = (_dst); \ const char *__ucu_src = (_src); \ size_t __ucu_len = (_len); \ unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u64, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u32, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u16, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u8, label); \ + unsafe_copy_elem(__ucu_dst, __ucu_src, __ucu_len, u32, label); \ + unsafe_copy_elem(__ucu_dst, __ucu_src, __ucu_len, u16, label); \ + unsafe_copy_elem(__ucu_dst, __ucu_src, __ucu_len, u8, label); \ } while (0) #define HAVE_GET_KERNEL_NOFAULT -- 2.31.1.368.gbe11c130af-goog