From patchwork Fri Sep 28 06:48:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4403314BD for ; Fri, 28 Sep 2018 06:49:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 339E12AE79 for ; Fri, 28 Sep 2018 06:49:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 245A12AEA5; Fri, 28 Sep 2018 06:49:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60B972AE79 for ; Fri, 28 Sep 2018 06:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=puD4HUq9mcayCoa11e1LHXJQNsx/P00ZqWJaoqMb/9A=; b=LeFe08lxBpfjK0 H95J/KTWMcxcklHNUMt7nXQ5+J7NgzefIuLjEBrcbtTEDYStHsrqFpeK4sown3RNoW6quvCPpgjVw nuu7k3bllD0dWNx3CzGMUTHuMm1Xbya3XJ0wxLpsifzybjJxZaCQHUmgBg700z+1Z15ZWxSJCMfN0 XGdexGME2/dlxFlxk5mOlARj3OqRxkasLz1KIon+jpRo6hm5PEwtnsU2BTMxLW5Z3Fwa2A03VcOav 6gw95f9tfbJ3plhsWE4Ucoflh8AmrSAup/eCYYbxOIg6WLWlYxOsld4l3aOehmeNeaZSuXcy5QPwF I3WKYiqTAl/pMsM1FN+Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5man-0004tg-AL; Fri, 28 Sep 2018 06:49:37 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mZc-0004er-I2 for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:26 +0000 Received: by mail-pf1-x442.google.com with SMTP id m77-v6so3620868pfi.8 for ; Thu, 27 Sep 2018 23:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p7VTwSew5JIQjBLJLLspuwEGyotzVxuUjhT6Cc4QWEY=; b=bFPgt1tplsXabUlQ6hCzj2urb7BtDmJeuUmQva+Qncik1zkUYv5VHI6lhF9oOye8/v Y+S8c0we9UP5r2SRWTJPjX3n6RRhyhpPNrtbFUtyk0LpbSHuAhLhWx3E0PCMQvFW8dky /BDwKAUo+vJkN8g49u451SCfEhAxV+z5uq9VI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p7VTwSew5JIQjBLJLLspuwEGyotzVxuUjhT6Cc4QWEY=; b=VCchFcmyWcI6l8AQMFt3z0eLiCOFpSkjq6GVJAWiRxJQJpO/p0ltMAbIhf7fsTVCwU 0ezMPTwzqNggHJQZZJCYDiQofOyZeUIHXuf7p/0Wsb6RObgAj3irQk+4FbXVKoi1ICv5 VhI3DI7CezfqGEbIuUI6gjUCADDurvIHyTeC8+0rVldqY6C5Hx9JZWhXf6niq3PySKw4 JW5gX5IG4Fp1iEdFg9GMMBGXzZ3eLcWIC2CnOs+pFoEjhXc8d57GGkr8vFfSxFDICcA/ aQGrh0oVPYlw5uheSHKm0ir72MJQoo8TcCn56bOmNyx5vcA8h0Wg7sT/vgQ1S/kAv10O OMVQ== X-Gm-Message-State: ABuFfogG0O78lpSXzmQ3Z2uNsfDPzTNRcqMXoxY0e8QkNyRJDLGMi1eg eCfglFpYCCV0KhmGVN4ICH0MfA== X-Google-Smtp-Source: ACcGV60VsEfy4rHhSlzP39UhpLCxpTClvNHcMNcg8Na087wbleYoeOwk+QV8NKrRCfjQRYnCHYZgfw== X-Received: by 2002:a62:3644:: with SMTP id d65-v6mr15022082pfa.133.1538117279596; Thu, 27 Sep 2018 23:47:59 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f6-v6sm5312638pgf.52.2018.09.27.23.47.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:47:58 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Fri, 28 Sep 2018 15:48:26 +0900 Message-Id: <20180928064841.14117-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234824_674226_62D5ABDC X-CRM114-Status: GOOD ( 11.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The initial user of this system call number is arm64. Signed-off-by: AKASHI Takahiro Acked-by: Arnd Bergmann --- include/uapi/asm-generic/unistd.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index df4bedb9b01c..acea91e49523 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -736,9 +736,11 @@ __SYSCALL(__NR_statx, sys_statx) __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) #define __NR_rseq 293 __SYSCALL(__NR_rseq, sys_rseq) +#define __NR_kexec_file_load 294 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 294 +#define __NR_syscalls 295 /* * 32 bit systems traditionally used different From patchwork Fri Sep 28 06:48:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E365C15A6 for ; Fri, 28 Sep 2018 06:56:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5DE72AEAD for ; Fri, 28 Sep 2018 06:56:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C91D72AF28; Fri, 28 Sep 2018 06:56:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 041B52AEAD for ; Fri, 28 Sep 2018 06:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wyy4GUy6TdCN+AxjpRVKBQdlAa1zP6iusUVwKZ0iSJ8=; b=dClALSrez3r2/I vd3BNfUstwJ3g5AYbvQXqlytg5ss7hwidtw0WqdbwiLlwPqUYP+8I6k+jEGE7H4lamTrwe+Tfdftc 1oDJ1+6bvY/V+Hn5lct5CWh14FKtmrHneVPLyvoie/RRXqGkNs61322PyXOlHdzX1hbDZ4jT/+8go QxDnNDFr4aG0xttIlH64EC3Ak4xO0ntCns3OEKTtjV2e28yL1BDNDCikur6cq/DHOkSMYSbcnJHSX 2AaS3bpbXf9wMKOpedxCxJzm1SJ/IwioWdscvaT3MQz50eEomVL/Te3AZDLKbGzrvrSOVfae+LVni OXQjuu3w5JeXjYkgW8mw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mhm-0002hf-AL; Fri, 28 Sep 2018 06:56:50 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mZo-0004fB-KR for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:42 +0000 Received: by mail-pg1-x52d.google.com with SMTP id r77-v6so3734418pgr.5 for ; Thu, 27 Sep 2018 23:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SFnjB8OZwPCkN/cF+2XtrYPYnwjUqNvYjNJ7CAWxc5o=; b=NOu5gWVY0xlMpxIclXnxjYR6bEPT29dU0ZklbtpXSY5Ypq8qCjjvQMi2SgJVNEJjEP YjEWlJKbjI/9XcoxOVGYN5Q1V5+A2MHBdjMa4vVEreAt9quWR2PwMrjes2N0vi6SeW66 3wKxN/9fSi1KQdhlDw7G7H7TV99dhfTxGOYoQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SFnjB8OZwPCkN/cF+2XtrYPYnwjUqNvYjNJ7CAWxc5o=; b=OlkO/5Fho4tW5F12mzcpHSZFI9qnxC2DR7EBxyqvQgNPJOdKJPgORIkamaTHNc/KWM JXu/gdZbFvsj3b0V3kmOs+XFp13Iuqt9ysyDyw+6R8htS5/BeSthRCUP2UrVNilhcb4Z NuKQuaxncVTedVsrJ5zBXZ+NPrTC6ujLTJSlKZq1A7D0Is+ybn5OOjP8x614mnl3lSog TG142WrERrGITLaM4Etpghmvpvx3MyTW5MKZuniim7cHLQ6UNyZKlRb9ovuNRf5m0qxB NMRhP9L+IAqNWOhW/xkMKohoBQ/YogCpHniO/atohT4UqO3E6Najs6pCQjimlditeIZh YvlA== X-Gm-Message-State: ABuFfoi7jK70HztAMNi1rZmHpRKNAdiSiubydEpzHJfYWKrfryaPUeRr oDFFnOq957cUiBqGMM1THOoAcA== X-Google-Smtp-Source: ACcGV62wHSCQDbe2gCAXySgK0gjx4k7VnV1SvMRCcldq9IaLlCj1mgGONJsIMITlezJ/ohUP9yWyoA== X-Received: by 2002:aa7:8895:: with SMTP id l21-v6mr2833137pfo.74.1538117284863; Thu, 27 Sep 2018 23:48:04 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a1-v6sm9770651pfc.28.2018.09.27.23.48.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:03 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Fri, 28 Sep 2018 15:48:27 +0900 Message-Id: <20180928064841.14117-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234836_725039_E0227C02 X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Change this function from static to global so that arm64 can implement its own arch_kimage_file_post_load_cleanup() later using kexec_image_post_load_cleanup_default(). Signed-off-by: AKASHI Takahiro Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- include/linux/kexec.h | 1 + kernel/kexec_file.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e4e638fb505..49ab758f4d91 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -143,6 +143,7 @@ extern const struct kexec_file_ops * const kexec_file_loaders[]; int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); +int kexec_image_post_load_cleanup_default(struct kimage *image); /** * struct kexec_buf - parameters for finding a place for a buffer in memory diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index c6a3b6851372..63c7ce1c0c3e 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -78,7 +78,7 @@ void * __weak arch_kexec_kernel_image_load(struct kimage *image) return kexec_image_load_default(image); } -static int kexec_image_post_load_cleanup_default(struct kimage *image) +int kexec_image_post_load_cleanup_default(struct kimage *image) { if (!image->fops || !image->fops->cleanup) return 0; From patchwork Fri Sep 28 06:48:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D8EC15A6 for ; Fri, 28 Sep 2018 06:57:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E64F2AF81 for ; Fri, 28 Sep 2018 06:57:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80CDB2AF96; Fri, 28 Sep 2018 06:57:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E95A2AF81 for ; Fri, 28 Sep 2018 06:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nJYlyHd2olJNFHBEpzQ/s1mE8RnRouwWA2zJLnzgTG8=; b=uxSxTjq/Xb4H1t 2856Eb2OheAJuDUipvsDoa+Wk2+WHUCM3UMPY+Hu7VDKQAcZ2R6SKfk+HQIhvcdtaewDm1kmboOGi 2PB7fh53al625ExpJYB11xNaePpPLCoCRUh8d3ZlJUEz3hRjEUEe5lTbKM1zrQsGg+D9uugSBtlnI +64uAzHrUjWFabIQHhVkKdrvmhkit6WarSqu5482+R2boZp3refg/YYDfmgAU8m+s/AiqeSq/HA22 HH1dDHEljHBmkwebGiplzRY1kHEpPjokgnrgfNaLQe6kQag/xyW7ogrrQGkXhPdVuG7aG39Ozctnl XXnXWFfbBRgcJ5U2LQ3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5miT-0002zS-PX; Fri, 28 Sep 2018 06:57:33 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mZo-0004fK-Ft for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:42 +0000 Received: by mail-pg1-x530.google.com with SMTP id v133-v6so3744153pgb.2 for ; Thu, 27 Sep 2018 23:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GkP10Cl5MP4nxVesufI8pOCjA8cWm/ywpOEKb9ueudc=; b=IkRQaACFLS0lvXgRp3LiGqnUuHtzQt5Y9M7/3TW1yIkM8S+qtrisT+jwz/Z+t5Mtt6 EwAYVYbezOlY0HkVAPEh813zdFagQ85MAMNEph2blAqjyEocIINOAM1T8nVMc2kK+wSs lYdOPoCwYjU5W4wPToawZjAor310uRDhp2A/c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GkP10Cl5MP4nxVesufI8pOCjA8cWm/ywpOEKb9ueudc=; b=cfrc9PNBobqgzvuSnP3SOBwcWPZqbtz7LZeFLeolSI1G66Bunm+ExdsAD2pEBFCPCu 8CrXzOpTzv31pFzhMRsKkTggR1/744TaizwMuBKzORQRV/OxBLYoHIEhmNNn5tIGuueV LO2DBteFrs82fXLy20ZVf23sTORPCR6O2sY5dmPXO8yWDexoAo9KZkdlayO7/C/NSTzN CHVaQUbUDxBZsPzIS36nosJ4xk2gZDvzEMwWK19q1Ulv0SHASGZp1n6GMieNATFn6TKr zbuhYPxLGvY0oTHa8gNKu7CSu/XDNkHTESTZA7KeChIf9bnn8TpMM8oLkjaZBUOMqg9f TyNw== X-Gm-Message-State: ABuFfoj9ntC1guWvJOHcWajiD4187j7BzxF9Y3iHp3sxFRaIFbo/8097 dbNSlDHNFt4X/DzOa6Jfmu/wYg== X-Google-Smtp-Source: ACcGV63YSylKyCjjqizFkyw8WfxTANncmJVizh2MBUkwGi/GB112j0mSsGtUxJMIwL8i7lNilwkwQA== X-Received: by 2002:a17:902:543:: with SMTP id 61-v6mr14871971plf.126.1538117289637; Thu, 27 Sep 2018 23:48:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e68-v6sm7165147pfg.93.2018.09.27.23.48.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:08 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Fri, 28 Sep 2018 15:48:28 +0900 Message-Id: <20180928064841.14117-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234836_573556_A469EDFE X-CRM114-Status: GOOD ( 15.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since s390 already knows where to locate buffers, calling arch_kexec_mem_walk() has no sense. So we can just drop it as kbuf->mem indicates this while all other architectures sets it to 0 initially. This change is a preparatory work for the next patch, where all the variant memory walks, either on system resource or memblock, will be put in one common place so that it will satisfy all the architectures' need. Signed-off-by: AKASHI Takahiro Reviewed-by: Philipp Rudo Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- include/linux/kexec.h | 8 ++++++++ kernel/kexec_file.c | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index f413f57f8d20..32023b4f9dc0 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -134,16 +134,6 @@ int kexec_file_add_initrd(struct kimage *image, struct s390_load_data *data, return ret; } -/* - * The kernel is loaded to a fixed location. Turn off kexec_locate_mem_hole - * and provide kbuf->mem by hand. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - return 1; -} - int arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 49ab758f4d91..f378cb786f1b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -145,6 +145,14 @@ int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); int kexec_image_post_load_cleanup_default(struct kimage *image); +/* + * If kexec_buf.mem is set to this value, kexec_locate_mem_hole() + * will try to allocate free memory. Arch may overwrite it. + */ +#ifndef KEXEC_BUF_MEM_UNKNOWN +#define KEXEC_BUF_MEM_UNKNOWN 0 +#endif + /** * struct kexec_buf - parameters for finding a place for a buffer in memory * @image: kexec image in which memory to search. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..0fcaa86219d1 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -534,6 +534,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) { int ret; + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Fri Sep 28 06:48:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC36B14BD for ; Fri, 28 Sep 2018 06:52:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C46C2AC41 for ; Fri, 28 Sep 2018 06:52:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FFF22AEAD; Fri, 28 Sep 2018 06:52:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 447752AC41 for ; Fri, 28 Sep 2018 06:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kMqp5K2JhgEzHKFyLEMH3fwR/hhrzssox9Du0VDzExI=; b=OknxSVlknqrYOV ATfBGk2HAIGJ8e42bt79mX1GKoHT/KDiCFmwFDiI/YKIvfnzYGwZhtJi13iEwyx0x31QnCbVFGHC6 2SrFIRHu1r1EmVkEFCLlWDEfM07Pb7UmRhYd3pEC7RAEp0vuaC+Pb74HERT60XdlnTEwWV9fQHusx /AypoJJmsl8AkCLqHVZH4NADpu875mNTPhA9IdXoKzoCZRPzlA2bKVM4xkOBs4XGEoT2CyAYdzDcf y2IBuoyFTCScX8MDgXSXxbAuk22b9gPv4YGv1f3d/aLVwKBdzuqXmeY5uy794uAlLEA7YOy4zodaB KhBKu84bavOWn2rFibfg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mdp-0006xM-7p; Fri, 28 Sep 2018 06:52:45 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mZn-0004fX-DM for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:38 +0000 Received: by mail-pg1-x543.google.com with SMTP id t70-v6so3705491pgd.12 for ; Thu, 27 Sep 2018 23:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QZGnKdcuU+QxzJqLLsvEp1lZ/3WCKPgonwBfWd5z9t4=; b=GMRI5rLStlj7z2WUaq7i+r7ic6z6h9eBlRzw1ReZKo6ppfjuzhpOVMpKl9vprH6VwN 5YcbxBbgpvKbosfXHGoKfpemYdL0BN7elOum100H/l032dciAePfu9SaOGOm3ge+QBUD hOMbaE4k29aNaEyiAz7RgfdHQndFToGVjTWg0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QZGnKdcuU+QxzJqLLsvEp1lZ/3WCKPgonwBfWd5z9t4=; b=le1Dv8UqheV1OsDCjSknRjCj7cS9yLwEjB6ezr1Yc75IV9HdHijgl1xFeYU7LAth8e v8RT3zJOm/RMvo7JB5Ub8aJTr+EguPp9tjGgIVlE5jzjeqAa9dIttu58quVKuUQIzfXd HlT4CY9Qcui7jTYcgpK9rgZvi0QsBoE8vRqO3ce63d9dSxSxTZXcSWQuDu8wcVqVWFfC jSDxMHtU+elUL06tpsy+x9cw5SViFrUpL4+CxXQ/DUABhlHYoLDiudz1W/IpcUn+wwBj x1NENrs7emz378+8TTE0Ylp+QTfhvMZIvhhYBGG2STaCW1VCj7+e526DNUoKYXtR1qsA KcPA== X-Gm-Message-State: ABuFfojjmXJHH+orKkaMLVuDGHrcDaHxhZsTJbK8LVi0IfVqU9FxxBb0 jpOeDh47eOC7cjzAApqJJKzPYA== X-Google-Smtp-Source: ACcGV60hOVJhKow090m9gV1tRuAWrEwsTwmj1D+hKDv7AIlOo6DzcC1cpKc1P2dudikauUyntADAVQ== X-Received: by 2002:a17:902:5a0f:: with SMTP id q15-v6mr14788388pli.253.1538117293618; Thu, 27 Sep 2018 23:48:13 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d7-v6sm1761775pfm.23.2018.09.27.23.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:12 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Fri, 28 Sep 2018 15:48:29 +0900 Message-Id: <20180928064841.14117-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234835_495438_6EA69030 X-CRM114-Status: GOOD ( 18.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, "Eric W. Biederman" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Memblock list is another source for usable system memory layout. So move powerpc's arch_kexec_walk_mem() to common code so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and integrated into kexec_locate_mem_hole(), which will now be usable for all architectures with no need for overriding arch_kexec_walk_mem(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------- include/linux/kexec.h | 2 - kernel/kexec_file.c | 60 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 59 deletions(-) diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index c77e95e9b384..0d20c7ad40fa 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index f378cb786f1b..d58d1f2fab10 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -192,8 +192,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 0fcaa86219d1..370d7eab49fe 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -510,8 +560,8 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) * and that value will be returned. If all free regions are visited without * func returning non-zero, then zero will be returned. */ -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) +static int kexec_walk_resources(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, @@ -538,7 +588,11 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Fri Sep 28 06:48:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2BAC174A for ; Fri, 28 Sep 2018 07:00:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A30D02B005 for ; Fri, 28 Sep 2018 07:00:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9726F2B00C; Fri, 28 Sep 2018 07:00:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2F882B005 for ; Fri, 28 Sep 2018 07:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VnHBWioLT0aD7857xJTclTmJCHM8DrMEVJw0ijZHFzM=; b=iOe4laB7JCmMck A0VjyIhFAMWG0utYfnQvmeoTRv/XlwKeuIjd6XtQ9M5XqF5pUNsV2MWh0tj4Ueu3dH85dkfYa7klM BmhL7V89EaPXAw2Ev+2qcmYbb/KcO0+g+AQDNLOpyFbf2n5jqF15G1PAF4VPMibbRumGPgrTDMnO/ CVUQMSzuZlkvNb8iUcPmR5hAeIFtpSSPiZ4DWaiCDIk5og/l4joYPsmse6YWjEZqmKYqeEkapJdVo 7RQW/GNabJuJSZiEEBcdQR/nlr04di6NvSC1FdKu5afAOCxIDGIk9dnFqmEep02c97aN6jL6916c7 reV238sxg1KYespguauA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mlJ-0004Dw-KD; Fri, 28 Sep 2018 07:00:29 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5ma0-0004fi-UJ for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:55 +0000 Received: by mail-pf1-x444.google.com with SMTP id b7-v6so3640051pfo.3 for ; Thu, 27 Sep 2018 23:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7lEK32bpyfZBbvzr+AgaMH3E2lcp0Tdtbfmv5MlM7pE=; b=Kk2MuAr2ZxQGAFTckoI4a3OJjqCm/d1ykOA9ozVI2d5mQlhjrcGdC9cRGkw13D3b5+ luxQvhuNtGsEi3sx4uVzGEz+tkO982AHPYPk2EFmfsZAQmC6Xwqt/4DxGwu7a7IsX9bz fTR41f4878GBeepJZeruzkxW8PtyUjdFaHlW8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7lEK32bpyfZBbvzr+AgaMH3E2lcp0Tdtbfmv5MlM7pE=; b=JP8jWrJ1nXuh4jHHsHZPs9/I/7XibH02lQIa8EiC0cE2jQpjeznbiX8vSMrqsK+G2A dAn09pWtbL6/x//5DXAl27810zZa85DFTV/WTFA1D+JMxZBN2HjCoKun8NnSTKA0kKaj 9bZil4S+s2QaPWlZwTwwZaxxpj8liBGxXhk4Bugo23d5QyIJSOYewfQk2hQ6ivjB7bzg AH1hP7+HnqROW4bdVyQOFvcze+iL7IUqIBkgbFmDkKzVQe8W9fnG1/1lO8IzlxoXFOtK 2hnkQ1sgd4fADIJ8nryUAKFqLph2y2HzrmhkvLOGBlTMIzRpmdKjxUpYcsplqt/fCxu0 ZZmg== X-Gm-Message-State: ABuFfohMvxgFT2XrLbrhC193xzs8Jm5YSV4REIp3HmQvdnjYyZzrcSE6 gGbwtajbLxg0MVYvTkvN4MVmug== X-Google-Smtp-Source: ACcGV60sTkh7k8gMS6cAMiFFQ89lfpIQtHaRo1p9d7THHcKbHldE5LM41g64aklBZ3NQ4VGGQtkkpQ== X-Received: by 2002:a17:902:9045:: with SMTP id w5-v6mr14943273plz.10.1538117298309; Thu, 27 Sep 2018 23:48:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h12-v6sm5847448pfo.135.2018.09.27.23.48.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:17 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Fri, 28 Sep 2018 15:48:30 +0900 Message-Id: <20180928064841.14117-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234849_062460_97CEA7C2 X-CRM114-Status: GOOD ( 13.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In kdump case, there exists only one dedicated memblock region as usable memory (crashk_res). With this patch, kexec_walk_memblock() runs a given callback function on this region. Cosmetic change: 0 to MEMBLOCK_NONE at for_each_free_mem_range*() Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: Dave Young --- kernel/kexec_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 370d7eab49fe..2f615a7968dd 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,8 +511,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the @@ -526,8 +529,8 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, break; } } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, + &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the * range while in kexec, end points to the last byte From patchwork Fri Sep 28 06:48:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 089F6913 for ; Fri, 28 Sep 2018 06:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8902B009 for ; Fri, 28 Sep 2018 06:59:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1D362B005; Fri, 28 Sep 2018 06:59:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F26842B005 for ; Fri, 28 Sep 2018 06:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uUkxX81w8WW03EH+EfktsB+Hj2BxiiRHlyZ6Y9lS7vg=; b=oWX5H4lEomAvnH J+vCVGY9lPJtk3IYUrGQ4p8pl3CCXGVHL4eYwqcwELmS2VnMqlKbB1wR9V8mn1KOXZwo6mPnqOgeh he+W1G4kW0HQE3Nj5rAbvA8AaE3wArtcQDOMENx92SRi8kzMA5KaKwJS4cyoIGnhSHpFVp2JeJDX9 qtpzu0PBFPrzVdfROtUSWSwwA3pfw+m8HRITtCyBi2zgCLjDWo1vuQ3XqX4DIlgbw7wTxzFHRKC+i +F6jrGF5jG0ZlJg1Vi6qk6MjDeG/iI42uW9LQqJMvVv5ylXJRX+6Et0AuX2HXY/vj49SXv+rqnzej g8wdbUfYlTSU8Zmf7CDA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mk3-0003i2-Hb; Fri, 28 Sep 2018 06:59:11 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5ma0-0004fu-QQ for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:51 +0000 Received: by mail-pg1-x543.google.com with SMTP id q19-v6so3715339pgn.10 for ; Thu, 27 Sep 2018 23:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pt0GdTUj/ouoBc0plwl0qxBtF8IeFfWdoXUu09cJo+Q=; b=a1qa43cUD3aEMCBBW+bPEPzCN0FPKwq7mNCLZT1Q8/I1oH07mIv3ms6vWZ0nRdjueB RWCSvRKjgb6jdgEZYiv0PSwrzd6TycaifX8EGVal+obfRXgDcaEMCtDQq3NzhlXgp3jV +q/uY98I7cnuQEWg2SjjZxoM4ZG3JndQxgZNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pt0GdTUj/ouoBc0plwl0qxBtF8IeFfWdoXUu09cJo+Q=; b=kl/qbZvulawXr8th2IDiqbXI6SpUV9esDdi7kCk+IU4mfBTnAB2R5vC5gX/RpJLBrX LdG28Tef/u8kJtEqZdJjww7rWirHi77sQjd2fRGIQFSLfZQBMBYYRLZD1rdFLDLUpQdB 0cqSboghgb9QBqzSVg28aEEDuruakYIhBSt879z3iAh3PPMibkOh5VCrDD/42EIT0e7S L5SUmNFKOGiHGzHwY9tXkmqeW20LGxHB/kcB6wmC3/mqyXtMponQaN+/QEe6i3WQMEjg EK+rP7KAOaJCUlyMDAX2PTfjIdS/0gx9OnX3hBte23Ysf7UJk7hSmw17hoxQHz7DMOM0 ZaqA== X-Gm-Message-State: ABuFfoh5bBaDa18My9NKoXZqqpOi+NGJjEwuru2kKw7AVVTNy9kUrCHA plvZeByorTW7pmi52/8KbqPWi+oi3Lg= X-Google-Smtp-Source: ACcGV6132QMgaHUkEnzpOJ34vEDqPCuVCNDWxwxsgSM4vQASkor4Pf8KuOATk2NREZeo2zXkL7a4ZA== X-Received: by 2002:a17:902:a40e:: with SMTP id p14-v6mr1085759plq.338.1538117302650; Thu, 27 Sep 2018 23:48:22 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 89-v6sm9522313pfk.134.2018.09.27.23.48.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:21 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 06/16] of/fdt: add helper functions for handling properties Date: Fri, 28 Sep 2018 15:48:31 +0900 Message-Id: <20180928064841.14117-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234848_902926_269AD026 X-CRM114-Status: GOOD ( 12.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP These functions will be used later to handle kexec-specific properties in arm64's kexec_file implementation. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org --- drivers/of/fdt.c | 56 ++++++++++++++++++++++++++++++++++++++++++ include/linux/of_fdt.h | 4 +++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 800ad252cf9c..c65c31562ccb 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -1323,3 +1324,58 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32((val64 >> (32 * (--cells))) & U32_MAX); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + int addr_cells, size_cells; + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + addr_cells = fdt_address_cells(fdt, 0); + if (addr_cells < 0) + return addr_cells; + size_cells = fdt_size_cells(fdt, 0); + if (size_cells < 0) + return size_cells; + + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((addr_cells == 1) && (addr > U32_MAX)) + return -FDT_ERR_BADVALUE; + + if ((size_cells == 1) && (size > U32_MAX)) + return -FDT_ERR_BADVALUE; + + buf_size = (addr_cells + size_cells) * sizeof(u32); + prop = buf; + + fill_property(prop, addr, addr_cells); + prop += addr_cells * sizeof(u32); + + fill_property(prop, size, size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b9cd9ebdf9b9..842af6ea92ea 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -108,5 +108,9 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +int fdt_prop_len(const char *prop_name, int len); +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */ From patchwork Fri Sep 28 06:48:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33F9915A6 for ; Fri, 28 Sep 2018 06:58:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2376E2AFE0 for ; Fri, 28 Sep 2018 06:58:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 132132AFEE; Fri, 28 Sep 2018 06:58:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B5372AFE0 for ; Fri, 28 Sep 2018 06:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vrSBMch5A1BYJC0XTkJqn8CDrWNZKW4SO8awZo43tQY=; b=Qy+b3/wBG1G+/C b5xO+zXRdWcePFP9+U9nKo+1VgctX0Up4CLvmgKfK4Kc5qZANz6/X4lLNFsRxDPVRnk18EnKgRzNf gkltBTBT4GiIY3zZSf/ght0th1UbUhkAb0EhNDLYk8QXI91wcKrC7IlwcMB04WJ4wUNaPedqjt8j3 f87P1oq49g3oRINWFMS2JZH6onm9B5QEjynF1sDP9JJXeH0f6p481aQb8y0IzzJZ9jJhvl5CvUN2m l3dLmLNCzHvKeK6MyYUPk++JSngXsDdyxYDcn1c/SZKjV2oeaGLhejiRrrJ5oWHGPo8OfubUSIuhk X3Jh/1itBlpEjzRo41cw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mjD-0003Hs-1X; Fri, 28 Sep 2018 06:58:19 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5ma0-0004gx-QK for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:51 +0000 Received: by mail-pg1-x543.google.com with SMTP id z3-v6so3720059pgv.8 for ; Thu, 27 Sep 2018 23:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PN5LeK8svtoziSd5ZB0HR3YbxUdhrZV+lLkgGkSy5ww=; b=Sr+o5pxeVXKOqw06DTNMIn4lVoKNr0kR4J9mRDFNopsLcBVTUokarh6DZcfsqDq0QC OFUT3k1jL133SZm3xC4fX3bXuVzu2TXeJOiVSRDTXzLuLjuV+vhNHNBPSMoCQPUanvUr P7wYBet1ILkC9dYZAI7aZV24GEykbffCAJv4w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PN5LeK8svtoziSd5ZB0HR3YbxUdhrZV+lLkgGkSy5ww=; b=NRVexTPmg7BMpiM+ramUhyBa/8PIJ3DM53ayizQs1XTcVb1L+hTugXndW9IwQbw4w3 n6Xu3t621q5yuKYterjuDejnET3NRBrP8/ZC09mV4Mm5D0AIZxdJuubDEPboDKTGgEq7 5snf9Fam2t8SCDVbQklaPiYBFR5Owe4sJRQgXB3+hrQG9zjnsniTA6cIA75txPRq3Bql yLbCKDB/QXJKS8euMMe0MrWtgBs4tdWiPvVsUJQ/6qtLo7N5BGn2P+wJHAb/mBsbczDp pi/leWaEQRngxgOWjuTo2huyKgias6YeAgDJvSwE9umrURkUjl1Ib6wutEy/bLKLITUT CX3g== X-Gm-Message-State: ABuFfojyeaWJr0YPojrG4iSqWqZgGA3agQrQp/ggzZ50Ss8zGNpfoEQ8 4N+Nc6+CBaTXWvBcULK/pq3AEg== X-Google-Smtp-Source: ACcGV62nBgWpFV+8q6H/25pGLwVOjlY7bVf20Tyu6xMawVDn02uriiocxqf19Yz2RVwaSmGyeQIiPQ== X-Received: by 2002:a17:902:c01:: with SMTP id 1-v6mr14301101pls.122.1538117307811; Thu, 27 Sep 2018 23:48:27 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 3-v6sm6995090pfq.10.2018.09.27.23.48.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:26 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 07/16] arm64: add image head flag definitions Date: Fri, 28 Sep 2018 15:48:32 +0900 Message-Id: <20180928064841.14117-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234848_896577_EF8B4324 X-CRM114-Status: GOOD ( 12.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Those image head's flags will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/include/asm/boot.h | 15 +++++++++++++++ arch/arm64/kernel/head.S | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/boot.h b/arch/arm64/include/asm/boot.h index 355e552a9175..0bab7eed3012 100644 --- a/arch/arm64/include/asm/boot.h +++ b/arch/arm64/include/asm/boot.h @@ -5,6 +5,21 @@ #include +#define ARM64_MAGIC "ARM\x64" + +#define HEAD_FLAG_BE_SHIFT 0 +#define HEAD_FLAG_PAGE_SIZE_SHIFT 1 +#define HEAD_FLAG_BE_MASK 0x1 +#define HEAD_FLAG_PAGE_SIZE_MASK 0x3 + +#define HEAD_FLAG_BE 1 +#define HEAD_FLAG_PAGE_SIZE_4K 1 +#define HEAD_FLAG_PAGE_SIZE_16K 2 +#define HEAD_FLAG_PAGE_SIZE_64K 3 + +#define head_flag_field(flags, field) \ + (((flags) >> field##_SHIFT) & field##_MASK) + /* * arm64 requires the DTB to be 8 byte aligned and * not exceed 2MB in size. diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b0853069702f..8cbac6232ed1 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -91,7 +91,7 @@ _head: .quad 0 // reserved .quad 0 // reserved .quad 0 // reserved - .ascii "ARM\x64" // Magic number + .ascii ARM64_MAGIC // Magic number #ifdef CONFIG_EFI .long pe_header - _head // Offset to the PE header. From patchwork Fri Sep 28 06:48:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB64515A6 for ; Fri, 28 Sep 2018 07:04:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBBB1284A5 for ; Fri, 28 Sep 2018 07:04:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFABC2B00C; Fri, 28 Sep 2018 07:04:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FF84284A5 for ; Fri, 28 Sep 2018 07:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Bz6pDXoqBFAvzrpQHrMOgUM0mOqP5sMcY8q2tTZN4No=; b=rjBOEJtqh5mTyF Ig3VDgziHRcy7dNEKarJ0WATPvH4YsszM6IfV7jZsanxVO/t0oqdzetg6WIfjVMrpNnO5LQ9PScfh 7ocxEgr8rVQqxNW8/1q6tUwDMxFtMHe/uNmJ7ikWqAgqS+Z6QKjrYGokBgem2lapvfoFzKA49uhbI PS79mJUTtE07Y3m/HbVIKq4eqeXJ8ydXVe+aa1aCQJtpxPlhBHO++iKs434ZnvIKJKpXRgkN1aUZL 5b7t1wdBkJQI4kj1WsG8sVVDudB+5EiTDuR86AsFPfON1RCvAXSt/Jc1MQzE+zmO26M+RmJ92sPJT +zSSP76XYCb19trCVnSA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mot-0005tt-G5; Fri, 28 Sep 2018 07:04:11 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5maF-0004iM-4n for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:49:05 +0000 Received: by mail-pg1-x543.google.com with SMTP id i4-v6so3117086pgq.9 for ; Thu, 27 Sep 2018 23:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4VJX5OtbVz8vzfF/CMl4UANq631qfAiD/HWUtm1wpWw=; b=MaprZxMEOptN6Y1PB4m8DaHjLUv1xwZglze7vHiCUBjtXFko9ADVOqvNtzuND72J6M yyckY2B3mKQKPzbxBQVTmVIbaPPw678THitZlBL9FdvrHCAq7Fm7knKejpDVshXvDsOC 9zlI5QDH9W7qxx4BpPrbX1kMrApuilWGjHMhk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4VJX5OtbVz8vzfF/CMl4UANq631qfAiD/HWUtm1wpWw=; b=EzvYL+quTcXRnYBml2g6BVY8htA/HAQ6WJtgREXZTxbyu5L3FkMaaqTQmy2QhY82S7 ChhpXda7q9jZZdsdkater0Ao5BpzfFXs6psSf7cZ3tbCTwLs1FpF8m8YO2SX7QXiT5OH 9cGYPLBgw77V10ew7U5QLuioT/3abjH3+u0TO31NO1ED0NPNVIrDFaEnnm97GJlM9NEk ExOCFZwSkHZzZaJUfUuKq4P2BIJjuIvTcSShoaGfJPI6hOCccYIfEry0Ano+brKhIi5Y NmQLM79L4wx8kBbTExGJbyVMVTfOlfDdlusFCPTkecze14eXF1+RRye4+oDAkadSAiNL N7BQ== X-Gm-Message-State: ABuFfogmFvuO0qyrJoWnsSGVBWN66jX4JmbfBX5CzC/cAhXeDXlGuYOJ 57rRBnyr3jLy0rZ5S1CNZ3dtfg== X-Google-Smtp-Source: ACcGV61QtLSWp926LY5pzkm6elmkTZCt0xy6fTGzQLd3zGU28eLKFCq0Oh6EqpyX4HWy33FrxfBfAQ== X-Received: by 2002:a62:384c:: with SMTP id f73-v6mr15351621pfa.242.1538117312657; Thu, 27 Sep 2018 23:48:32 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c85-v6sm5903582pfb.147.2018.09.27.23.48.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:31 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Fri, 28 Sep 2018 15:48:33 +0900 Message-Id: <20180928064841.14117-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234903_225840_BDB4C2F2 X-CRM114-Status: GOOD ( 10.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Those helper functions for MMFR0 register will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/cpufeature.h | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 1717ba1db35d..cd90b5252d6d 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -486,11 +486,59 @@ static inline bool system_supports_32bit_el0(void) return cpus_have_const_cap(ARM64_HAS_32BIT_EL0); } +static inline bool system_supports_4kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN4_SHIFT); + + return val == ID_AA64MMFR0_TGRAN4_SUPPORTED; +} + +static inline bool system_supports_64kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN64_SHIFT); + + return val == ID_AA64MMFR0_TGRAN64_SUPPORTED; +} + +static inline bool system_supports_16kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN16_SHIFT); + + return val == ID_AA64MMFR0_TGRAN16_SUPPORTED; +} + static inline bool system_supports_mixed_endian_el0(void) { return id_aa64mmfr0_mixed_endian_el0(read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1)); } +static inline bool system_supports_mixed_endian(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_BIGENDEL_SHIFT); + + return val == 0x1; +} + static inline bool system_supports_fpsimd(void) { return !cpus_have_const_cap(ARM64_HAS_NO_FPSIMD); From patchwork Fri Sep 28 06:48:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC01015A6 for ; Fri, 28 Sep 2018 07:07:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1DEE2AE9B for ; Fri, 28 Sep 2018 07:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93BF02B005; Fri, 28 Sep 2018 07:07:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D1A802AE9B for ; Fri, 28 Sep 2018 07:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HnPywlVy1aPzgXzMkN+I09mqKNe+fzVRWA5HrA6jAKs=; b=JH0RfPl0EGGcjn 5hM+QcFvxEmtc/01I3iaH2eVNeDpe0XAbTvGt6gbPS2YWsy3SeJE085cDZ74DVGBf56S0B0W4mgIX BbQqyzRleLeekJ03hR7Y008LAtw4gXFwmC+RFq/6OJIioZUm5E6FeK5XqvH0CKkc5+sQZvCS/iLH/ m+I1lP4p1U2HxNOAiZFhPeWgyGLuyKuQoqjxGqepyLNwnk+YLRdDNnQWWcJ1V6Ou4jO/z14no3m6X JCqqQsWixshCN6r2Gug/EVjNRbr4HNG1q515XUGjVi34jtIHsU3SWmyobRgVw5BR8yrkSlqWmbi3A q8gvBjJIg60CUwV+/9PQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mri-0007an-6C; Fri, 28 Sep 2018 07:07:06 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5maF-0004lh-7Y for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:49:08 +0000 Received: by mail-pf1-x441.google.com with SMTP id a23-v6so3604373pfi.12 for ; Thu, 27 Sep 2018 23:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N8QYerXEaqWdfHlNx6gpLi8IwzqsBwOqOFk9N60B1+Q=; b=Tc7XQ2hZJ6SjS4SXXcKYB/SZbNb8G/jmNJ+1vuqJYd6C/k6BbqE+edQSjeMnGiZs3Y A0VCZ/JHZhiBiB2/7MRSyB7FIRkKBkb47ALkfv9KmfCTbOszUQLURgCsckkyVtuljXOR T63PHJt3JR4e4MvygfII/ddGbUISN86QOFxSg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N8QYerXEaqWdfHlNx6gpLi8IwzqsBwOqOFk9N60B1+Q=; b=q22Yy/tf1X7QOwbdZwebVfkRCV0YPQimfGkfhnu7HxL4h9NiXl0T9G+gvOfKS87blj njJ3k07p5lIimmxc1FEMSvMvfM4bDg/fzG1JMlyZXOvpsHnz4IoPthgCnLdgeFhy3vBK 7AfceZeVUTqbK8X1adokUlnIS7nGFt4R7p/dtw3O9/AWfzfE67LeUibcXwnfnSXYYYTo H28MHyJ9VOqHGCMFUCwZSzN7c2WI2XLnaKYdRq7hvqYk/TM2t0K3UV2aQm1ipgWlVTka M7fyPfbALeGw+fuvujVvCyfe0gE/xva+bQpdc9hpqHjGXez4Zy2Lj1WeRNXaWuUOpsqu D2/Q== X-Gm-Message-State: ABuFfoj0ggFSPz/2v+/rkrPLL9/r3d7Ry6AcZpx2kHhVJHpgH0h+HM/f OrsYN1C/c4MTEofsFutnZ4rADw== X-Google-Smtp-Source: ACcGV60mPmG4AADbz/8T/ORk88Dmpu4qsOFHXgJ2s6jc32zlsjO64PKUhS8nPy+J/BF2GDfcl8kbdQ== X-Received: by 2002:a62:7501:: with SMTP id q1-v6mr15046736pfc.225.1538117320761; Thu, 27 Sep 2018 23:48:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m21-v6sm5869051pgd.6.2018.09.27.23.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:39 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 09/16] arm64: enable KEXEC_FILE config Date: Fri, 28 Sep 2018 15:48:34 +0900 Message-Id: <20180928064841.14117-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234903_368333_B26DD2AA X-CRM114-Status: GOOD ( 14.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Modify arm64/Kconfig to enable kexec_file_load support. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/Kconfig | 9 +++++++++ arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/machine_kexec_file.c | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1b1a0e95c751..5eb18d0cb513 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -843,6 +843,15 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + help + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 4c8b13bede80..030a39bff117 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Fri Sep 28 06:48:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBF9215A6 for ; Fri, 28 Sep 2018 07:07:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB11C2AE9B for ; Fri, 28 Sep 2018 07:07:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEBD22B00C; Fri, 28 Sep 2018 07:07:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E11882AE9B for ; Fri, 28 Sep 2018 07:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ON1cWzqTfh8BBnQn4kU28yqxZ2VgrxbCRT1V3h4vT3s=; b=JGPFMgwtWcs0rG qQ3Zb0VkVqg31WTM5NjGdlskSPxPwB/bRZ89sfnX+12yCXnUBm02bfHPzq3Rmj2dBTV0NYG9aAif0 3VSgf5vpMy8wUYJER9rhgkz5IeTfDQARLBRNLvvw0KQtlRCqomk2taXpkIahGyAU7/bf9OHbvpPfk TZxlPmC1iPg12/Hk0BEdC1aPX4Fp+mcL24prrOAd/1RAq4f79MyisLpjbr1klweeLD1vJ9ph8B1EV dRjRSkatmLNEoHs1FlqWFvZTYAT4+tsft04mIN9rQoKQNRDBNJ3LGpF+KPZHIuKymSKnchhmgq6x/ xdrv46Wm2ev24CPxsWkQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5msQ-0007r9-Ld; Fri, 28 Sep 2018 07:07:50 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mad-0004ps-AB for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:49:33 +0000 Received: by mail-pg1-x544.google.com with SMTP id f18-v6so224025pgv.3 for ; Thu, 27 Sep 2018 23:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vzr4R2Cq+6LI3NmBny8qeM6kKSI6IrCINci/4DwDurI=; b=NmzOBt9SYJiINTopNWJxES3Ii8Ip9h3YBRbfaMCfqDxr+8HgduY2+snZV3WvaKyjno jDgQ16BL5b0xBDer5t1T3srjxKkpSzcni4ev0szNZIZPI4/jnkEEoULsl0tM6bfFznQ9 0JtluZuWp7YbRG6fdx4+uCgn1rGy1WS7XfLGY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vzr4R2Cq+6LI3NmBny8qeM6kKSI6IrCINci/4DwDurI=; b=BiRU86g5+alCSorGe6WI284lSIurVdkcFB43u6Y86xTh5ZHS3xHgb2zYqzMtmzrDcU NDEh9PSwq5ZtDHTWzgFANeMx06og1Qp8MVhF7LIeVIXa+em7Xxy/mCYfCinzpYPsA7ds hVSpUUbtL/6ido5NmYsq5YZy9I6uXTLKt1uPjEnzryvz2qThFKst1+DPkA/EdCDpGFSz SvuMPAYR6fX8/SwMCnUk6QNneGfXcYc+wVvacpuOxVJGTcn4bupEF2bwAJlNmXpdkk6h ThVRDe6ITDqNAAiBvq8Nco3V/EwFzTjXM+hpkWLZCx2EKpJtGV1sgdTji2lZCr242PYx jB8Q== X-Gm-Message-State: ABuFfogVcR+wqxhfjCdie2qUctMDG2DvF4fAYYu9Z1bGNyxFhNGyTqgR 1Z0E/h9eUGxZuGSXgmYpf1zIhg== X-Google-Smtp-Source: ACcGV60RgPyS9f47l+aARxAWCcz+1AQ7BKGkss9wGAbsBBA/sz9LziQDQSp3FK7759bsa9TsuqflMQ== X-Received: by 2002:a62:2646:: with SMTP id m67-v6mr15207110pfm.254.1538117336614; Thu, 27 Sep 2018 23:48:56 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f6-v6sm5316468pgf.52.2018.09.27.23.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:55 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 10/16] arm64: kexec_file: load initrd and device-tree Date: Fri, 28 Sep 2018 15:48:35 +0900 Message-Id: <20180928064841.14117-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234927_450699_2CC111C9 X-CRM114-Status: GOOD ( 17.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP load_other_segments() is expected to allocate and place all the necessary memory segments other than kernel, including initrd and device-tree blob (and elf core header for crash). While most of the code was borrowed from kexec-tools' counterpart, users may not be allowed to specify dtb explicitly, instead, the dtb presented by the original boot loader is reused. arch_kimage_kernel_post_load_cleanup() is responsible for freeing arm64- specific data allocated in load_other_segments(). Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 17 +++ arch/arm64/kernel/machine_kexec_file.c | 188 +++++++++++++++++++++++++ 2 files changed, 205 insertions(+) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..157b2897d911 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,23 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb; + unsigned long dtb_mem; +}; + +struct kimage; + +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..f53f14bd1700 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,200 @@ * Copyright (C) 2018 Linaro Limited * Author: AKASHI Takahiro * + * Most code is derived from arm64 port of kexec-tools */ #define pr_fmt(fmt) "kexec_file: " fmt +#include +#include #include +#include +#include +#include +#include +#include + +/* relevant device tree properties */ +#define FDT_PSTR_INITRD_STA "linux,initrd-start" +#define FDT_PSTR_INITRD_END "linux,initrd-end" +#define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { NULL }; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb); + image->arch.dtb = NULL; + + return kexec_image_post_load_cleanup_default(image); +} + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + void **dtb_buf, unsigned long *dtb_buf_len) +{ + void *buf = NULL; + size_t buf_size; + int nodeoffset; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + + if (initrd_load_addr) { + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_INITRD_STA, sizeof(u64)); + buf_size += fdt_prop_len(FDT_PSTR_INITRD_END, sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) { + ret = -EINVAL; + goto out_err; + } + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, + cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_STA, + initrd_load_addr); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_STA); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + void *dtb = NULL; + unsigned long initrd_load_addr = 0, dtb_len; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr + kernel_size; + + /* load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.mem = 0; + kbuf.memsz = initrd_len; + kbuf.buf_align = 0; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 32; + kbuf.top_down = false; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.mem = 0; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + image->arch.dtb = dtb; + image->arch.dtb_mem = kbuf.mem; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kbuf.mem, dtb_len, dtb_len); + + return 0; + +out_err: + vfree(dtb); + return ret; +} From patchwork Fri Sep 28 06:48:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A4F816B1 for ; Fri, 28 Sep 2018 07:10:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782562AF7A for ; Fri, 28 Sep 2018 07:10:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C5A52B14A; Fri, 28 Sep 2018 07:10:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9701F2AF7A for ; Fri, 28 Sep 2018 07:10:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zf2lWZNkqMQmy+uCCuz65iqGh3gLSAGxlYSEvG/8ulw=; b=JqXFj2/rLR3+0t GtjQAOxnHddUCVo3wNPOW2ZzUCl2w+s7HL9mYOUcfTdpFQ5O5ZivIciIaGrpgwxLq9QMulhcX6R6Y LQnmnTi8kMsjDSE0ZPjwIWiu2AeCHd6FfabGJxd+/8OYLItz7brcCHFtu6GnibgU73Jleu2WaQ/zi LqtRpD0EZkBgLpB7HG3pcSRtfG2PLrdWmn3rL6M7K976MNSPUsay46YuhkKmA+j5+RrXxKCZ00Ox2 SkESIi6PJalK5AFgINS97DjntJ/GXmj4ZajQue5lUfUOhmXGL554y5fKo5MCGz2hvpmDDTk2y2PKB D2ajRmmP2Fuvha8zzopg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mub-0008JT-2h; Fri, 28 Sep 2018 07:10:05 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mad-0004r9-AE for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:49:36 +0000 Received: by mail-pf1-x444.google.com with SMTP id j26-v6so3613799pfi.10 for ; Thu, 27 Sep 2018 23:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gw6DpdgEdV2DBE7O7Gc03v3qbMo6bneJnE0aBac4sK8=; b=LiLd3clShYknPkFbvlOw8zSiZ3fVRzVFhqMxFPLPEts1PMk8QuaFZqU8O3HyH/9Rod Ksbo+V45gS2bLDf8tUJyhQOA4opizyZcKnmLmCfU67W0Dn8bc0K2z9IlJPcCDQX/ssVl NgtfhxevCcg11R3NebgBwz79MUanvpbTJfcOw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gw6DpdgEdV2DBE7O7Gc03v3qbMo6bneJnE0aBac4sK8=; b=YkaPo9S3z56Oj/2lgm8aSjxN6zdI+XFDkEyjO8PrNXw2osPPLHuRRcH2VGN5VE0DSP fyjHaVflZw+Y9F46WqhIjFMhhoS56xnLA1Eg4/hgmsJPkxpQmwIuw0zMHypkzAVAZIBh XM9It+p9fYKPbRfbEqWL4dmqWZ+N7vvIAffTx+GulL8y40BieB2d6Bo4lO6WQWi4ZDAX itzsJ87WG7JJBO4Mo80ybkzIHYjvS04BMYzBGEWvTTtinG5S8jRAL59TqJitMkpeBNUO og2wcIQGkWlBOjmCFHkQ4qoW4lE3cbk82WuHLWUeZvkEzrHS4iOYZH0+9ePG/wmPLOeC RRRQ== X-Gm-Message-State: ABuFfojvtiVeFKqP4+AkXI2hFQHFXNtA6mqFx3ytU0U/aEC7HnjIqUf5 pqfQHR6WU272HEetbIiaFXMZag== X-Google-Smtp-Source: ACcGV61gl+PfCsua2qPDoJAAFHJtEOy0AbNcNcUNrdRqHoFbsOiDx5EX3+ZN/iNiULu0vZxXkchpSQ== X-Received: by 2002:a17:902:784a:: with SMTP id e10-v6mr14612572pln.197.1538117343963; Thu, 27 Sep 2018 23:49:03 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j27-v6sm7623704pfj.91.2018.09.27.23.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:02 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Fri, 28 Sep 2018 15:48:36 +0900 Message-Id: <20180928064841.14117-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234927_421304_AE29DE65 X-CRM114-Status: GOOD ( 18.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch provides kexec_file_ops for "Image"-format kernel. In this implementation, a binary is always loaded with a fixed offset identified in text_offset field of its header. Regarding signature verification for trusted boot, this patch doesn't contains CONFIG_KEXEC_VERIFY_SIG support, which is to be added later in this series, but file-attribute-based verification is still a viable option by enabling IMA security subsystem. You can sign(label) a to-be-kexec'ed kernel image on target file system with: $ evmctl ima_sign --key /path/to/private_key.pem Image On live system, you must have IMA enforced with, at least, the following security policy: "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig" See more details about IMA here: https://sourceforge.net/p/linux-ima/wiki/Home/ Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 28 +++++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 108 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_image.c diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 157b2897d911..5e673481b3a3 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,34 @@ struct kimage_arch { unsigned long dtb_mem; }; +/** + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @mz_magic: DOS header magic number ('MZ', optional) + * @code1: Instruction (branch to stext) + * @text_offset: Image load offset + * @image_size: Effective image size + * @flags: Bit-field flags + * @reserved: Reserved + * @magic: Magic number + * @pe_header: Offset to PE COFF header (optional) + **/ + +struct arm64_image_header { + __le16 mz_magic; /* also code0 */ + __le16 pad; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 reserved[3]; + __le32 magic; + __le32 pe_header; +}; + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int arch_kimage_file_post_load_cleanup(struct kimage *image); diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 030a39bff117..48868255f09c 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,7 +51,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..d64f5e9f9d22 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kexec image loader + + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + const struct arm64_image_header *h; + + h = (const struct arm64_image_header *)(kernel_buf); + + if (!h || (kernel_len < sizeof(*h)) || + memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) + return -EINVAL; + + return 0; +} + +static void *image_load(struct kimage *image, + char *kernel, unsigned long kernel_len, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct arm64_image_header *h; + u64 flags, value; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* Don't support old kernel */ + h = (struct arm64_image_header *)kernel; + if (!h->text_offset) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + value = head_flag_field(flags, HEAD_FLAG_BE); + if (((value == HEAD_FLAG_BE) && !IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) || + ((value != HEAD_FLAG_BE) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))) + if (!system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = head_flag_field(flags, HEAD_FLAG_PAGE_SIZE); + if (((value == HEAD_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_16K) && + !system_supports_16kb_granule())) + return ERR_PTR(-EINVAL); + + /* Load the kernel */ + kbuf.image = image; + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = false; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.mem = 0; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = MIN_KIMG_ALIGN; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + return ERR_PTR(ret); + + kernel_segment = &image->segment[image->nr_segments - 1]; + kernel_segment->mem += text_offset; + kernel_segment->memsz -= text_offset; + image->start = kernel_segment->mem; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_segment->mem, kbuf.bufsz, + kernel_segment->memsz); + + /* Load additional data */ + ret = load_other_segments(image, + kernel_segment->mem, kernel_segment->memsz, + initrd, initrd_len, cmdline, cmdline_len); + + return ERR_PTR(ret); +} + +const struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index f53f14bd1700..05fb2d4e6fef 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -25,6 +25,7 @@ #define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Fri Sep 28 06:48:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 317F8913 for ; Fri, 28 Sep 2018 07:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 163312A7CC for ; Fri, 28 Sep 2018 07:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 067FE2A7E0; Fri, 28 Sep 2018 07:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 46FB72A7CC for ; Fri, 28 Sep 2018 07:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VscauBFTWADfayKc6RCk9OCRUwMEW6gCqjzKzHsvxO4=; b=QL62z0i2uSSkv9 U7akYohX+5SgLsW+Oph6EMN9SrsEVB1wDTHqH+VbADnwQg6PQh05Dih5XaS9NvTKqHZnDyezNYDIU W2iBUcY3bkUIkURzkAC8z4wnH45gWgmBzfiSSsS31s1FyWoBH45RFIaW2L6SE8R4ZXhb/cDhM/S+A qOjkHIFu25vd6zThuytoyJho/bqgjKNOZwTvXh6nfi9oIRwIBz48hYoi3j5VbZ+NSJO3BVvMMdpfR 0y6e7nnJxnNYIWotlFIqJ+0mnXIwZcJlttASBOjz5xbRplJPqnT02aJd5yP0sscNTyowVu4Ky2J7R rmYyct4hZdOY7Q/u3viw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5n42-0004Xq-GJ; Fri, 28 Sep 2018 07:19:50 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5maw-0004rr-K5 for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:50:25 +0000 Received: by mail-pg1-x542.google.com with SMTP id 85-v6so3729702pge.6 for ; Thu, 27 Sep 2018 23:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J8Y1VWFVHEgu9P7oEU8UAY9BvikA0olKUy5ed/MNwaE=; b=Rmxl+pcSKewfJvUQc7aty+Zf7gx63A4Ld5udoGDuU7FFhO7eJlxEc9iNUEiKc43heF EgZKRCSS3ugC9djMQPDh2sHtMN1EIzmf5Q5rpYH/stfpyV5FmE6AOukoFrdX5UgzE8Ad eZJKR4RNYHB6yr6Y1/7gZvokPhw5eJd/k2YLE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J8Y1VWFVHEgu9P7oEU8UAY9BvikA0olKUy5ed/MNwaE=; b=NYEk9O9Tng3JURddz8AVclHs3f5ikCT0GzJIuftlgXZJrDjTpkNqYPTw7ZrlY5g9D1 ttpJxxG69fQQLimGZwhK3CXS3f3BrsGvdSqQpU9DXdKUdXSHnTzwzEUiF5r4/Mv6eKEr qZ4/LYVx7wzK0QMT1jUknk5RJ0g1t1TN7cDXqlBYc+/MRQovOOA4pn/w/KLSJBj7bd/j JilbG4NWbo8tyBthdtltijbuLXmDdbNAZy0QzZc5RGRr08qNrOKyNZTYaEjYLv0nNIHV R4aRk7K9OajQMGB/ZCevvvTM6Lm7OkIR5O6GO3mjLos7rhqZPPPtCp+UJCAAP2dBt6jV Myvg== X-Gm-Message-State: ABuFfogru3r010Im77Q+VnfIUpGz37sboZRc0bZ6dQBLAd0JdEDOAej8 Lnj3K3Ff4XzEsr75TA7NhSQUpl+Q8ck= X-Google-Smtp-Source: ACcGV61b6zqMdz2WK8ofJJGx4t9sYegpLQ860OzQ33lDp5oa1QxE2BP2UTLYp95SjZOqT3AjvV7Q+Q== X-Received: by 2002:a65:588e:: with SMTP id d14-v6mr8052898pgu.117.1538117356121; Thu, 27 Sep 2018 23:49:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b7-v6sm4555243pgt.46.2018.09.27.23.49.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:15 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 12/16] arm64: kexec_file: add crash dump support Date: Fri, 28 Sep 2018 15:48:37 +0900 Message-Id: <20180928064841.14117-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234946_764975_AC57A581 X-CRM114-Status: GOOD ( 21.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org --- arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/machine_kexec_file.c | 109 ++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5e673481b3a3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; /** diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 05fb2d4e6fef..4b5ea256c84c 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,10 +16,14 @@ #include #include #include +#include #include +#include #include /* relevant device tree properties */ +#define FDT_PSTR_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PSTR_MEM_RANGE "linux,usable-memory-range" #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" @@ -34,6 +38,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb); image->arch.dtb = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -43,12 +51,25 @@ static int setup_dtb(struct kimage *image, void **dtb_buf, unsigned long *dtb_buf_len) { void *buf = NULL; - size_t buf_size; + int addr_cells, size_cells; + size_t buf_size, range_size; int nodeoffset; int ret; /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); + addr_cells = fdt_address_cells(initial_boot_params, 0); + if (addr_cells < 0) + return -EINVAL; + size_cells = fdt_size_cells(initial_boot_params, 0); + if (size_cells < 0) + return -EINVAL; + range_size = (addr_cells + size_cells) * sizeof(u32); + + if (image->type == KEXEC_TYPE_CRASH) { + buf_size += fdt_prop_len(FDT_PSTR_KEXEC_ELFHDR, range_size); + buf_size += fdt_prop_len(FDT_PSTR_MEM_RANGE, range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -78,6 +99,22 @@ static int setup_dtb(struct kimage *image, goto out_err; } + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, @@ -135,6 +172,43 @@ static int setup_dtb(struct kimage *image, return ret; } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + + if (!ret) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -142,14 +216,43 @@ int load_other_segments(struct kimage *image, char *cmdline, unsigned long cmdline_len) { struct kexec_buf kbuf; - void *dtb = NULL; - unsigned long initrd_load_addr = 0, dtb_len; + void *headers, *dtb = NULL; + unsigned long headers_sz, initrd_load_addr = 0, dtb_len; int ret = 0; kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&headers, &headers_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.buffer = headers; + kbuf.bufsz = headers_sz; + kbuf.mem = 0; + kbuf.memsz = headers_sz; + kbuf.buf_align = SZ_64K; /* largest supported page size */ + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(headers); + goto out_err; + } + image->arch.elf_headers = headers; + image->arch.elf_headers_mem = kbuf.mem; + image->arch.elf_headers_sz = headers_sz; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_headers_mem, headers_sz, headers_sz); + } + /* load initrd */ if (initrd) { kbuf.buffer = initrd; From patchwork Fri Sep 28 06:48:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DF0F913 for ; Fri, 28 Sep 2018 07:16:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67D632AA62 for ; Fri, 28 Sep 2018 07:16:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A0E22AB1F; Fri, 28 Sep 2018 07:16:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A79892AA62 for ; Fri, 28 Sep 2018 07:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yWhd6S/P6T9bDETVxIx7Qy6xAOG2Nd4vaqHKGNfyTYg=; b=Iylfkp9mdgsqzJ QQJxoLk4E8wvBbwDi6VweNXSivNzj30CU2ZaAPmAth0sS5i6Gtvps6/CI2YtBx0Be76u5fF0frQDZ eeBTK9ouWvVUdAlUn2OX2Te3xGnlh/B8pDNRgFuJWsBnHYwN6gCwL8L+U4Oeikf9JqVNu0ZYEFOoK 0qS8d8grObrrdn5MfHIlugAXQi+yQtafb2/SZBuwKf1A/cZcFhZklQA/HPRScsUQcfg0kRFx6c5dq dyfdMqNnf5cKlJcD6dkbmht/fKVG2ie435Mn41cPq+HwjCeueamKRJbXoOSwKVrHzzH84BZ6oh9rx yI95d+c5r/o1NrqHbI0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5n0Z-0003RO-2B; Fri, 28 Sep 2018 07:16:15 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5maw-0004se-K8 for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:49:59 +0000 Received: by mail-pg1-x541.google.com with SMTP id v133-v6so3746470pgb.2 for ; Thu, 27 Sep 2018 23:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=Akut7E51HyMcmoDJ8yq2dxz/1WR22lD8Tli0lJqraJGLfSUeCA7RHO949kC/rxf83y z5MqpcFwckf7HsZYfQldR7Dv1ZCJD6N3/miuWvGM3bGuOiGBs6//wrEYJ4V0HeODh+qP 0F93GU41LJIxZ3fOmJqvU3fiHH1f4dfNr7dkY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=AM8MPlVOfKIUXAe9v9R5SjE2BWevCihpfWn2KA5/czJ4/mfqWuzqPeQcumTVFI+NEO cA75QSRb656MjRUfJPMSlXVowh+EA6/Ux1OgfkGGSCig9Uo8yUax55Wu9Jbi22bpBRHi aW40Pgrauo/myRLaLIp6ZtImKH23RUNi54/wSAxvjA8DLWrMB7Tg0ggciHWiqY+Bc0YU o3oD6JEFRMfEMtLYFF0GIMBS3T2Zop8NMG7+0qcHjct/9sVMuE002qR+I0k14fbxc9/H DxlHvXwSzDHoz+GSZdQDtNslfNixTH5pQ3je8WNhVtm0JztCpjdwZH+Bh9VsuCdIhj0x XUMQ== X-Gm-Message-State: ABuFfoh4SNElXBUXgRCp0OIcNTAQpsjNVDbx5VuQZCgpBVd5pcmU3qfx B5ycfGuFGMoz5tTx7lMB9RTWyQ== X-Google-Smtp-Source: ACcGV61Cf7qGrnDdyVYFZ3yzbC5W9PbJu++kfm2zHsjntKkWshWhhZWlD/xgUvrGl+JbjEwrYihUaA== X-Received: by 2002:a17:902:e088:: with SMTP id cb8-v6mr14600861plb.189.1538117362702; Thu, 27 Sep 2018 23:49:22 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m27-v6sm6990442pff.187.2018.09.27.23.49.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:21 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Fri, 28 Sep 2018 15:48:38 +0900 Message-Id: <20180928064841.14117-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234946_745930_46C8F6E4 X-CRM114-Status: GOOD ( 15.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On arm64, purgatory would do almost nothing. So just invoke secondary kernel directly by jumping into its entry code. While, in this case, cpu_soft_restart() must be called with dtb address in the fifth argument, the behavior still stays compatible with kexec_load case as long as the argument is null. Signed-off-by: AKASHI Takahiro Reviewed-by: James Morse Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/cpu-reset.S | 8 ++++---- arch/arm64/kernel/machine_kexec.c | 12 ++++++++++-- arch/arm64/kernel/relocate_kernel.S | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 8021b46c9743..a2be30275a73 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -22,11 +22,11 @@ * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for * cpu_soft_restart. * - * @el2_switch: Flag to indicate a swich to EL2 is needed. + * @el2_switch: Flag to indicate a switch to EL2 is needed. * @entry: Location to jump to for soft reset. - * arg0: First argument passed to @entry. - * arg1: Second argument passed to @entry. - * arg2: Third argument passed to @entry. + * arg0: First argument passed to @entry. (relocation list) + * arg1: Second argument passed to @entry.(physical kernel entry) + * arg2: Third argument passed to @entry. (physical dtb address) * * Put the CPU into the same state as it would be if it had been reset, and * branch to what would be the reset vector. It must be executed with the diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 922add8adb74..aa9c94113700 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -212,9 +212,17 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - - cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0); + cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Fri Sep 28 06:48:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2BCD8913 for ; Fri, 28 Sep 2018 07:23:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 123BC284A5 for ; Fri, 28 Sep 2018 07:23:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 022272863D; Fri, 28 Sep 2018 07:23:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 50854284A5 for ; Fri, 28 Sep 2018 07:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RMICz8PdpenwZJ+Xrvc+Y+sXzw1+034SWZWNV7XVpyE=; b=FsvJ4D5J7Bqi6z gPyqh2Mxgq7RgVs9uS09W7IVKujviH8zomos3/IYaAKPQbWJx+IN0dM2aaL7JUaqTOzpEZdyvIwT5 wgBzjt6JBmYY0Cb64rxe3XqYE06m+oXWcwbqU4ByR1DKvUxojInWJJb5QjaHghRu7mlqaN9ERWC2w bMKxXk6WknvPhOZPJMZGToalJ44hehjRYPtCEWG4+olbgUtmcTtAnw9xGRdSYyUMgQmMK2LMQv//m 5Z+h+w8yUujqirHsm3xj80DtGRePphXE/Ed5xrQF7lIz/ddySOQjRs1RMFsNg9zOLUvctnz8vKFXd lz5rIkGy2qypgUUYxGoA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5n71-0006IU-6Q; Fri, 28 Sep 2018 07:22:55 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mb7-0004uX-RY for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:50:36 +0000 Received: by mail-pf1-x441.google.com with SMTP id d8-v6so3609603pfo.13 for ; Thu, 27 Sep 2018 23:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=Mh2bCx/ZN4Zr/xQdf+Ij2U350YGbZV2r17bFphhhLYuMo7nTEzXYoI8KgK05BStuHg 29FRhfAGp7d3b3cqtE3ewpnaKTCMcgMRrwEW56yUxea7nyOgJ6HWQkIjIbR61Ef6imOo yDiAjpO0CKf4ZkwsS5kiFcYyNa0dYA9L6lr/8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=Iu+7jOqqYVUDp1/Uz2y5K0nABXn0cEiBYLtkECEr/EbOMaRDz5M9zgYf8z35KRT7JO lUrpwC5ync3WBmRv6iKc77Kjs04HIjF86fw4XE74uaHxszgHS6VcSV+tFB1acNNTHQxR /1IdeDiEvtrakcBcKm1q1m9c8oCs52JET+ld4A54+iKO9KR7Sz31WI6TkoeYAmuAGE+4 uZhxBLC1HTPJZRcZ5cMdHLT/mC6l2H6IB5sea4A2WJm6ntyPJsuIlRrsHfFhORurobmb xhsIGYPA+UXiDsuvUzOexy07AIPlGK+QygiRYqDH3rz1BwqXEBwiwZIBTtJCst1vLdhF 7l9Q== X-Gm-Message-State: ABuFfoiYkmf3o0k6lwaTgAcFZI268oxQ0igvCeMYY2Lh0SDZtvmuBmGq MlWEdIf78DOAVA+njHjqdhZK+w== X-Google-Smtp-Source: ACcGV62gOh3DZWx1Vwu7nEf5PxhFhRq0LyZH5qhvdCcGY3XSjPCfLyXLcgZdADX0Jnuddwgy7W8XUg== X-Received: by 2002:a63:29c6:: with SMTP id p189-v6mr5419584pgp.188.1538117366876; Thu, 27 Sep 2018 23:49:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y128-v6sm5938994pfb.56.2018.09.27.23.49.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:25 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 14/16] include: pe.h: remove message[] from mz header definition Date: Fri, 28 Sep 2018 15:48:39 +0900 Message-Id: <20180928064841.14117-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234958_102320_00A7F7AA X-CRM114-Status: GOOD ( 14.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP message[] field won't be part of the definition of mz header. This change is crucial for enabling kexec_file_load on arm64 because arm64's "Image" binary, as in PE format, doesn't have any data for it and accordingly the following check in pefile_parse_binary() will fail: chkaddr(cursor, mz->peaddr, sizeof(*pe)); Signed-off-by: AKASHI Takahiro Reviewed-by: Ard Biesheuvel Cc: David Howells Cc: Vivek Goyal Cc: Herbert Xu Cc: David S. Miller --- include/linux/pe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Fri Sep 28 06:48:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2803913 for ; Fri, 28 Sep 2018 07:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA3E02A8A0 for ; Fri, 28 Sep 2018 07:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCE9C2A8AD; Fri, 28 Sep 2018 07:23:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 082E42A8A0 for ; Fri, 28 Sep 2018 07:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mkKMci5dXzCP0Bi10c73r89PbAOOWtCrRyymcS+LaB8=; b=fuZc2HbXLqe5t+ e3xsvDNN/H/HYef8IRipmTViA58gGWrVbFnpCbc35lVYazKqBi6Q++OaAxtG2PYIwJ9ykR0XGvWjk srtukCqMbYv4xiVrluJYNOoG1gZmq6Wm57/V0VVOoSzGba9gwrFPBeVfhxbOGvqEAXxXkVR629n1C RLr0yrV9WjSsj++ZcyIXyf3y/UGOVS3eHJf9bKx+3p0d+Q+A6+e3mfAszFNXG0XRbUcApl1ycmUwL GWeDi9rUtl8JzkEwbKV+R8hsowgwJdMtjkGgG/psfNDfeQ5njrRWJWJ+wM1MViyWe50ChWAMfvvJn uVPcdaqeSG9JOCetRLmQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5n7n-0006Yg-TP; Fri, 28 Sep 2018 07:23:43 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mb7-0004xJ-So for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:50:37 +0000 Received: by mail-pf1-x442.google.com with SMTP id s5-v6so3626885pfj.7 for ; Thu, 27 Sep 2018 23:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/+rOwpZAq7LVQH0becYmXtiL//qU2xu/pSqOkMjD4f0=; b=KB4DyH3/aOOCTeE+ulXend4IlnHljB8l5FxwaLh7zMawvTxl7hXakSbyIdy2GdfBCW TNu6W9rqd6YcC/Kpzk+yYa5fv0ttZ9AtOK1qLnCv7Fg6BTui3hGcYghBqoaFUVpmiYPY HiRibIaRnhkbDmMNt9I9kQiq9lvDDFVFZnlyk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/+rOwpZAq7LVQH0becYmXtiL//qU2xu/pSqOkMjD4f0=; b=T4koretZ0rgY52PugUp3vgeaE+ZAxGHDGM8SyztEN9esh2ADsw3yipj55V7BIHTKND c2RPA6aGJOw18khcQ/gshY8KEYWc2uXBCR+/JPPor0lKX9ddB3SJAwov3j6anYH2VBOH k3zt+HRq10CnQpCW56YXx3+LvEseRlQyn7aSh5mCkr1x2D5N28RUB1n6KXQ1uzSsFVwd cDLei4nQxcss0qlx0lsnN2UaPNXJ74JyZ/KQZMzTS+tfnx2+YewdJBms2JfWn86Q2XD2 vKqYjtBIlkOe4tnXB1AykLmdnEiWBziuG0IrD3wN7q1oOoss0Ik+6qydiDN1k/Pg4zew iYJg== X-Gm-Message-State: ABuFfojLANWjAnGRh4X5XZ1D+SyZ7RYJ6+LshgUCbTUJO3mlH/mwsSy9 7xB+FN7Mh0WEyN5p7ST4OffKeA== X-Google-Smtp-Source: ACcGV60SDpQTkxHCAGmUi4T9yL5fxZ5izgApfms5Yuq6163677NqEYfYEU7DiQUy9rUdcK58yn0tTg== X-Received: by 2002:a17:902:4e:: with SMTP id 72-v6mr14655909pla.318.1538117371502; Thu, 27 Sep 2018 23:49:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c79-v6sm195047pfc.92.2018.09.27.23.49.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:30 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 15/16] arm64: kexec_file: add kernel signature verification support Date: Fri, 28 Sep 2018 15:48:40 +0900 Message-Id: <20180928064841.14117-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234958_117229_03299AEB X-CRM114-Status: GOOD ( 16.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 5eb18d0cb513..e7de9500bf0b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -852,6 +852,30 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + +config KEXEC_IMAGE_VERIFY_SIG + bool "Enable Image signature verification support" + default y + depends on KEXEC_VERIFY_SIG + depends on EFI && SIGNED_PE_FILE_VERIFICATION + help + Enable Image signature verification support. + +comment "Support for PE file signature verification disabled" + depends on KEXEC_VERIFY_SIG + depends on !EFI || !SIGNED_PE_FILE_VERIFICATION + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index d64f5e9f9d22..578d358632d0 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -102,7 +106,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif }; From patchwork Fri Sep 28 06:48:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A935913 for ; Fri, 28 Sep 2018 07:18:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 714732A5EE for ; Fri, 28 Sep 2018 07:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 603E02A62E; Fri, 28 Sep 2018 07:18:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9E5292A5EE for ; Fri, 28 Sep 2018 07:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oxShrqo0MKia109MEVQSlobcdOW+EN1ilHgcsFfmv6g=; b=Ef7EKK/QNmN9wF qgyw2CznCsZ4/NEeVHE37KNd8aWRuFXFwUgeBjPBCOsdUPBfhcrJlkIlbYApq12nkL2M9J/zFzFKe BxpcrdvvDNoX6iZ+hHpWSrW7acQ3/y3J5LC8Yja1W3eUMTy9MzIY357caFQc+4LwhYdsxsRAoBpOs XiCytNc3pWcfJbH1Cf7dmGWFEy3NSXJItklGKwGCnBThwgYNduPFHkuDE5ccLDF67NF0n5dCX2dfm VUYhpI1TM/je4+b3VhG6qWdvQnKMauji9ATBaXR5lfvL/EezjAjLwNaBLFymRB1oTJNDlj4nTNC2k GA9ab2Xb/h9bFQSbNUYg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5n2K-0003mu-OP; Fri, 28 Sep 2018 07:18:04 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mb7-0004yk-NK for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:50:25 +0000 Received: by mail-pg1-x542.google.com with SMTP id b129-v6so3703858pga.13 for ; Thu, 27 Sep 2018 23:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A1to76Muk1fdla+xjmMFJtb5BFlQOFVgZ1KKX32hm3g=; b=WPP9Dm8h5cUbvm4Vfgv7CG3sbSL7MvhM+E7czCqoCAP7d5W0p+jJMUvGc6ekYRON7Q WjHEuVNSOUEXW6cep8nc4kw9iwIZywVej83PvFnvtFRAHMXDWfv8pwR4EjzmQK/Mxkp0 mCmlN2yGuQ9kXGuD2d1zUrHD3hAQAk7WOD/H0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A1to76Muk1fdla+xjmMFJtb5BFlQOFVgZ1KKX32hm3g=; b=l+XsKTdCYAg28/PzIVirpK3l26mFL0faHAPdTwsPFqWUSR8ipmgu9Szq50GGCWp07C ZuFuuj3DjSfwiT/BRrGOz0hV5hNUpCranzDWYIaq1oQmlhpDXMU/nZzXKW+REK0k3Kis JOFDyC3KbuEoaFCIfCd0fo+EZsE79KHCPhN7OSNCjsx2gXQEGob/DIZXFJi0NtYieMWK YfoA9XlMaQi1+zqoqKw483FAut/42/5KwKvgDBKme7JRqowVVKcf1ZsJOLSssMlU7os+ K46afFcwAaJ4Rz77DvXuabzTKqMAay/gGjtvfQWteFl2DWoyB+dS2GTeGYJ3jeSuciC3 /9Bg== X-Gm-Message-State: ABuFfohSUYfWSYEgbB98WQu0iEs4UVpNDjjqpat0S/ngjqmZJm5LLcvg aduO6yK97FuYcG4CKV2czX8s8A== X-Google-Smtp-Source: ACcGV62mEVMP4yeRl5oKUOSiQjF8auBWlkh6aFE/N6Azq43A328TlDptRmNL7cSZUf8D4XMBy2zjuw== X-Received: by 2002:a63:5816:: with SMTP id m22-v6mr13507559pgb.332.1538117376233; Thu, 27 Sep 2018 23:49:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r12-v6sm5024997pfh.79.2018.09.27.23.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:35 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 16/16] arm64: kexec_file: add kaslr support Date: Fri, 28 Sep 2018 15:48:41 +0900 Message-Id: <20180928064841.14117-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234957_905292_41FE64F8 X-CRM114-Status: GOOD ( 17.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Adding "kaslr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it will have no harm on kaslr-incapable kernel. We don't have any "switch" to turn off this feature directly, but still can suppress it by passing "nokaslr" as a kernel boot argument. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/machine_kexec_file.c | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 4b5ea256c84c..c2ca7c921e7a 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" +#define FDT_PSTR_KASLR_SEED "kaslr-seed" const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -45,6 +47,32 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } +/* crng needs to have been initialized for providing kaslr-seed */ +static int random_ready; + +static void random_ready_notified(struct random_ready_callback *unused) +{ + random_ready = 1; +} + +static struct random_ready_callback random_ready_cb = { + .func = random_ready_notified, +}; + +static __init int init_random_ready_cb(void) +{ + int ret; + + ret = add_random_ready_callback(&random_ready_cb); + if (ret == -EALREADY) + random_ready = 1; + else if (ret) + pr_warn("failed to add a callback for random_ready\n"); + + return 0; +} +late_initcall(init_random_ready_cb) + static int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -54,6 +82,7 @@ static int setup_dtb(struct kimage *image, int addr_cells, size_cells; size_t buf_size, range_size; int nodeoffset; + u64 value; int ret; /* duplicate dt blob */ @@ -81,6 +110,8 @@ static int setup_dtb(struct kimage *image, /* can be redundant, but trimmed at the end */ buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + buf_size += fdt_prop_len(FDT_PSTR_KASLR_SEED, sizeof(u64)); + buf = vmalloc(buf_size); if (!buf) { ret = -ENOMEM; @@ -160,6 +191,20 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + fdt_delprop(buf, nodeoffset, FDT_PSTR_KASLR_SEED); + if (random_ready) { + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_KASLR_SEED, + value); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + pr_notice("kaslr-seed won't be fed\n"); + } + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;