Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp422615imn; Wed, 3 Aug 2022 09:31:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR7w1MBNRtzsnO0U4XmgHBpsCJn4hRSvgfcGeKDAC8j70wZPd43Kf2itCKtpY90KpkR3LVWg X-Received: by 2002:a17:907:6818:b0:730:825d:7296 with SMTP id qz24-20020a170907681800b00730825d7296mr12468367ejc.21.1659544286027; Wed, 03 Aug 2022 09:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659544286; cv=none; d=google.com; s=arc-20160816; b=XYoAh5KbQWHzZmzwA3xsdFUbsF2NYqvN00vCDVo7B1/efNBKiu+j9UamXPaYxCL5uP I6dWqU5fJtl5JrK+JyQF2KI8kLdXBKJ5AEbr4/RweVvmCdI85Owzg37Z8GO4qBt+lshu cEDROftj6ZPUeEYM9B9wQoOeMbqEFK7ox2b8lYFnSK2Ak2TYWWVVn53NvuKVCAPtL9ot RrtUerIruv7D8iXEhBSd40ujI6VcWpDmlhsWG8dWQ6p9jg5lYxFsOtbNZQw/NSWPJsCh Erbt3iJ2/2Z2WsYZSLHLZ4PB8cjMczWbU439XcaDRUwJWdj5M2CpPbkGU6bGH9yVEXDu Zu0g== 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=QzJ33F4bJ7lwM5+m7mFsAcHdJMltjNvGnkKDEEt7hbs=; b=kGoZ9nxnCqM5wMuH4rVSQSXgURTt3t2O5LFDP/Y82OKMGUqx2dlOI9IdPNfsB23kd0 8csZElT+WZ5rwJDXBFN5AtK5NXpVZAFmVbt6UzhtfEK56jul67xYfzd27Xx6PuNmHMCy j9FznsQFVLs5rEtS3CIcjYY4it5IHC3X+euFUQUzumMjAXqz8hYb2IuBEuQPhg2xop2f LmvNLn0InvKAm4HE5BGhjRvkpgFvwZjOCqw9W9ToppNbk/9w5wBi7y/cxzpBwYJu3Krb 2PgnCppf4StR1qPOr2cJgaz2Y8/zX8u3zJQcHJALYSjIE2tY5voJ0iGCrXFVZ/aTwpbo NmiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GPH5p6d1; 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 gb18-20020a170907961200b0073067a0e4f2si10256093ejc.426.2022.08.03.09.31.01; Wed, 03 Aug 2022 09:31: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=20210112 header.b=GPH5p6d1; 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 S236711AbiHCQA7 (ORCPT + 99 others); Wed, 3 Aug 2022 12:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238423AbiHCQAs (ORCPT ); Wed, 3 Aug 2022 12:00:48 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B22311054B for ; Wed, 3 Aug 2022 09:00:46 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id j4-20020a05600c1c0400b003a4f287418bso1079544wms.5 for ; Wed, 03 Aug 2022 09:00:46 -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=QzJ33F4bJ7lwM5+m7mFsAcHdJMltjNvGnkKDEEt7hbs=; b=GPH5p6d1RDaRq+0Zommh1vpqc/rVqUPvZhgldr8qZLtuDtE+SjR13i2nnWrfSbH75X qH5TcRiDQCDkmHTRELxZKGL/gFt67o+6ViJ+oDt9+KG1Lwic6XzFNMun+N8rPczXN8W4 MTDKYbO2iyKrdEidEOrGgAiFv4c/E4OYYPnl+cs+s62wkPZkf3e5TOXU+l/Z0JyESNA7 NsIzQl7NiZdXhG+lljjL0B+6CtN9qZkrY72e6LOe5lCyspAg2xuxetRXFIBHg5s0VnJ0 V23kNJBsAeweX1hyiYcF36v1+dLZFqZ7JgEOqKBihdHIUGBen9+3IkYt51PmcNaaTJVB WT1g== 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=QzJ33F4bJ7lwM5+m7mFsAcHdJMltjNvGnkKDEEt7hbs=; b=aBMgDo4RdEH/Po8cS9M1577TbCuv7wKXx/BTZUazWRcEHimk2Um7esFCNPvbFuctLI cDTgFq0LpTTvN7DFlypybQMk6z4OrvPQqmpV2FXZs78k3cCoprxU5FmoA5dr44nlNYgF xdXuDWQ1Xc878BGwP9rCR6JSXWrV5VNcWWkft8KE9gSVBpVRzf066Qf4Z6ukyWRD6QqC OPtZvaRo4SEfdFN0btYXo8IWV4McM5Ejwh+hpl3Yt5eriSk49QzLoMjqg5W8IYcG4oA+ l1o8aFPrnTSlXLhIE+/KjXX7ZnyJ2xTCBd3Z6gGqUa+v8RePcrmz99jKUDBxWznYAkgi DKrw== X-Gm-Message-State: ACgBeo3dPtPnB7jaajGW00VZYiUKTF2UZ3DKCmzJwS3bX3B8GGezI+D2 1GlHYzvTKCVvsbvRw3a31aU= X-Received: by 2002:a05:600c:35c6:b0:3a3:4217:f06e with SMTP id r6-20020a05600c35c600b003a34217f06emr3167664wmq.95.1659542445094; Wed, 03 Aug 2022 09:00:45 -0700 (PDT) Received: from localhost.localdomain (host-79-27-108-198.retail.telecomitalia.it. [79.27.108.198]) by smtp.gmail.com with ESMTPSA id u11-20020a05600c19cb00b003a302fb9df7sm3240896wmq.21.2022.08.03.09.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 09:00:43 -0700 (PDT) From: "Fabio M. De Francesco" To: Eric Biederman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Baoquan He , Ira Weiny Cc: "Fabio M. De Francesco" Subject: [PATCH v3] kexec: Replace kmap() with kmap_local_page() Date: Wed, 3 Aug 2022 18:00:38 +0200 Message-Id: <20220803160038.22322-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and are still valid. Since its use in kexec_core.c is safe everywhere, it should be preferred. Therefore, replace kmap() with kmap_local_page() in kexec_core.c. Tested on a QEMU/KVM x86_32 VM, 6GB RAM, booting a kernel with HIGHMEM64GB enabled. Suggested-by: Ira Weiny Reviewed-by: Ira Weiny Acked-by: Baoquan He Signed-off-by: Fabio M. De Francesco --- v2->v3: Add more information in the commit message as requested by Baoquan He and forward two tags, respectively from Ira Weiny and Baoquan He (many thanks to them two!). v1->v2: A sentence of the commit message contained an error due to a mistake in copy-pasting from a previous patch. Replace "aio.c" with "kexec_core.c". kernel/kexec_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 4d34c78334ce..6f98274765d4 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -814,7 +814,7 @@ static int kimage_load_normal_segment(struct kimage *image, if (result < 0) goto out; - ptr = kmap(page); + ptr = kmap_local_page(page); /* Start with a clear page */ clear_page(ptr); ptr += maddr & ~PAGE_MASK; @@ -827,7 +827,7 @@ static int kimage_load_normal_segment(struct kimage *image, memcpy(ptr, kbuf, uchunk); else result = copy_from_user(ptr, buf, uchunk); - kunmap(page); + kunmap_local(ptr); if (result) { result = -EFAULT; goto out; @@ -878,7 +878,7 @@ static int kimage_load_crash_segment(struct kimage *image, goto out; } arch_kexec_post_alloc_pages(page_address(page), 1, 0); - ptr = kmap(page); + ptr = kmap_local_page(page); ptr += maddr & ~PAGE_MASK; mchunk = min_t(size_t, mbytes, PAGE_SIZE - (maddr & ~PAGE_MASK)); @@ -894,7 +894,7 @@ static int kimage_load_crash_segment(struct kimage *image, else result = copy_from_user(ptr, buf, uchunk); kexec_flush_icache_page(page); - kunmap(page); + kunmap_local(ptr); arch_kexec_pre_free_pages(page_address(page), 1); if (result) { result = -EFAULT; -- 2.37.1