Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1157497imi; Fri, 1 Jul 2022 04:25:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQGD3hzy3iB1L/RxQyawimYvlioWasGB4ZcNVcu9rkTO/dHRtKYh16yF/t7uGM7YZPx9hd X-Received: by 2002:a05:6402:909:b0:435:a8b:5232 with SMTP id g9-20020a056402090900b004350a8b5232mr17621910edz.240.1656674756207; Fri, 01 Jul 2022 04:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656674756; cv=none; d=google.com; s=arc-20160816; b=RtD8xMWja6ckwOWKu2bl4CrGkuRQNVBbtoI/GdoQVG6ZeDaUBdOiNUZto/DBitTe3S tkGWvVmBTGQ+STnxCeG+wkFSXj8idpXVMQTivjky3LUb4QtPcLtzRd6/w6vO4AakIPu7 vvfaies0G+HqPA20jX7x6xTqB1q79RWaf2+fltitkB3k24tBj96XJgebm28xJKJJaedq FzsPCejYdC06cwjkNbMpL5gM+bimFmvvGmEvSbykpBZl2cMq9XlXEkuP/DWaV9+p1PZG CCPWADT3AkZDpWAoZN7zeINBSitT59r6ZMInnbLiHLHwTSjW5nMKtewBWZ8xNWDl2k3X 2qfA== 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:dkim-signature; bh=oyc/+3fJaJYytyUhCXFNiLRQsFA3SKTfZsuSpfHSjfk=; b=dpy2h4skhdmCcDYNL1bo7mC/xBOX9Zi4VxU2tcAlUucnXb9EifLj24oZQU3pRQnLSm TKDI7gxao6xGAlV3Udhx1XrYIj1TQvLawd3BFPnC5yukE65Ngt5ZcJHXQAVHQ73+KkBI DgwUxBbcXSauvTEqYWD1FyWVsCYtzpO8MdmM4bM+gVObjE0NmBiBkWTrtWaViC1UTmbM zw1wYVtK/bo7I+wTEIIqwqRNjcfRnX5FXF7DTQ8jtKtLceRezsWfUvKrFjOaKwvQP3th a/DrnagTdJleJftUPNX8nH6RyTttcJxAwKakZQnLTGmSOAMmLw9z+kz+yVPvgCQXXi03 5HFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UPtMHhi3; 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 aj11-20020a1709069a4b00b007262a002373si22343620ejc.395.2022.07.01.04.25.29; Fri, 01 Jul 2022 04:25:56 -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=UPtMHhi3; 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 S235854AbiGAKwH (ORCPT + 99 others); Fri, 1 Jul 2022 06:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232764AbiGAKwF (ORCPT ); Fri, 1 Jul 2022 06:52:05 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A05107D1C2; Fri, 1 Jul 2022 03:51:59 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id o4so2655376wrh.3; Fri, 01 Jul 2022 03:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oyc/+3fJaJYytyUhCXFNiLRQsFA3SKTfZsuSpfHSjfk=; b=UPtMHhi38U0/t5d9VeVWXw3Io8R9s/W3Z+gbgw3uqRDHfFJyER3XwNewCH7fx6tnfU 6FtpREpQbHWHbbSSGaguF0ja8XHaKsi3W/0zTJcoj2URVrJ+6RPuwprENVG+zw+vvght ViMEwfm1+iyQ97ybW5I6vmshwPvKtCIFF17J578SP1uOAuzTk0C7Ac0+k47zb6paL8yI XI9wSrIr4EF73RzeTGxjOxHYtBgzhQjcgC5WOhD+Q8Q/Lx1AKmh6GKCEcJWSulicbgCC zGGYVDPl+QENDSzbLqOMQfNL0wFBREzNi1wEM5x9HtumdzB1CUb6iEOz5iKYsITY5OGf iOmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oyc/+3fJaJYytyUhCXFNiLRQsFA3SKTfZsuSpfHSjfk=; b=yLbUyW1xkPWJ86jEQEsM30ufAIc9ic7w48esjarFdTZjc5AlgSkfvdQupb0CGODWEA ckIGB0JKHVjcTSyLs/mG/tsBx5/ksCuhabiQNIAvXLbKGddmD7Ep7G88kjOkvrAU1SKa uK/irh0B66edTz/VyY7MgAOpdNZGMkrsMWU42gPN5UgXp8/6o0fhbnlsThz8InHgvbkF zyGteJFkGOZDNshl029jC04CnWlPL/H3qi0fKgI5O94wUqsJDaS5efI4CkZt7CpEMTYH dadCx/9RJhE+13jDd+ovh3wtstZCA5a1NV7OY6mWCd+oD+jXSxl4dvViPimFnsH40z6E SnkA== X-Gm-Message-State: AJIora8jYIrxpzCT/pXD0S+QIFyHvteMl1g0kJVwXw7CDdAYdcCmEbfS j00FZ+O/ChfcVIAytMTT8IYU7P8QuinUrQ== X-Received: by 2002:a05:6000:1449:b0:21b:b171:5eb8 with SMTP id v9-20020a056000144900b0021bb1715eb8mr13325469wrx.634.1656672718089; Fri, 01 Jul 2022 03:51:58 -0700 (PDT) Received: from localhost.localdomain (host-79-53-109-127.retail.telecomitalia.it. [79.53.109.127]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c269200b003a03a8475bfsm5777498wmt.16.2022.07.01.03.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 03:51:56 -0700 (PDT) From: "Fabio M. De Francesco" To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , David Ahern , Pavel Begunkov , Wei Wang , Yangbo Lu , Richard Palethorpe , Thomas Gleixner , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [RFC PATCH] net: core: Replace kmap() with kmap_local_page() Date: Fri, 1 Jul 2022 12:51:52 +0200 Message-Id: <20220701105152.6920-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 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 The use of kmap() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mappings are per thread, CPU local and not globally visible. Taking page faults is allowed. Furthermore, the mappings can be acquired from any context (including interrupts). Therefore, use kmap_local_page() in sock.c and datagram.c because these mappings are per thread, CPU local, and not globally visible. Actually this is an RFC because I'm not 100% sure that the mappings in sock.c are not handed over to other contexts. Unfortunately I know very little about this code. The fact that "page" is kmapped and then kunmapped before exiting sock_send_page*() is not a guarantee of thread locality. That "kernel_sendmsg*()" is a bit "suspicious". Can anyone please confirm whether or not "kaddr" is handed over to other contexts while the call sites might sleep between kmap() / kunmap()? Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- net/core/datagram.c | 4 ++-- net/core/sock.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/net/core/datagram.c b/net/core/datagram.c index 50f4faeea76c..3a8fa210e1a1 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -438,14 +438,14 @@ static int __skb_datagram_iter(const struct sk_buff *skb, int offset, end = start + skb_frag_size(frag); if ((copy = end - offset) > 0) { struct page *page = skb_frag_page(frag); - u8 *vaddr = kmap(page); + u8 *vaddr = kmap_local_page(page); if (copy > len) copy = len; n = INDIRECT_CALL_1(cb, simple_copy_to_iter, vaddr + skb_frag_off(frag) + offset - start, copy, data, to); - kunmap(page); + kunmap_local(vaddr); offset += n; if (n != copy) goto short_copy; diff --git a/net/core/sock.c b/net/core/sock.c index 2ff40dd0a7a6..12dd6ced62cf 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3155,11 +3155,11 @@ ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, siz ssize_t res; struct msghdr msg = {.msg_flags = flags}; struct kvec iov; - char *kaddr = kmap(page); + char *kaddr = kmap_local_page(page); iov.iov_base = kaddr + offset; iov.iov_len = size; res = kernel_sendmsg(sock, &msg, &iov, 1, size); - kunmap(page); + kunmap_local(kaddr); return res; } EXPORT_SYMBOL(sock_no_sendpage); @@ -3170,12 +3170,12 @@ ssize_t sock_no_sendpage_locked(struct sock *sk, struct page *page, ssize_t res; struct msghdr msg = {.msg_flags = flags}; struct kvec iov; - char *kaddr = kmap(page); + char *kaddr = kmap_local_page(page); iov.iov_base = kaddr + offset; iov.iov_len = size; res = kernel_sendmsg_locked(sk, &msg, &iov, 1, size); - kunmap(page); + kunmap_local(kaddr); return res; } EXPORT_SYMBOL(sock_no_sendpage_locked); -- 2.36.1