Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1431619rwb; Fri, 5 Aug 2022 01:35:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR67N3WoELE/m5nPTcrcn+Ah0sVNvyJGWbQazekuJIOhJeuluYFLqZFrOAf/bE+L1LpBVOV/ X-Received: by 2002:a17:902:ebcb:b0:168:e3ba:4b5a with SMTP id p11-20020a170902ebcb00b00168e3ba4b5amr5845539plg.11.1659688501045; Fri, 05 Aug 2022 01:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659688501; cv=none; d=google.com; s=arc-20160816; b=I7Vh8HYywLy+Q0zFT/XhGzjFBlMJr9ZQ3J4neo58et+eC43w+yzJWoGOSHWqbKPr50 Tp4ChECF4rIh/noiQfbzYTHiaDRipgnjkyHDOhWfgYf/EqS1DUAoxl5BGoZfLcD+5cUs bX2oQCTUEdUS7e2fT3IG+sYN4dVmP2ldSo9mc7yYe85lqWfzLf+mEdCWSN/Y958GCU0q XT0Y0F6B2+IWtJjaLJlYPNuGByk5rb9rJG7A+s4ue4VGGaD56Tk6xJMExk897RYDl4+l usMryxWh9F7ZONVHtv4fMYv2sq2Ie3dt0GyjzsMbDbgmTkMjkA2k1HqNdgul7sHB80cF TIow== 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; bh=E/vJaeCBGviaQ0hvzD8949Y30FhDcD4GWRiGcNZUjZ4=; b=rZl59oKu4lge43+iKa1DT0CX5Demm5wU519RWqQB514HSIMhz0hEX6cT9xrJ9I36tI oGQSrk0u9b/H6xy/2mYnqddvDwtyKKpM/44KBiiOpaIC+BlgH0GwXwGIUTAIcTzQC5T9 ecsq04RUUTMxHYPrxjeJP63Mu/8/6AhpvyGMjNckrWYeS50GecCkQq6tRGK1yE0TVQqD DOmP7j7958UrPgrDVjwJ7M3iiMR70SswZwoH+2TmRnRJgRI80+3ECrB+57vptG+PiQR6 FctW6R1fpe3ZYh087VjRVsRb7gh5LtJ9wCccvvGe/jpSx4JLGHf8Rd07izzX4/4Ikbrt MJJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ab4hS9bB; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 123-20020a620481000000b005252ffbda2esi3522594pfe.36.2022.08.05.01.34.46; Fri, 05 Aug 2022 01:35:01 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ab4hS9bB; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240357AbiHEHtb (ORCPT + 99 others); Fri, 5 Aug 2022 03:49:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240355AbiHEHtT (ORCPT ); Fri, 5 Aug 2022 03:49:19 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 757966D9C5; Fri, 5 Aug 2022 00:49:14 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id e8-20020a17090a280800b001f2fef7886eso2058627pjd.3; Fri, 05 Aug 2022 00:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=E/vJaeCBGviaQ0hvzD8949Y30FhDcD4GWRiGcNZUjZ4=; b=Ab4hS9bBEcHP2rHNZUseHVF0Kw0e80Tj0eXSPOSDMaSQ3heN0Lqrkw4M52EpZyd3sz H9AEvm+73fn4pFMKyNCe0D7m7XhYsjeLiVYlvI+r0WhTQ/DUsXNg61ByHct2DBLbc9oc ewCUbcq9frRNV20oyoqTu8u41JDh+umV94wF+N9+9UEkxR/nGoJPM4G1EGXLoFWR860r fIPFpLycsY8kqzkAHDiyitnIQI/hitho4s7dx4+1EH+2TNpZUjB/R83HhmaLT+MgLuI6 KHiq3EkjwE6QWABljF2bgdlGIj2IKOOOQcyAcsuQjR5rgW3YcnHOymJLiCN94q/lqtx4 +CBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=E/vJaeCBGviaQ0hvzD8949Y30FhDcD4GWRiGcNZUjZ4=; b=ORwKRgeJQQ68wpbs5E9ppXAvctFH6Yg9sfb1kGCPkksuAioUSBunZlqutTXffPs4XH hlsE+kEH0JDasvlpwIkDK4uximcbLclupouKm/PtfbtdzmpZS/3z1EGSIqaOzii/UtUO 4VgGyIZgbBUevyQcIU69i0eUNU5ddI8gvkS3R/Y3LH053PPqedBuWm2OV+iQBLOGH5Kn stXdHrgFta+vNQb36Tqm8Y0rNUVKfI5x0ZI2zkuTCUJCCDUQBhPIM9e7JiNTzpJMSq+P BKoTDnvfs83mlG1YU40rflyEo72TjlRUJOUruFJMmR6TwvpbORFWrtjsQgMdVYOiRCmE aX/w== X-Gm-Message-State: ACgBeo38jzcCJPajm+e9EPj+2lrOnKGIHVRxxjsSUSjGrFMII6VPDpvI SKcoJqTkktMr2aWqMWvghhA= X-Received: by 2002:a17:90a:e2cc:b0:1f3:1151:e0ff with SMTP id fr12-20020a17090ae2cc00b001f31151e0ffmr6512965pjb.50.1659685753937; Fri, 05 Aug 2022 00:49:13 -0700 (PDT) Received: from localhost ([117.136.0.155]) by smtp.gmail.com with ESMTPSA id z66-20020a626545000000b0052d3a442760sm2218418pfb.161.2022.08.05.00.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:49:13 -0700 (PDT) From: Hawkins Jiawei To: syzbot+5f26f85569bd179c18ce@syzkaller.appspotmail.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: paskripkin@gmail.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, 18801353760@163.com, Hawkins Jiawei , Jakub Kicinski , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v5 2/2] net: refactor bpf_sk_reuseport_detach() Date: Fri, 5 Aug 2022 15:48:36 +0800 Message-Id: <68ea55d47f10ac8faa0d44e184a5ec00a9dd0409.1659676823.git.yin31149@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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-kernel@vger.kernel.org Refactor sk_user_data dereference using more generic function __rcu_dereference_sk_user_data_with_flags(), which improve its maintainability Suggested-by: Jakub Kicinski Signed-off-by: Hawkins Jiawei --- kernel/bpf/reuseport_array.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/reuseport_array.c b/kernel/bpf/reuseport_array.c index e2618fb5870e..85fa9dbfa8bf 100644 --- a/kernel/bpf/reuseport_array.c +++ b/kernel/bpf/reuseport_array.c @@ -21,14 +21,11 @@ static struct reuseport_array *reuseport_array(struct bpf_map *map) /* The caller must hold the reuseport_lock */ void bpf_sk_reuseport_detach(struct sock *sk) { - uintptr_t sk_user_data; + struct sock __rcu **socks; write_lock_bh(&sk->sk_callback_lock); - sk_user_data = (uintptr_t)sk->sk_user_data; - if (sk_user_data & SK_USER_DATA_BPF) { - struct sock __rcu **socks; - - socks = (void *)(sk_user_data & SK_USER_DATA_PTRMASK); + socks = __rcu_dereference_sk_user_data_with_flags(sk, SK_USER_DATA_BPF); + if (socks) { WRITE_ONCE(sk->sk_user_data, NULL); /* * Do not move this NULL assignment outside of -- 2.25.1