From patchwork Fri Aug 26 15:07:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2994ECAAA3 for ; Fri, 26 Aug 2022 15:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6880994000D; Fri, 26 Aug 2022 11:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61174940007; Fri, 26 Aug 2022 11:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 464E394000D; Fri, 26 Aug 2022 11:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2E2DA940007 for ; Fri, 26 Aug 2022 11:08:29 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 00D5680C86 for ; Fri, 26 Aug 2022 15:08:28 +0000 (UTC) X-FDA: 79842075138.29.68B36B6 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf26.hostedemail.com (Postfix) with ESMTP id 7634A140030 for ; Fri, 26 Aug 2022 15:08:28 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id ne1-20020a1709077b8100b0073d957e2869so723283ejc.1 for ; Fri, 26 Aug 2022 08:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=P3BIEQv1T/KwZafUGZKUBc98ocOSrUKFpAGAcrUMbqQ=; b=Gfe3GoUcVz2DJqv+lUhS4wPJK1FSFGYSNmq3/sHYEp2DjOH5v5GNBK/z6hDTUoKcTj plBctrN9vrg8FpJag++EbXU4mr1O64PW/1loKp8KRZuDnOsIEMr3eAKPs++1evafDhuT A/bg0Xtm8uNzHgCE9+qQSnmN9op+um7DtTIxTFv5pIn/W8yBUx7UfecmpyVTt+dfsVnq R6+GNW8d47HlvsNhFF9IMt3QQ4Pdb3IpCNIvyzbkPzXHWf3cKsNzlrqWxpwtGBf+/qyd MYf6zzuhfYx17T33BFzvicCgkqik20kUTnJTp2XnCJSTdNO9O0hyzdD6GKvImE6ONG+Q idug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=P3BIEQv1T/KwZafUGZKUBc98ocOSrUKFpAGAcrUMbqQ=; b=xhPpfRx0iDVL7ngnODMfxV1H0LLJL3CM20l5AkLBx33AO3JlyozhRLQYPlOJesLdpC zw4in7diBQC4y/vDzeCJBHXFSEWLtZez9an+7Nu9ZyqU/Rvl4o6ogyBZdIXR8Glz4hNf 8wCNIR7Hb9+/UvSJ8wnznWeusQC2/8N6fWsbSP2UH8hNj3tFjNN48F+CDE0RFDn+JF8p dOY3AJkXp4v7wzDARSNBTc1dGqMRDX1bQr+18H8Pj05oPUBssns3xomFRpn4itoi3YFr W9jQb+Wiiles6Wfo4rPzZxGJ4Edbl41b29UlfQiu9Sbhvr3XZnGFSLdAEjPOTPuQL8vs Dlww== X-Gm-Message-State: ACgBeo3WbxPVrkEO4VCZTZDmnQxXViy/9zexplqSMBPk+R8b7n3FTBA/ Ul5FsBY8m1Bbdn7cZlMyB9G0/sUvaA0= X-Google-Smtp-Source: AA6agR7pRi8WRPCHvWZyrbJ+uMb1xTdRgH4930Ca34TprE6WyeH/LJquvC2M2sAE+eo6XOjsPj4V5JP8Hdk= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a17:907:c06:b0:701:eb60:ded with SMTP id ga6-20020a1709070c0600b00701eb600dedmr5913732ejc.178.1661526507100; Fri, 26 Aug 2022 08:08:27 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:28 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-6-glider@google.com> Subject: [PATCH v5 05/44] asm-generic: instrument usercopy in cacheflush.h From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526508; a=rsa-sha256; cv=none; b=BBD1eZr0prnZsPiZr585MxgaNIczRRPU6xuh+sdpHKg20b3zegeuFy711gwxc1F3b3Z7SV +A/aCn/CQmzNjGr9mH8BFnLzuKK4dKZYOgVfXvDH4D2RBFEWdzpXOkBqBRhqJQjIkvwPK7 B0KFdKIp13aUXN6YK5+DUaitw1NMCIE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Gfe3GoUc; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 36-EIYwYKCPAYdaVWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=36-EIYwYKCPAYdaVWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661526508; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=P3BIEQv1T/KwZafUGZKUBc98ocOSrUKFpAGAcrUMbqQ=; b=nyzXtdBBcQEKUrmcEl+Ey+2GBxQYo/oYLSrvlpkuY5SvrXTTHoOB5LkV0qkQ96oU9X4kju DQugQ8VDV64oGMm2faomxKOQHF3ZdGAw5eSQekOq/iNPsJj8PvSfz6EEGNxqXC5fcwg1n8 QAnyDWtzBFYOITBzshBsDU1BnB/sRfU= X-Rspamd-Queue-Id: 7634A140030 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Gfe3GoUc; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 36-EIYwYKCPAYdaVWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=36-EIYwYKCPAYdaVWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--glider.bounces.google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: ppxughato4rmzx993pj6nuwq5hrxp8jj X-HE-Tag: 1661526508-500565 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: Notify memory tools about usercopy events in copy_to_user_page() and copy_from_user_page(). Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- v5: -- cast user pointers to `void __user *` Link: https://linux-review.googlesource.com/id/Ic1ee8da1886325f46ad67f52176f48c2c836c48f --- include/asm-generic/cacheflush.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/cacheflush.h b/include/asm-generic/cacheflush.h index 4f07afacbc239..f46258d1a080f 100644 --- a/include/asm-generic/cacheflush.h +++ b/include/asm-generic/cacheflush.h @@ -2,6 +2,8 @@ #ifndef _ASM_GENERIC_CACHEFLUSH_H #define _ASM_GENERIC_CACHEFLUSH_H +#include + struct mm_struct; struct vm_area_struct; struct page; @@ -105,14 +107,22 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end) #ifndef copy_to_user_page #define copy_to_user_page(vma, page, vaddr, dst, src, len) \ do { \ + instrument_copy_to_user((void __user *)dst, src, len); \ memcpy(dst, src, len); \ flush_icache_user_page(vma, page, vaddr, len); \ } while (0) #endif + #ifndef copy_from_user_page -#define copy_from_user_page(vma, page, vaddr, dst, src, len) \ - memcpy(dst, src, len) +#define copy_from_user_page(vma, page, vaddr, dst, src, len) \ + do { \ + instrument_copy_from_user_before(dst, (void __user *)src, \ + len); \ + memcpy(dst, src, len); \ + instrument_copy_from_user_after(dst, (void __user *)src, len, \ + 0); \ + } while (0) #endif #endif /* _ASM_GENERIC_CACHEFLUSH_H */