From patchwork Wed Mar 25 16:12:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11458221 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 4890F14B4 for ; Wed, 25 Mar 2020 16:13:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F2F9E20409 for ; Wed, 25 Mar 2020 16:13:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Me6PcdEU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2F9E20409 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 C60666B000C; Wed, 25 Mar 2020 12:13:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C36D06B000D; Wed, 25 Mar 2020 12:13:00 -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 B74B06B000E; Wed, 25 Mar 2020 12:13:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id A10506B000C for ; Wed, 25 Mar 2020 12:13:00 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8553F18241814 for ; Wed, 25 Mar 2020 16:13:00 +0000 (UTC) X-FDA: 76634378520.21.party96_7189d46c5e536 X-Spam-Summary: 2,0,0,7a31fb000c1b0c8c,d41d8cd98f00b204,3con7xgykcpcfkhcdqfnnfkd.bnlkhmtw-lljuzbj.nqf@flex--glider.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:2892:2901:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3874:4118:4321:4605:5007:6261:6653:6742:6743:7875:8603:9036:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12114:12291:12296:12297:12438:12555:12895:13846:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21990:30034:30054:30064:30075:30090,0,RBL:209.85.128.73:@flex--glider.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: party96_7189d46c5e536 X-Filterd-Recvd-Size: 7098 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 16:13:00 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id r19so1063338wmg.8 for ; Wed, 25 Mar 2020 09:12:59 -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=xQHjl+h42Qjm7r/pFlrFoKMtDZmmakvwcHtx/vx9iIE=; b=Me6PcdEUIxDZNXeS4SvnxsCuz4U4H5H1XWwIH0wCCfXOpIT3tsV7ieexj/UgtddpU9 bQgQkik9vUcimusB+8O6hkfEQEp1cVSPWJmTq1XcVlwtkWnXGOmIjp9o4d/Tg3GFVgAN VNMHvrh/o5PsIZHWblJVQFJpinzcMDRzPgwt3eBHENd1I2cMsDjIj4tQWDERksGidAn7 CH93EZEbAI79vhFBSPRZFT2za5gki2TZjCTqYJz2CPc9sb+uAvBJF+BRZn8r3wz8QLqc fpIfTef4SxipDYl+Gh3KEzNRe7DyA2t2QQhqKT/fO3yByHXn/sIuClO9SkTzX0jnlDL6 m7MQ== 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=xQHjl+h42Qjm7r/pFlrFoKMtDZmmakvwcHtx/vx9iIE=; b=Ytn10aGyM5Iy4W4HrMEygsXFi6nftMsc/p+zOzlPTbknCAA/hZtyOAyJ/SmGPdsKz6 rPQgm2eWOPBAMOY8hIMfzU2TPkmLZK+7YeVeBjN4BYg+IXeBjL4ZItlktZSP+8fNYXZi +5fN6JOvg9tmsLcUZ2cp3RQAWi/Ui57rmwNtNNWJAd1JoZIzrg7JzEi3sLCxZ+4LQLSM MQAeI/nxxEW+H09mzSGNOAUkL5DV02p+51fJOxFtgZ1XWhSNVQMEGaVkFHYiaPPEhDGm HvF5ht+eLf1sgtC6MIPJT0oDQUqnskpUYhp0JgZ0e2k6dYhKyF0iYUg3pysun/G8BhDx l3yw== X-Gm-Message-State: ANhLgQ0Ld4FRpPy1vxL0tg0MDURg2a8P30hBbTKOOUfIEswIIY8Ys+KF j0J3U3s0QkpO/pOAnFdV/rP5lXB5s40= X-Google-Smtp-Source: ADFU+vt7sSaSTOsbYTuESz8mIf07c3SC+oAyfR00EKbQ+nUGoF9WsKrXf/0FcpgJwv12fP+3hmdvWtP3re8= X-Received: by 2002:adf:e588:: with SMTP id l8mr4044294wrm.186.1585152778239; Wed, 25 Mar 2020 09:12:58 -0700 (PDT) Date: Wed, 25 Mar 2020 17:12:12 +0100 In-Reply-To: <20200325161249.55095-1-glider@google.com> Message-Id: <20200325161249.55095-2-glider@google.com> Mime-Version: 1.0 References: <20200325161249.55095-1-glider@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v5 01/38] stackdepot: reserve 5 extra bits in depot_stack_handle_t From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , Marco Elver , Andrey Konovalov , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, akpm@linux-foundation.org, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@infradead.org, hch@lst.de, darrick.wong@oracle.com, davem@davemloft.net, dmitry.torokhov@gmail.com, ebiggers@google.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, mingo@elte.hu, jasowang@redhat.com, axboe@kernel.dk, m.szyprowski@samsung.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.com, mhocko@suse.com, monstr@monstr.eu, pmladek@suse.com, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, gor@linux.ibm.com, wsa@the-dreams.de 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: Marco Elver Cc: Andrey Konovalov 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 24d49c732341a..ac1b5a78d7f65 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 2caffc64e4c82..195ce3dc7c37e 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) @@ -136,6 +157,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;