From patchwork Thu Sep 15 15:04:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12977552 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 ECF3FECAAA1 for ; Thu, 15 Sep 2022 15:06:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84B4C8D0009; Thu, 15 Sep 2022 11:06:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 784AF8D0001; Thu, 15 Sep 2022 11:06:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64C118D0009; Thu, 15 Sep 2022 11:06:13 -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 507118D0001 for ; Thu, 15 Sep 2022 11:06:13 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 358D11C6262 for ; Thu, 15 Sep 2022 15:06:13 +0000 (UTC) X-FDA: 79914645426.06.0F7B666 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf17.hostedemail.com (Postfix) with ESMTP id D5FE5400A7 for ; Thu, 15 Sep 2022 15:06:11 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-349e90aa547so13295777b3.8 for ; Thu, 15 Sep 2022 08:06:11 -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=yflFKH40jmwCCGQluWMEQ//gU/gWIMkmRe3xdXByGVQ=; b=nHAQ6SAQ1faGRG9hCcyaUQIe9n4Ge0pIwJD55bA6+1hWT9R5/L1oJCjpqmJZktpPfg Zzf/dihTzHFGhAT9e/DSrZuoQV8vwHn9W923bX2O6zYQUYYhvbnhgiloRg7PukUjNtqq 4rFF+k8ohvV8a6XM78rLvVl2sgYj7aiX4GQ/hBOEUCoPhfBPQ/SZLt+/nkV+ankVPzU0 8z3PZ+ldmMmvDum55SGr04zcjq9E8UmqstAEXGSWTDd2uM9AOvDtxTuIIRLKoomWH6i1 KiRKZM0tStTYm/M5TBq4RUO3N3kwnZC9T4VW6TxeLO2DGHkKHIuA8r/FQKbCXKKQ/NF0 fHGA== 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=yflFKH40jmwCCGQluWMEQ//gU/gWIMkmRe3xdXByGVQ=; b=AGJjTAOS/8D3mUj5+OMiw14xdMc4tCxGgcaPj5Mr4KqLO3rwXHdzqUu05GSG3x4f3J uKrKjHDqCeFF8jMTJxaaZEJx0viPF6q4EbDOus9f/82saxkMk2noLMw66FyBgfwH2+mD 4umsQyAmGE3ISy+rgUFa/t1tqGMCi9Elp3sVxKgGy8kXysHMUsAN3Tc5qqySxfdn4Rzs 4KQsJkTjaz90Tcn3j5LhiLBdnvsplASbpooc8mxFZ1AoN+fFQIZIG3Hjf/LkFx3h4R00 8BC98SMnL29VUIARQy+38RQFncIUVWIQGRlSzlZKC7TnXVlHO5fBjlgmNMnseUi/2hJe GDbg== X-Gm-Message-State: ACrzQf22siww7cD+k61m+PzdM++n7boaZWUaWrJ5/7VjHTAHx/ACwV9z xOZwZ2zJtXWUjsHDhCtvgPniTvLDDsM= X-Google-Smtp-Source: AMsMyM6H/hSS0cPD7FS1q40ZA63aNPC7pVayxD24osgSkvd4IxyFksaB63ob13ApaIIuI+chLmajKEbvemw= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:686d:27b5:495:85b7]) (user=glider job=sendgmr) by 2002:a25:9d0d:0:b0:69b:6626:6915 with SMTP id i13-20020a259d0d000000b0069b66266915mr228697ybp.294.1663254371078; Thu, 15 Sep 2022 08:06:11 -0700 (PDT) Date: Thu, 15 Sep 2022 17:04:08 +0200 In-Reply-To: <20220915150417.722975-1-glider@google.com> Mime-Version: 1.0 References: <20220915150417.722975-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915150417.722975-35-glider@google.com> Subject: [PATCH v7 34/43] x86: kmsan: handle open-coded assembly in lib/iomem.c 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 Biggers , 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 , Stephen Rothwell , 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=nHAQ6SAQ; spf=pass (imf17.hostedemail.com: domain of 3Yz8jYwYKCI4y30vw9y66y3w.u64305CF-442Dsu2.69y@flex--glider.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Yz8jYwYKCI4y30vw9y66y3w.u64305CF-442Dsu2.69y@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663254371; a=rsa-sha256; cv=none; b=e+o9BkK/kqLHbvsKYBCSfhlFaXSJJIEiWgyd6UoqPWQQ4hyBdATPE+/2LkYBsxUTYtlniX Tq1jOI1LlUCc13FWCywZ4201YeF9C2BlZ0G/S7VfNXkM30LOitkuQplswiQJmzi/04H5nS tmY+ZCpgnSCfoWAfcW3jbugV2K+DhzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663254371; 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=yflFKH40jmwCCGQluWMEQ//gU/gWIMkmRe3xdXByGVQ=; b=ww1LR0i52rx0NgDWLl0w54syUNxvJMvftWtvX/Dc4+kXysKXANz3XvBkJl6gakcTX//ETD 1ZODNAh620PO2b+4kXXIdqrhaxZ/SybAhLNARdOYgTEP/L2US6JH0+t/Gjfc0URzVYLMMl YSA4dUYvxwq0j2xBjwfZLz71JZ02uOY= X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: D5FE5400A7 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nHAQ6SAQ; spf=pass (imf17.hostedemail.com: domain of 3Yz8jYwYKCI4y30vw9y66y3w.u64305CF-442Dsu2.69y@flex--glider.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Yz8jYwYKCI4y30vw9y66y3w.u64305CF-442Dsu2.69y@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 1pc19693sw9h7tx1pdjiggm3dcfhb7nz X-HE-Tag: 1663254371-465036 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 3e2f33fc33de2..e0411a3774d49 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 @@ static void string_memcpy_fromio(void *to, const volatile void __iomem *from, si n-=2; } rep_movs(to, (const void *)from, n); + /* KMSAN must treat values read from devices as initialized. */ + kmsan_unpoison_memory(to, n); } static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) @@ -44,6 +47,8 @@ static void string_memcpy_toio(volatile void __iomem *to, const void *from, size 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);