Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4453378ioa; Wed, 27 Apr 2022 04:19:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvOaXkTpfHNhDmLX2G92Tacx+RVDKCC59kf6pHi5orN3wH1jctBI1AAYN4qgnTopgXTO2D X-Received: by 2002:a17:902:d547:b0:15d:8ca:181a with SMTP id z7-20020a170902d54700b0015d08ca181amr16780945plf.123.1651058385472; Wed, 27 Apr 2022 04:19:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651058385; cv=none; d=google.com; s=arc-20160816; b=pui4lNu/cTPZ5qZckTSmNZdEOU5Eh09HQNFAtlaSFhFQlPJ/zXa3lMfRl0pIXTIIef y636Msipc+X3SwuPgcaUP8VM1oWcbDBTZnWu3kyWTYjKwViuW/k+pjA7h7DWlAQui/vf 6tLCQ33/mQ+dsx1rratODScsU0XZKI4Wz6vkP71gN/Typyx6mLYrtkJ81LtIj0NamHGC OTvNbPk0sCqHxOf21Y2wwsT8H0tI2LifTLSSyZ3SpTjhM1YBLsvQGF8xcsRyTfHehfwG noxix0dMfXN7GEoB1LUhRcw944QxflgooUgxPOXNlmKYudnbq+ER+7ZomQC0w/8jQI3E BgCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=xs3mnLw1SF/DZ/Tq7NTZzrdEtEEoGjj1tkhOxGSNVPQ=; b=cxIJdPZKMG+VCA0D7xrxAtaUAxAKXPs7/qa+SQcBjNaeOAS6g6Y9nyAnLIUKUx5xLv RD4gQ/dUuNafcwJIggJZZCsawgGvQodkM/FUH3mZGbjX8OPyrLxJtWoVWOetk7OqWkhL sXFf5gB3vjluqXfnS4kG91CD83FplR4HSdcG1PTFIWVdzUOm0c3Bp/MzqCfr1XmDQ3z9 K+wizXpm6STntbhb9iZOj4D6FJHcFkMGE8LOR/5HfmkfBzcmeRmjqbgJhQC6qNTUUO2M KFqu94IreFWjVl8Swh4//RlmNFGzQzKYyMQZl1JEKP1I/zdN2zmgIf7SQwyhA3ozco43 CuOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Dp8fDgew; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f26-20020a63555a000000b0039cbfcd3b1dsi1220386pgm.830.2022.04.27.04.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:19:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Dp8fDgew; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8EBB9320B03; Wed, 27 Apr 2022 03:13:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353388AbiDZQvy (ORCPT + 99 others); Tue, 26 Apr 2022 12:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353252AbiDZQvA (ORCPT ); Tue, 26 Apr 2022 12:51:00 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E85D0289A7 for ; Tue, 26 Apr 2022 09:46:05 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id t25-20020a508d59000000b00425d86c2987so4109343edt.21 for ; Tue, 26 Apr 2022 09:46:05 -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=xs3mnLw1SF/DZ/Tq7NTZzrdEtEEoGjj1tkhOxGSNVPQ=; b=Dp8fDgewCtm7EfJ+NxSWPaqf4fjHXCb5jsKUHsqjOQlRwQkgkKZ/UWCSiVVrRs/uZW OQRNetbiqEwnG85Z0p1Sf25DydKgfbA8aQ0Bsb8u1giNx3oJsml+h06KXd12ZFl+7zlh 88EaOBCQpujgyWZhEQULbY92x5FazQAo2pGdWFAwltYHX4X7vprtu3R+YlyuxLW4bV7A kz4jOXTPx7d0TC785iMRbaV+fkvSej+QsvFkw8jbYuayp+vHkk5UYhSq7fmBnGbZjeRh ej2EyGUQvI2W9wRBjeiQzBogyryUJQVM1Tt85ycKl00a26JFtroHDFnq/8e7RZbUcfE0 4QnQ== 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=xs3mnLw1SF/DZ/Tq7NTZzrdEtEEoGjj1tkhOxGSNVPQ=; b=Mt3yn8Ct68Yw+ddK6FI3m6vUK0dUU1YdxsUTByt35K4XtQxeXCWd96MBC1oNA/xL+E JRJxkWADsQaB6PEvHILa4+6qD+DL7ZdTkAz5keOpMIxa2oXa+7bl9wxLmDw8TDIvFME6 i6qvaYgc+X2Jj6o9kclQ8plvVTog7uy8T+TEVRF+IvZbB7bkPcGE28VuOsIEQXOh4y6j etbMhMNHUmZaU3ZwPEh0u2xqgE/Rx+f/H0CMxMnSVcaflYcu/UlBCcbq0aHEkjQtuVAZ tBeWktuEXrGylY7t6xeXOlXCDAzoJ+mxlxB/POy+Dr1yXgeUcAPIACdxcsFPHmMW493w sYOQ== X-Gm-Message-State: AOAM533skDPiK/4SOVnfu44P1S9/Pl4j6rddhQKnLKTFwE12Bk+fJnUa wI+RZjPWF2BX9LPqHBksaaQw8Qrz+BQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:d580:abeb:bf6d:5726]) (user=glider job=sendgmr) by 2002:aa7:c70f:0:b0:425:f70d:b34 with SMTP id i15-20020aa7c70f000000b00425f70d0b34mr7131646edq.306.1650991564200; Tue, 26 Apr 2022 09:46:04 -0700 (PDT) Date: Tue, 26 Apr 2022 18:43:09 +0200 In-Reply-To: <20220426164315.625149-1-glider@google.com> Message-Id: <20220426164315.625149-41-glider@google.com> Mime-Version: 1.0 References: <20220426164315.625149-1-glider@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 40/46] 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 , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.36.0.rc2.479.g8af0fa9b8e-goog