Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp589014rdb; Sat, 30 Sep 2023 18:19:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJHhrQFGe+nxugBggJ6sc0Jjq8PimLfhHH5wTWLm2MRovvqwtkypRgt3EFAfcHbYSak1Ts X-Received: by 2002:a05:620a:b16:b0:76d:4252:95d2 with SMTP id t22-20020a05620a0b1600b0076d425295d2mr7912453qkg.39.1696123152317; Sat, 30 Sep 2023 18:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696123152; cv=none; d=google.com; s=arc-20160816; b=Y5/Z5cy9vWFuVA4b7gGwtwxHx6JMGAEzvm2lu/HYhTxoirAU13Y5VIHlwvMf+eMxKv myIAnazGigA4xUwK6q09vRO8rC8OieGEfnr8027PoIgZGrTuqT6L3vQSwm9+FuhIjSZk kDxrMauVJQMJDp812xgFGo4P3Ixv6yvjOBIREW68x1E2v2FVx6FVIKt1Nu1ylrx9pp24 RpB6S3uDAB71fKL3en+EwwrD+Fv0stPQnNiAYPw3FW/+Ig0FsEGZChXW7ix0JT3tEPNf eTUu3EZXuXCt6Vq9UQjRGXQdR8L1pND1OSMbANY9kLUiinwKT2fzpKe0UVZW8/orbVcl TCCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RKqIHaosAw2qI5kHOFkLuyhg0rOLeHVcoTzGWdYEVOE=; fh=8gypT53hCfZEGpQfkGyp1Xoo3mJP/vrenKjMNOQxdWg=; b=dAA+Knr7TCq1yhottqHlPOH8nZt6DrjhY+qLkqlDgaQykSIFM8F7bGpdrO6bDcWRT9 jq/L9AjdT0dtrPP2RPGpNnWM6a1UpXl72UGjscWdaSoyR6vn7JSTnfJDDr7W1RdURpH3 aoULqycWra50GCDdhjb+Q2473JHDAYjsMm40zeEuSxc0kJ039FZt/THj84LGRw1P+ELX sNCi0KPAdsvUas9o7t2kL7CZhOypbg3IfZKanBhZJpblaRuCgLlBm17ntPusO5L3vw2g EA/hEZn3j5p+AsFvqJvkiJmZO1i0uQyGZcilyGwJWBLOp0TieNP5d85MaMbqT2sIRxHA UYvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=AaMGLYeZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m9-20020a654389000000b0056569ee3ae6si23886568pgp.798.2023.09.30.18.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 18:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=AaMGLYeZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id CA7F681945B1; Sat, 30 Sep 2023 10:47:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234666AbjI3RrG (ORCPT + 99 others); Sat, 30 Sep 2023 13:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234568AbjI3RrF (ORCPT ); Sat, 30 Sep 2023 13:47:05 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13AB9E3 for ; Sat, 30 Sep 2023 10:47:02 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3512efed950so41403445ab.2 for ; Sat, 30 Sep 2023 10:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1696096021; x=1696700821; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RKqIHaosAw2qI5kHOFkLuyhg0rOLeHVcoTzGWdYEVOE=; b=AaMGLYeZ4BQ3JOTkvw/ULAeII5LK/E6KUWNx+ItK+R1bsTFDY3EYH3Ub9iihRjDWiG OA0Up0Z6YKIQL1At+HLSdaNqSPqAoMsW0YcnxuNC6kUWxbISLvTueNkRnDGQBrfIlKaz TodGmRZ3RVuEHgJLJ9PrifU5D9+TJA9Yf4w+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696096021; x=1696700821; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RKqIHaosAw2qI5kHOFkLuyhg0rOLeHVcoTzGWdYEVOE=; b=O8IqDCTZCqc7yyFgwP5Bv3vgmlw7BbAA9dQcgxaMDrLaHfxgC2udfSEZSETVdNAGZW BxbI1VLJPf9HF11TXIwsmQNjLXI6c/nk5ko902tGVOR5UL25nx1ThLWinshDgA0fmC9k QJx6SnkjWI3CS1nLDMc+0z0RIoSNw6RhqJwDbuT9qbMga9mHDuZ+3aWYb/eKhvgDXZeE asYYEElEJ9mKFdEFyS8uXmYxsipoRklu1PnDkOOTFcH8qrx8DttlhjJxLfQiyblrVPOC hQwbxRgL6FpapbRQ3wPMx6AimPqGVJXo+bQ8rgV/nGp1lzevUk+nd3/WQRyycSKRr+yC +gMA== X-Gm-Message-State: AOJu0YxEoqbfj8SRPSy3xDOTNkG16XRu7PuI/cewjh30QwYtUlsRfWok pjAH0MdQzaDlZpF2AdOTCc/ooGaIeQ/8Ri4Pn7k= X-Received: by 2002:a05:6e02:1c46:b0:34f:d665:4c2e with SMTP id d6-20020a056e021c4600b0034fd6654c2emr9306390ilg.30.1696096020883; Sat, 30 Sep 2023 10:47:00 -0700 (PDT) Received: from joelboxx5.c.googlers.com.com (161.74.123.34.bc.googleusercontent.com. [34.123.74.161]) by smtp.gmail.com with ESMTPSA id f4-20020a02a804000000b00418a5e0e93esm5884180jaj.162.2023.09.30.10.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:47:00 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang Cc: Catalin Marinas , Christoph Paasch , stable@vger.kernel.org, rcu@vger.kernel.org Subject: [PATCH] rcu: kmemleak: Ignore kmemleak false positives when RCU-freeing objects Date: Sat, 30 Sep 2023 17:46:56 +0000 Message-ID: <20230930174657.800551-1-joel@joelfernandes.org> X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 30 Sep 2023 10:47:14 -0700 (PDT) From: Catalin Marinas Since the actual slab freeing is deferred when calling kvfree_rcu(), so is the kmemleak_free() callback informing kmemleak of the object deletion. From the perspective of the kvfree_rcu() caller, the object is freed and it may remove any references to it. Since kmemleak does not scan RCU internal data storing the pointer, it will report such objects as leaks during the grace period. Tell kmemleak to ignore such objects on the kvfree_call_rcu() path. Note that the tiny RCU implementation does not have such issue since the objects can be tracked from the rcu_ctrlblk structure. Signed-off-by: Catalin Marinas Reported-by: Christoph Paasch Closes: https://lore.kernel.org/all/F903A825-F05F-4B77-A2B5-7356282FBA2C@apple.com/ Cc: Tested-by: Christoph Paasch Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/tree.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..24423877962c 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -3388,6 +3389,14 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr) success = true; } + /* + * The kvfree_rcu() caller considers the pointer freed at this point + * and likely removes any references to it. Since the actual slab + * freeing (and kmemleak_free()) is deferred, tell kmemleak to ignore + * this object (no scanning or false positives reporting). + */ + kmemleak_ignore(ptr); + // Set timer to drain after KFREE_DRAIN_JIFFIES. if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING) schedule_delayed_monitor_work(krcp); -- 2.42.0.582.g8ccd20d70d-goog