From nobody Sun May 10 19:51:59 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C73C6C433EF for ; Mon, 25 Apr 2022 17:58:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244168AbiDYSBN (ORCPT ); Mon, 25 Apr 2022 14:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244143AbiDYSBG (ORCPT ); Mon, 25 Apr 2022 14:01:06 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5196433A0E for ; Mon, 25 Apr 2022 10:58:02 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id a1so13741692edt.3 for ; Mon, 25 Apr 2022 10:58:02 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=4HJrozkvVkscS0zdSWk9LaftjL2z1E2cnMkC2nHI7pY=; b=gitlin4eSQ5kEyFnKB9CpAO9Q3nsVpEq4IfwfoQ63ph3VaYJTDat6BhbWTkBxi9kx3 YeGbtuODl9+entPhkyr5TpazRNM8RHiJ8lQTcE+nXzQPQQtBsDUBwfhHsLKUB7w/2bgn qBLInehp/cdVF+tHJHIF7cDP2yRYa0Uin/xEa4B/t2m4A9nQc1wxL0Y3HOF4Ett8gEb+ bi4Q//JL9HzsdKkOox1lyIF/7yFf/lqUol+hUpGX/J+6Ho31bniPadBz5CvqHAHh0yqB 7DLYuzquCDpmjp2A5akX0rKMbBYz1qnsOY7m3F/eVYgusgq3q0IrNkdCT6CFcqlIBYRp iLAw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4HJrozkvVkscS0zdSWk9LaftjL2z1E2cnMkC2nHI7pY=; b=goUTzfCk/DVZJLJ6Ms4pczZ/1Uqxv9/Y9Y7WlnmeouX8bTUqrJpCmQvguSueU3DGWV QKsNN7jRykZuGOUVy54eTZaa8aQKSU4A2hA0h6ZjqQRefQAQs+y4g9IGxs0v1P6tGWxL DI8tBDelsunZiWq4EqEjYxmg0JVmfLuVNqBUJIjvscM4vPIiV669PxSMu196TIMgdsGM 1l6kt/rL7GkUmPJxBS3Hbz7gnBHpqBVCRYjoTmVPS6ny9NzXVzUCOKBtN12TkrmlOd4c 9OqokvwzZzzXDxT1sXFYv+Bpq94xCW7Yk8BYfL9r9LS/CPnZ476QN1QMyaaToQXGlpSG zbEg== X-Gm-Message-State: AOAM5337VK00WI7LqB2ate1uwA23NiE5znc/Mrb4Isui8RJUW2rxwxSp 3nDE+jMfrw5hXumhpX9mIyg= X-Google-Smtp-Source: ABdhPJy6AzM9WCKC1+WGQWunE0TwIw9DcswsxtS8VT8z5/lj5NUxCxegU64lNkHjPnC3a2aARqaBTw== X-Received: by 2002:aa7:d9d6:0:b0:425:dafc:2fc6 with SMTP id v22-20020aa7d9d6000000b00425dafc2fc6mr8299494eds.340.1650909480802; Mon, 25 Apr 2022 10:58:00 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id ia5-20020a170907a06500b006f392df973bsm1497207ejc.107.2022.04.25.10.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 10:57:59 -0700 (PDT) From: "Fabio M. De Francesco" To: Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Ira Weiny , linux-kernel@vger.kernel.org, Christophe JAILLET Cc: "Fabio M. De Francesco" , Todd Kjos Subject: [PATCH v2 1/3] binder: Use memset_page() in binder_alloc_clear_buf() Date: Mon, 25 Apr 2022 19:57:52 +0200 Message-Id: <20220425175754.8180-2-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425175754.8180-1-fmdefrancesco@gmail.com> References: <20220425175754.8180-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. With kmap_local_page(), the mapping is per thread, CPU local and not globally visible. binder_alloc_clear_buf() is a function where the use of kmap_local_page() in place of kmap() is correctly suited because the mapping is local to the thread. Therefore, use kmap_local_page() / kunmap_local() but, instead of open coding these two functions and adding a memset() of the virtual address of the mapping, prefer memset_page(). Cc: Christophe JAILLET Acked-by: Todd Kjos Signed-off-by: Fabio M. De Francesco Reviewed-by: Ira Weiny --- v1->v2: Add Todd Kjos's tag in the commit message (thanks!) drivers/android/binder_alloc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 2ac1008a5f39..0b3f2f569053 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1175,14 +1175,11 @@ static void binder_alloc_clear_buf(struct binder_al= loc *alloc, unsigned long size; struct page *page; pgoff_t pgoff; - void *kptr; =20 page =3D binder_alloc_get_page(alloc, buffer, buffer_offset, &pgoff); size =3D min_t(size_t, bytes, PAGE_SIZE - pgoff); - kptr =3D kmap(page) + pgoff; - memset(kptr, 0, size); - kunmap(page); + memset_page(page, pgoff, 0, size); bytes -=3D size; buffer_offset +=3D size; } --=20 2.34.1 From nobody Sun May 10 19:51:59 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2E0BC433EF for ; Mon, 25 Apr 2022 17:58:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244182AbiDYSBQ (ORCPT ); Mon, 25 Apr 2022 14:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244167AbiDYSBJ (ORCPT ); Mon, 25 Apr 2022 14:01:09 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A2FC286CE for ; Mon, 25 Apr 2022 10:58:04 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id z19so6134354edx.9 for ; Mon, 25 Apr 2022 10:58:04 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ogzFF1vidBXb8qUr8gbdeuYvvr4G0L7hay7vGN5jrk=; b=fQk1z1BqeH70BndD2TZKd5xfNwDkTjv0pCOIscV3w0xlpv4EByQ3g0nDFXzpYuYmaT RvuXfazqN51WsaphX9uC8uMOJzdPsRFjef1QnIjbJv6usa5cFne57w/1WeFj+YG2/dEm fiZsYE79OI1QraVMFla8BNx98JNUbyny0gjtxD1UBLKOXaADFgF64qiwJhpmKsCnW13l Zvp7CtVGE1LPjR2dHhE8/6Qxb0uSItPF+cbEapdHUd7M6U9lHDeI3bbSjv6n0kuPJew7 gGTXYdlq/iFOX46RHhEPwXw1o9Uaaa3nkECP9jk+yGhUgEFOSnQ2IRilFCv8oU8ak5Lg qtRA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ogzFF1vidBXb8qUr8gbdeuYvvr4G0L7hay7vGN5jrk=; b=GV8biGD3Itm7JRoXQBJRcS8D3Y6V8ujeKXGGTnoty2m0T1aBlD4ZTy3t+ncREEV4to wg3dY1wPZ/Ai8NfyjnV9RIM6StR4s1qBdkLFU/ISA+6tzGt8M72G+qOTCxJCJKyz3Yh7 OBSGdWFwzs8Sv1/l5Db/YaviI9pNoUaEJZdDH3BCXOC4dAjabqQqY60Ul7Hz/Q3jHxB2 cyfpJBRvxQP2sDFIUZhlNeCsqnohl//5HTEJsUJ9a6Iuy0gNW6UjzXeohrv4u+YR0ehN OopMdoI/k3knBAq9DqsbJYiWQqjc8ALfpu1lM0gPnb/LQu5fJt/prENC243QZm+0LZzr y0FA== X-Gm-Message-State: AOAM532/a+u4FlEV/S45fTDwIRHua5qvvy8a5daEa6v2XKJEJ8v1iSYT 9e5QPwvN2+5KLSa1IRl3d1HkDDta2oI= X-Google-Smtp-Source: ABdhPJwjFtfMyK+sAOiJ7QyESeOYFPoQId61DP7WcjKDuglqZugmp3vyRhWpSHMX6Dxt9u3oD+yP3g== X-Received: by 2002:a05:6402:1a26:b0:425:d3cf:d7f0 with SMTP id be6-20020a0564021a2600b00425d3cfd7f0mr13265179edb.251.1650909483031; Mon, 25 Apr 2022 10:58:03 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id ia5-20020a170907a06500b006f392df973bsm1497207ejc.107.2022.04.25.10.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 10:58:01 -0700 (PDT) From: "Fabio M. De Francesco" To: Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Ira Weiny , linux-kernel@vger.kernel.org, Christophe JAILLET Cc: "Fabio M. De Francesco" , Todd Kjos Subject: [PATCH v2 2/3] binder: Use kmap_local_page() in binder_alloc_copy_user_to_buffer() Date: Mon, 25 Apr 2022 19:57:53 +0200 Message-Id: <20220425175754.8180-3-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425175754.8180-1-fmdefrancesco@gmail.com> References: <20220425175754.8180-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. With kmap_local_page(), the mapping is per thread, CPU local and not globally visible. binder_alloc_copy_user_to_buffer() is a function where the use of kmap_local_page() in place of kmap() is correctly suited because the mapping is local to the thread. Therefore, use kmap_local_page() / kunmap_local(). Cc: Christophe JAILLET Acked-by: Todd Kjos Signed-off-by: Fabio M. De Francesco Reviewed-by: Ira Weiny --- v1->v2: Add Todd Kjos's tag in the commit message (thanks!). drivers/android/binder_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 0b3f2f569053..0875c463c002 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1217,9 +1217,9 @@ binder_alloc_copy_user_to_buffer(struct binder_alloc = *alloc, page =3D binder_alloc_get_page(alloc, buffer, buffer_offset, &pgoff); size =3D min_t(size_t, bytes, PAGE_SIZE - pgoff); - kptr =3D kmap(page) + pgoff; + kptr =3D kmap_local_page(page) + pgoff; ret =3D copy_from_user(kptr, from, size); - kunmap(page); + kunmap_local(kptr); if (ret) return bytes - size + ret; bytes -=3D size; --=20 2.34.1 From nobody Sun May 10 19:51:59 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50E32C433EF for ; Mon, 25 Apr 2022 17:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244191AbiDYSBV (ORCPT ); Mon, 25 Apr 2022 14:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244164AbiDYSBL (ORCPT ); Mon, 25 Apr 2022 14:01:11 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EB352AE03 for ; Mon, 25 Apr 2022 10:58:06 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id z99so19385529ede.5 for ; Mon, 25 Apr 2022 10:58:06 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=1bHZ+tZqolAzcHU1cWs/VivYqd7VAIYj72XruBW1EAM=; b=P7BlxsL/aeh1pYlUxsBLc5Mo7EnxYIpWQvWphQbXeYZ77gJjWeR5TcJk0gulo3zy8+ GxQXlfUX/knxnXU9334jt9XGaVtoKqEZcx5DGutni/s77D9Uh0Dvk7YXuunBoyf11vLJ 3TItX+kWCsBTpgkXvt+Ho6HIUZTYZ9hBpAbt3JH4AZycUK2n3tQuWPFsMQpeZqcUk9RT s3ayF/XpVArf39DL74YaasD5IJcos1VTWMasARpSHvTsU1H2b5qUQsh/gxZ80ccWJz2G zE8NsimWSPm8AGtpaLjXWzngoxM8ySpr0kyUdtN4yitYewfu+a8AaBMOWU75YKSRw4tG 63KQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=1bHZ+tZqolAzcHU1cWs/VivYqd7VAIYj72XruBW1EAM=; b=yaw1HBG6jl6gxP9JKkvI5NSGCV+4svNSNqJ6UNgMzwPlzQ4SUWYQLIIspGommqjKO1 oMW/W0RiaA51NP26+6cVDa9HF8ckCcZyp/y6BqNcdaORkUS0+wMyQjrB2deeh1GGO4AE K73hifsdKXq4TmTQflbvS3wpvEcE2Bf6d85UCcAzx1+TA+q0KGSllbOqJPyYbEszm+ei 4vNNlKTp+afAxdw/TsintIBk17uFV2EwnTpnBnBBxSKFozNQZ5BGHhrj6LdJvHSTh6Ow T1Gsw/O7wHvddmXyn4NhhX5yPEOAcjA1ttvCXsx32P4XCSwKMnazQu2ELAicLVO9+V7E lGwA== X-Gm-Message-State: AOAM533wYYVvMfIP2muPVCcEq+BU52KYvxux8/0cMqr+vgTvtyHgnljU AL5s9gM7kSpgPb8ub4W0PJQ= X-Google-Smtp-Source: ABdhPJwXTHe0xEVLUfl/2/b4vg4MZa5yXWsVhGSqrtQQBZYMJEU6qEbdG2xWdoUp6MmV1IP1THhBKg== X-Received: by 2002:a05:6402:50d0:b0:423:f4a1:597d with SMTP id h16-20020a05640250d000b00423f4a1597dmr20210068edb.228.1650909485178; Mon, 25 Apr 2022 10:58:05 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id ia5-20020a170907a06500b006f392df973bsm1497207ejc.107.2022.04.25.10.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 10:58:04 -0700 (PDT) From: "Fabio M. De Francesco" To: Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Ira Weiny , linux-kernel@vger.kernel.org, Christophe JAILLET Cc: "Fabio M. De Francesco" , Todd Kjos Subject: [PATCH v2 3/3] binder: Use memcpy_{to,from}_page() in binder_alloc_do_buffer_copy() Date: Mon, 25 Apr 2022 19:57:54 +0200 Message-Id: <20220425175754.8180-4-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425175754.8180-1-fmdefrancesco@gmail.com> References: <20220425175754.8180-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The use of kmap_atomic() is being deprecated in favor of kmap_local_page() where it is feasible. Each call of kmap_atomic() in the kernel creates a non-preemptible section and disable pagefaults. This could be a source of unwanted latency, so kmap_local_page() should be preferred. With kmap_local_page(), the mapping is per thread, CPU local and not globally visible. Furthermore, the mapping can be acquired from any context (including interrupts). binder_alloc_do_buffer_copy() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Use kmap_local_page() / kunmap_local() in place of kmap_atomic() / kunmap_atomic() but, instead of open coding the mappings and call memcpy() to and from the virtual addresses of the mapped pages, prefer the use of the memcpy_{to,from}_page() wrappers (as suggested by Christophe Jaillet). Cc: Christophe JAILLET Acked-by: Todd Kjos Signed-off-by: Fabio M. De Francesco Reviewed-by: Ira Weiny --- v1->v2: Add Todd Kjos's tag in the commit message (thanks!); re-write the subject which referred to another function (my fault!); use the memcpy_{to,from}_page() (as suggested by Christophe - thanks!); extend and rework the commit message to say something about the use of the above-mentioned wrappers. drivers/android/binder_alloc.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 0875c463c002..5649a0371a1f 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1244,23 +1244,14 @@ static int binder_alloc_do_buffer_copy(struct binde= r_alloc *alloc, unsigned long size; struct page *page; pgoff_t pgoff; - void *tmpptr; - void *base_ptr; =20 page =3D binder_alloc_get_page(alloc, buffer, buffer_offset, &pgoff); size =3D min_t(size_t, bytes, PAGE_SIZE - pgoff); - base_ptr =3D kmap_atomic(page); - tmpptr =3D base_ptr + pgoff; if (to_buffer) - memcpy(tmpptr, ptr, size); + memcpy_to_page(page, pgoff, ptr, size); else - memcpy(ptr, tmpptr, size); - /* - * kunmap_atomic() takes care of flushing the cache - * if this device has VIVT cache arch - */ - kunmap_atomic(base_ptr); + memcpy_from_page(ptr, page, pgoff, size); bytes -=3D size; pgoff =3D 0; ptr =3D ptr + size; --=20 2.34.1