From patchwork Sat Jun 10 03:50:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 105887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1333936vqr; Fri, 9 Jun 2023 20:54:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ic7V5Uw7PA0m/TkLbEDeATW8zeEnJfbkyuCNtTAdm8wmSFrLqw6MVOn0TSKww7gO7B1Kc X-Received: by 2002:a17:902:e747:b0:1ae:626b:4771 with SMTP id p7-20020a170902e74700b001ae626b4771mr852126plf.36.1686369248434; Fri, 09 Jun 2023 20:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686369248; cv=none; d=google.com; s=arc-20160816; b=GD374c9HqGuqKsvSZ6uFwCVSsy3BU62DFUoSkORGSO8hjYHByMAFhmEVprnx0nMUqf aCeEYYioAOEDVxwVcCTQdkt+NdOLRBGp8dEVyrC4nk4XP3BlwPjxmHFyMpvVGH4ZphC4 ABP3ahJTNFJVD5G4qxjEKD77X4G3/i4u18/XWFJiIv8FCwIi4hFXj+J2IBfO/N36IxWk TloBlLtKE+WiG5vLBPJC1YSRhe+bnMFJ9M4lEz940t9/9Gr1slD2pjsmT3x70YlRxQf3 Ci4mDCyRoWC3iFxCI3aJdbdzUAi75Q+R7obHmFFqvpHP+sHZHGWprVamEVLf9Bq46jtu 0YFw== 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; bh=3+QjjC2Q6R+F5tehvijFrBV+74kCnxo9UVFUil+fcVI=; b=WyigZ9nbO++XKFYS/ClDwTGoOTWjgWV5rpMyJU0uDmg2y7AoMko1mZ71+KujrSLdi5 RSu24x7cQAq6JgN9hWYD82L6FGYA5l6UZp3Ldtqc6/4WMKRmTwBQtOYJVCmoySQQ4Zqb eUnTPGV2Phy0VAZ6caKHzntFKT/RUXYnluwJ4O8s0QG+PFUwhZwrOmwv9ogrcKm5givM zO8NxOwma9NDhh0tnAUx7lze6wosbK51YkcIL1Io9w3lvLrXN0pJQHpOTbKLtvza7Xro k3iVihk8T4ll9V6czDp0xqtGpufGjWgu6SRcGdUPSB3GDyzIty0PkBRRaSmSpcOhTTMI JFQQ== ARC-Authentication-Results: i=1; mx.google.com; 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 kv3-20020a17090328c300b001a9baadecc0si204295plb.160.2023.06.09.20.53.56; Fri, 09 Jun 2023 20:54:08 -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; 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 S233293AbjFJDvJ (ORCPT + 99 others); Fri, 9 Jun 2023 23:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232709AbjFJDvB (ORCPT ); Fri, 9 Jun 2023 23:51:01 -0400 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA7D35B6; Fri, 9 Jun 2023 20:51:00 -0700 (PDT) Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6260f03b76dso17869976d6.1; Fri, 09 Jun 2023 20:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686369059; x=1688961059; 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=3+QjjC2Q6R+F5tehvijFrBV+74kCnxo9UVFUil+fcVI=; b=Mq+DBsf+GXQa0lrFwRYRtzYUZQ9a2Mt5MM/4diyDzXM3BnxavAZzQ9az5obUjv5/Cw leKyOjU43ieRJ7sLes0jhpCS1cr/EP/+8aiCn78m2i8nEBW2kinvijS3bEFT6uFLF+Nh CSEWFcPwwlsRj8ftMywdRo6CoaslzL7g+07C7XLIOL1MUuTWF+p3x5PW787WdEX0MUnR FlJa39Oir7KrbNF6aidAB/i5N70OhE2A1cFfcugNKy6AFtEdP7awP4QmecL54GA9gf2y BLXvJAz9ySL/PdbwrLLOyO7NuoRZeVLAsIl30gQ0AZF76s6N6sXvErFg5/Qa3DA+xqYe XTzA== X-Gm-Message-State: AC+VfDyUhsZ0T0kxb5H+REGzoj4PIPsMAJO1+PqH9OuDTSYkINFcN7yC oVxyrrTSRkhrPnhPz6qSEO/XOSsYc0eurCQD X-Received: by 2002:a05:6214:b68:b0:623:9126:8d7b with SMTP id ey8-20020a0562140b6800b0062391268d7bmr5436418qvb.28.1686369059185; Fri, 09 Jun 2023 20:50:59 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:81d3]) by smtp.gmail.com with ESMTPSA id a18-20020a0ce392000000b005fe4a301350sm1599968qvl.48.2023.06.09.20.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 20:50:58 -0700 (PDT) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, tj@kernel.org Subject: [PATCH bpf-next 3/5] bpf: Replace bpf_cpumask_any* with bpf_cpumask_any_distribute* Date: Fri, 9 Jun 2023 22:50:51 -0500 Message-Id: <20230610035053.117605-3-void@manifault.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230610035053.117605-1-void@manifault.com> References: <20230610035053.117605-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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?1768286321158779686?= X-GMAIL-MSGID: =?utf-8?q?1768286321158779686?= We currently export the bpf_cpumask_any() and bpf_cpumask_any_and() kfuncs. Intuitively, one would expect these to choose any CPU in the cpumask, but what they actually do is alias to cpumask_first() and cpmkas_first_and(). This is useless given that we already export bpf_cpumask_first() and bpf_cpumask_first_and(), so this patch replaces them with kfuncs that call cpumask_any_distribute() and cpumask_any_and_distribute(), which actually choose any CPU from the cpumask (or the AND of two cpumasks for the latter). Signed-off-by: David Vernet Acked-by: Yonghong Song --- kernel/bpf/cpumask.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c index 9416c8ac8a04..938a60ff4295 100644 --- a/kernel/bpf/cpumask.c +++ b/kernel/bpf/cpumask.c @@ -382,7 +382,7 @@ __bpf_kfunc void bpf_cpumask_copy(struct bpf_cpumask *dst, const struct cpumask } /** - * bpf_cpumask_any() - Return a random set CPU from a cpumask. + * bpf_cpumask_any_distribute() - Return a random set CPU from a cpumask. * @cpumask: The cpumask being queried. * * Return: @@ -391,26 +391,28 @@ __bpf_kfunc void bpf_cpumask_copy(struct bpf_cpumask *dst, const struct cpumask * * A struct bpf_cpumask pointer may be safely passed to @src. */ -__bpf_kfunc u32 bpf_cpumask_any(const struct cpumask *cpumask) +__bpf_kfunc u32 bpf_cpumask_any_distribute(const struct cpumask *cpumask) { - return cpumask_any(cpumask); + return cpumask_any_distribute(cpumask); } /** - * bpf_cpumask_any_and() - Return a random set CPU from the AND of two - * cpumasks. + * bpf_cpumask_any_and_distribute() - Return a random set CPU from the AND of + * two cpumasks. * @src1: The first cpumask. * @src2: The second cpumask. * * Return: - * * A random set bit within [0, num_cpus) if at least one bit is set. + * * A random set bit within [0, num_cpus) from the AND of two cpumasks, if at + * least one bit is set. * * >= num_cpus if no bit is set. * * struct bpf_cpumask pointers may be safely passed to @src1 and @src2. */ -__bpf_kfunc u32 bpf_cpumask_any_and(const struct cpumask *src1, const struct cpumask *src2) +__bpf_kfunc u32 bpf_cpumask_any_and_distribute(const struct cpumask *src1, + const struct cpumask *src2) { - return cpumask_any_and(src1, src2); + return cpumask_any_and_distribute(src1, src2); } __diag_pop(); @@ -438,8 +440,8 @@ BTF_ID_FLAGS(func, bpf_cpumask_subset, KF_RCU) BTF_ID_FLAGS(func, bpf_cpumask_empty, KF_RCU) BTF_ID_FLAGS(func, bpf_cpumask_full, KF_RCU) BTF_ID_FLAGS(func, bpf_cpumask_copy, KF_RCU) -BTF_ID_FLAGS(func, bpf_cpumask_any, KF_RCU) -BTF_ID_FLAGS(func, bpf_cpumask_any_and, KF_RCU) +BTF_ID_FLAGS(func, bpf_cpumask_any_distribute, KF_RCU) +BTF_ID_FLAGS(func, bpf_cpumask_any_and_distribute, KF_RCU) BTF_SET8_END(cpumask_kfunc_btf_ids) static const struct btf_kfunc_id_set cpumask_kfunc_set = {