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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B395DC433EF for ; Fri, 25 Mar 2022 13:16:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351208AbiCYNRe (ORCPT ); Fri, 25 Mar 2022 09:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346490AbiCYNR3 (ORCPT ); Fri, 25 Mar 2022 09:17:29 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C0E3BD2FA for ; Fri, 25 Mar 2022 06:15:51 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id t11so13994366ybi.6 for ; Fri, 25 Mar 2022 06:15:51 -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; bh=UVtmrpcYjsoxSNLprgvqR2q01AjSQZrSDBr9I2ujCrQ=; b=QunYh1X/vTWnm4E2/+QnA1pxI/i0Uo9LkqQfRz546sb9EOHXd8Vt+ShyU5kgd8ShBt peD0c61RkIzaxF0G9jkb/arKNspB0OeVJLspXCh/mJFP/m5gcxMksfvptI8eN7Jf4C4R 1TQqwv9UubymjB2lHqOrLGPPBPluo2Ey1TYWiXGKeayHXMgiLpaxS7w2nY9AnyhGLRKi Gql3YU231CDmpycokTqC7ylPkkLOBeZz9uBhRfndabW/olS8mFGJzcH78T6CmCTAEo/5 9lNcyGHWMvRMA69qw2qeBbMJ+zdBwV6V8e9Be99rMPwACAm6BLQYemx1tZNY6AN99z5+ h8xw== 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; bh=UVtmrpcYjsoxSNLprgvqR2q01AjSQZrSDBr9I2ujCrQ=; b=NReKJIp7ukJD4g2zjp0I9qPwWl1J3vtHpzVlbySK56zzV+a9pBPL3Ddyw+61ol3SBw gL9817qNzzlDJBeu1TyIP0bSRO/dL7oFXSIiT3P9dibDZFlkoSQL+QZ/nFNrtrQcgiRU MPtlksNa3E0o8VoywMVj11xI+iWYQN7Tk98ZJEPKMYBW/ehEm4kywggmXy2IOLTPhfzZ fSj5KHAihbsQBlh2mV6r237FPTH25uJM/C4Dz9sMWFAG5XtDjhmw/skNc6TCo5TZzXFG Tm2EsJl+LlrzgEneyGrkuKMhvBFWko8nWQB1ox0gmV35Wtqiu+FShH9kOzUqvNub+K37 ytQA== X-Gm-Message-State: AOAM532n0RdCMs87YZEdmczNWL9Lie4WAcvcyH/5Q+HkdO/HerEzWu6E AM9EoGb/JKQFSjTiGGvzhFLnY3vnS4uZlw38Z7WzkA== X-Google-Smtp-Source: ABdhPJw8jLmmkYMWCtGyb9SAEyWAmdLtUxmnI6j62OH72T/JezNOHDJSuka8BG+J+OQWwYh7kxgvHCtXaMopGrq5oY0= X-Received: by 2002:a25:3750:0:b0:634:6b89:ca9f with SMTP id e77-20020a253750000000b006346b89ca9fmr9903674yba.363.1648214150074; Fri, 25 Mar 2022 06:15:50 -0700 (PDT) MIME-Version: 1.0 References: <20211214162050.660953-1-glider@google.com> <20211214162050.660953-17-glider@google.com> <82de6739-a070-695b-bbc8-dfa931aa5e00@suse.cz> In-Reply-To: <82de6739-a070-695b-bbc8-dfa931aa5e00@suse.cz> From: Alexander Potapenko Date: Fri, 25 Mar 2022 14:15:13 +0100 Message-ID: Subject: Re: [PATCH 16/43] kmsan: mm: call KMSAN hooks from SLUB code To: Vlastimil Babka Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Ard Biesheuvel , 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 , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Linux Memory Management List , Linux-Arch , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > static inline void *get_freepointer(struct kmem_cache *s, void *object) > > { > > object = kasan_reset_tag(object); > > - return freelist_dereference(s, object + s->offset); > > + return kmsan_init(freelist_dereference(s, object + s->offset)); > > ... but I don't see why it applies to get_freepointer() too? What am I missing? Agreed, kmsan_init() is not needed here. > > } > > > > static void prefetch_freepointer(const struct kmem_cache *s, void *object) > > @@ -357,18 +361,28 @@ static void prefetch_freepointer(const struct kmem_cache *s, void *object) > > prefetchw(object + s->offset); > > } > > > > +/* > > + * When running under KMSAN, get_freepointer_safe() may return an uninitialized > > + * pointer value in the case the current thread loses the race for the next > > + * memory chunk in the freelist. In that case this_cpu_cmpxchg_double() in > > + * slab_alloc_node() will fail, so the uninitialized value won't be used, but > > + * KMSAN will still check all arguments of cmpxchg because of imperfect > > + * handling of inline assembly. > > + * To work around this problem, use kmsan_init() to force initialize the > > + * return value of get_freepointer_safe(). > > + */ > > static inline void *get_freepointer_safe(struct kmem_cache *s, void *object) > > { > > unsigned long freepointer_addr; > > void *p; > > > > if (!debug_pagealloc_enabled_static()) > > - return get_freepointer(s, object); > > + return kmsan_init(get_freepointer(s, object)); > > So here kmsan_init() is done twice? Yeah, removing it from get_freepointer() does not introduce new errors. I'll fix this in v2.