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 X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84154C433E0 for ; Fri, 12 Mar 2021 15:09:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59A9964FDC for ; Fri, 12 Mar 2021 15:09:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbhCLPJ0 (ORCPT ); Fri, 12 Mar 2021 10:09:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232043AbhCLPJI (ORCPT ); Fri, 12 Mar 2021 10:09:08 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6EFBC061574 for ; Fri, 12 Mar 2021 07:09:07 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so15396651wmi.3 for ; Fri, 12 Mar 2021 07:09:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8MLa7BfE7dVLn4tTMKZ+HSLGOdEizmmjEqt3urdruHo=; b=YXc7cfUGiDH4BrcqeCbErclE5UpFbj0KRoCqW+CdxyNwQfypBnOQ/JXl/BQWZPYMSf 5Ot87rpsNwc67IcIMaUT/2mT5iQ6JifR2oOH4+1U/x2JoNkrhbmVOP0/YaoFweuMp7Xz 9cjsoeb2E5H/+ycRfan42lPk+YhVQV0q9C93ePz3hYTf3vqsa7zhKFLd+0J374z3OvPR q6pRk3yb3Fm5X2u5AfJvSoi8ssYpIoIVql9zeUnzsjQwAIsrhkKfqf6SypfcT5+zh6SL StmOqnQ0w/Qq6RFrjTQcbTOAerPuU/TSLKo2ozPFpgkU0a0XsO0QSJg8Jy9m9AYJukk+ DznQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8MLa7BfE7dVLn4tTMKZ+HSLGOdEizmmjEqt3urdruHo=; b=Uc3IaOOSFE+t0sYr+IWvbt7gZbIshnogw/K6ahy5egUKwDY+OfOzUOwMdvtyDBsLnD akdFFOqlpA/MacE8MONIEbQw7obj7hersrSwFn7bDlOjyfhi1vGb6/ca/IpidblK3bdZ 6uXaW7tEBNUqFWfq2px1CRsPvdVT+xXxGbBXRnWk1D7G+hPIIrTe5M/PM0U01oD6jVlq sInf9qyvBiOK1yr9KgycrdF6bskL0VBt6qRDfjMmMsoZXO797iGqfoRVnX50+wHkQijT 4HsidCvFxU3nPHAXnHLUbJQPMuHvqM/xTmFKettuwTVti2IbI0jxsYn00oDpDjoU8m/J AJ5Q== X-Gm-Message-State: AOAM532H8y97iKSufs3YXKITC9f7+TnLM7oF4eiCfKi1ijYVPwFMfcnt qzW6BlsXVC6tK+AnBluHbudPpw== X-Google-Smtp-Source: ABdhPJzugoYcXn8oExDHUrj07sG0kptHYTO8yEvVKp4/4x1MmKQHsAr23VIN62ownUD9pD+bMeZBnA== X-Received: by 2002:a05:600c:2053:: with SMTP id p19mr13577526wmg.87.1615561741593; Fri, 12 Mar 2021 07:09:01 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:d5de:d45f:f79c:cb62]) by smtp.gmail.com with ESMTPSA id w131sm2402679wmb.8.2021.03.12.07.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 07:09:00 -0800 (PST) Date: Fri, 12 Mar 2021 16:08:55 +0100 From: Marco Elver To: Andrey Konovalov Cc: Andrew Morton , Alexander Potapenko , Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 06/11] kasan: docs: update GENERIC implementation details section Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.5 (2021-01-21) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 12, 2021 at 03:24PM +0100, Andrey Konovalov wrote: > Update the "Implementation details" section for generic KASAN: > > - Don't mention kmemcheck, it's not present in the kernel anymore. > - Don't mention GCC as the only supported compiler. > - Update kasan_mem_to_shadow() definition to match actual code. > - Punctuation, readability, and other minor clean-ups. > > Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver > --- > Documentation/dev-tools/kasan.rst | 27 +++++++++++++-------------- > 1 file changed, 13 insertions(+), 14 deletions(-) > > diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst > index 1189be9b4cb5..986410bf269f 100644 > --- a/Documentation/dev-tools/kasan.rst > +++ b/Documentation/dev-tools/kasan.rst > @@ -200,12 +200,11 @@ Implementation details > Generic KASAN > ~~~~~~~~~~~~~ > > -From a high level perspective, KASAN's approach to memory error detection is > -similar to that of kmemcheck: use shadow memory to record whether each byte of > -memory is safe to access, and use compile-time instrumentation to insert checks > -of shadow memory on each memory access. > +Software KASAN modes use shadow memory to record whether each byte of memory is > +safe to access and use compile-time instrumentation to insert shadow memory > +checks before each memory access. > > -Generic KASAN dedicates 1/8th of kernel memory to its shadow memory (e.g. 16TB > +Generic KASAN dedicates 1/8th of kernel memory to its shadow memory (16TB > to cover 128TB on x86_64) and uses direct mapping with a scale and offset to > translate a memory address to its corresponding shadow address. > > @@ -214,23 +213,23 @@ address:: > > static inline void *kasan_mem_to_shadow(const void *addr) > { > - return ((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) > + return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) > + KASAN_SHADOW_OFFSET; > } > > where ``KASAN_SHADOW_SCALE_SHIFT = 3``. > > Compile-time instrumentation is used to insert memory access checks. Compiler > -inserts function calls (__asan_load*(addr), __asan_store*(addr)) before each > -memory access of size 1, 2, 4, 8 or 16. These functions check whether memory > -access is valid or not by checking corresponding shadow memory. > +inserts function calls (``__asan_load*(addr)``, ``__asan_store*(addr)``) before > +each memory access of size 1, 2, 4, 8, or 16. These functions check whether > +memory accesses are valid or not by checking corresponding shadow memory. > > -GCC 5.0 has possibility to perform inline instrumentation. Instead of making > -function calls GCC directly inserts the code to check the shadow memory. > -This option significantly enlarges kernel but it gives x1.1-x2 performance > -boost over outline instrumented kernel. > +With inline instrumentation, instead of making function calls, the compiler > +directly inserts the code to check shadow memory. This option significantly > +enlarges the kernel, but it gives an x1.1-x2 performance boost over the > +outline-instrumented kernel. > > -Generic KASAN is the only mode that delays the reuse of freed object via > +Generic KASAN is the only mode that delays the reuse of freed objects via > quarantine (see mm/kasan/quarantine.c for implementation). > > Software tag-based KASAN > -- > 2.31.0.rc2.261.g7f71774620-goog >