From patchwork Mon May 25 21:47:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 11569471 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 DDAAE913 for ; Mon, 25 May 2020 21:48:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AB039207CB for ; Mon, 25 May 2020 21:48:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HmwS9Hf5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB039207CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 053ED80064; Mon, 25 May 2020 17:48:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F235280061; Mon, 25 May 2020 17:48:16 -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 D4D9080064; Mon, 25 May 2020 17:48:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id AFA7A80061 for ; Mon, 25 May 2020 17:48:16 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6725740D7 for ; Mon, 25 May 2020 21:48:16 +0000 (UTC) X-FDA: 76856580192.14.ring93_2b17d61d6f014 X-Spam-Summary: 2,0,0,6c7193b478193fa3,d41d8cd98f00b204,urezki@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:2907:3138:3139:3140:3141:3142:3354:3865:3866:3867:3870:3871:3872:4118:4321:4385:5007:6117:6119:6261:6653:7514:7576:7875:8660:9413:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13148:13149:13230:13894:14181:14394:14687:14721:21080:21444:21451:21627:21666:21740:21789:21939:21987:30003:30034:30054,0,RBL:209.85.208.193:@gmail.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:23,LUA_SUMMARY:none X-HE-Tag: ring93_2b17d61d6f014 X-Filterd-Recvd-Size: 7057 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Mon, 25 May 2020 21:48:15 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id q2so22118226ljm.10 for ; Mon, 25 May 2020 14:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s+GYAs311TuxCys/vNhpiV48XtphGpyqwqArPir1vEA=; b=HmwS9Hf5tRNKvWpc7rChtGmNKH52OEpaRZEDcq2huMBobbMyLS3W1ri6fqOH6hgQQm dG8FebHg4aifOm/2Bg1ujIP8FaUkppUxbOB2jSwctvALRBMUoibtEF+HaPmPZPfedZsm oOVCM1JwKFjxgUm/qo9NvVy0Wp18aqk63ujpfc9n8eVcRZT4l7Hg50gRWZ/SdD9MygYu Ysol6j+BrzySzgXdYFG0LsAI+D8so936BDFRNUcMfzlu/tKyy64WhJWvLbfnK66KIw1Q PHG0Zzki3cI/PupjxDSg7HRujzu71cGxzTjnE4mhSNOVjAnOIgZYytfQQzW56ODvkLKK Sq9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s+GYAs311TuxCys/vNhpiV48XtphGpyqwqArPir1vEA=; b=gj8uKA4/wS5noWF3/7gOa8ikzMHNMzJ8IWbUrtzq8x7n2RmNzNLVCBq85/e13POAlc usLp1oovGDMuw7h+5XOHWymG25YDINtu5FNXFSJuhk0CmdoLXTp/A1pr69ZQ+9GCr0og vazj5FT56vZaDWzVtKiMg/oz8vGdwUIGodc7YsM+6zMD2c+uXVilfmdcuLGdYw11vL6l s0C1a731Alq/JAHVO9i2vr0M091X9otGuuCeHBYIoYnfpIvgcfdIodycnD35k3PfP/Ut p+3G6VuGSPjK0/YK8qbHO7Utqb90NPdu24jLEyCFxsGZ56Q4QhlMe3uhBsEzaO5mXe2r lCRA== X-Gm-Message-State: AOAM532HcHsKImlfVJon7pbKyb2fj4VuSk3ns/Erm/crWjojd3c7mlUB vUm+92TQgx1F89B6Bfgr4bg= X-Google-Smtp-Source: ABdhPJw5QAHid24LqXhonjXjabD4R74L3No12FclTCqfTQczerEPg5Pgt8IKgCuBPeR0GAgrgoM5Ow== X-Received: by 2002:a2e:9081:: with SMTP id l1mr15678344ljg.81.1590443294766; Mon, 25 May 2020 14:48:14 -0700 (PDT) Received: from pc638.lan (h5ef52e31.seluork.dyn.perspektivbredband.net. [94.245.46.49]) by smtp.gmail.com with ESMTPSA id a6sm2280044lji.29.2020.05.25.14.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 14:48:14 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: LKML , linux-mm@kvack.org Cc: Andrew Morton , "Paul E . McKenney" , "Theodore Y . Ts'o" , Matthew Wilcox , Joel Fernandes , RCU , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH v2 04/16] rcu/tree: Make debug_objects logic independent of rcu_head Date: Mon, 25 May 2020 23:47:48 +0200 Message-Id: <20200525214800.93072-5-urezki@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525214800.93072-1-urezki@gmail.com> References: <20200525214800.93072-1-urezki@gmail.com> MIME-Version: 1.0 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: From: "Joel Fernandes (Google)" kfree_rcu()'s debug_objects logic uses the address of the object's embedded rcu_head to queue/unqueue. Instead of this, make use of the object's address itself as preparation for future headless kfree_rcu() support. Reviewed-by: Uladzislau Rezki Signed-off-by: Uladzislau Rezki (Sony) Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/tree.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index ae21e1bddd3e..776ccf858154 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2836,13 +2836,11 @@ EXPORT_SYMBOL_GPL(call_rcu); * @nr_records: Number of active pointers in the array * @records: Array of the kfree_rcu() pointers * @next: Next bulk object in the block chain - * @head_free_debug: For debug, when CONFIG_DEBUG_OBJECTS_RCU_HEAD is set */ struct kfree_rcu_bulk_data { unsigned long nr_records; void *records[KFREE_BULK_MAX_ENTR]; struct kfree_rcu_bulk_data *next; - struct rcu_head *head_free_debug; }; /** @@ -2892,11 +2890,13 @@ struct kfree_rcu_cpu { static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc); static __always_inline void -debug_rcu_head_unqueue_bulk(struct rcu_head *head) +debug_rcu_bhead_unqueue(struct kfree_rcu_bulk_data *bhead) { #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD - for (; head; head = head->next) - debug_rcu_head_unqueue(head); + int i; + + for (i = 0; i < bhead->nr_records; i++) + debug_rcu_head_unqueue((struct rcu_head *)(bhead->records[i])); #endif } @@ -2926,7 +2926,7 @@ static void kfree_rcu_work(struct work_struct *work) for (; bhead; bhead = bnext) { bnext = bhead->next; - debug_rcu_head_unqueue_bulk(bhead->head_free_debug); + debug_rcu_bhead_unqueue(bhead); rcu_lock_acquire(&rcu_callback_map); trace_rcu_invoke_kfree_bulk_callback(rcu_state.name, @@ -2948,14 +2948,15 @@ static void kfree_rcu_work(struct work_struct *work) */ for (; head; head = next) { unsigned long offset = (unsigned long)head->func; + void *ptr = (void *)head - offset; next = head->next; - debug_rcu_head_unqueue(head); + debug_rcu_head_unqueue((struct rcu_head *)ptr); rcu_lock_acquire(&rcu_callback_map); trace_rcu_invoke_kfree_callback(rcu_state.name, head, offset); if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset))) - kfree((void *)head - offset); + kfree(ptr); rcu_lock_release(&rcu_callback_map); cond_resched_tasks_rcu_qs(); @@ -3094,18 +3095,11 @@ kfree_call_rcu_add_ptr_to_bulk(struct kfree_rcu_cpu *krcp, /* Initialize the new block. */ bnode->nr_records = 0; bnode->next = krcp->bhead; - bnode->head_free_debug = NULL; /* Attach it to the head. */ krcp->bhead = bnode; } -#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD - head->func = func; - head->next = krcp->bhead->head_free_debug; - krcp->bhead->head_free_debug = head; -#endif - /* Finally insert. */ krcp->bhead->records[krcp->bhead->nr_records++] = (void *) head - (unsigned long) func; @@ -3129,14 +3123,17 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func) { unsigned long flags; struct kfree_rcu_cpu *krcp; + void *ptr; local_irq_save(flags); // For safely calling this_cpu_ptr(). krcp = this_cpu_ptr(&krc); if (krcp->initialized) raw_spin_lock(&krcp->lock); + ptr = (void *)head - (unsigned long)func; + // Queue the object but don't yet schedule the batch. - if (debug_rcu_head_queue(head)) { + if (debug_rcu_head_queue(ptr)) { // Probable double kfree_rcu(), just leak. WARN_ONCE(1, "%s(): Double-freed call. rcu_head %p\n", __func__, head);