From patchwork Tue Mar 29 12:40:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12794792 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 CD268C433EF for ; Tue, 29 Mar 2022 12:42:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 569308D000F; Tue, 29 Mar 2022 08:42:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5179F8D0003; Tue, 29 Mar 2022 08:42:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DF388D000F; Tue, 29 Mar 2022 08:42:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id 2FF758D0003 for ; Tue, 29 Mar 2022 08:42:23 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E9C888248D52 for ; Tue, 29 Mar 2022 12:42:22 +0000 (UTC) X-FDA: 79297386924.30.2B611A1 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf01.hostedemail.com (Postfix) with ESMTP id 3A92440005 for ; Tue, 29 Mar 2022 12:42:22 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id i4-20020aa7c9c4000000b00419c542270dso5231201edt.8 for ; Tue, 29 Mar 2022 05:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6EKMd0bjP1WkGhZZPkjCgU25E3DWfYJCasURW7mFnYs=; b=P1k71GssRqu7HsErV73nnblS85PhkUFheLyBFZgmPWLpl7OKiy1Bqi/JlOtZzfJVPy VAc7cvO8fwjHIxHwD4P9pVu2rdNH8e0p6iE439JugyKP3tEZpAogt6YoEY/b5rvhs6YN OlYMWP+8vwtXjv8eNiLfoejuKaPkdCuMEozoeNlW8PpIb+edtD9db/0+pmWKLdNhwURR 5E3Lth/p8S4d05TzSLze03fVsfkwrT++EyTKtUjOhLVyC4kbo3lKGGRltm0PtD2GB/IH Q3WE4SbVcH6AFhiknkVN5O3R1HMm1J+ZfOcalpdSexIx4dKDpVcT7q34bBD07dT9kvEi C7Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6EKMd0bjP1WkGhZZPkjCgU25E3DWfYJCasURW7mFnYs=; b=UkFTKI0T5rpk11Fixb5pDlH+dkMirGvVddaDgnqJfwDF36VTqbvDZF6kBANTYN5cCo Wjl3+PeUHO0a8CiSEn5vUmVGmvLDx5BscdK5Q4ZGf44tcJnBF64tbOmC2tBXvxKBGQT5 yDPIyVIgKatsjngZPjRzhgGyk+V6bpnfZQ3LWg3NSPVAfE6Sq6RIxk/RB0LDxVOjfGe7 LNXC3WpUaTZNbW4QmvE+kgDCSpje/NV/DKzy/YRk4gNm5BOmqTpV5YShfQVPldXzTpme 9sve+3ZknTQm2qFfRhx53NeVIVyKsY+ranwsPeGCOPvaqmcL3jclntsp1xJidhhgu1Lb M64g== X-Gm-Message-State: AOAM531YQHU8qrQpR7UagLo6xxOkKmns4oRP1KPPMQYZRgK/thFmRcke dTMKOt+Il9q2zZTtIz89mupHD+W10xs= X-Google-Smtp-Source: ABdhPJyN/u61iYoRLkPCDJv7Xs3UegKZjTjkx8b5A87Fx1oaelxWk3uqKnX5mytmcMKvTp7b3Wewv/gEEvA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:36eb:759:798f:98c3]) (user=glider job=sendgmr) by 2002:a17:906:3042:b0:6cd:20ed:7c5c with SMTP id d2-20020a170906304200b006cd20ed7c5cmr33818169ejd.241.1648557740796; Tue, 29 Mar 2022 05:42:20 -0700 (PDT) Date: Tue, 29 Mar 2022 14:40:11 +0200 In-Reply-To: <20220329124017.737571-1-glider@google.com> Message-Id: <20220329124017.737571-43-glider@google.com> Mime-Version: 1.0 References: <20220329124017.737571-1-glider@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 42/48] x86: kmsan: handle open-coded assembly in lib/iomem.c From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , 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 , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org X-Stat-Signature: 9uqdf9nmceumw9xsg8qbe99171c6he31 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=P1k71Gss; spf=pass (imf01.hostedemail.com: domain of 3rP5CYgYKCM0z41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3rP5CYgYKCM0z41wxAz77z4x.v75416DG-553Etv3.7Az@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3A92440005 X-HE-Tag: 1648557742-779611 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: KMSAN cannot intercept memory accesses within asm() statements. That's why we add kmsan_unpoison_memory() and kmsan_check_memory() to hint it how to handle memory copied from/to I/O memory. Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/Icb16bf17269087e475debf07a7fe7d4bebc3df23 --- arch/x86/lib/iomem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/lib/iomem.c b/arch/x86/lib/iomem.c index df50451d94ef7..2307770f3f4c8 100644 --- a/arch/x86/lib/iomem.c +++ b/arch/x86/lib/iomem.c @@ -1,6 +1,7 @@ #include #include #include +#include #define movs(type,to,from) \ asm volatile("movs" type:"=&D" (to), "=&S" (from):"0" (to), "1" (from):"memory") @@ -37,6 +38,8 @@ void memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) n-=2; } rep_movs(to, (const void *)from, n); + /* KMSAN must treat values read from devices as initialized. */ + kmsan_unpoison_memory(to, n); } EXPORT_SYMBOL(memcpy_fromio); @@ -45,6 +48,8 @@ void memcpy_toio(volatile void __iomem *to, const void *from, size_t n) if (unlikely(!n)) return; + /* Make sure uninitialized memory isn't copied to devices. */ + kmsan_check_memory(from, n); /* Align any unaligned destination IO */ if (unlikely(1 & (unsigned long)to)) { movs("b", to, from);