From patchwork Wed Dec 19 21:33:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6084814E5 for ; Wed, 19 Dec 2018 21:34:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 518D7286B2 for ; Wed, 19 Dec 2018 21:34:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45EEB286B4; Wed, 19 Dec 2018 21:34:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC9D8286B2 for ; Wed, 19 Dec 2018 21:34:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BC958E001F; Wed, 19 Dec 2018 16:34:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 16EBA8E001D; Wed, 19 Dec 2018 16:34:29 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 035D88E001F; Wed, 19 Dec 2018 16:34:28 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id 85D8C8E001D for ; Wed, 19 Dec 2018 16:34:28 -0500 (EST) Received: by mail-lj1-f198.google.com with SMTP id k16-v6so2559650lji.5 for ; Wed, 19 Dec 2018 13:34:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=nF+ce+AsD/YO6oFhBzoP5bXERd0j3/JBWm1ePv97n+k=; b=onhqh99dHd68Vfgq2Ii/Xo+yMcGU0hQwBlJKysnTxbUVzntpOE/RCFiM5lCdVuhBif wGhNHOCx6Q7/De20XRyZv/ktOo5koLesMPtpHAGhMcjlGbgfgNdnRH7PkcmXubPrx8g2 y5aUCmSlMB5eptvUbKJPSFPWL4wRLy7HiI8lSqSLL6IK623IkX2uXu1i4xXf4RKQTtY6 j21Nz9gKjicypekKkm3Dhp9mj7XiuLyATpr7kAf46rAS12Lxh1rmPXTNK9BcL/XwTvmN J+RdYWAQMsAvhk4WjcEhyyi1zBhvpowZFF18wDp86eNbMyP/COdMotb2HsqtdJxgHxle +YxQ== X-Gm-Message-State: AA+aEWYoszMm73N0/RlMaATRP01E2q1rQVzhoFY8eevJeIJcCQXJeLqw aTTVzbQOBCBrlzGWYTISJRqhexPikFOVWmjjteR7kRtMq54Cpc6+19hu7+OTJ+YLi6PjgjeXZOg oeqqiOvNlF+x9wHQFBoSpgqqvHY4p4mEBsKrF3o6MXiFIs5T79zSuEw27pzPAavlQ9W1zZ7vweb WsfQ4lQhsmONwa7jI3sgUf3HQF+P8a1DdcrkGHvJBQyYDix8Edy7S3oR/cyE+vaariPZMEry52z ZDibHMSMTuDkOJTMCo5qQjJyC7D0TAmsr5/tqB/urXb3O0rctyA9WxjNUp5pPoye7YgSPfNWKAt nM/J1qO3nD599BGfu/hymwSWGthhqIi04K+GuLpaCvJ0684AnNSgs8jTlEzWa6fWg8F/d7073eT b X-Received: by 2002:a19:a302:: with SMTP id m2mr14550152lfe.108.1545255267896; Wed, 19 Dec 2018 13:34:27 -0800 (PST) X-Received: by 2002:a19:a302:: with SMTP id m2mr14550116lfe.108.1545255266732; Wed, 19 Dec 2018 13:34:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255266; cv=none; d=google.com; s=arc-20160816; b=boxf7MIpHCdVv3cjJha6IlcZxiiU98agKjS+6UIWLboKPgZm2MoUWGBeGjdIkLc3h7 lhsu8QjmmwxSfzqpsGNIi+xRgR+K8XQJAniKublGe4xcNZ9anxO5YpWmFm15H9REIEzU j/PRofzHL+nAgFAvYSKodpN5YDygTwZZ57O1mVtBqf/p7nrKP+lQIDjUcl7pEPrcQeF0 DZ06d+YE6oMM8OU5o6dsxx1QwB9zOY26jHMh/vULEOhMiq7icDWwkC3OTp2i0VUfTv8x K3XJTYshYmt+aolfIKNZyb6P9+iRcyCsiLB8C9aLBn//8TfawgXs2M83VV8pCM2WjAWt 1vIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=nF+ce+AsD/YO6oFhBzoP5bXERd0j3/JBWm1ePv97n+k=; b=XesSUlTfNAhNupmnml4OnRQd/d8bl8f9OR0jCW9DPWT8IRn+vjz7ZXuqYmN+xbQQ9T GoEgfC3II3NwQ7r5krFdSGzEpfcm2ui5Q2xPwHPGrTAMvKDEPn1KAgEmY1UcEPSgOyGA lnnuaL9ilW5VhC2HImQ0xyl9PyWk3W/SwedOOct0UlT6JoB3LNd48Jlg3jTK+1QuRb6A aEDv678yC+Op9vBszojUAA9Kjd0M+bBlbkDPbmokEdvDOMiqGrJljFfzzmmyoRVB20nD LVx5nTvpaERqx/IXTz6kKDm1EZlFbMm6WiyxGLg6cPH62c8cE2biaRHpD85eqRbX5pzA 8qeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vGTkPcUF; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x66-v6sor12365850ljb.20.2018.12.19.13.34.26 for (Google Transport Security); Wed, 19 Dec 2018 13:34:26 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vGTkPcUF; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=nF+ce+AsD/YO6oFhBzoP5bXERd0j3/JBWm1ePv97n+k=; b=vGTkPcUFo/MMtKaWdBnUN7Wr0yJwxwfs21G27pnVV2k1BB2gRhB1bK7E0cHhYbqIgf stDCnsHWMfyP+yrG6oDmTMF96qa/BaUh7n6LG+3tu8TfXBh5Wu8DfaY+PV6lNfvBRdKh hNQbHgauq8nMJyjwqmvZjnwDRCxA5mLVfzWQ0bVZJe+zeth1/NOc5HzIGqpMFr/Qrlqx aAsQZ/q+cAxCC45Usqy0Xty8HNLpuBvEXpaPgWZc396htU9HqMdTxdiPYyjkaNHn7myJ xkIvhC2HOtkTyU5OhrA1C4U6i8nYCJDolSU8uTM4BXBZOybG0Kkmw2kFOsIZCZuoWSro lNVQ== X-Google-Smtp-Source: AFSGD/Wy2ENV+x3psGq5BTNSnjgWTYu45qYohRv5i5VPwG4fDvqlbGM3fM6N3dl/AyW8xTUnzykvyA== X-Received: by 2002:a2e:4601:: with SMTP id t1-v6mr15007443lja.111.1545255266361; Wed, 19 Dec 2018 13:34:26 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:25 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/12] x86_64: __clear_user as case of __memset_user Date: Wed, 19 Dec 2018 23:33:38 +0200 Message-Id: <20181219213338.26619-13-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To avoid code duplication, re-use __memset_user(), when clearing user-space memory. The overhead should be minimal (2 extra register assignments) and outside of the writing loop. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/lib/usercopy_64.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index 84f8f8a20b30..ab6aabb62055 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -69,34 +69,7 @@ EXPORT_SYMBOL(memset_user); unsigned long __clear_user(void __user *addr, unsigned long size) { - long __d0; - might_fault(); - /* no memory constraint because it doesn't change any memory gcc knows - about */ - stac(); - asm volatile( - " testq %[size8],%[size8]\n" - " jz 4f\n" - "0: movq $0,(%[dst])\n" - " addq $8,%[dst]\n" - " decl %%ecx ; jnz 0b\n" - "4: movq %[size1],%%rcx\n" - " testl %%ecx,%%ecx\n" - " jz 2f\n" - "1: movb $0,(%[dst])\n" - " incq %[dst]\n" - " decl %%ecx ; jnz 1b\n" - "2:\n" - ".section .fixup,\"ax\"\n" - "3: lea 0(%[size1],%[size8],8),%[size8]\n" - " jmp 2b\n" - ".previous\n" - _ASM_EXTABLE_UA(0b, 3b) - _ASM_EXTABLE_UA(1b, 2b) - : [size8] "=&c"(size), [dst] "=&D" (__d0) - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr)); - clac(); - return size; + return __memset_user(addr, 0, size); } EXPORT_SYMBOL(__clear_user);