From patchwork Fri Jul 1 14:23:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12903392 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 CC133C433EF for ; Fri, 1 Jul 2022 14:24:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E4446B0075; Fri, 1 Jul 2022 10:24:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 694606B0082; Fri, 1 Jul 2022 10:24:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55D856B0083; Fri, 1 Jul 2022 10:24:55 -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 45A406B0075 for ; Fri, 1 Jul 2022 10:24:55 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 1482F8041E for ; Fri, 1 Jul 2022 14:24:55 +0000 (UTC) X-FDA: 79638752550.18.3AC60AC Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf09.hostedemail.com (Postfix) with ESMTP id 93CB0140047 for ; Fri, 1 Jul 2022 14:24:54 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id z13-20020a056402274d00b004357fcdd51fso1871048edd.17 for ; Fri, 01 Jul 2022 07:24:54 -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=CG3pZwK286Wp+stKkliNeTwrORF17cOHhcnhVfCJeQE=; b=bYQ2u2U8tj3aHjd9MCtMixUrYfpSQwTg4WPOIoCPEeukhh64yxMHafM5vs/LGNKnzQ WbZCO/BXLkzB63X6UKAseam1QIfdrrDcHBVOGpbspRYW0ejgy0BAvw5OVpGh3iBOeZEX aaVkXTg3A0tuwa1e18PtKkEW1bZ16MVMyhI4LHrOLoqfrXkdK5JLNMCCXCzP+UqlS+7Y jMHKRvPORQSh2gGeBXFyCiEXw+TmFxCdnaNG5nGomGgf7TAWqOwR/NSipZV8JXpF91j0 T7T+oh1yqE70PVoxhXBFXshJGT1hPLtyEjj27zgL+pSYm9TNfYDnuWL3u/qLN7pkNGWn fRFw== 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=CG3pZwK286Wp+stKkliNeTwrORF17cOHhcnhVfCJeQE=; b=eGg0uBrUd4DO++x6CALsCLjsi1ji01PDLDfGkIQDX61MmHXyLZ2b+M1mOlg5oNaOpv pHnPnJppr+7Yeg8ivE3UZomeldIvfFK8RNV14rHB/KiIYTrLaJjOARtNYG6p5jc6run/ Ke8Y+MNiCQYq902j1EqpzvtoUfl4Q3DUR3dYhun3Wp6GgOEvPhkeo+o6hr7+7kNmKgUY y2+zn6U3RwUMiNMSp7M2veJsZYbyraIAtVtgc90m0JV3fS19fhTcaWr9/jgx6qzzF6bk 4OkWxCoFGR+fPUmNpfcqDB4Qcvmw9pxZ+bxjJcsWEjbCIDAhkTMbYeXaNsZHveQ/yQda ysog== X-Gm-Message-State: AJIora9jLTTSQpPn6y8OrTbpPqTx+K6qUfZlmPb8Xt1XCmsvoI2Lcwk3 el+uOI0H6JKZd6LfqwmTrBPIsH3F0VU= X-Google-Smtp-Source: AGRyM1vuhrwmXAXJ9wJid3cKYDBtVUPAQNXpJsIZnZORqGteH/3hS1Qh3dFSI+7P2W3d1z7T02mluBgbb3c= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a05:6402:2403:b0:439:682f:d12c with SMTP id t3-20020a056402240300b00439682fd12cmr7312146eda.301.1656685493399; Fri, 01 Jul 2022 07:24:53 -0700 (PDT) Date: Fri, 1 Jul 2022 16:23:00 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-36-glider@google.com> Mime-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 35/45] 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 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; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bYQ2u2U8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3tQO_YgYKCNQ6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3tQO_YgYKCNQ6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656685494; a=rsa-sha256; cv=none; b=qgYrFJKw0sR40n/bTrBOyTgM9k500Pqf7zE5besGIqfuXMZkN6G/avf0etlYkH3SE/mB5U lWxjdOH5B9pusEXv1oE+KJSVR8QPVGOPcXyp5RNyHrWpg9f94CEM5RCF5ZT8gzSrtfAonC XZJVUmsyxtR8VQddvrrtiyw7QcdtMRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656685494; 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=CG3pZwK286Wp+stKkliNeTwrORF17cOHhcnhVfCJeQE=; b=v4emhrPSxlKUb95XMGCCwS7hFNK6kKNAgYCM0pxNBGkyqlWJRhfftsxtEOUhETL1U8UD/f Iiepm22auNdpYC2g/7HJNuwWdhzq7ymHe1l8o6CKi5ZwvAiH/CUZg3HkAevb2iX6hXxtXQ Xmeu4xTdwmwjgj/90AbBh+H4I2c1p/Y= X-Stat-Signature: 61by4qnrga5g64iwkpyk61qrcddan5ty X-Rspamd-Queue-Id: 93CB0140047 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bYQ2u2U8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3tQO_YgYKCNQ6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3tQO_YgYKCNQ6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1656685494-92151 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);