Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1324437pxf; Fri, 12 Mar 2021 07:10:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHAcG7kQ8nTqbSELkfZA1anP7wYNNywYMxNz1w7r5BLhghc1cTaB4EoUAiN8+e59b5/9JF X-Received: by 2002:a17:906:d938:: with SMTP id rn24mr9491032ejb.87.1615561853215; Fri, 12 Mar 2021 07:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615561853; cv=none; d=google.com; s=arc-20160816; b=OoEUrQ1ISTmdGAWtP+pQ9zyCKXCZWY/QFJkK+BAtegxpRzxGldr5UrQdGMpp2Tc5zx KPFf97VRdW2tQGsQj1d4P0sHHuEv+6Q0lfAdFSUCAsK9Bkza3oz1dOGFyl6XmD6pPRad CHT7psLH09BB/5Zh6OVaP/rJfoT5mkyiT4kykpw4xYBlcH69lkzWJvYQM0GrZbmjIB2Z fSNfmsvKOj+8lyAlOWOCDp6V7v8EGsYo6AiwT4rVqLWOtocEKzQL/sG3Dyp4pQunShK9 lf3ENx51wRC27k/Z64At5MU1pjXJCEy8mazz2gQiUNjGPmR5jh6/al+DmzHec+/36Z6n 7kzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8MLa7BfE7dVLn4tTMKZ+HSLGOdEizmmjEqt3urdruHo=; b=DKjS/WsFyG02NWY2JvnAyWZnd1tQHnyHJtW+F+CdliEkXLqmetZxSLsr1o90LMDZyM bBFnrGMuQeYK4TlfnakO+NXpPYmnsRVOj3S+1oIHV8EHtZd4mycxvRVHslO7ECl8eC8Y JNgj6Amhp+KTvaX5gbpr/YXxwDarb0lEqDvorgJPRUJC8dwPXTnj4prEd8DC0wngDbY/ FJfeHFyK5i5sDBHVL27wVV76gNXsf1oidUrMFCrkqsiHDoFLjpLHCRu/+/7Uk1R0VTEc 09MWNJMZpyfuWGwXj3J1Ja/XTH51d2WMbdNIIBoKwCe453X7LGOvOVOWCLX5Cv4LlPCe xDZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YXc7cfUG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si4433622edd.471.2021.03.12.07.10.21; Fri, 12 Mar 2021 07:10:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YXc7cfUG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231745AbhCLPJZ (ORCPT + 99 others); Fri, 12 Mar 2021 10:09:25 -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-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 >