From patchwork Fri Dec 21 18:14:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10740829 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 5D02B924 for ; Fri, 21 Dec 2018 18:15:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 508D12835B for ; Fri, 21 Dec 2018 18:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44C9F28618; Fri, 21 Dec 2018 18:15:19 +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 CCF602835B for ; Fri, 21 Dec 2018 18:15:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4E268E000E; Fri, 21 Dec 2018 13:15:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ACF288E0001; Fri, 21 Dec 2018 13:15:12 -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 94EE68E000E; Fri, 21 Dec 2018 13:15:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by kanga.kvack.org (Postfix) with ESMTP id 1CDA28E0001 for ; Fri, 21 Dec 2018 13:15:12 -0500 (EST) Received: by mail-lf1-f69.google.com with SMTP id f16so708510lfc.3 for ; Fri, 21 Dec 2018 10:15:12 -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=SF4qk+bTzK3es4UM9b0qE6afh8/8sQWLd3sxWcWkQd8=; b=Yca6CcfIiYM3bVqMqSaO6C7EbZlodzkbDJgM/eMod1l8ItWqNwtZ7TxKo55YWxE11W JqaIJvskIvi5mN7VdSVkp+OuXK5mIul5QyhPJP41Mt7dQU5WyJx/MmkTGoRvXfShxgxG 2Vz5DV96wK7qr9sqv0r88XGiA4SiJm7cxCIyLVHL7wWcBKFQuzO2W42DnIk3Z7pi61yk rP8OziqJRBDepqcV+hy/TJlRvRT9/kDOIj2PtoyMxlzeMAg7BYgmPm9fmg7XTO8P5eTL FkcjfxhPVBKM+FO1B0OhrnQu0i5CA5K+qW6SiOgzmenNuaTW+gVI2/KFgW86C1geZ+AD orww== X-Gm-Message-State: AA+aEWZTSFzY6zWRWPB3h44DrW575hfmj8ldo0UdHC2grmkmbSYkI7qc 1qnxNLiP9+rxSVuWG/ZuOHC4Bw9xCF2nQz8o6SDgEIkK/gKiypkviefLie00vGh7Sjq6J0Vmqlw NCWOGE16SECwGVn4PB5ZuFI04EUWQ+UIqVmPEdm0OsEfqww/j1gqDngKqewqWjMWxpc+H1PpQ5x 4bjLFAZ1eyDxb8aBjctSlIDMs7VbuF4Bb5Z6mw0d7s6fDFiMf8df1y2cySg4QvxAR8qTvSFV1Yq mYf5RqJhq2sI/yaCM5eVtGL+X9rvDanKBRLIP/V9EAPfY0cebCzOORDk+BjZyj2lWYoLTVMlt/N /nAWEDf66oAShMn/SodILL/sVGgyohSkV4x4AqsqD3+UIboZh2IeVCQ709rbawEXLAuHdyjq6uK s X-Received: by 2002:a19:59c2:: with SMTP id n185mr1898613lfb.118.1545416110956; Fri, 21 Dec 2018 10:15:10 -0800 (PST) X-Received: by 2002:a19:59c2:: with SMTP id n185mr1898510lfb.118.1545416109657; Fri, 21 Dec 2018 10:15:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545416109; cv=none; d=google.com; s=arc-20160816; b=y50Ka+27aqcp/FmF2sZ1ZGmQq0U3n8eqO/+LY9/M4Jzit9gHjubMbpm6eiwOgVpKlr O5Kd2nw6WrHvYMV2ossCswd80EC79yloRyYOMHe5TQPiEPNYZcotk0ZtirrIwkd2VcN9 xrceGIKaI5I8R6jSgYsfpuMUZ3sBy/zxoU0QN5hYwqbYeA3/CgdKqZI4IPiUtq42I/EK u8wyvYQeWRQ/7gu5C3v3llWMKZSOhMfV4soiA/A2ehJcfXybIy0XtAb9RrufldOzuyQE T9aXU99gWihjsBfVoJN/BlYqUoKsD28wNyvA8l2aHvJIas5o8VxotvvLp6LIZtPvqiGl Bv9Q== 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=SF4qk+bTzK3es4UM9b0qE6afh8/8sQWLd3sxWcWkQd8=; b=qwkwuzpIck/v3xNV+20E7xHHqnSGpMEytCOORvhrSAiroGI9WgYnC/lnQwjFlQxPJi 6vrhdqAJ1NoTXbra4QJSySkcouIIqEV66JrD+HyBq7JAw/CDOi31X1vqKUsccKMgLFrG 0SMtR080yrJV0WceogG1pdem31Lro3eKkr+VfNvQxVL1w4nN/s4jF905LFDNOFXL/rzs 1dN3tkiRlEf8QbxlUC0980tnDxhZxokLIAZbNNoZ8byARr1DtkWNrAr9yRbE6RYMgZrJ zxOoobkhNiyl82AZM/gLdlxS6YuICYizKHlYdWiRuAjaGDlFdCqwS0YP6jaZnQCYZZqs +fFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Ii7ELF8/"; 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 h39-v6sor16663786lji.32.2018.12.21.10.15.09 for (Google Transport Security); Fri, 21 Dec 2018 10:15:09 -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="Ii7ELF8/"; 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=SF4qk+bTzK3es4UM9b0qE6afh8/8sQWLd3sxWcWkQd8=; b=Ii7ELF8/5y1rVaPhHiLhgDtq4P7/rfzqXnM3EeCH5GRSr2Kq2zzNF5t8kZw3ND0+a6 10vlyhvH2ZArYPGzD8PwHtf9EFg96E8dJK8mNhL944qEkX0oPwo3++zWdGQklQ9CWU8B ETzu3Boaxa10N5Nt8r1xtE9gTtRaR9kkLpPgE8BLmp1z/ycZC0NNjjNhkSeV27VB58Vh cylWppIJrf8u0uC15//e4cctuMhk9qlnQyspjtHkl2k33XBKfEPLw9N9gKQ8QuMGKnxR 26HLuc8Ps/OA9fdgIFgv2Zi8d3KV46SAyUsiabS45ayIX64sTa1CQlIsMkc80vD0t48o vIng== X-Google-Smtp-Source: AFSGD/U5nUYrabzF4bcWijW9jX9KfZDA5WG1g0TgA4b42uvAMM3t6RmJ/Cf3Ft6Rt3AgJtUscpiQGw== X-Received: by 2002:a2e:9cd2:: with SMTP id g18-v6mr2461814ljj.161.1545416109279; Fri, 21 Dec 2018 10:15:09 -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 m63-v6sm5444564lje.81.2018.12.21.10.15.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 10:15:08 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann Cc: 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: [PATCH 12/12] x86_64: __clear_user as case of __memset_user Date: Fri, 21 Dec 2018 20:14:23 +0200 Message-Id: <20181221181423.20455-13-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181221181423.20455-1-igor.stoppa@huawei.com> References: <20181221181423.20455-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: Thiago Jung Bauermann CC: Ahmed Soliman 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);