Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp702753rwi; Wed, 19 Oct 2022 01:38:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6In2x5aIIG0Z1WnXSAI8Z5TAPuOabsVr+tmXp7DVN/LtT7Xj4TkcoEiG0/tj+rFlNur8Cz X-Received: by 2002:a17:90a:b00a:b0:203:87a3:9e70 with SMTP id x10-20020a17090ab00a00b0020387a39e70mr8366512pjq.218.1666168688726; Wed, 19 Oct 2022 01:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168688; cv=none; d=google.com; s=arc-20160816; b=kINIi+V3ugxzk3chTCOCPup79SBDfDa4jFR6aInSMXYewwqUKWNb9TI37G4qjvS0u7 B2dzsJzyiJG3dkHXwAUZGJWRJMSlmWyL2/2+1hLfwqp4v0k6ZuNbUhmTSjYNuqe7VVQh 1OS+lIx7LAfNIzhxFtqqcn+D941gAonJsPIJL/D1LhiUQwdyAK5+qo7PHxb3dox8pt4T YLmTflZ0wAy7rn0O1amRF8l58Ya8Qm2vcbDVkhVKPYCH9j0+mCtt9pgcz2Wl7rAE8q2j OYvtrUd1kNnP2bWgIEhtJ9MafUjWbsl7HKZneFt9dXpV92Qt/cclDgfQPxT5yuND6TD/ PhWQ== 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:dkim-signature; bh=lE4h/gGDAk0yBt10s+3hx9RfdJ8m3r4PL0TleCCgZbQ=; b=oV3v+CNFnZA4PFuq0aAIjA2tJWNpF7MAvNWszVF+xDbjXy6XOyESSuMIdPa9hCDrHg 0cGR5RZo2LFj6Br/6CKCdKUVl16jB3De6sW4NQMrsUX7hT9JWyY1mxH47nFZV+a9Yg6l jLTrE0mXencswsmz9aSq8WIwfHsDdXzwxPzrqY7aKGta9Eu6vrmeIo+M/Iz5/B2Iy5Dq YmJnxvroMmtiFod4x3OV1jdF5qtVwYBMy7DCZ0PIw62CX/PyYOGV65tBVh6Ar60nGZIp /aQgjoXvFIyrfG4mefGZ0soiM+V2RhRY9Bic1NZWvDZb6T3nyuTy6+NetSFJZ/FB4szj 1Lxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=XtfXblTh; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a631e51000000b00422c003b4c9si17512381pgm.46.2022.10.19.01.37.50; Wed, 19 Oct 2022 01:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@suse.de header.s=susede2_rsa header.b=XtfXblTh; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbiJSIh0 (ORCPT + 99 others); Wed, 19 Oct 2022 04:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230070AbiJSIhY (ORCPT ); Wed, 19 Oct 2022 04:37:24 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9DA5AC4E; Wed, 19 Oct 2022 01:37:22 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9552D2036F; Wed, 19 Oct 2022 08:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666168640; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lE4h/gGDAk0yBt10s+3hx9RfdJ8m3r4PL0TleCCgZbQ=; b=XtfXblThih+H2z3lXpWveY5SYLNoqVOf1AWNmNq5EaoqAZoO6IwlMk+4jBXy7DT9i0vH4F mhaksZClG2j+TwYoS3FPm3nLcrbqV21Msx5JV6xgunkt2dDo+mJo1TP9R4oxXnBq576B7X UoR7Yy+I6Q8mo/krl7I5hrQH48MVBeA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666168640; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lE4h/gGDAk0yBt10s+3hx9RfdJ8m3r4PL0TleCCgZbQ=; b=yyavfjPgl7g9/9+NRoB0ar2h6C9zBUX9P4LhQwxE8ooKVWbJzugc7hkWGWM9dBYzp0xwfH jr58J9t/Dc6Z0TAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8514613345; Wed, 19 Oct 2022 08:37:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lJtYIEC3T2NFZQAAMHmgww (envelope-from ); Wed, 19 Oct 2022 08:37:20 +0000 From: Nicolai Stange To: Steffen Klassert , Daniel Jordan Cc: Herbert Xu , Martin Doucha , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH 1/5] padata: introduce internal padata_get/put_pd() helpers Date: Wed, 19 Oct 2022 10:37:04 +0200 Message-Id: <20221019083708.27138-2-nstange@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019083708.27138-1-nstange@suse.de> References: <20221019083708.27138-1-nstange@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-crypto@vger.kernel.org The next commit in this series will add yet another code site decrementing a struct parallel_data's refcount and invoking dealloction as appropriate. With that, it's due to provide proper helper functions for managing parallel_datas' refcounts and to convert the existing open-coded refcount manipulation sites. Implement padata_put_pd() as well as a padata_put_pd_many() for batched releases as needed in padata_serial_worker(). For symmetry reasons, also provide a padata_put_get(), even though its implementation is fairly trivial. Convert the exisiting open-coded parallel_data ->refcnt manipulation code sites to these new helpers. Signed-off-by: Nicolai Stange --- kernel/padata.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/kernel/padata.c b/kernel/padata.c index e5819bb8bd1d..3bd1e23f089b 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -45,6 +45,10 @@ struct padata_mt_job_state { }; static void padata_free_pd(struct parallel_data *pd); +static inline void padata_get_pd(struct parallel_data *pd); +static void padata_put_pd_many(struct parallel_data *pd, int cnt); +static inline void padata_put_pd(struct parallel_data *pd); + static void __init padata_mt_helper(struct work_struct *work); static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index) @@ -198,7 +202,7 @@ int padata_do_parallel(struct padata_shell *ps, if ((pinst->flags & PADATA_RESET)) goto out; - refcount_inc(&pd->refcnt); + padata_get_pd(pd); padata->pd = pd; padata->cb_cpu = *cb_cpu; @@ -370,8 +374,7 @@ static void padata_serial_worker(struct work_struct *serial_work) } local_bh_enable(); - if (refcount_sub_and_test(cnt, &pd->refcnt)) - padata_free_pd(pd); + padata_put_pd_many(pd, cnt); } /** @@ -608,6 +611,22 @@ static void padata_free_pd(struct parallel_data *pd) kfree(pd); } +static inline void padata_get_pd(struct parallel_data *pd) +{ + refcount_inc(&pd->refcnt); +} + +static void padata_put_pd_many(struct parallel_data *pd, int cnt) +{ + if (refcount_sub_and_test(cnt, &pd->refcnt)) + padata_free_pd(pd); +} + +static inline void padata_put_pd(struct parallel_data *pd) +{ + padata_put_pd_many(pd, 1); +} + static void __padata_start(struct padata_instance *pinst) { pinst->flags |= PADATA_INIT; @@ -654,8 +673,7 @@ static int padata_replace(struct padata_instance *pinst) synchronize_rcu(); list_for_each_entry_continue_reverse(ps, &pinst->pslist, list) - if (refcount_dec_and_test(&ps->opd->refcnt)) - padata_free_pd(ps->opd); + padata_put_pd(ps->opd); pinst->flags &= ~PADATA_RESET; -- 2.37.3