From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EB21C83000 for ; Tue, 28 Apr 2020 21:00:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E07C62072A for ; Tue, 28 Apr 2020 21:00:21 +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="uT3JK0wk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E07C62072A 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 877528E001C; Tue, 28 Apr 2020 17:00:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8279A8E0007; Tue, 28 Apr 2020 17:00:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73E6F8E001C; Tue, 28 Apr 2020 17:00:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 599BB8E0007 for ; Tue, 28 Apr 2020 17:00:02 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 16D224DA8 for ; Tue, 28 Apr 2020 21:00:02 +0000 (UTC) X-FDA: 76758481044.01.force50_578d1e54c820b X-HE-Tag: force50_578d1e54c820b X-Filterd-Recvd-Size: 6154 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Apr 2020 21:00:01 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id h4so189218ljg.12 for ; Tue, 28 Apr 2020 14:00:01 -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=7dg4vvvuMGvUTLvHmWPN1Rrhqpd5aScShP8yFUvMy+A=; b=uT3JK0wksSzmJdp1AC64KvjdyD8rxvkukt3pYhWUvkn+XTCa1XhRcC+h0weAIylNWW 5f0SOqHWyVHCSEHwX0q9HOjNPsnQn42cRtWxBuBvHzaC4KYuVFI22rxKRLywnxBir/XK 7mo2M71F/Fmv3ZXo9S/zpiGNWQNvBtZzOpNyeJdWgvfgG3JM1QS8l895wLB4DQihVrdx 5EPpzOGrTUGGfDLSf5MINED8eLwhxcNiA2XALr0K0t/iQOUh4koXDkHGBZ1ILsTEC2DJ g+LhG8On/9yrFZsL4Prg7zlIOUN0NJPUPcjH+ZC/4g0/Cj4+e11UHQqtKK4OgncU4gKV gHsA== 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=7dg4vvvuMGvUTLvHmWPN1Rrhqpd5aScShP8yFUvMy+A=; b=j/YtX43hp3RU5nq5w6C6XMwtBc+sdZ4dar15rTczyan1WOX2aStGDEPY1cURc2yQxt skp9kiIZAMMXNuBIszSYEJ6yx1lZSWHjEUbH4I8l/B9Txu3mUPL3xqge341ouFU9q1ZD JTEs1hh8LD+Kcmp2sScVGc1ZPOYz7yMnBtURrTNilIFPxoZqTYstCGWics+eA3Sxrt2t HKqnU/NUiRuBAylkTFaLkppD2ZiVOYj6Df/rkiFDjZ1tB+Pu70Yxv9nsRYGMPS+O/rt2 TG3RCdOH6t/rmejsL+pm6knNvvOcusRSYjtw9wmRCqN0jodSmdNlELM07ySTsQ3z9hVq Lnog== X-Gm-Message-State: AGi0Pua5Bc3Iw7LRn3J3QPwjtwCmNxdMzHtJQrMdL5fgF/DqYi9CP5zU zHXxv+kNLBJYm+/ZoQzgpKI= X-Google-Smtp-Source: APiQypJ74RE+BeVO/a4be2iqMHLz/Sbx0gEUw9T9zhqkEcIjYEMEfzVvNufri7CsMeJjoPs58csz2Q== X-Received: by 2002:a19:644f:: with SMTP id b15mr274982lfj.28.1588107600253; Tue, 28 Apr 2020 14:00:00 -0700 (PDT) Received: from pc638.lan (h5ef52e31.seluork.dyn.perspektivbredband.net. [94.245.46.49]) by smtp.gmail.com with ESMTPSA id z21sm295483ljh.42.2020.04.28.13.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 13:59:59 -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 23/24] rcu: Introduce 1 arg kvfree_rcu() interface Date: Tue, 28 Apr 2020 22:59:02 +0200 Message-Id: <20200428205903.61704-24-urezki@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428205903.61704-1-urezki@gmail.com> References: <20200428205903.61704-1-urezki@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 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 =3D kvmalloc(sizeof(struct X), GFP_KERNEL); if (ptr) kvfree_rcu(ptr, rhf); b) kvfree_rcu(ptr); void *ptr =3D 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) --- 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 51b26ab02878..d15d46db61f7 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -877,12 +877,42 @@ do { \ =20 /** * 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 =3D (ptr); \ + \ + if (___p) \ + kvfree_call_rcu(NULL, (rcu_callback_t) (___p)); \ +} while (0) =20 /* * Place this after a lock-acquisition primitive to guarantee that --=20 2.20.1