From patchwork Wed Mar 15 18:18:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 70352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp50837wrt; Wed, 15 Mar 2023 11:24:52 -0700 (PDT) X-Google-Smtp-Source: AK7set9SBgSdCbbpU0XeBLHrBynO37CtwYDAeCH65ym7HxyFF98oKXWgHmCR0A1x48k/zYj99w6y X-Received: by 2002:a05:6a20:4918:b0:d4:53ff:2ef5 with SMTP id ft24-20020a056a20491800b000d453ff2ef5mr704548pzb.26.1678904692655; Wed, 15 Mar 2023 11:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678904692; cv=none; d=google.com; s=arc-20160816; b=S9fxUW2kvyHnk+dZiLfk5mFgrC8nY2vYXK5m7O+UVf5nco2c2jM/X9nxCw130/2yxA S4raolY4SsbC2Jp5Qp2Vnmr3czQZQM33d0qdFv4/TV8W9n4Jyzv8bSFmFZZp9yG1CMd0 RQkZlE96efWGQ2bEWXzqQzuDRZ9BimuFu/ndw3BWpOlkyHvs0xF/SY5k3L1QKAtwb45z l5nyJ4Rt06hyLu7djs8KpDDiLaW8l018c/gSFAwxrtrYw+DLj8xARdg76Ghl6P5zVdNH 1zt1wrDdKvA7C3LwoDvm7dY1OYYN6Kr3646M0RXAkphVB84OdwxQpmlQ4m1iDNuB/wV9 4oKg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6C875UW3frLz1lRISgaVupsCOUcY7ixEg8V710uhHfA=; b=vZreffYNCiXz2uH7BFxDqWqwvU/GWd0FycmoNWivPU0anKhPM9EhTrX/y3CAAWuYuf UZ/ADini9JbDpSdnqk0fifKSke8JE9flbZC3tSMg3ghugaqGrHNva79c4vqTGvRrwc3f IRoS6DZ7JUpw03r+AkXdZKbdo0uMwC4pd0ox0AabO3JuvQVPo8SinVYQQnzzgm7i/uqE E13+IhMCZLjL2pPS1VzfE9Kbl+G4nVvCZltMADYF3mN4DLOFWFM/mp4/cBxC8wMPrrb4 nCf9NTHQhgs1NIa+CTB8p1G10r4urKMB56sB3rX/gCLQiKwsHJVPHD6TZQhMVkaMZI7x rmiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=DPSkv5Uu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r28-20020a63515c000000b0050bc150235dsi5689945pgl.104.2023.03.15.11.24.39; Wed, 15 Mar 2023 11:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=DPSkv5Uu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbjCOSUX (ORCPT + 99 others); Wed, 15 Mar 2023 14:20:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbjCOSTw (ORCPT ); Wed, 15 Mar 2023 14:19:52 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CC47E79F for ; Wed, 15 Mar 2023 11:19:37 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id c19so17158849qtn.13 for ; Wed, 15 Mar 2023 11:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1678904376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6C875UW3frLz1lRISgaVupsCOUcY7ixEg8V710uhHfA=; b=DPSkv5UuukMQB08VeLhWDOZpTsKRs7XRm8Z7PYEO2J1A3Fp78UTsApYrFQwlOxMViU KlIZY+sUHHk4B22w99eFw5THO2D8yPtupryB73gk56KlbQQEhhQukLDCu+ytVgTy+DM+ V819OE0WU+vOdwSGrLQboPd96Y//tbADX9h2Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678904376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6C875UW3frLz1lRISgaVupsCOUcY7ixEg8V710uhHfA=; b=OIpQR+92zV2nGpuGOYG75tThZo6I4jsLZ7PbHnlKWtiMx3W2KKhrfVgGct2B6cfFts Aam1pgBfPMe/ChWgxMPmS3e+oA4fSu6sG58L4HWtLoYDgZMsYGgQiCsDquDHyLmM+3gt YqdyO8ToeQNPiz2sAmlK9ywyXTQpN9UCT2lAnvvEOKyfHVlQpULz8CEZA0USy/EXMIpC 5mJd37JlWrTWR3GfDf8QVwqxb/AzDkXepYJ7ZtOUze8s6LUecq3dyS0V184ZGwCuRPUw 7c/9xnnsQrrEr+jLiyNRcbq+Re09m057Xt/k27vWKXJzB+a6EB3fRseBxLhQ5i92Jo7w NpmA== X-Gm-Message-State: AO0yUKXpINRJ4KpwdAdSOS0cA+nOjfuRMjPM0keG313Jf8QgnCfqlqBH 24pP2D11bvX+Zg7jM9n2tfjK4w== X-Received: by 2002:a05:622a:14c8:b0:3d4:6185:72eb with SMTP id u8-20020a05622a14c800b003d4618572ebmr1282272qtx.34.1678904376337; Wed, 15 Mar 2023 11:19:36 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id v125-20020a379383000000b007458ae32290sm4113974qkd.128.2023.03.15.11.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 11:19:36 -0700 (PDT) From: "Joel Fernandes (Google)" To: "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes Cc: "Uladzislau Rezki (Sony)" , rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/14] rcu/kvfree: Eliminate k[v]free_rcu() single argument macro Date: Wed, 15 Mar 2023 18:18:58 +0000 Message-Id: <20230315181902.4177819-11-joel@joelfernandes.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315181902.4177819-1-joel@joelfernandes.org> References: <20230315181902.4177819-1-joel@joelfernandes.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760459166827008189?= X-GMAIL-MSGID: =?utf-8?q?1760459166827008189?= From: "Uladzislau Rezki (Sony)" The kvfree_rcu() and kfree_rcu() APIs are hazardous in that if you forget the second argument, it works, but might sleep. This sleeping can be a correctness bug from atomic contexts, and even in non-atomic contexts it might introduce unacceptable latencies. This commit therefore removes the single-argument kvfree_rcu() and kfree_rcu() macros. Code that would have previously used these single-argument kvfree_rcu() and kfree_rcu() macros should instead use kvfree_rcu_mightsleep() or kfree_rcu_mightsleep(). [ paulmck: Apply Joel Fernandes feedback. ] Signed-off-by: Uladzislau Rezki (Sony) Signed-off-by: Paul E. McKenney Signed-off-by: Joel Fernandes (Google) --- include/linux/rcupdate.h | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 094321c17e48..7571dbfecb18 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -957,9 +957,8 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) /** * kfree_rcu() - kfree an object after a grace period. - * @ptr: pointer to kfree for both single- and double-argument invocations. - * @rhf: the name of the struct rcu_head within the type of @ptr, - * but only for double-argument invocations. + * @ptr: pointer to kfree for double-argument invocations. + * @rhf: the name of the struct rcu_head within the type of @ptr. * * Many rcu callbacks functions just call kfree() on the base structure. * These functions are trivial, but their size adds up, and furthermore @@ -982,26 +981,18 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) * The BUILD_BUG_ON check must not involve any function calls, hence the * checks are done in macros here. */ -#define kfree_rcu(ptr, rhf...) kvfree_rcu(ptr, ## rhf) +#define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf) +#define kvfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf) /** - * kvfree_rcu() - kvfree an object after a grace period. - * - * This macro consists of one or two arguments and it is - * based on whether an object is head-less or not. If it - * has a head then a semantic stays the same as it used - * to be before: - * - * kvfree_rcu(ptr, rhf); - * - * where @ptr is a pointer to kvfree(), @rhf is the name - * of the rcu_head structure within the type of @ptr. + * kfree_rcu_mightsleep() - kfree an object after a grace period. + * @ptr: pointer to kfree for single-argument invocations. * * When it comes to head-less variant, only one argument * is passed and that is just a pointer which has to be * freed after a grace period. Therefore the semantic is * - * kvfree_rcu(ptr); + * kfree_rcu_mightsleep(ptr); * * where @ptr is the pointer to be freed by kvfree(). * @@ -1010,13 +1001,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) * annotation. Otherwise, please switch and embed the * rcu_head structure within the type of @ptr. */ -#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__, \ - kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__) - +#define kfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr) #define kvfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr) -#define kfree_rcu_mightsleep(ptr) kvfree_rcu_mightsleep(ptr) -#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME #define kvfree_rcu_arg_2(ptr, rhf) \ do { \ typeof (ptr) ___p = (ptr); \