From patchwork Fri Aug 26 15:07:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956192 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 1DFEFECAAD4 for ; Fri, 26 Aug 2022 15:09:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1C0D94000B; Fri, 26 Aug 2022 11:09:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA4BC940007; Fri, 26 Aug 2022 11:09:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9211794000B; Fri, 26 Aug 2022 11:09:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7C85F940007 for ; Fri, 26 Aug 2022 11:09:07 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5D16EC0E54 for ; Fri, 26 Aug 2022 15:09:07 +0000 (UTC) X-FDA: 79842076734.19.249C5BC Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf17.hostedemail.com (Postfix) with ESMTP id 15F004000C for ; Fri, 26 Aug 2022 15:09:06 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id sd6-20020a1709076e0600b0073315809fb5so720610ejc.10 for ; Fri, 26 Aug 2022 08:09:06 -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=9AAV0khTKYQgqo5/UGS2nmhcIjrHMBeghL7l+ejLApU=; b=sDB5PJpJBZJ8zJUYHqSaroGLwunSs5Rwaz9QmpK5RO8+mlf1nYQAGNhjMXl1m0oFZH vzMQVlJHXNGU9aieZuBV0ihX2Xs7GeZCanFYLMBLdccTjtufIvPj0/C/g25QTIwI6/Qp sReL0ZmVrFu7c6GRkrze5jnIbC0eHcDyF/YHGMdyIlE3tPtruebYgAGRN7/qwGwqWIG0 d7O6U7dzRkmvp5N9Pl4k3vT+ZH5Z9JXhcKEWunCg7MMWVXl8aGl5D3s28uVHexHgHJDm JLeAgRz2XBzUtSevuOYUNl/dsbWhlT4VB5dIjKptqOcveXztv31OO3ARcYOVZyimZv3m XuFg== 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=9AAV0khTKYQgqo5/UGS2nmhcIjrHMBeghL7l+ejLApU=; b=mUktXoTORUVvE55cMCtm2O2EPwl18E9wf19+dLA1F/Kq0eJvTbulKN4AeYgdNgJC8b S01l+9bIOU+byo32saNNANz14dKGueO2XzypzdPJY/tCBsikmE90HrvUzQW7DxTSCs4O h4EvQcGswRtA8goIvbLK9sxVHXhfPTh1CxNz3tl4zkNiFv1lPBliDipAsVTHKEq1GGl6 tjCLn9xqgtaB2XI+q2IwVI9fTK4beI7ns+JlqcHBaUyfY2JMjdlG/FfSPzXmwijPsPTT 8ZGnZutRb8gCtbadr8g7KE3jcuy7+rLi8gHUWkO+qvZyrowzbIXE5noMJjrTq1p5QmNO 99RQ== X-Gm-Message-State: ACgBeo1R0JBeEusw9QxDYYros6g/tQjVpI3pNPjmuDGDwU2dJdk6KCgt RFYvwSCWEf+Sgx4aS5vM2RpwjOLzflE= X-Google-Smtp-Source: AA6agR7OB7JfBU0FR/Gx7VVFS0BYXkDkX/D+5e1f7tZDKGDtu48HBg9ANVBecrhroNJG7bsthdjAB8Rc34M= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a17:906:8a77:b0:73d:deef:8f76 with SMTP id hy23-20020a1709068a7700b0073ddeef8f76mr3332086ejc.765.1661526545890; Fri, 26 Aug 2022 08:09:05 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:42 +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-20-glider@google.com> Subject: [PATCH v5 19/44] kmsan: unpoison @tlb in arch_tlb_gather_mmu() 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-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sDB5PJpJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3EeIIYwYKCBg49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3EeIIYwYKCBg49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526547; a=rsa-sha256; cv=none; b=rIm/XvxFe9OoZlGQtD7FZEb86rpa9G1PLwC4Pjl//tclWBCDKf7HM1UOJPY4kDpA3WRuKp 1hQzYU29sQr2vdgfussjKZtZBq+iCcpuvKkyK+TtUqE9FJhYoypXG4J48q2TGZgALYgmeX ASYyOVamutqb96IJwn87mFWINBDOuFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661526547; 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=9AAV0khTKYQgqo5/UGS2nmhcIjrHMBeghL7l+ejLApU=; b=2D12cosG6wmlApv/erAm9xGpXEffLMMzCmb0ZLAN70FKi765cnAFk4eu6PN8rb+2wy8AW+ PpK0ljhp9flsGGAczMLheNVsGTtjDhyEpTcV9GeJD2VN55NDso3drDj+PgK3qn+RcEWLBr /cBL6+6wmRG6kw7aZ08lneGPRz+wYYg= X-Rspam-User: X-Rspamd-Queue-Id: 15F004000C Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sDB5PJpJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3EeIIYwYKCBg49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3EeIIYwYKCBg49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com X-Stat-Signature: wkn6xunu5hchgox9y4gcue4dfkjd35hj X-Rspamd-Server: rspam03 X-HE-Tag: 1661526546-28125 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: This is an optimization to reduce stackdepot pressure. struct mmu_gather contains 7 1-bit fields packed into a 32-bit unsigned int value. The remaining 25 bits remain uninitialized and are never used, but KMSAN updates the origin for them in zap_pXX_range() in mm/memory.c, thus creating very long origin chains. This is technically correct, but consumes too much memory. Unpoisoning the whole structure will prevent creating such chains. Signed-off-by: Alexander Potapenko Acked-by: Marco Elver --- v5: -- updated description as suggested by Marco Elver Link: https://linux-review.googlesource.com/id/I76abee411b8323acfdbc29bc3a60dca8cff2de77 --- mm/mmu_gather.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index a71924bd38c0d..add4244e5790d 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -265,6 +266,15 @@ void tlb_flush_mmu(struct mmu_gather *tlb) static void __tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm) { + /* + * struct mmu_gather contains 7 1-bit fields packed into a 32-bit + * unsigned int value. The remaining 25 bits remain uninitialized + * and are never used, but KMSAN updates the origin for them in + * zap_pXX_range() in mm/memory.c, thus creating very long origin + * chains. This is technically correct, but consumes too much memory. + * Unpoisoning the whole structure will prevent creating such chains. + */ + kmsan_unpoison_memory(tlb, sizeof(*tlb)); tlb->mm = mm; tlb->fullmm = fullmm;