From patchwork Sat Jul 11 03:55:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11657665 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDA2F618 for ; Sat, 11 Jul 2020 04:01:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C61632075F for ; Sat, 11 Jul 2020 04:01:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Dyt+R+YS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=dabbelt-com.20150623.gappssmtp.com header.i=@dabbelt-com.20150623.gappssmtp.com header.b="OCGtNKv0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C61632075F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zAPQjnqEqjCyTgBUNuiEZYPvZg0VX9DHN9O4wQ29wpU=; b=Dyt+R+YSySgO2Bjfpol/2gkzL 0XB7DPAfkSJpFEn3DY+DtOuWMO1OR2RDDinijM2dw24iEafveCuVGo4rHtcoAGHTX9iYibIhHsJ/Q MtD/WhoZNfNB9e79O6L73RLkFyvQF31cOZf71DdMyfUq2wwpVyU3QsQMXzwj7XW7klTiiukuCMOO0 SszZPiFGAY/TJ5aRrNbm+pYEz8Nwo1dAMyQ/lxDc5qcIEjqAk0jqt+exCSR66bJusvJL4o2n3yccU PCsEVloJb8iSO/6asaivtNiJLUpY0xsb9fEKQzYQE+f81FKp3K9LNQoeDsTouCUWOA4/mTVfve9hP EPhxY3/dQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ju6fh-0001Zk-ND; Sat, 11 Jul 2020 03:59:29 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ju6fa-0001Tx-Rs for linux-arm-kernel@lists.infradead.org; Sat, 11 Jul 2020 03:59:24 +0000 Received: by mail-pj1-x1044.google.com with SMTP id f16so3441005pjt.0 for ; Fri, 10 Jul 2020 20:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=P9MdyjVmHGjCLFd0myvGNT7BnRX3ygM0xdoKm/Ke/yY=; b=OCGtNKv0K4oDex1LzcuU+H5ZX76sTLShGnUcL9b36TQHeg3xbV6WkQgdMY9YVcpQ5i M8uXX+kjRjByWZNr8CgbQkEvnu3xP9SjNb5qMqTnjgiynqfGtrHJKMTGWTp4WZiYZ8Um zfwDpSnA6sFHCy6wMJYCreoMknhufE+qPeTdXneRp1mUWyOtqrofcJf/ZJrlTvBJ5LE/ vuV9MfwJ+USJ8aIBta8yKYbf/tC02W3Eho0XKDqWMgqgxgSS2N3uwcKPFFJLC/TFLKGt lv4cVafzWSoDTps9H7QoWxLaxybqJJxK1KnfFQwN+tG/gvV7wCENPgacFK/3lUfb6Sq4 UUxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=P9MdyjVmHGjCLFd0myvGNT7BnRX3ygM0xdoKm/Ke/yY=; b=Uv5OkqsLqgqKnAPjllPaDb5h+xBNaxr8nPJquAho365ekEkZw+PR30uenupGmzJEi2 gpuKKxCiw8VtXh2w7+7xK5Vu8q8+l/Ff0CCWZw5GNOOGSWYZ7YwI6npVcr/sbuhBOndc oMoag3sdwH6z6JhrWsd/sWwMx5Jf+Q/BJ2cMU9PIn1C7P/a17AzdRGF9WGmSxFHdr+rb KJNTPlffMH4L9w8yNOtOtu031Rp42u1gcFQSs1+i7qINZkH0jAlSQgyp2hIx874dEAax LyS3bQ3BhgFcEsVpBMnXVwUTLHzNU96951/KHu+mYsSU7JO7P4xq0LR8F5GN0tJkVF9b Wcog== X-Gm-Message-State: AOAM532ekdhgmwYN8g07+T3nVT65OKjLqzLnrHb71ggWsKB+xShwtDDF jdmvoVUMz3OEOOgdmmlf/FVYBw== X-Google-Smtp-Source: ABdhPJwxW+RayJdKkQ+JS7dT23gKNMK/oVXiknZXTWv/h3U+LQOqYbYRHyKYc4j42/P36M4Hzv2Mdg== X-Received: by 2002:a17:902:b084:: with SMTP id p4mr37584442plr.58.1594439960312; Fri, 10 Jul 2020 20:59:20 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id bx18sm7168249pjb.49.2020.07.10.20.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 20:59:19 -0700 (PDT) Subject: [PATCH 1/3] lib: Add a generic copy_oldmem_page() Date: Fri, 10 Jul 2020 20:55:42 -0700 Message-Id: <20200711035544.2832154-2-palmer@dabbelt.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog In-Reply-To: <20200711035544.2832154-1-palmer@dabbelt.com> References: <20200711035544.2832154-1-palmer@dabbelt.com> MIME-Version: 1.0 From: Palmer Dabbelt To: mick@ics.forth.gr X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200710_235923_095182_46A4D800 X-CRM114-Status: GOOD ( 22.89 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1044 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, gregory.0xf0@gmail.com, peterz@infradead.org, catalin.marinas@arm.com, linus.walleij@linaro.org, Palmer Dabbelt , brendanhiggins@google.com, elver@google.com, glider@google.com, krzk@kernel.org, mchehab+samsung@kernel.org, will@kernel.org, mingo@kernel.org, uwe@kleine-koenig.org, takahiro.akashi@linaro.org, paulmck@kernel.org, masahiroy@kernel.org, linux@armlinux.org.uk, willy@infradead.org, rppt@linux.ibm.com, bgolaszewski@baylibre.com, kernel-team@android.com, pmladek@suse.com, zaslonko@linux.ibm.com, keescook@chromium.org, Arnd Bergmann , broonie@kernel.org, matti.vaittinen@fi.rohmeurope.com, ben-linux@fluff.org, dan.j.williams@intel.com, linux-arm-kernel@lists.infradead.org, davidgow@google.com, rdunlap@infradead.org, Nick Desaulniers , linux-kernel@vger.kernel.org, mhiramat@kernel.org, ardb@kernel.org, akpm@linux-foundation.org, davem@davemloft.net Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Palmer Dabbelt A version of this that is identical to the arm64 version was recently copied into the RISC-V port while adding kexec() support. Instead I'd like to put a shared copy in lib/ and use it from the various ports. Signed-off-by: Palmer Dabbelt --- lib/Kconfig | 3 +++ lib/Makefile | 2 ++ lib/copy_oldmem_page.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/copy_oldmem_page.c diff --git a/lib/Kconfig b/lib/Kconfig index df3f3da95990..25544abc9547 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -676,3 +676,6 @@ config GENERIC_LIB_CMPDI2 config GENERIC_LIB_UCMPDI2 bool + +config GENERIC_LIB_COPY_OLDMEM_PAGE + bool diff --git a/lib/Makefile b/lib/Makefile index b1c42c10073b..30d57d8b32b1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -318,3 +318,5 @@ obj-$(CONFIG_OBJAGG) += objagg.o # KUnit tests obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o + +obj-$(CONFIG_GENERIC_LIB_COPY_OLDMEM_PAGE) += copy_oldmem_page.o diff --git a/lib/copy_oldmem_page.c b/lib/copy_oldmem_page.c new file mode 100644 index 000000000000..f0090027218a --- /dev/null +++ b/lib/copy_oldmem_page.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Routines for doing kexec-based kdump + * + * Originally part of arch/arm64/kernel/crash_dump.c + * Copyright (C) 2017 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include + +/** + * copy_oldmem_page() - copy one page from old kernel memory + * @pfn: page frame number to be copied + * @buf: buffer where the copied page is placed + * @csize: number of bytes to copy + * @offset: offset in bytes into the page + * @userbuf: if set, @buf is in a user address space + * + * This function copies one page from old kernel memory into buffer pointed by + * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes + * copied or negative error in case of failure. + */ +ssize_t copy_oldmem_page(unsigned long pfn, char *buf, + size_t csize, unsigned long offset, + int userbuf) +{ + void *vaddr; + + if (!csize) + return 0; + + vaddr = memremap(__pfn_to_phys(pfn), PAGE_SIZE, MEMREMAP_WB); + if (!vaddr) + return -ENOMEM; + + if (userbuf) { + if (copy_to_user((char __user *)buf, vaddr + offset, csize)) { + memunmap(vaddr); + return -EFAULT; + } + } else { + memcpy(buf, vaddr + offset, csize); + } + + memunmap(vaddr); + + return csize; +}