From mboxrd@z Thu Jan 1 00:00:00 1970 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 2A6A6C433EF for ; Mon, 21 Mar 2022 13:18:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97F346B0072; Mon, 21 Mar 2022 09:18:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92F476B0073; Mon, 21 Mar 2022 09:18:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CFFF6B0074; Mon, 21 Mar 2022 09:18:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 6E2286B0072 for ; Mon, 21 Mar 2022 09:18:22 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0BA98A3247 for ; Mon, 21 Mar 2022 13:18:22 +0000 (UTC) X-FDA: 79268447244.19.4FAD19C Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by imf09.hostedemail.com (Postfix) with ESMTP id 95C6914000D for ; Mon, 21 Mar 2022 13:18:21 +0000 (UTC) Received: by mail-qt1-f169.google.com with SMTP id a11so7909738qtb.12 for ; Mon, 21 Mar 2022 06:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TQ5DlndeeL1f8ja+gUYUVQpHHaIrThDTIuKyf0ppDTc=; b=LIRTe+Eafb9scj4JV2xH2RID6I1OGtDAZhtFmMZjaSpAoscNtWTI3rrhlkkhwkAI8d lxNzMRzHjCGHa+i1t92Dp7lRCxzfAttZ/Q9Hg0HPkk6JdV9t8bSixip+EbBHX1VZDiO5 pcerS60YzGYqUsQDa0b6EYqO/Bm4EtCwINiVYkhLjHAB/e8VsXliPXsV7dajsqig5Wic eJfMN6eE2JTFjri9e1JJ2oE3BVOrsBSmJ5UihOLHs9KxZdvLgHiDbOurrvuPLuhiLPHF DLJXp8tRVFiXxpnI6AYG+ojp5dmN+uYY6I1CWoRlTJm+0o1khQ3RlL+/9hKLlWRTFSQW 9bBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TQ5DlndeeL1f8ja+gUYUVQpHHaIrThDTIuKyf0ppDTc=; b=NhBND0DzYolZcpzQHommcq5/RucNyV9oiNXsvGSdRQNSvWsD00V4l3+1dgbm9i9YN1 aKD0KEmj4aUclS8iyfcVmJ5C7t+a5YvFSQWh8YPiXmS6r+fZ7cdNG8zNRhzBbBGcu7zB IUymXlktPneZ98xvjRMNuCngpGXZUVX/SGi22xHkQ1OzGQGba0k9UXWyHMTstlaS57K+ uFyWj7tnX7PLrk8o9Hn/UIEcFo3W50DbqDT4ITvS4h5xxZWklmcmT/RMt+lCV1kbz1o+ 2Ta+cAEMnY/B0/5OAP2xdbX54rztYJ7Nm4Yq6E8NrqgBDGAF3K1rVDoXfhtkjNXlm3LV FR2g== X-Gm-Message-State: AOAM5303xrGGfMZvUe78oYCHXISn97OPKal1JXtvo2Ui56yWu37Hn6rc Z5HQWTplZirMSVBgoI+Fm5Dy1xwefkvBT9wzqlq0WA== X-Google-Smtp-Source: ABdhPJwVmUD3yoMMw5kXu4JqJXi4wUkn2PlRIab4lbVgU5Iae1T4ofWbeudwh+1zEUcmvCn/AbwF6c2nWPK2J/sGW+8= X-Received: by 2002:ac8:5809:0:b0:2e1:f0bc:2e88 with SMTP id g9-20020ac85809000000b002e1f0bc2e88mr14516126qtg.138.1647868700564; Mon, 21 Mar 2022 06:18:20 -0700 (PDT) MIME-Version: 1.0 References: <20211214162050.660953-1-glider@google.com> <20211214162050.660953-14-glider@google.com> In-Reply-To: From: Alexander Potapenko Date: Mon, 21 Mar 2022 14:17:44 +0100 Message-ID: Subject: Re: [PATCH 13/43] kmsan: add KMSAN runtime core To: Dmitry Vyukov Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , Linux Memory Management List , Linux-Arch , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 95C6914000D Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LIRTe+Ea; spf=pass (imf09.hostedemail.com: domain of glider@google.com designates 209.85.160.169 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Stat-Signature: z6puiwm8iyjfgm4ktzkw5t7eyodwwoi1 X-HE-Tag: 1647868701-390980 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_WARN_ON(!src_slots || !dst_slots); > > + KMSAN_WARN_ON((src_slots < 1) || (dst_slots < 1)); > > The above 2 checks look equivalent. Right, I'll drop the first one. > > + KMSAN_WARN_ON((src_slots - dst_slots > 1) || > > + (dst_slots - src_slots < -1)); > > + backwards =3D dst > src; > > + i =3D backwards ? min(src_slots, dst_slots) - 1 : 0; > > + iter =3D backwards ? -1 : 1; > > + > > + align_shadow_src =3D > > + (u32 *)ALIGN_DOWN((u64)shadow_src, KMSAN_ORIGIN_SIZE); > > + for (step =3D 0; step < min(src_slots, dst_slots); step++, i += =3D iter) { > > + KMSAN_WARN_ON(i < 0); > > + shadow =3D align_shadow_src[i]; > > + if (i =3D=3D 0) { > > + /* > > + * If |src| isn't aligned on KMSAN_ORIGIN_SIZE,= don't > > + * look at the first |src % KMSAN_ORIGIN_SIZE| = bytes > > + * of the first shadow slot. > > + */ > > + skip_bits =3D ((u64)src % KMSAN_ORIGIN_SIZE) * = 8; > > + shadow =3D (shadow << skip_bits) >> skip_bits; > > Is this correct?... > For the first slot we want to ignore some of the first (low) bits. To > ignore low bits we need to shift right and then left, no? Yes, you are right, I forgot about the endianness. Will try to add some tests for this case. > > + } > > + if (i =3D=3D src_slots - 1) { > > + /* > > + * If |src + n| isn't aligned on > > + * KMSAN_ORIGIN_SIZE, don't look at the last > > + * |(src + n) % KMSAN_ORIGIN_SIZE| bytes of the > > + * last shadow slot. > > + */ > > + skip_bits =3D (((u64)src + n) % KMSAN_ORIGIN_SI= ZE) * 8; > > + shadow =3D (shadow >> skip_bits) << skip_bits; > > Same here. Done > > This can be a bit shorted and w/o the temp var as: > > new_origin =3D kmsan_internal_chain_origin(old_origin); > /* > * kmsan_internal_chain_origin() may return > * NULL, but we don't want to lose the previous > * origin value. > */ > if (!new_origin) > new_origin =3D old_origin; Done. > > > > + } > > + if (shadow) > > + origin_dst[i] =3D new_origin; > > Are we sure that origin_dst is aligned here? Yes, kmsan_get_metadata(..., KMSAN_META_ORIGIN) always returns aligned poin= ters. -- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Liana Sebastian Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Falls Sie diese f=C3=A4lschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, l=C3=B6schen Sie alle Kopien und Anh=C3=A4nge davon und lassen Sie = mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.