From nobody Wed May 13 22:06:51 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 72905C433EF for ; Sat, 23 Apr 2022 10:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234962AbiDWK23 (ORCPT ); Sat, 23 Apr 2022 06:28:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234899AbiDWK1b (ORCPT ); Sat, 23 Apr 2022 06:27:31 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 225C710E4 for ; Sat, 23 Apr 2022 03:24:34 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id bv16so14236419wrb.9 for ; Sat, 23 Apr 2022 03:24:34 -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=LA7DgNA9uVvinJw7IGw388CbOs1kZcBwqiYxarlq+dM=; b=W6TgrcHTH/xBgrp1tX2mK8ges1ZzMNhY2uPzGvnSdCY4IDF0tGscn8NKqTJuoYUV4V A3QZgQvxb4kfKOEusTZBhFLPOOnQYbPNacKozJOet+/AFWKICBYtZ9ZQdOXn34lMZYsJ 5m9Pd1dNy6km35hgwA/m8zAUzlEhSuMUtdhmRMMferMtyi0M7cBCMhtH1XiekQjjKWmx 52W0BrtY9Tq5izVyGZdfqs7aNjxDrIzy9jE6aFxlFs88Ib42/VerfM8EeK2x3bxmk1Is zgGUTPrk2Z5+gAhinxEPUzFTjOVPN1G6F62IZepyhctEyOE4TUqUlZu0y/kzOP6bsZAL 3P3g== 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=LA7DgNA9uVvinJw7IGw388CbOs1kZcBwqiYxarlq+dM=; b=Iyhf5AjrjcOMoqjCbeWv8GCEsm8jiAiePgnj9ayhOU8+jF0DKE0Rlg6bJEzM/GGlzk dqR/UuRyxWo0Kp8wUXjodk/fjxfTfsAf6hyJsFZZLh6BLNOywLDxgqLSPS4rxpcWNvkJ aaIc3jlE32DFcMvNVVwEDuuPeogElY0te/MWASiCgIMgZJGu/mD+ddrwNt2fXMGo6VwA XPHBX4VyuZbvqVS3VywWjg4JPlyCdS9jPItwBFidw8YvwUDTcptAdHV67Sh6YBipCMkQ xADKwCY8DbV/hHyOUZwMF/y98GbY9nreup5zTGKsWPz9Wr14iLDVmC2E5bCK/ClysAQV ItFw== X-Gm-Message-State: AOAM5320eNsqwODkTETe4pD0ZPs/6jMmL3VLvVrjndCkU+yixASrK5lS yIKh9/L3p0EqArT+nxCuzAo= X-Google-Smtp-Source: ABdhPJw3UxhCqXYJXJ0AFqJ3QQYGYerqWmYP/Y8CrtobN3Myvvblp2zWl9BxebyfN3bjaRs7jhQ9hg== X-Received: by 2002:a5d:48c8:0:b0:207:afc8:13fa with SMTP id p8-20020a5d48c8000000b00207afc813famr7038225wrs.487.1650709472633; Sat, 23 Apr 2022 03:24:32 -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 t15-20020adfeb8f000000b002060d26c211sm4089057wrn.114.2022.04.23.03.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 03:24:31 -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 Cc: "Fabio M. De Francesco" Subject: [PATCH 1/3] binder: Use memset_page() in binder_alloc_clear_buf() Date: Sat, 23 Apr 2022 12:24:19 +0200 Message-Id: <20220423102421.16869-2-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220423102421.16869-1-fmdefrancesco@gmail.com> References: <20220423102421.16869-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(). Signed-off-by: Fabio M. De Francesco Acked-by: Todd Kjos --- 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 Wed May 13 22:06:51 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 88E39C433F5 for ; Sat, 23 Apr 2022 10:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234908AbiDWK2L (ORCPT ); Sat, 23 Apr 2022 06:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234911AbiDWK1e (ORCPT ); Sat, 23 Apr 2022 06:27:34 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79AFF10E4 for ; Sat, 23 Apr 2022 03:24:36 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id f6so76674wma.0 for ; Sat, 23 Apr 2022 03:24:36 -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=JnzJn9/apOse1TRdog9QxKjgDoh08yuT8iYmEPjnkLo=; b=EdRnFs11rrayuYTjd5BRRXOPQ+6lHEDn37pxNXH+HIV3NgWTWMAzKj3mdnLsnM7ntT q05koXcf1+O2OIpp3SfPEK9RptcDXAr6XlEyDnuOQ+Poug3JuqInykzDCJnjQLqq13I2 MXclDmF1rAmIMpbZ9wI77X72rk9zp9AN+zxKfWMhMvHVypCkm9VzQlrIA1S5kh0oBUjg 1DqtbpsbmQfT9LU33EtELKde09//wwPjGq3kWkyKnVk72c1jd12/zfeHXnkK3xMqEKUe dpoCsaBFopex08M2tgjBPQhIiVq2P1Xrzi4licGX4dNkfqg7853kCehT2Af/eJE87sYy S6Nw== 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=JnzJn9/apOse1TRdog9QxKjgDoh08yuT8iYmEPjnkLo=; b=iHfiMqegn+dM2owAmFgEkWFgcD9p+B+2EqDCZLhnnz+2+L05DJt1I7KvWgFFUYN0Y7 2PdVuYXYd4MlSkgCoQiXiEpwwBB9dSXeduQNok7xHKyglRgfwkJQs/6lrYUOpKO178Vl DCPxsWTvZqo3m1y+bBLxcLbsoKIFZbixugsJ7jNy48ZvqE/lS/0743ghIwK3Kqk6LTVS 2ofs+mC2I/uyJ9er6of/NXUmkzB6t3sZaS7gMUumfK/iCySex2fGIGSXsZCCv+8m0OyQ JTuuI4s3n90PkrVGM2ukHX9AGGSS+w/ZLdqo6+5uBZ7J3FcwtcMnJusoHGfqv2/1Afy5 Yikg== X-Gm-Message-State: AOAM532TMcNe8ALnaxzQ4q6pGgyj8wcIechbztf4bW0gsJxMfUth4037 nuGE2PYiflig03C+d59QUMTeulBtRjE= X-Google-Smtp-Source: ABdhPJyS1uQmxp9EjFBBuu7Wu0WbDYSAIAiNH9tMqDan9RYRWsD+dh/C82c+oe7q2B0VbV9fc3mpvg== X-Received: by 2002:a05:600c:3641:b0:38e:4b2f:330 with SMTP id y1-20020a05600c364100b0038e4b2f0330mr17410186wmq.180.1650709475085; Sat, 23 Apr 2022 03:24:35 -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 t15-20020adfeb8f000000b002060d26c211sm4089057wrn.114.2022.04.23.03.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 03:24:33 -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 Cc: "Fabio M. De Francesco" Subject: [PATCH 2/3] binder: Use kmap_local_page() in binder_alloc_copy_user_to_buffer() Date: Sat, 23 Apr 2022 12:24:20 +0200 Message-Id: <20220423102421.16869-3-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220423102421.16869-1-fmdefrancesco@gmail.com> References: <20220423102421.16869-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(). Signed-off-by: Fabio M. De Francesco Acked-by: Todd Kjos --- 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 Wed May 13 22:06:51 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 CD5E5C433F5 for ; Sat, 23 Apr 2022 10:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234930AbiDWK2S (ORCPT ); Sat, 23 Apr 2022 06:28:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234913AbiDWK1f (ORCPT ); Sat, 23 Apr 2022 06:27:35 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1B8E55B8 for ; Sat, 23 Apr 2022 03:24:38 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id l62-20020a1c2541000000b0038e4570af2fso6720013wml.5 for ; Sat, 23 Apr 2022 03:24:38 -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=IrJ9VT1U6pXkFDAeCtKaSy4E+WG6fEcoDC8tfVpmfEc=; b=VC3B/QEi0icnjr6kEzpD3fkHieeml6wJWcnleIfuqOjC1Y8j+Nhlwr+C7IskW1LXAc jQiFYidfnGG3cZt9f5qPLtxQn/B5PVG1VWtcjF3SIMkkgB3fJSeXQY8YPh72biMOxRpq Cy9rZkGLO6nZQ63VR3f8yCd4DkBZ4Qzq2ysADdOnBLJJ8OaIdUsrfWieEkRunOGkdl8U fhOKzarOb7xvzoAJ549OLmviEq1EOVt+QO+Ezdqgj4v19X5FUtbSh1UMRATP8GsCQ0TM ecgb0rPcSr1JfjNViThNoFtwIGBVtcViImCyvoeiwV0GyRj1BqtjVDxhEz0tnVmy69X7 LViA== 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=IrJ9VT1U6pXkFDAeCtKaSy4E+WG6fEcoDC8tfVpmfEc=; b=Sk1EA5sO14XchnuboEOLjUmf55OsDCftMMlEYiO1f4wXHIlmZ6BiZMQJpiVyDmbvbH dEmDnpVKOyKmCh5Qv1mQ5pDJ+Sj+BSfOwtm0FjATmq7ltI8Rn6emyoGavEzCzLMK9dKK lX3+iFv02M7UFhRazso/TA4Oc8Z0vxFrCNmB6Kl6OcoaG4Uk+l/6VN6c25sXJFcMyPW9 GVEg0sUTwRNLbrwu11slyKWIg0oCtf1itSYjV3aXihYOZ77U+HjMTpw39cLbUiMNrFzd 9GaAKoKUHsu90k/9hA8O4Yoxrz6nQbUaaTNOPMqTrmVx+bQNTuJ9rD3+t93DVvrGIt/0 XnfA== X-Gm-Message-State: AOAM532OGL6rLcqrvlLocMW6h4j17kXdv2lPHXKTwj90A0/pDmwMXOwZ Q7uBP63Prwhv1D6Y6wr1TCc= X-Google-Smtp-Source: ABdhPJwD2Vte4EbWLpcsvpjuZbfLAin4wGBDAQJiL0Btp/8xWXaXgturiG+CR2Nw+RECunvtIJB0bw== X-Received: by 2002:a05:600c:1e85:b0:391:ca59:76be with SMTP id be5-20020a05600c1e8500b00391ca5976bemr16985309wmb.184.1650709477436; Sat, 23 Apr 2022 03:24:37 -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 t15-20020adfeb8f000000b002060d26c211sm4089057wrn.114.2022.04.23.03.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 03:24:36 -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 Cc: "Fabio M. De Francesco" Subject: [PATCH 3/3] binder: Use kmap_local_page() in binder_alloc_get_page() Date: Sat, 23 Apr 2022 12:24:21 +0200 Message-Id: <20220423102421.16869-4-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220423102421.16869-1-fmdefrancesco@gmail.com> References: <20220423102421.16869-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 it should be only used if it is absolutely required, otherwise 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). Therefore, use kmap_local_page() / kunmap_local() in place of kmap_atomic() / kunmap_atomic(). Signed-off-by: Fabio M. De Francesco Acked-by: Todd Kjos --- drivers/android/binder_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 0875c463c002..058595cc7ff0 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1250,17 +1250,17 @@ static int binder_alloc_do_buffer_copy(struct binde= r_alloc *alloc, 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); + base_ptr =3D kmap_local_page(page); tmpptr =3D base_ptr + pgoff; if (to_buffer) memcpy(tmpptr, ptr, size); else memcpy(ptr, tmpptr, size); /* - * kunmap_atomic() takes care of flushing the cache + * kunmap_local() takes care of flushing the cache * if this device has VIVT cache arch */ - kunmap_atomic(base_ptr); + kunmap_local(base_ptr); bytes -=3D size; pgoff =3D 0; ptr =3D ptr + size; --=20 2.34.1