From patchwork Mon Sep 5 12:24:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12966050 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 336F5ECAAD5 for ; Mon, 5 Sep 2022 12:25:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFBF28D007A; Mon, 5 Sep 2022 08:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAD4B8D0076; Mon, 5 Sep 2022 08:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4D1A8D007A; Mon, 5 Sep 2022 08:25:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 95A1E8D0076 for ; Mon, 5 Sep 2022 08:25:51 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 72AC11C6996 for ; Mon, 5 Sep 2022 12:25:51 +0000 (UTC) X-FDA: 79877953302.12.545DABF Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf08.hostedemail.com (Postfix) with ESMTP id 1A197160076 for ; Mon, 5 Sep 2022 12:25:50 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id jg40-20020a170907972800b0074148cdc7baso2257468ejc.12 for ; Mon, 05 Sep 2022 05:25:50 -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:subject:date; bh=JDbXYbJWwPmgAZI0cqV5N9fdafuEA5LdQ6bM1NbJ2qU=; b=FI/NN8FVkqveVSoB6HG4Dkazuf6XYCk/EwCAfidqLj4dNPa0BRhM4P5S4TqXDGIZaI qrEKGE+r+7Jt5yWEty94dld142fuFuiBwTfOiFHQUY5nxSHJ+D8ob7Cf47AnhjKOGoR5 Bklr3XpZrOoyXRce7z6Tw6kGBroRdXW/XXVfP6gsABeJuQtlQH3SmKvkiqAGb4lTB6cD 7eYPHMVcX5DUnPnmRo4rO7LVehmhKNFjhaZP9RF8f0ksJZ1mSX0p7FROg8hQn24pzOBV K93l7+1ykcepxF58K6O1XQpgozdC1Jvz1hxtlrAemelvnVlo8kdLN50VY5GotqXyWFJ4 nDnA== 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:subject:date; bh=JDbXYbJWwPmgAZI0cqV5N9fdafuEA5LdQ6bM1NbJ2qU=; b=EnPWCT/qWk/FqvBKM55DxeXIu6pAXLAfb9Audjbb3/TaPCoUSDlvGZXOiyOsCtzkYO aGE5U3GasHoyjkAlPbPFYXFYRrGrOt19MW+kj1MnKXLZ4noWcdjrDu2c7MTdqd18jka6 7mKgFzMm07jmSoYc4RVDQrf5izC1+gqqvZp0M0oxdSeQfvhxuBNHedapRnAu7g286D5M /I4E6CHM+JrhZIDFu3uELiEx1gakHBPC7kBOTPoJSRa2zouJcA5JDh9XAQvBNEKSUYVg qry9g9DlHf9JOKFlL1P4ptLHPT+ejfxJxDw52aC1WYBM8h0u7GjX3JVKQvevYdL9LSpg kYNQ== X-Gm-Message-State: ACgBeo3EJ+LiZGHHgazq7tW829PIWhoeYc6nQB61HwB1mEXwnOW/mM45 wKalWa8/O+1/BaUXmYXZ6Dy6qbquieY= X-Google-Smtp-Source: AA6agR6EtI+wppo4BmYhDO6R8PujqfTGTJqoZccyFkAtKf4bzdO9HJQ/6nSdJYuTNsjvrOtwDoN6L9AHrrA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b808:8d07:ab4a:554c]) (user=glider job=sendgmr) by 2002:a17:907:7242:b0:741:7cd6:57d5 with SMTP id ds2-20020a170907724200b007417cd657d5mr25769275ejc.419.1662380749795; Mon, 05 Sep 2022 05:25:49 -0700 (PDT) Date: Mon, 5 Sep 2022 14:24:27 +0200 In-Reply-To: <20220905122452.2258262-1-glider@google.com> Mime-Version: 1.0 References: <20220905122452.2258262-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220905122452.2258262-20-glider@google.com> Subject: [PATCH v6 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; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="FI/NN8FV"; spf=pass (imf08.hostedemail.com: domain of 3zeoVYwYKCBo6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3zeoVYwYKCBo6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662380751; a=rsa-sha256; cv=none; b=mDAGvOQXFYKK1Lng5gslH1ni615rYxkcfs1AZ/y73rQAU4V86+EG/TV8EIDVErEsWlqofw c0usw+2O3NDModgse+1ayRJ8QOp8jin2DF2MZf/BQrACf4X8O3aHwOWHx8DK0s6c8QLI2F yE7oG5Eq6HR2tiO9jSAzr8CVjOlkqck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662380751; 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=JDbXYbJWwPmgAZI0cqV5N9fdafuEA5LdQ6bM1NbJ2qU=; b=G5qNKwzAmGmFpnWkrKL80XRaOUwCq9oEZqavkDSVdeoYd+TH6/iCvZGuV7bSSXZOZfdxVn hXKUsirmR3Dutf464PCtIPSqiBp9uGao/7CFNSkHXEy5JYLjT9aDKh6HBtU5Cc1VJle3oz y6H5R0Ke3i9C2TN61M3bb7wAvkh7tTA= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="FI/NN8FV"; spf=pass (imf08.hostedemail.com: domain of 3zeoVYwYKCBo6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3zeoVYwYKCBo6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: qiehk8ny41s49shajzfedh3stfuehqus X-Rspamd-Queue-Id: 1A197160076 X-HE-Tag: 1662380750-689089 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;