From nobody Fri Dec 19 17:36:32 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02ABEC6FA89 for ; Thu, 15 Sep 2022 15:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbiIOPLD (ORCPT ); Thu, 15 Sep 2022 11:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbiIOPJp (ORCPT ); Thu, 15 Sep 2022 11:09:45 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA4B19A6BB for ; Thu, 15 Sep 2022 08:06:11 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-33dc888dc62so161466177b3.4 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=ZCQHBhYTUhpWrjW2oiXTKRHUHaJa3DOiE1xCEP/TkzSG149X2TyrFO9F1W0+9DLOqX hkd2nlnkAADZziSxizBuUyMv13eqboQZtsEIJ99oXThnSZ1s0WtSe3+CNbjNJOSpP1ck zSGRax9FrlXqF6vXVavZqUdiIoAOPmU8oELzU96Ar4lGoBajUHOk15N83LOi8I+1eVz1 jY5UjRJsnFP4ut5Z9IQ+PsudFrLykAsr1lIFHa53S8/YDWmdlP2lCGRfsjMohOk9t8Q0 aaYVysi2t1lyQ32fVUfanuqFikhvVpj3BLge4hF8nqTtcsvuFIQYKs4uALL1C/ogbneT Hc1w== X-Gm-Message-State: ACrzQf07DdhUk37LzX+MwyCyqOQxT1ZVxOUkznY3T/GWvcN4tF3ufJtN 86UCDE0Qup/3ZcMb5yVM2aoKKX3yAmE= 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/Icb16bf17269087e475debf07a7f= e7d4bebc3df23 --- 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 =20 #define movs(type,to,from) \ asm volatile("movs" type:"=3D&D" (to), "=3D&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-=3D2; } rep_movs(to, (const void *)from, n); + /* KMSAN must treat values read from devices as initialized. */ + kmsan_unpoison_memory(to, n); } =20 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; =20 + /* 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); --=20 2.37.2.789.g6183377224-goog