Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5390978rwd; Mon, 12 Jun 2023 04:36:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51xe+3ejFMtieaHlXjzy004hQi+f25bkDpnpDV0EYWNH/j4zocyURPGIk+c3X6v5dBdCyj X-Received: by 2002:a17:907:809:b0:977:cbaf:bc56 with SMTP id wv9-20020a170907080900b00977cbafbc56mr9917540ejb.43.1686569786911; Mon, 12 Jun 2023 04:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686569786; cv=none; d=google.com; s=arc-20160816; b=JALQ61UNgWaS+Un73aCsRy/Esg4Yrv2DRmg70J1QbA6t2XVkwO0UUxJ3/wTZmJDcbw DIw9hbGvsw2Hf+xcCxpYyijvE1e5yRBvcsIx+EK6zl6bIZdoCLgUb9v2RJFxgAP1YAD4 aEnpxkF+6sBrFvUXnrQYYX0VJbA0istUPYIrVagYxBrqRYVwh2LyrPcFp/pcgyi1lj1H +/PylOQhFfnvdm5t36p9uTNr80egec4G3TCdhedKpUCAwxRzCLMry1FOx3f4UZo3V/Hk yWpmYk5QlrvLsapSWg7HIZWp7V7b9q4WSqzBQ80FZ6CO9BqytxMpPoOxaNNOW7TJaWy9 NONg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=bfpZtHxfMfNOA+nAShm6Lv54zYUDy4unPqc7jTzW5IY=; b=K50zCmeZQhFbZmSFo9hPjAtJ/t8cQvhsHElCx2LvKTRKe3/FYBUm4utNdAYzZv+R4j lNRMHQ1X7jfchQdqlNOmDbke2707aC9azEe15/iIV8NqXvbCQbS+2suSKGFme28HGxeO woH2d2VuRBMoGtJJBROu/1hpvvsONcnH9yzH89Z6wsIt7VQjblLGigiMTX5vcSqNlSLQ gwm/7uNeC/SUybz9ALJ/YOc4BjkNVJWwIJDhdzdmpPsGc8kMgSbunXeXDi/YcDf1VaT1 71gXd37J3MqbKE9o1KJ4zLrOmFNhs02iS7jNqmL9uUAeYNSBTg4NQ0U0wVpaLyxr+Y7p Qwfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=g5MQrV06; 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 a26-20020a170906685a00b0097894b1261fsi5030868ejs.253.2023.06.12.04.36.02; Mon, 12 Jun 2023 04:36:26 -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=20221208 header.b=g5MQrV06; 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 S235557AbjFLKt2 (ORCPT + 99 others); Mon, 12 Jun 2023 06:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234671AbjFLKtN (ORCPT ); Mon, 12 Jun 2023 06:49:13 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D4849E1; Mon, 12 Jun 2023 03:33:50 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-544c0d768b9so2823150a12.0; Mon, 12 Jun 2023 03:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686566029; x=1689158029; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=bfpZtHxfMfNOA+nAShm6Lv54zYUDy4unPqc7jTzW5IY=; b=g5MQrV06tGnu5T49c+fqlRVbz+4vl6lTs+B5PSv26UDs8SmwuUjbtgpYvi4XYvsfXs g3Wc2jiZquREb5ZwSnwRH1DOO0gSmxP4ZhQb3LUz6RactKq1Qh1tXR07KR1JZ3n9uWCT OmsqK5utFoC85oyQFK3hSzIZZeudEFukchwPhsPYdiKrxiULBo149J62DCxM9rqD41OP 2n7nwRHR5sp/jW8AFmWtySZQaZxDatBrFk8cg247NVR8wSaZAu6PlfoyvC/ViMgBDKkk RAaGZwoamqew0CIJp9D6bhGrbvVd7HtX1+WQ2KrieFtv7QreWGEkuOXnHV8eTeMGwGfH vGLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686566029; x=1689158029; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bfpZtHxfMfNOA+nAShm6Lv54zYUDy4unPqc7jTzW5IY=; b=klHY3KT7nsVYH+OCPVC1Ij0lO+Bvv+rJHOh+YuF14SskOsX9HrNW/NMZiwes24SjGO 2RgE3n2OleroGM4C7yxbey27X/cd0nJS+NtAsi+ar5xh01uT3MuVCF9xk3e0JMGDEyXD sTtTwmff0CCWfFaLLCMh120PeNZ7HXea7p8457JA12Qp4xJOpNKg6HjAs4fXfSt4Ev1o PDBtQNlMRbb0CdkB3X3X7fjVcC7+g7xTUVRUeCTMoi4igQPn0RKKKp+NTH7PthHONQRQ uTbhLzycgfnQVkhJYSKuQJewy35+m/JN33vC7yd4y5Hwx7W7PhwJdCUiglBOcm/X72ME W08A== X-Gm-Message-State: AC+VfDwhdoGDcY6xVuGWRbCxVgYzbfLdXlJ1fv/DlCsLnfJR/O2uPu9o iJI7toM3BuFOZDzfzyg4XIo= X-Received: by 2002:a17:902:8d8a:b0:1b1:9d14:1537 with SMTP id v10-20020a1709028d8a00b001b19d141537mr5845271plo.55.1686566029363; Mon, 12 Jun 2023 03:33:49 -0700 (PDT) Received: from sumitra.com ([117.212.94.125]) by smtp.gmail.com with ESMTPSA id n3-20020a170902968300b001b0266579ebsm7866299plp.194.2023.06.12.03.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 03:33:48 -0700 (PDT) Date: Mon, 12 Jun 2023 03:33:41 -0700 From: Sumitra Sharma To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , Fabio , Deepak R Varma Subject: [PATCH] lib/test_bpf: Replace kmap() with kmap_local_page() Message-ID: <20230612103341.GA354790@sumitra.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 kmap() has been deprecated in favor of the kmap_local_page() due to high cost, restricted mapping space, the overhead of a global lock for synchronization, and making the process sleep in the absence of free slots. kmap_local_page() is faster than kmap() and offers thread-local and CPU-local mappings, take pagefaults in a local kmap region and preserves preemption by saving the mappings of outgoing tasks and restoring those of the incoming one during a context switch. The mapping is kept thread local in the function “generate_test_data” in test_bpf.c Therefore, replace kmap() with kmap_local_page() and use memcpy_to_page() to avoid open coding kmap_local_page() + memcpy() + kunmap_local(). Remove the unused variable “ptr”. Signed-off-by: Sumitra Sharma --- lib/test_bpf.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/test_bpf.c b/lib/test_bpf.c index ade9ac672adb..3bb94727d83b 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c @@ -14381,25 +14381,17 @@ static void *generate_test_data(struct bpf_test *test, int sub) * single fragment to the skb, filled with * test->frag_data. */ - void *ptr; - page = alloc_page(GFP_KERNEL); if (!page) goto err_kfree_skb; - ptr = kmap(page); - if (!ptr) - goto err_free_page; - memcpy(ptr, test->frag_data, MAX_DATA); - kunmap(page); + memcpy_to_page(page, 0, test->frag_data, MAX_DATA); skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA); } return skb; -err_free_page: - __free_page(page); err_kfree_skb: kfree_skb(skb); return NULL; -- 2.25.1