From patchwork Thu Mar 16 01:41:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 6723 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp232142wrt; Wed, 15 Mar 2023 18:54:52 -0700 (PDT) X-Google-Smtp-Source: AK7set9AGYUgu8yg65Z3axMLb0EZtfOnZPAtkEPpLwrADGVRK1kv1daaGm06+ZJtbTx2Tx3sfMUk X-Received: by 2002:a17:902:ce92:b0:19a:a210:825 with SMTP id f18-20020a170902ce9200b0019aa2100825mr1929533plg.20.1678931692431; Wed, 15 Mar 2023 18:54:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678931692; cv=none; d=google.com; s=arc-20160816; b=ACsUd32fCET8KpQ16oZdVLTVywTnkQoYvk6qWTUvrRpLZGNgUeqZuur6IFHa7do04k fdxZFEi60ozaRMIDHjF5Cnl5tkUkeUOlvHaSfEfe5SQFHB4pmsnEqP9QAdBRlIKE9vRu VZYaTlqGCnR3b0BGnvJ2+P0NjRIEvaArbJZlqYUjKE3b8LcrlDsy8FgOM1I2tjpJRGhH bFdutsBHvVqCikf6+iJjWN1XZkFELQnKS9sa5uEeAGS0iTSoqcS8hvXAOWK1ajuzyqsR JnZ1cHlU4zQdF06vVQBAzl2zQ+hBQMmcFc2HrJriZzYulmtwzMMugt+tffbtsAu3ZLMN pLuA== 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 :message-id:date:subject:cc:to:from; bh=P55rgRz7v69PxyoCgb99Xdtulupv+YyUUL74psxzFss=; b=Jd4FO95GUI1kDZsmt4mBTlrKYF0KQI4H9fqdIvdQNWjicW8RE1HSMyg9sVeT9J9ctb /Dke6AL4+gNahpAYMnfOz/QNlkYWmUFaAzpiBbjqTHd452Js09vjV7/pJ4ccb8/A771t wplf1POdQ8nrzy74rnhy5m7WhYA2uHEAI21ld5BNdoYh6H/lvLqOJVQ5Ob1qWylNXXWc ppWYcDkkJg0E7euQUEEmDcNrGQU1fbm03MNF1WgQILx2XwlCRnJBWd3CAgkjtuCc1crQ 4ofEf84Inw0b88/26J09HI0Mc63Yv7+fkY6br8Tqyo+QXQMVO/SCmjjLBr2QLF7DQJI6 dZLw== 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 s6-20020a170902ea0600b0019e37273b47si6987899plg.558.2023.03.15.18.54.36; Wed, 15 Mar 2023 18:54: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; 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 S229734AbjCPBl2 (ORCPT + 99 others); Wed, 15 Mar 2023 21:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjCPBl0 (ORCPT ); Wed, 15 Mar 2023 21:41:26 -0400 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00659ABB1C; Wed, 15 Mar 2023 18:41:25 -0700 (PDT) Received: by mail-qt1-f173.google.com with SMTP id h19so292618qtn.1; Wed, 15 Mar 2023 18:41:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678930884; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=P55rgRz7v69PxyoCgb99Xdtulupv+YyUUL74psxzFss=; b=o8Xr1lUpwYr7kSO7EpdlIecPeiwNZGBPD2321U0mf5D4Zk2bPluVmA1d9LWEiKmr+p qO3ZnbG/dhEI3HX8N6KHn/w/NALeDBVuU0roD/AIXf4/r994IC7a0D578nw5SUdzETHn llnUAPkWVztkl087PhYC1HDgyt1d737o8TFeKAFkyW3okPo0hIor2U/YoHB7LnGqMxTO ol8D+VLH+QhgjC/9tBZYtGnUhBhaX27yYF3fISc+jU/UIESr6UntPqz/vrFqWT0JidPn ldLza/VhWacSQ+VFHsWqcuOQBvwDHyI+uBBVrMCCBeGgjmZNFlE7FbxqRtVjwiDZEe1Z GKAg== X-Gm-Message-State: AO0yUKVHLsNn7kjNsslyV1uxAdHsdK4izVBBgVdOgUkwlNAxuCZ3At3Y AtCdjdKq6BBwF3lkbvMbVVFOiBlnyY7/sJef X-Received: by 2002:ac8:7fc6:0:b0:3bf:bbaf:5c82 with SMTP id b6-20020ac87fc6000000b003bfbbaf5c82mr3700973qtk.21.1678930884435; Wed, 15 Mar 2023 18:41:24 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:5c58]) by smtp.gmail.com with ESMTPSA id w19-20020a05620a0e9300b00746279f3fd5sm573675qkm.9.2023.03.15.18.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 18:41:23 -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@meta.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 Subject: [PATCH bpf-next 0/5] Make struct bpf_cpumask RCU safe Date: Wed, 15 Mar 2023 20:41:17 -0500 Message-Id: <20230316014122.678082-1-void@manifault.com> X-Mailer: git-send-email 2.39.0 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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS 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?1760487478422961899?= X-GMAIL-MSGID: =?utf-8?q?1760487478422961899?= The struct bpf_cpumask type is currently not RCU safe. It uses the bpf_mem_cache_{alloc,free}() APIs to allocate and release cpumasks, and those allocations may be reused before an RCU grace period has elapsed. We want to be able to enable using this pattern in BPF programs: private(MASK) static struct bpf_cpumask __kptr *global; int BPF_PROG(prog, ...) { struct bpf_cpumask *cpumask; bpf_rcu_read_lock(); cpumask = global; if (!cpumask) { bpf_rcu_read_unlock(); return -1; } bpf_cpumask_setall(cpumask); ... bpf_rcu_read_unlock(); } In other words, to be able to pass a kptr to KF_RCU bpf_cpumask kfuncs without requiring the acquisition and release of refcounts using bpf_cpumask_kptr_get(). This patchset enables this by making the struct bpf_cpumask type RCU safe, and removing the bpf_cpumask_kptr_get() function. David Vernet (5): bpf: Free struct bpf_cpumask in call_rcu handler bpf: Mark struct bpf_cpumask as rcu protected bpf/selftests: Test using global cpumask kptr with RCU bpf: Remove bpf_cpumask_kptr_get() kfunc bpf,docs: Remove bpf_cpumask_kptr_get() from documentation Documentation/bpf/cpumasks.rst | 30 +++----- kernel/bpf/cpumask.c | 37 +++------- kernel/bpf/verifier.c | 1 + .../selftests/bpf/prog_tests/cpumask.c | 2 +- .../selftests/bpf/progs/cpumask_common.h | 7 +- .../selftests/bpf/progs/cpumask_failure.c | 68 +++++++++++++++---- .../selftests/bpf/progs/cpumask_success.c | 29 ++++---- 7 files changed, 95 insertions(+), 79 deletions(-)