From patchwork Wed Oct 30 14:22:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11219613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47DE6112B for ; Wed, 30 Oct 2019 14:22:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F1CA620656 for ; Wed, 30 Oct 2019 14:22:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="USt262gJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1CA620656 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7DB556B000D; Wed, 30 Oct 2019 10:22:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 78EC76B000E; Wed, 30 Oct 2019 10:22:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62F506B0010; Wed, 30 Oct 2019 10:22:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id 3A4896B000D for ; Wed, 30 Oct 2019 10:22:57 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id DAF68180AD822 for ; Wed, 30 Oct 2019 14:22:56 +0000 (UTC) X-FDA: 76100667552.16.fight50_36c498c16c83a X-Spam-Summary: 2,0,0,77fd3856d548b5b1,d41d8cd98f00b204,3vpy5xqykcne38501e3bb381.zb985ahk-997ixz7.be3@flex--glider.bounces.google.com,:vegard.nossum@oracle.com:dvyukov@google.com::viro@zeniv.linux.org.uk:akpm@linux-foundation.org:aryabinin@virtuozzo.com:luto@kernel.org:ard.biesheuvel@linaro.org:arnd@arndb.de:hch@lst.de:dmitry.torokhov@gmail.com:edumazet@google.com:ericvh@gmail.com:gregkh@linuxfoundation.org:harry.wentland@amd.com:herbert@gondor.apana.org.au:mingo@elte.hu:axboe@kernel.dk:martin.petersen@oracle.com:schwidefsky@de.ibm.com:mst@redhat.com:monstr@monstr.eu:pmladek@suse.com:sergey.senozhatsky@gmail.com:rostedt@goodmis.org:tiwai@suse.com:tytso@mit.edu:tglx@linutronix.de:wsa@the-dreams.de:gor@linux.ibm.com:iii@linux.ibm.com:mark.rutland@arm.com:willy@infradead.org:rdunlap@infradead.org:andreyknvl@google.com:elver@google.com:glider@google.com,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747 :1777:17 X-HE-Tag: fight50_36c498c16c83a X-Filterd-Recvd-Size: 6793 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Oct 2019 14:22:56 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id i8so934187wmd.5 for ; Wed, 30 Oct 2019 07:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=H2Tf4p5InaykhPw6XaGzFla8deeHdIWiA5FFmW92s6o=; b=USt262gJUs3sxkakNKIDk1sJCInJe7jM93ofq2HHPyZqQO8rqNAr0h1ZxFRpymmW1m 4hrf9HVmM0p4aNYjDDvOuSUPuF1qYVsfA2GWW1oTPZrKqzT5MRE/kJ8VlWwVf93N+6fB 9fTBuwjcH+AKdrjZ1bqJ/1kcs4++pSNA8sQMBjEvZ3P4lEm7U702t9yjDkfCL7rq7c/q QcN2Y8gkrOriukCJEMv28Zv91gAKhdZaCiHn6+H0nXSUdLa9lzzbxeCi6vk/zy00jluD RdjofBROq2RIuXIAXXa7kzp+ZaaI7u7+fUhBwYvrjBSTLZXFtrCpgplOTY7xaL7EOPka UvQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=H2Tf4p5InaykhPw6XaGzFla8deeHdIWiA5FFmW92s6o=; b=sauz+0cDPij2RLvTXmkNeZLGqBNxIFcNfhiMcJ3OYDDdSVaHVfjwkj0TA93dpkm8Xe VuPociNzYnrs4rZNlKgnOxK0g0d3B+dBmlEpnQUA/KkTaUVkKZ3HpwTHLaOohv6s6r4s 2PsyDjG/rlwJeBtgoZ7YMXlqTERT24E5i1cdj4qZDR3d1tnf/RnqDhGRA7w44TFermTP E2Dv+WfQXHzLfKTFoAWB8/2yn6Zer9a793Dz7NvSOW6HTS3/KQb7G2Hu8wD2BjeEtbLP J+AiUAvpuuqZIwJb1qJMFU9qbr6/e+8ZRaSDx4KwmvgohAgYrk4qIX2JdjV7th6mS2KH WegA== X-Gm-Message-State: APjAAAXUSJOlSEZ7znuXcpoBiJmynmrBFEjeHiJMZWGIzwW35xghymFN z8F2JYIHvnGz6gcruKG+3KlLI2H8av0= X-Google-Smtp-Source: APXvYqzi6OWpVZPnRxIo10s3uHlOFkOUGoOhcEV4MArIStTlyn9CbtijEN7m0qRPKCZ6rYGRNn4Xy5CcEA4= X-Received: by 2002:adf:e942:: with SMTP id m2mr155171wrn.26.1572445374905; Wed, 30 Oct 2019 07:22:54 -0700 (PDT) Date: Wed, 30 Oct 2019 15:22:16 +0100 In-Reply-To: <20191030142237.249532-1-glider@google.com> Message-Id: <20191030142237.249532-5-glider@google.com> Mime-Version: 1.0 References: <20191030142237.249532-1-glider@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH RFC v2 04/25] stackdepot: reserve 5 extra bits in depot_stack_handle_t From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org Cc: viro@zeniv.linux.org.uk, akpm@linux-foundation.org, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@lst.de, dmitry.torokhov@gmail.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, mingo@elte.hu, axboe@kernel.dk, martin.petersen@oracle.com, schwidefsky@de.ibm.com, mst@redhat.com, monstr@monstr.eu, pmladek@suse.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, wsa@the-dreams.de, gor@linux.ibm.com, iii@linux.ibm.com, mark.rutland@arm.com, willy@infradead.org, rdunlap@infradead.org, andreyknvl@google.com, elver@google.com, Alexander Potapenko 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: Some users (currently only KMSAN) may want to use spare bits in depot_stack_handle_t. Let them do so and provide get_dsh_extra_bits() and set_dsh_extra_bits() to access those bits. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: linux-mm@kvack.org --- Change-Id: I23580dbde85908eeda0bdd8f83a8c3882ab3e012 --- include/linux/stackdepot.h | 8 ++++++++ lib/stackdepot.c | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 24d49c732341..ac1b5a78d7f6 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -12,6 +12,11 @@ #define _LINUX_STACKDEPOT_H typedef u32 depot_stack_handle_t; +/* + * Number of bits in the handle that stack depot doesn't use. Users may store + * information in them. + */ +#define STACK_DEPOT_EXTRA_BITS 5 depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); @@ -20,5 +25,8 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries); unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); +depot_stack_handle_t set_dsh_extra_bits(depot_stack_handle_t handle, + unsigned int bits); +unsigned int get_dsh_extra_bits(depot_stack_handle_t handle); #endif diff --git a/lib/stackdepot.c b/lib/stackdepot.c index decb1e073b58..460efd3ef742 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -40,8 +40,10 @@ #define STACK_ALLOC_ALIGN 4 #define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \ STACK_ALLOC_ALIGN) + #define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ - STACK_ALLOC_NULL_PROTECTION_BITS - STACK_ALLOC_OFFSET_BITS) + STACK_ALLOC_NULL_PROTECTION_BITS - \ + STACK_ALLOC_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) #define STACK_ALLOC_SLABS_CAP 8192 #define STACK_ALLOC_MAX_SLABS \ (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \ @@ -54,6 +56,7 @@ union handle_parts { u32 slabindex : STACK_ALLOC_INDEX_BITS; u32 offset : STACK_ALLOC_OFFSET_BITS; u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; }; }; @@ -72,6 +75,24 @@ static int next_slab_inited; static size_t depot_offset; static DEFINE_SPINLOCK(depot_lock); +depot_stack_handle_t set_dsh_extra_bits(depot_stack_handle_t handle, + u32 bits) +{ + union handle_parts parts = { .handle = handle }; + + parts.extra = bits & ((1U << STACK_DEPOT_EXTRA_BITS) - 1); + return parts.handle; +} +EXPORT_SYMBOL_GPL(set_dsh_extra_bits); + +u32 get_dsh_extra_bits(depot_stack_handle_t handle) +{ + union handle_parts parts = { .handle = handle }; + + return parts.extra; +} +EXPORT_SYMBOL_GPL(get_dsh_extra_bits); + static bool init_stack_slab(void **prealloc) { if (!*prealloc) @@ -132,6 +153,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size, stack->handle.slabindex = depot_index; stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; stack->handle.valid = 1; + stack->handle.extra = 0; memcpy(stack->entries, entries, size * sizeof(unsigned long)); depot_offset += required_size;