Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2000560ybb; Sun, 29 Mar 2020 19:34:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtBwz0Po7sMmqdlr4CUPk9k8cYBDKnQ0vRMizrZ5PPbZ+0CCYjjLujd+ItnFcQlPACMSGfd X-Received: by 2002:aca:d44d:: with SMTP id l74mr6379320oig.83.1585535693194; Sun, 29 Mar 2020 19:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585535693; cv=none; d=google.com; s=arc-20160816; b=ZW/yvsYlcBashp04KiqFAVH92i9UnRMAEj+XBIaYXK6bWV3Dh2EoGxFmZyUnldnh7M VMxrC9uPwMFpiUfes+H/psgtVdZXbwbIys0GAPNZFBluSLU/jq7OAJdnXQFhsGFDuSQ7 oWtoZPlUuIEKh8TDF2b2kxyR7JD+Y0il/0u3xDlskuiWxH4Ts+Q2amoBtAgG3u6dH41m TtudfAhImXYlQQy1SSF67IMZ3ULKOmbGrTQBrIP1i4z+iOTq1XIXBhymGhf9cYXux+gU glNynx1NP9uMJNKubntpTsFyu8PBoKQRGfzSGpA55TABcEs1bTdfb/70u/JnDg0VEThT brwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GUEUjnZByBMLXXgM/0YNDI/bxdwR+I0Cjr1aQHLknOs=; b=HJmGaoQOEOeDZ/4uxCIPMBe/qurSvJgIgHpzi8W8bSff1WBSIrm1q+jikytXLSckrw iYZYZWFlsjUqPYc5j0f9otuk+h5uto9y+BeHYZGE6eoNm70ZN0vQ4frDxPTeWdzFRvL8 Ds8HoONTUlBfF8HIc5CClKIW1zrlv1SHJoYl5bJit0yuRVaGINofIbAa0Fif8RLXeIsp nFU/AfrQXijDFDv8DEqJGDMpOrLYYVBuB3oTGPg89zhrff5V3/72L9aZoqJSqD3ua67v QtY/4MNQ6wWwz4Rk5XMRAwVXe36I2wtJGj8iwZguN3EhYH0fMOrf8WPKGOSc0tLCBqUF pJuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=QzIZMvvK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9si8210675ots.110.2020.03.29.19.34.41; Sun, 29 Mar 2020 19:34:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=QzIZMvvK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729287AbgC3CeD (ORCPT + 99 others); Sun, 29 Mar 2020 22:34:03 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:41059 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729197AbgC3Cdt (ORCPT ); Sun, 29 Mar 2020 22:33:49 -0400 Received: by mail-qt1-f195.google.com with SMTP id i3so13899365qtv.8 for ; Sun, 29 Mar 2020 19:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GUEUjnZByBMLXXgM/0YNDI/bxdwR+I0Cjr1aQHLknOs=; b=QzIZMvvKWmxMiOU35hOs8CLclttdCYXncAnCQ+hBWiQayLQhtd54ejH+VB98qoGytL jL4QHOy47RVa5FzCvrDWf8Y+mlYDsycomyOHalE85DcVFRzlvjF04cfiJQiaX6rxsrTb vvECi0mg+SEVN6NPXug5XDilRNcywkAzXeCnM= 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=GUEUjnZByBMLXXgM/0YNDI/bxdwR+I0Cjr1aQHLknOs=; b=EC21iTUXHlWNJk+tLijkXQ0ZSvIvitBaNeUg3j3V4RyecVh+mvpGFss5gtX34D5UlG lhPQMxBbBX/BWinftaANKv09+ZJuSCYh91Jt/T6/Vs5k7qWTfQjE8JAPyJpdb5A/1D9f VnZFCypwKiYbGVLqHf/SCP1tY5CC5Di79AOmJO9iekZ6hWkdp6/2URWLrUZjOgs1zzZ9 RQWnzaQrmAh/idvuJ6t5CKsNcfTYU0EkRyIJ+gMaUZvQlFo0nTrV9ERGAUu8QzkVO19u dd581N3Mhi+Kkfq4PPgccit7OL1Yw+35TOcjuX/XIdf0QLVpSTIvCAKBPumQtlKU1nxf FkwA== X-Gm-Message-State: ANhLgQ1m32JRPeYaZA+hDd5NtzBHhOqgf+sigOwdYB6ZZRWAoHwcuff5 HZsg/5FULDICSmCPnIfOalYMgj9SUDo= X-Received: by 2002:aed:3e8e:: with SMTP id n14mr10113639qtf.245.1585535626447; Sun, 29 Mar 2020 19:33:46 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id q15sm10030625qtj.83.2020.03.29.19.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Mar 2020 19:33:45 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Uladzislau Rezki (Sony)" , Joel Fernandes , Andrew Morton , Ingo Molnar , Josh Triplett , Lai Jiangshan , linux-mm@kvack.org, Mathieu Desnoyers , "Paul E. McKenney" , "Rafael J. Wysocki" , rcu@vger.kernel.org, Steven Rostedt Subject: [PATCH 15/18] rcu: Support headless variant in the kvfree_rcu() Date: Sun, 29 Mar 2020 22:32:45 -0400 Message-Id: <20200330023248.164994-16-joel@joelfernandes.org> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog In-Reply-To: <20200330023248.164994-1-joel@joelfernandes.org> References: <20200330023248.164994-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Uladzislau Rezki (Sony)" Make it possible to pass one or two arguments to the kvfree_rcu() macro what corresponds to either headless case or not, so it becomes a bit versatile. As a result we obtain two ways of using that macro, below are two examples: a) kvfree_rcu(ptr, rhf); struct X { struct rcu_head rhf; unsigned char data[100]; }; void *ptr = kvmalloc(sizeof(struct X), GFP_KERNEL); if (ptr) kvfree_rcu(ptr, rhf); b) kvfree_rcu(ptr); void *ptr = kvmalloc(some_bytes, GFP_KERNEL); if (ptr) kvfree_rcu(ptr); Last one, we name it headless variant, only needs one argument, means it does not require any rcu_head to be present within the type of ptr. There is a restriction the (b) context has to fall into might_sleep() annotation. To check that, please activate the CONFIG_DEBUG_ATOMIC_SLEEP option in your kernel. Reviewed-by: Joel Fernandes (Google) Signed-off-by: Uladzislau Rezki (Sony) Signed-off-by: Joel Fernandes (Google) --- include/linux/rcupdate.h | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index edb6eeba49f83..7d04bbeeeef14 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -872,12 +872,42 @@ do { \ /** * kvfree_rcu() - kvfree an object after a grace period. - * @ptr: pointer to kvfree - * @rhf: the name of the struct rcu_head within the type of @ptr. * - * Same as kfree_rcu(), just simple alias. + * 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. + * + * 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); + * + * where @ptr is a pointer to kvfree(). + * + * Please note, head-less way of freeing is permitted to + * use from a context that has to follow might_sleep() + * annotation. Otherwise, please switch and embed the + * rcu_head structure within the type of @ptr. */ -#define kvfree_rcu(ptr, rhf) kfree_rcu(ptr, rhf) +#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__, \ + kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__) + +#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME +#define kvfree_rcu_arg_2(ptr, rhf) kfree_rcu(ptr, rhf) +#define kvfree_rcu_arg_1(ptr) \ +do { \ + typeof(ptr) ___p = (ptr); \ + \ + if (___p) \ + kvfree_call_rcu(NULL, (rcu_callback_t) (___p)); \ +} while (0) /* * Place this after a lock-acquisition primitive to guarantee that -- 2.26.0.rc2.310.g2932bb562d-goog