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 4B2D9C02199 for ; Thu, 6 Feb 2025 18:14:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E8B280003; Thu, 6 Feb 2025 13:14:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1D00280001; Thu, 6 Feb 2025 13:14:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0C63280003; Thu, 6 Feb 2025 13:14:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9FB1A280001 for ; Thu, 6 Feb 2025 13:14:48 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 54D781413D0 for ; Thu, 6 Feb 2025 18:14:48 +0000 (UTC) X-FDA: 83090320656.04.6E9DC53 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf05.hostedemail.com (Postfix) with ESMTP id 6488E100007 for ; Thu, 6 Feb 2025 18:14:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ElH6pYF7; spf=pass (imf05.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738865686; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wTbbT4CsuJ/iXGmiqeOEuQTztaWXsApJ6CIEHLfEbjE=; b=NcbjaJmv/vU9Uyptv5u+GJJSWzqCSmOHM1MAxRutCFBjrAiftzzxOOpmDKextZOV7NEaOZ ygQd9ACUTpPF7TToDG3Qdqu8Uwulpbsm5V564KqVlzJzBSNnh/17GVslKnpT+Zt+BmFp+C ogtsW/rnuAbcXnnYnxYUVo9xKaNuD/U= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ElH6pYF7; spf=pass (imf05.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738865686; a=rsa-sha256; cv=none; b=bFDa5iZUdzUq5gYKtnRWgwWRaBxZQdK56SyyWbLXOvY5iJ5qyfdMKLSb3+9irGCdxBDYx6 0VtWHzBRJ8T1b7Q7G6KmEkwLAOsLFiOCd7XNz77JWZzQ9+bxzOK2DZJT0VKPKUw81hf25J PgkeRnw3tC+QdcLwDmU7viF/1w10IA0= Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-38dc5764fc0so448074f8f.3 for ; Thu, 06 Feb 2025 10:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738865685; x=1739470485; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wTbbT4CsuJ/iXGmiqeOEuQTztaWXsApJ6CIEHLfEbjE=; b=ElH6pYF7nlqZ5kSLIJXj0DxRjPxyr0MtokRNrt6Ee+9exrj4quc7Vd16QE9M3aaVZC lgQTpOGnNtYtpQBm6dMoxK86YLiE5/ybAv0UC63LCU2F2nXhZ08bjXnaFA+3dOrjCCOD O6ywgQ7v4Of1MgX6jgpNXUC38u1c5psXm84Jy7MrjznTZYl8pJ6EvmIrD6POw3w750uj bpE60Fgbdoz6A/NL82j/eA9o7krBSuSImM8ShwtshGyT2F9afDVl4DVh7dQ6qJgjFH7a J76LrbJMoa4og8vCXSpXcV1l9896+7EBKMyqCsXUbQzO69Xn+ObvEdsbcn6Q+P9bJpd1 FCjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738865685; x=1739470485; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wTbbT4CsuJ/iXGmiqeOEuQTztaWXsApJ6CIEHLfEbjE=; b=NXMhZgNTCVYYfXeOBf+mENKcDh8buH67QVwxdlyu3NQhy1M3hI1x5irVRKvBNVX/lZ kIxfnP9bjkh2akasqhZBMeOACOACu5D9PHHP0Uz4GfTD2Mh/XrwI+Fb1vq6vXxc7GTqH AfADTNaAlTCz9wspngf3vxUZNn386ZtUtoRzUUTvpsPPsAWxXAfqt7OOjt1yKWEzjtBk Aelg1QmSIJLJAXd2zASjF9fUpc4aTHQTb5Wjq0SLhKIsjKJYePFKrWK+3mN8PV4h3qZ/ /xXIePSg73w+QdzQZLs2kkhao1tsO9SOvRTYl0rNyXQ2otcDBIR6kc7ahXiYpn4SY81M 6AIg== X-Forwarded-Encrypted: i=1; AJvYcCXw5GxvbEcHcVfD3wv6VYeSNnSiAgYAe9AYUe0/bLzHcd1eER08hc6+9QrpUrPVfr4uTrK0X5hLxQ==@kvack.org X-Gm-Message-State: AOJu0YwT5PCS+7HerSmi1nSjB8Fkso5AV2FsXT5KHBQ8DPij+oYfbiZ0 ++qfF8xubwC2OlyAEqbTlNP/cwwci3MwMkdrBZl+kfDb2r8op69NS09JngUg5DiJz3YkBPkXVEO qFxloCJHmGuT678O/YNlNaQZtR2I= X-Gm-Gg: ASbGncsEK62CARlf+qe7tiRMH7PjZ5EIWJzfx9DjNWTmH1b0dV3TRhqP7H8Ryu1Ahff KEhPuHfr1TI2ug8zAdmP1c2b6NKZd7oAbpI8g1nkJZaC6x38R0liVfTwyjC599ubxaJgkpiir7Q == X-Google-Smtp-Source: AGHT+IHBkaKzKisMLjhYNPQEk4vOcutkS0bItT/CuWo+2lyB11rB/+L1N95UZJSHFEtHE7FQsPK4hkaRlaOSWfeGMWw= X-Received: by 2002:a05:6000:1acc:b0:38d:c2ef:e291 with SMTP id ffacd0b85a97d-38dc2efe475mr1873314f8f.39.1738865684758; Thu, 06 Feb 2025 10:14:44 -0800 (PST) MIME-Version: 1.0 References: <808cc6516f47d5f5e811d2c237983767952f3743.1738686764.git.maciej.wieczor-retman@intel.com> In-Reply-To: From: Andrey Konovalov Date: Thu, 6 Feb 2025 19:14:33 +0100 X-Gm-Features: AWEUYZmr-sZ7H7rQ5pJvdgslU5r_pD-83ZAYiTMD0XxDDSXEdCYqWWqGvarMkGQ Message-ID: Subject: Re: [PATCH 01/15] kasan: Allocation enhancement for dense tag-based mode To: Maciej Wieczor-Retman Cc: luto@kernel.org, xin@zytor.com, kirill.shutemov@linux.intel.com, palmer@dabbelt.com, tj@kernel.org, brgerst@gmail.com, ardb@kernel.org, dave.hansen@linux.intel.com, jgross@suse.com, will@kernel.org, akpm@linux-foundation.org, arnd@arndb.de, corbet@lwn.net, dvyukov@google.com, richard.weiyang@gmail.com, ytcoode@gmail.com, tglx@linutronix.de, hpa@zytor.com, seanjc@google.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, justinstitt@google.com, jason.andryuk@amd.com, glider@google.com, ubizjak@gmail.com, jannh@google.com, bhe@redhat.com, vincenzo.frascino@arm.com, rafael.j.wysocki@intel.com, ndesaulniers@google.com, mingo@redhat.com, catalin.marinas@arm.com, junichi.nomura@nec.com, nathan@kernel.org, ryabinin.a.a@gmail.com, dennis@kernel.org, bp@alien8.de, kevinloughlin@google.com, morbo@google.com, dan.j.williams@intel.com, julian.stecklina@cyberus-technology.de, peterz@infradead.org, cl@linux.com, kees@kernel.org, kasan-dev@googlegroups.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, linux-doc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6488E100007 X-Stat-Signature: jfj4pt4kyttg3h919kfdf73fkns5x3uj X-HE-Tag: 1738865686-699705 X-HE-Meta: U2FsdGVkX18rL4NnTxgRwLduZWLZ/0K0r1fWgahOP7Tr0/Po/xvQQfF1fe1nts9NvRjDr6eL/s75nggMbdAyqm4/NgnzjVAbtwySNxeAz0emAC2Ok1xuO/gHvgjuag8P/TFJy1SI4MKT7RqIyqq7Ie44fRMGq1Kzl4UygMwtOkY4kbV6mKThYbwpR25ljjCcDWaQ9rUeBMqRfhaQKxMfb+d2L9mxraVecTPBUmXxHHIAMyIg9hvINYYYFtZ4rASX3KXmVVlmlk1JlI8O0PudeLzvynNzNOBB8RtrT4IlZaD7sioogf+rjWCKin7R7tesF7lPIMnh0g9VgwkFx+qpii5QUzCB4R2mGvXQBXAF6FFqJb8Xz7v0iOIqvX0ujwQAQl1POmpARCErfJ//Ru0guBP5EuvFw9HZzze7JuVjxrDmrYNnjl4ZMMTtt9cftlygEpH5G/GMkVqpyuwj7kGfnPuXRV3KqR3dsITyocXfYw8KHeqBiXXmrRBUqsV4LVAzgJos3gCA/d1OPUA2x9/e1+xXeGu2/ao7yjfNI48FS74AMVF+eNwjjRJvz5YD155fbqw3m7ts0XCLIr/5WAx0meUB8trb0khnhxn57/NOPy0p/BN4dJG6ngZjurKrB1ecCHCevothdSuaAglNhcjhiI0ChwYCwULCJvKfiCzSTWFS2Q2hwb5BFz7Yu33o9f1LPxvFWiBsyAWNCJvIoO+4gv58SFZ6cuCvhnzKB8WwP+SFYz5EGNtIe9eHO5DtxgyMzDgPDoN9rfNFtP/7xs/I7tMLrRBZBp5NSMIhpTLFfvP8vWAL8xR6NbUAd/LsGQN2lVswHmYhtb3coaLmDAtlZhRiPkaPlUmgjMUXED5Aw35yn+NB7NB60s6lziL8FlduQuRUWcDrF2CgvAsB3YgUxJmMLKTaCzv9FyGf1/haNl/QfPA9T4hJK14Tp8oqUvYPM1UDoOUneWryRekLk8/ KgHMfPuz Vz+Oc565I4IFtwuGFOHdNA19/POSSBhcHgLKd0yxavIDd/ZX+Aq6DEjik7+wZLI1v/nMEqk1XpAcRMvikdWx43fNjk5X4jPmjIClWHuvJ2LPSMVT6FEL5D3jbM8GdhQy+4l7fbevK3A7Gvse4XaBqUm58QSIgvBXz65xLTswibczYmquySAOucIBsAvvVQFM/US/DOS1GICwcbuIuXzw/CbW33LgmZLrB1pi2ur8MgqXk48kxaO24cI51ZqEn3LyMUFPB0aTZI2/zRawJ1Y2JdoE+lvwvXSiuCZ7nX0jim5HHAxwDhp0NmFh6DM27/l2K0d5k3EkbjAAk5DDhUu8sNN10zPc9hMykM/pwRQ9jj7cF4CoyelCgqF/EreBguLB2iHEMQVY/WvqKnsxK2O4ZFJ9oLiYjGO/9khsK X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Feb 6, 2025 at 1:58=E2=80=AFPM Maciej Wieczor-Retman wrote: > > >Is there a reason these definitions are added to > >include/linux/kasan.h? At least within this patch, they are only used > >within mm/kasan, so let's keep them in mm/kasan/kasan.h. > > Parts of x86 arch use these later (minimal slab alignment, kasan shadow s= tart > address) so I thought it was convenient to already have it in place here? AFAICT, KASAN_SHADOW_START only relies on KASAN_SHADOW_SCALE_SHIFT, which is defined arch/x86/include/asm/kasan.h anyway. And ARCH_SLAB_MINALIGN is defined in asm headers, so the definitions from include/linux/kasan.h shouldn't be visible to it? I think that we need to do is to define KASAN_GRANULE_SHIFT next to KASAN_SHADOW_SCALE_SHIFT for x86 and then use it in mm/kasan/kasan.h to define KASAN_GRANULE_SIZE for SW_TAGS. (Similarly as with arm64, where ARCH_SLAB_MINALIGN depends on either KASAN_SHADOW_SCALE_SHIFT or MTE_GRANULE_SIZE, both of which are defined in arm64 asm headers.) Btw, I think ARCH_SLAB_MINALIGN needs to be defined in include/asm/cache.h: at least all other architectures have it there. > Since I'll be reordering patches I can just move these changes together. Otherwise, if you need to expose something new in include/linux/kasan.h, please do it together with the change that uses it. Or you can even put it into a separate patch with an explanation of why it's required - at least from the review perspective having separate smaller patches is often better. In general, if something doesn't need to get exposed to the rest of the kernel, keep it in mm/kasan/kasan.h. > >I think this should also depend on KASAN_OUTLINE: Clang/GCC aren't > >aware of the dense mode. > > I wasn't sure I fully understood how inline/outline interacts with clang/= gcc on > x86 (especially that I think some parts are still missing in x86 clang fo= r > tag-based KASAN). So I understand that compiling with inline doesn't do > anything? If so, is it not doing anything because of missing compiler cod= e or > something in the kernel? With inline instrumentation, the compiler directly embeds the instructions to calculate the shadow address and check the shadow value. Since the compiler assumes that one shadow byte corresponds to 16 bytes of memory and not 32, the generated instructions won't be compatible with the dense mode. With outline instrumentation, the compiler just adds function calls and thus all the shadow calculations are performed by the C code. Or did the dense mode work for you with KASAN_INLINE enabled? I would expect this not to work. Or maybe the inline instrumentation somehow got auto-disabled... > >Would it be possible to move this part to kasan_poison_last_granule()? > >That functions seems to be serving a similar purpose but for the > >Generic mode. > > > >It might also be cleaner to add a kasan_poison_first_granule() that > >contains the if (addr64 % KASAN_SHADOW_SCALE_SIZE) check. > ... > sure, I'll try to move these checks to kasan_poison_first/last_granule. For kasan_poison_last_granule(), I think the change makes sense. For kasan_poison_first_granule(), please check whether it gives any readability benefit - if kasan_poison() is the only caller, maybe adding another function is not worth it.